Search in sources :

Example 1 with Action

use of org.openstack4j.model.compute.Action in project camel by apache.

the class ServerProducerTest method serverAction.

@Test
public void serverAction() throws Exception {
    when(serverService.action(anyString(), any(Action.class))).thenReturn(ActionResponse.actionSuccess());
    when(endpoint.getOperation()).thenReturn(NovaConstants.ACTION);
    String id = "myID";
    msg.setHeader(NovaConstants.ACTION, Action.PAUSE);
    msg.setHeader(OpenstackConstants.ID, id);
    producer.process(exchange);
    ArgumentCaptor<Action> actionArgumentCaptor = ArgumentCaptor.forClass(Action.class);
    ArgumentCaptor<String> idArgumentCaptor = ArgumentCaptor.forClass(String.class);
    verify(serverService).action(idArgumentCaptor.capture(), actionArgumentCaptor.capture());
    assertEquals(id, idArgumentCaptor.getValue());
    assertTrue(actionArgumentCaptor.getValue() == Action.PAUSE);
    assertFalse(msg.isFault());
    assertNull(msg.getBody());
    //test fail
    final String failReason = "fr";
    when(serverService.action(anyString(), any(Action.class))).thenReturn(ActionResponse.actionFailed(failReason, 401));
    producer.process(exchange);
    assertTrue(msg.isFault());
    assertTrue(msg.getBody(String.class).contains(failReason));
}
Also used : Action(org.openstack4j.model.compute.Action) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 2 with Action

use of org.openstack4j.model.compute.Action in project camel by apache.

the class ServerProducer method doAction.

private void doAction(Exchange exchange) {
    final Message msg = exchange.getIn();
    final Action action = msg.getHeader(NovaConstants.ACTION, Action.class);
    final String serverId = msg.getHeader(OpenstackConstants.ID, String.class);
    ObjectHelper.notNull(action, "Server action");
    ObjectHelper.notEmpty(serverId, "Server ID");
    final ActionResponse response = os.compute().servers().action(serverId, action);
    checkFailure(response, msg, "Performing action " + action.name());
}
Also used : Action(org.openstack4j.model.compute.Action) Message(org.apache.camel.Message) ActionResponse(org.openstack4j.model.common.ActionResponse)

Aggregations

Action (org.openstack4j.model.compute.Action)2 Message (org.apache.camel.Message)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 ActionResponse (org.openstack4j.model.common.ActionResponse)1