|
| 1 | +/* |
| 2 | + * Copyright 2016 ThoughtWorks, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.thoughtworks.go.agent.common.util; |
| 17 | + |
| 18 | +import com.thoughtworks.go.agent.common.util.JarUtil; |
| 19 | + |
| 20 | +import org.junit.Test; |
| 21 | +import org.junit.Before; |
| 22 | +import org.junit.After; |
| 23 | +import static org.junit.Assert.*; |
| 24 | + |
| 25 | +import java.io.File; |
| 26 | +import java.io.IOException; |
| 27 | + |
| 28 | +import org.apache.commons.io.FileUtils; |
| 29 | + |
| 30 | +public class JarUtilTest { |
| 31 | + |
| 32 | + private static final String PATH_WITH_HASHES = "#hashes#in#path/"; |
| 33 | + |
| 34 | + @Before |
| 35 | + public void setUp() throws IOException { |
| 36 | + FileUtils.copyFile(new File("testdata/test-agent.jar"), new File(PATH_WITH_HASHES + "test-agent.jar")); |
| 37 | + } |
| 38 | + |
| 39 | + @After |
| 40 | + public void tearDown() throws IOException { |
| 41 | + FileUtils.deleteQuietly(new File(PATH_WITH_HASHES + "test-agent.jar")); |
| 42 | + FileUtils.deleteDirectory(new File(PATH_WITH_HASHES)); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void shouldNotThrowMalformedUrlException() throws Exception { |
| 47 | + String absolutePath = new File(PATH_WITH_HASHES + "test-agent.jar").getAbsolutePath(); |
| 48 | + |
| 49 | + try { |
| 50 | + Object agent_launcher = JarUtil.objectFromJar(absolutePath, "Go-Agent-Bootstrap-Class"); |
| 51 | + } catch (Exception e) { |
| 52 | + fail(); |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments