View Javadoc

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.dom4j.io.SAXReader;
25  import org.dom4j.Document;
26  import org.dom4j.Element;
27  
28  import java.io.File;
29  
30  /**
31   * @author Edwin Punzalan
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  }