package com.googlecode.jmeter.plugins.webdriver.sampler.gui;

import com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler;
import kg.apc.emulators.TestJMeterUtils;
import org.apache.jmeter.gui.JMeterGUIComponent;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

public class WebDriverSamplerGuiTest {

    private WebDriverSamplerGui gui;

    @BeforeClass
    public static void setupJMeterEnv() {
        TestJMeterUtils.createJmeterEnv();
    }

    @Before
    public void createGui() {
        gui = new WebDriverSamplerGui();
    }

    @Test
    public void shouldImplementJMeterGUIComponent() {
        assertThat(gui, is(CoreMatchers.instanceOf(JMeterGUIComponent.class)));
    }

    @Test
    public void shouldReturnStaticLabel() {
        assertThat(gui.getStaticLabel(), containsString("Web Driver Sampler"));
    }

    @Test
    public void shouldReturnCanonicalClassNameAsLabelResource() {
        assertThat(gui.getLabelResource(), is(gui.getClass().getCanonicalName()));
    }

    @Test
    public void shouldSetParameters() {
        gui.parameters.setText("parameter1 parameter2");
        final WebDriverSampler testElement = (WebDriverSampler) gui.createTestElement();
        assertThat(testElement.getParameters(), is("parameter1 parameter2"));
    }

    @Test
    public void shouldSetScript() {
        gui.script.setText("some script");
        final WebDriverSampler testElement = (WebDriverSampler) gui.createTestElement();
        assertThat(testElement.getScript(), is("some script"));
    }

    @Test
    public void shouldResetValuesOnClearGui() {
        gui.script.setText("script");
        gui.parameters.setText("p1 p2");

        gui.clearGui();

        assertThat(gui.script.getText(), is(""));
        assertThat(gui.parameters.getText(), is(""));
    }

    @Test
    public void shouldSetValuesOnConfigure() {
        WebDriverSampler sampler = new WebDriverSampler();
        sampler.setParameters("param1 param2");
        sampler.setScript("var script;");

        gui.configure(sampler);

        assertThat(gui.script.getText(), is(sampler.getScript()));
        assertThat(gui.parameters.getText(), is(sampler.getParameters()));
    }
}

@@ -431,16 +431,64 @@
 ers.is;%0A
+import static org.junit.Assert.assertNotEquals;%0A
 import s
@@ -1957,36 +1957,41 @@
 %0A%0A        assert
-That
+NotEquals
 (gui.script.getT
@@ -1993,31 +1993,27 @@
 .getText(), 
-is(
 %22%22)
-)
 ;%0A        as

fix test