void testResourceManagement() { qRegisterMetaType<Akonadi::AgentInstance>(); QSignalSpy spyAddInstance( AgentManager::self(), SIGNAL(instanceAdded(Akonadi::AgentInstance)) ); QVERIFY( spyAddInstance.isValid() ); QSignalSpy spyRemoveInstance( AgentManager::self(), SIGNAL(instanceRemoved(Akonadi::AgentInstance)) ); QVERIFY( spyRemoveInstance.isValid() ); AgentType type = AgentManager::self()->type( "akonadi_knut_resource" ); QVERIFY( type.isValid() ); QCOMPARE( type.capabilities(), QStringList( "Resource" ) ); AgentInstanceCreateJob *job = new AgentInstanceCreateJob( type ); AKVERIFYEXEC( job ); AgentInstance instance = job->instance(); QVERIFY( instance.isValid() ); QCOMPARE( spyAddInstance.count(), 1 ); QCOMPARE( spyAddInstance.first().at( 0 ).value<AgentInstance>(), instance ); QVERIFY( AgentManager::self()->instance( instance.identifier() ).isValid() ); job = new AgentInstanceCreateJob( type ); AKVERIFYEXEC( job ); AgentInstance instance2 = job->instance(); QVERIFY( !( instance == instance2 ) ); QCOMPARE( spyAddInstance.count(), 2 ); AgentManager::self()->removeInstance( instance ); AgentManager::self()->removeInstance( instance2 ); QTest::qWait( 2000 ); QCOMPARE( spyRemoveInstance.count(), 2 ); QVERIFY( !AgentManager::self()->instances().contains( instance ) ); QVERIFY( !AgentManager::self()->instances().contains( instance2 ) ); }
/****************************************************************************** * Called when the agent creation job for this resource has completed. * Applies the calendar resource configuration to the Akonadi agent. */ void CalendarCreator::agentCreated(KJob* j) { if (j->error()) { mErrorMessage = j->errorString(); kError() << "AgentInstanceCreateJob error:" << mErrorMessage; finish(false); return; } // Configure the Akonadi Agent kDebug() << mName; AgentInstanceCreateJob* job = static_cast<AgentInstanceCreateJob*>(j); mAgent = job->instance(); mAgent.setName(mName); bool ok = false; switch (mResourceType) { case LocalFile: ok = migrateLocalFile(); break; case LocalDir: ok = migrateLocalDirectory(); break; case RemoteFile: ok = migrateRemoteFile(); break; default: kError() << "Invalid resource type"; break; } if (!ok) { finish(true); return; } mAgent.reconfigure(); // notify the agent that its configuration has been changed // Wait for the resource to create its collection. ResourceSynchronizationJob* sjob = new ResourceSynchronizationJob(mAgent); connect(sjob, SIGNAL(result(KJob*)), SLOT(resourceSynchronised(KJob*))); sjob->start(); // this is required (not an Akonadi::Job) }