+++ /dev/null
-/*
- * Copyright 2005-2011 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.wamblee.xmlrouter.impl;
-
-import static junit.framework.Assert.*;
-import static org.mockito.Mockito.*;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.wamblee.xmlrouter.common.Id;
-import org.wamblee.xmlrouter.config.DocumentType;
-import org.wamblee.xmlrouter.config.Filter;
-import org.wamblee.xmlrouter.config.Transformation;
-
-public class SingleRouterConfigTest {
-
- private SingleRouterConfig config;
-
- @Before
- public void setUp() {
- config = new SingleRouterConfig("routerconfig");
- assertEquals("routerconfig", config.getId().getId());
- }
-
- @Test
- public void testDocumentType() {
- DocumentType type1 = mock(DocumentType.class);
- when(type1.getId()).thenReturn(new Id<DocumentType>("type1"));
- DocumentType type2 = mock(DocumentType.class);
- when(type2.getId()).thenReturn(new Id<DocumentType>("type2"));
-
- config.documentTypeConfig().add(type1);
- config.documentTypeConfig().add(type2);
-
- assertEquals(2, config.documentTypeConfig().values().size());
- Object firstValue = config.documentTypeConfig().values().iterator()
- .next();
- assertTrue(firstValue instanceof RobustDocumentType);
- }
-
- @Test
- public void testTransformation() {
- Transformation transformation1 = mock(Transformation.class);
- when(transformation1.getId()).thenReturn(new Id<Transformation>("t1"));
- Transformation transformation2 = mock(Transformation.class);
- when(transformation2.getId()).thenReturn(new Id<Transformation>("t2"));
-
- config.transformationConfig().add(transformation1);
-
- config.transformationConfig().add(transformation2);
-
- assertEquals(2, config.transformationConfig().values().size());
- Object firstValue = config.transformationConfig().values().iterator()
- .next();
- assertTrue(firstValue instanceof RobustTransformation);
- }
-
- @Test
- public void testFilter() {
- Filter filter1 = mock(Filter.class);
- when(filter1.getId()).thenReturn(new Id<Filter>("f1"));
- Filter filter2 = mock(Filter.class);
- when(filter2.getId()).thenReturn(new Id<Filter>("f2"));
-
- config.filterConfig().add(filter1);
-
- config.filterConfig().add(filter2);
-
- assertEquals(2, config.filterConfig().values().size());
- Object firstValue = config.filterConfig().values().iterator().next();
- assertTrue(firstValue instanceof RobustFilter);
- }
-
- @Test
- public void testEqualityEmptyConfig() {
- RouterConfig config1 = new SingleRouterConfig("routerconfig");
- RouterConfig config2 = new SingleRouterConfig("routerconfig");
- assertEquals(config1, config2);
- }
-
- @Test
- public void testEqualsNonEmpty() {
- RouterConfig config1 = new SingleRouterConfig("routerconfig");
-
- assertFalse(config1.equals(null));
- assertFalse(config.equals("hello"));
-
- RouterConfig config2 = new SingleRouterConfig("routerconfig");
- DocumentType type1 = mock(DocumentType.class);
- when(type1.getId()).thenReturn(new Id<DocumentType>("type1"));
- DocumentType type2 = mock(DocumentType.class);
- when(type2.getId()).thenReturn(new Id<DocumentType>("type1"));
- Filter filter1 = mock(Filter.class);
- when(filter1.getId()).thenReturn(new Id<Filter>("f1"));
- Filter filter2 = mock(Filter.class);
- when(filter2.getId()).thenReturn(new Id<Filter>("f1"));
- Transformation transformation1 = mock(Transformation.class);
- when(transformation1.getId()).thenReturn(new Id<Transformation>("t1"));
- Transformation transformation2 = mock(Transformation.class);
- when(transformation2.getId()).thenReturn(new Id<Transformation>("t1"));
-
- config1.documentTypeConfig().add(type1);
- assertFalse(config1.equals(config2));
-
- config2.documentTypeConfig().add(type2);
- assertEquals(config1, config2);
- assertEquals(config1.hashCode(), config2.hashCode());
-
- config1.transformationConfig().add(transformation1);
- config2.transformationConfig().add(transformation2);
-
- assertEquals(config1, config2);
- assertEquals(config1.hashCode(), config2.hashCode());
-
- config1.filterConfig().add(filter1);
- config2.filterConfig().add(filter2);
-
- assertEquals(config1, config2);
- assertEquals(config1.hashCode(), config2.hashCode());
- }
-
- @Test
- public void testCopy() {
- testDocumentType();
- testFilter();
- testTransformation();
-
- SingleRouterConfig copy = new SingleRouterConfig(config);
- assertEquals(config.getId(), copy.getId());
- assertEquals(config, copy);
-
- // verify the copy is not shallow.
-
- config.documentTypeConfig().remove(new Id<DocumentType>("type1"));
- config.transformationConfig().remove(new Id<Transformation>("t1"));
- config.filterConfig().remove(new Id<Filter>("f1"));
- assertEquals(1, config.documentTypeConfig().values().size());
- assertEquals(1, config.transformationConfig().values().size());
- assertEquals(1, config.filterConfig().values().size());
- assertFalse(config.equals(copy));
- }
-}