1 package com.simpligility.maven.plugins.android.phase09package;
2
3 import io.takari.maven.testing.TestResources;
4 import io.takari.maven.testing.executor.MavenExecutionResult;
5 import io.takari.maven.testing.executor.MavenRuntime;
6 import io.takari.maven.testing.executor.MavenRuntime.MavenRuntimeBuilder;
7 import io.takari.maven.testing.executor.MavenVersions;
8 import io.takari.maven.testing.executor.junit.MavenJUnitTestRunner;
9 import org.codehaus.plexus.util.IOUtil;
10 import org.junit.Ignore;
11 import org.junit.Rule;
12 import org.junit.Test;
13 import org.junit.runner.RunWith;
14
15 import java.io.File;
16 import java.io.IOException;
17 import java.io.InputStream;
18 import java.util.zip.ZipEntry;
19 import java.util.zip.ZipFile;
20
21 import static org.junit.Assert.*;
22
23 @RunWith(MavenJUnitTestRunner.class)
24 @MavenVersions({"3.2.3"})
25 public class ExtractDuplicatesIT {
26
27 @Rule
28 public final TestResources resources = new TestResources();
29
30 public final MavenRuntime mavenRuntime;
31
32 public ExtractDuplicatesIT(MavenRuntimeBuilder builder) throws Exception {
33 this.mavenRuntime = builder.withCliOptions( "-X" ).build();
34 }
35
36 @Ignore
37 @Test
38 public void buildDeployAndRun() throws Exception {
39 File basedir = resources.getBasedir( "duplicates" );
40 MavenExecutionResult result = mavenRuntime
41 .forProject(basedir)
42 .execute( "clean",
43 "install" );
44
45 result.assertErrorFreeLog();
46 result.assertLogText( "Duplicate file resourceA" );
47 result.assertLogText( "Duplicate file resourceB" );
48 result.assertLogText( "Duplicate file resourceC" );
49 File apk = new File(result.getBasedir().getAbsolutePath()+"/duplicates-app/target", "duplicates-app.apk");
50 assertNotNull("APK Not Null", apk);
51 ZipFile apkFile = new ZipFile(apk);
52 assertNotNull(apkFile.getEntry("resourceA"));
53 assertNotNull(apkFile.getEntry("resourceB"));
54 assertNotNull(apkFile.getEntry("resourceC"));
55
56
57 assertEntryContents(apkFile, "META-INF/services/com.jayway.maven.plugins.android.TestInterface",
58 "ImplementationA\nImplementationB\nImplementationC\nImplementationApp");
59
60
61 assertEntryContents( apkFile, "META-INF/kmodule.xml", expectedKmodule );
62 assertEntryContents( apkFile, "kmodule.info", expectedInfo );
63 }
64
65 private void assertEntryContents( ZipFile zip, String name, String expected ) throws IOException {
66 ZipEntry ze = zip.getEntry( name );
67 assertNotNull( ze );
68 InputStream is = null;
69 try {
70 is = zip.getInputStream( ze );
71 assertEquals(name, expected.replaceAll( "\\s","" ), IOUtil.toString( is ).trim().replaceAll( "\\s","" ));
72 }
73 finally
74 {
75 if( is != null ) is.close();
76 }
77 }
78
79 private static final String expectedKmodule =
80 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
81 "<kmodule xmlns=\"http://jboss.org/kie/6.0.0/kmodule\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
82 " <kbase name=\"kb1\" packages=\"org.drools.examples.helloworld\" equalsBehavior=\"equality\" />\n" +
83 " <kbase name=\"kb2\" packages=\"org.drools.examples.helloworld\" equalsBehavior=\"equality\" />\n" +
84 "</kmodule>";
85
86 private static final String expectedInfo =
87 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
88 "<org.drools.core.rule.KieModuleMetaInfo>\n" +
89 " <typeMetaInfos>\n" +
90 " <entry>\n" +
91 " <string>org.drools.examples.helloworld.TestType</string>\n" +
92 " <org.drools.core.rule.TypeMetaInfo>\n" +
93 " <kind>CLASS</kind>\n" +
94 " <role>FACT</role>\n" +
95 " <isDeclaredType>true</isDeclaredType>\n" +
96 " </org.drools.core.rule.TypeMetaInfo>\n" +
97 " </entry>\n" +
98 " <entry>\n" +
99 " <string>org.drools.examples.helloworld.Message</string>\n" +
100 " <org.drools.core.rule.TypeMetaInfo>\n" +
101 " <kind>CLASS</kind>\n" +
102 " <role>FACT</role>\n" +
103 " <isDeclaredType>false</isDeclaredType>\n" +
104 " </org.drools.core.rule.TypeMetaInfo>\n" +
105 " </entry>\n" +
106 " </typeMetaInfos>\n" +
107 " <rulesByPackage>\n" +
108 " <entry>\n" +
109 " <string>org.drools.examples.helloworld</string>\n" +
110 " <set>\n" +
111 " <string>Hello</string>\n" +
112 " </set>\n" +
113 " </entry>\n" +
114 " <entry>\n" +
115 " <string>org.drools.examples.goodbye</string>\n" +
116 " <set>\n" +
117 " <string>Good Bye</string>\n" +
118 " </set>\n" +
119 " </entry>\n" +
120 " </rulesByPackage>\n" +
121 "</org.drools.core.rule.KieModuleMetaInfo>";
122 }