a344f7201b34bd48a88e37ef2078ffd7db9c5f89
[xmlrouter] / impl / src / test / java / org / wamblee / xmlrouter / impl / SingleRouterConfigTest.java
1 /*
2  * Copyright 2005-2011 the original author or authors.
3  * 
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
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
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.
15  */
16 package org.wamblee.xmlrouter.impl;
17
18 import static junit.framework.Assert.*;
19 import static org.mockito.Mockito.*;
20
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;
28
29 public class SingleRouterConfigTest {
30
31     private ExtendedRouterConfig config;
32
33     @Before
34     public void setUp() {
35         config = new SingleRouterConfig(new Id<RouterConfig>("routerconfig"));
36     }
37
38     @Test
39     public void testDocumentType() {
40         DocumentType type1 = mock(DocumentType.class);
41         when(type1.getId()).thenReturn(new Id<DocumentType>("type1"));
42         DocumentType type2 = mock(DocumentType.class);
43         when(type2.getId()).thenReturn(new Id<DocumentType>("type2"));
44
45         config.documentTypeConfig().add(type1);
46         config.documentTypeConfig().add(type2);
47
48         assertEquals(2, config.documentTypeConfig().values().size());
49         assertTrue(config.documentTypeConfig().values().get(0) instanceof RobustDocumentType);
50     }
51
52     @Test
53     public void testTransformation() {
54         Transformation transformation1 = mock(Transformation.class);
55         when(transformation1.getId()).thenReturn(new Id<Transformation>("t1"));
56         Transformation transformation2 = mock(Transformation.class);
57         when(transformation2.getId()).thenReturn(new Id<Transformation>("t2"));
58
59         config.transformationConfig().add(transformation1);
60
61         config.transformationConfig().add(transformation2);
62
63         assertEquals(2, config.transformationConfig().values().size());
64         assertTrue(config.transformationConfig().values().get(0) instanceof RobustTransformation);
65     }
66
67     @Test
68     public void testFilter() {
69         Filter filter1 = mock(Filter.class);
70         when(filter1.getId()).thenReturn(new Id<Filter>("f1"));
71         Filter filter2 = mock(Filter.class);
72         when(filter2.getId()).thenReturn(new Id<Filter>("f2"));
73
74         config.filterConfig().add(filter1);
75
76         config.filterConfig().add(filter2);
77
78         assertEquals(2, config.filterConfig().values().size());
79         assertTrue(config.filterConfig().values().get(0) instanceof RobustFilter);
80     }
81 }