1 package org.apache.maven.doxia.site.decoration;
2
3 import org.codehaus.plexus.util.xml.Xpp3Dom;
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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 }