2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.apihandlerinfra;
25 import java.nio.file.Files;
26 import java.nio.file.Paths;
28 import javax.transaction.Transactional;
30 import org.junit.After;
31 import org.junit.BeforeClass;
32 import org.junit.runner.RunWith;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.boot.test.context.SpringBootTest;
37 import org.springframework.boot.test.web.client.TestRestTemplate;
38 import org.springframework.boot.web.server.LocalServerPort;
39 import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
40 import org.springframework.core.env.Environment;
41 import org.springframework.test.context.ActiveProfiles;
42 import org.springframework.test.context.ContextConfiguration;
43 import org.springframework.test.context.junit4.SpringRunner;
45 import com.github.tomakehurst.wiremock.WireMockServer;
46 import com.github.tomakehurst.wiremock.client.WireMock;
48 @RunWith(SpringRunner.class)
49 @SpringBootTest(classes = ApiHandlerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
50 @ActiveProfiles("test")
53 @AutoConfigureWireMock(port = 0)
54 public abstract class BaseTest {
55 protected Logger logger = LoggerFactory.getLogger(BaseTest.class);
56 protected TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
59 protected Environment env;
65 protected WireMockServer wireMockServer;
67 protected String createURLWithPort(String uri) {
68 return "http://localhost:" + port + uri;
71 protected String createURLWithPort(String uri, int iPort) {
72 return "http://localhost:" + iPort + uri;
76 public void tearDown(){
77 wireMockServer.resetAll();
80 public static String getResponseTemplate;
81 public static String getResponseTemplateNoBody;
82 public static String infraActivePost;
84 public static void setupTest() throws Exception {
85 getResponseTemplate = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/InfraActiveRequests/getInfraActiveRequest.json")));
86 getResponseTemplateNoBody = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/InfraActiveRequests/getInfraActiveRequestNoBody.json")));
87 infraActivePost = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/InfraActiveRequests/createInfraActiveRequests.json")));
90 public String getTestUrl(String requestId) {
91 return "/infraActiveRequests/" + requestId;