Removed MsoLogger from 'mso-api-handlers'
[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  * 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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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=========================================================
21  */
22
23 package org.onap.so.apihandlerinfra;
24
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;
40
41 import javax.transaction.Transactional;
42
43 import java.nio.file.Files;
44 import java.nio.file.Paths;
45
46 @RunWith(SpringRunner.class)
47 @SpringBootTest(classes = ApiHandlerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
48 @ActiveProfiles("test")
49 @ContextConfiguration
50 @Transactional
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");
55
56         @Autowired
57         protected Environment env;
58
59         @LocalServerPort
60         private int port;
61         
62         protected String createURLWithPort(String uri) {
63                 return "http://localhost:" + port + uri;
64         }
65         
66         protected String createURLWithPort(String uri, int iPort) {
67                 return "http://localhost:" + iPort + uri;
68         }       
69         
70         @After
71         public void tearDown(){
72                 WireMock.reset();
73         }
74
75         public static String getResponseTemplate;
76         public static String getResponseTemplateNoBody;
77         public static String infraActivePost;
78         @BeforeClass
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")));
83         }
84
85         public String getTestUrl(String requestId) {
86                 return "/infraActiveRequests/" + requestId;
87         }
88 }