forked from loafle/openapi-generator-original
Remove unused test dependencies org.reflections
& maven-rewrite
(#18798)
* Specify exact relative path to parent pom.xml * Remove org.reflections from the test stack * Remove unused parameter * Remove unused method * Fix raw use of parameterized variable warning * Use Files.readString instead of converting raw bytes * Add test coverage for TestUtils.validatePomXmlFiles(List) * Reimplement TestUtils.validatePomXmlFiles(List) with Jackson XML mapper * Remove maven-rewrite dependency
This commit is contained in:
parent
6a6f39d6f4
commit
66126a8ae4
@ -6,7 +6,7 @@
|
|||||||
<!-- RELEASE_VERSION -->
|
<!-- RELEASE_VERSION -->
|
||||||
<version>7.7.0-SNAPSHOT</version>
|
<version>7.7.0-SNAPSHOT</version>
|
||||||
<!-- /RELEASE_VERSION -->
|
<!-- /RELEASE_VERSION -->
|
||||||
<relativePath>../..</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>openapi-generator-cli</artifactId>
|
<artifactId>openapi-generator-cli</artifactId>
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<!-- RELEASE_VERSION -->
|
<!-- RELEASE_VERSION -->
|
||||||
<version>7.7.0-SNAPSHOT</version>
|
<version>7.7.0-SNAPSHOT</version>
|
||||||
<!-- /RELEASE_VERSION -->
|
<!-- /RELEASE_VERSION -->
|
||||||
<relativePath>../..</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<!-- RELEASE_VERSION -->
|
<!-- RELEASE_VERSION -->
|
||||||
<version>7.7.0-SNAPSHOT</version>
|
<version>7.7.0-SNAPSHOT</version>
|
||||||
<!-- /RELEASE_VERSION -->
|
<!-- /RELEASE_VERSION -->
|
||||||
<relativePath>../..</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<!-- RELEASE_VERSION -->
|
<!-- RELEASE_VERSION -->
|
||||||
<version>7.7.0-SNAPSHOT</version>
|
<version>7.7.0-SNAPSHOT</version>
|
||||||
<!-- /RELEASE_VERSION -->
|
<!-- /RELEASE_VERSION -->
|
||||||
<relativePath>../..</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||||
<name>openapi-generator (maven-plugin)</name>
|
<name>openapi-generator (maven-plugin)</name>
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<!-- RELEASE_VERSION -->
|
<!-- RELEASE_VERSION -->
|
||||||
<version>7.7.0-SNAPSHOT</version>
|
<version>7.7.0-SNAPSHOT</version>
|
||||||
<!-- /RELEASE_VERSION -->
|
<!-- /RELEASE_VERSION -->
|
||||||
<relativePath>../..</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>openapi-generator-online</artifactId>
|
<artifactId>openapi-generator-online</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<!-- RELEASE_VERSION -->
|
<!-- RELEASE_VERSION -->
|
||||||
<version>7.7.0-SNAPSHOT</version>
|
<version>7.7.0-SNAPSHOT</version>
|
||||||
<!-- /RELEASE_VERSION -->
|
<!-- /RELEASE_VERSION -->
|
||||||
<relativePath>../..</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>openapi-generator</artifactId>
|
<artifactId>openapi-generator</artifactId>
|
||||||
@ -349,17 +349,6 @@
|
|||||||
<version>3.24.9</version>
|
<version>3.24.9</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.openrewrite</groupId>
|
|
||||||
<artifactId>rewrite-maven</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.reflections</groupId>
|
|
||||||
<artifactId>reflections</artifactId>
|
|
||||||
<version>${reflections.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.googlecode.java-diff-utils</groupId>
|
<groupId>com.googlecode.java-diff-utils</groupId>
|
||||||
<artifactId>diffutils</artifactId>
|
<artifactId>diffutils</artifactId>
|
||||||
@ -392,6 +381,12 @@
|
|||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>${jackson-databind.version}</version>
|
<version>${jackson-databind.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||||
|
<artifactId>jackson-dataformat-xml</artifactId>
|
||||||
|
<version>${jackson.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||||
<artifactId>jackson-datatype-joda</artifactId>
|
<artifactId>jackson-datatype-joda</artifactId>
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
package org.openapitools.codegen;
|
package org.openapitools.codegen;
|
||||||
|
|
||||||
import static org.testng.Assert.assertNotNull;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import static org.testng.Assert.fail;
|
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||||
import static org.testng.Assert.assertTrue;
|
|
||||||
import static org.testng.Assert.assertFalse;
|
|
||||||
|
|
||||||
import com.github.javaparser.JavaParser;
|
import com.github.javaparser.JavaParser;
|
||||||
import com.github.javaparser.ParserConfiguration;
|
|
||||||
import com.github.javaparser.ParseResult;
|
import com.github.javaparser.ParseResult;
|
||||||
|
import com.github.javaparser.ParserConfiguration;
|
||||||
import com.github.javaparser.ast.CompilationUnit;
|
import com.github.javaparser.ast.CompilationUnit;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import io.swagger.parser.OpenAPIParser;
|
import io.swagger.parser.OpenAPIParser;
|
||||||
import io.swagger.v3.oas.models.Components;
|
import io.swagger.v3.oas.models.Components;
|
||||||
import io.swagger.v3.oas.models.OpenAPI;
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
@ -17,30 +15,20 @@ import io.swagger.v3.oas.models.info.Info;
|
|||||||
import io.swagger.v3.oas.models.media.Schema;
|
import io.swagger.v3.oas.models.media.Schema;
|
||||||
import io.swagger.v3.oas.models.servers.Server;
|
import io.swagger.v3.oas.models.servers.Server;
|
||||||
import io.swagger.v3.parser.core.models.ParseOptions;
|
import io.swagger.v3.parser.core.models.ParseOptions;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.openapitools.codegen.MockDefaultGenerator.WrittenTemplateBasedFile;
|
import org.openapitools.codegen.MockDefaultGenerator.WrittenTemplateBasedFile;
|
||||||
import org.openapitools.codegen.java.assertions.JavaFileAssert;
|
import org.openapitools.codegen.java.assertions.JavaFileAssert;
|
||||||
import org.openapitools.codegen.model.ModelMap;
|
import org.openapitools.codegen.model.ModelMap;
|
||||||
import org.openapitools.codegen.model.ModelsMap;
|
import org.openapitools.codegen.model.ModelsMap;
|
||||||
import org.openapitools.codegen.utils.ModelUtils;
|
import org.openapitools.codegen.utils.ModelUtils;
|
||||||
import org.openrewrite.maven.internal.RawPom;
|
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import static org.testng.Assert.*;
|
||||||
|
|
||||||
public class TestUtils {
|
public class TestUtils {
|
||||||
|
|
||||||
@ -100,7 +88,7 @@ public class TestUtils {
|
|||||||
return openAPI;
|
return openAPI;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OpenAPI createOpenAPIWithOneSchema(String name, Schema schema) {
|
public static OpenAPI createOpenAPIWithOneSchema(String name, Schema<?> schema) {
|
||||||
OpenAPI openAPI = createOpenAPI();
|
OpenAPI openAPI = createOpenAPI();
|
||||||
openAPI.setComponents(new Components());
|
openAPI.setComponents(new Components());
|
||||||
openAPI.getComponents().addSchemas(name, schema);
|
openAPI.getComponents().addSchemas(name, schema);
|
||||||
@ -135,47 +123,36 @@ public class TestUtils {
|
|||||||
assertFalse(generatedFiles.contains(path.toFile()), "File '" + path.toAbsolutePath() + "' was found in the list of generated files");
|
assertFalse(generatedFiles.contains(path.toFile()), "File '" + path.toAbsolutePath() + "' was found in the list of generated files");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void validatePomXmlFiles(final Map<String, String> fileMap) {
|
|
||||||
fileMap.forEach( (fileName, fileContents) -> {
|
|
||||||
if ("pom.xml".equals(fileName)) {
|
|
||||||
assertValidPomXml(fileContents);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void validatePomXmlFiles(final List<File> files) {
|
public static void validatePomXmlFiles(final List<File> files) {
|
||||||
files.forEach( f -> {
|
if (files == null
|
||||||
String fileName = f.getName();
|
|| files.isEmpty()
|
||||||
if ("pom.xml".equals(fileName)) {
|
|| files.stream().noneMatch(f -> f.getName().equals("pom.xml"))) return;
|
||||||
|
|
||||||
|
final XmlMapper mapper = new XmlMapper();
|
||||||
|
for (File file : files) {
|
||||||
|
if (!"pom.xml".equals(file.getName())) continue;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String fileContents = new String(Files.readAllBytes(f.toPath()), StandardCharsets.UTF_8);
|
JsonNode pomContents = mapper.readTree(file);
|
||||||
assertValidPomXml(fileContents);
|
assertValidPomXml(pomContents);
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
throw new RuntimeException(exception);
|
throw new RuntimeException(exception);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertValidPomXml(final String fileContents) {
|
private static void assertValidPomXml(final JsonNode pom) {
|
||||||
final InputStream input = new ByteArrayInputStream(fileContents.getBytes(StandardCharsets.UTF_8));
|
assertFalse(pom.path("dependencies").isEmpty());
|
||||||
try {
|
assertNotNull(pom.get("name"));
|
||||||
RawPom pom = RawPom.parse(input, null);
|
assertNotNull(pom.get("artifactId"));
|
||||||
assertTrue(pom.getDependencies().getDependencies().size() > 0);
|
assertNotNull(pom.get("groupId"));
|
||||||
assertNotNull(pom.getName());
|
assertNotNull(pom.get("version"));
|
||||||
assertNotNull(pom.getArtifactId());
|
|
||||||
assertNotNull(pom.getGroupId());
|
|
||||||
assertNotNull(pom.getVersion());
|
|
||||||
} finally {
|
|
||||||
IOUtils.closeQuietly(input);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void validateJavaSourceFiles(Map<String, String> fileMap) {
|
public static void validateJavaSourceFiles(Map<String, String> fileMap) {
|
||||||
fileMap.forEach( (fileName, fileContents) -> {
|
fileMap.forEach( (fileName, fileContents) -> {
|
||||||
if (fileName.endsWith(".java")) {
|
if (fileName.endsWith(".java")) {
|
||||||
assertValidJavaSourceCode(fileContents, fileName);
|
assertValidJavaSourceCode(fileContents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -183,21 +160,20 @@ public class TestUtils {
|
|||||||
|
|
||||||
public static void validateJavaSourceFiles(List<File> files) {
|
public static void validateJavaSourceFiles(List<File> files) {
|
||||||
files.forEach( f -> {
|
files.forEach( f -> {
|
||||||
String fileName = f.getName();
|
if (f.getName().endsWith(".java")) {
|
||||||
if (fileName.endsWith(".java")) {
|
|
||||||
String fileContents = "";
|
String fileContents = "";
|
||||||
try {
|
try {
|
||||||
fileContents = new String(Files.readAllBytes(f.toPath()), StandardCharsets.UTF_8);
|
fileContents = Files.readString(f.toPath());
|
||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
|
|
||||||
}
|
}
|
||||||
assertValidJavaSourceCode(fileContents, fileName);
|
assertValidJavaSourceCode(fileContents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertValidJavaSourceCode(String javaSourceCode, String filename) {
|
public static void assertValidJavaSourceCode(String javaSourceCode) {
|
||||||
ParserConfiguration config = new ParserConfiguration();
|
ParserConfiguration config = new ParserConfiguration();
|
||||||
config.setLanguageLevel(ParserConfiguration.LanguageLevel.JAVA_11);
|
config.setLanguageLevel(ParserConfiguration.LanguageLevel.JAVA_11);
|
||||||
JavaParser parser = new JavaParser(config);
|
JavaParser parser = new JavaParser(config);
|
||||||
@ -207,7 +183,7 @@ public class TestUtils {
|
|||||||
|
|
||||||
public static void assertFileContains(Path path, String... lines) {
|
public static void assertFileContains(Path path, String... lines) {
|
||||||
try {
|
try {
|
||||||
String generatedFile = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
|
String generatedFile = Files.readString(path);
|
||||||
String file = linearize(generatedFile);
|
String file = linearize(generatedFile);
|
||||||
assertNotNull(file);
|
assertNotNull(file);
|
||||||
for (String line : lines)
|
for (String line : lines)
|
||||||
@ -224,7 +200,7 @@ public class TestUtils {
|
|||||||
public static void assertFileNotContains(Path path, String... lines) {
|
public static void assertFileNotContains(Path path, String... lines) {
|
||||||
String generatedFile = null;
|
String generatedFile = null;
|
||||||
try {
|
try {
|
||||||
generatedFile = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
|
generatedFile = Files.readString(path);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
fail("Unable to evaluate file " + path);
|
fail("Unable to evaluate file " + path);
|
||||||
}
|
}
|
||||||
@ -236,7 +212,7 @@ public class TestUtils {
|
|||||||
|
|
||||||
public static void assertFileNotExists(Path path) {
|
public static void assertFileNotExists(Path path) {
|
||||||
try {
|
try {
|
||||||
new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
|
Files.readString(path);
|
||||||
fail("File exists when it should not: " + path);
|
fail("File exists when it should not: " + path);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// File exists, pass.
|
// File exists, pass.
|
||||||
@ -246,7 +222,7 @@ public class TestUtils {
|
|||||||
|
|
||||||
public static void assertFileExists(Path path) {
|
public static void assertFileExists(Path path) {
|
||||||
try {
|
try {
|
||||||
new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
|
Files.readString(path);
|
||||||
// File exists, pass.
|
// File exists, pass.
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -0,0 +1,175 @@
|
|||||||
|
package org.openapitools.codegen;
|
||||||
|
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
|
||||||
|
@SuppressWarnings("NewClassNamingConvention")
|
||||||
|
public class TestUtilsTest {
|
||||||
|
|
||||||
|
// forbiddenapis check will fail if we don't explicitly define localization when using String.format
|
||||||
|
static final Locale L = null;
|
||||||
|
|
||||||
|
public static class validatePomXmlFiles {
|
||||||
|
|
||||||
|
static final String POM_SCAFFOLD = "<project>%s<dependencies>%s</dependencies></project>";
|
||||||
|
static final String POM_PROJECT_INFO = "<name>foo</name><artifactId>foo.bar</artifactId><groupId>foobar</groupId><version>13.12</version>";
|
||||||
|
|
||||||
|
@Test void doesNotThrow_ifNotPom_doesNotExist() {
|
||||||
|
final var vaporFile = newTempDir().resolve("other.xml").toFile();
|
||||||
|
|
||||||
|
assertThatCode(() -> TestUtils.validatePomXmlFiles(List.of(vaporFile)))
|
||||||
|
.doesNotThrowAnyException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test void throwsRuntimeException_ifPomDoesNotExist() {
|
||||||
|
final var vaporBom = newTempDir().resolve("pom.xml").toFile();
|
||||||
|
|
||||||
|
assertThatThrownBy(() -> TestUtils.validatePomXmlFiles(List.of(vaporBom)))
|
||||||
|
.isExactlyInstanceOf(RuntimeException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test void throwsRuntimeException_ifXmlIsJson() {
|
||||||
|
Path testFile = newPomXmlFile("{\"not_xml\": 12345}");
|
||||||
|
|
||||||
|
assertThatThrownBy(() -> TestUtils.validatePomXmlFiles(List.of(testFile.toFile())))
|
||||||
|
.isExactlyInstanceOf(RuntimeException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test void throwsRuntimeException_ifXmlIsInvalid() {
|
||||||
|
final Path testFile = newPomXmlFile("<IAmNotClosed>");
|
||||||
|
|
||||||
|
assertThatThrownBy(() -> TestUtils.validatePomXmlFiles(List.of(testFile.toFile())))
|
||||||
|
.isExactlyInstanceOf(RuntimeException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test void throwsAssertionError_ifNameTagIsMissing() {
|
||||||
|
final Path testFile = newPomXmlFile(replaceTag("name", "", getMinimalValidPomContent()));
|
||||||
|
|
||||||
|
assertThatThrownBy(() -> TestUtils.validatePomXmlFiles(List.of(testFile.toFile())))
|
||||||
|
.isExactlyInstanceOf(AssertionError.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test void doesNotThrow_ifNameIsEmpty() {
|
||||||
|
final Path testFile = newPomXmlFile(
|
||||||
|
replaceTag("name", "<name></name>", getMinimalValidPomContent())
|
||||||
|
);
|
||||||
|
|
||||||
|
assertThatCode(() -> TestUtils.validatePomXmlFiles(List.of(testFile.toFile())))
|
||||||
|
.doesNotThrowAnyException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test void throwsAssertionError_ifArtifactIdTagIsMissing() {
|
||||||
|
final Path testFile = newPomXmlFile(replaceTag("artifactId", "", getMinimalValidPomContent()));
|
||||||
|
|
||||||
|
assertThatThrownBy(() -> TestUtils.validatePomXmlFiles(List.of(testFile.toFile())))
|
||||||
|
.isExactlyInstanceOf(AssertionError.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test void doesNotThrow_ifArtifactIdIsEmpty() {
|
||||||
|
final Path testFile = newPomXmlFile(
|
||||||
|
replaceTag("artifactId", "<artifactId></artifactId>", getMinimalValidPomContent())
|
||||||
|
);
|
||||||
|
|
||||||
|
assertThatCode(() -> TestUtils.validatePomXmlFiles(List.of(testFile.toFile())))
|
||||||
|
.doesNotThrowAnyException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test void throwsAssertionError_ifGroupIdTagIsMissing() {
|
||||||
|
final Path testFile = newPomXmlFile(replaceTag("groupId", "", getMinimalValidPomContent()));
|
||||||
|
|
||||||
|
assertThatThrownBy(() -> TestUtils.validatePomXmlFiles(List.of(testFile.toFile())))
|
||||||
|
.isExactlyInstanceOf(AssertionError.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test void doesNotThrow_ifGroupIdIsEmpty() {
|
||||||
|
final Path testFile = newPomXmlFile(
|
||||||
|
replaceTag("groupId", "<groupId></groupId>", getMinimalValidPomContent())
|
||||||
|
);
|
||||||
|
|
||||||
|
assertThatCode(() -> TestUtils.validatePomXmlFiles(List.of(testFile.toFile())))
|
||||||
|
.doesNotThrowAnyException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test void throwsAssertionError_ifVersionTagIsMissing() {
|
||||||
|
final Path testFile = newPomXmlFile(replaceTag("version", "", getMinimalValidPomContent()));
|
||||||
|
|
||||||
|
assertThatThrownBy(() -> TestUtils.validatePomXmlFiles(List.of(testFile.toFile())))
|
||||||
|
.isExactlyInstanceOf(AssertionError.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test void doesNotThrow_ifVersionIsEmpty() {
|
||||||
|
final Path testFile = newPomXmlFile(
|
||||||
|
replaceTag("version", "<version></version>", getMinimalValidPomContent())
|
||||||
|
);
|
||||||
|
|
||||||
|
assertThatCode(() -> TestUtils.validatePomXmlFiles(List.of(testFile.toFile())))
|
||||||
|
.doesNotThrowAnyException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test void throwsAssertionError_ifZeroDependencies() {
|
||||||
|
final Path testFile = newPomXmlFile(String.format(L, POM_SCAFFOLD, POM_PROJECT_INFO, ""));
|
||||||
|
|
||||||
|
assertThatThrownBy(() -> TestUtils.validatePomXmlFiles(List.of(testFile.toFile())))
|
||||||
|
.isExactlyInstanceOf(AssertionError.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test void doesNotThrow_ifAtLeastOneDependency() {
|
||||||
|
final Path testFile = newPomXmlFile(String.format(L, POM_SCAFFOLD, POM_PROJECT_INFO, "<dependency />"));
|
||||||
|
|
||||||
|
assertThatCode(() -> TestUtils.validatePomXmlFiles(List.of(testFile.toFile())))
|
||||||
|
.doesNotThrowAnyException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test void throwsAssertionError_withTwoValidPoms_whereSecondHasNoName() {
|
||||||
|
final File testFile1 = newPomXmlFile(getMinimalValidPomContent()).toFile();
|
||||||
|
final File testFile2 = newPomXmlFile(replaceTag("name", "", getMinimalValidPomContent())).toFile();
|
||||||
|
|
||||||
|
assertThatThrownBy(() -> TestUtils.validatePomXmlFiles(List.of(testFile1, testFile2)))
|
||||||
|
.isExactlyInstanceOf(AssertionError.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test void doesNotThrow_withTwoValidPoms() {
|
||||||
|
final File testFile1 = newPomXmlFile(getMinimalValidPomContent()).toFile();
|
||||||
|
final File testFile2 = newPomXmlFile(getMinimalValidPomContent()).toFile();
|
||||||
|
|
||||||
|
assertThatCode(() -> TestUtils.validatePomXmlFiles(List.of(testFile1, testFile2)))
|
||||||
|
.doesNotThrowAnyException();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String replaceTag(String tagToReplace, String replaceWith, String xml) {
|
||||||
|
return xml.replaceAll("<" + tagToReplace + ">[\\s\\S]*?</" + tagToReplace + ">", replaceWith);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getMinimalValidPomContent() {
|
||||||
|
return String.format(L, POM_SCAFFOLD, POM_PROJECT_INFO, "<dependency />");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Path newPomXmlFile(String content) {
|
||||||
|
try {
|
||||||
|
return Files.writeString(newTempDir().resolve("pom.xml"), content);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Path newTempDir() {
|
||||||
|
final Path tempDir;
|
||||||
|
try {
|
||||||
|
tempDir = Files.createTempDirectory("test");
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
tempDir.toFile().deleteOnExit();
|
||||||
|
return tempDir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
8
pom.xml
8
pom.xml
@ -1198,12 +1198,6 @@
|
|||||||
<version>${testng.version}</version>
|
<version>${testng.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.openrewrite</groupId>
|
|
||||||
<artifactId>rewrite-maven</artifactId>
|
|
||||||
<version>${openrewrite.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
<repositories>
|
<repositories>
|
||||||
@ -1248,9 +1242,7 @@
|
|||||||
<maven-site-plugin.version>4.0.0-M8</maven-site-plugin.version>
|
<maven-site-plugin.version>4.0.0-M8</maven-site-plugin.version>
|
||||||
<maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
|
<maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
|
||||||
<mockito.version>4.10.0</mockito.version>
|
<mockito.version>4.10.0</mockito.version>
|
||||||
<openrewrite.version>8.8.3</openrewrite.version>
|
|
||||||
<pmd-plugin.version>3.12.0</pmd-plugin.version>
|
<pmd-plugin.version>3.12.0</pmd-plugin.version>
|
||||||
<reflections.version>0.10.2</reflections.version>
|
|
||||||
<resolver-util-version>1.9.18</resolver-util-version>
|
<resolver-util-version>1.9.18</resolver-util-version>
|
||||||
<rxgen.version>1.4</rxgen.version>
|
<rxgen.version>1.4</rxgen.version>
|
||||||
<scala-maven-plugin.version>4.6.1</scala-maven-plugin.version>
|
<scala-maven-plugin.version>4.6.1</scala-maven-plugin.version>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user