Browse Source

Added more ConfigAdmin unit tests.

Sascha Zelzer 14 years ago
parent
commit
b92dc77262

+ 13 - 0
Libs/PluginFramework/Testing/ConfigAdminTest/CMakeLists.txt

@@ -4,14 +4,27 @@ SET(PLUGIN_export_directive "org_commontk_configadmintest_EXPORT")
 
 SET(PLUGIN_SRCS
   ctkConfigAdminTestActivator.cpp
+  ctkConfigurationAdminTestSuite.cpp
   ctkConfigurationListenerTestSuite.cpp
   ctkConfigurationPluginTestSuite.cpp
+  ctkManagedServiceFactoryTestSuite.cpp
+  ctkManagedServiceTestSuite.cpp
+
+  ctkConfigAdminTestActivator_p.h
+  ctkConfigurationAdminTestSuite_p.h
+  ctkConfigurationListenerTestSuite_p.h
+  ctkConfigurationPluginTestSuite_p.h
+  ctkManagedServiceFactoryTestSuite_p.h
+  ctkManagedServiceTestSuite_p.h
 )
 
 SET(PLUGIN_MOC_SRCS
   ctkConfigAdminTestActivator_p.h
+  ctkConfigurationAdminTestSuite_p.h
   ctkConfigurationListenerTestSuite_p.h
   ctkConfigurationPluginTestSuite_p.h
+  ctkManagedServiceFactoryTestSuite_p.h
+  ctkManagedServiceTestSuite_p.h
 )
 
 SET(PLUGIN_UI_FORMS

+ 18 - 0
Libs/PluginFramework/Testing/ConfigAdminTest/ctkConfigAdminTestActivator.cpp

@@ -27,6 +27,9 @@
 #include <QtPlugin>
 #include <QStringList>
 
+#include "ctkConfigurationAdminTestSuite_p.h"
+#include "ctkManagedServiceTestSuite_p.h"
+#include "ctkManagedServiceFactoryTestSuite_p.h"
 #include "ctkConfigurationPluginTestSuite_p.h"
 #include "ctkConfigurationListenerTestSuite_p.h"
 
@@ -58,6 +61,21 @@ void ctkConfigAdminTestActivator::start(ctkPluginContext* context)
 
   ServiceProperties props;
 
+  configAdminTestSuite = new ctkConfigurationAdminTestSuite(context, cmPluginId);
+  props.clear();
+  props.insert(ctkPluginConstants::SERVICE_PID, configAdminTestSuite->metaObject()->className());
+  context->registerService<ctkTestSuiteInterface>(configAdminTestSuite, props);
+
+  managedServiceTestSuite = new ctkManagedServiceTestSuite(context, cmPluginId);
+  props.clear();
+  props.insert(ctkPluginConstants::SERVICE_PID, managedServiceTestSuite->metaObject()->className());
+  context->registerService<ctkTestSuiteInterface>(managedServiceTestSuite, props);
+
+  managedServiceFactoryTestSuite = new ctkManagedServiceFactoryTestSuite(context, cmPluginId);
+  props.clear();
+  props.insert(ctkPluginConstants::SERVICE_PID, managedServiceFactoryTestSuite->metaObject()->className());
+  //context->registerService<ctkTestSuiteInterface>(managedServiceFactoryTestSuite, props);
+
   configPluginTestSuite = new ctkConfigurationPluginTestSuite(context, cmPluginId);
   props.clear();
   props.insert(ctkPluginConstants::SERVICE_PID, configPluginTestSuite->metaObject()->className());

+ 3 - 0
Libs/PluginFramework/Testing/ConfigAdminTest/ctkConfigAdminTestActivator_p.h

@@ -39,6 +39,9 @@ public:
 
 private:
 
+  QObject* configAdminTestSuite;
+  QObject* managedServiceTestSuite;
+  QObject* managedServiceFactoryTestSuite;
   QObject* configPluginTestSuite;
   QObject* configListenerTestSuite;
 };

+ 293 - 0
Libs/PluginFramework/Testing/ConfigAdminTest/ctkConfigurationAdminTestSuite.cpp

