package io.liveoak.scheduler;

import io.liveoak.container.ReturnFieldsImpl;
import io.liveoak.container.codec.DefaultResourceState;
import io.liveoak.spi.RequestContext;
import io.liveoak.spi.resource.RootResource;
import io.liveoak.spi.state.ResourceState;
import io.liveoak.testtools.AbstractResourceTestCase;
import org.junit.After;
import org.junit.Test;

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

/**
 * @author Bob McWhirter
 */
public class SchedulerResourceTest extends AbstractResourceTestCase {
    @Override
    public RootResource createRootResource() {
        return new SchedulerResource("scheduler");
    }

    @After
    public void stopScheduler() {
        //this.resource.destroy();
    }

    @Test
    public void testAddTrigger() throws Exception {
        RequestContext requestContext = new RequestContext.Builder().returnFields(new ReturnFieldsImpl("*").withExpand("members")).build();

        ResourceState triggerState = new DefaultResourceState();
        triggerState.putProperty("cron", "* * * * * ?");
        ResourceState returnedState = connector.create(requestContext, "/scheduler", triggerState);

        String id = returnedState.id();

        // intentional, to allow the job to fire some
        Thread.sleep(2000);

        ResourceState fromCollection = connector.read(requestContext, "/scheduler/" + id);

        assertThat(fromCollection).isNotNull();
        assertThat(fromCollection.getPropertyNames()).hasSize(2);
        assertThat(fromCollection.getProperty("cron")).isEqualTo("* * * * * ?");
        assertThat(fromCollection.getProperty("state")).isEqualTo("normal");

        assertThat(fromCollection.members().size()).isGreaterThanOrEqualTo(2);
    }

}

@@ -1038,32 +1038,84 @@
 %22* * * * * ?%22);%0A
+        System.err.println( %22creating a trigger%22 );%0A
         Resource
@@ -1202,49 +1202,170 @@
 e);%0A
-%0A        String id = returnedState.id();%0A
+        System.err.println( %22created a trigger: %22 + returnedState );%0A%0A        String id = returnedState.id();%0A%0A        System.err.println( %22Sleeping 2 seconds%22 );
 %0A   
@@ -1440,24 +1440,75 @@
 eep(2000);%0A%0A
+        System.err.println( %22Fetching firings%22 );%0A%0A
         Reso
@@ -1583,24 +1583,85 @@
 r/%22 + id);%0A%0A
+        System.err.println( %22Fetched: %22 + fromCollection );%0A%0A
         asse

Add debug to determine where CI is hanging.