use of cz.metacentrum.perun.core.api.exceptions.AnonymizationNotSupportedException in project perun by CESNET.
the class UsersManagerEntryIntegrationTest method anonymizeUserWhenAnonymizationNotSupported.
@Test
public void anonymizeUserWhenAnonymizationNotSupported() throws Exception {
System.out.println(CLASS_NAME + "anonymizeUserWhenAnonymizationNotSupported");
List<String> originalAttributesToAnonymize = BeansUtils.getCoreConfig().getAttributesToAnonymize();
// configure attributesToAnonymize so it contains only 1 attribute - dummy-test
BeansUtils.getCoreConfig().setAttributesToAnonymize(Collections.singletonList(AttributesManager.NS_USER_ATTR_DEF + ":dummy-test"));
// create dummy attribute
Attribute attrLogin = new Attribute();
attrLogin.setNamespace(AttributesManager.NS_USER_ATTR_DEF);
attrLogin.setFriendlyName("dummy-test");
attrLogin.setType(String.class.getName());
perun.getAttributesManager().createAttribute(sess, attrLogin);
// set dummy attribute
Attribute dummy = perun.getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":dummy-test");
dummy.setValue("dummy");
perun.getAttributesManagerBl().setAttribute(sess, user, dummy);
try {
usersManager.anonymizeUser(sess, user);
// anonymizeUser() should have thrown AnonymizationNotSupportedException
fail();
} catch (AnonymizationNotSupportedException ex) {
// this is expected
} finally {
// set attributesToAnonymize back to the original attributes
BeansUtils.getCoreConfig().setAttributesToAnonymize(originalAttributesToAnonymize);
}
}
Aggregations