2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
21 package org.apache.karaf.tooling.features;
23 import java.lang.reflect.Field;
24 import java.util.HashMap;
26 import org.apache.karaf.tooling.utils.MojoSupport;
27 import org.apache.maven.artifact.Artifact;
28 import org.apache.maven.artifact.factory.DefaultArtifactFactory;
29 import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
30 import org.apache.maven.artifact.handler.manager.DefaultArtifactHandlerManager;
31 import org.apache.maven.plugin.MojoExecutionException;
32 import org.apache.maven.plugin.MojoFailureException;
33 import org.junit.Test;
35 public class BundleToArtifactTest extends MojoSupport {
37 @SuppressWarnings("rawtypes")
38 public BundleToArtifactTest() throws NoSuchFieldException, IllegalAccessException {
39 factory = new DefaultArtifactFactory();
40 ArtifactHandlerManager artifactHandlerManager = new DefaultArtifactHandlerManager();
41 Field f = factory.getClass().getDeclaredField("artifactHandlerManager");
42 f.setAccessible(true);
43 f.set(factory, artifactHandlerManager);
44 f.setAccessible(false);
46 f = artifactHandlerManager.getClass().getDeclaredField("artifactHandlers");
47 f.setAccessible(true);
48 f.set(artifactHandlerManager, new HashMap());
49 f.setAccessible(false);
52 public void execute() throws MojoExecutionException, MojoFailureException {
56 public void testSimpleURL() throws Exception {
57 Artifact artifact = resourceToArtifact("mvn:org.foo/bar/1.0/kar", false);
58 assert artifact.getGroupId().equals("org.foo");
59 assert artifact.getArtifactId().equals("bar");
60 assert artifact.getBaseVersion().equals("1.0");
61 assert artifact.getType().equals("kar");
62 assert artifact.getRepository() == null;
63 assert artifact.getClassifier() == null;
67 public void testURLWithClassifier() throws Exception {
68 Artifact artifact = resourceToArtifact("mvn:org.foo/bar/1.0/kar/type", false);
69 assert artifact.getGroupId().equals("org.foo");
70 assert artifact.getArtifactId().equals("bar");
71 assert artifact.getBaseVersion().equals("1.0");
72 assert artifact.getType().equals("kar");
73 assert artifact.getRepository() == null;
74 assert artifact.getClassifier().equals("type");
78 public void testRemoteRepoURL() throws Exception {
79 Artifact artifact = resourceToArtifact("mvn:http://baz.com!org.foo/bar/1.0/kar", false);
80 assert artifact.getGroupId().equals("org.foo");
81 assert artifact.getArtifactId().equals("bar");
82 assert artifact.getBaseVersion().equals("1.0");
83 assert artifact.getType().equals("kar");
84 assert artifact.getRepository().getUrl().equals("http://baz.com");
85 assert artifact.getClassifier() == null;