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.apihandlerinfra;
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 com.github.tomakehurst.wiremock.client.WireMock;
28 import org.junit.After;
29 import org.junit.BeforeClass;
30 import org.junit.runner.RunWith;
31 import org.onap.so.logger.MsoLogger;
32 import org.onap.so.logger.MsoLogger.Catalog;
33 import org.springframework.beans.factory.annotation.Autowired;
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.core.env.Environment;
39 import org.springframework.http.HttpHeaders;
40 import org.springframework.test.context.ActiveProfiles;
41 import org.springframework.test.context.ContextConfiguration;
42 import org.springframework.test.context.jdbc.Sql;
43 import org.springframework.test.context.jdbc.Sql.ExecutionPhase;
44 import org.springframework.test.context.junit4.SpringRunner;
46 import javax.transaction.Transactional;
48 import java.nio.file.Files;
49 import java.nio.file.Paths;
51 @RunWith(SpringRunner.class)
52 @SpringBootTest(classes = ApiHandlerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
53 @ActiveProfiles("test")
56 //@Sql(executionPhase=ExecutionPhase.AFTER_TEST_METHOD,scripts="classpath:InfraActiveRequestsReset.sql")
57 @AutoConfigureWireMock(port = 0)
58 public abstract class BaseTest {
59 protected MsoLogger logger = MsoLogger.getMsoLogger(Catalog.GENERAL, BaseTest.class);
60 protected TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
63 protected Environment env;
68 protected String createURLWithPort(String uri) {
69 return "http://localhost:" + port + uri;
73 public void tearDown(){
77 public static String getResponseTemplate;
78 public static String getResponseTemplateNoBody;
79 public static String infraActivePost;
81 public static void setupTest() throws Exception {
82 getResponseTemplate = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/InfraActiveRequests/getInfraActiveRequest.json")));
83 getResponseTemplateNoBody = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/InfraActiveRequests/getInfraActiveRequestNoBody.json")));
84 infraActivePost = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/InfraActiveRequests/createInfraActiveRequests.json")));
87 public String getTestUrl(String requestId) {
88 return "/infraActiveRequests/" + requestId;