1   /*
2    * Copyright 2004-2010 the Seasar Foundation and the Others.
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,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  
17  package org.seasar.cubby.unit;
18  
19  import static org.junit.Assert.fail;
20  import junit.framework.AssertionFailedError;
21  
22  import org.junit.Test;
23  import org.seasar.cubby.action.ActionResult;
24  import org.seasar.cubby.action.Forward;
25  import org.seasar.cubby.action.Redirect;
26  
27  public class CubbyAssertTest {
28  
29  	@Test
30  	public void forward() {
31  		ActionResult actionResult = new Forward("aaa/bbb");
32  
33  		CubbyAssert.assertPathEquals(Forward.class, "aaa/bbb", actionResult);
34  
35  		// not null
36  		try {
37  			CubbyAssert.assertPathEquals(Forward.class, "aaa/bbb", null);
38  			fail();
39  		} catch (AssertionFailedError e) {
40  			System.out.println(e.getMessage());
41  		}
42  
43  		// type
44  		try {
45  			CubbyAssert.assertPathEquals(Redirect.class, "aaa/bbb", actionResult);
46  			fail();
47  		} catch (AssertionFailedError e) {
48  			System.out.println(e.getMessage());
49  		}
50  
51  		// path
52  		try {
53  			CubbyAssert
54  					.assertPathEquals(Forward.class, "aaa/ccc", actionResult);
55  			fail();
56  		} catch (AssertionFailedError e) {
57  			System.out.println(e.getMessage());
58  		}
59  	}
60  
61  	@Test
62  	public void redirect() {
63  		ActionResult actionResult = new Redirect("aaa/bbb");
64  
65  		CubbyAssert.assertPathEquals(Redirect.class, "aaa/bbb", actionResult);
66  
67  		// not null
68  		try {
69  			CubbyAssert.assertPathEquals(Redirect.class, "aaa/bbb", null);
70  			fail();
71  		} catch (AssertionFailedError e) {
72  			System.out.println(e.getMessage());
73  		}
74  
75  		// type
76  		try {
77  			CubbyAssert.assertPathEquals(Forward.class, "aaa/bbb", actionResult);
78  			fail();
79  		} catch (AssertionFailedError e) {
80  			System.out.println(e.getMessage());
81  		}
82  
83  		// path
84  		try {
85  			CubbyAssert
86  					.assertPathEquals(Redirect.class, "aaa/ccc", actionResult);
87  			fail();
88  		} catch (AssertionFailedError e) {
89  			System.out.println(e.getMessage());
90  		}
91  	}
92  
93  }