diff --git a/Jenkinsfile b/Jenkinsfile index 58c8cd6..e44e283 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -43,6 +43,9 @@ def upstreamProjects = [ 'servlet', // com.semanticcmssemanticcms-core-servlet // No Jenkins: com.github.spotbugsspotbugs-annotations + // Test Direct + // No Jenkins: junitjunit + // BOM '../../oss/javaee-web-api-bom', // com.aoappsjavaee-web-api-bom ] diff --git a/pom.xml b/pom.xml index 11cab2d..568dc60 100644 --- a/pom.xml +++ b/pom.xml @@ -192,6 +192,12 @@ along with semanticcms-core-sitemap. If not, see element-list, package-list ${project.build.directory}/offlineLinks/com.github.spotbugs/spotbugs-annotations + + + junitjunitjavadoc + element-list, package-list + ${project.build.directory}/offlineLinks/junit/junit + @@ -255,6 +261,11 @@ along with semanticcms-core-sitemap. If not, see https://javadoc.io/doc/com.github.spotbugs/spotbugs-annotations/${spotbugs-annotations.version}/ ${project.build.directory}/offlineLinks/com.github.spotbugs/spotbugs-annotations + + + https://junit.org/junit4/javadoc/latest/ + ${project.build.directory}/offlineLinks/junit/junit + @@ -398,6 +409,18 @@ along with semanticcms-core-sitemap. If not, see com.google.code.findbugsjsr3053.0.2 + + + junitjunit4.13.2 + + + + org.hamcresthamcrest2.2 + + + + org.hamcresthamcrest-core2.2 + com.aoappsjavaee-web-api-bom7.0.1-POST-SNAPSHOT @@ -452,6 +475,11 @@ along with semanticcms-core-sitemap. If not, see com.github.spotbugsspotbugs-annotations true + + + junitjunit + test + com.aoappsjavaee-web-api-bom7.0.1-POST-SNAPSHOT diff --git a/src/main/java/com/semanticcms/core/sitemap/SiteMapRobotsTxtServlet.java b/src/main/java/com/semanticcms/core/sitemap/SiteMapRobotsTxtServlet.java index 1bfe4bb..e18e869 100644 --- a/src/main/java/com/semanticcms/core/sitemap/SiteMapRobotsTxtServlet.java +++ b/src/main/java/com/semanticcms/core/sitemap/SiteMapRobotsTxtServlet.java @@ -64,12 +64,8 @@ public class SiteMapRobotsTxtServlet extends HttpServlet { static { try { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - if (cl == null) { - cl = ClassLoader.getSystemClassLoader(); - } - String classFilename = '/' + SiteMapRobotsTxtServlet.class.getName().replace('.', '/') + ".class"; - URL classFile = cl.getResource(classFilename); + String classFilename = SiteMapRobotsTxtServlet.class.getSimpleName() + ".class"; + URL classFile = SiteMapRobotsTxtServlet.class.getResource(classFilename); if (classFile == null) { throw new IOException("Unable to find class file: " + classFilename); } diff --git a/src/test/java/com/semanticcms/core/sitemap/SiteMapRobotsTxtServletTest.java b/src/test/java/com/semanticcms/core/sitemap/SiteMapRobotsTxtServletTest.java new file mode 100644 index 0000000..2916423 --- /dev/null +++ b/src/test/java/com/semanticcms/core/sitemap/SiteMapRobotsTxtServletTest.java @@ -0,0 +1,49 @@ +/* + * semanticcms-core-sitemap - Automatic sitemaps for SemanticCMS. + * Copyright (C) 2023 AO Industries, Inc. + * support@aoindustries.com + * 7262 Bull Pen Cir + * Mobile, AL 36695 + * + * This file is part of semanticcms-core-sitemap. + * + * semanticcms-core-sitemap is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * semanticcms-core-sitemap is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with semanticcms-core-sitemap. If not, see . + */ + +package com.semanticcms.core.sitemap; + +import static org.junit.Assert.assertNotEquals; + +import java.lang.reflect.Field; +import org.junit.Test; + +/** + * Tests {@link SiteMapRobotsTxtServlet}. + */ +public class SiteMapRobotsTxtServletTest { + + private static long getLastModified() throws ReflectiveOperationException { + Field field = SiteMapRobotsTxtServlet.class.getDeclaredField("LAST_MODIFIED"); + field.setAccessible(true); + return (long) field.get(null); + } + + /** + * Tests {@link SiteMapRobotsTxtServlet#LAST_MODIFIED}. + */ + @Test + public void testLastModified() throws ReflectiveOperationException { + assertNotEquals(0, getLastModified()); + } +}