From cd957318dca0b1dab2dbfa4e5c6059e9d5d09d66 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Thu, 13 Sep 2007 00:10:20 +0000 Subject: [PATCH] [MRM-496] start a test case git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@575133 13f79535-47bb-0310-9956-ffa450edef68 --- .../proxy/ConfigureProxyConnectorAction.java | 15 +-- .../ConfigureProxyConnectorActionTest.java | 95 +++++++++++++++++++ .../ConfigureProxyConnectorActionTest.xml | 45 +++++++++ 3 files changed, 145 insertions(+), 10 deletions(-) create mode 100644 archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/ConfigureProxyConnectorActionTest.java create mode 100644 archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/connectors/proxy/ConfigureProxyConnectorActionTest.xml diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/ConfigureProxyConnectorAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/ConfigureProxyConnectorAction.java index 1d420f041..02cce40ed 100644 --- a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/ConfigureProxyConnectorAction.java +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/ConfigureProxyConnectorAction.java @@ -445,11 +445,6 @@ public class ConfigureProxyConnectorAction this.connector = connector; } - public void setManagedRepoIdList( List managedRepoIdList ) - { - this.managedRepoIdList = managedRepoIdList; - } - public void setMode( String mode ) { this.mode = mode; @@ -465,11 +460,6 @@ public class ConfigureProxyConnectorAction this.propertyValue = propertyValue; } - public void setRemoteRepoIdList( List remoteRepoIdList ) - { - this.remoteRepoIdList = remoteRepoIdList; - } - public void setSource( String source ) { this.source = source; @@ -578,4 +568,9 @@ public class ConfigureProxyConnectorAction { this.pattern = pattern; } + + public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration ) + { + this.archivaConfiguration = archivaConfiguration; + } } diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/ConfigureProxyConnectorActionTest.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/ConfigureProxyConnectorActionTest.java new file mode 100644 index 000000000..cea72d4d7 --- /dev/null +++ b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/ConfigureProxyConnectorActionTest.java @@ -0,0 +1,95 @@ +package org.apache.maven.archiva.web.action.admin.connectors.proxy; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +import com.opensymphony.xwork.Action; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle; +import org.easymock.MockControl; + +/** + * Test the proxy connector configuration action returns the correct data. + */ +public class ConfigureProxyConnectorActionTest + extends PlexusTestCase +{ + private ConfigureProxyConnectorAction action; + + private MockControl archivaConfigurationControl; + + private ArchivaConfiguration archivaConfiguration; + + protected void setUp() + throws Exception + { + super.setUp(); + + // TODO: purely to quiet logging - shouldn't be needed + String appserverBase = getTestFile( "target/appserver-base" ).getAbsolutePath(); + System.setProperty( "appserver.base", appserverBase ); + action = (ConfigureProxyConnectorAction) lookup( Action.class.getName(), "configureProxyConnectorAction" ); + + archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); + archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); + action.setArchivaConfiguration( archivaConfiguration ); + } + + public void testSecureActionBundle() + throws Exception + { + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( new Configuration() ); + archivaConfigurationControl.replay(); + + action.prepare(); + SecureActionBundle bundle = action.getSecureActionBundle(); + assertTrue( bundle.requiresAuthentication() ); + assertEquals( 1, bundle.getAuthorizationTuples().size() ); + } + + public void testAddProxyConnectorInitialPage() + throws Exception + { + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( new Configuration() ); + archivaConfigurationControl.replay(); + + action.prepare(); + assertNull( action.getMode() ); + ProxyConnectorConfiguration configuration = action.getConnector(); + assertNotNull( configuration ); + assertNull( configuration.getProxyId() ); + assertNull( configuration.getSourceRepoId() ); + assertNull( configuration.getTargetRepoId() ); + assertTrue( configuration.getPolicies().isEmpty() ); + assertTrue( configuration.getProperties().isEmpty() ); + assertTrue( configuration.getBlackListPatterns().isEmpty() ); + assertTrue( configuration.getWhiteListPatterns().isEmpty() ); + + String status = action.add(); + assertEquals( Action.INPUT, status ); + } + + // TODO: test the population of proxyIdOptions, *RepoIdList (from prepare) and policyMap (from initialize) + // TODO: test the other methods. Should review the structure of the action in the process as there is a lot of different combinations of parameters +} diff --git a/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/connectors/proxy/ConfigureProxyConnectorActionTest.xml b/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/connectors/proxy/ConfigureProxyConnectorActionTest.xml new file mode 100644 index 000000000..21c90f5d4 --- /dev/null +++ b/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/connectors/proxy/ConfigureProxyConnectorActionTest.xml @@ -0,0 +1,45 @@ + + + + + + org.codehaus.plexus.logging.LoggerManager + org.codehaus.plexus.logging.slf4j.Slf4jLoggerManager + basic + + + com.opensymphony.xwork.Action + configureProxyConnectorAction + org.apache.maven.archiva.web.action.admin.connectors.proxy.ConfigureProxyConnectorAction + + per-lookup + + + org.apache.maven.archiva.policies.PreDownloadPolicy + preDownloadPolicyMap + + + org.apache.maven.archiva.policies.PostDownloadPolicy + postDownloadPolicyMap + + + + +