-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for WasapiClient and WasapiConnection.
- Loading branch information
Tommy Ingulfsen
committed
May 19, 2017
1 parent
87cb0ae
commit 33674a8
Showing
2 changed files
with
95 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package edu.stanford.dlss.was; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
|
||
import static org.hamcrest.CoreMatchers.*; | ||
import static org.junit.Assert.*; | ||
import org.junit.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class TestWasapiClient { | ||
@Test | ||
public void constructorInitializesCorrectly() throws IOException, SettingsLoadException { | ||
WasapiDownloaderSettings settings = new WasapiDownloaderSettings(WasapiDownloader.SETTINGS_FILE_LOCATION, null); | ||
WasapiClient testClient = new WasapiClient(settings); | ||
|
||
assertNotNull(testClient.wasapiClient); | ||
assertNotNull(testClient.wasapiContext); | ||
assertNotNull(testClient.cookieStore); | ||
assertEquals(testClient.settings, settings); | ||
} | ||
|
||
@Test | ||
public void closeCloses() throws IOException, SettingsLoadException { | ||
WasapiClient testClient = new WasapiClient(new WasapiDownloaderSettings(WasapiDownloader.SETTINGS_FILE_LOCATION, null)); | ||
CloseableHttpClient mockHttpClient = mock(CloseableHttpClient.class); | ||
testClient.wasapiClient = mockHttpClient; | ||
|
||
testClient.close(); | ||
|
||
verify(mockHttpClient, times(1)).close(); | ||
} | ||
|
||
@Test | ||
public void executeUsesContext() throws IOException, SettingsLoadException { | ||
WasapiClient testClient = new WasapiClient(new WasapiDownloaderSettings(WasapiDownloader.SETTINGS_FILE_LOCATION, null)); | ||
CloseableHttpClient mockHttpClient = mock(CloseableHttpClient.class); | ||
testClient.wasapiClient = mockHttpClient; | ||
|
||
JsonResponseHandler mockHandler = mock(JsonResponseHandler.class); | ||
HttpGet mockRequest = mock(HttpGet.class); | ||
|
||
testClient.execute(mockRequest, mockHandler); | ||
|
||
verify(mockHttpClient, times(1)).execute(mockRequest, mockHandler, testClient.wasapiContext); | ||
} | ||
} |
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,46 @@ | ||
package edu.stanford.dlss.was; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.http.client.methods.HttpGet; | ||
|
||
import static org.hamcrest.CoreMatchers.*; | ||
import static org.junit.Assert.*; | ||
import org.junit.*; | ||
import static org.mockito.Mockito.*; | ||
import org.mockito.ArgumentMatchers; | ||
|
||
public class TestWasapiConnection { | ||
|
||
private static final String JSON_QUERY = "http://example.com/example.json"; | ||
private static final String DOWNLOAD_QUERY = "http://example.com/download?file=example.warc"; | ||
private static final String OUTPUT_PATH = "/dev/null"; | ||
|
||
@Test | ||
public void constructorCallsLogin() throws IOException { | ||
WasapiClient mockClient = mock(WasapiClient.class); | ||
WasapiConnection testConnection = new WasapiConnection(mockClient); | ||
|
||
verify(mockClient, times(1)).login(); | ||
} | ||
|
||
@Test | ||
public void jsonQueryCallsExecute() throws IOException { | ||
WasapiClient mockClient = mock(WasapiClient.class); | ||
WasapiConnection testConnection = new WasapiConnection(mockClient); | ||
testConnection.jsonQuery(JSON_QUERY); | ||
|
||
verify(mockClient, times(1)).execute(ArgumentMatchers.<HttpGet>any(HttpGet.class), | ||
ArgumentMatchers.<JsonResponseHandler>any(JsonResponseHandler.class)); | ||
} | ||
|
||
@Test | ||
public void downloadQueryCallsExecute() throws IOException { | ||
WasapiClient mockClient = mock(WasapiClient.class); | ||
WasapiConnection testConnection = new WasapiConnection(mockClient); | ||
testConnection.downloadQuery(JSON_QUERY, OUTPUT_PATH); | ||
|
||
verify(mockClient, times(1)).execute(ArgumentMatchers.<HttpGet>any(HttpGet.class), | ||
ArgumentMatchers.<DownloadResponseHandler>any(DownloadResponseHandler.class)); | ||
} | ||
} |