@@ -0,0 +1,293 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+
+#include "ctkConfigurationAdminTestSuite_p.h"
+
+#include <ctkPluginContext.h>
+#include <ctkPluginConstants.h>
+#include <service/cm/ctkConfigurationAdmin.h>
+#include <service/cm/ctkConfiguration.h>
+
+#include <QTest>
+#include <QDebug>
+
+ctkConfigurationAdminTestSuite::ctkConfigurationAdminTestSuite(
+  ctkPluginContext* pc, long cmPluginId)
+  : context(pc), cmPluginId(cmPluginId), cm(0)
+{
+
+}
+
+void ctkConfigurationAdminTestSuite::init()
+{
+  context->getPlugin(cmPluginId)->start();
+  reference = context->getServiceReference<ctkConfigurationAdmin>();
+  cm = context->getService<ctkConfigurationAdmin>(reference);
+}
+
+void ctkConfigurationAdminTestSuite::cleanup()
+{
+  context->ungetService(reference);
+  context->getPlugin(cmPluginId)->stop();
+}
+
+void ctkConfigurationAdminTestSuite::testCreateConfig()
+{
+  ctkConfigurationPtr config = cm->getConfiguration("test");
+  QCOMPARE(QString("test"), config->getPid());
+}
+
+void ctkConfigurationAdminTestSuite::testCreateConfigNullPid()
+{
+  try
+  {
+    cm->getConfiguration(QString());
+  }
+  catch (const std::invalid_argument& e)
+  {
+    return;
+  }
+  QFAIL("no exception thrown");
+}
+
+void ctkConfigurationAdminTestSuite::testCreateConfigWithLocation()
+{
+  ctkConfigurationPtr config = cm->getConfiguration("test", QString());
+  QCOMPARE(QString("test"), config->getPid());
+}
+
+void ctkConfigurationAdminTestSuite::testCreateConfigNullPidWithLocation()
+{
+  try
+  {
+    cm->getConfiguration(QString(), QString());
+  }
+  catch (const std::invalid_argument& e)
+  {
+    return;
+  }
+  QFAIL("no exception thrown");
+}
+
+void ctkConfigurationAdminTestSuite::testCreateConfigWithAndWithoutLocation()
+{
+  ctkConfigurationPtr config = cm->getConfiguration("test", "x");
+  config->update();
+  ctkConfigurationPtr config2 = cm->getConfiguration("test");
+  QCOMPARE(config, config2);
+  config->remove();
+}
+
+void ctkConfigurationAdminTestSuite::testCreateConfigWithAndWithoutNullLocation()
+{
+  ctkConfigurationPtr config = cm->getConfiguration("test", QString());
+  config->update();
+  QVERIFY(config->getPluginLocation().isEmpty());
+  ctkConfigurationPtr config2 = cm->getConfiguration("test");
+  QCOMPARE(config, config2);
+  QCOMPARE(config2->getPluginLocation(), context->getPlugin()->getLocation());
+  config->remove();
+}
+
+void ctkConfigurationAdminTestSuite::testCreateFactoryConfig()
+{
+  ctkConfigurationPtr config = cm->createFactoryConfiguration("test");
+  QCOMPARE(QString("test"), config->getFactoryPid());
+}
+
+void ctkConfigurationAdminTestSuite::testCreateFactoryConfigNullPid()
+{
+  try
+  {
+    cm->createFactoryConfiguration(QString());
+  }
+  catch (const std::invalid_argument& e)
+  {
+    return;
+  }
+  QFAIL("no exception thrown");
+}
+
+void ctkConfigurationAdminTestSuite::testCreateFactoryConfigWithLocation()
+{
+  ctkConfigurationPtr config = cm->createFactoryConfiguration("test", QString());
+  QCOMPARE(QString("test"), config->getFactoryPid());
+}
+
+void ctkConfigurationAdminTestSuite::testCreateFactoryConfigNullPidWithLocation()
+{
+  try
+  {
+    cm->createFactoryConfiguration(QString(), QString());
+  }
+  catch (const std::invalid_argument& e)
+  {
+    return;
+  }
+  QFAIL("no exception thrown");
+}
+
+void ctkConfigurationAdminTestSuite::testCreateFactoryConfigWithAndWithoutLocation()
+{
+  ctkConfigurationPtr config = cm->createFactoryConfiguration("test", "x");
+  config->update();
+  ctkConfigurationPtr config2 = cm->getConfiguration(config->getPid());
+  QCOMPARE(config, config2);
+  config->remove();
+}
+
+void ctkConfigurationAdminTestSuite::testCreateFactoryConfigWithAndWithoutNullLocation()
+{
+  ctkConfigurationPtr config = cm->createFactoryConfiguration("test", QString());
+  config->update();
+  QVERIFY(config->getPluginLocation().isEmpty());
+  ctkConfigurationPtr config2 = cm->getConfiguration(config->getPid());
+  QCOMPARE(config, config2);
+  QCOMPARE(config2->getPluginLocation(), context->getPlugin()->getLocation());
+  config->remove();
+}
+
+void ctkConfigurationAdminTestSuite::testListConfiguration()
+{
+  ctkConfigurationPtr config = cm->getConfiguration("test", QString());
+  qDebug() << "$$$$ config props:" << config->getProperties();
+  config->update();
+  QList<ctkConfigurationPtr> configs = cm->listConfigurations(QString("(") + ctkPluginConstants::SERVICE_PID + "=test)");
+  QVERIFY(configs.isEmpty());
+  ctkDictionary props;
+  props.insert("testkey", "testvalue");
+  config->update(props);
+  configs = cm->listConfigurations(QString("(") + ctkPluginConstants::SERVICE_PID + "=test)");
+  QVERIFY(configs.size() > 0);
+  config->remove();
+}
+
+void ctkConfigurationAdminTestSuite::testListConfigurationWithBoundLocation()
+{
+  ctkConfigurationPtr config = cm->getConfiguration("test", QString());
+  config->update();
+  QString filterString = QString("(&(") + ctkConfigurationAdmin::SERVICE_PLUGINLOCATION
+      + "=" + context->getPlugin()->getLocation() + ")(" + ctkPluginConstants::SERVICE_PID + "=test)" + ")";
+  QList<ctkConfigurationPtr> configs = cm->listConfigurations(filterString);
+  QVERIFY(configs.isEmpty());
+  // bind ctkConfigurationPtr to this plugin's location
+  cm->getConfiguration("test");
+  configs = cm->listConfigurations(filterString);
+  QVERIFY(configs.isEmpty());
+  ctkDictionary props;
+  props.insert("testkey", "testvalue");
+  config->update(props);
+  configs = cm->listConfigurations(filterString);
+  QVERIFY(configs.size() > 0);
+  config->remove();
+}
+
+void ctkConfigurationAdminTestSuite::testListFactoryConfiguration()
+{
+  ctkConfigurationPtr config = cm->createFactoryConfiguration("test", QString());
+  config->update();
+  QString filterString = QString("(") + ctkConfigurationAdmin::SERVICE_FACTORYPID + "=test)";
+  QList<ctkConfigurationPtr> configs = cm->listConfigurations(filterString);
+  QVERIFY(configs.isEmpty());
+  ctkDictionary props;
+  props.insert("testkey", "testvalue");
+  config->update(props);
+  configs = cm->listConfigurations(filterString);
+  QVERIFY(configs.size() > 0);
+  config->remove();
+}
+
+void ctkConfigurationAdminTestSuite::testListFactoryConfigurationWithBoundLocation()
+{
+  ctkConfigurationPtr config = cm->createFactoryConfiguration("test", QString());
+  config->update();
+  QString filterString = QString("(&(") + ctkConfigurationAdmin::SERVICE_PLUGINLOCATION
+      + "=" + context->getPlugin()->getLocation() + ")(" + ctkPluginConstants::SERVICE_PID + "="
+      + config->getPid() + "))";
+  QList<ctkConfigurationPtr> configs = cm->listConfigurations(filterString);
+  QVERIFY(configs.isEmpty());
+  // bind ctkConfigurationPtr to this plugin's location
+  cm->getConfiguration(config->getPid());
+  configs = cm->listConfigurations(filterString);
+  QVERIFY(configs.isEmpty());
+  ctkDictionary props;
+  props.insert("testkey", "testvalue");
+  config->update(props);
+  configs = cm->listConfigurations(filterString);
+  QVERIFY(configs.size() > 0);
+  config->remove();
+}
+
+void ctkConfigurationAdminTestSuite::testListConfigurationNull()
+{
+  ctkConfigurationPtr config = cm->createFactoryConfiguration("test", QString());
+  config->update();
+  QList<ctkConfigurationPtr> configs = cm->listConfigurations(QString());
+  QVERIFY(configs.isEmpty());
+  ctkDictionary props;
+  props.insert("testkey", "testvalue");
+  config->update(props);
+  configs = cm->listConfigurations(QString());
+  QVERIFY(configs.size() > 0);
+  config->remove();
+}
+
+void ctkConfigurationAdminTestSuite::testPersistentConfig()
+{
+  ctkConfigurationPtr config = cm->getConfiguration("test");
+  QVERIFY(config->getProperties().isEmpty());
+  ctkDictionary props;
+  props.insert("testkey", "testvalue");
+  config->update(props);
+  QVERIFY(config->getPid() == "test");
+  QVERIFY(config->getProperties().value("testkey").toString() == "testvalue");
+  cleanup();
+  init();
+  config = cm->getConfiguration("test");
+  QVERIFY(config->getProperties().value("testkey").toString() == "testvalue");
+  config->remove();
+  cleanup();
+  init();
+  config = cm->getConfiguration("test");
+  QVERIFY(config->getProperties().isEmpty());
+}
+
+void ctkConfigurationAdminTestSuite::testPersistentFactoryConfig()
+{
+  ctkConfigurationPtr config = cm->createFactoryConfiguration("test");
+  QVERIFY(config->getProperties().isEmpty());
+  ctkDictionary props;
+  props.insert("testkey", "testvalue");
+  config->update(props);
+  QCOMPARE(config->getFactoryPid(), QString("test"));
+  QCOMPARE(config->getProperties().value("testkey").toString(), QString("testvalue"));
+  QString pid = config->getPid();
+  cleanup();
+  init();
+  config = cm->getConfiguration(pid);
+  QCOMPARE(config->getProperties().value("testkey").toString(), QString("testvalue"));
+  config->remove();
+  cleanup();
+  init();
+  config = cm->getConfiguration(pid);
+  QVERIFY(config->getProperties().isEmpty());
+}

