use of com.cloud.agent.api.CreateLogicalSwitchCommand in project cloudstack by apache.
the class NiciraNvpResourceTest method testCreateLogicalSwitchApiException.
@Test
public void testCreateLogicalSwitchApiException() throws ConfigurationException, NiciraNvpApiException {
resource.configure("NiciraNvpResource", parameters);
final LogicalSwitch ls = mock(LogicalSwitch.class);
when(ls.getUuid()).thenReturn("cccc").thenReturn("cccc");
when(nvpApi.createLogicalSwitch((LogicalSwitch) any())).thenThrow(new NiciraNvpApiException());
final CreateLogicalSwitchCommand clsc = new CreateLogicalSwitchCommand((String) parameters.get("guid"), "stt", "loigicalswitch", "owner");
final CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) resource.executeRequest(clsc);
assertFalse(clsa.getResult());
}
use of com.cloud.agent.api.CreateLogicalSwitchCommand in project cloudstack by apache.
the class NiciraNvpRequestWrapperTest method testCreateLogicalSwitchCommandWrapper.
@Test
public void testCreateLogicalSwitchCommandWrapper() {
final NiciraNvpApi niciraNvpApi = Mockito.mock(NiciraNvpApi.class);
final NiciraNvpUtilities niciraNvpUtilities = Mockito.mock(NiciraNvpUtilities.class);
final LogicalSwitch logicalSwitch = Mockito.mock(LogicalSwitch.class);
final String transportUuid = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
final String transportType = "stt";
final String name = "logicalswitch";
final String ownerName = "owner";
final CreateLogicalSwitchCommand command = new CreateLogicalSwitchCommand(transportUuid, transportType, name, ownerName);
final String truncated = "lswitch-" + command.getName();
when(niciraNvpResource.getNiciraNvpUtilities()).thenReturn(niciraNvpUtilities);
when(niciraNvpUtilities.createLogicalSwitch()).thenReturn(logicalSwitch);
when(niciraNvpResource.truncate("lswitch-" + command.getName(), NiciraNvpResource.NAME_MAX_LEN)).thenReturn(truncated);
when(niciraNvpResource.getNiciraNvpApi()).thenReturn(niciraNvpApi);
try {
when(niciraNvpApi.createLogicalSwitch(logicalSwitch)).thenReturn(logicalSwitch);
when(logicalSwitch.getUuid()).thenReturn(transportUuid);
} catch (final NiciraNvpApiException e) {
fail(e.getMessage());
}
final NiciraNvpRequestWrapper wrapper = NiciraNvpRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, niciraNvpResource);
assertTrue(answer.getResult());
}
use of com.cloud.agent.api.CreateLogicalSwitchCommand in project cosmic by MissionCriticalCloud.
the class NiciraNvpResourceTest method testRetries.
@Test
public void testRetries() throws ConfigurationException, NiciraNvpApiException {
resource.configure("NiciraNvpResource", parameters);
final LogicalSwitch ls = mock(LogicalSwitch.class);
when(ls.getUuid()).thenReturn("cccc").thenReturn("cccc");
when(nvpApi.createLogicalSwitch((LogicalSwitch) any())).thenThrow(new NiciraNvpApiException()).thenThrow(new NiciraNvpApiException()).thenReturn(ls);
final CreateLogicalSwitchCommand clsc = new CreateLogicalSwitchCommand((String) parameters.get("guid"), "stt", "loigicalswitch", "owner", null);
final CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) resource.executeRequest(clsc);
assertTrue(clsa.getResult());
}
use of com.cloud.agent.api.CreateLogicalSwitchCommand in project cosmic by MissionCriticalCloud.
the class NiciraNvpRequestWrapperTest method testCreateLogicalSwitchCommandWrapper.
@Test
public void testCreateLogicalSwitchCommandWrapper() {
final NiciraNvpApi niciraNvpApi = Mockito.mock(NiciraNvpApi.class);
final NiciraNvpUtilities niciraNvpUtilities = Mockito.mock(NiciraNvpUtilities.class);
final LogicalSwitch logicalSwitch = Mockito.mock(LogicalSwitch.class);
final String transportUuid = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
final String transportType = "stt";
final String name = "logicalswitch";
final String ownerName = "owner";
final CreateLogicalSwitchCommand command = new CreateLogicalSwitchCommand(transportUuid, transportType, name, ownerName, null);
final String truncated = "lswitch-" + command.getName();
when(niciraNvpResource.getNiciraNvpUtilities()).thenReturn(niciraNvpUtilities);
when(niciraNvpUtilities.createLogicalSwitch()).thenReturn(logicalSwitch);
when(niciraNvpResource.truncate("lswitch-" + command.getName(), NiciraNvpResource.NAME_MAX_LEN)).thenReturn(truncated);
when(niciraNvpResource.getNiciraNvpApi()).thenReturn(niciraNvpApi);
try {
when(niciraNvpApi.createLogicalSwitch(logicalSwitch)).thenReturn(logicalSwitch);
when(logicalSwitch.getUuid()).thenReturn(transportUuid);
} catch (final NiciraNvpApiException e) {
fail(e.getMessage());
}
final NiciraNvpRequestWrapper wrapper = NiciraNvpRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, niciraNvpResource);
assertTrue(answer.getResult());
}
use of com.cloud.agent.api.CreateLogicalSwitchCommand in project cosmic by MissionCriticalCloud.
the class NiciraNvpResourceTest method testCreateLogicalSwitchApiException.
@Test
public void testCreateLogicalSwitchApiException() throws ConfigurationException, NiciraNvpApiException {
resource.configure("NiciraNvpResource", parameters);
final LogicalSwitch ls = mock(LogicalSwitch.class);
when(ls.getUuid()).thenReturn("cccc").thenReturn("cccc");
when(nvpApi.createLogicalSwitch((LogicalSwitch) any())).thenThrow(new NiciraNvpApiException());
final CreateLogicalSwitchCommand clsc = new CreateLogicalSwitchCommand((String) parameters.get("guid"), "stt", "loigicalswitch", "owner", null);
final CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) resource.executeRequest(clsc);
assertFalse(clsa.getResult());
}
Aggregations