<commit_before>/**
 * 
 */
package org.carrot2.core.controller;

import static org.easymock.EasyMock.createStrictControl;
import static org.junit.Assert.assertEquals;

import java.util.HashMap;
import java.util.Map;

import org.carrot2.core.*;
import org.carrot2.core.parameter.*;
import org.easymock.IMocksControl;
import org.junit.*;

/**
 *
 */
public class SimpleControllerTest
{
    private IMocksControl mocksControl;

    private ProcessingComponent processingComponent1Mock;
    private ProcessingComponent processingComponent2Mock;
    private ProcessingComponent processingComponent3Mock;

    private SimpleController controller;

    private Map<String, Object> parameters;
    private Map<String, Object> attributes;

    @Bindable
    public static class ProcessingComponent1 extends DelegatingProcessingComponent
    {
        @Parameter(policy = BindingPolicy.INSTANTIATION, key = "delegate1")
        private ProcessingComponent delegate1;

        @Override
        ProcessingComponent getDelegate()
        {
            return delegate1;
        }
    }

    @Bindable
    public static class ProcessingComponent2 extends DelegatingProcessingComponent
    {
        @Parameter(policy = BindingPolicy.INSTANTIATION, key = "delegate2")
        private ProcessingComponent delegate2;

        @Override
        ProcessingComponent getDelegate()
        {
            return delegate2;
        }
    }

    @Bindable
    public static class ProcessingComponent3 extends DelegatingProcessingComponent
    {
        @Parameter(policy = BindingPolicy.INSTANTIATION, key = "delegate3")
        private ProcessingComponent delegate3;

        @Override
        ProcessingComponent getDelegate()
        {
            return delegate3;
        }
    }

    @Bindable
    public static class ProcessingComponentWithoutDefaultConstructor extends
        ProcessingComponentBase
    {
        private ProcessingComponentWithoutDefaultConstructor()
        {
        }
    }

    @Before
    public void init()
    {
        mocksControl = createStrictControl();

        processingComponent1Mock = mocksControl.createMock(DocumentSource.class);
        processingComponent2Mock = mocksControl.createMock(DocumentSource.class);
        processingComponent3Mock = mocksControl.createMock(DocumentSource.class);

        parameters = new HashMap<String, Object>();
        parameters.put("delegate1", processingComponent1Mock);
        parameters.put("delegate2", processingComponent2Mock);
        parameters.put("delegate3", processingComponent3Mock);

        attributes = new HashMap<String, Object>();

        controller = new SimpleController();
    }

    @After
    public void verifyMocks()
    {
        mocksControl.verify();
    }

    @Test
    public void testNormalExecution1Component()
    {
        processingComponent1Mock.init();
        processingComponent1Mock.beforeProcessing();
        processingComponent1Mock.performProcessing();
        processingComponent1Mock.afterProcessing();
        processingComponent1Mock.dispose();

        mocksControl.replay();

        parameters.put("instanceParameter", "i");
        parameters.put("runtimeParameter", "r");

        attributes.put("data", "d");

        controller.process(parameters, attributes, ProcessingComponent1.class);

        mocksControl.verify();

        assertEquals("dir", attributes.get("data"));
    }

    @Test
    public void testNormalExecution3Components()
    {
        processingComponent1Mock.init();
        processingComponent2Mock.init();
        processingComponent3Mock.init();

        processingComponent1Mock.beforeProcessing();
        processingComponent2Mock.beforeProcessing();
        processingComponent3Mock.beforeProcessing();

        processingComponent1Mock.performProcessing();
        processingComponent2Mock.performProcessing();
        processingComponent3Mock.performProcessing();

        processingComponent1Mock.afterProcessing();
        processingComponent2Mock.afterProcessing();
        processingComponent3Mock.afterProcessing();

        processingComponent1Mock.dispose();
        processingComponent2Mock.dispose();
        processingComponent3Mock.dispose();

        mocksControl.replay();

        parameters.put("instanceParameter", "i");
        parameters.put("runtimeParameter", "r");

        attributes.put("data", "d");

        controller.process(parameters, attributes, ProcessingComponent1.class,
            ProcessingComponent2.class, ProcessingComponent3.class);

        assertEquals("diririr", attributes.get("data"));
    }

    @Test(expected = ProcessingException.class)
    public void testExceptionWhileCreatingInstances()
    {
        mocksControl.replay();

        controller.process(parameters, attributes, ProcessingComponent1.class,
            ProcessingComponentWithoutDefaultConstructor.class);
    }

