Pierre De Rop | 3a00a21 | 2015-03-01 09:27:46 +0000 | [diff] [blame^] | 1 | /* |
| 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 |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 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 |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.apache.felix.dm.itest.api; |
| 20 | |
| 21 | import java.net.MalformedURLException; |
| 22 | import java.net.URL; |
| 23 | |
| 24 | import org.junit.Assert; |
| 25 | |
| 26 | import org.apache.felix.dm.Component; |
| 27 | import org.apache.felix.dm.ComponentDeclaration; |
| 28 | import org.apache.felix.dm.ComponentDependencyDeclaration; |
| 29 | import org.apache.felix.dm.DependencyManager; |
| 30 | import org.apache.felix.dm.itest.util.TestBase; |
| 31 | import org.osgi.framework.Bundle; |
| 32 | import org.osgi.service.log.LogService; |
| 33 | |
| 34 | /** |
| 35 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 36 | */ |
| 37 | public class FELIX4158_DependencyDeclarationTest extends TestBase { |
| 38 | public void testServiceDependencyDeclaration() { |
| 39 | DependencyManager m = getDM(); |
| 40 | Component c = m.createComponent() |
| 41 | .setImplementation(new Object()) |
| 42 | .add(m.createServiceDependency().setService(LogService.class, "(foo=bar)")); |
| 43 | |
| 44 | ComponentDeclaration cd = c.getComponentDeclaration(); |
| 45 | ComponentDependencyDeclaration[] cdds = cd.getComponentDependencies(); |
| 46 | Assert.assertNotNull(cdds); |
| 47 | Assert.assertNotNull(cdds.length == 1); |
| 48 | Assert.assertEquals(cdds[0].getName(), "org.osgi.service.log.LogService (foo=bar)"); |
| 49 | Assert.assertEquals(cdds[0].getSimpleName(), "org.osgi.service.log.LogService"); |
| 50 | Assert.assertNotNull(cdds[0].getFilter()); |
| 51 | Assert.assertEquals(cdds[0].getFilter(), "(foo=bar)"); |
| 52 | m.clear(); |
| 53 | } |
| 54 | |
| 55 | public void testConfigurationDependencyDeclaration() { |
| 56 | DependencyManager m = getDM(); |
| 57 | Component c = m.createComponent() |
| 58 | .setImplementation(new Object()) |
| 59 | .add(m.createConfigurationDependency().setPid("foo")); |
| 60 | |
| 61 | ComponentDeclaration cd = c.getComponentDeclaration(); |
| 62 | ComponentDependencyDeclaration[] cdds = cd.getComponentDependencies(); |
| 63 | Assert.assertNotNull(cdds); |
| 64 | Assert.assertNotNull(cdds.length == 1); |
| 65 | Assert.assertEquals(cdds[0].getName(), "foo"); |
| 66 | Assert.assertEquals(cdds[0].getSimpleName(), "foo"); |
| 67 | Assert.assertNull(cdds[0].getFilter()); |
| 68 | m.clear(); |
| 69 | } |
| 70 | |
| 71 | public void testResourceDependencyDeclaration() throws MalformedURLException { |
| 72 | DependencyManager m = getDM(); |
| 73 | Component c = m.createComponent() |
| 74 | .setImplementation(new Object()) |
| 75 | .add(m.createResourceDependency() |
| 76 | .setResource(new URL("file://localhost/path/to/file1.txt"))); |
| 77 | |
| 78 | ComponentDeclaration cd = c.getComponentDeclaration(); |
| 79 | ComponentDependencyDeclaration[] cdds = cd.getComponentDependencies(); |
| 80 | Assert.assertNotNull(cdds); |
| 81 | Assert.assertNotNull(cdds.length == 1); |
| 82 | Assert.assertEquals(cdds[0].getName(), "file://localhost/path/to/file1.txt"); |
| 83 | Assert.assertNotNull(cdds[0].getSimpleName()); |
| 84 | Assert.assertEquals(cdds[0].getSimpleName(), "file://localhost/path/to/file1.txt"); |
| 85 | Assert.assertNull(cdds[0].getFilter()); |
| 86 | m.clear(); |
| 87 | } |
| 88 | |
| 89 | public void testResourceDependencyDeclarationWithFilter() { |
| 90 | DependencyManager m = getDM(); |
| 91 | Component c = m.createComponent() |
| 92 | .setImplementation(new Object()) |
| 93 | .add(m.createResourceDependency() |
| 94 | .setFilter("(&(path=/path/to/*.txt)(host=localhost))")); |
| 95 | |
| 96 | ComponentDeclaration cd = c.getComponentDeclaration(); |
| 97 | ComponentDependencyDeclaration[] cdds = cd.getComponentDependencies(); |
| 98 | Assert.assertNotNull(cdds); |
| 99 | Assert.assertNotNull(cdds.length == 1); |
| 100 | Assert.assertEquals(cdds[0].getName(), ("(&(path=/path/to/*.txt)(host=localhost))")); |
| 101 | Assert.assertNull(cdds[0].getSimpleName()); |
| 102 | Assert.assertNotNull(cdds[0].getFilter()); |
| 103 | Assert.assertEquals(cdds[0].getFilter(), "(&(path=/path/to/*.txt)(host=localhost))"); |
| 104 | m.clear(); |
| 105 | } |
| 106 | |
| 107 | public void testBundleDependencyDeclaration() throws MalformedURLException { |
| 108 | DependencyManager m = getDM(); |
| 109 | Component c = m.createComponent() |
| 110 | .setImplementation(new Object()) |
| 111 | .add(m.createBundleDependency()); |
| 112 | |
| 113 | ComponentDeclaration cd = c.getComponentDeclaration(); |
| 114 | ComponentDependencyDeclaration[] cdds = cd.getComponentDependencies(); |
| 115 | Assert.assertNotNull(cdds); |
| 116 | Assert.assertNotNull(cdds.length == 1); |
| 117 | Assert.assertEquals(cdds[0].getName(), "active installed resolved"); |
| 118 | Assert.assertNotNull(cdds[0].getSimpleName()); |
| 119 | Assert.assertEquals(cdds[0].getSimpleName(), "active installed resolved"); |
| 120 | Assert.assertNull(cdds[0].getFilter()); |
| 121 | m.clear(); |
| 122 | } |
| 123 | |
| 124 | public void testBundleDependencyDeclarationWithMask() throws MalformedURLException { |
| 125 | DependencyManager m = getDM(); |
| 126 | Component c = m.createComponent() |
| 127 | .setImplementation(new Object()) |
| 128 | .add(m.createBundleDependency() |
| 129 | .setStateMask( Bundle.ACTIVE | Bundle.RESOLVED)); |
| 130 | |
| 131 | ComponentDeclaration cd = c.getComponentDeclaration(); |
| 132 | ComponentDependencyDeclaration[] cdds = cd.getComponentDependencies(); |
| 133 | Assert.assertNotNull(cdds); |
| 134 | Assert.assertNotNull(cdds.length == 1); |
| 135 | Assert.assertEquals(cdds[0].getName(), "active resolved"); |
| 136 | Assert.assertNotNull(cdds[0].getSimpleName()); |
| 137 | Assert.assertEquals(cdds[0].getSimpleName(), "active resolved"); |
| 138 | Assert.assertNull(cdds[0].getFilter()); |
| 139 | m.clear(); |
| 140 | } |
| 141 | |
| 142 | public void testBundleDependencyDeclarationWithFilter() throws MalformedURLException { |
| 143 | DependencyManager m = getDM(); |
| 144 | Component c = m.createComponent() |
| 145 | .setImplementation(new Object()) |
| 146 | .add(m.createBundleDependency() |
| 147 | .setStateMask( Bundle.ACTIVE ) |
| 148 | .setFilter("(DependencyManager-Component=*)")); |
| 149 | |
| 150 | ComponentDeclaration cd = c.getComponentDeclaration(); |
| 151 | ComponentDependencyDeclaration[] cdds = cd.getComponentDependencies(); |
| 152 | Assert.assertNotNull(cdds); |
| 153 | Assert.assertNotNull(cdds.length == 1); |
| 154 | Assert.assertEquals(cdds[0].getName(), "active (DependencyManager-Component=*)"); |
| 155 | Assert.assertNotNull(cdds[0].getSimpleName()); |
| 156 | Assert.assertEquals(cdds[0].getSimpleName(), "active"); |
| 157 | Assert.assertNotNull(cdds[0].getFilter()); |
| 158 | Assert.assertEquals(cdds[0].getFilter(), "(DependencyManager-Component=*)"); |
| 159 | m.clear(); |
| 160 | } |
| 161 | } |