Mod aaa-12 完善 h2store 以及 idmLightConfig类的测试用例

RCA:
SOL:
修改人:maxiaonan
检视人:maxiaonan
This commit is contained in:
maxiaonan 2019-07-25 15:14:19 +08:00
parent eb3a304683
commit dd55166b28
2 changed files with 59 additions and 1 deletions

View File

@ -102,9 +102,25 @@ public class H2StoreTest {
assertNotNull(h2Store.readUser(user.getUserid()));
user.setEnabled(false);
assertNotNull(h2Store.updateUser(user));
try{
user.setEmail(getExpectName());
h2Store.updateUser(user);
fail("update user error");
}catch (IDMStoreException e){
assertThat(e.getMessage(),containsString("SQL Exception"));
}
assertFalse(h2Store.readUser(user.getUserid()).isEnabled());
assertNotNull(h2Store.deleteUser(user.getUserid()));
}
private String getExpectName() {
return "1221r13r1rfdfsafsdfadfadfasfadsfdsfdaf" +
"dsfdsfafsdfadfasfsafdsafdfaadfdaffgdsfa" +
"safdsafafsafdasgfdsafdsafagadfadsfdsfdafda" +
"adfasdfdsafadsfsag4ef2313414r314313143113431" +
"1431413241231543143143154354321r3243fdsf3rfdr32f";
}
@Test
public void writeUserTest() throws IDMStoreException {
User user = mockUser("test3");
@ -136,6 +152,13 @@ public class H2StoreTest {
}
role.setName("changeRole");
assertNotNull(h2Store.updateRole(role));
try{
role.setDescription(getExpectName());
h2Store.updateRole(role);
fail("update role error");
}catch (IDMStoreException e){
assertThat(e.getMessage(),containsString("SQL Exception"));
}
assertNotNull(h2Store.readRole(role.getRoleid()));
assertNotNull(h2Store.deleteRole(role.getRoleid()));
}
@ -161,8 +184,14 @@ public class H2StoreTest {
}
domain.setName("changeDomain");
assertNotNull(h2Store.updateDomain(domain));
try{
domain.setName(getExpectName());
h2Store.updateDomain(domain);
fail("update domain error");
}catch (IDMStoreException e){
assertThat(e.getMessage(),containsString("Error updating domain"));
}
assertNotNull(h2Store.readDomain(domain.getDomainid()));
h2Store.readDomain("111");
assertNotNull(h2Store.deleteDomain(domain.getDomainid()));
}

View File

@ -14,6 +14,9 @@
package org.opendaylight.aaa.datastore.h2;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import java.io.File;
@ -61,9 +64,35 @@ public class IdmLightConfigTest {
public void testIdmBuilder() {
IdmLightConfigBuilder builder = new IdmLightConfigBuilder().dbUser("foo").dbPwd("bar");
builder.dbName("idmlight.db");
builder.dbDriver("org.h2.Driver");
builder.dbValidTimeOut(3);
builder.dbConnectionStringPrefix("jdbc:h2:");
IdmLightConfig config = builder.build();
IdmLightConfig config2 = builder.build();
assertNotNull(config.toString());
assertEquals(config.hashCode(),checkHashCode(config));
assertEquals(config, config2);
assertThat(config.getDbConnectionString())
.isEqualTo("jdbc:h2:./data" + File.separatorChar + "idmlight.db");
assertThat(config.getDbDriver())
.isEqualTo("org.h2.Driver");
assertThat(config.getDbValidTimeOut()).isEqualTo(3);
assertThat(config.getDbConnectionStringPrefix()).isEqualTo("jdbc:h2:");
}
private int checkHashCode(IdmLightConfig config) {
int h = 5381;
h += (h << 5) + config.getDbName().hashCode();
h += (h << 5) + config.getDbDirectory().hashCode();
h += (h << 5) + config.getDbDriver().hashCode();
h += (h << 5) + config.getDbUser().hashCode();
h += (h << 5) + config.getDbPwd().hashCode();
h += (h << 5) + config.getDbValidTimeOut();
h += (h << 5) + config.getDbConnectionStringPrefix().hashCode();
h += (h << 5) + config.getDbConnectionString().hashCode();
return h;
}
}