Commit f71ef981 authored by Rucha Deshpande's avatar Rucha Deshpande
Browse files

override tests

parent f58062dd
......@@ -20,15 +20,25 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opengroup.osdu.notification.util.Config;
import org.opengroup.osdu.notification.util.AwsTestUtils;
import org.opengroup.osdu.notification.util.RestDescriptor;
import org.opengroup.osdu.notification.util.TestUtils;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.notification.HmacSecret;
import org.opengroup.osdu.core.common.model.notification.Subscription;
import org.opengroup.osdu.core.common.notification.ISubscriptionService;
import org.opengroup.osdu.core.common.notification.SubscriptionException;
import org.opengroup.osdu.core.common.notification.SubscriptionFactory;
import org.opengroup.osdu.notification.util.*;
import com.sun.jersey.api.client.ClientResponse;
import java.util.HashMap;
import java.util.Map;
public class TestPubsubEndpointHMAC extends PubsubEndpointHMACTests {
private String subscriptionId = null;
private String notificationId = null;
private ISubscriptionService subscriptionService;
private static SubscriptionFactory factory;
@BeforeClass
public static void classSetup() throws Exception {
PubsubEndpointHMACTests.classSetup();
......@@ -63,4 +73,56 @@ public class TestPubsubEndpointHMAC extends PubsubEndpointHMACTests {
ClientResponse response = descriptor.run(getArg(), "");
assertEquals(error(response.getEntity(String.class)), 401, response.getStatus());
}
@Override
protected void createResource() throws Exception {
createResourceInPartition(TestUtils.getOsduTenant());
}
private void createResourceInPartition(String partitionId) throws Exception{
System.out.println("****NOTIFICATION Creating resource using overriden method*******");
Map<String, String> headers = new HashMap<>();
headers.put(DpsHeaders.DATA_PARTITION_ID, partitionId);
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);
subscriptionService = factory.create(dpsHeaders);
System.out.println("****NOTIFICATION Created subscriptionService using following headers*******");
Map<String,String> h = dpsHeaders.getHeaders();
System.out.println(h);
System.out.println("****NOTIFICATION Created subscriptionService using following headers DONE*******");
//Create a new subscription to pub/sub
Subscription subscription = new Subscription();
subscription.setName("subscription-integration-test-hmac");
subscription.setDescription("subscription created for hmac integration test");
subscription.setTopic(Config.Instance().Topic);
//This seems to be a bug. Dont 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 = subscriptionService.create(subscription);
notificationId = subscriptionCreated.getNotificationId();
subscriptionId = subscriptionCreated.getId();
Config.Instance().NotificationId = notificationId;
}catch (SubscriptionException e){
System.out.println("Subscription exception inner response : " + e.getHttpResponse());
throw e;
}
}
@Override
protected void deleteResource() throws Exception {
subscriptionService.delete(subscriptionId);
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment