1 package org.apache.maven.plugin.doap;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.StringWriter;
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import org.apache.maven.model.Developer;
27 import org.codehaus.plexus.PlexusTestCase;
28 import org.codehaus.plexus.i18n.I18N;
29 import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
30 import org.codehaus.plexus.util.xml.XMLWriter;
31
32
33
34
35
36
37
38 public class DoapUtilTest
39 extends PlexusTestCase
40 {
41
42 protected void setUp()
43 throws Exception
44 {
45 super.setUp();
46 }
47
48
49 protected void tearDown()
50 throws Exception
51 {
52 super.tearDown();
53 }
54
55
56
57
58
59
60 public void testWriteElementXMLWriterStringStringString()
61 throws Exception
62 {
63 StringWriter w = new StringWriter();
64 XMLWriter writer = new PrettyPrintXMLWriter( w );
65 DoapUtil.writeElement( writer, "name", "value" );
66 w.close();
67 assertEquals( w.toString(), "<name>value</name>" );
68
69 w = new StringWriter();
70 writer = new PrettyPrintXMLWriter( w );
71 try
72 {
73 DoapUtil.writeElement( writer, null, null );
74 assertTrue( "Null not catched", false );
75 }
76 catch ( IllegalArgumentException e )
77 {
78 assertTrue( "IllegalArgumentException catched", true );
79 }
80 finally
81 {
82 w.close();
83 }
84 }
85
86
87
88
89
90
91 public void testWriteRdfResourceElement()
92 throws Exception
93 {
94 StringWriter w = new StringWriter();
95 XMLWriter writer = new PrettyPrintXMLWriter( w );
96 DoapUtil.writeRdfResourceElement( writer, "name", "value" );
97 w.close();
98 assertEquals( w.toString(), "<name " + DoapUtil.RDF_RESOURCE + "=\"value\"/>" );
99
100 w = new StringWriter();
101 writer = new PrettyPrintXMLWriter( w );
102 try
103 {
104 DoapUtil.writeRdfResourceElement( writer, null, null );
105 assertTrue( "Null not catched", false );
106 }
107 catch ( IllegalArgumentException e )
108 {
109 assertTrue( "IllegalArgumentException catched", true );
110 }
111 finally
112 {
113 w.close();
114 }
115 }
116
117
118
119
120
121
122
123
124
125
126
127
128
129 public void testDevelopersOrContributorsByDoapRoles()
130 throws Exception
131 {
132 I18N i18n = (I18N) getContainer().lookup( I18N.ROLE );
133 assertNotNull( i18n );
134 assertNotNull( i18n.getBundle() );
135
136 List developersOrContributors = new ArrayList();
137
138
139 Developer dev = new Developer();
140 dev.setId( "dev1" );
141 dev.addRole( "maintainer" );
142
143 developersOrContributors.add( dev );
144
145 assertTrue( DoapUtil.getDevelopersOrContributorsWithDeveloperRole( i18n, developersOrContributors ).isEmpty() );
146 assertTrue( DoapUtil.getDevelopersOrContributorsWithDocumenterRole( i18n, developersOrContributors ).isEmpty() );
147 assertTrue( DoapUtil.getDevelopersOrContributorsWithHelperRole( i18n, developersOrContributors ).isEmpty() );
148 assertFalse( DoapUtil.getDevelopersOrContributorsWithMaintainerRole( i18n, developersOrContributors ).isEmpty() );
149 assertTrue( DoapUtil.getDevelopersOrContributorsWithTesterRole( i18n, developersOrContributors ).isEmpty() );
150 assertTrue( DoapUtil.getDevelopersOrContributorsWithTranslatorRole( i18n, developersOrContributors ).isEmpty() );
151 assertTrue( DoapUtil.getDevelopersOrContributorsWithUnknownRole( i18n, developersOrContributors ).isEmpty() );
152
153
154 developersOrContributors.clear();
155
156 dev = new Developer();
157 dev.setId( "dev1" );
158 dev.addRole( " MAINTAINER" );
159 dev.addRole( "tesTER " );
160 dev.addRole( "blabla" );
161 dev.addRole( "translato r" );
162
163 developersOrContributors.add( dev );
164
165 assertTrue( DoapUtil.getDevelopersOrContributorsWithDeveloperRole( i18n, developersOrContributors ).isEmpty() );
166 assertTrue( DoapUtil.getDevelopersOrContributorsWithDocumenterRole( i18n, developersOrContributors ).isEmpty() );
167 assertTrue( DoapUtil.getDevelopersOrContributorsWithHelperRole( i18n, developersOrContributors ).isEmpty() );
168 assertFalse( DoapUtil.getDevelopersOrContributorsWithMaintainerRole( i18n, developersOrContributors ).isEmpty() );
169 assertFalse( DoapUtil.getDevelopersOrContributorsWithTesterRole( i18n, developersOrContributors ).isEmpty() );
170 assertTrue( DoapUtil.getDevelopersOrContributorsWithTranslatorRole( i18n, developersOrContributors ).isEmpty() );
171 assertFalse( DoapUtil.getDevelopersOrContributorsWithUnknownRole( i18n, developersOrContributors ).isEmpty() );
172 }
173 }