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