782c39a31c8bf0d2c6e0db55ddfb7c99e7c62180
[externalapi/nbi.git] / src / test / java / org / onap / nbi / apis / ApiTestWithoutOnap.java
1 /**
2  *     Copyright (c) 2018 Orange
3  *
4  *     Licensed under the Apache License, Version 2.0 (the "License");
5  *     you may not use this file except in compliance with the License.
6  *     You may obtain a copy of the License at
7  *
8  *         http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *     Unless required by applicable law or agreed to in writing, software
11  *     distributed under the License is distributed on an "AS IS" BASIS,
12  *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *     See the License for the specific language governing permissions and
14  *     limitations under the License.
15  */
16 package org.onap.nbi.apis;
17
18 import static org.assertj.core.api.Assertions.assertThat;
19
20 import java.util.ArrayList;
21 import java.util.List;
22 import org.junit.After;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.onap.nbi.apis.assertions.ServiceOrderAssertions;
26 import org.onap.nbi.apis.servicecatalog.ServiceSpecificationResource;
27 import org.onap.nbi.apis.serviceinventory.ServiceInventoryResource;
28 import org.onap.nbi.apis.serviceorder.ServiceOrderResource;
29 import org.onap.nbi.apis.serviceorder.model.ActionType;
30 import org.onap.nbi.apis.serviceorder.model.RelatedParty;
31 import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
32 import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem;
33 import org.onap.nbi.apis.serviceorder.model.StateType;
34 import org.onap.nbi.apis.serviceorder.model.orchestrator.ExecutionTask;
35 import org.onap.nbi.apis.serviceorder.repositories.ExecutionTaskRepository;
36 import org.onap.nbi.apis.serviceorder.repositories.ServiceOrderRepository;
37 import org.onap.nbi.apis.serviceorder.workflow.SOTaskProcessor;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.boot.test.context.SpringBootTest;
40 import org.springframework.http.HttpStatus;
41 import org.springframework.http.ResponseEntity;
42 import org.springframework.test.context.junit4.SpringRunner;
43 import org.springframework.util.LinkedMultiValueMap;
44 import org.springframework.util.MultiValueMap;
45
46 @RunWith(SpringRunner.class)
47 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
48 public class ApiTestWithoutOnap {
49
50
51     @Autowired
52     ServiceOrderRepository serviceOrderRepository;
53
54     @Autowired
55     ExecutionTaskRepository executionTaskRepository;
56
57     @Autowired
58     SOTaskProcessor SoTaskProcessor;
59
60     @Autowired
61     ServiceSpecificationResource serviceSpecificationResource;
62
63     @Autowired
64     ServiceInventoryResource serviceInventoryResource;
65
66     @Autowired
67     ServiceOrderResource serviceOrderResource;
68
69     @After
70     public void tearsDownUpPort() throws Exception {
71         executionTaskRepository.deleteAll();
72         serviceOrderRepository.deleteAll();
73     }
74
75
76     public ExecutionTask getExecutionTask(String orderItemId) {
77         for (ExecutionTask executionTask : executionTaskRepository.findAll()) {
78             if (executionTask.getOrderItemId().equalsIgnoreCase(orderItemId)) {
79                 return executionTask;
80             }
81
82         }
83         return null;
84     }
85
86
87
88     @Test
89     public void testExecutionTaskWithoutOnap() throws Exception {
90
91         ExecutionTask executionTaskA = ServiceOrderAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
92             executionTaskRepository, ActionType.ADD);
93
94         SoTaskProcessor.processOrderItem(executionTaskA);
95         ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
96         assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED);
97         for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
98                 assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED);
99         }
100         assertThat(serviceOrderChecked.getOrderMessage().size()).isGreaterThan(0);
101         assertThat(serviceOrderChecked.getOrderMessage().get(0).getCode()).isEqualTo("502");
102         assertThat(serviceOrderChecked.getOrderMessage().get(0).getMessageInformation()).isEqualTo("Problem with SO API");
103
104         assertThat(executionTaskRepository.count()).isEqualTo(0);
105     }
106
107
108     @Test
109     public void testCheckServiceOrderWithSDCNotResponding() throws Exception {
110
111         ServiceOrder testServiceOrder = ServiceOrderAssertions.createTestServiceOrder(ActionType.ADD);
112         List<RelatedParty> customers = new ArrayList<>();
113         RelatedParty customer = new RelatedParty();
114         customer.setId("new");
115         customer.setRole("ONAPcustomer");
116         customer.setName("romain");
117         customers.add(customer);
118         testServiceOrder.setRelatedParty(customers);
119         testServiceOrder.setState(StateType.ACKNOWLEDGED);
120         testServiceOrder.setId("test");
121         serviceOrderRepository.save(testServiceOrder);
122
123         serviceOrderResource.scheduleCheckServiceOrders();
124
125         ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
126         assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.REJECTED);
127
128         assertThat(serviceOrderChecked.getOrderMessage().size()).isGreaterThan(0);
129         assertThat(serviceOrderChecked.getOrderMessage().get(0).getCode()).isEqualTo("500");
130         assertThat(serviceOrderChecked.getOrderMessage().get(0).getMessageInformation()).isEqualTo("Problem with SDC API");
131     }
132
133
134
135     @Test
136     public void testServiceCatalogGetResource() throws Exception {
137
138         ResponseEntity<Object> resource = serviceSpecificationResource
139             .getServiceSpecification("1e3feeb0-8e36-46c6-862c-236d9c626439", null);
140         assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
141
142
143     }
144
145
146
147     @Test
148     public void testServiceResourceGetInventory() throws Exception {
149
150         String serviceName = "vFW";
151         String serviceId = "e4688e5f-61a0-4f8b-ae02-a2fbde623bcb";
152         MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
153         params.add("serviceSpecification.name", serviceName);
154         params.add("relatedParty.id", "6490");
155         ResponseEntity<Object> resource = serviceInventoryResource.getServiceInventory(serviceId, params);
156         assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
157
158     }
159
160
161
162
163 }