Java 类org.apache.maven.plugin.testing.stubs.MavenProjectStub 实例源码

项目:eo    文件:CompileMojoTest.java   
/**
 * Main can print a simple text.
 * @throws Exception If some problem inside
 */
public void testSimpleCompilation() throws Exception {
    final CompileMojo mojo = new CompileMojo();
    this.temp.create();
    final File src = this.temp.newFolder();
    this.setVariableValueToObject(mojo, "sourceDirectory", src);
    new LengthOf(
        new TeeInput(
            new InputOf(
                "type Pixel:\n  Pixel moveTo(Integer x, Integer y)"
            ),
            new OutputTo(new File(src, "main.eo"))
        )
    ).value();
    final File target = this.temp.newFolder();
    this.setVariableValueToObject(mojo, "targetDirectory", target);
    this.setVariableValueToObject(mojo, "project", new MavenProjectStub());
    mojo.execute();
    MatcherAssert.assertThat(
        new File(target, "Pixel.java").exists(),
        Matchers.is(true)
    );
}
项目:greenpepper    文件:SpecificationRunnerSingleMojoTest.java   
public void testReadSinglePomWithSingleTestExecutionConfiguration() throws Exception {
    URL pomPath = SpecificationRunnerSingleMojoTest.class.getResource( "pom-single.xml");
    mojo = (SpecificationRunnerMojo) lookupMojo( "run", URIUtil.decoded(pomPath.getPath()) );
    mojo.project = new MavenProjectStub();
    mojo.project.setBasedir(new File("."));
    mojo.classpathElements = new ArrayList<String>( );
    String core = dependency( "greenpepper-core.jar" ).getAbsolutePath();
    mojo.classpathElements.add( core );
    mojo.classpathElements.add( dependency( "guice-1.0.jar" ).getAbsolutePath());

    mojo.pluginDependencies = new ArrayList<Artifact>();
    File extension = dependency( "greenpepper-extensions-java.jar" );
    mojo.pluginDependencies.add( new DependencyArtifact( "greenpepper-extensions-java", extension  ));
    mojo.pluginDependencies.add( new DependencyArtifact( "slf4j-api", dependency("slf4j-api-1.6.1.jar")));
    mojo.pluginDependencies.add( new DependencyArtifact( "jcl-over-slf4j", dependency("jcl-over-slf4j-1.6.1.jar")));

    mojo.execute();

}
项目:greenpepper    文件:SpecificationRunnerMojoTest.java   
public void setUp() throws Exception
  {
      super.setUp();
      URL pomPath = SpecificationRunnerMojoTest.class.getResource( "pom-runner.xml");
      mojo = (SpecificationRunnerMojo) lookupMojo( "run", URIUtil.decoded(pomPath.getPath()) );
      mojo.project = new MavenProjectStub();
      mojo.project.setBasedir(new File("."));
      mojo.classpathElements = new ArrayList<String>( );
      String core = dependency( "greenpepper-core.jar" ).getAbsolutePath();
      mojo.classpathElements.add( core );
      mojo.classpathElements.add( dependency( "guice-1.0.jar" ).getAbsolutePath());

      mojo.pluginDependencies = new ArrayList<Artifact>();
      File extension = dependency( "greenpepper-extensions-java.jar" );
      mojo.pluginDependencies.add( new DependencyArtifact( "greenpepper-extensions-java", extension  ));

      mojo.pluginDependencies.add( new DependencyArtifact( "slf4j-api", dependency("slf4j-api-1.6.1.jar")));
      mojo.pluginDependencies.add( new DependencyArtifact( "jcl-over-slf4j", dependency("jcl-over-slf4j-1.6.1.jar")));

assertEquals("en", mojo.locale);
assertEquals(MySelector.class.getName(), mojo.selector);
assertTrue(mojo.debug);
      mojo.refresh = true;
  }
