|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package org.apache.catalina.ant; |
| 18 | + |
| 19 | +import java.io.File; |
| 20 | +import java.io.IOException; |
| 21 | +import java.io.InputStream; |
| 22 | + |
| 23 | +import static org.junit.Assert.assertEquals; |
| 24 | + |
| 25 | +import org.junit.Test; |
| 26 | + |
| 27 | +import org.apache.catalina.startup.Tomcat; |
| 28 | +import org.apache.catalina.startup.TomcatBaseTest; |
| 29 | +import org.apache.tools.ant.BuildException; |
| 30 | + |
| 31 | +public class TestDeployTask extends TomcatBaseTest { |
| 32 | + |
| 33 | + @Test |
| 34 | + public void bug58086a() { |
| 35 | + DeployTask deployTask = new DeployTask() { |
| 36 | + |
| 37 | + @Override |
| 38 | + public void execute(String command, InputStream istream, String contentType, int contentLength) |
| 39 | + throws BuildException { |
| 40 | + assertEquals("/deploy?path=somepath", command); |
| 41 | + assertEquals("application/octet-stream", contentType); |
| 42 | + try { |
| 43 | + istream.close(); |
| 44 | + } catch (IOException e) { |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + }; |
| 49 | + |
| 50 | + setDefaults(deployTask); |
| 51 | + |
| 52 | + testExecute(deployTask, "file:./test/deployment/context.war"); |
| 53 | + testExecute(deployTask, "file:.\\test\\deployment\\context.war"); |
| 54 | + testExecute(deployTask, new File("test/deployment/context.war").toURI().toString()); |
| 55 | + testExecute(deployTask, new File("test/deployment/context.war").getAbsolutePath()); |
| 56 | + testExecute(deployTask, "jar:" + new File("test/deployment/context.jar").toURI().toString() + "!/context.war"); |
| 57 | + testExecute(deployTask, "file:./test/deployment/dir with spaces/context.war"); |
| 58 | + testExecute(deployTask, "file:.\\test\\deployment\\dir with spaces\\context.war"); |
| 59 | + testExecute(deployTask, new File("test/deployment/dir with spaces/context.war").toURI().toString()); |
| 60 | + testExecute(deployTask, new File("test/deployment/dir with spaces/context.war").getAbsolutePath()); |
| 61 | + testExecute(deployTask, "jar:" + new File("test/deployment/dir with spaces/context.jar").toURI().toString() |
| 62 | + + "!/context.war"); |
| 63 | + testExecute(deployTask, "file:./test/deployment/dir%20with%20spaces/context.war"); |
| 64 | + testExecute(deployTask, "file:.\\test\\deployment\\dir%20with%20spaces\\context.war"); |
| 65 | + } |
| 66 | + |
| 67 | + @Test(expected = BuildException.class) |
| 68 | + public void bug58086b() { |
| 69 | + DeployTask deployTask = new DeployTask(); |
| 70 | + setDefaults(deployTask); |
| 71 | + testExecute(deployTask, "scheme:./test/deployment/context.war"); |
| 72 | + } |
| 73 | + |
| 74 | + @Test(expected = BuildException.class) |
| 75 | + public void bug58086c() { |
| 76 | + DeployTask deployTask = new DeployTask(); |
| 77 | + setDefaults(deployTask); |
| 78 | + testExecute(deployTask, "sc:./test/deployment/context.war"); |
| 79 | + } |
| 80 | + |
| 81 | + @Test |
| 82 | + public void bug58086d() throws Exception { |
| 83 | + Tomcat tomcat = getTomcatInstance(); |
| 84 | + |
| 85 | + File root = new File("test/deployment"); |
| 86 | + tomcat.addWebapp("", root.getAbsolutePath()); |
| 87 | + |
| 88 | + tomcat.start(); |
| 89 | + |
| 90 | + DeployTask deployTask = new DeployTask() { |
| 91 | + |
| 92 | + @Override |
| 93 | + public void execute(String command, InputStream istream, String contentType, int contentLength) |
| 94 | + throws BuildException { |
| 95 | + assertEquals("/deploy?path=somepath", command); |
| 96 | + assertEquals("application/octet-stream", contentType); |
| 97 | + try { |
| 98 | + istream.close(); |
| 99 | + } catch (IOException e) { |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + }; |
| 104 | + |
| 105 | + setDefaults(deployTask); |
| 106 | + |
| 107 | + testExecute(deployTask, "http://localhost:" + getPort() + "/context.war"); |
| 108 | + } |
| 109 | + |
| 110 | + private void setDefaults(DeployTask deployTask) { |
| 111 | + deployTask.setUrl("someurl"); |
| 112 | + deployTask.setUsername("someuser"); |
| 113 | + deployTask.setPassword("somepassword"); |
| 114 | + deployTask.setPath("somepath"); |
| 115 | + } |
| 116 | + |
| 117 | + private void testExecute(DeployTask deployTask, String war) { |
| 118 | + deployTask.setWar(war); |
| 119 | + deployTask.execute(); |
| 120 | + } |
| 121 | +} |
0 commit comments