    @Test(expected = InitializationException.class)
    public void testExceptionWhileInit()
    {<commit_msg>Three tests fail.<commit_after>/**
 * 
 */
package org.carrot2.core.controller;

import static org.easymock.EasyMock.createStrictControl;
import static org.junit.Assert.assertEquals;

import java.util.HashMap;
import java.util.Map;

import org.carrot2.core.*;
import org.carrot2.core.parameter.*;
import org.easymock.IMocksControl;
import org.junit.*;

/**
 *
 */
public class SimpleControllerTest
{
    private IMocksControl mocksControl;

    private ProcessingComponent processingComponent1Mock;
    private ProcessingComponent processingComponent2Mock;
    private ProcessingComponent processingComponent3Mock;

    private SimpleController controller;

    private Map<String, Object> parameters;
    private Map<String, Object> attributes;

    @Bindable
    public static class ProcessingComponent1 extends DelegatingProcessingComponent
    {
        @Parameter(policy = BindingPolicy.INSTANTIATION, key = "delegate1")
        private ProcessingComponent delegate1;

        @Override
        ProcessingComponent getDelegate()
        {
            return delegate1;
        }
    }

    @Bindable
    public static class ProcessingComponent2 extends DelegatingProcessingComponent
    {
        @Parameter(policy = BindingPolicy.INSTANTIATION, key = "delegate2")
        private ProcessingComponent delegate2;

        @Override
        ProcessingComponent getDelegate()
        {
            return delegate2;
        }
    }

    @Bindable
    public static class ProcessingComponent3 extends DelegatingProcessingComponent
    {
        @Parameter(policy = BindingPolicy.INSTANTIATION, key = "delegate3")
        private ProcessingComponent delegate3;

        @Override
        ProcessingComponent getDelegate()
        {
            return delegate3;
        }
    }

    @Bindable
    public static class ProcessingComponentWithoutDefaultConstructor extends
        ProcessingComponentBase
    {
        private ProcessingComponentWithoutDefaultConstructor()
        {
        }
    }

    @Before
    public void init()
    {
        mocksControl = createStrictControl();

        processingComponent1Mock = mocksControl.createMock(DocumentSource.class);
        processingComponent2Mock = mocksControl.createMock(DocumentSource.class);
        processingComponent3Mock = mocksControl.createMock(DocumentSource.class);

        parameters = new HashMap<String, Object>();
        parameters.put("delegate1", processingComponent1Mock);
        parameters.put("delegate2", processingComponent2Mock);
        parameters.put("delegate3", processingComponent3Mock);

        attributes = new HashMap<String, Object>();

        controller = new SimpleController();
    }

    @After
    public void verifyMocks()
    {
        mocksControl.verify();
    }

    @Test
    public void testNormalExecution1Component()
    {
        processingComponent1Mock.init();
        processingComponent1Mock.beforeProcessing();
        processingComponent1Mock.performProcessing();
        processingComponent1Mock.afterProcessing();
        processingComponent1Mock.dispose();

        mocksControl.replay();

        parameters.put("instanceParameter", "i");
        parameters.put("runtimeParameter", "r");

        attributes.put("data", "d");

        controller.process(parameters, attributes, ProcessingComponent1.class);

        mocksControl.verify();

        assertEquals("dir", attributes.get("data"));
    }

    @Test
    public void testNormalExecution3Components()
    {
        processingComponent1Mock.init();
        processingComponent2Mock.init();
        processingComponent3Mock.init();

        processingComponent1Mock.beforeProcessing();
        processingComponent2Mock.beforeProcessing();
        processingComponent3Mock.beforeProcessing();

        processingComponent1Mock.performProcessing();
        processingComponent2Mock.performProcessing();
        processingComponent3Mock.performProcessing();

        processingComponent1Mock.afterProcessing();
        processingComponent2Mock.afterProcessing();
        processingComponent3Mock.afterProcessing();

        processingComponent1Mock.dispose();
        processingComponent2Mock.dispose();
        processingComponent3Mock.dispose();

        mocksControl.replay();

        parameters.put("instanceParameter", "i");
        parameters.put("runtimeParameter", "r");

        attributes.put("data", "d");

        controller.process(parameters, attributes, ProcessingComponent1.class,
            ProcessingComponent2.class, ProcessingComponent3.class);

        assertEquals("diririr", attributes.get("data"));
    }

    @Test(expected = ProcessingException.class)
    public void testExceptionWhileCreatingInstances()
    {
        mocksControl.replay();

        controller.process(parameters, attributes, ProcessingComponent1.class,
            ProcessingComponentWithoutDefaultConstructor.class);
    }

    // TODO: The tests below fail for me. Is there anything special
    // about them?
    
    @Test(expected = InitializationException.class)
    public void testExceptionWhileInit()
    {
{'fraction_non_alphanumeric': 0.08619662363455809, 'fraction_numerical': 0.010724925521350546, 'mean_word_length': 3.1979991663193, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2408071', 'n_tokens_mistral': 2447, 'n_tokens_neox': 2316, 'n_words': 449}