diff --git a/hsarback/src/de/hsadmin/mods/email/EMailAlias.java b/hsarback/src/de/hsadmin/mods/email/EMailAlias.java index 62affc7..3d057ef 100644 --- a/hsarback/src/de/hsadmin/mods/email/EMailAlias.java +++ b/hsarback/src/de/hsadmin/mods/email/EMailAlias.java @@ -48,7 +48,7 @@ public class EMailAlias extends AbstractEntity implements Serializable { @AnnFieldIO(validation="[a-z0-9]*", rw=ReadWriteAccess.READONLY) private Pac pac; - @AnnFieldIO(validation="[a-z0-9]{5}-[a-z0-9\\.\\_\\+]{1,}", rw=ReadWriteAccess.WRITEONCE) + @AnnFieldIO(validation="[a-z0-9]{5}(-[a-z0-9\\.\\_]{1,})?", rw=ReadWriteAccess.WRITEONCE) @Column(updatable=false) private String name; diff --git a/hsarback/src/de/hsadmin/mods/user/UnixUser.java b/hsarback/src/de/hsadmin/mods/user/UnixUser.java index a848c8e..842e627 100644 --- a/hsarback/src/de/hsadmin/mods/user/UnixUser.java +++ b/hsarback/src/de/hsadmin/mods/user/UnixUser.java @@ -40,7 +40,7 @@ public class UnixUser extends AbstractEntity implements Serializable { @Column(name="userid", columnDefinition="integer", nullable=false, updatable=false) private long userId; - @AnnFieldIO(validation="[a-z0-9]{5}-[a-z0-9\\.\\_]{1,}", rw=ReadWriteAccess.WRITEONCE) + @AnnFieldIO(validation="[a-z0-9]{5}(-[a-z0-9\\.\\_]{1,})?", rw=ReadWriteAccess.WRITEONCE) @Column(name="name", columnDefinition = "character varying(24)", unique=true, updatable=false) private String name; diff --git a/hsarback/test/de/hsadmin/validate/PacName.java b/hsarback/test/de/hsadmin/validate/PacName.java deleted file mode 100644 index d77a213..0000000 --- a/hsarback/test/de/hsadmin/validate/PacName.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.hsadmin.validate; - -import java.util.regex.Pattern; - - -public class PacName { - - public static void main(String[] args) { - Pattern pattern = Pattern.compile("[a-z0-9]{5}-[a-z0-9\\.\\_]{1,}"); - System.out.println("xyz00-a.b " + pattern.matcher("xyz00-a.b").matches()); - System.out.println("xyz00-a-b " + pattern.matcher("xyz00-a-b").matches()); - System.out.println("xyz00-a.B " + pattern.matcher("xyz00-a.B").matches()); - System.out.println("xyz00- " + pattern.matcher("xyz00-").matches()); - System.out.println("xyz00 " + pattern.matcher("xyz00").matches()); - System.out.println("xyz0 " + pattern.matcher("xyz0").matches()); - System.out.println("xyz00_a " + pattern.matcher("xyz00_a").matches()); - System.out.println("xyz00-a.b:c " + pattern.matcher("xyz00-a.b:c").matches()); - } - -} diff --git a/hsarback/test/de/hsadmin/validate/PacNameTest.java b/hsarback/test/de/hsadmin/validate/PacNameTest.java new file mode 100644 index 0000000..59c2f15 --- /dev/null +++ b/hsarback/test/de/hsadmin/validate/PacNameTest.java @@ -0,0 +1,36 @@ +package de.hsadmin.validate; + +import java.util.regex.Pattern; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class PacNameTest { + + private Pattern pattern; + + @Before + public void setUp() throws Exception { + pattern = Pattern.compile("[a-z0-9]{5}(-[a-z0-9\\.\\_]{1,})?"); + } + + @After + public void tearDown() throws Exception { + pattern = null; + } + + @Test + public void test() { + Assert.assertTrue("xyz00-a.b", pattern.matcher("xyz00-a.b").matches()); + Assert.assertFalse("xyz00-a-b", pattern.matcher("xyz00-a-b").matches()); + Assert.assertFalse("xyz00-a.B", pattern.matcher("xyz00-a.B").matches()); + Assert.assertFalse("xyz00-", pattern.matcher("xyz00-").matches()); + Assert.assertTrue("xyz00", pattern.matcher("xyz00").matches()); + Assert.assertFalse("xyz0", pattern.matcher("xyz0").matches()); + Assert.assertFalse("xyz00_a", pattern.matcher("xyz00_a").matches()); + Assert.assertFalse("xyz00-a.b:c", pattern.matcher("xyz00-a.b:c").matches()); + } + +}