ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/startup/TestTomcatNoServer.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/startup/TestTomcatNoServer.java
Status
scanned
Type
file
Name
TestTomcatNoServer.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
4739 (4.6 KB)
MD5
e9432c2d134c20bc140377715bb2c10d
SHA1
f329f6588ae6d92b93e77a8a9d0e0d6d11b6976d
SHA256
65aa590fd2612fc984122a752f47432ccce20cca8c300be7d9296baa1fd3da26
SHA512

      
    
SHA1_git
63b3b3e2061af1c32a9c18a0356e9bcea44c29e4
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestTomcatNoServer.java | 4.6 KB |

/* * 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. */ package org.apache.catalina.startup; import java.io.File; import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.jar.JarFile; import java.util.jar.Manifest; import org.junit.Assert; import org.junit.Test; import org.apache.catalina.core.StandardContext; import org.apache.tomcat.util.descriptor.DigesterFactory; import org.apache.tomcat.util.descriptor.XmlErrorHandler; import org.apache.tomcat.util.descriptor.web.WebRuleSet; import org.apache.tomcat.util.descriptor.web.WebXml; import org.apache.tomcat.util.digester.Digester; import org.xml.sax.InputSource; /** * Tests that do not require a Tomcat instance to be started. */ public class TestTomcatNoServer { @Test public void testDefaultMimeTypeMappings() throws Exception { StandardContext ctx = new StandardContext(); Tomcat.initWebappDefaults(ctx); InputSource globalWebXml = new InputSource(new File("conf/web.xml").getAbsoluteFile().toURI().toString()); WebXml webXmlDefaultFragment = new WebXml(); webXmlDefaultFragment.setOverridable(true); webXmlDefaultFragment.setDistributable(true); webXmlDefaultFragment.setAlwaysAddWelcomeFiles(false); Digester digester = DigesterFactory.newDigester(true, true, new WebRuleSet(), true); XmlErrorHandler handler = new XmlErrorHandler(); digester.setErrorHandler(handler); digester.push(webXmlDefaultFragment); digester.parse(globalWebXml); Assert.assertEquals(0, handler.getErrors().size()); Assert.assertEquals(0, handler.getWarnings().size()); Map<String,String> webXmlMimeMappings = webXmlDefaultFragment.getMimeMappings(); Set<String> embeddedExtensions = new HashSet<>(Arrays.asList(ctx.findMimeMappings())); boolean pass = true; /* * Check that each entry for embedded is present in web.xml with the same media type. * Also finds entries that are missing in conf/web.xml */ Iterator<String> embeddedExtensionIterator = embeddedExtensions.iterator(); while (embeddedExtensionIterator.hasNext()) { String embeddedExtension = embeddedExtensionIterator.next(); String embeddedMediaType = ctx.findMimeMapping(embeddedExtension); if (!embeddedMediaType.equals(webXmlMimeMappings.get(embeddedExtension))) { pass = false; System.out.println("Extension [" + embeddedExtension + "] is mapped to [" + embeddedMediaType + "] in embedded but [" + webXmlMimeMappings.get(embeddedExtension) + "] in conf/web.xml"); } // Remove from both whether they matched or not embeddedExtensionIterator.remove(); webXmlMimeMappings.remove(embeddedExtension); } // Check for entries missing in embedded if (webXmlMimeMappings.size() > 0) { pass = false; for (Map.Entry<String,String> mapping : webXmlMimeMappings.entrySet()) { System.out.println("Extension [" + mapping.getKey() + "] is mapped to [" + mapping.getValue() + "] in conf/web.xml but [null] in embedded"); } } Assert.assertTrue(pass); } @Test public void testJarsDecoration() throws Exception { File libDir = new File(LoggingBaseTest.getBuildDirectory(), "lib"); try (JarFile catalinaJar = new JarFile(new File(libDir, "tomcat-util.jar"))) { Manifest manifest = catalinaJar.getManifest(); Assert.assertFalse(manifest.getMainAttributes().getValue("Export-Package").isEmpty()); Assert.assertNotNull(catalinaJar.getJarEntry("module-info.class")); } } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
24.64
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9