1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugin.eclipse;
20  
21  import java.io.File;
22  import java.io.FileInputStream;
23  import java.util.Properties;
24  
25  import org.apache.maven.plugin.eclipse.writers.workspace.EclipseWorkspaceWriter;
26  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
27  import org.codehaus.plexus.PlexusTestCase;
28  
29  /**
30   * @author Edwin Punzalan
31   */
32  public class AddMavenRepoMojoTest
33      extends AbstractMojoTestCase
34  {
35      public void testMinConfiguration()
36          throws Exception
37      {
38      }
39  
40      private AddMavenRepoMojo executeMojo( String pomXml )
41          throws Exception
42      {
43          AddMavenRepoMojo mojo = getConfiguredMojo( pomXml );
44  
45          mojo.execute();
46  
47          File workDir = new File( mojo.getWorkspace(), EclipseWorkspaceWriter.ECLIPSE_CORE_RUNTIME_SETTINGS_DIR );
48  
49          File eclipseJDTCorePrefsFile = new File( workDir, EclipseWorkspaceWriter.ECLIPSE_JDT_CORE_PREFS_FILE );
50  
51          assertTrue( "Test if workspace properties exists", eclipseJDTCorePrefsFile.exists() );
52  
53          Properties props = new Properties();
54          props.load( new FileInputStream( eclipseJDTCorePrefsFile ) );
55  
56          String M2_REPO = props.getProperty( EclipseWorkspaceWriter.CLASSPATH_VARIABLE_M2_REPO );
57  
58          assertNotNull( "Test M2_REPO has a value", M2_REPO );
59  
60          String localRepo = PlexusTestCase.getBasedir() + "/target/local-repo";
61  
62          assertEquals( "Test M2_REPO value", localRepo.replace( '\\', '/' ), M2_REPO.replace( '\\', '/' ) );
63  
64          return mojo;
65      }
66  
67      private AddMavenRepoMojo getConfiguredMojo( String pomXml )
68          throws Exception
69      {
70          File pomXmlFile =
71              new File( PlexusTestCase.getBasedir(), "target/test-classes/test-harness/add-maven-repo/" + pomXml );
72  
73          AddMavenRepoMojo mojo = (AddMavenRepoMojo) lookupMojo( "add-maven-repo", pomXmlFile );
74  
75          return mojo;
76      }
77  }