Package com.volantis.osgi.cm.factory

Examples of com.volantis.osgi.cm.factory.ManagedServiceFactoryHandler


        // =====================================================================
        //   Test Expectations
        // =====================================================================

        ServiceHandler factoryHandler =
                new ManagedServiceFactoryHandler(manager);

        // Register a ManagedServiceFactory before a suitable configuration
        // has been created.
        factoryHandler.serviceRegistered(unauthorizedFactoryReferenceMock);

        // Attempt to register another factory for the same pid from a
        // different bundle. This should fail and log a warning. Then make sure
        // that the other service listener events do not fail.
        factoryHandler.serviceRegistered(attackingFactoryReferenceMock);
        factoryHandler.serviceModified(attackingFactoryReferenceMock);
        factoryHandler.serviceUnregistering(attackingFactoryReferenceMock);

        // Create a couple of factory configurations.
        Configuration fc1_1 =
                authorizedAdmin.createFactoryConfiguration(FACTORY_PID1, null);
        fc1_1.update(new Hashtable());
        checkLocationBinding(PREFIX + "a", UNAUTHORIZED_BUNDLE_LOCATION);

        Configuration fc1_2 =
                authorizedAdmin.createFactoryConfiguration(FACTORY_PID1, null);
        fc1_2.update(new Hashtable());
        checkLocationBinding(PREFIX + "b", UNAUTHORIZED_BUNDLE_LOCATION);

        Configuration fc1_3 =
                authorizedAdmin.createFactoryConfiguration(FACTORY_PID1,
                        UNAUTHORIZED_BUNDLE_LOCATION);
        fc1_3.update(new Hashtable());
        checkLocationBinding(PREFIX + "c", UNAUTHORIZED_BUNDLE_LOCATION);

        // Check to see if the information has been correctly persisted.
        checkPersistedConfigurations(
                new InternalConfiguration[]{
                        new ConfigurationImpl(PREFIX + "a", FACTORY_PID1, null,
                                null, new CaseInsensitiveDictionary()),
                        new ConfigurationImpl(PREFIX + "b", FACTORY_PID1, null,
                                null, new CaseInsensitiveDictionary()),
                        new ConfigurationImpl(PREFIX + "c", FACTORY_PID1, null,
                                UNAUTHORIZED_BUNDLE_LOCATION,
                                new CaseInsensitiveDictionary()),
                });

        // Delete a factory configuration.
        fc1_2.delete();

        // The ManagedServiceFactory service has changed.
        factoryHandler.serviceModified(unauthorizedFactoryReferenceMock);

        // The ManagedServiceFactory service has unregistered.
        factoryHandler.serviceUnregistering(unauthorizedFactoryReferenceMock);

        // Make sure that the configurations that were created without any
        // specific bundle location and have not since been deleted have
        // reverted to null.
        checkLocationBinding(PREFIX + "a", null);

        // Reregister another ManagedServiceFactory with the same PID but from
        // a different bundle.
        factoryHandler.serviceRegistered(attackingFactoryReferenceMock);

        // Check to see if the information has been correctly persisted.
        checkPersistedConfigurations(
                new InternalConfiguration[]{
                        new ConfigurationImpl(PREFIX + "a", FACTORY_PID1, null,
View Full Code Here


                .returns(new ConfigurationImpl("PID5", "FACTORY-PID", null,
                        ATTACKING_BUNDLE_LOCATION, null));

        // Create a handler for managing information about the registration
        // of
        ManagedServiceFactoryHandler handler =
                new ManagedServiceFactoryHandler(manager);

        // =====================================================================
        //   Test Expectations
        // =====================================================================

        // Creating a new configuration may check for configure permission but
        // shouldn't care if it does not have it.
        unauthorizedAdmin.createFactoryConfiguration("FACTORY-PID");

        // Creating a new configuration for a different bundle may check for
        // configure permission but shouldn't care if it does not have it.
        attackingAdmin.createFactoryConfiguration("FACTORY-PID");

        // Bind the factory PID to the unauthorized bundle.
        final ServiceReferenceMock managedServiceFactoryReferenceMock =
                new ServiceReferenceMock("managedServiceFactoryReferenceMock",
                        expectations);

        managedServiceFactoryReferenceMock.expects.getBundle()
                .returns(unauthorizedBundleMock).any();
        managedServiceFactoryReferenceMock.expects
                .getProperty(FrameworkConstants.SERVICE_PID)
                .returns("FACTORY-PID").any();

        // The unauthorized bundle should not see any configurations created
        // by the attacking bundle.
        dispatcherMock.expects.managedServiceFactoryRegistered(
                "FACTORY-PID", managedServiceFactoryReferenceMock,
                new ConfigurationSnapshot[]{
                        new ConfigurationSnapshot("PID1", new Hashtable())
                });

        // A message must be logged to the log service for the configuration
        // that was created by the attacking bundle.
        logServiceMock.expects.log(managedServiceFactoryReferenceMock,
                LogService.LOG_WARNING,
                "Configuration with pid 'PID2' for factory 'FACTORY-PID' is " +
                        "bound to '" + ATTACKING_BUNDLE_LOCATION +
                        "' instead of '" + UNAUTHORIZED_BUNDLE_LOCATION +
                        "' and so will be ignored");

        handler.serviceRegistered(managedServiceFactoryReferenceMock);

        // Creating a configuration for a factory PID that has been bound to
        // a specific bundle (the bundle that registered the
        // ManagedServiceFactory with the matching factory PID) should work
        // for the owning bundle and an authorized admin.
View Full Code Here

            ConfigurationManager manager,
            PluginManager pluginManager) {

        serviceHandlers = new ServiceHandler[]{
                new ManagedServiceHandler(manager),
                new ManagedServiceFactoryHandler(manager),
                new ConfigurationPluginHandler(pluginManager)
        };

        // Create a filter that will only select those services that are of the
        // same type as we care about.
View Full Code Here

TOP

Related Classes of com.volantis.osgi.cm.factory.ManagedServiceFactoryHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.