diff options
author | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2018-11-28 11:05:39 -0500 |
---|---|---|
committer | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2018-11-28 11:09:09 -0500 |
commit | 7f1a2052c6d793a1b77199ac8d98c08cf88df1d1 (patch) | |
tree | 3262ad7c9afc18fa4259cd496c739f1473871798 /bpmn/so-bpmn-tasks/src/test/java | |
parent | b9264cfc0c81ac25416268956c4ab389fdf0fcf6 (diff) |
Add support for naming service
Moved client and builder to namingservice package
Renamed file to NamingRequestObjectBuilder and updated packages
Updated namespaces for namingservice beans
Removed unused test resource files
Added endpoint and authentication information to yaml
Added NamingMapperTest for mapper layer
Added NamingMapper for mapping requests and responses
Began adding NamingClient for assign and unassign requests
Added maven dependency for namingmS client beans
Describe NamingClientResponseValidator as a Bean
Fix a JUnit for delete tasks for Naming Service.
Change NamingClient to return a String with the result and throw an
exception.
Add delete/create tasks for NamingService interaction and related
JUnits.
ResponseValidator for NamingClient and Resources class to support
Naming Service interactions.
removed naming service dependency
added serializable flag for naming service model gen
Change-Id: I0d9efe4009207f3739a3b6515592e67cfeedf822
Issue-ID: SO-1260
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/test/java')
6 files changed, 431 insertions, 0 deletions
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java index 95201d555d..21b89c3731 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java @@ -44,6 +44,7 @@ import org.onap.so.client.orchestration.AAIVfModuleResources; import org.onap.so.client.orchestration.AAIVnfResources; import org.onap.so.client.orchestration.AAIVolumeGroupResources; import org.onap.so.client.orchestration.AAIVpnBindingResources; +import org.onap.so.client.orchestration.NamingServiceResources; import org.onap.so.client.orchestration.NetworkAdapterResources; import org.onap.so.client.orchestration.SDNCNetworkResources; import org.onap.so.client.orchestration.SDNCServiceInstanceResources; @@ -111,6 +112,9 @@ public abstract class BaseTaskTest extends TestDataSetup { @Mock protected AAIInstanceGroupResources aaiInstanceGroupResources; + + @Mock + protected NamingServiceResources namingServiceResources; @Mock protected ApplicationControllerAction appCClient; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasksTest.java new file mode 100644 index 0000000000..41739f37e6 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasksTest.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T 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.so.bpmn.infrastructure.namingservice.tasks; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentMatchers; +import org.mockito.InjectMocks; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.client.exception.BBObjectNotFoundException; + +public class NamingServiceCreateTasksTest extends BaseTaskTest { + @InjectMocks + private NamingServiceCreateTasks namingServiceCreateTasks = new NamingServiceCreateTasks(); + + private InstanceGroup instanceGroup; + + @Before + public void before() throws BBObjectNotFoundException { + instanceGroup = setInstanceGroup(); + when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.INSTANCE_GROUP_ID), any())).thenReturn(instanceGroup); + } + + @Test + public void createInstanceGroupTest() throws Exception { + String policyInstanceName = "policyInstanceName"; + String nfNamingCode = "nfNamingCode"; + String generatedName = "generatedInstanceGroupName"; + execution.setVariable(policyInstanceName, policyInstanceName); + execution.setVariable(nfNamingCode, nfNamingCode); + doReturn(generatedName).when(namingServiceResources).generateInstanceGroupName(instanceGroup, policyInstanceName, nfNamingCode); + + namingServiceCreateTasks.createInstanceGroupName(execution); + verify(namingServiceResources, times(1)).generateInstanceGroupName(instanceGroup, policyInstanceName, nfNamingCode); + assertEquals(instanceGroup.getInstanceGroupName(), generatedName); + } + + @Test + public void createInstanceGroupExceptionTest() throws Exception { + expectedException.expect(BBObjectNotFoundException.class); + lookupKeyMap.put(ResourceKey.INSTANCE_GROUP_ID, "notfound"); + doThrow(BBObjectNotFoundException.class).when(extractPojosForBB).extractByKey(any(),ArgumentMatchers.eq(ResourceKey.INSTANCE_GROUP_ID),eq("notfound")); + String policyInstanceName = "policyInstanceName"; + String nfNamingCode = "nfNamingCode"; + execution.setVariable(policyInstanceName, policyInstanceName); + execution.setVariable(nfNamingCode, nfNamingCode); + doReturn("").when(namingServiceResources).generateInstanceGroupName(instanceGroup, policyInstanceName, nfNamingCode); + namingServiceCreateTasks.createInstanceGroupName(execution); + verify(namingServiceResources, times(1)).generateInstanceGroupName(instanceGroup, policyInstanceName, nfNamingCode); + + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasksTest.java new file mode 100644 index 0000000000..97dcc617ac --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasksTest.java @@ -0,0 +1,71 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T 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.so.bpmn.infrastructure.namingservice.tasks; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentMatchers; +import org.mockito.InjectMocks; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.client.exception.BBObjectNotFoundException; + +public class NamingServiceDeleteTasksTest extends BaseTaskTest { + @InjectMocks + private NamingServiceDeleteTasks namingServiceDeleteTasks = new NamingServiceDeleteTasks(); + + private InstanceGroup instanceGroup; + + @Before + public void before() throws BBObjectNotFoundException { + instanceGroup = setInstanceGroup(); + when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.INSTANCE_GROUP_ID), any())).thenReturn(instanceGroup); + } + + @Test + public void deleteInstanceGroupTest() throws Exception { + + doReturn("").when(namingServiceResources).deleteInstanceGroupName(instanceGroup); + + namingServiceDeleteTasks.deleteInstanceGroupName(execution); + verify(namingServiceResources, times(1)).deleteInstanceGroupName(instanceGroup); + } + + @Test + public void deleteInstanceGroupExceptionTest() throws Exception { + expectedException.expect(BBObjectNotFoundException.class); + lookupKeyMap.put(ResourceKey.INSTANCE_GROUP_ID, "notfound"); + doThrow(BBObjectNotFoundException.class).when(extractPojosForBB).extractByKey(any(),ArgumentMatchers.eq(ResourceKey.INSTANCE_GROUP_ID),eq("notfound")); + doReturn("").when(namingServiceResources).deleteInstanceGroupName(instanceGroup); + namingServiceDeleteTasks.deleteInstanceGroupName(execution); + verify(namingServiceResources, times(1)).deleteInstanceGroupName(instanceGroup); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientResponseValidatorTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientResponseValidatorTest.java new file mode 100644 index 0000000000..70036e7480 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientResponseValidatorTest.java @@ -0,0 +1,84 @@ +package org.onap.so.client.namingservice; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.onap.namingservice.model.NameGenDeleteResponse; +import org.onap.namingservice.model.NameGenResponse; +import org.onap.namingservice.model.Respelement; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.so.client.exception.BadResponseException; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +public class NamingClientResponseValidatorTest extends TestDataSetup { + + private NamingClientResponseValidator responseValidator = new NamingClientResponseValidator(); + private String instanceGroupName = "generatedInstanceGroupName"; + + @Test + public void validateNameGenResponseSuccessTest() throws BadResponseException { + NameGenResponse name = new NameGenResponse(); + Respelement respElement = new Respelement(); + respElement.setResourceName("instance-group-name"); + respElement.setResourceValue(instanceGroupName); + List<Respelement> respList = new ArrayList<Respelement>(); + respList.add(respElement); + name.setElements(respList); + ResponseEntity<NameGenResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK); + + String actual = responseValidator.validateNameGenResponse(resp); + + assertEquals(actual, "generatedInstanceGroupName"); + } + + @Test + public void validateNameGenResponseNoNameGeneratedTest() throws BadResponseException { + NameGenResponse name = new NameGenResponse(); + Respelement respElement = new Respelement(); + respElement.setResourceName("instance-group"); + respElement.setResourceValue(instanceGroupName); + List<Respelement> respList = new ArrayList<Respelement>(); + respList.add(respElement); + name.setElements(respList); + ResponseEntity<NameGenResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK); + + String actual = responseValidator.validateNameGenResponse(resp); + + assertEquals(actual, ""); + } + + @Test + public void validateNameGenResponseBadStatusTest() throws BadResponseException { + NameGenResponse name = new NameGenResponse(); + + ResponseEntity<NameGenResponse> resp = new ResponseEntity<>(name, null, HttpStatus.NOT_FOUND); + + expectedException.expect(BadResponseException.class); + responseValidator.validateNameGenResponse(resp); + } + + @Test + public void validateNameGenDeleteResponseSuccessTest() throws BadResponseException { + NameGenDeleteResponse name = new NameGenDeleteResponse(); + ResponseEntity<NameGenDeleteResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK); + + String actual = responseValidator.validateNameGenDeleteResponse(resp); + + assertEquals(actual, ""); + } + + @Test + public void validateNameGenDeleteResponseBadStatusTest() throws BadResponseException { + NameGenDeleteResponse name = new NameGenDeleteResponse(); + + ResponseEntity<NameGenDeleteResponse> resp = new ResponseEntity<>(name, null, HttpStatus.NOT_FOUND); + + expectedException.expect(BadResponseException.class); + responseValidator.validateNameGenDeleteResponse(resp); + } + +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingRequestObjectBuilderTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingRequestObjectBuilderTest.java new file mode 100644 index 0000000000..0a2dc1e4fa --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingRequestObjectBuilderTest.java @@ -0,0 +1,85 @@ +package org.onap.so.client.namingservice; + +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.junit.Assert.assertThat; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.onap.namingservice.model.Deleteelement; +import org.onap.namingservice.model.Element; +import org.onap.namingservice.model.NameGenDeleteRequest; +import org.onap.namingservice.model.NameGenRequest; +import org.onap.so.client.namingservice.NamingRequestObjectBuilder; + +public class NamingRequestObjectBuilderTest { + + private NamingRequestObjectBuilder mapper = new NamingRequestObjectBuilder(); + private String instanceGroupId = "95cbbe59-1017-4c13-b4e8-d824e54def3e"; + private String policyInstanceName = "MSO_Policy.Config_MS_VNFInstanceGroup"; + private String namingType = "InstanceGroup"; + private String nfNamingCode = "NamingCode"; + private String instanceGroupName = "InstanceGroupName"; + + @Test + public void elementMapperTest(){ + // Expected element + Element expected = new Element(); + expected.setExternalKey(instanceGroupId); + expected.setPolicyInstanceName(policyInstanceName); + expected.setNamingType(namingType); + expected.setResourceName(instanceGroupName); + expected.setNamingIngredientsZeroOrMore(nfNamingCode); + + // Actual element + Element actual = mapper.elementMapper(instanceGroupId, policyInstanceName, namingType, nfNamingCode, instanceGroupName); + + assertThat(actual, sameBeanAs(expected)); + } + @Test + public void deleteElementMapperTest(){ + // Expected Deleteelement + Deleteelement expected = new Deleteelement(); + expected.setExternalKey(instanceGroupId); + + // Actual Deleteelement + Deleteelement actual = mapper.deleteElementMapper(instanceGroupId); + + assertThat(actual, sameBeanAs(expected)); + } + @Test + public void nameGenRequestMapper(){ + // Expected NameGenRequest + NameGenRequest expected = new NameGenRequest(); + List<Element> elements = new ArrayList<>(); + Element element = new Element(); + element.setExternalKey(instanceGroupId); + element.setPolicyInstanceName(policyInstanceName); + element.setNamingType(namingType); + element.setResourceName(instanceGroupName); + element.setNamingIngredientsZeroOrMore(nfNamingCode); + elements.add(element); + expected.setElements(elements); + + //Actual NameGenRequest + NameGenRequest actual = mapper.nameGenRequestMapper(elements); + + assertThat(actual, sameBeanAs(expected)); + } + @Test + public void nameGenDeleteRequestMapper(){ + // Expected NameGenDeleteRequest + NameGenDeleteRequest expected = new NameGenDeleteRequest(); + List<Deleteelement> deleteElements = new ArrayList<>(); + Deleteelement deleteElement = new Deleteelement(); + deleteElement.setExternalKey(instanceGroupId); + deleteElements.add(deleteElement); + expected.setElements(deleteElements); + + // Actual NameGenDeleteRequest + NameGenDeleteRequest actual = mapper.nameGenDeleteRequestMapper(deleteElements); + + assertThat(actual, sameBeanAs(expected)); + } +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/NamingServiceResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/NamingServiceResourcesTest.java new file mode 100644 index 0000000000..629e98abb2 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/NamingServiceResourcesTest.java @@ -0,0 +1,105 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T 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.so.client.orchestration; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.bpmn.common.data.TestDataSetup; +import org.onap.namingservice.model.Deleteelement; +import org.onap.namingservice.model.Element; +import org.onap.namingservice.model.NameGenDeleteRequest; +import org.onap.namingservice.model.NameGenDeleteResponse; +import org.onap.namingservice.model.NameGenRequest; +import org.onap.namingservice.model.NameGenResponse; +import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; +import org.onap.so.client.namingservice.NamingClient; +import org.onap.so.client.namingservice.NamingRequestObjectBuilder; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +@RunWith(MockitoJUnitRunner.Silent.class) +public class NamingServiceResourcesTest extends TestDataSetup{ + @InjectMocks + private NamingServiceResources namingServiceResources = new NamingServiceResources(); + + private InstanceGroup instanceGroup; + + @Mock + protected NamingRequestObjectBuilder MOCK_namingRequestObjectBuilder; + + @Mock + protected NamingClient MOCK_namingClient; + + @Before + public void before() { + instanceGroup = buildInstanceGroup(); + } + + @Test + public void generateInstanceGroupNameTest() throws Exception { + NameGenResponse name = new NameGenResponse(); + ResponseEntity<NameGenResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK); + Element element = new Element(); + + NameGenRequest req = new NameGenRequest(); + doReturn(element).when(MOCK_namingRequestObjectBuilder).elementMapper(isA(String.class), isA(String.class), + isA(String.class), isA(String.class), isA(String.class)); + doReturn("generatedInstanceGroupName").when(MOCK_namingClient).postNameGenRequest(isA(NameGenRequest.class)); + doReturn(req).when(MOCK_namingRequestObjectBuilder).nameGenRequestMapper(isA(List.class)); + + String generatedName = namingServiceResources.generateInstanceGroupName(instanceGroup, "policyInstanceName", "nfNamingCode"); + + verify(MOCK_namingClient, times(1)).postNameGenRequest(any(NameGenRequest.class)); + assertEquals(generatedName, "generatedInstanceGroupName"); + } + + @Test + public void deleteInstanceGroupNameTest() throws Exception { + NameGenDeleteResponse name = new NameGenDeleteResponse(); + ResponseEntity<NameGenDeleteResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK); + Deleteelement deleteElement = new Deleteelement(); + deleteElement.setExternalKey(instanceGroup.getId()); + NameGenDeleteRequest req = new NameGenDeleteRequest(); + doReturn(deleteElement).when(MOCK_namingRequestObjectBuilder).deleteElementMapper(isA(String.class)); + doReturn("").when(MOCK_namingClient).deleteNameGenRequest(isA(NameGenDeleteRequest.class)); + doReturn(req).when(MOCK_namingRequestObjectBuilder).nameGenDeleteRequestMapper(isA(List.class)); + + namingServiceResources.deleteInstanceGroupName(instanceGroup); + + verify(MOCK_namingClient, times(1)).deleteNameGenRequest(any(NameGenDeleteRequest.class)); + + } + + +} |