

package com.consol.citrus.dsl.runner;

import com.consol.citrus.TestCase;
import com.consol.citrus.actions.EchoAction;
import com.consol.citrus.container.Parallel;
import com.consol.citrus.testng.AbstractTestNGUnitTest;
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;

public class ParallelTestRunnerTest extends AbstractTestNGUnitTest {
    @Test
    public void testParallelBuilder() {
        MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {
            @Override
            public void execute() {
                variable("var", "foo");

                parallel()
                    .actions(
                            echo("${var}"),
                            sleep(200),
                            echo("Hello World!")
                    );
            }
        };

        TestCase test = builder.getTestCase();
        assertEquals(test.getActionCount(), 1);
        assertEquals(test.getActions().get(0).getClass(), Parallel.class);
        assertEquals(test.getActions().get(0).getName(), "parallel");
        
        Parallel container = (Parallel)test.getActions().get(0);
        assertEquals(container.getActionCount(), 3);
        assertEquals(container.getTestAction(0).getClass(), EchoAction.class);
    }

    @Test
    public void testParallelBuilderNestedContainer() {
        MockTestRunner builder = new MockTestRunner(getClass().getSimpleName(), applicationContext, context) {
            @Override
            public void execute() {
                variable("var", "foo");

                parallel()
                    .actions(
                        echo("${var}"),
                        sequential()
                            .actions(
                                echo("1st in sequential"),
                                echo("2nd in sequential")
                            ),
                        sleep(200),
                        echo("Hello World!")
                    );
            }
        };

        TestCase test = builder.getTestCase();
        assertEquals(test.getActionCount(), 1);
        assertEquals(test.getActions().get(0).getClass(), Parallel.class);
        assertEquals(test.getActions().get(0).getName(), "parallel");

        Parallel container = (Parallel)test.getActions().get(0);
        assertEquals(container.getActionCount(), 4);
        assertEquals(container.getTestAction(0).getClass(), EchoAction.class);
    }
}
