FELIX-4401 Initial refactoring of integration tests to use ServiceComponentRuntime. Does not include factory component tests which do not compile
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1602633 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/pom.xml b/scr/pom.xml
index b2a592d..cb86891 100644
--- a/scr/pom.xml
+++ b/scr/pom.xml
@@ -252,7 +252,10 @@
org.apache.felix.scr;version=1.8,
org.apache.felix.scr.component;version=1.0;
mandatory:="status"; status="provisional",
- org.osgi.service.component
+ org.osgi.service.component,
+ org.osgi.service.component.runtime.*,
+ org.osgi.dto,
+ org.osgi.framework.dto
</Export-Package>
<Private-Package>
org.apache.felix.scr.impl.*,
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ActivateSignatureTest.java b/scr/src/test/java/org/apache/felix/scr/integration/ActivateSignatureTest.java
index d3337fd..8f18edb 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/ActivateSignatureTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ActivateSignatureTest.java
@@ -19,13 +19,16 @@
package org.apache.felix.scr.integration;
+import java.util.Collection;
+
import junit.framework.TestCase;
-import org.apache.felix.scr.Component;
import org.apache.felix.scr.integration.components.activatesignature.AbstractActivateSignatureTestComponent;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
+import org.osgi.service.component.runtime.dto.ComponentDescriptionDTO;
/**
@@ -53,24 +56,20 @@
// wait for components to fire up in the background....
delay();
- final Component[] components = getComponents();
+ final Collection<ComponentDescriptionDTO> components = getComponentDescriptions();
TestCase.assertNotNull( components );
- for ( Component component : components )
+ for ( ComponentDescriptionDTO component : components )
{
- TestCase.assertTrue( "Expecting component " + component.getName() + " to be enabled", component
- .isDefaultEnabled() );
+ TestCase.assertTrue( "Expecting component " + component.name + " to be enabled", component
+ .defaultEnabled );
- TestCase.assertEquals( "Expecting component " + component.getName() + " to be active",
- Component.STATE_ACTIVE, component.getState() );
+ ComponentConfigurationDTO cc = findComponentConfigurationByName(component.name, -1);
+ TestCase.assertEquals( "Expecting component " + component.name + " to be active",
+ ComponentConfigurationDTO.ACTIVE, cc.state );
+
+ TestCase.assertNotNull("Expect activate method to be called", AbstractActivateSignatureTestComponent.getInstance(component.name));
- final Object instance = component.getComponentInstance().getInstance();
- TestCase.assertTrue( "Expecting component " + component.getName()
- + " to be an AbstractActivateSignatureTestComponent",
- instance instanceof AbstractActivateSignatureTestComponent );
-
- final AbstractActivateSignatureTestComponent aastc = ( AbstractActivateSignatureTestComponent ) instance;
- TestCase.assertEquals( "Expect activate method to be called", component.getName(), aastc.getMethodCalled() );
}
}
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/CircularReferenceTest.java b/scr/src/test/java/org/apache/felix/scr/integration/CircularReferenceTest.java
index 6ff7e3b..624035a 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/CircularReferenceTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/CircularReferenceTest.java
@@ -29,6 +29,7 @@
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
@@ -57,56 +58,44 @@
public void test_A11_B11()
{
String componentNameA = "1.A.1.1.dynamic";
- final Component componentA = findComponentByName( componentNameA );
- TestCase.assertNotNull( componentA );
- TestCase.assertEquals( Component.STATE_UNSATISFIED, componentA.getState() );
+ final ComponentConfigurationDTO componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.UNSATISFIED );
String componentNameB = "1.B.1.1.dynamic";
- final Component componentB = findComponentByName( componentNameB );
- TestCase.assertNotNull( componentB );
- TestCase.assertEquals( Component.STATE_UNSATISFIED, componentB.getState() );
-
-
+ final ComponentConfigurationDTO componentB = findComponentConfigurationByName( componentNameB, ComponentConfigurationDTO.UNSATISFIED );
}
/**
* A > 1.1 > B > 0..n > A Both should start (A first), but B should not have an A reference.
+ * @throws InvalidSyntaxException
*/
@Test
- public void test_A11_B0n_immediate_A_first()
+ public void test_A11_B0n_immediate_A_first() throws InvalidSyntaxException
{
String componentNameA = "2.A.1.1.dynamic";
- final Component componentA = findComponentByName( componentNameA );
- TestCase.assertNotNull( componentA );
- TestCase.assertEquals( Component.STATE_ACTIVE, componentA.getState() );
- A a = ( A ) componentA.getComponentInstance().getInstance();
+ final ComponentConfigurationDTO componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.ACTIVE );
+ A a = getServiceFromConfiguration(componentA, A.class);
assertEquals( 1, a.getBs().size());
String componentNameB = "2.B.0.n.dynamic";
- final Component componentB = findComponentByName( componentNameB );
- TestCase.assertNotNull( componentB );
- TestCase.assertEquals( Component.STATE_ACTIVE, componentB.getState() );
- B b = ( B ) componentB.getComponentInstance().getInstance();
+ final ComponentConfigurationDTO componentB = findComponentConfigurationByName( componentNameB, ComponentConfigurationDTO.ACTIVE );
+ B b = getServiceFromConfiguration(componentB, B.class);
assertEquals( 1, b.getAs().size() );
}
/**
* A > 1.1 > B > 0..n > A Both should start (B first), and B should have an A reference.
+ * @throws InvalidSyntaxException
*/
@Test
- public void test_A11_B0n_immediate_B_first()
+ public void test_A11_B0n_immediate_B_first() throws InvalidSyntaxException
{
String componentNameA = "3.A.1.1.dynamic";
- final Component componentA = findComponentByName( componentNameA );
- TestCase.assertNotNull( componentA );
- TestCase.assertEquals( Component.STATE_ACTIVE, componentA.getState() );
- A a = ( A ) componentA.getComponentInstance().getInstance();
+ final ComponentConfigurationDTO componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.ACTIVE );
+ A a = getServiceFromConfiguration(componentA, A.class);
assertEquals( 1, a.getBs().size());
String componentNameB = "3.B.0.n.dynamic";
- final Component componentB = findComponentByName( componentNameB );
- TestCase.assertNotNull( componentB );
- TestCase.assertEquals( Component.STATE_ACTIVE, componentB.getState() );
- B b = ( B ) componentB.getComponentInstance().getInstance();
+ final ComponentConfigurationDTO componentB = findComponentConfigurationByName( componentNameB, ComponentConfigurationDTO.ACTIVE );
+ B b = getServiceFromConfiguration(componentB, B.class);
assertEquals( 1, b.getAs().size() );
}
/**
@@ -116,26 +105,22 @@
public void test_A11_B0n_delayed_A_first() throws InvalidSyntaxException
{
String componentNameA = "4.A.1.1.dynamic";
- final Component componentA = findComponentByName( componentNameA );
- TestCase.assertNotNull( componentA );
- TestCase.assertEquals( Component.STATE_REGISTERED, componentA.getState() );
+ final ComponentConfigurationDTO componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.SATISFIED );
String componentNameB = "4.B.0.n.dynamic";
- final Component componentB = findComponentByName( componentNameB );
- TestCase.assertNotNull( componentB );
- TestCase.assertEquals( Component.STATE_REGISTERED, componentB.getState() );
+ final ComponentConfigurationDTO componentB = findComponentConfigurationByName( componentNameB, ComponentConfigurationDTO.SATISFIED );
- ServiceReference[] serviceReferences = bundleContext.getServiceReferences( A.class.getName(), "(service.pid=" + componentNameA + ")" );
- TestCase.assertEquals( 1, serviceReferences.length );
- ServiceReference serviceReference = serviceReferences[0];
- Object service = bundleContext.getService( serviceReference );
- assertNotNull( service );
+// ServiceReference[] serviceReferences = bundleContext.getServiceReferences( A.class.getName(), "(service.pid=" + componentNameA + ")" );
+// TestCase.assertEquals( 1, serviceReferences.length );
+// ServiceReference serviceReference = serviceReferences[0];
+// Object service = bundleContext.getService( serviceReference );
+// assertNotNull( service );
delay();
- A a = ( A ) componentA.getComponentInstance().getInstance();
- assertEquals( 1, a.getBs().size() );
- B b = ( B ) componentB.getComponentInstance().getInstance();
+ A a = getServiceFromConfiguration(componentA, A.class);
+ assertEquals( 1, a.getBs().size());
+ B b = getServiceFromConfiguration(componentB, B.class);
assertEquals( 1, b.getAs().size() );
}
/**
@@ -145,14 +130,10 @@
public void test_A11_B0n_delayed_B_first() throws InvalidSyntaxException
{
String componentNameA = "4.A.1.1.dynamic";
- final Component componentA = findComponentByName( componentNameA );
- TestCase.assertNotNull( componentA );
- TestCase.assertEquals( Component.STATE_REGISTERED, componentA.getState() );
+ final ComponentConfigurationDTO componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.SATISFIED );
String componentNameB = "4.B.0.n.dynamic";
- final Component componentB = findComponentByName( componentNameB );
- TestCase.assertNotNull( componentB );
- TestCase.assertEquals( Component.STATE_REGISTERED, componentB.getState() );
+ final ComponentConfigurationDTO componentB = findComponentConfigurationByName( componentNameB, ComponentConfigurationDTO.SATISFIED);
ServiceReference[] serviceReferencesB = bundleContext.getServiceReferences( B.class.getName(), "(service.pid=" + componentNameB + ")" );
TestCase.assertEquals( 1, serviceReferencesB.length );
@@ -167,68 +148,62 @@
assertNotNull( serviceA );
delay();
- A a = ( A ) componentA.getComponentInstance().getInstance();
- assertEquals( 1, a.getBs().size() );
- B b = ( B ) componentB.getComponentInstance().getInstance();
+ A a = getServiceFromConfiguration(componentA, A.class);
+ assertEquals( 1, a.getBs().size());
+ B b = getServiceFromConfiguration(componentB, B.class);
assertEquals( 1, b.getAs().size() );
//disabling (removing the A service registration) and re-enabling will
//result in a service event to B, so B will bind A.
- componentA.disable();
+ disableAndCheck(componentA);
delay();
- componentA.enable();
+ enableAndCheck(componentA.description);
delay();
- ServiceReference[] serviceReferencesA1 = bundleContext.getServiceReferences( A.class.getName(), "(service.pid=" + componentNameA + ")" );
- TestCase.assertEquals( 1, serviceReferencesA1.length );
- ServiceReference serviceReferenceA1 = serviceReferencesA1[0];
- Object serviceA1 = bundleContext.getService( serviceReferenceA1 );
- assertNotNull( serviceA1 );
+// ServiceReference[] serviceReferencesA1 = bundleContext.getServiceReferences( A.class.getName(), "(service.pid=" + componentNameA + ")" );
+// TestCase.assertEquals( 1, serviceReferencesA1.length );
+// ServiceReference serviceReferenceA1 = serviceReferencesA1[0];
+// Object serviceA1 = bundleContext.getService( serviceReferenceA1 );
+// assertNotNull( serviceA1 );
- A a1 = ( A ) componentA.getComponentInstance().getInstance();
- assertEquals( 1, a1.getBs().size() );
- B b1 = ( B ) componentB.getComponentInstance().getInstance();
- assertEquals( 1, b1.getAs().size() );
+ a = getServiceFromConfiguration(componentA, A.class);
+ assertEquals( 1, a.getBs().size());
+ b = getServiceFromConfiguration(componentB, B.class);
+ assertEquals( 1, b.getAs().size() );
}
/**
* A > 1.1 > B > 0..1 > A Both should start (A first), but B should not have an A reference.
+ * @throws InvalidSyntaxException
*/
@Test
- public void test_A11_B01_immediate_A_first()
+ public void test_A11_B01_immediate_A_first() throws InvalidSyntaxException
{
String componentNameA = "5.A.1.1.dynamic";
- final Component componentA = findComponentByName( componentNameA );
- TestCase.assertNotNull( componentA );
- TestCase.assertEquals( Component.STATE_ACTIVE, componentA.getState() );
- A a = ( A ) componentA.getComponentInstance().getInstance();
+ final ComponentConfigurationDTO componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.ACTIVE );
+ A a = getServiceFromConfiguration(componentA, A.class);
assertEquals( 1, a.getBs().size());
String componentNameB = "5.B.0.1.dynamic";
- final Component componentB = findComponentByName( componentNameB );
- TestCase.assertNotNull( componentB );
- TestCase.assertEquals( Component.STATE_ACTIVE, componentB.getState() );
- B b = ( B ) componentB.getComponentInstance().getInstance();
+ final ComponentConfigurationDTO componentB = findComponentConfigurationByName( componentNameB, ComponentConfigurationDTO.ACTIVE );
+ B b = getServiceFromConfiguration(componentB, B.class);
assertEquals( 1, b.getAs().size() );
}
/**
* A > 1.1 > B > 0..1 > A Both should start (B first), and B should have an A reference.
+ * @throws InvalidSyntaxException
*/
@Test
- public void test_A11_B01_immediate_B_first()
+ public void test_A11_B01_immediate_B_first() throws InvalidSyntaxException
{
String componentNameA = "6.A.1.1.dynamic";
- final Component componentA = findComponentByName( componentNameA );
- TestCase.assertNotNull( componentA );
- TestCase.assertEquals( Component.STATE_ACTIVE, componentA.getState() );
- A a = ( A ) componentA.getComponentInstance().getInstance();
+ final ComponentConfigurationDTO componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.ACTIVE );
+ A a = getServiceFromConfiguration(componentA, A.class);
assertEquals( 1, a.getBs().size());
String componentNameB = "6.B.0.1.dynamic";
- final Component componentB = findComponentByName( componentNameB );
- TestCase.assertNotNull( componentB );
- TestCase.assertEquals( Component.STATE_ACTIVE, componentB.getState() );
- B b = ( B ) componentB.getComponentInstance().getInstance();
+ final ComponentConfigurationDTO componentB = findComponentConfigurationByName( componentNameB, ComponentConfigurationDTO.ACTIVE );
+ B b = getServiceFromConfiguration(componentB, B.class);
assertEquals( 1, b.getAs().size() );
}
/**
@@ -238,14 +213,10 @@
public void test_A11_B01_delayed_A_first() throws InvalidSyntaxException
{
String componentNameA = "7.A.1.1.dynamic";
- final Component componentA = findComponentByName( componentNameA );
- TestCase.assertNotNull( componentA );
- TestCase.assertEquals( Component.STATE_REGISTERED, componentA.getState() );
+ final ComponentConfigurationDTO componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.SATISFIED );
String componentNameB = "7.B.0.1.dynamic";
- final Component componentB = findComponentByName( componentNameB );
- TestCase.assertNotNull( componentB );
- TestCase.assertEquals( Component.STATE_REGISTERED, componentB.getState() );
+ final ComponentConfigurationDTO componentB = findComponentConfigurationByName( componentNameB, ComponentConfigurationDTO.SATISFIED );
ServiceReference[] serviceReferences = bundleContext.getServiceReferences( A.class.getName(), "(service.pid=" + componentNameA + ")" );
TestCase.assertEquals( 1, serviceReferences.length );
@@ -254,9 +225,9 @@
assertNotNull( service );
delay();
- A a = ( A ) componentA.getComponentInstance().getInstance();
- assertEquals( 1, a.getBs().size() );
- B b = ( B ) componentB.getComponentInstance().getInstance();
+ A a = getServiceFromConfiguration(componentA, A.class);
+ assertEquals( 1, a.getBs().size());
+ B b = getServiceFromConfiguration(componentB, B.class);
assertEquals( 1, b.getAs().size() );
}
/**
@@ -266,14 +237,10 @@
public void test_A11_B01_delayed_B_first() throws InvalidSyntaxException
{
String componentNameA = "7.A.1.1.dynamic";
- final Component componentA = findComponentByName( componentNameA );
- TestCase.assertNotNull( componentA );
- TestCase.assertEquals( Component.STATE_REGISTERED, componentA.getState() );
+ final ComponentConfigurationDTO componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.SATISFIED );
String componentNameB = "7.B.0.1.dynamic";
- final Component componentB = findComponentByName( componentNameB );
- TestCase.assertNotNull( componentB );
- TestCase.assertEquals( Component.STATE_REGISTERED, componentB.getState() );
+ final ComponentConfigurationDTO componentB = findComponentConfigurationByName( componentNameB, ComponentConfigurationDTO.SATISFIED );
ServiceReference[] serviceReferencesB = bundleContext.getServiceReferences( B.class.getName(), "(service.pid=" + componentNameB + ")" );
TestCase.assertEquals( 1, serviceReferencesB.length );
@@ -289,28 +256,28 @@
delay();
- A a = ( A ) componentA.getComponentInstance().getInstance();
- assertEquals( 1, a.getBs().size() );
- B b = ( B ) componentB.getComponentInstance().getInstance();
+ A a = getServiceFromConfiguration(componentA, A.class);
+ assertEquals( 1, a.getBs().size());
+ B b = getServiceFromConfiguration(componentB, B.class);
assertEquals( 1, b.getAs().size() );
//disabling (removing the A service registration) and re-enabling will
//result in a service event to B, so B will bind A.
- componentA.disable();
+ disableAndCheck(componentA);
delay();
- componentA.enable();
+ enableAndCheck(componentA.description);
delay();
- ServiceReference[] serviceReferencesA1 = bundleContext.getServiceReferences( A.class.getName(), "(service.pid=" + componentNameA + ")" );
- TestCase.assertEquals( 1, serviceReferencesA1.length );
- ServiceReference serviceReferenceA1 = serviceReferencesA1[0];
- Object serviceA1 = bundleContext.getService( serviceReferenceA1 );
- assertNotNull( serviceA1 );
+// ServiceReference[] serviceReferencesA1 = bundleContext.getServiceReferences( A.class.getName(), "(service.pid=" + componentNameA + ")" );
+// TestCase.assertEquals( 1, serviceReferencesA1.length );
+// ServiceReference serviceReferenceA1 = serviceReferencesA1[0];
+// Object serviceA1 = bundleContext.getService( serviceReferenceA1 );
+// assertNotNull( serviceA1 );
- A a1 = ( A ) componentA.getComponentInstance().getInstance();
- assertEquals( 1, a1.getBs().size() );
- B b1 = ( B ) componentB.getComponentInstance().getInstance();
- assertEquals( 1, b1.getAs().size() );
+ a = getServiceFromConfiguration(componentA, A.class);
+ assertEquals( 1, a.getBs().size());
+ b = getServiceFromConfiguration(componentB, B.class);
+ assertEquals( 1, b.getAs().size() );
}
}
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ComponentActivationTest.java b/scr/src/test/java/org/apache/felix/scr/integration/ComponentActivationTest.java
index db5bb84..7123198 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/ComponentActivationTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ComponentActivationTest.java
@@ -21,14 +21,13 @@
import junit.framework.TestCase;
-import org.apache.felix.scr.Component;
import org.apache.felix.scr.integration.components.ActivatorComponent;
-import org.apache.felix.scr.integration.components.SimpleService;
import org.apache.felix.scr.integration.components.SimpleServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
@RunWith(JUnit4TestRunner.class)
@@ -50,47 +49,21 @@
{
final String componentname = "ActivatorComponent.no.decl";
- final Component component = findComponentByName( componentname );
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.ACTIVE);
- TestCase.assertNotNull( component );
- TestCase.assertFalse( component.isDefaultEnabled() );
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
-
- component.disable();
-
- delay();
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+ disableAndCheck( cc );
}
-// @Test I think this test is wrong. Failure to activate does not mean that the state changes from Registered.
+ @Test //Changed to expect SATISFIED rather than unsatisfied
public void test_activate_missing()
{
final String componentname = "ActivatorComponent.activate.missing";
- final Component component = findComponentByName( componentname );
+ // activate must fail, so state remains SATISFIED
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.SATISFIED);
- TestCase.assertNotNull( component );
- TestCase.assertFalse( component.isDefaultEnabled() );
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
- component.enable();
- delay();
-
- // activate must fail
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
-
- component.disable();
-
- delay();
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+ disableAndCheck( cc );
}
@@ -99,22 +72,9 @@
{
final String componentname = "ActivatorComponent.deactivate.missing";
- final Component component = findComponentByName( componentname );
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.ACTIVE);
- TestCase.assertNotNull( component );
- TestCase.assertFalse( component.isDefaultEnabled() );
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
-
- component.disable();
-
- delay();
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+ disableAndCheck( cc );
}
@@ -123,47 +83,21 @@
{
final String componentname = "ActivatorComponent.decl";
- final Component component = findComponentByName( componentname );
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.ACTIVE);
- TestCase.assertNotNull( component );
- TestCase.assertFalse( component.isDefaultEnabled() );
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
-
- component.disable();
-
- delay();
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+ disableAndCheck( cc );
}
-// @Test Failure to activate does not mean the state should change to unsatisfied.
+ @Test // Failure to activate does not mean the state should change to unsatisfied.
public void test_activate_fail()
{
final String componentname = "ActivatorComponent.activate.fail";
- final Component component = findComponentByName( componentname );
+ // activate must fail, so state remains SATISFIED
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.SATISFIED);
- TestCase.assertNotNull( component );
- TestCase.assertFalse( component.isDefaultEnabled() );
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
- component.enable();
- delay();
-
- // activate has failed
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
-
- component.disable();
-
- delay();
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+ disableAndCheck( cc );
}
@@ -172,22 +106,9 @@
{
final String componentname = "ActivatorComponent.deactivate.fail";
- final Component component = findComponentByName( componentname );
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.ACTIVE);
- TestCase.assertNotNull( component );
- TestCase.assertFalse( component.isDefaultEnabled() );
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
-
- component.disable();
-
- delay();
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+ disableAndCheck( cc );
}
@@ -196,25 +117,14 @@
{
final String componentname = "ActivatorComponent.activate.with.bind";
- final Component component = findComponentByName( componentname );
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.ACTIVE);
- TestCase.assertNotNull( component );
- TestCase.assertFalse( component.isDefaultEnabled() );
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
-
- ActivatorComponent ac = (ActivatorComponent) component.getComponentInstance().getInstance();
+ ActivatorComponent ac = ActivatorComponent.getInstance();
TestCase.assertNotNull( ac.getSimpleService() );
-
- component.disable();
-
- delay();
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+
+ disableAndCheck( cc );
+
+ TestCase.assertNull( ac.getSimpleService() );
}
@@ -223,28 +133,13 @@
{
final String componentname = "ActivatorComponent.activate.delayed.with.bind";
- final Component component = findComponentByName( componentname );
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.SATISFIED);
- TestCase.assertNotNull( component );
- TestCase.assertFalse( component.isDefaultEnabled() );
+ getServiceFromConfiguration(cc, ActivatorComponent.class);
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+ findComponentConfigurationByName(componentname, ComponentConfigurationDTO.ACTIVE);
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_REGISTERED, component.getState() );
-
- ServiceReference<ActivatorComponent> ref = bundleContext.getServiceReference( ActivatorComponent.class );
- ActivatorComponent ac = bundleContext.getService( ref );
- TestCase.assertNotNull( ac.getSimpleService() );
-
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
-
- component.disable();
-
- delay();
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+ disableAndCheck( cc );
}
@Test
@@ -252,28 +147,13 @@
{
final String componentname = "ActivatorComponent.activate.service.factory.with.bind";
- final Component component = findComponentByName( componentname );
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.SATISFIED);
- TestCase.assertNotNull( component );
- TestCase.assertFalse( component.isDefaultEnabled() );
+ getServiceFromConfiguration(cc, ActivatorComponent.class);
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+ findComponentConfigurationByName(componentname, ComponentConfigurationDTO.ACTIVE);
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_REGISTERED, component.getState() );
-
- ServiceReference<ActivatorComponent> ref = bundleContext.getServiceReference( ActivatorComponent.class );
- ActivatorComponent ac = bundleContext.getService( ref );
- TestCase.assertNotNull( ac.getSimpleService() );
-
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
-
- component.disable();
-
- delay();
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+ disableAndCheck( cc );
}
@Test
@@ -319,26 +199,17 @@
private void testRequiredDependency(final String componentname)
{
- final Component component = findComponentByName( componentname );
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.UNSATISFIED);
- TestCase.assertNotNull( component );
- TestCase.assertFalse( component.isDefaultEnabled() );
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
-
SimpleServiceImpl ss = SimpleServiceImpl.create( bundleContext, "foo" );
- TestCase.assertEquals( Component.STATE_REGISTERED, component.getState() );
+ findComponentConfigurationByName(componentname, ComponentConfigurationDTO.SATISFIED);
ServiceReference<ActivatorComponent> ref = bundleContext.getServiceReference( ActivatorComponent.class );
ss.drop();
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ findComponentConfigurationByName(componentname, ComponentConfigurationDTO.UNSATISFIED);
+
TestCase.assertNull(bundleContext.getServiceReference( ActivatorComponent.class ));
ss = SimpleServiceImpl.create( bundleContext, "foo" );
@@ -346,12 +217,10 @@
ActivatorComponent ac = bundleContext.getService( ref );
TestCase.assertNotNull( ac.getSimpleService() );
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(componentname, ComponentConfigurationDTO.ACTIVE);
- component.disable();
- delay();
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+ disableAndCheck( cc );
}
}
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ComponentConcurrencyTest.java b/scr/src/test/java/org/apache/felix/scr/integration/ComponentConcurrencyTest.java
index 1569bd3..4d0a7c5 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/ComponentConcurrencyTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ComponentConcurrencyTest.java
@@ -16,11 +16,11 @@
import junit.framework.TestCase;
-import org.apache.felix.scr.Component;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.framework.BundleContext;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
@RunWith(JUnit4TestRunner.class)
public class ComponentConcurrencyTest extends ComponentTestBase
@@ -52,15 +52,8 @@
{
- final Component AFactory =
- findComponentByName( "org.apache.felix.scr.integration.components.concurrency.AFactory" );
- TestCase.assertNotNull( AFactory );
- AFactory.enable();
-
- final Component CFactory =
- findComponentByName( "org.apache.felix.scr.integration.components.concurrency.CFactory" );
- TestCase.assertNotNull( CFactory );
- CFactory.enable();
+ ComponentConfigurationDTO ccA = getDisabledConfigurationAndEnable( "org.apache.felix.scr.integration.components.concurrency.AFactory", ComponentConfigurationDTO.ACTIVE );
+ ComponentConfigurationDTO ccC = getDisabledConfigurationAndEnable( "org.apache.felix.scr.integration.components.concurrency.CFactory", ComponentConfigurationDTO.ACTIVE );
delay( 30 );
for ( Iterator it = log.foundWarnings().iterator(); it.hasNext();)
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationPidTest.java b/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationPidTest.java
index 906db4f..98653d8 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationPidTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationPidTest.java
@@ -21,11 +21,12 @@
import junit.framework.TestCase;
-import org.apache.felix.scr.Component;
import org.apache.felix.scr.integration.components.SimpleComponent;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
+import org.osgi.service.component.runtime.dto.ComponentDescriptionDTO;
@RunWith(JUnit4TestRunner.class)
@@ -43,40 +44,28 @@
{
final String pid = "ConfigurationPid.otherPid";
final String name = "ConfigurationPid.componentName";
- final Component component = findComponentByName( name );
-
deleteConfig( pid );
delay();
-
- TestCase.assertNotNull( component );
- TestCase.assertFalse( component.isDefaultEnabled() );
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
TestCase.assertNull( SimpleComponent.INSTANCE );
- component.enable();
- delay();
+ getConfigurationsDisabledThenEnable(name, 0, ComponentConfigurationDTO.UNSATISFIED);
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
TestCase.assertNull( SimpleComponent.INSTANCE );
configure( pid );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName( name, ComponentConfigurationDTO.ACTIVE);
TestCase.assertNotNull( SimpleComponent.INSTANCE );
TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
deleteConfig( pid );
delay();
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ ComponentDescriptionDTO cd = checkConfigurationCount(name, 0, -1);
TestCase.assertNull( SimpleComponent.INSTANCE );
- component.disable();
- delay();
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+ disableAndCheck( cd );
TestCase.assertNull( SimpleComponent.INSTANCE );
}
@@ -85,29 +74,21 @@
{
final String name = "ConfigurationPid.componentName";
final String pid = name;
- final Component component = findComponentByName( name );
-
deleteConfig( pid );
delay();
- TestCase.assertNotNull( component );
- TestCase.assertFalse( component.isDefaultEnabled() );
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
- TestCase.assertNull( SimpleComponent.INSTANCE );
-
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ getConfigurationsDisabledThenEnable(name, 0, ComponentConfigurationDTO.UNSATISFIED);
TestCase.assertNull( SimpleComponent.INSTANCE );
configure( pid );
delay();
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ ComponentDescriptionDTO cd = checkConfigurationCount(name, 0, -1);
+ TestCase.assertNull( SimpleComponent.INSTANCE );
deleteConfig( pid );
delay();
+
+ disableAndCheck( cd );
}
}
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java b/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java
index 6483df3..7393cbe 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java
@@ -19,6 +19,9 @@
package org.apache.felix.scr.integration;
+import java.util.Collection;
+
+import junit.framework.Assert;
import junit.framework.TestCase;
import org.apache.felix.scr.Component;
@@ -28,6 +31,7 @@
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.framework.Constants;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
@RunWith(JUnit4TestRunner.class)
@@ -44,42 +48,31 @@
public void test_SimpleComponent_configuration_ignore()
{
final String pid = "SimpleComponent.configuration.ignore";
- final Component component = findComponentByName( pid );
+ TestCase.assertNull( SimpleComponent.INSTANCE );
deleteConfig( pid );
delay();
- TestCase.assertNotNull( component );
- TestCase.assertFalse( component.isDefaultEnabled() );
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
- TestCase.assertNull( SimpleComponent.INSTANCE );
-
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.ACTIVE);
+
TestCase.assertNotNull( SimpleComponent.INSTANCE );
TestCase.assertNull( SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
configure( pid );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertNotNull( SimpleComponent.INSTANCE );
TestCase.assertNull( SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
deleteConfig( pid );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertNotNull( SimpleComponent.INSTANCE );
TestCase.assertNull( SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
- component.disable();
- delay();
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+ disableAndCheck( cc );
TestCase.assertNull( SimpleComponent.INSTANCE );
}
@@ -88,22 +81,9 @@
public void test_SimpleComponent_configuration_optional()
{
final String pid = "SimpleComponent.configuration.optional";
- final Component component = findComponentByName( pid );
-
- deleteConfig( pid );
- delay();
-
- TestCase.assertNotNull( component );
- TestCase.assertFalse( component.isDefaultEnabled() );
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
- TestCase.assertNull( SimpleComponent.INSTANCE );
-
- component.enable();
- delay();
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent firstInstance = SimpleComponent.INSTANCE;
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
TestCase.assertNotNull( firstInstance );
TestCase.assertNull( firstInstance.getProperty( PROP_NAME ) );
@@ -111,7 +91,7 @@
delay();
final SimpleComponent secondInstance = SimpleComponent.INSTANCE;
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertNotNull( secondInstance );
TestCase.assertEquals( PROP_NAME, secondInstance.getProperty( PROP_NAME ) );
@@ -119,7 +99,7 @@
delay();
final SimpleComponent thirdInstance = SimpleComponent.INSTANCE;
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertNotNull( thirdInstance );
TestCase.assertNull( thirdInstance.getProperty( PROP_NAME ) );
@@ -129,10 +109,7 @@
TestCase.assertNotSame( "Expect new instance object after configuration deletion (2)", secondInstance,
thirdInstance );
- component.disable();
- delay();
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+ disableAndCheck( cc );
TestCase.assertNull( SimpleComponent.INSTANCE );
}
@@ -141,40 +118,29 @@
public void test_SimpleComponent_configuration_require()
{
final String pid = "SimpleComponent.configuration.require";
- final Component component = findComponentByName( pid );
deleteConfig( pid );
delay();
-
- TestCase.assertNotNull( component );
- TestCase.assertFalse( component.isDefaultEnabled() );
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+
TestCase.assertNull( SimpleComponent.INSTANCE );
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ getConfigurationsDisabledThenEnable(pid, 0, ComponentConfigurationDTO.UNSATISFIED);
TestCase.assertNull( SimpleComponent.INSTANCE );
configure( pid );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ ComponentConfigurationDTO cc = findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertNotNull( SimpleComponent.INSTANCE );
TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
deleteConfig( pid );
delay();
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ checkConfigurationCount(pid, 0, -1);
TestCase.assertNull( SimpleComponent.INSTANCE );
- component.disable();
- delay();
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+ disableAndCheck( cc );
TestCase.assertNull( SimpleComponent.INSTANCE );
}
@@ -205,21 +171,11 @@
private void dynamicConfigTest(final String pid, boolean pre13) {
- final Component component = findComponentByName( pid );
-
deleteConfig( pid );
delay();
- TestCase.assertNotNull( component );
- TestCase.assertFalse( component.isDefaultEnabled() );
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.ACTIVE);
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
- TestCase.assertNull( SimpleComponent.INSTANCE );
-
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
TestCase.assertNotNull( SimpleComponent.INSTANCE );
TestCase.assertNull( SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
TestCase.assertEquals( pid, SimpleComponent.INSTANCE.getProperty( Constants.SERVICE_PID ) );
@@ -229,7 +185,7 @@
configure( pid );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertEquals( instance, SimpleComponent.INSTANCE );
TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
TestCase.assertEquals( pid, SimpleComponent.INSTANCE.getProperty( Constants.SERVICE_PID ) );
@@ -237,7 +193,7 @@
deleteConfig( pid );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
if (pre13)
{
TestCase.assertNotSame( instance, SimpleComponent.INSTANCE );
@@ -249,16 +205,13 @@
TestCase.assertNull( SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
TestCase.assertEquals( pid, SimpleComponent.INSTANCE.getProperty( Constants.SERVICE_PID ) );
- component.disable();
- delay();
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+ disableAndCheck( cc );
TestCase.assertNull( SimpleComponent.INSTANCE );
}
@Test
- public void test_SimpleComponent_dynamic_configuration_with_required_service()
+ public void test_SimpleComponent_dynamic_optional_configuration_with_required_service()
{
final String targetProp = "ref.target";
final String filterProp = "required";
@@ -266,36 +219,25 @@
try
{
final String pid = "DynamicConfigurationComponentWithRequiredReference";
- final Component component = findComponentByName( pid );
-
deleteConfig( pid );
delay();
- TestCase.assertNotNull( component );
- TestCase.assertFalse( component.isDefaultEnabled() );
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
- TestCase.assertNull( SimpleComponent.INSTANCE );
-
- component.enable();
- delay();
-
// mandatory ref missing --> component unsatisfied
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.UNSATISFIED);
// dynamically configure without the correct target
configure( pid );
delay();
// mandatory ref missing --> component unsatisfied
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.UNSATISFIED);
// dynamically configure with correct target
theConfig.put( targetProp, "(filterprop=" + filterProp + ")" );
configure( pid );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertNotNull( SimpleComponent.INSTANCE );
TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
TestCase.assertEquals( pid, SimpleComponent.INSTANCE.getProperty( Constants.SERVICE_PID ) );
@@ -306,7 +248,7 @@
delay();
// same instance after reconfiguration
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertEquals( instance, SimpleComponent.INSTANCE );
TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
TestCase.assertEquals( pid, SimpleComponent.INSTANCE.getProperty( Constants.SERVICE_PID ) );
@@ -318,18 +260,15 @@
delay();
// mandatory ref missing --> component unsatisfied
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.UNSATISFIED);
deleteConfig( pid );
delay();
// mandatory ref missing --> component unsatisfied
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.UNSATISFIED);
- component.disable();
- delay();
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+ disableAndCheck(cc);
TestCase.assertNull( SimpleComponent.INSTANCE );
}
finally
@@ -347,7 +286,7 @@
* to (still) match the other one. 2nd service should remain bound.
*/
@Test
- public void test_SimpleComponent_dynamic_configuration_with_required_service2()
+ public void test_SimpleComponent_dynamic_optional_configuration_with_required_service2()
{
final String targetProp = "ref.target";
final String filterProp1 = "one";
@@ -357,36 +296,25 @@
try
{
final String pid = "DynamicConfigurationComponentWithRequiredReference";
- final Component component = findComponentByName( pid );
-
deleteConfig( pid );
delay();
- TestCase.assertNotNull( component );
- TestCase.assertFalse( component.isDefaultEnabled() );
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
- TestCase.assertNull( SimpleComponent.INSTANCE );
-
- component.enable();
- delay();
-
// mandatory ref missing --> component unsatisfied
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.UNSATISFIED);
// dynamically configure without the correct target
configure( pid );
delay();
// mandatory ref missing --> component unsatisfied
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.UNSATISFIED);
// dynamically configure with correct target
theConfig.put( targetProp, "(|(filterprop=" + filterProp1 + ")(filterprop=" + filterProp2 + "))" );
configure( pid );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertNotNull( SimpleComponent.INSTANCE );
TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
TestCase.assertEquals( pid, SimpleComponent.INSTANCE.getProperty( Constants.SERVICE_PID ) );
@@ -402,7 +330,7 @@
service2.drop();
}
// same instance after reconfiguration
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertEquals( instance, SimpleComponent.INSTANCE );
TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
TestCase.assertEquals( pid, SimpleComponent.INSTANCE.getProperty( Constants.SERVICE_PID ) );
@@ -414,7 +342,7 @@
delay();
// same instance after reconfiguration
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertEquals( instance, SimpleComponent.INSTANCE );
TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
TestCase.assertEquals( pid, SimpleComponent.INSTANCE.getProperty( Constants.SERVICE_PID ) );
@@ -424,12 +352,9 @@
delay();
// mandatory ref missing --> component unsatisfied
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.UNSATISFIED);
- component.disable();
- delay();
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+ disableAndCheck(cc);
TestCase.assertNull( SimpleComponent.INSTANCE );
}
finally
@@ -443,7 +368,7 @@
}
@Test
- public void test_SimpleComponent_dynamic_configuration_with_optional_service() throws Exception
+ public void test_SimpleComponent_dynamic_optional_configuration_with_optional_service() throws Exception
{
final String targetProp = "ref.target";
final String filterProp = "required";
@@ -451,22 +376,12 @@
try
{
final String pid = "DynamicConfigurationComponentWithOptionalReference";
- final Component component = findComponentByName( pid );
-
deleteConfig( pid );
delay();
- TestCase.assertNotNull( component );
- TestCase.assertFalse( component.isDefaultEnabled() );
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
- TestCase.assertNull( SimpleComponent.INSTANCE );
-
- component.enable();
- delay();
-
// optional ref missing --> component active
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.ACTIVE);
+
TestCase.assertNotNull( SimpleComponent.INSTANCE );
final SimpleComponent instance = SimpleComponent.INSTANCE;
@@ -475,7 +390,7 @@
delay();
// optional ref missing --> component active
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertEquals( instance, SimpleComponent.INSTANCE );
TestCase.assertNull( SimpleComponent.INSTANCE.m_singleRef );
@@ -484,7 +399,7 @@
configure( pid );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertEquals( instance, SimpleComponent.INSTANCE );
TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
TestCase.assertEquals( pid, SimpleComponent.INSTANCE.getProperty( Constants.SERVICE_PID ) );
@@ -494,7 +409,7 @@
delay();
// same instance after reconfiguration
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertEquals( instance, SimpleComponent.INSTANCE );
TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
TestCase.assertEquals( pid, SimpleComponent.INSTANCE.getProperty( Constants.SERVICE_PID ) );
@@ -506,7 +421,7 @@
delay();
// optional ref missing --> component active
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertEquals( instance, SimpleComponent.INSTANCE );
TestCase.assertNull( SimpleComponent.INSTANCE.m_singleRef );
@@ -514,14 +429,11 @@
delay();
// optional ref missing --> component active
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertNotSame( instance, SimpleComponent.INSTANCE );
TestCase.assertNull( SimpleComponent.INSTANCE.m_singleRef );
- component.disable();
- delay();
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+ disableAndCheck(cc);
TestCase.assertNull( SimpleComponent.INSTANCE );
}
finally
@@ -544,21 +456,7 @@
deleteFactoryConfigurations( factoryPid );
delay();
- // one single component exists without configuration
- final Component[] noConfigurations = findComponentsByName( factoryPid );
- TestCase.assertNotNull( noConfigurations );
- TestCase.assertEquals( 1, noConfigurations.length );
- TestCase.assertEquals( Component.STATE_DISABLED, noConfigurations[0].getState() );
- TestCase.assertTrue( SimpleComponent.INSTANCES.isEmpty() );
-
- // enable the component, configuration required, hence unsatisfied
- noConfigurations[0].enable();
- delay();
-
- final Component[] enabledNoConfigs = findComponentsByName( factoryPid );
- TestCase.assertNotNull( enabledNoConfigs );
- TestCase.assertEquals( 1, enabledNoConfigs.length );
- TestCase.assertEquals( Component.STATE_UNSATISFIED, enabledNoConfigs[0].getState() );
+ getConfigurationsDisabledThenEnable(factoryPid, 0, -1);
TestCase.assertTrue( SimpleComponent.INSTANCES.isEmpty() );
// create two factory configurations expecting two components
@@ -566,71 +464,85 @@
final String pid1 = createFactoryConfiguration( factoryPid );
delay();
- // expect two components, only first is active, second is disabled
- final Component[] twoConfigs = findComponentsByName( factoryPid );
- TestCase.assertNotNull( twoConfigs );
- TestCase.assertEquals( 2, twoConfigs.length );
-
- // find the active and inactive configs, fail if none
- int activeConfig;
- int inactiveConfig;
- if ( twoConfigs[0].getState() == Component.STATE_ACTIVE )
- {
- // [0] is active, [1] expected disabled
- activeConfig = 0;
- inactiveConfig = 1;
- }
- else if ( twoConfigs[1].getState() == Component.STATE_ACTIVE )
- {
- // [1] is active, [0] expected disabled
- activeConfig = 1;
- inactiveConfig = 0;
- }
- else
- {
- TestCase.fail( "One of two components expected active" );
- return; // eases the compiler...
- }
-
- TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[activeConfig].getState() );
- TestCase.assertEquals( Component.STATE_DISABLED, twoConfigs[inactiveConfig].getState() );
- TestCase.assertEquals( 1, SimpleComponent.INSTANCES.size() );
- TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[activeConfig].getId() ) );
- TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( twoConfigs[inactiveConfig].getId() ) );
-
- // enable second component
- twoConfigs[inactiveConfig].enable();
- delay();
-
- // ensure both components active
- TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[0].getState() );
- TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[1].getState() );
- TestCase.assertEquals( 2, SimpleComponent.INSTANCES.size() );
- TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[0].getId() ) );
- TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[1].getId() ) );
+ // expect two active components, //TODO WTF?? only first is active, second is disabled
+ checkConfigurationCount(factoryPid, 2, ComponentConfigurationDTO.ACTIVE);
+// Collection<ComponentConfigurationDTO> ccs = findComponentConfigurationsByName(factoryPid);
+// Assert.assertEquals(2, ccs.size());
+//
+// ComponentConfigurationDTO activ e= null;
+// ComponentConfigurationDTO inactive = null;
+//
+// for (ComponentConfigurationDTO cc: ccs)
+// {
+// if (ComponentConfigurationDTO.ACTIVE == cc.state)
+// {
+// if
+// }
+// }
+//
+// // find the active and inactive configs, fail if none
+// int activeConfig;
+// int inactiveConfig;
+// if ( twoConfigs[0].getState() == Component.STATE_ACTIVE )
+// {
+// // [0] is active, [1] expected disabled
+// activeConfig = 0;
+// inactiveConfig = 1;
+// }
+// else if ( twoConfigs[1].getState() == Component.STATE_ACTIVE )
+// {
+// // [1] is active, [0] expected disabled
+// activeConfig = 1;
+// inactiveConfig = 0;
+// }
+// else
+// {
+// TestCase.fail( "One of two components expected active" );
+// return; // eases the compiler...
+// }
+//
+// TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[activeConfig].getState() );
+// TestCase.assertEquals( Component.STATE_DISABLED, twoConfigs[inactiveConfig].getState() );
+// TestCase.assertEquals( 1, SimpleComponent.INSTANCES.size() );
+// TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[activeConfig].getId() ) );
+// TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( twoConfigs[inactiveConfig].getId() ) );
+//
+// // enable second component
+// twoConfigs[inactiveConfig].enable();
+// delay();
+//
+// // ensure both components active
+// TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[0].getState() );
+// TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[1].getState() );
+// TestCase.assertEquals( 2, SimpleComponent.INSTANCES.size() );
+// TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[0].getId() ) );
+// TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[1].getId() ) );
// delete a configuration
deleteConfig( pid0 );
delay();
// expect one component
- final Component[] oneConfig = findComponentsByName( factoryPid );
- TestCase.assertNotNull( oneConfig );
- TestCase.assertEquals( 1, oneConfig.length );
- TestCase.assertEquals( Component.STATE_ACTIVE, oneConfig[0].getState() );
- TestCase.assertEquals( 1, SimpleComponent.INSTANCES.size() );
- TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( oneConfig[0].getId() ) );
+ checkConfigurationCount(factoryPid, 1, ComponentConfigurationDTO.ACTIVE);
+// final Component[] oneConfig = findComponentConfigurationsByName( factoryPid );
+// TestCase.assertNotNull( oneConfig );
+// TestCase.assertEquals( 1, oneConfig.length );
+// TestCase.assertEquals( Component.STATE_ACTIVE, oneConfig[0].getState() );
+// TestCase.assertEquals( 1, SimpleComponent.INSTANCES.size() );
+// TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( oneConfig[0].getId() ) );
// delete second configuration
deleteConfig( pid1 );
delay();
+ checkConfigurationCount(factoryPid, 0, ComponentConfigurationDTO.ACTIVE);
// expect a single unsatisfied component
- final Component[] configsDeleted = findComponentsByName( factoryPid );
- TestCase.assertNotNull( configsDeleted );
- TestCase.assertEquals( 1, configsDeleted.length );
- TestCase.assertEquals( Component.STATE_UNSATISFIED, configsDeleted[0].getState() );
- TestCase.assertEquals( 0, SimpleComponent.INSTANCES.size() );
+// final Component[] configsDeleted = findComponentConfigurationsByName( factoryPid );
+// TestCase.assertNotNull( configsDeleted );
+// TestCase.assertEquals( 1, configsDeleted.length );
+// TestCase.assertEquals( Component.STATE_UNSATISFIED, configsDeleted[0].getState() );
+// TestCase.assertEquals( 0, SimpleComponent.INSTANCES.size() );
+// disableAndCheck(cd); //TODO needed??
}
@Test
@@ -641,12 +553,8 @@
deleteFactoryConfigurations( factoryPid );
delay();
- // one single component exists without configuration
- final Component[] enabledNoConfigs = findComponentsByName( factoryPid );
- TestCase.assertNotNull( enabledNoConfigs );
- TestCase.assertEquals( 1, enabledNoConfigs.length );
- TestCase.assertEquals( Component.STATE_UNSATISFIED, enabledNoConfigs[0].getState() );
- TestCase.assertTrue( SimpleComponent.INSTANCES.isEmpty() );
+ checkConfigurationCount(factoryPid, 0, ComponentConfigurationDTO.ACTIVE);
+ // no component config exists without configuration
// create two factory configurations expecting two components
final String pid0 = createFactoryConfiguration( factoryPid );
@@ -654,76 +562,74 @@
delay();
// expect two components, all active
- final Component[] twoConfigs = findComponentsByName( factoryPid );
- TestCase.assertNotNull( twoConfigs );
- TestCase.assertEquals( 2, twoConfigs.length );
- TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[0].getState() );
- TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[1].getState() );
- TestCase.assertEquals( 2, SimpleComponent.INSTANCES.size() );
- TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[0].getId() ) );
- TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[1].getId() ) );
+ checkConfigurationCount(factoryPid, 2, ComponentConfigurationDTO.ACTIVE);
// disable the name component
- SimpleComponent.INSTANCES.values().iterator().next().m_activateContext.disableComponent( factoryPid );
+ disableAndCheck( factoryPid );
delay();
- // expect two disabled components
- final Component[] twoConfigsDisabled = findComponentsByName( factoryPid );
- TestCase.assertNotNull( twoConfigsDisabled );
- TestCase.assertEquals( 2, twoConfigsDisabled.length );
- TestCase.assertEquals( Component.STATE_DISABLED, twoConfigsDisabled[0].getState() );
- TestCase.assertEquals( Component.STATE_DISABLED, twoConfigsDisabled[1].getState() );
- TestCase.assertEquals( 0, SimpleComponent.INSTANCES.size() );
- TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( twoConfigs[0].getId() ) );
- TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( twoConfigs[1].getId() ) );
+ // expect no XXtwo disabled components
+// checkConfigurationCount(factoryPid, 0, ComponentConfigurationDTO.ACTIVE);
+// final Component[] twoConfigsDisabled = findComponentConfigurationsByName( factoryPid );
+// TestCase.assertNotNull( twoConfigsDisabled );
+// TestCase.assertEquals( 2, twoConfigsDisabled.length );
+// TestCase.assertEquals( Component.STATE_DISABLED, twoConfigsDisabled[0].getState() );
+// TestCase.assertEquals( Component.STATE_DISABLED, twoConfigsDisabled[1].getState() );
+// TestCase.assertEquals( 0, SimpleComponent.INSTANCES.size() );
+// TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( twoConfigs[0].getId() ) );
+// TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( twoConfigs[1].getId() ) );
// create a configuration
final String pid3 = createFactoryConfiguration( factoryPid );
delay();
// expect three disabled components
- final Component[] threeConfigsDisabled = findComponentsByName( factoryPid );
- TestCase.assertNotNull( threeConfigsDisabled );
- TestCase.assertEquals( 3, threeConfigsDisabled.length );
- TestCase.assertEquals( Component.STATE_DISABLED, threeConfigsDisabled[0].getState() );
- TestCase.assertEquals( Component.STATE_DISABLED, threeConfigsDisabled[1].getState() );
- TestCase.assertEquals( Component.STATE_DISABLED, threeConfigsDisabled[2].getState() );
- TestCase.assertEquals( 0, SimpleComponent.INSTANCES.size() );
- TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( threeConfigsDisabled[0].getId() ) );
- TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( threeConfigsDisabled[1].getId() ) );
- TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( threeConfigsDisabled[2].getId() ) );
-
- // enable a single component (to get ComponentContext later)
- threeConfigsDisabled[0].enable();
- delay();
-
- // expect one enabled and two disabled components
- final Component[] threeConfigs21 = findComponentsByName( factoryPid );
- TestCase.assertNotNull( threeConfigs21 );
- TestCase.assertEquals( 3, threeConfigs21.length );
- TestCase.assertEquals( 1, SimpleComponent.INSTANCES.size() );
- TestCase.assertEquals( Component.STATE_ACTIVE, threeConfigs21[0].getState() );
- TestCase.assertEquals( Component.STATE_DISABLED, threeConfigs21[1].getState() );
- TestCase.assertEquals( Component.STATE_DISABLED, threeConfigs21[2].getState() );
- TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( threeConfigs21[0].getId() ) );
- TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( threeConfigs21[1].getId() ) );
- TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( threeConfigs21[2].getId() ) );
-
- // enable all components now
- SimpleComponent.INSTANCES.values().iterator().next().m_activateContext.enableComponent( factoryPid );
- delay();
-
- // expect all enabled
- final Component[] threeConfigsEnabled = findComponentsByName( factoryPid );
- TestCase.assertNotNull( threeConfigsEnabled );
- TestCase.assertEquals( 3, threeConfigsEnabled.length );
- TestCase.assertEquals( Component.STATE_ACTIVE, threeConfigsEnabled[0].getState() );
- TestCase.assertEquals( Component.STATE_ACTIVE, threeConfigsEnabled[1].getState() );
- TestCase.assertEquals( Component.STATE_ACTIVE, threeConfigsEnabled[2].getState() );
- TestCase.assertEquals( 3, SimpleComponent.INSTANCES.size() );
- TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( threeConfigsEnabled[0].getId() ) );
- TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( threeConfigsEnabled[1].getId() ) );
- TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( threeConfigsEnabled[2].getId() ) );
+// checkConfigurationCount(factoryPid, 0, ComponentConfigurationDTO.ACTIVE);
+// final Component[] threeConfigsDisabled = findComponentConfigurationsByName( factoryPid );
+// TestCase.assertNotNull( threeConfigsDisabled );
+// TestCase.assertEquals( 3, threeConfigsDisabled.length );
+// TestCase.assertEquals( Component.STATE_DISABLED, threeConfigsDisabled[0].getState() );
+// TestCase.assertEquals( Component.STATE_DISABLED, threeConfigsDisabled[1].getState() );
+// TestCase.assertEquals( Component.STATE_DISABLED, threeConfigsDisabled[2].getState() );
+// TestCase.assertEquals( 0, SimpleComponent.INSTANCES.size() );
+// TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( threeConfigsDisabled[0].getId() ) );
+// TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( threeConfigsDisabled[1].getId() ) );
+// TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( threeConfigsDisabled[2].getId() ) );
+//disabled, no configurations.
+ getConfigurationsDisabledThenEnable(factoryPid, 0, ComponentConfigurationDTO.ACTIVE);
+
+// // enable a single component (to get ComponentContext later)
+// threeConfigsDisabled[0].enable();
+// delay();
+//
+// // expect one enabled and two disabled components
+// final Component[] threeConfigs21 = findComponentConfigurationsByName( factoryPid );
+// TestCase.assertNotNull( threeConfigs21 );
+// TestCase.assertEquals( 3, threeConfigs21.length );
+// TestCase.assertEquals( 1, SimpleComponent.INSTANCES.size() );
+// TestCase.assertEquals( Component.STATE_ACTIVE, threeConfigs21[0].getState() );
+// TestCase.assertEquals( Component.STATE_DISABLED, threeConfigs21[1].getState() );
+// TestCase.assertEquals( Component.STATE_DISABLED, threeConfigs21[2].getState() );
+// TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( threeConfigs21[0].getId() ) );
+// TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( threeConfigs21[1].getId() ) );
+// TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( threeConfigs21[2].getId() ) );
+//
+// // enable all components now
+// SimpleComponent.INSTANCES.values().iterator().next().m_activateContext.enableComponent( factoryPid );
+// delay();
+//
+// // expect all enabled
+// final Component[] threeConfigsEnabled = findComponentConfigurationsByName( factoryPid );
+// TestCase.assertNotNull( threeConfigsEnabled );
+// TestCase.assertEquals( 3, threeConfigsEnabled.length );
+// TestCase.assertEquals( Component.STATE_ACTIVE, threeConfigsEnabled[0].getState() );
+// TestCase.assertEquals( Component.STATE_ACTIVE, threeConfigsEnabled[1].getState() );
+// TestCase.assertEquals( Component.STATE_ACTIVE, threeConfigsEnabled[2].getState() );
+// TestCase.assertEquals( 3, SimpleComponent.INSTANCES.size() );
+// TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( threeConfigsEnabled[0].getId() ) );
+// TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( threeConfigsEnabled[1].getId() ) );
+// TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( threeConfigsEnabled[2].getId() ) );
}
+
}
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ComponentDisposeTest.java b/scr/src/test/java/org/apache/felix/scr/integration/ComponentDisposeTest.java
index 16af92e..af5059c 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/ComponentDisposeTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ComponentDisposeTest.java
@@ -20,16 +20,18 @@
import java.lang.reflect.Field;
+import java.util.Collection;
import java.util.Map;
+import junit.framework.Assert;
import junit.framework.TestCase;
-import org.apache.felix.scr.Component;
import org.apache.felix.scr.integration.components.SimpleComponent;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
@RunWith(JUnit4TestRunner.class)
@@ -50,70 +52,77 @@
deleteFactoryConfigurations( factoryPid );
delay();
- // one single component exists without configuration
- final Component[] noConfigurations = findComponentsByName( factoryPid );
- TestCase.assertNotNull( noConfigurations );
- TestCase.assertEquals( 1, noConfigurations.length );
- TestCase.assertEquals( Component.STATE_DISABLED, noConfigurations[0].getState() );
- TestCase.assertTrue( SimpleComponent.INSTANCES.isEmpty() );
-
- // enable the component, configuration required, hence unsatisfied
- noConfigurations[0].enable();
- delay();
-
- final Component[] enabledNoConfigs = findComponentsByName( factoryPid );
- TestCase.assertNotNull( enabledNoConfigs );
- TestCase.assertEquals( 1, enabledNoConfigs.length );
- TestCase.assertEquals( Component.STATE_UNSATISFIED, enabledNoConfigs[0].getState() );
- TestCase.assertTrue( SimpleComponent.INSTANCES.isEmpty() );
+ getConfigurationsDisabledThenEnable(factoryPid, 0, ComponentConfigurationDTO.ACTIVE);//there should be none
+// // one single component exists without configuration
+// final Component[] noConfigurations = findComponentConfigurationsByName( factoryPid, -1 );
+// TestCase.assertNotNull( noConfigurations );
+// TestCase.assertEquals( 1, noConfigurations.length );
+// TestCase.assertEquals( Component.STATE_DISABLED, noConfigurations[0].getState() );
+// TestCase.assertTrue( SimpleComponent.INSTANCES.isEmpty() );
+//
+// // enable the component, configuration required, hence unsatisfied
+// noConfigurations[0].enable();
+// delay();
+//
+// final Component[] enabledNoConfigs = findComponentConfigurationsByName( factoryPid, -1 );
+// TestCase.assertNotNull( enabledNoConfigs );
+// TestCase.assertEquals( 1, enabledNoConfigs.length );
+// TestCase.assertEquals( Component.STATE_UNSATISFIED, enabledNoConfigs[0].getState() );
+// TestCase.assertTrue( SimpleComponent.INSTANCES.isEmpty() );
// create two factory configurations expecting two components
final String pid0 = createFactoryConfiguration( factoryPid );
final String pid1 = createFactoryConfiguration( factoryPid );
delay();
+ Collection<ComponentConfigurationDTO> ccs = findComponentConfigurationsByName(factoryPid, ComponentConfigurationDTO.ACTIVE);
+ Assert.assertEquals(2, ccs.size());
// expect two components, only first is active, second is disabled
- final Component[] twoConfigs = findComponentsByName( factoryPid );
- TestCase.assertNotNull( twoConfigs );
- TestCase.assertEquals( 2, twoConfigs.length );
-
- // find the active and inactive configs, fail if none
- int activeConfig;
- int inactiveConfig;
- if ( twoConfigs[0].getState() == Component.STATE_ACTIVE )
+// final Component[] twoConfigs = findComponentConfigurationsByName( factoryPid, -1 );
+// TestCase.assertNotNull( twoConfigs );
+// TestCase.assertEquals( 2, twoConfigs.length );
+//
+// // find the active and inactive configs, fail if none
+// int activeConfig;
+// int inactiveConfig;
+// if ( twoConfigs[0].getState() == Component.STATE_ACTIVE )
+// {
+// // [0] is active, [1] expected disabled
+// activeConfig = 0;
+// inactiveConfig = 1;
+// }
+// else if ( twoConfigs[1].getState() == Component.STATE_ACTIVE )
+// {
+// // [1] is active, [0] expected disabled
+// activeConfig = 1;
+// inactiveConfig = 0;
+// }
+// else
+// {
+// TestCase.fail( "One of two components expected active" );
+// return; // eases the compiler...
+// }
+//
+// TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[activeConfig].getState() );
+// TestCase.assertEquals( Component.STATE_DISABLED, twoConfigs[inactiveConfig].getState() );
+ TestCase.assertEquals( 2, SimpleComponent.INSTANCES.size() );
+ for (ComponentConfigurationDTO cc: ccs)
{
- // [0] is active, [1] expected disabled
- activeConfig = 0;
- inactiveConfig = 1;
+ TestCase.assertTrue(SimpleComponent.INSTANCES.containsKey(cc.id));
}
- else if ( twoConfigs[1].getState() == Component.STATE_ACTIVE )
- {
- // [1] is active, [0] expected disabled
- activeConfig = 1;
- inactiveConfig = 0;
- }
- else
- {
- TestCase.fail( "One of two components expected active" );
- return; // eases the compiler...
- }
-
- TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[activeConfig].getState() );
- TestCase.assertEquals( Component.STATE_DISABLED, twoConfigs[inactiveConfig].getState() );
- TestCase.assertEquals( 1, SimpleComponent.INSTANCES.size() );
- TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[activeConfig].getId() ) );
- TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( twoConfigs[inactiveConfig].getId() ) );
+// TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[activeConfig].getId() ) );
+// TestCase.assertFalse( SimpleComponent.INSTANCES.containsKey( twoConfigs[inactiveConfig].getId() ) );
// enable second component
- twoConfigs[inactiveConfig].enable();
- delay();
-
- // ensure both components active
- TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[0].getState() );
- TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[1].getState() );
- TestCase.assertEquals( 2, SimpleComponent.INSTANCES.size() );
- TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[0].getId() ) );
- TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[1].getId() ) );
+// twoConfigs[inactiveConfig].enable();
+// delay();
+//
+// // ensure both components active
+// TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[0].getState() );
+// TestCase.assertEquals( Component.STATE_ACTIVE, twoConfigs[1].getState() );
+// TestCase.assertEquals( 2, SimpleComponent.INSTANCES.size() );
+// TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[0].getId() ) );
+// TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( twoConfigs[1].getId() ) );
// dispose an instance
final SimpleComponent anInstance = SimpleComponent.INSTANCE;
@@ -123,12 +132,15 @@
delay();
// expect one component
- final Component[] oneConfig = findComponentsByName( factoryPid );
- TestCase.assertNotNull( oneConfig );
- TestCase.assertEquals( 1, oneConfig.length );
- TestCase.assertEquals( Component.STATE_ACTIVE, oneConfig[0].getState() );
+ ComponentConfigurationDTO cc = findComponentConfigurationByName(factoryPid, ComponentConfigurationDTO.ACTIVE);
+
+// final Component[] oneConfig = findComponentConfigurationsByName( factoryPid, -1 );
+// TestCase.assertNotNull( oneConfig );
+// TestCase.assertEquals( 1, oneConfig.length );
+// TestCase.assertEquals( Component.STATE_ACTIVE, oneConfig[0].getState() );
TestCase.assertEquals( 1, SimpleComponent.INSTANCES.size() );
- TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( oneConfig[0].getId() ) );
+ TestCase.assertTrue(SimpleComponent.INSTANCES.containsKey(cc.id));
+// TestCase.assertTrue( SimpleComponent.INSTANCES.containsKey( oneConfig[0].getId() ) );
final SimpleComponent instance = SimpleComponent.INSTANCES.values().iterator().next();
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java b/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java
index edf7bb1..f1e0c2e 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java
@@ -62,7 +62,7 @@
final String componentname = "factory.component";
final String componentfactory = "factory.component.factory";
- final Component component = findComponentByName( componentname );
+ final Component component = findComponentDescriptorByName( componentname );
TestCase.assertNotNull( component );
TestCase.assertFalse( component.isDefaultEnabled() );
@@ -100,7 +100,7 @@
TestCase.assertTrue( instanceMap.containsValue( instanceManager ) );
// check registered components
- final Component[] allFactoryComponents = findComponentsByName( componentname );
+ final Component[] allFactoryComponents = findComponentConfigurationsByName( componentname, -1 );
TestCase.assertNotNull( allFactoryComponents );
TestCase.assertEquals( 2, allFactoryComponents.length );
for ( int i = 0; i < allFactoryComponents.length; i++ )
@@ -137,7 +137,7 @@
final String componentname = "factory.component";
final String componentfactory = "factory.component.factory";
- final Component component = findComponentByName( componentname );
+ final Component component = findComponentDescriptorByName( componentname );
TestCase.assertNotNull( component );
TestCase.assertFalse( component.isDefaultEnabled() );
@@ -199,7 +199,7 @@
final String componentname = "factory.component";
final String componentfactory = "factory.component.factory";
- final Component component = findComponentByName( componentname );
+ final Component component = findComponentDescriptorByName( componentname );
TestCase.assertNotNull( component );
TestCase.assertFalse( component.isDefaultEnabled() );
@@ -251,7 +251,7 @@
deleteConfig( componentname );
delay();
- final Component component = findComponentByName( componentname );
+ final Component component = findComponentDescriptorByName( componentname );
TestCase.assertNotNull( component );
TestCase.assertFalse( component.isDefaultEnabled() );
@@ -334,7 +334,7 @@
SimpleServiceImpl.create( bundleContext, "ignored" ).setFilterProperty( "ignored" );
- final Component component = findComponentByName( componentname );
+ final Component component = findComponentDescriptorByName( componentname );
TestCase.assertNotNull( component );
TestCase.assertFalse( component.isDefaultEnabled() );
@@ -383,7 +383,7 @@
TestCase.assertTrue( instanceMap.containsValue( instanceManager ) );
// check registered components
- final Component[] allFactoryComponents = findComponentsByName( componentname );
+ final Component[] allFactoryComponents = findComponentConfigurationsByName( componentname, -1 );
TestCase.assertNotNull( allFactoryComponents );
TestCase.assertEquals( 2, allFactoryComponents.length );
for ( int i = 0; i < allFactoryComponents.length; i++ )
@@ -440,7 +440,7 @@
TestCase.assertTrue( SimpleComponent.INSTANCE.m_multiRef.contains( noMatch ) );
// check registered components
- final Component[] allFactoryComponents2 = findComponentsByName( componentname );
+ final Component[] allFactoryComponents2 = findComponentConfigurationsByName( componentname, -1 );
TestCase.assertNotNull( allFactoryComponents2 );
TestCase.assertEquals( 2, allFactoryComponents2.length );
for ( int i = 0; i < allFactoryComponents2.length; i++ )
@@ -464,7 +464,7 @@
delay();
// check registered components (ComponentFactory aint no longer)
- final Component[] allFactoryComponents3 = findComponentsByName( componentname );
+ final Component[] allFactoryComponents3 = findComponentConfigurationsByName( componentname, -1 );
TestCase.assertNotNull( allFactoryComponents3 );
TestCase.assertEquals( 2, allFactoryComponents3.length );
for ( int i = 0; i < allFactoryComponents3.length; i++ )
@@ -489,7 +489,7 @@
delay();
// check registered components (ComponentFactory aint no longer)
- final Component[] allFactoryComponents4 = findComponentsByName( componentname );
+ final Component[] allFactoryComponents4 = findComponentConfigurationsByName( componentname, -1 );
TestCase.assertNotNull( allFactoryComponents4 );
TestCase.assertEquals( 1, allFactoryComponents4.length );
for ( int i = 0; i < allFactoryComponents4.length; i++ )
@@ -520,7 +520,7 @@
{
//set up the component that refers to the service the factory will create.
final String referringComponentName = "ComponentReferringToFactoryObject";
- final Component referringComponent = findComponentByName( referringComponentName );
+ final Component referringComponent = findComponentDescriptorByName( referringComponentName );
TestCase.assertNotNull( referringComponent );
referringComponent.enable();
delay();
@@ -532,7 +532,7 @@
final String componentname = "factory.component.referred";
final String componentfactory = "factory.component.factory.referred";
- final Component component = findComponentByName( componentname );
+ final Component component = findComponentDescriptorByName( componentname );
TestCase.assertNotNull( component );
TestCase.assertFalse( component.isDefaultEnabled() );
@@ -575,7 +575,7 @@
public void test_component_factory_with_target_filters() throws InvalidSyntaxException
{
final String componentfactory = "factory.component.reference.targetfilter";
- final Component component = findComponentByName( componentfactory );
+ final Component component = findComponentDescriptorByName( componentfactory );
TestCase.assertNotNull( component );
TestCase.assertFalse( component.isDefaultEnabled() );
@@ -629,7 +629,7 @@
public void test_component_factory_set_bundle_location_null() throws Exception
{
final String componentfactory = "factory.component.reference.targetfilter";
- final Component component = findComponentByName( componentfactory );
+ final Component component = findComponentDescriptorByName( componentfactory );
TestCase.assertNotNull( component );
TestCase.assertFalse( component.isDefaultEnabled() );
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java b/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
index 1c77465..1d92d4f 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
@@ -43,17 +43,21 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.Dictionary;
+import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.TreeSet;
import java.util.concurrent.LinkedBlockingQueue;
import javax.inject.Inject;
+import junit.framework.Assert;
import junit.framework.TestCase;
import org.apache.felix.scr.Component;
@@ -76,6 +80,9 @@
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.component.runtime.ServiceComponentRuntime;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
+import org.osgi.service.component.runtime.dto.ComponentDescriptionDTO;
import org.osgi.service.log.LogService;
import org.osgi.util.tracker.ServiceTracker;
@@ -88,9 +95,9 @@
protected Bundle bundle;
- protected ServiceTracker scrTracker;
+ protected ServiceTracker<ServiceComponentRuntime, ServiceComponentRuntime> scrTracker;
- protected ServiceTracker configAdminTracker;
+ protected ServiceTracker<ConfigurationAdmin, ConfigurationAdmin> configAdminTracker;
// the name of the system property providing the bundle file to be installed and tested
protected static final String BUNDLE_JAR_SYS_PROP = "project.bundle.file";
@@ -184,9 +191,9 @@
bundleContext.addFrameworkListener( log );
bundleContext.registerService( LogService.class.getName(), log, null );
- scrTracker = new ServiceTracker( bundleContext, "org.apache.felix.scr.ScrService", null );
+ scrTracker = new ServiceTracker<ServiceComponentRuntime, ServiceComponentRuntime>( bundleContext, ServiceComponentRuntime.class, null );
scrTracker.open();
- configAdminTracker = new ServiceTracker( bundleContext, "org.osgi.service.cm.ConfigurationAdmin", null );
+ configAdminTracker = new ServiceTracker<ConfigurationAdmin, ConfigurationAdmin>( bundleContext, ConfigurationAdmin.class, null );
configAdminTracker.open();
bundle = installBundle( descriptorFile, COMPONENT_PACKAGE );
@@ -217,41 +224,204 @@
}
- protected Component[] getComponents()
+ protected Collection<ComponentDescriptionDTO> getComponentDescriptions()
{
- ScrService scr = ( ScrService ) scrTracker.getService();
+ ServiceComponentRuntime scr = scrTracker.getService();
+ if ( scr == null )
+ {
+ TestCase.fail("no ServiceComponentRuntime");
+ }
+ return scr.getComponentDescriptionDTOs();
+ }
+
+
+ protected ComponentDescriptionDTO findComponentDescriptorByName( String name )
+ {
+ ServiceComponentRuntime scr = scrTracker.getService();
+ if ( scr == null )
+ {
+ TestCase.fail("no ServiceComponentRuntime");
+ }
+ return scr.getComponentDescriptionDTO(bundle, name);
+ }
+
+
+ protected Collection<ComponentConfigurationDTO> findComponentConfigurationsByName( Bundle b, String name, int expected )
+ {
+ ServiceComponentRuntime scr = scrTracker.getService();
+ if ( scr == null )
+ {
+ TestCase.fail("no ServiceComponentRuntime");
+ }
+ ComponentDescriptionDTO cd = scr.getComponentDescriptionDTO(bundle, name);
+ Collection<ComponentConfigurationDTO> ccs = scr.getComponentConfigurationDTOs(cd);
+ if (expected != -1)
+ {
+ for (ComponentConfigurationDTO cc: ccs)
+ {
+ Assert.assertEquals( "for ComponentConfiguration name: " + cc.description.name + " properties" + cc.properties + "Expected state " + STATES.get(expected) + " but was " + STATES.get(cc.state), expected, cc.state);
+ }
+ }
+ return ccs;
+ }
+
+ protected Collection<ComponentConfigurationDTO> findComponentConfigurationsByName( String name, int expected )
+ {
+ return findComponentConfigurationsByName(bundle, name, expected);
+ }
+
+ protected ComponentConfigurationDTO findComponentConfigurationByName( Bundle b, String name, int expected )
+ {
+ Collection<ComponentConfigurationDTO> ccs = findComponentConfigurationsByName( b, name, expected);
+ Assert.assertEquals(1, ccs.size());
+ return ccs.iterator().next();
+ }
+
+ protected ComponentConfigurationDTO findComponentConfigurationByName( String name, int expected )
+ {
+ return findComponentConfigurationByName( bundle, name, expected );
+ }
+// protected ComponentConfigurationDTO checkState( String name, int expected)
+// {
+// ComponentConfigurationDTO cc = findComponentConfigurationByName( name, expected);
+// return cc;
+// }
+
+ static final Map<Integer, String> STATES = new HashMap<Integer, String>();
+
+ static {
+ STATES.put(ComponentConfigurationDTO.UNSATISFIED, "Unsatisfied (" + ComponentConfigurationDTO.UNSATISFIED + ")" );
+ STATES.put(ComponentConfigurationDTO.SATISFIED, "Satisified (" + ComponentConfigurationDTO.SATISFIED + ")" );
+ STATES.put(ComponentConfigurationDTO.ACTIVE, "Active (" + ComponentConfigurationDTO.ACTIVE + ")" );
+ }
+
+ protected ComponentConfigurationDTO getDisabledConfigurationAndEnable( Bundle b, String name, int initialState )
+ {
+ int count = 1;
+ Collection<ComponentConfigurationDTO> ccs = getConfigurationsDisabledThenEnable(
+ b, name, count, initialState);
+ ComponentConfigurationDTO cc = ccs.iterator().next();
+ return cc;
+ }
+
+ protected ComponentConfigurationDTO getDisabledConfigurationAndEnable( String name, int initialState )
+ {
+ return getDisabledConfigurationAndEnable( bundle, name, initialState );
+ }
+
+ protected Collection<ComponentConfigurationDTO> getConfigurationsDisabledThenEnable( Bundle b, String name, int count, int initialState)
+ {
+ ServiceComponentRuntime scr = scrTracker.getService();
+ if ( scr == null )
+ {
+ TestCase.fail("no ServiceComponentRuntime");
+ }
+ ComponentDescriptionDTO cd = scr.getComponentDescriptionDTO(b, name);
+ Assert.assertFalse("Expected component disabled", scr.isComponentEnabled(cd));
+ scr.enableComponent(cd);
+ delay();//??
+ Assert.assertTrue("Expected component enabled", scr.isComponentEnabled(cd));
+
+ Collection<ComponentConfigurationDTO> ccs = scr.getComponentConfigurationDTOs(cd);
+ Assert.assertEquals(count, ccs.size());
+ for (ComponentConfigurationDTO cc: ccs) {
+ Assert.assertEquals("Expected state " + STATES.get(initialState)
+ + " but was " + STATES.get(cc.state), initialState,
+ cc.state);
+ }
+ return ccs;
+ }
+
+ protected Collection<ComponentConfigurationDTO> getConfigurationsDisabledThenEnable( String name, int count, int initialState)
+ {
+ return getConfigurationsDisabledThenEnable(bundle, name, count, initialState);
+ }
+
+ protected ComponentDescriptionDTO checkConfigurationCount( Bundle b, String name, int count, int expectedState )
+ {
+ ServiceComponentRuntime scr = scrTracker.getService();
+ if ( scr == null )
+ {
+ TestCase.fail("no ServiceComponentRuntime");
+ }
+ ComponentDescriptionDTO cd = scr.getComponentDescriptionDTO(b, name);
+ Assert.assertTrue("Expected component enabled", scr.isComponentEnabled(cd));
+
+ Collection<ComponentConfigurationDTO> ccs = scr.getComponentConfigurationDTOs(cd);
+ Assert.assertEquals(count, ccs.size());
+ if (expectedState != -1)
+ {
+ for (ComponentConfigurationDTO cc: ccs)
+ {
+ Assert.assertEquals("Expected state " + STATES.get(expectedState)
+ + " but was " + STATES.get(cc.state), expectedState,
+ cc.state);
+ }
+ }
+ return cd;
+ }
+
+ protected ComponentDescriptionDTO checkConfigurationCount( String name, int count, int expectedState )
+ {
+ return checkConfigurationCount(bundle, name, count, expectedState);
+ }
+
+ protected <S> S getServiceFromConfiguration( ComponentConfigurationDTO dto, Class<S> clazz )
+ {
+ long id = dto.id;
+ String filter = "(component.id=" + id + ")";
+ Collection<ServiceReference<S>> srs;
+ try {
+ srs = bundleContext.getServiceReferences(clazz, filter);
+ Assert.assertEquals(1, srs.size());
+ ServiceReference<S> sr = srs.iterator().next();
+ S s = bundleContext.getService(sr);
+ Assert.assertNotNull(s);
+ return s;
+ } catch (InvalidSyntaxException e) {
+ TestCase.fail(e.getMessage());
+ return null;//unreachable in fact
+ }
+ }
+
+ protected void enableAndCheck( ComponentDescriptionDTO cd )
+ {
+ ServiceComponentRuntime scr = scrTracker.getService();
if ( scr != null )
{
- return scr.getComponents();
+ scr.enableComponent(cd);
+ Assert.assertTrue("Expected component enabled", scr.isComponentEnabled(cd));
}
-
- return null;
- }
-
-
- protected Component findComponentByName( String name )
- {
- Component[] components = findComponentsByName( name );
- if ( components != null && components.length > 0 )
+ else
{
- return components[0];
+ throw new NullPointerException("no ServiceComponentRuntime");
}
-
- return null;
+
}
-
- protected Component[] findComponentsByName( String name )
+ protected void disableAndCheck( ComponentConfigurationDTO cc )
{
- ScrService scr = ( ScrService ) scrTracker.getService();
+ ComponentDescriptionDTO cd = cc.description;
+ disableAndCheck(cd);
+ }
+
+ protected void disableAndCheck(ComponentDescriptionDTO cd) {
+ ServiceComponentRuntime scr = scrTracker.getService();
if ( scr != null )
{
- return scr.getComponents( name );
+ scr.disableComponent(cd);
+ Assert.assertFalse("Expected component disabled", scr.isComponentEnabled(cd));
}
+ else
+ {
+ throw new NullPointerException("no ServiceComponentRuntime");
+ }
+ }
- return null;
- }
-
+ protected void disableAndCheck(String name) {
+ ComponentDescriptionDTO cd = findComponentDescriptorByName(name);
+ disableAndCheck(cd);
+ }
protected static void delay()
{
@@ -469,126 +639,126 @@
void info( PrintStream out )
{
- Component[] components = getComponents();
- if ( components == null )
- {
- return;
- }
-
- for ( int j = 0; j < components.length; j++ )
- {
- Component component = components[j];
- out.print( "ID: " );
- out.println( component.getId() );
- out.print( "Name: " );
- out.println( component.getName() );
- out.print( "Bundle: " );
- out.println( component.getBundle().getSymbolicName() + " (" + component.getBundle().getBundleId() + ")" );
- out.print( "State: " );
- out.println( toStateString( component.getState() ) );
- out.print( "Default State: " );
- out.println( component.isDefaultEnabled() ? "enabled" : "disabled" );
- out.print( "Activation: " );
- out.println( component.isImmediate() ? "immediate" : "delayed" );
-
- // DS 1.1 new features
- out.print( "Configuration Policy: " );
- out.println( component.getConfigurationPolicy() );
- out.print( "Activate Method: " );
- out.print( component.getActivate() );
- if ( component.isActivateDeclared() )
- {
- out.print( " (declared in the descriptor)" );
- }
- out.println();
- out.print( "Deactivate Method: " );
- out.print( component.getDeactivate() );
- if ( component.isDeactivateDeclared() )
- {
- out.print( " (declared in the descriptor)" );
- }
- out.println();
- out.print( "Modified Method: " );
- if ( component.getModified() != null )
- {
- out.print( component.getModified() );
- }
- else
- {
- out.print( "-" );
- }
- out.println();
-
- if ( component.getFactory() != null )
- {
- out.print( "Factory: " );
- out.println( component.getFactory() );
- }
-
- String[] services = component.getServices();
- if ( services != null )
- {
- out.print( "Services: " );
- out.println( services[0] );
- for ( int i = 1; i < services.length; i++ )
- {
- out.print( " " );
- out.println( services[i] );
- }
- out.print( "Service Scope: " );
- out.println( component.getServiceScope() );
- }
-
- Reference[] refs = component.getReferences();
- if ( refs != null )
- {
- for ( int i = 0; i < refs.length; i++ )
- {
- out.print( "Reference: " );
- out.println( refs[i].getName() );
- out.print( " Satisfied: " );
- out.println( refs[i].isSatisfied() ? "satisfied" : "unsatisfied" );
- out.print( " Service Name: " );
- out.println( refs[i].getServiceName() );
- if ( refs[i].getTarget() != null )
- {
- out.print( " Target Filter: " );
- out.println( refs[i].getTarget() );
- }
- out.print( " Multiple: " );
- out.println( refs[i].isMultiple() ? "multiple" : "single" );
- out.print( " Optional: " );
- out.println( refs[i].isOptional() ? "optional" : "mandatory" );
- out.print( " Policy: " );
- out.println( refs[i].isStatic() ? "static" : "dynamic" );
- out.print( " Policy option: " );
- out.println( refs[i].isReluctant() ? "reluctant" : "greedy" );
- }
- }
-
- Dictionary props = component.getProperties();
- if ( props != null )
- {
- out.println( "Properties:" );
- TreeSet keys = new TreeSet( Collections.list( props.keys() ) );
- for ( Iterator ki = keys.iterator(); ki.hasNext(); )
- {
- Object key = ki.next();
- out.print( " " );
- out.print( key );
- out.print( " = " );
-
- Object prop = props.get( key );
- if ( prop.getClass().isArray() )
- {
- prop = Arrays.asList( ( Object[] ) prop );
- }
- out.print( prop );
-
- out.println();
- }
- }
- }
+// Component[] components = getComponentDescriptions();
+// if ( components == null )
+// {
+// return;
+// }
+//
+// for ( int j = 0; j < components.length; j++ )
+// {
+// Component component = components[j];
+// out.print( "ID: " );
+// out.println( component.getId() );
+// out.print( "Name: " );
+// out.println( component.getName() );
+// out.print( "Bundle: " );
+// out.println( component.getBundle().getSymbolicName() + " (" + component.getBundle().getBundleId() + ")" );
+// out.print( "State: " );
+// out.println( toStateString( component.getState() ) );
+// out.print( "Default State: " );
+// out.println( component.isDefaultEnabled() ? "enabled" : "disabled" );
+// out.print( "Activation: " );
+// out.println( component.isImmediate() ? "immediate" : "delayed" );
+//
+// // DS 1.1 new features
+// out.print( "Configuration Policy: " );
+// out.println( component.getConfigurationPolicy() );
+// out.print( "Activate Method: " );
+// out.print( component.getActivate() );
+// if ( component.isActivateDeclared() )
+// {
+// out.print( " (declared in the descriptor)" );
+// }
+// out.println();
+// out.print( "Deactivate Method: " );
+// out.print( component.getDeactivate() );
+// if ( component.isDeactivateDeclared() )
+// {
+// out.print( " (declared in the descriptor)" );
+// }
+// out.println();
+// out.print( "Modified Method: " );
+// if ( component.getModified() != null )
+// {
+// out.print( component.getModified() );
+// }
+// else
+// {
+// out.print( "-" );
+// }
+// out.println();
+//
+// if ( component.getFactory() != null )
+// {
+// out.print( "Factory: " );
+// out.println( component.getFactory() );
+// }
+//
+// String[] services = component.getServices();
+// if ( services != null )
+// {
+// out.print( "Services: " );
+// out.println( services[0] );
+// for ( int i = 1; i < services.length; i++ )
+// {
+// out.print( " " );
+// out.println( services[i] );
+// }
+// out.print( "Service Scope: " );
+// out.println( component.getServiceScope() );
+// }
+//
+// Reference[] refs = component.getReferences();
+// if ( refs != null )
+// {
+// for ( int i = 0; i < refs.length; i++ )
+// {
+// out.print( "Reference: " );
+// out.println( refs[i].getName() );
+// out.print( " Satisfied: " );
+// out.println( refs[i].isSatisfied() ? "satisfied" : "unsatisfied" );
+// out.print( " Service Name: " );
+// out.println( refs[i].getServiceName() );
+// if ( refs[i].getTarget() != null )
+// {
+// out.print( " Target Filter: " );
+// out.println( refs[i].getTarget() );
+// }
+// out.print( " Multiple: " );
+// out.println( refs[i].isMultiple() ? "multiple" : "single" );
+// out.print( " Optional: " );
+// out.println( refs[i].isOptional() ? "optional" : "mandatory" );
+// out.print( " Policy: " );
+// out.println( refs[i].isStatic() ? "static" : "dynamic" );
+// out.print( " Policy option: " );
+// out.println( refs[i].isReluctant() ? "reluctant" : "greedy" );
+// }
+// }
+//
+// Dictionary props = component.getProperties();
+// if ( props != null )
+// {
+// out.println( "Properties:" );
+// TreeSet keys = new TreeSet( Collections.list( props.keys() ) );
+// for ( Iterator ki = keys.iterator(); ki.hasNext(); )
+// {
+// Object key = ki.next();
+// out.print( " " );
+// out.print( key );
+// out.print( " = " );
+//
+// Object prop = props.get( key );
+// if ( prop.getClass().isArray() )
+// {
+// prop = Arrays.asList( ( Object[] ) prop );
+// }
+// out.print( prop );
+//
+// out.println();
+// }
+// }
+// }
}
protected boolean isAtLeastR5()
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ConfigurationChangeTest.java b/scr/src/test/java/org/apache/felix/scr/integration/ConfigurationChangeTest.java
index b802a4a..da1eab9 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/ConfigurationChangeTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ConfigurationChangeTest.java
@@ -22,7 +22,6 @@
import junit.framework.TestCase;
-import org.apache.felix.scr.Component;
import org.apache.felix.scr.integration.components.SimpleComponent;
import org.apache.felix.scr.integration.components.SimpleServiceImpl;
import org.junit.Test;
@@ -33,6 +32,7 @@
import org.osgi.service.component.ComponentConstants;
import org.osgi.service.component.ComponentFactory;
import org.osgi.service.component.ComponentInstance;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
@RunWith(JUnit4TestRunner.class)
public class ConfigurationChangeTest extends ComponentTestBase
@@ -105,20 +105,13 @@
private void singleTest(String pid, boolean dynamic)
{
- final Component component = findComponentByName( pid );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
theConfig.put("ref.target", "(value=srv1)");
configure( pid );
- // async enabling
- component.enable();
- delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertEquals( srv1, comp10.m_singleRef );
@@ -150,7 +143,7 @@
TestCase.assertEquals( 0, comp20.m_singleRefUnbind);
TestCase.assertEquals( 1, comp10.m_singleRefUnbind);
}
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertEquals( srv2, comp20.m_singleRef );
TestCase.assertTrue( comp20.m_multiRef.isEmpty() );
}
@@ -214,20 +207,14 @@
private void multipleTest(String pid, boolean dynamic)
{
- final Component component = findComponentByName( pid );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
theConfig.put("ref.target", "(value=srv1)");
configure( pid );
- // async enabling
- component.enable();
- delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertEquals( 1, comp10.m_multiRef.size() );
@@ -259,7 +246,7 @@
TestCase.assertEquals( 0, comp20.m_multiRefUnbind);
TestCase.assertEquals( 1, comp10.m_multiRefUnbind);
}
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertEquals( 1, comp20.m_multiRef.size() );
TestCase.assertEquals( srv2, comp20.m_multiRef.iterator().next() );
}
@@ -271,20 +258,15 @@
String pid = "test_required_single_dynamic_factory";
final String factoryPid = "factory_" + pid;
boolean dynamic = true;
- final Component component = findComponentByName( pid );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
theConfig.put("ref.target", "(value=srv1)");
configure( pid );
- // async enabling
- component.enable();
- delay();
- TestCase.assertEquals( Component.STATE_FACTORY, component.getState() );
+ getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.ACTIVE); //?????? Not clear what should happen.
+// TestCase.assertEquals( Component.STATE_FACTORY, component.getState() );
// create a component instance
final ServiceReference[] refs = bundleContext.getServiceReferences( ComponentFactory.class.getName(), "("
@@ -333,7 +315,7 @@
TestCase.assertEquals( 0, comp20.m_singleRefUnbind);
TestCase.assertEquals( 1, comp10.m_singleRefUnbind);
}
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertEquals( srv2, comp20.m_singleRef );
TestCase.assertTrue( comp20.m_multiRef.isEmpty() );
}
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ConfigurationComponentFactoryTest.java b/scr/src/test/java/org/apache/felix/scr/integration/ConfigurationComponentFactoryTest.java
index 3fcb57a..5cfd2c4 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/ConfigurationComponentFactoryTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ConfigurationComponentFactoryTest.java
@@ -68,7 +68,7 @@
final String componentname = "factory.component";
final String componentfactory = "factory.component.factory";
- final Component component = findComponentByName( componentname );
+ final Component component = findComponentDescriptorByName( componentname );
TestCase.assertNotNull( component );
TestCase.assertFalse( component.isDefaultEnabled() );
@@ -104,7 +104,7 @@
// check registered components
- Component[] allFactoryComponents = findComponentsByName( componentname );
+ Component[] allFactoryComponents = findComponentConfigurationsByName( componentname, -1 );
TestCase.assertNotNull( allFactoryComponents );
TestCase.assertEquals( 2, allFactoryComponents.length );
for ( int i = 0; i < allFactoryComponents.length; i++ )
@@ -136,7 +136,7 @@
TestCase.assertEquals( PROP_NAME_FACTORY, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
// check registered components
- allFactoryComponents = findComponentsByName( componentname );
+ allFactoryComponents = findComponentConfigurationsByName( componentname, -1 );
TestCase.assertNotNull( allFactoryComponents );
TestCase.assertEquals( 2, allFactoryComponents.length );
for ( int i = 0; i < allFactoryComponents.length; i++ )
@@ -175,7 +175,7 @@
TestCase.assertEquals( 1, instanceMap.size() );
// check registered components
- allFactoryComponents = findComponentsByName( componentname );
+ allFactoryComponents = findComponentConfigurationsByName( componentname, -1 );
TestCase.assertNotNull( allFactoryComponents );
TestCase.assertEquals( 2, allFactoryComponents.length );
for ( int i = 0; i < allFactoryComponents.length; i++ )
@@ -205,7 +205,7 @@
TestCase.assertEquals( 0, instanceMap.size() );
// check registered components
- allFactoryComponents = findComponentsByName( componentname );
+ allFactoryComponents = findComponentConfigurationsByName( componentname, -1 );
TestCase.assertNotNull( allFactoryComponents );
TestCase.assertEquals( 1, allFactoryComponents.length );
for ( int i = 0; i < allFactoryComponents.length; i++ )
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/Felix3680Test.java b/scr/src/test/java/org/apache/felix/scr/integration/Felix3680Test.java
index f75730f..55dec63 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/Felix3680Test.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/Felix3680Test.java
@@ -24,11 +24,11 @@
import junit.framework.TestCase;
-import org.apache.felix.scr.Component;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.framework.BundleContext;
+import org.osgi.service.component.runtime.dto.ComponentDescriptionDTO;
/**
* This test validates the FELIX-3680 issue.
@@ -64,13 +64,11 @@
@Test
public void test_concurrent_reference_bindings()
{
- final Component main =
- findComponentByName("org.apache.felix.scr.integration.components.felix3680.Main");
- TestCase.assertNotNull(main);
- main.enable();
+ final ComponentDescriptionDTO main = findComponentDescriptorByName( "org.apache.felix.scr.integration.components.felix3680.Main" );
+ enableAndCheck(main);
delay(30);
- main.disable();
+ disableAndCheck( main );
delay( ); //async deactivate
for (Iterator it = log.foundWarnings().iterator(); it.hasNext();)
{
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/Felix3680_2Test.java b/scr/src/test/java/org/apache/felix/scr/integration/Felix3680_2Test.java
index 413c50a..f26ccf8 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/Felix3680_2Test.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/Felix3680_2Test.java
@@ -25,11 +25,11 @@
import junit.framework.TestCase;
-import org.apache.felix.scr.Component;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.framework.BundleContext;
+import org.osgi.service.component.runtime.dto.ComponentDescriptionDTO;
@RunWith(JUnit4TestRunner.class)
@@ -68,11 +68,10 @@
{
for ( int i = 0; i < 6; i++ )
{
- final Component main = findComponentByName( "org.apache.felix.scr.integration.components.felix3680_2.Main" );
- TestCase.assertNotNull( main );
- main.enable();
+ final ComponentDescriptionDTO main = findComponentDescriptorByName( "org.apache.felix.scr.integration.components.felix3680_2.Main" );
+ enableAndCheck(main);
delay( 5 ); //run test for 30 seconds
- main.disable();
+ disableAndCheck(main);
delay(); //async deactivate
if ( log.getFirstFrameworkThrowable() != null )
{
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/Felix4188Test.java b/scr/src/test/java/org/apache/felix/scr/integration/Felix4188Test.java
index 6f111ba..79ad028 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/Felix4188Test.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/Felix4188Test.java
@@ -26,7 +26,6 @@
import javax.inject.Inject;
import junit.framework.TestCase;
-import org.apache.felix.scr.Component;
import org.apache.felix.scr.integration.components.felix4188.Felix4188Component;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -35,6 +34,7 @@
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
import static org.ops4j.pax.tinybundles.core.TinyBundles.bundle;
import static org.ops4j.pax.tinybundles.core.TinyBundles.withBnd;
@@ -68,15 +68,13 @@
final Bundle bundle2 = installBundle("/integration_test_FELIX_4188_2.xml", "", "simplecomponent2");
bundle2.start();
- final Component aComp1 =
- findComponentByName("org.apache.felix.scr.integration.components.Felix4188Component-1");
- aComp1.enable();
- final Object aInst1 = aComp1.getComponentInstance().getInstance();
+ final ComponentConfigurationDTO aComp1 =
+ findComponentConfigurationByName( bundle1, "org.apache.felix.scr.integration.components.Felix4188Component-1", ComponentConfigurationDTO.ACTIVE);
+ final Felix4188Component aInst1 = getServiceFromConfiguration(aComp1, Felix4188Component.class);
- final Component aComp2 =
- findComponentByName("org.apache.felix.scr.integration.components.Felix4188Component-2");
- aComp2.enable();
- final Object aInst2 = aComp2.getComponentInstance().getInstance();
+ final ComponentConfigurationDTO aComp2 =
+ findComponentConfigurationByName( bundle1, "org.apache.felix.scr.integration.components.Felix4188Component-2", ComponentConfigurationDTO.ACTIVE);
+ final Felix4188Component aInst2 = getServiceFromConfiguration(aComp2, Felix4188Component.class);
final CountDownLatch latch = new CountDownLatch(1);
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/Felix4350Test.java b/scr/src/test/java/org/apache/felix/scr/integration/Felix4350Test.java
index a223105..eaaf6f3 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/Felix4350Test.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/Felix4350Test.java
@@ -18,13 +18,10 @@
*/
package org.apache.felix.scr.integration;
-import javax.inject.Inject;
-
import junit.framework.TestCase;
-import org.apache.felix.scr.Component;
+import org.apache.felix.scr.integration.components.Felix4350Component;
import org.apache.felix.scr.integration.components.SimpleComponent;
import org.apache.felix.scr.integration.components.SimpleComponent2;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
@@ -32,7 +29,7 @@
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.component.ComponentInstance;
+import org.osgi.service.component.runtime.dto.ComponentDescriptionDTO;
/**
* This test validates the FELIX-4350 issue.
@@ -81,40 +78,56 @@
protected void doTest(String componentName)
{
- final Component main = findComponentByName(componentName);
- TestCase.assertNotNull(main);
-
ServiceRegistration dep1Reg = register(new SimpleComponent(), 0);
ServiceRegistration dep2Reg = register(new SimpleComponent2(), 1000);
- main.enable();
- delay(300);
- dep1Reg.unregister();
- delay(2000);
+
+ final ComponentDescriptionDTO main = findComponentDescriptorByName(componentName);
+ TestCase.assertNotNull(main);
- ComponentInstance mainCompInst = main.getComponentInstance();
- TestCase.assertNull(mainCompInst);
+ asyncEnable(main); //needs to be async
+ delay(300); //dep2 getService has not yet returned
+ dep1Reg.unregister();
+ delay(2000); //dep2 getService has returned
+
+// ComponentInstance mainCompInst = main.getComponentInstance();
+// TestCase.assertNull(mainCompInst);
+ Felix4350Component.check(0, 0, false);
dep1Reg = register(new SimpleComponent(), 0);
delay(300);
- mainCompInst = main.getComponentInstance();
- TestCase.assertNotNull(mainCompInst);
+// mainCompInst = main.getComponentInstance();
+// TestCase.assertNotNull(mainCompInst);
+ Felix4350Component.check(1, 0, true);
- main.disable();
+ disableAndCheck(main); //does not need to be asyncv??
dep1Reg.unregister();
dep2Reg.unregister();
+ Felix4350Component.check(1, 1, false);
dep1Reg = register(new SimpleComponent(), 0);
dep2Reg = register(new SimpleComponent2(), 1000);
- main.enable();
+ Felix4350Component.check(1, 1, false);
+
+ asyncEnable(main); //needs to be async
delay(300);
dep1Reg.unregister();
delay(100);
dep1Reg = register(new SimpleComponent(), 0);
delay(2000);
- mainCompInst = main.getComponentInstance();
- TestCase.assertNotNull(mainCompInst);
+// mainCompInst = main.getComponentInstance();
+// TestCase.assertNotNull(mainCompInst);
+ Felix4350Component.check(2, 1, true); //n.b. counts are cumulative
+ }
+
+ protected void asyncEnable( final ComponentDescriptionDTO cd )
+ {
+ new Thread( new Runnable() {
+
+ public void run() {
+ enableAndCheck( cd );
+ }}).start();
}
protected ServiceRegistration register(final Object service, final int delay) {
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/LocateTest.java b/scr/src/test/java/org/apache/felix/scr/integration/LocateTest.java
index 412afeb..6674ee4 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/LocateTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/LocateTest.java
@@ -22,16 +22,12 @@
import java.util.Hashtable;
-import junit.framework.TestCase;
-
-import org.apache.felix.scr.Component;
-import org.apache.felix.scr.integration.components.SimpleServiceImpl;
-import org.apache.felix.scr.integration.components.deadlock.Consumer;
import org.apache.felix.scr.integration.components.deadlock.TestComponent;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.service.cm.Configuration;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
@RunWith(JUnit4TestRunner.class)
public class LocateTest extends ComponentTestBase
@@ -50,9 +46,7 @@
{
bundleContext.registerService( Object.class, new Object(), null );
- final Component consumerComponent = findComponentByName( "AsyncLocate" );
- TestCase.assertNotNull( consumerComponent );
- TestCase.assertEquals( Component.STATE_ACTIVE, consumerComponent.getState() );
+ findComponentConfigurationByName( "AsyncLocate", ComponentConfigurationDTO.ACTIVE );
final String pid = "SimpleComponent";
Configuration config = getConfigurationAdmin().getConfiguration( pid, null );
@@ -61,16 +55,14 @@
config.update(props);
delay();
- final Component component = findComponentByName( pid );
- TestCase.assertNotNull( component );
//when deadlock is present the state is actually unsatisfied.
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ ComponentConfigurationDTO cc = findComponentConfigurationByName( pid, ComponentConfigurationDTO.ACTIVE );
delay();
props.put( "target", "foo" );
config.update(props);
delay();
- TestComponent tc = (TestComponent) component.getComponentInstance().getInstance();
+ TestComponent tc = getServiceFromConfiguration(cc, TestComponent.class);
assertTrue(tc.isSuccess1());
assertTrue(tc.isSuccess2());
}
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/LocationTest.java b/scr/src/test/java/org/apache/felix/scr/integration/LocationTest.java
index 4e10d1e..231a3d7 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/LocationTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/LocationTest.java
@@ -20,7 +20,6 @@
import junit.framework.TestCase;
-import org.apache.felix.scr.Component;
import org.apache.felix.scr.integration.components.SimpleComponent;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -31,6 +30,7 @@
import org.osgi.service.cm.ConfigurationEvent;
import org.osgi.service.cm.ConfigurationListener;
import org.osgi.service.cm.ConfigurationPermission;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
@RunWith(JUnit4TestRunner.class)
public class LocationTest extends ComponentTestBase
@@ -52,45 +52,35 @@
public void testLocationBinding() throws Exception
{
final String pid = COMPONENT_NAME;
- final Component component = findComponentByName( pid );
-
deleteConfig( pid );
delay();
-
- TestCase.assertNotNull( component );
- TestCase.assertFalse( component.isDefaultEnabled() );
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
- TestCase.assertNull( SimpleComponent.INSTANCE );
-
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ checkConfigurationCount(pid, 0, -1);
TestCase.assertNull( SimpleComponent.INSTANCE );
Configuration config = configure( pid );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertNotNull( SimpleComponent.INSTANCE );
TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
Bundle b2 = installBundle( descriptorFile, COMPONENT_PACKAGE, "simplecomponent2", "0.0.11", null );
b2.start();
- Component[] components = findComponentsByName( pid );
- TestCase.assertEquals( 2, components.length );
- Component c2 = components[0] == component? components[1]: components[0];
-
- c2.enable();
- delay();
- TestCase.assertEquals( Component.STATE_UNSATISFIED, c2.getState() );
+ checkConfigurationCount(b2, pid, 0, -1);
+// Component[] components = findComponentConfigurationsByName( pid, -1 );
+// TestCase.assertEquals( 2, components.length );
+// Component c2 = components[0] == component? components[1]: components[0];
+//
+// c2.enable();
+// delay();
+// TestCase.assertEquals( Component.STATE_UNSATISFIED, c2.getState() );
bundle.stop();
delay();
- TestCase.assertEquals( Component.STATE_UNSATISFIED, c2.getState() );
+ checkConfigurationCount(b2, pid, 0, -1);
+// TestCase.assertEquals( Component.STATE_UNSATISFIED, c2.getState() );
ConfigurationListener listener = new ConfigurationListener() {
@@ -109,7 +99,7 @@
if ( eventReceived )
{
- TestCase.assertEquals( Component.STATE_ACTIVE, c2.getState() );
+ checkConfigurationCount(b2, pid, 1, ComponentConfigurationDTO.ACTIVE);
}
sr.unregister();
@@ -121,45 +111,34 @@
public void testLocationChangeToRegionBinding() throws Exception
{
final String pid = COMPONENT_NAME;
- final Component component = findComponentByName( pid );
-
- deleteConfig( pid );
- delay();
-
- TestCase.assertNotNull( component );
- TestCase.assertFalse( component.isDefaultEnabled() );
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
- TestCase.assertNull( SimpleComponent.INSTANCE );
-
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ checkConfigurationCount(pid, 0, -1);
TestCase.assertNull( SimpleComponent.INSTANCE );
Configuration config = configure( pid );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
+// TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
TestCase.assertNotNull( SimpleComponent.INSTANCE );
TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
Bundle b2 = installBundle( descriptorFile, COMPONENT_PACKAGE, "simplecomponent2", "0.0.11", null );
b2.start();
- Component[] components = findComponentsByName( pid );
- TestCase.assertEquals( 2, components.length );
- Component c2 = components[0] == component? components[1]: components[0];
-
- c2.enable();
- delay();
- TestCase.assertEquals( Component.STATE_UNSATISFIED, c2.getState() );
+ checkConfigurationCount(b2, pid, 0, -1);
+// Component[] components = findComponentConfigurationsByName( pid, -1 );
+// TestCase.assertEquals( 2, components.length );
+// Component c2 = components[0] == component? components[1]: components[0];
+//
+// c2.enable();
+// delay();
+// TestCase.assertEquals( Component.STATE_UNSATISFIED, c2.getState() );
bundle.stop();
delay();
- TestCase.assertEquals( Component.STATE_UNSATISFIED, c2.getState() );
+ checkConfigurationCount(b2, pid, 0, -1);
+// TestCase.assertEquals( Component.STATE_UNSATISFIED, c2.getState() );
ConfigurationListener listener = new ConfigurationListener() {
@@ -178,7 +157,8 @@
if ( eventReceived )
{
- TestCase.assertEquals( Component.STATE_ACTIVE, c2.getState() );
+ checkConfigurationCount(b2, pid, 1, ComponentConfigurationDTO.ACTIVE);
+// TestCase.assertEquals( Component.STATE_ACTIVE, c2.getState() );
}
sr.unregister();
@@ -199,40 +179,30 @@
}
final String pid = COMPONENT_NAME;
- final Component component = findComponentByName( pid );
-
deleteConfig( pid );
- delay();
-
- TestCase.assertNotNull( component );
- TestCase.assertFalse( component.isDefaultEnabled() );
-
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
- TestCase.assertNull( SimpleComponent.INSTANCE );
-
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ checkConfigurationCount(pid, 0, -1);
TestCase.assertNull( SimpleComponent.INSTANCE );
Configuration config = configure( pid, REGION );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
+// TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
TestCase.assertNotNull( SimpleComponent.INSTANCE );
TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
Bundle b2 = installBundle( descriptorFile, COMPONENT_PACKAGE, "simplecomponent2", "0.0.11", null );
b2.start();
- Component[] components = findComponentsByName( pid );
- TestCase.assertEquals( 2, components.length );
- Component c2 = components[0] == component? components[1]: components[0];
-
- c2.enable();
- delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, c2.getState() );
+// Component[] components = findComponentConfigurationsByName( pid, -1 );
+// TestCase.assertEquals( 2, components.length );
+// Component c2 = components[0] == component? components[1]: components[0];
+//
+// c2.enable();
+// delay();
+ checkConfigurationCount(b2, pid, 1, ComponentConfigurationDTO.ACTIVE);
+// getDisabledConfigurationAndEnable(b2, pid, ComponentConfigurationDTO.ACTIVE);
+// TestCase.assertEquals( Component.STATE_ACTIVE, c2.getState() );
}
}
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/MutablePropertiesTest.java b/scr/src/test/java/org/apache/felix/scr/integration/MutablePropertiesTest.java
index 05a8b08..a7effcc 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/MutablePropertiesTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/MutablePropertiesTest.java
@@ -33,6 +33,7 @@
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
@RunWith(JUnit4TestRunner.class)
@@ -52,9 +53,7 @@
public void test_mutable_properties() throws InvalidSyntaxException
{
String componentName = "components.mutable.properties";
- final Component component = findComponentByName( componentName );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_REGISTERED, component.getState() );
+ findComponentConfigurationByName(componentName, ComponentConfigurationDTO.SATISFIED);
ServiceReference[] serviceReferences = bundleContext.getServiceReferences( MutatingService.class.getName(), "(service.pid=" + componentName + ")" );
TestCase.assertEquals( 1, serviceReferences.length );
@@ -64,7 +63,7 @@
//update theValue
MutatingService s = ( MutatingService ) bundleContext.getService(serviceReference );
Assert.assertNotNull(s);
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(componentName, ComponentConfigurationDTO.ACTIVE);
Dictionary d = new Hashtable(Collections.singletonMap( PROP_NAME, "anotherValue" ));
s.updateProperties(d);
checkProperties(serviceReference, 5, "anotherValue", "p1", "p2");
@@ -86,9 +85,7 @@
public void test_mutable_properties_returned() throws InvalidSyntaxException
{
String componentName = "components.mutable.properties.return";
- final Component component = findComponentByName( componentName );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_REGISTERED, component.getState() );
+ findComponentConfigurationByName(componentName, ComponentConfigurationDTO.SATISFIED);
ServiceReference[] serviceReferences = bundleContext.getServiceReferences( MutatingService.class.getName(), "(service.pid=" + componentName + ")" );
TestCase.assertEquals( 1, serviceReferences.length );
@@ -99,7 +96,7 @@
MutatingService s = ( MutatingService ) bundleContext.getService( serviceReference );
Assert.assertNotNull(s);
checkProperties( serviceReference, 8, "anotherValue1", "p1", "p2" );
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(componentName, ComponentConfigurationDTO.ACTIVE);
Dictionary d = new Hashtable(Collections.singletonMap( PROP_NAME, "anotherValue" ));
s.updateProperties(d);
checkProperties(serviceReference, 5, "anotherValue", "p1", "p2");
@@ -122,9 +119,7 @@
public void test_mutable_properties_returned_public() throws InvalidSyntaxException
{
String componentName = "components.mutable.properties.return.public";
- final Component component = findComponentByName( componentName );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_REGISTERED, component.getState() );
+ findComponentConfigurationByName(componentName, ComponentConfigurationDTO.SATISFIED);
ServiceReference[] serviceReferences = bundleContext.getServiceReferences( MutatingService.class.getName(), "(service.pid=" + componentName + ")" );
TestCase.assertEquals( 1, serviceReferences.length );
@@ -135,7 +130,7 @@
MutatingService s = ( MutatingService ) bundleContext.getService( serviceReference );
Assert.assertNotNull(s);
checkProperties( serviceReference, 8, "anotherValue1", "p1", "p2" );
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(componentName, ComponentConfigurationDTO.ACTIVE);
Dictionary d = new Hashtable(Collections.singletonMap( PROP_NAME, "anotherValue" ));
s.updateProperties(d);
checkProperties(serviceReference, 5, "anotherValue", "p1", "p2");
@@ -158,9 +153,7 @@
public void test_mutable_properties_bind_returned() throws InvalidSyntaxException
{
String componentName = "components.mutable.properties.bind";
- final Component component = findComponentByName( componentName );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_REGISTERED, component.getState() );
+ findComponentConfigurationByName(componentName, ComponentConfigurationDTO.SATISFIED);
ServiceReference[] serviceReferences = bundleContext.getServiceReferences( MutatingService.class.getName(), "(service.pid=" + componentName + ")" );
TestCase.assertEquals( 1, serviceReferences.length );
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/PersistentComponentFactoryTest.java b/scr/src/test/java/org/apache/felix/scr/integration/PersistentComponentFactoryTest.java
index c7b11ed..f56776b 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/PersistentComponentFactoryTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/PersistentComponentFactoryTest.java
@@ -62,7 +62,7 @@
final String componentname = "factory.component";
final String componentfactory = "factory.component.factory";
- final Component component = findComponentByName( componentname );
+ final Component component = findComponentDescriptorByName( componentname );
TestCase.assertNotNull( component );
TestCase.assertFalse( component.isDefaultEnabled() );
@@ -100,7 +100,7 @@
TestCase.assertTrue( instanceMap.containsValue( instanceManager ) );
// check registered components
- final Component[] allFactoryComponents = findComponentsByName( componentname );
+ final Component[] allFactoryComponents = findComponentConfigurationsByName( componentname, -1 );
TestCase.assertNotNull( allFactoryComponents );
TestCase.assertEquals( 2, allFactoryComponents.length );
for ( int i = 0; i < allFactoryComponents.length; i++ )
@@ -137,7 +137,7 @@
final String componentname = "factory.component";
final String componentfactory = "factory.component.factory";
- final Component component = findComponentByName( componentname );
+ final Component component = findComponentDescriptorByName( componentname );
TestCase.assertNotNull( component );
TestCase.assertFalse( component.isDefaultEnabled() );
@@ -199,7 +199,7 @@
final String componentname = "factory.component";
final String componentfactory = "factory.component.factory";
- final Component component = findComponentByName( componentname );
+ final Component component = findComponentDescriptorByName( componentname );
TestCase.assertNotNull( component );
TestCase.assertFalse( component.isDefaultEnabled() );
@@ -243,7 +243,7 @@
deleteConfig( componentname );
delay();
- final Component component = findComponentByName( componentname );
+ final Component component = findComponentDescriptorByName( componentname );
TestCase.assertNotNull( component );
TestCase.assertFalse( component.isDefaultEnabled() );
@@ -326,7 +326,7 @@
SimpleServiceImpl.create( bundleContext, "ignored" ).setFilterProperty( "ignored" );
- final Component component = findComponentByName( componentname );
+ final Component component = findComponentDescriptorByName( componentname );
TestCase.assertNotNull( component );
TestCase.assertFalse( component.isDefaultEnabled() );
@@ -375,7 +375,7 @@
TestCase.assertTrue( instanceMap.containsValue( instanceManager ) );
// check registered components
- final Component[] allFactoryComponents = findComponentsByName( componentname );
+ final Component[] allFactoryComponents = findComponentConfigurationsByName( componentname, -1 );
TestCase.assertNotNull( allFactoryComponents );
TestCase.assertEquals( 2, allFactoryComponents.length );
for ( int i = 0; i < allFactoryComponents.length; i++ )
@@ -422,7 +422,7 @@
TestCase.assertTrue( SimpleComponent.INSTANCE.m_multiRef.contains( noMatch ) );
// check registered components
- final Component[] allFactoryComponents2 = findComponentsByName( componentname );
+ final Component[] allFactoryComponents2 = findComponentConfigurationsByName( componentname, -1 );
TestCase.assertNotNull( allFactoryComponents2 );
TestCase.assertEquals( 2, allFactoryComponents2.length );
for ( int i = 0; i < allFactoryComponents2.length; i++ )
@@ -446,7 +446,7 @@
delay();
// check registered components (ComponentFactory aint no longer)
- final Component[] allFactoryComponents3 = findComponentsByName( componentname );
+ final Component[] allFactoryComponents3 = findComponentConfigurationsByName( componentname, -1 );
TestCase.assertNotNull( allFactoryComponents3 );
TestCase.assertEquals( 2, allFactoryComponents3.length );
long lastId = SimpleComponent.INSTANCE.m_id;
@@ -472,7 +472,7 @@
delay();
// check registered components (ComponentFactory is still present)
- final Component[] allFactoryComponents4 = findComponentsByName( componentname );
+ final Component[] allFactoryComponents4 = findComponentConfigurationsByName( componentname, -1 );
TestCase.assertNotNull( allFactoryComponents4 );
TestCase.assertEquals( 2, allFactoryComponents4.length );
for ( int i = 0; i < allFactoryComponents4.length; i++ )
@@ -507,7 +507,7 @@
{
//set up the component that refers to the service the factory will create.
final String referringComponentName = "ComponentReferringToFactoryObject";
- final Component referringComponent = findComponentByName( referringComponentName );
+ final Component referringComponent = findComponentDescriptorByName( referringComponentName );
TestCase.assertNotNull( referringComponent );
referringComponent.enable();
delay();
@@ -519,7 +519,7 @@
final String componentname = "factory.component.referred";
final String componentfactory = "factory.component.factory.referred";
- final Component component = findComponentByName( componentname );
+ final Component component = findComponentDescriptorByName( componentname );
TestCase.assertNotNull( component );
TestCase.assertFalse( component.isDefaultEnabled() );
@@ -562,7 +562,7 @@
public void test_component_factory_with_target_filters() throws InvalidSyntaxException
{
final String componentfactory = "factory.component.reference.targetfilter";
- final Component component = findComponentByName( componentfactory );
+ final Component component = findComponentDescriptorByName( componentfactory );
TestCase.assertNotNull( component );
TestCase.assertFalse( component.isDefaultEnabled() );
@@ -616,7 +616,7 @@
public void test_component_factory_set_bundle_location_null() throws Exception
{
final String componentfactory = "factory.component.reference.targetfilter";
- final Component component = findComponentByName( componentfactory );
+ final Component component = findComponentDescriptorByName( componentfactory );
TestCase.assertNotNull( component );
TestCase.assertFalse( component.isDefaultEnabled() );
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ServiceBindGreedyTest.java b/scr/src/test/java/org/apache/felix/scr/integration/ServiceBindGreedyTest.java
index 3d841f7..b4a491c 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/ServiceBindGreedyTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ServiceBindGreedyTest.java
@@ -20,9 +20,8 @@
import java.util.Hashtable;
-
import junit.framework.TestCase;
-import org.apache.felix.scr.Component;
+
import org.apache.felix.scr.integration.components.SimpleComponent;
import org.apache.felix.scr.integration.components.SimpleComponent2;
import org.apache.felix.scr.integration.components.SimpleService2Impl;
@@ -35,6 +34,7 @@
import org.osgi.service.component.ComponentConstants;
import org.osgi.service.component.ComponentFactory;
import org.osgi.service.component.ComponentInstance;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
@RunWith(JUnit4TestRunner.class)
@@ -55,17 +55,10 @@
@Test
public void test_optional_single_dynamic()
{
- final Component component = findComponentByName( "test_optional_single_dynamic" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+ final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
- final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1", 1 );
-
- // async enabling
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ String name ="test_optional_single_dynamic";
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertEquals( srv1, comp10.m_singleRef );
@@ -74,7 +67,6 @@
srv1.drop();
// no delay, should be immediate
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
final SimpleComponent comp11 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp10, comp11 );
TestCase.assertNull( comp11.m_singleRef );
@@ -83,23 +75,22 @@
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2", 2 );
delay(); // async binding
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp10, comp12 );
TestCase.assertEquals( srv2, comp12.m_singleRef );
TestCase.assertTrue( comp12.m_multiRef.isEmpty() );
- component.disable();
- delay(); // async disabling
+ disableAndCheck(cc);
final SimpleServiceImpl srv3 = SimpleServiceImpl.create( bundleContext, "srv3", 2 );
// enable component with two services available of same ranking, expect srv2 bind
// async enabling
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp20 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp20 );
TestCase.assertNotSame( comp10, comp20 );
@@ -109,7 +100,7 @@
// drop srv2, expect rebind to srv3 (synchronously)
srv2.drop();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp21 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp21 );
TestCase.assertEquals( srv3, comp21.m_singleRef );
@@ -119,7 +110,7 @@
final SimpleServiceImpl srv4 = SimpleServiceImpl.create( bundleContext, "srv4", 4 );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp22 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp22 );
TestCase.assertEquals( srv4, comp22.m_singleRef );
@@ -129,14 +120,14 @@
srv4.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp23 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp23 );
TestCase.assertEquals( srv3, comp23.m_singleRef );
TestCase.assertTrue( comp23.m_multiRef.isEmpty() );
// "reset"
- component.disable();
+ disableAndCheck(cc);
srv3.drop();
delay();
@@ -144,10 +135,10 @@
final SimpleServiceImpl srv5 = SimpleServiceImpl.create( bundleContext, "srv5", 10 );
final SimpleServiceImpl srv6 = SimpleServiceImpl.create( bundleContext, "srv6", 20 );
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp30 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp30 );
TestCase.assertEquals( srv6, comp30.m_singleRef );
@@ -157,7 +148,7 @@
final SimpleServiceImpl srv7 = SimpleServiceImpl.create( bundleContext, "srv7", 30 );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp31 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp30, comp31 );
TestCase.assertEquals( srv7, comp31.m_singleRef );
@@ -167,7 +158,7 @@
srv6.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp32 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp30, comp32 );
TestCase.assertEquals( srv7, comp32.m_singleRef );
@@ -178,17 +169,11 @@
@Test
public void test_required_single_dynamic()
{
- final Component component = findComponentByName( "test_required_single_dynamic" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1", 1 );
- // async enabling
- component.enable();
- delay();
+ String name ="test_required_single_dynamic";
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertEquals( srv1, comp10.m_singleRef );
@@ -197,30 +182,31 @@
srv1.drop();
// no delay, should be immediate
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.UNSATISFIED);
+// findComponentConfigurationByName(name, ComponentConfigurationDTO.UNSATISFIED);
final SimpleComponent comp11 = SimpleComponent.INSTANCE;
TestCase.assertNull( comp11 );
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2", 2 );
delay(); // async binding
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp12 );
TestCase.assertEquals( srv2, comp12.m_singleRef );
TestCase.assertTrue( comp12.m_multiRef.isEmpty() );
- component.disable();
+ disableAndCheck(cc);
delay(); // async disabling
final SimpleServiceImpl srv3 = SimpleServiceImpl.create( bundleContext, "srv3", 2 );
// enable component with two services available of same ranking, expect srv2 bind
// async enabling
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp20 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp20 );
TestCase.assertNotSame( comp10, comp20 );
@@ -230,7 +216,7 @@
// drop srv2, expect rebind to srv3 (synchronously)
srv2.drop();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp21 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp21 );
TestCase.assertEquals( srv3, comp21.m_singleRef );
@@ -240,7 +226,7 @@
final SimpleServiceImpl srv4 = SimpleServiceImpl.create( bundleContext, "srv4", 2 );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp22 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp22 );
TestCase.assertEquals( srv3, comp22.m_singleRef );
@@ -250,14 +236,14 @@
srv4.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp23 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp23 );
TestCase.assertEquals( srv3, comp23.m_singleRef );
TestCase.assertTrue( comp23.m_multiRef.isEmpty() );
// "reset"
- component.disable();
+ disableAndCheck(cc);
srv3.drop();
delay();
@@ -265,10 +251,10 @@
final SimpleServiceImpl srv5 = SimpleServiceImpl.create( bundleContext, "srv5", 10 );
final SimpleServiceImpl srv6 = SimpleServiceImpl.create( bundleContext, "srv6", 20 );
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp30 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp30 );
TestCase.assertEquals( srv6, comp30.m_singleRef );
@@ -278,7 +264,7 @@
final SimpleServiceImpl srv7 = SimpleServiceImpl.create( bundleContext, "srv7", 30 );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp31 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp30, comp31 );
TestCase.assertEquals( srv7, comp31.m_singleRef );
@@ -288,7 +274,7 @@
srv6.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp32 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp30, comp32 );
TestCase.assertEquals( srv7, comp32.m_singleRef );
@@ -299,17 +285,11 @@
@Test
public void test_optional_multiple_dynamic()
{
- final Component component = findComponentByName( "test_optional_multiple_dynamic" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
- // async enabling
- component.enable();
- delay();
+ String name ="test_optional_multiple_dynamic";
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertNull( comp10.m_singleRef );
@@ -318,7 +298,7 @@
srv1.drop();
// no delay, should be immediate
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp11 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp10, comp11 );
TestCase.assertNull( comp11.m_singleRef );
@@ -327,23 +307,23 @@
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay(); // async binding
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp10, comp12 );
TestCase.assertNull( comp12.m_singleRef );
TestCase.assertTrue( comp12.m_multiRef.contains( srv2 ) );
- component.disable();
+ disableAndCheck(cc);
delay(); // async disabling
final SimpleServiceImpl srv3 = SimpleServiceImpl.create( bundleContext, "srv3" );
// enable component with two services available, expect both bind
// async enabling
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp20 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp20 );
TestCase.assertNotSame( comp10, comp20 );
@@ -353,7 +333,7 @@
srv2.drop();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp21 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp21 );
TestCase.assertNull( comp21.m_singleRef );
@@ -364,7 +344,7 @@
final SimpleServiceImpl srv4 = SimpleServiceImpl.create( bundleContext, "srv4" );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp22 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp22 );
TestCase.assertNull( comp22.m_singleRef );
@@ -376,7 +356,7 @@
srv4.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp23 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp23 );
TestCase.assertNull( comp23.m_singleRef );
@@ -385,7 +365,7 @@
TestCase.assertFalse( comp23.m_multiRef.contains( srv4 ) );
// "reset"
- component.disable();
+ disableAndCheck(cc);
srv3.drop();
delay();
@@ -393,10 +373,10 @@
final SimpleServiceImpl srv5 = SimpleServiceImpl.create( bundleContext, "srv5", 10 );
final SimpleServiceImpl srv6 = SimpleServiceImpl.create( bundleContext, "srv6", 20 );
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp30 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp30 );
TestCase.assertNull( comp30.m_singleRef );
@@ -407,7 +387,8 @@
final SimpleServiceImpl srv7 = SimpleServiceImpl.create( bundleContext, "srv7", 30 );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp31 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp30, comp31 );
TestCase.assertNull( comp31.m_singleRef );
@@ -419,7 +400,8 @@
srv6.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp32 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp30, comp32 );
TestCase.assertNull( comp32.m_singleRef );
@@ -432,17 +414,11 @@
@Test
public void test_required_multiple_dynamic()
{
- final Component component = findComponentByName( "test_required_multiple_dynamic" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
- // async enabling
- component.enable();
- delay();
+ String name ="test_required_multiple_dynamic";
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertNull( comp10.m_singleRef );
@@ -451,30 +427,32 @@
srv1.drop();
// no delay, should be immediate
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.UNSATISFIED);
final SimpleComponent comp11 = SimpleComponent.INSTANCE;
TestCase.assertNull( comp11 );
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay(); // async binding
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp12 );
TestCase.assertNull( comp12.m_singleRef );
TestCase.assertTrue( comp12.m_multiRef.contains( srv2 ) );
- component.disable();
+ disableAndCheck(cc);
delay(); // async disabling
final SimpleServiceImpl srv3 = SimpleServiceImpl.create( bundleContext, "srv3" );
// enable component with two services available, expect both bind
// async enabling
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp20 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp20 );
TestCase.assertNotSame( comp10, comp20 );
@@ -484,7 +462,8 @@
srv2.drop();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp21 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp21 );
TestCase.assertNull( comp21.m_singleRef );
@@ -495,7 +474,8 @@
final SimpleServiceImpl srv4 = SimpleServiceImpl.create( bundleContext, "srv4" );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp22 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp22 );
TestCase.assertNull( comp22.m_singleRef );
@@ -507,7 +487,8 @@
srv4.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp23 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp23 );
TestCase.assertNull( comp23.m_singleRef );
@@ -516,7 +497,7 @@
TestCase.assertFalse( comp23.m_multiRef.contains( srv4 ) );
// "reset"
- component.disable();
+ disableAndCheck(cc);
srv3.drop();
delay();
@@ -524,10 +505,11 @@
final SimpleServiceImpl srv5 = SimpleServiceImpl.create( bundleContext, "srv5", 10 );
final SimpleServiceImpl srv6 = SimpleServiceImpl.create( bundleContext, "srv6", 20 );
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp30 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp30 );
TestCase.assertNull( comp30.m_singleRef );
@@ -538,7 +520,8 @@
final SimpleServiceImpl srv7 = SimpleServiceImpl.create( bundleContext, "srv7", 30 );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp31 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp30, comp31 );
TestCase.assertNull( comp31.m_singleRef );
@@ -550,7 +533,8 @@
srv6.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp32 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp30, comp32 );
TestCase.assertNull( comp32.m_singleRef );
@@ -563,22 +547,24 @@
@Test
public void test_required_multiple_dynamic_factory() throws InvalidSyntaxException
{
- final String pid = "test_required_multiple_dynamic_factory";
- final String factoryPid = "factory_" + pid;
-
- final Component component = findComponentByName( pid );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
- // async enabling (unsatisfied)
- component.enable();
- delay();
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ String name ="test_required_multiple_dynamic_factory"; //also pid
+ final String factoryPid = "factory_" + name;
+ getConfigurationsDisabledThenEnable(name, 0, ComponentConfigurationDTO.UNSATISFIED);
+// final String pid = "test_required_multiple_dynamic_factory";
+//
+// final Component component = findComponentDescriptorByName( pid );
+// TestCase.assertNotNull( component );
+// TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+//
+// // async enabling (unsatisfied)
+// enableAndCheck(cc.description);
+// delay();
+// findComponentConfigurationByName(name, ComponentConfigurationDTO.UNSATISFIED);
// register service, satisfying
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
delay();
- TestCase.assertEquals( Component.STATE_FACTORY, component.getState() );
+// TestCase.assertEquals( Component.STATE_FACTORY, component.getState() );
// create a component instance
final ServiceReference[] refs = bundleContext.getServiceReferences( ComponentFactory.class.getName(), "("
@@ -601,28 +587,29 @@
TestCase.assertTrue( sc.m_multiRef.contains( srv1 ) );
// ensure factory is not bound
- TestCase.assertNull( component.getReferences()[0].getServiceReferences() );
+// TestCase.assertNull( component.getReferences()[0].getServiceReferences() );
// assert two components managed
- final Component[] allFactoryComponents = findComponentsByName( pid );
- TestCase.assertNotNull( allFactoryComponents );
- TestCase.assertEquals( 2, allFactoryComponents.length );
- for ( int i = 0; i < allFactoryComponents.length; i++ )
- {
- final Component c = allFactoryComponents[i];
- if ( c.getId() == component.getId() )
- {
- TestCase.assertEquals( Component.STATE_FACTORY, c.getState() );
- }
- else if ( c.getId() == SimpleComponent.INSTANCE.m_id )
- {
- TestCase.assertEquals( Component.STATE_ACTIVE, c.getState() );
- }
- else
- {
- TestCase.fail( "Unexpected Component " + c );
- }
- }
+ checkConfigurationCount(name, 1, ComponentConfigurationDTO.ACTIVE);
+// final Component[] allFactoryComponents = findComponentConfigurationsByName( pid, -1 );
+// TestCase.assertNotNull( allFactoryComponents );
+// TestCase.assertEquals( 2, allFactoryComponents.length );
+// for ( int i = 0; i < allFactoryComponents.length; i++ )
+// {
+// final Component c = allFactoryComponents[i];
+// if ( c.getId() == component.getId() )
+// {
+// TestCase.assertEquals( Component.STATE_FACTORY, c.getState() );
+// }
+// else if ( c.getId() == SimpleComponent.INSTANCE.m_id )
+// {
+// TestCase.assertEquals( Component.STATE_ACTIVE, c.getState() );
+// }
+// else
+// {
+// TestCase.fail( "Unexpected Component " + c );
+// }
+// }
// register second service
final SimpleServiceImpl srv11 = SimpleServiceImpl.create( bundleContext, "srv11" );
@@ -634,7 +621,7 @@
TestCase.assertTrue( sc.m_multiRef.contains( srv11 ) );
// ensure factory is not bound
- TestCase.assertNull( component.getReferences()[0].getServiceReferences() );
+// TestCase.assertNull( component.getReferences()[0].getServiceReferences() );
// drop second service and ensure unbound (and active)
srv11.drop();
@@ -643,73 +630,69 @@
TestCase.assertEquals( SimpleComponent.INSTANCE, instance.getInstance() );
TestCase.assertEquals( 1, sc.m_multiRef.size() );
TestCase.assertTrue( sc.m_multiRef.contains( srv1 ) );
- TestCase.assertNull( component.getReferences()[0].getServiceReferences() );
+// TestCase.assertNull( component.getReferences()[0].getServiceReferences() );
// remove the service, expect factory to deactivate and instance to dispose
srv1.drop();
delay();
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.UNSATISFIED);
TestCase.assertNull( instance.getInstance() );
// assert component factory only managed
- final Component[] allFactoryComponents2 = findComponentsByName( pid );
- TestCase.assertNotNull( allFactoryComponents2 );
- TestCase.assertEquals( 1, allFactoryComponents2.length );
- for ( int i = 0; i < allFactoryComponents2.length; i++ )
- {
- final Component c = allFactoryComponents2[i];
- if ( c.getId() == component.getId() )
- {
- TestCase.assertEquals( Component.STATE_UNSATISFIED, c.getState() );
- }
- else
- {
- TestCase.fail( "Unexpected Component " + c );
- }
- }
+ //TODO this check should be whether the service is registered.
+// final Component[] allFactoryComponents2 = findComponentConfigurationsByName( pid, -1 );
+// TestCase.assertNotNull( allFactoryComponents2 );
+// TestCase.assertEquals( 1, allFactoryComponents2.length );
+// for ( int i = 0; i < allFactoryComponents2.length; i++ )
+// {
+// final Component c = allFactoryComponents2[i];
+// if ( c.getId() == component.getId() )
+// {
+// TestCase.assertEquals( Component.STATE_UNSATISFIED, c.getState() );
+// }
+// else
+// {
+// TestCase.fail( "Unexpected Component " + c );
+// }
+// }
// registeranother service, factory must come back, instance not
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay();
- TestCase.assertEquals( Component.STATE_FACTORY, component.getState() );
+// TestCase.assertEquals( Component.STATE_FACTORY, component.getState() );
TestCase.assertNull( instance.getInstance() );
// assert component factory only managed
- final Component[] allFactoryComponents3 = findComponentsByName( pid );
- TestCase.assertNotNull( allFactoryComponents3 );
- TestCase.assertEquals( 1, allFactoryComponents3.length );
- for ( int i = 0; i < allFactoryComponents3.length; i++ )
- {
- final Component c = allFactoryComponents3[i];
- if ( c.getId() == component.getId() )
- {
- TestCase.assertEquals( Component.STATE_FACTORY, c.getState() );
- }
- else
- {
- TestCase.fail( "Unexpected Component " + c );
- }
- }
+ checkConfigurationCount(name, 0, -1);
+// final Component[] allFactoryComponents3 = findComponentConfigurationsByName( pid, -1 );
+// TestCase.assertNotNull( allFactoryComponents3 );
+// TestCase.assertEquals( 1, allFactoryComponents3.length );
+// for ( int i = 0; i < allFactoryComponents3.length; i++ )
+// {
+// final Component c = allFactoryComponents3[i];
+// if ( c.getId() == component.getId() )
+// {
+// TestCase.assertEquals( Component.STATE_FACTORY, c.getState() );
+// }
+// else
+// {
+// TestCase.fail( "Unexpected Component " + c );
+// }
+// }
}
@Test
public void test_optional_single_static()
{
- final Component component = findComponentByName( "test_optional_single_static" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
- // async enabling
- component.enable();
- delay();
+ String name ="test_optional_single_static";
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertEquals( srv1, comp10.m_singleRef );
@@ -718,7 +701,8 @@
srv1.drop();
delay(); // async reactivate
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp11 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp11 );
TestCase.assertNull( comp11.m_singleRef );
@@ -728,24 +712,25 @@
delay(); // async binding
// greedy static reference rebinds
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp12 );
TestCase.assertNotSame( comp11, comp12 );
TestCase.assertEquals( srv2, comp12.m_singleRef );
TestCase.assertTrue( comp12.m_multiRef.isEmpty() );
- component.disable();
+ disableAndCheck(cc);
delay(); // async disabling
final SimpleServiceImpl srv3 = SimpleServiceImpl.create( bundleContext, "srv3" );
// enable component with two services available, expect srv2 bind
// async enabling
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp20 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp20 );
TestCase.assertNotSame( comp10, comp20 );
@@ -756,7 +741,8 @@
srv2.drop();
delay(); // async reactivate
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp21 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp21 );
TestCase.assertEquals( srv3, comp21.m_singleRef );
@@ -766,7 +752,8 @@
final SimpleServiceImpl srv4 = SimpleServiceImpl.create( bundleContext, "srv4", -1 );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp22 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp22 );
TestCase.assertSame( comp21, comp22 );
@@ -777,7 +764,8 @@
srv4.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp23 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp23 );
TestCase.assertSame( comp21, comp23 );
@@ -786,7 +774,7 @@
TestCase.assertTrue( comp23.m_multiRef.isEmpty() );
// "reset"
- component.disable();
+ disableAndCheck(cc);
srv3.drop();
delay();
@@ -794,10 +782,11 @@
final SimpleServiceImpl srv5 = SimpleServiceImpl.create( bundleContext, "srv5", 10 );
final SimpleServiceImpl srv6 = SimpleServiceImpl.create( bundleContext, "srv6", 20 );
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp30 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp23, comp30 );
TestCase.assertEquals( srv6, comp30.m_singleRef );
@@ -807,7 +796,8 @@
final SimpleServiceImpl srv7 = SimpleServiceImpl.create( bundleContext, "srv7", 30 );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp31 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp30, comp31 );
TestCase.assertEquals( srv7, comp31.m_singleRef );
@@ -817,7 +807,8 @@
srv6.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp32 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp30, comp32 );
TestCase.assertSame( comp31, comp32 );
@@ -829,17 +820,11 @@
@Test
public void test_required_single_static()
{
- final Component component = findComponentByName( "test_required_single_static" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
- // async enabling
- component.enable();
- delay();
+ String name ="test_required_single_static";
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertEquals( srv1, comp10.m_singleRef );
@@ -848,30 +833,32 @@
srv1.drop();
delay(); // async reactivate
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.UNSATISFIED);
final SimpleComponent comp11 = SimpleComponent.INSTANCE;
TestCase.assertNull( comp11 );
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay(); // async binding
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp12 );
TestCase.assertEquals( srv2, comp12.m_singleRef );
TestCase.assertTrue( comp12.m_multiRef.isEmpty() );
- component.disable();
+ disableAndCheck(cc);
delay(); // async disabling
final SimpleServiceImpl srv3 = SimpleServiceImpl.create( bundleContext, "srv3" );
// enable component with two services available, expect srv2 bind
// async enabling
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp20 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp20 );
TestCase.assertNotSame( comp10, comp20 );
@@ -882,7 +869,8 @@
srv2.drop();
delay(); // async reactivate
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp21 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp21 );
TestCase.assertEquals( srv3, comp21.m_singleRef );
@@ -892,7 +880,8 @@
final SimpleServiceImpl srv4 = SimpleServiceImpl.create( bundleContext, "srv4" );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp22 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp22 );
TestCase.assertSame( comp21, comp22 );
@@ -903,7 +892,8 @@
srv4.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp23 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp23 );
TestCase.assertSame( comp21, comp23 );
@@ -912,7 +902,7 @@
TestCase.assertTrue( comp23.m_multiRef.isEmpty() );
// "reset"
- component.disable();
+ disableAndCheck(cc);
srv3.drop();
delay();
@@ -920,10 +910,11 @@
final SimpleServiceImpl srv5 = SimpleServiceImpl.create( bundleContext, "srv5", 10 );
final SimpleServiceImpl srv6 = SimpleServiceImpl.create( bundleContext, "srv6", 20 );
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp30 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp23, comp30 );
TestCase.assertEquals( srv6, comp30.m_singleRef );
@@ -933,7 +924,8 @@
final SimpleServiceImpl srv7 = SimpleServiceImpl.create( bundleContext, "srv7", 30 );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp31 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp30, comp31 );
TestCase.assertEquals( srv7, comp31.m_singleRef );
@@ -943,7 +935,8 @@
srv6.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp32 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp30, comp32 );
TestCase.assertSame( comp31, comp32 );
@@ -955,17 +948,11 @@
@Test
public void test_optional_multiple_static()
{
- final Component component = findComponentByName( "test_optional_multiple_static" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
- // async enabling
- component.enable();
- delay();
+ String name ="test_optional_multiple_static";
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertNull( comp10.m_singleRef );
@@ -974,7 +961,8 @@
srv1.drop();
delay(); // async reactivate
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp11 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp11 );
TestCase.assertNull( comp11.m_singleRef );
@@ -983,24 +971,26 @@
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay(); // async binding
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp12 );
TestCase.assertNotSame( comp11, comp12 );
TestCase.assertNull( comp12.m_singleRef );
TestCase.assertTrue( comp12.m_multiRef.contains( srv2 ) );
- component.disable();
+ disableAndCheck(cc);
delay(); // async disabling
final SimpleServiceImpl srv3 = SimpleServiceImpl.create( bundleContext, "srv3" );
// enable component with two services available, expect both bind
// async enabling
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp20 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp20 );
TestCase.assertNotSame( comp10, comp20 );
@@ -1013,7 +1003,8 @@
srv2.drop();
delay(); // async reactivate
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp21 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp21 );
TestCase.assertNull( comp21.m_singleRef );
@@ -1024,7 +1015,8 @@
final SimpleServiceImpl srv4 = SimpleServiceImpl.create( bundleContext, "srv4" );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp22 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp22 );
TestCase.assertNotSame( comp21, comp22 );
@@ -1037,7 +1029,8 @@
srv4.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp23 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp23 );
TestCase.assertNotSame( comp21, comp23 );
@@ -1048,7 +1041,7 @@
TestCase.assertFalse( comp23.m_multiRef.contains( srv4 ) );
// "reset"
- component.disable();
+ disableAndCheck(cc);
srv3.drop();
delay();
@@ -1056,10 +1049,11 @@
final SimpleServiceImpl srv5 = SimpleServiceImpl.create( bundleContext, "srv5", 10 );
final SimpleServiceImpl srv6 = SimpleServiceImpl.create( bundleContext, "srv6", 20 );
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp30 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp23, comp30 );
TestCase.assertNull( comp30.m_singleRef );
@@ -1070,7 +1064,8 @@
final SimpleServiceImpl srv7 = SimpleServiceImpl.create( bundleContext, "srv7", 30 );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp31 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp30, comp31 );
TestCase.assertNull( comp31.m_singleRef );
@@ -1082,7 +1077,8 @@
srv6.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp32 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp30, comp32 );
TestCase.assertNotSame( comp31, comp32 );
@@ -1096,17 +1092,11 @@
@Test
public void test_required_multiple_static()
{
- final Component component = findComponentByName( "test_required_multiple_static" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
- // async enabling
- component.enable();
- delay();
+ String name ="test_required_multiple_static";
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertNull( comp10.m_singleRef );
@@ -1115,30 +1105,32 @@
srv1.drop();
delay(); // async reactivate
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.UNSATISFIED);
final SimpleComponent comp11 = SimpleComponent.INSTANCE;
TestCase.assertNull( comp11 );
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay(); // async binding
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp12 );
TestCase.assertNull( comp12.m_singleRef );
TestCase.assertTrue( comp12.m_multiRef.contains( srv2 ) );
- component.disable();
+ disableAndCheck(cc);
delay(); // async disabling
final SimpleServiceImpl srv3 = SimpleServiceImpl.create( bundleContext, "srv3" );
// enable component with two services available, expect both bind
// async enabling
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp20 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp20 );
TestCase.assertNotSame( comp10, comp20 );
@@ -1150,7 +1142,8 @@
srv2.drop();
delay(); // async reactivate
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp21 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp21 );
TestCase.assertNull( comp21.m_singleRef );
@@ -1161,7 +1154,8 @@
final SimpleServiceImpl srv4 = SimpleServiceImpl.create( bundleContext, "srv4" );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp22 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp22 );
TestCase.assertNotSame( comp21, comp22 );
@@ -1174,7 +1168,8 @@
srv4.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp23 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp23 );
TestCase.assertNotSame( comp21, comp23 );
@@ -1185,7 +1180,7 @@
TestCase.assertFalse( comp23.m_multiRef.contains( srv4 ) );
// "reset"
- component.disable();
+ disableAndCheck(cc);
srv3.drop();
delay();
@@ -1193,10 +1188,11 @@
final SimpleServiceImpl srv5 = SimpleServiceImpl.create( bundleContext, "srv5", 10 );
final SimpleServiceImpl srv6 = SimpleServiceImpl.create( bundleContext, "srv6", 20 );
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp30 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp23, comp30 );
TestCase.assertNull( comp30.m_singleRef );
@@ -1207,7 +1203,8 @@
final SimpleServiceImpl srv7 = SimpleServiceImpl.create( bundleContext, "srv7", 30 );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp31 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp30, comp31 );
TestCase.assertNull( comp31.m_singleRef );
@@ -1219,7 +1216,8 @@
srv6.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp32 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp30, comp32 );
TestCase.assertNotSame( comp31, comp32 );
@@ -1232,25 +1230,19 @@
@Test
public void test_multi_service_bind_unbind_order()
{
- final Component component = findComponentByName( "test_multi_service_bind_unbind_order" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
final SimpleService2Impl srv2 = SimpleService2Impl.create( bundleContext, "srv2" );
- // async enabling
- component.enable();
- delay();
+ String name ="test_multi_service_bind_unbind_order";
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
final SimpleComponent2 comp10 = SimpleComponent2.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertEquals( 2, comp10.getBindings().size() );
TestCase.assertEquals( "bindSimpleService", comp10.getBindings().get( 0 ) );
TestCase.assertEquals( "bindSimpleService2", comp10.getBindings().get( 1 ) );
- component.disable();
+ disableAndCheck(cc);
delay();
TestCase.assertEquals( 4, comp10.getBindings().size() );
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ServiceBindTest.java b/scr/src/test/java/org/apache/felix/scr/integration/ServiceBindTest.java
index 8c1d3b6..299f5fa 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/ServiceBindTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ServiceBindTest.java
@@ -35,6 +35,7 @@
import org.osgi.service.component.ComponentConstants;
import org.osgi.service.component.ComponentFactory;
import org.osgi.service.component.ComponentInstance;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
@RunWith(JUnit4TestRunner.class)
@@ -55,17 +56,10 @@
@Test
public void test_optional_single_dynamic()
{
- final Component component = findComponentByName( "test_optional_single_dynamic" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
- // async enabling
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ String name ="test_optional_single_dynamic";
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertEquals( srv1, comp10.m_singleRef );
@@ -74,7 +68,6 @@
srv1.drop();
// no delay, should be immediate
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
final SimpleComponent comp11 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp10, comp11 );
TestCase.assertNull( comp11.m_singleRef );
@@ -83,23 +76,22 @@
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay(); // async binding
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp10, comp12 );
TestCase.assertEquals( srv2, comp12.m_singleRef );
TestCase.assertTrue( comp12.m_multiRef.isEmpty() );
- component.disable();
- delay(); // async disabling
+ disableAndCheck(cc);
final SimpleServiceImpl srv3 = SimpleServiceImpl.create( bundleContext, "srv3" );
// enable component with two services available, expect srv2 bind
// async enabling
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp20 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp20 );
TestCase.assertNotSame( comp10, comp20 );
@@ -109,7 +101,7 @@
// drop srv2, expect rebind to srv3 (synchronously)
srv2.drop();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp21 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp21 );
TestCase.assertEquals( srv3, comp21.m_singleRef );
@@ -119,7 +111,7 @@
final SimpleServiceImpl srv4 = SimpleServiceImpl.create( bundleContext, "srv4" );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp22 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp22 );
TestCase.assertEquals( srv3, comp22.m_singleRef );
@@ -129,14 +121,14 @@
srv4.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp23 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp23 );
TestCase.assertEquals( srv3, comp23.m_singleRef );
TestCase.assertTrue( comp23.m_multiRef.isEmpty() );
// "reset"
- component.disable();
+ disableAndCheck(cc);
srv3.drop();
delay();
@@ -144,10 +136,10 @@
final SimpleServiceImpl srv5 = SimpleServiceImpl.create( bundleContext, "srv5", 10 );
final SimpleServiceImpl srv6 = SimpleServiceImpl.create( bundleContext, "srv6", 20 );
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp30 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp30 );
TestCase.assertEquals( srv6, comp30.m_singleRef );
@@ -157,7 +149,7 @@
final SimpleServiceImpl srv7 = SimpleServiceImpl.create( bundleContext, "srv7", 30 );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp31 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp30, comp31 );
TestCase.assertEquals( srv6, comp31.m_singleRef );
@@ -167,7 +159,7 @@
srv6.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp32 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp30, comp32 );
TestCase.assertEquals( srv7, comp32.m_singleRef );
@@ -178,17 +170,11 @@
@Test
public void test_required_single_dynamic()
{
- final Component component = findComponentByName( "test_required_single_dynamic" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
- // async enabling
- component.enable();
- delay();
+ String name ="test_required_single_dynamic";
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertEquals( srv1, comp10.m_singleRef );
@@ -197,30 +183,31 @@
srv1.drop();
// no delay, should be immediate
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.UNSATISFIED);
+// findComponentConfigurationByName(name, ComponentConfigurationDTO.UNSATISFIED);
final SimpleComponent comp11 = SimpleComponent.INSTANCE;
TestCase.assertNull( comp11 );
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay(); // async binding
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp12 );
TestCase.assertEquals( srv2, comp12.m_singleRef );
TestCase.assertTrue( comp12.m_multiRef.isEmpty() );
- component.disable();
+ disableAndCheck(cc);
delay(); // async disabling
final SimpleServiceImpl srv3 = SimpleServiceImpl.create( bundleContext, "srv3" );
// enable component with two services available, expect srv2 bind
// async enabling
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp20 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp20 );
TestCase.assertNotSame( comp10, comp20 );
@@ -230,7 +217,7 @@
// drop srv2, expect rebind to srv3 (synchronously)
srv2.drop();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp21 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp21 );
TestCase.assertEquals( srv3, comp21.m_singleRef );
@@ -240,7 +227,7 @@
final SimpleServiceImpl srv4 = SimpleServiceImpl.create( bundleContext, "srv4" );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp22 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp22 );
TestCase.assertEquals( srv3, comp22.m_singleRef );
@@ -250,14 +237,14 @@
srv4.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp23 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp23 );
TestCase.assertEquals( srv3, comp23.m_singleRef );
TestCase.assertTrue( comp23.m_multiRef.isEmpty() );
// "reset"
- component.disable();
+ disableAndCheck(cc);
srv3.drop();
delay();
@@ -265,10 +252,10 @@
final SimpleServiceImpl srv5 = SimpleServiceImpl.create( bundleContext, "srv5", 10 );
final SimpleServiceImpl srv6 = SimpleServiceImpl.create( bundleContext, "srv6", 20 );
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp30 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp30 );
TestCase.assertEquals( srv6, comp30.m_singleRef );
@@ -278,7 +265,7 @@
final SimpleServiceImpl srv7 = SimpleServiceImpl.create( bundleContext, "srv7", 30 );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp31 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp30, comp31 );
TestCase.assertEquals( srv6, comp31.m_singleRef );
@@ -288,7 +275,7 @@
srv6.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp32 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp30, comp32 );
TestCase.assertEquals( srv7, comp32.m_singleRef );
@@ -299,17 +286,11 @@
@Test
public void test_optional_multiple_dynamic()
{
- final Component component = findComponentByName( "test_optional_multiple_dynamic" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
- // async enabling
- component.enable();
- delay();
+ String name ="test_optional_multiple_dynamic";
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertNull( comp10.m_singleRef );
@@ -318,7 +299,7 @@
srv1.drop();
// no delay, should be immediate
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp11 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp10, comp11 );
TestCase.assertNull( comp11.m_singleRef );
@@ -327,23 +308,23 @@
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay(); // async binding
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp10, comp12 );
TestCase.assertNull( comp12.m_singleRef );
TestCase.assertTrue( comp12.m_multiRef.contains( srv2 ) );
- component.disable();
+ disableAndCheck(cc);
delay(); // async disabling
final SimpleServiceImpl srv3 = SimpleServiceImpl.create( bundleContext, "srv3" );
// enable component with two services available, expect both bind
// async enabling
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp20 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp20 );
TestCase.assertNotSame( comp10, comp20 );
@@ -353,7 +334,7 @@
srv2.drop();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp21 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp21 );
TestCase.assertNull( comp21.m_singleRef );
@@ -364,7 +345,7 @@
final SimpleServiceImpl srv4 = SimpleServiceImpl.create( bundleContext, "srv4" );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp22 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp22 );
TestCase.assertNull( comp22.m_singleRef );
@@ -376,7 +357,7 @@
srv4.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp23 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp23 );
TestCase.assertNull( comp23.m_singleRef );
@@ -385,7 +366,7 @@
TestCase.assertFalse( comp23.m_multiRef.contains( srv4 ) );
// "reset"
- component.disable();
+ disableAndCheck(cc);
srv3.drop();
delay();
@@ -393,10 +374,10 @@
final SimpleServiceImpl srv5 = SimpleServiceImpl.create( bundleContext, "srv5", 10 );
final SimpleServiceImpl srv6 = SimpleServiceImpl.create( bundleContext, "srv6", 20 );
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp30 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp30 );
TestCase.assertNull( comp30.m_singleRef );
@@ -407,7 +388,8 @@
final SimpleServiceImpl srv7 = SimpleServiceImpl.create( bundleContext, "srv7", 30 );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp31 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp30, comp31 );
TestCase.assertNull( comp31.m_singleRef );
@@ -419,7 +401,8 @@
srv6.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp32 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp30, comp32 );
TestCase.assertNull( comp32.m_singleRef );
@@ -432,17 +415,11 @@
@Test
public void test_required_multiple_dynamic()
{
- final Component component = findComponentByName( "test_required_multiple_dynamic" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
- // async enabling
- component.enable();
- delay();
+ String name ="test_required_multiple_dynamic";
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertNull( comp10.m_singleRef );
@@ -451,30 +428,32 @@
srv1.drop();
// no delay, should be immediate
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.UNSATISFIED);
final SimpleComponent comp11 = SimpleComponent.INSTANCE;
TestCase.assertNull( comp11 );
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay(); // async binding
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp12 );
TestCase.assertNull( comp12.m_singleRef );
TestCase.assertTrue( comp12.m_multiRef.contains( srv2 ) );
- component.disable();
+ disableAndCheck(cc);
delay(); // async disabling
final SimpleServiceImpl srv3 = SimpleServiceImpl.create( bundleContext, "srv3" );
// enable component with two services available, expect both bind
// async enabling
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp20 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp20 );
TestCase.assertNotSame( comp10, comp20 );
@@ -484,7 +463,8 @@
srv2.drop();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp21 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp21 );
TestCase.assertNull( comp21.m_singleRef );
@@ -495,7 +475,8 @@
final SimpleServiceImpl srv4 = SimpleServiceImpl.create( bundleContext, "srv4" );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp22 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp22 );
TestCase.assertNull( comp22.m_singleRef );
@@ -507,7 +488,8 @@
srv4.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp23 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp20, comp23 );
TestCase.assertNull( comp23.m_singleRef );
@@ -516,7 +498,7 @@
TestCase.assertFalse( comp23.m_multiRef.contains( srv4 ) );
// "reset"
- component.disable();
+ disableAndCheck(cc);
srv3.drop();
delay();
@@ -524,10 +506,11 @@
final SimpleServiceImpl srv5 = SimpleServiceImpl.create( bundleContext, "srv5", 10 );
final SimpleServiceImpl srv6 = SimpleServiceImpl.create( bundleContext, "srv6", 20 );
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp30 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp30 );
TestCase.assertNull( comp30.m_singleRef );
@@ -538,7 +521,8 @@
final SimpleServiceImpl srv7 = SimpleServiceImpl.create( bundleContext, "srv7", 30 );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp31 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp30, comp31 );
TestCase.assertNull( comp31.m_singleRef );
@@ -550,7 +534,8 @@
srv6.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp32 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp30, comp32 );
TestCase.assertNull( comp32.m_singleRef );
@@ -563,22 +548,24 @@
@Test
public void test_required_multiple_dynamic_factory() throws InvalidSyntaxException
{
- final String pid = "test_required_multiple_dynamic_factory";
- final String factoryPid = "factory_" + pid;
-
- final Component component = findComponentByName( pid );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
- // async enabling (unsatisfied)
- component.enable();
- delay();
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ String name ="test_required_multiple_dynamic_factory"; //also pid
+ final String factoryPid = "factory_" + name;
+ getConfigurationsDisabledThenEnable(name, 0, ComponentConfigurationDTO.UNSATISFIED);
+// final String pid = "test_required_multiple_dynamic_factory";
+//
+// final Component component = findComponentDescriptorByName( pid );
+// TestCase.assertNotNull( component );
+// TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+//
+// // async enabling (unsatisfied)
+// enableAndCheck(cc.description);
+// delay();
+// findComponentConfigurationByName(name, ComponentConfigurationDTO.UNSATISFIED);
// register service, satisfying
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
delay();
- TestCase.assertEquals( Component.STATE_FACTORY, component.getState() );
+// TestCase.assertEquals( Component.STATE_FACTORY, component.getState() );
// create a component instance
final ServiceReference[] refs = bundleContext.getServiceReferences( ComponentFactory.class.getName(), "("
@@ -601,28 +588,29 @@
TestCase.assertTrue( sc.m_multiRef.contains( srv1 ) );
// ensure factory is not bound
- TestCase.assertNull( component.getReferences()[0].getServiceReferences() );
+// TestCase.assertNull( component.getReferences()[0].getServiceReferences() );
// assert two components managed
- final Component[] allFactoryComponents = findComponentsByName( pid );
- TestCase.assertNotNull( allFactoryComponents );
- TestCase.assertEquals( 2, allFactoryComponents.length );
- for ( int i = 0; i < allFactoryComponents.length; i++ )
- {
- final Component c = allFactoryComponents[i];
- if ( c.getId() == component.getId() )
- {
- TestCase.assertEquals( Component.STATE_FACTORY, c.getState() );
- }
- else if ( c.getId() == SimpleComponent.INSTANCE.m_id )
- {
- TestCase.assertEquals( Component.STATE_ACTIVE, c.getState() );
- }
- else
- {
- TestCase.fail( "Unexpected Component " + c );
- }
- }
+ checkConfigurationCount(name, 1, ComponentConfigurationDTO.ACTIVE);
+// final Component[] allFactoryComponents = findComponentConfigurationsByName( pid, -1 );
+// TestCase.assertNotNull( allFactoryComponents );
+// TestCase.assertEquals( 2, allFactoryComponents.length );
+// for ( int i = 0; i < allFactoryComponents.length; i++ )
+// {
+// final Component c = allFactoryComponents[i];
+// if ( c.getId() == component.getId() )
+// {
+// TestCase.assertEquals( Component.STATE_FACTORY, c.getState() );
+// }
+// else if ( c.getId() == SimpleComponent.INSTANCE.m_id )
+// {
+// TestCase.assertEquals( Component.STATE_ACTIVE, c.getState() );
+// }
+// else
+// {
+// TestCase.fail( "Unexpected Component " + c );
+// }
+// }
// register second service
final SimpleServiceImpl srv11 = SimpleServiceImpl.create( bundleContext, "srv11" );
@@ -634,7 +622,7 @@
TestCase.assertTrue( sc.m_multiRef.contains( srv11 ) );
// ensure factory is not bound
- TestCase.assertNull( component.getReferences()[0].getServiceReferences() );
+// TestCase.assertNull( component.getReferences()[0].getServiceReferences() );
// drop second service and ensure unbound (and active)
srv11.drop();
@@ -643,73 +631,69 @@
TestCase.assertEquals( SimpleComponent.INSTANCE, instance.getInstance() );
TestCase.assertEquals( 1, sc.m_multiRef.size() );
TestCase.assertTrue( sc.m_multiRef.contains( srv1 ) );
- TestCase.assertNull( component.getReferences()[0].getServiceReferences() );
+// TestCase.assertNull( component.getReferences()[0].getServiceReferences() );
// remove the service, expect factory to deactivate and instance to dispose
srv1.drop();
delay();
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.UNSATISFIED);
TestCase.assertNull( instance.getInstance() );
// assert component factory only managed
- final Component[] allFactoryComponents2 = findComponentsByName( pid );
- TestCase.assertNotNull( allFactoryComponents2 );
- TestCase.assertEquals( 1, allFactoryComponents2.length );
- for ( int i = 0; i < allFactoryComponents2.length; i++ )
- {
- final Component c = allFactoryComponents2[i];
- if ( c.getId() == component.getId() )
- {
- TestCase.assertEquals( Component.STATE_UNSATISFIED, c.getState() );
- }
- else
- {
- TestCase.fail( "Unexpected Component " + c );
- }
- }
+ //TODO this check should be whether the service is registered.
+// final Component[] allFactoryComponents2 = findComponentConfigurationsByName( pid, -1 );
+// TestCase.assertNotNull( allFactoryComponents2 );
+// TestCase.assertEquals( 1, allFactoryComponents2.length );
+// for ( int i = 0; i < allFactoryComponents2.length; i++ )
+// {
+// final Component c = allFactoryComponents2[i];
+// if ( c.getId() == component.getId() )
+// {
+// TestCase.assertEquals( Component.STATE_UNSATISFIED, c.getState() );
+// }
+// else
+// {
+// TestCase.fail( "Unexpected Component " + c );
+// }
+// }
// registeranother service, factory must come back, instance not
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay();
- TestCase.assertEquals( Component.STATE_FACTORY, component.getState() );
+// TestCase.assertEquals( Component.STATE_FACTORY, component.getState() );
TestCase.assertNull( instance.getInstance() );
// assert component factory only managed
- final Component[] allFactoryComponents3 = findComponentsByName( pid );
- TestCase.assertNotNull( allFactoryComponents3 );
- TestCase.assertEquals( 1, allFactoryComponents3.length );
- for ( int i = 0; i < allFactoryComponents3.length; i++ )
- {
- final Component c = allFactoryComponents3[i];
- if ( c.getId() == component.getId() )
- {
- TestCase.assertEquals( Component.STATE_FACTORY, c.getState() );
- }
- else
- {
- TestCase.fail( "Unexpected Component " + c );
- }
- }
+ checkConfigurationCount(name, 0, -1);
+// final Component[] allFactoryComponents3 = findComponentConfigurationsByName( pid, -1 );
+// TestCase.assertNotNull( allFactoryComponents3 );
+// TestCase.assertEquals( 1, allFactoryComponents3.length );
+// for ( int i = 0; i < allFactoryComponents3.length; i++ )
+// {
+// final Component c = allFactoryComponents3[i];
+// if ( c.getId() == component.getId() )
+// {
+// TestCase.assertEquals( Component.STATE_FACTORY, c.getState() );
+// }
+// else
+// {
+// TestCase.fail( "Unexpected Component " + c );
+// }
+// }
}
@Test
public void test_optional_single_static()
{
- final Component component = findComponentByName( "test_optional_single_static" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
- // async enabling
- component.enable();
- delay();
+ String name ="test_optional_single_static";
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertEquals( srv1, comp10.m_singleRef );
@@ -718,7 +702,8 @@
srv1.drop();
delay(); // async reactivate
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp11 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp11 );
TestCase.assertNull( comp11.m_singleRef );
@@ -728,24 +713,26 @@
delay(); // async binding
// static reference does not rebind unless component is cycled for other reasons !!
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp12 );
TestCase.assertSame( comp11, comp12 );
TestCase.assertNull( comp12.m_singleRef );
TestCase.assertTrue( comp12.m_multiRef.isEmpty() );
- component.disable();
+ disableAndCheck(cc);
delay(); // async disabling
final SimpleServiceImpl srv3 = SimpleServiceImpl.create( bundleContext, "srv3" );
// enable component with two services available, expect srv2 bind
// async enabling
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp20 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp20 );
TestCase.assertNotSame( comp10, comp20 );
@@ -756,7 +743,8 @@
srv2.drop();
delay(); // async reactivate
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp21 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp21 );
TestCase.assertEquals( srv3, comp21.m_singleRef );
@@ -766,7 +754,8 @@
final SimpleServiceImpl srv4 = SimpleServiceImpl.create( bundleContext, "srv4" );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp22 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp22 );
TestCase.assertSame( comp21, comp22 );
@@ -777,7 +766,8 @@
srv4.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp23 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp23 );
TestCase.assertSame( comp21, comp23 );
@@ -786,7 +776,7 @@
TestCase.assertTrue( comp23.m_multiRef.isEmpty() );
// "reset"
- component.disable();
+ disableAndCheck(cc);
srv3.drop();
delay();
@@ -794,10 +784,11 @@
final SimpleServiceImpl srv5 = SimpleServiceImpl.create( bundleContext, "srv5", 10 );
final SimpleServiceImpl srv6 = SimpleServiceImpl.create( bundleContext, "srv6", 20 );
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp30 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp23, comp30 );
TestCase.assertEquals( srv6, comp30.m_singleRef );
@@ -807,7 +798,8 @@
final SimpleServiceImpl srv7 = SimpleServiceImpl.create( bundleContext, "srv7", 30 );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp31 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp30, comp31 );
TestCase.assertEquals( srv6, comp31.m_singleRef );
@@ -817,7 +809,8 @@
srv6.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp32 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp30, comp32 );
TestCase.assertNotSame( comp31, comp32 );
@@ -829,17 +822,11 @@
@Test
public void test_required_single_static()
{
- final Component component = findComponentByName( "test_required_single_static" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
- // async enabling
- component.enable();
- delay();
+ String name ="test_required_single_static";
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertEquals( srv1, comp10.m_singleRef );
@@ -848,30 +835,32 @@
srv1.drop();
delay(); // async reactivate
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.UNSATISFIED);
final SimpleComponent comp11 = SimpleComponent.INSTANCE;
TestCase.assertNull( comp11 );
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay(); // async binding
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp12 );
TestCase.assertEquals( srv2, comp12.m_singleRef );
TestCase.assertTrue( comp12.m_multiRef.isEmpty() );
- component.disable();
+ disableAndCheck(cc);
delay(); // async disabling
final SimpleServiceImpl srv3 = SimpleServiceImpl.create( bundleContext, "srv3" );
// enable component with two services available, expect srv2 bind
// async enabling
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp20 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp20 );
TestCase.assertNotSame( comp10, comp20 );
@@ -882,7 +871,8 @@
srv2.drop();
delay(); // async reactivate
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp21 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp21 );
TestCase.assertEquals( srv3, comp21.m_singleRef );
@@ -892,7 +882,8 @@
final SimpleServiceImpl srv4 = SimpleServiceImpl.create( bundleContext, "srv4" );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp22 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp22 );
TestCase.assertSame( comp21, comp22 );
@@ -903,7 +894,8 @@
srv4.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp23 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp23 );
TestCase.assertSame( comp21, comp23 );
@@ -912,7 +904,7 @@
TestCase.assertTrue( comp23.m_multiRef.isEmpty() );
// "reset"
- component.disable();
+ disableAndCheck(cc);
srv3.drop();
delay();
@@ -920,10 +912,11 @@
final SimpleServiceImpl srv5 = SimpleServiceImpl.create( bundleContext, "srv5", 10 );
final SimpleServiceImpl srv6 = SimpleServiceImpl.create( bundleContext, "srv6", 20 );
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp30 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp23, comp30 );
TestCase.assertEquals( srv6, comp30.m_singleRef );
@@ -933,7 +926,8 @@
final SimpleServiceImpl srv7 = SimpleServiceImpl.create( bundleContext, "srv7", 30 );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp31 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp30, comp31 );
TestCase.assertEquals( srv6, comp31.m_singleRef );
@@ -943,7 +937,8 @@
srv6.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp32 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp30, comp32 );
TestCase.assertNotSame( comp31, comp32 );
@@ -955,17 +950,11 @@
@Test
public void test_optional_multiple_static()
{
- final Component component = findComponentByName( "test_optional_multiple_static" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
- // async enabling
- component.enable();
- delay();
+ String name ="test_optional_multiple_static";
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertNull( comp10.m_singleRef );
@@ -974,7 +963,8 @@
srv1.drop();
delay(); // async reactivate
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp11 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp11 );
TestCase.assertNull( comp11.m_singleRef );
@@ -983,24 +973,26 @@
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay(); // async binding
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp12 );
TestCase.assertSame( comp11, comp12 );
TestCase.assertNull( comp12.m_singleRef );
TestCase.assertTrue( comp12.m_multiRef.isEmpty() );
- component.disable();
+ disableAndCheck(cc);
delay(); // async disabling
final SimpleServiceImpl srv3 = SimpleServiceImpl.create( bundleContext, "srv3" );
// enable component with two services available, expect both bind
// async enabling
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp20 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp20 );
TestCase.assertNotSame( comp10, comp20 );
@@ -1013,7 +1005,8 @@
srv2.drop();
delay(); // async reactivate
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp21 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp21 );
TestCase.assertNull( comp21.m_singleRef );
@@ -1024,7 +1017,8 @@
final SimpleServiceImpl srv4 = SimpleServiceImpl.create( bundleContext, "srv4" );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp22 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp22 );
TestCase.assertSame( comp21, comp22 );
@@ -1037,7 +1031,8 @@
srv4.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp23 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp23 );
TestCase.assertSame( comp21, comp23 );
@@ -1048,7 +1043,7 @@
TestCase.assertFalse( comp23.m_multiRef.contains( srv4 ) );
// "reset"
- component.disable();
+ disableAndCheck(cc);
srv3.drop();
delay();
@@ -1056,10 +1051,11 @@
final SimpleServiceImpl srv5 = SimpleServiceImpl.create( bundleContext, "srv5", 10 );
final SimpleServiceImpl srv6 = SimpleServiceImpl.create( bundleContext, "srv6", 20 );
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp30 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp23, comp30 );
TestCase.assertNull( comp30.m_singleRef );
@@ -1070,7 +1066,8 @@
final SimpleServiceImpl srv7 = SimpleServiceImpl.create( bundleContext, "srv7", 30 );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp31 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp30, comp31 );
TestCase.assertNull( comp31.m_singleRef );
@@ -1082,7 +1079,8 @@
srv6.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp32 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp30, comp32 );
TestCase.assertNotSame( comp31, comp32 );
@@ -1096,17 +1094,11 @@
@Test
public void test_required_multiple_static()
{
- final Component component = findComponentByName( "test_required_multiple_static" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
- // async enabling
- component.enable();
- delay();
+ String name ="test_required_multiple_static";
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertNull( comp10.m_singleRef );
@@ -1115,30 +1107,32 @@
srv1.drop();
delay(); // async reactivate
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.UNSATISFIED);
final SimpleComponent comp11 = SimpleComponent.INSTANCE;
TestCase.assertNull( comp11 );
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay(); // async binding
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp12 );
TestCase.assertNull( comp12.m_singleRef );
TestCase.assertTrue( comp12.m_multiRef.contains( srv2 ) );
- component.disable();
+ disableAndCheck(cc);
delay(); // async disabling
final SimpleServiceImpl srv3 = SimpleServiceImpl.create( bundleContext, "srv3" );
// enable component with two services available, expect both bind
// async enabling
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp20 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp20 );
TestCase.assertNotSame( comp10, comp20 );
@@ -1150,7 +1144,8 @@
srv2.drop();
delay(); // async reactivate
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp21 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp21 );
TestCase.assertNull( comp21.m_singleRef );
@@ -1161,7 +1156,8 @@
final SimpleServiceImpl srv4 = SimpleServiceImpl.create( bundleContext, "srv4" );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp22 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp22 );
TestCase.assertSame( comp21, comp22 );
@@ -1174,7 +1170,8 @@
srv4.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp23 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp20, comp23 );
TestCase.assertSame( comp21, comp23 );
@@ -1185,7 +1182,7 @@
TestCase.assertFalse( comp23.m_multiRef.contains( srv4 ) );
// "reset"
- component.disable();
+ disableAndCheck(cc);
srv3.drop();
delay();
@@ -1193,10 +1190,11 @@
final SimpleServiceImpl srv5 = SimpleServiceImpl.create( bundleContext, "srv5", 10 );
final SimpleServiceImpl srv6 = SimpleServiceImpl.create( bundleContext, "srv6", 20 );
- component.enable();
+ enableAndCheck(cc.description);
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp30 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp23, comp30 );
TestCase.assertNull( comp30.m_singleRef );
@@ -1207,7 +1205,8 @@
final SimpleServiceImpl srv7 = SimpleServiceImpl.create( bundleContext, "srv7", 30 );
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp31 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp30, comp31 );
TestCase.assertNull( comp31.m_singleRef );
@@ -1219,7 +1218,8 @@
srv6.drop();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp32 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp30, comp32 );
TestCase.assertNotSame( comp31, comp32 );
@@ -1232,25 +1232,19 @@
@Test
public void test_multi_service_bind_unbind_order()
{
- final Component component = findComponentByName( "test_multi_service_bind_unbind_order" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
final SimpleService2Impl srv2 = SimpleService2Impl.create( bundleContext, "srv2" );
- // async enabling
- component.enable();
- delay();
+ String name ="test_multi_service_bind_unbind_order";
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
final SimpleComponent2 comp10 = SimpleComponent2.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertEquals( 2, comp10.getBindings().size() );
TestCase.assertEquals( "bindSimpleService", comp10.getBindings().get( 0 ) );
TestCase.assertEquals( "bindSimpleService2", comp10.getBindings().get( 1 ) );
- component.disable();
+ disableAndCheck(cc);
delay();
TestCase.assertEquals( 4, comp10.getBindings().size() );
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ServiceChangedTest.java b/scr/src/test/java/org/apache/felix/scr/integration/ServiceChangedTest.java
index 9151c49..52fd68f 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/ServiceChangedTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ServiceChangedTest.java
@@ -21,12 +21,12 @@
import junit.framework.TestCase;
-import org.apache.felix.scr.Component;
import org.apache.felix.scr.integration.components.SimpleComponent;
import org.apache.felix.scr.integration.components.SimpleServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
@RunWith(JUnit4TestRunner.class)
@@ -44,17 +44,10 @@
@Test
public void test_optional_single_dynamic()
{
- final Component component = findComponentByName( "test_optional_single_dynamic_target" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
+ String name = "test_optional_single_dynamic_target";
+ getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
- // async enabling
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertEquals( srv1, comp10.m_singleRef );
@@ -74,7 +67,7 @@
// set target to not match any more
srv1.setFilterProperty( "don't match" );
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp11 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp10, comp11 );
TestCase.assertNull( comp11.m_singleRef );
@@ -85,7 +78,7 @@
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay(); // async binding
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp10, comp12 );
TestCase.assertEquals( srv2, comp12.m_singleRef );
@@ -112,17 +105,10 @@
@Test
public void test_required_single_dynamic()
{
- final Component component = findComponentByName( "test_required_single_dynamic_target" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
-
- // async enabling
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ String name = "test_required_single_dynamic_target";
+ getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
+
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertEquals( srv1, comp10.m_singleRef );
@@ -141,7 +127,7 @@
// set target to not match any more -> deactivate this component
srv1.setFilterProperty( "don't match" );
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.UNSATISFIED);
TestCase.assertNull( SimpleComponent.INSTANCE );
TestCase.assertNull( comp10.m_singleRef );
TestCase.assertTrue( comp10.m_multiRef.isEmpty() );
@@ -151,7 +137,7 @@
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay(); // async binding
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp12 );
TestCase.assertEquals( srv2, comp12.m_singleRef );
@@ -178,17 +164,9 @@
@Test
public void test_optional_multiple_dynamic()
{
- final Component component = findComponentByName( "test_optional_multiple_dynamic_target" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
-
- // async enabling
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ String name = "test_optional_multiple_dynamic_target";
+ getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertNull( comp10.m_singleRef );
@@ -208,7 +186,7 @@
// set target to not match any more
srv1.setFilterProperty( "don't match" );
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp11 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp10, comp11 );
TestCase.assertNull( comp10.m_singleRef );
@@ -219,7 +197,7 @@
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay(); // async binding
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertSame( comp10, comp12 );
TestCase.assertNull( comp10.m_singleRef );
@@ -249,17 +227,9 @@
@Test
public void test_required_multiple_dynamic()
{
- final Component component = findComponentByName( "test_required_multiple_dynamic_target" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
-
- // async enabling
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ String name = "test_required_multiple_dynamic_target";
+ getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertNull( comp10.m_singleRef );
@@ -279,7 +249,7 @@
// set target to not match any more
srv1.setFilterProperty( "don't match" );
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.UNSATISFIED);
final SimpleComponent comp11 = SimpleComponent.INSTANCE;
TestCase.assertNull( comp11 );
TestCase.assertNull( comp10.m_singleRef );
@@ -290,7 +260,7 @@
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay(); // async binding
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp12 );
TestCase.assertNull( comp12.m_singleRef );
@@ -320,17 +290,9 @@
@Test
public void test_optional_single_static()
{
- final Component component = findComponentByName( "test_optional_single_static_target" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
-
- // async enabling
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ String name = "test_optional_single_static_target";
+ getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertEquals( srv1, comp10.m_singleRef );
@@ -351,7 +313,7 @@
srv1.setFilterProperty( "don't match" );
delay(); // async reactivation
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp11 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp11 );
TestCase.assertNull( comp11.m_singleRef );
@@ -362,7 +324,7 @@
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay(); // async binding
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp12 );
TestCase.assertSame( comp11, comp12 );
@@ -399,17 +361,9 @@
@Test
public void test_required_single_static()
{
- final Component component = findComponentByName( "test_required_single_static_target" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
-
- // async enabling
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ String name = "test_required_single_static_target";
+ getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertEquals( srv1, comp10.m_singleRef );
@@ -428,7 +382,7 @@
// set target to not match any more -> deactivate this component
srv1.setFilterProperty( "don't match" );
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.UNSATISFIED);
TestCase.assertNull( SimpleComponent.INSTANCE );
TestCase.assertNull( comp10.m_singleRef );
TestCase.assertTrue( comp10.m_multiRef.isEmpty() );
@@ -438,7 +392,7 @@
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay(); // async binding
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp12 );
TestCase.assertEquals( srv2, comp12.m_singleRef );
@@ -473,17 +427,9 @@
@Test
public void test_optional_multiple_static()
{
- final Component component = findComponentByName( "test_optional_multiple_static_target" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
-
- // async enabling
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ String name = "test_optional_multiple_static_target";
+ getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertNull( comp10.m_singleRef );
@@ -504,7 +450,7 @@
srv1.setFilterProperty( "don't match" );
delay(); // async reactivation (for unbind)
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp11 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp11 );
TestCase.assertNull( comp10.m_singleRef );
@@ -519,7 +465,7 @@
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay(); // async binding (not expected for an optional static ref)
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp12 );
TestCase.assertSame( comp11, comp12 );
@@ -541,7 +487,7 @@
srv2.setFilterProperty( "don't match" );
delay(); // allow reactivation delay (for unbind/bind)
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp13 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp13 );
TestCase.assertSame( comp11, comp13 );
@@ -557,17 +503,9 @@
@Test
public void test_required_multiple_static()
{
- final Component component = findComponentByName( "test_required_multiple_static_target" );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
-
- // async enabling
- component.enable();
- delay();
-
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ String name = "test_required_multiple_static_target";
+ getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertNull( comp10.m_singleRef );
@@ -587,7 +525,7 @@
// set target to not match any more
srv1.setFilterProperty( "don't match" );
- TestCase.assertEquals( Component.STATE_UNSATISFIED, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.UNSATISFIED);
final SimpleComponent comp11 = SimpleComponent.INSTANCE;
TestCase.assertNull( comp11 );
TestCase.assertNull( comp10.m_singleRef );
@@ -598,7 +536,7 @@
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay(); // async binding
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp12 );
TestCase.assertNull( comp12.m_singleRef );
@@ -619,7 +557,7 @@
srv2.setFilterProperty( "don't match" );
delay(); // allow reactivation/rebinding
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp13 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp13 );
TestCase.assertNotSame( comp11, comp13 );
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ServiceComponentTest.java b/scr/src/test/java/org/apache/felix/scr/integration/ServiceComponentTest.java
index 9f1c7ba..597217a 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/ServiceComponentTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ServiceComponentTest.java
@@ -20,20 +20,16 @@
import java.io.IOException;
-import java.util.Dictionary;
-import java.util.Hashtable;
import junit.framework.TestCase;
-import org.apache.felix.scr.Component;
-import org.apache.felix.scr.impl.config.ScrConfiguration;
import org.apache.felix.scr.integration.components.SimpleComponent;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.Configuration;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
@RunWith(JUnit4TestRunner.class)
@@ -52,15 +48,8 @@
final String pid = "ServiceComponent";
// one single component exists without configuration
- final Component component = findComponentByName( pid );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
- component.enable();
- delay();
-
+ getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent instance = SimpleComponent.INSTANCE;
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
TestCase.assertNotNull( instance );
// assert component properties (all !)
@@ -99,15 +88,7 @@
final String pid = "DelayedServiceComponent";
// one single component exists without configuration
- final Component component = findComponentByName( pid );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
- component.enable();
- delay();
-
- // the delayed service is expected to only be registered before use
- TestCase.assertEquals( Component.STATE_REGISTERED, component.getState() );
+ getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.SATISFIED);
TestCase.assertNull( SimpleComponent.INSTANCE );
// get the service
@@ -118,7 +99,7 @@
final Object theService = bundleContext.getService( reference );
// service must now be active
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
// and of course we expect the instance
TestCase.assertEquals( SimpleComponent.INSTANCE, theService );
@@ -129,7 +110,7 @@
}
// service is not used anymore, ensure REGISTERED state and INSTANCE==null
- TestCase.assertEquals( Component.STATE_REGISTERED, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.SATISFIED);
TestCase.assertNull( SimpleComponent.INSTANCE );
}
@@ -140,22 +121,15 @@
final String pid = "DelayedServiceComponent";
// one single component exists without configuration
- final Component component = findComponentByName( pid );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
- component.enable();
- delay();
-
// the delayed service is expected to only be registered before use
- TestCase.assertEquals( Component.STATE_REGISTERED, component.getState() );
+ getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.SATISFIED);
TestCase.assertNull( SimpleComponent.INSTANCE );
// get the service once
final ServiceReference reference1 = bundleContext.getServiceReference( "java.lang.Object" );
TestCase.assertNotNull( reference1 );
bundleContext.getService( reference1 );
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertNotNull( SimpleComponent.INSTANCE );
// get the service a second time
@@ -163,17 +137,17 @@
final ServiceReference reference2 = bundleContext2.getServiceReference( "java.lang.Object" );
TestCase.assertNotNull( reference2 );
bundleContext2.getService( reference2 );
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertNotNull( SimpleComponent.INSTANCE );
// unget the service once -- must still be active !
bundleContext2.ungetService( reference2 );
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertNotNull( SimpleComponent.INSTANCE );
// unget the service second time -- must be registered and null now
bundleContext.ungetService( reference1 );
- TestCase.assertEquals( Component.STATE_REGISTERED, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.SATISFIED);
TestCase.assertNull( SimpleComponent.INSTANCE );
}
@@ -194,15 +168,8 @@
final String pid = "DelayedKeepInstancesServiceComponent";
// one single component exists without configuration
- final Component component = findComponentByName( pid );
- TestCase.assertNotNull( component );
- TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
-
- component.enable();
- delay();
-
// the delayed service is expected to only be registered before use
- TestCase.assertEquals( Component.STATE_REGISTERED, component.getState() );
+ getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.SATISFIED);
TestCase.assertNull( SimpleComponent.INSTANCE );
// get the service
@@ -213,7 +180,7 @@
final Object theService = bundleContext.getService( reference );
// service must now be active
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
// and of course we expect the instance
TestCase.assertEquals( SimpleComponent.INSTANCE, theService );
@@ -224,7 +191,7 @@
}
// component instance must not be disposed off (due to config)
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+ findComponentConfigurationByName(pid, ComponentConfigurationDTO.ACTIVE);
TestCase.assertNotNull( SimpleComponent.INSTANCE );
// delete the SCR configuration again
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/TargetedPIDTest.java b/scr/src/test/java/org/apache/felix/scr/integration/TargetedPIDTest.java
index 25589fb..b4339d0 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/TargetedPIDTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/TargetedPIDTest.java
@@ -20,23 +20,24 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import junit.framework.TestCase;
-import org.apache.felix.scr.Component;
import org.apache.felix.scr.integration.components.SimpleComponent;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.framework.Bundle;
-import org.osgi.framework.ServiceRegistration;
+//import org.osgi.framework.ServiceRegistration;
import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationEvent;
-import org.osgi.service.cm.ConfigurationListener;
+//import org.osgi.service.cm.ConfigurationEvent;
+//import org.osgi.service.cm.ConfigurationListener;
import org.osgi.service.cm.ConfigurationPermission;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
@RunWith(JUnit4TestRunner.class)
public class TargetedPIDTest extends ComponentTestBase
@@ -45,7 +46,7 @@
private static final String TARGETED_PID = "targetedPID";
private static final String COMPONENT_NAME = "SimpleComponent.configuration.require";
private static final String REGION = "?foo";
- private boolean eventReceived;
+// private boolean eventReceived;
static
{
@@ -88,14 +89,12 @@
configSNVL.setBundleLocation( REGION );
//Add more and more specific components to check that they pick up the appropriate configuration
- Set<Component> known = new HashSet<Component>();
+ Set<ComponentConfigurationDTO> known = new HashSet<ComponentConfigurationDTO>();
- final Component component = findComponentByName( COMPONENT_NAME );
+ final ComponentConfigurationDTO component = findComponentConfigurationByName( COMPONENT_NAME, ComponentConfigurationDTO.ACTIVE );
known.add( component );
- component.enable();
- delay();
+// component.enable();
- TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
TestCase.assertNotNull( SimpleComponent.INSTANCE );
SimpleComponent sc = SimpleComponent.INSTANCE;
TestCase.assertEquals( pid, sc.getProperty( TARGETED_PID ) );
@@ -103,38 +102,36 @@
Bundle bSN = installBundle( descriptorFile, COMPONENT_PACKAGE, "simplecomponent2", "0.0.11", null );
bSN.start();
- Component[] components = findComponentsByName( pid );
- TestCase.assertEquals( 2, components.length );
- Component cSN = getNewComponent( known, components );
+ findComponentConfigurationByName( bSN, pid, ComponentConfigurationDTO.ACTIVE );
- cSN.enable();
- delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, cSN.getState() );
+// cSN.enable();
+// delay();
+// TestCase.assertEquals( Component.STATE_ACTIVE, cSN.getState() );
SimpleComponent scSN = SimpleComponent.INSTANCE;
TestCase.assertEquals( pidSN, scSN.getProperty( TARGETED_PID ) );
Bundle bSNV = installBundle( descriptorFile, COMPONENT_PACKAGE, "simplecomponent2", "0.0.12", null );
bSNV.start();
- components = findComponentsByName( pid );
- TestCase.assertEquals( 3, components.length );
- Component cSNV = getNewComponent( known, components );
+ findComponentConfigurationByName( bSNV, pid, ComponentConfigurationDTO.ACTIVE );
+// TestCase.assertEquals( 3, components.size() );
+// ComponentConfigurationDTO cSNV = getNewComponent( known, components );
- cSNV.enable();
- delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, cSNV.getState() );
+// cSNV.enable();
+// delay();
+// TestCase.assertEquals( Component.STATE_ACTIVE, cSNV.getState() );
SimpleComponent scSNV = SimpleComponent.INSTANCE;
TestCase.assertEquals( pidSNV, scSNV.getProperty( TARGETED_PID ) );
Bundle bSNVL = installBundle( descriptorFile, COMPONENT_PACKAGE, "simplecomponent2", "0.0.12", "bundleLocation" );
bSNVL.start();
- components = findComponentsByName( pid );
- TestCase.assertEquals( 4, components.length );
- Component cSNVL = getNewComponent( known, components );
+ findComponentConfigurationsByName( bSNVL, pid, ComponentConfigurationDTO.ACTIVE );
+// TestCase.assertEquals( 4, components.size() );
+// ComponentConfigurationDTO cSNVL = getNewComponent( known, components );
- cSNVL.enable();
- delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, cSNVL.getState() );
+// cSNVL.enable();
+// delay();
+// TestCase.assertEquals( Component.STATE_ACTIVE, cSNVL.getState() );
SimpleComponent scSNVL = SimpleComponent.INSTANCE;
TestCase.assertEquals( pidSNVL, scSNVL.getProperty( TARGETED_PID ) );
@@ -142,37 +139,43 @@
configSNVL.delete();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, cSNVL.getState() );
+ findComponentConfigurationsByName( bSNVL, pid, ComponentConfigurationDTO.ACTIVE );
+// TestCase.assertEquals( Component.STATE_ACTIVE, cSNVL.getState() );
TestCase.assertEquals( pidSNV, scSNVL.getProperty( TARGETED_PID ) );
configSNV.delete();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, cSNVL.getState() );
+ findComponentConfigurationsByName( bSNVL, pid, ComponentConfigurationDTO.ACTIVE );
+// TestCase.assertEquals( Component.STATE_ACTIVE, cSNVL.getState() );
TestCase.assertEquals( pidSN, scSNVL.getProperty( TARGETED_PID ) );
- TestCase.assertEquals( Component.STATE_ACTIVE, cSNV.getState() );
+ findComponentConfigurationByName( bSNV, pid, ComponentConfigurationDTO.ACTIVE );
+// TestCase.assertEquals( Component.STATE_ACTIVE, cSNV.getState() );
TestCase.assertEquals( pidSN, scSNV.getProperty( TARGETED_PID ) );
configSN.delete();
delay();
- TestCase.assertEquals( Component.STATE_ACTIVE, cSNVL.getState() );
+ findComponentConfigurationsByName( bSNVL, pid, ComponentConfigurationDTO.ACTIVE );
+// TestCase.assertEquals( Component.STATE_ACTIVE, cSNVL.getState() );
TestCase.assertEquals( pid, scSNVL.getProperty( TARGETED_PID ) );
- TestCase.assertEquals( Component.STATE_ACTIVE, cSNV.getState() );
+ findComponentConfigurationByName( bSNV, pid, ComponentConfigurationDTO.ACTIVE );
+// TestCase.assertEquals( Component.STATE_ACTIVE, cSNV.getState() );
TestCase.assertEquals( pid, scSNV.getProperty( TARGETED_PID ) );
- TestCase.assertEquals( Component.STATE_ACTIVE, cSN.getState() );
+ findComponentConfigurationByName( bSN, pid, ComponentConfigurationDTO.ACTIVE );
+// TestCase.assertEquals( Component.STATE_ACTIVE, cSN.getState() );
TestCase.assertEquals( pid, scSN.getProperty( TARGETED_PID ) );
}
- private Component getNewComponent(Set<Component> known, Component[] components)
- {
- List<Component> cs = new ArrayList(Arrays.asList( components ));
- cs.removeAll( known );
- Component c = cs.get( 0 );
- known.add(c);
- return c;
- }
+// private ComponentConfigurationDTO getNewComponent(Set<ComponentConfigurationDTO> known, Collection<ComponentConfigurationDTO> components)
+// {
+// List<ComponentConfigurationDTO> cs = new ArrayList(Arrays.asList( components ));
+// cs.removeAll( known );
+// ComponentConfigurationDTO c = cs.get( 0 );
+// known.add(c);
+// return c;
+// }
}
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/components/ActivatorComponent.java b/scr/src/test/java/org/apache/felix/scr/integration/components/ActivatorComponent.java
index cc68d99..1f33540 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/components/ActivatorComponent.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/components/ActivatorComponent.java
@@ -33,10 +33,17 @@
public static final String FLAG_FAIL_DEACTIVATE = "failDeactivate";
public static final String FLAG_REGISTER_SERVICE = "registerService";
+
+ private static ActivatorComponent activatorComponent;
private ServiceRegistration registration;
private SimpleService simpleService;
+
+ public static ActivatorComponent getInstance()
+ {
+ return activatorComponent;
+ }
@SuppressWarnings("unused")
private void myActivate( BundleContext context, Map<?, ?> configuration )
@@ -49,6 +56,11 @@
{
registration = context.registerService( SimpleService.class.getName(), new SimpleServiceImpl(), null );
}
+ if ( activatorComponent != null )
+ {
+ throw new IllegalStateException( "not the only activator component");
+ }
+ this.activatorComponent = this;
}
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/components/Felix4350Component.java b/scr/src/test/java/org/apache/felix/scr/integration/components/Felix4350Component.java
index f4423e8..af57cc1 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/components/Felix4350Component.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/components/Felix4350Component.java
@@ -20,6 +20,10 @@
public class Felix4350Component {
+ private static Felix4350Component m_instance;
+ private static int m_activateCount;
+ private static int m_deactivateCount;
+
private SimpleComponent component1;
private SimpleComponent2 component2;
@@ -40,9 +44,27 @@
}
public void start() {
+ m_instance = this;
+ m_activateCount++;
}
public void stop() {
+ m_instance = null;
+ m_deactivateCount++;
}
-
+
+ public static void check(int activateCount, int deactivateCount, boolean activated)
+ {
+ if (activateCount != m_activateCount ||
+ deactivateCount != m_deactivateCount ||
+ activated == (m_instance == null))
+ {
+ String message = "activation: expected " + activateCount + " actual " + m_activateCount +
+ " deactivation: expected " + deactivateCount + " actual " + m_deactivateCount +
+ " activated: expected " + activated + " actual " + (m_instance != null);
+ throw new IllegalStateException( message );
+
+ }
+ }
+
}
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/components/activatesignature/AbstractActivateSignatureTestComponent.java b/scr/src/test/java/org/apache/felix/scr/integration/components/activatesignature/AbstractActivateSignatureTestComponent.java
index 6061d6b..76950c6 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/components/activatesignature/AbstractActivateSignatureTestComponent.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/components/activatesignature/AbstractActivateSignatureTestComponent.java
@@ -19,6 +19,7 @@
package org.apache.felix.scr.integration.components.activatesignature;
+import java.util.HashMap;
import java.util.Map;
import org.osgi.service.component.ComponentConstants;
@@ -27,6 +28,13 @@
public abstract class AbstractActivateSignatureTestComponent
{
+
+ private static final Map<String, AbstractActivateSignatureTestComponent> instances = new HashMap<String, AbstractActivateSignatureTestComponent>();
+
+ public static AbstractActivateSignatureTestComponent getInstance(String name)
+ {
+ return instances.get(name);
+ }
private String methodCalled;
@@ -40,6 +48,7 @@
protected void setMethodCalled( String methodCalled )
{
this.methodCalled = methodCalled;
+ instances.put(methodCalled, this);
}
diff --git a/scr/src/test/resources/integration_test_FELIX_4188_1.xml b/scr/src/test/resources/integration_test_FELIX_4188_1.xml
index aa69698..2b5c631 100644
--- a/scr/src/test/resources/integration_test_FELIX_4188_1.xml
+++ b/scr/src/test/resources/integration_test_FELIX_4188_1.xml
@@ -13,5 +13,8 @@
<scr:component xmlns:scr='http://www.osgi.org/xmlns/scr/v1.1.0'
name='org.apache.felix.scr.integration.components.Felix4188Component-1' activate='start' deactivate='stop'>
<implementation class="org.apache.felix.scr.integration.components.felix4188.Felix4188Component" />
+ <service>
+ <provide>org.apache.felix.scr.integration.components.felix4188.Felix4188Component</provide>
+ </service>
</scr:component>
</components>
diff --git a/scr/src/test/resources/integration_test_FELIX_4188_2.xml b/scr/src/test/resources/integration_test_FELIX_4188_2.xml
index 99eec1d..8eccbf7 100644
--- a/scr/src/test/resources/integration_test_FELIX_4188_2.xml
+++ b/scr/src/test/resources/integration_test_FELIX_4188_2.xml
@@ -13,5 +13,8 @@
<scr:component xmlns:scr='http://www.osgi.org/xmlns/scr/v1.1.0'
name='org.apache.felix.scr.integration.components.Felix4188Component-2' activate='start' deactivate='stop'>
<implementation class="org.apache.felix.scr.integration.components.felix4188.Felix4188Component" />
+ <service>
+ <provide>org.apache.felix.scr.integration.components.felix4188.Felix4188Component</provide>
+ </service>
</scr:component>
</components>
diff --git a/scr/src/test/resources/integration_test_simple_components_location.xml b/scr/src/test/resources/integration_test_simple_components_location.xml
index 072c8a6..076f0c2 100644
--- a/scr/src/test/resources/integration_test_simple_components_location.xml
+++ b/scr/src/test/resources/integration_test_simple_components_location.xml
@@ -21,11 +21,11 @@
<!-- component requires configuration -->
<scr:component name="SimpleComponent.configuration.require"
- enabled="false"
+ enabled="true"
configuration-policy="require"
modified="modified" >
<implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
- <property name="service.pid" value="SimpleComponent.configuration.require" />
+ <!-- <property name="service.pid" value="SimpleComponent.configuration.require" /> -->
</scr:component>
</components>