aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rotty3...@apache.org
Subject svn commit: r1807424 [6/8] - in /aries/trunk/cdi: ./ cdi-extender/ cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/ cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/bean/ cdi-extender/src/main/java/org/apache/aries/...
Date Tue, 05 Sep 2017 22:01:15 GMT
Added: aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/reference/ReferenceModel_PropertiesTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/reference/ReferenceModel_PropertiesTest.java?rev=1807424&view=auto
==============================================================================
--- aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/reference/ReferenceModel_PropertiesTest.java (added)
+++ aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/reference/ReferenceModel_PropertiesTest.java Tue Sep  5 22:01:11 2017
@@ -0,0 +1,415 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.aries.cdi.container.internal.reference;
+
+import static org.junit.Assert.assertEquals;
+
+import java.lang.reflect.Type;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import org.apache.aries.cdi.container.internal.model.CollectionType;
+import org.apache.aries.cdi.container.internal.reference.ReferenceModel;
+import org.apache.aries.cdi.container.test.MockInjectionPoint;
+import org.junit.Test;
+import org.osgi.service.cdi.annotations.ReferenceCardinality;
+import org.osgi.util.converter.TypeReference;
+
+public class ReferenceModel_PropertiesTest {
+
+	@Test(expected = IllegalArgumentException.class)
+	public void withoutServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			Map<String, Object>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test
+	public void withServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			Map<String, Object>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(Map.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MANDATORY, referenceModel.getCardinality());
+		assertEquals(CollectionType.PROPERTIES, referenceModel.getCollectionType());
+	}
+
+	@Test
+	public void withServiceDefined_cardinality() throws Exception {
+		Type type = new TypeReference<
+			Map<String, Object>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).cardinality(ReferenceCardinality.OPTIONAL).build();
+
+		assertEquals(Map.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.OPTIONAL, referenceModel.getCardinality());
+		assertEquals(CollectionType.PROPERTIES, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void withServiceDefined_cardinality_multiple() throws Exception {
+		Type type = new TypeReference<
+			Map<String, Object>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).cardinality(ReferenceCardinality.MULTIPLE).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void withServiceDefined_cardinality_atleastone() throws Exception {
+		Type type = new TypeReference<
+			Map<String, Object>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).cardinality(ReferenceCardinality.AT_LEAST_ONE).build();
+	}
+
+	@Test
+	public void withServiceDefinedAsWildCard() throws Exception {
+		Type type = new TypeReference<
+			Map<String, ?>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(Map.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MANDATORY, referenceModel.getCardinality());
+		assertEquals(CollectionType.PROPERTIES, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void collectionWithoutServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			Collection<Map<String, Object>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void collectionWithoutServiceDefined_Wildcard() throws Exception {
+		Type type = new TypeReference<
+			Collection<Map<String, ?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test
+	public void collectionWithServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			Collection<Map<String, Object>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(Collection.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.PROPERTIES, referenceModel.getCollectionType());
+	}
+
+	@Test
+	public void collectionWithServiceDefined_cardinality() throws Exception {
+		Type type = new TypeReference<
+			Collection<Map<String, Object>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).cardinality(ReferenceCardinality.AT_LEAST_ONE).build();
+
+		assertEquals(Collection.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.AT_LEAST_ONE, referenceModel.getCardinality());
+		assertEquals(CollectionType.PROPERTIES, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void collectionWithServiceDefined_cardinality_mandatory() throws Exception {
+		Type type = new TypeReference<
+			Collection<Map<String, Object>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).cardinality(ReferenceCardinality.MANDATORY).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void collectionWithServiceDefined_cardinality_optional() throws Exception {
+		Type type = new TypeReference<
+			Collection<Map<String, Object>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).cardinality(ReferenceCardinality.OPTIONAL).build();
+	}
+
+	@Test
+	public void collectionWithServiceDefined_Wildcard() throws Exception {
+		Type type = new TypeReference<
+			Collection<Map<String, ?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(Collection.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.PROPERTIES, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void listWithoutServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			List<Map<String, Object>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void listWithoutServiceDefined_Wildcard() throws Exception {
+		Type type = new TypeReference<
+			List<Map<String, ?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test
+	public void listWithServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			List<Map<String, Object>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(List.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.PROPERTIES, referenceModel.getCollectionType());
+	}
+
+	@Test
+	public void listWithServiceDefined_cardinality() throws Exception {
+		Type type = new TypeReference<
+			List<Map<String, Object>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).cardinality(ReferenceCardinality.AT_LEAST_ONE).build();
+
+		assertEquals(List.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.AT_LEAST_ONE, referenceModel.getCardinality());
+		assertEquals(CollectionType.PROPERTIES, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void listWithServiceDefined_cardinality_mandatory() throws Exception {
+		Type type = new TypeReference<
+			List<Map<String, Object>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).cardinality(ReferenceCardinality.MANDATORY).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void listWithServiceDefined_cardinality_optional() throws Exception {
+		Type type = new TypeReference<
+			List<Map<String, Object>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).cardinality(ReferenceCardinality.OPTIONAL).build();
+	}
+
+	@Test
+	public void listWithServiceDefined_Wildcard() throws Exception {
+		Type type = new TypeReference<
+			List<Map<String, ?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(List.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.PROPERTIES, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void instanceWithoutServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			Instance<Map<String, Object>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void instanceWithoutServiceDefined_Wildcard() throws Exception {
+		Type type = new TypeReference<
+			Instance<Map<String, ?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test
+	public void instanceWithServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			Instance<Map<String, Object>>
+		>(){}.getType();
+		Type injectionPointType = new TypeReference<
+			Map<String, Object>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(Map.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(injectionPointType, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.PROPERTIES, referenceModel.getCollectionType());
+	}
+
+	@Test
+	public void instanceWithServiceDefined_cardinality() throws Exception {
+		Type type = new TypeReference<
+			Instance<Map<String, Object>>
+		>(){}.getType();
+		Type injectionPointType = new TypeReference<
+			Map<String, Object>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).cardinality(ReferenceCardinality.AT_LEAST_ONE).build();
+
+		assertEquals(Map.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(injectionPointType, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.AT_LEAST_ONE, referenceModel.getCardinality());
+		assertEquals(CollectionType.PROPERTIES, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void instanceWithServiceDefined_cardinality_mandatory() throws Exception {
+		Type type = new TypeReference<
+			Instance<Map<String, Object>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).cardinality(ReferenceCardinality.MANDATORY).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void instanceWithServiceDefined_cardinality_optional() throws Exception {
+		Type type = new TypeReference<
+			Instance<Map<String, Object>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).cardinality(ReferenceCardinality.OPTIONAL).build();
+	}
+
+	@Test
+	public void instanceWithServiceDefined_Wildcard() throws Exception {
+		Type type = new TypeReference<
+			Instance<Map<String, ?>>
+		>(){}.getType();
+		Type injectionPointType = new TypeReference<
+			Map<String, ?>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(Map.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(injectionPointType, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.PROPERTIES, referenceModel.getCollectionType());
+	}
+
+}
\ No newline at end of file

Added: aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/reference/ReferenceModel_ServiceObjectsTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/reference/ReferenceModel_ServiceObjectsTest.java?rev=1807424&view=auto
==============================================================================
--- aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/reference/ReferenceModel_ServiceObjectsTest.java (added)
+++ aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/reference/ReferenceModel_ServiceObjectsTest.java Tue Sep  5 22:01:11 2017
@@ -0,0 +1,394 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.aries.cdi.container.internal.reference;
+
+import static org.junit.Assert.assertEquals;
+
+import java.lang.reflect.Type;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import org.apache.aries.cdi.container.internal.model.CollectionType;
+import org.apache.aries.cdi.container.internal.reference.ReferenceModel;
+import org.apache.aries.cdi.container.test.MockInjectionPoint;
+import org.apache.aries.cdi.container.test.beans.Foo;
+import org.junit.Test;
+import org.osgi.framework.ServiceObjects;
+import org.osgi.service.cdi.annotations.ReferenceCardinality;
+import org.osgi.util.converter.TypeReference;
+
+public class ReferenceModel_ServiceObjectsTest {
+
+	@Test(expected = IllegalArgumentException.class)
+	public void withoutServiceDefined() throws Exception {
+		@SuppressWarnings("rawtypes")
+		Type type = new TypeReference<
+			ServiceObjects
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void withoutServiceDefined_wildcard() throws Exception {
+		Type type = new TypeReference<
+			ServiceObjects<?>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test
+	public void withServiceDefined() throws Exception {
+		@SuppressWarnings("rawtypes")
+		Type type = new TypeReference<
+			ServiceObjects
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(ServiceObjects.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MANDATORY, referenceModel.getCardinality());
+		assertEquals(CollectionType.SERVICEOBJECTS, referenceModel.getCollectionType());
+	}
+
+	@Test
+	public void withServiceDefined_wildcard() throws Exception {
+		Type type = new TypeReference<
+			ServiceObjects<?>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(ServiceObjects.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MANDATORY, referenceModel.getCardinality());
+		assertEquals(CollectionType.SERVICEOBJECTS, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void collectionWithoutServiceDefined() throws Exception {
+		@SuppressWarnings("rawtypes")
+		Type type = new TypeReference<
+			Collection<ServiceObjects>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void collectionWithoutServiceDefined_wildcard() throws Exception {
+		Type type = new TypeReference<
+			Collection<ServiceObjects<?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test
+	public void collectionWithServiceDefined() throws Exception {
+		@SuppressWarnings("rawtypes")
+		Type type = new TypeReference<
+			Collection<ServiceObjects>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(Collection.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.SERVICEOBJECTS, referenceModel.getCollectionType());
+	}
+
+	@Test
+	public void collectionWithServiceDefined_wildcard() throws Exception {
+		Type type = new TypeReference<
+			Collection<ServiceObjects<?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(Collection.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.SERVICEOBJECTS, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void listWithoutServiceDefined() throws Exception {
+		@SuppressWarnings("rawtypes")
+		Type type = new TypeReference<
+			List<ServiceObjects>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void listWithoutServiceDefined_wildcard() throws Exception {
+		Type type = new TypeReference<
+			List<ServiceObjects<?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test
+	public void listWithServiceDefined() throws Exception {
+		@SuppressWarnings("rawtypes")
+		Type type = new TypeReference<
+			List<ServiceObjects>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(List.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.SERVICEOBJECTS, referenceModel.getCollectionType());
+	}
+
+	@Test
+	public void listWithServiceDefined_wildcard() throws Exception {
+		Type type = new TypeReference<
+			List<ServiceObjects<?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(List.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.SERVICEOBJECTS, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void instanceWithoutServiceDefined() throws Exception {
+		@SuppressWarnings("rawtypes")
+		Type type = new TypeReference<
+			Instance<ServiceObjects>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void instanceWithoutServiceDefined_wildcard() throws Exception {
+		Type type = new TypeReference<
+			Instance<ServiceObjects<?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test
+	public void instanceWithServiceDefined() throws Exception {
+		@SuppressWarnings("rawtypes")
+		Type type = new TypeReference<
+			Instance<ServiceObjects>
+		>(){}.getType();
+		@SuppressWarnings("rawtypes")
+		Type injectionPointType = new TypeReference<
+			ServiceObjects
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(ServiceObjects.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(injectionPointType, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.SERVICEOBJECTS, referenceModel.getCollectionType());
+	}
+
+	@Test
+	public void instanceWithServiceDefined_wildcard() throws Exception {
+		Type type = new TypeReference<
+			Instance<ServiceObjects<?>>
+		>(){}.getType();
+		Type injectionPointType = new TypeReference<
+			ServiceObjects<?>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(ServiceObjects.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(injectionPointType, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.SERVICEOBJECTS, referenceModel.getCollectionType());
+	}
+
+	///////////////////////////////////////////////////////////////////////////////
+
+	@Test
+	public void typed_withoutServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			ServiceObjects<Foo>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+
+		assertEquals(ServiceObjects.class, referenceModel.getBeanClass());
+		assertEquals(Foo.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MANDATORY, referenceModel.getCardinality());
+		assertEquals(CollectionType.SERVICEOBJECTS, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void typed_withServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			ServiceObjects<Foo>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+	}
+
+	@Test
+	public void typed_collectionWithoutServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			Collection<ServiceObjects<Foo>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+
+		assertEquals(Collection.class, referenceModel.getBeanClass());
+		assertEquals(Foo.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.SERVICEOBJECTS, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void typed_collectionWithServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			Collection<ServiceObjects<Foo>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+	}
+
+	@Test
+	public void typed_listWithoutServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			List<ServiceObjects<Foo>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+
+		assertEquals(List.class, referenceModel.getBeanClass());
+		assertEquals(Foo.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.SERVICEOBJECTS, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void typed_listWithServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			List<ServiceObjects<Foo>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+	}
+
+	@Test
+	public void typed_instanceWithoutServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			Instance<ServiceObjects<Foo>>
+		>(){}.getType();
+		Type injectionPointType = new TypeReference<
+			ServiceObjects<Foo>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+
+		assertEquals(ServiceObjects.class, referenceModel.getBeanClass());
+		assertEquals(Foo.class, referenceModel.getServiceClass());
+		assertEquals(injectionPointType, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.SERVICEOBJECTS, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void typed_instanceWithServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			Instance<ServiceObjects<Foo>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+	}
+
+}
\ No newline at end of file

Added: aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/reference/ReferenceModel_ServiceReferenceTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/reference/ReferenceModel_ServiceReferenceTest.java?rev=1807424&view=auto
==============================================================================
--- aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/reference/ReferenceModel_ServiceReferenceTest.java (added)
+++ aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/reference/ReferenceModel_ServiceReferenceTest.java Tue Sep  5 22:01:11 2017
@@ -0,0 +1,433 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.aries.cdi.container.internal.reference;
+
+import static org.junit.Assert.assertEquals;
+
+import java.lang.reflect.Type;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import org.apache.aries.cdi.container.internal.model.CollectionType;
+import org.apache.aries.cdi.container.internal.reference.ReferenceModel;
+import org.apache.aries.cdi.container.test.MockInjectionPoint;
+import org.apache.aries.cdi.container.test.beans.Foo;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cdi.annotations.ReferenceCardinality;
+import org.osgi.util.converter.TypeReference;
+
+public class ReferenceModel_ServiceReferenceTest {
+
+	@Test(expected = IllegalArgumentException.class)
+	public void withoutServiceDefined() throws Exception {
+		@SuppressWarnings("rawtypes")
+		Type type = new TypeReference<
+			ServiceReference
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void withoutServiceDefined_wildcard() throws Exception {
+		Type type = new TypeReference<
+			ServiceReference<?>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void withoutServiceDefined_wildcardExt() throws Exception {
+		Type type = new TypeReference<
+			ServiceReference<? extends Callable<?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test
+	public void withServiceDefined() throws Exception {
+		@SuppressWarnings("rawtypes")
+		Type type = new TypeReference<
+			ServiceReference
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(ServiceReference.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MANDATORY, referenceModel.getCardinality());
+		assertEquals(CollectionType.REFERENCE, referenceModel.getCollectionType());
+	}
+
+	@Test
+	public void withServiceDefined_wildcard() throws Exception {
+		Type type = new TypeReference<
+			ServiceReference<?>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(ServiceReference.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MANDATORY, referenceModel.getCardinality());
+		assertEquals(CollectionType.REFERENCE, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void collectionWithoutServiceDefined() throws Exception {
+		@SuppressWarnings("rawtypes")
+		Type type = new TypeReference<
+			Collection<ServiceReference>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void collectionWithoutServiceDefined_wildcard() throws Exception {
+		Type type = new TypeReference<
+			Collection<ServiceReference<?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test
+	public void collectionWithServiceDefined() throws Exception {
+		@SuppressWarnings("rawtypes")
+		Type type = new TypeReference<
+			Collection<ServiceReference>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(Collection.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.REFERENCE, referenceModel.getCollectionType());
+	}
+
+	@Test
+	public void collectionWithServiceDefined_wildcard() throws Exception {
+		Type type = new TypeReference<
+			Collection<ServiceReference<?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(Collection.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.REFERENCE, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void listWithoutServiceDefined() throws Exception {
+		@SuppressWarnings("rawtypes")
+		Type type = new TypeReference<
+			List<ServiceReference>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void listWithoutServiceDefined_wildcard() throws Exception {
+		Type type = new TypeReference<
+			List<ServiceReference<?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test
+	public void listWithServiceDefined() throws Exception {
+		@SuppressWarnings("rawtypes")
+		Type type = new TypeReference<
+			List<ServiceReference>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(List.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.REFERENCE, referenceModel.getCollectionType());
+	}
+
+	@Test
+	public void listWithServiceDefined_wildcard() throws Exception {
+		Type type = new TypeReference<
+			List<ServiceReference<?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(List.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.REFERENCE, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void instanceWithoutServiceDefined() throws Exception {
+		@SuppressWarnings("rawtypes")
+		Type type = new TypeReference<
+			Instance<ServiceReference>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void instanceWithoutServiceDefined_wildcard() throws Exception {
+		Type type = new TypeReference<
+			Instance<ServiceReference<?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test
+	public void instanceWithServiceDefined() throws Exception {
+		@SuppressWarnings("rawtypes")
+		Type type = new TypeReference<
+			Instance<ServiceReference>
+		>(){}.getType();
+		@SuppressWarnings("rawtypes")
+		Type injectionPointType = new TypeReference<
+			ServiceReference
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(ServiceReference.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(injectionPointType, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.REFERENCE, referenceModel.getCollectionType());
+	}
+
+	@Test
+	public void instanceWithServiceDefined_wildcard() throws Exception {
+		Type type = new TypeReference<
+			Instance<ServiceReference<?>>
+		>(){}.getType();
+		Type injectionPointType = new TypeReference<
+			ServiceReference<?>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(ServiceReference.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(injectionPointType, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.REFERENCE, referenceModel.getCollectionType());
+	}
+
+	///////////////////////////////////////////////////////////////////////////////
+
+	@Test
+	public void typed_withoutServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			ServiceReference<Foo>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+
+		assertEquals(ServiceReference.class, referenceModel.getBeanClass());
+		assertEquals(Foo.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MANDATORY, referenceModel.getCardinality());
+		assertEquals(CollectionType.REFERENCE, referenceModel.getCollectionType());
+	}
+
+	@Test
+	public void typed_withoutServiceDefined_wildcardExt() throws Exception {
+		Type type = new TypeReference<
+			ServiceReference<? extends Foo>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+
+		assertEquals(ServiceReference.class, referenceModel.getBeanClass());
+		assertEquals(Foo.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MANDATORY, referenceModel.getCardinality());
+		assertEquals(CollectionType.REFERENCE, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void typed_withServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			ServiceReference<Foo>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+	}
+
+	@Test
+	public void typed_collectionWithoutServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			Collection<ServiceReference<Foo>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+
+		assertEquals(Collection.class, referenceModel.getBeanClass());
+		assertEquals(Foo.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.REFERENCE, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void typed_collectionWithServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			Collection<ServiceReference<Foo>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+	}
+
+	@Test
+	public void typed_listWithoutServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			List<ServiceReference<Foo>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+
+		assertEquals(List.class, referenceModel.getBeanClass());
+		assertEquals(Foo.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.REFERENCE, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void typed_listWithServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			List<ServiceReference<Foo>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+	}
+
+	@Test
+	public void typed_instanceWithoutServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			Instance<ServiceReference<Foo>>
+		>(){}.getType();
+		Type injectionPointType = new TypeReference<
+			ServiceReference<Foo>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+
+		assertEquals(ServiceReference.class, referenceModel.getBeanClass());
+		assertEquals(Foo.class, referenceModel.getServiceClass());
+		assertEquals(injectionPointType, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.REFERENCE, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void typed_instanceWithServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			Instance<ServiceReference<Foo>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void typed_instanceWithServiceDefined_wildcardExt() throws Exception {
+		Type type = new TypeReference<
+			Instance<ServiceReference<? extends Foo>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+	}
+
+}
\ No newline at end of file

Added: aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/reference/ReferenceModel_ServiceTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/reference/ReferenceModel_ServiceTest.java?rev=1807424&view=auto
==============================================================================
--- aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/reference/ReferenceModel_ServiceTest.java (added)
+++ aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/reference/ReferenceModel_ServiceTest.java Tue Sep  5 22:01:11 2017
@@ -0,0 +1,378 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.aries.cdi.container.internal.reference;
+
+import static org.junit.Assert.assertEquals;
+
+import java.lang.reflect.Type;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import org.apache.aries.cdi.container.internal.model.CollectionType;
+import org.apache.aries.cdi.container.internal.reference.ReferenceModel;
+import org.apache.aries.cdi.container.test.MockInjectionPoint;
+import org.apache.aries.cdi.container.test.beans.Foo;
+import org.junit.Test;
+import org.osgi.service.cdi.annotations.ReferenceCardinality;
+import org.osgi.util.converter.TypeReference;
+
+public class ReferenceModel_ServiceTest {
+
+	@Test
+	public void single() throws Exception {
+		Type type = new TypeReference<
+			Callable<?>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+
+		assertEquals(Callable.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MANDATORY, referenceModel.getCardinality());
+		assertEquals(CollectionType.SERVICE, referenceModel.getCollectionType());
+	}
+
+	@Test
+	public void single_cardinality() throws Exception {
+		Type type = new TypeReference<
+			Callable<?>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).cardinality(ReferenceCardinality.OPTIONAL).build();
+
+		assertEquals(Callable.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.OPTIONAL, referenceModel.getCardinality());
+		assertEquals(CollectionType.SERVICE, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void single_cardinality_multiple() throws Exception {
+		Type type = new TypeReference<
+			Callable<?>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).cardinality(ReferenceCardinality.MULTIPLE).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void single_cardinality_atleastone() throws Exception {
+		Type type = new TypeReference<
+			Callable<?>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).cardinality(ReferenceCardinality.AT_LEAST_ONE).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void single_incompatibleSpecified() throws Exception {
+		Type type = new TypeReference<
+			Callable<String>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Foo.class).build();
+	}
+
+	@Test
+	public void collection() throws Exception {
+		Type type = new TypeReference<
+			Collection<Callable<String>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+
+		assertEquals(Collection.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.SERVICE, referenceModel.getCollectionType());
+	}
+
+	@Test
+	public void collection_cardinality() throws Exception {
+		Type type = new TypeReference<
+			Collection<Callable<String>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).cardinality(ReferenceCardinality.AT_LEAST_ONE).build();
+
+		assertEquals(Collection.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.AT_LEAST_ONE, referenceModel.getCardinality());
+		assertEquals(CollectionType.SERVICE, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void collection_cardinality_mandatory() throws Exception {
+		Type type = new TypeReference<
+			Collection<Callable<String>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).cardinality(ReferenceCardinality.MANDATORY).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void collection_cardinality_optional() throws Exception {
+		Type type = new TypeReference<
+			Collection<Callable<String>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).cardinality(ReferenceCardinality.OPTIONAL).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void collection_incompatibleSpecified() throws Exception {
+		Type type = new TypeReference<
+			Collection<Callable<String>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Foo.class).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void collection_Wildcard() throws Exception {
+		Type type = new TypeReference<
+			Collection<?>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test
+	public void collection_specified_Wilcard() throws Exception {
+		Type type = new TypeReference<
+			Collection<?>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(Collection.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.SERVICE, referenceModel.getCollectionType());
+	}
+
+	@Test
+	public void list() throws Exception {
+		Type type = new TypeReference<
+			List<Callable<String>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+
+		assertEquals(List.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.SERVICE, referenceModel.getCollectionType());
+	}
+
+	@Test
+	public void list_cardinality() throws Exception {
+		Type type = new TypeReference<
+			List<Callable<String>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).cardinality(ReferenceCardinality.AT_LEAST_ONE).build();
+
+		assertEquals(List.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.AT_LEAST_ONE, referenceModel.getCardinality());
+		assertEquals(CollectionType.SERVICE, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void list_cardinality_mandatory() throws Exception {
+		Type type = new TypeReference<
+			List<Callable<String>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).cardinality(ReferenceCardinality.MANDATORY).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void list_cardinality_optional() throws Exception {
+		Type type = new TypeReference<
+			List<Callable<String>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).cardinality(ReferenceCardinality.OPTIONAL).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void list_incompatibleSpecified() throws Exception {
+		Type type = new TypeReference<
+			List<Callable<String>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Foo.class).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void list_Wildcard() throws Exception {
+		Type type = new TypeReference<
+			List<?>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test
+	public void list_specified_wildcard() throws Exception {
+		Type type = new TypeReference<
+			List<?>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(List.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.SERVICE, referenceModel.getCollectionType());
+	}
+
+	@Test
+	public void instance() throws Exception {
+		Type type = new TypeReference<
+			Instance<Callable<String>>
+		>(){}.getType();
+		Type injectionPointType = new TypeReference<
+			Callable<String>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+
+		assertEquals(Callable.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(injectionPointType, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.SERVICE, referenceModel.getCollectionType());
+	}
+
+	@Test
+	public void instance_cardinality() throws Exception {
+		Type type = new TypeReference<
+			Instance<Callable<String>>
+		>(){}.getType();
+		Type injectionPointType = new TypeReference<
+			Callable<String>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).cardinality(ReferenceCardinality.AT_LEAST_ONE).build();
+
+		assertEquals(Callable.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(injectionPointType, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.AT_LEAST_ONE, referenceModel.getCardinality());
+		assertEquals(CollectionType.SERVICE, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void instance_cardinality_mandatory() throws Exception {
+		Type type = new TypeReference<
+			Instance<Callable<String>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).cardinality(ReferenceCardinality.MANDATORY).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void instance_cardinality_optional() throws Exception {
+		Type type = new TypeReference<
+			Instance<Callable<String>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).cardinality(ReferenceCardinality.OPTIONAL).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void instance_incompatibleSpecified() throws Exception {
+		Type type = new TypeReference<
+			Instance<Callable<String>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Foo.class).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void instance_Wildcard() throws Exception {
+		Type type = new TypeReference<
+			Instance<?>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+}
\ No newline at end of file

Added: aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/reference/ReferenceModel_TupleTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/reference/ReferenceModel_TupleTest.java?rev=1807424&view=auto
==============================================================================
--- aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/reference/ReferenceModel_TupleTest.java (added)
+++ aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/reference/ReferenceModel_TupleTest.java Tue Sep  5 22:01:11 2017
@@ -0,0 +1,358 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.aries.cdi.container.internal.reference;
+
+import static org.junit.Assert.assertEquals;
+
+import java.lang.reflect.Type;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import org.apache.aries.cdi.container.internal.model.CollectionType;
+import org.apache.aries.cdi.container.internal.reference.ReferenceModel;
+import org.apache.aries.cdi.container.test.MockInjectionPoint;
+import org.apache.aries.cdi.container.test.beans.Foo;
+import org.junit.Test;
+import org.osgi.service.cdi.annotations.ReferenceCardinality;
+import org.osgi.util.converter.TypeReference;
+
+public class ReferenceModel_TupleTest {
+
+	@Test
+	public void withServiceType() throws Exception {
+		Type type = new TypeReference<
+			Map.Entry<Map<String, ?>, Callable<?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+
+		assertEquals(Map.Entry.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MANDATORY, referenceModel.getCardinality());
+		assertEquals(CollectionType.TUPLE, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void withServiceType_wrongKeyType_A() throws Exception {
+		Type type = new TypeReference<
+			Map.Entry<?, Callable<?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void withServiceType_wrongKeyType_B() throws Exception {
+		Type type = new TypeReference<
+			Map.Entry<Collection<?>, Callable<?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void withServiceType_wrongKeyType_C() throws Exception {
+		@SuppressWarnings("rawtypes")
+		Type type = new TypeReference<
+			Map.Entry<Map, Callable<?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void withServiceType_wrongKeyType_D() throws Exception {
+		Type type = new TypeReference<
+			Map.Entry<Map<?, Foo>, Callable<?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void withServiceType_wrongKeyType_E() throws Exception {
+		Type type = new TypeReference<
+			Map.Entry<Map<String, Foo>, Callable<?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void withServiceType_wrongKeyType_F() throws Exception {
+		Type type = new TypeReference<
+			Map.Entry<Map<String, ? extends Foo>, Callable<?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void withoutServiceDefined() throws Exception {
+		@SuppressWarnings("rawtypes")
+		Type type = new TypeReference<
+			Map.Entry
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test
+	public void withServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			Map.Entry<Map<String, ?>, ?>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(Map.Entry.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MANDATORY, referenceModel.getCardinality());
+		assertEquals(CollectionType.TUPLE, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void collectionWithoutServiceDefined() throws Exception {
+		@SuppressWarnings("rawtypes")
+		Type type = new TypeReference<
+			Collection<Map.Entry>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test
+	public void collectionWithServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			Collection<Map.Entry<Map<String, ?>, ?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(Collection.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.TUPLE, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void listWithoutServiceDefined() throws Exception {
+		@SuppressWarnings("rawtypes")
+		Type type = new TypeReference<
+			List<Map.Entry>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test
+	public void listWithServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			List<Map.Entry<Map<String, ?>, ?>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(List.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.TUPLE, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void instanceWithoutServiceDefined() throws Exception {
+		@SuppressWarnings("rawtypes")
+		Type type = new TypeReference<
+			Instance<Map.Entry>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+	}
+
+	@Test
+	public void instanceWithServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			Instance<Map.Entry<Map<String, ?>, ?>>
+		>(){}.getType();
+		Type injectionPointType = new TypeReference<
+			Map.Entry<Map<String, ?>, ?>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+
+		assertEquals(Map.Entry.class, referenceModel.getBeanClass());
+		assertEquals(Callable.class, referenceModel.getServiceClass());
+		assertEquals(injectionPointType, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.TUPLE, referenceModel.getCollectionType());
+	}
+
+	///////////////////////////////////////////////////////////////////////////////
+
+	@Test
+	public void typed_withoutServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			Map.Entry<Map<String, Object>, Foo>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+
+		assertEquals(Map.Entry.class, referenceModel.getBeanClass());
+		assertEquals(Foo.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MANDATORY, referenceModel.getCardinality());
+		assertEquals(CollectionType.TUPLE, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void typed_withServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			Map.Entry<Map<String, Object>, Foo>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+	}
+
+	@Test
+	public void typed_collectionWithoutServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			Collection<Map.Entry<Map<String, Object>, Foo>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+
+		assertEquals(Collection.class, referenceModel.getBeanClass());
+		assertEquals(Foo.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.TUPLE, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void typed_collectionWithServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			Collection<Map.Entry<Map<String, Object>, Foo>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+	}
+
+	@Test
+	public void typed_listWithoutServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			List<Map.Entry<Map<String, Object>, Foo>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+
+		assertEquals(List.class, referenceModel.getBeanClass());
+		assertEquals(Foo.class, referenceModel.getServiceClass());
+		assertEquals(type, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.TUPLE, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void typed_listWithServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			List<Map.Entry<Map<String, Object>, Foo>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+	}
+
+	@Test
+	public void typed_instanceWithoutServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			Instance<Map.Entry<Map<String, Object>, Foo>>
+		>(){}.getType();
+		Type injectionPointType = new TypeReference<
+			Map.Entry<Map<String, Object>, Foo>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		ReferenceModel referenceModel = new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).build();
+
+		assertEquals(Map.Entry.class, referenceModel.getBeanClass());
+		assertEquals(Foo.class, referenceModel.getServiceClass());
+		assertEquals(injectionPointType, referenceModel.getInjectionPointType());
+		assertEquals(ReferenceCardinality.MULTIPLE, referenceModel.getCardinality());
+		assertEquals(CollectionType.TUPLE, referenceModel.getCollectionType());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void typed_instanceWithServiceDefined() throws Exception {
+		Type type = new TypeReference<
+			Instance<Map.Entry<Map<String, Object>, Foo>>
+		>(){}.getType();
+
+		InjectionPoint injectionPoint = new MockInjectionPoint(type);
+
+		new ReferenceModel.Builder(injectionPoint.getQualifiers()).annotated(injectionPoint.getAnnotated()).service(Callable.class).build();
+	}
+
+}
\ No newline at end of file

Copied: aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/test/MockBeanDeploymentArchive.java (from r1806482, aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/container/BundleDeploymentArchive.java)
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/test/MockBeanDeploymentArchive.java?p2=aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/test/MockBeanDeploymentArchive.java&p1=aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/container/BundleDeploymentArchive.java&r1=1806482&r2=1807424&rev=1807424&view=diff
==============================================================================
--- aries/trunk/cdi/cdi-extender/src/main/java/org/apache/aries/cdi/container/internal/container/BundleDeploymentArchive.java (original)
+++ aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/test/MockBeanDeploymentArchive.java Tue Sep  5 22:01:11 2017
@@ -12,76 +12,58 @@
  * limitations under the License.
  */
 
-package org.apache.aries.cdi.container.internal.container;
+package org.apache.aries.cdi.container.test;
 
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.List;
 
-import org.apache.aries.cdi.container.internal.loader.BundleResourcesLoader;
 import org.jboss.weld.bootstrap.api.ServiceRegistry;
 import org.jboss.weld.bootstrap.api.helpers.SimpleServiceRegistry;
 import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
 import org.jboss.weld.bootstrap.spi.BeansXml;
 import org.jboss.weld.ejb.spi.EjbDescriptor;
-import org.jboss.weld.resources.spi.ResourceLoader;
-import org.jboss.weld.serialization.spi.ProxyServices;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.wiring.BundleWiring;
-
-public class BundleDeploymentArchive implements BeanDeploymentArchive {
-
-	public BundleDeploymentArchive(
-		BundleWiring bundleWiring, String id, Collection<String> beanClassNames, BeansXml beansXml,
-		Bundle extenderBundle) {
 
-		_id = id;
-		_beanClassNames = beanClassNames;
-		_beanDeploymentArchives = Collections.emptyList();
-		_beansXml = beansXml;
-		_ejbs = Collections.emptyList();
-		_services = new SimpleServiceRegistry();
-
-		BundleResourcesLoader loader = new BundleResourcesLoader(bundleWiring, extenderBundle);
+public class MockBeanDeploymentArchive implements BeanDeploymentArchive {
 
-		_services.add(ResourceLoader.class, loader);
-		_services.add(ProxyServices.class, loader);
+	public MockBeanDeploymentArchive(String id, String... beanClasses) {
+		_id = id;
+		_beanClasses = Arrays.asList(beanClasses);
 	}
 
 	@Override
-	public Collection<String> getBeanClasses() {
-		return _beanClassNames;
+	public Collection<BeanDeploymentArchive> getBeanDeploymentArchives() {
+		return Collections.emptyList();
 	}
 
 	@Override
-	public Collection<BeanDeploymentArchive> getBeanDeploymentArchives() {
-		return _beanDeploymentArchives;
+	public Collection<String> getBeanClasses() {
+		return _beanClasses;
 	}
 
 	@Override
 	public BeansXml getBeansXml() {
-		return _beansXml;
+		return BeansXml.EMPTY_BEANS_XML;
 	}
 
 	@Override
 	public Collection<EjbDescriptor<?>> getEjbs() {
-		return _ejbs;
+		return Collections.emptyList();
 	}
 
 	@Override
-	public String getId() {
-		return _id;
+	public ServiceRegistry getServices() {
+		return _services;
 	}
 
 	@Override
-	public ServiceRegistry getServices() {
-		return _services;
+	public String getId() {
+		return _id;
 	}
 
-	private final Collection<String> _beanClassNames;
-	private final Collection<BeanDeploymentArchive> _beanDeploymentArchives;
-	private final BeansXml _beansXml;
-	private final Collection<EjbDescriptor<?>> _ejbs;
+	private final List<String> _beanClasses;
 	private final String _id;
-	private final ServiceRegistry _services;
+	private final ServiceRegistry _services = new SimpleServiceRegistry();
 
 }
\ No newline at end of file



Mime
View raw message