Commit 5e10ac8f authored by Sviatoslav Nekhaienko's avatar Sviatoslav Nekhaienko
Browse files

introduced generateActualNameWithoutTs method, this decreases number of renamings

parent b6b8692a
Pipeline #20196 failed with stage
in 43 seconds
......@@ -66,8 +66,8 @@ public class CleanupIndiciesSteps extends TestsBase {
for (Setup input : inputList) {
TestIndex testIndex = getTextIndex();
testIndex.setHttpClient(httpClient);
testIndex.setIndex(generateActualNameWithTS(input.getIndex(), timeStamp));
testIndex.setKind(generateActualNameWithTS(input.getKind(), timeStamp));
testIndex.setIndex(generateActualName(input.getIndex(), timeStamp));
testIndex.setKind(generateActualName(input.getKind(), timeStamp));
testIndex.setSchemaFile(input.getSchemaFile());
inputIndexMap.put(testIndex.getKind(), testIndex);
}
......@@ -81,16 +81,16 @@ public class CleanupIndiciesSteps extends TestsBase {
}
public void iIngestRecordsWithTheforAGiven(String record, String dataGroup, String kind) {
String actualKind = generateActualNameWithTS(kind, timeStamp);
String actualKind = generateActualName(kind, timeStamp);
try {
String fileContent = FileHandler.readFile(String.format("%s.%s", record, "json"));
records = new Gson().fromJson(fileContent, new TypeToken<List<Map<String, Object>>>() {}.getType());
for (Map<String, Object> testRecord : records) {
testRecord.put("id", generateActualNameWithTS(testRecord.get("id").toString(), timeStamp));
testRecord.put("id", generateActualName(testRecord.get("id").toString(), timeStamp));
testRecord.put("kind", actualKind);
testRecord.put("legal", generateLegalTag());
String[] x_acl = {generateActualNameWithTS(dataGroup,timeStamp)+"."+getEntitlementsDomain()};
String[] x_acl = {generateActualName(dataGroup,timeStamp)+"."+getEntitlementsDomain()};
Acl acl = Acl.builder().viewers(x_acl).owners(x_acl).build();
testRecord.put("acl", acl);
}
......@@ -103,7 +103,7 @@ public class CleanupIndiciesSteps extends TestsBase {
}
public void iCheckThatTheIndexForHasBeenCreated(String kind) throws IOException, InterruptedException {
assertTrue(isNewIndexCreated(generateActualNameWithTS(kind, timeStamp)));
assertTrue(isNewIndexCreated(generateActualName(kind, timeStamp)));
}
public void iShouldDeleteTheRecordsForICreatedEarlier() {
......@@ -124,13 +124,13 @@ public class CleanupIndiciesSteps extends TestsBase {
public void iShouldDeleteTheSchemaForICreatedEarlier(String kind) {
ClientResponse response = httpClient.send(HttpMethod.DELETE,
String.format("%sschemas%s", getStorageBaseURL(), "/" + generateActualNameWithTS(kind, timeStamp)),null,
String.format("%sschemas%s", getStorageBaseURL(), "/" + generateActualName(kind, timeStamp)),null,
headers, httpClient.getAccessToken());
assertEquals(HttpStatus.SC_NO_CONTENT, response.getStatus());
}
public void iShouldCheckThetTheIndexforHasNotBeenDeleted(String kind) throws IOException, InterruptedException {
assertTrue(isNewIndexExist(generateActualNameWithTS(kind, timeStamp)));
assertTrue(isNewIndexExist(generateActualName(kind, timeStamp)));
}
public void iShouldToRunCleanupOfIndexesForAnd(String kind, String message) {
......@@ -143,11 +143,11 @@ public class CleanupIndiciesSteps extends TestsBase {
}
public void iShouldCheckThatTheIndexForHasBeenDeleted(String kind) throws IOException, InterruptedException {
assertFalse(isNewIndexExist(generateActualNameWithTS(kind, timeStamp)));
assertFalse(isNewIndexExist(generateActualName(kind, timeStamp)));
}
private String convertMessageIntoJson(String kind, String message) {
String actualKind = generateActualNameWithTS(kind, timeStamp);
String actualKind = generateActualName(kind, timeStamp);
RecordChangedMessages recordChangedMessages = (new Gson()).fromJson(String.format(message,
actualKind, actualKind, timeStamp), RecordChangedMessages.class);
return new Gson().toJson(recordChangedMessages);
......
......@@ -73,8 +73,8 @@ public class RecordSteps extends TestsBase {
for (Setup input : inputList) {
TestIndex testIndex = getTextIndex();
testIndex.setHttpClient(httpClient);
testIndex.setIndex(generateActualNameWithTS(input.getIndex(), timeStamp));
testIndex.setKind(generateActualNameWithTS(input.getKind(), timeStamp));
testIndex.setIndex(generateActualName(input.getIndex(), timeStamp));
testIndex.setKind(generateActualName(input.getKind(), timeStamp));
testIndex.setSchemaFile(input.getSchemaFile());
inputIndexMap.put(testIndex.getKind(), testIndex);
}
......@@ -91,7 +91,7 @@ public class RecordSteps extends TestsBase {
public void i_ingest_records_with_the_for_a_given(String record, String dataGroup, String kind) {
String actualKind = generateActualNameWithTS(kind, timeStamp);
String actualKind = generateActualName(kind, timeStamp);
try {
String fileContent = FileHandler.readFile(String.format("%s.%s", record, "json"));
records = new Gson().fromJson(fileContent, new TypeToken<List<Map<String, Object>>>() {}.getType());
......@@ -100,7 +100,7 @@ public class RecordSteps extends TestsBase {
testRecord.put("id", generateRecordId(testRecord));
testRecord.put("kind", actualKind);
testRecord.put("legal", generateLegalTag());
String[] x_acl = {generateActualNameWithTS(dataGroup,timeStamp)+"."+getEntitlementsDomain()};
String[] x_acl = {generateActualName(dataGroup,timeStamp)+"."+getEntitlementsDomain()};
Acl acl = Acl.builder().viewers(x_acl).owners(x_acl).build();
testRecord.put("acl", acl);
}
......@@ -114,17 +114,17 @@ public class RecordSteps extends TestsBase {
}
protected String generateRecordId(Map<String, Object> testRecord) {
return generateActualNameWithTS(testRecord.get("id").toString(), timeStamp);
return generateActualName(testRecord.get("id").toString(), timeStamp);
}
public void i_should_get_the_documents_for_the_in_the_Elastic_Search(int expectedCount, String index) throws Throwable {
index = generateActualNameWithTS(index, timeStamp);
index = generateActualName(index, timeStamp);
long numOfIndexedDocuments = createIndex(index);
assertEquals(expectedCount, numOfIndexedDocuments);
}
public void i_should_get_the_elastic_for_the_tenant_testindex_timestamp_well_in_the_Elastic_Search(String expectedMapping, String type, String index) throws Throwable {
index = generateActualNameWithTS(index, timeStamp);
index = generateActualName(index, timeStamp);
ImmutableOpenMap<String, MappingMetaData> elasticMapping = elasticUtils.getMapping(index);
assertNotNull(elasticMapping);
......@@ -135,7 +135,7 @@ public class RecordSteps extends TestsBase {
}
public void iShouldGetTheNumberDocumentsForTheIndexInTheElasticSearchWithOutSkippedAttribute(int expectedCount, String index, String skippedAttributes) throws Throwable {
index = generateActualNameWithTS(index, timeStamp);
index = generateActualName(index, timeStamp);
long numOfIndexedDocuments = createIndex(index);
long documentCountByQuery = elasticUtils.fetchRecordsByExistQuery(index, skippedAttributes);
assertEquals(expectedCount, documentCountByQuery);
......
......@@ -18,13 +18,13 @@ public class SchemaServiceRecordSteps extends RecordSteps {
public void the_schema_is_created_with_the_following_kind(DataTable dataTable) {
List<Setup> inputList = dataTable.asList(Setup.class);
inputList.forEach(this::createSchema);
inputList.forEach(s -> deleteIndex(generateActualName(s.getIndex())));
inputList.forEach(s -> deleteIndex(generateActualNameWithoutTs(s.getIndex())));
super.addShutDownHook();
}
private void createSchema(Setup input) {
PersistentSchemaTestIndex testIndex = new PersistentSchemaTestIndex(super.elasticUtils, super.httpClient, this);
testIndex.setIndex(generateActualNameWithTS(input.getIndex(), super.getTimeStamp()));
testIndex.setIndex(generateActualName(input.getIndex(), super.getTimeStamp()));
testIndex.setSchemaFile(input.getSchemaFile());
testIndex.setHttpClient(super.httpClient);
testIndex.setupSchema();
......@@ -39,7 +39,7 @@ public class SchemaServiceRecordSteps extends RecordSteps {
@Override
protected String generateRecordId(Map<String, Object> testRecord) {
return generateActualName(testRecord.get("id").toString());
return generateActualNameWithoutTs(testRecord.get("id").toString());
}
@Override
......
......@@ -54,19 +54,19 @@ public abstract class TestsBase {
for (Setup input : inputList) {
TestIndex testIndex = getTextIndex();
testIndex.setHttpClient(httpClient);
testIndex.setIndex(generateActualNameWithTS(input.getIndex(), timeStamp));
testIndex.setKind(generateActualNameWithTS(input.getKind(), timeStamp));
testIndex.setIndex(generateActualName(input.getIndex(), timeStamp));
testIndex.setKind(generateActualName(input.getKind(), timeStamp));
testIndex.setMappingFile(input.getMappingFile());
testIndex.setRecordFile(input.getRecordFile());
List<String> dataGroup = new ArrayList<>();
String[] viewerGroup = input.getViewerGroup().split(",");
for (int i = 0; i < viewerGroup.length; i++) {
viewerGroup[i] = generateActualNameWithTS(viewerGroup[i], timeStamp) + "." + getEntitlementsDomain();
viewerGroup[i] = generateActualName(viewerGroup[i], timeStamp) + "." + getEntitlementsDomain();
dataGroup.add(viewerGroup[i]);
}
String[] ownerGroup = input.getOwnerGroup().split(",");
for (int i = 0; i < ownerGroup.length; i ++) {
ownerGroup[i] = generateActualNameWithTS(ownerGroup[i], timeStamp) + "." + getEntitlementsDomain();
ownerGroup[i] = generateActualName(ownerGroup[i], timeStamp) + "." + getEntitlementsDomain();
if (dataGroup.indexOf(ownerGroup[i]) > 0) {
dataGroup.add(ownerGroup[i]);
}
......@@ -123,18 +123,18 @@ public abstract class TestsBase {
log.info(String.format("Scenario Name: %s, Correlation-Id: %s", scenario.getId(), headers.get("correlation-id")));
}
public String generateActualName(String rawName) {
protected String generateActualName(String rawName, String timeStamp) {
for (Map.Entry<String, String> tenant : tenantMap.entrySet()) {
rawName = rawName.replaceAll(tenant.getKey(), tenant.getValue());
}
return rawName.replaceAll("<timestamp>", "");
return rawName.replaceAll("<timestamp>", timeStamp);
}
protected String generateActualNameWithTS(String rawName, String timeStamp) {
public String generateActualNameWithoutTs(String rawName) {
for (Map.Entry<String, String> tenant : tenantMap.entrySet()) {
rawName = rawName.replaceAll(tenant.getKey(), tenant.getValue());
}
return rawName.replaceAll("<timestamp>", timeStamp);
return rawName.replaceAll("<timestamp>", "");
}
protected Legal generateLegalTag() {
......
......@@ -31,7 +31,7 @@ public class PersistentSchemaTestIndex extends TestIndex {
this.schemaModel = readSchemaFromJson();
SchemaIdentity schemaIdentity = schemaModel.getSchemaInfo().getSchemaIdentity();
LOGGER.log(Level.INFO, "Read the schema={0}", schemaIdentity);
schemaIdentity.setAuthority(recordSteps.generateActualName(schemaIdentity.getAuthority()));
schemaIdentity.setAuthority(recordSteps.generateActualNameWithoutTs(schemaIdentity.getAuthority()));
LOGGER.log(Level.INFO, "Updated the schema={0}", schemaIdentity);
schemaServiceClient.createIfNotExist(schemaModel);
LOGGER.log(Level.INFO, "Finished setting up the schema={0}", schemaIdentity);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment