Refactor SOL003 Adapter to organize its modules
[so.git] / adapters / etsi-sol003-adapter / etsi-sol003-package-management / etsi-sol003-package-management-adapter / src / test / java / org / onap / so / adapters / vnfmadapter / rest / EtsiSubscriptionNotificationControllerTest.java
@@ -22,10 +22,13 @@ package org.onap.so.adapters.vnfmadapter.rest;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
-import static org.onap.so.adapters.vnfmadapter.Constants.ETSI_SUBSCRIPTION_NOTIFICATION_CONTROLLER_BASE_URL;
+import static org.onap.so.adapters.vnfmadapter.common.CommonConstants.ETSI_SUBSCRIPTION_NOTIFICATION_CONTROLLER_BASE_URL;
 import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE;
 import static org.springframework.test.annotation.DirtiesContext.ClassMode.BEFORE_CLASS;
-import static org.springframework.test.web.client.match.MockRestRequestMatchers.*;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.header;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.jsonPath;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
 import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
 import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
 import java.net.URI;
@@ -36,17 +39,16 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.onap.so.adapters.vnfmadapter.Constants;
-import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication;
+import org.onap.so.adapters.vnfmadapter.PackageManagementConstants;
 import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.ProblemDetails;
-import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.notification.model.NOTIFICATIONLINKSERIALIZER;
-import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.notification.model.PkgChangeNotification;
-import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.notification.model.PkgOnboardingNotification;
-import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.notification.model.PkgmLinks;
-import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.PkgmSubscriptionRequest;
-import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsAuthentication;
-import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsAuthenticationParamsBasic;
-import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsAuthenticationParamsOauth2ClientCredentials;
+import org.onap.so.adapters.vnfmadapter.etsicatalog.notification.model.NOTIFICATIONLINKSERIALIZER;
+import org.onap.so.adapters.vnfmadapter.etsicatalog.notification.model.PkgChangeNotification;
+import org.onap.so.adapters.vnfmadapter.etsicatalog.notification.model.PkgOnboardingNotification;
+import org.onap.so.adapters.vnfmadapter.etsicatalog.notification.model.PkgmLinks;
+import org.onap.so.adapters.vnfmadapter.packagemanagement.model.PkgmSubscriptionRequest;
+import org.onap.so.adapters.vnfmadapter.packagemanagement.model.SubscriptionsAuthentication;
+import org.onap.so.adapters.vnfmadapter.packagemanagement.model.SubscriptionsAuthenticationParamsBasic;
+import org.onap.so.adapters.vnfmadapter.packagemanagement.model.SubscriptionsAuthenticationParamsOauth2ClientCredentials;
 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.notification.model.VnfPackageChangeNotification;
 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.notification.model.VnfPackageOnboardingNotification;
 import org.onap.so.configuration.rest.BasicHttpHeadersProvider;
@@ -57,7 +59,11 @@ import org.springframework.boot.test.web.client.TestRestTemplate;
 import org.springframework.boot.web.server.LocalServerPort;
 import org.springframework.cache.Cache;
 import org.springframework.cache.CacheManager;
-import org.springframework.http.*;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
 import org.springframework.test.annotation.DirtiesContext;
 import org.springframework.test.context.ActiveProfiles;
 import org.springframework.test.context.junit4.SpringRunner;
@@ -74,7 +80,7 @@ import com.google.gson.GsonBuilder;
  *
  */
 @RunWith(SpringRunner.class)
