01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.pluto.util.impl;
18:
19: import org.apache.pluto.PortletWindowID;
20: import org.apache.pluto.util.PlutoTestCase;
21: import org.apache.pluto.util.NamespaceMapper;
22:
23: /**
24: * Test Class
25: *
26: * @version 1.0
27: * @since June 1, 2005
28: */
29: public class NamespaceMapperImplTest extends PlutoTestCase {
30:
31: private final NamespaceMapper mapper = new NamespaceMapperImpl();
32: private PortletWindowID id1;
33: private PortletWindowID id2;
34:
35: public void setUp() throws Exception {
36: super .setUp();
37: id1 = new InternalPortletWindowID();
38: id2 = new InternalPortletWindowID();
39: }
40:
41: public void testEncodeUniquenessWithSameName() {
42: String mappedA = mapper.encode(id1, "testNumber1");
43: String mappedB = mapper.encode(id2, "testNumber1");
44: assertFalse(mappedA.equals(mappedB));
45: }
46:
47: public void testEncodeUniquenessWithSameObjectID() {
48: String mappedA = mapper.encode(id1, "testNumber1");
49: String mappedB = mapper.encode(id1, "testNumber2");
50: assertFalse(mappedA.equals(mappedB));
51: }
52:
53: public void testDecode() {
54: String original = "original";
55: String mappedA = mapper.encode(id1, original);
56: assertEquals(original, mapper.decode(id1, mappedA));
57: }
58:
59: public void testDecodeInvalidId() {
60: assertNull(mapper.decode(id1, mapper.encode(id2, "test")));
61: }
62:
63: private static int objectIDCounter = 1;
64:
65: private class InternalPortletWindowID implements PortletWindowID {
66:
67: private final int id;
68:
69: public InternalPortletWindowID() {
70: id = objectIDCounter++;
71: }
72:
73: public String getStringId() {
74: return "uniqueId" + id;
75: }
76: }
77: }
|