View Javadoc
1   package org.apache.maven.doxia.site.decoration;
2   
3   import org.codehaus.plexus.util.xml.Xpp3Dom;
4   
5   /*
6    * Licensed to the Apache Software Foundation (ASF) under one
7    * or more contributor license agreements.  See the NOTICE file
8    * distributed with this work for additional information
9    * regarding copyright ownership.  The ASF licenses this file
10   * to you under the Apache License, Version 2.0 (the
11   * "License"); you may not use this file except in compliance
12   * with the License.  You may obtain a copy of the License at
13   *
14   *   http://www.apache.org/licenses/LICENSE-2.0
15   *
16   * Unless required by applicable law or agreed to in writing,
17   * software distributed under the License is distributed on an
18   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19   * KIND, either express or implied.  See the License for the
20   * specific language governing permissions and limitations
21   * under the License.
22   */
23  
24  import org.junit.Test;
25  
26  import static org.junit.Assert.*;
27  
28  public class DecorationUtilsTest
29  {
30      @Test
31      public void testIsLink()
32      {
33          assertFalse( DecorationUtils.isLink( null ) );
34          assertFalse( DecorationUtils.isLink( "" ) );
35          assertFalse( DecorationUtils.isLink( " " ) );
36          assertTrue( DecorationUtils.isLink( "http://maven.apache.org/" ) );
37          assertTrue( DecorationUtils.isLink( "https://maven.apache.org/" ) );
38          assertTrue( DecorationUtils.isLink( "ftp://maven.apache.org/pub/" ) );
39          assertTrue( DecorationUtils.isLink( "file:///home" ) );
40          assertTrue( DecorationUtils.isLink( "mailto:toto@maven.org" ) );
41          assertTrue( DecorationUtils.isLink( "any-protocol://" ) );
42      }
43  
44      @Test
45      public void testGetCustomChild()
46      {
47          Xpp3Dom dom = new Xpp3Dom( "root" );
48          Xpp3Dom level1 = new Xpp3Dom( "level1" );
49          dom.addChild( level1 );
50          Xpp3Dom level2 = new Xpp3Dom( "level2" );
51          level2.setValue( "value" );
52          level1.addChild( level2 );
53  
54          assertEquals( level1, DecorationUtils.getCustomChild( dom, "level1" ) );
55          assertEquals( level2, DecorationUtils.getCustomChild( dom, "level1.level2" ) );
56          assertNull( DecorationUtils.getCustomChild( dom, "no.level2" ) );
57          assertNull( DecorationUtils.getCustomChild( dom, "level1.no" ) );
58  
59          assertEquals( "value", DecorationUtils.getCustomValue( dom, "level1.level2" ) );
60          assertNull( DecorationUtils.getCustomValue( dom, "no.level2" ) );
61          assertNull( DecorationUtils.getCustomValue( dom, "level1.no" ) );
62  
63          assertEquals( "value", DecorationUtils.getCustomValue( dom, "level1.level2", "default" ) );
64          assertEquals( "default", DecorationUtils.getCustomValue( dom, "no.level2", "default" ) );
65          assertEquals( "default", DecorationUtils.getCustomValue( dom, "level1.no", "default" ) );
66      }
67  }