org.jboss.arquillian.core.spi.ServiceLoader Java Examples

The following examples show how to use org.jboss.arquillian.core.spi.ServiceLoader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JiraGovernorTestCase.java    From arquillian-governor with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {

    serviceProducer.set(serviceLoader);

    final List<GovernorProvider> governorProviders = new ArrayList<GovernorProvider>();
    governorProviders.add(governorProvider);

    Mockito.when(serviceLoader.all(GovernorProvider.class)).thenReturn(governorProviders);

    manager = Mockito.spy(getManager());
    Mockito.when(manager.resolve(ServiceLoader.class)).thenReturn(serviceLoader);

    governorConfiguration = new GovernorConfiguration();
    bind(ApplicationScoped.class, GovernorConfiguration.class, governorConfiguration);

    jiraGovernorConfiguration = new JiraGovernorConfiguration();
    jiraGovernorConfiguration.setServer(JIRA_SERVER_ADDRESS);
    jiraGovernorConfiguration.setUsername(USERNAME);
    jiraGovernorConfiguration.setPassword(PASSWORD);

    bind(ApplicationScoped.class, JiraGovernorConfiguration.class, jiraGovernorConfiguration);

    final JiraGovernorClient jiraGovernorClient = new JiraGovernorClientFactory().build(jiraGovernorConfiguration);
    bind(ApplicationScoped.class, JiraGovernorClient.class, jiraGovernorClient);
}
 
Example #2
Source File: BlurLevelTestCase.java    From arquillian-recorder with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    bind(ApplicationScoped.class, ServiceLoader.class, serviceLoader);
    bind(ApplicationScoped.class, ScreenshooterConfiguration.class, configuration);
    bind(ApplicationScoped.class, Screenshooter.class, screenshooter);
    bind(ApplicationScoped.class, RecorderStrategyRegister.class, recorderStrategyRegister);

    Mockito.when(screenshooter.getScreenshotType()).thenReturn(ScreenshotType.PNG);

    Mockito.doNothing().when(cleaner).clean(configuration);

    Mockito.when(serviceLoader.onlyOne(ScreenshooterEnvironmentCleaner.class, DefaultScreenshooterEnvironmentCleaner.class))
        .thenReturn(cleaner);

    screenshotFile = folder.newFile("screenshot.png");
    URL resource = BlurLevelTestCase.class.getResource("/arquillian_ui_success_256px.png");
    FileUtils.copyURLToFile(resource, screenshotFile);
    originalSize = (int) screenshotFile.length();
    OUTPUT_FILE = screenshotFile.getAbsoluteFile();
}
 
Example #3
Source File: RegistryCreator.java    From keycloak with Apache License 2.0 6 votes vote down vote up
public void createRegistry(@Observes ArquillianDescriptor event) {
    ContainerRegistry reg = new Registry(injector.get());
    ServiceLoader serviceLoader = loader.get();

    log.info("arquillian.xml: " + System.getProperty("arquillian.xml"));

    @SuppressWarnings("rawtypes")
    Collection<DeployableContainer> containers = serviceLoader.all(DeployableContainer.class);

    if (containers.isEmpty()) {
        throw new IllegalStateException("There are not any container adapters on the classpath");
    }

    List<ContainerDef> containersDefs = event.getContainers();//arquillian.xml
    List<GroupDef> groupDefs = event.getGroups();//arquillian.xml

    addAppServerContainers(containersDefs, groupDefs);//dynamically loaded containers/groups

    createRegistry(containersDefs, reg, serviceLoader);

    for (GroupDef group : groupDefs) {
        createRegistry(group.getGroupContainers(), reg, serviceLoader);
    }

    registry.set(reg);
}
 
Example #4
Source File: Registry.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private Container domainContainer(ServiceLoader loader, ContainerDef definition) {
    for (Container container : containers) {
        String adapterImplClassValue = container.getContainerConfiguration().getContainerProperties()
                .get(ADAPTER_IMPL_CONFIG_STRING);

        if (isServiceLoaderClassAssignableFromAdapterImplClass(loader, adapterImplClassValue.trim())) {
            try {
                return addContainer((Container) injector.inject(
                        new ContainerImpl(
                                definition.getContainerName(),
                                (DeployableContainer) loader.onlyOne(DeployableContainer.class),
                                definition)));
            } catch (Exception ex) {
                throw new ContainerCreationException(
                        "Could not create Container " + definition.getContainerName(), ex);
            }
        }
    }
    return null;
}
 
