6ec16b1b8d5857f7c7eaf9f48eb1a02a0422e586
[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         assertEquals("routerconfig", config.getId().getId());
37     }
38
39     @Test
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"));
45
46         config.documentTypeConfig().add(type1);
47         config.documentTypeConfig().add(type2);
48
49         assertEquals(2, config.documentTypeConfig().values().size());
50         assertTrue(config.documentTypeConfig().values().get(0) instanceof RobustDocumentType);
51     }
52
53     @Test
54     public void testTransformation() {
55         Transformation transformation1 = mock(Transformation.class);
56         when(transformation1.getId()).thenReturn(new Id<Transformation>("t1"));
57         Transformation transformation2 = mock(Transformation.class);
58         when(transformation2.getId()).thenReturn(new Id<Transformation>("t2"));
59
60         config.transformationConfig().add(transformation1);
61
62         config.transformationConfig().add(transformation2);
63
64         assertEquals(2, config.transformationConfig().values().size());
65         assertTrue(config.transformationConfig().values().get(0) instanceof RobustTransformation);
66     }
67
68     @Test
69     public void testFilter() {
70         Filter filter1 = mock(Filter.class);
71         when(filter1.getId()).thenReturn(new Id<Filter>("f1"));
72         Filter filter2 = mock(Filter.class);
73         when(filter2.getId()).thenReturn(new Id<Filter>("f2"));
74
75         config.filterConfig().add(filter1);
76
77         config.filterConfig().add(filter2);
78
79         assertEquals(2, config.filterConfig().values().size());
80         assertTrue(config.filterConfig().values().get(0) instanceof RobustFilter);
81     }
82 }