2 * ============LICENSE_START=======================================================
3 * PNF-REGISTRATION-HANDLER
4 * ================================================================================
5 * Copyright (C) 2019 NOKIA 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.dcaegen2.services.prh.model;
23 import com.google.gson.Gson;
24 import org.junit.jupiter.api.Test;
25 import org.onap.dcaegen2.services.prh.model.utils.PrhModelAwareGsonBuilder;
27 import java.io.InputStreamReader;
28 import java.util.Objects;
30 import static org.assertj.core.api.Assertions.assertThat;
32 class AaiServiceInstanceResultModelTest {
35 void shouldParseAaiServiceInstance() {
36 AaiServiceInstanceResultModel serviceInstance = PrhModelAwareGsonBuilder.createGson().fromJson(
37 new InputStreamReader(Objects.requireNonNull(
38 ClassLoader.getSystemResourceAsStream("some_aai_service_instance.json"))),
39 AaiServiceInstanceResultModel.class);
41 assertThat(serviceInstance.getServiceInstanceId()).isEqualTo("some serviceInstanceId");
42 assertThat(serviceInstance.getServiceInstanceName()).isEqualTo("some serviceInstanceName");
43 assertThat(serviceInstance.getServiceType()).isEqualTo("some serviceType");
44 assertThat(serviceInstance.getServiceRole()).isEqualTo("some serviceRole");
45 assertThat(serviceInstance.getEnvironmentContext()).isEqualTo("some environmentContext");
46 assertThat(serviceInstance.getWorkloadContext()).isEqualTo("some workloadContext");
47 assertThat(serviceInstance.getCreatedAt()).isEqualTo("some createdAt");
48 assertThat(serviceInstance.getUpdatedAt()).isEqualTo("some updatedAt");
49 assertThat(serviceInstance.getDescription()).isEqualTo("some description");
50 assertThat(serviceInstance.getModelInvariantId()).isEqualTo("some modelInvariantId");
51 assertThat(serviceInstance.getModelVersionId()).isEqualTo("some modelVersionId");
52 assertThat(serviceInstance.getPersonaModelVersion()).isEqualTo("some personaModelVersion");
53 assertThat(serviceInstance.getWidgetModelId()).isEqualTo("some widgetModelId");
54 assertThat(serviceInstance.getWidgetModelVersion()).isEqualTo("some widgetModelVersion");
55 assertThat(serviceInstance.getBandwidthTotal()).isEqualTo("some bandwidthTotal");
56 assertThat(serviceInstance.getBandwidthUpWan1()).isEqualTo("some bandwidthUpWan1");
57 assertThat(serviceInstance.getBandwidthDownWan1()).isEqualTo("some bandwidthDownWan1");
58 assertThat(serviceInstance.getBandwidthUpWan2()).isEqualTo("some bandwidthUpWan2");
59 assertThat(serviceInstance.getBandwidthDownWan2()).isEqualTo("some bandwidthDownWan2");
60 assertThat(serviceInstance.getVhnPortalUrl()).isEqualTo("some vhnPortalUrl");
61 assertThat(serviceInstance.getServiceInstanceLocationId()).isEqualTo("some serviceInstanceLocationId");
62 assertThat(serviceInstance.getResourceVersion()).isEqualTo("some resourceVersion");
63 assertThat(serviceInstance.getSelflink()).isEqualTo("some selflink");
64 assertThat(serviceInstance.getOrchestrationStatus()).isEqualTo("some orchestrationStatus");
66 RelationshipDict relationshipDict = serviceInstance.getRelationshipList().getRelationship().get(0);
67 assertThat(relationshipDict.getRelatedTo()).isEqualTo("some relatedTo");
68 assertThat(relationshipDict.getRelationshipData()).hasSize(1);
69 RelationshipData relationshipData = relationshipDict.getRelationshipData().get(0);
70 assertThat(relationshipData.getRelationshipKey()).isEqualTo("some relationshipKey");
71 assertThat(relationshipData.getRelationshipValue()).isEqualTo("some relationshipValue");
76 void shouldProvideEmptyRelationshipListForEmptyJson() {
77 Gson gson = PrhModelAwareGsonBuilder.createGson();
78 AaiServiceInstanceResultModel serviceInstance = gson.fromJson("{}", AaiServiceInstanceResultModel.class);
79 assertThat(serviceInstance.getRelationshipList()).isNotNull();
80 assertThat(serviceInstance.getRelationshipList().getRelationship()).isEmpty();
84 void shouldIgnoreUnexpectedFieldsInJson() {
85 Gson gson = PrhModelAwareGsonBuilder.createGson();
86 gson.fromJson("{\"foo\":\"bar\"}", AaiServiceInstanceResultModel.class);