2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
23 import java.io.IOException;
24 import java.nio.charset.Charset;
25 import java.nio.file.Files;
26 import java.nio.file.Paths;
27 import java.util.HashMap;
29 import org.camunda.bpm.engine.RepositoryService;
30 import org.camunda.bpm.engine.RuntimeService;
31 import org.camunda.bpm.model.bpmn.Bpmn;
32 import org.camunda.bpm.model.bpmn.BpmnModelInstance;
33 import org.junit.Before;
34 import org.junit.runner.RunWith;
35 import org.onap.so.bpmn.buildingblock.SniroHomingV2;
36 import org.onap.so.bpmn.common.DelegateExecutionImpl;
37 import org.onap.so.bpmn.common.InjectionHelper;
38 import org.onap.so.bpmn.infrastructure.aai.tasks.AAIFlagTasks;
39 import org.onap.so.bpmn.sdno.tasks.SDNOHealthCheckTasks;
40 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup;
41 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupMapperLayer;
42 import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils;
43 import org.onap.so.client.aai.mapper.AAIObjectMapper;
44 import org.onap.so.client.adapter.network.NetworkAdapterClientImpl;
45 import org.onap.so.client.adapter.network.mapper.NetworkAdapterObjectMapper;
46 import org.onap.so.client.exception.ExceptionBuilder;
47 import org.onap.so.client.orchestration.AAIVnfResources;
48 import org.onap.so.client.orchestration.SDNOHealthCheckResources;
49 import org.onap.so.client.sdnc.SDNCClient;
50 import org.onap.so.client.sniro.SniroClient;
51 import org.onap.so.db.catalog.client.CatalogDbClient;
52 import org.springframework.beans.factory.annotation.Autowired;
53 import org.springframework.beans.factory.annotation.Value;
54 import org.springframework.boot.web.server.LocalServerPort;
55 import org.springframework.boot.test.context.SpringBootTest;
56 import org.springframework.boot.test.mock.mockito.MockBean;
57 import org.springframework.boot.test.mock.mockito.SpyBean;
58 import org.springframework.boot.test.web.client.TestRestTemplate;
59 import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
60 import org.springframework.http.HttpHeaders;
61 import org.springframework.test.context.ActiveProfiles;
62 import org.springframework.test.context.ContextConfiguration;
63 import org.springframework.test.context.junit4.SpringRunner;
64 import com.fasterxml.jackson.databind.JsonNode;
65 import com.fasterxml.jackson.databind.ObjectMapper;
67 @RunWith(SpringRunner.class)
68 @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
69 @ActiveProfiles("test")
71 @AutoConfigureWireMock(port = 0)
72 public abstract class BaseTest extends BuildingBlockTestDataSetup {
75 protected Map<String, Object> variables = new HashMap<>();
77 protected TestRestTemplate restTemplate = new TestRestTemplate();
79 protected HttpHeaders headers = new HttpHeaders();
81 @Value("${wiremock.server.port}")
82 protected String wireMockPort;
85 protected RuntimeService runtimeService;
88 private RepositoryService repositoryService;
90 * Mocked for injection via autowiring
93 @Value("${mso.catalog.db.spring.endpoint}")
94 protected String endpoint;
97 protected CatalogDbClient MOCK_catalogDbClient;
100 protected InjectionHelper MOCK_injectionHelper;
103 protected NetworkAdapterObjectMapper MOCK_networkAdapterObjectMapper;
106 protected AAIObjectMapper MOCK_aaiObjectMapper;
108 protected NetworkAdapterClientImpl MOCK_networkAdapterClient;
110 protected SDNCClient MOCK_sdncClient;
113 protected AAIFlagTasks aaiFlagTasks;
116 protected AAIVnfResources aaiVnfResources;
119 protected ExceptionBuilder exceptionUtil;
122 protected SDNOHealthCheckResources MOCK_sdnoHealthCheckResources;
127 * Classes that cannot be simply mocked because they are both needed for testing another class, and must be
128 * autowired when being tested themselves....or classes with private methods that must be stubbed during testing
134 protected BBInputSetupMapperLayer SPY_bbInputSetupMapperLayer;
136 protected BBInputSetupUtils SPY_bbInputSetupUtils;
138 protected BBInputSetup SPY_bbInputSetup;
140 protected SniroHomingV2 sniroHoming;
143 protected SniroClient sniroClient;
146 protected SDNOHealthCheckTasks sdnoHealthCheckTasks;
149 * Mocked for injection via the IntectionHelper
155 public void baseTestBefore() {
156 variables.put("gBuildingBlockExecution", new DelegateExecutionImpl(new HashMap<>()));
164 protected String readFile(String path) throws IOException {
165 return readFile(path, Charset.defaultCharset());
168 protected String readFile(String path, Charset encoding) throws IOException {
169 byte[] encoded = Files.readAllBytes(Paths.get(path));
170 return new String(encoded, encoding);
173 protected String readJsonFileAsString(String fileLocation) throws IOException {
174 ObjectMapper mapper = new ObjectMapper();
175 JsonNode jsonNode = mapper.readTree(new File(fileLocation));
176 return jsonNode.asText();
179 protected String createURLWithPort(String uri) {
180 return "http://localhost:" + port + uri;
184 * Create and deploy a process model with one logger delegate as service task.
186 * @param origProcessKey key to call
187 * @param mockProcessName process name
188 * @param fileName file name without extension
190 protected void mockSubprocess(String origProcessKey, String mockProcessName, String fileName) {
191 BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(origProcessKey).name(mockProcessName)
192 .startEvent().name("Start Point").serviceTask().name("Log Something for Test")
193 .camundaClass(MockLoggerDelegate.class.getName()).endEvent().name("End Point").done();
194 repositoryService.createDeployment().addModelInstance(fileName + ".bpmn", modelInstance).deploy();