Author: wire
Date: Tue Aug  9 13:18:16 2005
New Revision: 231101

URL: http://svn.apache.org/viewcvs?rev=231101&view=rev
Log:
Moved test out of default package so it runs in tomcat

Added:
    webservices/muse/trunk/src/examples/ieeedemo/client/test/tests/
    
webservices/muse/trunk/src/examples/ieeedemo/client/test/tests/WsCompatabilityTest.java
      - copied, changed from r230846, 
webservices/muse/trunk/src/examples/ieeedemo/client/test/WsCompatabilityTest.java
Removed:
    
webservices/muse/trunk/src/examples/ieeedemo/client/test/WsCompatabilityTest.java

Copied: 
webservices/muse/trunk/src/examples/ieeedemo/client/test/tests/WsCompatabilityTest.java
 (from r230846, 
webservices/muse/trunk/src/examples/ieeedemo/client/test/WsCompatabilityTest.java)
URL: 
http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/ieeedemo/client/test/tests/WsCompatabilityTest.java?p2=webservices/muse/trunk/src/examples/ieeedemo/client/test/tests/WsCompatabilityTest.java&p1=webservices/muse/trunk/src/examples/ieeedemo/client/test/WsCompatabilityTest.java&r1=230846&r2=231101&rev=231101&view=diff
==============================================================================
--- 
webservices/muse/trunk/src/examples/ieeedemo/client/test/WsCompatabilityTest.java
 (original)
+++ 
webservices/muse/trunk/src/examples/ieeedemo/client/test/tests/WsCompatabilityTest.java
 Tue Aug  9 13:18:16 2005
@@ -1,8 +1,14 @@
+package tests;

+import java.io.ByteArrayOutputStream;

 import java.io.IOException;

+import java.io.OutputStream;

+import java.io.PrintStream;

+import java.io.StringBufferInputStream;

 import java.util.Calendar;

 import java.util.Set;

 import java.util.TreeSet;

 

+import javax.servlet.jsp.JspWriter;

 import javax.xml.namespace.QName;

 

 import junit.framework.TestCase;

@@ -21,10 +27,12 @@
 import org.apache.xmlbeans.XmlObject;

 import org.apache.xmlbeans.impl.values.XmlDoubleImpl;

 import org.apache.xmlbeans.impl.values.XmlStringImpl;

+import org.mortbay.util.StringBufferWriter;

 import org.oasisOpen.docs.wsdm.x2004.x12.mows.wsdmMows.impl.DurationMetricImpl;

 import 
org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart1.impl.ManagementEventTypeImpl;

 import 
org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.impl.OperationalStatusDocumentImpl;

 import 
org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.NotificationMessageHolderType;

+import org.wsdmdemo.service.weatherStation.KickmeDocument;

 import org.wsdmdemo.service.weatherStation.RecalibrateDocument;

 import org.wsdmdemo.service.weatherStation.impl.PriceDocumentImpl;

 import org.wsdmdemo.service.weatherStation.impl.TemperatureMetricTypeImpl;

@@ -236,14 +244,15 @@
         *

         */

        public void testRecalibrate() throws IOException, InterruptedException, 
