Adding aai line of business endpoints
[integration/csit.git] / plans / so / integration-etsi-testing / so-simulators / aai-simulator / src / test / java / org / onap / so / aaisimulator / controller / LinesOfBusinessControllerTest.java
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.aaisimulator.controller;
21
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;
43
44 /**
45  * @author Waqas Ikram (waqas.ikram@est.tech)
46  *
47  */
48 @RunWith(SpringJUnit4ClassRunner.class)
49 @ActiveProfiles("test")
50 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
51 @Configuration
52 public class LinesOfBusinessControllerTest {
53     @LocalServerPort
54     private int port;
55
56     @Autowired
57     private TestRestTemplateService testRestTemplateService;
58
59     @Autowired
60     private LinesOfBusinessCacheServiceProvider linesOfBusinessCacheServiceProvider;
61
62     @After
63     public void after() {
64         linesOfBusinessCacheServiceProvider.clearAll();
65     }
66
67     @Test
68     public void test_putLineOfBusiness_successfullyAddedToCache() throws Exception {
69
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());
74
75         final ResponseEntity<LineOfBusiness> response = testRestTemplateService.invokeHttpGet(url, LineOfBusiness.class);
76         assertEquals(HttpStatus.OK, response.getStatusCode());
77
78         assertTrue(response.hasBody());
79
80         final LineOfBusiness actualLineOfBusiness = response.getBody();
81         assertEquals(LINE_OF_BUSINESS_NAME, actualLineOfBusiness.getLineOfBusinessName());
82         assertNotNull("resource version should not be null", actualLineOfBusiness.getResourceVersion());
83
84     }
85
86     private String getUrl(final String... urls) {
87         return TestUtils.getUrl(port, urls);
88     }
89 }