From 40947fe037eaa244996994f8f1eb9ff11d023e61 Mon Sep 17 00:00:00 2001 From: Peter Palaga Date: Fri, 16 Oct 2020 14:34:38 +0200 Subject: [PATCH] Test a scenario using mvn #92 --- .../jboss/fuse/mvnd/it/InvokerNativeIT.java | 72 ++++++++++++ .../org/jboss/fuse/mvnd/it/InvokerTest.java | 23 ++++ .../src/test/projects/invoker/.mvn/.gitkeep | 0 .../src/test/projects/invoker/pom.xml | 106 ++++++++++++++++++ .../src/it/invoke-hello/invoker.properties | 15 +++ .../invoker/src/it/invoke-hello/pom.xml | 104 +++++++++++++++++ .../invoker/src/it/invoke-hello/verify.groovy | 24 ++++ .../mvnd/test/invoker/hello/HelloMojo.java | 51 +++++++++ 8 files changed, 395 insertions(+) create mode 100644 integration-tests/src/test/java/org/jboss/fuse/mvnd/it/InvokerNativeIT.java create mode 100644 integration-tests/src/test/java/org/jboss/fuse/mvnd/it/InvokerTest.java create mode 100644 integration-tests/src/test/projects/invoker/.mvn/.gitkeep create mode 100644 integration-tests/src/test/projects/invoker/pom.xml create mode 100644 integration-tests/src/test/projects/invoker/src/it/invoke-hello/invoker.properties create mode 100644 integration-tests/src/test/projects/invoker/src/it/invoke-hello/pom.xml create mode 100644 integration-tests/src/test/projects/invoker/src/it/invoke-hello/verify.groovy create mode 100644 integration-tests/src/test/projects/invoker/src/main/java/org/jboss/fuse/mvnd/test/invoker/hello/HelloMojo.java diff --git a/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/InvokerNativeIT.java b/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/InvokerNativeIT.java new file mode 100644 index 00000000..6fc0a00e --- /dev/null +++ b/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/InvokerNativeIT.java @@ -0,0 +1,72 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.fuse.mvnd.it; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.regex.Pattern; +import javax.inject.Inject; +import org.assertj.core.api.Assertions; +import org.jboss.fuse.mvnd.client.Client; +import org.jboss.fuse.mvnd.client.ClientLayout; +import org.jboss.fuse.mvnd.common.logging.ClientOutput; +import org.jboss.fuse.mvnd.junit.MvndNativeTest; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +@MvndNativeTest(projectDir = "src/test/projects/invoker") +public class InvokerNativeIT { + + @Inject + Client client; + + @Inject + ClientLayout layout; + + @Test + void cleanInstall() throws IOException, InterruptedException { + + final Path helloPath = layout.multiModuleProjectDirectory().resolve("target/it/invoke-hello/target/hello.txt"); + try { + Files.deleteIfExists(helloPath); + } catch (IOException e) { + throw new RuntimeException("Could not delete " + helloPath); + } + final Path logPath = layout.multiModuleProjectDirectory().resolve("target/it/invoke-hello/build.log"); + try { + Files.deleteIfExists(logPath); + } catch (IOException e) { + throw new RuntimeException("Could not delete " + helloPath); + } + + final ClientOutput output = Mockito.mock(ClientOutput.class); + client.execute(output, "clean", "verify", "-e", "-Dmvnd.log.level=DEBUG").assertSuccess(); + + Assertions.assertThat(helloPath).exists(); + Assertions.assertThat(helloPath).usingCharset(StandardCharsets.UTF_8).hasContent("Hello"); + + Assertions.assertThat(logPath).exists(); + final List logLines = Files.readAllLines(logPath, StandardCharsets.UTF_8); + Assertions.assertThat(logLines.size()).isGreaterThan(0); + + final String lastLine = logLines.get(logLines.size() - 1); + Assertions.assertThat(lastLine).matches(Pattern.compile("\\QFinished post-build script: \\E.*verify.groovy$")); + + } +} diff --git a/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/InvokerTest.java b/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/InvokerTest.java new file mode 100644 index 00000000..6ccd6115 --- /dev/null +++ b/integration-tests/src/test/java/org/jboss/fuse/mvnd/it/InvokerTest.java @@ -0,0 +1,23 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.fuse.mvnd.it; + +import org.jboss.fuse.mvnd.junit.MvndTest; + +@MvndTest(projectDir = "src/test/projects/invoker") +public class InvokerTest extends InvokerNativeIT { + +} diff --git a/integration-tests/src/test/projects/invoker/.mvn/.gitkeep b/integration-tests/src/test/projects/invoker/.mvn/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/integration-tests/src/test/projects/invoker/pom.xml b/integration-tests/src/test/projects/invoker/pom.xml new file mode 100644 index 00000000..fc7bb9a0 --- /dev/null +++ b/integration-tests/src/test/projects/invoker/pom.xml @@ -0,0 +1,106 @@ + + + 4.0.0 + + org.jboss.fuse.mvnd.test.invoker + invoker-hello-maven-plugin + 0.0.1-SNAPSHOT + maven-plugin + + + UTF-8 + 1.8 + 1.8 + + 2.5 + 3.8.0 + 2.4 + 2.6 + 3.0.0-M5 + + + + + org.apache.maven.plugin-tools + maven-plugin-annotations + provided + 3.5 + + + org.apache.maven + maven-plugin-api + 3.6.0 + + + + + + + + org.apache.maven.plugins + maven-clean-plugin + ${maven-clean-plugin.version} + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + + org.apache.maven.plugins + maven-install-plugin + ${maven-install-plugin.version} + + + org.apache.maven.plugins + maven-resources-plugin + ${maven-resources-plugin.version} + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + + + + + maven-invoker-plugin + 3.2.1 + + ${project.build.directory}/it + ${project.build.directory}/local-repo + verify + + + + integration-test + + install + run + verify + + + + + + + \ No newline at end of file diff --git a/integration-tests/src/test/projects/invoker/src/it/invoke-hello/invoker.properties b/integration-tests/src/test/projects/invoker/src/it/invoke-hello/invoker.properties new file mode 100644 index 00000000..14ea3e30 --- /dev/null +++ b/integration-tests/src/test/projects/invoker/src/it/invoke-hello/invoker.properties @@ -0,0 +1,15 @@ +# +# Copyright 2017 Decipher Technology Studios LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +invoker.goals=validate diff --git a/integration-tests/src/test/projects/invoker/src/it/invoke-hello/pom.xml b/integration-tests/src/test/projects/invoker/src/it/invoke-hello/pom.xml new file mode 100644 index 00000000..40402d22 --- /dev/null +++ b/integration-tests/src/test/projects/invoker/src/it/invoke-hello/pom.xml @@ -0,0 +1,104 @@ + + + 4.0.0 + + org.jboss.fuse.mvnd.test.invoker + invoke-hello + 0.0.1-SNAPSHOT + pom + + + UTF-8 + 1.8 + 1.8 + + 2.5 + 3.8.0 + 2.4 + 2.6 + 3.0.0-M5 + + + + + org.apache.maven.plugin-tools + maven-plugin-annotations + provided + 3.5 + + + org.apache.maven + maven-plugin-api + 3.6.0 + + + + + + + + org.apache.maven.plugins + maven-clean-plugin + ${maven-clean-plugin.version} + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + + org.apache.maven.plugins + maven-install-plugin + ${maven-install-plugin.version} + + + org.apache.maven.plugins + maven-resources-plugin + ${maven-resources-plugin.version} + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + + + + + org.jboss.fuse.mvnd.test.invoker + invoker-hello-maven-plugin + @project.version@ + + + hello + + hello + + validate + + ${basedir}/target/hello.txt + + + + + + + \ No newline at end of file diff --git a/integration-tests/src/test/projects/invoker/src/it/invoke-hello/verify.groovy b/integration-tests/src/test/projects/invoker/src/it/invoke-hello/verify.groovy new file mode 100644 index 00000000..26c2935e --- /dev/null +++ b/integration-tests/src/test/projects/invoker/src/it/invoke-hello/verify.groovy @@ -0,0 +1,24 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import java.nio.file.Path; +import java.nio.file.Files; + +Path basePath = basedir.toPath() +Path helloPath = basePath.resolve('target/hello.txt') + +assert Files.exists(helloPath) + +assert helloPath.text.equals('Hello') diff --git a/integration-tests/src/test/projects/invoker/src/main/java/org/jboss/fuse/mvnd/test/invoker/hello/HelloMojo.java b/integration-tests/src/test/projects/invoker/src/main/java/org/jboss/fuse/mvnd/test/invoker/hello/HelloMojo.java new file mode 100644 index 00000000..3205a80e --- /dev/null +++ b/integration-tests/src/test/projects/invoker/src/main/java/org/jboss/fuse/mvnd/test/invoker/hello/HelloMojo.java @@ -0,0 +1,51 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jboss.fuse.mvnd.test.invoker.hello; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; + +/** + */ +@Mojo(name = "hello", requiresProject = true) +public class HelloMojo extends AbstractMojo { + + @Parameter + File file; + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + + try { + final Path path = file.toPath(); + Files.createDirectories(path.getParent()); + Files.write(path, "Hello".getBytes(StandardCharsets.UTF_8)); + } catch (IOException e) { + throw new RuntimeException("", e); + } + + } + +}