KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > integration > ant > deployment > TestEarParser


1 /*
2  * ========================================================================
3  *
4  * Copyright 2003 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * ========================================================================
19  */

20 package org.apache.cactus.integration.ant.deployment;
21
22 import org.apache.cactus.integration.ant.deployment.application.ApplicationXml;
23 import org.apache.cactus.integration.ant.deployment.application.EarArchive;
24 import org.apache.tools.ant.BuildException;
25
26 import com.mockobjects.dynamic.Mock;
27
28 import junit.framework.TestCase;
29
30 /**
31  * Unit tests for {@link EarParser}.
32  *
33  * @version $Id: TestEarParser.java,v 1.1 2004/05/31 20:05:24 vmassol Exp $
34  */

35 public final class TestEarParser extends TestCase
36 {
37     /**
38      * Control mock for {@link ApplicationXml}.
39      */

40     private Mock mockApplicationXml;
41
42     /**
43      * Mock for {@link ApplicationXml}.
44      */

45     private ApplicationXml applicationXml;
46
47     /**
48      * Control mock for {@link EarArchive}.
49      */

50     private Mock mockArchive;
51
52     /**
53      * Mock for {@link EarArchive}.
54      */

55     private EarArchive archive;
56     
57     /**
58      * @see TestCase#setUp()
59      */

60     protected void setUp()
61     {
62         mockApplicationXml = new Mock(ApplicationXml.class);
63         applicationXml = (ApplicationXml) mockApplicationXml.proxy();
64
65         mockArchive = new Mock(EarArchive.class);
66         archive = (EarArchive) mockArchive.proxy();
67         mockArchive.expectAndReturn("getApplicationXml", applicationXml);
68     }
69
70     /**
71      * Verify that if the <code>application.xml</code> defines a
72      * <code>context-root</code> element, then Cactus will use it
73      * as the test context to use when polling the container to see
74      * if it is started.
75      *
76      * @exception Exception on error
77      */

78     public void testParseTestContextWhenWebUriDefined() throws Exception JavaDoc
79     {
80         mockApplicationXml.expectAndReturn("getWebModuleContextRoot",
81             "test.war", "/testcontext");
82
83         String JavaDoc context = EarParser.parseTestContext(archive, "test.war");
84         assertEquals("testcontext", context);
85     }
86
87     /**
88      * Verify that if the <code>application.xml</code> does not define a
89      * <code>context-root</code> element, an exception is raised.
90      *
91      * @exception Exception on error
92      */

93     public void testParseTestContextWhenNoWebUriInApplicationXml()
94         throws Exception JavaDoc
95     {
96         mockApplicationXml.expectAndReturn("getWebModuleContextRoot",
97             "test.war", null);
98
99         try
100         {
101             EarParser.parseTestContext(archive, "test.war");
102         }
103         catch (BuildException expected)
104         {
105             assertTrue(true);
106         }
107     }
108 }
109
Popular Tags