XmlException, FaultException{

+               //System.out.println("Starting Recal Test");

                // Start Listener, Notifications will be passed to 

                m_listener=new 
NotificationListener(LISTENER_PORT,NOTIFICATION_TIMEOUT,m_buffer);

                m_listener.start();

                

                // Subscribe

                assertNotNull("Please define the WeatherStationListenerHostname 
System property.",weatherStationListenerHostname);

-               String notificationURL = 
"http://"+weatherStationListenerHostname+":"+LISTENER_PORT+"/unittest";;

-               EndpointReference subscriptionEpr = 
m_wsResourceStub.subscribe(notificationURL,weatherStationStatusTopic);

+               String notificationURL = 
"http://"+weatherStationListenerHostname+":"+LISTENER_PORT+"/"+weatherStationRid;

+               EndpointReference subscriptionEpr = 
m_wsResourceStub.subscribe(notificationURL,weatherStationStatusTopic,30000);

                assertNotNull(subscriptionEpr);

                

                // Unit test thread will now block until a notification or a 
timeout occurs

@@ -256,31 +265,50 @@
                }

                

                synchronized(m_buffer){

-                       String messageText=m_buffer.toString();         

+                       String messageText=m_buffer.toString();

+                       //System.out.println(messageText);                      

                        m_buffer.notify();// Release the buffer

                        String status = extractStatus(messageText);

-                       assertEquals("Your weather station did not report 
unavailable in response to recalibrate","Unavailable",status);

+                       assertEquals("Your weather station did not report 
unavailable in response to recalibrate. Notfification was 
"+messageText+".","Unavailable",status);

+                       //System.out.println("Received Unavailable in response 
to Recalibrate.");

                }

-               // There should be an available notification too

+               // There should be an available notification too but endure a 
few 

+               // more unavailables if they are sent first

+               //System.out.println("Waiting for system to become 
available...");

                synchronized(m_buffer){

                        m_buffer.wait();

                }

 

-               synchronized(m_buffer){

-                       String messageText=m_buffer.toString();         

-                       m_buffer.notify();// Release the buffer

-                       String status = extractStatus(messageText);

-                       assertEquals("Your weather station did not report 
available after unavailable in response to recalibrate","Available",status);

-               }

+

+//             boolean pass=false;

+               //for(int retry=0;retry <10;retry++){                   

+                       synchronized(m_buffer){

+                               String messageText=m_buffer.toString();         

+                               //System.out.println(messageText);              
        

+                               m_buffer.notify();// Release the buffer

+                               String status = extractStatus(messageText);

+                               //System.out.println("Received "+status);

+                               assertEquals("Your weather station did not 
report available after unavailable in response to recalibrate. This message 
also occurs if there is a previous subscription which has not expired causing 
double notification.","Available",status);

+//                             if(status.equals("Available")){

+//                                     pass=true;

+//                                     break;

+//                             }

+                       }

+               //}

+               

+

+               // Destroy this subscription

+               //System.out.println("Destroying Subscription");

+               ResourceStub subManager=new ResourceStub(subscriptionEpr);

+               subManager.destroySubscription();//EndpointReference 
subscriptionEpr1 = 

+               //System.out.println("Ending Recal Test");

+               

        }

 

        private String extractStatus(String messageText) throws XmlException {

-               // If we get here there is something in our buffer

-               System.out.println("Notification Starts.");

-               System.out.println(messageText);

-               System.out.println("Notification Ends.");

 

                // Break down the message

+               assertNotNull("The content received as a notifications was 
null.",messageText);

                NotificationMessageHolderType noteMess = 
WcMgrApp.getNotificationMessageHolder(messageText);

                assertNotNull(noteMess);

                ManagementEventTypeImpl manEvt = 
WcMgrApp.parseManagementEvent(noteMess);                               

@@ -289,20 +317,52 @@
                assertNotNull(optStatus);

                EndpointReferenceType epr = WcMgrApp.parseSourceEpr(noteMess);

                assertNotNull(epr);

-               assertNotNull("You are required to provide a vailid Source Epr 
for your notifications.",epr);

+               assertNotNull("You are required to provide a vailid Source Epr 
for your notifications. Notification XML was "+messageText+".",epr);

                AttributedURI address = epr.getAddress();

                assertNotNull(address);

-               assertEquals("The Source EPR address should match your 
service's EPR for the clients to identify the origination of your 
notification.",weatherStationURL,address.getStringValue());

+               

+               // Make sure that the POST Uri is the same as the URI provided 
by the subscription request.

+               // This is how notifications will be sorted by clients 

+               assertEquals("The Notification URI should match the URI 
provided by the subscriber. This is required because the client may need to 
identify your notifications from other weather 
stations.","/"+weatherStationRid,m_listener.getRequestUri());

                return optStatus;

        }

        

        /**

         * Objectives:

         * When a kick is issued, weather readings should drop out of the 
expected range.

+        * @throws FaultException 

+        * @throws XmlException 

+        * @throws InterruptedException 

+        * @throws IOException 

         *

         */

-       public void testForKickResponse(){

+       public void testForKickResponse() throws FaultException, IOException, 
InterruptedException, XmlException{

+        KickmeDocument kickmeDocument = KickmeDocument.Factory.newInstance();

+        kickmeDocument.addNewKickme();

+        XmlObject kickResponse = 
m_wsResourceStub.sendRequest(kickmeDocument,"http://kickme","M";);

+               assertNotNull(kickResponse);

+

+               // Temperature should drop below 75

+               XmlObject[] 
responseArry=m_wsResourceStub.getResourceProperty(weatherStationTemperatureQname);

+               assertNotNull(responseArry);

+               assertTrue(responseArry.length>0);

+

+               assertTrue("The response document was not a 
TemperatureMetricTypeImpl. This may indicate that you are missing the xbean 
jars for the Weather Station. Confirm that they are on the classpath and try 
again.",

+                               responseArry[0] instanceof 
TemperatureMetricTypeImpl);

+               

+               TemperatureMetricTypeImpl 
temperatureMetric=(TemperatureMetricTypeImpl)responseArry[0];

+               assertNotNull(temperatureMetric);

                                

+               double temperature = temperatureMetric.doubleValue();

+               assertTrue("Temperature should be less than 75 Degrees because 
the station has just been kicked. Reported Temperature was 
"+temperature,temperature<75.0);

+

+               // Issue a recalibrate. This should reset the temperature to 
range after going 

+               // unavaiable and then available.

+               testRecalibrate();

+               

+               // Get temp and check is it is in range.

+               getCurrentTemperature();

+               

        }

        

        

@@ -333,9 +393,31 @@
                if(args.length>=3)

                        
System.setProperty("WeatherStationListenerHostname",args[2]);

                

+               junit.textui.TestRunner.run(WsCompatabilityTest.class);

                

-               junit.swingui.TestRunner.run(WsCompatabilityTest.class);

        }

-

-

+       public static void runTests(String[] args, JspWriter jspw) 
{//PrintStream

+               if(args.length==0){

+                       System.out.println("Usage: wstest <ServiceURL> 
<ServiceResourceID> <ListenerHostname>");

+                       return ;

+               }

+               if(args.length>=1)

+                       System.setProperty("WeatherStationServiceURL",args[0]);

+               if(args.length>=2)

+                       
System.setProperty("WeatherStationServiceResourceID",args[1]);

+               if(args.length>=3)

+                       
System.setProperty("WeatherStationListenerHostname",args[2]);

+               

+               PrintStream saveOut = System.out;

+               ByteArrayOutputStream os=new ByteArrayOutputStream();

+               PrintStream sbip = new PrintStream(os);

+               System.setOut(sbip);

+               junit.textui.TestRunner.run(WsCompatabilityTest.class);

+               System.setOut(saveOut);

+               try {

+                       jspw.println(os.toString());

+               } catch (IOException e) {               

+                       e.printStackTrace();

+               }

+       }

 }




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to