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 = GlobalResourceLoader.getService(new QName(NAMESPACE, KMS_SERVICE));
58
59
60 InboxResource inboxResource = kmsService.getResource("inbox");
61
62
63 MessageResource messageResource = kmsService.getResource(MessageResource.class);
64
65 exerciseMessagingService(inboxResource, messageResource);
66 }
67
68
69
70
71
72
73
74 private void exerciseMessagingService(InboxResource inboxResource,
75 MessageResource messageResource) {
76 Inbox inbox = new Inbox();
77 inbox.setOwner("Joe Q. Tester");
78
79 inbox = inboxResource.createInbox(inbox);
80
81 Message message = new Message();
82 message.setRecipient("Joe Q. Tester");
83 message.setSubject("Hello new world!");
84 message.setText("This is a test message.");
85
86 Message createdMessage = messageResource.createMessage(message);
87
88 List<String> messages = inbox.getMessages();
89 messages.add(createdMessage.getId());
90
91 inboxResource.updateInbox(inbox);
92
93 inbox = inboxResource.retrieveInbox(inbox.getId());
94
95 List<String> updatedMessages = inbox.getMessages();
96
97 String updatedMessageId = updatedMessages.get(0);
98
99 Message retrievedMessage = messageResource.retrieve(updatedMessageId);
100
101 assertTrue(retrievedMessage.getSubject().equals("Hello new world!"));
102 }
103
104
105
106
107 @Test
108 public void testBaseballCardCollectionService() {
109 BaseballCard cardA = new BaseballCard("Mickey Mantle", "Topps", 1952);
110 BaseballCard cardB = new BaseballCard("Ted Williams", "Bowman", 1954);
111 BaseballCard cardC = new BaseballCard("Willie Mays", "Bowman", 1951);
112 BaseballCard cardD = new BaseballCard("Willie Mays Hayes", "Bogus", 1989);
113
114 BaseballCardCollectionService service =
115 (BaseballCardCollectionService) GlobalResourceLoader.getService(
116 new QName(NAMESPACE, BBCARD_SERVICE)
117 );
118
119
120 service.add(cardA);
121 service.add(cardB);
122 Integer willieMaysId = service.add(cardC);
123
124
125 List<BaseballCard> allCards = service.getAll();
126 assertNotNull(allCards);
127 assertTrue(allCards.size() == 3);
128 assertTrue(allCards.contains(cardA));
129 assertTrue(allCards.contains(cardB));
130 assertTrue(allCards.contains(cardC));
131
132
133 service.update(willieMaysId, cardD);
134 allCards = service.getAll();
135 assertNotNull(allCards);
136 assertTrue(allCards.size() == 3);
137 assertFalse(allCards.contains(cardC));
138 assertTrue(allCards.contains(cardD));
139
140
141 service.delete(willieMaysId);
142 allCards = service.getAll();
143 assertNotNull(allCards);
144 assertTrue(allCards.size() == 2);
145 assertFalse(allCards.contains(cardD));
146
147
148 service.add(cardA);
149 service.add(cardA);
150 service.add(cardA);
151 allCards = service.getAll();
152 assertTrue(allCards.size() == 5);
153
154 try {
155 service.unannotatedMethod();
156 fail("Magic? You can't remotely invoke a method that doesn't have JAX-RS annotations in the resource class!");
157 } catch (Exception e) {
158
159 e.printStackTrace();
160 }
161 }
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184 }