// embeddedRegistryService = new InMemoryEmbeddedRegistryService();
// get the realm config to retrieve admin username, password
RealmConfiguration realmConfig = ctx.getRealmService().getBootstrapRealmConfiguration();
UserRegistry adminRegistry = embeddedRegistryService.
getUserRegistry(realmConfig.getAdminUserName(), realmConfig.getAdminPassword());
UserRealm adminRealm = adminRegistry.getUserRealm();
adminRealm.getUserStoreManager().addUser("foo", "cce123", null, null, null);
adminRealm.getUserStoreManager();
adminRealm.getAuthorizationManager().
authorizeUser("foo", RegistryConstants.ROOT_PATH, ActionConstants.PUT);
adminRealm.getUserStoreManager().addUser("bar", "swe123", null, null, null);
UserRegistry fooRegistry = embeddedRegistryService.getUserRegistry("foo", "cce123");
UserRegistry barRegistry = embeddedRegistryService.getUserRegistry("bar", "swe123");
String r1Content = "R1";
Resource r1 = fooRegistry.newResource();
r1.setContent(r1Content.getBytes());
fooRegistry.put("/r1", r1);
adminRegistry.applyTag("/r1", "java");
fooRegistry.applyTag("/r1", "java");
barRegistry.applyTag("/r1", "java");
Tag[] tags1 = adminRegistry.getTags("/r1");
assertEquals("There should be 3 taggings on resource '/r1'", 3, tags1[0].getTagCount());
// owner of the /r1 removes a tag. all tags should be removed
fooRegistry.removeTag("/r1", "java");
Tag[] tags2 = adminRegistry.getTags("/r1");
assertEquals("There should be 0 taggings on resource '/r1'", 0, tags2.length);
adminRegistry.applyTag("/r1", "java");
fooRegistry.applyTag("/r1", "java");
barRegistry.applyTag("/r1", "java");
// admin removes a tag. all tags should be removed
adminRegistry.removeTag("/r1", "java");
Tag[] tags3 = adminRegistry.getTags("/r1");
assertEquals("There should be 0 taggings on resource '/r1'", 0, tags3.length);
adminRegistry.applyTag("/r1", "java");
fooRegistry.applyTag("/r1", "java");
barRegistry.applyTag("/r1", "java");
// normal user removes a tag. only the tag applied by the user is removed
barRegistry.removeTag("/r1", "java");
Tag[] tags4 = adminRegistry.getTags("/r1");
assertEquals("There should be 2 taggings on resource '/r1'", 2, tags4[0].getTagCount());
}