Search in sources :

Example 11 with ActionEventRequest

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

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

the class ActionEventDeserializerTest method shouldDeserializeActionEvent.

@Test
public void shouldDeserializeActionEvent() throws IOException {
    String json = "{description=\"description\", displayName=\"displayName\", subject=\"subject\", serviceInterface=\"serviceInterface\", serviceMethod=\"serviceMethod\"," + "actionParameters=[{\"displayName\":\"externalId\",\"type\":\"UNICODE\",\"key\":\"ExternalId\",\"order\":3},{\"displayName\":\"motechId\",\"type\":\"INTEGER\",\"key\":\"MotechId\"}]," + "postActionParameters=[{\"displayName\":\"externalId\",\"key\":\"ExternalId\"}]}";
    TypeToken<ActionEventRequest> typeToken = new TypeToken<ActionEventRequest>() {
    };
    Map<Type, Object> typeAdapters = new HashMap<>();
    typeAdapters.put(ActionEventRequest.class, new ActionEventRequestDeserializer());
    ActionEventRequest actionEventRequest = (ActionEventRequest) new MotechJsonReader().readFromString(json, typeToken.getType(), typeAdapters);
    assertNotNull(actionEventRequest);
    assertThat(actionEventRequest.getDisplayName(), is("displayName"));
    assertThat(actionEventRequest.getActionParameters().size(), is(2));
    assertThat(actionEventRequest.getActionParameters().iterator().next().getOrder(), is(3));
    assertThat(actionEventRequest.getPostActionParameters().size(), is(1));
}
Also used : MotechJsonReader(org.motechproject.commons.api.json.MotechJsonReader) ParameterType(org.motechproject.tasks.domain.enums.ParameterType) Type(java.lang.reflect.Type) HashMap(java.util.HashMap) TypeToken(com.google.gson.reflect.TypeToken) JsonObject(com.google.gson.JsonObject) ActionEventRequest(org.motechproject.tasks.contract.ActionEventRequest) Test(org.junit.Test)

Example 13 with ActionEventRequest

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

the class ActionEventRequestBuilderTest method shouldConsiderRequestValidIfEitherSubjectOrServicePresent.

@Test
public void shouldConsiderRequestValidIfEitherSubjectOrServicePresent() {
    TestActionEventRequestBuilder requestBuilder = new TestActionEventRequestBuilder();
    ActionEventRequest fullyFormedRequest = requestBuilder.setSubject(SUBJECT).setServiceInterface(SERVICE_INTERFACE).setServiceMethod(SERVICE_METHOD).createActionEventRequest();
    assertThat(fullyFormedRequest.isValid(), is(true));
    ActionEventRequest requestWithSubjectButNotService = requestBuilder.setSubject(SUBJECT).setNullServiceInterface().setNullServiceMethod().createActionEventRequest();
    assertThat(requestWithSubjectButNotService.isValid(), is(true));
    ActionEventRequest requestWithoutSubjectButWithService = requestBuilder.setNullSubject().setServiceInterface(SERVICE_INTERFACE).setServiceMethod(SERVICE_METHOD).createActionEventRequest();
    assertThat(requestWithoutSubjectButWithService.isValid(), is(true));
    ActionEventRequest requestWithoutSubjectAndWithoutService = requestBuilder.setNullSubject().setNullServiceInterface().setNullServiceMethod().createActionEventRequest();
    assertThat(requestWithoutSubjectAndWithoutService.isValid(), is(false));
    ActionEventRequest requestWithoutSubjectAndWithServiceMethodOnly = requestBuilder.setNullSubject().setNullServiceInterface().setServiceMethod(SERVICE_METHOD).createActionEventRequest();
    assertThat(requestWithoutSubjectAndWithServiceMethodOnly.isValid(), is(false));
    ActionEventRequest requestWithoutSubjectAndWithServiceInterfaceOnly = requestBuilder.setNullSubject().setServiceInterface(SERVICE_INTERFACE).setNullServiceMethod().createActionEventRequest();
    assertThat(requestWithoutSubjectAndWithServiceInterfaceOnly.isValid(), is(false));
}
Also used : ActionEventRequest(org.motechproject.tasks.contract.ActionEventRequest) Test(org.junit.Test)

Example 14 with ActionEventRequest

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