This repository has been archived by the owner on Dec 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0fcc7ce
commit 71e28b8
Showing
4 changed files
with
90 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
android-google-spreadsheets-lib/src/tests/assets/spreadsheet_feed.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'> | ||
<id>https://spreadsheets.google.com/feeds/spreadsheets/private/full</id> | ||
<updated>2013-11-26T17:32:23.771Z</updated> | ||
<category scheme='http://schemas.google.com/spreadsheets/2006' term='http://schemas.google.com/spreadsheets/2006#spreadsheet'/> | ||
<title type='text'>Available Spreadsheets - [email protected]</title> | ||
<link rel='alternate' type='text/html' href='http://docs.google.com'/> | ||
<link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/spreadsheets/private/full'/> | ||
<link rel='self' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/spreadsheets/private/full'/> | ||
<openSearch:totalResults>43</openSearch:totalResults> | ||
<openSearch:startIndex>1</openSearch:startIndex> | ||
<entry> | ||
<id>https://spreadsheets.google.com/feeds/spreadsheets/private/full/tSjX-5loafCgwX2ABudzw</id> | ||
<updated>2013-11-10T09:18:32.792Z</updated> | ||
<category scheme='http://schemas.google.com/spreadsheets/2006' term='http://schemas.google.com/spreadsheets/2006#spreadsheet'/> | ||
<title type='text'>custom_word_list</title> | ||
<content type='text'>custom_word_list</content> | ||
<link rel='http://schemas.google.com/spreadsheets/2006#worksheetsfeed' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/worksheets/tSjX-5loafp1CgwX2ABudzw/private/full'/> | ||
<link rel='alternate' type='text/html' href='https://spreadsheets.google.com/ccc?key=0Ar60JNdr-jIhdFNqWC01bG9hZnAxQ2d3WDJBQnVkenc'/> | ||
<link rel='self' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/spreadsheets/private/full/tSjX-5loafp1CgwX2ABudzw'/> | ||
<author> | ||
<name>sa</name> | ||
<email>[email protected]</email> | ||
</author> | ||
</entry> | ||
<entry> | ||
<id>https://spreadsheets.google.com/feeds/spreadsheets/private/full/tNCapdcsed6XvXblUZmtVA</id> | ||
<updated>2013-11-10T04:10:17.860Z</updated> | ||
<category scheme='http://schemas.google.com/spreadsheets/2006' term='http://schemas.google.com/spreadsheets/2006#spreadsheet'/> | ||
<title type='text'>Word List</title> | ||
<content type='text'>Word List</content> | ||
<link rel='http://schemas.google.com/spreadsheets/2006#worksheetsfeed' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/worksheets/tNCapdcsed6XvXblUZGmtVA/private/full'/> | ||
<link rel='alternate' type='text/html' href='https://spreadsheets.google.com/ccc?key=0Ar60JNdr-jIhdE5DYXBkY3NlZDZYdlhibFVaR210VkE'/> | ||
<link rel='self' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/spreadsheets/private/full/tNCapdcsed6XvXblUZGmtVA'/> | ||
<author> | ||
<name>sa</name> | ||
<email>[email protected]</email> | ||
</author> | ||
</entry> | ||
<entry> | ||
<id>https://spreadsheets.google.com/feeds/spreadsheets/private/full/pCQbetd-CptGXxQIG7VFI</id> | ||
<updated>2009-02-02T12:48:36.459Z</updated> | ||
<category scheme='http://schemas.google.com/spreadsheets/2006' term='http://schemas.google.com/spreadsheets/2006#spreadsheet'/> | ||
<title type='text'>Sample spreadsheet</title> | ||
<content type='text'>Sample spreadsheet</content> | ||
<link rel='http://schemas.google.com/spreadsheets/2006#worksheetsfeed' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/worksheets/pCQbetd-CptGXxxQIG7VFIQ/private/values'/> | ||
<link rel='alternate' type='text/html' href='https://spreadsheets.google.com/ccc?key=0AiFfbdok-kQKcENRYmV0ZC1DcHRHWHh4UUlHN1ZGSVE'/> | ||
<link rel='self' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/spreadsheets/private/full/pCQbetd-CptGXxxQIG7VFIQ'/> | ||
<author> | ||
<name>visualization.api</name> | ||
<email>[email protected]</email> | ||
</author> | ||
</entry> | ||
</feed> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,13 @@ | |
import com.android.volley.Response; | ||
import com.github.spreadsheets.android.api.model.Feed; | ||
import com.github.spreadsheets.android.api.model.SpreadsheetFeed; | ||
import com.github.spreadsheets.android.api.testutils.AssetsFileReader; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.fest.assertions.api.Assertions.assertThat; | ||
|
||
@SmallTest | ||
public class SpreadsheetRequestTest extends AndroidTestCase { | ||
private SpreadsheetRequest mRequest; | ||
|
@@ -22,52 +25,10 @@ public class SpreadsheetRequestTest extends AndroidTestCase { | |
public void setUp() throws Exception { | ||
super.setUp(); | ||
mRequest = new SpreadsheetRequest<Feed>(Request.Method.GET, null, null); | ||
|
||
String responseText = "<feed xmlns=\"http://www.w3.org/2005/Atom\"\n" + | ||
" xmlns:openSearch=\"http://a9.com/-/spec/opensearch/1.1/\"\n" + | ||
" xmlns:gs=\"http://schemas.google.com/spreadsheets/2006\"\n" + | ||
" xmlns:gd=\"http://schemas.google.com/g/2005\"\n" + | ||
" gd:etag=\"D0cERnk-eip7ImA9WBBXGEg.\">\n" + | ||
" <id>https://spreadsheets.google.com/feeds/worksheets/key/private/full</id>\n" + | ||
" <updated>2006-11-17T18:23:45.173Z</updated>\n" + | ||
" <title type=\"text\">Groceries R Us</title>\n" + | ||
" <link rel=\"alternate\" type=\"text/html\"\n" + | ||
" href=\"https://spreadsheets.google.com/ccc?key=key\"/>\n" + | ||
" <link rel=\"http://schemas.google.com/g/2005#feed\"\n" + | ||
" type=\"application/atom+xml\"\n" + | ||
" href=\"https://spreadsheets.google.com/feeds/worksheets/key/private/full\"/>\n" + | ||
" <link rel=\"self\" type=\"application/atom+xml\"\n" + | ||
" href=\"https://spreadsheets.google.com/feeds/worksheets/key/private/full\"/>\n" + | ||
" <link rel=\"http://schemas.google.com/g/2005#post\" type=\"application/atom+xml\"\n" + | ||
" href=\"https://spreadsheets.google.com/feeds/worksheets/key/private/full\"/>\n" + | ||
" <author>\n" + | ||
" <name>Fitzwilliam Darcy</name>\n" + | ||
" <email>[email protected]</email>\n" + | ||
" </author>\n" + | ||
" <openSearch:totalResults>1</openSearch:totalResults>\n" + | ||
" <openSearch:startIndex>1</openSearch:startIndex>\n" + | ||
" <openSearch:itemsPerPage>1</openSearch:itemsPerPage>\n" + | ||
" <entry gd:etag='\"YDwqeyI.\"'>\n" + | ||
" <id>https://spreadsheets.google.com/feeds/worksheets/key/private/full/worksheetId</id>\n" + | ||
" <updated>2006-11-17T18:23:45.173Z</updated>\n" + | ||
" <title type=\"text\">Sheet1</title>\n" + | ||
" <content type=\"text\">Sheet1</content>\n" + | ||
" <link rel=\"http://schemas.google.com/spreadsheets/2006#listfeed\"\n" + | ||
" type=\"application/atom+xml\"\n" + | ||
" href=\"https://spreadsheets.google.com/feeds/list/key/worksheetId/private/full\"/>\n" + | ||
" <link rel=\"http://schemas.google.com/spreadsheets/2006#cellsfeed\"\n" + | ||
" type=\"application/atom+xml\"\n" + | ||
" href=\"https://spreadsheets.google.com/feeds/cells/key/worksheetId/private/full\"/>\n" + | ||
" <link rel=\"self\" type=\"application/atom+xml\"\n" + | ||
" href=\"https://spreadsheets.google.com/feeds/worksheets/key/private/full/worksheetId\"/>\n" + | ||
" <link rel=\"edit\" type=\"application/atom+xml\"\n" + | ||
" href=\"https://spreadsheets.google.com/feeds/worksheets/key/private/full/worksheetId/version\"/>\n" + | ||
" <gs:rowCount>100</gs:rowCount>\n" + | ||
" <gs:colCount>20</gs:colCount>\n" + | ||
" </entry>\n" + | ||
"</feed>"; | ||
headers.put(com.google.common.net.HttpHeaders.CONTENT_TYPE, "application/atom+xml; charset=UTF-8"); | ||
mMockResponse = new NetworkResponse(200, responseText.getBytes(), headers, false); | ||
String xml = new AssetsFileReader().assetFileContents("spreadsheet_feed.xml"); | ||
headers.put(com.google.common.net.HttpHeaders.CONTENT_TYPE, | ||
"application/atom+xml; charset=UTF-8"); | ||
mMockResponse = new NetworkResponse(200, xml.getBytes(), headers, false); | ||
} | ||
|
||
public void testParsingSuccess() { | ||
|
@@ -85,7 +46,10 @@ public void testParsingFailure() { | |
public void testParseNetworkResponse() { | ||
Response feedResponse = mRequest.parseNetworkResponse(mMockResponse); | ||
SpreadsheetFeed feed = (SpreadsheetFeed) feedResponse.result; | ||
assertEquals(feed.etag, "D0cERnk-eip7ImA9WBBXGEg."); | ||
assertThat(feed.getEntries().size()).isEqualTo(3); | ||
assertThat(feed.getEntries().get(0).title).isEqualTo("custom_word_list"); | ||
assertThat(feed.getEntries().get(1).title).isEqualTo("Word List"); | ||
assertThat(feed.getEntries().get(2).title).isEqualTo("Sample spreadsheet"); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...ts-lib/src/tests/java/com/github/spreadsheets/android/api/testutils/AssetsFileReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.github.spreadsheets.android.api.testutils; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
|
||
public class AssetsFileReader { | ||
public String assetFileContents(final String fileName) throws IOException { | ||
StringBuilder text = new StringBuilder(); | ||
InputStream fileStream = this.getClass().getClassLoader() | ||
.getResourceAsStream("assets/" + fileName); | ||
|
||
BufferedReader reader = new BufferedReader(new InputStreamReader(fileStream)); | ||
String line; | ||
while((line = reader.readLine()) != null) { | ||
text.append(line); | ||
} | ||
return text.toString(); | ||
} | ||
} |