Skip to content
Snippets Groups Projects
Commit 24542900 authored by Yash Dholakia's avatar Yash Dholakia
Browse files

Fix Integration tests

parent 99e105b2
No related branches found
No related tags found
1 merge request!417AWS sync dev to master
......@@ -76,11 +76,10 @@ public class RecordUtils {
return record;
}
public static final String getAclSuffix(boolean isTestPartition) {
public static String getAclSuffix(boolean isTestPartition) {
String environment = getEnvironment();
//build.gradle currently throws exception if a variable is set to empty or not set at all
//workaround by setting it to an "empty" string to construct the url
if (environment.equalsIgnoreCase("empty")) environment = "";
if (!environment.isEmpty())
environment = "." + environment;
......
......@@ -23,6 +23,8 @@ import static org.junit.Assert.assertEquals;
public class TestNotificationsEndpoint extends TestBase {
private String subscriptionId_TestPartition;
private String subscriptionId;
private ISubscriptionService awssubscriptionService;
private TestUtils testUtils;
......@@ -46,17 +48,55 @@ public class TestNotificationsEndpoint extends TestBase {
}
@Before
public void setup() throws Exception {
public void setup() {
this.testUtils = new AwsTestUtils();
}
@After
@Override
public void tearDown() throws Exception {
//LegalTagUtils.delete(LEGAL_TAG, testUtils.getOpsToken());
LegalTagUtils.delete(LEGAL_TAG_TEST, testUtils.getOpsToken(), true);
LegalTagUtils.delete(LEGAL_TAG, testUtils.getOpsToken(), false);
this.testUtils = null;
}
private void createResourceForTestParition() throws Exception {
Map<String, String> headers = new HashMap<>();
headers.put(DpsHeaders.DATA_PARTITION_ID, TestUtils.getOsduTenant());
headers.put(DpsHeaders.AUTHORIZATION, testUtils.getOpsToken());
//hardcoding user here for 200 response tests. This is just initializing the subscription creation
headers.put("x-user-id", AwsConfig.getAWSCognitoUser());
DpsHeaders dpsHeaders = DpsHeaders.createFromMap(headers);
awssubscriptionService = awsfactory.create(dpsHeaders);
Map<String,String> h = dpsHeaders.getHeaders();
System.out.println(h);
//Create a new subscription to pub/sub
Subscription subscription = new Subscription();
subscription.setName("Subscription-test-for-notification");
subscription.setDescription("Subscription with test Partition for fetching notifications");
subscription.setTopic(Config.Instance().Topic);
//This seems to be a bug. Don't need to add the string
//subscription.setPushEndpoint(Config.Instance().HMACPushUrl + "hmac-integration-test");
subscription.setPushEndpoint(Config.Instance().HMACPushUrl);
HmacSecret secret = new HmacSecret();
secret.setValue(Config.Instance().hmacSecretValue);
subscription.setSecret(secret);
try {
Subscription subscriptionCreated = awssubscriptionService.create(subscription);
System.out.println("Subscription created successfully");
String notificationId = subscriptionCreated.getNotificationId();
subscriptionId_TestPartition = subscriptionCreated.getId();
Config.Instance().NotificationId = notificationId;
}catch (SubscriptionException e){
System.out.println("Subscription exception inner response : " + e.getHttpResponse());
throw e;
}
}
private void createResource() throws Exception {
Map<String, String> headers = new HashMap<>();
headers.put(DpsHeaders.DATA_PARTITION_ID, TestUtils.getOsduTenant());
......@@ -73,7 +113,7 @@ public class TestNotificationsEndpoint extends TestBase {
//Create a new subscription to pub/sub
Subscription subscription = new Subscription();
subscription.setName("Subscription-test-for-notification");
subscription.setDescription("Subscription test for fetching notifications");
subscription.setDescription("Subscription for fetching notifications");
subscription.setTopic(Config.Instance().Topic);
//This seems to be a bug. Don't need to add the string
//subscription.setPushEndpoint(Config.Instance().HMACPushUrl + "hmac-integration-test");
......@@ -110,7 +150,7 @@ public class TestNotificationsEndpoint extends TestBase {
public void testVerifyNotificationReceivedWhenDataPartitionIdIsDifferent() throws Exception {
try {
LegalTagUtils.create(LEGAL_TAG_TEST, testUtils.getOpsToken(), true);
createResource();
createResourceForTestParition();
final String correlationId = UUID.randomUUID().toString();
ClientResponse response = createStorageRecordForTestPartition(correlationId);
assertEquals(201, response.getStatus());
......@@ -124,10 +164,9 @@ public class TestNotificationsEndpoint extends TestBase {
int exitValue = process.exitValue();
assertEquals(exitValue, 1);
} catch (Exception e) {
System.out.println("Error while verifying notification service" + Arrays.toString(e.getStackTrace()));
System.out.println("Error while verifying notification service. Error = " + e.getMessage() + " Stack Trace = " + Arrays.toString(e.getStackTrace()));
} finally {
awssubscriptionService.delete(subscriptionId);
LegalTagUtils.delete(LEGAL_TAG_TEST, testUtils.getOpsToken(), true);
awssubscriptionService.delete(subscriptionId_TestPartition);
}
}
......@@ -149,10 +188,9 @@ public class TestNotificationsEndpoint extends TestBase {
int exitValue = process.exitValue();
assertEquals(exitValue, 0);
} catch (Exception e) {
System.out.println("Error while verifying notification service" + Arrays.toString(e.getStackTrace()));
System.out.println("Error while verifying notification service. Error = " + e.getMessage() + " Stack Trace = " + Arrays.toString(e.getStackTrace()));
} finally {
awssubscriptionService.delete(subscriptionId);
LegalTagUtils.delete(LEGAL_TAG_TEST, testUtils.getOpsToken(), false);
}
}
}
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