KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > mavenplugins > car > PlanProcessorMojoTest


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. 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,
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  */

19
20 package org.apache.geronimo.mavenplugins.car;
21
22 import java.io.File JavaDoc;
23 import java.io.FileInputStream JavaDoc;
24 import java.io.InputStream JavaDoc;
25
26 import org.apache.geronimo.testsupport.TestSupport;
27 import org.apache.maven.model.Model;
28 import org.apache.maven.plugin.logging.SystemStreamLog;
29 import org.apache.maven.project.MavenProject;
30
31 /**
32  * @version $Rev: 433457 $ $Date: 2006-08-22 11:40:18 +1000 (Tue, 22 Aug 2006) $
33  */

34 public class PlanProcessorMojoTest extends TestSupport {
35
36     private PlanProcessorMojo processorMojo;
37
38     protected void setUp() throws Exception JavaDoc {
39         processorMojo = new PlanProcessorMojoTester();
40         Model model = new Model();
41         MavenProject mavenProject = new MavenProject(model);
42         mavenProject.setGroupId("dummy-group");
43         mavenProject.setArtifactId("dummy-artifact-id");
44         mavenProject.setVersion("dummy-version");
45         processorMojo.project = mavenProject;
46         processorMojo.sourceDir = new File JavaDoc(BASEDIR, "src/test/resources");
47         processorMojo.targetDir = new File JavaDoc(BASEDIR, "target/PlanProcessorMojoTest");
48     }
49     
50     public void testEmptyPlanProcessing() throws Exception JavaDoc {
51         String JavaDoc planName = "empty-plan.xml";
52         processorMojo.planFileName = planName;
53         processorMojo.targetFile = new File JavaDoc(processorMojo.targetDir, "actual-" + planName);
54         
55         processorMojo.doExecute();
56         
57         assertResultingPlan(planName);
58     }
59
60     public void testNoEnvironmentPlanProcessing() throws Exception JavaDoc {
61         String JavaDoc planName = "no-env-plan.xml";
62         processorMojo.planFileName = planName;
63         processorMojo.targetFile = new File JavaDoc(processorMojo.targetDir, "actual-" + planName);
64         
65         processorMojo.doExecute();
66         
67         assertResultingPlan(planName);
68     }
69
70     private void assertResultingPlan(String JavaDoc planName) throws Exception JavaDoc {
71         InputStream JavaDoc expectedIn = new FileInputStream JavaDoc(new File JavaDoc(processorMojo.sourceDir, "expected-" + planName));
72         InputStream JavaDoc actualIn = new FileInputStream JavaDoc(new File JavaDoc(processorMojo.targetDir, "actual-" + planName));
73         
74         int read;
75         while (-1 == (read = expectedIn.read())) {
76             int actualRead = actualIn.read();
77             if (-1 == actualRead) {
78                 fail();
79             }
80             assertEquals(read, actualRead);
81         }
82     }
83     
84     private class PlanProcessorMojoTester extends PlanProcessorMojo {
85         public PlanProcessorMojoTester() {
86             log = new SystemStreamLog();
87         }
88     }
89 }
90
Popular Tags