Package org.jboss.arquillian.drone.spi

Examples of org.jboss.arquillian.drone.spi.DroneContext


        // then
        DroneRegistry registry = getManager().getContext(SuiteContext.class).getObjectStore().get(DroneRegistry.class);
        Assert.assertNotNull("Drone registry was created in the context", registry);

        DroneContext context = getManager().getContext(ApplicationContext.class).getObjectStore().get(DroneContext
                .class);
        Assert.assertNotNull("DroneContext was created in the context", context);

        GlobalDroneConfiguration globalDroneConfiguration = context.getGlobalDroneConfiguration
                (GlobalDroneConfiguration.class);
        Assert.assertNotNull("Global Drone configuration was created", globalDroneConfiguration);
        Assert.assertEquals("Drone timeout is set to " + timeout + " seconds", timeout,
                globalDroneConfiguration.getInstantiationTimeoutInSeconds());
View Full Code Here


        Assert.assertTrue("Configurator is of MockDronePriorityFactory type",
                registry.getEntryFor(MockDrone.class, Configurator.class) instanceof MockDronePriorityFactory);

        getManager().fire(new BeforeClass(this.getClass()));

        DroneContext context = getManager().getContext(ApplicationContext.class).getObjectStore().get(DroneContext
                .class);
        Assert.assertNotNull("Drone object holder was created in the context", context);

        DronePoint<MockDrone> dronePoint = new DronePointImpl<MockDrone>(MockDrone.class,DronePoint.Lifecycle.CLASS,
                AnnotationMocks.drone());

        MockDroneConfiguration configuration = context.get(dronePoint).getConfigurationAs(MockDroneConfiguration.class);
        Assert.assertEquals("MockDrone configuration was created by MockDronePriorityFactory",
                MockDronePriorityFactory.MOCK_DRONE_PRIORITY_FACTORY_FIELD, configuration.getField());
    }
View Full Code Here

        Method testDummyMethod = DummyClass.class.getMethod("testDummyMethod");

        getManager().getContext(TestContext.class).activate(instance);
        fire(new BeforeSuite());

        DroneContext context = getManager()
            .getContext(ApplicationContext.class).getObjectStore().get(DroneContext.class);
        Assert.assertNotNull("DroneContext was created in the context", context);

        DroneRegistry registry = getManager().getContext(SuiteContext.class).getObjectStore().get(DroneRegistry.class);
        Assert.assertNotNull("Drone registry was created in the context", registry);
View Full Code Here

        createDroneCallable(registry, dronePoint);
    }

    private <DRONE> void configureDrone(DroneRegistry registry, DronePoint<DRONE> dronePoint) {
        ArquillianDescriptor descriptor = arquillianDescriptor.get();
        DroneContext context = droneContext.get();
        Validate.stateNotNull(descriptor, "ArquillianDescriptor should not be null");
        Validate.stateNotNull(context, "DroneContext should be available while working with method scoped instances");

        if (context.get(dronePoint).hasConfiguration()) {
            logger.log(Level.WARNING, "Could not configure drone for injection point {0}, " +
                    "because it was already configured!", dronePoint);
            return;
        }

        Configurator<DRONE, ?> configurator = registry.getEntryFor(dronePoint.getDroneType(), Configurator.class);

        beforeDroneConfiguredEvent.fire(new BeforeDroneConfigured(configurator, dronePoint));

        // If nobody else provided the configuration, we have to do it
        if (!context.get(dronePoint).hasConfiguration()) {
            DroneConfiguration configuration = configurator.createConfiguration(descriptor, dronePoint);

            context.get(dronePoint).setConfiguration(configuration);
        }

        afterDroneConfiguredEvent.fire(new AfterDroneConfigured(dronePoint));
    }
View Full Code Here

        afterDroneConfiguredEvent.fire(new AfterDroneConfigured(dronePoint));
    }

    private <DRONE> void createDroneCallable(DroneRegistry registry, final DronePoint<DRONE> dronePoint) {
        final DroneContext context = droneContext.get();

        if (context.get(dronePoint).hasFutureInstance()) {
            logger.log(Level.WARNING, "Could not create drone callable for injection point {0}, " +
                    "because it was already created!", dronePoint);
            return;
        }

        final Instantiator instantiator = registry.getEntryFor(dronePoint.getDroneType(), Instantiator.class);
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("Using instantiator defined in class: " + instantiator.getClass().getName() + ", " +
                    "with precedence " + instantiator.getPrecedence());
        }

        beforeDroneCallableCreatedEvent.fire(new BeforeDroneCallableCreated(instantiator, dronePoint));

        // create future instance
        CachingCallable<DRONE> futureDrone = new CachingCallableImpl<DRONE>() {
            @Override
            protected DRONE createInstance() throws Exception {
                DroneConfiguration<?> configuration = context
                        .get(dronePoint)
                        .getConfigurationAs(DroneConfiguration.class);
                return (DRONE) instantiator.createInstance(configuration);
            }
        };

        context.get(dronePoint).setFutureInstance(futureDrone);

        afterDroneCallableCreatedEvent.fire(new AfterDroneCallableCreated(dronePoint));
    }
