2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.adapters.vnf;
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;
43 import java.io.BufferedReader;
45 import java.io.FileReader;
46 import java.io.IOException;
48 import static com.github.tomakehurst.wiremock.client.WireMock.reset;
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;
59 @Qualifier("JettisonStyle")
60 protected TestRestTemplate restTemplate;
62 protected HttpHeaders headers = new HttpHeaders();
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();
73 protected String createURLWithPort(String uri) {
74 return "http://localhost:" + port + uri;
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();
82 while (line != null) {
97 public void testNothing(){