Search in sources :

Example 1 with TestActionEventRequestBuilder

use of org.motechproject.tasks.contract.builder.TestActionEventRequestBuilder in project motech by motech.

the class ActionEventDeserializerParametrizedTest method getPillReminderEvents.

private static List<ActionEventRequest> getPillReminderEvents() {
    SortedSet<ActionParameterRequest> parameters = new TreeSet<>();
    parameters.add(new ActionParameterRequestBuilder().setKey("DosageID").setDisplayName("pillreminder.dossageID").setOrder(0).createActionParameterRequest());
    parameters.add(new ActionParameterRequestBuilder().setKey("ExternalID").setDisplayName("pillreminder.externalID").setOrder(1).createActionParameterRequest());
    parameters.add(new ActionParameterRequestBuilder().setKey("times-reminders-sent").setDisplayName("pillreminder.times.sent").setOrder(2).setType("INTEGER").createActionParameterRequest());
    parameters.add(new ActionParameterRequestBuilder().setKey("times-reminders-to-be-sent").setDisplayName("pillreminder.total.times.sent").setOrder(3).setType("INTEGER").createActionParameterRequest());
    parameters.add(new ActionParameterRequestBuilder().setKey("retry-interval").setDisplayName("pillreminder.retry.interval").setOrder(4).setType("INTEGER").createActionParameterRequest());
    ActionEventRequest event = new TestActionEventRequestBuilder().setDisplayName("pillreminder.event.subject.scheduler").setSubject("org.motechproject.server.pillreminder.scheduler-reminder").setDescription("description").setServiceInterface(null).setServiceMethod(null).setActionParameters(parameters).createActionEventRequest();
    List<ActionEventRequest> events = new ArrayList<>();
    events.add(event);
    return events;
}
Also used : TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) 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)

Example 2 with TestActionEventRequestBuilder

use of org.motechproject.tasks.contract.builder.TestActionEventRequestBuilder in project motech by motech.

the class ActionEventDeserializerParametrizedTest method getMessageCampaignEvents.

private static List<ActionEventRequest> getMessageCampaignEvents() {
    SortedSet<ActionParameterRequest> parameters1 = new TreeSet<>();
    parameters1.add(new ActionParameterRequestBuilder().setKey("CampaignName").setDisplayName("msgCampaign.campaign.name").setOrder(0).createActionParameterRequest());
    parameters1.add(new ActionParameterRequestBuilder().setKey("ExternalID").setDisplayName("msgCampaign.externalID").setOrder(1).createActionParameterRequest());
    parameters1.add(new ActionParameterRequestBuilder().setKey("MessageKey").setDisplayName("msgCampaign.message.key").setOrder(2).createActionParameterRequest());
    ActionEventRequest event1 = new TestActionEventRequestBuilder().setDisplayName("msgCampaign.send.message").setSubject("org.motechproject.messagecampaign.fired-campaign-message").setDescription("description").setServiceInterface(null).setServiceMethod(null).setActionParameters(parameters1).createActionEventRequest();
    SortedSet<ActionParameterRequest> parameters2 = new TreeSet<>();
    parameters2.add(new ActionParameterRequestBuilder().setKey("ExternalID").setDisplayName("msgCampaign.externalID").setOrder(0).createActionParameterRequest());
    parameters2.add(new ActionParameterRequestBuilder().setKey("CampaignName").setDisplayName("msgCampaign.campaign.name").setOrder(1).createActionParameterRequest());
    ActionEventRequest event2 = new TestActionEventRequestBuilder().setDisplayName("msgCampaign.campaign.completed").setSubject("org.motechproject.messagecampaign.campaign-completed").setDescription("description").setServiceInterface("org.motechproject.messagecampaign.service.MessageCampaignService").setServiceMethod("campaignCompleted").setActionParameters(parameters2).createActionEventRequest();
    return asList(event1, event2);
}
Also used : TreeSet(java.util.TreeSet) 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)

Example 3 with TestActionEventRequestBuilder

use of org.motechproject.tasks.contract.builder.TestActionEventRequestBuilder 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 4 with TestActionEventRequestBuilder

use of org.motechproject.tasks.contract.builder.TestActionEventRequestBuilder 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

ActionEventRequest (org.motechproject.tasks.contract.ActionEventRequest)4 ActionParameterRequest (org.motechproject.tasks.contract.ActionParameterRequest)4 TestActionEventRequestBuilder (org.motechproject.tasks.contract.builder.TestActionEventRequestBuilder)4 TreeSet (java.util.TreeSet)3 ActionParameterRequestBuilder (org.motechproject.tasks.contract.builder.ActionParameterRequestBuilder)3 Test (org.junit.Test)2 JsonObject (com.google.gson.JsonObject)1 ArrayList (java.util.ArrayList)1 ChannelRequest (org.motechproject.tasks.contract.ChannelRequest)1 EventParameterRequest (org.motechproject.tasks.contract.EventParameterRequest)1 TriggerEventRequest (org.motechproject.tasks.contract.TriggerEventRequest)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 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)1