use of org.onap.aai.domain.yang.GenericVnfs in project so by onap.
the class AaiResourceIdValidator method validateVnfResourceIdInAAI.
protected String validateVnfResourceIdInAAI(String generatedResourceId, String instanceName, RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException {
Optional<GenericVnf> vnf = bbInputSetupUtils.getRelatedVnfByNameFromServiceInstance(workflowResourceIds.getServiceInstanceId(), instanceName);
if (vnf.isPresent()) {
if (vnf.get().getModelCustomizationId().equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) {
return vnf.get().getVnfId();
} else {
throw new DuplicateNameException("generic-vnf", String.format(NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID, instanceName, vnf.get().getModelCustomizationId()));
}
}
GenericVnfs vnfs = bbInputSetupUtils.getAAIVnfsGloballyByName(instanceName);
if (vnfs != null) {
throw new DuplicateNameException("generic-vnf", String.format(NAME_EXISTS_WITH_DIFF_PARENT, instanceName, vnfs.getGenericVnf().get(0).getVnfId()));
}
return generatedResourceId;
}
use of org.onap.aai.domain.yang.GenericVnfs in project so by onap.
the class BBInputSetupUtilsTest method getAAIVnfsGloballyByName_noAAIResourceTest.
@Test
public void getAAIVnfsGloballyByName_noAAIResourceTest() {
final String vnfName = "vnfName";
doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIPluralResourceUri.class));
GenericVnfs actualGenericVnfs = bbInputSetupUtils.getAAIVnfsGloballyByName(vnfName);
assertNull(actualGenericVnfs);
}
use of org.onap.aai.domain.yang.GenericVnfs in project so by onap.
the class AAIResourcesClientTest method testGetFirstMultipleResults.
@Test
public void testGetFirstMultipleResults() {
GenericVnf vnf = new GenericVnf();
vnf.setVnfId("my-vnf-id");
GenericVnf vnf2 = new GenericVnf();
vnf2.setVnfId("my-vnf-id2");
GenericVnfs vnfs = new GenericVnfs();
vnfs.getGenericVnf().add(vnf);
vnfs.getGenericVnf().add(vnf2);
AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnfs());
RestClient restClientMock = mock(RestClient.class);
doReturn(restClientMock).when(client).createClient(uri);
when(restClientMock.get(GenericVnfs.class)).thenReturn(Optional.of(vnfs));
Optional<GenericVnf> result = aaiClient.getFirst(GenericVnfs.class, GenericVnf.class, uri);
assertEquals("my-vnf-id", result.get().getVnfId());
}
use of org.onap.aai.domain.yang.GenericVnfs in project so by onap.
the class AaiConnection method receiveGenericVnfId.
public String receiveGenericVnfId(final String href) {
final AAIPluralResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnfs()).queryParam(SELFLINK, href);
final Optional<GenericVnfs> response = getResourcesClient().get(GenericVnfs.class, resourceUri);
if (response.isPresent()) {
final GenericVnfs vnfs = response.get();
logger.info("The AAI replied with: {}", vnfs);
final List<GenericVnf> genericVnfList = vnfs.getGenericVnf();
final int size = genericVnfList.size();
if (size == 1) {
final GenericVnf genericVnf = genericVnfList.get(FIRST_INDEX);
return genericVnf.getVnfId();
} else if (size > 1) {
logger.warn("more generic vnfs available");
}
}
return null;
}
use of org.onap.aai.domain.yang.GenericVnfs in project so by onap.
the class AaiResourceIdValidatorTest method validateResourceIdInAAIVnfNotGloballyUniqueTest.
@Test
public void validateResourceIdInAAIVnfNotGloballyUniqueTest() throws Exception {
RequestDetails reqDetails = setupRequestDetails();
GenericVnfs genericVnfs = new GenericVnfs();
GenericVnf vnf3 = new GenericVnf();
vnf3.setVnfId("id123");
genericVnfs.getGenericVnf().add(vnf3);
when(bbInputSetupUtilsMock.getAAIVnfsGloballyByName("vnfName333")).thenReturn(genericVnfs);
this.expectedException.expect(DuplicateNameException.class);
this.expectedException.expectMessage(containsString("generic-vnf with name (vnfName333) id (id123) and different parent relationship already exists. The name must be unique."));
testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VNF, "vnfName333", reqDetails, new WorkflowResourceIds());
}
Aggregations