Replaced all tabs with spaces in java and pom.xml
[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 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.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.boot.test.context.SpringBootTest;
35 import org.springframework.boot.test.web.client.TestRestTemplate;
36 import org.springframework.boot.web.server.LocalServerPort;
37 import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock;
38 import org.springframework.core.env.Environment;
39 import org.springframework.test.context.ActiveProfiles;
40 import org.springframework.test.context.ContextConfiguration;
41 import org.springframework.test.context.junit4.SpringRunner;
42 import com.github.tomakehurst.wiremock.WireMockServer;
43 import com.github.tomakehurst.wiremock.client.WireMock;
44
45 @RunWith(SpringRunner.class)
46 @SpringBootTest(classes = ApiHandlerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
47 @ActiveProfiles("test")
48 @ContextConfiguration
49 @Transactional
50 @AutoConfigureWireMock(port = 0)
51 public abstract class BaseTest {
52     protected Logger logger = LoggerFactory.getLogger(BaseTest.class);
53     protected TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
54
55     @Autowired
56     protected Environment env;
57
58     @LocalServerPort
59     private int port;
60
61     @Autowired
62     protected WireMockServer wireMockServer;
63
64     protected String createURLWithPort(String uri) {
65         return "http://localhost:" + port + uri;
66     }
67
68     protected String createURLWithPort(String uri, int iPort) {
69         return "http://localhost:" + iPort + uri;
70     }
71
72     @After
73     public void tearDown() {
74         wireMockServer.resetAll();
75     }
76
77     public static String getResponseTemplate;
78     public static String getResponseTemplateNoBody;
79     public static String infraActivePost;
80
81     @BeforeClass
82     public static void setupTest() throws Exception {
83         getResponseTemplate = new String(Files
84                 .readAllBytes(Paths.get("src/test/resources/__files/InfraActiveRequests/getInfraActiveRequest.json")));
85         getResponseTemplateNoBody = new String(Files.readAllBytes(
86                 Paths.get("src/test/resources/__files/InfraActiveRequests/getInfraActiveRequestNoBody.json")));
87         infraActivePost = new String(Files.readAllBytes(
88                 Paths.get("src/test/resources/__files/InfraActiveRequests/createInfraActiveRequests.json")));
89     }
90
91     public String getTestUrl(String requestId) {
92         return "/infraActiveRequests/" + requestId;
93     }
94 }