aboutsummaryrefslogtreecommitdiffstats
path: root/container-core/src/test/java/com/yahoo/processing/test/ProcessingTestCase.java
blob: 96d8191a86889bc42238862908d15f1a12044bec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.processing.test;

import com.yahoo.component.chain.Chain;
import com.yahoo.processing.Processor;
import com.yahoo.processing.Request;
import com.yahoo.processing.Response;
import com.yahoo.processing.execution.Execution;
import org.junit.jupiter.api.Test;

import static com.yahoo.processing.test.ProcessorLibrary.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * Tests the basic of the processing framework
 */
public class ProcessingTestCase {

    /** Execute three simple processors doing some phony processing */
    @Test
    void testChainedProcessing1() {
        // Create a chain
        Chain<Processor> chain = new Chain<>(new CombineData(), new Get6DataItems(), new DataSource());

        // Execute it
        Request request = new Request();
        request.properties().set("appendage", 1);
        Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request);

        // Verify the result
        assertEquals(6 - 1, response.data().asList().size());
        assertEquals("first.2, third.2", response.data().get(0).toString());
        assertEquals("second.2", response.data().get(1).toString());
        assertEquals("first.3", response.data().get(2).toString());
        assertEquals("second.3", response.data().get(3).toString());
        assertEquals("third.3", response.data().get(4).toString());
    }

    /** Execute the same processors in a different order */
    @Test
    void testChainedProcessing2() {
        // Create a chain
        Chain<Processor> chain = new Chain<>(new Get6DataItems(), new CombineData(), new DataSource());

        // Execute it
        Request request = new Request();
        request.properties().set("appendage", 1);
        Response response = Execution.createRoot(chain, 0, Execution.Environment.createEmpty()).process(request);

        // Check the result
        assertEquals(6, response.data().asList().size());
        assertEquals("first.2, third.2", response.data().get(0).toString());
        assertEquals("second.2", response.data().get(1).toString());
        assertEquals("first.4, third.4", response.data().get(2).toString());
        assertEquals("second.4", response.data().get(3).toString());
        assertEquals("first.6, third.6", response.data().get(4).toString());
        assertEquals("second.6", response.data().get(5).toString());
    }

}