1 16 package org.apache.commons.chain.impl; 17 18 19 import junit.framework.Test; 20 import junit.framework.TestSuite; 21 import org.apache.commons.chain.Context; 22 23 24 28 29 public class TestContextTestCase extends ContextBaseTestCase { 30 31 32 34 39 public TestContextTestCase(String name) { 40 super(name); 41 } 42 43 44 46 47 50 public void setUp() { 51 context = createContext(); 52 } 53 54 55 58 public static Test suite() { 59 return (new TestSuite(TestContextTestCase.class)); 60 } 61 62 63 65 66 public void testPristine() { 68 69 super.testPristine(); 70 assertEquals("readOnly", (String ) context.get("readOnly")); 71 assertEquals("readWrite", (String ) context.get("readWrite")); 72 assertEquals("writeOnly", ((TestContext) context).returnWriteOnly()); 73 74 } 75 76 77 public void testReadOnly() { 79 80 Object readOnly = context.get("readOnly"); 81 assertNotNull("readOnly found", readOnly); 82 assertTrue("readOnly String", 83 readOnly instanceof String ); 84 assertEquals("readOnly value", "readOnly", readOnly); 85 86 try { 87 context.put("readOnly", "new readOnly"); 88 fail("Should have thrown UnsupportedOperationException"); 89 } catch (UnsupportedOperationException e) { 90 ; } 92 assertEquals("readOnly unchanged", "readOnly", 93 (String ) context.get("readOnly")); 94 95 } 96 97 98 public void testReadWrite() { 100 101 Object readWrite = context.get("readWrite"); 102 assertNotNull("readWrite found", readWrite); 103 assertTrue("readWrite String", 104 readWrite instanceof String ); 105 assertEquals("readWrite value", "readWrite", readWrite); 106 107 context.put("readWrite", "new readWrite"); 108 readWrite = context.get("readWrite"); 109 assertNotNull("readWrite found", readWrite); 110 assertTrue("readWrite String", 111 readWrite instanceof String ); 112 assertEquals("readWrite value", "new readWrite", readWrite); 113 114 } 115 116 117 public void testWriteOnly() { 119 120 Object writeOnly = ((TestContext) context).returnWriteOnly(); 121 assertNotNull("writeOnly found", writeOnly); 122 assertTrue("writeOnly String", 123 writeOnly instanceof String ); 124 assertEquals("writeOnly value", "writeOnly", writeOnly); 125 126 context.put("writeOnly", "new writeOnly"); 127 writeOnly = ((TestContext) context).returnWriteOnly(); 128 assertNotNull("writeOnly found", writeOnly); 129 assertTrue("writeOnly String", 130 writeOnly instanceof String ); 131 assertEquals("writeOnly value", "new writeOnly", writeOnly); 132 133 } 134 135 136 138 139 protected Context createContext() { 141 return (new TestContext()); 142 } 143 144 145 } 146 | Popular Tags |