View Javadoc

1   package org.codehaus.mojo.javascript;
2   
3   /*
4    * Copyright 2001-2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * 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, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.io.File;
20  
21  import org.apache.maven.plugin.Mojo;
22  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
23  import org.codehaus.plexus.util.FileUtils;
24  
25  /**
26   * @author <a href="mailto:nicolas@apache.org">nicolas De Loof</a>
27   */
28  public class CompileMojoTest
29      extends AbstractMojoTestCase
30  {
31      public void testCompileAndAssemble()
32          throws Exception
33      {
34          File testPom = new File( getBasedir(), "src/test/resources/compile.pom" );
35          Mojo mojo = (Mojo) lookupMojo( "compile", testPom );
36          assertNotNull( "Failed to configure the plugin", mojo );
37  
38          mojo.execute();
39  
40          File expected = new File( "./target/test-target/compile/scriptaculous.js" );
41          assertTrue( "expected file not found " + expected.getName(), expected.exists() );
42  
43          expected = new File( "./target/test-target/compile/prototype.js" );
44          assertTrue( "expected file not found " + expected.getName(), expected.exists() );
45  
46          String merged = FileUtils.fileRead( expected );
47          assertTrue( "builder not merged", merged.contains( "var Builder = {" ) );
48          assertTrue( "slider not merged", merged.contains( "Slider.prototype = {" ) );
49  
50          File unexpected = new File( "./target/test-target/compile/builder.js" );
51          assertTrue( "unexpected file found " + unexpected.getName(), !unexpected.exists() );
52  
53          unexpected = new File( "./target/test-target/compile/slider.js" );
54          assertTrue( "unexpected file found " + unexpected.getName(), !unexpected.exists() );
55      }
56  }