force nbi generate id of serviceorder
[externalapi/nbi.git] / src / test / java / org / onap / nbi / test / 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.test;
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.ServiceOrderExecutionTaskAssertions;
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.annotation.DirtiesContext;
43 import org.springframework.test.annotation.DirtiesContext.ClassMode;
44 import org.springframework.test.context.ActiveProfiles;
45 import org.springframework.test.context.junit4.SpringRunner;
46 import org.springframework.util.LinkedMultiValueMap;
47 import org.springframework.util.MultiValueMap;
48
49 @ActiveProfiles("test")
50 @RunWith(SpringRunner.class)
51 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
52 @DirtiesContext(classMode= ClassMode.AFTER_CLASS)
53 public class ApiTestWithoutOnap {
54
55
56     @Autowired
57     ServiceOrderRepository serviceOrderRepository;
58
59     @Autowired
60     ExecutionTaskRepository executionTaskRepository;
61
62     @Autowired
63     SOTaskProcessor SoTaskProcessor;
64
65     @Autowired
66     ServiceSpecificationResource serviceSpecificationResource;
67
68     @Autowired
69     ServiceInventoryResource serviceInventoryResource;
70
71     @Autowired
72     ServiceOrderResource serviceOrderResource;
73
74     @After
75     public void tearsDownUpPort() throws Exception {
76         executionTaskRepository.deleteAll();
77         serviceOrderRepository.deleteAll();
78     }
79
80
81     public ExecutionTask getExecutionTask(String orderItemId) {
82         for (ExecutionTask executionTask : executionTaskRepository.findAll()) {
83             if (executionTask.getOrderItemId().equalsIgnoreCase(orderItemId)) {
84                 return executionTask;
85             }
86
87         }
88         return null;
89     }
90
91
92
93     @Test
94     public void testExecutionTaskWithoutOnap() throws Exception {
95
96         ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository,
97             executionTaskRepository, ActionType.ADD);
98
99         SoTaskProcessor.processOrderItem(executionTaskA);
100         ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
101         assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED);
102         for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) {
103                 assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED);
104         }
105         assertThat(serviceOrderChecked.getOrderMessage().size()).isGreaterThan(0);
106         assertThat(serviceOrderChecked.getOrderMessage().get(0).getCode()).isEqualTo("502");
107         assertThat(serviceOrderChecked.getOrderMessage().get(0).getMessageInformation()).isEqualTo("Problem with SO API");
108
109         assertThat(executionTaskRepository.count()).isEqualTo(0);
110     }
111
112
113     @Test
114     public void testCheckServiceOrderWithSDCNotResponding() throws Exception {
115
116         ServiceOrder testServiceOrder = ServiceOrderExecutionTaskAssertions.createTestServiceOrder(ActionType.ADD);
117         List<RelatedParty> customers = new ArrayList<>();
118         RelatedParty customer = new RelatedParty();
119         customer.setId("new");
120         customer.setRole("ONAPcustomer");
121         customer.setName("romain");
122         customers.add(customer);
123         testServiceOrder.setRelatedParty(customers);
124         testServiceOrder.setState(StateType.ACKNOWLEDGED);
125         testServiceOrder.setId("test");
126         serviceOrderRepository.save(testServiceOrder);
127
128         serviceOrderResource.checkServiceOrder(testServiceOrder);
129
130         ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test");
131         assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.REJECTED);
132
133         assertThat(serviceOrderChecked.getOrderMessage().size()).isGreaterThan(0);
134         assertThat(serviceOrderChecked.getOrderMessage().get(0).getCode()).isEqualTo("500");
135         assertThat(serviceOrderChecked.getOrderMessage().get(0).getMessageInformation()).isEqualTo("Problem with SDC API");
136     }
137
138
139
140     @Test
141     public void testServiceCatalogGetResource() throws Exception {
142
143         ResponseEntity<Object> resource = serviceSpecificationResource
144             .getServiceSpecification("1e3feeb0-8e36-46c6-862c-236d9c626439", null);
145         assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
146
147
148     }
149
150
151
152     @Test
153     public void testServiceResourceGetInventory() throws Exception {
154
155         String serviceName = "vFW";
156         String serviceId = "e4688e5f-61a0-4f8b-ae02-a2fbde623bcb";
157         MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
158         params.add("serviceSpecification.name", serviceName);
159         params.add("relatedParty.id", "6490");
160         ResponseEntity<Object> resource = serviceInventoryResource.getServiceInventory(serviceId, params);
161         assertThat(resource.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
162
163
164     }
165
166
167
168
169 }