01: package com.mockrunner.test.connector;
02:
03: import javax.resource.ResourceException;
04:
05: import com.mockrunner.connector.GenericFailureInteraction;
06: import com.mockrunner.connector.InteractionHandler;
07:
08: import junit.framework.TestCase;
09:
10: public class GenericFailureInteractionTest extends TestCase {
11: private InteractionHandler interactionHandler;
12:
13: protected void setUp() throws Exception {
14: interactionHandler = new InteractionHandler();
15: }
16:
17: protected void tearDown() throws Exception {
18: interactionHandler = null;
19: }
20:
21: public void testEnableAndDisable() throws Exception {
22: GenericFailureInteraction interaction = new GenericFailureInteraction();
23: assertTrue(interaction.canHandle(null, null, null));
24: interaction.disable();
25: assertFalse(interaction.canHandle(null, null, null));
26: interaction.enable();
27: assertTrue(interaction.canHandle(null, null, null));
28: interactionHandler.addImplementor(interaction);
29: try {
30: interactionHandler.execute(null, null);
31: fail();
32: } catch (ResourceException exc) {
33: //expected exception
34: }
35: interaction.disable();
36: interactionHandler.execute(null, null, null);
37: }
38:
39: public void testThrowsException() throws Exception {
40: GenericFailureInteraction interaction = new GenericFailureInteraction();
41: interactionHandler.addImplementor(interaction);
42: try {
43: interactionHandler.execute(null, null, null);
44: fail();
45: } catch (ResourceException exc) {
46: //expected exception
47: }
48: interaction.setThrowException(false);
49: assertFalse(interactionHandler.execute(null, null, null));
50: assertNull(interactionHandler.execute(null, null));
51: interaction.setThrowException(true);
52: try {
53: interactionHandler.execute(null, null);
54: fail();
55: } catch (ResourceException exc) {
56: //expected exception
57: }
58: }
59:
60: public void testExceptionType() throws Exception {
61: ResourceException setExc = new ResourceException();
62: Exception nested = new Exception();
63: setExc.setLinkedException(nested);
64: GenericFailureInteraction interaction = new GenericFailureInteraction(
65: true, setExc);
66: interactionHandler.addImplementor(interaction);
67: try {
68: interactionHandler.execute(null, null, null);
69: fail();
70: } catch (ResourceException exc) {
71: assertSame(setExc, exc);
72: assertSame(nested, exc.getLinkedException());
73: }
74: }
75: }
|