package org.wisdom.mongodb;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.ServiceReference;
import org.ow2.chameleon.testing.helpers.OSGiHelper;
import org.wisdom.test.parents.WisdomTest;

import java.util.Date;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * Check the behavior of the Mongo DB Client.
 */
public class MongoDBClientIT extends WisdomTest {

    private OSGiHelper osgi;

    @Before
    public void setUp() {
        osgi = new OSGiHelper(context);
    }

    @After
    public void after() {
        osgi.dispose();
    }

    @Test
    public void testOSGiService() {
        DB db = osgi.waitForService(DB.class, null, 5000);
        ServiceReference reference = osgi.getServiceReference(DB.class);
        // Check properties
        assertThat(reference.getProperty("host")).isEqualTo("localhost");
        assertThat(reference.getProperty("port")).isNotNull();
        assertThat(reference.getProperty("name")).isEqualTo("kitten");
        assertThat((String[]) reference.getProperty("datasources")).contains("test").hasSize(1);

        // Check Mongo
        DBCollection col = db.getCollection("testCol");
        if (col == null) {
            col = db.createCollection("testCol", new BasicDBObject());
        }
        col.save(new BasicDBObject("testDoc", new Date()));
    }

}

@@ -1454,16 +1454,160 @@
 ate()));
+%0A%0A        // Check datasource filter%0A        db = osgi.waitForService(DB.class, %22(datasources=test)%22, 5000);%0A        assertThat(db).isNotNull();
 %0A    %7D%0A%0A

Improve integration tests