View Full Code Here

    @Inject
    private Instance<DroneContext> droneContext;

    public void destroyDrone(@Observes DestroyDrone command) {
        DroneContext context = droneContext.get();
        DronePoint<?> dronePoint = command.getDronePoint();
        // FIXME this condition might not be valid anymore!
        if (dronePoint == null || !context.contains(dronePoint)) {
            return;
        }

        boolean wasInstantiated = context.get(dronePoint).isInstantiated();
        if (wasInstantiated) {
            Destructor destructor = getDestructorFor(dronePoint.getDroneType());

            droneLifecycleEvent.fire(new BeforeDroneDestroyed(dronePoint));

            // we need to get drone once again, at it might get modified by observers on previous event
            Object drone = context.get(dronePoint).getInstance();

            destructor.destroyInstance(drone);
        }

        if (wasInstantiated) {
            droneLifecycleEvent.fire(new AfterDroneDestroyed(dronePoint));
        }

        context.remove(dronePoint);
    }
View Full Code Here

    @Inject
    private Event<DroneLifecycleEvent> droneLifecycleEvent;

    @Override
    public void enrich(Object testCase) {
        DroneContext context = droneContext.get();

        Map<Field, DronePoint<?>> injectionPoints = InjectionPoints.fieldsInClass(droneContext.get(),
                testCase.getClass());

        for (Field field : injectionPoints.keySet()) {
            // omit setting if already set
            if (SecurityActions.getFieldValue(testCase, field) != null) {
                log.log(Level.FINER, "Skipped injection of field {0}", field.getName());
                continue;
            }

            DronePoint<?> dronePoint = injectionPoints.get(field);

            ensureInjectionPointPrepared(dronePoint);

            log.log(Level.FINE, "Injecting @Drone for field {0}, injection point {1}",
                    new Object[] { dronePoint.getDroneType().getSimpleName(), dronePoint }
            );

            Object drone = context.get(dronePoint).getInstance();
            Validate.stateNotNull(drone, "Retrieved a null from Drone Context, " +
                            "which is not a valid Drone browser object. \nClass: {0}, field: {1}, injection point: {2}",
                    testCase.getClass().getName(), field.getName(), dronePoint
            );
            SecurityActions.setFieldValue(testCase, field, drone);
View Full Code Here

        }
    }

    @Override
    public Object[] resolve(Method method) {
        DroneContext context = droneContext.get();
        DronePoint<?>[] dronePoints = InjectionPoints.parametersInMethod(droneContext.get(), method);
        Object[] resolution = new Object[dronePoints.length];
        for (int i = 0; i < dronePoints.length; i++) {
            DronePoint<?> dronePoint = dronePoints[i];
            if (dronePoint == null) {
                resolution[i] = null;
                continue;
            }

            ensureInjectionPointPrepared(dronePoint);

            log.log(Level.FINE, "Injecting @Drone for method {0}, injection point {1}",
                    new Object[] { method.getName(), dronePoint }
            );

            Object drone = context.get(dronePoint).getInstance();
            Validate.stateNotNull(drone, "Retrieved a null from Drone Context, which is not a valid Drone browser " +
                    "object" +
                    ".\nMethod: {0}, injection point: {1},", method.getName(), dronePoint);
            resolution[i] = drone;
        }
View Full Code Here

    @Inject
    private Event<DestroyDrone> destroyDroneCommand;

    public void managerStarted(@Observes ManagerStarted event) {
        try {
            DroneContext context = injector.get().inject(new DroneContextImpl());
            droneContext.set(context);
        } catch (TypeNotPresentException e) {
            log.log(Level.SEVERE,
                "Unable to create Drone Context due to missing services on classpath. Please make sure to use Arquillian Core 1.1.4.Final or later.");
            throw new IllegalStateException("Unable to create Drone Context due to missing services on classpath. Please make sure to use Arquillian Core 1.1.4.Final or later.",
View Full Code Here

                e);
        }
    }

    public void configureDroneExtension(@Observes BeforeSuite event) {
        DroneContext context = droneContext.get();

        if (context.getGlobalDroneConfiguration(DroneConfiguration.class) != null) {
            return;
        }

        beforeDroneExtensionConfiguredEvent.fire(new BeforeDroneExtensionConfigured());

        if (context.getGlobalDroneConfiguration(DroneConfiguration.class) == null) {
            GlobalDroneConfiguration configuration =
                new GlobalDroneConfiguration().configure(arquillianDescriptor.get(), null);
            context.setGlobalDroneConfiguration(configuration);
        }

        afterDroneExtensionConfiguredEvent.fire(new AfterDroneExtensionConfigured());
    }
View Full Code Here

TOP

Related Classes of org.jboss.arquillian.drone.spi.DroneContext

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.