KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > jbi > messaging > types > InOnlyImplTest


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: InOnlyImplTest.java 17:30:10 ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.jbi.messaging.types;
23
24 import java.io.ByteArrayInputStream JavaDoc;
25
26 import javax.jbi.messaging.NormalizedMessage;
27 import javax.jbi.messaging.MessageExchange.Role;
28 import javax.xml.transform.stream.StreamSource JavaDoc;
29
30 import junit.framework.TestCase;
31
32 import org.objectweb.petals.jbi.messaging.MessageExchangeImpl;
33 import org.objectweb.petals.jbi.messaging.NormalizedMessageImpl;
34
35 /**
36  * Test the InOnlyImpl
37  *
38  * @author ddesjardins - eBMWebsourcing
39  */

40 public class InOnlyImplTest extends TestCase {
41
42     private InOnlyImpl inOnlyImpl;
43
44     private MessageExchangeImpl messageExchangeImpl;
45
46     private NormalizedMessageImpl normalizedMessageImpl;
47
48     public void setUp() throws Exception JavaDoc {
49         messageExchangeImpl = new MessageExchangeImpl(null);
50
51         normalizedMessageImpl = new NormalizedMessageImpl();
52
53         StreamSource JavaDoc source = new StreamSource JavaDoc();
54         byte[] msgByte = "test message".getBytes();
55         ByteArrayInputStream JavaDoc in = new ByteArrayInputStream JavaDoc(msgByte);
56         source.setInputStream(in);
57
58         normalizedMessageImpl.setContent(source);
59
60     }
61
62     public void testGetInMessage() throws Exception JavaDoc {
63         normalizedMessageImpl.setProperty("test", "valuein");
64         messageExchangeImpl.setPattern(MessageExchangeImpl.IN_OUT_PATTERN);
65         messageExchangeImpl.setMessage(normalizedMessageImpl, "in");
66         inOnlyImpl = new InOnlyImpl(messageExchangeImpl, Role.CONSUMER);
67
68         NormalizedMessage normalizedMessage = inOnlyImpl.getInMessage();
69         assertEquals(normalizedMessage.getProperty("test"), "valuein");
70     }
71
72     public void testSetInMessage() throws Exception JavaDoc {
73         normalizedMessageImpl.setProperty("test", "valuein");
74         messageExchangeImpl.setPattern(MessageExchangeImpl.IN_OUT_PATTERN);
75         messageExchangeImpl.setRole(Role.CONSUMER);
76         inOnlyImpl = new InOnlyImpl(messageExchangeImpl, Role.CONSUMER);
77         inOnlyImpl.setInMessage(normalizedMessageImpl);
78
79         NormalizedMessage normalizedMessage = inOnlyImpl.getInMessage();
80         assertEquals(normalizedMessage.getProperty("test"), "valuein");
81     }
82
83 }
84
Popular Tags