]> source.dussan.org Git - archiva.git/commitdiff
validation for repository group addition
authorBrett Porter <brett@apache.org>
Sat, 1 Oct 2011 17:25:28 +0000 (17:25 +0000)
committerBrett Porter <brett@apache.org>
Sat, 1 Oct 2011 17:25:28 +0000 (17:25 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1178047 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/VirtualRepositoryTest.java
archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/parent/AbstractRepositoryTest.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/repositories/RepositoryGroupsAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/resources/org/apache/archiva/web/action/admin/repositories/RepositoryGroupsAction-addRepositoryGroup-validation.xml [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositoryGroups.jsp

index a17f0b005881a211692cc121cef0f0b7f39a053e..9df08da44906979376316abd00eed321dc03642d 100644 (file)
@@ -27,18 +27,17 @@ import org.testng.Assert;
 public class VirtualRepositoryTest
     extends AbstractRepositoryTest
 {
-    // FIXME: says repositoryGroup id cannot be empty
-    @Test( enabled = false )
+    @Test
     public void testAddRepositoryGroupNullValue()
     {
-        addRepositoryGroup( " " );
+        addRepositoryGroup( " ", false );
         assertTextPresent( "Identifier field is required." );
     }
 
     @Test( dependsOnMethods = { "testWithCorrectUsernamePassword" } )
     public void testAddRepositoryGroupValidValue()
     {
-        addRepositoryGroup( "testing" );
+        addRepositoryGroup( "testing", true );
         Assert.assertEquals( getSelenium().getText( "//div[@id='contentArea']/div[2]/div/div[1]/p[1]" ), "testing" );
     }
 
index 28451198f2ce516800c53c0600f9c0e2af4787da..a1214acfb9822a57d759e9adfcd779ea03b56f66 100644 (file)
@@ -73,11 +73,11 @@ public abstract class AbstractRepositoryTest
         assertButtonWithValuePresent( "Cancel" );
     }
 
-    public void addRepositoryGroup( String repoGroupName )
+    public void addRepositoryGroup( String repoGroupName, boolean wait )
     {
         goToRepositoryGroupsPage();
         setFieldValue( "repositoryGroup.id", repoGroupName );
-        clickButtonWithValue( "Add Group" );
+        clickButtonWithValue( "Add Group", wait );
     }
 
     public void addRepositoryToRepositoryGroup( String repositoryGroupName, String repositoryName )
index 7c5d9f86e7428186f95ba5192cd36ca566d153d9..5d12e100b5184c6374b09591b232db8f0db3eec0 100644 (file)
@@ -65,8 +65,6 @@ public class RepositoryGroupsAction
      */
     private String baseUrl;
 
-    private static final Pattern REPO_GROUP_ID_PATTERN = Pattern.compile( "[A-Za-z0-9\\._\\-]+" );
-
     public void setServletRequest( HttpServletRequest request )
     {
         this.baseUrl = ContextUtils.getBaseURL( request, "repository" );
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/resources/org/apache/archiva/web/action/admin/repositories/RepositoryGroupsAction-addRepositoryGroup-validation.xml b/archiva-modules/archiva-web/archiva-webapp/src/main/resources/org/apache/archiva/web/action/admin/repositories/RepositoryGroupsAction-addRepositoryGroup-validation.xml
new file mode 100644 (file)
index 0000000..ba5c4a9
--- /dev/null
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  ~ 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.
+  -->
+
+<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
+    "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
+
+<validators>
+  <field name="repositoryGroup.id">
+    <field-validator type="requiredstring">
+      <message>Identifier field is required.</message>
+    </field-validator>
+    <field-validator type="regex">
+        <param name="trim">true</param>
+        <param name="expression">^[a-zA-Z0-9._-]+$</param>
+        <message>Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-).</message>
+    </field-validator>
+  </field>
+</validators>
index ec7c8c2dda0c720a7795a63426c3337c2caa9bdb..13bafd384c887a34694dbba52bb9f4ba60e22496 100644 (file)
 
 <div align="right">
   <redback:ifAnyAuthorized permissions="archiva-manage-configuration">
-    <s:form action="addRepositoryGroup" namespace="/admin">
-      <span class="label">Identifier<span style="color:red">*</span>:</span> 
-      <s:textfield size="10" label="Identifier" theme="simple" name="repositoryGroup.id"/>
+    <s:form name="addRepositoryGroup" action="addRepositoryGroup" namespace="/admin" validate="true">
+      <s:textfield size="10" label="Identifier" name="repositoryGroup.id"/>
       <s:token/>
-      <s:submit value="Add Group" theme="simple" cssClass="button"/>
+      <s:submit value="Add Group" cssClass="button"/>
     </s:form>
   </redback:ifAnyAuthorized>
 </div>