Commit bcbbe8e9 authored by satish.nargani's avatar satish.nargani Committed by satish kumar nargani
Browse files

Added test cases

parent 0616f977
......@@ -23,7 +23,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<version>2.2.2.RELEASE</version>
<relativePath/>
</parent>
......@@ -46,13 +46,14 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<spring-boot.version>2.2.5.RELEASE</spring-boot.version>
<spring-cloud.version>Hoxton.SR3</spring-cloud.version>
<spring-boot.version>2.2.4.RELEASE</spring-boot.version>
<spring-cloud.version>Hoxton.SR2</spring-cloud.version>
<javax.inject.version>1</javax.inject.version>
<org.mapstruct.version>1.3.1.Final</org.mapstruct.version>
<maven-surefire-plugin.version>3.0.0-M4</maven-surefire-plugin.version>
<os-core-common.version>0.3.5</os-core-common.version>
<springfox.version>2.9.2</springfox.version>
<os-core-common.version>0.0.13-gcp</os-core-common.version>
<lombok.version>1.18.0</lombok.version>
<springfox.version>2.9.2</springfox.version>
</properties>
<licenses>
......@@ -77,6 +78,11 @@
<dependencies>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
<version>${os-core-common.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
......@@ -93,14 +99,6 @@
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox.version}</version>
</dependency>
<!-- OSDU -->
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
<version>${os-core-common.version}</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
......@@ -118,11 +116,6 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-json</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
......@@ -301,19 +294,19 @@
<repositories>
<repository>
<id>${repo.releases.id}</id>
<url>${repo.releases.url}</url>
<id>${gitlab-server}</id>
<url>https://community.opengroup.org/api/v4/groups/17/-/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>${publish.releases.id}</id>
<url>${publish.releases.url}</url>
<id>${gitlab-server}</id>
<url>https://community.opengroup.org/api/v4/projects/146/packages/maven</url>
</repository>
<snapshotRepository>
<id>${publish.snapshots.id}</id>
<url>${publish.snapshots.url}</url>
<id>${gitlab-server}</id>
<url>https://community.opengroup.org/api/v4/projects/146/packages/maven</url>
</snapshotRepository>
</distributionManagement>
......
......@@ -21,6 +21,7 @@ import java.util.logging.Logger;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONObject;
import org.opengroup.osdu.workflow.model.WorkflowStatus;
import org.opengroup.osdu.workflow.provider.interfaces.ISubmitIngestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -57,8 +58,10 @@ public class SubmitIngestServiceImpl implements ISubmitIngestService {
String airflowApiUrl = String.format("%s/api/experimental/dags/%s/dag_runs", airflowURL, dagName);
String workflowId = data.get(RUN_ID_PARAMETER_NAME).toString();
data.remove(RUN_ID_PARAMETER_NAME);
/* String workflowId = data.get(RUN_ID_PARAMETER_NAME).toString();
data.remove(RUN_ID_PARAMETER_NAME);*/
String workflowId = data.get(WorkflowStatus.Fields.WORKFLOW_ID).toString();
data.remove(WorkflowStatus.Fields.WORKFLOW_ID);
JSONObject requestBody = new JSONObject();
requestBody.put(RUN_ID_PARAMETER_NAME, workflowId);
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2017-2019 Schlumberger
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.opengroup.osdu.workflow</groupId>
<artifactId>workflow-test-azure</artifactId>
<version>0.0.2-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.main.basedir>${project.basedir}</project.main.basedir>
<jackson.version>2.10.1</jackson.version>
</properties>
<dependencies>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>workflow-test-core</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>workflow-test-core</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- Tests -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>5.1.10.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.25</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
<scope>test</scope>
</dependency>
</dependencies>
<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/44/packages/maven</url>
</repository>
<snapshotRepository>
<id>${gitlab-server}</id>
<url>https://community.opengroup.org/api/v4/projects/44/packages/maven</url>
</snapshotRepository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/workflow</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
</plugins>
</build>
</project>
package org.opengroup.osdu.azure.workflow;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.runner.RunWith;
@RunWith(JUnitPlatform.class)
@SelectPackages("org.opengroup.osdu.azure.workflow")
public class RunTests {
}
package org.opengroup.osdu.azure.workflow.utils;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.opengroup.osdu.workflow.consts.TestConstants;
import org.opengroup.osdu.workflow.util.PayloadBuilder;
import java.util.HashMap;
import java.util.Map;
public class AzurePayLoadBuilder {
public static String buildInvalidWorkflowIdPayload(String workflowId){
Map<String, Object> payload = new HashMap<>();
payload.put("Workflow", workflowId);
return new Gson().toJson(payload);
}
public static String buildStartWorkflow(Map<String, Object> context, String type){
Map<String, Object> payload = new HashMap<>();
payload.put("WorkflowType", type);
payload.put("DataType", "opaqueo");
payload.put("Context", context);
return new Gson().toJson(payload);
}
public static String getValidWorkflowPayload(){
return PayloadBuilder.buildStartWorkflow(buildContext(), TestConstants.WORKFLOW_TYPE_INGEST);
}
public static String getInValidWorkflowPayload(){
return AzurePayLoadBuilder.buildStartWorkflow(buildContext(), TestConstants.WORKFLOW_TYPE_INGEST);
}
public static Map<String, Object> buildContext() {
Map<String, Object> context = new HashMap<>();
Map<String, Object> conf = new HashMap<>();
conf.put("test","test") ;
context.put("conf", conf);
return context;
}
public static JsonObject getWellLogCtxObj()
{
JsonObject main= new JsonObject();
JsonObject item= new JsonObject();
item.addProperty("data-partition-id","opendes");
JsonObject legalTagitem= new JsonObject();
JsonArray legal = new JsonArray();
legal.add("opendes-dps-integration-test-valid2-legal-tag");
JsonArray otherRelevantDataCountries = new JsonArray();
otherRelevantDataCountries.add("US");
legalTagitem.add("legaltags",legal);
legalTagitem.add("otherRelevantDataCountries",otherRelevantDataCountries);
legalTagitem.addProperty("status","complaint");
//acl
JsonObject acl= new JsonObject();
JsonArray viewers = new JsonArray();
viewers.add("data.default.viewer@opendes.contoso.com");
JsonArray owners = new JsonArray();
owners.add("data.default.owner@opendes.contoso.com");
acl.add("viewers",viewers);
acl.add("owners",owners);
item.add("legal-tags",legalTagitem);
item.add("acl",acl);
JsonObject workproduct= new JsonObject();
workproduct.addProperty("ResourceTypeID","srn:type:work-product/WellLog:");
workproduct.addProperty("ResourceSecurityClassification","srn:reference-data/ResourceSecurityClassification:RESTRICTED:");
JsonObject groupTypeProperties= new JsonObject();
JsonArray Components = new JsonArray();
JsonArray Artefacts1 = new JsonArray();
JsonObject GroupTypeProperties = new JsonObject();
GroupTypeProperties.add("Components",Components);
groupTypeProperties.add("GroupTypeProperties", GroupTypeProperties);
JsonObject data= new JsonObject();
JsonObject individualTypeProperties= new JsonObject();
individualTypeProperties.addProperty("Name","AKM-11 LOG");
individualTypeProperties.addProperty("Description","Well Log");
groupTypeProperties.add("IndividualTypeProperties",individualTypeProperties );
JsonObject extensionProperties= new JsonObject();
groupTypeProperties.add("ExtensionProperties",extensionProperties);
JsonArray componentsAssociativeIDs = new JsonArray();
componentsAssociativeIDs.add("wpc-1");
groupTypeProperties.add("ComponentsAssociativeIDs", componentsAssociativeIDs);
JsonArray workproductcomponents= new JsonArray();
JsonObject resourceTypeID= new JsonObject();
resourceTypeID.addProperty("ResourceTypeID", "srn:type:work-product-component/WellLog:");
resourceTypeID.addProperty("ResourceSecurityClassification", "srn:reference-data/ResourceSecurityClassification:RESTRICTED:");
workproductcomponents.add(resourceTypeID);
JsonObject dataa= new JsonObject();
JsonObject groupTypePropertiess= new JsonObject();
JsonArray files = new JsonArray();
JsonArray Artefacts = new JsonArray();
JsonObject GroupTypeProperties1 = new JsonObject();
GroupTypeProperties1.add("Files",files);
GroupTypeProperties1.add("Artefacts",Artefacts);
groupTypePropertiess.add("GroupTypeProperties", GroupTypeProperties1);
JsonObject individualTypePropertie= new JsonObject();
individualTypePropertie.addProperty("Name","AKM-11 LOG");
individualTypePropertie.addProperty("Description","Well Log");
individualTypePropertie.addProperty("WellboreID","srn:master-data/Wellbore:1013:");
groupTypePropertiess.add("IndividualTypeProperties", individualTypePropertie);
JsonObject topMeasuredDepth= new JsonObject();
topMeasuredDepth.addProperty("Depth", 2182.0004);
topMeasuredDepth.addProperty("UnitOfMeasure", "srn:reference-data/UnitOfMeasure:M:");
groupTypePropertiess.add("TopMeasuredDepth", topMeasuredDepth);
JsonObject bottomMeasuredDepth= new JsonObject();
bottomMeasuredDepth.addProperty("Depth", 2481.0);
bottomMeasuredDepth.addProperty("UnitOfMeasure", "srn:reference-data/UnitOfMeasure:M:");
groupTypePropertiess.add("BottomMeasuredDepth", bottomMeasuredDepth);
JsonArray curves = new JsonArray();
JsonObject curvesObj= new JsonObject();
curvesObj.addProperty("Mnemonic","DEPT");
curvesObj.addProperty("TopDepth",2182.0);
curvesObj.addProperty("BaseDepth",2481.0);
curvesObj.addProperty("DepthUnit","srn:reference-data/UnitOfMeasure:M:");
curvesObj.addProperty("CurveUnit","srn:reference-data/UnitOfMeasure:M:");
JsonObject curvesObj2= new JsonObject();
curvesObj2.addProperty("Mnemonic","GR");
curvesObj2.addProperty("TopDepth",2182.0);
curvesObj2.addProperty("BaseDepth",2481.0);
curvesObj2.addProperty("DepthUnit","srn:reference-data/UnitOfMeasure:M:");
curvesObj2.addProperty("CurveUnit","srn:reference-data/UnitOfMeasure:GAPI:");
JsonObject curvesObj3= new JsonObject();
curvesObj3.addProperty("Mnemonic","DT");
curvesObj3.addProperty("TopDepth",2182.0);
curvesObj3.addProperty("BaseDepth",2481.0);
curvesObj3.addProperty("DepthUnit","srn:reference-data/UnitOfMeasure:M:");
curvesObj3.addProperty("CurveUnit","srn:reference-data/UnitOfMeasure:US/F:");
JsonObject curvesObj4= new JsonObject();
curvesObj4.addProperty("Mnemonic","RHOB");
curvesObj4.addProperty("TopDepth",2182.0);
curvesObj4.addProperty("BaseDepth",2481.0);
curvesObj4.addProperty("DepthUnit","srn:reference-data/UnitOfMeasure:M:");
curvesObj4.addProperty("CurveUnit","srn:reference-data/UnitOfMeasure:G/C3:");
JsonObject curvesObj5= new JsonObject();
curvesObj5.addProperty("Mnemonic","DRHO");
curvesObj5.addProperty("TopDepth",2182.0);
curvesObj5.addProperty("BaseDepth",2481.0);
curvesObj5.addProperty("DepthUnit","srn:reference-data/UnitOfMeasure:M:");
curvesObj5.addProperty("CurveUnit","srn:reference-data/UnitOfMeasure:G/C3:");
JsonObject curvesObj6= new JsonObject();
curvesObj6.addProperty("Mnemonic","NPHI");
curvesObj6.addProperty("TopDepth",2182.0);
curvesObj6.addProperty("BaseDepth",2481.0);
curvesObj6.addProperty("DepthUnit","srn:reference-data/UnitOfMeasure:M:");
curvesObj6.addProperty("CurveUnit","srn:reference-data/UnitOfMeasure:V/V:");
curves.add(curvesObj);
curves.add(curvesObj2);
curves.add(curvesObj3);
curves.add(curvesObj4);
curves.add(curvesObj5);
curves.add(curvesObj6);
groupTypePropertiess.add("Curves", curves);
JsonObject emptyObj= new JsonObject();
groupTypePropertiess.add("ExtensionProperties",emptyObj);
resourceTypeID.addProperty("AssociativeID", "wpc-1");
JsonArray fileAssociativeIDs = new JsonArray();
fileAssociativeIDs.add("f-1");
groupTypePropertiess.add("FileAssociativeIDs", fileAssociativeIDs);
JsonArray filesData= new JsonArray();
JsonObject resourceType= new JsonObject();
resourceType.addProperty("ResourceTypeID", "srn:type:file/las2:");
resourceType.addProperty("ResourceSecurityClassification", "srn:reference-data/ResourceSecurityClassification:RESTRICTED:");
resourceType.addProperty("AssociativeID", "f-1");
JsonObject gTypeProperties= new JsonObject();
gTypeProperties.addProperty("FileSource", "");
gTypeProperties.addProperty("PreLoadFilePath", "https://azglobalosdulake.blob.core.windows.net/data/well-logs/1013_akm11_1978_comp.las");
JsonObject DData= new JsonObject();
JsonObject Grp= new JsonObject();
Grp.add("GroupTypeProperties", gTypeProperties);
Grp.add("IndividualTypeProperties",emptyObj);
Grp.add("ExtensionProperties",emptyObj);
DData.add("Data", Grp);
filesData.add(resourceType);
filesData.add(DData);
data.add("Files", filesData);
dataa.add("Data",groupTypePropertiess);
workproductcomponents.add(dataa);
workproduct.add("Data", groupTypeProperties);
data.add("Workproduct", workproduct);
data.add("WorkProductComponents", workproductcomponents);
item.add("data", data);
main.add("Context", item);
return item;
}
}
// Copyright © Microsoft Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.azure.workflow.utils;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
public class AzureServicePrincipal {
public static String getIdToken(String sp_id, String sp_secret, String tenant_id, String app_resource_id) throws Exception {
String aad_endpoint = String.format("https://login.microsoftonline.com/%s/oauth2/token", tenant_id);
URL url = new URL(aad_endpoint);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
Map<String, String> parameters = new HashMap<>();
parameters.put("grant_type", "client_credentials");
parameters.put("client_id", sp_id);
parameters.put("client_secret", sp_secret);
parameters.put("resource", app_resource_id);
con.setDoOutput(true);
DataOutputStream out = new DataOutputStream(con.getOutputStream());
out.writeBytes(getParamsString(parameters));
out.flush();
out.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer content = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
in.close();
con.disconnect();
Gson gson = new Gson();
JsonObject jobj = gson.fromJson(content.toString(), JsonObject.class);
String token = jobj.get("access_token").getAsString();
return token;
}
private static String getParamsString(Map<String, String> params)
throws UnsupportedEncodingException {
StringBuilder result = new StringBuilder();
for (Map.Entry<String, String> entry : params.entrySet()) {
result.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
result.append("=");
result.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
result.append("&");
}
String resultString = result.toString();
return resultString.length() > 0
? resultString.substring(0, resultString.length() - 1)
: resultString;
}
}
package org.opengroup.osdu.azure.workflow.utils;
import com.google.gson.Gson;
import com.sun.jersey.api.client.ClientResponse;
public class DummyRecordsHelper {
public BadRequestMock getRecordsMockFromBadRequestResponse(ClientResponse response) {
String json = response.getEntity(String.class);
Gson gson = new Gson();
return gson.fromJson(json, BadRequestMock.class);
}
public class BadRequestMock {
public String status;
public String message;
public String[] errors;
}
}
// Copyright 2017-2019, Schlumberger
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.