aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorNicolasLaplaud <nicolas.laplaud@orange.com>2018-09-07 16:18:11 +0200
committerMatthieuGeerebaert <matthieu.geerebaert@orange.com>2018-09-12 16:52:30 +0200
commitd04ad9a5abd23a93e948ebac2cbe5ae1925e2099 (patch)
tree007324164767c6d5efd4d75e66d92176322e70ff /src/test
parent5bfec6934fc307aecadca43e75b3c04d647bf005 (diff)
Add HubRessource Test
- Improve junit test coverage on HubResource method Change-Id: I90e96ed57b4cb781a2454ac26953f5384a60c032 Issue-ID: EXTAPI-135 Signed-off-by: NicolasLaplaud <nicolas.laplaud@orange.com>
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/onap/nbi/apis/ApiTest.java121
-rw-r--r--src/test/java/org/onap/nbi/apis/assertions/HubAssertions.java45
2 files changed, 152 insertions, 14 deletions
diff --git a/src/test/java/org/onap/nbi/apis/ApiTest.java b/src/test/java/org/onap/nbi/apis/ApiTest.java
index 489af4e..22e6200 100644
--- a/src/test/java/org/onap/nbi/apis/ApiTest.java
+++ b/src/test/java/org/onap/nbi/apis/ApiTest.java
@@ -16,8 +16,6 @@
package org.onap.nbi.apis;
-import static org.assertj.core.api.Assertions.assertThat;
-
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.http.ResponseDefinition;
import com.github.tomakehurst.wiremock.stubbing.ListStubMappingsResult;
@@ -30,25 +28,22 @@ import java.util.Set;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
+
+import org.junit.*;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.onap.nbi.apis.assertions.HubAssertions;
import org.onap.nbi.apis.assertions.ServiceCatalogAssertions;
import org.onap.nbi.apis.assertions.ServiceInventoryAssertions;
import org.onap.nbi.apis.assertions.ServiceOrderAssertions;
+import org.onap.nbi.apis.hub.HubResource;
+import org.onap.nbi.apis.hub.model.Subscriber;
+import org.onap.nbi.apis.hub.model.Subscription;
+import org.onap.nbi.apis.hub.service.SubscriptionService;
import org.onap.nbi.apis.servicecatalog.ServiceSpecificationResource;
import org.onap.nbi.apis.serviceinventory.ServiceInventoryResource;
import org.onap.nbi.apis.serviceorder.ServiceOrderResource;
-import org.onap.nbi.apis.serviceorder.model.ActionType;
-import org.onap.nbi.apis.serviceorder.model.RelatedParty;
-import org.onap.nbi.apis.serviceorder.model.Service;
-import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
-import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem;
-import org.onap.nbi.apis.serviceorder.model.ServiceSpecificationRef;
-import org.onap.nbi.apis.serviceorder.model.StateType;
+import org.onap.nbi.apis.serviceorder.model.*;
import org.onap.nbi.apis.serviceorder.model.orchestrator.ExecutionTask;
import org.onap.nbi.apis.serviceorder.repositories.ExecutionTaskRepository;
import org.onap.nbi.apis.serviceorder.repositories.ServiceOrderRepository;
@@ -57,9 +52,15 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.ResponseEntity;
+import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
+import org.springframework.web.context.request.RequestAttributes;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@@ -82,6 +83,12 @@ public class ApiTest {
ServiceOrderResource serviceOrderResource;
@Autowired
+ HubResource hubResource;
+
+ @Autowired
+ SubscriptionService subscriptionService;
+
+ @Autowired
ServiceOrderRepository serviceOrderRepository;
@Autowired
@@ -90,8 +97,17 @@ public class ApiTest {
@Autowired
SOTaskProcessor SoTaskProcessor;
+ @Mock
+ private RequestAttributes attrs;
+
static Validator validator;
+ @Before
+ public void before() {
+ MockHttpServletRequest request = new MockHttpServletRequest();
+ RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
+ }
+
@BeforeClass
public static void setUp() throws Exception {
wireMockServer.start();
@@ -109,6 +125,7 @@ public class ApiTest {
public void tearsDownUpPort() throws Exception {
executionTaskRepository.deleteAll();
serviceOrderRepository.deleteAll();
+ subscriptionService.deleteAll();
wireMockServer.resetToDefaultMappings();
}
@@ -1229,6 +1246,82 @@ public class ApiTest {
}
+ // hub
+
+ @Test
+ public void testFindWhenNoSubscriber() throws Exception {
+ ResponseEntity<Object> findResponseEntity = hubResource.findSubscribers(new LinkedMultiValueMap<>());
+ assertThat(findResponseEntity.getStatusCodeValue()).isEqualTo(200);
+ ArrayList subscribers = (ArrayList) findResponseEntity.getBody();
+ assertThat(subscribers.size()).isEqualTo(0);
+ }
+
+ @Test
+ public void testSubscriberCreation() throws Exception {
+ ResponseEntity<Subscriber> firstCreationResponseEntity = hubResource
+ .createEventSubscription(HubAssertions.createServiceOrderCreationSubscription());
+ assertThat(firstCreationResponseEntity.getStatusCodeValue()).isEqualTo(201);
+ assertThat(firstCreationResponseEntity.getHeaders().getLocation()).isNotNull();
+ assertThat(subscriptionService.countSubscription()).isEqualTo(1);
+ }
+
+ @Test
+ public void testCreationAndFindSubscriber() throws Exception {
+ ResponseEntity<Subscriber> firstCreationResponseEntity = hubResource
+ .createEventSubscription(HubAssertions.createServiceOrderCreationSubscription());
+ ResponseEntity<Object> findResponseEntity = hubResource.findSubscribers(new LinkedMultiValueMap<>());
+ ArrayList subscribers = (ArrayList) findResponseEntity.getBody();
+ assertThat(subscribers.size()).isEqualTo(1);
+ }
+
+ @Test
+ public void testCreationAndGetByIdSubscriber() throws Exception {
+ ResponseEntity<Subscriber> createResponseEntity = hubResource
+ .createEventSubscription(HubAssertions.createServiceOrderCreationSubscription());
+ String resourceId = createResponseEntity.getHeaders().getLocation().getPath().substring(1);
+ ResponseEntity<Subscription> getResponseEntity = hubResource.getSubscription(resourceId);
+ assertThat(getResponseEntity.getStatusCodeValue()).isEqualTo(200);
+ assertThat(getResponseEntity.getBody()).isInstanceOf(Subscription.class);
+ }
+
+ @Test
+ public void testMultiCreationAndFindSubscriber() throws Exception {
+ hubResource.createEventSubscription(HubAssertions.createServiceOrderCreationSubscription());
+ hubResource.createEventSubscription(HubAssertions.createServiceOrderStateChangeSubscription());
+ hubResource.createEventSubscription(HubAssertions.createServiceOrderItemStateChangeSubscription());
+
+ ResponseEntity<Object> findAllResponseEntity = hubResource.findSubscribers(new LinkedMultiValueMap<>());
+ ArrayList subscribers = (ArrayList) findAllResponseEntity.getBody();
+ assertThat(subscribers.size()).isEqualTo(3);
+ }
+
+ @Test
+ public void testMultiCreationAndFindWithFilteringSubscriber() throws Exception {
+ hubResource.createEventSubscription(HubAssertions.createServiceOrderCreationSubscription());
+ hubResource.createEventSubscription(HubAssertions.createServiceOrderStateChangeSubscription());
+ hubResource.createEventSubscription(HubAssertions.createServiceOrderItemStateChangeSubscription());
+ MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
+ params.add("query.eventType", "ServiceOrderCreationNotification");
+ ResponseEntity<Object> findWithFilterResponseEntity = hubResource.findSubscribers(params);
+ ArrayList subscribers = (ArrayList) findWithFilterResponseEntity.getBody();
+ assertThat(subscribers.size()).isEqualTo(1);
+ }
+ @Test
+ public void testSubscriberDeletion() throws Exception {
+ ResponseEntity<Subscriber> createResponseEntity = hubResource
+ .createEventSubscription(HubAssertions.createServiceOrderCreationSubscription());
+ String resourceId = createResponseEntity.getHeaders().getLocation().getPath().substring(1);
+
+ ResponseEntity<Object> findResponseEntity = hubResource.findSubscribers(new LinkedMultiValueMap<>());
+ ArrayList subscribers = (ArrayList) findResponseEntity.getBody();
+ assertThat(subscribers.size()).isEqualTo(1);
+
+ hubResource.deleteSubscription(resourceId);
+
+ findResponseEntity = hubResource.findSubscribers(new LinkedMultiValueMap<>());
+ subscribers = (ArrayList) findResponseEntity.getBody();
+ assertThat(subscribers).isEmpty();
+ }
}
diff --git a/src/test/java/org/onap/nbi/apis/assertions/HubAssertions.java b/src/test/java/org/onap/nbi/apis/assertions/HubAssertions.java
new file mode 100644
index 0000000..486c4ef
--- /dev/null
+++ b/src/test/java/org/onap/nbi/apis/assertions/HubAssertions.java
@@ -0,0 +1,45 @@
+/**
+ * Copyright (c) 2018 Orange
+ *
+ * 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.onap.nbi.apis.assertions;
+
+import org.onap.nbi.apis.hub.model.Subscription;
+
+public class HubAssertions {
+
+ public static Subscription createServiceOrderCreationSubscription(){
+ Subscription subscription = new Subscription();
+ subscription.setId("id");
+ subscription.setCallback("http://localhost:8090");
+ subscription.setQuery("eventType = ServiceOrderCreationNotification");
+ return subscription;
+ }
+
+ public static Subscription createServiceOrderStateChangeSubscription(){
+ Subscription subscription = new Subscription();
+ subscription.setId("id");
+ subscription.setCallback("http://localhost:8090");
+ subscription.setQuery("eventType = ServiceOrderStateChangeNotification");
+ return subscription;
+ }
+
+ public static Subscription createServiceOrderItemStateChangeSubscription(){
+ Subscription subscription = new Subscription();
+ subscription.setId("id");
+ subscription.setCallback("http://localhost:8090");
+ subscription.setQuery("eventType = ServiceOrderItemStateChangeNotification");
+ return subscription;
+ }
+}