CVS: Tapestry/junit/src/net/sf/tapestry/junit/mock TestPersistentProperties.xml,NONE,1.1.2.1 AttributeHolder.java,1.4,1.4.2.1 MockTester.java,1.8.2.6,1.8.2.7 MockTestCase.java,1.10.2.12,1.10.2.13 MockRequest.java,1.3.2.1,1.3.2.2

Howard Lewis Ship <[email protected]>
Newsgroups gmane.comp.java.tapestry.cvs
Message-ID <[email protected]>
Update of /cvsroot/tapestry/Tapestry/junit/src/net/sf/tapestry/junit/mock
In directory sc8-pr-cvs1:/tmp/cvs-serv9155/junit/src/net/sf/tapestry/junit/mock

Modified Files:
      Tag: hship-2-3
	AttributeHolder.java MockTester.java MockTestCase.java 
	MockRequest.java 
Added Files:
      Tag: hship-2-3
	TestPersistentProperties.xml 
Log Message:
Automatically register components as page listeners if they implement necessary interfaces
Major rework on page property persistance
[ 653358 ] IPage.getName() == qualified name
[ 608768 ] Changes saved AFTER IPage.detach()

--- NEW FILE: TestPersistentProperties.xml ---
<?xml version="1.0" encoding="UTF-8"?>

<!-- $Id: TestPersistentProperties.xml,v 1.1.2.1 2002/12/30 03:04:57 hship Exp $ -->

<mock-test>
    <context name="c6" root="context6"/>

  	<servlet name="app" class="net.sf.tapestry.ApplicationServlet"/>
       
    <request>
 		
 		<assert-output name="Page Title">
<![CDATA[
<title>Peristant Page Property</title>
]]> 		
 		</assert-output>
 		
 		<assert-output name="Initial Message">
Message: Hello
 		</assert-output>
 		
 		<assert-output name="Initial Active Page Names">
Active page names: [] 		
		</assert-output>
			
		<assert-output name="Change Message Link">
<![CDATA[		
/c6/app?service=direct&amp;context=0/Home/$DirectLink		
]]>
		</assert-output>				
		
		<assert-expression name="Check No Session"
			expression="request.session == null"/>
 	</request>
			
	<!-- Now, trigger the link. -->
	
	<request>
		<parameter name="service" value="direct"/>
		<parameter name="context" value="0/Home/$DirectLink"/>
		
 		<assert-output name="Page Title">
<![CDATA[
<title>Peristant Page Property</title>
]]> 		
 		</assert-output>
 		
 		<assert-output name="Changed Message">
Message: Changed
 		</assert-output>
 		
 		<assert-output name="Active Page Names">
Active page names: [Home] 		
		</assert-output>
								
		<assert name="Session Attribute"
			expression='request.session.getAttribute("app/Home/message").equals("Changed")'
			/>				
	</request>
	
	<!-- Return to the page, check for the change.  -->
	
	<request>
 		<assert-output name="Page Title">
<![CDATA[
<title>Peristant Page Property</title>
]]> 		
 		</assert-output>
 		
 		<assert-output name="Changed Message">
Message: Changed
 		</assert-output>
 		
 		<assert-output name="Active Page Names">
Active page names: [Home] 		
		</assert-output>
	</request>
	
	<!-- Simulate a failover. -->
	
	<request failover="true">		
 		<assert-output name="Page Title">
<![CDATA[
<title>Peristant Page Property</title>
]]> 		
 		</assert-output>
 		
 		<assert-output name="Changed Message">
Message: Changed
 		</assert-output>
 		
 		<assert-output name="Active Page Names">
Active page names: [Home] 		
		</assert-output>
	</request>
				
	<!-- Now try page "Two", with the Nested component. -->
	
	<request>
		<parameter name="service" value="page"/>
		<parameter name="context" value="Two"/>

 		<assert-output name="Page Title">
<![CDATA[
<title>Peristant Component Property</title>
]]> 		
 		</assert-output>
 		
 		<assert-output name="Initial Nested Message">
Nested Message: Nested
 		</assert-output>
 		
 		<assert-output name="Initial Active Page Names">
Active page names: [Home] 		
		</assert-output>
			
		<assert-output name="Change Message Link">
<![CDATA[		
/c6/app?service=direct&amp;context=1/Two/$Nested.$DirectLink		
]]>
		</assert-output>				

	</request>		
		
	<!-- Trigger the link in the nested component. -->
	
	<request>
		<parameter name="service" value="direct"/>
		<parameter name="context" value="1/Two/$Nested.$DirectLink"/>
		
 		<assert-output name="Page Title">
