01: package org.apache.maven.embedder;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21:
22: import junit.framework.TestCase;
23: import org.apache.maven.artifact.factory.ArtifactFactory;
24: import org.codehaus.plexus.PlexusContainer;
25: import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
26:
27: import java.io.File;
28:
29: /** @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a> */
30: public class TestComponentOverride extends TestCase {
31: private String basedir;
32:
33: private MavenEmbedder maven;
34:
35: protected PlexusContainer container;
36:
37: protected void setUp() throws Exception {
38: basedir = System.getProperty("basedir");
39:
40: ClassLoader loader = Thread.currentThread()
41: .getContextClassLoader();
42:
43: Configuration request = new DefaultConfiguration();
44:
45: request.setClassLoader(loader);
46:
47: request
48: .setMavenEmbedderLogger(new MavenEmbedderConsoleLogger());
49:
50: request.addExtension(new File(basedir, "src/test/extensions")
51: .toURI().toURL());
52:
53: // register callback to get a hold of the container
54: request.setConfigurationCustomizer(new ContainerCustomizer() {
55: public void customize(PlexusContainer container) {
56: TestComponentOverride.this .container = container;
57: }
58: });
59:
60: maven = new MavenEmbedder(request);
61: }
62:
63: public void testComponentOverride() throws ComponentLookupException {
64: ArtifactFactory factory = (ArtifactFactory) container
65: .lookup(ArtifactFactory.class);
66:
67: assertNotNull(factory);
68:
69: assertTrue("Expecting " + CustomArtifactFactory.class.getName()
70: + " but was " + factory.getClass().getName(),
71: CustomArtifactFactory.class.isAssignableFrom(factory
72: .getClass()));
73:
74: // test wheter the requirement is injected - if not, it nullpointers
75: factory.createArtifact("testGroupId", "testArtifactId",
76: "testVersion", "compile", "jar");
77: }
78: }
|