Skip to content
Snippets Groups Projects
Commit d4aaa0bb authored by Deepa Kumari's avatar Deepa Kumari
Browse files

Merge branch 'dk/az-int-tests' into 'master'

Fix Azure integration tests

See merge request !469
parents 7ea8f23b b42ad6f4
No related branches found
No related tags found
1 merge request!469Fix Azure integration tests
Pipeline #177363 failed
Showing
with 4 additions and 1209 deletions
......@@ -344,7 +344,7 @@ The following software have components provided under the terms of this license:
- GSON extensions to the Google HTTP Client Library for Java. (from https://repo1.maven.org/maven2/com/google/http-client/google-http-client-gson)
- Google APIs Client Library for Java (from https://repo1.maven.org/maven2/com/google/api-client/google-api-client)
- Google App Engine extensions to the Google HTTP Client Library for Java. (from https://repo1.maven.org/maven2/com/google/http-client/google-http-client-appengine)
- Google Cloud Core (from https://github.com/googleapis/google-cloud-java, https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core, https://github.com/googleapis/java-core)
- Google Cloud Core (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core, https://github.com/googleapis/java-core, https://repo1.maven.org/maven2/com/google/cloud/google-cloud-core)
- Google Cloud Core HTTP (from https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http, https://github.com/googleapis/google-cloud-java, https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http, https://github.com/googleapis/java-core)
- Google Cloud Core gRPC (from https://github.com/googleapis/google-cloud-java, https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc, https://github.com/googleapis/java-core)
- Google Cloud Datastore (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-datastore, https://github.com/googleapis/java-datastore)
......@@ -613,7 +613,6 @@ The following software have components provided under the terms of this license:
- PostgreSQL JDBC Driver
- Protocol Buffer Java API (from http://code.google.com/p/protobuf, https://repo1.maven.org/maven2/com/google/protobuf/protobuf-java)
- Protocol Buffers [Util] (from https://repo1.maven.org/maven2/com/google/protobuf/protobuf-java-util)
- SnakeYAML (from http://code.google.com/p/snakeyaml/, http://www.snakeyaml.org, https://bitbucket.org/snakeyaml/snakeyaml)
- Spring Core (from http://www.springframework.org, https://github.com/spring-projects/spring-framework, https://repo1.maven.org/maven2/org/springframework/spring-core)
- ThreeTen backport (from https://github.com/ThreeTen/threetenbp, https://www.threeten.org/threetenbp)
- google (from http://breakingcode.wordpress.com/)
......@@ -721,7 +720,6 @@ The following software have components provided under the terms of this license:
- Microsoft Application Insights Java SDK Spring Boot starter (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Web Module (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Log4j 2 Appender (from https://github.com/Microsoft/ApplicationInsights-Java)
- SnakeYAML (from http://code.google.com/p/snakeyaml/, http://www.snakeyaml.org, https://bitbucket.org/snakeyaml/snakeyaml)
========================================================================
EPL-2.0
......@@ -754,13 +752,6 @@ The following software have components provided under the terms of this license:
- RabbitMQ Java Client (from http://www.rabbitmq.com, https://www.rabbitmq.com)
- tomcat-embed-core (from http://tomcat.apache.org/)
========================================================================
GPL-2.0-or-later
========================================================================
The following software have components provided under the terms of this license:
- SnakeYAML (from http://code.google.com/p/snakeyaml/, http://www.snakeyaml.org, https://bitbucket.org/snakeyaml/snakeyaml)
========================================================================
GPL-2.0-with-classpath-exception
========================================================================
......@@ -835,7 +826,6 @@ The following software have components provided under the terms of this license:
- Java Native Access (from https://github.com/java-native-access/jna, https://github.com/twall/jna)
- Java Native Access Platform (from https://github.com/java-native-access/jna)
- Javassist (from http://www.javassist.org/)
- SnakeYAML (from http://code.google.com/p/snakeyaml/, http://www.snakeyaml.org, https://bitbucket.org/snakeyaml/snakeyaml)
========================================================================
MIT
......
......@@ -10,160 +10,7 @@
<artifactId>schema-test-azure</artifactId>
<version>0.21.0-SNAPSHOT</version>
<properties>
<os-core-lib-ibm.version>0.7.0</os-core-lib-ibm.version>
<os-core-lib-azure.version>0.6.1</os-core-lib-azure.version>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-schema-core</artifactId>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
</exclusion>
</exclusions>
<version>0.21.0-SNAPSHOT</version>
</dependency>
<!--Rest assured dependency to be placed before JUnit dependency -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-guice</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>1.76.0</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-azure</artifactId>
<version>${os-core-lib-azure.version}</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu.core.aws</groupId>
<artifactId>os-core-lib-aws</artifactId>
<version>0.3.16</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-lib-ibm</artifactId>
<version>${os-core-lib-ibm.version}</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<!-- Inherit managed dependencies from core-lib-azure -->
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-azure</artifactId>
<version>${os-core-lib-azure.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<skipTests>${skipItTests}</skipTests>
<includes>
<include>org.opengroup.osdu.schema.runner.PreIntegrationTestsRunner</include>
</includes>
</configuration>
</execution>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<skipTests>${skipItTests}</skipTests>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>org.opengroup.osdu.schema.runner.SchemaServiceTestsRunner</include>
</includes>
</configuration>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<skipTests>${skipItTests}</skipTests>
<includes>
<include>org.opengroup.osdu.schema.runner.TearDownTestsRunner</include>
</includes>
</configuration>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<packaging>jar</packaging>
<name>schema-test-azure</name>
<description>Azure integration tests for schema service</description>
</project>
package org.opengroup.osdu.schema.constants;
public class HttpConnection {
public static final boolean FOLLOW_REDIRECTS = true;
public static final int CONNECTION_TIMEOUT_IN_MILLISECONDS = 80000;
public static final String HTTP_SOCKET_TIMEOUT = "http.socket.timeout";
public static final String HTTP_CONNECTION_TIMEOUT = "http.connection.timeout";
public static final String CONTENT_TYPE = "Content-Type";
public static final String APPLICATION_JSON = "application/json";
}
package org.opengroup.osdu.schema.constants;
public class TestConstants {
public static final String FORWARD_SLASH = "/";
public static final String PUT_ENDPOINT = "/api/schema-service/v1/schemas/system";
public static final String POST_ENDPOINT = "/api/schema-service/v1/schema";
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 GET_INFO_ENDPOINT = "/api/schema-service/v1/info";
//public static final String HOST = "http://localhost:8080";
public static final String INTERNAL_SERVER_ERROR = "internal server error";
public static final String INTERNAL = "INTERNAL";
public static final String SCHEMA_KIND = "schema";
public static final String AUTHORITY = "authority";
public static final String LATEST_VERSION = "latestVersion";
public static final String GET_SUCCESSRESPONSECODE = "200";
public static final String SOURCE = "source";
public static final String ENTITY_TYPE = "entityType";
public static final String MAJOR_VERSION = "majorVersion";
public static final String MINOR_VERSION = "minorVersion";
public static final String PATCH_VERSION = "patchVersion";
public static final String CREATED_BY = "createdBy";
public static final String SUPERSEDED_BY = "supersededBy";
public static final String DATE_CREATED = "dateCreated";
public static final String SCHEMA = "schema";
public static final String OBSOLETE = "OBSOLETE";
public static final String PUBLISHED = "PUBLISHED";
public static final String SCOPE = "scope";
public static final String STATUS = "status";
public static final String ALREADY_EXISTS = "ALREADY_EXISTS";
public static final String DATAECOSYSTEM = "dataecosystem";
public static final String AUTHORIZATION = "authorization";
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 JSON_CONTENT = "application/json";
public static final String schemaIdOfInputPayload = "schemaInfo.schemaIdentity.id";
public static final String SCHEMA_IDENTITY = "schemaIdentity";
public static final String ENTITY = "entityType";
public static final String SCHEMA_MAJOR_VERSION = "schemaVersionMajor";
public static final String SCHEMA_MINOR_VERSION = "schemaVersionMinor";
public static final String SCHEMA_PATCH_VERSION = "schemaVersionPatch";
public static final String ID = "id";
public static final String DOT = ".";
public static final String ERROR = "error";
public static final String MESSAGE = "message";
public static final String STORAGE_SCHEMA = "StorageSchema";
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 TRUE = "true";
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"));
public static final String SYSTEM_TENANT = System.getProperty("SYSTEM_TENANT", System.getenv("SYSTEM_TENANT"));
}
package org.opengroup.osdu.schema.runner;
import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
@RunWith(Cucumber.class)
@CucumberOptions(features = "classpath:features", glue = { "classpath:org.opengroup.osdu.schema.stepdefs" }, tags = {
"@Startup" }, plugin = { "pretty", "junit:target/cucumber-reports/schema-service-test-report.xml" })
public class PreIntegrationTestsRunner {
}
\ No newline at end of file
package org.opengroup.osdu.schema.runner;
import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
@RunWith(Cucumber.class)
@CucumberOptions(features = "classpath:features", glue = { "classpath:org.opengroup.osdu.schema.stepdefs" }, tags = {
"@SchemaServiceAzure" }, plugin = { "pretty", "junit:target/cucumber-reports/schema-service-test-report.xml" })
public class SchemaServiceTestsRunner {
}
package org.opengroup.osdu.schema.runner;
import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
@RunWith(Cucumber.class)
@CucumberOptions(features = "classpath:features", glue = { "classpath:org.opengroup.osdu.schema.stepdefs" }, tags = {
"@TearDown" }, plugin = { "pretty", "junit:target/cucumber-reports/schema-service-test-report.xml" })
public class TearDownTestsRunner {
}
package org.opengroup.osdu.schema.stepdefs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import com.google.inject.Inject;
import io.cucumber.java8.En;
import org.opengroup.osdu.schema.constants.TestConstants;
import org.opengroup.osdu.schema.stepdefs.model.HttpRequest;
import org.opengroup.osdu.schema.stepdefs.model.HttpResponse;
import org.opengroup.osdu.schema.stepdefs.model.SchemaServiceScope;
import org.opengroup.osdu.schema.util.HttpClientFactory;
import org.opengroup.osdu.schema.util.VersionInfoUtils;
public class InfoStepDef_GET implements En {
@Inject
private SchemaServiceScope context;
private VersionInfoUtils versionInfoUtil = new VersionInfoUtils();
public InfoStepDef_GET() {
Given("I send get request to version info endpoint", () -> {
HttpRequest httpRequest = HttpRequest.builder()
.url(TestConstants.HOST + TestConstants.GET_INFO_ENDPOINT)
.httpMethod(HttpRequest.GET)
.build();
HttpResponse response = HttpClientFactory.getInstance().send(httpRequest);
this.context.setHttpResponse(response);
});
Then("service should respond back with version info in response", () -> {
assertEquals(200, this.context.getHttpResponse().getCode());
VersionInfoUtils.VersionInfo responseObject = this.versionInfoUtil
.getVersionInfoFromResponse(this.context.getHttpResponse());
assertNotNull(responseObject.groupId);
assertNotNull(responseObject.artifactId);
assertNotNull(responseObject.version);
assertNotNull(responseObject.buildTime);
assertNotNull(responseObject.branch);
assertNotNull(responseObject.commitId);
assertNotNull(responseObject.commitMessage);
});
}
}
package org.opengroup.osdu.schema.stepdefs;
import io.cucumber.java8.En;
import lombok.extern.java.Log;
@Log
public class LocalSetupStepDef implements En {
public LocalSetupStepDef() {
}
}
\ No newline at end of file
package org.opengroup.osdu.schema.stepdefs;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.opengroup.osdu.schema.constants.TestConstants;
import org.opengroup.osdu.schema.stepdefs.model.HttpRequest;
import org.opengroup.osdu.schema.stepdefs.model.HttpResponse;
import org.opengroup.osdu.schema.stepdefs.model.SchemaServiceScope;
import org.opengroup.osdu.schema.util.AuthUtil;
import org.opengroup.osdu.schema.util.HttpClientFactory;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.inject.Inject;
import io.cucumber.java8.En;
public class SchemaServiceStepDef_GET implements En {
@Inject
private SchemaServiceScope context;
static String[] GetListBaseFilterArray;
static String[] GetListVersionFilterArray;
String queryParameter;
private static TreeSet<String> LIST_OF_AVAILABLE_SCHEMAS = new TreeSet<String>();
private final static Logger LOGGER = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
List<HashMap<String, String>> list_schemaParameterMap = new ArrayList<HashMap<String, String>>();
public SchemaServiceStepDef_GET() {
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);
}
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, selectTenant(tenant));
authHeaders.put(TestConstants.CONTENT_TYPE, TestConstants.JSON_CONTENT);
this.context.setAuthHeaders(authHeaders);
}
});
Given("I generate user token and set request headers for system API", () -> {
if (this.context.getToken() == null) {
String token = new AuthUtil().getToken();
this.context.setToken(token);
}
if (this.context.getAuthHeaders() == null) {
Map<String, String> authHeaders = new HashMap<String, String>();
authHeaders.put(TestConstants.AUTHORIZATION, this.context.getToken());
authHeaders.put(TestConstants.CONTENT_TYPE, TestConstants.JSON_CONTENT);
this.context.setAuthHeaders(authHeaders);
}
});
Given("I get latest schema with authority, source, entityType as {string}, {string}, {string} respectively",
(String authority, String source, String entityType) -> {
Map<String, String> queryParams = new HashMap<String, String>();
queryParams.put(TestConstants.AUTHORITY, authority);
queryParams.put(TestConstants.SOURCE, source);
queryParams.put(TestConstants.ENTITY_TYPE, entityType);
queryParams.put(TestConstants.LATEST_VERSION, TestConstants.TRUE);
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()));
LOGGER.log(Level.INFO, "resp - " + response.toString());
verifyGetListResponse(TestConstants.AUTHORITY, authority);
});
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())
.httpMethod(HttpRequest.GET).requestHeaders(this.context.getAuthHeaders()).build();
HttpResponse response = HttpClientFactory.getInstance().send(httpRequest);
assertEquals(ReponseStatusCode, String.valueOf(response.getCode()));
String body = this.context.getFileUtils().read(ResponseToBeVerified);
Gson gsn = new Gson();
JsonObject expectedData = gsn.fromJson(body, JsonObject.class);
JsonObject responseMsg = gsn.fromJson(response.getBody().toString(), JsonObject.class);
assertEquals(expectedData.toString(), responseMsg.toString());
});
}
private void verifyGetListResponse(String parameter, String parameterVal) throws IOException {
prepareSchemaParameterMapList();
verifySchemaInfoResponse(parameter, parameterVal);
}
public void prepareSchemaParameterMapList() throws IOException {
String response = this.context.getHttpResponse().getBody();
Gson gsn = new Gson();
JsonObject schemaInfosList = gsn.fromJson(response, JsonObject.class);
JsonArray root = (JsonArray) schemaInfosList.get("schemaInfos");
if (root.size() > 0) {
for (JsonElement eachSchemaInfo : root) {
Map<String, String> schemaIdentityMap = new HashMap<String, String>();
JsonObject schemaIdentity_ForEachSchemaStatus = (JsonObject) (eachSchemaInfo.getAsJsonObject());
this.context.setStatus(schemaIdentity_ForEachSchemaStatus.get("status").getAsString());
JsonObject schemaIdentity_ForEachSchemaInfo = (JsonObject) eachSchemaInfo.getAsJsonObject()
.get("schemaIdentity");
schemaIdentityMap.put("authority", schemaIdentity_ForEachSchemaInfo.get("authority").getAsString());
schemaIdentityMap.put("source", schemaIdentity_ForEachSchemaInfo.get("source").getAsString());
schemaIdentityMap.put("entityType", schemaIdentity_ForEachSchemaInfo.get("entityType").getAsString());
schemaIdentityMap.put("schemaVersionMajor",
schemaIdentity_ForEachSchemaInfo.get("schemaVersionMajor").getAsString());
this.context.setSchemaVersionMajor(
schemaIdentity_ForEachSchemaInfo.get("schemaVersionMajor").getAsString());
schemaIdentityMap.put("schemaVersionMinor",
schemaIdentity_ForEachSchemaInfo.get("schemaVersionMinor").getAsString());
this.context.setSchemaVersionMinor(
schemaIdentity_ForEachSchemaInfo.get("schemaVersionMinor").getAsString());
schemaIdentityMap.put("schemaVersionPatch",
schemaIdentity_ForEachSchemaInfo.get("schemaVersionPatch").getAsString());
this.context.setSchemaVersionPatch(
schemaIdentity_ForEachSchemaInfo.get("schemaVersionPatch").getAsString());
schemaIdentityMap.put("scope", eachSchemaInfo.getAsJsonObject().get("scope").getAsString());
schemaIdentityMap.put("status", eachSchemaInfo.getAsJsonObject().get("status").getAsString());
this.list_schemaParameterMap.add((HashMap<String, String>) schemaIdentityMap);
}
LOGGER.log(Level.INFO, "SchemaParameterMapList - " + this.list_schemaParameterMap.toString());
}
}
private void verifySchemaInfoResponse(String parameterName, String parameterVal) {
for (HashMap<String, String> schemaInfoMap : this.list_schemaParameterMap) {
assertEquals(
"Response schemaInfoList contains schemaInfo not matching parameter criteria - " + parameterName,
parameterVal.toString(), schemaInfoMap.get(parameterName).toString());
}
}
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
package org.opengroup.osdu.schema.stepdefs;
public class TearDownStepDefs {
}
package org.opengroup.osdu.schema.stepdefs.model;
import lombok.Builder;
import lombok.Data;
import java.util.HashMap;
import java.util.Map;
@Builder
@Data
public class HttpRequest {
public static final String PATCH = "PATCH";
public static final String POST = "POST";
public static final String PUT = "PUT";
public static final String GET = "GET";
public static final String DELETE = "DELETE";
String httpMethod;
String url;
String body;
@Builder.Default
Map<String, String> requestHeaders = new HashMap<>();
@Builder.Default
Map<String, ?> queryParams = new HashMap<>();
@Builder.Default
Map<String, ?> pathParams = new HashMap<>();
@Override
public String toString() {
return String.format("%s, httpMethod=%s", url, httpMethod);
}
}
package org.opengroup.osdu.schema.stepdefs.model;
import lombok.Builder;
import lombok.Data;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Data
@Builder
public class HttpResponse {
@Builder.Default
Map<String, List<String>> responseHeaders = new HashMap<>();
private int code;
private Exception exception;
private String body;
}
package org.opengroup.osdu.schema.stepdefs.model;
import java.util.Map;
import org.opengroup.osdu.schema.util.FileUtils;
import com.google.inject.Inject;
import io.cucumber.guice.ScenarioScoped;
import lombok.Data;
@ScenarioScoped
@Data
public class SchemaServiceScope {
@Inject
private FileUtils fileUtils;
private String token;
private String jobId;
private String schemaVersionMinor;
private String schemaVersionMajor;
private String schemaVersionPatch;
private HttpResponse httpResponse;
private String jsonPayloadForPostPUT;
private String status;
private Map<String, String> authHeaders;
private Map<String, String> queryParams;
private String SchemaIdFromInputPayload;
private String SchemaFromInputPayload;
private String supersededById;
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public void setJsonPayloadForPostPUT(String jsonPayloadForPostPUT) {
this.jsonPayloadForPostPUT = jsonPayloadForPostPUT;
}
public String getJsonPayloadForPostPUT() {
return jsonPayloadForPostPUT;
}
public String getSchemaVersionMinor() {
return schemaVersionMinor;
}
public void setSchemaIdFromInputPayload(String schemaId) {
this.SchemaIdFromInputPayload = schemaId;
}
public void setSchemaVersionMinor(String schemaVersionMinor) {
this.schemaVersionMinor = schemaVersionMinor;
}
public String getSchemaVersionMajor() {
return schemaVersionMajor;
}
public void getSchemaVersionMajor(String schemaVersionMajor) {
this.schemaVersionMajor = schemaVersionMajor;
}
public String getSchemaVersionPatch() {
return schemaVersionPatch;
}
public void getSchemaVersionPatch(String schemaVersionPatch) {
this.schemaVersionPatch = schemaVersionPatch;
}
public String getJobId() {
return jobId;
}
public void setJobId(String jobId) {
this.jobId = jobId;
}
public HttpResponse getHttpResponse() {
return httpResponse;
}
public void setHttpResponse(HttpResponse httpResponse) {
this.httpResponse = httpResponse;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
package org.opengroup.osdu.schema.util;
import com.google.common.base.Strings;
import org.opengroup.osdu.azure.util.AzureServicePrincipal;
import org.opengroup.osdu.core.aws.cognito.AWSCognitoClient;
import org.opengroup.osdu.core.ibm.util.IdentityClient;
public class AuthUtil {
public synchronized String getToken() throws Exception {
String token = null;
String vendor = System.getProperty("VENDOR", System.getenv("VENDOR"));
if (Strings.isNullOrEmpty(token) && vendor.equals("azure")) {
String sp_id = System.getProperty("INTEGRATION_TESTER", System.getenv("INTEGRATION_TESTER"));
String sp_secret = System.getProperty("TESTER_SERVICEPRINCIPAL_SECRET", System.getenv("TESTER_SERVICEPRINCIPAL_SECRET"));
String tenant_id = System.getProperty("AZURE_AD_TENANT_ID", System.getenv("AZURE_AD_TENANT_ID"));
String app_resource_id = System.getProperty("AZURE_AD_APP_RESOURCE_ID", System.getenv("AZURE_AD_APP_RESOURCE_ID"));
token = new AzureServicePrincipal().getIdToken(sp_id, sp_secret, tenant_id, app_resource_id);
}
return "Bearer " + token;
}
}
package org.opengroup.osdu.schema.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collection;
public class FileUtils {
public String read(String filePath) throws IOException {
InputStream inStream = this.getClass().getResourceAsStream(filePath);
BufferedReader br = new BufferedReader(new InputStreamReader(inStream));
StringBuilder stringBuilder = new StringBuilder();
String eachLine = "";
while((eachLine = br.readLine()) != null){
stringBuilder.append(eachLine);
}
return stringBuilder.toString();
}
public static boolean isNullOrEmpty( final Collection< ? > c ) {
return c == null || c.isEmpty();
}
}
package org.opengroup.osdu.schema.util;
import org.opengroup.osdu.schema.stepdefs.model.HttpRequest;
import org.opengroup.osdu.schema.stepdefs.model.HttpResponse;
public interface HttpClient {
HttpResponse send(HttpRequest httpRequest);
<T> T send(HttpRequest httpRequest, Class<T> classOfT);
}
package org.opengroup.osdu.schema.util;
public class HttpClientFactory {
private static HttpClient httpClient = null;
public static HttpClient getInstance() {
if (httpClient == null) {
httpClient = new RestAssuredClient();
}
return httpClient;
}
}
package org.opengroup.osdu.schema.util;
import com.google.gson.Gson;
import io.restassured.path.json.JsonPath;
public class JsonUtils {
public static String toJson(Object src) {
return new Gson().toJson(src);
}
public static <T> T fromJson(String json, Class<T> classOfT) {
return new Gson().fromJson(json, classOfT);
}
public static JsonPath getAsJsonPath(String src) {
return JsonPath.with(src);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment