aboutsummaryrefslogtreecommitdiffstats
path: root/container-core/src/test/java/com/yahoo/processing/test/DocumentationTestCase.java
blob: 8716b858696df88b10c1d1e81b29ab85bd66e8d3 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.processing.test;

import org.junit.jupiter.api.Test;
import com.yahoo.component.chain.Chain;

import static org.junit.jupiter.api.Assertions.assertEquals;
import com.yahoo.processing.Processor;
import com.yahoo.processing.Request;
import com.yahoo.processing.Response;
import com.yahoo.processing.execution.Execution;
import com.yahoo.processing.test.documentation.AsyncDataProcessingInitiator;
import com.yahoo.processing.test.documentation.AsyncDataProducer;
import com.yahoo.processing.test.documentation.ExampleProcessor;
import com.yahoo.processing.test.documentation.Federator;

/**
 * See to it we can actually run the examples in the doc.
 *
 * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
 */
public class DocumentationTestCase {

    @SuppressWarnings("unchecked")
    @Test
    final void test() {
        Processor p = new ExampleProcessor();
        Chain<Processor> basic = new Chain<>(p);
        Processor initiator = new AsyncDataProcessingInitiator(basic);
        Chain<Processor> postProcessing = new Chain<>(initiator);
        Execution e = Execution.createRoot(postProcessing, 0, Execution.Environment.createEmpty());
        Response r = e.process(new Request());
        // just adds a listener to the result returned from basic
        assertEquals(0, r.data().asList().size());
        Processor producer = new AsyncDataProducer();
        Chain<Processor> asyncChain = new Chain<>(producer);
        Processor federator = new Federator(basic, asyncChain);
        e = Execution.createRoot(federator, 0, Execution.Environment.createEmpty());
        r = e.process(new Request());
        assertEquals(2, r.data().asList().size());
    }

}