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/10/06 18:10:08 UTC
svn commit: r306795 - in
/webservices/muse/trunk/client/src/test/org/apache/ws/client/muse/client/impl/lifetime:
./ LifetimeEnabledResourceImplTest.java
Author: wire
Date: Thu Oct 6 09:10:06 2005
New Revision: 306795
URL: http://svn.apache.org/viewcvs?rev=306795&view=rev
Log:
-adding tests for ResourceLifeTime.
Added:
webservices/muse/trunk/client/src/test/org/apache/ws/client/muse/client/impl/lifetime/
webservices/muse/trunk/client/src/test/org/apache/ws/client/muse/client/impl/lifetime/LifetimeEnabledResourceImplTest.java
Added: webservices/muse/trunk/client/src/test/org/apache/ws/client/muse/client/impl/lifetime/LifetimeEnabledResourceImplTest.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/client/src/test/org/apache/ws/client/muse/client/impl/lifetime/LifetimeEnabledResourceImplTest.java?rev=306795&view=auto
==============================================================================
--- webservices/muse/trunk/client/src/test/org/apache/ws/client/muse/client/impl/lifetime/LifetimeEnabledResourceImplTest.java (added)
+++ webservices/muse/trunk/client/src/test/org/apache/ws/client/muse/client/impl/lifetime/LifetimeEnabledResourceImplTest.java Thu Oct 6 09:10:06 2005
@@ -0,0 +1,118 @@
+/*=============================================================================*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *=============================================================================
+ */
+package org.apache.ws.client.muse.client.impl.lifetime;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Calendar;
+
+//import org.apache.ws.client.muse.client.impl.ManageableResourceImpl;
+import org.apache.ws.client.muse.client.impl.exceptions.FaultException;
+import org.apache.ws.client.muse.client.impl.exceptions.UnexpectedServerResponseException;
+import org.apache.ws.service.testresource.TestResourcePropertyQNames;
+import org.apache.ws.util.test.axis.MuseClientTestCase;
+import org.apache.xmlbeans.XmlDateTime;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
+
+public class LifetimeEnabledResourceImplTest extends MuseClientTestCase {
+
+ private static String id="0001";
+ private String eprTxt;
+ private URL testAddress;
+ private LifetimeEnabledResourceImpl testImpl;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.testAddress=new URL(getAxisBaseUrl().toExternalForm()+"TestResource");
+ this.eprTxt = eprFromAddessandId(this.testAddress.toString(),id);
+ this.testImpl = new LifetimeEnabledResourceImpl(eprTxt);
+
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ this.testAddress = null;
+ this.eprTxt = null;
+ this.testImpl = null;
+ }
+
+ //TODO: remove A so that test can be run routinely after refactor for fresh axis each time
+ public void AtestResourceLifetimeImmediateDestroy() throws FaultException, URISyntaxException, IOException, XmlException, UnexpectedServerResponseException{
+ //Test immediate destroy capability
+ //make simple call to ensure that resource does exist
+ String propValue=String.valueOf(testImpl.getPropertyAsDouble(TestResourcePropertyQNames.PRICE));
+ assertNotNull(propValue);
+ assertTrue(propValue.length()>0);
+
+ //call for immediate destroy on it
+ testImpl.destroyResourceImmediately();
+ //check to see whether destroy worked
+ try{
+ propValue=String.valueOf(testImpl.getPropertyAsDouble(TestResourcePropertyQNames.PRICE));
+ fail("Resource was not successfully destroyed!");
+ }catch(FaultException exc){
+ }
+ }
+
+ public void AtestResourceLifetimeScheduledDestroy() throws URISyntaxException, IOException, XmlException, UnexpectedServerResponseException, FaultException{
+ //Before scheduling destruction .. test out CurrentTime and TerminationTime resource props
+ //query current time
+ String currentTime = testImpl.getCurrentTimeAsString(TestResourcePropertyQNames.CURRENTTIME2);
+ assertNotNull(currentTime);
+ assertTrue("Current time not returned!",(currentTime.trim().length()>0));
+ //query TerminationTime to see that it is not set yet.
+ String terminationTime = testImpl.getTerminationTimeAsString(TestResourcePropertyQNames.TERMINATIONTIME);
+ assertNull(terminationTime);
+
+ //Build timed death request and send it
+ XmlDateTime curTime = testImpl.getCurrentTime(TestResourcePropertyQNames.CURRENTTIME2);
+ long secondsFromNow = 20;
+ //set Time of Death
+ long current = curTime.getCalendarValue().getTimeInMillis();
+ curTime.getCalendarValue().setTimeInMillis(current+(secondsFromNow*1000));
+ //build new XmlDateTime to schedule TOD
+ XmlDateTime tod = XmlDateTime.Factory.newInstance();
+ Calendar instance = Calendar.getInstance();
+ instance.setTimeInMillis(current+(secondsFromNow*1000));
+ tod.setCalendarValue(instance);
+
+ //issue the Scheduled death request
+ XmlObject[] response = testImpl.setTerminationTime(tod);
+
+ //check that normal requests still work
+ testImpl.getCurrentTimeAsString(TestResourcePropertyQNames.CURRENTTIME2);
+
+ //wait for time to pass ..
+ Thread unit_test_thread=Thread.currentThread();
+ synchronized (unit_test_thread) {
+ try {
+ //Set sufficient time for destroy to occur. Add 1 minute buffer
+ unit_test_thread.wait((secondsFromNow+60)*1000);
+ } catch (InterruptedException e) {
+ }
+ }
+
+ // verify that it's dead.
+ try{
+ testImpl.getCurrentTimeAsString(TestResourcePropertyQNames.CURRENTTIME2);
+ fail("Resource was not successfully destroyed after set time!");
+ }catch(FaultException fex){
+ }
+ }
+}