Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LiveTests #227

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/TestSuite.class</include>
<include>**/LiveTestSuite.class</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/yahoofinance/YahooFinance.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class YahooFinance {
public static final String HISTQUOTES2_ENABLED = System.getProperty("yahoofinance.histquotes2.enabled", "true");
public static final String HISTQUOTES2_BASE_URL = System.getProperty("yahoofinance.baseurl.histquotes2", "https://query1.finance.yahoo.com/v7/finance/download/");
public static final String HISTQUOTES_QUERY2V8_BASE_URL = System.getProperty("yahoofinance.baseurl.histquotesquery2v8", "https://query2.finance.yahoo.com/v8/finance/chart/");
public static final String HISTQUOTES2_SCRAPE_URL = System.getProperty("yahoofinance.scrapeurl.histquotes2", "https://finance.yahoo.com/quote/%5EGSPC/options");
public static final String HISTQUOTES2_SCRAPE_URL = System.getProperty("yahoofinance.scrapeurl.histquotes2", "https://finance.yahoo.com/quote/^GSPC");
public static final String HISTQUOTES2_CRUMB_URL = System.getProperty("yahoofinance.crumburl.histquotes2", "https://query1.finance.yahoo.com/v1/test/getcrumb");
public static final String HISTQUOTES2_CRUMB = System.getProperty("yahoofinance.crumb", "");
public static final String HISTQUOTES2_COOKIE = System.getProperty("yahoofinance.cookie", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import yahoofinance.Utils;
import yahoofinance.YahooFinance;
import yahoofinance.util.RedirectableRequest;
import yahoofinance.util.CrumbManager;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import yahoofinance.histquotes.HistoricalQuote;
import yahoofinance.histquotes.Interval;
import yahoofinance.util.RedirectableRequest;
import yahoofinance.util.CrumbManager;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import yahoofinance.Utils;
import yahoofinance.YahooFinance;
import yahoofinance.util.RedirectableRequest;
import yahoofinance.util.CrumbManager;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/yahoofinance/quotes/query1v7/QuotesRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
import yahoofinance.Utils;
import yahoofinance.YahooFinance;
import yahoofinance.util.RedirectableRequest;

import yahoofinance.util.CrumbManager;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -59,7 +60,8 @@ public List<T> getResult() throws IOException {

Map<String, String> params = new LinkedHashMap<String, String>();
params.put("symbols", this.symbols);


params.put("crumb", CrumbManager.getCrumb());
String url = YahooFinance.QUOTES_QUERY1V7_BASE_URL + "?" + Utils.getURLParameters(params);

// Get JSON from Yahoo
Expand All @@ -69,7 +71,10 @@ public List<T> getResult() throws IOException {
RedirectableRequest redirectableRequest = new RedirectableRequest(request, 5);
redirectableRequest.setConnectTimeout(YahooFinance.CONNECTION_TIMEOUT);
redirectableRequest.setReadTimeout(YahooFinance.CONNECTION_TIMEOUT);
URLConnection connection = redirectableRequest.openConnection();
Map<String, String> requestProperties = new HashMap<String, String>();
requestProperties.put("Cookie", CrumbManager.getCookie());
requestProperties.put("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
URLConnection connection = redirectableRequest.openConnection(requestProperties);

InputStreamReader is = new InputStreamReader(connection.getInputStream());
JsonNode node = objectMapper.readTree(is);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package yahoofinance.histquotes2;
package yahoofinance.util;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down Expand Up @@ -46,9 +46,10 @@ private static void setCookie() throws IOException {
redirectableRequest.setConnectTimeout(YahooFinance.CONNECTION_TIMEOUT);
redirectableRequest.setReadTimeout(YahooFinance.CONNECTION_TIMEOUT);


URLConnection connection = redirectableRequest.openConnection();

Map<String, String> requestProperties = new HashMap<String, String>();
requestProperties.put("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
URLConnection connection = redirectableRequest.openConnection(requestProperties);

for(String headerKey : connection.getHeaderFields().keySet()) {
if("Set-Cookie".equalsIgnoreCase(headerKey)) {
for(String cookieField : connection.getHeaderFields().get(headerKey)) {
Expand Down Expand Up @@ -162,7 +163,8 @@ private static void setCrumb() throws IOException {

Map<String, String> requestProperties = new HashMap<String, String>();
requestProperties.put("Cookie", cookie);

requestProperties.put("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");

URLConnection crumbConnection = redirectableCrumbRequest.openConnection(requestProperties);
InputStreamReader is = new InputStreamReader(crumbConnection.getInputStream());
BufferedReader br = new BufferedReader(is);
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/yahoofinance/LiveTestSuite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package yahoofinance;


import org.junit.runner.RunWith;
import org.junit.runners.Suite;

//ADD new test Classes here
@RunWith(Suite.class)
@Suite.SuiteClasses({
OnlineRequestTest.class


})
public class LiveTestSuite {

}
28 changes: 28 additions & 0 deletions src/test/java/yahoofinance/MockTestSuite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package yahoofinance;


import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import yahoofinance.mock.MockedServersTest;




import java.io.IOException;

//ADD new test Classes here
@RunWith(Suite.class)
@Suite.SuiteClasses({
HistoricalQuoteRequestTest.class,
FxQuoteRequestTest.class,
QuoteRequestFlowTest.class,
SimpleQuoteRequestTest.class


})
public class MockTestSuite {
public void MockTestSuite(){
MockedServersTest.startServers();
}

}
25 changes: 25 additions & 0 deletions src/test/java/yahoofinance/OnlineRequestTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package yahoofinance;

import org.junit.Test;
import yahoofinance.quotes.fx.FxQuote;
import yahoofinance.quotes.fx.FxSymbols;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Map;

import static org.junit.Assert.*;

/**
*
* @author Paul ProgramComputer
*/
public class OnlineRequestTest {

@Test
public void OnlineRequestTest() throws IOException {
Stock stock = YahooFinance.get("AAPL");
assertEquals(stock.getStats().getSymbol(),"AAPL");

}
}