felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1602633 [5/5] - in /felix/trunk/scr: ./ src/test/java/org/apache/felix/scr/integration/ src/test/java/org/apache/felix/scr/integration/components/ src/test/java/org/apache/felix/scr/integration/components/activatesignature/ src/test/resour...
Date Sun, 15 Jun 2014 01:09:32 GMT
Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/TargetedPIDTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/TargetedPIDTest.java?rev=1602633&r1=1602632&r2=1602633&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/TargetedPIDTest.java (original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/TargetedPIDTest.java Sun
Jun 15 01:09:31 2014
@@ -20,23 +20,24 @@ package org.apache.felix.scr.integration
 
 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 @@ public class TargetedPIDTest extends Com
     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 @@ public class TargetedPIDTest extends Com
         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 @@ public class TargetedPIDTest extends Com
         
         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 ); 
-        
-        cSNV.enable();
-        delay();
-        TestCase.assertEquals( Component.STATE_ACTIVE, cSNV.getState() );
+        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() );
         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 ); 
-        
-        cSNVL.enable();
-        delay();
-        TestCase.assertEquals( Component.STATE_ACTIVE, cSNVL.getState() );
+        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() );
         SimpleComponent scSNVL = SimpleComponent.INSTANCE;
         TestCase.assertEquals( pidSNVL, scSNVL.getProperty( TARGETED_PID ) );
         
@@ -142,37 +139,43 @@ public class TargetedPIDTest extends Com
         
         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;
+//    }
 
 
 }

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/ActivatorComponent.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/ActivatorComponent.java?rev=1602633&r1=1602632&r2=1602633&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/ActivatorComponent.java
(original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/ActivatorComponent.java
Sun Jun 15 01:09:31 2014
@@ -33,10 +33,17 @@ public class ActivatorComponent
     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 @@ public class ActivatorComponent
         {
             registration = context.registerService( SimpleService.class.getName(), new SimpleServiceImpl(),
null );
         }
+        if ( activatorComponent != null )
+        {
+        	throw new IllegalStateException( "not the only activator component");
+        }
+        this.activatorComponent = this;
     }
 
 

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/Felix4350Component.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/Felix4350Component.java?rev=1602633&r1=1602632&r2=1602633&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/Felix4350Component.java
(original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/Felix4350Component.java
Sun Jun 15 01:09:31 2014
@@ -20,6 +20,10 @@ package org.apache.felix.scr.integration
 
 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 class Felix4350Component {
     }
 
     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 );
+    		
+    	}
+    }
+    
 }

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/activatesignature/AbstractActivateSignatureTestComponent.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/activatesignature/AbstractActivateSignatureTestComponent.java?rev=1602633&r1=1602632&r2=1602633&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/activatesignature/AbstractActivateSignatureTestComponent.java
(original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/activatesignature/AbstractActivateSignatureTestComponent.java
Sun Jun 15 01:09:31 2014
@@ -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 @@ import org.osgi.service.component.Compon
 
 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 @@ public abstract class AbstractActivateSi
     protected void setMethodCalled( String methodCalled )
     {
         this.methodCalled = methodCalled;
+        instances.put(methodCalled, this);
     }
 
 

Modified: felix/trunk/scr/src/test/resources/integration_test_FELIX_4188_1.xml
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/resources/integration_test_FELIX_4188_1.xml?rev=1602633&r1=1602632&r2=1602633&view=diff
==============================================================================
--- felix/trunk/scr/src/test/resources/integration_test_FELIX_4188_1.xml (original)
+++ felix/trunk/scr/src/test/resources/integration_test_FELIX_4188_1.xml Sun Jun 15 01:09:31
2014
@@ -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>

Modified: felix/trunk/scr/src/test/resources/integration_test_FELIX_4188_2.xml
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/resources/integration_test_FELIX_4188_2.xml?rev=1602633&r1=1602632&r2=1602633&view=diff
==============================================================================
--- felix/trunk/scr/src/test/resources/integration_test_FELIX_4188_2.xml (original)
+++ felix/trunk/scr/src/test/resources/integration_test_FELIX_4188_2.xml Sun Jun 15 01:09:31
2014
@@ -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>

Modified: felix/trunk/scr/src/test/resources/integration_test_simple_components_location.xml
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/resources/integration_test_simple_components_location.xml?rev=1602633&r1=1602632&r2=1602633&view=diff
==============================================================================
--- felix/trunk/scr/src/test/resources/integration_test_simple_components_location.xml (original)
+++ felix/trunk/scr/src/test/resources/integration_test_simple_components_location.xml Sun
Jun 15 01:09:31 2014
@@ -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>



Mime
View raw message