001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.servicemix.eip;
018:
019: import javax.jbi.messaging.ExchangeStatus;
020: import javax.jbi.messaging.InOnly;
021: import javax.jbi.messaging.InOut;
022: import javax.jbi.messaging.NormalizedMessage;
023: import javax.xml.namespace.QName;
024: import javax.xml.transform.dom.DOMSource;
025:
026: import org.w3c.dom.Document;
027: import org.w3c.dom.Element;
028:
029: import org.apache.servicemix.eip.patterns.ContentEnricher;
030: import org.apache.servicemix.jbi.util.DOMUtil;
031: import org.apache.servicemix.tck.ReceiverComponent;
032:
033: public class ContentEnricherTest extends AbstractEIPTest {
034:
035: protected ContentEnricher enricher;
036:
037: protected void setUp() throws Exception {
038: super .setUp();
039:
040: enricher = new ContentEnricher();
041: enricher
042: .setEnricherTarget(createServiceExchangeTarget(new QName(
043: "enricherTarget")));
044: enricher.setTarget(createServiceExchangeTarget(new QName(
045: "target")));
046:
047: configurePattern(enricher);
048: activateComponent(enricher, "enricher");
049: }
050:
051: public void testInOnly() throws Exception {
052:
053: activateComponent(new ReturnMockComponent("<halloMock/>"),
054: "enricherTarget");
055:
056: ReceiverComponent rec = activateReceiver("target");
057:
058: InOnly me = client.createInOnlyExchange();
059:
060: me.setService(new QName("enricher"));
061: me.getInMessage().setContent(createSource("<hello/>"));
062: client.sendSync(me);
063:
064: assertEquals(ExchangeStatus.DONE, me.getStatus());
065:
066: assertEquals(1, rec.getMessageList().getMessageCount());
067:
068: NormalizedMessage object = (NormalizedMessage) rec
069: .getMessageList().getMessages().get(0);
070:
071: DOMSource domSource = (DOMSource) object.getContent();
072: Document doc = (Document) domSource.getNode();
073:
074: Element e = doc.getDocumentElement();
075: assertEquals("enricher", e.getNodeName());
076: Element r = DOMUtil.getFirstChildElement(e);
077: assertEquals("request", r.getNodeName());
078: assertEquals("hello", DOMUtil.getFirstChildElement(r)
079: .getNodeName());
080: r = DOMUtil.getNextSiblingElement(r);
081: assertEquals("result", r.getNodeName());
082: assertEquals("halloMock", DOMUtil.getFirstChildElement(r)
083: .getNodeName());
084: }
085:
086: public void testInOut() throws Exception {
087:
088: activateComponent(new ReturnMockComponent("<halloMock/>"),
089: "enricherTarget");
090:
091: InOut me = client.createInOutExchange();
092:
093: me.setService(new QName("enricher"));
094: me.getInMessage().setContent(createSource("<hello/>"));
095: client.sendSync(me);
096:
097: assertEquals(ExchangeStatus.ERROR, me.getStatus());
098:
099: }
100: }
|