]> source.dussan.org Git - archiva.git/commitdiff
[MRM-496] start a test case
authorBrett Porter <brett@apache.org>
Thu, 13 Sep 2007 00:10:20 +0000 (00:10 +0000)
committerBrett Porter <brett@apache.org>
Thu, 13 Sep 2007 00:10:20 +0000 (00:10 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@575133 13f79535-47bb-0310-9956-ffa450edef68

archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/ConfigureProxyConnectorAction.java
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/connectors/proxy/ConfigureProxyConnectorActionTest.java [new file with mode: 0644]
archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/connectors/proxy/ConfigureProxyConnectorActionTest.xml [new file with mode: 0644]

index 1d420f0419b5194b6e51532c501b195d1d1c8eaf..02cce40ed8e198c0bbfc93b667850392647c4a6d 100644 (file)
@@ -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 (file)
index 0000000..cea72d4
--- /dev/null
@@ -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 (file)
index 0000000..21c90f5
--- /dev/null
@@ -0,0 +1,45 @@
+<!--
+  ~ 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.
+  -->
+
+<plexus>
+  <components>
+    <component>
+      <role>org.codehaus.plexus.logging.LoggerManager</role>
+      <implementation>org.codehaus.plexus.logging.slf4j.Slf4jLoggerManager</implementation>
+      <lifecycle-handler>basic</lifecycle-handler>
+    </component>
+    <component>
+      <role>com.opensymphony.xwork.Action</role>
+      <role-hint>configureProxyConnectorAction</role-hint>
+      <implementation>org.apache.maven.archiva.web.action.admin.connectors.proxy.ConfigureProxyConnectorAction
+      </implementation>
+      <instantiation-strategy>per-lookup</instantiation-strategy>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.archiva.policies.PreDownloadPolicy</role>
+          <field-name>preDownloadPolicyMap</field-name>
+        </requirement>
+        <requirement>
+          <role>org.apache.maven.archiva.policies.PostDownloadPolicy</role>
+          <field-name>postDownloadPolicyMap</field-name>
+        </requirement>
+      </requirements>
+    </component>
+  </components>
+</plexus>