Skip to content

Commit

Permalink
SHRINKRES-42 Added unit tests for property interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
kpiwko committed Dec 17, 2012
1 parent 2943494 commit 49e803a
Show file tree
Hide file tree
Showing 32 changed files with 218 additions and 25 deletions.
1 change: 1 addition & 0 deletions impl-maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@
<filtering>true</filtering>
</resource>
</resources>
<escapeString>\</escapeString>
</configuration>
</execution>
<execution>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* 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.shrinkwrap.resolver.impl.maven.integration;

import java.io.File;
import java.io.IOException;

import junit.framework.Assert;

import org.jboss.shrinkwrap.resolver.api.maven.Maven;
import org.jboss.shrinkwrap.resolver.impl.maven.util.TestFileUtil;
import org.jboss.shrinkwrap.resolver.impl.maven.util.ValidationUtil;
import org.junit.BeforeClass;
import org.junit.Test;

/**
* Tests for System property interpolation in Maven metadata.
*
* SHRINKRES-42
*
* @author <a href="kpiwko@redhat.com">Karel Piwko</a>
*
*/
public class PropertiesInterpolationTestCase {

private static final File INTERPOLATED_REPOSITORY;
static {
String javaVersion = System.getProperty("java.version");
INTERPOLATED_REPOSITORY = new File("target/repository-" + javaVersion);
}

@BeforeClass
public static void initialize() throws IOException {
System.clearProperty("maven.repo.local"); // May conflict with release settings
TestFileUtil.removeDirectory(INTERPOLATED_REPOSITORY);
}

@Test
public void interpolateSettingsXml() {

File file = Maven.configureResolver().fromFile("target/settings/profiles/settings-interpolation.xml")
.resolve("org.jboss.shrinkwrap.test:test-deps-c:1.0.0")
.withoutTransitivity().asSingle(File.class);
Assert.assertEquals("The file is packaged as test-deps-c-1.0.0.jar", "test-deps-c-1.0.0.jar", file.getName());

// check that repository was created
Assert.assertTrue("Local repository was created using interpolated ${java.version}", INTERPOLATED_REPOSITORY.exists());
}

@Test
public void interpolatePomWithSystemScopeXml() {

File[] files = Maven.configureResolver().fromFile("target/settings/profiles/settings.xml")
.resolve("org.jboss.shrinkwrap.test:test-system-scope:pom:1.0.0")
.withTransitivity().asFile();

new ValidationUtil("tools").validate(files);
}
}
11 changes: 11 additions & 0 deletions impl-maven/src/test/resources/poms/install-all.xml
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,17 @@
</configuration>
</execution>

<execution>
<id>install-system-scoped</id>
<goals>
<goal>install-file</goal>
</goals>
<phase>install</phase>
<configuration>
<file>${basedir}/test-system-scope.xml</file>
<pomFile>${basedir}/test-system-scope.xml</pomFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
27 changes: 27 additions & 0 deletions impl-maven/src/test/resources/poms/test-system-scope.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/maven-v4_0_0.xsd">

<!-- Model Version -->
<modelVersion>4.0.0</modelVersion>

<!-- Artifact Configuration -->
<groupId>org.jboss.shrinkwrap.test</groupId>
<artifactId>test-system-scope</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>

<build>
</build>

<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.6</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>

</project>
42 changes: 42 additions & 0 deletions impl-maven/src/test/resources/profiles/settings-interpolation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<!-- here we are on purpose excaping java version is maven does not filter it by itself -->
<localRepository>target/repository-\${java.version}</localRepository>

<profiles>
<profile>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>test-repository</id>
<name>Test repository</name>
<url>file://${basedir}/target/repository</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>test-repository</id>
<name>Test repository</name>
<url>file://${basedir}/target/repository</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</settings>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<version>1.0.0</version>
<version>2.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<version>2.0.0</version>
<version>1.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<version>2.0.0</version>
<version>1.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20120305203006</lastUpdated>
<lastUpdated>20121217110400</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/maven-v4_0_0.xsd">

<!-- Model Version -->
<modelVersion>4.0.0</modelVersion>

<!-- Artifact Configuration -->
<groupId>org.jboss.shrinkwrap.test</groupId>
<artifactId>test-system-scope</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>

<build>
</build>

<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.6</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>

</project>

0 comments on commit 49e803a

Please sign in to comment.