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.Matchers.*;
20 import static org.mockito.Mockito.*;
22 import java.util.UUID;
24 import javax.xml.transform.dom.DOMSource;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.wamblee.xmlrouter.common.Id;
29 import org.wamblee.xmlrouter.config.Filter;
31 public class RobustFilterTest {
33 private Filter filter;
34 private Filter robust;
35 private DOMSource source;
39 filter = mock(Filter.class);
40 when(filter.getId()).thenReturn(
41 new Id<Filter>(UUID.randomUUID().toString()));
42 robust = new RobustFilter("filter", filter);
43 source = mock(DOMSource.class);
47 public void testNoEzception() {
48 when(filter.isAllowed(anyString(), any(DOMSource.class))).thenReturn(
50 assertTrue(robust.isAllowed("xx", source));
51 verify(filter).isAllowed(eq("xx"), same(source));
54 when(filter.isAllowed(anyString(), any(DOMSource.class))).thenReturn(
56 assertFalse(robust.isAllowed("xx", source));
57 verify(filter).isAllowed(eq("xx"), same(source));
61 public void testException() {
62 doThrow(new RuntimeException("bla")).when(filter).isAllowed(
63 anyString(), any(DOMSource.class));
64 assertTrue(robust.isAllowed("xx", source));
65 verify(filter).isAllowed(eq("xx"), same(source));