Package org.ops4j.pax.exam

Examples of org.ops4j.pax.exam.TestContainerException


        boolean forceOverwrite = overwrite || !destination.exists();
        if (!forceOverwrite) {
            try {
                String cachingName = determineCachingName(destination, hashFileName);
                if (!destination.getName().equals(cachingName)) {
                    throw new TestContainerException("File " + destination + " should have name "
                        + cachingName);
                }
            }
            catch (TestContainerException ignore) {
                forceOverwrite = true;
            }
        }
        if (forceOverwrite) {
            try {
                LOGGER.debug("Creating new file at destination: " + destination.getAbsolutePath());
                destination.getParentFile().mkdirs();
                destination.createNewFile();
                FileOutputStream os = null;
                try {
                    os = new FileOutputStream(destination);
                    FileChannel fileChannel = os.getChannel();
                    StreamUtils.ProgressBar progressBar = null;
                    if (LOGGER.isInfoEnabled()) {
                        if (downloadFeeback) {
                            progressBar = new StreamUtils.FineGrainedProgressBar(displayName);
                        }
                        else {
                            progressBar = new StreamUtils.CoarseGrainedProgressBar(displayName);
                        }
                    }
                    // Check if this is an exploded bundle...
                    if (url.getPath().endsWith("/") && "file".equals(url.getProtocol())) {
                        StreamUtils.streamCopy(new URL("assembly:" + url.toExternalForm()),
                            fileChannel, progressBar);
                    }
                    else {
                        StreamUtils.streamCopy(url, fileChannel, progressBar);
                    }

                    fileChannel.close();
                    LOGGER.debug("Successfully downloaded to [" + destination + "]");
                }
                finally {
                    if (os != null) {
                        os.close();
                    }
                }
            }
            catch (IOException e) {
                throw new TestContainerException("[" + url + "] could not be downloaded", e);
            }
        }
        if (checkAttributes) {
            try {
                validateBundle(url, destination);
            }
            catch (TestContainerException e) {
                if (failOnValidation) {
                    throw e;
                }
                return null;
            }
        }
        String cachingName = determineCachingName(destination, hashFileName);
        File newDestination = new File(destination.getParentFile(), cachingName);
        if (!cachingName.equals(destination.getName())) {
            if (newDestination.exists()) {
                if (!newDestination.delete()) {
                    throw new TestContainerException("Cannot delete " + newDestination);
                }
            }
            if (!destination.renameTo(newDestination)) {
                throw new TestContainerException("Cannot rename " + destination + " to "
                    + newDestination);
            }
            fileNamesForUrls.setProperty(url.toExternalForm(), cachingName);
            saveProperties(fileNamesForUrls, downloadedBundlesFile);
        }
View Full Code Here


        try {
            os = new FileOutputStream(file);
            properties.store(os, "");
        }
        catch (IOException e) {
            throw new TestContainerException("Cannot store properties " + file, e);
        }
        finally {
            if (os != null) {
                try {
                    os.close();
View Full Code Here

                    stream.close();
                }

            }
            catch (IOException e) {
                throw new TestContainerException("[" + url + "] is not a valid exploded bundle", e);
            }
        }
        else {
            JarFile jar = null;
            try {
                // verify that is a valid jar. Do not verify that is signed (the false param).
                jar = new JarFile(file, false);
                final Manifest manifest = jar.getManifest();
                if (manifest == null) {
                    throw new TestContainerException("[" + url
                        + "] is not a valid bundle (manifest is missing)");
                }
                bundleSymbolicName = manifest.getMainAttributes().getValue(
                    Constants.BUNDLE_SYMBOLICNAME);
                bundleName = manifest.getMainAttributes().getValue(Constants.BUNDLE_NAME);
            }
            catch (IOException e) {
                throw new TestContainerException("[" + url
                    + "] is not a valid bundle (reading jar failed)", e);
            }
            finally {
                if (jar != null) {
                    try {
                        jar.close();
                    }
                    catch (IOException ignore) {
                        // just ignore as this is less probably to happen.
                    }
                }
            }
        }
        if (bundleSymbolicName == null && bundleName == null) {
            throw new TestContainerException("[" + url
                + "] is not a valid bundle (bundleSymbolicName and bundleName are null)");
        }
    }
