Commit 8f6bdbeb authored by Rustam Lotsmanenko (EPAM)'s avatar Rustam Lotsmanenko (EPAM)
Browse files

test transaction

parent 4af2084d
Pipeline #121123 failed with stages
in 113 minutes and 53 seconds
......@@ -92,10 +92,21 @@
</parent>
<dependencies>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>osm</artifactId>
<version>0.16.0-test-transaction</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-gcp</artifactId>
<version>0.15.0-rc3</version>
<exclusions>
<exclusion>
<groupId>org.opengroup.osdu</groupId>
<artifactId>osm</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
......
......@@ -14,27 +14,11 @@
package org.opengroup.osdu.storage.query;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.sun.jersey.api.client.ClientResponse;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.http.HttpStatus;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.opengroup.osdu.storage.util.AnthosTestUtils;
import org.opengroup.osdu.storage.util.DummyRecordsHelper;
import org.opengroup.osdu.storage.util.DummyRecordsHelper.RecordStatusMock;
import org.opengroup.osdu.storage.util.HeaderUtils;
import org.opengroup.osdu.storage.util.RecordUtil;
import org.opengroup.osdu.storage.util.TenantUtils;
import org.opengroup.osdu.storage.util.TestUtils;
public class TestPostFetchRecordsIntegration extends PostFetchRecordsIntegrationTests {
......@@ -61,46 +45,4 @@ public class TestPostFetchRecordsIntegration extends PostFetchRecordsIntegration
public void tearDown() throws Exception {
this.testUtils = null;
}
//TODO Override due to instability at anthos env, the core test fails if there is no time out between record creating and querying it
@Override
public void should_returnOriginalRecordsAndConversionStatusAsNoMeta_whenConversionRequiredAndNoMetaBlockInRecord() throws Exception {
String recordId = RECORD_ID_PREFIX + UUID.randomUUID().toString();
String jsonInput = RecordUtil.createJsonRecordNoMetaBlock(2, recordId, KIND, LEGAL_TAG);
ClientResponse
createResponse = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), jsonInput, "");
assertEquals(201, createResponse.getStatus());
JsonArray records = new JsonArray();
records.add(recordId + 0);
records.add(recordId + 1);
records.add("nonexisting:id");
JsonObject body = new JsonObject();
body.add("records", records);
Map<String, String> headers = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken());
headers.put("frame-of-reference", "units=SI;crs=wgs84;elevation=msl;azimuth=true north;dates=utc;");
//Without timeout, test may fail from time to time
Thread.sleep(300);
ClientResponse response = TestUtils.send("query/records:batch", "POST", headers, body.toString(),
"");
assertEquals(HttpStatus.SC_OK, response.getStatus());
DummyRecordsHelper.ConvertedRecordsMock responseObject = RECORDS_HELPER.getConvertedRecordsMockFromResponse(response);
assertEquals(2, responseObject.records.length);
assertEquals(1, responseObject.notFound.length);
assertEquals(2, responseObject.conversionStatuses.size());
assertEquals("nonexisting:id", responseObject.notFound[0]);
assertEquals(KIND, responseObject.records[0].kind);
assertTrue(responseObject.records[0].version != null && !responseObject.records[0].version.isEmpty());
assertEquals(3, responseObject.records[0].data.size());
List<RecordStatusMock> conversionStatuses = responseObject.conversionStatuses;
assertEquals("CRS Conversion: Meta Block is missing or empty in this record, no conversion applied.", conversionStatuses.get(0).errors.get(0));
ClientResponse deleteResponse1 = TestUtils.send("records/" + recordId + 0, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "");
assertEquals(204, deleteResponse1.getStatus());
ClientResponse deleteResponse2 = TestUtils.send("records/" + recordId + 1, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "");
assertEquals(204, deleteResponse2.getStatus());
}
}
......@@ -14,33 +14,12 @@
package org.opengroup.osdu.storage.records;
import static org.junit.Assert.assertEquals;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.sun.jersey.api.client.ClientResponse;
import java.util.Map;
import org.apache.http.HttpStatus;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.storage.util.AnthosTestUtils;
import org.opengroup.osdu.storage.util.DummyRecordsHelper;
import org.opengroup.osdu.storage.util.HeaderUtils;
import org.opengroup.osdu.storage.util.LegalTagUtils;
import org.opengroup.osdu.storage.util.RecordUtil;
import org.opengroup.osdu.storage.util.TenantUtils;
import org.opengroup.osdu.storage.util.TestUtils;
public class TestUpdateRecordsMetadata extends UpdateRecordsMetadataTest {
private static long NOW = System.currentTimeMillis();
private static String KIND = TenantUtils.getFirstTenantName() + ":bulkupdate:test:1.1." + NOW;
private static String LEGAL_TAG_3 = LegalTagUtils.createRandomName() + "3";
private static String LEGAL_TAG_4 = LegalTagUtils.createRandomName() + "4";
private static String RECORD_ID_3 = TenantUtils.getFirstTenantName() + ":test:1.3." + NOW;
private static String RECORD_ID_4 = TenantUtils.getFirstTenantName() + ":test:1.4." + NOW;
private static final DummyRecordsHelper RECORDS_HELPER = new DummyRecordsHelper();
@Before
@Override
public void setup() throws Exception {
......@@ -54,88 +33,4 @@ public class TestUpdateRecordsMetadata extends UpdateRecordsMetadataTest {
super.tearDown();
this.testUtils = null;
}
//TODO Override due to instability at anthos env, the core test fails if there is no time out between record creating and querying it
@Override
public void should_return206andUpdateMetadata_whenOneRecordProvided() throws Exception {
createRecords();
//1. query 2 records, check the acls
JsonArray records = new JsonArray();
records.add(RECORD_ID_3);
records.add(RECORD_ID_4);
JsonObject queryBody = new JsonObject();
queryBody.add("records", records);
Map<String, String> queryHeader = HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken());
queryHeader.put("slb-frame-of-reference", "none");
//Without timeout, test may fail from time to time
Thread.sleep(300);
ClientResponse queryResponse1 = TestUtils.send("query/records:batch", "POST", queryHeader, queryBody.toString(),
"");
assertEquals(HttpStatus.SC_OK, queryResponse1.getStatus());
DummyRecordsHelper.ConvertedRecordsMock queryResponseObject1 = RECORDS_HELPER.getConvertedRecordsMockFromResponse(queryResponse1);
assertEquals(2, queryResponseObject1.records.length);
assertEquals(TestUtils.getAcl(), queryResponseObject1.records[0].acl.viewers[0]);
assertEquals(TestUtils.getAcl(), queryResponseObject1.records[0].acl.owners[0]);
//2. bulk update requests, change acls
JsonArray value = new JsonArray();
value.add(TestUtils.getIntegrationTesterAcl());
JsonObject op1 = new JsonObject();
op1.addProperty("op", "replace");
op1.addProperty("path", "/acl/viewers");
op1.add("value", value);
JsonObject op2 = new JsonObject();
op2.addProperty("op", "replace");
op2.addProperty("path", "/acl/owners");
op2.add("value", value);
JsonArray ops = new JsonArray();
ops.add(op1);
ops.add(op2);
JsonArray records2 = new JsonArray();
records2.add(RECORD_ID_3);
records2.add(RECORD_ID_4);
records2.add(TenantUtils.getFirstTenantName() + ":not:found");
JsonObject query = new JsonObject();
query.add("ids", records2);
JsonObject updateBody = new JsonObject();
updateBody.add("query", query);
updateBody.add("ops", ops);
ClientResponse bulkUpdateResponse =
TestUtils.send("records", "PATCH", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), updateBody.toString(),
"");
assertEquals(HttpStatus.SC_PARTIAL_CONTENT, bulkUpdateResponse.getStatus());
//Without timeout, test may fail from time to time
Thread.sleep(300);
//3. query 2 records again, check acls
ClientResponse queryResponse2 = TestUtils.send("query/records:batch", "POST", queryHeader, queryBody.toString(),
"");
assertEquals(HttpStatus.SC_OK, queryResponse2.getStatus());
DummyRecordsHelper.ConvertedRecordsMock queryResponseObject2 = RECORDS_HELPER.getConvertedRecordsMockFromResponse(queryResponse2);
assertEquals(2, queryResponseObject2.records.length);
assertEquals(TestUtils.getIntegrationTesterAcl(), queryResponseObject2.records[0].acl.viewers[0]);
assertEquals(TestUtils.getIntegrationTesterAcl(), queryResponseObject2.records[0].acl.owners[0]);
deleteRecords();
}
private void deleteRecords() throws Exception {
TestUtils.send("records/" + RECORD_ID_3, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "");
TestUtils.send("records/" + RECORD_ID_4, "DELETE", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()), "", "");
}
private void createRecords() throws Exception {
ClientResponse response3 = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()),
RecordUtil.createDefaultJsonRecord(RECORD_ID_3, KIND, LEGAL_TAG_3), "");
ClientResponse response4 = TestUtils.send("records", "PUT", HeaderUtils.getHeaders(TenantUtils.getTenantName(), testUtils.getToken()),
RecordUtil.createDefaultJsonRecord(RECORD_ID_4, KIND, LEGAL_TAG_4), "");
assertEquals(HttpStatus.SC_CREATED, response3.getStatus());
assertEquals(HttpStatus.SC_CREATED, response4.getStatus());
}
}
Supports Markdown
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