added extensive urls inheritance unit tests, even for most tricky parts

This commit is contained in:
Hervé Boutemy 2015-09-02 04:36:00 +02:00
parent 6b6e9bf39e
commit a2eb2fe3ee
13 changed files with 623 additions and 9 deletions

View File

@ -28,6 +28,8 @@
import org.custommonkey.xmlunit.XMLAssert;
import org.custommonkey.xmlunit.XMLUnit;
import junit.framework.AssertionFailedError;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@ -71,29 +73,109 @@ private Model getModel( String name )
public void testPluginConfiguration()
throws Exception
{
Model parent = getModel( "plugin-configuration-parent" );
testInheritance( "plugin-configuration" );
}
Model child = getModel( "plugin-configuration-child" );
/**
* Check most classical urls inheritance: directory structure where parent POM in parent directory
* and child directory == artifatId
* @throws Exception
*/
public void testUrls()
throws Exception
{
testInheritance( "urls" );
}
/**
* Flat directory structure: parent & child POMs in sibling directories, child directory == artifactId.
* @throws Exception
*/
public void testFlatUrls()
throws Exception
{
testInheritance( "flat-urls" );
}
/**
* Tricky case: flat directory structure, but child directory != artifactId.
* Model interpolation does not give same result when calculated from build or from repo...
* This is why MNG-5000 fix in code is marked as bad practice (uses file names)
* @throws Exception
*/
public void testFlatTrickyUrls()
throws Exception
{
// parent references child with artifactId (which is not directory name)
// then relative path calculation will fail during build from disk but success when calculated from repo
try
{
// build from disk expected to fail
testInheritance( "tricky-flat-artifactId-urls", false );
fail( "should have failed since module reference == artifactId != directory name" );
}
catch ( AssertionFailedError afe )
{
// expected failure: wrong relative path calculation
assertTrue( afe.getMessage().contains( "http://www.apache.org/path/to/parent/child-artifact-id/" ) );
}
// but ok from repo: local disk is ignored
testInheritance( "tricky-flat-artifactId-urls", true );
// parent references child with directory name (which is not artifact id)
// then relative path calculation will success during build from disk but failwhen calculated from repo
testInheritance( "tricky-flat-directory-urls", false );
try
{
testInheritance( "tricky-flat-directory-urls", true );
fail( "should have failed since module reference == directory name != artifactId" );
}
catch ( AssertionFailedError afe )
{
// expected failure
assertTrue( afe.getMessage().contains( "http://www.apache.org/path/to/parent/child-artifact-id/" ) );
}
}
public void testInheritance( String baseName )
throws Exception
{
testInheritance( baseName, false );
testInheritance( baseName, true );
}
public void testInheritance( String baseName, boolean fromRepo )
throws Exception
{
Model parent = getModel( baseName + "-parent" );
Model child = getModel( baseName + "-child" );
if ( fromRepo )
{
// when model is read from repo, a stream is used, then pomFile == null
// (has consequences in inheritance algorithm since getProjectDirectory() returns null)
parent.setPomFile( null );
child.setPomFile( null );
}
SimpleProblemCollector problems = new SimpleProblemCollector();
assembler.assembleModelInheritance( child, parent, null, problems );
File actual = getTestFile( "target/test-classes/poms/inheritance/plugin-configuration-actual.xml" );
// write baseName + "-actual"
File actual = getTestFile( "target/test-classes/poms/inheritance/" + baseName
+ ( fromRepo ? "-build" : "-repo" ) + "-actual.xml" );
writer.write( actual, null, child );
// check with getPom( "plugin-configuration-effective" )
File expected = getPom( "plugin-configuration-expected" );
// check with getPom( baseName + "-expected" )
File expected = getPom( baseName + "-expected" );
try ( Reader control = new InputStreamReader( new FileInputStream( expected ), "UTF-8" );
Reader test = new InputStreamReader( new FileInputStream( actual ), "UTF-8" ) )
{
XMLUnit.setIgnoreComments( true );
XMLUnit.setIgnoreWhitespace( true );
XMLAssert.assertXMLEqual( control, test );
}
}
}

View File

