2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 Nokia. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.vid.aai;
25 import static org.assertj.core.api.Assertions.assertThat;
27 import com.fasterxml.jackson.core.JsonProcessingException;
28 import com.fasterxml.jackson.databind.ObjectMapper;
29 import java.io.IOException;
30 import java.util.ArrayList;
31 import org.onap.vid.aai.model.RelationshipList;
32 import org.testng.annotations.Test;
35 public class OperationalEnvironmentTest {
37 private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
39 private static final String OPERATIONAL_ENVIRONMENT_JSON_DASHES = "{\n" +
40 "\"operational-environment-id\": \"testEnvironmentId\",\n" +
41 "\"operational-environment-name\": \"testEnvironmentName\",\n" +
42 "\"operational-environment-type\": \"testEnvironmentType\",\n" +
43 "\"operational-environment-status\": \"testEnvironmentStatus\",\n" +
44 "\"tenant-context\": \"testTenantContext\",\n" +
45 "\"workload-context\": \"testWorkloadContext\",\n" +
46 "\"resource-version\": \"testResourceVersion\",\n" +
47 "\"relationship-list\": {\n" +
48 "\"relationship\": []\n" +
52 private static final String OPERATIONAL_ENVIRONMENT_JSON_CAMELCASE = "{\n" +
53 "\"operationalEnvironmentId\": \"testEnvironmentId\",\n" +
54 "\"operationalEnvironmentName\": \"testEnvironmentName\",\n" +
55 "\"operationalEnvironmentType\": \"testEnvironmentType\",\n" +
56 "\"operationalEnvironmentStatus\": \"testEnvironmentStatus\",\n" +
57 "\"tenantContext\": \"testTenantContext\",\n" +
58 "\"workloadContext\": \"testWorkloadContext\",\n" +
59 "\"resourceVersion\": \"testResourceVersion\",\n" +
60 "\"relationshipList\": {\n" +
61 "\"relationship\": []\n" +
66 public void shouldProperlyConvertJsonToOperationalEnvironment_whenJsonPropertyNamesContainDashSeparators()
68 assertOperationalEnvironmentDeserialization(OPERATIONAL_ENVIRONMENT_JSON_DASHES);
72 public void shouldProperlyConvertJsonToOperationalEnvironment_whenJsonPropertyNamesAreCamelCase()
74 assertOperationalEnvironmentDeserialization(OPERATIONAL_ENVIRONMENT_JSON_CAMELCASE);
77 private void assertOperationalEnvironmentDeserialization(String operationalEnvironmentTestDashes)
79 OperationalEnvironment operationalEnvironment =
80 OBJECT_MAPPER.readValue(operationalEnvironmentTestDashes, OperationalEnvironment.class);
82 assertThat(operationalEnvironment.getOperationalEnvironmentId()).isEqualTo("testEnvironmentId");
83 assertThat(operationalEnvironment.getOperationalEnvironmentName()).isEqualTo("testEnvironmentName");
84 assertThat(operationalEnvironment.getOperationalEnvironmentType()).isEqualTo("testEnvironmentType");
85 assertThat(operationalEnvironment.getOperationalEnvironmentStatus()).isEqualTo("testEnvironmentStatus");
86 assertThat(operationalEnvironment.getTenantContext()).isEqualTo("testTenantContext");
87 assertThat(operationalEnvironment.getWorkloadContext()).isEqualTo("testWorkloadContext");
88 assertThat(operationalEnvironment.getResourceVersion()).isEqualTo("testResourceVersion");
89 assertThat(operationalEnvironment.getRelationshipList().getRelationship()).hasSize(0);
93 public void shouldSerializeToJson_usingActualPropertyNameAsJsonLogicalProperty() throws JsonProcessingException {
94 RelationshipList relationshipList = new RelationshipList();
95 relationshipList.relationship = new ArrayList<>();
97 OperationalEnvironment operationalEnvironment = createOperationalEnvironment(relationshipList);
99 assertThat(OPERATIONAL_ENVIRONMENT_JSON_CAMELCASE)
100 .isEqualToIgnoringWhitespace(OBJECT_MAPPER.writeValueAsString(operationalEnvironment));
103 private OperationalEnvironment createOperationalEnvironment(RelationshipList relationshipList) {
104 return new OperationalEnvironment.OperationalEnvironmentBuilder()
105 .withOperationalEnvironmentId("testEnvironmentId")
106 .withOperationalEnvironmentName("testEnvironmentName")
107 .withOperationalEnvironmentType("testEnvironmentType")
108 .withOperationalEnvironmentStatus("testEnvironmentStatus")
109 .withTenantContext("testTenantContext")
110 .withWorkloadContext("testWorkloadContext")
111 .withResourceVersion("testResourceVersion")
112 .withRelationshipList(relationshipList)