<commit_before>package be.wegenenverkeer.atomium.japi.client;

import be.wegenenverkeer.atomium.japi.format.Entry;
import be.wegenenverkeer.rxhttp.HttpServerError;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.common.SingleRootFileSource;
import com.github.tomakehurst.wiremock.junit.WireMockClassRule;
import org.junit.*;
import rx.Observable;
import rx.Subscription;
import rx.observers.TestSubscriber;

import javax.xml.bind.annotation.*;
import java.util.concurrent.TimeUnit;

import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static com.github.tomakehurst.wiremock.client.WireMock.*;

import static org.junit.Assert.assertEquals;

/**
 * Created by <NAME>, Geovise BVBA on 16/03/15.
 */
public class FunctionalTest {

    private final static SingleRootFileSource WIREMOCK_MAPPINGS = new SingleRootFileSource
            ("modules/client-java/src/test/resources/basis-scenario");

    @ClassRule
    public static WireMockClassRule wireMockRule = new WireMockClassRule(
            wireMockConfig().fileSource(WIREMOCK_MAPPINGS)
    );

    @Rule
    public WireMockClassRule instanceRule = wireMockRule;

    AtomiumClient client;

    @Before
    public void before(){
        client = new AtomiumClient.Builder()
                .setBaseUrl("http://localhost:8080/")
                .setAcceptXml()
                .build();

        //reset WireMock so it will serve the events feed
        WireMock.resetToDefault();
    }

    @After
    public void after() {
        client.close();
    }



    @Test
    public void testSubscribingToObservable(){
        Observable<Entry<Event>> observable = client.feed("/feeds/events", Event.class).observeSince("urn:uuid:8641f2fd-e8dc-4756-acf2-3b708080ea3a", "20/forward/10", 1000);


        TestSubscriber<Entry<Event>> subscriber = new TestSubscriber<>();

        observable.take(1000).subscribe(subscriber);

        subscriber.awaitTerminalEvent(3, TimeUnit.SECONDS);

        subscriber.assertNoErrors();

        //we should have received exactly 1000 events.
        assertEquals(1000, subscriber.getOnNextEvents().size());

        //we should have received exactly 1 onComplete
        assertEquals(1, subscriber.getOnCompletedEvents().size());

    }

    @Test
    public void testReceivingAnError(){
        stubFor(get(urlEqualTo("/fault"))
                .willReturn(aResponse().withStatus(500)));

        Observable<Entry<Event>> observable = client.feed("/fault", Event.class).observe(100);

        TestSubscriber<Entry<Event>> subscriber = new TestSubscriber<>();

        observable.subscribe(subscriber);

        subscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);

        assertEquals(0, subscriber.getOnNextEvents().size());
        assertEquals(1, subscriber.getOnErrorEvents().size());

        assertEquals(HttpServerError.class, subscriber.getOnErrorEvents().get(0).getClass());

    }

    @Test
    public void testUnSubscribingFromObservable() throws InterruptedException {
<commit_msg>Smaller functional tests for Java client.<commit_after>package be.wegenenverkeer.atomium.japi.client;

import be.wegenenverkeer.atomium.japi.format.Entry;
import be.wegenenverkeer.rxhttp.HttpServerError;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.common.SingleRootFileSource;
import com.github.tomakehurst.wiremock.junit.WireMockClassRule;
import org.junit.*;
import rx.Observable;
import rx.Subscription;
import rx.observers.TestSubscriber;

import javax.xml.bind.annotation.*;
import java.util.concurrent.TimeUnit;

import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static com.github.tomakehurst.wiremock.client.WireMock.*;

import static org.junit.Assert.assertEquals;

/**
 * Created by <NAME>, Geovise BVBA on 16/03/15.
 */
public class FunctionalTest {

    private final static SingleRootFileSource WIREMOCK_MAPPINGS = new SingleRootFileSource
            ("modules/client-java/src/test/resources/basis-scenario");

    @ClassRule
    public static WireMockClassRule wireMockRule = new WireMockClassRule(
            wireMockConfig().fileSource(WIREMOCK_MAPPINGS)
    );

    @Rule
    public WireMockClassRule instanceRule = wireMockRule;

    AtomiumClient client;

    @Before
    public void before(){
        client = new AtomiumClient.Builder()
                .setBaseUrl("http://localhost:8080/")
                .setAcceptXml()
                .build();

        //reset WireMock so it will serve the events feed
        WireMock.resetToDefault();
    }

    @After
    public void after() {
        client.close();
    }



    @Test
    public void testSubscribingToObservable(){
        Observable<Entry<Event>> observable = client.feed("/feeds/events", Event.class).observeSince("urn:uuid:8641f2fd-e8dc-4756-acf2-3b708080ea3a", "20/forward/10", 1000);


        TestSubscriber<Entry<Event>> subscriber = new TestSubscriber<>();

        observable.take(20).subscribe(subscriber);

        subscriber.awaitTerminalEvent(3, TimeUnit.SECONDS);

        subscriber.assertNoErrors();

        //we should have received exactly 1000 events.
        assertEquals(20, subscriber.getOnNextEvents().size());

        //we should have received exactly 1 onComplete
        assertEquals(1, subscriber.getOnCompletedEvents().size());

    }

    @Test
    public void testReceivingAnError(){
        stubFor(get(urlEqualTo("/fault"))
                .willReturn(aResponse().withStatus(500)));

        Observable<Entry<Event>> observable = client.feed("/fault", Event.class).observe(100);

        TestSubscriber<Entry<Event>> subscriber = new TestSubscriber<>();

        observable.subscribe(subscriber);

        subscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);

        assertEquals(0, subscriber.getOnNextEvents().size());
        assertEquals(1, subscriber.getOnErrorEvents().size());

        assertEquals(HttpServerError.class, subscriber.getOnErrorEvents().get(0).getClass());

    }

    @Test
    public void testUnSubscribingFromObservable() throws InterruptedException {

{'fraction_non_alphanumeric': 0.11185064935064935, 'fraction_numerical': 0.01948051948051948, 'mean_word_length': 3.5670867309117864, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '7396369', 'n_tokens_mistral': 1893, 'n_tokens_neox': 1730, 'n_words': 317}