1 19 20 package org.apache.geronimo.mavenplugins.car; 21 22 import java.io.File ; 23 import java.io.FileInputStream ; 24 import java.io.InputStream ; 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 34 public class PlanProcessorMojoTest extends TestSupport { 35 36 private PlanProcessorMojo processorMojo; 37 38 protected void setUp() throws Exception { 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 (BASEDIR, "src/test/resources"); 47 processorMojo.targetDir = new File (BASEDIR, "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, "actual-" + planName); 54 55 processorMojo.doExecute(); 56 57 assertResultingPlan(planName); 58 } 59 60 public void testNoEnvironmentPlanProcessing() throws Exception { 61 String planName = "no-env-plan.xml"; 62 processorMojo.planFileName = planName; 63 processorMojo.targetFile = new File (processorMojo.targetDir, "actual-" + planName); 64 65 processorMojo.doExecute(); 66 67 assertResultingPlan(planName); 68 } 69 70 private void assertResultingPlan(String planName) throws Exception { 71 InputStream expectedIn = new FileInputStream (new File (processorMojo.sourceDir, "expected-" + planName)); 72 InputStream actualIn = new FileInputStream (new File (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 |