6500e3a85087ce322745ae011ed8de747ac7eb3b
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / BaseIntegrationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.onap.so;
21
22 import java.io.IOException;
23 import java.io.InputStream;
24
25 import org.junit.Before;
26 import org.junit.runner.RunWith;
27 import org.onap.so.bpmn.buildingblock.SniroHomingV2;
28 import org.onap.so.bpmn.common.data.TestDataSetup;
29 import org.onap.so.client.appc.ApplicationControllerAction;
30 import org.onap.so.client.orchestration.SDNOHealthCheckResources;
31 import org.onap.so.client.sdnc.SDNCClient;
32 import org.onap.so.client.sniro.SniroClient;
33 import org.onap.so.db.catalog.client.CatalogDbClient;
34 import org.springframework.beans.factory.annotation.Value;
35 import org.springframework.boot.test.context.SpringBootTest;
36 import org.springframework.boot.test.mock.mockito.MockBean;
37 import org.springframework.boot.test.mock.mockito.SpyBean;
38 import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
39 import org.springframework.test.context.ActiveProfiles;
40 import org.springframework.test.context.ContextConfiguration;
41 import org.springframework.test.context.junit4.SpringRunner;
42
43 import com.github.tomakehurst.wiremock.client.WireMock;
44
45 @RunWith(SpringRunner.class)
46 @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
47 @ActiveProfiles("test")
48 @ContextConfiguration
49 @AutoConfigureWireMock(port = 0)
50 public abstract class BaseIntegrationTest extends TestDataSetup {
51
52         @Value("${wiremock.server.port}")
53         protected String wireMockPort;
54
55         @SpyBean
56         protected SDNCClient SPY_sdncClient;
57
58         @SpyBean
59         protected SDNOHealthCheckResources MOCK_sdnoHealthCheckResources;
60
61         @SpyBean
62         protected SniroHomingV2 sniroHoming;
63
64         @SpyBean
65         protected SniroClient sniroClient;
66
67         @MockBean
68         protected ApplicationControllerAction appCClient;
69
70         @MockBean
71         protected CatalogDbClient catalogDbClient;
72
73         @Before
74         public void baseTestBefore() {
75                 WireMock.reset();
76         }
77         public String readResourceFile(String fileName) {
78                 InputStream stream;
79                 try {
80                         stream = getResourceAsStream(fileName);
81                         byte[] bytes;
82                         bytes = new byte[stream.available()];
83                         if(stream.read(bytes) > 0) {
84                                 stream.close();
85                                 return new String(bytes);
86                         } else {
87                                 stream.close();
88                                 return "";
89                         }
90                 } catch (IOException e) {
91                         return "";
92                 }
93         }
94
95         private  InputStream getResourceAsStream(String resourceName) throws IOException {
96                 InputStream stream =
97                                 FileUtil.class.getClassLoader().getResourceAsStream(resourceName);
98                 if (stream == null) {
99                         throw new IOException("Can't access resource '" + resourceName + "'");
100                 }
101                 return stream;
102         }
103 }
104
105