Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 13144 invoked from network); 3 Sep 2004 14:49:00 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 3 Sep 2004 14:49:00 -0000 Received: (qmail 1684 invoked by uid 500); 3 Sep 2004 14:48:39 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 1549 invoked by uid 500); 3 Sep 2004 14:48:37 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 1422 invoked by uid 99); 3 Sep 2004 14:48:36 -0000 X-ASF-Spam-Status: No, hits=-2.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Fri, 03 Sep 2004 07:48:35 -0700 Received: (qmail 12712 invoked by uid 65534); 3 Sep 2004 14:48:32 -0000 Date: 3 Sep 2004 14:48:32 -0000 Message-ID: <20040903144832.12707.qmail@minotaur.apache.org> From: ugo@apache.org To: cvs@cocoon.apache.org Subject: svn commit: rev 37475 - cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: ugo Date: Fri Sep 3 07:48:31 2004 New Revision: 37475 Added: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/HostSelectorTestCase.java cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/HostSelectorTestCase.xtest cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/RequestAttributeSelectorTestCase.java cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/RequestAttributeSelectorTestCase.xtest Log: Sync with trunk Added: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/HostSelectorTestCase.java ============================================================================== --- (empty file) +++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/HostSelectorTestCase.java Fri Sep 3 07:48:31 2004 @@ -0,0 +1,98 @@ +/* +* Copyright 1999-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.cocoon.selection; + +import junit.framework.Test; +import junit.framework.TestSuite; +import junit.textui.TestRunner; +import org.apache.avalon.framework.parameters.Parameters; +import org.apache.cocoon.SitemapComponentTestCase; + + +public class HostSelectorTestCase extends SitemapComponentTestCase { + + private final String HOST_SELECTOR = "host"; + + public HostSelectorTestCase(String name) { + super(name); + } + + /** + * Run this test suite from commandline + * + * @param args commandline arguments (ignored) + */ + public static void main( String[] args ) { + TestRunner.run(suite()); + } + + /** Create a test suite. + * This test suite contains all test cases of this class. + * @return the Test object containing all test cases. + */ + public static Test suite() { + TestSuite suite = new TestSuite(HostSelectorTestCase.class); + return suite; + } + + /** + * A simple host selector test + */ + public void testHostSelectEurope() throws Exception { + final String host = "myhost-dns-name-in-a-europe-country"; + String expectedHostName; + + getRequest().setHeader("Host", host ); + Parameters parameters = new Parameters(); + boolean result; + + // test selecting succeeds + expectedHostName = "myhost-eu"; + result = this.select( HOST_SELECTOR, expectedHostName, parameters ); + System.out.println(result); + assertTrue( "Test if host is " + expectedHostName, result ); + + // test selecting fails + expectedHostName = "myhost-us"; + result = this.select( HOST_SELECTOR, expectedHostName, parameters ); + System.out.println(result); + assertTrue( "Test if host is not " + expectedHostName, !result ); + } + + /** + * A simple host selector test + */ + public void testHostSelectUnknownHost() throws Exception { + final String host = "myhost-dns-name-in-a-asia-country"; + String expectedHostName; + + getRequest().setHeader("Host", host ); + Parameters parameters = new Parameters(); + boolean result; + + // test selecting succeeds + expectedHostName = "myhost-eu"; + result = this.select( HOST_SELECTOR, expectedHostName, parameters ); + System.out.println(result); + assertTrue( "Test if host is not " + expectedHostName, !result ); + + // test selecting fails + expectedHostName = "myhost-us"; + result = this.select( HOST_SELECTOR, expectedHostName, parameters ); + System.out.println(result); + assertTrue( "Test if host is not " + expectedHostName, !result ); + } +} Added: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/HostSelectorTestCase.xtest ============================================================================== --- (empty file) +++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/HostSelectorTestCase.xtest Fri Sep 3 07:48:31 2004 @@ -0,0 +1,74 @@ + + + + + Test Cases: HostSelector + + + + + + + + + System.out + + %7.7{priority} %5.5{time} [%9.9{category}] (%{context}): %{message}\n%{throwable} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Added: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/RequestAttributeSelectorTestCase.java ============================================================================== --- (empty file) +++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/RequestAttributeSelectorTestCase.java Fri Sep 3 07:48:31 2004 @@ -0,0 +1,96 @@ +/* +* Copyright 1999-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.cocoon.selection; + +import junit.framework.Test; +import junit.framework.TestSuite; +import junit.textui.TestRunner; +import org.apache.avalon.framework.parameters.Parameters; +import org.apache.cocoon.SitemapComponentTestCase; + + +public class RequestAttributeSelectorTestCase extends SitemapComponentTestCase { + + public RequestAttributeSelectorTestCase(String name) { + super(name); + } + + /** + * Run this test suite from commandline + * + * @param args commandline arguments (ignored) + */ + public static void main( String[] args ) { + TestRunner.run(suite()); + } + + /** Create a test suite. + * This test suite contains all test cases of this class. + * @return the Test object containing all test cases. + */ + public static Test suite() { + TestSuite suite = new TestSuite(RequestAttributeSelectorTestCase.class); + return suite; + } + + /** + * A request-attribute parameter select test + */ + public void testRequestAttributeSelect() throws Exception { + final String attributeName = "requestAttributeSelector"; + final String attributeValue = "requestAttributeSelectorValue"; + getRequest().setAttribute( attributeName, attributeValue ); + Parameters parameters = new Parameters(); + boolean result; + + // test selection success + result = this.select( "request-attribute", attributeValue, parameters ); + System.out.println( result ); + assertTrue( "Test if a request attribtue is selected", result ); + + // test selection failure + result = this.select( "request-attribute", "unknownValue", parameters ); + System.out.println( result ); + assertTrue( "Test if a request attribute is not selected", !result ); + } + + /** + * A request-attribute parameter select test + */ + public void testRequestAttributeSelectOverridden() throws Exception { + final String attributeName = "requestAttributeSelector1"; + final String attributeValue = "requestAttributeSelectorValue1"; + getRequest().setAttribute( attributeName, attributeValue ); + + final String attributeNameOverridden = "requestAttributeSelector"; + final String attributeValueOverridden = "requestAttributeSelectorValue"; + getRequest().setAttribute( attributeNameOverridden, attributeValueOverridden ); + + Parameters parameters = new Parameters(); + parameters.setParameter( "attribute-name", attributeName ); + boolean result; + + // test selection success + result = this.select( "request-attribute", attributeValue, parameters ); + System.out.println( result ); + assertTrue( "Test if a requst attribtue is selected", result ); + + // test selection failure + result = this.select( "request-attribute", attributeValueOverridden, parameters ); + System.out.println( result ); + assertTrue( "Test if a request attribute is not selected", !result ); + } +} Added: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/RequestAttributeSelectorTestCase.xtest ============================================================================== --- (empty file) +++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/selection/RequestAttributeSelectorTestCase.xtest Fri Sep 3 07:48:31 2004 @@ -0,0 +1,73 @@ + + + + + Test Cases: RequestAttributeSelector + + + + + + + + + System.out + + %7.7{priority} %5.5{time} [%9.9{category}] (%{context}): %{message}\n%{throwable} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + requestAttributeSelector + + + + +