Please replace MessageUtilsTest with the attached file or try to apply the patch or change MockFacesContext to FacesContext in MessageUtilsTest

Bernd

Sean Schofield schrieb:
MessageUtilsTest fails b/c it cannot find MockFacesContext.  I have
already renamed one of the files for you in svn.  I will commit the
rest for you tomorrow when you send me the file.  Then you should be
able to commit your own stuff once Manfred grants you the karma!

Sean

ps. Thanks for all of this great Maven work!

On 1/11/06, Bernd Bohmann <[EMAIL PROTECTED]> wrote:

I will send you my patches for fixing the tests first

Please rename impl/src/test/java/org/apache/myfaces/el/TestBean.java

to DummyBean.java

see surefire-plugin documentation.

Please delete StateUtilsTestCase and add StateUtilsAbstractCase
or rename StateUtilsTestCase to StateUtilsAbstractCase and replace it
with the attached file.

I'm not sure that I send you all required patches.

Please test it.

Tomorrow I will send you the patches for the tlddoc(and the assembly
stuff). Preparing the patches takes some more time :-(

Best Regards

Bernd

Sean Schofield schrieb:

That's great!  Do you have a patch for me?

Sean

On 1/11/06, Bernd Bohmann <[EMAIL PROTECTED]> wrote:


Hello Sean,

I have deployed the site with javadoc and tlddoc on
http://people.apache.org/~bommel/

You find the tlddoc report under 'Project Reports' on the site of the
project pages.

Regards


Bernd

Bernd Bohmann schrieb:


Hello Sean

I fixed the other tests except two test cases.
Should I open an issue or send you the patches?




OK this is fixed.  I thought it sounded familiar and it was.  I had
already fixed one issue with MessageUtilsTest by copying the
Message.properties over to a new test/resources dir.  It turns out
that the rest of the properties are needed as well so I copied them
over too.


Is a copy of properties a good idea or should the properties moved to
commons/src/main/resources ?




Sean


Regards

Bernd



--
Dipl.-Ing. Bernd Bohmann - Atanion GmbH - Software Development
Bismarckstr. 13, 26122 Oldenburg, http://www.atanion.com
phone: +49 441 4082312, mobile: +49 173 8839471, fax: +49 441 4082333



--
Dipl.-Ing. Bernd Bohmann - Atanion GmbH - Software Development
Bismarckstr. 13, 26122 Oldenburg, http://www.atanion.com
phone: +49 441 4082312, mobile: +49 173 8839471, fax: +49 441 4082333






--
Dipl.-Ing. Bernd Bohmann - Atanion GmbH - Software Development
Bismarckstr. 13, 26122 Oldenburg, http://www.atanion.com
phone: +49 441 4082312, mobile: +49 173 8839471, fax: +49 441 4082333
Index: src/test/java/org/apache/myfaces/util/StateUtilsAbstractCase.java
===================================================================
--- src/test/java/org/apache/myfaces/util/StateUtilsAbstractCase.java	(Revision 368304)
+++ src/test/java/org/apache/myfaces/util/StateUtilsAbstractCase.java	(Arbeitskopie)
@@ -1,193 +1,179 @@
-package org.apache.myfaces.util;
-
-/** 
- * This TestCase is not meant to be run, it's children are.  It is 
- * nevertheless concrete because it creates instances of itself
- * for testing.  Running this TestCase directly will blow up.
- * 
- * @author Dennis C. Byrne
- */
-
-import java.io.Serializable;
-import java.util.Arrays;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import junit.framework.TestCase;
-
-public class StateUtilsTestCase extends TestCase implements Serializable{
-	private static final Log log = LogFactory.getLog(StateUtilsTestCase.class);
-	protected String sensitiveString;
-	private static final String TEST_DATA = "This is the test data.";
-	private String dummy ;
-	// 76543210
-	public static final String BASE64_KEY_SIZE_8 = "NzY1NDMyMTA=";
-	// 7654321076543210
-	public static final String BASE64_KEY_SIZE_16 = "NzY1NDMyMTA3NjU0MzIxMA==";
-	// 012345678901234567890123
-	public static final String BASE64_KEY_SIZE_24 = "MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIz";
-
-	public String getDummy() {
-		return dummy;
-	}
-
-	public void setDummy(String dummy) {
-		this.dummy = dummy;
-	}
-
-	protected void setUp() throws Exception {
-		sensitiveString = "this is my secret";
-	}
-
-	protected void tearDown() throws Exception {
-		sensitiveString = null;
-	}
-
-	/**
-	 * Test for Restore View phase.
-	 */
-
-	public void testConstructionString(){
-		String constructed = StateUtils.construct(sensitiveString); 
-		Object object = StateUtils.reconstruct(constructed);
-		assertTrue(object instanceof String);
-		String string = (String)object;
-		string.equals(sensitiveString);
-	}
-
-	/**
-	 * Test for Restore View phase.  This method actually runs an instance of
-	 * StateUtilsTestCase through the construct/reconstruct process. 
-	 */	
-	
-	public void testConstruction(){
-		StateUtilsTestCase sutc = new StateUtilsTestCase();
-		sutc.setDummy(TEST_DATA);
-		String constructed = StateUtils.construct(sutc); 
-		Object object = StateUtils.reconstruct(constructed);
-		assertTrue(sutc.equals(object));
-	}
-	
-	public void testSerialization(){
-		StateUtilsTestCase sutc = new StateUtilsTestCase();
-		sutc.setDummy(TEST_DATA);
-		byte[] bytes = StateUtils.getAsByteArray(sutc);
-		Object object = StateUtils.getAsObject(bytes);
-		assertTrue(sutc.equals(object));
-	}
-	
-	public void testCryptography(){
-		byte[] sensitiveBytes = sensitiveString.getBytes();
-		byte[] secure = StateUtils.encrypt(sensitiveBytes);
-		byte[] insecure = StateUtils.decrypt(secure);
-		secure = StateUtils.encrypt(insecure); // * 2
-		insecure = StateUtils.decrypt(secure);
-		assertTrue(Arrays.equals(insecure, sensitiveBytes));
-	}
-	
-	public void testCompression(){
-		int size = 2049;
-		byte[] orginalBytes = new byte[size];
-		byte[] lessBytes = StateUtils.compress(orginalBytes);
-		assertTrue(lessBytes.length < orginalBytes.length);
-		byte[] moreBytes = StateUtils.decompress(lessBytes);
-		assertTrue(moreBytes.length > lessBytes.length);
-		assertTrue(Arrays.equals(moreBytes, orginalBytes));
-	}
-
-	public void testEncoding(){
-		byte[] orginalBytes = sensitiveString.getBytes();
-		byte[] encoded = StateUtils.encode(orginalBytes);
-		byte[] decoded = StateUtils.decode(encoded);
-		assertTrue(Arrays.equals(decoded, orginalBytes));
-	}
-	
-	/**
-	 * Simulates testConstruction w/ corrupt data.
-	 */
-	
-	public void testConstructionNegative(){
-		StateUtilsTestCase sutc = new StateUtilsTestCase();
-		sutc.setDummy(TEST_DATA);
-		String constructed = StateUtils.construct(sutc);
-		constructed = constructed.substring(1, constructed.length());
-		Object object = null;
-		try{
-			object = StateUtils.reconstruct(constructed);
-			assertFalse(sutc.equals(object));
-		}catch(Exception e){}
-	}
-	
-	/**
-	 * Simulates testSerialization w/ corrput data.
-	 */
-	
-	public void testSerializationNegative(){
-		StateUtilsTestCase sutc = new StateUtilsTestCase();
-		sutc.setDummy(TEST_DATA);
-		byte[] bytes = StateUtils.getAsByteArray(sutc);
-		bytes[1] = (byte)3;
-		try{
-			Object object = StateUtils.getAsObject(bytes);
-			assertFalse(sutc.equals(object));
-		}catch(Exception e){}
-	}
-	
-	/**
-	 * Simulates testCryptography w/ corrupt data.
-	 */
-	
-	public void testCryptographyNegative(){
-		byte[] sensitiveBytes = sensitiveString.getBytes();
-		byte[] secure = StateUtils.encrypt(sensitiveBytes);
-		secure[3] = (byte)1;
-		try{
-			byte[] insecure = StateUtils.decrypt(secure);
-			assertFalse(Arrays.equals(insecure, sensitiveBytes));
-		}catch(Exception e){}		
-	}
-
-	/**
-	 * Simulates testCompression w/ corrupt data.
-	 */
-	
-	public void testCompressionNegative(){
-		int size = 2049;
-		byte[] orginalBytes = new byte[size];
-		byte[] lessBytes = StateUtils.compress(orginalBytes);
-		lessBytes[1] = (byte)3;
-		try{
-			byte[] moreBytes = StateUtils.decompress(lessBytes);
-			assertFalse(Arrays.equals(moreBytes, orginalBytes));
-		}catch(Exception e){}
-	}	
-	
-	/**
-	 * Simulates testEncoding w/ corrupt data.
-	 */
-	
-	public void testEncodingNegative(){
-		byte[] orginalBytes = sensitiveString.getBytes();
-		byte[] encoded = StateUtils.encode(orginalBytes);
-		encoded[1] = (byte)9;
-		try{
-			byte[] decoded = StateUtils.decode(encoded);
-			assertFalse(Arrays.equals(decoded, orginalBytes));
-		}catch(Exception e){}
-	}
-	
-	public boolean equals(Object object) {
-		if(object == null)
-			return false;
-		if(object == this)
-			return true;
-		if(object instanceof StateUtilsTestCase){
-			StateUtilsTestCase other = (StateUtilsTestCase)object;
-			return other.getDummy().equals(this.getDummy());
-		}else{
-			return false;
-		}
-	}
-	
-}
+package org.apache.myfaces.util;
+
+/** 
+ * This TestCase is not meant to be run, it's children are.  It is 
+ * nevertheless concrete because it creates instances of itself
+ * for testing.  Running this TestCase directly will blow up.
+ * 
+ * @author Dennis C. Byrne
+ */
+
+import java.io.Serializable;
+import java.util.Arrays;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.test.FacesContextHelper;
+
+import junit.framework.TestCase;
+
+public abstract class StateUtilsAbstractCase extends TestCase implements Serializable{
+	private static final Log log = LogFactory.getLog(StateUtilsAbstractCase.class);
+	protected String sensitiveString;
+	private static final String TEST_DATA = "This is the test data.";
+	private String dummy ;
+	// 76543210
+	public static final String BASE64_KEY_SIZE_8 = "NzY1NDMyMTA=";
+	// 7654321076543210
+	public static final String BASE64_KEY_SIZE_16 = "NzY1NDMyMTA3NjU0MzIxMA==";
+	// 012345678901234567890123
+	public static final String BASE64_KEY_SIZE_24 = "MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIz";
+
+
+
+	protected void setUp() throws Exception {
+    FacesContextHelper.setCurrentInstance(null);
+    sensitiveString = "this is my secret";
+	}
+
+	protected void tearDown() throws Exception {
+		sensitiveString = null;
+	}
+
+	/**
+	 * Test for Restore View phase.
+	 */
+
+	public void testConstructionString(){
+		String constructed = StateUtils.construct(sensitiveString); 
+		Object object = StateUtils.reconstruct(constructed);
+		assertTrue(object instanceof String);
+		String string = (String)object;
+		string.equals(sensitiveString);
+	}
+
+	/**
+	 * Test for Restore View phase.  This method actually runs an instance of
+	 * StateUtilsTestCase through the construct/reconstruct process. 
+	 */	
+	
+	public void testConstruction(){
+	  String constructed = StateUtils.construct(TEST_DATA);
+		Object object = StateUtils.reconstruct(constructed);
+		assertTrue(TEST_DATA.equals(object));
+	}
+	
+	public void testSerialization(){
+		byte[] bytes = StateUtils.getAsByteArray(TEST_DATA);
+		Object object = StateUtils.getAsObject(bytes);
+		assertTrue(TEST_DATA.equals(object));
+	}
+	
+	public void testCryptography(){
+		byte[] sensitiveBytes = sensitiveString.getBytes();
+		byte[] secure = StateUtils.encrypt(sensitiveBytes);
+		byte[] insecure = StateUtils.decrypt(secure);
+		secure = StateUtils.encrypt(insecure); // * 2
+		insecure = StateUtils.decrypt(secure);
+		assertTrue(Arrays.equals(insecure, sensitiveBytes));
+	}
+	
+	public void testCompression(){
+		int size = 2049;
+		byte[] orginalBytes = new byte[size];
+		byte[] lessBytes = StateUtils.compress(orginalBytes);
+		assertTrue(lessBytes.length < orginalBytes.length);
+		byte[] moreBytes = StateUtils.decompress(lessBytes);
+		assertTrue(moreBytes.length > lessBytes.length);
+		assertTrue(Arrays.equals(moreBytes, orginalBytes));
+	}
+
+	public void testEncoding(){
+		byte[] orginalBytes = sensitiveString.getBytes();
+		byte[] encoded = StateUtils.encode(orginalBytes);
+		byte[] decoded = StateUtils.decode(encoded);
+		assertTrue(Arrays.equals(decoded, orginalBytes));
+	}
+	
+	/**
+	 * Simulates testConstruction w/ corrupt data.
+	 */
+	
+	public void testConstructionNegative(){
+		String constructed = StateUtils.construct(TEST_DATA);
+		constructed = constructed.substring(1, constructed.length());
+		try{
+			Object object = StateUtils.reconstruct(constructed);
+			assertFalse(TEST_DATA.equals(object));
+		} catch (Exception e) {
+      // do nothing
+    }
+	}
+	
+	/**
+	 * Simulates testSerialization w/ corrput data.
+	 */
+	
+	public void testSerializationNegative(){
+		byte[] bytes = StateUtils.getAsByteArray(TEST_DATA);
+		bytes[1] = (byte)3;
+		try{
+			Object object = StateUtils.getAsObject(bytes);
+			assertFalse(TEST_DATA.equals(object));
+		} catch (Exception e) {
+      // do nothing
+    }
+
+  }
+	
+	/**
+	 * Simulates testCryptography w/ corrupt data.
+	 */
+	
+	public void testCryptographyNegative(){
+		byte[] sensitiveBytes = sensitiveString.getBytes();
+		byte[] secure = StateUtils.encrypt(sensitiveBytes);
+		secure[3] = (byte)1;
+		try{
+			byte[] insecure = StateUtils.decrypt(secure);
+			assertFalse(Arrays.equals(insecure, sensitiveBytes));
+		} catch (Exception e) {
+      // do nothing
+    }
+	}
+
+	/**
+	 * Simulates testCompression w/ corrupt data.
+	 */
+	
+	public void testCompressionNegative(){
+		int size = 2049;
+		byte[] orginalBytes = new byte[size];
+		byte[] lessBytes = StateUtils.compress(orginalBytes);
+		lessBytes[1] = (byte)3;
+		try{
+			byte[] moreBytes = StateUtils.decompress(lessBytes);
+			assertFalse(Arrays.equals(moreBytes, orginalBytes));
+		} catch (Exception e){
+      // do nothing
+    }
+	}	
+	
+	/**
+	 * Simulates testEncoding w/ corrupt data.
+	 */
+	
+	public void testEncodingNegative(){
+		byte[] orginalBytes = sensitiveString.getBytes();
+		byte[] encoded = StateUtils.encode(orginalBytes);
+		encoded[1] = (byte)9;
+		try{
+			byte[] decoded = StateUtils.decode(encoded);
+			assertFalse(Arrays.equals(decoded, orginalBytes));
+		} catch (Exception e){
+      // do nothing
+    }
+	}
+	
+
+}
Index: src/test/java/org/apache/myfaces/util/StateUtilsDefaultTestCase.java
===================================================================
--- src/test/java/org/apache/myfaces/util/StateUtilsDefaultTestCase.java	(Revision 368304)
+++ src/test/java/org/apache/myfaces/util/StateUtilsDefaultTestCase.java	(Arbeitskopie)
@@ -7,10 +7,13 @@
  * @author Dennis C. Byrne
  */
 
-public class StateUtilsDefaultTestCase extends StateUtilsTestCase {
+public class StateUtilsDefaultTestCase extends StateUtilsAbstractCase {
 	
 	protected void setUp() throws Exception {
 		super.setUp();
-		System.setProperty(StateUtils.INIT_SECRET, BASE64_KEY_SIZE_8);
-	}
+    StateUtils.setSecret(BASE64_KEY_SIZE_8);
+		StateUtils.setAlgorithm("DES");
+		StateUtils.setAlgorithmParams( "ECB/PKCS5Padding");
+		StateUtils.setIv((byte [])null);
+  }
 }
Index: src/test/java/org/apache/myfaces/util/StateUtilsTripleDES_ECBTestCase.java
===================================================================
--- src/test/java/org/apache/myfaces/util/StateUtilsTripleDES_ECBTestCase.java	(Revision 368304)
+++ src/test/java/org/apache/myfaces/util/StateUtilsTripleDES_ECBTestCase.java	(Arbeitskopie)
@@ -13,13 +13,14 @@
  * @author Dennis C. Byrne
  */
 
-public class StateUtilsTripleDES_ECBTestCase extends StateUtilsTestCase {
+public class StateUtilsTripleDES_ECBTestCase extends StateUtilsAbstractCase {
 
 	protected void setUp() throws Exception {
 		super.setUp();
-		System.setProperty(StateUtils.INIT_SECRET, BASE64_KEY_SIZE_24);
-		System.setProperty(StateUtils.INIT_ALGORITHM, "DESede");
-		System.setProperty(StateUtils.INIT_ALGORITHM_PARAM, "ECB/PKCS5Padding");
-	}
+		StateUtils.setSecret(BASE64_KEY_SIZE_24);
+		StateUtils.setAlgorithm("DESede");
+		StateUtils.setAlgorithmParams( "ECB/PKCS5Padding");
+		StateUtils.setIv((byte [])null);
+  }
 	
 }
Index: src/test/java/org/apache/myfaces/util/StateUtilsBlowfish_ECBTestCase.java
===================================================================
--- src/test/java/org/apache/myfaces/util/StateUtilsBlowfish_ECBTestCase.java	(Revision 368304)
+++ src/test/java/org/apache/myfaces/util/StateUtilsBlowfish_ECBTestCase.java	(Arbeitskopie)
@@ -14,13 +14,15 @@
  *
  */
 
-public class StateUtilsBlowfish_ECBTestCase extends StateUtilsTestCase {
+public class StateUtilsBlowfish_ECBTestCase extends StateUtilsAbstractCase {
 
 	protected void setUp() throws Exception {
 		super.setUp();
-		System.setProperty(StateUtils.INIT_SECRET, BASE64_KEY_SIZE_16);
-		System.setProperty(StateUtils.INIT_ALGORITHM, "Blowfish");
-		System.setProperty(StateUtils.INIT_ALGORITHM_PARAM, "ECB/PKCS5Padding");
-	}
+    StateUtils.setSecret(BASE64_KEY_SIZE_16);
+		StateUtils.setAlgorithm("Blowfish");
+		StateUtils.setAlgorithmParams( "ECB/PKCS5Padding");
+		StateUtils.setIv((byte [])null);
+  }
+
 	
 }
Index: src/test/java/org/apache/myfaces/util/MessageUtilsTest.java
===================================================================
--- src/test/java/org/apache/myfaces/util/MessageUtilsTest.java	(Revision 368304)
+++ src/test/java/org/apache/myfaces/util/MessageUtilsTest.java	(Arbeitskopie)
@@ -19,14 +19,17 @@
 import java.util.ResourceBundle;
 
 import javax.faces.FactoryFinder;
+import javax.faces.render.RenderKit;
 import javax.faces.application.Application;
 import javax.faces.application.FacesMessage;
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.*;
+import javax.faces.context.ResponseStream;
 
 import junit.framework.Assert;
 import junit.framework.TestCase;
 import org.apache.myfaces.test.MockResponseWriter;
+import org.apache.myfaces.test.FacesContextHelper;
 import org.easymock.MockControl;
 import org.easymock.classextension.MockClassControl;
 
@@ -42,6 +45,7 @@
 
     private MockResponseWriter writer;
 
+
     private static final String DEFAULT_BUNDLE = "javax.faces.Messages";
 
     /**
@@ -181,8 +185,15 @@
     {
         this.writer = new MockResponseWriter();
         this.context = createMockFacesContext(this.writer);
+        FacesContextHelper.setCurrentInstance(context);
     }
+    protected void tearDown() throws Exception
+    {
+        FacesContextHelper.setCurrentInstance(null);
+        super.tearDown();
 
+    }
+
     /**
      * create the Mock object for FacesContext and required sub objects.
      *
@@ -196,7 +207,7 @@
                                  "org.apache.myfaces.renderkit.RenderKitFactoryImpl");
 
         MockControl ctxControl = MockClassControl
-                                 .createControl(MockFacesContext.class);
+                                 .createControl(FacesContext.class);
         FacesContext mockFacesCtx = (FacesContext) ctxControl.getMock();
 
         MockControl extCtxControl = MockClassControl
@@ -240,20 +251,5 @@
 
         return mockFacesCtx;
     }
-
-    /**
-     * Mock for FacesContext
-     * @author Stephan Strittmatter
-     */
-    abstract class MockFacesContext extends FacesContext
-    {
-
-        /**
-         * default constructor setting itself as current Instance of FacesContext.
-         */
-        public MockFacesContext()
-        {
-            FacesContext.setCurrentInstance(this);
-        }
-    }
 }
