You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-dev@ws.apache.org by ip...@apache.org on 2005/04/01 02:22:18 UTC

svn commit: r159652 - in incubator/muse/trunk/src/site/content/interop/src/test/org/apache/ws/muws/interop/client: AbstractWsdmInteropTestCase.java ResourceStub.java SmallDeviceMgmtTestCase.java

Author: ips
Date: Thu Mar 31 16:22:16 2005
New Revision: 159652

URL: http://svn.apache.org/viewcvs?view=rev&rev=159652
Log:
finished writing all blackberry tests

Modified:
    incubator/muse/trunk/src/site/content/interop/src/test/org/apache/ws/muws/interop/client/AbstractWsdmInteropTestCase.java
    incubator/muse/trunk/src/site/content/interop/src/test/org/apache/ws/muws/interop/client/ResourceStub.java
    incubator/muse/trunk/src/site/content/interop/src/test/org/apache/ws/muws/interop/client/SmallDeviceMgmtTestCase.java

Modified: incubator/muse/trunk/src/site/content/interop/src/test/org/apache/ws/muws/interop/client/AbstractWsdmInteropTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/muse/trunk/src/site/content/interop/src/test/org/apache/ws/muws/interop/client/AbstractWsdmInteropTestCase.java?view=diff&r1=159651&r2=159652
==============================================================================
--- incubator/muse/trunk/src/site/content/interop/src/test/org/apache/ws/muws/interop/client/AbstractWsdmInteropTestCase.java (original)
+++ incubator/muse/trunk/src/site/content/interop/src/test/org/apache/ws/muws/interop/client/AbstractWsdmInteropTestCase.java Thu Mar 31 16:22:16 2005
@@ -15,21 +15,28 @@
  *=============================================================================*/
 package org.apache.ws.muws.interop.client;
 
+import org.apache.ws.muws.v1_0.MuwsConstants;
 import org.apache.ws.muws.v1_0.capability.IdentityCapability;
 import org.apache.ws.muws.v1_0.capability.ManageabilityCharacteristicsCapability;
 import org.apache.ws.muws.v1_0.capability.OperationalStatusCapability;
+import org.apache.ws.notification.base.v1_2.BaseNotification1_2Constants;
+import org.apache.ws.util.XmlBeanUtils;
 import org.apache.ws.util.jndi.XmlBeanJndiUtils;
+import org.apache.ws.util.test.PortListen;
 import org.apache.ws.util.test.axis.AbstractOneAxisTestCase;
 import org.apache.xmlbeans.XmlAnyURI;
+import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlPositiveInteger;
+import org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart1.ManagementEventType;
 import org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.OperationalStatusDocument;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.NotificationMessageHolderType;
+import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.NotifyDocument;
+import org.xmlsoap.schemas.soap.envelope.EnvelopeDocument;
 import org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceDocument;
-import org.everestWeather.wsdm.samples.x2005.x04.schema.WeatherstationPropertyQNames;
 
 import javax.xml.namespace.QName;
+import java.net.InetAddress;
 import java.net.URL;
