Search in sources :

Example 1 with StateListener

use of com.cloud.utils.fsm.StateListener in project cloudstack by apache.

the class ConfigDriveNetworkElementTest method testExpunge.

@Test
@SuppressWarnings("unchecked")
public void testExpunge() throws NoTransitionException, NoSuchFieldException, IllegalAccessException {
    final StateMachine2<VirtualMachine.State, VirtualMachine.Event, VirtualMachine> stateMachine = VirtualMachine.State.getStateMachine();
    final Field listenersField = StateMachine2.class.getDeclaredField("_listeners");
    listenersField.setAccessible(true);
    List<StateListener<VirtualMachine.State, VirtualMachine.Event, VirtualMachine>> listeners = (List<StateListener<VirtualMachine.State, VirtualMachine.Event, VirtualMachine>>) listenersField.get(stateMachine);
    listeners.clear();
    _configDrivesNetworkElement.start();
    when(virtualMachine.getState()).thenReturn(VirtualMachine.State.Stopped);
    when(_vmInstanceDao.updateState(VirtualMachine.State.Stopped, VirtualMachine.Event.ExpungeOperation, VirtualMachine.State.Expunging, virtualMachine, null)).thenReturn(true);
    final HandleConfigDriveIsoAnswer answer = mock(HandleConfigDriveIsoAnswer.class);
    when(agentManager.easySend(anyLong(), any(HandleConfigDriveIsoCommand.class))).thenReturn(answer);
    when(answer.getResult()).thenReturn(true);
    stateMachine.transitTo(virtualMachine, VirtualMachine.Event.ExpungeOperation, null, _vmInstanceDao);
    ArgumentCaptor<HandleConfigDriveIsoCommand> commandCaptor = ArgumentCaptor.forClass(HandleConfigDriveIsoCommand.class);
    verify(agentManager, times(1)).easySend(anyLong(), commandCaptor.capture());
    HandleConfigDriveIsoCommand deleteCommand = commandCaptor.getValue();
    assertThat(deleteCommand.isCreate(), is(false));
}
Also used : Field(java.lang.reflect.Field) HandleConfigDriveIsoAnswer(com.cloud.agent.api.HandleConfigDriveIsoAnswer) HandleConfigDriveIsoCommand(com.cloud.agent.api.HandleConfigDriveIsoCommand) StateListener(com.cloud.utils.fsm.StateListener) List(java.util.List) VirtualMachine(com.cloud.vm.VirtualMachine) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

HandleConfigDriveIsoAnswer (com.cloud.agent.api.HandleConfigDriveIsoAnswer)1 HandleConfigDriveIsoCommand (com.cloud.agent.api.HandleConfigDriveIsoCommand)1 StateListener (com.cloud.utils.fsm.StateListener)1 VirtualMachine (com.cloud.vm.VirtualMachine)1 Field (java.lang.reflect.Field)1 List (java.util.List)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1