Search in sources :

Example 6 with ActionParameterRequest

use of org.motechproject.tasks.contract.ActionParameterRequest in project motech by motech.

the class ActionEventDeserializerTest method shouldDeserializeJsonWithActionParameters.

@Test
public void shouldDeserializeJsonWithActionParameters() {
    ActionEventRequest expected = new TestActionEventRequestBuilder().setDisplayName(DISPLAY_NAME_FIELD).setSubject(SUBJECT_FIELD).setDescription(DESCRIPTION_FIELD).setServiceInterface(SERVICE_INTERFACE_FIELD).setServiceMethod(SERVICE_METHOD_FIELD).setActionParameters(getActionParameters()).createActionEventRequest();
    JsonObject object = createJsonObject(expected);
    ActionParameterRequest actionParameterRequestWithoutOrder = new ActionParameterRequestBuilder().setKey("Witout order").setDisplayName("withoutOrder").createActionParameterRequest();
    expected.addParameter(actionParameterRequestWithoutOrder, true);
    object.getAsJsonArray(ACTION_PARAMETERS_FIELD).add(createParameter(actionParameterRequestWithoutOrder));
    ActionEventRequest actual = deserializer.deserialize(object, null, context);
    assertEquals(expected, actual);
}
Also used : JsonObject(com.google.gson.JsonObject) ActionParameterRequest(org.motechproject.tasks.contract.ActionParameterRequest) ActionEventRequest(org.motechproject.tasks.contract.ActionEventRequest) ActionParameterRequestBuilder(org.motechproject.tasks.contract.builder.ActionParameterRequestBuilder) TestActionEventRequestBuilder(org.motechproject.tasks.contract.builder.TestActionEventRequestBuilder) Test(org.junit.Test)

Example 7 with ActionParameterRequest

use of org.motechproject.tasks.contract.ActionParameterRequest in project motech by motech.

the class ActionEventDeserializerTest method getActionParameters.

private SortedSet<ActionParameterRequest> getActionParameters() {
    SortedSet<ActionParameterRequest> parameters = new TreeSet<>();
    parameters.add(new ActionParameterRequestBuilder().setKey(EXTERNAL_DISPLAY_NAME).setDisplayName(EXTERNAL_KEY).setOrder(0).createActionParameterRequest());
    parameters.add(new ActionParameterRequestBuilder().setKey(MOTECH_DISPLAY_NAME).setDisplayName(MOTECH_KEY).setOrder(1).setType(ParameterType.INTEGER.getValue()).createActionParameterRequest());
    return parameters;
}
Also used : TreeSet(java.util.TreeSet) ActionParameterRequest(org.motechproject.tasks.contract.ActionParameterRequest) ActionParameterRequestBuilder(org.motechproject.tasks.contract.builder.ActionParameterRequestBuilder)

Example 8 with ActionParameterRequest

use of org.motechproject.tasks.contract.ActionParameterRequest in project motech by motech.

the class ChannelServiceImplTest method shouldRegisterChannelFromChannelRequest.

@Test
public void shouldRegisterChannelFromChannelRequest() {
    List<ActionEventRequest> actionEventRequests = asList(new TestActionEventRequestBuilder().setDisplayName("actionName").setSubject("subject.foo").setDescription("action description").setServiceInterface("some.interface").setServiceMethod("method").setActionParameters(new TreeSet<ActionParameterRequest>()).setPostActionParameters(new TreeSet<ActionParameterRequest>()).createActionEventRequest());
    List<TriggerEventRequest> triggerEventsRequest = asList(new TriggerEventRequest("displayName", "subject.foo", "description", asList(new EventParameterRequest("displayName", "eventKey"))));
    ChannelRequest channelRequest = new ChannelRequest(BUNDLE_SYMBOLIC_NAME, BUNDLE_SYMBOLIC_NAME, VERSION, "", triggerEventsRequest, actionEventRequests);
    channelService.registerChannel(channelRequest);
    ArgumentCaptor<Channel> captor = ArgumentCaptor.forClass(Channel.class);
    verify(channelsDataService).create(captor.capture());
    Channel channelToBeCreated = captor.getValue();
    assertEquals(BUNDLE_SYMBOLIC_NAME, channelToBeCreated.getDisplayName());
    assertEquals(BUNDLE_SYMBOLIC_NAME, channelToBeCreated.getModuleName());
    assertEquals(VERSION, channelToBeCreated.getModuleVersion());
    assertEquals(1, channelToBeCreated.getTriggerTaskEvents().size());
    TriggerEvent expectedTrigger = new TriggerEvent("displayName", "subject.foo", "description", asList(new EventParameter("displayName", "eventKey")), "");
    TriggerEvent actualTrigger = channelToBeCreated.getTriggerTaskEvents().get(0);
    assertEquals(expectedTrigger, actualTrigger);
    assertEquals(1, channelToBeCreated.getActionTaskEvents().size());
    ActionEvent expectedAction = new ActionEventBuilder().setDisplayName("actionName").setSubject("subject.foo").setDescription("action description").setServiceInterface("some.interface").setServiceMethod("method").setActionParameters(new TreeSet<>()).setPostActionParameters(new TreeSet<>()).build();
    ActionEvent actualAction = channelToBeCreated.getActionTaskEvents().get(0);
    assertEquals(expectedAction, actualAction);
}
Also used : ChannelRequest(org.motechproject.tasks.contract.ChannelRequest) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) EventParameterRequest(org.motechproject.tasks.contract.EventParameterRequest) Channel(org.motechproject.tasks.domain.mds.channel.Channel) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) ActionEventRequest(org.motechproject.tasks.contract.ActionEventRequest) TestActionEventRequestBuilder(org.motechproject.tasks.contract.builder.TestActionEventRequestBuilder) EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) TriggerEventRequest(org.motechproject.tasks.contract.TriggerEventRequest) TreeSet(java.util.TreeSet) ActionParameterRequest(org.motechproject.tasks.contract.ActionParameterRequest) Test(org.junit.Test)

Aggregations

ActionParameterRequest (org.motechproject.tasks.contract.ActionParameterRequest)8 ActionEventRequest (org.motechproject.tasks.contract.ActionEventRequest)5 TreeSet (java.util.TreeSet)4 ActionParameterRequestBuilder (org.motechproject.tasks.contract.builder.ActionParameterRequestBuilder)4 TestActionEventRequestBuilder (org.motechproject.tasks.contract.builder.TestActionEventRequestBuilder)4 JsonObject (com.google.gson.JsonObject)3 Test (org.junit.Test)3 JsonArray (com.google.gson.JsonArray)2 JsonParseException (com.google.gson.JsonParseException)1 TypeToken (com.google.gson.reflect.TypeToken)1 ArrayList (java.util.ArrayList)1 MotechJsonReader (org.motechproject.commons.api.json.MotechJsonReader)1 ChannelRequest (org.motechproject.tasks.contract.ChannelRequest)1 EventParameterRequest (org.motechproject.tasks.contract.EventParameterRequest)1 TriggerEventRequest (org.motechproject.tasks.contract.TriggerEventRequest)1 ActionEventRequestBuilder (org.motechproject.tasks.contract.builder.ActionEventRequestBuilder)1 ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)1 Channel (org.motechproject.tasks.domain.mds.channel.Channel)1 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)1 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)1