Skip to content
Snippets Groups Projects
Commit dc341024 authored by Komal Makkar's avatar Komal Makkar
Browse files

Refactoring of Integration Tests

parents cb2e2f9d 8b65d8c5
No related branches found
No related tags found
1 merge request!15Integration tests Refactored
Pipeline #6451 failed
......@@ -20,6 +20,9 @@ import org.opengroup.osdu.notification.util.Config;
import org.opengroup.osdu.notification.util.RestDescriptor;
import org.opengroup.osdu.notification.util.TestUtils;
import java.util.HashMap;
import java.util.Map;
public class PubsubEndpointGSADescriptor extends RestDescriptor {
@Override
......@@ -41,7 +44,21 @@ public class PubsubEndpointGSADescriptor extends RestDescriptor {
"\t\"data-partition-id\": \"" + TestUtils.getOsduTenant() + "\"},\n" +
"\t\"data\": \"W3sia2luZCI6InRlc3RraW5kIiwiaWQiOiJ0ZXN0aWQiLCJvcGVyYXRpb250eXBlIjoiY3JlYXRlIn0seyJraW5kIjoidGVzdGtpbmQyIiwiaWQiOiJ0ZXN0aWQyIiwib3BlcmF0aW9udHlwZSI6InVwZGF0ZSJ9XQ\",\n" +
"\t\"messageId\": \"136969346945\"},\n" +
"\t\"subscription\":\"" + Config.Instance().NotificationId + "\"\n" +
"\t\"subscription\":\"" +arg() + "\"\n" +
"}";
}
@Override
public Map<String,String> getOsduTenantHeaders(){
Map<String, String> headers = new HashMap<>();
headers.put("data-partition-id", Config.Instance().ClientTenant);
return headers;
}
@Override
public Map<String,String> getCustomerTenantHeaders(){
Map<String, String> headers = new HashMap<>();
headers.put("data-partition-id", Config.Instance().ClientTenant);
return headers;
}
}
......@@ -16,9 +16,13 @@
package org.opengroup.osdu.notification.api;
import org.opengroup.osdu.notification.util.Config;
import org.opengroup.osdu.notification.util.RestDescriptor;
import org.opengroup.osdu.notification.util.TestUtils;
import java.util.HashMap;
import java.util.Map;
public class PubsubEndpointHMACDescriptor extends RestDescriptor {
@Override
......@@ -45,4 +49,18 @@ public class PubsubEndpointHMACDescriptor extends RestDescriptor {
"\t\"subscription\": \""+ arg() +"\"\n" +
"}\n";
}
@Override
public Map<String,String> getOsduTenantHeaders(){
Map<String, String> headers = new HashMap<>();
headers.put("data-partition-id", Config.Instance().ClientTenant);
return headers;
}
@Override
public Map<String,String> getCustomerTenantHeaders(){
Map<String, String> headers = new HashMap<>();
headers.put("data-partition-id", Config.Instance().ClientTenant);
return headers;
}
}
......@@ -92,6 +92,8 @@ public abstract class PubsubEndpointHMACTests extends BaseTestTemplate {
Subscription subscriptionCreated = subscriptionService.create(subscription);
notificationId = subscriptionCreated.getNotificationId();
subscriptionId = subscriptionCreated.getId();
Config.Instance().NotificationId = notificationId;
}
@Override
......
......@@ -18,6 +18,8 @@ package org.opengroup.osdu.notification.util;
import com.sun.jersey.api.client.ClientResponse;
import java.util.Map;
public abstract class RestDescriptor {
public RestDescriptor() {
......@@ -30,22 +32,24 @@ public abstract class RestDescriptor {
public abstract String getPath();
public abstract String getHttpMethod();
public abstract String getValidBody();
public abstract Map<String,String> getOsduTenantHeaders();
public abstract Map<String,String> getCustomerTenantHeaders();
public String getQuery() { return ""; }
public ClientResponse runHttp(String arg, String token) throws Exception{
this.arg = arg;
return TestUtils.send(getPath(), getHttpMethod(), token, getValidBody(), getQuery(), true);
return TestUtils.send(getPath(), getHttpMethod(), token, getValidBody(), getQuery(), getOsduTenantHeaders(),true);
}
public ClientResponse run(String arg, String token) throws Exception{
this.arg = arg;
return TestUtils.send(getPath(), getHttpMethod(), token, getValidBody(), getQuery(), false);
return TestUtils.send(getPath(), getHttpMethod(), token, getValidBody(), getQuery(), getOsduTenantHeaders(),false);
}
public ClientResponse runOnCustomerTenant(String arg, String token) throws Exception{
this.arg = arg;
return TestUtils.send(getPath(), getHttpMethod(), token, getValidBody(), getQuery(), TestUtils.getCustomerTenantHeaders(), false);
return TestUtils.send(getPath(), getHttpMethod(), token, getValidBody(), getQuery(), getCustomerTenantHeaders(), false);
}
public ClientResponse runOptions(String arg, String token) throws Exception{
this.arg = arg;
return TestUtils.send(getPath(), "OPTIONS", token, "", "", false);
return TestUtils.send(getPath(), "OPTIONS", token, "", "", getOsduTenantHeaders(),false);
}
}
\ No newline at end of file
......@@ -62,27 +62,6 @@ public abstract class TestUtils {
public abstract String getEditorToken() throws Exception;
public abstract String getNoAccessToken() throws Exception;
public static ClientResponse send(String path, String httpMethod, String token, String requestBody, String query, boolean enforceHttp)
throws Exception {
Map<String, String> headers = getOsduTenantHeaders();
return send(path, httpMethod, token, requestBody, query, headers, enforceHttp);
}
public static Map<String, String> getOsduTenantHeaders() {
Map<String, String> headers = new HashMap<>();
headers.put("data-partition-id", getOsduTenant());
return headers;
}
public static Map<String, String> getCustomerTenantHeaders() {
Map<String, String> headers = new HashMap<>();
headers.put("data-partition-id", getCustomerTenant());
return headers;
}
public static ClientResponse send(String path, String httpMethod, String token, String requestBody, String query,
Map<String,String> headers, boolean enforceHttp)
throws Exception {
......
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