View Full Code Here

            .iterator();
        while (iter.hasNext()) {
            factories.add(iter.next());
        }
        if (factories.size() == 0) {
            throw new TestContainerException("No TestContainer implementation in Classpath");
        }
        else if (factories.size() > 1) {
            for (TestContainerFactory fac : factories) {
                LOG.error("Ambiguous TestContainer:  " + fac.getClass().getName());
            }
            throw new TestContainerException("Too many TestContainer implementations in Classpath");
        }
        else {
            // good!
            return;
        }
View Full Code Here

            javaRunner.exec(vmOptions, buildClasspath(beforeFrameworkClasspath, afterFrameworkClasspath),
                RemoteFrameworkImpl.class.getName(), args, getJavaHome(), null);
            return findRemoteFramework(port, rmiName);
        }
        catch (RemoteException | ExecutionException | URISyntaxException exc) {
            throw new TestContainerException(exc);
        }
    }
View Full Code Here

        String[] classpath = new String[entries];
        int i = 0;
        if (beforeFrameworkClasspath != null) {
            for (String beforeFrameworkLibrary : beforeFrameworkClasspath) {
                if (!new File(beforeFrameworkLibrary).exists()) {
                    throw new TestContainerException(
                            "Invalid boot classpath library: " + beforeFrameworkLibrary);
                }
                classpath[i++] = beforeFrameworkLibrary;
            }
        }
        classpath[i++] = frameworkPath;
        classpath[i++] = launcherPath;
        classpath[i++] = serviceLookupPath;
        if (afterFrameworkClasspath != null) {
            for (String afterFrameworkLibrary : afterFrameworkClasspath) {
                if (!new File(afterFrameworkLibrary).exists()) {
                    throw new TestContainerException(
                            "Invalid boot classpath library: " + afterFrameworkLibrary);
                }
                classpath[i++] = afterFrameworkLibrary;
            }
        }
View Full Code Here

                reason = e;
            }
        }
        while (framework == null && (System.currentTimeMillis() < startedTrying + TIMEOUT));
        if (framework == null) {
            throw new TestContainerException("cannot find remote framework in RMI registry", reason);
        }
        return framework;

    }
View Full Code Here

             * now, just to be on the safe side.
             */
            javaRunner.shutdown();
        }
        catch (NoSuchObjectException exc) {
            throw new TestContainerException(exc);
        }
    }
View Full Code Here

public class ForkedTestContainerFactory implements TestContainerFactory {

    public TestContainer[] create(final ExamSystem system) {
        List<FrameworkFactory> frameworkFactories = findFrameworkFactories();
        if (frameworkFactories.isEmpty()) {
            throw new TestContainerException(
                "No service org.osgi.framework.launch.FrameworkFactory found in META-INF/services on classpath");
        }
        TestContainer[] containers = new TestContainer[frameworkFactories.size()];
        int index = 0;
        for (FrameworkFactory frameworkFactory : frameworkFactories) {
View Full Code Here

            try {
                containers.add(new NativeTestContainer(system, factories.next()));
                factoryFound = true;
            }
            catch (IOException e) {
                throw new TestContainerException("Problem initializing container.", e);
            }
        }
        if (!factoryFound) {
            throw new TestContainerException(
                "No service org.osgi.framework.launch.FrameworkFactory found in META-INF/services on classpath");
        }
        return containers.toArray(new TestContainer[containers.size()]);
    }
View Full Code Here

TOP

Related Classes of org.ops4j.pax.exam.TestContainerException

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.