### Question:
AssignVnf { public void createInstanceGroups(BuildingBlockExecution execution) { try { GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); List<InstanceGroup> instanceGroups = vnf.getInstanceGroups(); for (InstanceGroup instanceGroup : instanceGroups) { if (ModelInfoInstanceGroup.TYPE_VNFC .equalsIgnoreCase(instanceGroup.getModelInfoInstanceGroup().getType())) { instanceGroup.setInstanceGroupName( aaiObjectInstanceNameGenerator.generateInstanceGroupName(instanceGroup, vnf)); aaiInstanceGroupResources.createInstanceGroup(instanceGroup); aaiInstanceGroupResources.connectInstanceGroupToVnf(instanceGroup, vnf, AAIEdgeLabel.BELONGS_TO); } else if (ModelInfoInstanceGroup.TYPE_L3_NETWORK .equalsIgnoreCase(instanceGroup.getModelInfoInstanceGroup().getType())) { aaiInstanceGroupResources.connectInstanceGroupToVnf(instanceGroup, vnf, AAIEdgeLabel.USES); } } } catch (Exception ex) { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); } }  void createInstanceGroups(BuildingBlockExecution execution);  }### Answer:
@Test public void createInstanceGroupsSunnyDayTest() throws Exception { List<InstanceGroup> instanceGroupList = genericVnf.getInstanceGroups(); instanceGroupList.add(instanceGroup1); instanceGroupList.add(instanceGroup2); instanceGroupList.add(instanceGroup3); instanceGroupList.add(instanceGroup4); assignVnf.createInstanceGroups(execution); verify(aaiInstanceGroupResources, times(1)).createInstanceGroup(instanceGroup1); verify(aaiInstanceGroupResources, times(1)).createInstanceGroup(instanceGroup2); verify(aaiInstanceGroupResources, times(1)).connectInstanceGroupToVnf(instanceGroup1, genericVnf, AAIEdgeLabel.BELONGS_TO); verify(aaiInstanceGroupResources, times(1)).connectInstanceGroupToVnf(instanceGroup2, genericVnf, AAIEdgeLabel.BELONGS_TO); verify(aaiInstanceGroupResources, times(1)).connectInstanceGroupToVnf(instanceGroup3, genericVnf, AAIEdgeLabel.USES); verify(aaiInstanceGroupResources, times(1)).connectInstanceGroupToVnf(instanceGroup4, genericVnf, AAIEdgeLabel.USES); }
@Test public void createVnfcInstanceGroupNoneTest() throws Exception { assignVnf.createInstanceGroups(execution); verify(aaiInstanceGroupResources, times(0)).createInstanceGroup(any(InstanceGroup.class)); verify(aaiInstanceGroupResources, times(0)).connectInstanceGroupToVnf(any(InstanceGroup.class), any(GenericVnf.class)); }
@Test public void createVnfcInstanceGroupExceptionTest() throws Exception { List<InstanceGroup> instanceGroupList = genericVnf.getInstanceGroups(); instanceGroupList.add(instanceGroup1); instanceGroupList.add(instanceGroup2); instanceGroupList.add(instanceGroup3); instanceGroupList.add(instanceGroup4); doThrow(RuntimeException.class).when(aaiInstanceGroupResources).createInstanceGroup(isA(InstanceGroup.class)); expectedException.expect(BpmnError.class); genericVnf.setVnfId("test-999"); assignVnf.createInstanceGroups(execution); }