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 com.github.tomakehurst.wiremock.client.WireMock;
26 import org.junit.After;
27 import org.junit.BeforeClass;
28 import org.junit.runner.RunWith;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.boot.web.server.LocalServerPort;
33 import org.springframework.boot.test.context.SpringBootTest;
34 import org.springframework.boot.test.web.client.TestRestTemplate;
35 import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
36 import org.springframework.core.env.Environment;
37 import org.springframework.test.context.ActiveProfiles;
38 import org.springframework.test.context.ContextConfiguration;
39 import org.springframework.test.context.junit4.SpringRunner;
41 import javax.transaction.Transactional;
43 import java.nio.file.Files;
44 import java.nio.file.Paths;
46 @RunWith(SpringRunner.class)
47 @SpringBootTest(classes = ApiHandlerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
48 @ActiveProfiles("test")
51 @AutoConfigureWireMock(port = 0)
52 public abstract class BaseTest {
53 protected Logger logger = LoggerFactory.getLogger(BaseTest.class);
54 protected TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
57 protected Environment env;
62 protected String createURLWithPort(String uri) {
63 return "http://localhost:" + port + uri;
66 protected String createURLWithPort(String uri, int iPort) {
67 return "http://localhost:" + iPort + uri;
71 public void tearDown(){
75 public static String getResponseTemplate;
76 public static String getResponseTemplateNoBody;
77 public static String infraActivePost;
79 public static void setupTest() throws Exception {
80 getResponseTemplate = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/InfraActiveRequests/getInfraActiveRequest.json")));
81 getResponseTemplateNoBody = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/InfraActiveRequests/getInfraActiveRequestNoBody.json")));
82 infraActivePost = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/InfraActiveRequests/createInfraActiveRequests.json")));
85 public String getTestUrl(String requestId) {
86 return "/infraActiveRequests/" + requestId;