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.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;
40 * @author waqas.ikram@ericsson.com
43 public class OwningEntityControllerTest extends AbstractSpringBootTest {
45 private static final String OWN_ENTITY_ID_VALUE = "oe_1";
46 private static final String OWN_ENTITY_NAME_VALUE = "oe_2";
49 private OwnEntityCacheServiceProvider cacheServiceProvider;
53 cacheServiceProvider.clearAll();
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);
62 assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode());
64 final ResponseEntity<OwningEntity> actualResponse =
65 testRestTemplateService.invokeHttpGet(url, OwningEntity.class);
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());
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);
82 assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode());
84 final ResponseEntity<Results> actualResponse = testRestTemplateService
85 .invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=" + Format.COUNT.getValue(), Results.class);
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));
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());
102 final String owningEntityRelationshipUrl = url + RELATIONSHIP_LIST_RELATIONSHIP_URL;
104 final ResponseEntity<Void> putResponse = testRestTemplateService.invokeHttpPut(owningEntityRelationshipUrl,
105 TestUtils.getOwningEntityRelationship(), Void.class);
107 assertEquals(HttpStatus.ACCEPTED, putResponse.getStatusCode());
109 final ResponseEntity<OwningEntity> actualResponse =
110 testRestTemplateService.invokeHttpGet(url, OwningEntity.class);
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));