+ 77 - 0
Libs/PluginFramework/Testing/ConfigAdminTest/ctkConfigurationAdminTestSuite_p.h

@@ -0,0 +1,77 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+
+#ifndef CTKCONFIGURATIONADMINTESTSUITE_P_H
+#define CTKCONFIGURATIONADMINTESTSUITE_P_H
+
+#include <QObject>
+
+#include <ctkServiceReference.h>
+#include <ctkTestSuiteInterface.h>
+
+class ctkPluginContext;
+class ctkConfigurationAdmin;
+
+class ctkConfigurationAdminTestSuite : public QObject,
+    public ctkTestSuiteInterface
+{
+  Q_OBJECT
+  Q_INTERFACES(ctkTestSuiteInterface)
+
+public:
+
+  ctkConfigurationAdminTestSuite(ctkPluginContext* pc, long cmPluginId);
+
+private slots:
+
+  void init();
+  void cleanup();
+
+  void testCreateConfig();
+  void testCreateConfigNullPid();
+  void testCreateConfigWithLocation();
+  void testCreateConfigNullPidWithLocation();
+  void testCreateConfigWithAndWithoutLocation();
+  void testCreateConfigWithAndWithoutNullLocation();
+  void testCreateFactoryConfig();
+  void testCreateFactoryConfigNullPid();
+  void testCreateFactoryConfigWithLocation();
+  void testCreateFactoryConfigNullPidWithLocation();
+  void testCreateFactoryConfigWithAndWithoutLocation();
+  void testCreateFactoryConfigWithAndWithoutNullLocation();
+  void testListConfiguration();
+  void testListConfigurationWithBoundLocation();
+  void testListFactoryConfiguration();
+  void testListFactoryConfigurationWithBoundLocation();
+  void testListConfigurationNull();
+  void testPersistentConfig();
+  void testPersistentFactoryConfig();
+
+private:
+
+  ctkPluginContext* context;
+  long cmPluginId;
+  ctkConfigurationAdmin* cm;
+  ctkServiceReference reference;
+};
+
+#endif // CTKCONFIGURATIONADMINTESTSUITE_P_H

