aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rotty3...@apache.org
Subject svn commit: r1807424 [5/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/configuration/ConfigurationCallbackTest_Require.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/configuration/ConfigurationCallbackTest_Require.java?rev=1807424&view=auto
==============================================================================
--- aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/configuration/ConfigurationCallbackTest_Require.java (added)
+++ aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/configuration/ConfigurationCallbackTest_Require.java Tue Sep  5 22:01:11 2017
@@ -0,0 +1,362 @@
+/**
+ * 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.configuration;
+
+import static org.osgi.framework.Constants.SERVICE_PID;
+import static org.apache.aries.cdi.container.test.TestUtil.*;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.osgi.service.cdi.annotations.ConfigurationPolicy;
+
+public class ConfigurationCallbackTest_Require {
+
+	@Test(expected = IllegalArgumentException.class)
+	public void test_emptyAdd() throws Exception {
+		ConfigurationCallback callback = getCallback(POLICY);
+
+		Assert.assertFalse(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertTrue(callback.properties().isEmpty());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+
+		callback.added(properties);
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void test_emptyUpdate() throws Exception {
+		ConfigurationCallback callback = getCallback(POLICY);
+
+		Assert.assertFalse(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertTrue(callback.properties().isEmpty());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+
+		callback.updated(properties);
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void test_nullAdd() throws Exception {
+		ConfigurationCallback callback = getCallback(POLICY);
+
+		Assert.assertFalse(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertTrue(callback.properties().isEmpty());
+
+		callback.added(null);
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void test_nullUpdate() throws Exception {
+		ConfigurationCallback callback = getCallback(POLICY);
+
+		Assert.assertFalse(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertTrue(callback.properties().isEmpty());
+
+		callback.updated(null);
+	}
+
+	@Test(expected = IllegalStateException.class)
+	public void test_addAfterAdd() throws Exception {
+		ConfigurationCallback callback = getCallback(POLICY);
+
+		Assert.assertFalse(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertTrue(callback.properties().isEmpty());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put(SERVICE_PID, "foo");
+
+		callback.added(properties);
+
+		Assert.assertTrue(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertFalse(callback.properties().isEmpty());
+
+		callback.added(properties);
+	}
+
+	@Test
+	public void test_addAfterRemove() throws Exception {
+		ConfigurationCallback callback = getCallback(POLICY);
+
+		Assert.assertFalse(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertTrue(callback.properties().isEmpty());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put(SERVICE_PID, "foo");
+
+		callback.added(properties);
+
+		Assert.assertTrue(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertFalse(callback.properties().isEmpty());
+
+		callback.removed();
+
+		Assert.assertFalse(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertTrue(callback.properties().isEmpty());
+
+		callback.added(properties);
+
+		Assert.assertTrue(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertFalse(callback.properties().isEmpty());
+	}
+
+	@Test(expected = IllegalStateException.class)
+	public void test_addAfterUpdate() throws Exception {
+		ConfigurationCallback callback = getCallback(POLICY);
+
+		Assert.assertFalse(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertTrue(callback.properties().isEmpty());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put(SERVICE_PID, "foo");
+
+		callback.added(properties);
+
+		Assert.assertTrue(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertFalse(callback.properties().isEmpty());
+
+		properties = new Hashtable<>();
+		properties.put(SERVICE_PID, "foo");
+
+		callback.updated(properties);
+
+		Assert.assertTrue(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertFalse(callback.properties().isEmpty());
+
+		callback.added(properties);
+	}
+
+	@Test
+	public void test_removeAfterAdd() throws Exception {
+		ConfigurationCallback callback = getCallback(POLICY);
+
+		Assert.assertFalse(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertTrue(callback.properties().isEmpty());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put(SERVICE_PID, "foo");
+
+		callback.added(properties);
+
+		Assert.assertTrue(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertFalse(callback.properties().isEmpty());
+
+		callback.removed();
+
+		Assert.assertFalse(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertTrue(callback.properties().isEmpty());
+	}
+
+	@Test(expected = IllegalStateException.class)
+	public void test_removeAfterRemove() throws Exception {
+		ConfigurationCallback callback = getCallback(POLICY);
+
+		Assert.assertFalse(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertTrue(callback.properties().isEmpty());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put(SERVICE_PID, "foo");
+
+		callback.added(properties);
+
+		Assert.assertTrue(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertFalse(callback.properties().isEmpty());
+
+		callback.removed();
+
+		Assert.assertFalse(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertTrue(callback.properties().isEmpty());
+
+		callback.removed();
+	}
+
+	@Test
+	public void test_removeAfterUpdate() throws Exception {
+		ConfigurationCallback callback = getCallback(POLICY);
+
+		Assert.assertFalse(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertTrue(callback.properties().isEmpty());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put(SERVICE_PID, "foo");
+
+		callback.added(properties);
+
+		Assert.assertTrue(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertFalse(callback.properties().isEmpty());
+		Assert.assertEquals("foo", callback.properties().get(SERVICE_PID));
+
+		properties = new Hashtable<>();
+		properties.put(SERVICE_PID, "fum");
+
+		callback.updated(properties);
+
+		Assert.assertTrue(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertFalse(callback.properties().isEmpty());
+		Assert.assertEquals("fum", callback.properties().get(SERVICE_PID));
+
+		callback.removed();
+
+		Assert.assertFalse(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertTrue(callback.properties().isEmpty());
+	}
+
+	@Test(expected = IllegalStateException.class)
+	public void test_removeBeforeAdd() throws Exception {
+		ConfigurationCallback callback = getCallback(POLICY);
+
+		Assert.assertFalse(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertTrue(callback.properties().isEmpty());
+
+		callback.removed();
+	}
+
+	@Test
+	public void test_updateAfterAdd() throws Exception {
+		ConfigurationCallback callback = getCallback(POLICY);
+
+		Assert.assertFalse(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertTrue(callback.properties().isEmpty());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put(SERVICE_PID, "foo");
+
+		callback.added(properties);
+
+		Assert.assertTrue(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertFalse(callback.properties().isEmpty());
+		Assert.assertEquals("foo", callback.properties().get(SERVICE_PID));
+
+		properties = new Hashtable<>();
+		properties.put(SERVICE_PID, "fum");
+
+		callback.updated(properties);
+
+		Assert.assertTrue(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertFalse(callback.properties().isEmpty());
+		Assert.assertEquals("fum", callback.properties().get(SERVICE_PID));
+	}
+
+	@Test(expected = IllegalStateException.class)
+	public void test_updateAfterRemove() throws Exception {
+		ConfigurationCallback callback = getCallback(POLICY);
+
+		Assert.assertFalse(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertTrue(callback.properties().isEmpty());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put(SERVICE_PID, "foo");
+
+		callback.added(properties);
+
+		Assert.assertTrue(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertFalse(callback.properties().isEmpty());
+
+		callback.removed();
+
+		Assert.assertFalse(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertTrue(callback.properties().isEmpty());
+
+		callback.updated(properties);
+	}
+
+	@Test
+	public void test_updateAfterUpdate() throws Exception {
+		ConfigurationCallback callback = getCallback(POLICY);
+
+		Assert.assertFalse(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertTrue(callback.properties().isEmpty());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put(SERVICE_PID, "foo");
+
+		callback.added(properties);
+
+		Assert.assertTrue(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertFalse(callback.properties().isEmpty());
+		Assert.assertEquals("foo", callback.properties().get(SERVICE_PID));
+
+		properties = new Hashtable<>();
+		properties.put(SERVICE_PID, "fum");
+
+		callback.updated(properties);
+
+		Assert.assertTrue(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertFalse(callback.properties().isEmpty());
+		Assert.assertEquals("fum", callback.properties().get(SERVICE_PID));
+
+		properties = new Hashtable<>();
+		properties.put(SERVICE_PID, "fee");
+
+		callback.updated(properties);
+
+		Assert.assertTrue(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertFalse(callback.properties().isEmpty());
+		Assert.assertEquals("fee", callback.properties().get(SERVICE_PID));
+	}
+
+	@Test(expected = IllegalStateException.class)
+	public void test_updateBeforeAdd() throws Exception {
+		ConfigurationCallback callback = getCallback(POLICY);
+
+		Assert.assertFalse(callback.resolved());
+		Assert.assertNotNull(callback.properties());
+		Assert.assertTrue(callback.properties().isEmpty());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put(SERVICE_PID, "foo");
+
+		callback.updated(properties);
+	}
+
+	private ConfigurationPolicy POLICY = ConfigurationPolicy.REQUIRE;
+
+}

Added: aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/configuration/ConfigurationManagedServiceTest_Ignore.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/configuration/ConfigurationManagedServiceTest_Ignore.java?rev=1807424&view=auto
==============================================================================
--- aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/configuration/ConfigurationManagedServiceTest_Ignore.java (added)
+++ aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/configuration/ConfigurationManagedServiceTest_Ignore.java Tue Sep  5 22:01:11 2017
@@ -0,0 +1,269 @@
+/**
+ * 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.configuration;
+
+import static org.apache.aries.cdi.container.test.TestUtil.*;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.osgi.service.cdi.annotations.ConfigurationPolicy;
+import org.osgi.service.cm.ManagedService;
+
+public class ConfigurationManagedServiceTest_Ignore {
+
+	@Test
+	public void test_emptyAdd() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(new Hashtable<>());
+	}
+
+	@Test
+	public void test_nullAdd() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(null);
+	}
+
+	@Test
+	public void test_add() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertTrue(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertTrue(configurationCallback.resolved());
+	}
+
+	@Test
+	public void test_addAfterRemove() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertTrue(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.STARTED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(null);
+
+		Assert.assertEquals(ConfigurationCallback.State.STARTED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.STARTED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+	}
+
+	@Test
+	public void test_addAfterUpdate() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertTrue(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.STARTED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.STARTED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.STARTED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+	}
+
+	@Test
+	public void test_removeAfterAdd() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertTrue(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.STARTED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(null);
+
+		Assert.assertEquals(ConfigurationCallback.State.STARTED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+	}
+
+	@Test
+	public void test_removeAfterRemove() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertTrue(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.STARTED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(null);
+
+		Assert.assertEquals(ConfigurationCallback.State.STARTED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(null);
+	}
+
+	@Test
+	public void test_removeAfterUpdate() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertTrue(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.STARTED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.STARTED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(null);
+
+		Assert.assertEquals(ConfigurationCallback.State.STARTED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+	}
+
+	@Test
+	public void test_updateAfterAdd() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertTrue(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.STARTED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.STARTED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+	}
+
+	@Test
+	public void test_updateAfterRemove() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertTrue(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.STARTED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(null);
+
+		Assert.assertEquals(ConfigurationCallback.State.STARTED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(properties);
+	}
+
+	@Test
+	public void test_updateAfterUpdate() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertTrue(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.STARTED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.STARTED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.STARTED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+	}
+
+	private ConfigurationPolicy POLICY = ConfigurationPolicy.IGNORE;
+
+}

Added: aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/configuration/ConfigurationManagedServiceTest_Optional.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/configuration/ConfigurationManagedServiceTest_Optional.java?rev=1807424&view=auto
==============================================================================
--- aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/configuration/ConfigurationManagedServiceTest_Optional.java (added)
+++ aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/configuration/ConfigurationManagedServiceTest_Optional.java Tue Sep  5 22:01:11 2017
@@ -0,0 +1,272 @@
+/**
+ * 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.configuration;
+
+import static org.apache.aries.cdi.container.test.TestUtil.*;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.osgi.service.cdi.annotations.ConfigurationPolicy;
+import org.osgi.service.cm.ManagedService;
+
+public class ConfigurationManagedServiceTest_Optional {
+
+	@Test(expected = IllegalArgumentException.class)
+	public void test_emptyAdd() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(new Hashtable<>());
+	}
+
+	@Ignore // this is due to a quirk in the spec... not sure why!
+	@Test(expected = IllegalStateException.class)
+	public void test_nullAdd() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(null);
+	}
+
+	@Test
+	public void test_add() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertTrue(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertTrue(configurationCallback.resolved());
+	}
+
+	@Test
+	public void test_addAfterRemove() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertTrue(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.ADDED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(null);
+
+		Assert.assertEquals(ConfigurationCallback.State.REMOVED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.ADDED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+	}
+
+	@Test
+	public void test_addAfterUpdate() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertTrue(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.ADDED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.UPDATED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.UPDATED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+	}
+
+	@Test
+	public void test_removeAfterAdd() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertTrue(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.ADDED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(null);
+
+		Assert.assertEquals(ConfigurationCallback.State.REMOVED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+	}
+
+	@Ignore // this is due to a quirk in the spec... not sure why!
+	@Test(expected = IllegalStateException.class)
+	public void test_removeAfterRemove() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertTrue(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.ADDED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(null);
+
+		Assert.assertEquals(ConfigurationCallback.State.REMOVED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(null);
+	}
+
+	@Test
+	public void test_removeAfterUpdate() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertTrue(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.ADDED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.UPDATED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(null);
+
+		Assert.assertEquals(ConfigurationCallback.State.REMOVED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+	}
+
+	@Test
+	public void test_updateAfterAdd() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertTrue(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.ADDED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.UPDATED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+	}
+
+	@Test
+	public void test_updateAfterRemove() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertTrue(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.ADDED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(null);
+
+		Assert.assertEquals(ConfigurationCallback.State.REMOVED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(properties);
+	}
+
+	@Test
+	public void test_updateAfterUpdate() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertTrue(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.ADDED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.UPDATED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.UPDATED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+	}
+
+	private ConfigurationPolicy POLICY = ConfigurationPolicy.OPTIONAL;
+
+}

Added: aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/configuration/ConfigurationManagedServiceTest_Require.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/configuration/ConfigurationManagedServiceTest_Require.java?rev=1807424&view=auto
==============================================================================
--- aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/configuration/ConfigurationManagedServiceTest_Require.java (added)
+++ aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/configuration/ConfigurationManagedServiceTest_Require.java Tue Sep  5 22:01:11 2017
@@ -0,0 +1,272 @@
+/**
+ * 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.configuration;
+
+import static org.apache.aries.cdi.container.test.TestUtil.*;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.osgi.service.cdi.annotations.ConfigurationPolicy;
+import org.osgi.service.cm.ManagedService;
+
+public class ConfigurationManagedServiceTest_Require {
+
+	@Test(expected = IllegalArgumentException.class)
+	public void test_emptyAdd() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertFalse(configurationCallback.resolved());
+
+		managedService.updated(new Hashtable<>());
+	}
+
+	@Ignore // this is due to a quirk in the spec... not sure why!
+	@Test(expected = IllegalStateException.class)
+	public void test_nullAdd() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertFalse(configurationCallback.resolved());
+
+		managedService.updated(null);
+	}
+
+	@Test
+	public void test_add() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertFalse(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertTrue(configurationCallback.resolved());
+	}
+
+	@Test
+	public void test_addAfterRemove() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertFalse(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.ADDED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(null);
+
+		Assert.assertEquals(ConfigurationCallback.State.REMOVED, configurationCallback.state());
+		Assert.assertFalse(configurationCallback.resolved());
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.ADDED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+	}
+
+	@Test
+	public void test_addAfterUpdate() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertFalse(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.ADDED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.UPDATED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.UPDATED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+	}
+
+	@Test
+	public void test_removeAfterAdd() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertFalse(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.ADDED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(null);
+
+		Assert.assertEquals(ConfigurationCallback.State.REMOVED, configurationCallback.state());
+		Assert.assertFalse(configurationCallback.resolved());
+	}
+
+	@Ignore // this is due to a quirk in the spec... not sure why!
+	@Test(expected = IllegalStateException.class)
+	public void test_removeAfterRemove() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertFalse(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.ADDED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(null);
+
+		Assert.assertEquals(ConfigurationCallback.State.REMOVED, configurationCallback.state());
+		Assert.assertFalse(configurationCallback.resolved());
+
+		managedService.updated(null);
+	}
+
+	@Test
+	public void test_removeAfterUpdate() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertFalse(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.ADDED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.UPDATED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(null);
+
+		Assert.assertEquals(ConfigurationCallback.State.REMOVED, configurationCallback.state());
+		Assert.assertFalse(configurationCallback.resolved());
+	}
+
+	@Test
+	public void test_updateAfterAdd() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertFalse(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.ADDED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.UPDATED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+	}
+
+	@Test
+	public void test_updateAfterRemove() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertFalse(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.ADDED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(null);
+
+		Assert.assertEquals(ConfigurationCallback.State.REMOVED, configurationCallback.state());
+		Assert.assertFalse(configurationCallback.resolved());
+
+		managedService.updated(properties);
+	}
+
+	@Test
+	public void test_updateAfterUpdate() throws Exception {
+		ConfigurationCallback configurationCallback = getCallback(POLICY);
+
+		ManagedService managedService = new ConfigurationManagedService("foo", configurationCallback);
+
+		Assert.assertFalse(configurationCallback.resolved());
+
+		Dictionary<String, Object> properties = new Hashtable<>();
+		properties.put("foo", "bar");
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.ADDED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.UPDATED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+
+		managedService.updated(properties);
+
+		Assert.assertEquals(ConfigurationCallback.State.UPDATED, configurationCallback.state());
+		Assert.assertTrue(configurationCallback.resolved());
+	}
+
+	private ConfigurationPolicy POLICY = ConfigurationPolicy.REQUIRE;
+
+}

Added: aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/container/ContainerDiscoveryTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/container/ContainerDiscoveryTest.java?rev=1807424&view=auto
==============================================================================
--- aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/container/ContainerDiscoveryTest.java (added)
+++ aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/container/ContainerDiscoveryTest.java Tue Sep  5 22:01:11 2017
@@ -0,0 +1,500 @@
+/**
+ * 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.container;
+
+import static org.apache.aries.cdi.container.test.TestUtil.*;
+import static org.junit.Assert.*;
+
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.DefinitionException;
+
+import org.apache.aries.cdi.container.internal.component.ComponentModel;
+import org.apache.aries.cdi.container.internal.configuration.ConfigurationModel;
+import org.apache.aries.cdi.container.internal.model.AbstractModelBuilder;
+import org.apache.aries.cdi.container.internal.model.BeansModel;
+import org.apache.aries.cdi.container.internal.model.CollectionType;
+import org.apache.aries.cdi.container.internal.reference.ReferenceModel;
+import org.apache.aries.cdi.container.internal.util.Sets;
+import org.apache.aries.cdi.container.test.beans.Bar;
+import org.apache.aries.cdi.container.test.beans.BarAnnotated;
+import org.apache.aries.cdi.container.test.beans.BarReference;
+import org.apache.aries.cdi.container.test.beans.BarWithConfig;
+import org.apache.aries.cdi.container.test.beans.BarWithReference;
+import org.apache.aries.cdi.container.test.beans.Config;
+import org.apache.aries.cdi.container.test.beans.Foo;
+import org.apache.aries.cdi.container.test.beans.FooAnnotated;
+import org.apache.aries.cdi.container.test.beans.FooReference;
+import org.apache.aries.cdi.container.test.beans.FooWithConfig;
+import org.apache.aries.cdi.container.test.beans.FooWithReference;
+import org.jboss.weld.resources.spi.ResourceLoader;
+import org.jboss.weld.serialization.spi.ProxyServices;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cdi.annotations.ConfigurationPolicy;
+import org.osgi.service.cdi.annotations.ReferenceCardinality;
+import org.osgi.service.cdi.annotations.ReferencePolicy;
+import org.osgi.service.cdi.annotations.ReferencePolicyOption;
+import org.osgi.service.cdi.annotations.ReferenceScope;
+import org.osgi.service.cdi.annotations.ServiceScope;
+import org.osgi.util.converter.TypeReference;
+
+public class ContainerDiscoveryTest {
+
+	@Test
+	public void testBeansOnly() throws Exception {
+		AbstractModelBuilder builder = getModelBuilder(Collections.singletonList("OSGI-INF/cdi/beans-only.xml"), null);
+
+		final BeansModel beansModel = builder.build();
+
+		ContainerState containerState = new ContainerState(null, null) {
+
+			@Override
+			public BeansModel beansModel() {
+				return beansModel;
+			}
+
+			public <T extends ResourceLoader & ProxyServices> T loader() {
+				return null;
+			}
+
+		};
+
+		ContainerDiscovery.discover(containerState);
+
+		Collection<ComponentModel> componentModels = sort(
+			beansModel.getComponentModels(), (a, b) -> a.getName().compareTo(b.getName()));
+
+		assertEquals(2, componentModels.size());
+
+		Iterator<ComponentModel> iterator = componentModels.iterator();
+
+		assertComponentModel(
+			iterator.next(),
+			Bar.class,
+			0,
+			Bar.class.getName(),
+			new String[0],
+			Collections.emptyList(),
+			0,
+			ServiceScope.NONE);
+
+		assertComponentModel(
+			iterator.next(),
+			Foo.class,
+			0,
+			Foo.class.getName(),
+			new String[0],
+			Collections.emptyList(),
+			0,
+			ServiceScope.NONE);
+	}
+
+	@Test
+	public void testConfiguration() throws Exception {
+		AbstractModelBuilder builder = getModelBuilder(Collections.singletonList("OSGI-INF/cdi/beans-configuration.xml"), null);
+
+		final BeansModel beansModel = builder.build();
+
+		ContainerState containerState = new ContainerState(null, null) {
+
+			@Override
+			public BeansModel beansModel() {
+				return beansModel;
+			}
+
+			public <T extends ResourceLoader & ProxyServices> T loader() {
+				return null;
+			}
+
+		};
+
+		ContainerDiscovery.discover(containerState);
+
+		Collection<ComponentModel> componentModels = sort(
+			beansModel.getComponentModels(), (a, b) -> a.getName().compareTo(b.getName()));
+
+		assertEquals(2, componentModels.size());
+
+		Iterator<ComponentModel> compItr = componentModels.iterator();
+
+		ComponentModel componentModel = compItr.next();
+
+		assertComponentModel(
+			componentModel,
+			BarWithConfig.class,
+			2,
+			BarWithConfig.class.getName(),
+			new String[0],
+			Collections.emptyList(),
+			0,
+			ServiceScope.NONE);
+
+		Collection<ConfigurationModel> configurations = sort(componentModel.getConfigurations(), (a, b) -> a.getType().getTypeName().compareTo(b.getType().getTypeName()));
+
+		Iterator<ConfigurationModel> confItr = configurations.iterator();
+
+		assertConfigurationModel(
+			confItr.next(),
+			new String[] {"$"},
+			ConfigurationPolicy.OPTIONAL,
+			new TypeReference<Bar>() {}.getType());
+
+		assertConfigurationModel(
+			confItr.next(),
+			new String[] {"$"},
+			ConfigurationPolicy.REQUIRE,
+			new TypeReference<Config>() {}.getType());
+
+		componentModel = compItr.next();
+
+		assertComponentModel(
+			componentModel,
+			FooWithConfig.class,
+			1,
+			FooWithConfig.class.getName(),
+			new String[0],
+			Collections.emptyList(),
+			0,
+			ServiceScope.NONE);
+
+		configurations = sort(componentModel.getConfigurations(), (a, b) -> a.getType().getTypeName().compareTo(b.getType().getTypeName()));
+
+		confItr = configurations.iterator();
+
+		assertConfigurationModel(
+			confItr.next(),
+			new String[] {"$", "foo.config"},
+			ConfigurationPolicy.OPTIONAL,
+			new TypeReference<Config>() {}.getType());
+	}
+
+	@Test
+	public void testReferences() throws Exception {
+		AbstractModelBuilder builder = getModelBuilder(Collections.singletonList("OSGI-INF/cdi/beans-references.xml"), null);
+
+		final BeansModel beansModel = builder.build();
+
+		ContainerState containerState = new ContainerState(null, null) {
+
+			@Override
+			public BeansModel beansModel() {
+				return beansModel;
+			}
+
+			public <T extends ResourceLoader & ProxyServices> T loader() {
+				return null;
+			}
+
+		};
+
+		ContainerDiscovery.discover(containerState);
+
+		Collection<ComponentModel> componentModels = sort(
+			beansModel.getComponentModels(), (a, b) -> a.getName().compareTo(b.getName()));
+
+		assertEquals(2, componentModels.size());
+
+		Iterator<ComponentModel> compItr = componentModels.iterator();
+
+		ComponentModel componentModel = compItr.next();
+
+		assertComponentModel(
+			componentModel,
+			BarWithReference.class,
+			0,
+			BarWithReference.class.getName(),
+			new String[0],
+			Collections.emptyList(),
+			1,
+			ServiceScope.NONE);
+
+		Collection<ReferenceModel> references = componentModel.getReferences();
+
+		Iterator<ReferenceModel> refIter = references.iterator();
+
+		assertReferenceModel(
+			refIter.next(),
+			BarReference.class,
+			ReferenceCardinality.MANDATORY,
+			CollectionType.SERVICE,
+			BarReference.class,
+			"barReference",
+			ReferencePolicy.STATIC,
+			ReferencePolicyOption.RELUCTANT,
+			ReferenceScope.BUNDLE,
+			BarReference.class,
+			"",
+			Sets.hashSet(BarReference.class, Object.class));
+
+		componentModel = compItr.next();
+
+		assertComponentModel(
+			componentModel,
+			FooWithReference.class,
+			0,
+			FooWithReference.class.getName(),
+			new String[0],
+			Collections.emptyList(),
+			1,
+			ServiceScope.NONE);
+
+		references = componentModel.getReferences();
+
+		refIter = references.iterator();
+
+		assertReferenceModel(
+			refIter.next(),
+			FooReference.class,
+			ReferenceCardinality.MANDATORY,
+			CollectionType.SERVICE,
+			FooReference.class,
+			"fooReference",
+			ReferencePolicy.STATIC,
+			ReferencePolicyOption.RELUCTANT,
+			ReferenceScope.BUNDLE,
+			FooReference.class,
+			"",
+			Sets.hashSet(FooReference.class, Object.class));
+	}
+
+	@Test
+	public void testAnnotatedBeans() throws Exception {
+		AbstractModelBuilder builder = getModelBuilder(Collections.singletonList("OSGI-INF/cdi/beans-annotated.xml"), null);
+
+		final BeansModel beansModel = builder.build();
+
+		ContainerState containerState = new ContainerState(null, null) {
+
+			@Override
+			public BeansModel beansModel() {
+				return beansModel;
+			}
+
+			public <T extends ResourceLoader & ProxyServices> T loader() {
+				return null;
+			}
+
+		};
+
+		ContainerDiscovery.discover(containerState);
+
+		Collection<ComponentModel> componentModels = sort(
+			beansModel.getComponentModels(), (a, b) -> a.getName().compareTo(b.getName()));
+
+		assertEquals(2, componentModels.size());
+
+		Iterator<ComponentModel> compItr = componentModels.iterator();
+
+		ComponentModel componentModel = compItr.next();
+
+		assertComponentModel(
+			componentModel,
+			FooAnnotated.class,
+			0,
+			"foo.annotated",
+			new String[] {"service.ranking:Integer=12"},
+			Arrays.asList(Foo.class.getName()),
+			0,
+			ServiceScope.SINGLETON);
+
+		componentModel = compItr.next();
+
+		assertComponentModel(
+			componentModel,
+			BarAnnotated.class,
+			1,
+			BarAnnotated.class.getName(),
+			new String[0],
+			Collections.emptyList(),
+			6,
+			ServiceScope.NONE);
+
+		Collection<ReferenceModel> references = sort(componentModel.getReferences(), (a, b) -> a.getName().compareTo(b.getName()));
+
+		Iterator<ReferenceModel> refIter = references.iterator();
+
+		assertReferenceModel(
+			refIter.next(),
+			Collection.class,
+			ReferenceCardinality.MULTIPLE,
+			CollectionType.SERVICE,
+			new TypeReference<Collection<Foo>>() {}.getType(),
+			"collectionFoos",
+			ReferencePolicy.DYNAMIC,
+			ReferencePolicyOption.RELUCTANT,
+			ReferenceScope.DEFAULT,
+			Foo.class,
+			"",
+			Sets.hashSet(new TypeReference<Collection<Foo>>() {}.getType(), Object.class));
+
+		assertReferenceModel(
+			refIter.next(),
+			Foo.class,
+			ReferenceCardinality.OPTIONAL,
+			CollectionType.SERVICE,
+			Foo.class,
+			"foo",
+			ReferencePolicy.STATIC,
+			ReferencePolicyOption.RELUCTANT,
+			ReferenceScope.DEFAULT,
+			Foo.class,
+			"",
+			Sets.hashSet(Foo.class, Object.class));
+
+		assertReferenceModel(
+			refIter.next(),
+			Foo.class,
+			ReferenceCardinality.MULTIPLE,
+			CollectionType.SERVICE,
+			Foo.class,
+			"foos",
+			ReferencePolicy.STATIC,
+			ReferencePolicyOption.RELUCTANT,
+			ReferenceScope.DEFAULT,
+			Foo.class,
+			"",
+			Sets.hashSet(Foo.class, Object.class));
+
+		assertReferenceModel(
+			refIter.next(),
+			Collection.class,
+			ReferenceCardinality.MULTIPLE,
+			CollectionType.PROPERTIES,
+			new TypeReference<Collection<Map<String, Object>>>(){}.getType(),
+			"propertiesFoos",
+			ReferencePolicy.STATIC,
+			ReferencePolicyOption.RELUCTANT,
+			ReferenceScope.DEFAULT,
+			Foo.class,
+			"",
+			Sets.hashSet(new TypeReference<Collection<Map<String, Object>>>(){}.getType(), Object.class));
+
+		assertReferenceModel(
+			refIter.next(),
+			Collection.class,
+			ReferenceCardinality.MULTIPLE,
+			CollectionType.REFERENCE,
+			new TypeReference<Collection<ServiceReference<Foo>>>(){}.getType(),
+			"serviceReferencesFoos",
+			ReferencePolicy.STATIC,
+			ReferencePolicyOption.RELUCTANT,
+			ReferenceScope.PROTOTYPE,
+			Foo.class,
+			"",
+			Sets.hashSet(new TypeReference<Collection<ServiceReference<Foo>>>(){}.getType(), Object.class));
+
+		assertReferenceModel(
+			refIter.next(),
+			Collection.class,
+			ReferenceCardinality.MULTIPLE,
+			CollectionType.TUPLE,
+			new TypeReference<Collection<Map.Entry<Map<String, Object>, Foo>>>(){}.getType(),
+			"tupleFoos",
+			ReferencePolicy.STATIC,
+			ReferencePolicyOption.GREEDY,
+			ReferenceScope.DEFAULT,
+			Foo.class,
+			"",
+			Sets.hashSet(new TypeReference<Collection<Map.Entry<Map<String, Object>, Foo>>>(){}.getType(), Object.class));
+	}
+
+	@Test(expected = DefinitionException.class)
+	public void testDescriptorError1() throws Exception {
+		AbstractModelBuilder builder = getModelBuilder(Collections.singletonList("OSGI-INF/cdi/beans-badly-annotated.xml"), null);
+
+		final BeansModel beansModel = builder.build();
+
+		ContainerState containerState = new ContainerState(null, null) {
+
+			@Override
+			public BeansModel beansModel() {
+				return beansModel;
+			}
+
+			public <T extends ResourceLoader & ProxyServices> T loader() {
+				return null;
+			}
+
+		};
+
+		ContainerDiscovery.discover(containerState);
+	}
+
+	protected void assertComponentModel(
+		ComponentModel componentModel,
+		Class<?> beanClass,
+		int confSize,
+		String name,
+		String[] properties,
+		List<String> provides,
+		int refSize,
+		ServiceScope scope) {
+
+		assertEquals(beanClass, componentModel.getBeanClass());
+		assertEquals(confSize, componentModel.getConfigurations().size());
+		assertEquals(name, componentModel.getName());
+		assertArrayEquals(properties, componentModel.getProperties());
+		assertEquals(provides, componentModel.getProvides());
+		assertEquals(refSize, componentModel.getReferences().size());
+		assertEquals(scope, componentModel.getServiceScope());
+	}
+
+	protected void assertConfigurationModel(
+		ConfigurationModel configurationModel,
+		String[] pid,
+		ConfigurationPolicy policy,
+		Type type) {
+
+		assertArrayEquals(pid, configurationModel.getPid());
+		assertEquals(policy, configurationModel.getConfigurationPolicy());
+		assertEquals(type, configurationModel.getType());
+	}
+
+	private void assertReferenceModel(
+		ReferenceModel referenceModel,
+		Class<?> beanClass,
+		ReferenceCardinality cardinality,
+		CollectionType collectionType,
+		Type injectionPointType,
+		String name,
+		ReferencePolicy policy,
+		ReferencePolicyOption option,
+		ReferenceScope scope,
+		Class<?> serviceClass,
+		String target,
+		Set<Type> types) {
+
+		assertEquals(beanClass, referenceModel.getBeanClass());
+		assertEquals(cardinality, referenceModel.getCardinality());
+		assertEquals(collectionType, referenceModel.getCollectionType());
+		assertEquals(injectionPointType, referenceModel.getInjectionPointType());
+		assertEquals(name, referenceModel.getName());
+		assertEquals(policy, referenceModel.getPolicy());
+		assertEquals(option, referenceModel.getPolicyOption());
+		assertEquals(scope, referenceModel.getScope());
+		assertEquals(serviceClass, referenceModel.getServiceClass());
+		assertEquals(target, referenceModel.getTarget());
+		assertEquals(types, referenceModel.getTypes());
+	}
+
+}

Added: aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/model/EventsTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/model/EventsTest.java?rev=1807424&view=auto
==============================================================================
--- aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/model/EventsTest.java (added)
+++ aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/model/EventsTest.java Tue Sep  5 22:01:11 2017
@@ -0,0 +1,99 @@
+/**
+ * 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.model;
+
+import static org.apache.aries.cdi.container.test.TestUtil.*;
+import static org.junit.Assert.*;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Bean;
+
+import org.jboss.weld.manager.BeanManagerImpl;
+import org.apache.aries.cdi.container.internal.component.ComponentModel;
+import org.apache.aries.cdi.container.internal.container.ContainerState;
+import org.apache.aries.cdi.container.internal.literal.AnyLiteral;
+import org.apache.aries.cdi.container.internal.reference.ReferenceCallback;
+import org.apache.aries.cdi.container.internal.reference.ReferenceModel;
+import org.apache.aries.cdi.container.test.MockCdiContainerAndComponents;
+import org.apache.aries.cdi.container.test.MockServiceReference;
+import org.apache.aries.cdi.container.test.beans.Foo;
+import org.apache.aries.cdi.container.test.beans.ObserverFoo;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cdi.CdiEvent;
+
+public class EventsTest {
+
+	@Test
+	public void test_Event() throws Exception {
+		try (MockCdiContainerAndComponents container = new MockCdiContainerAndComponents(
+				"test", ObserverFoo.class.getName())) {
+
+			ContainerState containerState = container.containerState();
+
+			BeansModel beansModel = containerState.beansModel();
+
+			Collection<ComponentModel> models = sort(beansModel.getComponentModels());
+
+			assertEquals(1, models.size());
+
+			assertEquals(CdiEvent.Type.CREATED, containerState.lastState());
+
+			BeanManagerImpl beanManager = containerState.getBeanManager();
+			Set<Bean<?>> beans = beanManager.getBeans(ObserverFoo.class, AnyLiteral.INSTANCE);
+			@SuppressWarnings("rawtypes")
+			Bean bean = beanManager.resolve(beans);
+			@SuppressWarnings("unchecked")
+
+			javax.enterprise.context.spi.Context context = beanManager.getContext(bean.getScope());
+			ObserverFoo observerFoo = (ObserverFoo)context.get(bean, beanManager.createCreationalContext(bean));
+
+			assertEquals(0, observerFoo.foos().size());
+			assertEquals(CdiEvent.Type.CREATED, containerState.lastState());
+
+			ComponentModel componentModel = models.iterator().next();
+			List<ReferenceModel> references = componentModel.getReferences();
+			assertEquals(1, references.size());
+
+			Map<String, ReferenceCallback> map = containerState.referenceCallbacks().get(componentModel);
+			assertEquals(1, map.size());
+			ReferenceCallback callback = map.get(references.iterator().next().getName());
+			assertNotNull(callback);
+
+			MockServiceReference<Object> mockServiceReference = new MockServiceReference<Object>(new Foo() {});
+
+			callback.addingService(mockServiceReference);
+
+			assertEquals(1, observerFoo.foos().size());
+
+			mockServiceReference.setProperty(Constants.SERVICE_RANKING, 1);
+
+			callback.modifiedService(mockServiceReference, mockServiceReference.getService());
+
+			assertEquals(1, observerFoo.foos().size());
+
+			callback.removedService(mockServiceReference, mockServiceReference.getService());
+
+			assertEquals(0, observerFoo.foos().size());
+		}
+	}
+
+}

Modified: aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/model/MapsTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/model/MapsTest.java?rev=1807424&r1=1807423&r2=1807424&view=diff
==============================================================================
--- aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/model/MapsTest.java (original)
+++ aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/model/MapsTest.java Tue Sep  5 22:01:11 2017
@@ -238,6 +238,7 @@ public class MapsTest {
 		assertEquals(new HashSet<Byte>(Arrays.asList(new Byte("126"), new Byte("91"))), entry.getValue());
 	}
 
+	@SuppressWarnings("rawtypes")
 	@Test
 	public void testMixedConversion() throws Exception {
 		Map<String,Object> map = Maps.map(

Modified: aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/model/ModelTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/model/ModelTest.java?rev=1807424&r1=1807423&r2=1807424&view=diff
==============================================================================
--- aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/model/ModelTest.java (original)
+++ aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/model/ModelTest.java Tue Sep  5 22:01:11 2017
@@ -14,97 +14,122 @@
 
 package org.apache.aries.cdi.container.internal.model;
 
+import static org.apache.aries.cdi.container.test.TestUtil.*;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
-import java.net.URL;
-import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 
+import org.apache.aries.cdi.container.internal.component.ComponentModel;
+import org.apache.aries.cdi.container.internal.configuration.ConfigurationModel;
+import org.apache.aries.cdi.container.internal.reference.ReferenceModel;
+import org.apache.aries.cdi.container.test.beans.BarReference;
+import org.apache.aries.cdi.container.test.beans.Foo;
+import org.apache.aries.cdi.container.test.beans.FooReference;
 import org.junit.Test;
-import org.osgi.service.cdi.CdiConstants;
+import org.osgi.service.cdi.annotations.ConfigurationPolicy;
 
 public class ModelTest {
 
 	@Test
 	public void testModelWithBeansOnly() throws Exception {
-		AbstractModelBuilder builder = getBuilder("OSGI-INF/cdi/beans-only.xml");
+		AbstractModelBuilder builder = getModelBuilder("OSGI-INF/cdi/beans-only.xml");
 		BeansModel beansModel = builder.build();
 		assertNotNull(beansModel);
 
-		Collection<String> beanClassNames = beansModel.getBeanClassNames();
+		Collection<String> beanClassNames = sort(beansModel.getBeanClassNames(), (c1, c2) -> c1.compareTo(c2));
 		assertEquals(2, beanClassNames.size());
-		assertEquals("com.foo.FooImpl", beanClassNames.iterator().next());
+		assertEquals("org.apache.aries.cdi.container.test.beans.Bar", beanClassNames.iterator().next());
 	}
 
 	@Test
 	public void testModelWithConfiguration() throws Exception {
-		AbstractModelBuilder builder = getBuilder("OSGI-INF/cdi/beans-configuration.xml");
+		AbstractModelBuilder builder = getModelBuilder("OSGI-INF/cdi/beans-configuration.xml");
 		BeansModel beansModel = builder.build();
 		assertNotNull(beansModel);
 
-		Collection<String> beanClassNames = beansModel.getBeanClassNames();
+		Collection<String> beanClassNames = sort(beansModel.getBeanClassNames());
 		assertEquals(2, beanClassNames.size());
-		assertEquals("com.foo.FooImpl", beanClassNames.iterator().next());
+		assertEquals("org.apache.aries.cdi.container.test.beans.BarWithConfig", beanClassNames.iterator().next());
 
-		Collection<ConfigurationModel> configurationModels = beansModel.getConfigurationModels();
-		assertEquals(3, configurationModels.size());
-		Iterator<ConfigurationModel> iterator = configurationModels.iterator();
-
-		ConfigurationModel configurationModel = iterator.next();
-		assertArrayEquals(new String[] {"com.foo.FooImpl"}, configurationModel.pids());
-		assertEquals("com.foo.Config", configurationModel.beanClass());
-		assertEquals(true, configurationModel.required());
-
-		configurationModel = iterator.next();
-		assertArrayEquals(new String[] {"com.foo.other", "and.another"}, configurationModel.pids());
-		assertEquals("com.foo.Baz", configurationModel.beanClass());
-		assertEquals(true, configurationModel.required());
-
-		configurationModel = iterator.next();
-		assertArrayEquals(new String[] {"an.optional.configuration"}, configurationModel.pids());
-		assertEquals(false, configurationModel.required());
+		Collection<ComponentModel> componentModels = beansModel.getComponentModels();
+		assertEquals(2, componentModels.size());
+		Iterator<ComponentModel> components = componentModels.iterator();
+
+		ComponentModel componentModel = components.next();
+		Collection<ConfigurationModel> configurations = sort(componentModel.getConfigurations());
+		Iterator<ConfigurationModel> confIterator = configurations.iterator();
+
+		ConfigurationModel configurationModel = confIterator.next();
+		assertArrayEquals(new String[] {"$"}, configurationModel.getPid());
+		assertEquals(ConfigurationPolicy.OPTIONAL, configurationModel.getConfigurationPolicy());
+		assertEquals("org.apache.aries.cdi.container.test.beans.Bar", configurationModel.getType().getTypeName());
+
+		configurationModel = confIterator.next();
+		assertArrayEquals(new String[] {"$"}, configurationModel.getPid());
+		assertEquals(ConfigurationPolicy.REQUIRE, configurationModel.getConfigurationPolicy());
+		assertEquals("org.apache.aries.cdi.container.test.beans.Config", configurationModel.getType().getTypeName());
+
+		componentModel = components.next();
+		configurations = sort(componentModel.getConfigurations());
+		configurationModel = configurations.iterator().next();
+		assertArrayEquals(new String[] {"$", "foo.config"}, configurationModel.getPid());
+		assertEquals(ConfigurationPolicy.OPTIONAL, configurationModel.getConfigurationPolicy());
+		assertEquals("org.apache.aries.cdi.container.test.beans.Config", configurationModel.getType().getTypeName());
 	}
 
 	@Test
 	public void testModelWithReferences() throws Exception {
-		AbstractModelBuilder builder = getBuilder("OSGI-INF/cdi/beans-references.xml");
+		AbstractModelBuilder builder = getModelBuilder("OSGI-INF/cdi/beans-references.xml");
 		BeansModel beansModel = builder.build();
 		assertNotNull(beansModel);
 
-		Collection<String> beanClassNames = beansModel.getBeanClassNames();
+		Collection<String> beanClassNames = sort(beansModel.getBeanClassNames());
 		assertEquals(2, beanClassNames.size());
-		assertEquals("com.foo.FooImpl", beanClassNames.iterator().next());
+		assertEquals("org.apache.aries.cdi.container.test.beans.BarWithReference", beanClassNames.iterator().next());
 
-		Collection<ReferenceModel> referenceModels = beansModel.getReferenceModels();
-		assertEquals(2, referenceModels.size());
-		ReferenceModel referenceModel = referenceModels.iterator().next();
-		assertEquals("java.util.concurrent.Callable", referenceModel.getBeanClass());
-		assertEquals("(objectClass=java.util.concurrent.Callable)", referenceModel.getTarget());
+		Collection<ComponentModel> componentModels = sort(beansModel.getComponentModels());
+		assertEquals(2, componentModels.size());
+		Iterator<ComponentModel> iterator = componentModels.iterator();
+
+		ComponentModel componentModel = iterator.next();
+		ReferenceModel referenceModel = componentModel.getReferences().iterator().next();
+		assertEquals(BarReference.class, referenceModel.getBeanClass());
+
+		componentModel = iterator.next();
+		referenceModel = componentModel.getReferences().iterator().next();
+		assertEquals(FooReference.class, referenceModel.getBeanClass());
 	}
 
 	@Test
 	public void testModelWithServices() throws Exception {
-		AbstractModelBuilder builder = getBuilder("OSGI-INF/cdi/beans-services.xml");
+		AbstractModelBuilder builder = getModelBuilder("OSGI-INF/cdi/beans-services.xml");
 		BeansModel beansModel = builder.build();
 		assertNotNull(beansModel);
 
-		Collection<String> beanClassNames = beansModel.getBeanClassNames();
+		Collection<String> beanClassNames = sort(beansModel.getBeanClassNames());
 		assertEquals(2, beanClassNames.size());
-		assertEquals("com.foo.FooImpl", beanClassNames.iterator().next());
+		assertEquals("org.apache.aries.cdi.container.test.beans.FooService", beanClassNames.iterator().next());
 
-		Collection<ServiceModel> serviceModels = beansModel.getServiceModels();
-		assertEquals(1, serviceModels.size());
-		ServiceModel serviceModel = serviceModels.iterator().next();
-		List<String> provides = serviceModel.getProvides();
+		Collection<ComponentModel> componentModels = sort(beansModel.getComponentModels(), (a, b) -> a.getName().compareTo(b.getName()));
+		assertEquals(2, componentModels.size());
+
+		Iterator<ComponentModel> iterator = componentModels.iterator();
+
+		ComponentModel componentModel = iterator.next();
+		List<String> provides = componentModel.getProvides();
+		assertEquals(0, provides.size());
+
+		componentModel = iterator.next();
+		provides = componentModel.getProvides();
 		assertEquals(2, provides.size());
-		assertEquals("com.foo.Foo", provides.get(0));
-		String[] serviceProperties = serviceModel.getProperties();
+
+		assertEquals(Foo.class.getName(), provides.get(0));
+		assertEquals(Cloneable.class.getName(), provides.get(1));
+		String[] serviceProperties = componentModel.getProperties();
 		assertEquals(33, serviceProperties.length);
 
 		assertEquals("foo:String=fum", serviceProperties[0]);
@@ -144,48 +169,13 @@ public class ModelTest {
 
 	@Test
 	public void testModelWithAllDescriptors() throws Exception {
-		AbstractModelBuilder builder = getBuilder(null);
+		AbstractModelBuilder builder = getModelBuilder(null);
 		BeansModel beansModel = builder.build();
 		assertNotNull(beansModel);
 
-		Collection<String> beanClassNames = beansModel.getBeanClassNames();
-		assertEquals(2, beanClassNames.size());
-		assertEquals("com.foo.FooImpl", beanClassNames.iterator().next());
-	}
-
-	AbstractModelBuilder getBuilder(final String osgiBeansFile) {
-		return new AbstractModelBuilder() {
-
-			@Override
-			List<String> getDefaultResources() {
-				return Arrays.asList(
-						"OSGI-INF/cdi/beans-configuration.xml",
-						"OSGI-INF/cdi/beans-only.xml",
-						"OSGI-INF/cdi/beans-references.xml",
-						"OSGI-INF/cdi/beans-services.xml"
-					);
-			}
-
-			@Override
-			URL getResource(String resource) {
-				return getClassLoader().getResource(resource);
-			}
-
-			@Override
-			ClassLoader getClassLoader() {
-				return getClass().getClassLoader();
-			}
-
-			@Override
-			Map<String, Object> getAttributes() {
-				if (osgiBeansFile == null) {
-					return Collections.emptyMap();
-				}
-
-				return Collections.singletonMap(
-					CdiConstants.REQUIREMENT_OSGI_BEANS_ATTRIBUTE, Arrays.asList(osgiBeansFile));
-			}
-		};
+		Collection<String> beanClassNames = sort(beansModel.getBeanClassNames());
+		assertEquals(8, beanClassNames.size());
+		assertEquals("org.apache.aries.cdi.container.test.beans.FooService", beanClassNames.iterator().next());
 	}
 
 }

Added: aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/phase/ConfigurationPhaseTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/phase/ConfigurationPhaseTest.java?rev=1807424&view=auto
==============================================================================
--- aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/phase/ConfigurationPhaseTest.java (added)
+++ aries/trunk/cdi/cdi-extender/src/test/java/org/apache/aries/cdi/container/internal/phase/ConfigurationPhaseTest.java Tue Sep  5 22:01:11 2017
@@ -0,0 +1,201 @@
+/**
+ * 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.phase;
+
+import static org.apache.aries.cdi.container.test.TestUtil.*;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.apache.aries.cdi.container.internal.container.ContainerDiscovery;
+import org.apache.aries.cdi.container.internal.container.ContainerState;
+import org.apache.aries.cdi.container.internal.model.AbstractModelBuilder;
+import org.apache.aries.cdi.container.internal.model.BeansModel;
+import org.junit.Assert;
+import org.junit.Test;
+import org.osgi.framework.Constants;
+import org.osgi.service.cdi.CdiEvent;
+import org.osgi.service.cm.ManagedService;
+
+public class ConfigurationPhaseTest {
+
+	@Test
+	public void testOnlyBeans() throws Exception {
+		AbstractModelBuilder builder = getModelBuilder(Collections.singletonList("OSGI-INF/cdi/beans-only.xml"), null);
+
+		final BeansModel beansModel = builder.build();
+
+		ContainerState containerState = getContainerState(beansModel);
+
+		ContainerDiscovery.discover(containerState);
+
+		Phase_Configuration phase = new Phase_Configuration(containerState, Collections.emptyList());
+
+		phase.open();
+
+		Assert.assertEquals(2, containerState.managedServiceRegistrator().size());
+		Assert.assertEquals(1, containerState.beanManagerRegistrator().size());
+		Assert.assertEquals(0, containerState.serviceRegistrator().size());
+		Assert.assertEquals(CdiEvent.Type.CREATED, containerState.lastState());
+	}
+
+	@Test
+	public void testConfiguration() throws Exception {
+		AbstractModelBuilder builder = getModelBuilder(Collections.singletonList("OSGI-INF/cdi/beans-configuration.xml"), null);
+
+		final BeansModel beansModel = builder.build();
+
+		ContainerState containerState = getContainerState(beansModel);
+
+		ContainerDiscovery.discover(containerState);
+
+		Phase_Configuration phase = new Phase_Configuration(containerState, Collections.emptyList());
+
+		phase.open();
+
+		Assert.assertEquals(4, containerState.managedServiceRegistrator().size());
+		Assert.assertEquals(0, containerState.beanManagerRegistrator().size());
+		Assert.assertEquals(0, containerState.serviceRegistrator().size());
+		Assert.assertEquals(CdiEvent.Type.WAITING_FOR_CONFIGURATIONS, containerState.lastState());
+	}
+
+	@Test
+	public void testReferences() throws Exception {
+		AbstractModelBuilder builder = getModelBuilder(Collections.singletonList("OSGI-INF/cdi/beans-references.xml"), null);
+
+		final BeansModel beansModel = builder.build();
+
+		ContainerState containerState = getContainerState(beansModel);
+
+		ContainerDiscovery.discover(containerState);
+
+		Phase_Configuration phase = new Phase_Configuration(containerState, Collections.emptyList());
+
+		phase.open();
+
+		Assert.assertEquals(2, containerState.managedServiceRegistrator().size());
+		Assert.assertEquals(0, containerState.beanManagerRegistrator().size());
+		Assert.assertEquals(0, containerState.serviceRegistrator().size());
+		Assert.assertEquals(CdiEvent.Type.WAITING_FOR_SERVICES, containerState.lastState());
+	}
+
+	@Test
+	public void testEverything() throws Exception {
+		AbstractModelBuilder builder = getModelBuilder(null);
+
+		final BeansModel beansModel = builder.build();
+
+		ContainerState containerState = getContainerState(beansModel);
+
+		ContainerDiscovery.discover(containerState);
+
+		Phase_Configuration phase = new Phase_Configuration(containerState, Collections.emptyList());
+
+		phase.open();
+
+		Assert.assertEquals(10, containerState.managedServiceRegistrator().size());
+		Assert.assertEquals(0, containerState.beanManagerRegistrator().size());
+		Assert.assertEquals(0, containerState.serviceRegistrator().size());
+		Assert.assertEquals(CdiEvent.Type.WAITING_FOR_CONFIGURATIONS, containerState.lastState());
+	}
+
+	@Test
+	public void testEverythingCreateConfigurations() throws Exception {
+		AbstractModelBuilder builder = getModelBuilder(null);
+
+		final BeansModel beansModel = builder.build();
+
+		ContainerState containerState = getContainerState(beansModel);
+
+		ContainerDiscovery.discover(containerState);
+
+		Phase_Configuration phase = new Phase_Configuration(containerState, Collections.emptyList());
+
+		phase.open();
+
+		Assert.assertEquals(10, containerState.managedServiceRegistrator().size());
+		Assert.assertEquals(0, containerState.beanManagerRegistrator().size());
+		Assert.assertEquals(0, containerState.serviceRegistrator().size());
+		Assert.assertEquals(CdiEvent.Type.WAITING_FOR_CONFIGURATIONS, containerState.lastState());
+
+		Set<Entry<Dictionary<String,?>,ManagedService>> entrySet =
+			((TMSRegistrator)containerState.managedServiceRegistrator()).registrations.entrySet();
+
+		for (Map.Entry<Dictionary<String, ?>, ManagedService> entry : entrySet) {
+			Dictionary<String, Object> properties = new Hashtable<>();
+
+			properties.put(Constants.SERVICE_PID, entry.getKey().get(Constants.SERVICE_PID));
+			properties.put("time", System.currentTimeMillis());
+
+			entry.getValue().updated(properties);
+		}
+
+		Assert.assertEquals(CdiEvent.Type.WAITING_FOR_SERVICES, containerState.lastState());
+	}
+
+	@Test
+	public void testReactiveConfigurations() throws Exception {
+		AbstractModelBuilder builder = getModelBuilder(Collections.singletonList("OSGI-INF/cdi/beans-configuration.xml"), null);
+
+		final BeansModel beansModel = builder.build();
+
+		ContainerState containerState = getContainerState(beansModel);
+
+		ContainerDiscovery.discover(containerState);
+
+		Phase_Configuration phase = new Phase_Configuration(containerState, Collections.emptyList());
+
+		phase.open();
+
+		Assert.assertEquals(4, containerState.managedServiceRegistrator().size());
+		Assert.assertEquals(0, containerState.beanManagerRegistrator().size());
+		Assert.assertEquals(0, containerState.serviceRegistrator().size());
+		Assert.assertEquals(CdiEvent.Type.WAITING_FOR_CONFIGURATIONS, containerState.lastState());
+
+		Collection<Entry<Dictionary<String, ?>, ManagedService>> collection = sort(
+			((TMSRegistrator)containerState.managedServiceRegistrator()).registrations.entrySet(), (a, b) -> ((Integer)a.getKey().get("component.id")).compareTo((Integer)b.getKey().get("component.id")));
+
+		Iterator<Entry<Dictionary<String, ?>, ManagedService>> iterator = collection.iterator();
+
+		Entry<Dictionary<String, ?>, ManagedService> entry = iterator.next();
+		Dictionary<String, Object> properties = new Hashtable<>();
+		String pid = (String)entry.getKey().get(Constants.SERVICE_PID);
+		Assert.assertEquals("org.apache.aries.cdi.container.test.beans.BarWithConfig", pid);
+		properties.put(Constants.SERVICE_PID, pid);
+		properties.put("time", System.currentTimeMillis());
+		entry.getValue().updated(properties);
+		Assert.assertEquals(CdiEvent.Type.WAITING_FOR_CONFIGURATIONS, containerState.lastState());
+
+		entry = iterator.next();
+		properties = new Hashtable<>();
+		pid = (String)entry.getKey().get(Constants.SERVICE_PID);
+		Assert.assertEquals("org.apache.aries.cdi.container.test.beans.BarWithConfig", pid);
+		properties.put(Constants.SERVICE_PID, pid);
+		properties.put("time", System.currentTimeMillis());
+		entry.getValue().updated(properties);
+		Assert.assertEquals(CdiEvent.Type.CREATED, containerState.lastState());
+		entry.getValue().updated(null);
+		Assert.assertEquals(CdiEvent.Type.WAITING_FOR_CONFIGURATIONS, containerState.lastState());
+		entry.getValue().updated(properties);
+		Assert.assertEquals(CdiEvent.Type.CREATED, containerState.lastState());
+	}
+
+}



Mime
View raw message