+ @Test
+ public void existingPnfInAaiWithInventoriedStatusCanBeUsed() throws Exception {
+ // given
+ org.onap.aai.domain.yang.Pnf pnfFromAai = createPnf(OrchestrationStatus.INVENTORIED.toString());
+ when(injectionHelperMock.getAaiClient().get(org.onap.aai.domain.yang.Pnf.class,
+ AAIUriFactory.createResourceUri(AAIObjectType.PNF, PNF_NAME))).thenReturn(Optional.of(pnfFromAai));
+ // when
+ testedObject.checkIfPnfExistsInAaiAndCanBeUsed(PNF_NAME);
+ }
+
+ @Test
+ public void existingPnfInAaiWithNullStatusCanBeUsed() throws Exception {
+ // given
+ org.onap.aai.domain.yang.Pnf pnfFromAai = createPnf(null);
+ when(injectionHelperMock.getAaiClient().get(org.onap.aai.domain.yang.Pnf.class,
+ AAIUriFactory.createResourceUri(AAIObjectType.PNF, PNF_NAME))).thenReturn(Optional.of(pnfFromAai));
+ // when
+ testedObject.checkIfPnfExistsInAaiAndCanBeUsed(PNF_NAME);
+ }
+
+ @Test
+ public void existingPnfInAaiWithEmptyStatusCanBeUsed() throws Exception {
+ // given
+ org.onap.aai.domain.yang.Pnf pnfFromAai = createPnf(Strings.EMPTY);
+ when(injectionHelperMock.getAaiClient().get(org.onap.aai.domain.yang.Pnf.class,
+ AAIUriFactory.createResourceUri(AAIObjectType.PNF, PNF_NAME))).thenReturn(Optional.of(pnfFromAai));
+ // when
+ testedObject.checkIfPnfExistsInAaiAndCanBeUsed(PNF_NAME);
+ }
+
+ @Test
+ public void existingPnfInAaiCanNotBeUsed() {
+ // given
+ org.onap.aai.domain.yang.Pnf pnfFromAai = createPnf(OrchestrationStatus.ACTIVE.toString());
+ when(injectionHelperMock.getAaiClient().get(org.onap.aai.domain.yang.Pnf.class,
+ AAIUriFactory.createResourceUri(AAIObjectType.PNF, PNF_NAME))).thenReturn(Optional.of(pnfFromAai));
+ // when
+ try {
+ testedObject.checkIfPnfExistsInAaiAndCanBeUsed(PNF_NAME);
+ } catch (Exception e) {
+ // then
+ assertThat(e.getMessage()).isEqualTo(String.format(
+ "pnf with name %s already exists with orchestration status Active, only status Inventoried allows to use existing pnf",
+ PNF_NAME));
+ }
+ }
+
+ private org.onap.aai.domain.yang.Pnf createPnf(String orchestrationStatus) {
+ org.onap.aai.domain.yang.Pnf pnfFromAai = new org.onap.aai.domain.yang.Pnf();
+ pnfFromAai.setPnfName(PNF_NAME);
+ pnfFromAai.setOrchestrationStatus(orchestrationStatus);
+ return pnfFromAai;
+ }