1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ksb.messaging;
17
18 import java.util.List;
19
20 import javax.xml.namespace.QName;
21
22 import org.junit.Test;
23 import org.kuali.rice.core.config.ConfigContext;
24 import org.kuali.rice.core.util.RiceUtilities;
25 import org.kuali.rice.ksb.messaging.remotedservices.TestRepeatMessageQueue;
26 import org.kuali.rice.ksb.messaging.service.ServiceRegistry;
27 import org.kuali.rice.ksb.service.KSBServiceLocator;
28 import org.kuali.rice.ksb.test.KSBTestCase;
29 import org.kuali.rice.ksb.util.KSBConstants;
30 import org.kuali.rice.test.TransactionalTest;
31
32
33
34
35
36
37 @TransactionalTest
38 public class ServiceUpdateAndRemovalTest extends KSBTestCase {
39
40
41
42
43
44
45 @Test
46 public void testRemovalOfAllLocalServices() throws Exception {
47 ServiceRegistry serviceRegistry = KSBServiceLocator.getServiceRegistry();
48 String ipNumber = RiceUtilities.getIpNumber();
49 String serviceNamespace = ConfigContext.getCurrentContextConfig().getServiceNamespace();
50 List<ServiceInfo> serviceInfos = serviceRegistry.findLocallyPublishedServices(ipNumber, serviceNamespace);
51 assertTrue("There should be at least one locally published service in the database.", serviceInfos.size() > 0);
52 serviceRegistry.removeLocallyPublishedServices(ipNumber, serviceNamespace);
53 serviceInfos = serviceRegistry.findLocallyPublishedServices(ipNumber, serviceNamespace);
54 assertEquals("There should not be any locally published services in the database.", 0, serviceInfos.size());
55 }
56
57
58
59
60
61
62 @Test
63 public void testModificationOfLocalServices() throws Exception {
64 RemotedServiceRegistry remotedServiceRegistry = KSBServiceLocator.getServiceDeployer();
65 QName serviceName = new QName("KEW", "serviceForTestingModifications");
66 QName forwardServiceName = new QName("KEW", "serviceForTestingModifications" + KSBConstants.FORWARD_HANDLER_SUFFIX);
67 ServiceInfo regularInfo = null;
68 ServiceInfo forwardInfo = null;
69
70 ServiceDefinition serviceDefinition = new JavaServiceDefinition();
71 serviceDefinition.setServiceName(serviceName);
72 serviceDefinition.setPriority(4);
73 serviceDefinition.setService(new TestRepeatMessageQueue());
74 serviceDefinition.validate();
75 remotedServiceRegistry.registerService(serviceDefinition, true);
76
77 regularInfo = remotedServiceRegistry.getRemotedServiceHolder(serviceName).getServiceInfo();
78 forwardInfo = remotedServiceRegistry.getRemotedServiceHolder(forwardServiceName).getServiceInfo();
79
80 assertRegistryRefreshHasExpectedResults(remotedServiceRegistry, regularInfo, forwardInfo, serviceName, forwardServiceName, false);
81
82 regularInfo = remotedServiceRegistry.getRemotedServiceHolder(serviceName).getServiceInfo();
83 forwardInfo = remotedServiceRegistry.getRemotedServiceHolder(forwardServiceName).getServiceInfo();
84 serviceDefinition.setPriority(3);
85 serviceDefinition.validate();
86 assertRegistryRefreshHasExpectedResults(remotedServiceRegistry, regularInfo, forwardInfo, serviceName, forwardServiceName, true);
87 }
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102 private void assertRegistryRefreshHasExpectedResults(RemotedServiceRegistry remotedServiceRegistry, ServiceInfo regularInfo, ServiceInfo forwardInfo,
103 QName serviceName, QName forwardServiceName, boolean serviceDefinitionsShouldDiffer) throws Exception {
104 MessageHelper messageHelper = KSBServiceLocator.getMessageHelper();
105
106 remotedServiceRegistry.refresh();
107 ServiceInfo newRegularInfo = remotedServiceRegistry.getRemotedServiceHolder(serviceName).getServiceInfo();
108 ServiceInfo newForwardInfo = remotedServiceRegistry.getRemotedServiceHolder(forwardServiceName).getServiceInfo();
109
110 assertTrue("The ServiceInfo instances for the service should satisy the non-ServiceDefinition part of an isSame() check",
111 regularInfo.getAlive().equals(newRegularInfo.getAlive()) && regularInfo.getQname().equals(newRegularInfo.getQname()) &&
112 regularInfo.getServerIp().equals(newRegularInfo.getServerIp()) &&
113 regularInfo.getServiceNamespace().equals(newRegularInfo.getServiceNamespace()));
114 assertTrue("The ServiceInfo instances for the ForwardedCallHandler should satisy the non-ServiceDefinition part of an isSame() check",
115 forwardInfo.getAlive().equals(newForwardInfo.getAlive()) && forwardInfo.getQname().equals(newForwardInfo.getQname()) &&
116 forwardInfo.getServerIp().equals(newForwardInfo.getServerIp()) &&
117 forwardInfo.getServiceNamespace().equals(newForwardInfo.getServiceNamespace()));
118 assertTrue("The service definition references should be pointing to the same instance",
119 regularInfo.getServiceDefinition(messageHelper) == newRegularInfo.getServiceDefinition(messageHelper));
120
121 if (serviceDefinitionsShouldDiffer) {
122 assertNotSame("The checksum for the configured service should have been modified after refreshing the registry.",
123 regularInfo.getChecksum(), newRegularInfo.getChecksum());
124 assertNotSame("The checksum for the ForwardedCallHandler service should have been modified after refreshing the registry.",
125 forwardInfo.getChecksum(), newForwardInfo.getChecksum());
126 assertTrue("The ForwardedCallHandler service definitions should not be the same",
127 !forwardInfo.getServiceDefinition(messageHelper).isSame(newForwardInfo.getServiceDefinition(messageHelper)));
128 assertNotSame("The serialized versions of the service definitions should not be the same",
129 regularInfo.getSerializedServiceNamespace().getFlattenedServiceDefinitionData(),
130 newRegularInfo.getSerializedServiceNamespace().getFlattenedServiceDefinitionData());
131 assertNotSame("The serialized versions of the ForwardedCallHandler service definitions should not be the same",
132 forwardInfo.getSerializedServiceNamespace().getFlattenedServiceDefinitionData(),
133 newForwardInfo.getSerializedServiceNamespace().getFlattenedServiceDefinitionData());
134 } else {
135 assertEquals("The checksum for the configured service should not have been modified after refreshing the registry.",
136 regularInfo.getChecksum(), newRegularInfo.getChecksum());
137 assertEquals("The checksum for the ForwardedCallHandler service should not have been modified after refreshing the registry.",
138 forwardInfo.getChecksum(), newForwardInfo.getChecksum());
139 assertTrue("The ForwardedCallHandler service definitions should be the same",
140 forwardInfo.getServiceDefinition(messageHelper).isSame(newForwardInfo.getServiceDefinition(messageHelper)));
141 assertEquals("The serialized versions of the service definitions should be the same",
142 regularInfo.getSerializedServiceNamespace().getFlattenedServiceDefinitionData(),
143 newRegularInfo.getSerializedServiceNamespace().getFlattenedServiceDefinitionData());
144 assertEquals("The serialized versions of the ForwardedCallHandler service definitions should be the same",
145 forwardInfo.getSerializedServiceNamespace().getFlattenedServiceDefinitionData(),
146 newForwardInfo.getSerializedServiceNamespace().getFlattenedServiceDefinitionData());
147 }
148 }
149 }