-import java.math.BigInteger;
 
 /**
  * TODO
@@ -37,6 +44,10 @@
 public abstract class AbstractWsdmInteropTestCase extends AbstractOneAxisTestCase
 {
 
+    protected static final int        NOTIF_LISTENER_TIMEOUT           = 20000;
+    protected static final int        NOTIF_LISTENER_PORT              = 9101;
+    protected static String           s_consumerURL;
+
     private static final boolean RUN_AXIS_SERVER = Boolean.valueOf( System.getProperty( "runAxis", "false" ) )
             .booleanValue();
 
@@ -48,6 +59,7 @@
     protected void setUp() throws Exception
     {
         super.setUp();
+        s_consumerURL = "http://" + InetAddress.getLocalHost().getHostAddress() + ":" + NOTIF_LISTENER_PORT + "/";
         if ( RUN_AXIS_SERVER )
         {
             //init jndi from config
@@ -76,17 +88,8 @@
         assertTrue( statusPropElems[0] instanceof OperationalStatusDocument.OperationalStatus );
     }
 
-    protected void performMuwsMetricChangeAct( ResourceStub resource ) throws FaultException
-    {
-        // TODO
-    }
-
     protected void performMuwsStatusChangeEventAct( ResourceStub resource ) throws FaultException
     {
-        XmlObject[] capabilityPropElems = resource.getResourceProperty(
-                ManageabilityCharacteristicsCapability.PROP_NAME_MANAGEABILITY_CAPABILITY );
-        assertContainsURI( capabilityPropElems, OperationalStatusCapability.URI );
-        // TODO: subscribe to muws-events:StatusCapability topic and receive/validate a propChanged event
     }
 
     protected XmlObject getSingleProperty( ResourceStub resource, QName propName )
@@ -97,6 +100,12 @@
         return propElems[0];
     }
 
+    protected void setSingleProperty( ResourceStub resource, XmlObject propElem )
+            throws FaultException
+    {
+        resource.updateResourceProperty( new XmlObject[] {propElem} );
+    }
+
     protected void assertContainsURI( XmlObject[] capabilityPropElems, String uri )
     {
         boolean result = false;
@@ -122,6 +131,35 @@
     protected EndpointReferenceDocument getEndpointReference( URL url ) throws Exception
     {
         return (EndpointReferenceDocument) XmlObject.Factory.parse( url );
+    }
+
+    protected ManagementEventType waitForManagementEvent( PortListen notificationListener ) throws XmlException
+    {
+        // TODO: add support for unwrapped events
+        // wait for that termination notification
+        String incomingMsg = notificationListener.waitForIncomingMessage();
+        assertTrue( incomingMsg, incomingMsg.indexOf( "ERROR" ) == -1 );
+
+        //get envelope
+        XmlObject xmlObject = XmlObject.Factory.parse(incomingMsg);
+        assertTrue("The returned message was not a SOAP Envelope.", xmlObject instanceof EnvelopeDocument);
+        EnvelopeDocument envelope = (EnvelopeDocument) xmlObject;
+
+        //get notify
+        XmlObject bodyElems[] = XmlBeanUtils.getChildElements(envelope.getEnvelope().getBody(), new QName(BaseNotification1_2Constants.NSURI_WSNT_SCHEMA, "Notify"));
+        assertEquals( "The SOAP Body does not contain exactly one element.", 1, bodyElems.length );
+        XmlObject notifyDoc = bodyElems[0];
+        assertTrue("The SOAP Body does not contain a Notify element.", notifyDoc instanceof NotifyDocument.Notify);
+        NotifyDocument.Notify notify = (NotifyDocument.Notify) notifyDoc;
+
+        //get contained management event
+        NotificationMessageHolderType notificationMessageType = notify.getNotificationMessageArray(0);
+        XmlObject message = notificationMessageType.getMessage();
+        XmlObject xmlManagementEvent = XmlBeanUtils.getChildElements(message, new QName(MuwsConstants.NSURI_MUWS_PART1_SCHEMA, "ManagementEvent"))[0];
+        assertTrue("The Notify did not contain a ManagementEvent.", xmlManagementEvent instanceof ManagementEventType);
+
+        ManagementEventType mgmtEvent = (ManagementEventType) xmlManagementEvent;
+        return mgmtEvent;
     }
 
 }

Modified: incubator/muse/trunk/src/site/content/interop/src/test/org/apache/ws/muws/interop/client/ResourceStub.java
URL: http://svn.apache.org/viewcvs/incubator/muse/trunk/src/site/content/interop/src/test/org/apache/ws/muws/interop/client/ResourceStub.java?view=diff&r1=159651&r2=159652
==============================================================================
--- incubator/muse/trunk/src/site/content/interop/src/test/org/apache/ws/muws/interop/client/ResourceStub.java (original)
+++ incubator/muse/trunk/src/site/content/interop/src/test/org/apache/ws/muws/interop/client/ResourceStub.java Thu Mar 31 16:22:16 2005
@@ -87,7 +87,7 @@
     {
         SubscribeDocument requestDoc = SubscribeDocument.Factory.newInstance();
         SubscribeDocument.Subscribe subscribe = requestDoc.addNewSubscribe();
-        subscribe.setUseNotify(false);
+        //subscribe.setUseNotify(false);
         Calendar instance = Calendar.getInstance();
         instance.setTimeInMillis(instance.getTimeInMillis() + 20000);
         subscribe.setInitialTerminationTime( instance );

Modified: incubator/muse/trunk/src/site/content/interop/src/test/org/apache/ws/muws/interop/client/SmallDeviceMgmtTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/muse/trunk/src/site/content/interop/src/test/org/apache/ws/muws/interop/client/SmallDeviceMgmtTestCase.java?view=diff&r1=159651&r2=159652
==============================================================================
--- incubator/muse/trunk/src/site/content/interop/src/test/org/apache/ws/muws/interop/client/SmallDeviceMgmtTestCase.java (original)
+++ incubator/muse/trunk/src/site/content/interop/src/test/org/apache/ws/muws/interop/client/SmallDeviceMgmtTestCase.java Thu Mar 31 16:22:16 2005
@@ -15,34 +15,28 @@
  *=============================================================================*/
 package org.apache.ws.muws.interop.client;
 
