1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ken.services.ws.impl;
17
18 import java.io.ByteArrayOutputStream;
19 import java.io.IOException;
20 import java.io.InputStream;
21
22 import org.junit.Ignore;
23 import org.junit.Test;
24
25
26
27
28
29 @Ignore
30 public class NotificationTestUsageGenerator extends NotificationUsageSimulator {
31 private String webServiceHost = null;
32
33 private final String[] NOTIFICATIONS = new String[5];
34
35 protected static String readStream(InputStream is) throws IOException {
36 ByteArrayOutputStream baos = new ByteArrayOutputStream();
37 byte[] buf = new byte[1024];
38 int read;
39 try {
40 while ((read = is.read(buf)) != -1) {
41 baos.write(buf, 0, read);
42 }
43 } finally {
44 is.close();
45 }
46 return new String(baos.toByteArray());
47 }
48
49 protected int counter = 0;
50
51 @Override
52 protected void initialize() {
53 try {
54 NOTIFICATIONS[0] = readStream(getClass().getResourceAsStream("StaticMessage0.xml"));
55 NOTIFICATIONS[1] = readStream(getClass().getResourceAsStream("StaticMessage1.xml"));
56 NOTIFICATIONS[2] = readStream(getClass().getResourceAsStream("StaticMessage2.xml"));
57 NOTIFICATIONS[3] = readStream(getClass().getResourceAsStream("StaticMessage3.xml"));
58 NOTIFICATIONS[4] = readStream(getClass().getResourceAsStream("StaticMessage4.xml"));
59 } catch (IOException ioe) {
60 throw new RuntimeException("Error loading test notification data", ioe);
61 }
62 }
63
64 @Override
65 protected synchronized String generateNotificationMessage() {
66 String notification = NOTIFICATIONS[counter];
67 counter = (counter + 1) % NOTIFICATIONS.length;
68 return notification;
69 }
70
71 @Override
72 protected int getNumThreads() {
73 return 1;
74 }
75
76 @Override
77 protected long getSleepTimeMillis() {
78 return 1000 * 60 * 30;
79 }
80
81 @Override
82 protected long getTestDuration() {
83 return 0;
84 }
85
86 @Override
87 protected int getWebServicePort() {
88 return 8080;
89 }
90
91 @Override
92 protected String getWebServiceHost() {
93 return webServiceHost;
94 }
95
96 public void setWebServiceHost(String s) {
97 this.webServiceHost = s;
98 }
99
100 @Override
101 protected boolean shouldStartWebService() {
102 return false;
103 }
104
105
106
107
108
109
110 @Test
111 public void runTest() throws Throwable {
112
113
114
115
116 super.runSimulation();
117
118 }
119
120 public static void main(String[] args) {
121
122
123 NotificationTestUsageGenerator test = new NotificationTestUsageGenerator();
124 if (args.length > 0) {
125 test.setWebServiceHost(args[0]);
126 }
127
128 }
129 }