package fr.synchrotron.soleil.ica.ci.lib.workflow;

import org.junit.Test;

import java.util.Arrays;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

/**
 * @author Gregory Boissinot
 */
public class WorkflowTest {

    @Test(expected = NullPointerException.class)
    public void testNullNormalizedStatus() {
        Workflow workflow = Workflow.DEFAULT_WORKFLOW_STATUS;
        assertNull(workflow.getNormalizedStatus(null));
    }

    public void testNormalizedStatus(String label) {
        Workflow workflow = Workflow.DEFAULT_WORKFLOW_STATUS;
        assertEquals("BUILD", workflow.getNormalizedStatus("build"));
        assertEquals("BUILD", workflow.getNormalizedStatus("BUILD"));
        assertEquals("INTEGRATION", workflow.getNormalizedStatus("integration"));
        assertEquals("INTEGRATION", workflow.getNormalizedStatus("INTEGRATION"));
        assertEquals("RELEASE", workflow.getNormalizedStatus("release"));
        assertEquals("RELEASE", workflow.getNormalizedStatus("RELEASE"));
    }


    @Test
    public void testBuildWorkflowOneElement() {
        Workflow workflow = new Workflow("TEST_WORKFLOW_ONE_ELEMENT", Arrays.asList("BUILD"));
        assertEquals("TEST_WORKFLOW_ONE_ELEMENT", workflow.getName());
        assertEquals("BUILD", workflow.getLatestPromotedStatus());
        assertNull(workflow.getNextStatusLabel("build"));
        assertNull(workflow.getNextStatusLabel("BUILD"));
        assertNull(workflow.getNextStatusLabel("UNKNOWN_STATUS_LABEL"));
    }

    @Test
    public void testBuildWorkflowTwoElements() {
        Workflow workflow = new Workflow("TEST_WORKFLOW_TWO_ELEMENTS", Arrays.asList("BUILD", "INTEGRATION"));
        assertEquals("TEST_WORKFLOW_TWO_ELEMENTS", workflow.getName());
        assertEquals("INTEGRATION", workflow.getLatestPromotedStatus());
        assertEquals("INTEGRATION", workflow.getNextStatusLabel("build"));
        assertEquals("INTEGRATION", workflow.getNextStatusLabel("BUILD"));
        assertNull(workflow.getNextStatusLabel("integration"));
        assertNull(workflow.getNextStatusLabel("INTEGRATION"));
        assertNull(workflow.getNextStatusLabel("UNKNOWN_STATUS_LABEL"));
    }

    @Test
    public void testBuildWorkflowThreeElements() {
        Workflow workflow = new Workflow("TEST_WORKFLOW_THREE_ELEMENTS", Arrays.asList("BUILD", "INTEGRATION", "RELEASE"));
        assertEquals("TEST_WORKFLOW_THREE_ELEMENTS", workflow.getName());
        assertEquals("RELEASE", workflow.getLatestPromotedStatus());
        assertEquals("INTEGRATION", workflow.getNextStatusLabel("build"));
        assertEquals("INTEGRATION", workflow.getNextStatusLabel("BUILD"));
        assertEquals("RELEASE", workflow.getNextStatusLabel("integration"));
        assertEquals("RELEASE", workflow.getNextStatusLabel("INTEGRATION"));
        assertNull(workflow.getNextStatusLabel("release"));
        assertNull(workflow.getNextStatusLabel("RELEASE"));
        assertNull(workflow.getNextStatusLabel("UNKNOWN_STATUS_LABEL"));
    }
}

@@ -465,24 +465,34 @@
 l));%0A    %7D%0A%0A
+    @Test%0A
     public v
@@ -520,20 +520,8 @@
 tus(
-String label
 ) %7B%0A
@@ -1041,17 +1041,16 @@
 %0A    %7D%0A%0A
-%0A
     @Tes

Add unit test