+import org.apache.ws.addressing.XmlBeansEndpointReference;
+import org.apache.ws.muws.v1_0.MuwsConstants;
+import org.apache.ws.muws.v1_0.capability.ConfigurationCapability;
 import org.apache.ws.muws.v1_0.capability.ManageabilityCharacteristicsCapability;
 import org.apache.ws.muws.v1_0.capability.MetricsCapability;
-import org.apache.ws.muws.v1_0.capability.ConfigurationCapability;
-import org.apache.ws.muws.v1_0.MuwsConstants;
-import org.apache.ws.addressing.XmlBeansEndpointReference;
-import org.apache.ws.util.test.PortListen;
-import org.apache.ws.util.XmlBeanUtils;
-import org.apache.ws.notification.base.v1_2.BaseNotification1_2Constants;
+import org.apache.ws.muws.v1_0.capability.OperationalStatusCapability;
+import org.apache.ws.resource.example.blackberry.BlackberryPropertyQNames;
 import org.apache.ws.resource.properties.v2004_06.ResourcePropertiesConstants;
+import org.apache.ws.util.XmlBeanUtils;
+import org.apache.ws.util.test.PortListen;
 import org.apache.xmlbeans.XmlDateTime;
 import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlException;
-import org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceDocument;
-import org.xmlsoap.schemas.soap.envelope.EnvelopeDocument;
-import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.NotifyDocument;
-import org.oasisOpen.docs.wsn.x2004.x06.wsnWSBaseNotification12Draft01.NotificationMessageHolderType;
-import org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart1.ManagementEventDocument;
 import org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart1.ManagementEventType;
-
-import java.net.URL;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
+import org.oasisOpen.docs.wsdm.x2004.x12.muws.wsdmMuwsPart2.OperationalStatusDocument;
+import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.ResourcePropertyValueChangeNotificationType;
+import org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceDocument;
 import rim.pda.DateDocument;
 import rim.pda.TimeDocument;
 import rim.pda.TotalCodeModuleSizeDocument;
 
 import javax.xml.namespace.QName;