<![CDATA[
<title>Peristant Component Property</title>
]]> 		
 		</assert-output>
 		
 		<assert-output name="Changed Nested Message">
Nested Message: Changed
 		</assert-output>
 		
 		<!-- This is going to be a little pain because we can't count on the
 		 	 ordering!  May need to put some kind of sort filter in place in the
 		 	 presentation.  -->
 		 	 
 		<assert-output name="Changed Active Page Names">
Active page names: [Home, Two] 		
		</assert-output>				
		
		<assert name="Session Attribute"
			expression='request.session.getAttribute("app/Two/$Nested/message").equals("Changed")'
			/>				
					
	</request>
	
	<!-- Check that it works on a revisit. -->
	
	<request>
		<parameter name="service" value="page"/>
		<parameter name="context" value="Two"/>
		
 		<assert-output name="Page Title">
<![CDATA[
<title>Peristant Component Property</title>
]]> 		
 		</assert-output>
 		
 		<assert-output name="Changed Active Page Names">
Active page names: [Home, Two] 		
		</assert-output>	
		 		
 		<assert-output name="Changed Nested Message">
Nested Message: Changed
 		</assert-output>
	</request>
		
	<!-- Check that it works after a failover. -->
	
	<request failover="true">
		<parameter name="service" value="page"/>
		<parameter name="context" value="Two"/>
		
 		<assert-output name="Page Title">
<![CDATA[
<title>Peristant Component Property</title>
]]> 		
 		</assert-output>
 		
 		<assert-output name="Changed Active Page Names">
Active page names: [Home, Two] 		
		</assert-output>	
		 		
 		<assert-output name="Changed Nested Message">
Nested Message: Changed
 		</assert-output>
	</request>	
	
	<!-- Now on to page Three, where we test EJBs. -->
	
	<request>
		<parameter name="service" value="page"/>
		<parameter name="context" value="Three"/>
		
 		<assert-output name="Page Title">
<![CDATA[
<title>Peristant EJB Property</title>
]]> 		
 		</assert-output>	
 		
		<assert-output name="EJB Initial Value">
EJB is null
		</assert-output>
		
		<assert-output name="Create link">
<![CDATA[
/c6/app?service=direct&amp;context=1/Three/$DirectLink
]]>		
		</assert-output>		 			
				
	</request>
	
	<!-- Trigger the link. -->
	
	<request>
		<parameter name="service" value="direct"/>
		<parameter name="context" value="1/Three/$DirectLink"/>

 		<assert-output name="Page Title">
<![CDATA[
<title>Peristant EJB Property</title>
]]> 		
 		</assert-output>
 				

		<assert-output name="Updated EJB Value">
EJB is FakeEJBObject[997]
		</assert-output>			
				
		<assert 
			name="Stored Value"
			expression='request.session.getAttribute("app/Three/ejb").getClass().getName().equals("net.sf.tapestry.record.EJBWrapper")'/>
		
	</request>
	
	<!-- Now, pretend a failover. -->
	
	<request failover="true">
		<parameter name="service" value="page"/>
		<parameter name="context" value="Three"/>
					
 		<assert-output name="Page Title">
<![CDATA[
<title>Peristant EJB Property</title>
]]> 		
 		</assert-output>
 				

		<assert-output name="Updated EJB Value">
EJB is FakeEJBObject[997]
		</assert-output>			
				
		<assert-output name="Discard URL">
<![CDATA[
/c6/app?service=direct&amp;context=1/Three/$DirectLink_0
]]>
		</assert-output>
								
	</request>		
	
	<!-- Trigger the discard link. -->
	
	<request>
		<parameter name="service" value="direct"/>
		<parameter name="context" value="1/Three/$DirectLink_0"/>
		
 		<assert-output name="Page Title">
<![CDATA[
<title>Peristant EJB Property</title>
]]> 		
 		</assert-output>

		<!-- Doesn't update the current state of the page! --> 				

		<assert-output name="Updated EJB Value">
EJB is FakeEJBObject[997]
		</assert-output>		
		
		<assert 
			name="Attribute missing."
			expression='request.session.getAttribute("app/Three/ejb") == null'/>
	</request>
			
	<!-- Check that the value is now gone. -->
	
	<request>
		<parameter name="service" value="page"/>
		<parameter name="context" value="Three"/>
		
 		<assert-output name="Page Title">
