Skip to content

Commit

Permalink
add time series tests
Browse files Browse the repository at this point in the history
  • Loading branch information
crazzyghost committed Oct 23, 2019
1 parent c3d4be1 commit 3b5a39c
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 6 deletions.
2 changes: 2 additions & 0 deletions META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Manifest-Version: 1.0

Original file line number Diff line number Diff line change
@@ -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;
Expand Down
136 changes: 136 additions & 0 deletions src/test/java/TestTimeSeries.java
Original file line number Diff line number Diff line change
@@ -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<TimeSeriesResponse> response = new AtomicReference<>();

Fetcher.FailureCallback failureCallback = (e) -> lock.countDown();

Fetcher.SuccessCallback<TimeSeriesResponse> 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<TimeSeriesResponse> response = new AtomicReference<>();

Fetcher.FailureCallback failureCallback = (e) -> lock.countDown();

Fetcher.SuccessCallback<TimeSeriesResponse> 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<TimeSeriesResponse> response = new AtomicReference<>();

Fetcher.FailureCallback failureCallback = (e) -> lock.countDown();

Fetcher.SuccessCallback<TimeSeriesResponse> 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<TimeSeriesResponse> response = new AtomicReference<>();

Fetcher.FailureCallback failureCallback = (e) -> lock.countDown();

Fetcher.SuccessCallback<TimeSeriesResponse> 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());
}
}

0 comments on commit 3b5a39c

Please sign in to comment.