Skip to content
Snippets Groups Projects

Fix: refactoring tests

Merged Susie Lin requested to merge fix-integ-tests into master
2 files
+ 17
18
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -19,7 +19,9 @@ import static org.junit.Assert.assertTrue;
import com.amazonaws.services.sqs.model.Message;
import org.opengroup.osdu.core.common.http.json.HttpResponseBodyMapper;
import org.opengroup.osdu.core.common.model.indexer.OperationType;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.storage.PubSubInfo;
import org.opengroup.osdu.core.common.model.storage.Record;
import org.opengroup.osdu.core.common.model.storage.StorageException;
import org.opengroup.osdu.core.common.storage.IStorageService;
@@ -34,37 +36,33 @@ import java.util.List;
public class StorageTestUtils {
private final IStorageService storageService;
private final HashSet<String> allowedOps = new HashSet<>();
private final HashSet<OperationType> allowedOps = new HashSet<>();
public StorageTestUtils(DpsHeaders headers, HttpResponseBodyMapper mapper) {
StorageAPIConfig config = StorageAPIConfig.builder().rootUrl(Config.Instance().StorageServicePath).build();
StorageFactory subscriptionFactory = new StorageFactory(config, mapper);
storageService = subscriptionFactory.create(headers);
allowedOps.add("create");
allowedOps.add("delete");
allowedOps.add(OperationType.create);
allowedOps.add(OperationType.delete);
}
protected static final String PERSISTABLE_REFERENCE = "%7B%22LB_CRS%22%3A%22%257B%2522WKT%2522%253A%2522PROJCS%255B%255C%2522British_National_Grid%255C%2522%252CGEOGCS%255B%255C%2522GCS_OSGB_1936%255C%2522%252CDATUM%255B%255C%2522D_OSGB_1936%255C%2522%252CSPHEROID%255B%255C%2522Airy_1830%255C%2522%252C6377563.396%252C299.3249646%255D%255D%252CPRIMEM%255B%255C%2522Greenwich%255C%2522%252C0.0%255D%252CUNIT%255B%255C%2522Degree%255C%2522%252C0.0174532925199433%255D%255D%252CPROJECTION%255B%255C%2522Transverse_Mercator%255C%2522%255D%252CPARAMETER%255B%255C%2522False_Easting%255C%2522%252C400000.0%255D%252CPARAMETER%255B%255C%2522False_Northing%255C%2522%252C-100000.0%255D%252CPARAMETER%255B%255C%2522Central_Meridian%255C%2522%252C-2.0%255D%252CPARAMETER%255B%255C%2522Scale_Factor%255C%2522%252C0.9996012717%255D%252CPARAMETER%255B%255C%2522Latitude_Of_Origin%255C%2522%252C49.0%255D%252CUNIT%255B%255C%2522Meter%255C%2522%252C1.0%255D%252CAUTHORITY%255B%255C%2522EPSG%255C%2522%252C27700%255D%255D%2522%252C%2522Type%2522%253A%2522LBCRS%2522%252C%2522EngineVersion%2522%253A%2522PE_10_3_1%2522%252C%2522AuthorityCode%2522%253A%257B%2522Authority%2522%253A%2522EPSG%2522%252C%2522Code%2522%253A%252227700%2522%257D%252C%2522Name%2522%253A%2522British_National_Grid%2522%257D%22%2C%22TRF%22%3A%22%257B%2522WKT%2522%253A%2522GEOGTRAN%255B%255C%2522OSGB_1936_To_WGS_1984_Petroleum%255C%2522%252CGEOGCS%255B%255C%2522GCS_OSGB_1936%255C%2522%252CDATUM%255B%255C%2522D_OSGB_1936%255C%2522%252CSPHEROID%255B%255C%2522Airy_1830%255C%2522%252C6377563.396%252C299.3249646%255D%255D%252CPRIMEM%255B%255C%2522Greenwich%255C%2522%252C0.0%255D%252CUNIT%255B%255C%2522Degree%255C%2522%252C0.0174532925199433%255D%255D%252CGEOGCS%255B%255C%2522GCS_WGS_1984%255C%2522%252CDATUM%255B%255C%2522D_WGS_1984%255C%2522%252CSPHEROID%255B%255C%2522WGS_1984%255C%2522%252C6378137.0%252C298.257223563%255D%255D%252CPRIMEM%255B%255C%2522Greenwich%255C%2522%252C0.0%255D%252CUNIT%255B%255C%2522Degree%255C%2522%252C0.0174532925199433%255D%255D%252CMETHOD%255B%255C%2522Position_Vector%255C%2522%255D%252CPARAMETER%255B%255C%2522X_Axis_Translation%255C%2522%252C446.448%255D%252CPARAMETER%255B%255C%2522Y_Axis_Translation%255C%2522%252C-125.157%255D%252CPARAMETER%255B%255C%2522Z_Axis_Translation%255C%2522%252C542.06%255D%252CPARAMETER%255B%255C%2522X_Axis_Rotation%255C%2522%252C0.15%255D%252CPARAMETER%255B%255C%2522Y_Axis_Rotation%255C%2522%252C0.247%255D%252CPARAMETER%255B%255C%2522Z_Axis_Rotation%255C%2522%252C0.842%255D%252CPARAMETER%255B%255C%2522Scale_Difference%255C%2522%252C-20.489%255D%252CAUTHORITY%255B%255C%2522EPSG%255C%2522%252C1314%255D%255D%2522%252C%2522Type%2522%253A%2522STRF%2522%252C%2522EngineVersion%2522%253A%2522PE_10_3_1%2522%252C%2522AuthorityCode%2522%253A%257B%2522Authority%2522%253A%2522EPSG%2522%252C%2522Code%2522%253A%25221314%2522%257D%252C%2522Name%2522%253A%2522OSGB_1936_To_WGS_1984_Petroleum%2522%257D%22%2C%22Type%22%3A%22EBCRS%22%2C%22EngineVersion%22%3A%22PE_10_3_1%22%2C%22Name%22%3A%22OSGB+1936+*+UKOOA-Pet+%2F+British+National+Grid+%5B27700%2C1314%5D%22%2C%22AuthorityCode%22%3A%7B%22Authority%22%3A%22MyCompany%22%2C%22Code%22%3A%2227700006%22%7D%7D";
private static final String RECORD_ID_PREFIX_TEST = TenantUtils.getTenantName(true) + ":query:";
private static final long NOW = System.currentTimeMillis();
private static final String KIND_TEST = TenantUtils.getTenantName(true) + ":ds:query:1.0." + NOW;
public StorageMessage createAndPutRecord(String correlationId, String legalTag) throws StorageException {
public PubSubInfo createAndPutRecord(String correlationId, String legalTag) throws StorageException {
String recordId = RECORD_ID_PREFIX_TEST + correlationId;
Record[] records = RecordUtils.createRecordsWithReference(1, recordId, KIND_TEST, legalTag, PERSISTABLE_REFERENCE, "CRS", true);
storageService.upsertRecord(records);
// We append the index in RecordUtils to ensure the IDs are unique. Maybe we don't need to do that.
return new StorageMessage(records[0].getId(), KIND_TEST, "create");
return PubSubInfo.builder().id(records[0].getId()).kind(KIND_TEST).op(OperationType.create).build();
}
public void assertFirstMessagesSimilar(StorageMessage expected, List<Message> receivedMessages) throws Exception {
public void assertFirstMessagesSimilar(PubSubInfo expected, List<Message> receivedMessages) throws Exception {
System.out.printf("Total received messages: %d\n", receivedMessages.size());
StorageMessage actual = AwsTestUtils.unwrapFirst(receivedMessages, StorageMessage[].class);
assertTrue("Expect the op to be in the \"created\" or \"deleted\" set.", allowedOps.contains(actual.op()));
assertEquals(expected.kind(), actual.kind());
assertEquals(expected.id(), actual.id());
PubSubInfo actual = AwsTestUtils.unwrapFirst(receivedMessages, PubSubInfo[].class);
assertTrue("Expect the op to be in the \"created\" or \"deleted\" set.", allowedOps.contains(actual.getOp()));
assertEquals(expected.getKind(), actual.getKind());
assertEquals(expected.getId(), actual.getId());
}
}
record StorageMessage(String id, String kind, String op) {
}
Loading