001: package com.sun.portal.rproxy.rewriter.services.idsame.test;
002:
003: import com.sun.portal.rewriter.test.util.BasicTestCase;
004: import com.sun.portal.log.common.PortalLogger;
005: import com.sun.portal.rproxy.rewriter.SRAPRewriterModule;
006: import com.sun.portal.rproxy.rewriter.services.idsame.IDSAMEDataServiceStub;
007: import junit.framework.Test;
008: import junit.framework.TestCase;
009: import junit.framework.TestSuite;
010:
011: import java.util.Iterator;
012: import java.util.Properties;
013:
014: public class TestIDSAMEDataServiceStub extends TestCase {
015: private IDSAMEDataServiceStub remoteService;
016:
017: public TestIDSAMEDataServiceStub(String name) {
018: super (name);
019: }//constructor
020:
021: public void setUp() throws Exception {
022: remoteService = new IDSAMEDataServiceStub(new Properties());
023: }//setUp()
024:
025: public void testRetrieveKeys() throws Exception {
026: for (Iterator itr = remoteService.retrieveKeys().iterator(); itr
027: .hasNext();) {
028: String key = (String) itr.next();
029: assertTrue("RULESET-ID1".equals(key)
030: || "RULESET-ID2".equals(key)
031: || "RULESET-ID3".equals(key)
032: || "RULESET-ID4".equals(key)
033: || "RULESET-ID5".equals(key));
034: }//for loop
035: }//testRetrieveKeys()
036:
037: public void testRetrieveXML() throws Exception {
038: String value = remoteService.retrieveXML("RULESET-ID1");
039: assertEquals("RULESET-VALUE1", value);
040: value = remoteService.retrieveXML("RULESET-ID2");
041: assertEquals("RULESET-VALUE2", value);
042: value = remoteService.retrieveXML("RULESET-ID5");
043: assertEquals("RULESET-VALUE5", value);
044: value = remoteService.retrieveXML("RULESET-ID4");
045: assertEquals("RULESET-VALUE4", value);
046: value = remoteService.retrieveXML("RULESET-ID3");
047: assertEquals("RULESET-VALUE3", value);
048: }//testRetrieveXML()
049:
050: public void testRetrieveXMLException() throws Exception {
051: try {
052: remoteService.retrieveXML(null);
053: } catch (IllegalArgumentException e) {
054: // this is expected.
055: }
056: String value = remoteService.retrieveXML("SOME-JUNK-ID");
057: assertNull(value);
058: }//testRetrieveXMLException()
059:
060: public void testStoreXML() throws Exception {
061: String key = "RULESET-ID6";
062: String value = "RULESET-VALUE6";
063: String oldvalue = remoteService.storeXML(key, value);
064:
065: assertNull(oldvalue);
066: assertEquals(value, remoteService.retrieveXML(key));
067:
068: remoteService.deleteKey(key);
069: assertNull(remoteService.retrieveXML(key));
070:
071: String id = "RULESET-ID3";
072: String oldValue = "RULESET-VALUE3";
073: assertEquals(oldValue, remoteService.retrieveXML(id));
074:
075: String newValue = " this is the new value";
076:
077: assertEquals(oldValue, remoteService.storeXML(id, newValue));
078: assertEquals(newValue, remoteService.retrieveXML(id));
079:
080: assertEquals(newValue, remoteService.storeXML(id, oldValue));
081: assertEquals(oldValue, remoteService.retrieveXML(id));
082: }//testStoreXML()
083:
084: public void testStoreXMLException() throws Exception {
085: String[][] lData = { { null, "some junk" },
086: { "some key", null }, { " ", "some value" },
087: { "some key", "" }, { "NEW-KEY", " " }, };
088:
089: for (int i = 0; i < lData.length; i++) {
090: try {
091: remoteService.storeXML(lData[i][0], lData[i][1]);
092: fail("Accepting invalid Parameter for storeXML");
093: } catch (IllegalArgumentException e) {
094: assertTrue(true);
095: // this is expected ...
096: }//try/catch
097: }
098: }//testStoreXMLException()
099:
100: public void testDeleteKey() throws Exception {
101: String key = "NEW-KEY";
102: String value = "NEW-VALUE";
103: String oldvalue = remoteService.storeXML(key, value);
104: assertNull(oldvalue);
105: assertEquals(value, remoteService.retrieveXML(key));
106: assertEquals(value, remoteService.deleteKey(key));
107: assertNull(value, remoteService.retrieveXML(key));
108: }//testDeleteKey()
109:
110: public void testDeleteKeyException() throws Exception {
111: String[][] lData = { { null }, { " " }, { "" }, };
112:
113: for (int i = 0; i < lData.length; i++) {
114: try {
115: remoteService.deleteKey(lData[i][0]);
116: fail("Acceptiong invalid param for delete");
117: } catch (IllegalArgumentException e) {
118: assertTrue(true);
119: // this is expected ...
120: }//try/catch
121: }
122:
123: remoteService
124: .deleteKey("KEY-DOES-NOT-EXIST_no_exception_shoud_be_thrown");
125: }//testDeleteKeyException()
126:
127: public void testAddData() {
128: remoteService.storeXML("RULESET-ID1", "RULESET-VALUE1");
129: remoteService.storeXML("RULESET-ID2", "RULESET-VALUE2");
130: remoteService.storeXML("RULESET-ID3", "RULESET-VALUE3");
131: remoteService.storeXML("RULESET-ID4", "RULESET-VALUE4");
132: remoteService.storeXML("RULESET-ID5", "RULESET-VALUE5");
133: }//testAddData()
134:
135: public void testDeleteData() {
136: remoteService.deleteKey("RULESET-ID1");
137: remoteService.deleteKey("RULESET-ID2");
138: remoteService.deleteKey("RULESET-ID3");
139: remoteService.deleteKey("RULESET-ID4");
140: remoteService.deleteKey("RULESET-ID5");
141: }//testDeleteData()
142:
143: public static Test suite() {
144: TestSuite suite = new TestSuite();
145:
146: // Adding the Sample Data to test - must be the first test
147: suite.addTest(new TestIDSAMEDataServiceStub("testAddData"));
148:
149: suite
150: .addTest(new TestIDSAMEDataServiceStub(
151: "testRetrieveKeys"));
152: suite.addTest(new TestIDSAMEDataServiceStub("testRetrieveXML"));
153: suite.addTest(new TestIDSAMEDataServiceStub(
154: "testRetrieveXMLException"));
155: suite.addTest(new TestIDSAMEDataServiceStub("testStoreXML"));
156: suite.addTest(new TestIDSAMEDataServiceStub("testDeleteKey"));
157: suite.addTest(new TestIDSAMEDataServiceStub(
158: "testStoreXMLException"));
159: suite.addTest(new TestIDSAMEDataServiceStub(
160: "testDeleteKeyException"));
161:
162: // Deleting the Sample Data created - must be the last test
163: suite.addTest(new TestIDSAMEDataServiceStub("testDeleteData"));
164: return suite;
165: }//suite()
166:
167: public static void main(String[] args) {
168: SRAPRewriterModule.initFile();
169: //BasicTestCase.run( TestIDSAMEDataServiceStub.class );
170:
171: TestSuite testSuite = new TestSuite();
172: testSuite
173: .addTest(new TestIDSAMEDataServiceStub("testStoreXML"));
174: BasicTestCase.run(testSuite);
175: }//main()
176: }//class TestIDSAMEDataServiceStub
|