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.apache.maven.plugin.idea.stubs.TestCounter;
25 import org.dom4j.io.SAXReader;
26 import org.dom4j.Document;
27 import org.dom4j.Element;
28
29 import java.io.File;
30
31
32
33
34 public class IdeaTest
35 extends AbstractMojoTestCase
36 {
37 public void testIdea()
38 throws Exception
39 {
40 File pluginXmlFile = new File( getBasedir(), "src/test/idea-plugin-configs/min-plugin-config.xml" );
41
42 Mojo mojo = lookupMojo( "idea", pluginXmlFile );
43
44 mojo.execute();
45
46 File basedir = new File( getBasedir(), "target/test-harness/" + TestCounter.currentCount() );
47
48 String artifactId = "plugin-test-" + TestCounter.currentCount();
49
50 File iprFile = new File( basedir, artifactId + ".ipr" );
51 assertTrue( "Test creation of project files", iprFile.exists() );
52
53 File imlFile = new File( basedir, artifactId + ".iml" );
54 assertTrue( "Test creation of project files", imlFile.exists() );
55
56 File iwsFile = new File( basedir, artifactId + ".iws" );
57 assertTrue( "Test creation of project files", iwsFile.exists() );
58 }
59
60 public void testIdeaWithMacro()
61 throws Exception
62 {
63 File pluginXmlFile = new File( getBasedir(), "src/test/idea-plugin-configs/macro-plugin-config.xml" );
64
65 Mojo mojo = lookupMojo( "idea", pluginXmlFile );
66
67 mojo.execute();
68
69 int testCounter = TestCounter.currentCount();
70
71 File basedir = new File( getBasedir(), "target/test-harness/" + TestCounter.currentCount() );
72
73 String artifactId = "plugin-test-" + testCounter;
74
75 File iprFile = new File( basedir, artifactId + ".ipr" );
76 assertTrue( "Test creation of project files", iprFile.exists() );
77
78 File imlFile = new File( basedir, artifactId + ".iml" );
79 assertTrue( "Test creation of project files", imlFile.exists() );
80
81 File iwsFile = new File( basedir, artifactId + ".iws" );
82 assertTrue( "Test creation of project files", iwsFile.exists() );
83
84 File outputFile = new File( getBasedir(), "target/test-harness/" + testCounter + "/plugin-test-" + testCounter + ".ipr" );
85
86 SAXReader reader = new SAXReader();
87
88 Document iprDocument = reader.read( outputFile );
89
90 Element macros = iprDocument.getRootElement().element( "UsedPathMacros" );
91
92 assertEquals( "Test creation of macros", 1, macros.elements( "macro" ).size() );
93
94 Element macro = macros.element( "macro" );
95
96 assertEquals( "Test macro name", "USER_HOME", macro.attributeValue( "name" ) );
97 }
98 }