This commit is contained in:
2024-11-30 19:03:49 +08:00
commit 1e6763c160
3806 changed files with 737676 additions and 0 deletions

View File

@@ -0,0 +1,244 @@
/*
* 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.util;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class TestContextName {
private ContextName cn1;
private ContextName cn2;
private ContextName cn3;
private ContextName cn4;
private ContextName cn5;
private ContextName cn6;
private ContextName cn7;
private ContextName cn8;
private ContextName cn9;
private ContextName cn10;
private ContextName cn11;
private ContextName cn12;
private ContextName cn13;
private ContextName cn14;
private ContextName cn15;
private ContextName cn16;
private ContextName cn17;
private ContextName cn18;
private ContextName cn19;
private ContextName cn20;
private ContextName cn21;
private ContextName cn22;
@Before
public void setUp() throws Exception {
cn1 = new ContextName(null, null);
cn2 = new ContextName("", null);
cn3 = new ContextName("/", null);
cn4 = new ContextName("/foo", null);
cn5 = new ContextName("/foo/bar", null);
cn6 = new ContextName(null, "A");
cn7 = new ContextName("", "B");
cn8 = new ContextName("/", "C");
cn9 = new ContextName("/foo", "D");
cn10 = new ContextName("/foo/bar", "E");
cn11 = new ContextName("ROOT", false);
cn12 = new ContextName("foo", false);
cn13 = new ContextName("foo#bar", false);
cn14 = new ContextName("ROOT##A", false);
cn15 = new ContextName("foo##D", false);
cn16 = new ContextName("foo#bar##E", false);
cn17 = new ContextName("/ROOT", null);
cn18 = new ContextName("/ROOT#bar", false);
cn19 = new ContextName("/ROOT#bar##A", false);
cn20 = new ContextName("/ROOT##A", false);
cn21 = new ContextName("foo.war", false);
cn22 = new ContextName("foo.war", true);
}
@Test
public void testGetBaseName() {
Assert.assertEquals("ROOT", cn1.getBaseName());
Assert.assertEquals("ROOT", cn2.getBaseName());
Assert.assertEquals("ROOT", cn3.getBaseName());
Assert.assertEquals("foo", cn4.getBaseName());
Assert.assertEquals("foo#bar", cn5.getBaseName());
Assert.assertEquals("ROOT##A", cn6.getBaseName());
Assert.assertEquals("ROOT##B", cn7.getBaseName());
Assert.assertEquals("ROOT##C", cn8.getBaseName());
Assert.assertEquals("foo##D", cn9.getBaseName());
Assert.assertEquals("foo#bar##E", cn10.getBaseName());
Assert.assertEquals("ROOT", cn11.getBaseName());
Assert.assertEquals("foo", cn12.getBaseName());
Assert.assertEquals("foo#bar", cn13.getBaseName());
Assert.assertEquals("ROOT##A", cn14.getBaseName());
Assert.assertEquals("foo##D", cn15.getBaseName());
Assert.assertEquals("foo#bar##E", cn16.getBaseName());
Assert.assertEquals("ROOT", cn17.getBaseName());
Assert.assertEquals("ROOT#bar", cn18.getBaseName());
Assert.assertEquals("ROOT#bar##A", cn19.getBaseName());
Assert.assertEquals("ROOT##A", cn20.getBaseName());
Assert.assertEquals("foo.war", cn21.getBaseName());
Assert.assertEquals("foo", cn22.getBaseName());
}
@Test
public void testGetPath() {
Assert.assertEquals("", cn1.getPath());
Assert.assertEquals("", cn2.getPath());
Assert.assertEquals("", cn3.getPath());
Assert.assertEquals("/foo", cn4.getPath());
Assert.assertEquals("/foo/bar", cn5.getPath());
Assert.assertEquals("", cn6.getPath());
Assert.assertEquals("", cn7.getPath());
Assert.assertEquals("", cn8.getPath());
Assert.assertEquals("/foo", cn9.getPath());
Assert.assertEquals("/foo/bar", cn10.getPath());
Assert.assertEquals("", cn11.getPath());
Assert.assertEquals("/foo", cn12.getPath());
Assert.assertEquals("/foo/bar", cn13.getPath());
Assert.assertEquals("", cn14.getPath());
Assert.assertEquals("/foo", cn15.getPath());
Assert.assertEquals("/foo/bar", cn16.getPath());
Assert.assertEquals("", cn17.getPath());
Assert.assertEquals("/ROOT/bar", cn18.getPath());
Assert.assertEquals("/ROOT/bar", cn19.getPath());
Assert.assertEquals("", cn20.getPath());
Assert.assertEquals("/foo.war", cn21.getPath());
Assert.assertEquals("/foo", cn22.getPath());
}
@Test
public void testGetVersion() {
Assert.assertEquals("", cn1.getVersion());
Assert.assertEquals("", cn2.getVersion());
Assert.assertEquals("", cn3.getVersion());
Assert.assertEquals("", cn4.getVersion());
Assert.assertEquals("", cn5.getVersion());
Assert.assertEquals("A", cn6.getVersion());
Assert.assertEquals("B", cn7.getVersion());
Assert.assertEquals("C", cn8.getVersion());
Assert.assertEquals("D", cn9.getVersion());
Assert.assertEquals("E", cn10.getVersion());
Assert.assertEquals("", cn11.getVersion());
Assert.assertEquals("", cn12.getVersion());
Assert.assertEquals("", cn13.getVersion());
Assert.assertEquals("A", cn14.getVersion());
Assert.assertEquals("D", cn15.getVersion());
Assert.assertEquals("E", cn16.getVersion());
Assert.assertEquals("", cn17.getVersion());
Assert.assertEquals("", cn18.getVersion());
Assert.assertEquals("A", cn19.getVersion());
Assert.assertEquals("A", cn20.getVersion());
Assert.assertEquals("", cn21.getVersion());
Assert.assertEquals("", cn22.getVersion());
}
@Test
public void testGetName() {
Assert.assertEquals("", cn1.getName());
Assert.assertEquals("", cn2.getName());
Assert.assertEquals("", cn3.getName());
Assert.assertEquals("/foo", cn4.getName());
Assert.assertEquals("/foo/bar", cn5.getName());
Assert.assertEquals("##A", cn6.getName());
Assert.assertEquals("##B", cn7.getName());
Assert.assertEquals("##C", cn8.getName());
Assert.assertEquals("/foo##D", cn9.getName());
Assert.assertEquals("/foo/bar##E", cn10.getName());
Assert.assertEquals("", cn11.getName());
Assert.assertEquals("/foo", cn12.getName());
Assert.assertEquals("/foo/bar", cn13.getName());
Assert.assertEquals("##A", cn14.getName());
Assert.assertEquals("/foo##D", cn15.getName());
Assert.assertEquals("/foo/bar##E", cn16.getName());
Assert.assertEquals("", cn17.getName());
Assert.assertEquals("/ROOT/bar", cn18.getName());
Assert.assertEquals("/ROOT/bar##A", cn19.getName());
Assert.assertEquals("##A", cn20.getName());
Assert.assertEquals("/foo.war", cn21.getName());
Assert.assertEquals("/foo", cn22.getName());
}
@Test
public void testGetDisplayName() {
Assert.assertEquals("/", cn1.getDisplayName());
Assert.assertEquals("/", cn2.getDisplayName());
Assert.assertEquals("/", cn3.getDisplayName());
Assert.assertEquals("/foo", cn4.getDisplayName());
Assert.assertEquals("/foo/bar", cn5.getDisplayName());
Assert.assertEquals("/##A", cn6.getDisplayName());
Assert.assertEquals("/##B", cn7.getDisplayName());
Assert.assertEquals("/##C", cn8.getDisplayName());
Assert.assertEquals("/foo##D", cn9.getDisplayName());
Assert.assertEquals("/foo/bar##E", cn10.getDisplayName());
Assert.assertEquals("/", cn11.getDisplayName());
Assert.assertEquals("/foo", cn12.getDisplayName());
Assert.assertEquals("/foo/bar", cn13.getDisplayName());
Assert.assertEquals("/##A", cn14.getDisplayName());
Assert.assertEquals("/foo##D", cn15.getDisplayName());
Assert.assertEquals("/foo/bar##E", cn16.getDisplayName());
Assert.assertEquals("/", cn17.getDisplayName());
Assert.assertEquals("/ROOT/bar", cn18.getDisplayName());
Assert.assertEquals("/ROOT/bar##A", cn19.getDisplayName());
Assert.assertEquals("/##A", cn20.getDisplayName());
Assert.assertEquals("/foo.war", cn21.getDisplayName());
Assert.assertEquals("/foo", cn22.getDisplayName());
}
@Test
public void testConstructorString() {
doTestConstructorString(cn1);
doTestConstructorString(cn2);
doTestConstructorString(cn3);
doTestConstructorString(cn4);
doTestConstructorString(cn5);
doTestConstructorString(cn6);
doTestConstructorString(cn7);
doTestConstructorString(cn8);
doTestConstructorString(cn9);
doTestConstructorString(cn10);
doTestConstructorString(cn11);
doTestConstructorString(cn12);
doTestConstructorString(cn13);
doTestConstructorString(cn14);
doTestConstructorString(cn15);
doTestConstructorString(cn16);
doTestConstructorString(cn17);
doTestConstructorString(cn18);
doTestConstructorString(cn19);
doTestConstructorString(cn20);
doTestConstructorString(cn21);
doTestConstructorString(cn22);
}
private void doTestConstructorString(ContextName src) {
doCompare(src, new ContextName(src.getBaseName(), false));
doCompare(src, new ContextName(src.getDisplayName(), false));
doCompare(src, new ContextName(src.getName(), false));
}
private void doCompare(ContextName cn1, ContextName cn2) {
Assert.assertEquals(cn1.getBaseName(), cn2.getBaseName());
Assert.assertEquals(cn1.getDisplayName(), cn2.getDisplayName());
Assert.assertEquals(cn1.getName(), cn2.getName());
Assert.assertEquals(cn1.getPath(), cn2.getPath());
Assert.assertEquals(cn1.getVersion(), cn2.getVersion());
}
}

View File

@@ -0,0 +1,137 @@
/*
* 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.util;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public final class TestNetMask {
@Parameter(0)
public String mask;
@Parameter(1)
public String input;
@Parameter(2)
public Boolean valid;
@Parameter(3)
public Boolean matches;
@Parameters(name="{index}: mask [{0}], input [{1}]")
public static Collection<Object[]> inputs() {
List<Object[]> result = new ArrayList<>();
// Invalid IPv4 netmasks
result.add(new Object[] { "260.1.1.1", null, Boolean.FALSE, null });
result.add(new Object[] { "1.2.3.4/foo", null, Boolean.FALSE, null });
result.add(new Object[] { "1.2.3.4/-1", null, Boolean.FALSE, null });
result.add(new Object[] { "1.2.3.4/33", null, Boolean.FALSE, null });
// Invalid IPv6 netmasks
result.add(new Object[] { "fffff::/71", null, Boolean.FALSE, null });
result.add(new Object[] { "ae31::27:ef2:1/foo", null, Boolean.FALSE, null });
result.add(new Object[] { "ae31::27:ef2:1/-1", null, Boolean.FALSE, null });
result.add(new Object[] { "ae31::27:ef2:1/129", null, Boolean.FALSE, null });
// IPv4
result.add(new Object[] { "1.2.3.4", "1.2.3.4", Boolean.TRUE, Boolean.TRUE });
result.add(new Object[] { "1.2.3.4/32", "1.2.3.3", Boolean.TRUE, Boolean.FALSE });
result.add(new Object[] { "1.2.3.4/32", "1.2.3.4", Boolean.TRUE, Boolean.TRUE });
result.add(new Object[] { "1.2.3.4/32", "1.2.3.5", Boolean.TRUE, Boolean.FALSE });
result.add(new Object[] { "1.2.3.4/31", "1.2.3.3", Boolean.TRUE, Boolean.FALSE });
result.add(new Object[] { "1.2.3.4/31", "1.2.3.4", Boolean.TRUE, Boolean.TRUE });
result.add(new Object[] { "1.2.3.4/31", "1.2.3.5", Boolean.TRUE, Boolean.TRUE });
result.add(new Object[] { "1.2.3.4/31", "1.2.3.6", Boolean.TRUE, Boolean.FALSE });
result.add(new Object[] { "10.0.0.0/22", "9.255.255.255", Boolean.TRUE, Boolean.FALSE });
result.add(new Object[] { "10.0.0.0/22", "10.0.0.0", Boolean.TRUE, Boolean.TRUE });
result.add(new Object[] { "10.0.0.0/22", "10.0.3.255", Boolean.TRUE, Boolean.TRUE });
result.add(new Object[] { "10.0.0.0/22", "10.0.4.0", Boolean.TRUE, Boolean.FALSE });
// IPv6
result.add(new Object[] { "::5:1", "::5:1", Boolean.TRUE, Boolean.TRUE });
result.add(new Object[] { "::5:1/128", "::4:ffff", Boolean.TRUE, Boolean.FALSE });
result.add(new Object[] { "::5:1/128", "::5:1", Boolean.TRUE, Boolean.TRUE });
result.add(new Object[] { "::5:1/128", "::5:2", Boolean.TRUE, Boolean.FALSE });
result.add(new Object[] { "::5:1/127", "::4:ffff", Boolean.TRUE, Boolean.FALSE });
result.add(new Object[] { "::5:1/127", "::5:0", Boolean.TRUE, Boolean.TRUE });
result.add(new Object[] { "::5:1/127", "::5:1", Boolean.TRUE, Boolean.TRUE });
result.add(new Object[] { "::5:1/127", "::5:2", Boolean.TRUE, Boolean.FALSE });
result.add(new Object[] { "a::5:1/42", "9:ffff:ffff:ffff:ffff:ffff:ffff:ffff", Boolean.TRUE, Boolean.FALSE });
result.add(new Object[] { "a::5:1/42", "a::0", Boolean.TRUE, Boolean.TRUE });
result.add(new Object[] { "a::5:1/42", "a:0:3f:ffff:ffff:ffff:ffff:ffff", Boolean.TRUE, Boolean.TRUE });
result.add(new Object[] { "a::5:1/42", "a:0:40::", Boolean.TRUE, Boolean.FALSE });
// Mixed
result.add(new Object[] { "10.0.0.0/22", "::1", Boolean.TRUE, Boolean.FALSE });
return result;
}
@Test
public void testNetMask() {
Exception exception = null;
NetMask netMask = null;
try {
netMask = new NetMask(mask);
} catch (Exception e) {
exception =e;
}
if (valid.booleanValue()) {
Assert.assertNull(exception);
Assert.assertNotNull(netMask);
} else {
Assert.assertNotNull(exception);
Assert.assertEquals(IllegalArgumentException.class.getName(),
exception.getClass().getName());
return;
}
InetAddress inetAddress = null;
try {
inetAddress = InetAddress.getByName(input);
} catch (UnknownHostException e) {
e.printStackTrace();
Assert.fail();
}
Assert.assertEquals(matches, Boolean.valueOf(netMask.matches(inetAddress)));
Assert.assertEquals(mask, netMask.toString());
}
}

View File

@@ -0,0 +1,254 @@
/*
* 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.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class TestParameterMap {
private static final String[] TEST_PARAM_VALUES_1 = { "value1" };
private static final String[] TEST_PARAM_VALUES_2 = { "value2" };
private static final String[] TEST_PARAM_VALUES_2_UPDATED = { "value2-updated" };
private static final String[] TEST_PARAM_VALUES_3 = { "value3" };
private Map<String, String[]> paramMap;
@Before
public void setUp() {
paramMap = new ParameterMap<>();
paramMap.put("param1", TEST_PARAM_VALUES_1);
paramMap.put("param2", TEST_PARAM_VALUES_2);
paramMap.put("param3", TEST_PARAM_VALUES_3);
Assert.assertTrue(paramMap.containsKey("param1"));
Assert.assertArrayEquals(TEST_PARAM_VALUES_1, paramMap.get("param1"));
Assert.assertTrue(paramMap.containsKey("param2"));
Assert.assertArrayEquals(TEST_PARAM_VALUES_2, paramMap.get("param2"));
Assert.assertTrue(paramMap.containsKey("param3"));
Assert.assertArrayEquals(TEST_PARAM_VALUES_3, paramMap.get("param3"));
final Set<String> keySet = paramMap.keySet();
Assert.assertTrue(keySet.contains("param1"));
Assert.assertTrue(keySet.contains("param2"));
Assert.assertTrue(keySet.contains("param3"));
paramMap.put("param2", TEST_PARAM_VALUES_2_UPDATED);
paramMap.remove("param3");
Assert.assertTrue(paramMap.containsKey("param1"));
Assert.assertArrayEquals(TEST_PARAM_VALUES_1, paramMap.get("param1"));
Assert.assertTrue(paramMap.containsKey("param2"));
Assert.assertArrayEquals(TEST_PARAM_VALUES_2_UPDATED, paramMap.get("param2"));
Assert.assertFalse(paramMap.containsKey("param3"));
Assert.assertNull(paramMap.get("param3"));
Assert.assertTrue(keySet.contains("param1"));
Assert.assertTrue(keySet.contains("param2"));
Assert.assertFalse(keySet.contains("param3"));
}
@After
public void tearDown() {
Assert.assertTrue(paramMap.containsKey("param1"));
Assert.assertArrayEquals(TEST_PARAM_VALUES_1, paramMap.get("param1"));
Assert.assertTrue(paramMap.containsKey("param2"));
Assert.assertArrayEquals(TEST_PARAM_VALUES_2_UPDATED, paramMap.get("param2"));
Assert.assertFalse(paramMap.containsKey("param3"));
Assert.assertNull(paramMap.get("param3"));
}
@Test
public void testMapImmutabilityAfterLocked() {
((ParameterMap<String, String[]>) paramMap).setLocked(true);
try {
String[] updatedParamValues22 = new String[] { "value2-updated-2" };
paramMap.put("param2", updatedParamValues22);
Assert.fail("ParameterMap is not locked.");
} catch (IllegalStateException expectedException) {
}
try {
final Map<String, String[]> additionalParams = new HashMap<>();
additionalParams.put("param4", new String[] { "value4" });
paramMap.putAll(additionalParams);
Assert.fail("ParameterMap is not locked.");
} catch (IllegalStateException expectedException) {
}
try {
paramMap.remove("param2");
Assert.fail("ParameterMap is not locked.");
} catch (IllegalStateException expectedException) {
}
try {
paramMap.clear();
Assert.fail("ParameterMap is not locked.");
} catch (IllegalStateException expectedException) {
}
}
@Test
public void testKeySetImmutabilityAfterLocked() {
((ParameterMap<String, String[]>) paramMap).setLocked(true);
final Set<String> keySet = paramMap.keySet();
try {
keySet.add("param4");
Assert.fail("ParameterMap is not locked.");
} catch (UnsupportedOperationException expectedException) {
}
try {
keySet.remove("param2");
Assert.fail("ParameterMap is not locked.");
} catch (UnsupportedOperationException expectedException) {
}
try {
keySet.removeAll(Arrays.asList("param1", "param2"));
Assert.fail("ParameterMap is not locked.");
} catch (UnsupportedOperationException expectedException) {
}
try {
keySet.retainAll(Collections.emptyList());
Assert.fail("ParameterMap is not locked.");
} catch (UnsupportedOperationException expectedException) {
}
try {
keySet.clear();
Assert.fail("ParameterMap is not locked.");
} catch (UnsupportedOperationException expectedException) {
}
}
@Test
public void testValuesImmutabilityAfterLocked() {
((ParameterMap<String, String[]>) paramMap).setLocked(true);
final Collection<String[]> valuesCol = paramMap.values();
try {
valuesCol.add(new String[] { "value4" });
Assert.fail("ParameterMap is not locked.");
} catch (UnsupportedOperationException expectedException) {
}
try {
List<String[]> list = new ArrayList<>();
list.add(new String[] { "value4" });
valuesCol.addAll(list);
Assert.fail("ParameterMap is not locked.");
} catch (UnsupportedOperationException expectedException) {
}
try {
valuesCol.remove(TEST_PARAM_VALUES_1);
Assert.fail("ParameterMap is not locked.");
} catch (UnsupportedOperationException expectedException) {
}
try {
List<String[]> list = new ArrayList<>();
list.add(TEST_PARAM_VALUES_1);
valuesCol.removeAll(list);
Assert.fail("ParameterMap is not locked.");
} catch (UnsupportedOperationException expectedException) {
}
try {
valuesCol.retainAll(Collections.emptyList());
Assert.fail("ParameterMap is not locked.");
} catch (UnsupportedOperationException expectedException) {
}
try {
valuesCol.clear();
Assert.fail("ParameterMap is not locked.");
} catch (UnsupportedOperationException expectedException) {
}
}
@Test
public void testEntrySetImmutabilityAfterLocked() {
((ParameterMap<String, String[]>) paramMap).setLocked(true);
final Set<Map.Entry<String, String[]>> entrySet = paramMap.entrySet();
try {
final Map<String, String[]> anotherParamsMap = new HashMap<>();
anotherParamsMap.put("param4", new String[] { "value4" });
Map.Entry<String, String[]> anotherEntry = anotherParamsMap.entrySet().iterator().next();
entrySet.add(anotherEntry);
Assert.fail("ParameterMap is not locked.");
} catch (UnsupportedOperationException expectedException) {
}
try {
final Map<String, String[]> anotherParamsMap = new HashMap<>();
anotherParamsMap.put("param4", new String[] { "value4" });
anotherParamsMap.put("param5", new String[] { "value5" });
entrySet.addAll(anotherParamsMap.entrySet());
Assert.fail("ParameterMap is not locked.");
} catch (UnsupportedOperationException expectedException) {
}
try {
final Map.Entry<String, String[]> entry = entrySet.iterator().next();
entrySet.remove(entry);
Assert.fail("ParameterMap is not locked.");
} catch (UnsupportedOperationException expectedException) {
}
try {
Set<Map.Entry<String, String[]>> anotherEntrySet = new HashSet<>(entrySet);
entrySet.removeAll(anotherEntrySet);
Assert.fail("ParameterMap is not locked.");
} catch (UnsupportedOperationException expectedException) {
}
try {
entrySet.retainAll(Collections.emptySet());
Assert.fail("ParameterMap is not locked.");
} catch (UnsupportedOperationException expectedException) {
}
try {
entrySet.clear();
Assert.fail("ParameterMap is not locked.");
} catch (UnsupportedOperationException expectedException) {
}
}
}

View File

@@ -0,0 +1,31 @@
/*
* 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.util;
import org.junit.Test;
public class TestServerInfo {
/**
* Test that prints the server version info.
*/
@Test
public void testServerInfo() {
ServerInfo.main(new String[0]);
}
}

