You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-commits@ws.apache.org by wi...@apache.org on 2005/09/27 17:56:55 UTC

svn commit: r291980 - /webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/muse/client/impl/ManageableResourceImplTest.java

Author: wire
Date: Tue Sep 27 08:56:53 2005
New Revision: 291980

URL: http://svn.apache.org/viewcvs?rev=291980&view=rev
Log:
Removed restriction on the exact numer of properties that must be available

Modified:
    webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/muse/client/impl/ManageableResourceImplTest.java

Modified: webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/muse/client/impl/ManageableResourceImplTest.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/muse/client/impl/ManageableResourceImplTest.java?rev=291980&r1=291979&r2=291980&view=diff
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/muse/client/impl/ManageableResourceImplTest.java (original)
+++ webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/muse/client/impl/ManageableResourceImplTest.java Tue Sep 27 08:56:53 2005
@@ -9,6 +9,8 @@
 
 import org.apache.ws.client.muse.client.impl.exceptions.FaultException;
 import org.apache.ws.client.muse.client.impl.exceptions.UnexpectedServerResponseException;
+import org.apache.ws.client.muse.client.model.SetPropertiesRequest;
+import org.apache.ws.resource.properties.faults.InvalidResourcePropertyQNameFaultException;
 import org.apache.ws.muws.v1_0.impl.advertiser.ResourceAdvertiserPropertyQNames;
 import org.apache.ws.service.testresource.TestResourcePropertyQNames;
 import org.apache.ws.util.test.axis.MuseClientTestCase;
@@ -20,6 +22,8 @@
 	private String eprTxt; 
 	private URL testAddress;
 	private ManageableResourceImpl testImpl;
