Search in sources :

Example 1 with XWikiExecutor

use of org.xwiki.test.integration.XWikiExecutor in project xwiki-platform by xwiki.

the class AbstractClusterHttpTest method init.

@BeforeClass
public static void init() throws Exception {
    if (context == null) {
        // Start HSQLDB server if not already running
        try (Socket ignored = new Socket("localhost", 9001)) {
            LOGGER.info("HSQLDB server is already running");
        } catch (IOException ignored) {
            LOGGER.info("HSQLDB server is not running. Starting one...");
            Server server = new Server();
            server.setSilent(true);
            File testDirectory = new File("target/test-" + new Date().getTime()).getAbsoluteFile();
            File databaseDirectory = new File(testDirectory, "database");
            server.setDatabaseName(0, "xwiki_db");
            server.setDatabasePath(0, databaseDirectory.toString());
            server.setDaemon(true);
            server.start();
            LOGGER.info("HSQLDB server started");
        }
        List<XWikiExecutor> executors = new ArrayList<>(2);
        executors.add(createExecutor(0));
        executors.add(createExecutor(1));
        // Require some AbstractTest initialization
        AbstractTest.init(executors);
    }
}
Also used : XWikiExecutor(org.xwiki.test.integration.XWikiExecutor) Server(org.hsqldb.Server) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) Socket(java.net.Socket) Date(java.util.Date) BeforeClass(org.junit.BeforeClass)

Example 2 with XWikiExecutor

use of org.xwiki.test.integration.XWikiExecutor in project xwiki-platform by xwiki.

the class AllITs method preStart.

@XWikiExecutorSuite.PreStart
public void preStart(List<XWikiExecutor> executors) throws Exception {
    XWikiExecutor executor = executors.get(0);
    repositoryUtil = new RepositoryUtils();
    LOGGER.info("Adding repository to xwiki.properties");
    PropertiesConfiguration properties = executor.loadXWikiPropertiesConfiguration();
    // Put self and Maven as extensions repository
    properties.setProperty("extension.repositories", Arrays.asList("self:xwiki:http://localhost:8080/xwiki/rest", "maven-test:maven:" + repositoryUtil.getMavenRepository().toURI()));
    // Disable core extension resolve because Jetty is not ready when it starts
    properties.setProperty("extension.core.resolve", false);
    executor.saveXWikiProperties();
}
Also used : RepositoryUtils(org.xwiki.extension.test.RepositoryUtils) XWikiExecutor(org.xwiki.test.integration.XWikiExecutor) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Example 3 with XWikiExecutor

use of org.xwiki.test.integration.XWikiExecutor in project xwiki-platform by xwiki.

the class ForEachProfileSuite method run.

@Override
public void run(RunNotifier notifier) {
    // Get the list of test profiles.
    final List<Class<?>> profiles = new ClasspathClassesFinder(IsProfileTester.INSTANCE, "java.class.path").find();
    final Map<Profile, XWikiExecutor> executorByProfile = new HashMap<Profile, XWikiExecutor>();
    for (int i = 0; i < profiles.size(); i++) {
        try {
            // All executors are #0 because they will not be run in parallel.
            executorByProfile.put(((Class<Profile>) profiles.get(i)).newInstance(), new XWikiExecutor(0));
        } catch (Exception e) {
            throw new RuntimeException("Failed to instanciate configuration profile.", e);
        }
    }
    // Callback to setup executors in the suite class.
    try {
        for (Profile profile : executorByProfile.keySet()) {
            profile.apply(executorByProfile.get(profile));
        }
    } catch (Exception e) {
        throw new RuntimeException("Failed to initialize XWiki Executors", e);
    }
    for (final Profile profile : executorByProfile.keySet()) {
        final XWikiExecutor executor = executorByProfile.get(profile);
        try {
            try {
                executor.start();
            } catch (Exception e) {
                throw new RuntimeException("Failed to start XWiki", e);
            }
            try {
                Object instance = this.getTestClass().getJavaClass().newInstance();
                // and has an @Inject annotation, inject the current executor.
                for (Field field : this.getTestClass().getJavaClass().getDeclaredFields()) {
                    if (field.getType() == XWikiExecutor.class && field.getAnnotation(Inject.class) != null) {
                        field.setAccessible(true);
                        field.set(instance, executor);
                    }
                }
                // If the class is initializable then call initialize.
                final Class<?>[] interfaces = this.getTestClass().getJavaClass().getInterfaces();
                for (int i = 0; i < interfaces.length; i++) {
                    if (interfaces[i] == Initializable.class) {
                        this.getTestClass().getJavaClass().getMethod("initialize").invoke(instance);
                    }
                }
            } catch (Exception e) {
                throw new RuntimeException("Failed to prepare tests to run in config profile.", e);
            }
            super.run(notifier);
        } finally {
            try {
                executor.stop();
            } catch (Exception e) {
            // Squash this and let the original exception be thrown.
            }
        }
    }
}
Also used : XWikiExecutor(org.xwiki.test.integration.XWikiExecutor) HashMap(java.util.HashMap) Field(java.lang.reflect.Field) ClasspathClassesFinder(org.junit.extensions.cpsuite.ClasspathClassesFinder)

Example 4 with XWikiExecutor

use of org.xwiki.test.integration.XWikiExecutor in project xwiki-platform by xwiki.

the class AbstractClusterHttpTest method createExecutor.

protected static XWikiExecutor createExecutor(int index) {
    XWikiExecutor executor = new XWikiExecutor(index);
    AllTests.setupExecutor(executor);
    return executor;
}
Also used : XWikiExecutor(org.xwiki.test.integration.XWikiExecutor)

Example 5 with XWikiExecutor

use of org.xwiki.test.integration.XWikiExecutor in project xwiki-platform by xwiki.

the class AllTests method preStart.

@XWikiExecutorSuite.PreStart
public void preStart(List<XWikiExecutor> executors) throws Exception {
    XWikiExecutor executor = executors.get(0);
    repositoryUtil = new RepositoryUtils();
    LOGGER.info("Adding maven repository to xwiki.properties");
    PropertiesConfiguration properties = executor.loadXWikiPropertiesConfiguration();
    // Put self as extensions repository
    properties.setProperty("extension.repositories", "maven-test:maven:" + repositoryUtil.getMavenRepository().toURI());
    // Disable core extension resolve because Jetty is not ready when it starts
    properties.setProperty("extension.core.resolve", false);
    executor.saveXWikiProperties();
}
Also used : RepositoryUtils(org.xwiki.extension.test.RepositoryUtils) XWikiExecutor(org.xwiki.test.integration.XWikiExecutor) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Aggregations

XWikiExecutor (org.xwiki.test.integration.XWikiExecutor)5 PropertiesConfiguration (org.apache.commons.configuration2.PropertiesConfiguration)2 RepositoryUtils (org.xwiki.extension.test.RepositoryUtils)2 File (java.io.File)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 Socket (java.net.Socket)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Server (org.hsqldb.Server)1 BeforeClass (org.junit.BeforeClass)1 ClasspathClassesFinder (org.junit.extensions.cpsuite.ClasspathClassesFinder)1