/** * テーブルのデータ型を網羅するDDL実行テスト。 * * <h4>検証内容</h4> * <ul> * <li>各DBごとにサポートするデータ型を網羅したテーブルのDDLを実行。</li> * </ul> * <h4>検証結果</h4> * <ul> * <li>DDLの実行でエラーが発生しなければOK</li> * </ul> * * @throws Exception */ @Test @TestDBPattern(testCase = "type", testDb = { TestDB.oracle, TestDB.postgresql, TestDB.db2, TestDB.h2, TestDB.sqlserver, TestDB.mysql }) public void testType() throws Exception { // 指定されたケース及びテスト対象のDBだけループ for (MojoTestFixture mf : mojoTestFixtureList) { // テストケース対象プロジェクトのpom.xmlを取得 File pom = new File(getTestCaseDBPath(mf) + "/pom.xml"); // pom.xmlより指定ゴールのMojoを取得し実行。Mavenプロファイルを指定する(DB) Mojo mojo = this.lookupConfiguredMojo(pom, EXECUTE_DDL, mf.testDb); mojo.execute(); } }
/** * パラメータ:optionalDialectsのテスト。 * * <h4>検証内容</h4> * <ul> * <li>optionalDialectsによりDialectクラスを差し替えることが出来るかをテスト。</li> * <li>h2だけでテスト。</li> * <li>同じjdbcURLのDBプロトコルでも、optionalDialectsで指定したDialectが優先されることをテスト。</li> * <li>このテストで差し込むoptionalDialectsはオブジェクト生成時に例外を投げるようにし、これを期待値とする。</li> * </ul> * <h4>検証結果</h4> * <ul> * <li>正しく差し替えられていれば、例外がスローされるのでそれを期待値とする。</li> * </ul> * * @throws Exception */ @Test @TestDBPattern(testCase = "optionalDialects_1", testDb = { TestDB.h2 }) public void testOptionalDialects1() throws Exception { // 指定されたケース及びテスト対象のDBだけループ for (MojoTestFixture mf : mojoTestFixtureList) { // 差し替えたDialectはただ例外を投げる動きをするので、それを期待値とする。 expected.expect(MojoExecutionException.class); expected.expectMessage("OptionalDialectsTestDialect"); // テストケース対象プロジェクトのpom.xmlを取得 File pom = new File(getTestCaseDBPath(mf) + "/pom.xml"); // pom.xmlより指定ゴールのMojoを取得し実行。Mavenプロファイルを指定する(DB) Mojo mojo = this.lookupConfiguredMojo(pom, EXECUTE_DDL, mf.testDb); mojo.execute(); } }
/** * パラメータ:optionalDialectsのテスト. * * <h4>検証内容</h4> * <ul> * <li>optionalDialectsによりDialectクラスを差し替えることが出来るかをテスト。</li> * <li>h2だけでテスト。</li> * <li>gspに標準装備されていないjdbcURLのDBプロトコルで、optionalDialectsを差し込むことが出来ることをテスト。 * </li> * <li>このテストで差し込むoptionalDialectsはオブジェクト生成時に例外を投げるようにし、これを期待値とする。</li> * </ul> * <h4>検証結果</h4> * <ul> * <li>正しく差し替えられていれば、例外がスローされるのでそれを期待値とする。</li> * </ul> * * @throws Exception */ @Test @TestDBPattern(testCase = "optionalDialects_2", testDb = { TestDB.h2 }) public void testOptionalDialects2() throws Exception { // 指定されたケース及びテスト対象のDBだけループ for (MojoTestFixture mf : mojoTestFixtureList) { expected.expect(MojoExecutionException.class); expected.expectMessage("OptionalDialectsTestDialect"); // テストケース対象プロジェクトのpom.xmlを取得 File pom = new File(getTestCaseDBPath(mf) + "/pom.xml"); // pom.xmlより指定ゴールのMojoを取得し実行。Mavenプロファイルを指定する(DB) Mojo mojo = this.lookupConfiguredMojo(pom, EXECUTE_DDL, mf.testDb); mojo.execute(); } }
/** * パラメータ:onErrorの検証 * * <h4>検証内容</h4> * <ul> * <li>h2だけでテスト。</li> * <li>不正なDDLを実行することでDDL実行エラーを引き起こす。</li> * </ul> * <h4>検証結果</h4> * <ul> * <li>abortを指定した場合は例外がスローされるのでそれを期待値とする。</li> * </ul> * * @throws Exception */ @Test @TestDBPattern(testCase = "on_error_abort", testDb = { TestDB.h2 }) public void testOnErrorAbort() throws Exception { // 指定されたケース及びテスト対象のDBだけループ for (MojoTestFixture mf : mojoTestFixtureList) { expected.expect(MojoExecutionException.class); expected.expectMessage("DDLの実行に失敗しました:"); // テストケース対象プロジェクトのpom.xmlを取得 File pom = new File(getTestCaseDBPath(mf) + "/pom.xml"); // pom.xmlより指定ゴールのMojoを取得し実行。Mavenプロファイルを指定する(DB) Mojo mojo = this.lookupConfiguredMojo(pom, EXECUTE_DDL, mf.testDb); mojo.execute(); } }
/** * パラメータ:onErrorの検証 * * <h4>検証内容</h4> * <ul> * <li>h2だけでテスト。</li> * <li>不正なDDLを実行することでDDL実行エラーを引き起こす。</li> * </ul> * <h4>検証結果</h4> * <ul> * <li>例外が発生しなければOK。</li> * </ul> * * @throws Exception */ @Test @TestDBPattern(testCase = "on_error_continue", testDb = { TestDB.h2 }) public void testOnErrorContinue() throws Exception { // 指定されたケース及びテスト対象のDBだけループ for (MojoTestFixture mf : mojoTestFixtureList) { // テストケース対象プロジェクトのpom.xmlを取得 File pom = new File(getTestCaseDBPath(mf) + "/pom.xml"); // pom.xmlより指定ゴールのMojoを取得し実行。Mavenプロファイルを指定する(DB) Mojo mojo = this.lookupConfiguredMojo(pom, EXECUTE_DDL, mf.testDb); mojo.execute(); // 例外がスローされてこなければOK! } }
/** * 汎用モードでのパラメータ:ddlDirectoryの指定誤りによる例外テスト * * <h4>検証内容</h4> * <ul> * <li>パラメータ:ddlDirectoryに存在しないパスを指定する。</li> * <li>db2</li> * </ul> * * <h4>検証結果</h4> * <ul> * <li>エラーメッセージが表示され処理が中断されること。</li> * </ul> * * @throws Exception */ @Test @TestDBPattern(testCase = "ddl_dir_not_exist", testDb = { TestDB.h2 }) public void testDdlDirectoryNotExist() throws Exception { // 指定されたケース及びテスト対象のDBだけループ for (MojoTestFixture mf : mojoTestFixtureList) { // テストケース対象プロジェクトのpom.xmlを取得 File pom = new File(getTestCaseDBPath(mf) + "/pom.xml"); // pom.xmlより指定ゴールのMojoを取得し実行。Mavenプロファイルを指定する(DB) Mojo mojo = this.lookupConfiguredMojo(pom, EXPORT_SCHEMA, mf.testDb); try { mojo.execute(); fail("期待した例外が発生しませんでした。"); } catch (Exception e) { assertThat(e.getCause().getClass().equals(MojoExecutionException.class), is(true)); assertThat(e.getCause().getMessage().equals("DDLディレクトリの指定が誤っています"), is(true)); } } }
/** * 汎用モードでのパラメータ:extraDdlDirectoryの指定誤りによる例外テスト * * <h4>検証内容</h4> * <ul> * <li>パラメータ:extraDdlDirectoryに存在しないパスを指定する。</li> * <li>db2</li> * </ul> * * <h4>検証結果</h4> * <ul> * <li>エラーメッセージが表示され処理が中断されること。</li> * </ul> * * @throws Exception */ @Test @TestDBPattern(testCase = "extraDdl_dir_not_exist", testDb = { TestDB.h2 }) public void testExtraDdlDirectoryNotExist() throws Exception { // 指定されたケース及びテスト対象のDBだけループ for (MojoTestFixture mf : mojoTestFixtureList) { // テストケース対象プロジェクトのpom.xmlを取得 File pom = new File(getTestCaseDBPath(mf) + "/pom.xml"); // pom.xmlより指定ゴールのMojoを取得し実行。Mavenプロファイルを指定する(DB) Mojo mojo = this.lookupConfiguredMojo(pom, EXPORT_SCHEMA, mf.testDb); try { mojo.execute(); fail("期待した例外が発生しませんでした。"); } catch (Exception e) { assertThat(e.getCause().getClass().equals(MojoExecutionException.class), is(true)); assertThat(e.getCause().getMessage().equals("extraDDLディレクトリの指定が誤っています"), is(true)); } } }
/** * Creates a new GitHubPages object and clones the specified repository. * * @param mojo plugin execution * @param workingDir to clone repo to * @param contentDir directory within workingDir that content should be copied to * @param uri to clone repo from * @param branch of repo to clone * @throws MojoExecutionException if the workingDir cannot be created or the repo cannot be cloned * @throws org.apache.maven.plugin.MojoFailureException if content directory is not a subdirectory of working * directory */ public GitHubPages(Mojo mojo, File workingDir, File contentDir, String uri, String branch) throws MojoExecutionException, MojoFailureException { log = mojo.getLog(); this.workingDir = workingDir; if (!isSubDirectoryOf(contentDir, workingDir)) throw new MojoFailureException("Content directory must be a subdirectory of the working directory"); this.contentDir = contentDir; this.uri = uri; this.branch = branch; setupWorkingDirectory(); cloneRepo(); if (!checkoutBranch()) { // branch not found, create new one createBranch(); } }
/** * Workaround for parent class lookupMojo and lookupConfiguredMojo. * @param name the name of the Mojo to lookup * @param pomPath where to find the POM file * @return a configured MSBuild Mojo for testing * @throws Exception if we can't find the Mojo or the POM is malformed */ protected final Mojo lookupConfiguredMojo( String name, String pomPath ) throws Exception { File pom = new File( getClass().getResource( pomPath ).getPath() ); assertTrue( pom.exists() ); // The following 4 lines are simply to get a MavenProject object MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest(); ProjectBuilder projectBuilder = this.lookup( ProjectBuilder.class ); MavenProject mavenProject = projectBuilder.build( pom, buildingRequest ).getProject(); assertNotNull( mavenProject ); // Used lookupMojo as it sets up most of what we need and reads configuration // variables from the poms. // It doesn't set a MavenProject so we have to do that manually // lookupConfiguredMojo doesn't work properly, configuration variables are no expanded // as we expect and it fails to setup a Log. Mojo mojo = lookupMojo( name, pom ); //Mojo mojo = super.lookupConfiguredMojo( mavenProject, name ); assertNotNull( mojo ); setVariableValueToObject( mojo, "mavenProject", mavenProject ); return mojo; }
private void execute(String goal, String target) throws Exception { Mojo mojo = mojoRule.lookupMojo(goal, new File("src/test/resources/net/bytebuddy/test/" + target + ".pom.xml")); if (goal.equals("transform")) { mojoRule.setVariableValueToObject(mojo, "outputDirectory", project.getAbsolutePath()); mojoRule.setVariableValueToObject(mojo, "compileClasspathElements", Collections.emptyList()); } else if (goal.equals("transform-test")) { mojoRule.setVariableValueToObject(mojo, "testOutputDirectory", project.getAbsolutePath()); mojoRule.setVariableValueToObject(mojo, "testClasspathElements", Collections.emptyList()); } else { throw new AssertionError("Unknown goal: " + goal); } mojoRule.setVariableValueToObject(mojo, "repositorySystem", repositorySystem); mojoRule.setVariableValueToObject(mojo, "groupId", FOO); mojoRule.setVariableValueToObject(mojo, "artifactId", BAR); mojoRule.setVariableValueToObject(mojo, "version", QUX); mojo.setLog(new SilentLog()); mojo.execute(); }
public void setUp() throws MojoExecutionException { Mojo mojo = new GenerateComponentsMojo(); File genSrcDir = new File("target/mojo-test-output/java"); setMojoProject(mojo, "project"); setMojoField(mojo, "packageContains", "org"); setMojoField(mojo, "typePrefix", "org.apache"); setMojoField(mojo, "templateSourceDirectory", new File("src/test/java-templates")); setMojoField(mojo, "generatedSourceDirectory", genSrcDir); setMojoField(mojo, "force", Boolean.TRUE); _mojo = mojo; _genSrcDir = genSrcDir; }
@Test public void testExecuteCommands() throws Exception { final Mojo executeCommandsMojo = lookupMojoAndVerify("execute-commands", "execute-commands-pom.xml"); executeCommandsMojo.execute(); // Read the attribute ModelNode address = ServerOperations.createAddress("system-property", "org.wildfly.maven.plugin-exec-cmd"); ModelNode op = ServerOperations.createReadAttributeOperation(address, "value"); ModelNode result = executeOperation(op); assertEquals("true", ServerOperations.readResultAsString(result)); // Clean up the property executeOperation(ServerOperations.createRemoveOperation(address)); // Read the attribute address = ServerOperations.createAddress("system-property", "property2"); op = ServerOperations.createReadAttributeOperation(address, "value"); result = executeOperation(op); assertEquals("property 2", ServerOperations.readResultAsString(result)); // Clean up the property executeOperation(ServerOperations.createRemoveOperation(address)); }
@Test public void testExecuteBatchCommands() throws Exception { final Mojo executeCommandsMojo = lookupMojoAndVerify("execute-commands", "execute-batch-commands-pom.xml"); executeCommandsMojo.execute(); // Read the attribute final ModelNode address = ServerOperations.createAddress("system-property", "org.wildfly.maven.plugin-batch"); final ModelNode op = ServerOperations.createReadAttributeOperation(address, "value"); final ModelNode result = executeOperation(op); assertEquals("true", ServerOperations.readResultAsString(result)); // Clean up the property executeOperation(ServerOperations.createRemoveOperation(address)); }
@Test public void testExecuteCommandsFailOnError() throws Exception { final Mojo executeCommandsMojo = lookupMojoAndVerify("execute-commands", "execute-commands-failOnError-pom.xml"); try { executeCommandsMojo.execute(); fail("IllegalArgumentException expected."); } catch (IllegalArgumentException e) { assertEquals(CommandLineException.class, e.getCause().getClass()); } final ModelNode address = ServerOperations.createAddress("system-property", "propertyFailOnError"); final ModelNode op = ServerOperations.createReadAttributeOperation(address, "value"); final ModelNode result = executeOperation(op); try { assertEquals("initial value", ServerOperations.readResultAsString(result)); } finally { // Remove the system property executeOperation(ServerOperations.createRemoveOperation(address)); } }
@Test public void testExecuteCommandsLocalFailOnError() throws Exception { final Mojo executeCommandsMojo = lookupMojoAndVerify("execute-commands", "execute-commands-failOnError-pom.xml"); // Set the JBoss home field so commands will be executed in a new process setValue(executeCommandsMojo, "jbossHome", Environment.WILDFLY_HOME.toString()); try { executeCommandsMojo.execute(); fail("IllegalArgumentException expected."); } catch (IllegalArgumentException ignore) { } final ModelNode address = ServerOperations.createAddress("system-property", "propertyFailOnError"); final ModelNode op = ServerOperations.createReadAttributeOperation(address, "value"); final ModelNode result = executeOperation(op); try { assertEquals("initial value", ServerOperations.readResultAsString(result)); } finally { // Remove the system property executeOperation(ServerOperations.createRemoveOperation(address)); } }
@Test public void testExecuteCommandsContinueOnError() throws Exception { final Mojo executeCommandsMojo = lookupMojoAndVerify("execute-commands", "execute-commands-continueOnError-pom.xml"); executeCommandsMojo.execute(); // Read the attribute final ModelNode address = ServerOperations.createAddress("system-property", "propertyContinueOnError"); final ModelNode op = ServerOperations.createReadAttributeOperation(address, "value"); final ModelNode result = executeOperation(op); try { assertEquals("continue on error", ServerOperations.readResultAsString(result)); } finally { // Clean up the property executeOperation(ServerOperations.createRemoveOperation(address)); } }
@Test public void testExecuteCommandsLocalContinueOnError() throws Exception { final Mojo executeCommandsMojo = lookupMojoAndVerify("execute-commands", "execute-commands-continueOnError-pom.xml"); // Set the JBoss home field so commands will be executed in a new process setValue(executeCommandsMojo, "jbossHome", Environment.WILDFLY_HOME.toString()); executeCommandsMojo.execute(); // Read the attribute final ModelNode address = ServerOperations.createAddress("system-property", "propertyContinueOnError"); final ModelNode op = ServerOperations.createReadAttributeOperation(address, "value"); final ModelNode result = executeOperation(op); try { assertEquals("continue on error", ServerOperations.readResultAsString(result)); } finally { // Clean up the property executeOperation(ServerOperations.createRemoveOperation(address)); } }
@Test public void testExecuteCommandScriptFailOnError() throws Exception { final Mojo executeCommandsMojo = lookupMojoAndVerify("execute-commands", "execute-script-failOnError-pom.xml"); try { executeCommandsMojo.execute(); fail("IllegalArgumentException expected."); } catch (IllegalArgumentException e) { assertEquals(IllegalArgumentException.class, e.getCause().getClass()); assertEquals(CommandLineException.class, e.getCause().getCause().getClass()); } final ModelNode address = ServerOperations.createAddress("system-property", "scriptFailOnError"); final ModelNode op = ServerOperations.createReadAttributeOperation(address, "value"); final ModelNode result = executeOperation(op); try { assertEquals("initial value", ServerOperations.readResultAsString(result)); } finally { // Remove the system property executeOperation(ServerOperations.createRemoveOperation(address)); } }
@Test public void testExecuteCommandScriptContinueOnError() throws Exception { final Mojo executeCommandsMojo = lookupMojoAndVerify("execute-commands", "execute-script-continueOnError-pom.xml"); executeCommandsMojo.execute(); // Read the attribute final ModelNode address = ServerOperations.createAddress("system-property", "scriptContinueOnError"); final ModelNode op = ServerOperations.createReadAttributeOperation(address, "value"); final ModelNode result = executeOperation(op); try { assertEquals("continue on error", ServerOperations.readResultAsString(result)); } finally { // Clean up the property executeOperation(ServerOperations.createRemoveOperation(address)); } }
protected Mojo lookupMojo(Path pomPath, String goal) throws Exception { File pom = getTestFile(pomPath.toString()); assertTrue(pom.exists()); MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest(); buildingRequest.setRepositorySession(new DefaultRepositorySystemSession()); ProjectBuilder projectBuilder = lookup(ProjectBuilder.class); MavenProject project = projectBuilder.build(pom, buildingRequest).getProject(); return lookupConfiguredMojo(project, goal); }
private Mojo lookupConfiguredMojo(String goal, File pom) throws Exception { MavenExecutionRequest request = new DefaultMavenExecutionRequest(); request.setBaseDirectory(pom.getParentFile()); ProjectBuildingRequest configuration = request.getProjectBuildingRequest(); // Fix for bug: https://git-wip-us.apache.org/repos/asf?p=maven-plugin-testing.git;a=commit;h=3cd5f47c586499e438a3f9393304ac9d1f9a7f53 configuration.setRepositorySession(new DefaultRepositorySystemSession()); MavenProject project = lookup(ProjectBuilder.class).build(pom, configuration).getProject(); return super.lookupConfiguredMojo(project, goal); }
private <M extends Mojo> M getMojo(String goal) throws Exception { File testBaseDir = new File(getClass().getResource("pom.xml").getFile()).getParentFile(); Web2AppMojo mojo = (Web2AppMojo) rule.lookupConfiguredMojo(testBaseDir, goal); File localRepositoryFile = new File(testBaseDir, "repo"); mojo.mavenProject.setRemoteArtifactRepositories(Arrays.asList(repository)); DefaultRepositorySystemSession repositorySystemSession = (DefaultRepositorySystemSession) mojo.mavenSession.getRepositorySession(); repositorySystemSession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySystemSession, new LocalRepository(localRepositoryFile))); mojo.mavenSession.getRequest().setLocalRepository(new StubArtifactRepository(localRepositoryFile.getAbsolutePath())); return (M) mojo; }
@Override public void initialize(final Mojo pMojo, final MavenProject pProject, final List<MavenProject> pReactorProjects) throws PluginException { setLog(pMojo.getLog()); setRootProject(pProject); setReactorProjects(pReactorProjects); setConfiguration(new ConfigurationAccessor(pMojo)); for (final Initializable initializable : initializables) { initializable.initialize(); } }
public Mojo forProject(String projectName, List<Property> properties) throws Exception { File pom = testPomFor(projectName); Mojo mojo = lookupConfiguredMojo(mavenProjectFor(pom, properties), mojoName); assertThat(mojo, not(nullValue())); return mojo; }
private Mojo configureMojo(final String parameter, final String value) throws Exception { final MavenSession mavenSession = mojoRule.newMavenSession(getMavenProject(DEFAULT_CONFIG)); final MojoExecution mojoExecution = mojoRule.newMojoExecution(GOAL_NAME); final Xpp3Dom configuration = new Xpp3Dom("configuration"); final Xpp3Dom generationConfig = new Xpp3Dom("generationConfig"); final Xpp3Dom useBigDecimal = new Xpp3Dom(parameter); useBigDecimal.setValue(value); generationConfig.addChild(useBigDecimal); configuration.addChild(generationConfig); mojoExecution.setConfiguration(configuration); return mojoRule.lookupConfiguredMojo(mavenSession, mojoExecution); }
/** As {@link #lookupConfiguredMojo(MavenProject, String)} but taking the pom file * and creating the {@link MavenProject}. */ protected Mojo lookupConfiguredMojo(File pom, String goal) throws Exception { assertNotNull( pom ); assertTrue( pom.exists() ); ProjectBuildingRequest buildingRequest = newMavenSession().getProjectBuildingRequest(); ProjectBuilder projectBuilder = lookup(ProjectBuilder.class); MavenProject project = projectBuilder.build(pom, buildingRequest).getProject(); return lookupConfiguredMojo(project, goal); }
@SuppressWarnings("unchecked") protected <T> T createMojo(String projectName, boolean hasConfiguration) throws Exception { File baseDir = resources.getBasedir(projectName); File pom = new File(baseDir, "pom.xml"); Mojo mojo = hasConfiguration ? mojoRule.lookupMojo(mojoName(), pom) : mojoRule.lookupEmptyMojo(mojoName(), pom); writePrivate(mojo, "workingDirectory", baseDir); Log logger = createLogger(); writePrivate(mojo, "log", logger); return (T) mojo; }
protected void setUp() throws Exception { super.setUp(); mavenProjectBuilder = (MavenProjectBuilder) getContainer().lookup( MavenProjectBuilder.ROLE); ArtifactFactory artifactFactory = (ArtifactFactory) getContainer() .lookup(ArtifactFactory.ROLE); final Map<String, Mojo> mojos = (Map<String, Mojo>) getContainer() .lookupMap(Mojo.ROLE); for (Mojo mojo : mojos.values()) { if (mojo instanceof Hyperjaxb3Mojo) { this.mojo = (Hyperjaxb3Mojo) mojo; } } MavenSettingsBuilder settingsBuilder = (MavenSettingsBuilder) getContainer() .lookup(MavenSettingsBuilder.ROLE); ArtifactRepositoryLayout repositoryLayout = (ArtifactRepositoryLayout) getContainer() .lookup(ArtifactRepositoryLayout.ROLE, "default"); Settings settings = settingsBuilder.buildSettings(); String url = settings.getLocalRepository(); if (!url.startsWith("file:")) { url = "file://" + url; } localRepository = new DefaultArtifactRepository("local", url, new DefaultRepositoryLayout()); }
protected Mojo lookupAndPrepareMojo( String artifactId, File testPom ) throws Exception { Mojo mojo = lookupMojo( artifactId, testPom ); MavenProject mavenProject = new MavenProjectStub(); setVariableValueToObject( mojo, "project", mavenProject ); return mojo; }
@SuppressWarnings("unchecked") public <T extends Mojo> T loadPlugin(final String goal, final URL config) throws Exception { final File pomFile = temporaryFolder.newFile(); try (final InputStream in = config.openStream()) { FileUtils.copyInputStreamToFile(in, pomFile); } return (T) mojo.lookupMojo(goal, pomFile); }
@Override public void testExecute() throws Exception { final Mojo mojo = initMojo(); mojo.execute(); generatedCodeFixture.assertInterfaces(); }
protected Runnable getMojoExecutionTask(final Mojo mojo) { return new Runnable() { @Override public void run() { try { mojo.execute(); } catch (Exception e) { e.printStackTrace(); } } }; }
protected void setMojoProject( Mojo mojo, String name) throws MojoExecutionException { Model model = new Model(); Build build = new Build(); build.setOutputDirectory("target/test-build-output"); model.setBuild(build); setMojoField(mojo, name, new MavenProject(model)); }
protected void setMojoProperty( Mojo mojo, String name, Object value) throws MojoExecutionException { setMojoProperty(mojo, name, value.getClass(), value); }
protected void setMojoProperty( Mojo mojo, String name, boolean value) throws MojoExecutionException { setMojoProperty(mojo, name, Boolean.TYPE, Boolean.valueOf(value)); }
public void setUp() throws MojoExecutionException { Mojo mojo = new GenerateFacesConfigMojo(); File targetDir = new File("target/mojo-test-output/java"); setMojoProject(mojo, "project"); setMojoField(mojo, "configDirectory", new File("src/test/resources")); setMojoField(mojo, "configPath", "META-INF/faces-config.xml"); setMojoField(mojo, "targetDirectory", targetDir); setMojoField(mojo, "force", Boolean.TRUE); _mojo = mojo; _targetDir = targetDir; }
/** * Creates a new pipeline. Notice that the set of watchers cannot change. * @param mojo the 'run' mojo * @param baseDir the base directory of the watched project * @param list the set of watchers plugged on the pipeline, the order of the list will be the notification order. * @param pomFileMonitoring flag enabling or disabling the pom file monitoring */ public Pipeline(Mojo mojo, File baseDir, List<? extends Watcher> list, boolean pomFileMonitoring) { this.mojo = mojo; this.baseDir = baseDir; this.pomFileMonitoring = pomFileMonitoring; mojo.getLog().debug("Initializing watch mode with " + list); watchers = new ArrayList<>(); for (Object o : list) { watchers.add(new WatcherDelegate(o)); } }
@Test public void testNoWatchers() throws Exception { MavenSession session = mock(MavenSession.class); when(session.getExecutionProperties()).thenReturn(new Properties()); File baseDir = new File("target/junk"); Mojo mojo = mock(Mojo.class); Log log = mock(Log.class); when(mojo.getLog()).thenReturn(log); Pipelines.watchers(session, baseDir, mojo, true); }
@Before public void setUp() throws IOException { FileUtils.forceMkdir(SOURCES); textWatcher = new SpyWatcher(SOURCES, "txt"); mdWatcher = new SpyWatcher(SOURCES, "md"); mojo = mock(Mojo.class); Log log = mock(Log.class); when(mojo.getLog()).thenReturn(log); pipeline = new Pipeline(mojo, FAKE, Arrays.asList(textWatcher, mdWatcher), false); pipeline.watch(); }