You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2016/12/28 09:41:36 UTC
svn commit: r1776251 [2/2] - in /felix/trunk/configadmin: ./
src/main/java/org/apache/felix/cm/file/
src/main/java/org/apache/felix/cm/impl/
src/main/java/org/apache/felix/cm/impl/helper/
src/test/java/org/apache/felix/cm/ src/test/java/org/apache/feli...
Modified: felix/trunk/configadmin/src/test/java/org/apache/felix/cm/MockBundle.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/test/java/org/apache/felix/cm/MockBundle.java?rev=1776251&r1=1776250&r2=1776251&view=diff
==============================================================================
--- felix/trunk/configadmin/src/test/java/org/apache/felix/cm/MockBundle.java (original)
+++ felix/trunk/configadmin/src/test/java/org/apache/felix/cm/MockBundle.java Wed Dec 28 09:41:36 2016
@@ -50,128 +50,150 @@ public class MockBundle implements Bundl
}
+ @Override
public Enumeration findEntries( String arg0, String arg1, boolean arg2 )
{
return null;
}
+ @Override
public BundleContext getBundleContext()
{
return context;
}
+ @Override
public long getBundleId()
{
return 0;
}
+ @Override
public URL getEntry( String arg0 )
{
return null;
}
+ @Override
public Enumeration getEntryPaths( String arg0 )
{
return null;
}
+ @Override
public Dictionary getHeaders()
{
return null;
}
+ @Override
public Dictionary getHeaders( String arg0 )
{
return null;
}
+ @Override
public long getLastModified()
{
return 0;
}
+ @Override
public String getLocation()
{
return location;
}
+ @Override
public ServiceReference[] getRegisteredServices()
{
return null;
}
+ @Override
public URL getResource( String arg0 )
{
return null;
}
+ @Override
public Enumeration getResources( String arg0 )
{
return null;
}
+ @Override
public ServiceReference[] getServicesInUse()
{
return null;
}
+ @Override
public int getState()
{
return 0;
}
+ @Override
public String getSymbolicName()
{
return null;
}
+ @Override
public boolean hasPermission( Object arg0 )
{
return false;
}
+ @Override
public Class loadClass( String arg0 ) throws ClassNotFoundException
{
throw new ClassNotFoundException( arg0 );
}
+ @Override
public void start()
{
}
+ @Override
public void stop()
{
}
+ @Override
public void uninstall()
{
}
+ @Override
public void update()
{
}
+ @Override
public void update( InputStream arg0 ) throws BundleException
{
if ( arg0 != null )
@@ -188,16 +210,19 @@ public class MockBundle implements Bundl
}
+ @Override
public void start( int options )
{
}
+ @Override
public void stop( int options )
{
}
+ @Override
public int compareTo( Bundle o )
{
return 0;
@@ -206,26 +231,30 @@ public class MockBundle implements Bundl
// Framework 1.5 additions
+ @Override
public Map<X509Certificate, List<X509Certificate>> getSignerCertificates( int signersType )
{
throw new AbstractMethodError( "Not supported on Framework API 1.4; added in Framework API 1.5" );
}
+ @Override
public Version getVersion()
{
- throw new AbstractMethodError( "Not supported on Framework API 1.4; added in Framework API 1.5" );
+ return Version.emptyVersion;
}
// Framework 1.6 additions
+ @Override
public <A> A adapt( Class<A> type )
{
throw new AbstractMethodError( "Not supported on Framework API 1.4; added in Framework API 1.6" );
}
+ @Override
public File getDataFile( String filename )
{
throw new AbstractMethodError( "Not supported on Framework API 1.4; added in Framework API 1.6" );
Modified: felix/trunk/configadmin/src/test/java/org/apache/felix/cm/impl/ConfigurationManagerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/test/java/org/apache/felix/cm/impl/ConfigurationManagerTest.java?rev=1776251&r1=1776250&r2=1776251&view=diff
==============================================================================
--- felix/trunk/configadmin/src/test/java/org/apache/felix/cm/impl/ConfigurationManagerTest.java (original)
+++ felix/trunk/configadmin/src/test/java/org/apache/felix/cm/impl/ConfigurationManagerTest.java Wed Dec 28 09:41:36 2016
@@ -28,6 +28,7 @@ import java.util.HashSet;
import java.util.Hashtable;
import java.util.Map;
import java.util.Set;
+
import org.apache.felix.cm.MockBundleContext;
import org.apache.felix.cm.MockLogService;
import org.apache.felix.cm.MockNotCachablePersistenceManager;
@@ -42,6 +43,7 @@ import org.osgi.service.cm.Configuration
import org.osgi.service.cm.SynchronousConfigurationListener;
import org.osgi.service.log.LogService;
import org.osgi.util.tracker.ServiceTracker;
+
import junit.framework.TestCase;
public class ConfigurationManagerTest extends TestCase
@@ -61,6 +63,7 @@ public class ConfigurationManagerTest ex
output = new ByteArrayOutputStream();
System.setErr( new PrintStream( output ) );
+ setLogLevel(LogService.LOG_WARNING);
}
@@ -77,11 +80,11 @@ public class ConfigurationManagerTest ex
String pid = "testDefaultPersistenceManager";
ConfigurationManager configMgr = new ConfigurationManager();
setServiceTrackerField( configMgr, "persistenceManagerTracker" );
-
+
Field field = configMgr.getClass().getDeclaredField( "persistenceManagers" );
field.setAccessible( true );
CachingPersistenceManagerProxy[] persistenceManagers = new CachingPersistenceManagerProxy [1];
- PersistenceManager pm =new MockPersistenceManager();
+ PersistenceManager pm =new MockPersistenceManager();
Dictionary dictionary = new Hashtable();
dictionary.put( "property1", "value1" );
dictionary.put( Constants.SERVICE_PID, pid );
@@ -89,36 +92,36 @@ public class ConfigurationManagerTest ex
persistenceManagers[0] = new CachingPersistenceManagerProxy(pm);
field.set(configMgr, persistenceManagers);
-
+
ConfigurationImpl[] conf = configMgr.listConfigurations(new ConfigurationAdminImpl(configMgr, null), null);
-
+
assertEquals(1, conf.length);
assertEquals(2, conf[0].getProperties(true).size());
-
+
dictionary = new Hashtable();
dictionary.put( "property1", "value2" );
pid = "testDefaultPersistenceManager";
dictionary.put( Constants.SERVICE_PID, pid );
pm.store( pid, dictionary );
-
+
conf = configMgr.listConfigurations(new ConfigurationAdminImpl(configMgr, null), null);
assertEquals(1, conf.length);
assertEquals(2, conf[0].getProperties(true).size());
// verify that the property in the configurations cache was used
assertEquals("value1", conf[0].getProperties(true).get("property1"));
- }
-
+ }
+
public void test_listConfigurations_notcached() throws Exception
{
- String pid = "testDefaultPersistenceManager";
+ String pid = "testDefaultPersistenceManager";
ConfigurationManager configMgr = new ConfigurationManager();
setServiceTrackerField( configMgr, "persistenceManagerTracker" );
-
+
Field field = configMgr.getClass().getDeclaredField( "persistenceManagers" );
field.setAccessible( true );
CachingPersistenceManagerProxy[] persistenceManagers = new CachingPersistenceManagerProxy[1];
- PersistenceManager pm =new MockNotCachablePersistenceManager();
+ PersistenceManager pm =new MockNotCachablePersistenceManager();
Dictionary dictionary = new Hashtable();
dictionary.put( "property1", "value1" );
dictionary.put( Constants.SERVICE_PID, pid );
@@ -126,18 +129,18 @@ public class ConfigurationManagerTest ex
persistenceManagers[0] = new CachingPersistenceManagerProxy(pm);
field.set(configMgr, persistenceManagers);
-
+
ConfigurationImpl[] conf = configMgr.listConfigurations(new ConfigurationAdminImpl(configMgr, null), null);
-
+
assertEquals(1, conf.length);
assertEquals(2, conf[0].getProperties(true).size());
-
+
dictionary = new Hashtable();
dictionary.put("property1", "valueNotCached");
pid = "testDefaultPersistenceManager";
dictionary.put( Constants.SERVICE_PID, pid );
pm.store( pid, dictionary );
-
+
conf = configMgr.listConfigurations(new ConfigurationAdminImpl(configMgr, null), null);
assertEquals(1, conf.length);
assertEquals(2, conf[0].getProperties(true).size());
@@ -148,48 +151,48 @@ public class ConfigurationManagerTest ex
public void testLogNoLogService()
{
- ConfigurationManager configMgr = createConfigurationManager( null );
+ ConfigurationManager configMgr = createConfigurationManagerAndLog( null );
- setLogLevel( configMgr, LogService.LOG_WARNING );
+ setLogLevel( LogService.LOG_WARNING );
assertNoLog( configMgr, LogService.LOG_DEBUG, "Debug Test Message", null );
assertNoLog( configMgr, LogService.LOG_INFO, "Info Test Message", null );
assertLog( configMgr, LogService.LOG_WARNING, "Warning Test Message", null );
assertLog( configMgr, LogService.LOG_ERROR, "Error Test Message", null );
- setLogLevel( configMgr, LogService.LOG_ERROR );
+ setLogLevel( LogService.LOG_ERROR );
assertNoLog( configMgr, LogService.LOG_DEBUG, "Debug Test Message", null );
assertNoLog( configMgr, LogService.LOG_INFO, "Info Test Message", null );
assertNoLog( configMgr, LogService.LOG_WARNING, "Warning Test Message", null );
assertLog( configMgr, LogService.LOG_ERROR, "Error Test Message", null );
// lower than error -- no output
- setLogLevel( configMgr, LogService.LOG_ERROR - 1 );
+ setLogLevel( LogService.LOG_ERROR - 1 );
assertNoLog( configMgr, LogService.LOG_DEBUG, "Debug Test Message", null );
assertNoLog( configMgr, LogService.LOG_INFO, "Info Test Message", null );
assertNoLog( configMgr, LogService.LOG_WARNING, "Warning Test Message", null );
assertNoLog( configMgr, LogService.LOG_ERROR, "Error Test Message", null );
// minimal log level -- no output
- setLogLevel( configMgr, Integer.MIN_VALUE );
+ setLogLevel( Integer.MIN_VALUE );
assertNoLog( configMgr, LogService.LOG_DEBUG, "Debug Test Message", null );
assertNoLog( configMgr, LogService.LOG_INFO, "Info Test Message", null );
assertNoLog( configMgr, LogService.LOG_WARNING, "Warning Test Message", null );
assertNoLog( configMgr, LogService.LOG_ERROR, "Error Test Message", null );
- setLogLevel( configMgr, LogService.LOG_INFO );
+ setLogLevel( LogService.LOG_INFO );
assertNoLog( configMgr, LogService.LOG_DEBUG, "Debug Test Message", null );
assertLog( configMgr, LogService.LOG_INFO, "Info Test Message", null );
assertLog( configMgr, LogService.LOG_WARNING, "Warning Test Message", null );
assertLog( configMgr, LogService.LOG_ERROR, "Error Test Message", null );
- setLogLevel( configMgr, LogService.LOG_DEBUG );
+ setLogLevel( LogService.LOG_DEBUG );
assertLog( configMgr, LogService.LOG_DEBUG, "Debug Test Message", null );
assertLog( configMgr, LogService.LOG_INFO, "Info Test Message", null );
assertLog( configMgr, LogService.LOG_WARNING, "Warning Test Message", null );
assertLog( configMgr, LogService.LOG_ERROR, "Error Test Message", null );
// maximal log level -- all output
- setLogLevel( configMgr, Integer.MAX_VALUE );
+ setLogLevel( Integer.MAX_VALUE );
assertLog( configMgr, LogService.LOG_DEBUG, "Debug Test Message", null );
assertLog( configMgr, LogService.LOG_INFO, "Info Test Message", null );
assertLog( configMgr, LogService.LOG_WARNING, "Warning Test Message", null );
@@ -202,45 +205,45 @@ public class ConfigurationManagerTest ex
public void testLogWithLogService()
{
LogService logService = new MockLogService();
- ConfigurationManager configMgr = createConfigurationManager( logService );
+ ConfigurationManager configMgr = createConfigurationManagerAndLog( logService );
- setLogLevel( configMgr, LogService.LOG_WARNING );
+ setLogLevel( LogService.LOG_WARNING );
assertLog( configMgr, LogService.LOG_DEBUG, "Debug Test Message", null );
assertLog( configMgr, LogService.LOG_INFO, "Info Test Message", null );
assertLog( configMgr, LogService.LOG_WARNING, "Warning Test Message", null );
assertLog( configMgr, LogService.LOG_ERROR, "Error Test Message", null );
- setLogLevel( configMgr, LogService.LOG_ERROR );
+ setLogLevel( LogService.LOG_ERROR );
assertLog( configMgr, LogService.LOG_DEBUG, "Debug Test Message", null );
assertLog( configMgr, LogService.LOG_INFO, "Info Test Message", null );
assertLog( configMgr, LogService.LOG_WARNING, "Warning Test Message", null );
assertLog( configMgr, LogService.LOG_ERROR, "Error Test Message", null );
- setLogLevel( configMgr, LogService.LOG_ERROR - 1 );
+ setLogLevel( LogService.LOG_ERROR - 1 );
assertLog( configMgr, LogService.LOG_DEBUG, "Debug Test Message", null );
assertLog( configMgr, LogService.LOG_INFO, "Info Test Message", null );
assertLog( configMgr, LogService.LOG_WARNING, "Warning Test Message", null );
assertLog( configMgr, LogService.LOG_ERROR, "Error Test Message", null );
- setLogLevel( configMgr, Integer.MIN_VALUE );
+ setLogLevel( Integer.MIN_VALUE );
assertLog( configMgr, LogService.LOG_DEBUG, "Debug Test Message", null );
assertLog( configMgr, LogService.LOG_INFO, "Info Test Message", null );
assertLog( configMgr, LogService.LOG_WARNING, "Warning Test Message", null );
assertLog( configMgr, LogService.LOG_ERROR, "Error Test Message", null );
- setLogLevel( configMgr, LogService.LOG_INFO );
+ setLogLevel( LogService.LOG_INFO );
assertLog( configMgr, LogService.LOG_DEBUG, "Debug Test Message", null );
assertLog( configMgr, LogService.LOG_INFO, "Info Test Message", null );
assertLog( configMgr, LogService.LOG_WARNING, "Warning Test Message", null );
assertLog( configMgr, LogService.LOG_ERROR, "Error Test Message", null );
- setLogLevel( configMgr, LogService.LOG_DEBUG );
+ setLogLevel( LogService.LOG_DEBUG );
assertLog( configMgr, LogService.LOG_DEBUG, "Debug Test Message", null );
assertLog( configMgr, LogService.LOG_INFO, "Info Test Message", null );
assertLog( configMgr, LogService.LOG_WARNING, "Warning Test Message", null );
assertLog( configMgr, LogService.LOG_ERROR, "Error Test Message", null );
- setLogLevel( configMgr, Integer.MAX_VALUE );
+ setLogLevel( Integer.MAX_VALUE );
assertLog( configMgr, LogService.LOG_DEBUG, "Debug Test Message", null );
assertLog( configMgr, LogService.LOG_INFO, "Info Test Message", null );
assertLog( configMgr, LogService.LOG_WARNING, "Warning Test Message", null );
@@ -251,32 +254,32 @@ public class ConfigurationManagerTest ex
public void testLogSetup()
{
final MockBundleContext bundleContext = new MockBundleContext();
- ConfigurationManager configMgr = createConfigurationManager( null );
+ ConfigurationManager configMgr = createConfigurationManagerAndLog( null );
// ensure the configuration data goes to target
bundleContext.setProperty( "felix.cm.dir", "target/config" );
// default value is 2
bundleContext.setProperty( "felix.cm.loglevel", null );
- configMgr.start( bundleContext );
- assertEquals( 2, getLogLevel( configMgr ) );
- configMgr.stop( bundleContext );
+ Log.logger.start( bundleContext );
+ assertEquals( 2, getLogLevel( ) );
+ Log.logger.stop( );
// illegal number yields default value
bundleContext.setProperty( "felix.cm.loglevel", "not-a-number" );
- configMgr.start( bundleContext );
- assertEquals( 2, getLogLevel( configMgr ) );
- configMgr.stop( bundleContext );
+ Log.logger.start( bundleContext );
+ assertEquals( 2, getLogLevel( ) );
+ Log.logger.stop( );
bundleContext.setProperty( "felix.cm.loglevel", "-100" );
- configMgr.start( bundleContext );
- assertEquals( -100, getLogLevel( configMgr ) );
- configMgr.stop( bundleContext );
+ Log.logger.start( bundleContext );
+ assertEquals( -100, getLogLevel( ) );
+ Log.logger.stop( );
bundleContext.setProperty( "felix.cm.loglevel", "4" );
- configMgr.start( bundleContext );
- assertEquals( 4, getLogLevel( configMgr ) );
- configMgr.stop( bundleContext );
+ Log.logger.start( bundleContext );
+ assertEquals( 4, getLogLevel( ) );
+ Log.logger.stop( );
}
@@ -315,7 +318,6 @@ public class ConfigurationManagerTest ex
ConfigurationManager configMgr = new ConfigurationManager();
- setServiceTrackerField( configMgr, "logTracker" );
setServiceTrackerField( configMgr, "configurationListenerTracker" );
ServiceReference[] refs =
setServiceTrackerField( configMgr, "syncConfigurationListenerTracker",
@@ -345,7 +347,7 @@ public class ConfigurationManagerTest ex
srField.set( configMgr, mockReg );
Field utField = configMgr.getClass().getDeclaredField( "updateThread" );
utField.setAccessible( true );
- utField.set( configMgr, new UpdateThread( configMgr, null, "Test updater" ));
+ utField.set( configMgr, new UpdateThread( null, "Test updater" ));
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put( Constants.SERVICE_PID, "org.acme.testpid" );
@@ -360,7 +362,7 @@ public class ConfigurationManagerTest ex
{
try
{
- configMgr.log( level, message, t );
+ Log.logger.log( level, message, t );
assertTrue( "Expecting no log output", output.size() == 0 );
}
finally
@@ -375,7 +377,7 @@ public class ConfigurationManagerTest ex
{
try
{
- configMgr.log( level, message, t );
+ Log.logger.log( level, message, t );
assertTrue( "Expecting log output", output.size() > 0 );
final String expectedLog = MockLogService.toMessageLine( level, message );
@@ -391,14 +393,14 @@ public class ConfigurationManagerTest ex
}
- private static void setLogLevel( ConfigurationManager configMgr, int level )
+ private static void setLogLevel( int level )
{
final String fieldName = "logLevel";
try
{
- Field field = configMgr.getClass().getDeclaredField( fieldName );
+ Field field = Log.class.getDeclaredField( fieldName );
field.setAccessible( true );
- field.setInt( configMgr, level );
+ field.setInt( Log.logger, level );
}
catch ( Throwable ignore )
{
@@ -408,14 +410,14 @@ public class ConfigurationManagerTest ex
}
- private static int getLogLevel( ConfigurationManager configMgr )
+ private static int getLogLevel( )
{
final String fieldName = "logLevel";
try
{
- Field field = configMgr.getClass().getDeclaredField( fieldName );
+ Field field = Log.class.getDeclaredField( fieldName );
field.setAccessible( true );
- return field.getInt( configMgr );
+ return field.getInt( Log.logger );
}
catch ( Throwable ignore )
{
@@ -425,15 +427,15 @@ public class ConfigurationManagerTest ex
}
- private static ConfigurationManager createConfigurationManager( final LogService logService )
+ private static ConfigurationManager createConfigurationManagerAndLog( final LogService logService )
{
ConfigurationManager configMgr = new ConfigurationManager();
try
{
- Field field = configMgr.getClass().getDeclaredField( "logTracker" );
+ Field field = Log.class.getDeclaredField( "logTracker" );
field.setAccessible( true );
- field.set( configMgr, new ServiceTracker( new MockBundleContext(), "", null )
+ field.set( Log.logger, new ServiceTracker( new MockBundleContext(), "", null )
{
@Override
public Object getService()
Modified: felix/trunk/configadmin/src/test/java/org/apache/felix/cm/impl/helper/TargetedPidTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/configadmin/src/test/java/org/apache/felix/cm/impl/helper/TargetedPidTest.java?rev=1776251&r1=1776250&r2=1776251&view=diff
==============================================================================
--- felix/trunk/configadmin/src/test/java/org/apache/felix/cm/impl/helper/TargetedPidTest.java (original)
+++ felix/trunk/configadmin/src/test/java/org/apache/felix/cm/impl/helper/TargetedPidTest.java Wed Dec 28 09:41:36 2016
@@ -19,11 +19,6 @@
package org.apache.felix.cm.impl.helper;
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-import junit.framework.TestCase;
-
import org.apache.felix.cm.MockBundle;
import org.apache.felix.cm.MockBundleContext;
import org.apache.felix.cm.MockServiceReference;
@@ -34,6 +29,8 @@ import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.Version;
+import junit.framework.TestCase;
+
public class TargetedPidTest
{
@@ -166,6 +163,7 @@ public class TargetedPidTest
BundleContext ctx = new MockBundleContext();
return new MockBundle( ctx, location )
{
+ @Override
public String getSymbolicName()
{
return symbolicName;
@@ -173,14 +171,8 @@ public class TargetedPidTest
@Override
- public Dictionary getHeaders()
- {
- return new Hashtable<String, Object>()
- {
- {
- put( Constants.BUNDLE_VERSION, version.toString() );
- }
- };
+ public Version getVersion() {
+ return version;
}
};
}