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.
17 package org.wamblee.security.authorization;
19 import junit.framework.TestCase;
22 * Test of the operation registry.
24 * @author Erik Brakkee
26 public class DefaultOperationRegistryTest extends TestCase {
28 private OperationRegistry _registry;
31 * @see junit.framework.TestCase#setUp()
34 protected void setUp() throws Exception {
36 _registry = new DefaultOperationRegistry(new Operation[] {
40 new DeleteOperation(),
46 * Tests encoding and decoding of no operations.
49 public void testEncodeDecodeNooperations() {
50 assertEquals("", _registry.encode(new Operation[0]));
51 assertEquals(0, _registry.decode(Object.class, "").length);
55 * Verifies that encoding of operations into a string works.
58 public void testEncode() {
59 assertEquals("read,write", _registry.encode(new Operation[] { new ReadOperation(), new WriteOperation() }));
63 * Verifies that decoding of operation from a string works.
66 public void testDecode() {
67 Operation[] operations = _registry.decode(Object.class, "read,write");
68 assertTrue( operations[0] instanceof ReadOperation);
69 assertTrue( operations[1] instanceof WriteOperation);
73 * Verifies that an IllegalArgumentException occurs when attempting to decode
74 * an operation that is not known.
77 public void testDecodeUnknownOperation() {
79 _registry.decode(Object.class, "bla");
81 } catch (IllegalArgumentException e) {