+import java.net.URL;
 
 /**
  * A test case containing a test for each act in the "Small Device Management"
@@ -65,9 +59,6 @@
     private static final QName PROP_NAME_DATE = new QName( NSURI_BLACKBERRY, "date", NSPREFIX_BLACKBERRY );
     private static final QName PROP_NAME_TIME = new QName( NSURI_BLACKBERRY, "time", NSPREFIX_BLACKBERRY );
 
-    private static final int        LISTENER_TIMEOUT           = 50000;
-    private static final int        NOTIFICATION_LISTENER_PORT = 9101;
-
     private ResourceStub m_resource;
 
     protected void setUp() throws Exception
@@ -88,9 +79,15 @@
         XmlObject[] capabilityElems = m_resource.getResourceProperty( ManageabilityCharacteristicsCapability.PROP_NAME_MANAGEABILITY_CAPABILITY );
         assertContainsURI( capabilityElems, MetricsCapability.URI );
         assertContainsURI( capabilityElems, CAPABILITY_URI_BLACKBERRY_METRICS );
+
         XmlObject currentTimePropElem = getSingleProperty( m_resource, MetricsCapability.PROP_NAME_CURRENT_TIME );
         assertTrue( currentTimePropElem instanceof XmlDateTime );
-        // TODO: retrieve and verify Blackberry metrics
+        XmlObject allocatedStoragePropElem = getSingleProperty( m_resource, BlackberryPropertyQNames.ALLOCATEDSTORAGE );
+        // TODO: check type & metric attribs
+        XmlObject freeStoragePropElem = getSingleProperty( m_resource, BlackberryPropertyQNames.FREESTORAGE );
+        // TODO: check type & metric attribs
+        XmlObject totalCodeModuleSizePropElem = getSingleProperty( m_resource, BlackberryPropertyQNames.TOTALCODEMODULESIZE );
+        // TODO: check type & metric attribs
     }
 
     public void testBlackberryConfiguration() throws FaultException
@@ -98,14 +95,36 @@
         XmlObject[] capabilityElems = m_resource.getResourceProperty( ManageabilityCharacteristicsCapability.PROP_NAME_MANAGEABILITY_CAPABILITY );
         assertContainsURI( capabilityElems, ConfigurationCapability.URI );
         assertContainsURI( capabilityElems, CAPABILITY_URI_BLACKBERRY_CONFIGURATION );
-        // TODO: set values on Date and Time props
+
+        // set date prop
+        DateDocument dateDoc = DateDocument.Factory.newInstance();
+        DateDocument.Date newDate = dateDoc.addNewDate();
+        newDate.setDay( 24 );
+        newDate.setMonth( 8 );
+        newDate.setYear( 1975 );
+        setSingleProperty( m_resource, dateDoc );
+
+        // set time prop
+        TimeDocument timeDoc = TimeDocument.Factory.newInstance();
+        TimeDocument.Time newTime = timeDoc.addNewTime();
+        newTime.setHour( 6 );
+        newTime.setMinute( 30 );
+        setSingleProperty( m_resource, timeDoc );
+
+        // get date prop and validate value is as we set it
         XmlObject datePropElem = getSingleProperty( m_resource, PROP_NAME_DATE );
         assertTrue( datePropElem instanceof DateDocument.Date );
         DateDocument.Date date = (DateDocument.Date)datePropElem;
+        assertEquals( newDate.getDay(), date.getDay() );
+        assertEquals( newDate.getMonth(), date.getMonth() );
+        assertEquals( newDate.getYear(), date.getYear() );
+
+        // get time prop and validate value is as we set it
         XmlObject timePropElem = getSingleProperty( m_resource, PROP_NAME_TIME );
         assertTrue( timePropElem instanceof TimeDocument.Time );
         TimeDocument.Time time = (TimeDocument.Time)timePropElem;
-        // TODO: check that the retrieved values match the values that we set above
+        assertEquals( newTime.getHour(), time.getHour() );
+        assertEquals( newTime.getMinute(), time.getMinute() );
     }
 
     public void testMuwsStatus() throws FaultException
@@ -113,53 +132,69 @@
         performMuwsStatusAct( m_resource );
     }
 
-    public void testMuwsMetricChange() throws FaultException
+    public void testMuwsMetricChange() throws Exception
     {
-        // TODO: is this act being removed?
-        performMuwsMetricChangeAct( m_resource );
+        XmlObject[] capabilityElems = m_resource.getResourceProperty( ManageabilityCharacteristicsCapability.PROP_NAME_MANAGEABILITY_CAPABILITY );
+        assertContainsURI( capabilityElems, MetricsCapability.URI );
+
+        m_resource.subscribe( s_consumerURL, new QName( MuwsConstants.NSURI_MUWS_PART2_TOPICS, MetricsCapability.TOPIC_NAME, MuwsConstants.NSPREFIX_MUWS_PART2_TOPICS ) );
+
+        PortListen notifListener = new PortListen( NOTIF_LISTENER_PORT, NOTIF_LISTENER_TIMEOUT );
+
+        TotalCodeModuleSizeDocument totalCodeModuleSizeDocument = TotalCodeModuleSizeDocument.Factory.newInstance();
+        totalCodeModuleSizeDocument.setTotalCodeModuleSize( 1111 );
+        setSingleProperty( m_resource, totalCodeModuleSizeDocument );
+
+        ManagementEventType mgmtEvent = waitForManagementEvent( notifListener );
+
+        XmlObject propChangedEvent = XmlBeanUtils.getChildElements(mgmtEvent, new QName(ResourcePropertiesConstants.NSURI_WSRP_SCHEMA, "ResourcePropertyValueChangeNotification"))[0];
+        assertNotNull("ManagementEvent does not contain a ResourcePropertyValueChangeNotification", propChangedEvent);
     }
 
-    public void testBlackberryCodeModuleSizeChangeEvent() throws FaultException, XmlException, UnknownHostException
+    public void testBlackberryCodeModuleSizeChangeEvent() throws Exception
     {
         XmlObject[] capabilityElems = m_resource.getResourceProperty( ManageabilityCharacteristicsCapability.PROP_NAME_MANAGEABILITY_CAPABILITY );
         assertContainsURI( capabilityElems, MetricsCapability.URI );
-        m_resource.subscribe( "http://" + InetAddress.getLocalHost().getHostAddress() + ":" + NOTIFICATION_LISTENER_PORT + "/", new QName( NSURI_BLACKBERRY, "CodeModuleSize_Change", NSPREFIX_BLACKBERRY ) );
 
-        //test as a listener for events
-        PortListen notificationListener = new PortListen( NOTIFICATION_LISTENER_PORT, LISTENER_TIMEOUT );
+        m_resource.subscribe( s_consumerURL, new QName( NSURI_BLACKBERRY, "CodeModuleSize_Change", NSPREFIX_BLACKBERRY ) );
+
+        PortListen notifListener = new PortListen( NOTIF_LISTENER_PORT, NOTIF_LISTENER_TIMEOUT );
 
         TotalCodeModuleSizeDocument totalCodeModuleSizeDocument = TotalCodeModuleSizeDocument.Factory.newInstance();
         totalCodeModuleSizeDocument.setTotalCodeModuleSize( 9999 );
+        setSingleProperty( m_resource, totalCodeModuleSizeDocument );
 
-        m_resource.updateResourceProperty( new XmlObject[] { totalCodeModuleSizeDocument } );
+        ManagementEventType mgmtEvent = waitForManagementEvent( notifListener );
 
-        // wait for that termination notification
-        String incomingMessage = notificationListener.waitForIncomingMessage();
+        XmlObject propChangedEvent = XmlBeanUtils.getChildElements(mgmtEvent, new QName(ResourcePropertiesConstants.NSURI_WSRP_SCHEMA, "ResourcePropertyValueChangeNotification"))[0];
+        assertNotNull("ManagementEvent does not contain a ResourcePropertyValueChangeNotification", propChangedEvent);
+    }
 
-        //get envelope
-        XmlObject xmlObject = XmlObject.Factory.parse(incomingMessage);
-        assertTrue("The returned message was not a SOAP Envelope.", xmlObject instanceof EnvelopeDocument);
-        EnvelopeDocument envelope = (EnvelopeDocument) xmlObject;
+    public void testMuwsStatusChangeEvent() throws Exception
+    {
+        XmlObject[] capabilityPropElems = m_resource.getResourceProperty(
+                ManageabilityCharacteristicsCapability.PROP_NAME_MANAGEABILITY_CAPABILITY );
+        assertContainsURI( capabilityPropElems, OperationalStatusCapability.URI );
 
-        //get notify
-        XmlObject notifyDoc = XmlBeanUtils.getChildElements(envelope.getEnvelope().getBody(), new QName(BaseNotification1_2Constants.NSURI_WSNT_SCHEMA, "Notify"))[0];
-        assertTrue("The body did not contain a NotifyDocument.", notifyDoc instanceof NotifyDocument.Notify);
-        NotifyDocument.Notify notify = (NotifyDocument.Notify) notifyDoc;
+        // init status to Available
+        OperationalStatusDocument operationalStatusDoc = OperationalStatusDocument.Factory.newInstance();
+        operationalStatusDoc.setOperationalStatus( OperationalStatusDocument.OperationalStatus.AVAILABLE );
+        setSingleProperty( m_resource, operationalStatusDoc );
 
-        //get contained management event
-        NotificationMessageHolderType notificationMessageType = notify.getNotificationMessageArray(0);
-        XmlObject message = notificationMessageType.getMessage();
-        XmlObject xmlManagementEvent = XmlBeanUtils.getChildElements(message, new QName(MuwsConstants.NSURI_MUWS_PART1_SCHEMA, "ManagementEvent"))[0];
-        assertTrue("The Notify did not contain a ManagementEvent.", xmlManagementEvent instanceof ManagementEventType);
+        m_resource.subscribe( s_consumerURL, new QName( MuwsConstants.NSURI_MUWS_PART2_TOPICS, OperationalStatusCapability.TOPIC_NAME, MuwsConstants.NSPREFIX_MUWS_PART2_TOPICS ) );
+        PortListen notifListener = new PortListen( NOTIF_LISTENER_PORT, NOTIF_LISTENER_TIMEOUT );
 
-        ManagementEventType managementEvent = (ManagementEventType) xmlManagementEvent;
-        XmlObject rpcEvent = XmlBeanUtils.getChildElements(managementEvent, new QName(ResourcePropertiesConstants.NSURI_WSRP_SCHEMA, "ResourcePropertyValueChangeNotification"))[0];
-        assertNotNull("There was no ResourcePropertyChangeEvent",rpcEvent);
-    }
+        // change status to Unavailable
+        operationalStatusDoc.setOperationalStatus( OperationalStatusDocument.OperationalStatus.UNAVAILABLE );
+        setSingleProperty( m_resource, operationalStatusDoc );
 
-    public void testMuwsStatusChangeEvent() throws FaultException
-    {
-        performMuwsStatusChangeEventAct( m_resource );
+        // make sure we receive a propChanged mgmtEvent
+        ManagementEventType mgmtEvent = waitForManagementEvent( notifListener );
+        XmlObject[] propChangedEvents = XmlBeanUtils.getChildElements(mgmtEvent, new QName(ResourcePropertiesConstants.NSURI_WSRP_SCHEMA, "ResourcePropertyValueChangeNotification"));
+        assertEquals( "ManagementEvent does not contain a single ResourcePropertyValueChangeNotification", 1, propChangedEvents.length );
+        assertTrue( propChangedEvents[0] instanceof ResourcePropertyValueChangeNotificationType );
+        ResourcePropertyValueChangeNotificationType propChangedEvent = (ResourcePropertyValueChangeNotificationType)propChangedEvents[0];
+        assertFalse( propChangedEvent.getNewValue().toString().equals( propChangedEvent.getOldValue().toString() ) );
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: muse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-dev-help@ws.apache.org