1   package org.apache.maven.plugin.idea;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * @author Edwin Punzalan
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  }