View Javadoc

1   /*
2    * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
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 de.smartics.properties.spi.config.support;
17  
18  import static org.hamcrest.MatcherAssert.assertThat;
19  import static org.hamcrest.Matchers.is;
20  
21  import java.net.MalformedURLException;
22  import java.net.URL;
23  
24  import org.junit.Test;
25  
26  import de.smartics.testdoc.annotations.Uut;
27  
28  @Uut(type = UrlUtil.class)
29  public class UrlUtilTest
30  {
31    // ********************************* Fields *********************************
32  
33    // --- constants ------------------------------------------------------------
34  
35    // --- members --------------------------------------------------------------
36  
37    // ****************************** Inner Classes *****************************
38  
39    // ********************************* Methods ********************************
40  
41    // --- prepare --------------------------------------------------------------
42  
43    // --- helper ---------------------------------------------------------------
44  
45    // --- tests ----------------------------------------------------------------
46  
47    @Test
48    public void testShortenJarURLContainingMetaInf() throws MalformedURLException
49    {
50      final URL url =
51          new URL(
52              "jar:file:/D:/jboss/jboss-as-7.1.1.Final/modules/javax/servlet/api/main/jboss-servlet-api_3.0_spec-1.0.0.Final.jar!/META-INF");
53      final URL shortenedUrl = UrlUtil.shortenUrl(url, "/META-INF");
54      assertThat(shortenedUrl + "META-INF", is(url.toString()));
55    }
56  
57    @Test
58    public void testShortenFileURLContainingMetaInf()
59      throws MalformedURLException
60    {
61      final URL url =
62          new URL(
63              "file:/D:/jboss/jboss-as-7.1.1.Final/modules/sun/jdk/main/service-loader-resources/META-INF");
64      final URL shortenedUrl = UrlUtil.shortenUrl(url, "/META-INF");
65      assertThat(shortenedUrl + "META-INF", is(url.toString()));
66    }
67  
68    @Test
69    public void testShortenJarURLContainingNothing() throws MalformedURLException
70    {
71      final URL url =
72          new URL(
73              "jar:file:/D:/jboss/jboss-as-7.1.1.Final/modules/javax/servlet/api/main/jboss-servlet-api_3.0_spec-1.0.0.Final.jar!/");
74      final URL shortenedUrl = UrlUtil.shortenUrl(url, "");
75      assertThat(shortenedUrl.toString(), is(url.toString()));
76    }
77  
78    @Test
79    public void testShortenFileURLContainingNothingEndingWithSlash()
80      throws MalformedURLException
81    {
82      final URL url =
83          new URL(
84              "file:/D:/jboss/jboss-as-7.1.1.Final/modules/sun/jdk/main/service-loader-resources/");
85      final URL shortenedUrl = UrlUtil.shortenUrl(url, "");
86      assertThat(shortenedUrl.toString(), is(url.toString()));
87    }
88  
89    @Test
90    public void testShortenFileURLContainingNothingNotEndingWithSlash()
91      throws MalformedURLException
92    {
93      final URL url =
94          new URL(
95              "file:/D:/jboss/jboss-as-7.1.1.Final/modules/sun/jdk/main/service-loader-resources");
96      final URL shortenedUrl = UrlUtil.shortenUrl(url, "");
97      assertThat(shortenedUrl.toString(), is(url.toString() + "/"));
98    }
99  
100 }