Commit 35bfdaca authored by NSarda's avatar NSarda
Browse files

Updated folder structure for schema service

parent 8c97f21e
Pipeline #4814 passed with stages
in 11 minutes and 29 seconds
......@@ -57,10 +57,13 @@ They can then be run/debugged directly in your IDE of choice using the GUI or vi
Below command has to be run post building complete project.
cd testing/schema-test-gcp
mvn verify
cd testing/schema-test-core
mvn verify -DVENDOR=gcp -DHOST=https://open.opendes.cloud.slb-ds.com -DPRIVATE_TENANT1=opendes -DPRIVATE_TENANT2=tenant2 -DSHARED_TENANT=common -Dcucumber.options="--tags @SchemaService"
Below command can be run through azure-pipeline.yml after setting environment variables in the pipeline.
verify "-Dcucumber.options=--tags @SchemaService"
## Deploy Shared Schemas
Schema service as part of deployment deploys pre-defined OSDU schemas so end users can get community accepted schemas to refer. Such schemas are present in [folder](https://dev.azure.com/slb-des-ext-collaboration/open-data-ecosystem/_git/os-schema?path=%2Fdeployments%2Fshared-schemas%2Fosdu) and script to deploy the schema are present [here](https://dev.azure.com/slb-des-ext-collaboration/open-data-ecosystem/_git/os-schema?path=%2Fdeployments%2Fscripts).
......
......@@ -91,8 +91,8 @@ stages:
- task: Maven@3
displayName: 'Running IntegrationTest'
inputs:
mavenPomFile: 'testing/schema-test-gcp/pom.xml'
goals: 'verify'
mavenPomFile: 'testing/schema-test-core/pom.xml'
goals: 'verify "-Dcucumber.options=--tags @SchemaService"'
options: '--settings maven/settings.xml -DVSTS_FEED_TOKEN=$(VSTS_FEED_TOKEN)'
publishJUnitResults: false
javaHomeOption: 'JDKVersion'
......@@ -103,6 +103,12 @@ stages:
env:
INTEGRATION_TEST_AUDIENCE: $(INTEGRATION_TEST_AUDIENCE)
INTEGRATION_TESTER : $(INTEGRATION_TESTER)
PRIVATE_TENANT1 : $(PRIVATE_TENANT1)
PRIVATE_TENANT2 : $(PRIVATE_TENANT2)
SHARED_TENANT : $(SHARED_TENANT)
HOST : $(HOST)
VENDOR : $(VENDOR)
- task: UsePythonVersion@0
inputs:
......
......@@ -9,7 +9,7 @@
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>schema-test-gcp</artifactId>
<artifactId>schema-test-core</artifactId>
<dependencies>
<dependency>
......@@ -117,37 +117,4 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>Default</id>
<properties>
<skipUnitTests>true</skipUnitTests>
<skipItTests>false</skipItTests>
<preIntegrationPhase>pre-integration-test</preIntegrationPhase>
<postIntegrationPhase>post-integration-test</postIntegrationPhase>
<mainClass>org.opengroup.osdu.schema.SchemaApplication</mainClass>
</properties>
</profile>
</profiles>
<repositories>
<repository>
<id>${gitlab-server}</id>
<url>https://community.opengroup.org/api/v4/groups/17/-/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>${gitlab-server}</id>
<url>https://community.opengroup.org/api/v4/projects/26/packages/maven</url>
</repository>
<snapshotRepository>
<id>${gitlab-server}</id>
<url>https://community.opengroup.org/api/v4/projects/26/packages/maven</url>
</snapshotRepository>
</distributionManagement>
</project>
\ No newline at end of file
......@@ -7,7 +7,6 @@ public class TestConstants {
public static final String GET_LIST_ENDPOINT = "/api/schema-service/v1/schema";
public static final String GET_ENDPOINT = "/api/schema-service/v1/schema/";
public static final String GET_FLATTENED_ENDPOINT = "/api/schema-service/v1/schema/{id}/IndexerSchemaV1";
public static final String HOST = "https://open.opendes.cloud.slb-ds.com";
//public static final String HOST = "http://localhost:8080";
public static final String INTERNAL_SERVER_ERROR = "internal server error";
public static final String INTERNAL = "INTERNAL";
......@@ -34,7 +33,6 @@ public class TestConstants {
public static final String DATA_PARTITION_ID = "data-partition-id";
public static final String BEARER = "Bearer ";
public static final String CONTENT_TYPE = "Content-Type";
public static final String TENANT = "opendes";
public static final String JSON_CONTENT = "application/json";
public static final String schemaIdOfInputPayload = "schemaInfo.schemaIdentity.id";
public static final String SCHEMA_IDENTITY = "schemaIdentity";
......@@ -50,4 +48,8 @@ public class TestConstants {
public static final String USER = "user";
public static final String STORAGE_SCHEMA_USER_EMAIL = "testUserEmail@test.com";
public static final String KIND = "kind";
public static final String HOST = System.getProperty("HOST", System.getenv("HOST"));
public static final String PRIVATE_TENANT1 = System.getProperty("PRIVATE_TENANT1", System.getenv("PRIVATE_TENANT1"));
public static final String PRIVATE_TENANT2 = System.getProperty("PRIVATE_TENANT2", System.getenv("PRIVATE_TENANT2"));
public static final String SHARED_TENANT = System.getProperty("SHARED_TENANT", System.getenv("SHARED_TENANT"));
}
......@@ -41,7 +41,7 @@ public class SchemaServiceStepDef_GET implements En {
public SchemaServiceStepDef_GET() {
Given("I generate user token and set request headers", () -> {
Given("I generate user token and set request headers for {string}", (String tenant) -> {
if (this.context.getToken() == null) {
String token = new AuthUtil().getToken();
this.context.setToken(token);
......@@ -50,7 +50,7 @@ public class SchemaServiceStepDef_GET implements En {
if (this.context.getAuthHeaders() == null) {
Map<String, String> authHeaders = new HashMap<String, String>();
authHeaders.put(TestConstants.AUTHORIZATION, this.context.getToken());
authHeaders.put(TestConstants.DATA_PARTITION_ID, TestConstants.TENANT);
authHeaders.put(TestConstants.DATA_PARTITION_ID, selectTenant(tenant));
authHeaders.put(TestConstants.CONTENT_TYPE, TestConstants.JSON_CONTENT);
this.context.setAuthHeaders(authHeaders);
}
......@@ -61,9 +61,9 @@ public class SchemaServiceStepDef_GET implements En {
Map<String, String> queryParams = new HashMap<String, String>();
queryParams.put(parameter, parameterVal);
queryParams.put("latestVersion", latestVersion);
HttpRequest httpRequest = HttpRequest.builder()
.url(TestConstants.HOST + TestConstants.GET_LIST_ENDPOINT).queryParams(queryParams)
.httpMethod(HttpRequest.GET).requestHeaders(this.context.getAuthHeaders()).build();
HttpRequest httpRequest = HttpRequest.builder().url(TestConstants.HOST + TestConstants.GET_LIST_ENDPOINT)
.queryParams(queryParams).httpMethod(HttpRequest.GET)
.requestHeaders(this.context.getAuthHeaders()).build();
HttpResponse response = HttpClientFactory.getInstance().send(httpRequest);
this.context.setHttpResponse(response);
assertEquals("200", String.valueOf(response.getCode()));
......@@ -103,9 +103,9 @@ public class SchemaServiceStepDef_GET implements En {
queryParams.put(TestConstants.LATEST_VERSION, latestVersion);
this.context.setQueryParams(queryParams);
HttpRequest httpRequest = HttpRequest.builder()
.url(TestConstants.HOST + TestConstants.GET_LIST_ENDPOINT).queryParams(queryParams)
.httpMethod(HttpRequest.GET).requestHeaders(this.context.getAuthHeaders()).build();
HttpRequest httpRequest = HttpRequest.builder().url(TestConstants.HOST + TestConstants.GET_LIST_ENDPOINT)
.queryParams(queryParams).httpMethod(HttpRequest.GET)
.requestHeaders(this.context.getAuthHeaders()).build();
HttpResponse response = HttpClientFactory.getInstance().send(httpRequest);
this.context.setHttpResponse(response);
});
......@@ -123,9 +123,8 @@ public class SchemaServiceStepDef_GET implements En {
});
Given("I hit schema service GET API with {string}", (String schemaId) -> {
HttpRequest httpRequest = HttpRequest.builder()
.url(TestConstants.HOST + TestConstants.GET_ENDPOINT + schemaId).httpMethod(HttpRequest.GET)
.requestHeaders(this.context.getAuthHeaders()).build();
HttpRequest httpRequest = HttpRequest.builder().url(TestConstants.HOST + TestConstants.GET_ENDPOINT + schemaId)
.httpMethod(HttpRequest.GET).requestHeaders(this.context.getAuthHeaders()).build();
HttpResponse response = HttpClientFactory.getInstance().send(httpRequest);
this.context.setHttpResponse(response);
});
......@@ -155,8 +154,7 @@ public class SchemaServiceStepDef_GET implements En {
Map<String, String> authHeaders = this.context.getAuthHeaders();
authHeaders.put(TestConstants.DATA_PARTITION_ID, otherTenant);
HttpRequest httpRequest = HttpRequest.builder()
.url(TestConstants.HOST + TestConstants.GET_ENDPOINT
+ this.context.getSchemaIdFromInputPayload())
.url(TestConstants.HOST + TestConstants.GET_ENDPOINT + this.context.getSchemaIdFromInputPayload())
.httpMethod(HttpRequest.GET).requestHeaders(authHeaders).build();
HttpResponse response = HttpClientFactory.getInstance().send(httpRequest);
this.context.setHttpResponse(response);
......@@ -175,8 +173,7 @@ public class SchemaServiceStepDef_GET implements En {
Then("schema service should respond back with {string} and {string}",
(String ReponseStatusCode, String ResponseToBeVerified) -> {
HttpRequest httpRequest = HttpRequest.builder()
.url(TestConstants.HOST + TestConstants.GET_ENDPOINT
+ this.context.getSchemaIdFromInputPayload())
.url(TestConstants.HOST + TestConstants.GET_ENDPOINT + this.context.getSchemaIdFromInputPayload())
.httpMethod(HttpRequest.GET).requestHeaders(this.context.getAuthHeaders()).build();
HttpResponse response = HttpClientFactory.getInstance().send(httpRequest);
assertEquals(ReponseStatusCode, String.valueOf(response.getCode()));
......@@ -194,9 +191,9 @@ public class SchemaServiceStepDef_GET implements En {
Map<String, String> queryParams = new HashMap<String, String>();
queryParams.put(parameter, parameterVal);
HttpRequest httpRequest = HttpRequest.builder()
.url(TestConstants.HOST + TestConstants.GET_LIST_ENDPOINT).queryParams(queryParams)
.httpMethod(HttpRequest.GET).requestHeaders(this.context.getAuthHeaders()).build();
HttpRequest httpRequest = HttpRequest.builder().url(TestConstants.HOST + TestConstants.GET_LIST_ENDPOINT)
.queryParams(queryParams).httpMethod(HttpRequest.GET)
.requestHeaders(this.context.getAuthHeaders()).build();
HttpResponse response = HttpClientFactory.getInstance().send(httpRequest);
this.context.setHttpResponse(response);
});
......@@ -255,9 +252,9 @@ public class SchemaServiceStepDef_GET implements En {
}
this.context.setQueryParams(queryParams);
HttpRequest httpRequest = HttpRequest.builder()
.url(TestConstants.HOST + TestConstants.GET_LIST_ENDPOINT).queryParams(queryParams)
.httpMethod(HttpRequest.GET).requestHeaders(this.context.getAuthHeaders()).build();
HttpRequest httpRequest = HttpRequest.builder().url(TestConstants.HOST + TestConstants.GET_LIST_ENDPOINT)
.queryParams(queryParams).httpMethod(HttpRequest.GET)
.requestHeaders(this.context.getAuthHeaders()).build();
HttpResponse response = HttpClientFactory.getInstance().send(httpRequest);
this.context.setHttpResponse(response);
});
......@@ -392,4 +389,21 @@ public class SchemaServiceStepDef_GET implements En {
verifyResponseJsonElement(key, value, root);
});
}
private String selectTenant(String tenant) {
switch (tenant) {
case "TENANT1":
tenant = TestConstants.PRIVATE_TENANT1;
break;
case "TENANT2":
tenant = TestConstants.PRIVATE_TENANT2;
break;
case "COMMON":
tenant = TestConstants.SHARED_TENANT;
break;
default:
System.out.println("Invalid tenant");
}
return tenant;
}
}
\ No newline at end of file
......@@ -29,7 +29,7 @@ public class SchemaServiceStepDef_POST implements En {
@Inject
private SchemaServiceScope context;
static String[] GetListBaseFilterArray;
static String[] GetListVersionFilterArray;
String queryParameter;
......@@ -41,6 +41,7 @@ public class SchemaServiceStepDef_POST implements En {
Given("I hit schema service POST API with {string} and data-partition-id as {string} only if status is not development",
(String inputPayload, String tenant) -> {
tenant = selectTenant(tenant);
String resp = this.context.getHttpResponse().getBody();
Gson gsn = new Gson();
JsonObject schemaInfosList = gsn.fromJson(resp, JsonObject.class);
......@@ -51,11 +52,11 @@ public class SchemaServiceStepDef_POST implements En {
JsonElement jsonBody = new Gson().fromJson(body, JsonElement.class);
int currentMinorVersion = 0;
int currentMajorVersion = 0;
if(root.size() > 0) {
currentMinorVersion = Integer.parseInt(this.context.getSchemaVersionMinor());
currentMajorVersion = Integer.parseInt(this.context.getSchemaVersionMajor());
if (root.size() > 0) {
currentMinorVersion = Integer.parseInt(this.context.getSchemaVersionMinor());
currentMajorVersion = Integer.parseInt(this.context.getSchemaVersionMajor());
}
int nextMinorVersion = currentMinorVersion + 1;
int nextMajorVersion = currentMajorVersion + 1;
String schemaId = "SchemaSanityTest:testSource:testEntity:" + nextMajorVersion + "."
......@@ -74,8 +75,8 @@ public class SchemaServiceStepDef_POST implements En {
Given("I hit schema service POST API with {string} and data-partition-id as {string}",
(String inputPayload, String tenant) -> {
tenant = selectTenant(tenant);
String body = this.context.getFileUtils().read(inputPayload);
JsonElement jsonBody = new Gson().fromJson(body, JsonElement.class);
int currentMinorVersion = Integer.parseInt(this.context.getSchemaVersionMinor());
int currentMajorVersion = Integer.parseInt(this.context.getSchemaVersionMajor());
......@@ -91,6 +92,7 @@ public class SchemaServiceStepDef_POST implements En {
Given("I hit schema service POST API with {string} and data-partition-id as {string} with increased minor version only",
(String inputPayload, String tenant) -> {
tenant = selectTenant(tenant);
String body = this.context.getFileUtils().read(inputPayload);
JsonElement jsonBody = new Gson().fromJson(body, JsonElement.class);
int currentMinorVersion = Integer.parseInt(this.context.getSchemaVersionMinor());
......@@ -117,6 +119,7 @@ public class SchemaServiceStepDef_POST implements En {
Given("I hit schema service POST API with {string} and data-partition-id as {string} without increasing any version",
(String inputPayload, String tenant) -> {
tenant = selectTenant(tenant);
String body = this.context.getFileUtils().read(inputPayload);
JsonElement jsonBody = new Gson().fromJson(body, JsonElement.class);
int currentMinorVersion = Integer.parseInt(this.context.getSchemaVersionMinor());
......@@ -148,9 +151,7 @@ public class SchemaServiceStepDef_POST implements En {
HttpResponse response = this.context.getHttpResponse();
if (response != null) {
assertEquals(ReponseStatusCode, String.valueOf(response.getCode()));
commonAssertion(response, jsonBody);
Assert.assertNotNull(jsonBody.get(TestConstants.DATE_CREATED));
Assert.assertNotNull(jsonBody.get(TestConstants.CREATED_BY));
}
......@@ -217,7 +218,7 @@ public class SchemaServiceStepDef_POST implements En {
Given("I hit schema service POST API for supersededBy with {string} and data-partition-id as {string}",
(String inputPayload, String tenant) -> {
tenant = selectTenant(tenant);
String body = this.context.getFileUtils().read(inputPayload);
JsonElement jsonBody = new Gson().fromJson(body, JsonElement.class);
......@@ -262,7 +263,7 @@ public class SchemaServiceStepDef_POST implements En {
this.context.getSupersededById());
}
});
});
}
private HttpResponse postRequest(JsonElement jsonBody, String schemaId, String tenant) {
......@@ -275,7 +276,6 @@ public class SchemaServiceStepDef_POST implements En {
HttpRequest httpRequest = HttpRequest.builder().url(TestConstants.HOST + TestConstants.POST_ENDPOINT)
.body(jsonBody.toString()).httpMethod(HttpRequest.POST).requestHeaders(headers).build();
HttpResponse response = HttpClientFactory.getInstance().send(httpRequest);
return response;
}
......@@ -349,4 +349,22 @@ public class SchemaServiceStepDef_POST implements En {
this.context
.setSchemaVersionMinor(schemaIdentity_ForEachSchemaIdentity.get("schemaVersionMinor").getAsString());
}
private String selectTenant(String tenant) {
switch (tenant) {
case "TENANT1":
tenant = TestConstants.PRIVATE_TENANT1;
break;
case "TENANT2":
tenant = TestConstants.PRIVATE_TENANT2;
break;
case "COMMON":
tenant = TestConstants.SHARED_TENANT;
break;
default:
System.out.println("Invalid tenant");
}
return tenant;
}
}
\ No newline at end of file
......@@ -43,7 +43,7 @@ public class SchemaServiceStepDef_PUT implements En {
Given("I hit schema service PUT API with {string}, data-partition-id as {string} and mark schema as {string}.",
(String inputPayload, String tenant, String status) -> {
tenant = selectTenant(tenant);
String body = this.context.getFileUtils().read(inputPayload);
JsonElement jsonBody = new Gson().fromJson(body, JsonElement.class);
int currentMinorVersion = Integer.parseInt(this.context.getSchemaVersionMinor());
......@@ -67,7 +67,7 @@ public class SchemaServiceStepDef_PUT implements En {
Given("I hit schema service PUT API with {string}, data-partition-id as {string} and mark schema as {string} for next major version",
(String inputPayload, String tenant, String status) -> {
tenant = selectTenant(tenant);
String body = this.context.getFileUtils().read(inputPayload);
JsonElement jsonBody = new Gson().fromJson(body, JsonElement.class);
int currentMinorVersion = Integer.parseInt(this.context.getSchemaVersionMinor());
......@@ -92,7 +92,7 @@ public class SchemaServiceStepDef_PUT implements En {
Given("I hit schema service PUT API with {string}, data-partition-id as {string}",
(String inputPayload, String tenant) -> {
tenant = selectTenant(tenant);
String body = this.context.getFileUtils().read(inputPayload);
JsonElement jsonBody = new Gson().fromJson(body, JsonElement.class);
int currentMinorVersion = Integer.parseInt(this.context.getSchemaVersionMinor());
......@@ -113,6 +113,7 @@ public class SchemaServiceStepDef_PUT implements En {
Given("I hit schema service PUT API with {string}, data-partition-id as {string} for superceded input",
(String inputPayload, String tenant) -> {
tenant = selectTenant(tenant);
String body = this.context.getFileUtils().read(inputPayload);
JsonElement jsonBody = new Gson().fromJson(body, JsonElement.class);
int currentMinorVersion = Integer.parseInt(this.context.getSchemaVersionMinor());
......@@ -136,7 +137,7 @@ public class SchemaServiceStepDef_PUT implements En {
Given("I hit schema service PUT API with {string}, data-partition-id as {string} with increased minor version only",
(String inputPayload, String tenant) -> {
tenant = selectTenant(tenant);
String body = this.context.getFileUtils().read(inputPayload);
JsonElement jsonBody = new Gson().fromJson(body, JsonElement.class);
int currentMinorVersion = Integer.parseInt(this.context.getSchemaVersionMinor());
......@@ -158,7 +159,7 @@ public class SchemaServiceStepDef_PUT implements En {
Given("I hit schema service PUT API with {string}, data-partition-id as {string} with different entityType",
(String inputPayload, String tenant) -> {
tenant = selectTenant(tenant);
String body = this.context.getFileUtils().read(inputPayload);
JsonElement jsonBody = new Gson().fromJson(body, JsonElement.class);
int currentMinorVersion = Integer.parseInt(this.context.getSchemaVersionMinor());
......@@ -185,7 +186,7 @@ public class SchemaServiceStepDef_PUT implements En {
Given("I hit schema service PUT API with {string}, data-partition-id as {string} with next major version",
(String inputPayload, String tenant) -> {
tenant = selectTenant(tenant);
String body = this.context.getFileUtils().read(inputPayload);
JsonElement jsonBody = new Gson().fromJson(body, JsonElement.class);
int currentMinorVersion = Integer.parseInt(this.context.getSchemaVersionMinor());
......@@ -230,7 +231,7 @@ public class SchemaServiceStepDef_PUT implements En {
Given("I hit schema service PUT API for supersededBy with {string} and data-partition-id as {string}",
(String inputPayload, String tenant) -> {
tenant = selectTenant(tenant);
String body = this.context.getFileUtils().read(inputPayload);
JsonElement jsonBody = new Gson().fromJson(body, JsonElement.class);
......@@ -340,4 +341,22 @@ public class SchemaServiceStepDef_PUT implements En {
jsonBody.getAsJsonObject().getAsJsonObject("schemaInfo").getAsJsonObject(TestConstants.SUPERSEDED_BY)
.addProperty(TestConstants.SCHEMA_PATCH_VERSION, patchVersion);
}
private String selectTenant(String tenant) {
switch (tenant) {
case "TENANT1":
tenant = TestConstants.PRIVATE_TENANT1;
break;
case "TENANT2":
tenant = TestConstants.PRIVATE_TENANT2;
break;
case "COMMON":
tenant = TestConstants.SHARED_TENANT;
break;
default:
System.out.println("Invalid tenant");
}
return tenant;
}
}
\ No newline at end of file
......@@ -3,14 +3,22 @@ package org.opengroup.osdu.schema.util;
import com.google.common.base.Strings;
public class AuthUtil {
public synchronized String getToken() throws Exception {
public synchronized String getToken() throws Exception {
String token = null;
if (Strings.isNullOrEmpty(token)) {
String serviceAccountFile = System.getProperty("INTEGRATION_TESTER", System.getenv("INTEGRATION_TESTER"));
String vendor = System.getProperty("VENDOR", System.getenv("VENDOR"));
if (Strings.isNullOrEmpty(token) && vendor.equals("gcp")) {
String serviceAccountFile = System.getProperty("INTEGRATION_TESTER", System.getenv("INTEGRATION_TESTER"));
String audience = System.getProperty("INTEGRATION_TEST_AUDIENCE",
System.getenv("INTEGRATION_TEST_AUDIENCE"));
token = new GoogleServiceAccount(serviceAccountFile).getAuthToken(audience);
}
}else if (Strings.isNullOrEmpty(token) && vendor.equals("aws")) {
System.out.println("Token generation code for aws comes here");
} else if (Strings.isNullOrEmpty(token) && vendor.equals("azure")) {
System.out.println("Token generation code for azure comes here");
} else if (Strings.isNullOrEmpty(token) && vendor.equals("ibm")) {
System.out.println("Token generation code for ibm comes here");
}
System.out.println("Bearer " + token);
return "Bearer " + token;
}
}
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