@ -0,0 +1,34 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>inheritance</groupId>
<artifactId>parent</artifactId>
<version>11-SNAPSHOT</version>
</parent>
<artifactId>inheritance</artifactId><!-- same as directory name -->
<name>Model urls inheritance test child</name>
</project>

View File

@ -0,0 +1,50 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>inheritance</groupId>
<artifactId>parent</artifactId>
<version>11-SNAPSHOT</version>
</parent>
<groupId>inheritance</groupId>
<artifactId>inheritance</artifactId>
<version>11-SNAPSHOT</version>
<name>Model urls inheritance test child</name>
<description>Flat directory structure case: module = ../child-artifact-id + child directory path == child-artifact-id</description>
<!-- 5 inherited urls with ../${project.artifactId} added to parent -->
<url>http://www.apache.org/path/to/parent/../inheritance/</url>
<scm>
<connection>scm:my-scm:http://domain.org/base/../inheritance</connection>
<developerConnection>scm:my-scm:https://domain.org/base/../inheritance/</developerConnection>
<url>https://domain.org/base/../inheritance</url>
</scm>
<distributionManagement>
<site>
<url>scp://scp.domain.org/base/../inheritance/</url>
</site>
</distributionManagement>
</project>

View File

@ -0,0 +1,49 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>inheritance</groupId>
<artifactId>parent</artifactId>
<version>11-SNAPSHOT</version>
<name>Model urls inheritance test parent</name>
<description>Flat directory structure case: module = ../child-artifact-id + child directory path == child-artifact-id</description>
<modules>
<module>../inheritance</module>
</modules>
<!-- 5 urls in the pom will be inherited with path added -->
<url>http://www.apache.org/path/to/parent/</url>
<scm>
<connection>scm:my-scm:http://domain.org/base</connection>
<developerConnection>scm:my-scm:https://domain.org/base/</developerConnection>
<url>https://domain.org/base</url>
</scm>
<distributionManagement>
<site>
<url>scp://scp.domain.org/base/</url>
</site>
</distributionManagement>
</project>

View File

@ -0,0 +1,34 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>inheritance</groupId>
<artifactId>parent</artifactId>
<version>11-SNAPSHOT</version>
</parent>
<artifactId>child-artifact-id</artifactId>
<name>Model urls inheritance test child</name>
</project>

View File

@ -0,0 +1,50 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>inheritance</groupId>
<artifactId>parent</artifactId>
<version>11-SNAPSHOT</version>
</parent>
<groupId>inheritance</groupId>
<artifactId>child-artifact-id</artifactId>
<version>11-SNAPSHOT</version>
<name>Model urls inheritance test child</name>
<description>Flat directory structure case: module = ../child-artifact-id + child directory path != child-artifact-id</description>
<!-- 5 inherited urls with ../${project.artifactId} added to parent -->
<url>http://www.apache.org/path/to/parent/../child-artifact-id/</url>
<scm>
<connection>scm:my-scm:http://domain.org/base/../child-artifact-id</connection>
<developerConnection>scm:my-scm:https://domain.org/base/../child-artifact-id/</developerConnection>
<url>https://domain.org/base/../child-artifact-id</url>
</scm>
<distributionManagement>
<site>
<url>scp://scp.domain.org/base/../child-artifact-id/</url>
</site>
</distributionManagement>
</project>

View File

@ -0,0 +1,49 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>inheritance</groupId>
<artifactId>parent</artifactId>
<version>11-SNAPSHOT</version>
<name>Model urls inheritance test parent</name>
<description>Flat directory structure case: module = ../child-artifact-id + child directory path != child-artifact-id</description>
<modules>
<module>../child-artifact-id</module><!-- use child artifact id, even if different from directory -->
</modules>
<!-- 5 urls in the pom will be inherited with path added -->
<url>http://www.apache.org/path/to/parent/</url>
<scm>
<connection>scm:my-scm:http://domain.org/base</connection>
<developerConnection>scm:my-scm:https://domain.org/base/</developerConnection>
<url>https://domain.org/base</url>
</scm>
<distributionManagement>
<site>
<url>scp://scp.domain.org/base/</url>
</site>
</distributionManagement>
</project>