项目:wso2-axis2    文件:WSDL2CodeMojoTest.java   
protected WSDL2CodeMojo newMojo(String pDir, String pGoal) throws Exception {
    File baseDir = new File(new File(getBasedir()), pDir);
    File testPom = new File(baseDir, "pom.xml");
    WSDL2CodeMojo mojo = (WSDL2CodeMojo)lookupMojo(pGoal, testPom);
    MavenProjectStub project = new MavenProjectStub();
    project.setDependencyArtifacts(new HashSet());
    setVariableValueToObject(mojo, "project", project);
    setVariableValueToObject(mojo, "wsdlFile",
                             new File(baseDir, "src/main/axis2/service.wsdl").getAbsolutePath());
    setVariableValueToObject(mojo, "outputDirectory",
                             new File(baseDir, "target/generated-sources/axis2/wsdl2code"));
    setVariableValueToObject(mojo, "syncMode", "both");
    setVariableValueToObject(mojo, "databindingName", "adb");
    setVariableValueToObject(mojo, "language", "java");
    return mojo;
}
项目:dsl-compiler-client    文件:DslPlatformMojoIntegrationTest.java   
@Test
public void testGenerateCode() throws Exception {
    File pom = getTestFile("src/test/resources/properties-pom.xml");
    assertNotNull(pom);
    assertTrue(pom.exists());

    DslPlatformMojo mojo = (DslPlatformMojo) lookupMojo(DslPlatformMojo.GOAL, pom);
    assertNotNull(mojo);
    mojo.setProject(new MavenProjectStub());
    mojo.execute();

    File tempPath = TempPath.getTempProjectPath(mojo.getContext());
    String sourcesPath = tempPath.getAbsolutePath() + "/JAVA_POJO";
    TestUtils.assertDir(sourcesPath);
    TestUtils.assertDir(sourcesPath + "/DslPlatformMojoTestModule");
    TestUtils.assertFile(sourcesPath + "/DslPlatformMojoTestModule/Guards.java");
    TestUtils.assertFile(sourcesPath + "/DslPlatformMojoTestModule/DslPlatformMojoTestAggregate.java");
}
项目:dsl-compiler-client    文件:GenerateCodeMojoIntegrationTest.java   
@Test
public void testGenerateCode() throws Exception {
    File pom = getTestFile("src/test/resources/generate-code-pom.xml");
    assertNotNull(pom);
    assertTrue(pom.exists());

    GenerateCodeMojo mojo = (GenerateCodeMojo) lookupMojo(GenerateCodeMojo.GOAL, pom);
    assertNotNull(mojo);
    mojo.setProject(new MavenProjectStub());
    mojo.execute();

    String sourcesPath = mojo.getGeneratedSources();
    TestUtils.assertDir(sourcesPath);
    TestUtils.assertDir(sourcesPath + "/MojoTestModule");
    TestUtils.assertFile(sourcesPath + "/MojoTestModule/Guards.java");
    TestUtils.assertFile(sourcesPath + "/MojoTestModule/MojoTestAggregate.java");

    String[] settings = mojo.getOptions();
    assertEquals(null, settings);
}
项目:sql-maven-plugin    文件:SqlExecMojoTest.java   
public void setUp()
    throws Exception
{
    super.setUp();
    p = new Properties();
    p.load( getClass().getResourceAsStream( "/test.properties" ) );

    mojo = new SqlExecMojo();

    // populate parameters
    mojo.setDriver( p.getProperty( "driver" ) );
    mojo.setUsername( p.getProperty( "user" ) );
    mojo.setPassword( p.getProperty( "password" ) );
    mojo.setUrl( p.getProperty( "url" ) );
    mojo.setDriverProperties( p.getProperty( "driverProperties" ) );
    mojo.setSqlCommand( null );
    mojo.setDelimiter( SqlExecMojo.DEFAULT_DELIMITER );// This will simulate the defaultValue of @Parameter (...)
    mojo.setOnError( SqlExecMojo.ON_ERROR_ABORT );
    mojo.setDelimiterType( DelimiterType.NORMAL );
    mojo.setEscapeProcessing( true );

    MavenFileFilter filter =
        (MavenFileFilter) lookup( "org.apache.maven.shared.filtering.MavenFileFilter", "default" );
    mojo.setFileFilter( filter );

    SecDispatcher securityDispatcher =
        (SecDispatcher) lookup( "org.sonatype.plexus.components.sec.dispatcher.SecDispatcher", "default" );
    mojo.setSecurityDispatcher( securityDispatcher );

    MavenProject project = new MavenProjectStub();
    setVariableValueToObject( mojo, "project", project );
}
项目:brooklyn-maven-plugin    文件:DeployBlueprintMojoTest.java   
@Test
public void testPostsConfiguredBlueprintToServerAndSetsConfiguredProperty() throws Exception {
    // Just enough of a task summary to work.
    server.enqueue(deployApplicationResponse());
    server.enqueue(applicationStatusResponse("STARTING"));
    server.enqueue(applicationStatusResponse("RUNNING"));
    server.play();

    final MavenProjectStub project = new BrooklynMavenProjectStub();
    DeployBlueprintMojo mojo = new DeployBlueprintMojo(server.getUrl("/"), blueprintPath, NEW_APP_PROPERTY);
    mojo.setPollPeriod(1, TimeUnit.MILLISECONDS);
    mojo.setProject(project);
    // Test ignoreSkipTests at the same time.
    mojo.setSkipTests();
    mojo.setIgnoreSkipTests();
    executeMojoWithTimeout(mojo);

    // Mojo posts blueprint
    RecordedRequest request = server.takeRequest(1, TimeUnit.MILLISECONDS);
    assertEquals("/v1/applications", request.getPath());
    assertEquals("POST", request.getMethod());
    assertEquals(YAML, new String(request.getBody(), Charset.forName("UTF-8")));

    // Mojo waits for blueprint to be running
    request = server.takeRequest(1, TimeUnit.MILLISECONDS);
    assertEquals("/v1/applications/" + APP_ID, request.getPath());
    assertEquals("GET", request.getMethod());
    request = server.takeRequest(1, TimeUnit.MILLISECONDS);
    assertEquals("/v1/applications/" + APP_ID, request.getPath());
    assertEquals("GET", request.getMethod());

    // No more requests and the property was set
    assertEquals(3, server.getRequestCount());

    // And the property was set on the project
    assertEquals("Property " + NEW_APP_PROPERTY + " was not set on the Maven project",
            APP_ID, project.getProperties().getProperty(NEW_APP_PROPERTY));
}
项目:brooklyn-maven-plugin    文件:StartBrooklynMojoTest.java   
@Test
public void testStartGoal() throws Exception {
    final MavenProjectStub project = new BrooklynMavenProjectStub();
    final String mainUrlProperty = "mainUrlProperty";
    final ConstantDependencySupplier dependencySupplier = new ConstantDependencySupplier();
    final RecordingForker forker = new RecordingForker();
    final String bindPort = "bindPort";
    final String bindAddress = "bindAddress";

    StartBrooklynMojo mojo = new StartBrooklynMojo(
            dependencySupplier,
            bindAddress,
            bindPort,
            "mainClass",
            "launchCommand",
            "classpathScope",
            mainUrlProperty);
    mojo.setProject(project);
    mojo.setForker(forker);
    // Test ignoreSkipTests at the same time.
    mojo.setIgnoreSkipTests();
    mojo.setSkipTests();
    executeMojoWithTimeout(mojo);

    Object urlProperty = project.getProperties().get(mainUrlProperty);
    assertNotNull("Start goal did not set configured property " + mainUrlProperty, urlProperty);
    assertEquals(String.class, urlProperty.getClass());
    String serverUrl = urlProperty.toString();
    assertTrue("Server url did not contain configured bind address", serverUrl.contains(bindAddress));
    assertTrue("Server url did not contain configured bind port", serverUrl.contains(bindPort));

    ForkOptions options = forker.options;
    assertNotNull("BrooklynForker class was not called", options);
    assertEquals("mainClass", options.mainClass());
    assertEquals("launchCommand", options.launchCommand());
    assertEquals(bindAddress, options.bindAddress());
    assertEquals(bindPort, options.bindPort());
    assertEquals(dependencySupplier.get(), options.classpath());
}
项目:legstar-core2    文件:LegStarAbstractMojoTestCase.java   
protected Mojo lookupAndPrepareMojo( String artifactId, File testPom )
    throws Exception
{
    Mojo mojo = lookupMojo( artifactId, testPom );
    MavenProject mavenProject = new MavenProjectStub();
    setVariableValueToObject( mojo, "project", mavenProject );

    return mojo;
}
项目:wso2-axis2    文件:Java2WSDLMojoTest.java   
protected Java2WSDLMojo newMojo( String pDir, String pGoal ) throws Exception
{
    final File baseDir = new File(new File(getBasedir()), pDir);
    File testPom = new File( baseDir, "pom.xml" );
    Java2WSDLMojo mojo = (Java2WSDLMojo) lookupMojo( pGoal, testPom );
    MavenProjectStub project = new MavenProjectStub(){
        public File getBasedir() { return baseDir; }
    };
    setVariableValueToObject(mojo, "project", project);
    setVariableValueToObject(mojo, "outputFileName", WSDL_FILE);
    return mojo;
}
项目:deadcode4j    文件:A_PackagingHandler.java   
@Test
public void addsNoRepositoryIfThereAreNoCompileSourceRoots() throws MojoExecutionException {
    MavenProjectStub mavenProject = new MavenProjectStub();
    mavenProject.setCompileSourceRoots(null);

    Iterable<Repository> repositories = objectUnderTest.getAdditionalRepositoriesFor(mavenProject);

    assertThat(repositories, is(emptyIterable()));
}
项目:credentials-maven-plugin    文件:MojoTestSteps.java   
@Override
@Before(order = 2)
public void setUp() throws Exception {
    super.setUp();
    SecDispatcher securityDispatcher = (SecDispatcher) lookup(
            "org.sonatype.plexus.components.sec.dispatcher.SecDispatcher",
            "default");
    setVariableValueToObject(mojo, "securityDispatcher", securityDispatcher);
    securityDispatcher.decrypt("");
    properties = new Properties();
    project = new MavenProjectStub() {
        @Override
        public Properties getProperties() {
            return properties;
        }
    };
    setVariableValueToObject(mojo, "project", project);

    settings = new Settings();
    setVariableValueToObject(mojo, "settings", settings);
    systemProperties = new ArrayList<String>();

    mojo.setLog(new SystemStreamLog() {
        @Override
        public boolean isDebugEnabled() {
            return true;
        }
    });
}