validation for repository group addition

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1178047 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2011-10-01 17:25:28 +00:00
parent adcd341efe
commit ea1e15a65d
5 changed files with 43 additions and 12 deletions

View 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" );
}

View 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 )

View 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" );

View File

@ -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>

View File

@ -47,11 +47,10 @@
<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>