You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2020/10/21 18:13:21 UTC
[maven] 05/06: Add unittest to verify transform result of
ConsumerModelSourceTransformer
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch MNG-6999
in repository https://gitbox.apache.org/repos/asf/maven.git
commit 6d6bdefa515d3b5a8ed2eb76f1ab304f36b2687b
Author: rfscholte <rf...@apache.org>
AuthorDate: Mon Oct 19 21:34:24 2020 +0200
Add unittest to verify transform result of ConsumerModelSourceTransformer
---
.../aether/ConsumerModelSourceTransformerTest.java | 75 ++++++++++++++++++++
.../src/test/resources/projects/transform.pom | 81 ++++++++++++++++++++++
2 files changed, 156 insertions(+)
diff --git a/maven-core/src/test/java/org/apache/maven/internal/aether/ConsumerModelSourceTransformerTest.java b/maven-core/src/test/java/org/apache/maven/internal/aether/ConsumerModelSourceTransformerTest.java
new file mode 100644
index 0000000..4863264
--- /dev/null
+++ b/maven-core/src/test/java/org/apache/maven/internal/aether/ConsumerModelSourceTransformerTest.java
@@ -0,0 +1,75 @@
+package org.apache.maven.internal.aether;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.Paths;
+import java.util.stream.Collectors;
+
+import org.apache.maven.model.Model;
+import org.apache.maven.model.building.TransformerContext;
+import org.junit.Test;
+import org.xmlunit.assertj.XmlAssert;
+
+public class ConsumerModelSourceTransformerTest
+{
+ private ConsumerModelSourceTransformer transformer = new ConsumerModelSourceTransformer();
+
+ @Test
+ public void test() throws Exception
+ {
+ Path pomFile = Paths.get( "src/test/resources/projects/transform.pom").toAbsolutePath();
+ InputStream in = transformer.transform( pomFile, new NoTransformerContext() );
+
+ String text =
+ new BufferedReader( new InputStreamReader( in,
+ StandardCharsets.UTF_8 ) ).lines().collect( Collectors.joining( "\n" ) );
+
+ XmlAssert.assertThat( in ).and( Files.newInputStream( pomFile ) ).areIdentical();
+ }
+
+ private static class NoTransformerContext implements TransformerContext
+ {
+ @Override
+ public String getUserProperty( String key )
+ {
+ return null;
+ }
+
+ @Override
+ public Model getRawModel( String groupId, String artifactId )
+ throws IllegalStateException
+ {
+ return null;
+ }
+
+ @Override
+ public Model getRawModel( Path p )
+ {
+ return null;
+ }
+ }
+}
diff --git a/maven-core/src/test/resources/projects/transform.pom b/maven-core/src/test/resources/projects/transform.pom
new file mode 100644
index 0000000..f48aba3
--- /dev/null
+++ b/maven-core/src/test/resources/projects/transform.pom
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you 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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>test</groupId>
+ <artifactId>test</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.1</version>
+ <configuration>
+ <source> 1.5 </source>
+ <target xml:space="preserve"> 1.5 </target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>test</id>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>default</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ </profile>
+ <profile>
+ <id>file</id>
+ <activation>
+ <file>
+ <exists>simple.xml</exists>
+ </file>
+ </activation>
+ <properties>
+ <profile.file>activated</profile.file>
+ </properties>
+ </profile>
+ </profiles>
+</project>