Containerization feature of SO
[so.git] / adapters / mso-openstack-adapters / src / test / java / org / onap / so / adapters / vnf / BaseRestTestUtils.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
21 package org.onap.so.adapters.vnf;
22
23 import com.fasterxml.jackson.core.JsonParseException;
24 import com.fasterxml.jackson.databind.JsonMappingException;
25 import com.fasterxml.jackson.databind.JsonNode;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.onap.so.adapters.openstack.MsoOpenstackAdaptersApplication;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.beans.factory.annotation.Qualifier;
33 import org.springframework.beans.factory.annotation.Value;
34 import org.springframework.boot.context.embedded.LocalServerPort;
35 import org.springframework.boot.test.context.SpringBootTest;
36 import org.springframework.boot.test.web.client.TestRestTemplate;
37 import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
38 import org.springframework.http.HttpHeaders;
39 import org.springframework.test.annotation.DirtiesContext;
40 import org.springframework.test.context.ActiveProfiles;
41 import org.springframework.test.context.junit4.SpringRunner;
42
43 import java.io.BufferedReader;
44 import java.io.File;
45 import java.io.FileReader;
46 import java.io.IOException;
47
48 import static com.github.tomakehurst.wiremock.client.WireMock.reset;
49
50 @RunWith(SpringRunner.class)
51 @SpringBootTest(classes = MsoOpenstackAdaptersApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
52 @ActiveProfiles("test")
53 @AutoConfigureWireMock(port = 0)
54 public class BaseRestTestUtils {
55         @Value("${wiremock.server.port}")
56     protected int wireMockPort;
57         
58         @Autowired
59         @Qualifier("JettisonStyle")
60         protected TestRestTemplate restTemplate;
61
62         protected HttpHeaders headers = new HttpHeaders();      
63         
64         @LocalServerPort
65         private int port;
66         
67         protected String readJsonFileAsString(String fileLocation) throws JsonParseException, JsonMappingException, IOException{
68                 ObjectMapper mapper = new ObjectMapper();
69                 JsonNode jsonNode = mapper.readTree(new File(fileLocation));
70                 return jsonNode.asText();
71         }
72         
73         protected String createURLWithPort(String uri) {
74                 return "http://localhost:" + port + uri;
75         }
76         
77         protected String readFile(String fileName) throws IOException {
78                 try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {
79                         StringBuilder sb = new StringBuilder();
80                         String line = br.readLine();
81
82                         while (line != null) {
83                                 sb.append(line);
84                                 sb.append("\n");
85                                 line = br.readLine();
86                         }
87                         return sb.toString();
88                 }
89         }
90         
91         @Before
92         public void setUp(){
93                 reset();
94         }
95         
96         @Test
97         public void testNothing(){
98                 
99         }
100
101 }