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 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 }