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 junit.framework.TestCase;
25  
26  public class DecorationUtilsTest
27      extends TestCase
28  {
29      public void testIsLink()
30      {
31          assertFalse( DecorationUtils.isLink( null ) );
32          assertFalse( DecorationUtils.isLink( "" ) );
33          assertFalse( DecorationUtils.isLink( " " ) );
34          assertTrue( DecorationUtils.isLink( "http://maven.apache.org/" ) );
35          assertTrue( DecorationUtils.isLink( "https://maven.apache.org/" ) );
36          assertTrue( DecorationUtils.isLink( "ftp://maven.apache.org/pub/" ) );
37          assertTrue( DecorationUtils.isLink( "file:///home" ) );
38          assertTrue( DecorationUtils.isLink( "mailto:toto@maven.org" ) );
39          assertTrue( DecorationUtils.isLink( "any-protocol://" ) );
40      }
41  
42      public void testGetCustomChild()
43      {
44          Xpp3Dom dom = new Xpp3Dom( "root" );
45          Xpp3Dom level1 = new Xpp3Dom( "level1" );
46          dom.addChild( level1 );
47          Xpp3Dom level2 = new Xpp3Dom( "level2" );
48          level2.setValue( "value" );
49          level1.addChild( level2 );
50  
51          assertEquals( level1, DecorationUtils.getCustomChild( dom, "level1" ) );
52          assertEquals( level2, DecorationUtils.getCustomChild( dom, "level1.level2" ) );
53          assertNull( DecorationUtils.getCustomChild( dom, "no.level2" ) );
54          assertNull( DecorationUtils.getCustomChild( dom, "level1.no" ) );
55  
56          assertEquals( "value", DecorationUtils.getCustomValue( dom, "level1.level2" ) );
57          assertNull( DecorationUtils.getCustomValue( dom, "no.level2" ) );
58          assertNull( DecorationUtils.getCustomValue( dom, "level1.no" ) );
59  
60          assertEquals( "value", DecorationUtils.getCustomValue( dom, "level1.level2", "default" ) );
61          assertEquals( "default", DecorationUtils.getCustomValue( dom, "no.level2", "default" ) );
62          assertEquals( "default", DecorationUtils.getCustomValue( dom, "level1.no", "default" ) );
63      }
64  }