From 3b5a39c3a992ed1b2778cc08dfdd7033ef7ff44c Mon Sep 17 00:00:00 2001 From: crazzyghost Date: Wed, 23 Oct 2019 19:56:27 +0000 Subject: [PATCH] add time series tests --- META-INF/MANIFEST.MF | 2 + .../exchangerate/ExchangeRate.java | 13 +- src/test/java/TestTimeSeries.java | 136 ++++++++++++++++++ 3 files changed, 145 insertions(+), 6 deletions(-) create mode 100644 META-INF/MANIFEST.MF create mode 100644 src/test/java/TestTimeSeries.java diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF new file mode 100644 index 0000000..59499bc --- /dev/null +++ b/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/src/main/java/com/crazzyghost/alphavantage/exchangerate/ExchangeRate.java b/src/main/java/com/crazzyghost/alphavantage/exchangerate/ExchangeRate.java index 9cec7a6..badf489 100644 --- a/src/main/java/com/crazzyghost/alphavantage/exchangerate/ExchangeRate.java +++ b/src/main/java/com/crazzyghost/alphavantage/exchangerate/ExchangeRate.java @@ -1,22 +1,23 @@ package com.crazzyghost.alphavantage.exchangerate; +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.Map; +import java.util.concurrent.TimeUnit; + import com.crazzyghost.alphavantage.AlphaVantageException; -import com.crazzyghost.alphavantage.Fetcher; import com.crazzyghost.alphavantage.Config; +import com.crazzyghost.alphavantage.Fetcher; import com.crazzyghost.alphavantage.UrlExtractor; import com.squareup.moshi.JsonAdapter; import com.squareup.moshi.Moshi; import com.squareup.moshi.Types; + import okhttp3.Call; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; -import java.io.IOException; -import java.lang.reflect.Type; -import java.util.Map; -import java.util.concurrent.TimeUnit; - public class ExchangeRate implements Fetcher { private Config config; diff --git a/src/test/java/TestTimeSeries.java b/src/test/java/TestTimeSeries.java new file mode 100644 index 0000000..465633c --- /dev/null +++ b/src/test/java/TestTimeSeries.java @@ -0,0 +1,136 @@ +import com.crazzyghost.alphavantage.AlphaVantage; +import com.crazzyghost.alphavantage.Config; +import com.crazzyghost.alphavantage.Fetcher; +import com.crazzyghost.alphavantage.parameters.OutputSize; +import com.crazzyghost.alphavantage.timeseries.response.TimeSeriesResponse; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + + +public class TestTimeSeries { + + private CountDownLatch lock = new CountDownLatch(1); + + @BeforeClass + public static void setUp(){ + + Config config = Config.builder() + .key("M77PQNYAVBG0MB5N") + .timeOut(10) + .build(); + + AlphaVantage.api().init(config); + + } + + @AfterClass + public static void tearDown(){ + + } + + @Test + public void timeSeriesDaily() throws InterruptedException { + + AtomicReference response = new AtomicReference<>(); + + Fetcher.FailureCallback failureCallback = (e) -> lock.countDown(); + + Fetcher.SuccessCallback successCallback = (e) -> { + lock.countDown(); + response.set(e); + }; + + AlphaVantage.api() + .timeSeries() + .daily() + .forSymbol("GOOGL") + .outputSize(OutputSize.COMPACT) + .onFailure(failureCallback) + .onSuccess(successCallback) + .fetch(); + + lock.await(10, TimeUnit.SECONDS); + assertNotNull(response.get()); + } + + @Test + public void timeSeriesDailyAdjusted() throws InterruptedException { + + AtomicReference response = new AtomicReference<>(); + + Fetcher.FailureCallback failureCallback = (e) -> lock.countDown(); + + Fetcher.SuccessCallback successCallback = (e) -> { + lock.countDown(); + response.set(e); + }; + + AlphaVantage.api() + .timeSeries() + .daily() + .adjusted() + .forSymbol("GOOGL") + .outputSize(OutputSize.COMPACT) + .onFailure(failureCallback) + .onSuccess(successCallback) + .fetch(); + + lock.await(10, TimeUnit.SECONDS); + assertNotNull(response.get()); + } + + @Test + public void timeSeriesWeekly() throws InterruptedException { + + AtomicReference response = new AtomicReference<>(); + + Fetcher.FailureCallback failureCallback = (e) -> lock.countDown(); + + Fetcher.SuccessCallback successCallback = (e) -> { + lock.countDown(); + response.set(e); + }; + + AlphaVantage.api() + .timeSeries() + .weekly() + .forSymbol("GOOGL") + .onFailure(failureCallback) + .onSuccess(successCallback) + .fetch(); + + lock.await(10, TimeUnit.SECONDS); + assertNotNull(response.get()); + } + + @Test + public void timeSeriesWeeklyAdjusted() throws InterruptedException { + + AtomicReference response = new AtomicReference<>(); + + Fetcher.FailureCallback failureCallback = (e) -> lock.countDown(); + + Fetcher.SuccessCallback successCallback = (e) -> { + lock.countDown(); + response.set(e); + }; + + AlphaVantage.api() + .timeSeries() + .weekly() + .adjusted() + .forSymbol("GOOGL") + .onFailure(failureCallback) + .onSuccess(successCallback) + .fetch(); + + lock.await(10, TimeUnit.SECONDS); + assertNotNull(response.get()); + } +}