2 * Copyright 2005-2011 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.xmlrouter.impl;
18 import static junit.framework.Assert.*;
19 import static org.mockito.Mockito.*;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.wamblee.xmlrouter.common.Id;
24 import org.wamblee.xmlrouter.config.DocumentType;
25 import org.wamblee.xmlrouter.config.Filter;
26 import org.wamblee.xmlrouter.config.RouterConfig;
27 import org.wamblee.xmlrouter.config.Transformation;
29 public class SingleRouterConfigTest {
31 private ExtendedRouterConfig config;
35 config = new SingleRouterConfig(new Id<RouterConfig>("routerconfig"));
36 assertEquals("routerconfig", config.getId().getId());
40 public void testDocumentType() {
41 DocumentType type1 = mock(DocumentType.class);
42 when(type1.getId()).thenReturn(new Id<DocumentType>("type1"));
43 DocumentType type2 = mock(DocumentType.class);
44 when(type2.getId()).thenReturn(new Id<DocumentType>("type2"));
46 config.documentTypeConfig().add(type1);
47 config.documentTypeConfig().add(type2);
49 assertEquals(2, config.documentTypeConfig().values().size());
50 Object firstValue = config.documentTypeConfig().values().iterator()
52 assertTrue(firstValue instanceof RobustDocumentType);
56 public void testTransformation() {
57 Transformation transformation1 = mock(Transformation.class);
58 when(transformation1.getId()).thenReturn(new Id<Transformation>("t1"));
59 Transformation transformation2 = mock(Transformation.class);
60 when(transformation2.getId()).thenReturn(new Id<Transformation>("t2"));
62 config.transformationConfig().add(transformation1);
64 config.transformationConfig().add(transformation2);
66 assertEquals(2, config.transformationConfig().values().size());
67 Object firstValue = config.transformationConfig().values().iterator()
69 assertTrue(firstValue instanceof RobustTransformation);
73 public void testFilter() {
74 Filter filter1 = mock(Filter.class);
75 when(filter1.getId()).thenReturn(new Id<Filter>("f1"));
76 Filter filter2 = mock(Filter.class);
77 when(filter2.getId()).thenReturn(new Id<Filter>("f2"));
79 config.filterConfig().add(filter1);
81 config.filterConfig().add(filter2);
83 assertEquals(2, config.filterConfig().values().size());
84 Object firstValue = config.filterConfig().values().iterator().next();
85 assertTrue(firstValue instanceof RobustFilter);
89 public void testEqualityEmptyConfig() {
90 RouterConfig config1 = new SingleRouterConfig(new Id<RouterConfig>(
92 RouterConfig config2 = new SingleRouterConfig(new Id<RouterConfig>(
94 assertEquals(config1, config2);
98 public void testEqualsNonEmpty() {
99 RouterConfig config1 = new SingleRouterConfig(new Id<RouterConfig>(
102 assertFalse(config1.equals(null));
103 assertFalse(config.equals("hello"));
105 RouterConfig config2 = new SingleRouterConfig(new Id<RouterConfig>(
107 DocumentType type1 = mock(DocumentType.class);
108 when(type1.getId()).thenReturn(new Id<DocumentType>("type1"));
109 DocumentType type2 = mock(DocumentType.class);
110 when(type2.getId()).thenReturn(new Id<DocumentType>("type1"));
111 Filter filter1 = mock(Filter.class);
112 when(filter1.getId()).thenReturn(new Id<Filter>("f1"));
113 Filter filter2 = mock(Filter.class);
114 when(filter2.getId()).thenReturn(new Id<Filter>("f1"));
115 Transformation transformation1 = mock(Transformation.class);
116 when(transformation1.getId()).thenReturn(new Id<Transformation>("t1"));
117 Transformation transformation2 = mock(Transformation.class);
118 when(transformation2.getId()).thenReturn(new Id<Transformation>("t1"));
120 config1.documentTypeConfig().add(type1);
121 assertFalse(config1.equals(config2));
123 config2.documentTypeConfig().add(type2);
124 assertEquals(config1, config2);
125 assertEquals(config1.hashCode(), config2.hashCode());
127 config1.transformationConfig().add(transformation1);
128 config2.transformationConfig().add(transformation2);
130 assertEquals(config1, config2);
131 assertEquals(config1.hashCode(), config2.hashCode());
133 config1.filterConfig().add(filter1);
134 config2.filterConfig().add(filter2);
136 assertEquals(config1, config2);
137 assertEquals(config1.hashCode(), config2.hashCode());