test regexp validation
This commit is contained in:
parent
bab2f0356f
commit
53d2f38fa0
@ -9,6 +9,7 @@ import de.hsadmin.module.property.ReadWritePolicy;
|
|||||||
import de.hsadmin.module.property.Required;
|
import de.hsadmin.module.property.Required;
|
||||||
import de.hsadmin.module.property.Search;
|
import de.hsadmin.module.property.Search;
|
||||||
import de.hsadmin.module.property.SearchPolicy;
|
import de.hsadmin.module.property.SearchPolicy;
|
||||||
|
import de.hsadmin.module.property.StringSet;
|
||||||
|
|
||||||
public class LdapUserVO extends AbstractVO {
|
public class LdapUserVO extends AbstractVO {
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ public class LdapUserVO extends AbstractVO {
|
|||||||
private String nickName;
|
private String nickName;
|
||||||
|
|
||||||
@ReadWrite(ReadWritePolicy.READWRITE)
|
@ReadWrite(ReadWritePolicy.READWRITE)
|
||||||
private String[] sshPublicKey;
|
private StringSet sshPublicKey;
|
||||||
|
|
||||||
public LdapUserVO() throws TechnicalException {
|
public LdapUserVO() throws TechnicalException {
|
||||||
super();
|
super();
|
||||||
@ -120,14 +121,12 @@ public class LdapUserVO extends AbstractVO {
|
|||||||
this.nickName = nickName;
|
this.nickName = nickName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getSshPublicKey() {
|
public StringSet getSshPublicKey() {
|
||||||
return sshPublicKey;
|
return sshPublicKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSshPublicKey(String[] sshPublicKey) {
|
public void setSshPublicKey(StringSet sshPublicKey) {
|
||||||
this.sshPublicKey = sshPublicKey;
|
this.sshPublicKey = sshPublicKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,82 @@
|
|||||||
|
package de.hsadmin.service.ldap;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import de.hsadmin.common.error.TechnicalException;
|
||||||
|
import de.hsadmin.common.error.UserError;
|
||||||
|
import de.hsadmin.common.error.UserException;
|
||||||
|
import de.hsadmin.module.impl.ValidationDelegate;
|
||||||
|
import de.hsadmin.module.property.StringProperty;
|
||||||
|
|
||||||
|
public class ValidationTest {
|
||||||
|
|
||||||
|
private LdapUserVO vo;
|
||||||
|
private ValidationDelegate<LdapUserVO> val;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
vo = new LdapUserVO();
|
||||||
|
val = new ValidationDelegate<LdapUserVO>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
vo = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetUid() {
|
||||||
|
final String uidFail = "ac-someuid";
|
||||||
|
try {
|
||||||
|
((StringProperty) vo.get("uid")).setValue(uidFail);
|
||||||
|
String uid = vo.getUid();
|
||||||
|
assertEquals(uidFail, uid);
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final String uidOk = "abc-someuid";
|
||||||
|
final String mailOk = "someone@example.org";
|
||||||
|
final String snOk = "Mustermann";
|
||||||
|
try {
|
||||||
|
((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.checkPrototypeIsCreateable(vo);
|
||||||
|
} catch (UserException | TechnicalException e) {
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user