10/31: merge casablanca to master
[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.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.db.catalog.client.CatalogDbClient;
32 import org.springframework.boot.test.context.SpringBootTest;
33 import org.springframework.boot.test.mock.mockito.MockBean;
34 import org.springframework.boot.test.mock.mockito.SpyBean;
35 import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
36 import org.springframework.test.context.ActiveProfiles;
37 import org.springframework.test.context.ContextConfiguration;
38 import org.springframework.test.context.junit4.SpringRunner;
39
40 @RunWith(SpringRunner.class)
41 @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
42 @ActiveProfiles("test")
43 @ContextConfiguration
44 @AutoConfigureWireMock(port = 0)
45 public abstract class BaseIntegrationTest extends TestDataSetup {
46         
47         @SpyBean
48         protected SDNCClient SPY_sdncClient;
49         
50         @SpyBean
51         protected SDNOHealthCheckResources MOCK_sdnoHealthCheckResources;
52
53         @MockBean
54         protected SniroHomingV2 sniroHoming;
55         
56         @MockBean
57         protected ApplicationControllerAction appCClient;
58         
59         
60         @MockBean
61         protected CatalogDbClient catalogDbClient;
62         
63         public String readResourceFile(String fileName) {
64                 InputStream stream;
65                 try {
66                         stream = getResourceAsStream(fileName);
67                         byte[] bytes;
68                         bytes = new byte[stream.available()];
69                         if(stream.read(bytes) > 0) {
70                                 stream.close();
71                                 return new String(bytes);
72                         } else {
73                                 stream.close();
74                                 return "";
75                         }
76                 } catch (IOException e) {                  
77                         return "";
78                 }
79         }
80
81         private  InputStream getResourceAsStream(String resourceName) throws IOException {
82                 InputStream stream =
83                                 FileUtil.class.getClassLoader().getResourceAsStream(resourceName);
84                 if (stream == null) {
85                         throw new IOException("Can't access resource '" + resourceName + "'");
86                 }
87                 return stream;
88         }       
89 }
90
91