Author: craigmcc
Date: Fri Sep 16 21:54:25 2005
New Revision: 289706
URL: http://svn.apache.org/viewcvs?rev=289706&view=rev
Log:
Add new test case for TokenProcessor.
Added:
struts/shale/trunk/core-library/src/test/org/apache/shale/util/TokenProcessorTestCase.java
Added:
struts/shale/trunk/core-library/src/test/org/apache/shale/util/TokenProcessorTestCase.java
URL:
http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/test/org/apache/shale/util/TokenProcessorTestCase.java?rev=289706&view=auto
==============================================================================
---
struts/shale/trunk/core-library/src/test/org/apache/shale/util/TokenProcessorTestCase.java
(added)
+++
struts/shale/trunk/core-library/src/test/org/apache/shale/util/TokenProcessorTestCase.java
Fri Sep 16 21:54:25 2005
@@ -0,0 +1,120 @@
+/*
+ * 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.shale.util;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import javax.faces.context.FacesContext;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.shale.test.base.AbstractJsfTestCase;
+
+/**
+ * <p>Test case for <code>TokenProcessor</code>.</p>
+ */
+public class TokenProcessorTestCase extends AbstractJsfTestCase {
+
+
+ // ------------------------------------------------------------
Constructors
+
+
+ // Construct a new instance of this test case.
+ public TokenProcessorTestCase(String name) {
+ super(name);
+ }
+
+
+ // ---------------------------------------------------- Overall Test
Methods
+
+
+ // Set up instance variables required by this test case.
+ public void setUp() {
+
+ super.setUp();
+
+ // Set up the instance we will be testing
+ tp = new TokenProcessor();
+
+ }
+
+
+ // Return the tests included in this test case.
+ public static Test suite() {
+
+ return (new TestSuite(TokenProcessorTestCase.class));
+
+ }
+
+
+ // Tear down instance variables required by this test case.
+ public void tearDown() {
+
+ tp = null;
+ super.tearDown();
+
+ }
+
+
+ // ------------------------------------------------------ Instance
Variables
+
+
+ // The instance to be tested
+ TokenProcessor tp = null;
+
+
+ // ------------------------------------------------------------ Test
Methods
+
+
+ // Test generation of multiple tokens and the ability to validate them
+ public void testMultiple() {
+
+ Set set = new HashSet();
+
+ // Create a bunch of tokens
+ for (int i = 0; i < 1000; i++) {
+ String token = tp.generate(facesContext);
+ if (set.contains(token)) {
+ fail("Token set already contains '" + token + "'");
+ }
+ set.add(token);
+ try {
+ Thread.sleep(2);
+ } catch (InterruptedException e) {
+ ;
+ }
+ }
+
+ // Ensure that we can verify all of them
+ Iterator tokens = set.iterator();
+ while (tokens.hasNext()) {
+ String token = (String) tokens.next();
+ assertTrue("Cannot verify token '" + token + "'",
tp.verify(facesContext, token));
+ }
+
+ }
+
+
+ // Test a pristine instance
+ public void testPristine() {
+
+ assertNotNull(tp);
+
+ }
+
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]