1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.eclipse.writers;
20
21 import java.io.File;
22 import java.io.IOException;
23
24 import junit.framework.TestCase;
25
26 import org.apache.maven.plugin.MojoExecutionException;
27 import org.apache.maven.plugin.eclipse.writers.testutils.TestEclipseWriterConfig;
28 import org.apache.maven.plugin.eclipse.writers.wtp.EclipseWtpComponent15Writer;
29 import org.apache.maven.plugin.eclipse.writers.wtp.EclipseWtpComponentWriter;
30 import org.apache.maven.plugin.ide.IdeDependency;
31 import org.apache.maven.plugin.logging.Log;
32 import org.apache.maven.plugin.logging.SystemStreamLog;
33 import org.apache.maven.project.MavenProject;
34 import org.apache.maven.shared.tools.easymock.TestFileManager;
35 import org.jdom.Attribute;
36 import org.jdom.Document;
37 import org.jdom.JDOMException;
38 import org.jdom.input.SAXBuilder;
39 import org.jdom.xpath.XPath;
40
41
42
43
44
45
46 public class EclipseWtpComponent15WriterTest
47 extends TestCase
48 {
49
50 private TestFileManager fileManager = new TestFileManager( "EclipseWtpComponent15Writer.unitTest.", "" );
51
52 protected void tearDown()
53 throws IOException
54 {
55 fileManager.cleanUp();
56 }
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 public void testWriteEjbComponentMECLIPSE455()
72 throws MojoExecutionException, IOException, JDOMException
73 {
74
75 TestEclipseWriterConfig config = new TestEclipseWriterConfig();
76
77 config.setWtpVersion( 1.5f );
78 config.setEclipseProjectName( "test-project" );
79
80 File basedir = fileManager.createTempDir();
81 File pom = new File( basedir, "pom.xml" );
82 pom.createNewFile();
83
84 MavenProject project = new MavenProject();
85 project.setFile( pom );
86
87 config.setProject( project );
88 config.setProjectBaseDir( basedir );
89
90 config.setEclipseProjectDirectory( basedir );
91 config.setPackaging( "ear" );
92
93
94 config.setDeps( new IdeDependency[] { createDep( "ejb" ), createDep( "jar" ) } );
95
96 EclipseWtpComponentWriter lWriter = new EclipseWtpComponent15Writer();
97
98 Log log = new TestLog();
99
100 lWriter.init( log, config );
101
102 lWriter.write();
103
104
105 SAXBuilder builder = new SAXBuilder( false );
106
107 Document doc = builder.build( new File( basedir, ".settings/org.eclipse.wst.common.component" ) );
108
109 XPath archiveNames = XPath.newInstance( "//dependent-module/@archiveName" );
110
111 assertEquals( "Must be 2 modules", 2, archiveNames.selectNodes( doc ).size() );
112 for (Object o : archiveNames.selectNodes(doc)) {
113 Attribute attribute = (Attribute) o;
114
115 String archiveName = attribute.getValue();
116 String extension = archiveName.substring(archiveName.lastIndexOf(".") + 1).toLowerCase();
117
118 assertEquals("Must be of type jar", "jar", extension);
119 }
120
121 }
122
123 private IdeDependency createDep( String packagingType )
124 {
125 IdeDependency dependency = new IdeDependency();
126 dependency.setGroupId( "g" );
127 dependency.setArtifactId( packagingType + "Artifact" );
128 dependency.setVersion( "v" );
129 dependency.setReferencedProject( true );
130 dependency.setAddedToClasspath( true );
131 dependency.setEclipseProjectName( packagingType + "Project" );
132 dependency.setType( packagingType );
133 return dependency;
134 }
135
136 private static final class TestLog
137 extends SystemStreamLog
138 {
139 public boolean isDebugEnabled()
140 {
141 return true;
142 }
143 }
144
145 }