View File

@ -0,0 +1,34 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>inheritance</groupId>
<artifactId>parent</artifactId>
<version>11-SNAPSHOT</version>
</parent>
<artifactId>child-artifact-id</artifactId>
<name>Model urls inheritance test child</name>
</project>

View File

@ -0,0 +1,50 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>inheritance</groupId>
<artifactId>parent</artifactId>
<version>11-SNAPSHOT</version>
</parent>
<groupId>inheritance</groupId>
<artifactId>child-artifact-id</artifactId>
<version>11-SNAPSHOT</version>
<name>Model urls inheritance test child</name>
<description>Flat directory structure case: module = ../child directory path + child directory path != child-artifact-id</description>
<!-- 5 inherited urls with ../${project.artifactId} added to parent -->
<url>http://www.apache.org/path/to/parent/../child-artifact-id/</url>
<scm>
<connection>scm:my-scm:http://domain.org/base/../child-artifact-id</connection>
<developerConnection>scm:my-scm:https://domain.org/base/../child-artifact-id/</developerConnection>
<url>https://domain.org/base/../child-artifact-id</url>
</scm>
<distributionManagement>
<site>
<url>scp://scp.domain.org/base/../child-artifact-id/</url>
</site>
</distributionManagement>
</project>

View File

@ -0,0 +1,49 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>inheritance</groupId>
<artifactId>parent</artifactId>
<version>11-SNAPSHOT</version>
<name>Model urls inheritance test parent</name>
<description>Flat directory structure case: module = ../child directory path + child directory path != child-artifact-id</description>
<modules>
<module>../inheritance</module><!-- current directory == inheritance -->
</modules>
<!-- 5 urls in the pom will be inherited with path added -->
<url>http://www.apache.org/path/to/parent/</url>
<scm>
<connection>scm:my-scm:http://domain.org/base</connection>
<developerConnection>scm:my-scm:https://domain.org/base/</developerConnection>
<url>https://domain.org/base</url>
</scm>
<distributionManagement>
<site>
<url>scp://scp.domain.org/base/</url>
</site>
</distributionManagement>
</project>

View File

@ -0,0 +1,34 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>inheritance</groupId>
<artifactId>parent</artifactId>
<version>11-SNAPSHOT</version>
</parent>
<artifactId>child-artifact-id</artifactId>
<name>Model urls inheritance test child</name>
</project>

View File

@ -0,0 +1,50 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>inheritance</groupId>
<artifactId>parent</artifactId>
<version>11-SNAPSHOT</version>
</parent>
<groupId>inheritance</groupId>
<artifactId>child-artifact-id</artifactId>
<version>11-SNAPSHOT</version>
<name>Model urls inheritance test child</name>
<description>Most classical case: child in direct subdirectory with directory name == child artifactId</description>
<!-- 5 inherited urls with ${project.artifactId} added to parent -->
<url>http://www.apache.org/path/to/parent/child-artifact-id/</url>
<scm>
<connection>scm:my-scm:http://domain.org/base/child-artifact-id</connection>
<developerConnection>scm:my-scm:https://domain.org/base/child-artifact-id/</developerConnection>
<url>https://domain.org/base/child-artifact-id</url>
</scm>
<distributionManagement>
<site>
<url>scp://scp.domain.org/base/child-artifact-id/</url>
</site>
</distributionManagement>
</project>

View File

@ -0,0 +1,49 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>inheritance</groupId>
<artifactId>parent</artifactId>
<version>11-SNAPSHOT</version>
<name>Model urls inheritance test parent</name>
<description>Most classical case: child in direct subdirectory with directory name == child artifactId</description>
<modules>
<module>child-artifact-id</module>
</modules>
<!-- 5 urls in the pom will be inherited with path added -->
<url>http://www.apache.org/path/to/parent/</url>
<scm>
<connection>scm:my-scm:http://domain.org/base</connection>
<developerConnection>scm:my-scm:https://domain.org/base/</developerConnection>
<url>https://domain.org/base</url>
</scm>
<distributionManagement>
<site>
<url>scp://scp.domain.org/base/</url>
</site>
</distributionManagement>
</project>