+ 1 - 1
Libs/PluginFramework/Testing/ConfigAdminTest/ctkConfigurationPluginTestSuite.cpp

@@ -72,7 +72,7 @@ ctkConfigurationPluginTestSuite::~ctkConfigurationPluginTestSuite()
 void ctkConfigurationPluginTestSuite::init()
 {
   context->getPlugin(cmPluginId)->start();
-      reference = context->getServiceReference<ctkConfigurationAdmin>();
+  reference = context->getServiceReference<ctkConfigurationAdmin>();
   cm = context->getService<ctkConfigurationAdmin>(reference);
 }
 

+ 1 - 1
Libs/PluginFramework/Testing/ConfigAdminTest/ctkConfigurationPluginTestSuite_p.h

@@ -65,7 +65,7 @@ public:
 private:
 
   ctkConfigurationPluginTestSuite* const ts;
- };
+};
 
 class ctkConfigurationPluginTestSuite : public QObject,
     public ctkTestSuiteInterface

+ 193 - 0
Libs/PluginFramework/Testing/ConfigAdminTest/ctkManagedServiceFactoryTestSuite.cpp

@@ -0,0 +1,193 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+
+#include "ctkManagedServiceFactoryTestSuite_p.h"
+
+#include <ctkPluginContext.h>
+#include <ctkPluginConstants.h>
+
+#include <service/cm/ctkConfiguration.h>
+#include <service/cm/ctkConfigurationAdmin.h>
+
+#include <QTest>
+
+_ManagedServiceFactoryUpdateTest::_ManagedServiceFactoryUpdateTest(ctkManagedServiceFactoryTestSuite* ts)
+  : ts(ts)
+{
+
+}
+
+void _ManagedServiceFactoryUpdateTest::deleted(const QString& pid)
+{
+  Q_UNUSED(pid)
+
+  QMutexLocker l(&ts->mutex);
+  ts->locked = false;
+  ts->lock.wakeOne();
+  ts->updateCount++;
+}
+
+QString _ManagedServiceFactoryUpdateTest::getName()
+{
+  return QString();
+}
+
+void _ManagedServiceFactoryUpdateTest::updated(const QString& pid, const ctkDictionary& properties)
+{
+  Q_UNUSED(pid)
+  Q_UNUSED(properties)
+
+  QMutexLocker l(&ts->mutex);
+  ts->locked = false;
+  ts->lock.wakeOne();
+  ts->updateCount++;
+}
+
+ctkManagedServiceFactoryTestSuite::ctkManagedServiceFactoryTestSuite(ctkPluginContext* pc, long cmPluginId)
+  : context(pc), cmPluginId(cmPluginId), cm(0), updateCount(0),
+    locked(false)
+{
+
+}
+
+void ctkManagedServiceFactoryTestSuite::init()
+{
+  context->getPlugin(cmPluginId)->start();
+  reference = context->getServiceReference<ctkConfigurationAdmin>();
+  cm = context->getService<ctkConfigurationAdmin>(reference);
+}
+
+void ctkManagedServiceFactoryTestSuite::cleanup()
+{
+  context->ungetService(reference);
+  context->getPlugin(cmPluginId)->stop();
+}
+
+void ctkManagedServiceFactoryTestSuite::testSamePidManagedServiceFactory()
+{
+  ctkConfigurationPtr config = cm->createFactoryConfiguration("test");
+  ctkDictionary props;
+  props.insert("testkey", "testvalue");
+  config->update(props);
+
+  updateCount = 0;
+  _ManagedServiceFactoryUpdateTest msf(this);
+
+  ctkDictionary dict;
+  dict.insert(ctkPluginConstants::SERVICE_PID, "test");
+  ctkServiceRegistration reg;
+  {
+    QMutexLocker l(&mutex);
+    reg = context->registerService<ctkManagedServiceFactory>(&msf, dict);
+    locked = true;
+    lock.wait(&mutex, 5000);
+    if (locked)
+      QFAIL("should have updated");
+    QCOMPARE(1, updateCount);
+  }
+
+  ctkServiceRegistration reg2;
+  {
+    QMutexLocker l(&mutex);
+    reg2 = context->registerService<ctkManagedServiceFactory>(&msf, dict);
+    locked = true;
+    lock.wait(&mutex, 100);
+    QVERIFY(locked);
+    QCOMPARE(1, updateCount);
+    locked = false;
+  }
+  reg.unregister();
+  reg2.unregister();
+  config->remove();
+}
+
+//void ctkManagedServiceFactoryTestSuite::testGeneralManagedServiceFactory()
+//{
+//  updateCount = 0;
+//  _ManagedServiceFactoryUpdateTest msf(this);
+
+//  ctkDictionary dict;
+//  dict.insert(ctkPluginConstants::SERVICE_PID, "test");
+
+//  ctkServiceRegistration reg;
+//  {
+//    QMutexLocker l(&mutex);
+//    reg = context->registerService<ctkManagedServiceFactory>(&msf, dict);
+//    locked = true;
+//    lock.wait(&mutex, 100);
+//    QVERIFY(locked);
+//    QCOMPARE(0, updateCount);
+//    locked = false;
+//  }
+
+//  ctkConfigurationPtr config = cm->createFactoryConfiguration("test");
+//  QVERIFY(config->getProperties().isEmpty());
+//  ctkDictionary props;
+//  props.insert("testkey", "testvalue");
+
+//  {
+//    QMutexLocker l(&mutex);
+//    config->update(props);
+//    locked = true;
+//    lock.wait(&mutex, 5000);
+//    if (locked)
+//      QFAIL("should have updated");
+//    QCOMPARE(1, updateCount);
+//  }
+
+//  dict.remove(ctkPluginConstants::SERVICE_PID);
+//  {
+//    QMutexLocker l(&mutex);
+//    reg.setProperties(dict);
+//    props.insert("testkey", "testvalue2");
+//    config->update(props);
+//    locked = true;
+//    lock.wait(&mutex, 100);
+//    QVERIFY(locked);
+//    QCOMPARE(1, updateCount);
+//    locked = false;
+//  }
+
+//  config->remove();
+//  config = cm->createFactoryConfiguration("test2");
+//  dict.insert(ctkPluginConstants::SERVICE_PID, "test2");
+//  {
+//    QMutexLocker l(&mutex);
+//    reg.setProperties(dict);
+//    locked = true;
+//    lock.wait(&mutex, 5000);
+//    if (locked)
+//      QFAIL("should have updated");
+//    QCOMPARE(2, updateCount);
+//  }
+
+//  {
+//    QMutexLocker l(&mutex);
+//    config->remove();
+//    locked = true;
+//    lock.wait(&mutex, 5000);
+//    if (locked)
+//      QFAIL("should have updated");
+//    QCOMPARE(3, updateCount);
+//  }
+//  reg.unregister();
+//}

