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

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

      
    
Rootfs path

      
    
Size
4662 (4.6 KB)
MD5
d666daba8854425248c213cc04c2101c
SHA1
0abbae018d76caaeb96f41de8ee3cf33631045b6
SHA256
512351bf435cfbdb9fe2de684d7fa15588c6c5694d63787875250dae7d63a967
SHA512

      
    
SHA1_git
292da324c0b0f2c21980b20f2bf6b5301ab6903c
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestPropertySources.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.ByteArrayInputStream; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.apache.catalina.Context; import org.apache.catalina.startup.TestTomcat.HelloWorld; import org.apache.tomcat.util.buf.ByteChunk; public class TestPropertySources extends LoggingBaseTest { public static class MyPropertySource1 implements org.apache.tomcat.util.IntrospectionUtils.PropertySource { @Override public String getProperty(String key) { if ("connector.port".equals(key)) { return "0"; } return null; } } public static class MyPropertySource2 implements org.apache.tomcat.util.IntrospectionUtils.PropertySource { @Override public String getProperty(String key) { if ("connector.timeout".equals(key)) { return "10000"; } return null; } } protected class ServerXml extends CatalinaBaseConfigurationSource { public ServerXml() { super(getTemporaryDirectory(), null); } private static final String SERVER_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> " + "<Server port=\"8005\" shutdown=\"SHUTDOWN\"> " + " <Service name=\"Catalina\"> " + " " + " <Connector port=\"${mysystemproperty}\" protocol=\"HTTP/1.1\" " + " connectionTimeout=\"${connector.timeout}\" " + " redirectPort=\"8443\" /> " + " <Engine name=\"Catalina\" defaultHost=\"localhost\"> " + " <Host name=\"localhost\" /> " + " </Engine> " + " </Service> " + "</Server>"; @Override public Resource getServerXml() throws IOException { Resource resource; try { resource = new Resource(new ByteArrayInputStream(SERVER_XML.getBytes(StandardCharsets.ISO_8859_1)), new URI("file:server.xml")); } catch (URISyntaxException e) { throw new IOException(e); } return resource; } } @BeforeClass public static void setupSystemProperties() { System.setProperty("org.apache.tomcat.util.digester.PROPERTY_SOURCE", "org.apache.catalina.startup.TestPropertySources$MyPropertySource1,org.apache.catalina.startup.TestPropertySources$MyPropertySource2"); System.setProperty("org.apache.tomcat.util.digester.REPLACE_SYSTEM_PROPERTIES", "true"); System.setProperty("mysystemproperty", "${connector.port}"); } @Test public void testPropertyReplacement() throws Exception { Tomcat tomcat = new Tomcat(); tomcat.init(new ServerXml()); // No file system docBase required Context ctx = tomcat.addContext("", null); Tomcat.addServlet(ctx, "myServlet", new HelloWorld()); ctx.addServletMappingDecoded("/", "myServlet"); tomcat.start(); Assert.assertEquals(System.getProperty("mysystemproperty"), "0"); Assert.assertEquals(tomcat.getConnector().getPort(), 0); Assert.assertEquals(tomcat.getConnector().getProperty("connectionTimeout"), Integer.valueOf(10000)); ByteChunk res = TomcatBaseTest.getUrl("http://localhost:" + tomcat.getConnector().getLocalPort() + "/"); Assert.assertEquals("Hello world", res.toString()); tomcat.stop(); tomcat.destroy(); } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
27.36
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