1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.ksb.messaging;
18
19 import java.util.List;
20
21 import javax.xml.namespace.QName;
22
23 import org.junit.Test;
24 import org.kuali.rice.core.config.ConfigContext;
25 import org.kuali.rice.core.resourceloader.GlobalResourceLoader;
26 import org.kuali.rice.ksb.messaging.remotedservices.BaseballCard;
27 import org.kuali.rice.ksb.messaging.remotedservices.BaseballCardCollectionService;
28 import org.kuali.rice.ksb.messaging.remotedservices.Inbox;
29 import org.kuali.rice.ksb.messaging.remotedservices.InboxResource;
30 import org.kuali.rice.ksb.messaging.remotedservices.Message;
31 import org.kuali.rice.ksb.messaging.remotedservices.MessageResource;
32 import org.kuali.rice.ksb.messaging.serviceconnectors.ResourceFacade;
33 import org.kuali.rice.ksb.test.KSBTestCase;
34
35
36
37
38
39
40
41 public class RESTServiceTest extends KSBTestCase {
42
43 private static final String BBCARD_SERVICE = "baseballCardCollectionService";
44 private static final String KMS_SERVICE = "kms";
45 private static final String KMS_MESSAGE_RESOURCE = "kms::message";
46 private static final String NAMESPACE = "test";
47
48
49 public boolean startClient1() {
50 return true;
51 }
52
53 private String getBaseBusUrl() {
54 return "http://localhost:" +
55 getClient1Port() +
56 "/TestClient1/remoting/";
57 }
58
59 private String getEndpointUrl() {
60 return getBaseBusUrl() + BBCARD_SERVICE;
61 }
62
63
64 private String getClient1Port() {
65 return ConfigContext.getCurrentContextConfig().getProperty("ksb.client1.port");
66 }
67
68 @Test
69 public void testMessagingService() throws Exception {
70 ResourceFacade kmsService =
71 (ResourceFacade) GlobalResourceLoader.getService(
72 new QName(NAMESPACE, KMS_SERVICE));
73
74
75 InboxResource inboxResource = kmsService.getResource("inbox");
76
77
78 MessageResource messageResource = kmsService.getResource(MessageResource.class);
79
80 exerciseMessagingService(inboxResource, messageResource);
81 }
82
83
84
85
86
87
88
89 private void exerciseMessagingService(InboxResource inboxResource,
90 MessageResource messageResource) {
91 Inbox inbox = new Inbox();
92 inbox.setOwner("Joe Q. Tester");
93
94 inbox = inboxResource.createInbox(inbox);
95
96 Message message = new Message();
97 message.setRecipient("Joe Q. Tester");
98 message.setSubject("Hello new world!");
99 message.setText("This is a test message.");
100
101 Message createdMessage = messageResource.createMessage(message);
102
103 List<String> messages = inbox.getMessages();
104 messages.add(createdMessage.getId());
105
106 inboxResource.updateInbox(inbox);
107
108 inbox = inboxResource.retrieveInbox(inbox.getId());
109
110 List<String> updatedMessages = inbox.getMessages();
111
112 String updatedMessageId = updatedMessages.get(0);
113
114 Message retrievedMessage = messageResource.retrieve(updatedMessageId);
115
116 assertTrue(retrievedMessage.getSubject().equals("Hello new world!"));
117 }
118
119
120
121
122 @Test
123 public void testBaseballCardCollectionService() {
124 BaseballCard cardA = new BaseballCard("Mickey Mantle", "Topps", 1952);
125 BaseballCard cardB = new BaseballCard("Ted Williams", "Bowman", 1954);
126 BaseballCard cardC = new BaseballCard("Willie Mays", "Bowman", 1951);
127 BaseballCard cardD = new BaseballCard("Willie Mays Hayes", "Bogus", 1989);
128
129 BaseballCardCollectionService service =
130 (BaseballCardCollectionService) GlobalResourceLoader.getService(
131 new QName(NAMESPACE, BBCARD_SERVICE)
132 );
133
134
135 service.add(cardA);
136 service.add(cardB);
137 Integer willieMaysId = service.add(cardC);
138
139
140 List<BaseballCard> allCards = service.getAll();
141 assertNotNull(allCards);
142 assertTrue(allCards.size() == 3);
143 assertTrue(allCards.contains(cardA));
144 assertTrue(allCards.contains(cardB));
145 assertTrue(allCards.contains(cardC));
146
147
148 service.update(willieMaysId, cardD);
149 allCards = service.getAll();
150 assertNotNull(allCards);
151 assertTrue(allCards.size() == 3);
152 assertFalse(allCards.contains(cardC));
153 assertTrue(allCards.contains(cardD));
154
155
156 service.delete(willieMaysId);
157 allCards = service.getAll();
158 assertNotNull(allCards);
159 assertTrue(allCards.size() == 2);
160 assertFalse(allCards.contains(cardD));
161
162
163 service.add(cardA);
164 service.add(cardA);
165 service.add(cardA);
166 allCards = service.getAll();
167 assertTrue(allCards.size() == 5);
168
169 try {
170 service.unannotatedMethod();
171 fail("Magic? You can't remotely invoke a method that doesn't have JAX-RS annotations in the resource class!");
172 } catch (Exception e) {
173
174 e.printStackTrace();
175 }
176 }
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199 }