-@SpringBootTest(classes = VnfmAdapterApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
 @ActiveProfiles("test")
 @DirtiesContext(classMode = BEFORE_CLASS)
 public class EtsiSubscriptionNotificationControllerTest {
@@ -106,7 +112,7 @@ public class EtsiSubscriptionNotificationControllerTest {
     @Autowired
     @Qualifier(CONFIGURABLE_REST_TEMPLATE)
     private RestTemplate restTemplate;
-    private MockRestServiceServer mockRestServer;
+    private MockRestServiceServer mockRestServiceServer;
 
     @Autowired
     private TestRestTemplate testRestTemplate;
@@ -117,14 +123,15 @@ public class EtsiSubscriptionNotificationControllerTest {
 
     @Before
     public void setUp() {
-        mockRestServer = MockRestServiceServer.bindTo(restTemplate).build();
+        mockRestServiceServer = MockRestServiceServer.bindTo(restTemplate).build();
         basicHttpHeadersProvider = new BasicHttpHeadersProvider();
-        cache = cacheServiceProvider.getCache(Constants.PACKAGE_MANAGEMENT_SUBSCRIPTION_CACHE);
+        cache = cacheServiceProvider.getCache(PackageManagementConstants.PACKAGE_MANAGEMENT_SUBSCRIPTION_CACHE);
         cache.clear();
     }
 
     @After
     public void tearDown() {
+        mockRestServiceServer.reset();
         cache.clear();
     }
 
@@ -142,7 +149,7 @@ public class EtsiSubscriptionNotificationControllerTest {
         final PkgOnboardingNotification notification = buildPkgOnboardingNotification();
         final String notificationString = gson.toJson(notification);
 
-        mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+        mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
                 .andExpect(jsonPath("$.id").value(NOTIFICATION_ID))
                 .andExpect(jsonPath("$.notificationType")
                         .value(VnfPackageOnboardingNotification.NotificationTypeEnum.VNFPACKAGEONBOARDINGNOTIFICATION
@@ -183,7 +190,7 @@ public class EtsiSubscriptionNotificationControllerTest {
         final PkgOnboardingNotification notification = buildPkgOnboardingNotification();
         final String notificationString = gson.toJson(notification);
 
-        mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+        mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
                 .andRespond(withStatus(HttpStatus.BAD_REQUEST));
 
         final ResponseEntity<?> response = sendHttpPost(notificationString);
@@ -206,7 +213,7 @@ public class EtsiSubscriptionNotificationControllerTest {
         final PkgOnboardingNotification notification = buildPkgOnboardingNotification();
         final String notificationString = gson.toJson(notification);
 
-        mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+        mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
                 .andRespond(withStatus(HttpStatus.MOVED_PERMANENTLY));
 
         final ResponseEntity<?> response = sendHttpPost(notificationString);
@@ -228,7 +235,7 @@ public class EtsiSubscriptionNotificationControllerTest {
         final PkgOnboardingNotification notification = buildPkgOnboardingNotification();
         final String notificationString = gson.toJson(notification);
 
-        mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+        mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
                 .andRespond(withStatus(HttpStatus.NOT_FOUND));
 
         final ResponseEntity<?> response = sendHttpPost(notificationString);
@@ -251,7 +258,7 @@ public class EtsiSubscriptionNotificationControllerTest {
         final PkgOnboardingNotification notification = buildPkgOnboardingNotification();
         final String notificationString = gson.toJson(notification);
 
-        mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+        mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
                 .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
 
         final ResponseEntity<?> response = sendHttpPost(notificationString);
@@ -275,7 +282,7 @@ public class EtsiSubscriptionNotificationControllerTest {
         final PkgChangeNotification notification = buildPkgChangeNotification();
         final String notificationString = gson.toJson(notification);
 
-        mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+        mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
                 .andExpect(jsonPath("$.id").value(NOTIFICATION_ID))
                 .andExpect(jsonPath("$.notificationType").value(
                         VnfPackageChangeNotification.NotificationTypeEnum.VNFPACKAGECHANGENOTIFICATION.getValue()))
@@ -319,7 +326,7 @@ public class EtsiSubscriptionNotificationControllerTest {
         final PkgChangeNotification notification = buildPkgChangeNotification();
         final String notificationString = gson.toJson(notification);
 
-        mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+        mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
                 .andRespond(withStatus(HttpStatus.BAD_REQUEST));
 
         final ResponseEntity<?> response = sendHttpPost(notificationString);
@@ -342,7 +349,7 @@ public class EtsiSubscriptionNotificationControllerTest {
         final PkgChangeNotification notification = buildPkgChangeNotification();
         final String notificationString = gson.toJson(notification);
 
-        mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+        mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
                 .andRespond(withStatus(HttpStatus.NOT_FOUND));
 
         final ResponseEntity<?> response = sendHttpPost(notificationString);
@@ -365,7 +372,7 @@ public class EtsiSubscriptionNotificationControllerTest {
         final PkgChangeNotification notification = buildPkgChangeNotification();
         final String notificationString = gson.toJson(notification);
 
-        mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+        mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
                 .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
 
         final ResponseEntity<?> response = sendHttpPost(notificationString);
@@ -389,7 +396,7 @@ public class EtsiSubscriptionNotificationControllerTest {
         final PkgOnboardingNotification notification = buildPkgOnboardingNotification();
         final String notificationString = gson.toJson(notification);
 
-        mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+        mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
                 .andExpect(jsonPath("$.id").value(NOTIFICATION_ID))
                 .andExpect(jsonPath("$.notificationType")
                         .value(VnfPackageOnboardingNotification.NotificationTypeEnum.VNFPACKAGEONBOARDINGNOTIFICATION
@@ -414,7 +421,7 @@ public class EtsiSubscriptionNotificationControllerTest {
         final PkgChangeNotification notification = buildPkgChangeNotification();
         final String notificationString = gson.toJson(notification);
 
-        mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+        mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
                 .andExpect(header("Authorization", EXPECTED_BASIC_AUTHORIZATION))
                 .andRespond(withStatus(HttpStatus.UNAUTHORIZED));
 
@@ -438,11 +445,11 @@ public class EtsiSubscriptionNotificationControllerTest {
         final PkgChangeNotification notification = buildPkgChangeNotification();
         final String notificationString = gson.toJson(notification);
 
-        mockRestServer.expect(requestTo(TOKEN_ENDPOINT)).andExpect(method(HttpMethod.POST))
+        mockRestServiceServer.expect(requestTo(TOKEN_ENDPOINT)).andExpect(method(HttpMethod.POST))
                 .andExpect(header("Authorization", EXPECTED_BASIC_AUTHORIZATION))
                 .andRespond(withSuccess(JSON_TOKEN, MediaType.APPLICATION_JSON));
 
-        mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+        mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
                 .andExpect(header("Authorization", EXPECTED_OAUTH_AUTHORIZATION))
                 .andExpect(jsonPath("$.id").value(NOTIFICATION_ID))
                 .andExpect(jsonPath("$.notificationType").value(
@@ -470,7 +477,7 @@ public class EtsiSubscriptionNotificationControllerTest {
         final PkgChangeNotification notification = buildPkgChangeNotification();
         final String notificationString = gson.toJson(notification);
 
-        mockRestServer.expect(requestTo(TOKEN_ENDPOINT)).andExpect(method(HttpMethod.POST))
+        mockRestServiceServer.expect(requestTo(TOKEN_ENDPOINT)).andExpect(method(HttpMethod.POST))
                 .andExpect(header("Authorization", EXPECTED_BASIC_AUTHORIZATION)).andRespond(withSuccess());
 
         final ResponseEntity<?> response = sendHttpPost(notificationString);