diff --git a/.gitignore b/.gitignore index 6b15ed8..8dd2ceb 100644 --- a/.gitignore +++ b/.gitignore @@ -140,4 +140,5 @@ gradle .idea/ .vscode **/Main.java -bin/** \ No newline at end of file +bin/** +*.sh \ No newline at end of file diff --git a/build.gradle b/build.gradle index cfe5d9e..0be1e3c 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ test.finalizedBy jacocoTestReport dependencies { testImplementation group: 'junit', name: 'junit', version: '4.12' implementation 'com.squareup.okhttp3:okhttp:3.11.0' - implementation("com.squareup.okhttp3:logging-interceptor:4.5.0") + implementation 'com.squareup.okhttp3:logging-interceptor:4.5.0' implementation 'com.squareup.moshi:moshi:1.8.0' } diff --git a/src/main/java/com/crazzyghost/alphavantage/indicator/response/AROONResponse.java b/src/main/java/com/crazzyghost/alphavantage/indicator/response/AROONResponse.java index e49096f..cf78021 100644 --- a/src/main/java/com/crazzyghost/alphavantage/indicator/response/AROONResponse.java +++ b/src/main/java/com/crazzyghost/alphavantage/indicator/response/AROONResponse.java @@ -26,18 +26,9 @@ public String getErrorMessage() { return errorMessage; } - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - } - public List getIndicatorUnits() { return indicatorUnits; } - - public void setIndicatorUnits(List indicatorUnits) { - this.indicatorUnits = indicatorUnits; - } - public MetaData getMetaData() { return metaData; diff --git a/src/main/java/com/crazzyghost/alphavantage/indicator/response/MACDEXTResponse.java b/src/main/java/com/crazzyghost/alphavantage/indicator/response/MACDEXTResponse.java index 0229131..0e7ab37 100644 --- a/src/main/java/com/crazzyghost/alphavantage/indicator/response/MACDEXTResponse.java +++ b/src/main/java/com/crazzyghost/alphavantage/indicator/response/MACDEXTResponse.java @@ -26,18 +26,9 @@ public String getErrorMessage() { return errorMessage; } - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - } - public List getIndicatorUnits() { return indicatorUnits; } - - public void setIndicatorUnits(List indicatorUnits) { - this.indicatorUnits = indicatorUnits; - } - public MetaData getMetaData() { return metaData; @@ -190,23 +181,14 @@ public double getSignalPeriod() { return signalPeriod; } - /** - * @return the fastMaType - */ public double getFastMaType() { return fastMaType; } - /** - * @return the slowMaType - */ public double getSlowMaType() { return slowMaType; } - /** - * @return the signalMaType - */ public double getSignalMaType() { return signalMaType; } diff --git a/src/main/java/com/crazzyghost/alphavantage/indicator/response/MACDResponse.java b/src/main/java/com/crazzyghost/alphavantage/indicator/response/MACDResponse.java index e4ed6c5..bf03e5b 100644 --- a/src/main/java/com/crazzyghost/alphavantage/indicator/response/MACDResponse.java +++ b/src/main/java/com/crazzyghost/alphavantage/indicator/response/MACDResponse.java @@ -26,18 +26,9 @@ public String getErrorMessage() { return errorMessage; } - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - } - public List getIndicatorUnits() { return indicatorUnits; } - - public void setIndicatorUnits(List indicatorUnits) { - this.indicatorUnits = indicatorUnits; - } - public MetaData getMetaData() { return metaData; diff --git a/src/main/java/com/crazzyghost/alphavantage/indicator/response/MAMAResponse.java b/src/main/java/com/crazzyghost/alphavantage/indicator/response/MAMAResponse.java index d231767..6ecb9dd 100644 --- a/src/main/java/com/crazzyghost/alphavantage/indicator/response/MAMAResponse.java +++ b/src/main/java/com/crazzyghost/alphavantage/indicator/response/MAMAResponse.java @@ -25,18 +25,9 @@ public String getErrorMessage() { return errorMessage; } - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - } - public List getIndicatorUnits() { return indicatorUnits; } - - public void setIndicatorUnits(List indicatorUnits) { - this.indicatorUnits = indicatorUnits; - } - public MetaData getMetaData() { return metaData; diff --git a/src/main/java/com/crazzyghost/alphavantage/indicator/response/PeriodicResponse.java b/src/main/java/com/crazzyghost/alphavantage/indicator/response/PeriodicResponse.java index b4c4280..44aceb9 100644 --- a/src/main/java/com/crazzyghost/alphavantage/indicator/response/PeriodicResponse.java +++ b/src/main/java/com/crazzyghost/alphavantage/indicator/response/PeriodicResponse.java @@ -26,18 +26,10 @@ public String getErrorMessage() { return errorMessage; } - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - } - public List getIndicatorUnits() { return indicatorUnits; } - public void setIndicatorUnits(List indicatorUnits) { - this.indicatorUnits = indicatorUnits; - } - public MetaData getMetaData() { return metaData; diff --git a/src/main/java/com/crazzyghost/alphavantage/indicator/response/PeriodicSeriesResponse.java b/src/main/java/com/crazzyghost/alphavantage/indicator/response/PeriodicSeriesResponse.java index 37eacc1..7a5f470 100644 --- a/src/main/java/com/crazzyghost/alphavantage/indicator/response/PeriodicSeriesResponse.java +++ b/src/main/java/com/crazzyghost/alphavantage/indicator/response/PeriodicSeriesResponse.java @@ -26,17 +26,9 @@ public String getErrorMessage() { return errorMessage; } - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - } - public List getIndicatorUnits() { return indicatorUnits; } - - public void setInidcatorUnits(List indicatorUnits) { - this.indicatorUnits = indicatorUnits; - } public MetaData getMetaData() { return metaData; diff --git a/src/main/java/com/crazzyghost/alphavantage/indicator/response/PriceOscillatorResponse.java b/src/main/java/com/crazzyghost/alphavantage/indicator/response/PriceOscillatorResponse.java index 122fc7b..576c918 100644 --- a/src/main/java/com/crazzyghost/alphavantage/indicator/response/PriceOscillatorResponse.java +++ b/src/main/java/com/crazzyghost/alphavantage/indicator/response/PriceOscillatorResponse.java @@ -26,18 +26,9 @@ public String getErrorMessage() { return errorMessage; } - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - } - public List getIndicatorUnits() { return indicatorUnits; } - - public void setIndicatorUnits(List indicatorUnits) { - this.indicatorUnits = indicatorUnits; - } - public MetaData getMetaData() { return metaData; diff --git a/src/main/java/com/crazzyghost/alphavantage/indicator/response/STOCHFResponse.java b/src/main/java/com/crazzyghost/alphavantage/indicator/response/STOCHFResponse.java index 0e9cf15..4a2763a 100644 --- a/src/main/java/com/crazzyghost/alphavantage/indicator/response/STOCHFResponse.java +++ b/src/main/java/com/crazzyghost/alphavantage/indicator/response/STOCHFResponse.java @@ -26,18 +26,9 @@ public String getErrorMessage() { return errorMessage; } - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - } - public List getIndicatorUnits() { return indicatorUnits; } - - public void setIndicatorUnits(List indicatorUnits) { - this.indicatorUnits = indicatorUnits; - } - public MetaData getMetaData() { return metaData; diff --git a/src/main/java/com/crazzyghost/alphavantage/indicator/response/STOCHRSIResponse.java b/src/main/java/com/crazzyghost/alphavantage/indicator/response/STOCHRSIResponse.java index cfa7f48..f11a2e0 100644 --- a/src/main/java/com/crazzyghost/alphavantage/indicator/response/STOCHRSIResponse.java +++ b/src/main/java/com/crazzyghost/alphavantage/indicator/response/STOCHRSIResponse.java @@ -26,18 +26,10 @@ public String getErrorMessage() { return errorMessage; } - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - } - public List getIndicatorUnits() { return indicatorUnits; } - public void setIndicatorUnits(List indicatorUnits) { - this.indicatorUnits = indicatorUnits; - } - public MetaData getMetaData() { return metaData; } diff --git a/src/main/java/com/crazzyghost/alphavantage/indicator/response/STOCHResponse.java b/src/main/java/com/crazzyghost/alphavantage/indicator/response/STOCHResponse.java index dcae15f..215e60e 100644 --- a/src/main/java/com/crazzyghost/alphavantage/indicator/response/STOCHResponse.java +++ b/src/main/java/com/crazzyghost/alphavantage/indicator/response/STOCHResponse.java @@ -25,19 +25,10 @@ public String getErrorMessage() { return errorMessage; } - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - } - public List getIndicatorUnits() { return indicatorUnits; } - - public void setIndicatorUnits(List indicatorUnits) { - this.indicatorUnits = indicatorUnits; - } - - + public MetaData getMetaData() { return metaData; } diff --git a/src/main/java/com/crazzyghost/alphavantage/indicator/response/SeriesResponse.java b/src/main/java/com/crazzyghost/alphavantage/indicator/response/SeriesResponse.java index fbf4e47..374d3c3 100644 --- a/src/main/java/com/crazzyghost/alphavantage/indicator/response/SeriesResponse.java +++ b/src/main/java/com/crazzyghost/alphavantage/indicator/response/SeriesResponse.java @@ -26,18 +26,9 @@ public String getErrorMessage() { return errorMessage; } - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - } - public List getIndicatorUnits() { return indicatorUnits; } - - public void setIndicatorUnits(List indicatorUnits) { - this.indicatorUnits = indicatorUnits; - } - public MetaData getMetaData() { return metaData; diff --git a/src/main/java/com/crazzyghost/alphavantage/indicator/response/SimpleIndicatorResponse.java b/src/main/java/com/crazzyghost/alphavantage/indicator/response/SimpleIndicatorResponse.java index 405b34d..5f99893 100644 --- a/src/main/java/com/crazzyghost/alphavantage/indicator/response/SimpleIndicatorResponse.java +++ b/src/main/java/com/crazzyghost/alphavantage/indicator/response/SimpleIndicatorResponse.java @@ -26,18 +26,9 @@ public String getErrorMessage() { return errorMessage; } - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - } - public List getIndicatorUnits() { return indicatorUnits; } - - public void setIndicatorUnits(List indicatorUnits) { - this.indicatorUnits = indicatorUnits; - } - public MetaData getMetaData() { return metaData; diff --git a/src/main/java/com/crazzyghost/alphavantage/indicator/response/ULTOSCResponse.java b/src/main/java/com/crazzyghost/alphavantage/indicator/response/ULTOSCResponse.java index d436e65..3491f25 100644 --- a/src/main/java/com/crazzyghost/alphavantage/indicator/response/ULTOSCResponse.java +++ b/src/main/java/com/crazzyghost/alphavantage/indicator/response/ULTOSCResponse.java @@ -26,18 +26,9 @@ public String getErrorMessage() { return errorMessage; } - public void setErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - } - public List getIndicatorUnits() { return indicatorUnits; } - - public void setIndicatorUnits(List indicatorUnits) { - this.indicatorUnits = indicatorUnits; - } - public MetaData getMetaData() { return metaData; diff --git a/src/test/java/indicator/IndicatorResponseTest.java b/src/test/java/indicator/IndicatorResponseTest.java new file mode 100644 index 0000000..e85a184 --- /dev/null +++ b/src/test/java/indicator/IndicatorResponseTest.java @@ -0,0 +1,343 @@ +package indicator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.lang.reflect.Type; +import java.nio.file.Paths; +import java.util.Map; + +import com.crazzyghost.alphavantage.indicator.response.AROONResponse; +import com.crazzyghost.alphavantage.indicator.response.MACDEXTResponse; +import com.crazzyghost.alphavantage.indicator.response.MACDResponse; +import com.crazzyghost.alphavantage.indicator.response.MAMAResponse; +import com.crazzyghost.alphavantage.indicator.response.PeriodicResponse; +import com.crazzyghost.alphavantage.indicator.response.PeriodicSeriesResponse; +import com.crazzyghost.alphavantage.indicator.response.PriceOscillatorResponse; +import com.crazzyghost.alphavantage.indicator.response.STOCHFResponse; +import com.crazzyghost.alphavantage.indicator.response.STOCHRSIResponse; +import com.crazzyghost.alphavantage.indicator.response.STOCHResponse; +import com.crazzyghost.alphavantage.indicator.response.SimpleIndicatorResponse; +import com.crazzyghost.alphavantage.indicator.response.ULTOSCResponse; +import com.squareup.moshi.JsonAdapter; +import com.squareup.moshi.Moshi; +import com.squareup.moshi.Types; + +import org.junit.Test; + +import okio.BufferedSource; +import okio.Okio; + +public class IndicatorResponseTest { + + String errorMessage = "{" + + "\"Information\":" + "\"The **demo** API key is for demo purposes only. Please claim your free API key at (https://www.alphavantage.co/support/#api-key) to explore our full API offerings. It takes fewer than 20 seconds, and we are committed to making it free forever.\"" + + "}"; + + private BufferedSource getJson(String filename) throws FileNotFoundException { + FileInputStream stream = new FileInputStream(Paths.get("src","test","java","indicator","data", filename + ".json").toFile()); + return Okio.buffer(Okio.source(stream)); + } + + private JsonAdapter> getJsonAdapter() { + final Moshi moshi = new Moshi.Builder().build(); + final Type type = Types.newParameterizedType(Map.class, String.class, Object.class); + return moshi.adapter(type); + } + + @Test + public void testPeriodicSeriesResponse() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + PeriodicSeriesResponse response = PeriodicSeriesResponse.of(adapter.fromJson(getJson("sma")), "SMA"); + assertEquals(response.getIndicatorUnits().size(), 2); + } + + @Test + public void testPeriodicSeriesResponseError() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + PeriodicSeriesResponse response = PeriodicSeriesResponse.of(adapter.fromJson(errorMessage), "SMA"); + assertEquals(response.getIndicatorUnits().size(), 0); + assertNotNull(response.getErrorMessage()); + assertEquals(response.getMetaData().getIndicator(),""); + assertEquals(response.getMetaData().getInterval(),""); + assertEquals(response.getMetaData().getLastRefreshed(),""); + assertEquals(response.getMetaData().getSeriesType(),""); + assertEquals(response.getMetaData().getSymbol(),""); + assertEquals(response.getMetaData().getTimePeriod(), 0); + assertEquals(response.getMetaData().getTimeZone(), ""); + } + + @Test + public void testMAMAResponse() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + MAMAResponse response = MAMAResponse.of(adapter.fromJson(getJson("mama"))); + assertEquals(response.getIndicatorUnits().size(), 2); + } + + @Test + public void testMAMAResponseFails() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + MAMAResponse response = MAMAResponse.of(adapter.fromJson(errorMessage)); + assertEquals(response.getIndicatorUnits().size(), 0); + assertNotNull(response.getErrorMessage()); + assertEquals(response.getMetaData().getIndicator(),""); + assertEquals(response.getMetaData().getInterval(),""); + assertEquals(response.getMetaData().getLastRefreshed(),""); + assertEquals(response.getMetaData().getSeriesType(),""); + assertEquals(response.getMetaData().getSymbol(),""); + assertEquals(response.getMetaData().getSlowLimit(), 0.1, 0); + assertEquals(response.getMetaData().getFastLimit(), 0.1, 0); + assertEquals(response.getMetaData().getTimeZone(), ""); + } + + @Test + public void testMACDResponse() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + MACDResponse response = MACDResponse.of(adapter.fromJson(getJson("macd"))); + assertEquals(response.getIndicatorUnits().size(), 2); + } + + @Test + public void testMACDResponseError() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + MACDResponse response = MACDResponse.of(adapter.fromJson(errorMessage)); + assertEquals(response.getIndicatorUnits().size(), 0); + assertNotNull(response.getErrorMessage()); + assertEquals(response.getMetaData().getIndicator(),""); + assertEquals(response.getMetaData().getInterval(),""); + assertEquals(response.getMetaData().getLastRefreshed(),""); + assertEquals(response.getMetaData().getSymbol(),""); + assertEquals(response.getMetaData().getSeriesType(),""); + assertEquals(response.getMetaData().getFastPeriod(), 12, 0); + assertEquals(response.getMetaData().getSlowPeriod(), 26, 0); + assertEquals(response.getMetaData().getSignalPeriod(), 9, 0); + assertEquals(response.getMetaData().getTimeZone(), ""); + } + + + @Test + public void testMACDEXTResponse() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + MACDEXTResponse response = MACDEXTResponse.of(adapter.fromJson(getJson("macdext"))); + assertEquals(response.getIndicatorUnits().size(), 2); + } + + @Test + public void testMACDEXTResponseError() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + MACDEXTResponse response = MACDEXTResponse.of(adapter.fromJson(errorMessage)); + assertEquals(response.getIndicatorUnits().size(), 0); + assertNotNull(response.getErrorMessage()); + assertEquals(response.getMetaData().getIndicator(),""); + assertEquals(response.getMetaData().getInterval(),""); + assertEquals(response.getMetaData().getLastRefreshed(),""); + assertEquals(response.getMetaData().getSymbol(),""); + assertEquals(response.getMetaData().getSeriesType(),""); + assertEquals(response.getMetaData().getFastPeriod(), 12, 0); + assertEquals(response.getMetaData().getSlowPeriod(), 26, 0); + assertEquals(response.getMetaData().getSignalPeriod(), 9, 0); + assertEquals(response.getMetaData().getFastMaType(), 0, 0); + assertEquals(response.getMetaData().getSlowMaType(), 0, 0); + assertEquals(response.getMetaData().getSignalMaType(), 0, 0); + assertEquals(response.getMetaData().getTimeZone(), ""); + } + + @Test + public void testSTOCHResponse() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + STOCHResponse response = STOCHResponse.of(adapter.fromJson(getJson("stoch"))); + assertEquals(response.getIndicatorUnits().size(), 2); + } + + @Test + public void testSTOCHResponseError() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + STOCHResponse response = STOCHResponse.of(adapter.fromJson(errorMessage)); + assertEquals(response.getIndicatorUnits().size(), 0); + assertNotNull(response.getErrorMessage()); + assertEquals(response.getMetaData().getIndicator(),""); + assertEquals(response.getMetaData().getInterval(),""); + assertEquals(response.getMetaData().getLastRefreshed(),""); + assertEquals(response.getMetaData().getSymbol(),""); + assertEquals(response.getMetaData().getFastKPeriod(), 5, 0); + assertEquals(response.getMetaData().getSlowKPeriod(), 3, 0); + assertEquals(response.getMetaData().getSlowKMaType(), 0, 0); + assertEquals(response.getMetaData().getSlowDPeriod(), 3, 0); + assertEquals(response.getMetaData().getSlowDMaType(), 0, 0); + assertEquals(response.getMetaData().getTimeZone(), ""); + } + + @Test + public void testSTOCHFResponse() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + STOCHFResponse response = STOCHFResponse.of(adapter.fromJson(getJson("stochf"))); + assertEquals(response.getIndicatorUnits().size(), 2); + } + + @Test + public void testSTOCHFResponseError() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + STOCHFResponse response = STOCHFResponse.of(adapter.fromJson(errorMessage)); + assertEquals(response.getIndicatorUnits().size(), 0); + assertNotNull(response.getErrorMessage()); + assertEquals(response.getMetaData().getIndicator(),""); + assertEquals(response.getMetaData().getInterval(),""); + assertEquals(response.getMetaData().getLastRefreshed(),""); + assertEquals(response.getMetaData().getSymbol(),""); + assertEquals(response.getMetaData().getSymbol(),""); + assertEquals(response.getMetaData().getFastKPeriod(), 5, 0); + assertEquals(response.getMetaData().getFastDPeriod(), 3, 0); + assertEquals(response.getMetaData().getFastDMaType(), 0, 0); + assertEquals(response.getMetaData().getTimeZone(), ""); + } + + @Test + public void testSTOCHRSIResponse() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + STOCHRSIResponse response = STOCHRSIResponse.of(adapter.fromJson(getJson("stochrsi"))); + assertEquals(response.getIndicatorUnits().size(), 2); + } + + @Test + public void testSTOCHRSIResponseError() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + STOCHRSIResponse response = STOCHRSIResponse.of(adapter.fromJson(errorMessage)); + assertEquals(response.getIndicatorUnits().size(), 0); + assertNotNull(response.getErrorMessage()); + assertEquals(response.getMetaData().getIndicator(),""); + assertEquals(response.getMetaData().getInterval(),""); + assertEquals(response.getMetaData().getLastRefreshed(),""); + assertEquals(response.getMetaData().getSymbol(),""); + assertEquals(response.getMetaData().getTimePeriod(), 10, 0); + assertEquals(response.getMetaData().getFastKPeriod(), 5, 0); + assertEquals(response.getMetaData().getFastDPeriod(), 3, 0); + assertEquals(response.getMetaData().getFastDMaType(), 0, 0); + assertEquals(response.getMetaData().getSeriesType(),""); + assertEquals(response.getMetaData().getTimeZone(), ""); + } + + + @Test + public void testPeriodicResponse() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + PeriodicResponse response = PeriodicResponse.of(adapter.fromJson(getJson("adx")), "ADX"); + assertEquals(response.getIndicatorUnits().size(), 2); + } + + @Test + public void testPeriodicResponseError() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + PeriodicResponse response = PeriodicResponse.of(adapter.fromJson(errorMessage), "ADX"); + assertEquals(response.getIndicatorUnits().size(), 0); + assertNotNull(response.getErrorMessage()); + assertEquals(response.getMetaData().getIndicator(),""); + assertEquals(response.getMetaData().getInterval(),""); + assertEquals(response.getMetaData().getLastRefreshed(),""); + assertEquals(response.getMetaData().getSymbol(),""); + assertEquals(response.getMetaData().getTimePeriod(), 0); + assertEquals(response.getMetaData().getTimeZone(), ""); + } + + @Test + public void testPPO() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + PriceOscillatorResponse response = PriceOscillatorResponse.of(adapter.fromJson(getJson("ppo")), "PPO"); + assertEquals(response.getIndicatorUnits().size(), 2); + } + + @Test + public void testAPO() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + PriceOscillatorResponse response = PriceOscillatorResponse.of(adapter.fromJson(getJson("apo")),"APO"); + assertEquals(response.getIndicatorUnits().size(), 2); + + } + + @Test + public void testPOError() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + PriceOscillatorResponse response = PriceOscillatorResponse.of(adapter.fromJson(errorMessage), "PPO"); + assertEquals(response.getIndicatorUnits().size(), 0); + assertNotNull(response.getErrorMessage()); + assertEquals(response.getMetaData().getIndicator(),""); + assertEquals(response.getMetaData().getInterval(),""); + assertEquals(response.getMetaData().getLastRefreshed(),""); + assertEquals(response.getMetaData().getSymbol(),""); + assertEquals(response.getMetaData().getFastPeriod(), 0); + assertEquals(response.getMetaData().getSlowPeriod(), 0); + assertEquals(response.getMetaData().getMaType(), 0); + assertEquals(response.getMetaData().getSeriesType(), ""); + assertEquals(response.getMetaData().getTimeZone(), ""); + } + + + @Test + public void testAROON() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + AROONResponse response = AROONResponse.of(adapter.fromJson(getJson("aroon"))); + assertEquals(response.getIndicatorUnits().size(), 2); + } + + @Test + public void testAROONError() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + AROONResponse response = AROONResponse.of(adapter.fromJson(errorMessage)); + assertEquals(response.getIndicatorUnits().size(), 0); + assertNotNull(response.getErrorMessage()); + assertEquals(response.getMetaData().getIndicator(),""); + assertEquals(response.getMetaData().getInterval(),""); + assertEquals(response.getMetaData().getLastRefreshed(),""); + assertEquals(response.getMetaData().getSymbol(),""); + assertEquals(response.getMetaData().getTimePeriod(), 0); + assertEquals(response.getMetaData().getTimeZone(), ""); + } + + @Test + public void testSimpleIndicatorResponse() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + SimpleIndicatorResponse response = SimpleIndicatorResponse.of(adapter.fromJson(getJson("vwap")), "VWAP"); + assertEquals(response.getIndicatorUnits().size(), 2); + } + + @Test + public void testSimpleIndicatorResponseError() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + SimpleIndicatorResponse response = SimpleIndicatorResponse.of(adapter.fromJson(errorMessage), "VWAP"); + assertEquals(response.getIndicatorUnits().size(), 0); + assertNotNull(response.getErrorMessage()); + assertEquals(response.getMetaData().getIndicator(),""); + assertEquals(response.getMetaData().getInterval(),""); + assertEquals(response.getMetaData().getLastRefreshed(),""); + assertEquals(response.getMetaData().getSymbol(),""); + assertEquals(response.getMetaData().getTimeZone(), ""); + } + + @Test + public void testULTOSC() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + ULTOSCResponse response = ULTOSCResponse.of(adapter.fromJson(getJson("ultosc")), "ULTOSC"); + assertEquals(response.getIndicatorUnits().size(), 2); + } + + @Test + public void testULTOSCError() throws IOException{ + final JsonAdapter> adapter = getJsonAdapter(); + ULTOSCResponse response = ULTOSCResponse.of(adapter.fromJson(errorMessage), "ULTOSC"); + assertEquals(response.getIndicatorUnits().size(), 0); + assertNotNull(response.getErrorMessage()); + assertEquals(response.getMetaData().getIndicator(),""); + assertEquals(response.getMetaData().getInterval(),""); + assertEquals(response.getMetaData().getLastRefreshed(),""); + assertEquals(response.getMetaData().getSymbol(),""); + assertEquals(response.getMetaData().getTimePeriod1(), 0); + assertEquals(response.getMetaData().getTimePeriod2(), 0); + assertEquals(response.getMetaData().getTimePeriod3(), 0); + assertEquals(response.getMetaData().getTimeZone(), ""); + } + + +} \ No newline at end of file diff --git a/src/test/java/indicator/IndicatorUnitTest.java b/src/test/java/indicator/IndicatorUnitTest.java index 03d3663..53bf8d7 100644 --- a/src/test/java/indicator/IndicatorUnitTest.java +++ b/src/test/java/indicator/IndicatorUnitTest.java @@ -45,12 +45,20 @@ public void testMAMAIndicatorUnit(){ @Test public void testSimpleIndicatorUnit(){ - SimpleIndicatorUnit unit = new SimpleIndicatorUnit("2012-02-02", 4.5); + SimpleIndicatorUnit unit = new SimpleIndicatorUnit("2012-02-02", 4.5,"SMA"); assertEquals(unit.getValue(), 4.5, 0.0); assertEquals(unit.getDate(), "2012-02-02"); assertNotNull(unit.toString()); } + @Test + public void testSimpleIndicatorUnitWithNoIndicator(){ + SimpleIndicatorUnit unit = new SimpleIndicatorUnit("2012-02-02", 4.5); + assertEquals(unit.getValue(), 4.5, 0.0); + assertEquals(unit.getDate(), "2012-02-02"); + assertNotNull(unit.toString()); + } + @Test public void testSTOCHIndicatorUnit(){ STOCHIndicatorUnit unit = new STOCHIndicatorUnit("2012-02-02", 4.5, 4.0); diff --git a/src/test/java/indicator/ResponseTest.java b/src/test/java/indicator/ResponseTest.java deleted file mode 100644 index 9acb3d4..0000000 --- a/src/test/java/indicator/ResponseTest.java +++ /dev/null @@ -1,138 +0,0 @@ -package indicator; - -import static org.junit.Assert.assertEquals; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.lang.reflect.Type; -import java.nio.file.Paths; -import java.util.Map; - -import com.crazzyghost.alphavantage.indicator.response.AROONResponse; -import com.crazzyghost.alphavantage.indicator.response.MACDEXTResponse; -import com.crazzyghost.alphavantage.indicator.response.MACDResponse; -import com.crazzyghost.alphavantage.indicator.response.MAMAResponse; -import com.crazzyghost.alphavantage.indicator.response.PeriodicResponse; -import com.crazzyghost.alphavantage.indicator.response.PeriodicSeriesResponse; -import com.crazzyghost.alphavantage.indicator.response.PriceOscillatorResponse; -import com.crazzyghost.alphavantage.indicator.response.STOCHFResponse; -import com.crazzyghost.alphavantage.indicator.response.STOCHRSIResponse; -import com.crazzyghost.alphavantage.indicator.response.STOCHResponse; -import com.crazzyghost.alphavantage.indicator.response.SimpleIndicatorResponse; -import com.crazzyghost.alphavantage.indicator.response.ULTOSCResponse; -import com.squareup.moshi.JsonAdapter; -import com.squareup.moshi.Moshi; -import com.squareup.moshi.Types; - -import org.junit.Test; - -import okio.BufferedSource; -import okio.Okio; - -public class ResponseTest { - - private BufferedSource getJson(String filename) throws FileNotFoundException { - FileInputStream stream = new FileInputStream(Paths.get("src","test","java","indicator","data", filename + ".json").toFile()); - return Okio.buffer(Okio.source(stream)); - } - - private JsonAdapter> getJsonAdapter() { - final Moshi moshi = new Moshi.Builder().build(); - final Type type = Types.newParameterizedType(Map.class, String.class, Object.class); - return moshi.adapter(type); - } - - @Test - public void testPeriodicSeriesResponse() throws IOException{ - final JsonAdapter> adapter = getJsonAdapter(); - PeriodicSeriesResponse response = PeriodicSeriesResponse.of(adapter.fromJson(getJson("sma")), "SMA"); - assertEquals(response.getIndicatorUnits().size(), 2); - } - - @Test - public void testMAMAResponse() throws IOException{ - final JsonAdapter> adapter = getJsonAdapter(); - MAMAResponse response = MAMAResponse.of(adapter.fromJson(getJson("mama"))); - assertEquals(response.getIndicatorUnits().size(), 2); - } - - @Test - public void testMACDResponse() throws IOException{ - final JsonAdapter> adapter = getJsonAdapter(); - MACDResponse response = MACDResponse.of(adapter.fromJson(getJson("macd"))); - assertEquals(response.getIndicatorUnits().size(), 2); - } - - @Test - public void testMACDEXTResponse() throws IOException{ - final JsonAdapter> adapter = getJsonAdapter(); - MACDEXTResponse response = MACDEXTResponse.of(adapter.fromJson(getJson("macdext"))); - assertEquals(response.getIndicatorUnits().size(), 2); - } - - @Test - public void testSTOCHResponse() throws IOException{ - final JsonAdapter> adapter = getJsonAdapter(); - STOCHResponse response = STOCHResponse.of(adapter.fromJson(getJson("stoch"))); - assertEquals(response.getIndicatorUnits().size(), 2); - } - - @Test - public void testSTOCHFResponse() throws IOException{ - final JsonAdapter> adapter = getJsonAdapter(); - STOCHFResponse response = STOCHFResponse.of(adapter.fromJson(getJson("stochf"))); - assertEquals(response.getIndicatorUnits().size(), 2); - } - - @Test - public void testSTOCHRSIResponse() throws IOException{ - final JsonAdapter> adapter = getJsonAdapter(); - STOCHRSIResponse response = STOCHRSIResponse.of(adapter.fromJson(getJson("stochrsi"))); - assertEquals(response.getIndicatorUnits().size(), 2); - } - - @Test - public void testPeriodicResponse() throws IOException{ - final JsonAdapter> adapter = getJsonAdapter(); - PeriodicResponse response = PeriodicResponse.of(adapter.fromJson(getJson("adx")), "ADX"); - assertEquals(response.getIndicatorUnits().size(), 2); - } - - @Test - public void testPPO() throws IOException{ - final JsonAdapter> adapter = getJsonAdapter(); - PriceOscillatorResponse response = PriceOscillatorResponse.of(adapter.fromJson(getJson("ppo")), "PPO"); - assertEquals(response.getIndicatorUnits().size(), 2); - } - - @Test - public void testAPO() throws IOException{ - final JsonAdapter> adapter = getJsonAdapter(); - PriceOscillatorResponse response = PriceOscillatorResponse.of(adapter.fromJson(getJson("apo")), "APO"); - assertEquals(response.getIndicatorUnits().size(), 2); - } - - @Test - public void testAROON() throws IOException{ - final JsonAdapter> adapter = getJsonAdapter(); - AROONResponse response = AROONResponse.of(adapter.fromJson(getJson("aroon"))); - assertEquals(response.getIndicatorUnits().size(), 2); - } - - @Test - public void testSimpleIndicatorResponse() throws IOException{ - final JsonAdapter> adapter = getJsonAdapter(); - SimpleIndicatorResponse response = SimpleIndicatorResponse.of(adapter.fromJson(getJson("vwap")), "VWAP"); - assertEquals(response.getIndicatorUnits().size(), 2); - } - - @Test - public void testULTOSC() throws IOException{ - final JsonAdapter> adapter = getJsonAdapter(); - ULTOSCResponse response = ULTOSCResponse.of(adapter.fromJson(getJson("ultosc")), "ULTOSC"); - assertEquals(response.getIndicatorUnits().size(), 2); - } - - -} \ No newline at end of file