<![CDATA[
<title>Peristant EJB Property</title>
]]> 		
 		</assert-output>	
 		
		<assert-output name="EJB Value back to null">
EJB is null
		</assert-output>
					
	</request>
				
	<!-- Now, test that all sorts of variations on fireObservedChange() work with
	     different overloaded types. -->
	     
	<request>
		<parameter name="service" value="page"/>
		<parameter name="context" value="Four"/>
		
 		<assert-output name="Page Title">
<![CDATA[
<title>Property Types</title>
]]> 		
 		</assert-output>	
 		
 		 <assert-output name="Boolean">
Boolean value: false		
 		</assert-output>
 		
 		<assert-output name="Char">
Char value: [ ]
		</assert-output>
		
 		 <assert-output name="Byte">
Byte value: 0		
 		</assert-output>
 		
 		 <assert-output name="Short">
Short value: 0		
 		</assert-output>
 		
 		 <assert-output name="Long">
Long value: 0		
 		</assert-output>
 		
 		 <assert-output name="Float">
Float value: 0.0		
 		</assert-output>
 		
 		 <assert-output name="Double">
Double value: 0.0	
 		</assert-output>
 		
 		<assert-output name="Create Link">
<![CDATA[
/c6/app?service=direct&amp;context=1/Four/$DirectLink
]]>	
		</assert-output>
		
 	</request>			     									
 	
 	
 	<!-- Trigger the link to create values. -->
 	
 	<request>
 		<parameter name="service" value="direct"/>
 		<parameter name="context" value="1/Four/$DirectLink"/>
 		
 		<assert-output name="Page Title">
<![CDATA[
<title>Property Types</title>
]]> 		
 		</assert-output>	
 		
 		 <assert-output name="Boolean">
Boolean value: true
 		</assert-output>
 		
 		<assert-output name="Char">
Char value: [H]
		</assert-output>
		
 		 <assert-output name="Byte">
Byte value: 27
 		</assert-output>
 				
 		 <assert-output name="Short">
Short value: 127
 		</assert-output>
 		
 		 <assert-output name="Long">
Long value: 1234567890123		
 		</assert-output>
 		
 		 <assert-output name="Float">
Float value: -1.5		
 		</assert-output>
 		
 		 <assert-output name="Double">
Double value: 3.142857142857143	
 		</assert-output>

	</request>
	
	<!-- And return to ensure that values are properly restored. -->
	
	<request failover="true">
		<parameter name="service" value="page"/>
		<parameter name="context" value="Four"/>
		
 		 <assert-output name="Boolean">
Boolean value: true
 		</assert-output>
 		
 		<assert-output name="Char">
Char value: [H]
		</assert-output>
		
 		 <assert-output name="Byte">
Byte value: 27
 		</assert-output>
 				
 		 <assert-output name="Short">
Short value: 127
 		</assert-output>
 		
 		 <assert-output name="Long">
Long value: 1234567890123		
 		</assert-output>
 		
 		 <assert-output name="Float">
Float value: -1.5		
 		</assert-output>
 		
 		 <assert-output name="Double">
Double value: 3.142857142857143	
 		</assert-output>		
	</request>
	
</mock-test>
    	

Index: AttributeHolder.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/junit/src/net/sf/tapestry/junit/mock/AttributeHolder.java,v
retrieving revision 1.4
retrieving revision 1.4.2.1
diff -C2 -d -r1.4 -r1.4.2.1
*** AttributeHolder.java	27 Nov 2002 17:58:52 -0000	1.4
--- AttributeHolder.java	30 Dec 2002 03:04:57 -0000	1.4.2.1
***************
*** 1,5 ****
--- 1,10 ----
  package net.sf.tapestry.junit.mock;
  
+ import java.io.ByteArrayInputStream;
+ import java.io.ByteArrayOutputStream;
+ import java.io.IOException;
  import java.io.InputStream;
+ import java.io.ObjectInputStream;
+ import java.io.ObjectOutputStream;
  import java.net.MalformedURLException;
  import java.net.URL;
***************
*** 11,14 ****
--- 16,21 ----
  import javax.servlet.ServletException;
  
