View Javadoc

1   /*
2    * Copyright 2007 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * This class runs the s2s generator that throws notifications at the system to simulate that situation for users.
27   * @author Kuali Rice Team (rice.collab@kuali.org)
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; // 30 minutes
79      }
80  
81      @Override
82      protected long getTestDuration() {
83          return 0; // forever
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      * Override runTest directly, as it is seems not to be called by either Eclipse or Ant JUnit test runner
108      * (which is the behavoir we want: we don't want a load test included with all the other tests)
109      */
110     @Test
111     public void runTest() throws Throwable {
112         // don't bother rolling back anything that was committed within the unit test transaction
113         //setComplete();
114 
115         // expose this method in this subclass for JUnit
116         super.runSimulation();
117 
118     }
119 
120     public static void main(String[] args) {
121         // can't use anonymous class to expose the real test
122         // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4071957
123         NotificationTestUsageGenerator test = new NotificationTestUsageGenerator();
124         if (args.length > 0) {
125             test.setWebServiceHost(args[0]);
126         }
127         //TestResult result = TestRunner.run(test);
128     }
129 }