+ 88 - 0
Libs/PluginFramework/Testing/ConfigAdminTest/ctkManagedServiceFactoryTestSuite_p.h

@@ -0,0 +1,88 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+
+#ifndef CTKMANAGEDSERVICEFACTORYTESTSUITE_P_H
+#define CTKMANAGEDSERVICEFACTORYTESTSUITE_P_H
+
+#include <QObject>
+#include <QWaitCondition>
+#include <QMutex>
+
+#include <service/cm/ctkManagedServiceFactory.h>
+#include <ctkServiceReference.h>
+#include <ctkTestSuiteInterface.h>
+
+class ctkConfigurationAdmin;
+class ctkManagedServiceFactoryTestSuite;
+
+class _ManagedServiceFactoryUpdateTest : public QObject,
+    public ctkManagedServiceFactory
+{
+  Q_OBJECT
+  Q_INTERFACES(ctkManagedServiceFactory)
+
+public:
+
+  _ManagedServiceFactoryUpdateTest(ctkManagedServiceFactoryTestSuite* ts);
+
+  void deleted(const QString& pid);
+  QString getName();
+  void updated(const QString& pid, const ctkDictionary& properties);
+
+private:
+
+  ctkManagedServiceFactoryTestSuite* const ts;
+};
+
+class ctkManagedServiceFactoryTestSuite : public QObject,
+    public ctkTestSuiteInterface
+{
+  Q_OBJECT
+  Q_INTERFACES(ctkTestSuiteInterface)
+
+public:
+
+  ctkManagedServiceFactoryTestSuite(ctkPluginContext* pc, long cmPluginId);
+
+private slots:
+
+  void init();
+  void cleanup();
+
+  void testSamePidManagedServiceFactory();
+  //void testGeneralManagedServiceFactory();
+
+private:
+
+  ctkPluginContext* context;
+  long cmPluginId;
+  ctkConfigurationAdmin* cm;
+  ctkServiceReference reference;
+  int updateCount;
+  bool locked;
+  QMutex mutex;
+  QWaitCondition lock;
+
+  friend class _ManagedServiceFactoryUpdateTest;
+};
+
+#endif // CTKMANAGEDSERVICEFACTORYTESTSUITE_P_H

