34ac30aefa678b6e56ae7f404e0cc50bb09bcf1f
[integration/csit.git] / plans / so / integration-etsi-testing / so-simulators / aai-simulator / src / test / java / org / onap / so / aaisimulator / controller / OwningEntityControllerTest.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.assertFalse;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
26 import static org.onap.so.aaisimulator.utils.Constants.RELATIONSHIP_LIST_RELATIONSHIP_URL;
27 import org.junit.After;
28 import org.junit.Test;
29 import org.onap.aai.domain.yang.OwningEntity;
30 import org.onap.so.aaisimulator.models.Format;
31 import org.onap.so.aaisimulator.models.Results;
32 import org.onap.so.aaisimulator.service.providers.OwnEntityCacheServiceProvider;
33 import org.onap.so.aaisimulator.utils.Constants;
34 import org.onap.so.aaisimulator.utils.TestUtils;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.http.HttpStatus;
37 import org.springframework.http.ResponseEntity;
38
39 /**
40  * @author waqas.ikram@ericsson.com
41  *
42  */
43 public class OwningEntityControllerTest extends AbstractSpringBootTest {
44
45     private static final String OWN_ENTITY_ID_VALUE = "oe_1";
46     private static final String OWN_ENTITY_NAME_VALUE = "oe_2";
47
48     @Autowired
49     private OwnEntityCacheServiceProvider cacheServiceProvider;
50
51     @After
52     public void after() {
53         cacheServiceProvider.clearAll();
54     }
55
56     @Test
57     public void test_putOwningEntity_successfullyAddedToCache() throws Exception {
58         final String url = getUrl(Constants.OWNING_ENTITY_URL, OWN_ENTITY_ID_VALUE);
59         final ResponseEntity<Void> actual =
60                 testRestTemplateService.invokeHttpPut(url, TestUtils.getOwningEntity(), Void.class);
61
62         assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode());
63
64         final ResponseEntity<OwningEntity> actualResponse =
65                 testRestTemplateService.invokeHttpGet(url, OwningEntity.class);
66
67         assertEquals(HttpStatus.OK, actualResponse.getStatusCode());
68         assertTrue(actualResponse.hasBody());
69         final OwningEntity actualOwningEntity = actualResponse.getBody();
70         assertEquals(OWN_ENTITY_ID_VALUE, actualOwningEntity.getOwningEntityId());
71         assertEquals(OWN_ENTITY_NAME_VALUE, actualOwningEntity.getOwningEntityName());
72         assertNotNull(actualOwningEntity.getResourceVersion());
73
74     }
75
76     @Test
77     public void test_getOwningEntityCount_correctResult() throws Exception {
78         final String url = getUrl(Constants.OWNING_ENTITY_URL, OWN_ENTITY_ID_VALUE);
79         final ResponseEntity<Void> actual =
80                 testRestTemplateService.invokeHttpPut(url, TestUtils.getOwningEntity(), Void.class);
81
82         assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode());
83
84         final ResponseEntity<Results> actualResponse = testRestTemplateService
85                 .invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=" + Format.COUNT.getValue(), Results.class);
86
87         assertEquals(HttpStatus.OK, actualResponse.getStatusCode());
88         assertTrue(actualResponse.hasBody());
89         final Results result = actualResponse.getBody();
90         assertNotNull(result.getValues());
91         assertFalse(result.getValues().isEmpty());
92         assertEquals(1, result.getValues().get(0).get(Constants.OWNING_ENTITY));
93     }
94
95     @Test
96     public void test_putOwningEntityRelationShip_successfullyAddedToCache() throws Exception {
97         final String url = getUrl(Constants.OWNING_ENTITY_URL, OWN_ENTITY_ID_VALUE);
98         final ResponseEntity<Void> actual =
99                 testRestTemplateService.invokeHttpPut(url, TestUtils.getOwningEntity(), Void.class);
100         assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode());
101
102         final String owningEntityRelationshipUrl = url + RELATIONSHIP_LIST_RELATIONSHIP_URL;
103
104         final ResponseEntity<Void> putResponse = testRestTemplateService.invokeHttpPut(owningEntityRelationshipUrl,
105                 TestUtils.getOwningEntityRelationship(), Void.class);
106
107         assertEquals(HttpStatus.ACCEPTED, putResponse.getStatusCode());
108
109         final ResponseEntity<OwningEntity> actualResponse =
110                 testRestTemplateService.invokeHttpGet(url, OwningEntity.class);
111
112         assertEquals(HttpStatus.OK, actualResponse.getStatusCode());
113         assertTrue(actualResponse.hasBody());
114         final OwningEntity actualOwningEntity = actualResponse.getBody();
115         assertEquals(OWN_ENTITY_ID_VALUE, actualOwningEntity.getOwningEntityId());
116         assertEquals(OWN_ENTITY_NAME_VALUE, actualOwningEntity.getOwningEntityName());
117         assertNotNull(actualOwningEntity.getRelationshipList());
118         assertFalse(actualOwningEntity.getRelationshipList().getRelationship().isEmpty());
119         assertNotNull(actualOwningEntity.getRelationshipList().getRelationship().get(0));
120
121     }
122
123 }