Search in sources :

Example 1 with AnonymizationNotSupportedException

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);
    }
}
Also used : AnonymizationNotSupportedException(cz.metacentrum.perun.core.api.exceptions.AnonymizationNotSupportedException) Attribute(cz.metacentrum.perun.core.api.Attribute) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)1 Attribute (cz.metacentrum.perun.core.api.Attribute)1 AnonymizationNotSupportedException (cz.metacentrum.perun.core.api.exceptions.AnonymizationNotSupportedException)1 Test (org.junit.Test)1