+ private AAIClient aaiClient = Mockito.mock(AAIClient.class);
+ private final BundleContext bundleContext= Mockito.mock(BundleContext.class);
+ private final Bundle bundleService=Mockito.mock(Bundle.class);
+ private final ServiceReference sref=Mockito.mock(ServiceReference.class);
+
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
+ @Before
+ public void setup() {
+ PowerMockito.mockStatic(FrameworkUtil.class);
+ PowerMockito.when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
+ PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext);
+ PowerMockito.when(bundleContext.getServiceReference(Matchers.any(Class.class))).thenReturn(sref);
+ PowerMockito.when(bundleContext.getService(sref)).thenReturn(aaiClient);
+ }
+
+ @Test
+ public void testMissingVnfId() throws AaiServiceInternalException, SvcLogicException {
+ AaiService aaiService = new AaiService();
+ expectedEx.expect(AaiServiceInternalException.class);
+ expectedEx.expectMessage("VnfId is missing");
+ aaiService.getGenericVnfInfo(new HashMap<String, String>(), new SvcLogicContext());
+ }
+
+ @Test
+ public void testGetVmInfoExceptionFlow() throws SvcLogicException, AaiServiceInternalException {
+ AaiService aaiService = Mockito.spy(new AaiService());
+ Map<String, String> inParams = new HashMap<String, String>();
+ inParams.put("vserverId", "vserverId1");
+ inParams.put("tenantId", "tenantId1");
+ inParams.put("cloudOwner", "cloudOwner1");
+ inParams.put("cloudRegionId", "cloudRegionId1");
+ inParams.put("responsePrefix", "tmp.vnfInfo");
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ Mockito.doThrow(new SvcLogicException()).when(aaiService).readResource(Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("Failed to fetch VM info");
+ aaiService.getVMInfo(inParams, ctx);
+ }
+
+ @Test
+ public void testGetVnfcInfoExceptionFlow() throws Exception {
+ AaiService aaiService = new AaiService();
+ Map<String, String> inParams = new HashMap<String, String>();
+ inParams.put("vnfcName", "");
+ inParams.put("responsePrefix", "tmp.vnfInfo");
+ SvcLogicContext ctx = new SvcLogicContext();
+ expectedEx.expect(AaiServiceInternalException.class);
+ expectedEx.expectMessage("Vnfc Name is missing");
+ aaiService.getVnfcInfo(inParams, ctx);
+ }
+
+ @Test
+ public void testInsertVnfcsExceptionFlow() throws Exception {
+ AaiService aaiService = new AaiService();
+ Map<String, String> inParams = new HashMap<String, String>();
+ inParams.put("responsePrefix", "tmp.vnfInfo");
+ SvcLogicContext ctx = new SvcLogicContext();
+ inParams.put("AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX", "prefix.");
+ ctx.setAttribute("tmp.vnfInfo.vm[1].vnfc-name", "nullnull001");
+ aaiService.insertVnfcs(inParams, ctx, 2, 2, null);
+ }
+
+ @Test
+ public void testGetVnfcData() {
+ AaiService aaiService = new AaiService();
+ Map<String, String> inParams = new HashMap<String, String>();
+ inParams.put("responsePrefix", "tmp.vnfInfo");
+ SvcLogicContext ctx = new SvcLogicContext();
+ inParams.put("AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX", "prefix.");
+ ctx.setAttribute("tmp.vnfInfo.vm[1].vnfc-name", "nullnull001");
+ aaiService.getVnfcData(inParams, ctx, 1, 1);
+ }
+
+ @Test
+ public void testReadResource() throws AaiServiceInternalException, SvcLogicException {
+ AaiService aaiService = Mockito.spy(new AaiService());
+ Map<String, String> inParams = new HashMap<String, String>();
+ inParams.put("responsePrefix", "tmp.vnfInfo");
+ inParams.put("AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX", "prefix.");
+ Mockito.doReturn(QueryStatus.FAILURE).when(aaiClient).query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(SvcLogicContext.class));
+ expectedEx.expect(AaiServiceInternalException.class);
+ expectedEx.expectMessage("Error Retrieving null from A&AI");
+ aaiService.readResource(null, null, null);
+ }
+
+ @Test
+ public void testCheckAndUpdateVnfc() throws AaiServiceInternalException, SvcLogicException {
+ AaiService aaiService = Mockito.spy(new AaiService());
+ Map<String, String> inParams = new HashMap<String, String>();
+ inParams.put("responsePrefix", "tmp.vnfInfo");
+ SvcLogicContext ctx = new SvcLogicContext();
+ inParams.put("AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX", "prefix.");
+ ctx.setAttribute("tmp.vnfInfo.vm[0].vnfc-name", "nullnull001");
+ aaiService.checkAndUpdateVnfc(inParams, ctx, 1, 1);
+ Mockito.verify(aaiService).updateVnfcStatus(Mockito.anyString(), Mockito.anyMap(), Mockito.anyString());
+ }