Example #5
Source File: RedmineGovernorTestCase.java    From arquillian-governor with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {

    serviceProducer.set(serviceLoader);

    final List<GovernorProvider> governorProviders = new ArrayList<GovernorProvider>();
    governorProviders.add(governorProvider);

    Mockito.when(serviceLoader.all(GovernorProvider.class)).thenReturn(governorProviders);

    manager = Mockito.spy(getManager());
    Mockito.when(manager.resolve(ServiceLoader.class)).thenReturn(serviceLoader);

    governorConfiguration = new GovernorConfiguration();
    bind(ApplicationScoped.class, GovernorConfiguration.class, governorConfiguration);

    redminebGovernorConfiguration = new RedmineGovernorConfiguration();
    redminebGovernorConfiguration.setApiKey("apikey");
    redminebGovernorConfiguration.setServer("http://localhost");
    redminebGovernorConfiguration.setForce(true);
    redminebGovernorConfiguration.setClosePassed(true);

    bind(ApplicationScoped.class, RedmineGovernorConfiguration.class, redminebGovernorConfiguration);

    final RedmineGovernorClient redmineGovernorClient = new RedmineGovernorClientFactory().build(redminebGovernorConfiguration);
    bind(ApplicationScoped.class, RedmineGovernorClient.class, redmineGovernorClient);
}
 
Example #6
Source File: GitHubGovernorTestCase.java    From arquillian-governor with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {

    serviceProducer.set(serviceLoader);

    final List<GovernorProvider> governorProviders = new ArrayList<GovernorProvider>();
    governorProviders.add(governorProvider);

    Mockito.when(serviceLoader.all(GovernorProvider.class)).thenReturn(governorProviders);

    manager = Mockito.spy(getManager());
    Mockito.when(manager.resolve(ServiceLoader.class)).thenReturn(serviceLoader);

    governorConfiguration = new GovernorConfiguration();
    bind(ApplicationScoped.class, GovernorConfiguration.class, governorConfiguration);

    gitHubGovernorConfiguration = new GitHubGovernorConfiguration();
    gitHubGovernorConfiguration.setRepository(REPOSITORY_NAME);
    gitHubGovernorConfiguration.setRepositoryUser(REPOSITORY_USERNAME);
    gitHubGovernorConfiguration.setForce(true);
    gitHubGovernorConfiguration.setClosePassed(true);

    if (!TOKEN.equals(EMPTY_STRING)) {
        gitHubGovernorConfiguration.setToken(TOKEN);
    }

    gitHubGovernorConfiguration.setUsername(USERNAME);
    gitHubGovernorConfiguration.setPassword(PASSWORD);

    bind(ApplicationScoped.class, GitHubGovernorConfiguration.class, gitHubGovernorConfiguration);

    final GitHubGovernorClient gitHubGovernorClient = new GitHubGovernorClientFactory().build(gitHubGovernorConfiguration);
    bind(ApplicationScoped.class, GitHubGovernorClient.class, gitHubGovernorClient);
}
 
Example #7
Source File: GovernorTestCase.java    From arquillian-governor with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    serviceProducer.set(serviceLoader);

    final List<GovernorProvider> governorProviders = new ArrayList<GovernorProvider>();
    governorProviders.add(governorProvider);

    Mockito.when(serviceLoader.all(GovernorProvider.class)).thenReturn(governorProviders);

    manager = Mockito.spy(getManager());
    Mockito.when(manager.resolve(ServiceLoader.class)).thenReturn(serviceLoader);

    governorConfiguration = new GovernorConfiguration();
    bind(ApplicationScoped.class, GovernorConfiguration.class, governorConfiguration);
}
 
Example #8
Source File: ScreenshooterLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 5 votes vote down vote up
@org.junit.Before
public void setMocks() throws Exception {
    bind(ApplicationScoped.class, ServiceLoader.class, serviceLoader);
    bind(ApplicationScoped.class, ScreenshooterConfiguration.class, configuration);
    bind(ApplicationScoped.class, Screenshooter.class, screenshooter);
    bind(ApplicationScoped.class, RecorderStrategyRegister.class, recorderStrategyRegister);

    Mockito.when(screenshooter.getScreenshotType()).thenReturn(ScreenshotType.PNG);

    Mockito.doNothing().when(cleaner).clean(configuration);

    Mockito.when(serviceLoader.onlyOne(ScreenshooterEnvironmentCleaner.class, DefaultScreenshooterEnvironmentCleaner.class))
        .thenReturn(cleaner);
}
 
