Search in sources :

Example 11 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class PasswordDecodeMetadataFilterTest method testFilter_NoMatches.

@Test
public void testFilter_NoMatches() throws Exception {
    PasswordDecodeMetadataFilter filter = new PasswordDecodeMetadataFilter();
    AdaptrisMessage msg = createMessage();
    MetadataCollection filtered = filter.filter(msg);
    assertEquals(3, filtered.size());
    // Changes not reflected in the underlying message.
    assertNotSame("password1", msg.getMetadataValue("passwordKey1"));
    assertNotSame("password2", msg.getMetadataValue("passwordKey2"));
    assertEquals("PW:WillNotDecode", msg.getMetadataValue("key1"));
    for (MetadataElement e : filtered) {
        if ("passwordKey1".equalsIgnoreCase(e.getKey())) {
            assertTrue(e.getValue().startsWith("PW:"));
        }
        if ("passwordKey2".equalsIgnoreCase(e.getKey())) {
            assertTrue(e.getValue().startsWith("PW:"));
        }
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataCollection(com.adaptris.core.MetadataCollection) MetadataElement(com.adaptris.core.MetadataElement) Test(org.junit.Test)

Example 12 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class WorkflowManagerTest method testProcess.

@Test
public void testProcess() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    AdapterManager adapterManager = new AdapterManager(adapter);
    Channel channel = createChannel("c1");
    ChannelManager channelManager = new ChannelManager(channel, adapterManager);
    StandardWorkflow workflow = createWorkflow("w1");
    workflow.getServiceCollection().add(new AddMetadataService(Arrays.asList(new MetadataElement(getName(), getName()))));
    WorkflowManager realWorkflowManager = new WorkflowManager(workflow, channelManager);
    adapterManager.createObjectName();
    ObjectName workflowObj = realWorkflowManager.createObjectName();
    channelManager.createObjectName();
    List<BaseComponentMBean> mBeans = new ArrayList<BaseComponentMBean>();
    mBeans.add(adapterManager);
    mBeans.addAll(adapterManager.getAllDescendants());
    String msgUniqueId = new GuidGenerator().getUUID();
    SerializableMessage msg = createSM(msgUniqueId);
    try {
        register(mBeans);
        MessageProcessor workflowManagerProxy = JMX.newMBeanProxy(mBeanServer, workflowObj, MessageProcessor.class);
        adapterManager.requestStart();
        SerializableMessage reply = workflowManagerProxy.process(msg);
        assertEquals(msgUniqueId, reply.getUniqueId());
        assertEquals(PAYLOAD, reply.getContent());
        assertEquals(PAYLOAD_ENCODING, reply.getContentEncoding());
        Map<String, String> headers = reply.getMessageHeaders();
        assertTrue(headers.containsKey(METADATA_KEY));
        assertEquals(METADATA_VALUE, headers.get(METADATA_KEY));
        assertTrue(headers.containsKey(getName()));
        assertEquals(getName(), headers.get(getName()));
        assertEquals("", reply.getNextServiceId());
    } finally {
        adapter.requestClose();
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) Channel(com.adaptris.core.Channel) MessageProcessor(com.adaptris.interlok.management.MessageProcessor) ArrayList(java.util.ArrayList) Adapter(com.adaptris.core.Adapter) MetadataElement(com.adaptris.core.MetadataElement) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) ObjectName(javax.management.ObjectName) StubSerializableMessage(com.adaptris.core.stubs.StubSerializableMessage) SerializableMessage(com.adaptris.interlok.types.SerializableMessage) GuidGenerator(com.adaptris.util.GuidGenerator) Test(org.junit.Test)

Example 13 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class WorkflowManagerTest method testInjectWithReply.

@Test
public void testInjectWithReply() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    AdapterManager adapterManager = new AdapterManager(adapter);
    Channel channel = createChannel("c1");
    ChannelManager channelManager = new ChannelManager(channel, adapterManager);
    StandardWorkflow workflow = createWorkflow("w1");
    workflow.getServiceCollection().add(new AddMetadataService(Arrays.asList(new MetadataElement(getName(), getName()))));
    WorkflowManager realWorkflowManager = new WorkflowManager(workflow, channelManager);
    adapterManager.createObjectName();
    ObjectName workflowObj = realWorkflowManager.createObjectName();
    channelManager.createObjectName();
    List<BaseComponentMBean> mBeans = new ArrayList<BaseComponentMBean>();
    mBeans.add(adapterManager);
    mBeans.addAll(adapterManager.getAllDescendants());
    String msgUniqueId = new GuidGenerator().getUUID();
    SerializableAdaptrisMessage msg = createSAM(msgUniqueId);
    try {
        register(mBeans);
        WorkflowManagerMBean workflowManagerProxy = JMX.newMBeanProxy(mBeanServer, workflowObj, WorkflowManagerMBean.class);
        adapterManager.requestStart();
        SerializableAdaptrisMessage reply = (SerializableAdaptrisMessage) workflowManagerProxy.process(msg);
        assertEquals(msgUniqueId, reply.getUniqueId());
        assertEquals(PAYLOAD, reply.getContent());
        assertEquals(PAYLOAD_ENCODING, reply.getContentEncoding());
        assertTrue(reply.containsKey(METADATA_KEY));
        assertEquals(METADATA_VALUE, reply.getMetadataValue(METADATA_KEY));
        assertTrue(reply.containsKey(getName()));
        assertEquals(getName(), reply.getMetadataValue(getName()));
    } finally {
        adapter.requestClose();
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) Channel(com.adaptris.core.Channel) ArrayList(java.util.ArrayList) Adapter(com.adaptris.core.Adapter) MetadataElement(com.adaptris.core.MetadataElement) SerializableAdaptrisMessage(com.adaptris.core.SerializableAdaptrisMessage) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) ObjectName(javax.management.ObjectName) GuidGenerator(com.adaptris.util.GuidGenerator) Test(org.junit.Test)

