aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwr...@apache.org
Subject svn commit: r1451752 - in /aries/trunk/subsystem/subsystem-obr/src/test/java/org/apache/aries/subsystem/obr/internal: FelixCapabilityAdapterTest.java FelixRequirementAdapterTest.java OsgiRequirementAdapterTest.java
Date Fri, 01 Mar 2013 22:46:21 GMT
Author: jwross
Date: Fri Mar  1 22:46:21 2013
New Revision: 1451752

URL: http://svn.apache.org/r1451752
Log:
New tests for the subsystems <-> obr bridge.

Added:
    aries/trunk/subsystem/subsystem-obr/src/test/java/org/apache/aries/subsystem/obr/internal/FelixCapabilityAdapterTest.java
    aries/trunk/subsystem/subsystem-obr/src/test/java/org/apache/aries/subsystem/obr/internal/OsgiRequirementAdapterTest.java
Modified:
    aries/trunk/subsystem/subsystem-obr/src/test/java/org/apache/aries/subsystem/obr/internal/FelixRequirementAdapterTest.java

Added: aries/trunk/subsystem/subsystem-obr/src/test/java/org/apache/aries/subsystem/obr/internal/FelixCapabilityAdapterTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-obr/src/test/java/org/apache/aries/subsystem/obr/internal/FelixCapabilityAdapterTest.java?rev=1451752&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-obr/src/test/java/org/apache/aries/subsystem/obr/internal/FelixCapabilityAdapterTest.java
(added)
+++ aries/trunk/subsystem/subsystem-obr/src/test/java/org/apache/aries/subsystem/obr/internal/FelixCapabilityAdapterTest.java
Fri Mar  1 22:46:21 2013
@@ -0,0 +1,82 @@
+package org.apache.aries.subsystem.obr.internal;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.felix.bundlerepository.Capability;
+import org.apache.felix.bundlerepository.Resource;
+import org.easymock.EasyMock;
+import org.junit.Test;
+import org.osgi.framework.namespace.BundleNamespace;
+import org.osgi.framework.namespace.PackageNamespace;
+import org.osgi.namespace.service.ServiceNamespace;
+
+public class FelixCapabilityAdapterTest {
+	@Test
+	public void testObjectClassAttribute() {
+		String objectClass = "com.foo.Bar";
+		Capability cap = EasyMock.createNiceMock(Capability.class);
+		EasyMock.expect(cap.getName()).andReturn(Capability.SERVICE);
+		Map<String, Object> props = new HashMap<String, Object>();
+		props.put(ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE.toLowerCase(), objectClass);
+		EasyMock.expect(cap.getPropertiesAsMap()).andReturn(props);
+		EasyMock.replay(cap);
+		FelixCapabilityAdapter adapter = new FelixCapabilityAdapter(cap, EasyMock.createNiceMock(org.osgi.resource.Resource.class));
+		assertEquals("Wrong value for attribute " + ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE,
objectClass, adapter.getAttributes().get(ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE));
+	}
+	
+	@Test
+	public void testOsgiServiceNamespace() {
+		Capability cap = EasyMock.createNiceMock(Capability.class);
+		EasyMock.expect(cap.getName()).andReturn(Capability.SERVICE);
+		EasyMock.replay(cap);
+		FelixCapabilityAdapter adapter = new FelixCapabilityAdapter(cap, EasyMock.createNiceMock(org.osgi.resource.Resource.class));
+		assertEquals("Wrong namespace", ServiceNamespace.SERVICE_NAMESPACE, adapter.getNamespace());
+	}
+	
+	@Test
+	public void testOsgiWiringPackageAttribute() {
+		String pkg = "com.foo.Bar";
+		Capability cap = EasyMock.createNiceMock(Capability.class);
+		EasyMock.expect(cap.getName()).andReturn(Capability.PACKAGE).anyTimes();
+		Map<String, Object> props = new HashMap<String, Object>();
+		props.put(Capability.PACKAGE, pkg);
+		EasyMock.expect(cap.getPropertiesAsMap()).andReturn(props);
+		EasyMock.replay(cap);
+		FelixCapabilityAdapter adapter = new FelixCapabilityAdapter(cap, EasyMock.createNiceMock(org.osgi.resource.Resource.class));
+		assertEquals("Wrong value for attribute " + PackageNamespace.PACKAGE_NAMESPACE, pkg, adapter.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
+	}
+	
+	@Test
+	public void testOsgiWiringPackageNamespace() {
+		Capability cap = EasyMock.createNiceMock(Capability.class);
+		EasyMock.expect(cap.getName()).andReturn(Capability.PACKAGE);
+		EasyMock.replay(cap);
+		FelixCapabilityAdapter adapter = new FelixCapabilityAdapter(cap, EasyMock.createNiceMock(org.osgi.resource.Resource.class));
+		assertEquals("Wrong namespace", PackageNamespace.PACKAGE_NAMESPACE, adapter.getNamespace());
+	}
+	
+	@Test
+	public void testOsgiWiringBundleNamespace() {
+		Capability cap = EasyMock.createNiceMock(Capability.class);
+		EasyMock.expect(cap.getName()).andReturn(Capability.BUNDLE);
+		EasyMock.replay(cap);
+		FelixCapabilityAdapter adapter = new FelixCapabilityAdapter(cap, EasyMock.createNiceMock(org.osgi.resource.Resource.class));
+		assertEquals("Wrong namespace", BundleNamespace.BUNDLE_NAMESPACE, adapter.getNamespace());
+	}
+	
+	@Test
+	public void testOsgiWiringBundleAttribute() {
+		String symbolicName = "derbyclient";
+		Capability cap = EasyMock.createNiceMock(Capability.class);
+		EasyMock.expect(cap.getName()).andReturn(Capability.BUNDLE).anyTimes();
+		Map<String, Object> props = new HashMap<String, Object>();
+		props.put(Resource.SYMBOLIC_NAME, symbolicName);
+		EasyMock.expect(cap.getPropertiesAsMap()).andReturn(props);
+		EasyMock.replay(cap);
+		FelixCapabilityAdapter adapter = new FelixCapabilityAdapter(cap, EasyMock.createNiceMock(org.osgi.resource.Resource.class));
+		assertEquals("Wrong value for attribute " + BundleNamespace.BUNDLE_NAMESPACE, symbolicName,
adapter.getAttributes().get(BundleNamespace.BUNDLE_NAMESPACE));
+	}
+}

Modified: aries/trunk/subsystem/subsystem-obr/src/test/java/org/apache/aries/subsystem/obr/internal/FelixRequirementAdapterTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-obr/src/test/java/org/apache/aries/subsystem/obr/internal/FelixRequirementAdapterTest.java?rev=1451752&r1=1451751&r2=1451752&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-obr/src/test/java/org/apache/aries/subsystem/obr/internal/FelixRequirementAdapterTest.java
(original)
+++ aries/trunk/subsystem/subsystem-obr/src/test/java/org/apache/aries/subsystem/obr/internal/FelixRequirementAdapterTest.java
Fri Mar  1 22:46:21 2013
@@ -16,7 +16,7 @@ public class FelixRequirementAdapterTest
 		EasyMock.expect(req.isMultiple()).andReturn(true);
 		EasyMock.replay(req);
 		FelixRequirementAdapter adapter = new FelixRequirementAdapter(req, EasyMock.createNiceMock(Resource.class));
-		assertEquals(adapter.getDirectives().get(Namespace.REQUIREMENT_CARDINALITY_DIRECTIVE),
Namespace.CARDINALITY_MULTIPLE);
+		assertEquals("Wrong value for directive " + Namespace.REQUIREMENT_CARDINALITY_DIRECTIVE,
Namespace.CARDINALITY_MULTIPLE, adapter.getDirectives().get(Namespace.REQUIREMENT_CARDINALITY_DIRECTIVE));
 	}
 	
 	@Test
