View Javadoc
1   /*
2    * Copyright (C) 2014 simpligility technologies inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.simpligility.maven.plugins.android.standalonemojos;
17  
18  import io.takari.maven.testing.TestResources;
19  import io.takari.maven.testing.executor.MavenExecutionResult;
20  import io.takari.maven.testing.executor.MavenRuntime;
21  import io.takari.maven.testing.executor.MavenRuntime.MavenRuntimeBuilder;
22  import io.takari.maven.testing.executor.MavenVersions;
23  import io.takari.maven.testing.executor.junit.MavenJUnitTestRunner;
24  import org.junit.Assert;
25  import org.junit.Rule;
26  import org.junit.Test;
27  import org.junit.runner.RunWith;
28  
29  import java.io.File;
30  import java.util.Enumeration;
31  import java.util.HashMap;
32  import java.util.Map;
33  import java.util.zip.ZipEntry;
34  import java.util.zip.ZipFile;
35  
36  @RunWith(MavenJUnitTestRunner.class)
37  @MavenVersions({"3.3.9"})
38  public class AarMojoIntegrationTest
39  {
40  
41    @Rule
42    public final TestResources resources = new TestResources();
43  
44    public final MavenRuntime mavenRuntime;
45  
46    public AarMojoIntegrationTest( MavenRuntimeBuilder builder) throws Exception {
47      this.mavenRuntime = builder.build();
48    }
49    
50    @Test
51    public void buildDeployAndRun() throws Exception {
52      File basedir = resources.getBasedir( "aar-no-resources" );
53      MavenExecutionResult result = mavenRuntime
54            .forProject(basedir)
55            .execute( "clean", "install" );
56      result.assertErrorFreeLog();
57  
58      // Check contents of AAR and confirm that /res folder and R.txt exist.
59      final File targetFolder = new File( basedir, "target" );
60      final ZipFile aarFile = new ZipFile( new File( targetFolder, "aar-no-resources.aar" ) );
61      try {
62        final Enumeration<? extends ZipEntry> entries = aarFile.entries();
63        final Map<String, ? extends ZipEntry> entriesMap = convertEntriesToNamedMap( entries );
64        Assert.assertTrue( "AAR must have res folder", entriesMap.containsKey( "res/" ) );
65        Assert.assertTrue( "AAR must have R.txt", entriesMap.containsKey( "R.txt" ) );
66      } finally
67      {
68        aarFile.close();
69      }
70  
71    }
72  
73    private Map<String, ? extends ZipEntry> convertEntriesToNamedMap( Enumeration<? extends ZipEntry> entries )
74    {
75      final Map< String, ZipEntry> map = new HashMap<>();
76      while ( entries.hasMoreElements() )
77      {
78        final ZipEntry entry = entries.nextElement();
79        map.put( entry.getName(), entry );
80      }
81      return map;
82    }
83  }