2 * Copyright 2005 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;
22 * Test of the operation registry.
24 * @author Erik Brakkee
26 public class DefaultOperationRegistryTest extends TestCase {
30 private OperationRegistry registry;
33 * @see junit.framework.TestCase#setUp()
38 * @throws Exception DOCUMENT ME!
41 protected void setUp() throws Exception {
42 registry = new DefaultOperationRegistry(new Operation[] {
43 new AllOperation(), new ReadOperation(),
44 new WriteOperation(), new DeleteOperation(),
50 * Tests encoding and decoding of no operations.
52 public void testEncodeDecodeNooperations() {
53 assertEquals("", registry.encode(new Operation[0]));
54 assertEquals(0, registry.decode(Object.class, "").length);
58 * Verifies that encoding of operations into a string works.
60 public void testEncode() {
61 assertEquals("read,write",
63 new Operation[] { new ReadOperation(), new WriteOperation() }));
67 * Verifies that decoding of operation from a string works.
69 public void testDecode() {
70 Operation[] operations = registry.decode(Object.class, "read,write");
71 assertTrue(operations[0] instanceof ReadOperation);
72 assertTrue(operations[1] instanceof WriteOperation);
76 * Verifies that an IllegalArgumentException occurs when attempting
77 * to decode an operation that is not known.
79 public void testDecodeUnknownOperation() {
81 registry.decode(Object.class, "bla");
83 } catch (IllegalArgumentException e) {