1 17 package org.alfresco.repo.service; 18 19 import org.alfresco.service.cmr.repository.NodeRef; 20 import org.alfresco.service.cmr.repository.StoreRef; 21 import org.springframework.context.ApplicationContext; 22 import org.springframework.context.support.ClassPathXmlApplicationContext; 23 24 import junit.framework.TestCase; 25 26 public class StoreRedirectorProxyFactoryTest extends TestCase 27 { 28 29 private ApplicationContext factory = null; 30 31 public void setUp() 32 { 33 factory = new ClassPathXmlApplicationContext("org/alfresco/repo/service/testredirector.xml"); 34 } 35 36 public void testRedirect() 37 { 38 StoreRef storeRef1 = new StoreRef("Type1", "id"); 39 StoreRef storeRef2 = new StoreRef("Type2", "id"); 40 StoreRef storeRef3 = new StoreRef("Type3", "id"); 41 StoreRef storeRef4 = new StoreRef("Type3", "woof"); 42 NodeRef nodeRef1 = new NodeRef(storeRef1, "id"); 43 NodeRef nodeRef2 = new NodeRef(storeRef2, "id"); 44 45 TestServiceInterface service = (TestServiceInterface) factory.getBean("redirector_service1"); 46 47 String result1 = service.defaultBinding("redirector_service1"); 48 assertEquals("Type1:redirector_service1", result1); 49 String result1a = service.noArgs(); 50 assertEquals("Type1", result1a); 51 String result2 = service.storeRef(storeRef1); 52 assertEquals("Type1:" + storeRef1, result2); 53 String result3 = service.storeRef(storeRef2); 54 assertEquals("Type2:" + storeRef2, result3); 55 String result4 = service.nodeRef(nodeRef1); 56 assertEquals("Type1:" + nodeRef1, result4); 57 String result5 = service.nodeRef(nodeRef2); 58 assertEquals("Type2:" + nodeRef2, result5); 59 String result6 = service.multiStoreRef(storeRef1, storeRef1); 60 assertEquals("Type1:" + storeRef1 + "," + storeRef1, result6); 61 String result7 = service.multiStoreRef(storeRef2, storeRef2); 62 assertEquals("Type2:" + storeRef2 + "," + storeRef2, result7); 63 String result8 = service.multiNodeRef(nodeRef1, nodeRef1); 64 assertEquals("Type1:" + nodeRef1 + "," + nodeRef1, result8); 65 String result9 = service.multiNodeRef(nodeRef2, nodeRef2); 66 assertEquals("Type2:" + nodeRef2 + "," + nodeRef2, result9); 67 String result10 = service.mixedStoreNodeRef(storeRef1, nodeRef1); 68 assertEquals("Type1:" + storeRef1 + "," + nodeRef1, result10); 69 String result11 = service.mixedStoreNodeRef(storeRef2, nodeRef2); 70 assertEquals("Type2:" + storeRef2 + "," + nodeRef2, result11); 71 String result12 = service.mixedStoreNodeRef(null, null); 72 assertEquals("Type1:null,null", result12); 73 String result13 = service.mixedStoreNodeRef(storeRef1, null); 74 assertEquals("Type1:" + storeRef1 + ",null", result13); 75 76 String result14 = service.storeRef(storeRef3); 78 assertEquals("Type3:" + storeRef3, result14); 79 String result15 = service.storeRef(storeRef4); 80 assertEquals("Type1:" + storeRef4, result15); 81 } 82 83 public void testInvalidArgs() 84 { 85 StoreRef defaultRef = new StoreRef("Type1", "id"); 86 StoreRef storeRef1 = new StoreRef("InvalidType1", "id"); 87 NodeRef nodeRef1 = new NodeRef(storeRef1, "id"); 88 89 TestServiceInterface service = (TestServiceInterface) factory.getBean("redirector_service1"); 90 String result1 = service.storeRef(storeRef1); 91 assertEquals("Type1:" + storeRef1, result1); 92 String result2 = service.nodeRef(nodeRef1); 93 assertEquals("Type1:" + nodeRef1, result2); 94 } 95 96 public void testException() 97 { 98 StoreRef storeRef1 = new StoreRef("Type1", "id"); 99 NodeRef nodeRef1 = new NodeRef(storeRef1, "id"); 100 TestServiceInterface service = (TestServiceInterface) factory.getBean("redirector_service1"); 101 102 try 103 { 104 service.throwException(nodeRef1); 105 fail("Service method did not throw exception"); 106 } 107 catch(Exception e) 108 { 109 assertTrue(e instanceof IllegalArgumentException ); 110 assertEquals(nodeRef1.toString(), e.getMessage()); 111 } 112 } 113 114 115 public interface TestServiceInterface 116 { 117 public String noArgs(); 118 119 public String defaultBinding(String arg); 120 121 public String storeRef(StoreRef ref1); 122 123 public String nodeRef(NodeRef ref1); 124 125 public String multiStoreRef(StoreRef ref1, StoreRef ref2); 126 127 public String multiNodeRef(NodeRef ref1, NodeRef ref2); 128 129 public String mixedStoreNodeRef(StoreRef ref2, NodeRef ref1); 130 131 public void throwException(NodeRef ref1); 132 } 133 134 135 public static abstract class Component implements TestServiceInterface 136 { 137 private String type; 138 139 private Component(String type) 140 { 141 this.type = type; 142 } 143 144 public String noArgs() 145 { 146 return type; 147 } 148 149 public String defaultBinding(String arg) 150 { 151 return type + ":" + arg; 152 } 153 154 public String nodeRef(NodeRef ref1) 155 { 156 return type + ":" + ref1; 157 } 158 159 public String storeRef(StoreRef ref1) 160 { 161 return type + ":" + ref1; 162 } 163 164 public String multiNodeRef(NodeRef ref1, NodeRef ref2) 165 { 166 return type + ":" + ref1 + "," + ref2; 167 } 168 169 public String multiStoreRef(StoreRef ref1, StoreRef ref2) 170 { 171 return type + ":" + ref1 + "," + ref2; 172 } 173 174 public String mixedStoreNodeRef(StoreRef ref1, NodeRef ref2) 175 { 176 return type + ":" + ref1 + "," + ref2; 177 } 178 179 public void throwException(NodeRef ref1) 180 { 181 throw new IllegalArgumentException (ref1.toString()); 182 } 183 184 } 185 186 public static class Type1Component extends Component 187 { 188 private Type1Component() 189 { 190 super("Type1"); 191 } 192 } 193 194 public static class Type2Component extends Component 195 { 196 private Type2Component() 197 { 198 super("Type2"); 199 } 200 } 201 202 public static class Type3Component extends Component 203 { 204 private Type3Component() 205 { 206 super("Type3"); 207 } 208 } 209 210 } 211 | Popular Tags |