more validation tests

This commit is contained in:
Peter Hormanns 2018-08-24 20:56:31 +02:00
parent 53d2f38fa0
commit 1aef34a46a
2 changed files with 58 additions and 75 deletions

View File

@ -127,27 +127,6 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>migratePostgresLiquibaseChangeLogToH2</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${project.basedir}/scripts/migratePostgresLiquibaseChangeLogToH2.${script.extension}</executable>
<arguments>
<argument>${project.parent.basedir}/db-migration/src/main/resources/liquibase/db.changelog.xml</argument>
<argument>${project.build.directory}/classes/liquibase/db.changelog.xml</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin> <plugin>
<groupId>org.apache.openejb.maven</groupId> <groupId>org.apache.openejb.maven</groupId>
<artifactId>tomee-maven-plugin</artifactId> <artifactId>tomee-maven-plugin</artifactId>
@ -164,34 +143,6 @@
</libs> </libs>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-maven-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<includes>**/bo/*.class</includes>
<addDefaultConstructor>true</addDefaultConstructor>
<enforcePropertyRestrictions>true</enforcePropertyRestrictions>
</configuration>
<executions>
<execution>
<id>enhancer</id>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<!-- set the version to be the same as the level in your runtime -->
<version>2.4.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
</plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

View File

@ -20,6 +20,18 @@ public class ValidationTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
vo = new LdapUserVO(); vo = new LdapUserVO();
final String uidOk = "abc-someuid";
final String mailOk = "someone@example.org";
final String snOk = "Mustermann";
((StringProperty) vo.get("uid")).setValue(uidOk);
String uid = vo.getUid();
assertEquals(uidOk, uid);
((StringProperty) vo.get("mail")).setValue(mailOk);
String mail = vo.getMail();
assertEquals(mailOk, mail);
((StringProperty) vo.get("sn")).setValue(snOk);
String sn = vo.getSn();
assertEquals(snOk, sn);
val = new ValidationDelegate<LdapUserVO>(); val = new ValidationDelegate<LdapUserVO>();
} }
@ -30,6 +42,11 @@ public class ValidationTest {
@Test @Test
public void testSetUid() { public void testSetUid() {
try {
val.checkPrototypeIsCreateable(vo);
} catch (UserException | TechnicalException e) {
fail(e.getMessage());
}
final String uidFail = "ac-someuid"; final String uidFail = "ac-someuid";
try { try {
((StringProperty) vo.get("uid")).setValue(uidFail); ((StringProperty) vo.get("uid")).setValue(uidFail);
@ -45,38 +62,53 @@ public class ValidationTest {
fail(e.getMessage()); fail(e.getMessage());
} }
} }
final String uidOk = "abc-someuid"; }
final String mailOk = "someone@example.org";
final String snOk = "Mustermann"; @Test
public void testSetMail() {
final String mailFail = "someuid";
try { try {
((StringProperty) vo.get("uid")).setValue(uidOk); ((StringProperty) vo.get("mail")).setValue(mailFail);
String uid = vo.getUid();
assertEquals(uidOk, uid);
((StringProperty) vo.get("mail")).setValue(mailOk);
String mail = vo.getMail(); String mail = vo.getMail();
assertEquals(mailOk, mail); assertEquals(mailFail, mail);
((StringProperty) vo.get("sn")).setValue(snOk); val.checkPrototypeIsCreateable(vo);
String sn = vo.getSn(); fail("expect UserException");
assertEquals(snOk, sn); } catch (UserException | TechnicalException e) {
if (e instanceof UserException) {
UserException ue = (UserException) e;
assertTrue("expect validationerror " + UserError.MSG_FIELD_DOESNOT_VALIDATE, ue.hasError(UserError.MSG_FIELD_DOESNOT_VALIDATE));
} else {
fail(e.getMessage());
}
}
}
@Test
public void testSetMobile() {
try {
final String phoneFail = "+49 1234 S55678";
((StringProperty) vo.get("mobile")).setValue(phoneFail);
String mobile = vo.getMobile();
assertEquals(phoneFail, mobile);
val.checkPrototypeIsCreateable(vo);
fail("expect UserException");
} catch (UserException | TechnicalException e) {
if (e instanceof UserException) {
UserException ue = (UserException) e;
assertTrue("expect validationerror " + UserError.MSG_FIELD_DOESNOT_VALIDATE, ue.hasError(UserError.MSG_FIELD_DOESNOT_VALIDATE));
} else {
fail(e.getMessage());
}
}
try {
final String phoneOk = "+49 1234 555678";
((StringProperty) vo.get("mobile")).setValue(phoneOk);
String mobile = vo.getMobile();
assertEquals(phoneOk, mobile);
val.checkPrototypeIsCreateable(vo); val.checkPrototypeIsCreateable(vo);
} catch (UserException | TechnicalException e) { } catch (UserException | TechnicalException e) {
fail(e.getMessage()); fail(e.getMessage());
} }
} }
// @Test
public void testSetMail() {
fail("Not yet implemented");
}
// @Test
public void testSetMobile() {
fail("Not yet implemented");
}
// @Test
public void testSetNickName() {
fail("Not yet implemented");
}
} }