X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=security%2Fimpl%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fsecurity%2Fauthorization%2FDefaultOperationRegistryTest.java;fp=security%2Fimpl%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fsecurity%2Fauthorization%2FDefaultOperationRegistryTest.java;h=e09f7fa1cd52ff93535143dc829ab49dcd41e16f;hb=5ea8f0e2af53562c1507e8fb5a3ede2af5c5de6c;hp=0000000000000000000000000000000000000000;hpb=b9eccdf9751b8e2e671e0792f885d05c6ed0f43c;p=utils diff --git a/security/impl/src/test/java/org/wamblee/security/authorization/DefaultOperationRegistryTest.java b/security/impl/src/test/java/org/wamblee/security/authorization/DefaultOperationRegistryTest.java new file mode 100644 index 00000000..e09f7fa1 --- /dev/null +++ b/security/impl/src/test/java/org/wamblee/security/authorization/DefaultOperationRegistryTest.java @@ -0,0 +1,77 @@ +/* + * Copyright 2005-2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wamblee.security.authorization; + +import junit.framework.TestCase; + +/** + * Test of the operation registry. + * + * @author Erik Brakkee + */ +public class DefaultOperationRegistryTest extends TestCase { + private OperationRegistry registry; + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + registry = new DefaultOperationRegistry(new Operation[] { + new AllOperation(), new ReadOperation(), new WriteOperation(), + new DeleteOperation(), new CreateOperation() }); + } + + /** + * Tests encoding and decoding of no operations. + */ + public void testEncodeDecodeNooperations() { + assertEquals("", registry.encode(new Operation[0])); + assertEquals(0, registry.decode(Object.class, "").length); + } + + /** + * Verifies that encoding of operations into a string works. + */ + public void testEncode() { + assertEquals("read,write", registry.encode(new Operation[] { + new ReadOperation(), new WriteOperation() })); + } + + /** + * Verifies that decoding of operation from a string works. + */ + public void testDecode() { + Operation[] operations = registry.decode(Object.class, "read,write"); + assertTrue(operations[0] instanceof ReadOperation); + assertTrue(operations[1] instanceof WriteOperation); + } + + /** + * Verifies that an IllegalArgumentException occurs when attempting to + * decode an operation that is not known. + */ + public void testDecodeUnknownOperation() { + try { + registry.decode(Object.class, "bla"); + fail(); + } catch (IllegalArgumentException e) { + // ok + } + } +}