+
Index: src/test/java/org/apache/myfaces/util/StateUtilsAES_CBCTestCase.java
===================================================================
--- src/test/java/org/apache/myfaces/util/StateUtilsAES_CBCTestCase.java	(Revision 368304)
+++ src/test/java/org/apache/myfaces/util/StateUtilsAES_CBCTestCase.java	(Arbeitskopie)
@@ -13,14 +13,14 @@
  * @author Dennis C. Byrne
  */
 
-public class StateUtilsAES_CBCTestCase extends StateUtilsTestCase {
+public class StateUtilsAES_CBCTestCase extends StateUtilsAbstractCase {
 
 	protected void setUp() throws Exception {
 		super.setUp();
-		System.setProperty(StateUtils.INIT_SECRET, BASE64_KEY_SIZE_24);
-		System.setProperty(StateUtils.INIT_ALGORITHM, "AES");
-		System.setProperty(StateUtils.INIT_ALGORITHM_PARAM, "CBC/PKCS5Padding");
-		System.setProperty(StateUtils.INIT_ALGORITHM_IV, BASE64_KEY_SIZE_16);
+		StateUtils.setSecret(BASE64_KEY_SIZE_24);
+		StateUtils.setAlgorithm("AES");
+		StateUtils.setAlgorithmParams("CBC/PKCS5Padding");
+		StateUtils.setIv(BASE64_KEY_SIZE_16);
 	}
 	
 }
Index: src/main/java/org/apache/myfaces/util/StateUtils.java
===================================================================
--- src/main/java/org/apache/myfaces/util/StateUtils.java	(Revision 368132)
+++ src/main/java/org/apache/myfaces/util/StateUtils.java	(Arbeitskopie)
@@ -87,6 +87,7 @@
 
     static
     {
+        try {
         FacesContext ctx = FacesContext.getCurrentInstance();
         String _secret;
         String _algorithm;
@@ -98,16 +99,16 @@
                 _algorithm = ctx.getExternalContext().getInitParameter(INIT_ALGORITHM);
                 _algorithmParams = ctx.getExternalContext().getInitParameter(INIT_ALGORITHM_PARAM);
                 _iv = ctx.getExternalContext().getInitParameter(INIT_ALGORITHM_IV);
-        }else{ // not recommended for users ... mostly here for testing
+        } else{ // not recommended for users ... mostly here for testing
                 _secret = System.getProperty(INIT_SECRET);
                 _algorithm = System.getProperty(INIT_ALGORITHM);
                 _algorithmParams = System.getProperty(INIT_ALGORITHM_PARAM);
                 _iv = System.getProperty(INIT_ALGORITHM_IV);
         }
 
-        if(_secret == null){
+        if (_secret == null){
                 log.debug("secret for " + INIT_SECRET + " not located, encryption disabled");
-        }else{
+        } else{
                 if(_algorithmParams != null && _algorithmParams.startsWith("CBC") & _iv == null){
                         throw new FacesException(INIT_ALGORITHM_PARAM +
                                         " parameter has been set with CBC mode," +
@@ -124,6 +125,9 @@
                 secure = true;
                 log.debug("encryption enabled using " + algorithm + "/" + algorithmParams);
         }
+        } catch (Throwable t) {
+          t.printStackTrace();
+        }
     }
 
     public static boolean isSecure()
@@ -339,7 +343,43 @@
        }
     }
 
-    public static void main (String[] args) throws UnsupportedEncodingException
+    public static byte[] getSecret() {
+      return secret;
+    }
+    public static void setSecret(String _secret) {
+      secret =new Base64().decode(_secret.getBytes());
+    }
+    public static void setSecret(byte[] secret) {
+      StateUtils.secret = secret;
+    }
+
+    public static String getAlgorithm() {
+      return algorithm;
+    }
+
+    public static void setAlgorithm(String algorithm) {
+      StateUtils.algorithm = algorithm;
+    }
+
+    public static String getAlgorithmParams() {
+      return algorithmParams;
+    }
+
+    public static void setAlgorithmParams(String algorithmParams) {
+      StateUtils.algorithmParams = algorithmParams;
+    }
+
+    public static byte[] getIv() {
+      return iv;
+    }
+    public static void setIv(String _iv) {
+      iv = new Base64().decode(_iv.getBytes());
+    }
+    public static void setIv(byte[] iv) {
+      StateUtils.iv = iv;
+    }
+
+  public static void main (String[] args) throws UnsupportedEncodingException
     {
     	byte[] bytes = encode(args[0].getBytes(ZIP_CHARSET));
     	System.out.println(new String(bytes, ZIP_CHARSET));
Index: pom.xml
===================================================================
--- pom.xml	(Revision 368132)
+++ pom.xml	(Arbeitskopie)
@@ -119,6 +119,26 @@
 
   </dependencies>
 
+  <build>
+
+    <plugins>
+
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.1.2</version>
+         <configuration>
+          <excludes>
+            <exclude>**/*StateUtilsAES_CBCTestCase*</exclude>
+          </excludes>
+        </configuration>
+      </plugin>
+
+    </plugins>
+
+  </build>
+
+
   <reporting>
 
     <plugins>
/*
 * 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.myfaces.util;

import java.util.Locale;
import java.util.ResourceBundle;

import javax.faces.FactoryFinder;
import javax.faces.render.RenderKit;
import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIViewRoot;
import javax.faces.context.*;
import javax.faces.context.ResponseStream;

import junit.framework.Assert;
import junit.framework.TestCase;
import org.apache.myfaces.test.MockResponseWriter;
import org.apache.myfaces.test.FacesContextHelper;
import org.easymock.MockControl;
import org.easymock.classextension.MockClassControl;

/**
 * TestCase for MessageUtils
 *
 * @author Stephan Strittmatter
 */
public class MessageUtilsTest extends TestCase
{

    private FacesContext context;

    private MockResponseWriter writer;


    private static final String DEFAULT_BUNDLE = "javax.faces.Messages";

    /**
     * Test method for 'org.apache.myfaces.util.MessageUtils.getMessage(Severity, String, Object)'
     */
    public void testGetMessageSeverityStringObject()
    {
        FacesMessage msg = MessageUtils.getMessage(FacesMessage.SEVERITY_ERROR,
            "javax.faces.component.UIInput.CONVERSION", null);
        assertEquals("Conversion Error", msg.getSummary());

        msg = MessageUtils.getMessage(FacesMessage.SEVERITY_ERROR,
                                      "javax.faces.component.UIInput.CONVERSION",
                                      "blubb");
        assertEquals("Konvertierungsfehler", msg.getSummary());
    }

    /**
     * Test method for 'org.apache.myfaces.util.MessageUtils.getMessage(Severity, String, Object[])'
     */
    public void testGetMessageSeverityStringObjectArray()
    {
        FacesMessage msg = MessageUtils.getMessage(FacesMessage.SEVERITY_ERROR,
            "javax.faces.component.UIInput.CONVERSION", null);
        assertEquals("Conversion Error", msg.getSummary());

        msg = MessageUtils.getMessage(FacesMessage.SEVERITY_ERROR,
                                      "javax.faces.component.UIInput.CONVERSION", null);
        assertEquals("Konvertierungsfehler", msg.getSummary());
    }

    /**
     * Test method for 'org.apache.myfaces.util.MessageUtils.getMessage(Severity, String, Object[], FacesContext)'
     */
    public void testGetMessageSeverityStringObjectArrayFacesContext()
    {
        FacesMessage msg = MessageUtils.getMessage(FacesMessage.SEVERITY_ERROR,
            "javax.faces.component.UIInput.CONVERSION", null, getFacesContext());
        assertEquals("Conversion Error", msg.getSummary());

        msg = MessageUtils.getMessage(FacesMessage.SEVERITY_ERROR,
                                      "javax.faces.component.UIInput.CONVERSION", null,
                                      getFacesContext());
        assertEquals("Konvertierungsfehler", msg.getSummary());
    }

    /**
     * Test method for 'org.apache.myfaces.util.MessageUtils.getMessage(Locale, String, Object[])'
     */
    public void testGetMessageLocaleStringObjectArray()
    {
        FacesMessage msg = MessageUtils.getMessage(Locale.ENGLISH,
            "javax.faces.component.UIInput.CONVERSION", null);
        assertEquals("Conversion Error", msg.getSummary());

        msg = MessageUtils.getMessage(Locale.GERMAN,
                                      "javax.faces.component.UIInput.CONVERSION", null);
        assertEquals("Konvertierungsfehler", msg.getSummary());

    }

    /**
     * Test method for 'org.apache.myfaces.util.MessageUtils.getMessage(FacesContext, String)'
     */
    public void testGetMessageFacesContextString()
    {
        FacesMessage msg = MessageUtils.getMessage(this.getFacesContext(),
            "javax.faces.component.UIInput.CONVERSION");
        assertEquals("Conversion Error", msg.getSummary());

        msg = MessageUtils.getMessage(this.getFacesContext(),
                                      "javax.faces.component.UIInput.CONVERSION");
        assertEquals("Konvertierungsfehler", msg.getSummary());
    }

    /**
     * Test method for 'org.apache.myfaces.util.MessageUtils.getMessage(FacesContext, String, Object[])'
     */
    public void testGetMessageFacesContextStringObjectArray()
    {
        FacesMessage msg = MessageUtils.getMessage(this.getFacesContext(),
            "javax.faces.component.UIInput.CONVERSION", null);
        assertEquals("Conversion Error", msg.getSummary());

        msg = MessageUtils.getMessage(this.getFacesContext(),
                                      "javax.faces.component.UIInput.CONVERSION", null);
        assertEquals("Konvertierungsfehler", msg.getSummary());
    }

    /**
     * testGetMessageWithBundle
     */
    public void testGetMessageWithBundle()
    {
        ResourceBundle bundle = ResourceBundle.getBundle(DEFAULT_BUNDLE,
            Locale.ENGLISH);
        FacesMessage msg = MessageUtils.getMessage(bundle,
            "javax.faces.component.UIInput.CONVERSION", null);

        assertEquals("Conversion Error", msg.getSummary());
    }

    /**
     * testGetMessageWithBundleName
     */
    public void testGetMessageWithBundleName()
    {
        FacesMessage msg = MessageUtils.getMessage(DEFAULT_BUNDLE,
            "javax.faces.component.UIInput.CONVERSION", null);

        assertEquals("Conversion Error", msg.getSummary());
    }

    /**
     * testGetMessageWithBundleNameLocale
     */
    public void testGetMessageWithBundleNameLocale()
    {
        FacesMessage msg = MessageUtils.getMessage(DEFAULT_BUNDLE,
            Locale.GERMAN, "javax.faces.component.UIInput.CONVERSION", null);

        assertEquals("Konvertierungsfehler", msg.getSummary());
    }

    /**
     * @return FacesContext
     */
    protected FacesContext getFacesContext()
    {
        Assert.assertNotNull(
            "Please extend setUp() to create a valid FacesContext "
            + "instead of overwrite it!", this.context);
        return this.context;
    }

    protected void setUp() throws Exception
    {
        this.writer = new MockResponseWriter();
        this.context = createMockFacesContext(this.writer);
        FacesContextHelper.setCurrentInstance(context);
    }
    protected void tearDown() throws Exception
    {
        FacesContextHelper.setCurrentInstance(null);
        super.tearDown();

    }

    /**
     * create the Mock object for FacesContext and required sub objects.
     *
     * @param rWriter writer to get access to the content
     * @return the Mock of FacesContext
     */
    protected FacesContext createMockFacesContext(ResponseWriter rWriter)
    {

        FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
                                 "org.apache.myfaces.renderkit.RenderKitFactoryImpl");

        MockControl ctxControl = MockClassControl
                                 .createControl(FacesContext.class);
        FacesContext mockFacesCtx = (FacesContext) ctxControl.getMock();

        MockControl extCtxControl = MockClassControl
                                    .createControl(ExternalContext.class);
        ExternalContext mockExtCtx = (ExternalContext) extCtxControl.getMock();

        mockFacesCtx.getExternalContext();
        ctxControl.setDefaultReturnValue(mockExtCtx);

        MockControl appControl = MockClassControl.createControl(Application.class);
        Application mockApplication = (Application) appControl.getMock();

        mockApplication.getMessageBundle();
        appControl.setDefaultReturnValue(DEFAULT_BUNDLE);

        mockFacesCtx.getApplication();
        ctxControl.setDefaultReturnValue(mockApplication);

        mockFacesCtx.renderResponse();
        ctxControl.setVoidCallable();

        mockFacesCtx.getResponseWriter();
        ctxControl.setDefaultReturnValue(rWriter);

        MockControl viewRootControl = MockClassControl
                                      .createControl(UIViewRoot.class);
        UIViewRoot uiViewRoot = (UIViewRoot) viewRootControl.getMock();

        uiViewRoot.getLocale();
        //set the return values: first EN, then DE!
        viewRootControl.setReturnValue(Locale.ENGLISH);
        viewRootControl.setReturnValue(Locale.GERMAN);

        mockFacesCtx.getViewRoot();
        ctxControl.setDefaultReturnValue(uiViewRoot);

        ctxControl.replay();
        appControl.replay();
        extCtxControl.replay();
        viewRootControl.replay();

        return mockFacesCtx;
    }
}

Reply via email to