1 package org.apache.maven.plugin.idea;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
23 import org.apache.maven.plugin.Mojo;
24 import org.dom4j.io.SAXReader;
25 import org.dom4j.Document;
26 import org.dom4j.Element;
27
28 import java.io.File;
29
30
31
32
33 public class IdeaTest
34 extends AbstractMojoTestCase
35 {
36 public void testIdea()
37 throws Exception
38 {
39 File pluginXmlFile = new File( getBasedir(), "src/test/idea-plugin-configs/min-plugin-config.xml" );
40
41 Mojo mojo = lookupMojo( "idea", pluginXmlFile );
42
43 mojo.execute();
44
45 File basedir = new File( getBasedir(), "target/test-harness/i-min" );
46
47 String artifactId = "plugin-test-i-min";
48
49 File iprFile = new File( basedir, artifactId + ".ipr" );
50 assertTrue( "Test creation of project files", iprFile.exists() );
51
52 File imlFile = new File( basedir, artifactId + ".iml" );
53 assertTrue( "Test creation of project files", imlFile.exists() );
54
55 File iwsFile = new File( basedir, artifactId + ".iws" );
56 assertTrue( "Test creation of project files", iwsFile.exists() );
57 }
58
59 public void testIdeaWithMacro()
60 throws Exception
61 {
62 File pluginXmlFile = new File( getBasedir(), "src/test/idea-plugin-configs/macro-plugin-config.xml" );
63
64 Mojo mojo = lookupMojo( "idea", pluginXmlFile );
65
66 mojo.execute();
67
68 File basedir = new File( getBasedir(), "target/test-harness/i-macro" );
69
70 String artifactId = "plugin-test-i-macro";
71
72 File iprFile = new File( basedir, artifactId + ".ipr" );
73 assertTrue( "Test creation of project files", iprFile.exists() );
74
75 File imlFile = new File( basedir, artifactId + ".iml" );
76 assertTrue( "Test creation of project files", imlFile.exists() );
77
78 File iwsFile = new File( basedir, artifactId + ".iws" );
79 assertTrue( "Test creation of project files", iwsFile.exists() );
80
81 File outputFile = new File( getBasedir(), "target/test-harness/i-macro/plugin-test-i-macro.ipr" );
82
83 SAXReader reader = new SAXReader();
84
85 Document iprDocument = reader.read( outputFile );
86
87 Element macros = iprDocument.getRootElement().element( "UsedPathMacros" );
88
89 assertEquals( "Test creation of macros", 1, macros.elements( "macro" ).size() );
90
91 Element macro = macros.element( "macro" );
92
93 assertEquals( "Test macro name", "USER_HOME", macro.attributeValue( "name" ) );
94 }
95 }