2 * Copyright 2005-2010 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.security.authorization;
18 import junit.framework.TestCase;
21 * Test of the operation registry.
23 * @author Erik Brakkee
25 public class DefaultOperationRegistryTest extends TestCase {
26 private OperationRegistry registry;
31 * @see junit.framework.TestCase#setUp()
34 protected void setUp() throws Exception {
35 registry = new DefaultOperationRegistry(new Operation[] {
36 new AllOperation(), new ReadOperation(), new WriteOperation(),
37 new DeleteOperation(), new CreateOperation() });
41 * Tests encoding and decoding of no operations.
43 public void testEncodeDecodeNooperations() {
44 assertEquals("", registry.encode(new Operation[0]));
45 assertEquals(0, registry.decode(Object.class, "").length);
49 * Verifies that encoding of operations into a string works.
51 public void testEncode() {
52 assertEquals("read,write", registry.encode(new Operation[] {
53 new ReadOperation(), new WriteOperation() }));
57 * Verifies that decoding of operation from a string works.
59 public void testDecode() {
60 Operation[] operations = registry.decode(Object.class, "read,write");
61 assertTrue(operations[0] instanceof ReadOperation);
62 assertTrue(operations[1] instanceof WriteOperation);
66 * Verifies that an IllegalArgumentException occurs when attempting to
67 * decode an operation that is not known.
69 public void testDecodeUnknownOperation() {
71 registry.decode(Object.class, "bla");
73 } catch (IllegalArgumentException e) {