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