Example #9
Source File: RecorderLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 5 votes vote down vote up
@org.junit.Before
    public void setup() throws Exception {
        bind(ApplicationScoped.class, ServiceLoader.class, serviceLoader);
        bind(ApplicationScoped.class, VideoConfiguration.class, configuration);
        bind(ApplicationScoped.class, Recorder.class, recorder);
        bind(ApplicationScoped.class, TakenResourceRegister.class, takenResourceRegister);

        strategy.setConfiguration(configuration);
        bind(ApplicationScoped.class, VideoStrategy.class, strategy);

        Mockito.when(recorder.getVideoType()).thenReturn(VideoType.MP4);

        Mockito.doNothing().when(cleaner).clean(configuration);

        Mockito.when(serviceLoader.onlyOne(VideoRecorderEnvironmentCleaner.class, DefaultVideoRecorderEnvironmentCleaner.class))
            .thenReturn(cleaner);

//        Mockito.when(serviceLoader.onlyOne(VideoStrategy.class, DefaultVideoStrategy.class))
//            .thenReturn(strategy);

        videoFile = File.createTempFile("fakeVideo", recorder.getVideoType().toString().toLowerCase());

        Mockito.when(configuration.getVideoName()).thenReturn("record");

        Mockito.when(video.getResource()).thenReturn(videoFile);
        Mockito.when(video.getResourceType()).thenReturn(VideoType.MP4);
        Mockito.when(video.getWidth()).thenReturn(100);
        Mockito.when(video.getHeight()).thenReturn(100);

        Mockito.when(recorder.stopRecording()).thenReturn(video);
    }
 
Example #10
Source File: RegistryCreator.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void createRegistry(List<ContainerDef> containerDefs, ContainerRegistry reg, ServiceLoader serviceLoader) {
    for (ContainerDef container : containerDefs) {
        if (isAdapterImplClassAvailable(container)) {
            if (isEnabled(container)) {
                log.info("Registering container: " + container.getContainerName());
                reg.create(container, serviceLoader);
            } else {
                log.info("Container is disabled: " + container.getContainerName());
            }
        }
    }
}
 
Example #11
Source File: Registry.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public Container create(ContainerDef definition, ServiceLoader loader) {
    Validate.notNull(definition, "Definition must be specified");

    try {
        logger.log(Level.FINE, "Registering container: {0}", definition.getContainerName());

        @SuppressWarnings("rawtypes")
        Collection<DeployableContainer> containerAdapters = loader.all(DeployableContainer.class);

        DeployableContainer<?> dcService = null;

        if (containerAdapters.size() == 1) {
            // just one container on cp
            dcService = containerAdapters.iterator().next();
        } else {
            Container domainContainer = domainContainer(loader, definition);
            if (domainContainer != null) {
                return domainContainer;
            }
            if (dcService == null) {
                dcService = getContainerAdapter(getAdapterImplClassValue(definition), containerAdapters);
            }
            if (dcService == null) {
                throw new ConfigurationException("Unable to get container adapter from Arquillian configuration.");
            }
        }

        // before a Container is added to a collection of containers, inject into its injection point
        return addContainer(injector.inject(
                new ContainerImpl(definition.getContainerName(), dcService, definition)));

    } catch (ConfigurationException e) {
        throw new ContainerCreationException("Could not create Container " + definition.getContainerName(), e);
    }
}
 
Example #12
Source File: Registry.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private boolean isServiceLoaderClassAssignableFromAdapterImplClass(ServiceLoader loader, String adapterImplClassValue) {
    if (adapterImplClassValue == null && loader == null) {
        return false;
    }
    if (isClassPresent(adapterImplClassValue)) {
        Class<?> aClass = loadClass(adapterImplClassValue);
        String loaderClassName = loader.getClass().getName();
        if (loaderClassName.contains("$")) {
            loaderClassName = loaderClassName.substring(0, loaderClassName.indexOf("$"));
        }
        return loadClass(loaderClassName).isAssignableFrom(aClass);
    }
    return false;
}