package org.ow2.chameleon.core;

import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.BundleException;

import java.io.File;

import static org.fest.assertions.Assertions.assertThat;

/**
 * Check the behavior of the Chameleon class.
 */
public class ChameleonTest {

    public static final File CHAMELEON = new File("target/test/chameleon");
    public static final File APPLICATION = new File(CHAMELEON, "application");
    private Chameleon chameleon;

    @Before
    public void init() throws Exception {
        FileUtils.deleteQuietly(APPLICATION);
        APPLICATION.mkdirs();
        chameleon = new Chameleon(CHAMELEON, false, null);
    }

    @After
    public void stop() throws BundleException, InterruptedException {
        chameleon.stop();
        chameleon = null;
    }

    @Test
    public void testStart() throws BundleException {
        assertThat(chameleon).isNotNull();
        assertThat(chameleon.context()).isNull();
        chameleon.start();
        assertThat(chameleon.context()).isNotNull();
        assertThat(chameleon.framework()).isNotNull();
    }

}

package org.ow2.chameleon.core;

import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.BundleException;

import java.io.File;

import static org.fest.assertions.Assertions.assertThat;

/**
 * Check the behavior of the Chameleon class.
 */
public class ChameleonTest {

    public static final File CHAMELEON = new File("target/test/chameleon");
    public static final File APPLICATION = new File(CHAMELEON, "application");
    private Chameleon chameleon;

    @Before
    public void init() throws Exception {
        FileUtils.deleteQuietly(APPLICATION);
        APPLICATION.mkdirs();
        chameleon = new Chameleon(CHAMELEON, false, null);
    }

    @After
    public void stop() throws BundleException, InterruptedException {
        chameleon.stop();
        chameleon = null;
    }

    @Test
    public void testStart() throws BundleException {
        assertThat(chameleon).isNotNull();
        assertThat(chameleon.context()).isNull();
        chameleon.start();
        assertThat(chameleon.context()).isNotNull();
        assertThat(chameleon.framework()).isNotNull();
    }

    @Test
    public void testInitializationFromConfiguration() throws Exception {
        File baseDirectory = new File("target/test-classes/configurations/regular");
        assertThat(baseDirectory).isDirectory();
        ChameleonConfiguration configuration = new ChameleonConfiguration(baseDirectory);
        chameleon = new Chameleon(configuration);
        assertThat(chameleon).isNotNull();
        assertThat(chameleon.context()).isNull();
        chameleon.start();
        assertThat(chameleon.context()).isNotNull();
        assertThat(chameleon.framework()).isNotNull();
    }

}

Check the initialization form a configuration
Check the initialization form a configuration

Signed-off-by: Clement Escoffier <6397137e57d1f87002962a37058f2a1c76fca9db@gmail.com>
