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);
}
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));
}
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));
}
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);
}
Aggregations