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;
24 import java.io.IOException;
26 import javax.transaction.Transactional;
28 import org.junit.After;
29 import org.junit.runner.RunWith;
30 import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository;
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 com.fasterxml.jackson.core.JsonParseException;
47 import com.fasterxml.jackson.databind.JsonMappingException;
48 import com.fasterxml.jackson.databind.JsonNode;
49 import com.fasterxml.jackson.databind.ObjectMapper;
50 import com.github.tomakehurst.wiremock.client.WireMock;
52 @RunWith(SpringRunner.class)
53 @SpringBootTest(classes = ApiHandlerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
54 @ActiveProfiles("test")
57 @Sql(executionPhase=ExecutionPhase.AFTER_TEST_METHOD,scripts="classpath:InfraActiveRequestsReset.sql")
58 @AutoConfigureWireMock(port = 0)
59 public abstract class BaseTest {
61 protected MsoLogger logger = MsoLogger.getMsoLogger(Catalog.GENERAL, BaseTest.class);
62 protected TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
64 protected HttpHeaders headers = new HttpHeaders();
67 protected Environment env;
70 protected InfraActiveRequestsRepository iar;
75 protected String readJsonFileAsString(String fileLocation) throws JsonParseException, JsonMappingException, IOException{
76 ObjectMapper mapper = new ObjectMapper();
77 JsonNode jsonNode = mapper.readTree(new File(fileLocation));
78 return jsonNode.asText();
81 protected String createURLWithPort(String uri) {
82 return "http://localhost:" + port + uri;
86 public void tearDown(){