View File

@@ -0,0 +1,56 @@
/*
* 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.util;
import java.nio.charset.StandardCharsets;
import org.junit.Assert;
import org.junit.Test;
public class TestURLEncoder {
private static final String SPACE = " ";
private static final String DOLLAR = "$";
private static final String AMPERSAND = "&";
private static final String AMPERSAND_ENCODED = "%26";
@Test
public void testClone() {
URLEncoder original = new URLEncoder();
URLEncoder clone = (URLEncoder) original.clone();
// Ensure encode as space is not shared
original.setEncodeSpaceAsPlus(true);
Assert.assertNotEquals(original.encode(SPACE, StandardCharsets.UTF_8),
clone.encode(SPACE, StandardCharsets.UTF_8));
// Ensure safe characters is not shared
original.addSafeCharacter('$');
Assert.assertNotEquals(original.encode(DOLLAR, StandardCharsets.UTF_8),
clone.encode(DOLLAR, StandardCharsets.UTF_8));
}
@Test
public void testRemoveSafeCharacter() {
URLEncoder xml = (URLEncoder) URLEncoder.DEFAULT.clone();
// This should not encode '&'
Assert.assertEquals(AMPERSAND, xml.encode(AMPERSAND, StandardCharsets.UTF_8));
xml.removeSafeCharacter('&');
Assert.assertEquals(AMPERSAND_ENCODED, xml.encode(AMPERSAND, StandardCharsets.UTF_8));
}
}