01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.geronimo.mavenplugins.car;
19:
20: import java.io.File;
21: import java.io.FileInputStream;
22: import java.io.InputStream;
23:
24: import org.apache.geronimo.testsupport.TestSupport;
25: import org.apache.maven.model.Model;
26: import org.apache.maven.plugin.logging.SystemStreamLog;
27: import org.apache.maven.project.MavenProject;
28:
29: /**
30: * @version $Rev: 514085 $ $Date: 2007-03-02 22:09:54 -0800 (Fri, 02 Mar 2007) $
31: */
32: public class PlanProcessorMojoTest extends TestSupport {
33:
34: private PlanProcessorMojo processorMojo;
35:
36: protected void setUp() throws Exception {
37: processorMojo = new PlanProcessorMojoTester();
38: Model model = new Model();
39: MavenProject mavenProject = new MavenProject(model);
40: mavenProject.setGroupId("dummy-group");
41: mavenProject.setArtifactId("dummy-artifact-id");
42: mavenProject.setVersion("dummy-version");
43: processorMojo.project = mavenProject;
44: processorMojo.sourceDir = new File(BASEDIR,
45: "src/test/resources");
46: processorMojo.targetDir = new File(BASEDIR,
47: "target/PlanProcessorMojoTest");
48: }
49:
50: public void testEmptyPlanProcessing() throws Exception {
51: String planName = "empty-plan.xml";
52: processorMojo.planFileName = planName;
53: processorMojo.targetFile = new File(processorMojo.targetDir,
54: "actual-" + planName);
55:
56: processorMojo.doExecute();
57:
58: assertResultingPlan(planName);
59: }
60:
61: public void testNoEnvironmentPlanProcessing() throws Exception {
62: String planName = "no-env-plan.xml";
63: processorMojo.planFileName = planName;
64: processorMojo.targetFile = new File(processorMojo.targetDir,
65: "actual-" + planName);
66:
67: processorMojo.doExecute();
68:
69: assertResultingPlan(planName);
70: }
71:
72: private void assertResultingPlan(String planName) throws Exception {
73: InputStream expectedIn = new FileInputStream(new File(
74: processorMojo.sourceDir, "expected-" + planName));
75: InputStream actualIn = new FileInputStream(new File(
76: processorMojo.targetDir, "actual-" + planName));
77:
78: int read;
79: while (-1 == (read = expectedIn.read())) {
80: int actualRead = actualIn.read();
81: if (-1 == actualRead) {
82: fail();
83: }
84: assertEquals(read, actualRead);
85: }
86: }
87:
88: private class PlanProcessorMojoTester extends PlanProcessorMojo {
89: public PlanProcessorMojoTester() {
90: log = new SystemStreamLog();
91: }
92: }
93: }
|