Example 14 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class EmbeddedScriptingServiceTest method testBranchingServiceExcecution_NextServiceId.

@Test
public void testBranchingServiceExcecution_NextServiceId() throws Exception {
    BranchingServiceCollection bsc = new BranchingServiceCollection();
    bsc.setFirstServiceId(getName());
    bsc.add(createServiceForBranch(getName(), NEXT_SERVICE_ID));
    AddMetadataService next = new AddMetadataService(new ArrayList<>(Arrays.asList(new MetadataElement(MY_METADATA_KEY2, MY_METADATA_VALUE))));
    next.setUniqueId(NEXT_SERVICE_ID);
    bsc.add(next);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    msg.addMetadata(MY_METADATA_KEY, MY_METADATA_VALUE);
    execute(bsc, msg);
    assertEquals(MY_METADATA_VALUE, msg.getMetadataValue(MY_METADATA_KEY));
    assertEquals(MY_METADATA_VALUE, msg.getMetadataValue(MY_METADATA_KEY2));
}
Also used : BranchingServiceCollection(com.adaptris.core.BranchingServiceCollection) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Example 15 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class AddToCacheServiceTest method testDoService.

@Test
public void testDoService() throws Exception {
    AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(JmsConstants.JMS_CORRELATION_ID, CORRELATION_ID) }));
    Cache cache = createCacheInstanceForTests();
    AddToCacheService service = createServiceForTests();
    try {
        service.setConnection(new CacheConnection(cache));
        service.setEnforceSerializable(false);
        start(service);
        service.doService(msg);
        Object value = cache.get(CORRELATION_ID);
        assertTrue("Cached object should be a JMS Queue", value instanceof Queue);
        assertEquals(QUEUE_NAME, ((Queue) value).getQueueName());
    } finally {
        stop(service);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Queue(javax.jms.Queue) Cache(com.adaptris.core.cache.Cache) Test(org.junit.Test)

Aggregations

MetadataElement (com.adaptris.core.MetadataElement)151 Test (org.junit.Test)101 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)94 XPath (com.adaptris.util.text.xml.XPath)23 Document (org.w3c.dom.Document)19 MetadataCollection (com.adaptris.core.MetadataCollection)18 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)18 ServiceException (com.adaptris.core.ServiceException)17 ServiceList (com.adaptris.core.ServiceList)14 Cache (com.adaptris.core.cache.Cache)14 MetadataCacheValueTranslator (com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator)12 ArrayList (java.util.ArrayList)11 CoreException (com.adaptris.core.CoreException)10 Service (com.adaptris.core.Service)10 HashSet (java.util.HashSet)9 ExpiringMapCache (com.adaptris.core.cache.ExpiringMapCache)8 StandaloneProducer (com.adaptris.core.StandaloneProducer)7 StaticCacheValueTranslator (com.adaptris.core.services.cache.translators.StaticCacheValueTranslator)7 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)6 Session (javax.jms.Session)6