NIHVIVO-1232 Pull the code that covers restricted Namespaces and URIs into its own class.

This commit is contained in:
jeb228 2010-12-02 19:11:13 +00:00
parent 5cc801ee2c
commit d27c258ad5
4 changed files with 360 additions and 266 deletions

View file

@ -0,0 +1,45 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.auth.policy;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
/**
* TODO
*/
public class AdministrativeUriRestrictorTest extends AbstractTestClass {
private static final String SAFE_NS = "http://test.mannlib.cornell.edu/ns/01#";
private static final String UNSAFE_NS = VitroVocabulary.vitroURI;
private static final String SAFE_RESOURCE = SAFE_NS + "otherIndividual77777";
private static final String UNSAFE_RESOURCE = UNSAFE_NS + "otherIndividual99999";
private static final String SAFE_PREDICATE = SAFE_NS + "hasHairStyle";
private static final String UNSAFE_PREDICATE = UNSAFE_NS + "hasSuperPowers";
private AdministrativeUriRestrictor restrictor;
@Before
public void setup() {
restrictor = new AdministrativeUriRestrictor(null, null, null, null);
}
@Test
public void testCanModifiyNs(){
Assert.assertTrue( restrictor.canModifyResource("http://bobs.com#hats") );
Assert.assertTrue( restrictor.canModifyResource("ftp://bobs.com#hats"));
Assert.assertTrue( restrictor.canModifyResource( SAFE_RESOURCE ));
Assert.assertTrue( restrictor.canModifyPredicate( SAFE_PREDICATE ));
Assert.assertTrue( restrictor.canModifyResource("http://bobs.com/hats"));
Assert.assertTrue( ! restrictor.canModifyResource(""));
Assert.assertTrue( ! restrictor.canModifyResource(VitroVocabulary.vitroURI + "something"));
Assert.assertTrue( ! restrictor.canModifyResource(VitroVocabulary.OWL + "Ontology"));
Assert.assertTrue( ! restrictor.canModifyPredicate( UNSAFE_PREDICATE ));
Assert.assertTrue( ! restrictor.canModifyResource( UNSAFE_RESOURCE ));
Assert.assertTrue( ! restrictor.canModifyResource( UNSAFE_NS ));
}
}

View file

@ -7,12 +7,10 @@ import static edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization.
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static org.junit.Assert.*;
import java.util.HashSet;
import java.util.Set;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@ -72,24 +70,6 @@ public class SelfEditingPolicyTest extends AbstractTestClass {
}
@Test
public void testCanModifiyNs(){
Assert.assertTrue( policy.canModifyResource("http://bobs.com#hats") );
Assert.assertTrue( policy.canModifyResource("ftp://bobs.com#hats"));
Assert.assertTrue( policy.canModifyResource( SAFE_RESOURCE ));
Assert.assertTrue( policy.canModifyPredicate( SAFE_PREDICATE ));
Assert.assertTrue( policy.canModifyResource("http://bobs.com/hats"));
Assert.assertTrue( ! policy.canModifyResource(""));
Assert.assertTrue( ! policy.canModifyResource(VitroVocabulary.vitroURI + "something"));
Assert.assertTrue( ! policy.canModifyResource(VitroVocabulary.OWL + "Ontology"));
Assert.assertTrue( ! policy.canModifyPredicate( UNSAFE_PREDICATE ));
Assert.assertTrue( ! policy.canModifyResource( UNSAFE_RESOURCE ));
Assert.assertTrue( ! policy.canModifyResource( UNSAFE_NS ));
}
@Test
public void testProhibitedProperties() {
Set<String> badProps = new HashSet<String>();