001: /*
002: * ========================================================================
003: *
004: * Copyright 2003 The Apache Software Foundation.
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * ========================================================================
019: */
020: package org.apache.cactus.integration.ant.deployment;
021:
022: import org.apache.cactus.integration.ant.deployment.application.ApplicationXml;
023: import org.apache.cactus.integration.ant.deployment.application.EarArchive;
024: import org.apache.tools.ant.BuildException;
025:
026: import com.mockobjects.dynamic.Mock;
027:
028: import junit.framework.TestCase;
029:
030: /**
031: * Unit tests for {@link EarParser}.
032: *
033: * @version $Id: TestEarParser.java 239003 2004-05-31 20:05:27Z vmassol $
034: */
035: public final class TestEarParser extends TestCase {
036: /**
037: * Control mock for {@link ApplicationXml}.
038: */
039: private Mock mockApplicationXml;
040:
041: /**
042: * Mock for {@link ApplicationXml}.
043: */
044: private ApplicationXml applicationXml;
045:
046: /**
047: * Control mock for {@link EarArchive}.
048: */
049: private Mock mockArchive;
050:
051: /**
052: * Mock for {@link EarArchive}.
053: */
054: private EarArchive archive;
055:
056: /**
057: * @see TestCase#setUp()
058: */
059: protected void setUp() {
060: mockApplicationXml = new Mock(ApplicationXml.class);
061: applicationXml = (ApplicationXml) mockApplicationXml.proxy();
062:
063: mockArchive = new Mock(EarArchive.class);
064: archive = (EarArchive) mockArchive.proxy();
065: mockArchive
066: .expectAndReturn("getApplicationXml", applicationXml);
067: }
068:
069: /**
070: * Verify that if the <code>application.xml</code> defines a
071: * <code>context-root</code> element, then Cactus will use it
072: * as the test context to use when polling the container to see
073: * if it is started.
074: *
075: * @exception Exception on error
076: */
077: public void testParseTestContextWhenWebUriDefined()
078: throws Exception {
079: mockApplicationXml.expectAndReturn("getWebModuleContextRoot",
080: "test.war", "/testcontext");
081:
082: String context = EarParser
083: .parseTestContext(archive, "test.war");
084: assertEquals("testcontext", context);
085: }
086:
087: /**
088: * Verify that if the <code>application.xml</code> does not define a
089: * <code>context-root</code> element, an exception is raised.
090: *
091: * @exception Exception on error
092: */
093: public void testParseTestContextWhenNoWebUriInApplicationXml()
094: throws Exception {
095: mockApplicationXml.expectAndReturn("getWebModuleContextRoot",
096: "test.war", null);
097:
098: try {
099: EarParser.parseTestContext(archive, "test.war");
100: } catch (BuildException expected) {
101: assertTrue(true);
102: }
103: }
104: }
|