+  	String dialect1 = "http://www.w3.org/TR/1999/REC-xpath-19991116";
+  	String dialect2 = "http://www.w3.org/TR/2003/WD-xpath20-20031112";
 	
 	protected void setUp() throws Exception {
 		super.setUp();
@@ -33,7 +37,59 @@
 	protected void tearDown() throws Exception {
 		super.tearDown();
 	}
+	/**
+	 * Objective: Request a list of property qnames and make sure it is 
+	 * of the expected length. 
+	 * @throws UnexpectedServerResponseException 
+	 * @throws XmlException 
+	 * @throws IOException 
+	 * @throws URISyntaxException 
+	 * @throws FaultException 
+	 * @throws FaultException 
+	 *
+	 */
+	public void testGetPropertyNames() throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException{
+		QName[] infoArry= testImpl.getPropertyQNames();
+		assertNotNull(infoArry);
+		assertTrue(infoArry.length>0);
+	}
+
+	// DONE: Beginning support for QueryResourceProperties
+	/**
+	 * Objective: Query resource properties with an XPath expression using 
+	 * a specific XPath dialect. 
+	 * @throws UnexpectedServerResponseException 
+	 * @throws XmlException 
+	 * @throws IOException 
+	 * @throws URISyntaxException 
+	 * @throws UnexpectedServerResponseException 
+	 * @throws XmlException 
+	 * @throws IOException 
+	 * @throws URISyntaxException 
+	 * @throws FaultException 
+	 * @throws FaultException 
+	 *
+	 */	
+    public void testQueryResourceProperties() throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException{
+
+    	//DONE: figure out how to specify a supported dialect.  Start with xpath 1.0 and xpath 2.0
+	  	String dialect1 = "http://www.w3.org/TR/1999/REC-xpath-19991116";
+	  	String dialect2 = "http://www.w3.org/TR/2003/WD-xpath20-20031112";
+	  	
+	  	//test a select all query
+    	String xpathExpression = "*";
+    	XmlObject[] resourceProps = testImpl.queryResourceProperties(xpathExpression,dialect1);
+    	assertNotNull(resourceProps);
+    	assertTrue(resourceProps.length>0);
+
+	  	//test a boolean query
+    	xpathExpression = "boolean(/*/Price=0.99)";
+    	resourceProps = testImpl.queryResourceProperties(xpathExpression,dialect1);
+    	assertNotNull(resourceProps);
+    	assertEquals(1,resourceProps.length);
 
+    	
+    }
 	/**
 	 * Objective: Get the Resource ID of a resource.
 	 * @throws MalformedURLException
@@ -125,23 +181,8 @@
 
 	}
 	
-	/**
-	 * Objective: Request a list of property qnames and make sure it is 
-	 * of the expected length. 
-	 * @throws UnexpectedServerResponseException 
-	 * @throws XmlException 
-	 * @throws IOException 
-	 * @throws URISyntaxException 
-	 * @throws FaultException 
-	 * @throws FaultException 
-	 *
-	 */
-	public void testGetPropertyNames() throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException{
-		QName[] infoArry= testImpl.getPropertyQNames();
-		assertNotNull(infoArry);
-		assertEquals(17,infoArry.length);
-	}
-	
+
+	// DONE: GetMultipleresourceProperties	
 	public void testGetMultipleResourceProperties() throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException{
 		//define list of requested resouces as QName array
 		QName[] requestedResourceProperties = new QName[3];
@@ -152,10 +193,20 @@
 		
 		XmlObject[] resourceArry= testImpl.getMultipleResourceProperties(requestedResourceProperties);
 		assertNotNull(resourceArry);
-		//Which resource properties do we expect back?  
-		//How do we specify which mulitple resource properies to retrieve?
-//		assertEquals(,resourceArry.length);
-	
+		
+		//DONE: test for 3 returned resource properties.
+		assertTrue("Incorrect number of XML fragments returned!",(resourceArry.length==requestedResourceProperties.length));
+			
+		//DONE: check that queried resources are actually returned
+		 String name ="UnitTestResource";
+		 String price = "0.99";
+		 String resId ="rn:0001";
+		 assertTrue("Expected resource not found.",
+				 resourceArry[0].toString().indexOf(name)>-1);
+		 assertTrue("Expected resource not found.",
+				 resourceArry[1].toString().indexOf(price)>-1);
+		 assertTrue("Expected resource not found.",
+				 resourceArry[2].toString().indexOf(resId)>-1);
 	}
 
 	/**
@@ -187,10 +238,203 @@
 	
 	// TODO Support QueryResourceProperties
 	
-	// TODO GetMultipleresourceProperties
+	// TODO Resolve the best way to support getting metrics
 	
 	// TODO Support for setting properties
 	
+
+    //  DONE: Support for setting properties. 
+	/**
+	 * Objective: Query resource properties with an XPath expression using 
+	 * a specific XPath dialect. 
+	 * @throws UnexpectedServerResponseException 
+	 * @throws XmlException 
+	 * @throws IOException 
+	 * @throws URISyntaxException 
+	 * @throws UnexpectedServerResponseException 
+	 * @throws XmlException 
+	 * @throws IOException 
+	 * @throws URISyntaxException 
+	 * @throws FaultException 
+	 * @throws FaultException 
+	 *
+	 */	
+    public void testSetResourceProperties() throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException{
+
+     //UPDATE: BEGIN	
+	  	//test that a simple update operation works.
+	  	 //retrieve an existing property
+	  	 double propValue=testImpl.getPropertyAsDouble(TestResourcePropertyQNames.PRICE);
+	  	 double newVal = (propValue - .2); 
+	  	 //update that property
+	  	   SetPropertiesRequest setRequest =
+	  		 testImpl.createNewSetPropertiesRequest();
+	  	   String[] updates = {String.valueOf(newVal)};
+	  	   setRequest.addUpdateRequest(TestResourcePropertyQNames.PRICE,updates);
+	  	  testImpl.setProperties(setRequest);
+	  	 //make sure that it's changed
+	  		double newValue=testImpl.getPropertyAsDouble(TestResourcePropertyQNames.PRICE);
+	  		assertTrue("Value not successfully updated!",(newValue==newVal));
+	  	 
+	  		//test multiple update values: PRICE & NAME
+	  		double storedValue = newValue;		
+	  		newValue = (propValue - .1);
+	  		String namePropValue=testImpl.getPropertyAsString(TestResourcePropertyQNames.NAME);
+	  		String newValue2 = namePropValue+"-modified";
+	  		SetPropertiesRequest setRequest2 =
+	  			testImpl.createNewSetPropertiesRequest();
+	  		String[] priceUpdate = {String.valueOf(newValue)};
+	  		setRequest2.addUpdateRequest(TestResourcePropertyQNames.PRICE,priceUpdate);
+	  		String[] nameUpdate = {newValue2};
+	  		setRequest2.addUpdateRequest(TestResourcePropertyQNames.NAME,nameUpdate);
+	  		testImpl.setProperties(setRequest2);
+	  		//make sure that the values have changed
+	  		double newPrice=testImpl.getPropertyAsDouble(TestResourcePropertyQNames.PRICE);
+	  		 assertTrue("Value not successfully updated!",(newValue==newPrice));
+	  		String newName=testImpl.getPropertyAsString(TestResourcePropertyQNames.NAME);
+	  		 assertTrue("Value not successfully updated!",(newValue2.equals(newName)));
+
+//	  		//test multiple update values with same QNAME: TestManageability ex. <t:com>val1><t:com>val2>
+//	  	    SetPropertiesRequest setRequest3 =
+//		  		 testImpl.createNewSetPropertiesRequest();
+//		  	String[] tmUpdate = {"0.456", "0.678"};
+//		  	 setRequest3.addUpdateRequest(TestResourcePropertyQNames.TESTMETRIC,tmUpdate);
+//		  	testImpl.setProperties(setRequest3);
+		  	
+//		  	 //make sure that the values have changed
+//		  	XmlObject[] vals=testImpl.getMultipleResourceProperties(new QName[]{TestResourcePropertyQNames.TESTMETRIC});
+//			assertTrue("Value not successfully updated!",(2==vals.length));
+			
+	 //UPDATE: END
+	 
+     //INSERT: BEGIN	  		
+	  			  	 
+	  //test that insert works
+		//insert a new TestMetric into the document
+	  	 //create it
+	   SetPropertiesRequest tmpRequest =
+  		 testImpl.createNewSetPropertiesRequest();
+	   double tstMetVal = 3.4;
+  	   String[] total = {""+tstMetVal};
+	   tmpRequest.addInsertRequest(TestResourcePropertyQNames.TESTMETRIC,total);  	     
+	   testImpl.setProperties(tmpRequest);
+	  	//verify it
+	  	 //make sure that it's changed
+	   QName[] mResReq = new QName[1]; mResReq[0]=TestResourcePropertyQNames.TESTMETRIC;
+	   XmlObject[] val=testImpl.getMultipleResourceProperties(mResReq);
+	   assertEquals("Value not successfully updated!",3,val.length);
+	    //parse response to ensure that value is included
+	    boolean exists = false;
+	    for (int i = 0; i < val.length; i++) {
+			XmlObject obj = val[i];
+			if(obj.toString().indexOf(tstMetVal+"")>-1){
+			   exists =true;	
+			}
+		}
+	    assertTrue("Value not successfully found!",exists);
+	   
+   	String xpathExpression = "*";
+	XmlObject[] resourceProps = testImpl.queryResourceProperties(xpathExpression,dialect1);
+	   
+	//	INSERT: END
+	// DELETE: BEGIN
+		  tmpRequest = testImpl.createNewSetPropertiesRequest();
+		   tmpRequest.addDeleteRequest(TestResourcePropertyQNames.MANAGEABILITYCAPABILITY);
+		   testImpl.setProperties(tmpRequest);
+		   //test to see that the property no longer exists
+		   resourceProps = testImpl.queryResourceProperties(xpathExpression,dialect1);
+		   try{
+			   newValue=testImpl.getPropertyAsDouble(TestResourcePropertyQNames.MANAGEABILITYCAPABILITY);
+			   fail("Query for non-existant resource passed!");
+		   }catch(Exception ex){
+			  //swallow exception 
+		   }
+	
+	// DELETE: END
+		   
+	//MULTIPLE SET REQUEST: BEGIN	   
+	  	//now carry out update, delete and insert in one call.
+	  	 //verify that those values were successfully changed.
+ 	 //temp check that messages built properly
+	 tmpRequest = testImpl.createNewSetPropertiesRequest();
+       newVal = newVal - .01; 
+	    String[] multSetUpdate = {String.valueOf(newVal)};
+	   String newInst ="http://docs.oasis-open.org/wsdm/2004/12/muws/capabilities/Identity";
+	    String[] multSetInsert = {newInst,"NewTestInsert"};
+	   tmpRequest.addUpdateRequest(TestResourcePropertyQNames.PRICE,multSetUpdate);
+	   tmpRequest.addInsertRequest(TestResourcePropertyQNames.MANAGEABILITYCAPABILITY,multSetInsert);
+	   //then delete the same ones just inserted. Should work as order matters.
+	   tmpRequest.addDeleteRequest(TestResourcePropertyQNames.MANAGEABILITYCAPABILITY);
+	   
+	  //now make the request 
+	  testImpl.setProperties(tmpRequest);
+	  //carry out quick visual test	
+	   //test to see that the property no longer exists
+	   resourceProps = testImpl.queryResourceProperties(xpathExpression,dialect1);
+	   //TODO: insert logic to test contents
+	//MULTIPLE SET REQUEST: END  	
+    	
+    }    
+	
+	// TODO Calling Operations on Resources
+	
+	// TODO Next try the create and destroys.
+	
+	// TODO Notifications
+	
+    //TODO: getResourcePropertyDocument
+    /**
+     * Objective: Request a list of property qnames and make sure it is 
+     * of the expected length. 
+     * @throws UnexpectedServerResponseException 
+     * @throws XmlException 
+     * @throws IOException 
+     * @throws URISyntaxException 
+     * @throws FaultException 
+     *
+     */
+//    public void NotImplemented_testGetResourcePropertyDocument() throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException{
+//    	XmlObject resPropDoc= testImpl.getResourcePropertyDocument();
+//    	assertNotNull(resPropDoc);
+//    	//TODO: test content returned
+////  	assertEquals(1,resPropDoc.length);
+//    }
+
+    //TODO: testQueryExpressionDialect
+	/**
+	 * Objective: Request a list of property qnames and make sure it is 
+	 * of the expected length. 
+	 * @throws UnexpectedServerResponseException 
+	 * @throws XmlException 
+	 * @throws IOException 
+	 * @throws URISyntaxException 
+	 * @throws FaultException 
+	 * @throws UnexpectedServerResponseException 
+	 * @throws XmlException 
+	 * @throws IOException 
+	 * @throws URISyntaxException 
+	 * @throws FaultException 
+	 *
+	 */
+//	public void testQueryExpressionDialect() throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException{
+////		XmlObject resPropDoc= testImpl.queryExpressionDialect();
+////		assertNotNull(resPropDoc);
+//		//TODO: test content returned
+////		assertEquals(1,resPropDoc.length);
+//	}
+    
+    public void testUpdateProperty() throws FaultException, URISyntaxException, IOException, XmlException, UnexpectedServerResponseException{
+	  	//test that a simple update operation works.
+	  	 //retrieve an existing property
+	  	 double propValue=testImpl.getPropertyAsDouble(TestResourcePropertyQNames.PRICE);
+	  	 double newVal = (propValue - .2); 
+	  	 //update that property
+	  	  testImpl.updateProperty(TestResourcePropertyQNames.PRICE,newVal);
+	  	 //make sure that it's changed
+	  		double newValue=testImpl.getPropertyAsDouble(TestResourcePropertyQNames.PRICE);
+	  		assertTrue("Value not successfully updated!",(newValue==newVal));
+    	
+    }
 	// TODO Calling Operations on Resources
 	
 	// TODO Next try the create and destroys.