<commit_before>package de.hpi.bpt.chimera.jcore;

//import com.ibatis.common.jdbc.ScriptRunner;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import de.hpi.bpt.chimera.AbstractDatabaseDependentTest;
import de.hpi.bpt.chimera.ScenarioTestHelper;

import de.hpi.bpt.chimera.jcore.data.DataAttributeInstance;
import de.hpi.bpt.chimera.jcore.data.DataManager;
import org.apache.commons.io.FileUtils;
import org.junit.*;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Collection;

import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;



/**
 * This class extends JerseyTest, because it's need the Rest Interface to check the Webservice Task functions.
 * The GET, PUT and POST Requests are send to the Rest Interface.
 */
public class WebServiceAcceptanceTest  {

    String json;

    @Rule
    public WireMockRule wireMockRule = new WireMockRule(8089);

    @After
    public void resetDatabase() throws IOException, SQLException {
        AbstractDatabaseDependentTest.resetDatabase();
    }

    @Before
    public void setUp() throws IOException {
        String path ="src/test/resources/json/jsonPathExample.json";
        json = FileUtils.readFileToString(new File(path));
    }

    @Test
    public void testWebServiceIntegrationGet() throws IOException {
        stubFor(get(urlEqualTo("/my/resource"))
                .willReturn(aResponse()
                        .withStatus(200)
                        .withHeader("Content-Type", "application/json")
                        .withBody(json)));

        ScenarioInstance instance = ScenarioTestHelper.createScenarioInstance(
                "src/test/resources/Scenarios/JsonPathWebserviceScenarioGet.json");
        DataManager manager = instance.getDataManager();
        Collection<DataAttributeInstance> dataAttributes =
                manager.getDataAttributeInstances();
        assertDataAttributeInstancesEmpty(dataAttributes);
        // Terminating the manual task starts the automatic task
        ScenarioTestHelper.executeActivityByName("ManualTask", instance);
        dataAttributes = manager.getDataAttributeInstances();
        assertDataAttributeInstanceHasValue(dataAttributes);
    }

    @Test
    public void testWebServiceIntegrationPost() throws IOException {
        stubFor(post(urlEqualTo("/my/resource"))
                .withHeader("Accept", matching("application/json"))
                .willReturn(aResponse()
                        .withStatus(200)
                        .withHeader("Content-Type", "application/json")
                        .withBody(json)));

        ScenarioInstance instance = ScenarioTestHelper.createScenarioInstance(
                "src/test/resources/Scenarios/JsonPathWebserviceScenarioPost.json");
        DataManager manager = instance.getDataManager();
        Collection<DataAttributeInstance> dataAttributes =
                manager.getDataAttributeInstances();
        assertDataAttributeInstancesEmpty(dataAttributes);
        ScenarioTestHelper.executeActivityByName("ManualTask", instance);
        dataAttributes = manager.getDataAttributeInstances();
        assertDataAttributeInstanceHasValue(dataAttributes);
    }

    private void assertDataAttributeInstancesEmpty(Collection<DataAttributeInstance> dataAttributes) {
        // Before executing the webservice task none of the data attributes has a value
        for (DataAttributeInstance dataAttribute : dataAttributes) {
            assertEquals("",  dataAttribute.getValue());
        }
    }

    private void assertDataAttributeInstanceHasValue(Collection<DataAttributeInstance> dataAttributes) {
        long amountOfDataAttributesWithValues = dataAttributes.stream().filter(x -> "foo".equals(x.getValue())).count();
        assertEquals(1L, amountOfDataAttributesWithValues);
    }
}<commit_msg>add comment for test purpose<commit_after>package de.hpi.bpt.chimera.jcore;

//import com.ibatis.common.jdbc.ScriptRunner;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import de.hpi.bpt.chimera.AbstractDatabaseDependentTest;
import de.hpi.bpt.chimera.ScenarioTestHelper;

import de.hpi.bpt.chimera.jcore.data.DataAttributeInstance;
import de.hpi.bpt.chimera.jcore.data.DataManager;
import org.apache.commons.io.FileUtils;
import org.junit.*;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Collection;

import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;



/**
 * This class extends JerseyTest, because it's need the Rest Interface to check the Webservice Task functions.
 * The GET, PUT and POST Requests are send to the Rest Interface.
 */
/*
 * In addition the test checks whether an Webservice Task with multiple data
 * objects runs automatically. The Webservice Task should execute without the
 * users decision which data object shall be used by the Webservice Task.
 */
public class WebServiceAcceptanceTest  {

    String json;

    @Rule
    public WireMockRule wireMockRule = new WireMockRule(8089);

    @After
    public void resetDatabase() throws IOException, SQLException {
        AbstractDatabaseDependentTest.resetDatabase();
    }

    @Before
    public void setUp() throws IOException {
        String path ="src/test/resources/json/jsonPathExample.json";
        json = FileUtils.readFileToString(new File(path));
    }

    @Test
    public void testWebServiceIntegrationGet() throws IOException {
        stubFor(get(urlEqualTo("/my/resource"))
                .willReturn(aResponse()
                        .withStatus(200)
                        .withHeader("Content-Type", "application/json")
                        .withBody(json)));

        ScenarioInstance instance = ScenarioTestHelper.createScenarioInstance(
                "src/test/resources/Scenarios/JsonPathWebserviceScenarioGet.json");
        DataManager manager = instance.getDataManager();
        Collection<DataAttributeInstance> dataAttributes =
                manager.getDataAttributeInstances();
        assertDataAttributeInstancesEmpty(dataAttributes);
        // Terminating the manual task starts the automatic task
        ScenarioTestHelper.executeActivityByName("ManualTask", instance);
        dataAttributes = manager.getDataAttributeInstances();
        assertDataAttributeInstanceHasValue(dataAttributes);
    }

    @Test
    public void testWebServiceIntegrationPost() throws IOException {
        stubFor(post(urlEqualTo("/my/resource"))
                .withHeader("Accept", matching("application/json"))
                .willReturn(aResponse()
                        .withStatus(200)
                        .withHeader("Content-Type", "application/json")
                        .withBody(json)));

        ScenarioInstance instance = ScenarioTestHelper.createScenarioInstance(
                "src/test/resources/Scenarios/JsonPathWebserviceScenarioPost.json");
        DataManager manager = instance.getDataManager();
        Collection<DataAttributeInstance> dataAttributes =
                manager.getDataAttributeInstances();
        assertDataAttributeInstancesEmpty(dataAttributes);
        ScenarioTestHelper.executeActivityByName("ManualTask", instance);
        dataAttributes = manager.getDataAttributeInstances();
        assertDataAttributeInstanceHasValue(dataAttributes);
    }

    private void assertDataAttributeInstancesEmpty(Collection<DataAttributeInstance> dataAttributes) {
        // Before executing the webservice task none of the data attributes has a value
        for (DataAttributeInstance dataAttribute : dataAttributes) {
            assertEquals("",  dataAttribute.getValue());
        }
    }

    private void assertDataAttributeInstanceHasValue(Collection<DataAttributeInstance> dataAttributes) {
		long amountOfDataAttributesWithValues = dataAttributes.stream().filter(x -> "foo".equals(x.getValue())).count();
        assertEquals(1L, amountOfDataAttributesWithValues);
    }
}
{'fraction_non_alphanumeric': 0.08846200905420286, 'fraction_numerical': 0.0026917900403768506, 'mean_word_length': 3.3617929562433297, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6000869', 'n_tokens_mistral': 2081, 'n_tokens_neox': 2022, 'n_words': 424}