split single and plural graph inventory uris
[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 import org.junit.Before;
25 import org.junit.runner.RunWith;
26 import org.onap.so.bpmn.buildingblock.OofHomingV2;
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.oof.OofClient;
31 import org.onap.so.client.orchestration.SDNOHealthCheckResources;
32 import org.onap.so.client.sdnc.SDNCClient;
33 import org.onap.so.client.sniro.SniroClient;
34 import org.onap.so.db.catalog.client.CatalogDbClient;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.beans.factory.annotation.Value;
37 import org.springframework.boot.test.context.SpringBootTest;
38 import org.springframework.boot.test.mock.mockito.MockBean;
39 import org.springframework.boot.test.mock.mockito.SpyBean;
40 import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
41 import org.springframework.test.context.ActiveProfiles;
42 import org.springframework.test.context.ContextConfiguration;
43 import org.springframework.test.context.junit4.SpringRunner;
44 import com.github.tomakehurst.wiremock.WireMockServer;
45
46 @RunWith(SpringRunner.class)
47 @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
48 @ActiveProfiles("test")
49 @ContextConfiguration
50 @AutoConfigureWireMock(port = 0)
51 public abstract class BaseIntegrationTest extends TestDataSetup {
52
53     @Value("${wiremock.server.port}")
54     protected String wireMockPort;
55
56     @SpyBean
57     protected SDNCClient SPY_sdncClient;
58
59     @SpyBean
60     protected SDNOHealthCheckResources MOCK_sdnoHealthCheckResources;
61
62     @SpyBean
63     protected SniroHomingV2 sniroHoming;
64
65     @SpyBean
66     protected SniroClient sniroClient;
67
68     @SpyBean
69     protected OofHomingV2 oofHoming;
70
71     @SpyBean
72     protected OofClient oofClient;
73
74     @MockBean
75     protected ApplicationControllerAction appCClient;
76
77     @MockBean
78     protected CatalogDbClient catalogDbClient;
79
80     @Autowired
81     protected WireMockServer wireMockServer;
82
83     @Before
84     public void baseTestBefore() {
85         wireMockServer.resetAll();
86     }
87
88     public String readResourceFile(String fileName) {
89         InputStream stream;
90         try {
91             stream = getResourceAsStream(fileName);
92             byte[] bytes;
93             bytes = new byte[stream.available()];
94             if (stream.read(bytes) > 0) {
95                 stream.close();
96                 return new String(bytes);
97             } else {
98                 stream.close();
99                 return "";
100             }
101         } catch (IOException e) {
102             return "";
103         }
104     }
105
106     private InputStream getResourceAsStream(String resourceName) throws IOException {
107         InputStream stream = FileUtil.class.getClassLoader().getResourceAsStream(resourceName);
108         if (stream == null) {
109             throw new IOException("Can't access resource '" + resourceName + "'");
110         }
111         return stream;
112     }
113 }
114
115