+ import net.sf.tapestry.ApplicationRuntimeException;
+ 
  /**
   *  
***************
*** 27,31 ****
  {
      private Map _attributes = new HashMap();
!     
      public Object getAttribute(String name)
      {
--- 34,38 ----
  {
      private Map _attributes = new HashMap();
! 
      public Object getAttribute(String name)
      {
***************
*** 33,37 ****
      }
  
- 
      public Enumeration getAttributeNames()
      {
--- 40,43 ----
***************
*** 48,55 ****
          Set keys = _attributes.keySet();
          int count = keys.size();
!         
          String[] array = new String[count];
!         
!         return (String[])keys.toArray(array);
      }
  
--- 54,61 ----
          Set keys = _attributes.keySet();
          int count = keys.size();
! 
          String[] array = new String[count];
! 
!         return (String[]) keys.toArray(array);
      }
  
***************
*** 59,63 ****
      }
  
- 
      public void removeAttribute(String name)
      {
--- 65,68 ----
***************
*** 65,67 ****
--- 70,124 ----
      }
  
+     /**
+      *  Serializes and then deserializes the {@link Map}
+      *  containing all attributes.
+      * 
+      **/
+ 
+     public void simulateFailover()
+     {
+         byte[] serialized = serializeAttributes();
+         
+         _attributes = null;
+         
+         Map restoredAttributes = deserializeAttributes(serialized);
+         
+         _attributes = restoredAttributes;
+     }
+ 
+     private byte[] serializeAttributes()
+     {
+         try
+         {
+             ByteArrayOutputStream bos = new ByteArrayOutputStream();
+             ObjectOutputStream oos = new ObjectOutputStream(bos);
+ 
+             oos.writeObject(_attributes);
+ 
+             oos.close();
+ 
+             return bos.toByteArray();
+         }
+         catch (IOException ex)
+         {
+             throw new ApplicationRuntimeException("Unable to serialize attributes.", ex);
+         }
+     }
+ 
+     private Map deserializeAttributes(byte[] serialized)
+     {
+         try
+         {
+             ByteArrayInputStream bis = new ByteArrayInputStream(serialized);
+             ObjectInputStream ois = new ObjectInputStream(bis);
+ 
+             Map result = (Map) ois.readObject();
+ 
+             return result;
+         }
+         catch (Exception ex)
+         {
+             throw new ApplicationRuntimeException("Unable to deserialize attributes.", ex);
+         }
+     }
  }

Index: MockTester.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/junit/src/net/sf/tapestry/junit/mock/MockTester.java,v
retrieving revision 1.8.2.6
retrieving revision 1.8.2.7
diff -C2 -d -r1.8.2.6 -r1.8.2.7
*** MockTester.java	11 Dec 2002 14:02:25 -0000	1.8.2.6
--- MockTester.java	30 Dec 2002 03:04:57 -0000	1.8.2.7
***************
*** 244,247 ****
--- 244,252 ----
          }
  
+         String failover = request.getAttributeValue("failover");
+         
+         if (failover != null && failover.equals("true"))
+             _request.simulateFailover();
+ 
          // TBD: Headers, etc., etc.
      }

Index: MockTestCase.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/junit/src/net/sf/tapestry/junit/mock/MockTestCase.java,v
retrieving revision 1.10.2.12
retrieving revision 1.10.2.13
diff -C2 -d -r1.10.2.12 -r1.10.2.13
*** MockTestCase.java	21 Dec 2002 13:05:46 -0000	1.10.2.12
--- MockTestCase.java	30 Dec 2002 03:04:57 -0000	1.10.2.13
***************
*** 42,45 ****
--- 42,51 ----
  
  
+     public void testPersistentProperties()
+     throws Exception
+     {
+         attempt("TestPersistentProperties.xml");
+     }
+ 
      /**
       *  Test several Stale Link scenarios for the Form component.

Index: MockRequest.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/junit/src/net/sf/tapestry/junit/mock/MockRequest.java,v
retrieving revision 1.3.2.1
retrieving revision 1.3.2.2
diff -C2 -d -r1.3.2.1 -r1.3.2.2
*** MockRequest.java	2 Dec 2002 22:37:38 -0000	1.3.2.1
--- MockRequest.java	30 Dec 2002 03:04:57 -0000	1.3.2.2
***************
*** 347,349 ****
--- 347,361 ----
              addCookie(cookies[i]);
      }
+     
+     /**
+      *  Delegates this to the {@link net.sf.tapestry.junit.mock.MockSession}, if
+      *  it exists.
+      * 
+      **/
+     
+     public void simulateFailover()
+     {
+         if (_session != null)
+             _session.simulateFailover();
+     }
  }



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.