Skip to content
Permalink
Browse files
[JENKINS-31703] fixed ATX form validation
  • Loading branch information
cpoenisch committed Nov 23, 2015
1 parent 029cb25 commit 8ea43015567967ec2a1bc653b1a2bafb5063986d
@@ -29,6 +29,7 @@
*/
package de.tracetronic.jenkins.plugins.ecutest.util.validation;

import hudson.Util;
import hudson.util.FormValidation;

import java.io.BufferedReader;
@@ -141,9 +142,14 @@ public FormValidation validateServerPort(final String serverPort) {
*/
public FormValidation validateArchiveMiscFiles(final String expression) {
FormValidation returnValue = FormValidation.ok();
final String pattern = "([A-Za-z0-9/\\*]+\\.[A-Za-z0-9\\*]+(\\;|$))+";
if (!StringUtils.isEmpty(expression) && !Pattern.matches(pattern, expression)) {
returnValue = FormValidation.error(Messages.ATXPublisher_InvalidFileExpression());
final String pattern = "[A-Za-z0-9./\\*]+";
if (!StringUtils.isEmpty(expression)) {
for (final String token : Util.tokenize(expression, ";")) {
if (!Pattern.matches(pattern, token)) {
returnValue = FormValidation.error(Messages.ATXPublisher_InvalidFileExpression());
break;
}
}
}
return returnValue;
}
@@ -157,11 +163,16 @@ public FormValidation validateArchiveMiscFiles(final String expression) {
*/
public FormValidation validateCoveredAttributes(final String expression) {
FormValidation returnValue = FormValidation.ok();
final String pattern = "((Designer|Name|Status|Testlevel|Tools|VersionCounter|"
final String pattern = "(Designer|Name|Status|Testlevel|Tools|VersionCounter|"
+ "Design Contact|Design Department|Estimated Duration \\[min\\]|"
+ "Execution Priority|Test Comment)(\\;|$))+";
if (!StringUtils.isEmpty(expression) && !Pattern.matches(pattern, expression)) {
returnValue = FormValidation.error(Messages.ATXPublisher_InvalidAttributeExpression());
+ "Execution Priority|Test Comment)";
if (!StringUtils.isEmpty(expression)) {
for (final String token : Util.tokenize(expression, ";")) {
if (!Pattern.matches(pattern, token)) {
returnValue = FormValidation.warning(Messages.ATXPublisher_CustomAttributeExpression());
break;
}
}
}
return returnValue;
}
@@ -29,7 +29,7 @@ ATXBuildAction.DisplayName=ATX Reports
ATXProjectAction.DisplayName=Latest ATX Reports
ATXPublisher.DisplayName=[TT] Publish ATX Reports
ATXPublisher.DuplicateSetting=Setting is already existing and will be ignored.
ATXPublisher.InvalidAttributeExpression=Invalid package attribute expression.
ATXPublisher.CustomAttributeExpression=Custom package attributes can not be validated.
ATXPublisher.InvalidFileExpression=Invalid file search expression.
ATXPublisher.InvalidPort=Choose a port greater than 0 and less than 65535.
ATXPublisher.InvalidServer=Server at {0} does not appear to be a TEST-GUIDE server.
@@ -29,7 +29,7 @@ ATXBuildAction.DisplayName=ATX-Reports
ATXProjectAction.DisplayName=Letzte ATX-Reports
ATXPublisher.DisplayName=[TT] ATX-Reports ver\u00f6ffentlichen
ATXPublisher.DuplicateSetting=Einstellung existiert bereits und wird ignoriert.
ATXPublisher.InvalidAttributeExpression=Ung\u00fcltiger Package-Attributeausdruck.
ATXPublisher.CustomAttributeExpression=Benutzerdefinierte Package-Attribute k\u00f6nnen nicht \u00fcberpr\u00fcft werden.
ATXPublisher.InvalidFileExpression=Ung\u00fcltiger Datei-Suchausdruck.
ATXPublisher.InvalidPort=Port gr\u00f6\u00dfer als 0 und kleiner als 65535 w\u00e4hlen.
ATXPublisher.InvalidServer=Server unter {0} scheint kein TEST-GUIDE-Server zu sein.
@@ -169,19 +169,19 @@ public void testNullArchiveExpression() {
@Test
public void testValidSingleArchiveExpression() {
final FormValidation validation = atxValidator.validateArchiveMiscFiles("myFile*.asc");
assertEquals("Valid single expression ", FormValidation.Kind.OK, validation.kind);
assertEquals("Valid single expression", FormValidation.Kind.OK, validation.kind);
}

@Test
public void testValidMultiArchiveExpression() {
final FormValidation validation = atxValidator.validateArchiveMiscFiles("myFile*.asc;asc/**/myDirFile.*;");
assertEquals("Valid multiple expression ", FormValidation.Kind.OK, validation.kind);
final FormValidation validation = atxValidator.validateArchiveMiscFiles("myFile*.asc;asc/**/myDirFile.*;*;**");
assertEquals("Valid multiple expression", FormValidation.Kind.OK, validation.kind);
}

@Test
public void testInvalidArchiveExpression() {
final FormValidation validation = atxValidator.validateArchiveMiscFiles("invalid");
assertEquals("Invalid archive expression ", FormValidation.Kind.ERROR, validation.kind);
final FormValidation validation = atxValidator.validateArchiveMiscFiles("-");
assertEquals("Invalid archive expression", FormValidation.Kind.ERROR, validation.kind);
}

// Validation of covered attributes
@@ -200,20 +200,26 @@ public void testNullAttributesExpression() {
@Test
public void testValidSingleAttributesExpression() {
final FormValidation validation = atxValidator.validateCoveredAttributes("Testlevel");
assertEquals("Valid single expression ", FormValidation.Kind.OK, validation.kind);
assertEquals("Valid single expression", FormValidation.Kind.OK, validation.kind);
}

@Test
public void testValidMultiAttributesExpression() {
final FormValidation validation = atxValidator
.validateCoveredAttributes("Testlevel;Designer;Execution Priority;Estimated Duration [min];");
assertEquals("Valid multiple expression ", FormValidation.Kind.OK, validation.kind);
assertEquals("Valid multiple expression", FormValidation.Kind.OK, validation.kind);
}

@Test
public void testCustomAttributesExpression() {
final FormValidation validation = atxValidator.validateCoveredAttributes("Requirements IDs; Custom Attribute");
assertEquals("Custom archive expression", FormValidation.Kind.WARNING, validation.kind);
}

@Test
public void testInvalidAttributesExpression() {
final FormValidation validation = atxValidator.validateCoveredAttributes("invalid");
assertEquals("Invalid archive expression ", FormValidation.Kind.ERROR, validation.kind);
final FormValidation validation = atxValidator.validateCoveredAttributes("-");
assertEquals("Invalid archive expression", FormValidation.Kind.WARNING, validation.kind);
}

// Validation of settings switch

0 comments on commit 8ea4301

Please sign in to comment.