1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.index.creator;
20
21 import java.io.File;
22
23 import org.apache.maven.index.AbstractTestSupport;
24 import org.apache.maven.index.ArtifactContext;
25 import org.apache.maven.index.ArtifactInfo;
26 import org.apache.maven.index.context.IndexCreator;
27 import org.junit.Test;
28
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertNotNull;
31 import static org.junit.Assert.assertNull;
32 import static org.junit.Assert.assertTrue;
33
34
35
36
37 public class JarFileContentsIndexCreatorTest extends AbstractTestSupport {
38 protected IndexCreator indexCreator;
39
40 @Override
41 public void setUp() throws Exception {
42 super.setUp();
43
44 indexCreator = this.lookup(IndexCreator.class, "jarContent");
45 }
46
47 @Test
48 public void test_nexus_2318_indexJarWithClasses() throws Exception {
49 File artifact = new File(getBasedir(), "src/test/nexus-2318/aopalliance/aopalliance/1.0/aopalliance-1.0.jar");
50
51 File pom = new File(getBasedir(), "src/test/nexus-2318/aopalliance/aopalliance/1.0/aopalliance-1.0.pom");
52
53 ArtifactInfo artifactInfo = new ArtifactInfo("test", "aopalliance", "aopalliance", "1.0", null, "jar");
54
55 ArtifactContext artifactContext = new ArtifactContext(pom, artifact, null, artifactInfo, null);
56
57 indexCreator.populateArtifactInfo(artifactContext);
58
59 assertNotNull(
60 "Classes should not be null", artifactContext.getArtifactInfo().getClassNames());
61 }
62
63 @Test
64 public void test_nexus_2318_indexZipWithClasses() throws Exception {
65 File artifact = new File(getBasedir(), "src/test/nexus-2318/aopalliance/aopalliance/1.0/aopalliance-1.0.zip");
66
67 File pom = new File(getBasedir(), "src/test/nexus-2318/aopalliance/aopalliance/1.0/aopalliance-1.0.pom");
68
69 ArtifactInfo artifactInfo = new ArtifactInfo("test", "aopalliance", "aopalliance", "1.0", null, "zip");
70
71 ArtifactContext artifactContext = new ArtifactContext(pom, artifact, null, artifactInfo, null);
72
73 indexCreator.populateArtifactInfo(artifactContext);
74
75 assertNotNull(
76 "Classes should not be null", artifactContext.getArtifactInfo().getClassNames());
77
78 String[] classNames = artifactContext.getArtifactInfo().getClassNames().split("\n");
79
80 assertEquals("Unexpected classes length", 9, classNames.length);
81
82 assertEquals("Advice class was expected", "/org/aopalliance/aop/Advice", classNames[0]);
83
84 assertEquals("AspectException class was expected", "/org/aopalliance/aop/AspectException", classNames[1]);
85
86 assertEquals(
87 "ConstructorInterceptor class was expected",
88 "/org/aopalliance/intercept/ConstructorInterceptor",
89 classNames[2]);
90
91 assertEquals(
92 "ConstructorInvocation class was expected",
93 "/org/aopalliance/intercept/ConstructorInvocation",
94 classNames[3]);
95
96 assertEquals("Interceptor class was expected", "/org/aopalliance/intercept/Interceptor", classNames[4]);
97
98 assertEquals("Invocation class was expected", "/org/aopalliance/intercept/Invocation", classNames[5]);
99
100 assertEquals("Joinpoint class was expected", "/org/aopalliance/intercept/Joinpoint", classNames[6]);
101
102 assertEquals(
103 "MethodInterceptor class was expected", "/org/aopalliance/intercept/MethodInterceptor", classNames[7]);
104
105 assertEquals(
106 "MethodInvocation class was expected", "/org/aopalliance/intercept/MethodInvocation", classNames[8]);
107 }
108
109 @Test
110 public void test_nexus_2318_indexJarWithSources() throws Exception {
111 File artifact =
112 new File(getBasedir(), "src/test/nexus-2318/aopalliance/aopalliance/1.0/aopalliance-1.0-sources.jar");
113
114 File pom = new File(getBasedir(), "src/test/nexus-2318/aopalliance/aopalliance/1.0/aopalliance-1.0.pom");
115
116 ArtifactInfo artifactInfo = new ArtifactInfo("test", "aopalliance", "aopalliance", "1.0", null, "jar");
117
118 ArtifactContext artifactContext = new ArtifactContext(pom, artifact, null, artifactInfo, null);
119
120 indexCreator.populateArtifactInfo(artifactContext);
121
122 assertNull("Classes should be null", artifactContext.getArtifactInfo().getClassNames());
123 }
124
125 @Test
126 public void test_nexus_2318_indexZipWithSources() throws Exception {
127 File artifact =
128 new File(getBasedir(), "src/test/nexus-2318/aopalliance/aopalliance/1.0/aopalliance-1.0-sources.zip");
129
130 File pom = new File(getBasedir(), "src/test/nexus-2318/aopalliance/aopalliance/1.0/aopalliance-1.0.pom");
131
132 ArtifactInfo artifactInfo = new ArtifactInfo("test", "aopalliance", "aopalliance", "1.0", null, "zip");
133
134 ArtifactContext artifactContext = new ArtifactContext(pom, artifact, null, artifactInfo, null);
135
136 indexCreator.populateArtifactInfo(artifactContext);
137
138 assertNull("Classes should be null", artifactContext.getArtifactInfo().getClassNames());
139 }
140
141 @Test
142 public void testMindexer35ScanWar() throws Exception {
143 File artifact = new File(
144 getBasedir(),
145 "src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/sample-war-1.0-SNAPSHOT.war");
146
147 File pom = new File(
148 getBasedir(),
149 "src/test/mindexer-35/org/apache/maven/indexer/test/sample-war/1.0-SNAPSHOT/sample-war-1.0-SNAPSHOT.pom");
150
151 ArtifactInfo artifactInfo =
152 new ArtifactInfo("test", "org.apache.maven.indexer.test", "sample-war", "1.0-SNAPSHOT", null, "war");
153
154 ArtifactContext artifactContext = new ArtifactContext(pom, artifact, null, artifactInfo, null);
155
156 indexCreator.populateArtifactInfo(artifactContext);
157
158 assertTrue(
159 "Classes should contain WebappClass",
160 artifactContext.getArtifactInfo().getClassNames().contains("WebappClass"));
161 assertEquals(
162 "WebappClass should have proper package",
163 "/org/apache/maven/indexer/samples/webapp/WebappClass",
164 artifactContext.getArtifactInfo().getClassNames());
165 }
166 }