@@ -26,7 +26,7 @@ public class FelixRequirementAdapterTest
 		EasyMock.expect(req.isMultiple()).andReturn(false);
 		EasyMock.replay(req);
 		FelixRequirementAdapter adapter = new FelixRequirementAdapter(req, EasyMock.createNiceMock(Resource.class));
-		assertEquals(adapter.getDirectives().get(Namespace.REQUIREMENT_CARDINALITY_DIRECTIVE),
Namespace.CARDINALITY_SINGLE);
+		assertEquals("Wrong value for directive " + Namespace.REQUIREMENT_CARDINALITY_DIRECTIVE,
Namespace.CARDINALITY_SINGLE, adapter.getDirectives().get(Namespace.REQUIREMENT_CARDINALITY_DIRECTIVE));
 	}
 	
 	@Test
@@ -36,7 +36,7 @@ public class FelixRequirementAdapterTest
 		EasyMock.expect(req.isOptional()).andReturn(false);
 		EasyMock.replay(req);
 		FelixRequirementAdapter adapter = new FelixRequirementAdapter(req, EasyMock.createNiceMock(Resource.class));
-		assertEquals(adapter.getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE), Namespace.RESOLUTION_MANDATORY);
+		assertEquals("Wrong value for directive " + Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE,
Namespace.RESOLUTION_MANDATORY, adapter.getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE));
 	}
 	
 	@Test
