FileUtils.copyURLToFile(getClass().getResource("usersTemplate.xml"),xmlFile);
GeoServerUserGroupService service1 =
createUserGroupService("locking1",xmlFile.getCanonicalPath());
GeoServerUserGroupService service2 =
createUserGroupService("locking2",xmlFile.getCanonicalPath());
GeoServerUserGroupStore store1= createStore(service1);
GeoServerUserGroupStore store2= createStore(service2);
GeoServerUser user = store1.createUserObject("user", "ps", true);
GeoServerUserGroup group = store2.createGroupObject("group", true);
// obtain a lock
store1.addUser(user);
boolean fail;
String failMessage="Concurrent lock not allowed";
fail=true;
try {
store2.clear();
} catch (IOException ex) {
fail=false;
}
if (fail)
Assert.fail(failMessage);
// release lock
store1.load();
// get lock
store2.addUser(user);
fail=true;
try {
store1.clear();
} catch (IOException ex) {
fail=false;
}
if (fail)
Assert.fail(failMessage);
// release lock
store2.store();
store1.clear();
store1.store();
//// end of part one, now check all modifying methods
// obtain a lock
store1.addUser(user);
fail=true;
try {
store2.associateUserToGroup(user, group);
} catch (IOException ex) {
try {
store2.disAssociateUserFromGroup(user, group);
} catch (IOException e) {
fail=false;
}
}
if (fail)
Assert.fail(failMessage);
fail=true;
try {
store2.updateUser(user);
} catch (IOException ex) {
try {
store2.removeUser(user);
} catch (IOException ex1) {
try {
store2.addUser(user);
} catch (IOException ex2) {
fail=false;
}
}
}
if (fail)
Assert.fail(failMessage);
fail=true;
try {
store2.updateGroup(group);
} catch (IOException ex) {
try {
store2.removeGroup(group);
} catch (IOException ex1) {
try {
store2.addGroup(group);
} catch (IOException ex2) {
fail=false;
}
}
}
if (fail)
Assert.fail(failMessage);
fail=true;
try {
store2.clear();
} catch (IOException ex) {
try {
store2.store();
} catch (IOException e) {
fail=false;
}
}
if (fail)