From 3b330924bcd41af4dbac2fd8cd1a55a62cc89c33 Mon Sep 17 00:00:00 2001 From: Lukasz Muszkieta Date: Fri, 15 Jan 2021 11:15:58 +0100 Subject: add junit coverage Issue-ID: SO-3433 Signed-off-by: Lukasz Muszkieta Change-Id: I04e8bcc47b92c20bd9eb2a61c243a808e1e312fd Signed-off-by: Lukasz Muszkieta --- .../WorkflowActionExtractResourcesAAITest.java | 83 ++++++++++++++++++++-- 1 file changed, 78 insertions(+), 5 deletions(-) (limited to 'bpmn/so-bpmn-tasks/src/test/java/org/onap') diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAITest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAITest.java index 35a5bfefd7..7ac245d0f4 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAITest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAITest.java @@ -56,7 +56,8 @@ public class WorkflowActionExtractResourcesAAITest { public void extractRelationshipsConfigurationSuccess() { // given Relationships relationships = mock(Relationships.class); - when(relationships.getByType(Types.CONFIGURATION)).thenReturn(getConfigurationList()); + when(relationships.getByType(Types.CONFIGURATION)) + .thenReturn(getConfigurationList("{\"configuration-id\" : \"" + CONFIGURATION_ID + "\"}")); // when Optional resultOpt = testedObject.extractRelationshipsConfiguration(relationships); // then @@ -65,7 +66,18 @@ public class WorkflowActionExtractResourcesAAITest { } @Test - public void extractRelationshipsConfiguration_notFound() { + public void extractRelationshipsConfiguration_noConfigurationFoundInList() { + // given + Relationships relationships = mock(Relationships.class); + when(relationships.getByType(Types.CONFIGURATION)).thenReturn(getConfigurationList("noJson")); + // when + Optional resultOpt = testedObject.extractRelationshipsConfiguration(relationships); + // then + assertThat(resultOpt).isEmpty(); + } + + @Test + public void extractRelationshipsConfiguration_notFound_listEmpty() { // given Relationships relationships = mock(Relationships.class); when(relationships.getByType(Types.CONFIGURATION)).thenReturn(Collections.emptyList()); @@ -92,10 +104,71 @@ public class WorkflowActionExtractResourcesAAITest { assertThat(resultOpt.get().getVpnId()).isEqualTo(VPN_ID); } - private List getConfigurationList() { + @Test + public void extractRelationshipsVpnBinding_noVpnBindingFoundInList() { + // given + Relationships relationships = mock(Relationships.class); + AAIResourceUri aaiResourceUri = mock(AAISimpleUri.class); + List aaiResourceUriList = new ArrayList<>(); + aaiResourceUriList.add(aaiResourceUri); + when(relationships.getRelatedUris(Types.VPN_BINDING)).thenReturn(aaiResourceUriList); + AAIResultWrapper aaiResultWrapper = new AAIResultWrapper("noJson"); + when(bbInputSetupUtils.getAAIResourceDepthOne(aaiResourceUri)).thenReturn(aaiResultWrapper); + // when + Optional resultOpt = testedObject.extractRelationshipsVpnBinding(relationships); + // then + assertThat(resultOpt).isEmpty(); + } + + @Test + public void extractRelationshipsVpnBinding_notFound_listEmpty() { + // given + Relationships relationships = mock(Relationships.class); + when(relationships.getRelatedUris(Types.VPN_BINDING)).thenReturn(Collections.emptyList()); + // when + Optional resultOpt = testedObject.extractRelationshipsVpnBinding(relationships); + // then + assertThat(resultOpt).isEmpty(); + } + + @Test + public void extractRelationshipsVnfcSuccess() { + // given + Relationships relationships = mock(Relationships.class); + when(relationships.getByType(Types.VNFC)).thenReturn( + getConfigurationList("{\"relationship-list\": {\"relationship\": [{\"related-to\": \"tenant\"}]}}")); + // when + Optional resultOpt = testedObject.extractRelationshipsVnfc(relationships); + // then + assertThat(resultOpt).isNotEmpty(); + assertThat(resultOpt.get().getJson()).isEqualTo("{\"relationship\":[{\"related-to\":\"tenant\"}]}"); + } + + @Test + public void extractRelationshipsVnfc_noRelationFoundList() { + // given + Relationships relationships = mock(Relationships.class); + when(relationships.getByType(Types.VNFC)).thenReturn(getConfigurationList("{\"jsonWithNoRelation\": {}}")); + // when + Optional resultOpt = testedObject.extractRelationshipsVnfc(relationships); + // then + assertThat(resultOpt).isEmpty(); + } + + @Test + public void extractRelationshipsVnfc_notFound_listEmpty() { + // given + Relationships relationships = mock(Relationships.class); + when(relationships.getByType(Types.VNFC)).thenReturn(Collections.emptyList()); + // when + Optional resultOpt = testedObject.extractRelationshipsVnfc(relationships); + // then + assertThat(resultOpt).isEmpty(); + } + + private List getConfigurationList(String json) { List configurations = new ArrayList<>(); - AAIResultWrapper aaiResultWrapper = - new AAIResultWrapper("{\"configuration-id\" : \"" + CONFIGURATION_ID + "\"}"); + AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(json); configurations.add(aaiResultWrapper); return configurations; } -- cgit 1.2.3-korg