+ 191 - 0
Libs/PluginFramework/Testing/ConfigAdminTest/ctkManagedServiceTestSuite.cpp

@@ -0,0 +1,191 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+
+#include "ctkManagedServiceTestSuite_p.h"
+
+#include <service/cm/ctkConfigurationAdmin.h>
+#include <ctkPluginContext.h>
+#include <ctkPluginConstants.h>
+
+#include <QTest>
+
+_ManagedServiceUpdateTest::_ManagedServiceUpdateTest(
+  ctkManagedServiceTestSuite* ts)
+  : ts(ts)
+{
+
+}
+
+void _ManagedServiceUpdateTest::updated(
+  const ctkDictionary& properties)
+{
+  Q_UNUSED(properties)
+
+  QMutexLocker l(&ts->mutex);
+  ts->locked = false;
+  ts->lock.wakeOne();
+  ts->updateCount++;
+}
+
+ctkManagedServiceTestSuite::ctkManagedServiceTestSuite(
+  ctkPluginContext* pc, long cmPluginId)
+  : context(pc), cmPluginId(cmPluginId), cm(0), updateCount(0),
+    locked(false)
+{
+
+}
+
+void ctkManagedServiceTestSuite::init()
+{
+  context->getPlugin(cmPluginId)->start();
+  reference = context->getServiceReference<ctkConfigurationAdmin>();
+  cm = context->getService<ctkConfigurationAdmin>(reference);
+}
+
+void ctkManagedServiceTestSuite::cleanup()
+{
+  context->ungetService(reference);
+  context->getPlugin(cmPluginId)->stop();
+}
+
+void ctkManagedServiceTestSuite::testSamePidManagedService()
+{
+  ctkConfigurationPtr config = cm->getConfiguration("test");
+  ctkDictionary props;
+  props.insert("testkey", "testvalue");
+  config->update(props);
+
+  updateCount = 0;
+  _ManagedServiceUpdateTest ms(this);
+
+  ctkDictionary dict;
+  dict.insert(ctkPluginConstants::SERVICE_PID, "test");
+  ctkServiceRegistration reg;
+  {
+    QMutexLocker l(&mutex);
+    reg = context->registerService<ctkManagedService>(&ms, dict);
+    locked = true;
+    lock.wait(&mutex, 5000);
+    if (locked)
+      QFAIL("should have updated");
+    QCOMPARE(1, updateCount);
+  }
+
+  ctkServiceRegistration reg2;
+  {
+    QMutexLocker l(&mutex);
+    reg2 = context->registerService<ctkManagedService>(&ms, dict);
+    locked = true;
+    lock.wait(&mutex, 100);
+    QVERIFY(locked);
+    QCOMPARE(1, updateCount);
+    locked = false;
+  }
+  reg.unregister();
+  reg2.unregister();
+  config->remove();
+}
+
+void ctkManagedServiceTestSuite::testGeneralManagedService()
+{
+  updateCount = 0;
+  _ManagedServiceUpdateTest ms(this);
+
+  ctkDictionary dict;
+  dict.insert(ctkPluginConstants::SERVICE_PID, "test");
+
+  ctkServiceRegistration reg;
+  {
+    QMutexLocker l(&mutex);
+    reg = context->registerService<ctkManagedService>(&ms, dict);
+    locked = true;
+    lock.wait(&mutex, 5000);
+    if (locked)
+      QFAIL("should have updated");
+    QCOMPARE(1, updateCount);
+  }
+
+  ctkConfigurationPtr config = cm->getConfiguration("test");
+  QVERIFY(config->getProperties().isEmpty());
+  ctkDictionary props;
+  props.insert("testkey", "testvalue");
+
+  {
+    QMutexLocker l(&mutex);
+    config->update(props);
+    locked = true;
+    lock.wait(&mutex, 5000);
+    if (locked)
+      QFAIL("should have updated");
+    QCOMPARE(2, updateCount);
+  }
+
+  QString location = config->getPluginLocation();
+  config->setPluginLocation("bogus");
+  {
+    QMutexLocker l(&mutex);
+    config->update();
+    locked = true;
+    lock.wait(&mutex, 100);
+    QVERIFY(locked);
+    QCOMPARE(2, updateCount);
+    locked = false;
+  }
+  config->setPluginLocation(location);
+
+  dict.remove(ctkPluginConstants::SERVICE_PID);
+  {
+    QMutexLocker l(&mutex);
+    reg.setProperties(dict);
+    props.insert("testkey", "testvalue2");
+    config->update(props);
+    locked = true;
+    lock.wait(&mutex, 100);
+    QVERIFY(locked);
+    QCOMPARE(2, updateCount);
+    locked = false;
+  }
+
+  config->remove();
+  config = cm->getConfiguration("test2");
+  dict.insert(ctkPluginConstants::SERVICE_PID, "test2");
+  {
+    QMutexLocker l(&mutex);
+    reg.setProperties(dict);
+    locked = true;
+    lock.wait(&mutex, 5000);
+    if (locked)
+      QFAIL("should have updated");
+    QCOMPARE(3, updateCount);
+  }
+
+  {
+    QMutexLocker l(&mutex);
+    config->remove();
+    locked = true;
+    lock.wait(&mutex, 5000);
+    if (locked)
+      QFAIL("should have updated");
+    QCOMPARE(4, updateCount);
+  }
+  reg.unregister();
+}

