|
16 | 16 |
|
17 | 17 | package org.openapitools.codegen.plugin;
|
18 | 18 |
|
| 19 | +import static org.junit.Assert.assertThrows; |
| 20 | + |
19 | 21 | import java.io.File;
|
20 | 22 | import java.nio.file.Files;
|
21 | 23 | import java.nio.file.Path;
|
|
31 | 33 | import org.apache.maven.execution.MavenExecutionRequest;
|
32 | 34 | import org.apache.maven.execution.MavenSession;
|
33 | 35 | import org.apache.maven.plugin.MojoExecution;
|
| 36 | +import org.apache.maven.plugin.MojoExecutionException; |
34 | 37 | import org.apache.maven.project.MavenProject;
|
35 | 38 | import org.apache.maven.project.ProjectBuilder;
|
36 | 39 | import org.apache.maven.project.ProjectBuildingRequest;
|
@@ -181,6 +184,36 @@ public void testCollapsedSpecAddedToArtifacts() throws Exception {
|
181 | 184 | assertEquals(1, matchingArtifacts.size());
|
182 | 185 | }
|
183 | 186 |
|
| 187 | + public void testAnyInputSpecMustBeProvided() throws Exception { |
| 188 | + // GIVEN |
| 189 | + Path folder = Files.createTempDirectory("test"); |
| 190 | + CodeGenMojo mojo = loadMojo(folder.toFile(), "src/test/resources/default", "executionId"); |
| 191 | + mojo.inputSpec = null; |
| 192 | + mojo.inputSpecRootDirectory = null; |
| 193 | + |
| 194 | + // WHEN |
| 195 | + MojoExecutionException e = assertThrows(MojoExecutionException.class, mojo::execute); |
| 196 | + |
| 197 | + // THEN |
| 198 | + assertEquals("inputSpec or inputSpecRootDirectory must be specified", e.getMessage()); |
| 199 | + } |
| 200 | + |
| 201 | + public void testInputSpecRootDirectoryDoesNotRequireInputSpec() throws Exception { |
| 202 | + // GIVEN |
| 203 | + Path folder = Files.createTempDirectory("test"); |
| 204 | + CodeGenMojo mojo = loadMojo(folder.toFile(), "src/test/resources/default", "executionId"); |
| 205 | + mojo.inputSpec = null; |
| 206 | + mojo.inputSpecRootDirectory = "src/test/resources/default"; |
| 207 | + |
| 208 | + // WHEN |
| 209 | + mojo.execute(); |
| 210 | + |
| 211 | + // THEN |
| 212 | + /* Check the hash file was created */ |
| 213 | + final Path hashFolder = folder.resolve("target/generated-sources/common-maven/remote-openapi/.openapi-generator"); |
| 214 | + assertTrue(hashFolder.resolve("_merged_spec.yaml-executionId.sha256").toFile().exists()); |
| 215 | + } |
| 216 | + |
184 | 217 | protected CodeGenMojo loadMojo(File temporaryFolder, String projectRoot) throws Exception {
|
185 | 218 | return loadMojo(temporaryFolder, projectRoot, "default");
|
186 | 219 | }
|
|
0 commit comments