@@ -46,6 +46,6 @@ public class FelixRequirementAdapterTest
 		EasyMock.expect(req.isOptional()).andReturn(true);
 		EasyMock.replay(req);
 		FelixRequirementAdapter adapter = new FelixRequirementAdapter(req, EasyMock.createNiceMock(Resource.class));
-		assertEquals(adapter.getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE), Namespace.RESOLUTION_OPTIONAL);
+		assertEquals("Wrong value for directive " + Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE,
Namespace.RESOLUTION_OPTIONAL, adapter.getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE));
 	}
 }

Added: aries/trunk/subsystem/subsystem-obr/src/test/java/org/apache/aries/subsystem/obr/internal/OsgiRequirementAdapterTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-obr/src/test/java/org/apache/aries/subsystem/obr/internal/OsgiRequirementAdapterTest.java?rev=1451752&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-obr/src/test/java/org/apache/aries/subsystem/obr/internal/OsgiRequirementAdapterTest.java
(added)
+++ aries/trunk/subsystem/subsystem-obr/src/test/java/org/apache/aries/subsystem/obr/internal/OsgiRequirementAdapterTest.java
Fri Mar  1 22:46:21 2013
@@ -0,0 +1,67 @@
+package org.apache.aries.subsystem.obr.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.felix.bundlerepository.Capability;
+import org.easymock.EasyMock;
+import org.junit.Test;
+import org.osgi.framework.namespace.BundleNamespace;
+import org.osgi.framework.namespace.PackageNamespace;
+import org.osgi.namespace.service.ServiceNamespace;
+import org.osgi.resource.Namespace;
+import org.osgi.resource.Requirement;
+public class OsgiRequirementAdapterTest {
+	@Test
+	public void testGetNameBundle() {
+		Requirement req = EasyMock.createNiceMock(Requirement.class);
+		EasyMock.expect(req.getNamespace()).andReturn(BundleNamespace.BUNDLE_NAMESPACE);
+		EasyMock.replay(req);
+		OsgiRequirementAdapter adapter = new OsgiRequirementAdapter(req);
+		assertEquals("Wrong name", Capability.BUNDLE, adapter.getName());
+	}
+	
+	@Test
+	public void testGetNamePackage() {
+		Requirement req = EasyMock.createNiceMock(Requirement.class);
+		EasyMock.expect(req.getNamespace()).andReturn(PackageNamespace.PACKAGE_NAMESPACE);
+		EasyMock.replay(req);
+		OsgiRequirementAdapter adapter = new OsgiRequirementAdapter(req);
+		assertEquals("Wrong name", Capability.PACKAGE, adapter.getName());
+	}
+	
+	@Test
+	public void testGetNameService() {
+		Requirement req = EasyMock.createNiceMock(Requirement.class);
+		EasyMock.expect(req.getNamespace()).andReturn(ServiceNamespace.SERVICE_NAMESPACE);
+		EasyMock.replay(req);
+		OsgiRequirementAdapter adapter = new OsgiRequirementAdapter(req);
+		assertEquals("Wrong name", Capability.SERVICE, adapter.getName());
+	}
+	
+	@Test
+	public void testIsMultipleFalse() {
+		Requirement req = EasyMock.createNiceMock(Requirement.class);
+		Map<String, String> directives = new HashMap<String, String>();
+		directives.put(Namespace.REQUIREMENT_CARDINALITY_DIRECTIVE, Namespace.CARDINALITY_SINGLE);
+		EasyMock.expect(req.getDirectives()).andReturn(directives);
+		EasyMock.replay(req);
+		OsgiRequirementAdapter adapter = new OsgiRequirementAdapter(req);
+		assertFalse("Requirement was multiple", adapter.isMultiple());
+	}
+	
+	@Test
+	public void testIsMultipleTrue() {
+		Requirement req = EasyMock.createNiceMock(Requirement.class);
+		Map<String, String> directives = new HashMap<String, String>();
+		directives.put(Namespace.REQUIREMENT_CARDINALITY_DIRECTIVE, Namespace.CARDINALITY_MULTIPLE);
+		EasyMock.expect(req.getDirectives()).andReturn(directives);
+		EasyMock.replay(req);
+		OsgiRequirementAdapter adapter = new OsgiRequirementAdapter(req);
+		assertTrue("Requirement was not multiple", adapter.isMultiple());
+	}
+}



Mime
View raw message