Commit 77601685 authored by Aman Verma's avatar Aman Verma
Browse files

Merge branch 'users/amaverma/AddITsForNewAPI' into 'master'

Adding integration tests schemas/system endpoint

See merge request !118
parents a9fc1321 81cec127
Pipeline #49561 failed with stages
in 38 minutes and 19 seconds
...@@ -17,6 +17,7 @@ variables: ...@@ -17,6 +17,7 @@ variables:
AZURE_SERVICE: schema AZURE_SERVICE: schema
AZURE_BUILD_SUBDIR: provider/schema-azure AZURE_BUILD_SUBDIR: provider/schema-azure
AZURE_TEST_SUBDIR: testing/schema-test-core AZURE_TEST_SUBDIR: testing/schema-test-core
AZURE_ONLY_TEST_SUBDIR: testing/schema-test-azure
AZURE_DEPLOYMENTS_SUBDIR: deployments/scripts/azure AZURE_DEPLOYMENTS_SUBDIR: deployments/scripts/azure
AZURE_DEPLOYMENTS_SCRIPTS_SUBDIR: deployments/scripts AZURE_DEPLOYMENTS_SCRIPTS_SUBDIR: deployments/scripts
AZURE_CLIENT_ID: $AZURE_PRINCIPAL_ID AZURE_CLIENT_ID: $AZURE_PRINCIPAL_ID
......
...@@ -714,6 +714,7 @@ CDDL-1.1 ...@@ -714,6 +714,7 @@ CDDL-1.1
======================================================================== ========================================================================
The following software have components provided under the terms of this license: The following software have components provided under the terms of this license:
- JavaBeans Activation Framework (from )
- JavaBeans(TM) Activation Framework (from http://java.sun.com/javase/technologies/desktop/javabeans/jaf/index.jsp) - JavaBeans(TM) Activation Framework (from http://java.sun.com/javase/technologies/desktop/javabeans/jaf/index.jsp)
- tomcat-embed-core (from http://tomcat.apache.org/) - tomcat-embed-core (from http://tomcat.apache.org/)
...@@ -787,6 +788,7 @@ GPL-2.0-only ...@@ -787,6 +788,7 @@ GPL-2.0-only
The following software have components provided under the terms of this license: The following software have components provided under the terms of this license:
- Expression Language 3.0 (from https://projects.eclipse.org/projects/ee4j.el) - Expression Language 3.0 (from https://projects.eclipse.org/projects/ee4j.el)
- JavaBeans Activation Framework (from )
- JavaMail API (from ) - JavaMail API (from )
- jakarta.annotation-api (from https://projects.eclipse.org/projects/ee4j.ca) - jakarta.annotation-api (from https://projects.eclipse.org/projects/ee4j.ca)
- javax.annotation-api (from http://jcp.org/en/jsr/detail?id=250) - javax.annotation-api (from http://jcp.org/en/jsr/detail?id=250)
...@@ -800,6 +802,7 @@ The following software have components provided under the terms of this license: ...@@ -800,6 +802,7 @@ The following software have components provided under the terms of this license:
- Checker Qual (from https://checkerframework.org) - Checker Qual (from https://checkerframework.org)
- Expression Language 3.0 (from https://projects.eclipse.org/projects/ee4j.el) - Expression Language 3.0 (from https://projects.eclipse.org/projects/ee4j.el)
- Google Guice - Core Library (from ) - Google Guice - Core Library (from )
- JavaBeans Activation Framework (from )
- JavaMail API (from ) - JavaMail API (from )
- jakarta.annotation-api (from https://projects.eclipse.org/projects/ee4j.ca) - jakarta.annotation-api (from https://projects.eclipse.org/projects/ee4j.ca)
- tomcat-embed-core (from http://tomcat.apache.org/) - tomcat-embed-core (from http://tomcat.apache.org/)
......
package org.opengroup.osdu.schema.azure.auth; package org.opengroup.osdu.schema.azure.auth;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.schema.azure.interfaces.IAuthorizationServiceForServicePrincipal; import org.opengroup.osdu.schema.azure.interfaces.IAuthorizationServiceForServicePrincipal;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -9,10 +10,14 @@ import org.springframework.web.context.annotation.RequestScope; ...@@ -9,10 +10,14 @@ import org.springframework.web.context.annotation.RequestScope;
@RequestScope @RequestScope
public class AuthorizationFilterSP { public class AuthorizationFilterSP {
@Autowired
private DpsHeaders headers;
@Autowired @Autowired
private IAuthorizationServiceForServicePrincipal authorizationService; private IAuthorizationServiceForServicePrincipal authorizationService;
public boolean hasPermissions() { public boolean hasPermissions() {
headers.put(DpsHeaders.USER_EMAIL, "ServicePrincipalUser");
return authorizationService.isDomainAdminServiceAccount(); return authorizationService.isDomainAdminServiceAccount();
} }
} }
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-schema-test</artifactId>
<version>0.10.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>schema-test-azure</artifactId>
<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.0.1</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>
</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 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 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