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;
27 import javax.transaction.Transactional;
28 import org.junit.After;
29 import org.junit.BeforeClass;
30 import org.junit.runner.RunWith;
31 import org.onap.so.db.request.client.RequestsDbClient;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.boot.test.context.SpringBootTest;
36 import org.springframework.boot.test.mock.mockito.SpyBean;
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;
44 import com.github.tomakehurst.wiremock.WireMockServer;
45 import com.github.tomakehurst.wiremock.client.WireMock;
47 @RunWith(SpringRunner.class)
48 @SpringBootTest(classes = ApiHandlerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
49 @ActiveProfiles("test")
52 @AutoConfigureWireMock(port = 0)
53 public abstract class BaseTest {
54 protected Logger logger = LoggerFactory.getLogger(BaseTest.class);
55 protected TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
58 protected RequestsDbClient requestsDbClient;
61 protected Environment env;
67 protected WireMockServer wireMockServer;
69 protected String createURLWithPort(String uri) {
70 return "http://localhost:" + port + uri;
73 protected String createURLWithPort(String uri, int iPort) {
74 return "http://localhost:" + iPort + uri;
78 public void tearDown() {
79 wireMockServer.resetAll();
82 public static String getResponseTemplate;
83 public static String getResponseTemplateNoBody;
84 public static String infraActivePost;
87 public static void setupTest() throws Exception {
88 getResponseTemplate = new String(Files
89 .readAllBytes(Paths.get("src/test/resources/__files/InfraActiveRequests/getInfraActiveRequest.json")));
90 getResponseTemplateNoBody = new String(Files.readAllBytes(
91 Paths.get("src/test/resources/__files/InfraActiveRequests/getInfraActiveRequestNoBody.json")));
92 infraActivePost = new String(Files.readAllBytes(
93 Paths.get("src/test/resources/__files/InfraActiveRequests/createInfraActiveRequests.json")));
96 public String getTestUrl(String requestId) {
97 return "/infraActiveRequests/" + requestId;