Replaced all tabs with spaces in java and pom.xml
[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.SniroHomingV2;
27 import org.onap.so.bpmn.common.data.TestDataSetup;
28 import org.onap.so.client.appc.ApplicationControllerAction;
29 import org.onap.so.client.orchestration.SDNOHealthCheckResources;
30 import org.onap.so.client.sdnc.SDNCClient;
31 import org.onap.so.client.sniro.SniroClient;
32 import org.onap.so.db.catalog.client.CatalogDbClient;
33 import org.springframework.beans.factory.annotation.Autowired;
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 import com.github.tomakehurst.wiremock.WireMockServer;
43
44 @RunWith(SpringRunner.class)
45 @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
46 @ActiveProfiles("test")
47 @ContextConfiguration
48 @AutoConfigureWireMock(port = 0)
49 public abstract class BaseIntegrationTest extends TestDataSetup {
50
51     @Value("${wiremock.server.port}")
52     protected String wireMockPort;
53
54     @SpyBean
55     protected SDNCClient SPY_sdncClient;
56
57     @SpyBean
58     protected SDNOHealthCheckResources MOCK_sdnoHealthCheckResources;
59
60     @SpyBean
61     protected SniroHomingV2 sniroHoming;
62
63     @SpyBean
64     protected SniroClient sniroClient;
65
66     @MockBean
67     protected ApplicationControllerAction appCClient;
68
69     @MockBean
70     protected CatalogDbClient catalogDbClient;
71
72     @Autowired
73     protected WireMockServer wireMockServer;
74
75     @Before
76     public void baseTestBefore() {
77         wireMockServer.resetAll();
78     }
79
80     public String readResourceFile(String fileName) {
81         InputStream stream;
82         try {
83             stream = getResourceAsStream(fileName);
84             byte[] bytes;
85             bytes = new byte[stream.available()];
86             if (stream.read(bytes) > 0) {
87                 stream.close();
88                 return new String(bytes);
89             } else {
90                 stream.close();
91                 return "";
92             }
93         } catch (IOException e) {
94             return "";
95         }
96     }
97
98     private InputStream getResourceAsStream(String resourceName) throws IOException {
99         InputStream stream = FileUtil.class.getClassLoader().getResourceAsStream(resourceName);
100         if (stream == null) {
101             throw new IOException("Can't access resource '" + resourceName + "'");
102         }
103         return stream;
104     }
105 }
106
107