use of com.adaptris.core.AdaptrisMessage in project interlok by adaptris.
the class MetadataTokenWriterTest method testApply_NoAdditionalData.
@Test
public void testApply_NoAdditionalData() throws Exception {
AccessToken token = new AccessToken("Bearer", "token");
MetadataAccessTokenWriter writer = new MetadataAccessTokenWriter().withTokenKey("access_token").withTokenExpiryKey("expiry_token").withRefreshTokenKey("refresh_token");
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
try {
LifecycleHelper.initAndStart(writer);
writer.apply(token, msg);
assertTrue(msg.headersContainsKey("access_token"));
assertEquals("Bearer token", msg.getMetadataValue("access_token"));
assertFalse(msg.headersContainsKey("expiry_token"));
assertFalse(msg.headersContainsKey("refresh_token"));
} finally {
LifecycleHelper.stopAndClose(writer);
}
}
use of com.adaptris.core.AdaptrisMessage in project interlok by adaptris.
the class FtpRecursiveConsumerTest method testBasicConsume.
@Test
public void testBasicConsume() throws Exception {
int count = 1;
EmbeddedFtpServer helper = new EmbeddedFtpServer();
MockMessageListener listener = new MockMessageListener();
FakeFtpServer server = helper.createAndStart(createFilesystem(helper, count));
StandaloneConsumer sc = null;
try {
FtpRecursiveConsumer ftpConsumer = createForTests(listener);
FtpConnection consumeConnection = create(server);
sc = new StandaloneConsumer(consumeConnection, ftpConsumer);
// INTERLOK-3329 For coverage so the prepare() warning is executed 2x
LifecycleHelper.prepare(sc);
start(sc);
// account for files in sub directories
waitForMessages(listener, count + (count * subDirectories.length));
List<AdaptrisMessage> messages = listener.getMessages();
helper.assertMessages(messages, count + (count * subDirectories.length));
for (AdaptrisMessage message : messages) {
assertTrue(message.headersContainsKey(CoreConstants.FS_CONSUME_PARENT_DIR));
String path = message.getMetadataValue(CoreConstants.FS_CONSUME_DIRECTORY);
assertEquals(new File(path).getName(), message.getMetadataValue(CoreConstants.FS_CONSUME_PARENT_DIR));
}
} catch (Exception e) {
throw e;
} finally {
stop(sc);
server.stop();
}
}
use of com.adaptris.core.AdaptrisMessage in project interlok by adaptris.
the class FtpRecursiveConsumerTest method testConsumeWithEncoder.
@Test
public void testConsumeWithEncoder() throws Exception {
int count = 1;
EmbeddedFtpServer helper = new EmbeddedFtpServer();
MockMessageListener listener = new MockMessageListener(100);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD);
byte[] bytes = new MimeEncoder().encode(msg);
FileSystem filesystem = helper.createFilesystem_DirsOnly();
for (int i = 0; i < count; i++) {
FileEntry entry = new FileEntry(DEFAULT_WORK_DIR_CANONICAL + SLASH + DEFAULT_FILENAME + i + ".txt");
entry.setContents(bytes);
filesystem.add(entry);
}
FakeFtpServer server = helper.createAndStart(filesystem);
StandaloneConsumer sc = null;
try {
FtpRecursiveConsumer ftpConsumer = createForTests(listener);
ftpConsumer.setEncoder(new MimeEncoder());
FtpConnection consumeConnection = create(server);
sc = new StandaloneConsumer(consumeConnection, ftpConsumer);
start(sc);
waitForMessages(listener, count);
helper.assertMessages(listener.getMessages(), count);
} catch (Exception e) {
throw e;
} finally {
stop(sc);
server.stop();
}
}
use of com.adaptris.core.AdaptrisMessage in project interlok by adaptris.
the class StoredProcedureProducerTest method testMultipleExecutions.
@Test
public void testMultipleExecutions() throws Exception {
if (areTestsEnabled()) {
JdbcStoredProcedureProducer spp = new JdbcStoredProcedureProducer();
spp.setProcedureName(("one_in_one_out"));
AdaptrisMessage message = createMessage(XML_PAYLOAD);
AdaptrisMessage message2 = createMessage(XML_PAYLOAD);
JdbcXPathParameter inParameter = new JdbcXPathParameter();
inParameter.setXpath("/head/body/element1");
inParameter.setName("xType");
inParameter.setType(ParameterValueType.VARCHAR);
InParameters inParameters = new InParameters();
inParameters.add(inParameter);
JdbcMetadataParameter outParameter = new JdbcMetadataParameter();
outParameter.setMetadataKey("result");
outParameter.setName("transferCount");
outParameter.setType(ParameterValueType.INTEGER);
OutParameters outParameters = new OutParameters();
outParameters.add(outParameter);
spp.setInParameters(inParameters);
spp.setOutParameters(outParameters);
StandaloneProducer producer = configureForTests(spp, true);
try {
// INTERLOK-3329 For coverage so the prepare() warning is executed 2x
LifecycleHelper.prepare(producer);
start(producer);
assertEquals(0, message.getMetadata().size());
producer.doService(message);
assertEquals(1, message.getMetadata().size());
assertEquals("15", message.getMetadataValue("result"));
assertEquals(0, message2.getMetadata().size());
producer.doService(message2);
assertEquals(1, message2.getMetadata().size());
assertEquals("15", message2.getMetadataValue("result"));
} finally {
stop(producer);
}
}
}
use of com.adaptris.core.AdaptrisMessage in project interlok by adaptris.
the class StoredProcedureProducerTest method testOneObjectMetadataParamIn.
@Test
public void testOneObjectMetadataParamIn() throws Exception {
if (areTestsEnabled()) {
JdbcStoredProcedureProducer spp = new JdbcStoredProcedureProducer();
spp.setProcedureName(("one_in"));
JdbcObjectMetadataParameter inParameter = new JdbcObjectMetadataParameter();
inParameter.setMetadataKey("xType");
inParameter.setName("xType");
inParameter.setType(ParameterValueType.VARCHAR);
AdaptrisMessage message = createMessage();
message.addObjectHeader("xType", "Sold");
InParameters inParameters = new InParameters();
inParameters.add(inParameter);
spp.setInParameters(inParameters);
Map<Object, Object> objectMetadata = message.getObjectHeaders();
assertEquals(1, objectMetadata.size());
StandaloneProducer producer = configureForTests(spp, true);
try {
start(producer);
producer.doService(message);
objectMetadata = message.getObjectHeaders();
assertEquals(1, objectMetadata.size());
} finally {
stop(producer);
}
}
}
Aggregations