3 * Licensed to the Apache Software Foundation (ASF) under one or more
4 * contributor license agreements. See the NOTICE file distributed with
5 * this work for additional information regarding copyright ownership.
6 * The ASF licenses this file to You under the Apache License, Version 2.0
7 * (the "License"); you may not use this file except in compliance with
8 * 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, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.karaf.tooling.features;
20 import static org.apache.karaf.tooling.utils.ManifestUtils.matches;
22 import junit.framework.TestCase;
24 import org.apache.felix.utils.manifest.Attribute;
25 import org.apache.felix.utils.manifest.Clause;
26 import org.apache.felix.utils.manifest.Directive;
27 import org.apache.karaf.tooling.utils.ManifestUtils;
28 import org.osgi.framework.Constants;
31 * Test cased for {@link org.apache.karaf.tooling.utils.ManifestUtils}
33 public class ManifestUtilsTest extends TestCase {
35 public void testIsOptional() {
36 Directive[] directive = new Directive[0];
37 Attribute[] attribute = new Attribute[0];
38 Clause clause = new Clause("org.apache.karaf.test", directive, attribute);
39 assertFalse(ManifestUtils.isOptional(clause));
41 directive = new Directive[1];
42 directive[0] = new Directive("resolution", "mandatory");
43 clause = new Clause("org.apache.karaf.test", directive, attribute);
45 assertFalse(ManifestUtils.isOptional(clause));
47 directive[0] = new Directive("resolution", "optional");
48 clause = new Clause("org.apache.karaf.test", directive, attribute);
49 assertTrue(ManifestUtils.isOptional(clause));
52 public void testMatches() {
53 assertFalse(matches(clause("org.apache.karaf.dev"), clause("org.apache.karaf.test")));
54 assertTrue(matches(clause("org.apache.karaf.test"), clause("org.apache.karaf.test")));
56 assertFalse(matches(clause("org.apache.karaf.test", "1.2.0"), clause("org.apache.karaf.test", "[1.1.0, 1.1.0]")));
57 assertTrue(matches(clause("org.apache.karaf.test", "1.1.0"), clause("org.apache.karaf.test", "[1.1.0, 1.1.0]")));
59 // a single version means >= 1.0.0, so 1.1.O should be a match
60 assertTrue(matches(clause("org.apache.karaf.test", "1.0.0"), clause("org.apache.karaf.test", "1.1.0")));
61 assertTrue(matches(clause("org.apache.karaf.test", "1.0.0"), clause("org.apache.karaf.test")));
63 assertFalse(matches(clause("org.apache.karaf.test", "[1.1.0, 1.2.0)"), clause("org.apache.karaf.test", "[1.0.0, 1.0.0]")));
64 assertFalse(matches(clause("org.apache.karaf.test", "[1.1.0, 1.2.0)"), clause("org.apache.karaf.test", "[1.2.0, 1.2.0]")));
65 assertTrue(matches(clause("org.apache.karaf.test", "[1.1.0, 1.2.0)"), clause("org.apache.karaf.test", "[1.1.0, 1.1.0]")));
66 assertTrue(matches(clause("org.apache.karaf.test", "[1.1.0, 1.2.0)"), clause("org.apache.karaf.test", "[1.1.1, 1.1.1]")));
67 assertTrue(matches(clause("org.apache.karaf.test", "[1.1.0, 1.1.0]"), clause("org.apache.karaf.test", "[1.1.0, 1.1.0]")));
68 assertFalse(matches(clause("org.apache.karaf.test", "[1.1.0, 1.1.0]"), clause("org.apache.karaf.test", "1.1.1")));
69 assertTrue(matches(clause("org.apache.karaf.test", "[1.1.0, 1.1.0]"), clause("org.apache.karaf.test", "1.0.0")));
72 private Clause clause(String name) {
73 return new Clause(name, new Directive[0], new Attribute[0]);
76 private Clause clause(String name, String version) {
77 Attribute[] attribute = {new Attribute(Constants.VERSION_ATTRIBUTE, version)};
78 return new Clause(name, new Directive[0], attribute);