-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated archetypes and created a test to keep archetype versions up-t…
…o-date Signed-off-by: jansupol <jan.supol@oracle.com>
- Loading branch information
Showing
4 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
tests/release-test/src/test/java/org/glassfish/jersey/test/artifacts/ArchetypesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
package org.glassfish.jersey.test.artifacts; | ||
|
||
import org.apache.maven.model.Model; | ||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
public class ArchetypesTest { | ||
public static final String[] archetypePoms = { | ||
"../../archetypes/jersey-example-java8-webapp/src/main/resources/archetype-resources/pom.xml", | ||
"../../archetypes/jersey-heroku-webapp/src/main/resources/archetype-resources/pom.xml", | ||
"../../archetypes/jersey-quickstart-grizzly2/src/main/resources/archetype-resources/pom.xml", | ||
"../../archetypes/jersey-quickstart-webapp/src/main/resources/archetype-resources/pom.xml", | ||
}; | ||
|
||
@Test | ||
public void testPropertiesVersion() throws XmlPullParserException, IOException { | ||
Properties properties = MavenUtil.getModelFromFile("../../pom.xml").getProperties(); | ||
// System.out.println(properties); | ||
TestResult testResult = new TestResult(); | ||
for (String pom : archetypePoms) { | ||
File pomFile = new File(pom); | ||
Assert.assertTrue("The pom file " + pom + " does not exist", pomFile.exists()); | ||
Assert.assertTrue("The pom file " + pom + " cannot be read", pomFile.canRead()); | ||
|
||
boolean failed = false; | ||
Model pomModel = MavenUtil.getModelFromFile(pom); | ||
Properties pomProperties = pomModel.getProperties(); | ||
for (Map.Entry<Object, Object> pomEntry : pomProperties.entrySet()) { | ||
if (pomEntry.getKey().equals("jersey.config.test.container.port")) { | ||
// Skip the following | ||
continue; | ||
} | ||
// Update the names with the ones in Jersey | ||
Map.Entry<Object, Object> updatedEntry = updateEntry(pomEntry); | ||
// Check the properties are there | ||
if (properties.getProperty(updatedEntry.getKey().toString()) == null) { | ||
testResult.ok().append("Property ") | ||
.append(pomEntry.getKey().toString()) | ||
.append(" from ").append(pom).println(" not in Jersey"); | ||
failed = true; | ||
} | ||
// check the values | ||
else if (!properties.getProperty(updatedEntry.getKey().toString()).equals(updatedEntry.getValue())) { | ||
testResult.exception().append("The property ") | ||
.append(pomEntry.getKey().toString()) | ||
.append(" in archetype pom ") | ||
.append(pom) | ||
.append(" not equals Jersey ") | ||
.println(properties.getProperty(pomEntry.getKey().toString())); | ||
failed = true; | ||
} | ||
} | ||
if (!failed) { | ||
testResult.ok().append("The properties in archetype pom ").append(pom).println(" equals Jersey"); | ||
} | ||
} | ||
|
||
if (!testResult.result()) { | ||
Assert.fail(); | ||
} | ||
} | ||
|
||
private Map.Entry<Object, Object> updateEntry(Map.Entry<Object, Object> pomEntry) { | ||
if (pomEntry.getKey().equals("junit-jupiter.version")) { | ||
return new Map.Entry<Object, Object>() { | ||
@Override | ||
public Object getKey() { | ||
return "junit5.version"; | ||
} | ||
|
||
@Override | ||
public Object getValue() { | ||
return pomEntry.getValue(); | ||
} | ||
|
||
@Override | ||
public Object setValue(Object value) { | ||
return value; | ||
} | ||
}; | ||
} | ||
return pomEntry; | ||
} | ||
} |