Search in sources :

Example 1 with ActionEventRequest

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

the class ActionEventRequestBuilderTest method shouldTestSubjectAvailability.

@Test
public void shouldTestSubjectAvailability() {
    TestActionEventRequestBuilder requestBuilder = new TestActionEventRequestBuilder();
    ActionEventRequest requestWithSubject = requestBuilder.setSubject(SUBJECT).createActionEventRequest();
    assertThat(requestWithSubject.hasSubject(), is(true));
    ActionEventRequest requestWithoutSubject = requestBuilder.setNullSubject().createActionEventRequest();
    assertThat(requestWithoutSubject.hasSubject(), is(false));
    ActionEventRequest requestWithEmptySubject = requestBuilder.setEmptySubject().createActionEventRequest();
    assertThat(requestWithEmptySubject.hasSubject(), is(false));
}
Also used : ActionEventRequest(org.motechproject.tasks.contract.ActionEventRequest) Test(org.junit.Test)

Example 2 with ActionEventRequest

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

the class ActionEventRequestBuilderTest method shouldTestServiceAvailability.

@Test
public void shouldTestServiceAvailability() {
    TestActionEventRequestBuilder requestBuilder = new TestActionEventRequestBuilder();
    ActionEventRequest fullyFormedRequest = requestBuilder.setServiceInterface(SERVICE_INTERFACE).setServiceMethod(SERVICE_METHOD).createActionEventRequest();
    assertThat(fullyFormedRequest.hasService(), is(true));
    ActionEventRequest requestWithoutServiceInterface = requestBuilder.setNullServiceInterface().setServiceMethod(SERVICE_METHOD).createActionEventRequest();
    assertThat(requestWithoutServiceInterface.hasService(), is(false));
    ActionEventRequest requestWithEmptyServiceInterface = requestBuilder.setEmptyServiceInterface().setServiceMethod(SERVICE_METHOD).createActionEventRequest();
    assertThat(requestWithEmptyServiceInterface.hasService(), is(false));
    ActionEventRequest requestWithoutServiceMethod = requestBuilder.setServiceInterface(SERVICE_INTERFACE).setNullServiceMethod().createActionEventRequest();
    assertThat(requestWithoutServiceMethod.hasService(), is(false));
    ActionEventRequest requestWithEmptyServiceMethod = requestBuilder.setServiceInterface(SERVICE_INTERFACE).setEmptyServiceMethod().createActionEventRequest();
    assertThat(requestWithEmptyServiceMethod.hasService(), is(false));
}
Also used : ActionEventRequest(org.motechproject.tasks.contract.ActionEventRequest) Test(org.junit.Test)

Example 3 with ActionEventRequest

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

the class ActionEventDeserializerParametrizedTest method shouldDeserializeJson.

@Test
public void shouldDeserializeJson() {
    ChannelRequest channelRequest = (ChannelRequest) reader.readFromString(channelAsString, type, typeAdapters);
    List<ActionEventRequest> actionTaskEvents = channelRequest.getActionTaskEvents();
    assertEquals(expected, actionTaskEvents);
}
Also used : ChannelRequest(org.motechproject.tasks.contract.ChannelRequest) ActionEventRequest(org.motechproject.tasks.contract.ActionEventRequest) Test(org.junit.Test)

Example 4 with ActionEventRequest

use of org.motechproject.tasks.contract.ActionEventRequest 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 5 with ActionEventRequest

use of org.motechproject.tasks.contract.ActionEventRequest 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)

Aggregations

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