+ 85 - 0
Libs/PluginFramework/Testing/ConfigAdminTest/ctkManagedServiceTestSuite_p.h

@@ -0,0 +1,85 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+
+#ifndef CTKMANAGEDSERVICETESTSUITE_P_H
+#define CTKMANAGEDSERVICETESTSUITE_P_H
+
+#include <QObject>
+#include <QWaitCondition>
+#include <QMutex>
+
+#include <service/cm/ctkManagedService.h>
+#include <ctkServiceReference.h>
+#include <ctkTestSuiteInterface.h>
+
+class ctkManagedServiceTestSuite;
+class ctkConfigurationAdmin;
+
+class _ManagedServiceUpdateTest : public QObject, public ctkManagedService
+{
+  Q_OBJECT
+  Q_INTERFACES(ctkManagedService)
+
+public:
+
+  _ManagedServiceUpdateTest(ctkManagedServiceTestSuite* ts);
+
+  void updated(const ctkDictionary& properties);
+
+private:
+
+  ctkManagedServiceTestSuite* const ts;
+};
+
+class ctkManagedServiceTestSuite : public QObject,
+    public ctkTestSuiteInterface
+{
+  Q_OBJECT
+  Q_INTERFACES(ctkTestSuiteInterface)
+
+public:
+
+  ctkManagedServiceTestSuite(ctkPluginContext* pc, long cmPluginId);
+
+private slots:
+
+  void init();
+  void cleanup();
+
+  void testSamePidManagedService();
+  void testGeneralManagedService();
+
+private:
+
+  ctkPluginContext* context;
+  long cmPluginId;
+  ctkConfigurationAdmin* cm;
+  ctkServiceReference reference;
+  int updateCount;
+  bool locked;
+  QMutex mutex;
+  QWaitCondition lock;
+
+  friend class _ManagedServiceUpdateTest;
+};
+
+#endif // CTKMANAGEDSERVICETESTSUITE_P_H