Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated archetypes and created a test to keep archetype versions up-to-date #5277

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,19 @@
<war>\${project.build.directory}/\${project.build.finalName}.war</war>
</configuration>
</plugin>
<plugin>
<!-- Surefire support for JUnit-5 -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.mvn.plugin.version}</version>
</plugin>
</plugins>
</build>

<properties>
<jersey.version>${project.version}</jersey.version>
<jetty.version>9.4.49.v20220914</jetty.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jetty.version>9.4.28.v20200408</jetty.version>
<surefire.mvn.plugin.version>3.0.0-M7</surefire.mvn.plugin.version>
</properties>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,19 @@
<mainClass>\${package}.Main</mainClass>
</configuration>
</plugin>
<plugin>
<!-- Surefire support for JUnit-5 -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.mvn.plugin.version}</version>
</plugin>
</plugins>
</build>

<properties>
<jersey.version>${project.version}</jersey.version>
<junit-jupiter.version>5.9.1</junit-jupiter.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<surefire.mvn.plugin.version>3.0.0-M7</surefire.mvn.plugin.version>
</properties>
</project>
7 changes: 4 additions & 3 deletions tests/release-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
<reuseForks>false</reuseForks>
<enableAssertions>false</enableAssertions>
<includes>
<include>**/NoticeFilesTest.class</include>
<include>**/ArchetypesTest</include>
<include>**/NoticeFilesTest</include>
</includes>
</configuration>
</plugin>
Expand Down Expand Up @@ -154,8 +155,8 @@
<reuseForks>false</reuseForks>
<enableAssertions>false</enableAssertions>
<includes>
<include>**/DownloadBomPomDependencies.java</include>
<include>**/*Test.class</include>
<include>**/DownloadBomPomDependencies</include>
<include>**/*Test</include>
</includes>
</configuration>
</plugin>
Expand Down
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;
}
}