use of org.motechproject.tasks.contract.ChannelRequest 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);
}
use of org.motechproject.tasks.contract.ChannelRequest in project motech by motech.
the class ChannelRequestTest method shouldDeserializeChannelJson.
@Test
public void shouldDeserializeChannelJson() throws IOException {
String triggerEvent = "{ displayName: 'displayName', subject: 'subject', eventParameters: [{ displayName: 'displayName', eventKey: 'eventKey' }] }";
String channel = String.format("{displayName: %s, moduleName: %s, moduleVersion: %s, triggerTaskEvents: [%s]}", "foo", "bar", "1.0", triggerEvent);
InputStream stream = new ByteArrayInputStream(channel.getBytes(Charset.forName("UTF-8")));
Type type = new TypeToken<ChannelRequest>() {
}.getType();
StringWriter writer = new StringWriter();
IOUtils.copy(stream, writer);
Map<Type, Object> typeAdapters = new HashMap<>();
typeAdapters.put(ActionEventRequest.class, new ActionEventRequestDeserializer());
ChannelRequest channelRequest = (ChannelRequest) new MotechJsonReader().readFromString(writer.toString(), type, typeAdapters);
assertEquals(1, channelRequest.getTriggerTaskEvents().size());
}
use of org.motechproject.tasks.contract.ChannelRequest in project motech by motech.
the class ActionParametersBundleIT method loadChannel.
private Channel loadChannel() throws IOException {
Type type = new TypeToken<ChannelRequest>() {
}.getType();
HashMap<Type, Object> typeAdapters = new HashMap<>();
typeAdapters.put(ActionEventRequest.class, new ActionEventRequestDeserializer());
StringWriter writer = new StringWriter();
try (InputStream stream = getClass().getResourceAsStream("/task-testmodule-channel.json")) {
IOUtils.copy(stream, writer);
}
ChannelRequest channelRequest = (ChannelRequest) motechJsonReader.readFromString(writer.toString(), type, typeAdapters);
channelRequest.setModuleName(TASK_TEST_CHANNEL_NAME);
channelRequest.setModuleVersion("0.29.0.SNAPSHOT");
return ChannelBuilder.fromChannelRequest(channelRequest).build();
}
use of org.motechproject.tasks.contract.ChannelRequest in project motech by motech.
the class ChannelServiceImpl method registerChannel.
@Override
@Transactional
public void registerChannel(final InputStream stream, String moduleName, String moduleVersion) {
LOGGER.info("Registering channel: {}", moduleName);
Type type = new TypeToken<ChannelRequest>() {
}.getType();
StringWriter writer = new StringWriter();
try {
IOUtils.copy(stream, writer);
ChannelRequest channelRequest = (ChannelRequest) motechJsonReader.readFromString(writer.toString(), type, typeAdapters);
channelRequest.setModuleName(moduleName);
channelRequest.setModuleVersion(moduleVersion);
registerChannel(channelRequest);
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
}
}
use of org.motechproject.tasks.contract.ChannelRequest in project motech by motech.
the class ChannelsDataServiceBundleIT method loadChannels.
private List<Channel> loadChannels() throws IOException {
Type type = new TypeToken<ChannelRequest>() {
}.getType();
HashMap<Type, Object> typeAdapters = new HashMap<>();
typeAdapters.put(ActionEventRequest.class, new ActionEventRequestDeserializer());
List<StringWriter> writers = new ArrayList<>(2);
for (String json : Arrays.asList("/message-campaign-test-channel.json", "/pillreminder-test-channel.json")) {
try (InputStream stream = getClass().getResourceAsStream(json)) {
StringWriter writer = new StringWriter();
IOUtils.copy(stream, writer);
writers.add(writer);
}
}
List<Channel> channelRequests = new ArrayList<>(2);
for (StringWriter writer : writers) {
ChannelRequest channelRequest = (ChannelRequest) motechJsonReader.readFromString(writer.toString(), type, typeAdapters);
channelRequest.setModuleName(channelRequest.getDisplayName());
channelRequest.setModuleVersion("1.0");
channelRequests.add(ChannelBuilder.fromChannelRequest(channelRequest).build());
}
return channelRequests;
}
Aggregations