Skip to content

Commit

Permalink
Merge pull request #42 from efroese/master
Browse files Browse the repository at this point in the history
More tests and a bug in Authorizable.removeProperty
  • Loading branch information
ieb committed May 10, 2011
2 parents 0b4abe8 + 844ac55 commit 617f749
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 45 deletions.
Expand Up @@ -272,9 +272,9 @@ public Object getProperty(String name) {
* remove the property.
* @param name
*/
public void removeProperty(String name) {
if (!readOnly && authorizableMap.containsKey(name)) {
modifiedMap.put(name, new RemoveProperty());
public void removeProperty(String key) {
if (!readOnly && (authorizableMap.containsKey(key) || modifiedMap.containsKey(key))) {
modifiedMap.put(key, new RemoveProperty());
}
}

Expand Down
@@ -0,0 +1,92 @@
package org.sakaiproject.nakamura.api.lite.authorizable;

import java.util.HashMap;
import java.util.Map;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class AuthorizableTest {

protected Authorizable u;

@Before
public void setup(){
u = new User(new HashMap<String, Object>());
}

/**
* A non-anonymous user has the EVERYONE principal.
*/
@Test
public void testInitEmpty(){
Assert.assertEquals(1, u.getPrincipals().length);
Assert.assertEquals(Group.EVERYONE, u.getPrincipals()[0]);
}

/**
* The anonymous user has no principals.
*/
@Test
public void testInitAnonymous(){
Map<String,Object> props = new HashMap<String, Object>();
props.put(Authorizable.ID_FIELD, User.ANON_USER);
Authorizable a = new User(props);
Assert.assertEquals(0, a.getPrincipals().length);
}

@Test
public void testInitPrincipals(){
Map<String,Object> props = new HashMap<String, Object>();
props.put(Authorizable.PRINCIPALS_FIELD, "principal1-managers;principal2");
Authorizable a = new User(props);
// principal1-managers, principal2, Group.EVERYONE
Assert.assertEquals(3, a.getPrincipals().length);
}

@Test
public void testHasProperty(){
Assert.assertFalse(u.hasProperty("anykey"));
u.setProperty("anykey", "where's the any key?");
Assert.assertTrue(u.hasProperty("anykey"));
}

/**
* Reset the {@link Authorizable} properties with new ones.
* Old properties should no longer be present.
*/
@Test
public void testReset(){
u.setProperty("anykey", "where's the any key?");

Map<String, Object> newProps = new HashMap<String, Object>();
newProps.put("tab", "No time for that the computer's starting!");
u.reset(newProps);

Assert.assertFalse(u.hasProperty("anykey"));
Assert.assertTrue(u.hasProperty("tab"));
Assert.assertEquals(0, u.modifiedMap.size());
}

/**
* Reset the {@link Authorizable} properties with an empty {@link HashMap}.
* No properties should be present.
*/
@Test
public void testResetEmpty(){
u.setProperty("anykey", "where's the any key?");
u.reset(new HashMap<String, Object>());
Assert.assertFalse(u.hasProperty("anykey"));
Assert.assertEquals(0, u.modifiedMap.size());
}

@Test
public void testRemoveProperty(){
Authorizable u = new User(new HashMap<String, Object>());
u.setProperty("anykey", "where's the any key?");
Assert.assertTrue(u.hasProperty("anykey"));
u.removeProperty("anykey");
Assert.assertFalse(u.hasProperty("anykey"));
}
}

This file was deleted.

0 comments on commit 617f749

Please sign in to comment.