2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.onap.so.aaisimulator.controller;
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertTrue;
25 import static org.onap.so.aaisimulator.utils.TestConstants.LINE_OF_BUSINESS_NAME;
26 import org.junit.After;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.onap.aai.domain.yang.LineOfBusiness;
30 import org.onap.so.aaisimulator.service.providers.LinesOfBusinessCacheServiceProvider;
31 import org.onap.so.aaisimulator.utils.Constants;
32 import org.onap.so.aaisimulator.utils.TestRestTemplateService;
33 import org.onap.so.aaisimulator.utils.TestUtils;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.boot.test.context.SpringBootTest;
36 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
37 import org.springframework.boot.web.server.LocalServerPort;
38 import org.springframework.context.annotation.Configuration;
39 import org.springframework.http.HttpStatus;
40 import org.springframework.http.ResponseEntity;
41 import org.springframework.test.context.ActiveProfiles;
42 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
45 * @author Waqas Ikram (waqas.ikram@est.tech)
48 @RunWith(SpringJUnit4ClassRunner.class)
49 @ActiveProfiles("test")
50 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
52 public class LinesOfBusinessControllerTest {
57 private TestRestTemplateService testRestTemplateService;
60 private LinesOfBusinessCacheServiceProvider linesOfBusinessCacheServiceProvider;
64 linesOfBusinessCacheServiceProvider.clearAll();
68 public void test_putLineOfBusiness_successfullyAddedToCache() throws Exception {
70 final String url = getUrl(Constants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME);
71 final ResponseEntity<Void> lineOfBusinessResponse =
72 testRestTemplateService.invokeHttpPut(url, TestUtils.getLineOfBusiness(), Void.class);
73 assertEquals(HttpStatus.ACCEPTED, lineOfBusinessResponse.getStatusCode());
75 final ResponseEntity<LineOfBusiness> response = testRestTemplateService.invokeHttpGet(url, LineOfBusiness.class);
76 assertEquals(HttpStatus.OK, response.getStatusCode());
78 assertTrue(response.hasBody());
80 final LineOfBusiness actualLineOfBusiness = response.getBody();
81 assertEquals(LINE_OF_BUSINESS_NAME, actualLineOfBusiness.getLineOfBusinessName());
82 assertNotNull("resource version should not be null", actualLineOfBusiness.getResourceVersion());
86 private String getUrl(final String... urls) {
87 return TestUtils.getUrl(port, urls);