@Override public void create() throws ResourceAllocationException { PhysicalNetworkServiceProvider result = _networkService.addProviderToPhysicalNetwork(getPhysicalNetworkId(), getProviderName(), getDestinationPhysicalNetworkId(), getEnabledServices()); if (result != null) { setEntityId(result.getId()); setEntityUuid(result.getUuid()); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add service provider entity to physical network"); } }
@Override public String getEventDescription() { return "Adding physical network ServiceProvider: " + getEntityId(); }
@Override public void execute() { CallContext.current().setEventDetails("Network ServiceProvider Id: " + getEntityId()); PhysicalNetworkServiceProvider result = _networkService.getCreatedPhysicalNetworkServiceProvider(getEntityId()); if (result != null) { ProviderResponse response = _responseGenerator.createNetworkServiceProviderResponse(result); response.setResponseName(getCommandName()); this.setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add service provider to physical network"); } }
@Test public void testCreateProviderToPhysicalNetworkFailure() throws ResourceAllocationException { NetworkService networkService = Mockito.mock(NetworkService.class); addNetworkServiceProviderCmd._networkService = networkService; Mockito.when(networkService.addProviderToPhysicalNetwork(Matchers.anyLong(), Matchers.anyString(), Matchers.anyLong(), Matchers.anyList())).thenReturn(null); try { addNetworkServiceProviderCmd.create(); } catch (ServerApiException exception) { Assert.assertEquals("Failed to add service provider entity to physical network", exception.getDescription()); } }
@Test public void testCreateProviderToPhysicalNetworkSuccess() { NetworkService networkService = Mockito.mock(NetworkService.class); addNetworkServiceProviderCmd._networkService = networkService; PhysicalNetworkServiceProvider physicalNetworkServiceProvider = Mockito.mock(PhysicalNetworkServiceProvider.class); Mockito.when(networkService.addProviderToPhysicalNetwork(Matchers.anyLong(), Matchers.anyString(), Matchers.anyLong(), Matchers.anyList())).thenReturn( physicalNetworkServiceProvider); try { addNetworkServiceProviderCmd.create(); } catch (ResourceAllocationException e) { e.printStackTrace(); } }