diff options
Diffstat (limited to 'prh-commons/src/test/java/org/onap/dcaegen2/services/prh')
9 files changed, 485 insertions, 145 deletions
diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderTest.java new file mode 100644 index 00000000..60ce520c --- /dev/null +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderTest.java @@ -0,0 +1,114 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.prh.model; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.junit.jupiter.api.Test; + +class AaiJsonBodyBuilderTest { + + @Test + void createJsonBody_shouldReturnJsonInString() { + + ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder() + .correlationId("NOKnhfsadhff") + .ipv4("256.22.33.155") + .ipv6("200J:0db8:85a3:0000:0000:8a2e:0370:7334") + .serialNumber("1234") + .equipVendor("NOKIA") + .equipModel("3310") + .equipType("cell") + .nfRole("role") + .swVersion("1.2.3") + .build(); + + String expectedResult = "{" + + "\"correlationId\":\"NOKnhfsadhff\"," + + "\"ipaddress-v4-oam\":\"256.22.33.155\"," + + "\"ipaddress-v6-oam\":\"200J:0db8:85a3:0000:0000:8a2e:0370:7334\"," + + "\"serial-number\":\"1234\"," + + "\"equip-vendor\":\"NOKIA\"," + + "\"equip-model\":\"3310\"," + + "\"equip-type\":\"cell\"," + + "\"nf-role\":\"role\"," + + "\"sw-version\":\"1.2.3\"" + + "}"; + + assertEquals(expectedResult, new AaiJsonBodyBuilderImpl().createJsonBody(model)); + } + + @Test + void createJsonBodyWithoutIPs_shouldReturnJsonInString() { + + ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder() + .correlationId("NOKnhfsadhff") + .serialNumber("1234") + .equipVendor("NOKIA") + .equipModel("3310") + .equipType("cell") + .nfRole("role") + .swVersion("1.2.3") + .build(); + + String expectedResult = "{" + + "\"correlationId\":\"NOKnhfsadhff\"," + + "\"serial-number\":\"1234\"," + + "\"equip-vendor\":\"NOKIA\"," + + "\"equip-model\":\"3310\"," + + "\"equip-type\":\"cell\"," + + "\"nf-role\":\"role\"," + + "\"sw-version\":\"1.2.3\"" + + "}"; + + assertEquals(expectedResult, new AaiJsonBodyBuilderImpl().createJsonBody(model)); + } + + @Test + void createJsonBodyWithEmptyIPs_shouldReturnJsonInString() { + + ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder() + .correlationId("NOKnhfsadhff") + .ipv4("") + .ipv6("") + .serialNumber("1234") + .equipVendor("NOKIA") + .equipModel("3310") + .equipType("cell") + .nfRole("role") + .swVersion("1.2.3") + .build(); + + String expectedResult = "{" + + "\"correlationId\":\"NOKnhfsadhff\"," + + "\"serial-number\":\"1234\"," + + "\"equip-vendor\":\"NOKIA\"," + + "\"equip-model\":\"3310\"," + + "\"equip-type\":\"cell\"," + + "\"nf-role\":\"role\"," + + "\"sw-version\":\"1.2.3\"" + + "}"; + + assertEquals(expectedResult, new AaiJsonBodyBuilderImpl().createJsonBody(model)); + } +} diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiPnfResultModelTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiPnfResultModelTest.java new file mode 100644 index 00000000..3f396e82 --- /dev/null +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiPnfResultModelTest.java @@ -0,0 +1,87 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2019 NOKIA Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.prh.model; + +import com.google.gson.Gson; +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.prh.model.utils.PrhModelAwareGsonBuilder; + +import java.io.InputStreamReader; +import java.util.Objects; + +import static org.assertj.core.api.Assertions.assertThat; + +class AaiPnfResultModelTest { + + @Test + void shouldParseAaiPnf() { + Gson gson = PrhModelAwareGsonBuilder.createGson(); + AaiPnfResultModel pnf = gson.fromJson(new InputStreamReader(Objects.requireNonNull( + ClassLoader.getSystemResourceAsStream("some_aai_pnf.json"))), AaiPnfResultModel.class); + + assertThat(pnf.getPnfName()).isEqualTo("some pnfName"); + assertThat(pnf.getPnfName2()).isEqualTo("some pnfName2"); + assertThat(pnf.getSelflink()).isEqualTo("some selflink"); + assertThat(pnf.getPnfName2Source()).isEqualTo("some pnfName2Source"); + assertThat(pnf.getPnfId()).isEqualTo("some pnfId"); + assertThat(pnf.getEquipType()).isEqualTo("some equipType"); + assertThat(pnf.getEquipVendor()).isEqualTo("some equipVendor"); + assertThat(pnf.getEquipModel()).isEqualTo("some equipModel"); + assertThat(pnf.getManagementOption()).isEqualTo("some managementOption"); + assertThat(pnf.getIpaddressV4Oam()).isEqualTo("some ipaddressV4Oam"); + assertThat(pnf.getSwVersion()).isEqualTo("some swVersion"); + assertThat(pnf.isInMaint()).isFalse(); + assertThat(pnf.getFrameId()).isEqualTo("some frameId"); + assertThat(pnf.getSerialNumber()).isEqualTo("some serialNumber"); + assertThat(pnf.getIpaddressV4Loopback0()).isEqualTo("some ipaddressV4Loopback0"); + assertThat(pnf.getIpaddressV6Loopback0()).isEqualTo("some ipaddressV6Loopback0"); + assertThat(pnf.getIpaddressV4Aim()).isEqualTo("some ipaddressV4Aim"); + assertThat(pnf.getIpaddressV6Aim()).isEqualTo("some ipaddressV6Aim"); + assertThat(pnf.getIpaddressV6Oam()).isEqualTo("some ipaddressV6Oam"); + assertThat(pnf.getInvStatus()).isEqualTo("some invStatus"); + assertThat(pnf.getResourceVersion()).isEqualTo("some resourceVersion"); + assertThat(pnf.getProvStatus()).isEqualTo("some provStatus"); + assertThat(pnf.getNfRole()).isEqualTo("some nfRole"); + + assertThat(pnf.getRelationshipList().getRelationship()).hasSize(1); + RelationshipDict relationshipDict = pnf.getRelationshipList().getRelationship().get(0); + assertThat(relationshipDict.getRelatedTo()).isEqualTo("some relatedTo"); + assertThat(relationshipDict.getRelationshipData()).hasSize(1); + RelationshipData relationshipData = relationshipDict.getRelationshipData().get(0); + assertThat(relationshipData.getRelationshipKey()).isEqualTo("some relationshipKey"); + assertThat(relationshipData.getRelationshipValue()).isEqualTo("some relationshipValue"); + } + + @Test + void shouldProvideEmptyRelationshipListForEmptyJson() { + Gson gson = PrhModelAwareGsonBuilder.createGson(); + AaiPnfResultModel pnf = gson.fromJson("{}", AaiPnfResultModel.class); + assertThat(pnf.getRelationshipList()).isNotNull(); + assertThat(pnf.getRelationshipList().getRelationship()).isEmpty(); + } + + @Test + void shouldIgnoreUnexpectedFieldsInJson() { + Gson gson = PrhModelAwareGsonBuilder.createGson(); + gson.fromJson("{\"foo\":\"bar\"}", AaiPnfResultModel.class); + } + +}
\ No newline at end of file diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiServiceInstanceResultModelTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiServiceInstanceResultModelTest.java new file mode 100644 index 00000000..5f9ca14d --- /dev/null +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/AaiServiceInstanceResultModelTest.java @@ -0,0 +1,89 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2019 NOKIA Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.prh.model; + +import com.google.gson.Gson; +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.prh.model.utils.PrhModelAwareGsonBuilder; + +import java.io.InputStreamReader; +import java.util.Objects; + +import static org.assertj.core.api.Assertions.assertThat; + +class AaiServiceInstanceResultModelTest { + + @Test + void shouldParseAaiServiceInstance() { + AaiServiceInstanceResultModel serviceInstance = PrhModelAwareGsonBuilder.createGson().fromJson( + new InputStreamReader(Objects.requireNonNull( + ClassLoader.getSystemResourceAsStream("some_aai_service_instance.json"))), + AaiServiceInstanceResultModel.class); + + assertThat(serviceInstance.getServiceInstanceId()).isEqualTo("some serviceInstanceId"); + assertThat(serviceInstance.getServiceInstanceName()).isEqualTo("some serviceInstanceName"); + assertThat(serviceInstance.getServiceType()).isEqualTo("some serviceType"); + assertThat(serviceInstance.getServiceRole()).isEqualTo("some serviceRole"); + assertThat(serviceInstance.getEnvironmentContext()).isEqualTo("some environmentContext"); + assertThat(serviceInstance.getWorkloadContext()).isEqualTo("some workloadContext"); + assertThat(serviceInstance.getCreatedAt()).isEqualTo("some createdAt"); + assertThat(serviceInstance.getUpdatedAt()).isEqualTo("some updatedAt"); + assertThat(serviceInstance.getDescription()).isEqualTo("some description"); + assertThat(serviceInstance.getModelInvariantId()).isEqualTo("some modelInvariantId"); + assertThat(serviceInstance.getModelVersionId()).isEqualTo("some modelVersionId"); + assertThat(serviceInstance.getPersonaModelVersion()).isEqualTo("some personaModelVersion"); + assertThat(serviceInstance.getWidgetModelId()).isEqualTo("some widgetModelId"); + assertThat(serviceInstance.getWidgetModelVersion()).isEqualTo("some widgetModelVersion"); + assertThat(serviceInstance.getBandwidthTotal()).isEqualTo("some bandwidthTotal"); + assertThat(serviceInstance.getBandwidthUpWan1()).isEqualTo("some bandwidthUpWan1"); + assertThat(serviceInstance.getBandwidthDownWan1()).isEqualTo("some bandwidthDownWan1"); + assertThat(serviceInstance.getBandwidthUpWan2()).isEqualTo("some bandwidthUpWan2"); + assertThat(serviceInstance.getBandwidthDownWan2()).isEqualTo("some bandwidthDownWan2"); + assertThat(serviceInstance.getVhnPortalUrl()).isEqualTo("some vhnPortalUrl"); + assertThat(serviceInstance.getServiceInstanceLocationId()).isEqualTo("some serviceInstanceLocationId"); + assertThat(serviceInstance.getResourceVersion()).isEqualTo("some resourceVersion"); + assertThat(serviceInstance.getSelflink()).isEqualTo("some selflink"); + assertThat(serviceInstance.getOrchestrationStatus()).isEqualTo("some orchestrationStatus"); + + RelationshipDict relationshipDict = serviceInstance.getRelationshipList().getRelationship().get(0); + assertThat(relationshipDict.getRelatedTo()).isEqualTo("some relatedTo"); + assertThat(relationshipDict.getRelationshipData()).hasSize(1); + RelationshipData relationshipData = relationshipDict.getRelationshipData().get(0); + assertThat(relationshipData.getRelationshipKey()).isEqualTo("some relationshipKey"); + assertThat(relationshipData.getRelationshipValue()).isEqualTo("some relationshipValue"); + } + + + @Test + void shouldProvideEmptyRelationshipListForEmptyJson() { + Gson gson = PrhModelAwareGsonBuilder.createGson(); + AaiServiceInstanceResultModel serviceInstance = gson.fromJson("{}", AaiServiceInstanceResultModel.class); + assertThat(serviceInstance.getRelationshipList()).isNotNull(); + assertThat(serviceInstance.getRelationshipList().getRelationship()).isEmpty(); + } + + @Test + void shouldIgnoreUnexpectedFieldsInJson() { + Gson gson = PrhModelAwareGsonBuilder.createGson(); + gson.fromJson("{\"foo\":\"bar\"}", AaiServiceInstanceResultModel.class); + } + +}
\ No newline at end of file diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/CommonFunctionsTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/CommonFunctionsTest.java deleted file mode 100644 index 86717d7e..00000000 --- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/CommonFunctionsTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * PNF-REGISTRATION-HANDLER - * ================================================================================ - * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.dcaegen2.services.prh.model; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.Test; - -class CommonFunctionsTest { - - @Test - void createJsonBody_shouldReturnJsonInString() { - String expectedResult = "{\"correlationId\":\"NOKnhfsadhff\",\"ipaddress-v4-oam\":\"256.22.33.155\"" - + ",\"ipaddress-v6-oam\":\"200J:0db8:85a3:0000:0000:8a2e:0370:7334\"}"; - assertEquals(expectedResult, new JsonBodyBuilderImpl().createJsonBody(new ConsumerDmaapModelForUnitTest())); - } -} diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModelTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModelTest.java deleted file mode 100644 index 4c4c345f..00000000 --- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModelTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * PNF-REGISTRATION-HANDLER - * ================================================================================ - * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.dcaegen2.services.prh.model; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -class ConsumerDmaapModelTest { - - @Test - void consumerDmaapModelBuilder_shouldBuildAnObject() { - - // When - // Given - String sourceName = "NOKnhfsadhff"; - String ipv4 = "11.22.33.155"; - String ipv6 = "2001:0db8:85a3:0000:0000:8a2e:0370:7334"; - ConsumerDmaapModel consumerDmaapModel = ImmutableConsumerDmaapModel.builder() - .correlationId(sourceName) - .ipv4(ipv4) - .ipv6(ipv6) - .build(); - - // Then - Assertions.assertNotNull(consumerDmaapModel); - Assertions.assertEquals(sourceName, consumerDmaapModel.getCorrelationId()); - Assertions.assertEquals(ipv4, consumerDmaapModel.getIpv4()); - Assertions.assertEquals(ipv6, consumerDmaapModel.getIpv6()); - } -} diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/PnfReadyJsonBodyBuilderTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/PnfReadyJsonBodyBuilderTest.java new file mode 100644 index 00000000..769e1673 --- /dev/null +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/PnfReadyJsonBodyBuilderTest.java @@ -0,0 +1,82 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.prh.model; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.junit.jupiter.api.Test; + +class PnfReadyJsonBodyBuilderTest { + + @Test + void createJsonBody_shouldReturnJsonInString() { + + JsonObject jsonObject = parse("{\n" + + " \"attachmentPoint\": \"bla-bla-30-3\",\n" + + " \"cvlan\": \"678\",\n" + + " \"svlan\": \"1005\"\n" + + " }"); + + ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder() + .correlationId("NOKnhfsadhff") + .additionalFields(jsonObject) + .build(); + + JsonObject expectedResult = parse("{" + + "\"correlationId\":\"NOKnhfsadhff\"," + + "\"additionalFields\":{\"attachmentPoint\":\"bla-bla-30-3\",\"cvlan\":\"678\",\"svlan\":\"1005\"}" + + "}"); + + assertEquals(expectedResult, new PnfReadyJsonBodyBuilder().createJsonBody(model)); + } + + @Test + void createJsonBodyWithNullableFieldsNotSet_shouldReturnJsonInString() { + + ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder() + .correlationId("NOKnhfsadhff") + .build(); + + JsonObject expectedResult = parse("{\"correlationId\":\"NOKnhfsadhff\"}"); + + assertEquals(expectedResult, new PnfReadyJsonBodyBuilder().createJsonBody(model)); + } + + @Test + void createJsonBodyWithEmptyOptionalPnfRegistrationFields_shouldReturnJsonInString() { + JsonObject jsonObject = new JsonObject(); + + ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder() + .correlationId("NOKnhfsadhff") + .additionalFields(jsonObject) + .build(); + + JsonObject expectedResult = parse("{\"correlationId\":\"NOKnhfsadhff\"}"); + + assertEquals(expectedResult, new PnfReadyJsonBodyBuilder().createJsonBody(model)); + } + + private static JsonObject parse(String jsonString) { + return new JsonParser().parse(jsonString).getAsJsonObject(); + } +} diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/queries/NamedNodesTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/queries/NamedNodesTest.java new file mode 100644 index 00000000..0991d31f --- /dev/null +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/queries/NamedNodesTest.java @@ -0,0 +1,58 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2019 NOKIA Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.prh.model.queries; + +import static java.util.Objects.requireNonNull; +import static org.assertj.core.api.Assertions.assertThat; + +import com.google.gson.Gson; +import java.io.InputStreamReader; +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.prh.model.utils.PrhModelAwareGsonBuilder; + +class NamedNodesTest { + + @Test + void shouldParseJsonToNamedNodes() { + // given + InputStreamReader inputStream = getJsonFromFile("pnf_query_response.json"); + Gson gson = PrhModelAwareGsonBuilder.createGson(); + + // when + NamedNodes nodes = gson.fromJson(inputStream, NamedNodes.class); + + // then + assertThat(nodes.results().size()).isEqualTo(3); + assertThat(nodes.results().get(0)) + .matches(node -> "pnf".equals(node.name())) + .matches(node -> node.properties().get("pnf-name").equals("foo")); + assertThat(nodes.results().get(1)) + .matches(node -> "logical-link".equals(node.name())) + .matches(node -> node.properties().get("link-name").equals("bar")); + assertThat(nodes.results().get(2)) + .matches(node -> "service-instance".equals(node.name())) + .matches(node -> node.properties().get("service-instance-name").equals("baz")); + } + + private InputStreamReader getJsonFromFile(String file) { + return new InputStreamReader(requireNonNull(getClass().getClassLoader().getResourceAsStream(file))); + } +} diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/queries/PnfQueryTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/queries/PnfQueryTest.java new file mode 100644 index 00000000..0ab0b17b --- /dev/null +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/queries/PnfQueryTest.java @@ -0,0 +1,55 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2019 NOKIA Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.prh.model.queries; + +import static java.util.Objects.requireNonNull; +import static java.util.stream.Collectors.joining; +import static org.assertj.core.api.Assertions.assertThat; + +import com.google.gson.Gson; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.prh.model.utils.PrhModelAwareGsonBuilder; + +class PnfQueryTest { + + @Test + void shouldParseToCorrectJson() throws IOException { + // given + PnfQuery pnfQuery = new PnfQuery("foo"); + + // when + Gson gson = PrhModelAwareGsonBuilder.createGson(); + + // then + String json = gson.toJson(pnfQuery); + assertThat(json).isEqualToIgnoringWhitespace(getJsonFromFile("pnf_query_request.json")); + } + + private String getJsonFromFile(String file) throws IOException { + try (BufferedReader br = new BufferedReader(new InputStreamReader( + requireNonNull(getClass().getClassLoader().getResourceAsStream(file))))) { + return br.lines().collect(joining(System.lineSeparator())); + } + } +}
\ No newline at end of file diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/ssl/SslFactoryTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/ssl/SslFactoryTest.java deleted file mode 100644 index dbd63911..00000000 --- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/ssl/SslFactoryTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * PNF-REGISTRATION-HANDLER - * ================================================================================ - * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.dcaegen2.services.prh.ssl; - -import javax.net.ssl.SSLException; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - - -class SslFactoryTest { - - private static final String KEY_STORE = "org.onap.dcae.jks"; - private static final String KEYSTORE_PASSWORD = "keystore.password"; - private static final String TRUSTSTORE_PASSWORD = "truststore.password"; - private static final String TRUST_STORE = "org.onap.dcae.trust.jks"; - private SslFactory sslFactory = new SslFactory(); - - @Test - void shouldCreateInsecureContext() throws SSLException { - Assertions.assertNotNull(sslFactory.createInsecureContext()); - } - - @Test - void shouldCreateSecureContext() throws SSLException { - Assertions.assertNotNull(sslFactory.createSecureContext( - getPath(KEY_STORE), - getPath(KEYSTORE_PASSWORD), - getPath(TRUST_STORE), - getPath(TRUSTSTORE_PASSWORD))); - } - - @Test - void shouldThrowSslExceptionWhenKeystorePasswordIsIncorrect() { - Assertions.assertThrows(SSLException.class, () -> sslFactory.createSecureContext( - getPath(KEY_STORE), - getPath(TRUSTSTORE_PASSWORD), - getPath(TRUST_STORE), - getPath(TRUSTSTORE_PASSWORD))); - } - - private String getPath(String fileName) { - return this.getClass().getClassLoader().getResource(fileName).getPath(); - } -}
\ No newline at end of file |