Springboot 2.0 upgrade
[so.git] / mso-api-handlers / mso-api-handler-infra / src / test / java / org / onap / so / apihandlerinfra / BaseTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.apihandlerinfra;
22
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.web.server.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;
45
46 import javax.transaction.Transactional;
47
48 import java.nio.file.Files;
49 import java.nio.file.Paths;
50
51 @RunWith(SpringRunner.class)
52 @SpringBootTest(classes = ApiHandlerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
53 @ActiveProfiles("test")
54 @ContextConfiguration
55 @Transactional
56 @AutoConfigureWireMock(port = 0)
57 public abstract class BaseTest {
58         protected MsoLogger logger = MsoLogger.getMsoLogger(Catalog.GENERAL, BaseTest.class);
59         protected TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
60
61         @Autowired
62         protected Environment env;
63
64         @LocalServerPort
65         private int port;
66         
67         protected String createURLWithPort(String uri) {
68                 return "http://localhost:" + port + uri;
69         }
70         
71         @After
72         public void tearDown(){
73                 WireMock.reset();
74         }
75
76         public static String getResponseTemplate;
77         public static String getResponseTemplateNoBody;
78         public static String infraActivePost;
79         @BeforeClass
80         public static void setupTest() throws Exception {
81                 getResponseTemplate = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/InfraActiveRequests/getInfraActiveRequest.json")));
82                 getResponseTemplateNoBody = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/InfraActiveRequests/getInfraActiveRequestNoBody.json")));
83                 infraActivePost = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/InfraActiveRequests/createInfraActiveRequests.json")));
84         }
85
86         public String getTestUrl(String requestId) {
87                 return "/infraActiveRequests/" + requestId;
88         }
89 }