001: package org.objectweb.celtix.bus.context;
002:
003: import java.io.InputStream;
004: import java.io.OutputStream;
005:
006: import javax.xml.ws.handler.MessageContext;
007:
008: import org.easymock.classextension.EasyMock;
009: import org.objectweb.celtix.context.GenericMessageContext;
010: import org.objectweb.celtix.context.InputStreamMessageContext;
011: import org.objectweb.celtix.context.MessageContextWrapper;
012: import org.objectweb.celtix.context.OutputStreamMessageContext;
013: import org.objectweb.celtix.context.StreamMessageContext;
014:
015: public class StreamMessageContextImplTest extends
016: AbstractMessageContextTestBase {
017: private final GenericMessageContext base = new GenericMessageContext();
018:
019: @Override
020: protected MessageContext getMessageContext() {
021: return new StreamMessageContextImpl(
022: new ToyInputStreamMessageContext(base));
023: }
024:
025: public void testContextWithInputStream() {
026:
027: InputStream inStream = EasyMock.createMock(InputStream.class);
028: InputStreamMessageContext inctx = EasyMock
029: .createMock(InputStreamMessageContext.class);
030:
031: inctx.getInputStream();
032: org.easymock.EasyMock.expectLastCall().andReturn(inStream);
033:
034: StreamMessageContext ctx = new StreamMessageContextImpl(inctx);
035:
036: EasyMock.replay(inctx);
037: assertSame(inStream, ctx.getInputStream());
038: EasyMock.verify(inctx);
039:
040: EasyMock.reset(inctx);
041: InputStream in2 = EasyMock.createMock(InputStream.class);
042: inctx.setInputStream(in2);
043: EasyMock.replay(inctx);
044: ctx.setInputStream(in2);
045:
046: EasyMock.verify(inctx);
047:
048: }
049:
050: public void testContextWithOutputStream() {
051:
052: OutputStream outStream = EasyMock
053: .createMock(OutputStream.class);
054: OutputStreamMessageContext outctx = EasyMock
055: .createMock(OutputStreamMessageContext.class);
056:
057: outctx.getOutputStream();
058: org.easymock.EasyMock.expectLastCall().andReturn(outStream);
059:
060: StreamMessageContext ctx = new StreamMessageContextImpl(outctx);
061:
062: EasyMock.replay(outctx);
063: assertSame(outStream, ctx.getOutputStream());
064: EasyMock.verify(outctx);
065:
066: EasyMock.reset(outctx);
067: OutputStream out2 = EasyMock.createMock(OutputStream.class);
068: outctx.setOutputStream(out2);
069: EasyMock.replay(outctx);
070: ctx.setOutputStream(out2);
071:
072: EasyMock.verify(outctx);
073: }
074:
075: public void testContextWithOutputStreamInvokeInputStream() {
076:
077: OutputStreamMessageContext outctx = EasyMock
078: .createMock(OutputStreamMessageContext.class);
079: StreamMessageContext ctx = new StreamMessageContextImpl(outctx);
080:
081: try {
082: ctx.getInputStream();
083: fail("did not get expected exception");
084: } catch (IllegalStateException ex) {
085: // expected
086: }
087:
088: try {
089: ctx.setInputStream(EasyMock.createMock(InputStream.class));
090: fail("did not get expected exception");
091: } catch (IllegalStateException ex) {
092: // expected
093: }
094: }
095:
096: public void testContextWithInputStreamInvokeOutputStream() {
097:
098: InputStreamMessageContext inctx = EasyMock
099: .createMock(InputStreamMessageContext.class);
100: StreamMessageContext ctx = new StreamMessageContextImpl(inctx);
101:
102: try {
103: ctx.getOutputStream();
104: fail("did not get expected exception");
105: } catch (IllegalStateException ex) {
106: // expected
107: }
108:
109: try {
110: ctx
111: .setOutputStream(EasyMock
112: .createMock(OutputStream.class));
113: fail("did not get expected exception");
114: } catch (IllegalStateException ex) {
115: // expected
116: }
117: }
118:
119: public void testContrcutorNullInput() {
120:
121: try {
122: new StreamMessageContextImpl(
123: (InputStreamMessageContext) null);
124: fail("did not get expected expcetion");
125: } catch (NullPointerException ex) {
126: // expected
127: }
128: }
129:
130: public void testContrcutorNullOutput() {
131:
132: try {
133: new StreamMessageContextImpl(
134: (OutputStreamMessageContext) null);
135: fail("did not get expected expcetion");
136: } catch (NullPointerException ex) {
137: // expected
138: }
139: }
140:
141: static class ToyInputStreamMessageContext extends
142: MessageContextWrapper implements InputStreamMessageContext {
143: private static final long serialVersionUID = 1;
144:
145: ToyInputStreamMessageContext(MessageContext wrapped) {
146: super (wrapped);
147: }
148:
149: public InputStream getInputStream() {
150: return null;
151: }
152:
153: public void setInputStream(InputStream ins) {
154: }
155:
156: public boolean isFault() {
157: return false;
158: }
159:
160: public void setFault(boolean b) {
161: }
162: }
163:
164: }
|