fix: HttpEngine tests
This commit is contained in:
parent
3f9847f617
commit
5c277f4d54
@ -3,6 +3,7 @@ apply plugin: 'maven'
|
||||
|
||||
dependencies {
|
||||
compile project(':vtm')
|
||||
compile 'com.squareup.okhttp:okhttp:1.5.2'
|
||||
testCompile 'junit:junit:4.11'
|
||||
testCompile 'org.mockito:mockito-all:1.9.5'
|
||||
testCompile 'org.easytesting:fest-assert-core:2.0M10'
|
||||
|
@ -1,8 +1,11 @@
|
||||
package org.oscim.tiling.source;
|
||||
|
||||
import com.squareup.okhttp.mockwebserver.MockResponse;
|
||||
import com.squareup.okhttp.mockwebserver.MockWebServer;
|
||||
import com.squareup.okhttp.mockwebserver.RecordedRequest;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@ -10,12 +13,9 @@ import org.junit.Test;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import com.squareup.okhttp.mockwebserver.MockResponse;
|
||||
import com.squareup.okhttp.mockwebserver.MockWebServer;
|
||||
import com.squareup.okhttp.mockwebserver.RecordedRequest;
|
||||
|
||||
public class OkHttpEngineTest {
|
||||
private OkHttpEngine engine;
|
||||
@ -29,7 +29,8 @@ public class OkHttpEngineTest {
|
||||
server = new MockWebServer();
|
||||
server.enqueue(mockResponse);
|
||||
server.play();
|
||||
engine = (OkHttpEngine) new OkHttpEngine.OkHttpFactory().create();
|
||||
engine = (OkHttpEngine) new OkHttpEngine.OkHttpFactory()
|
||||
.create(new OSciMap4TileSource(server.getUrl("/tiles/vtm").toString()));
|
||||
}
|
||||
|
||||
@After
|
||||
@ -44,13 +45,12 @@ public class OkHttpEngineTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void sendRequest_shouldRejectNullTile() throws Exception {
|
||||
engine.sendRequest(null, null);
|
||||
engine.sendRequest(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendRequest_shouldAppendXYZToPath() throws Exception {
|
||||
engine.sendRequest(new OSciMap4TileSource(server.getUrl("/tiles/vtm").toString()),
|
||||
new Tile(1, 2, new Integer(3).byteValue()));
|
||||
engine.sendRequest(new Tile(1, 2, new Integer(3).byteValue()));
|
||||
|
||||
RecordedRequest request = server.takeRequest();
|
||||
assertThat(request.getPath()).isEqualTo("/tiles/vtm/3/1/2.vtm");
|
||||
@ -58,8 +58,7 @@ public class OkHttpEngineTest {
|
||||
|
||||
@Test
|
||||
public void read_shouldReturnResponseStream() throws Exception {
|
||||
engine.sendRequest(new OSciMap4TileSource(server.getUrl("/tiles/vtm").toString()),
|
||||
new Tile(1, 2, new Integer(3).byteValue()));
|
||||
engine.sendRequest(new Tile(1, 2, new Integer(3).byteValue()));
|
||||
|
||||
InputStream responseStream = engine.read();
|
||||
String response = new BufferedReader(new InputStreamReader(responseStream)).readLine();
|
||||
@ -68,8 +67,7 @@ public class OkHttpEngineTest {
|
||||
|
||||
@Test(expected = IOException.class)
|
||||
public void close_shouldCloseInputStream() throws Exception {
|
||||
engine.sendRequest(new OSciMap4TileSource(server.getUrl("/tiles/vtm").toString()),
|
||||
new Tile(1, 2, new Integer(3).byteValue()));
|
||||
engine.sendRequest(new Tile(1, 2, new Integer(3).byteValue()));
|
||||
engine.close();
|
||||
|
||||
// Calling read after the stream is closed should throw an exception.
|
||||
@ -79,8 +77,7 @@ public class OkHttpEngineTest {
|
||||
|
||||
@Test(expected = IOException.class)
|
||||
public void requestCompleted_shouldCloseInputStream() throws Exception {
|
||||
engine.sendRequest(new OSciMap4TileSource(server.getUrl("/tiles/vtm").toString()),
|
||||
new Tile(1, 2, new Integer(3).byteValue()));
|
||||
engine.sendRequest(new Tile(1, 2, new Integer(3).byteValue()));
|
||||
engine.requestCompleted(true);
|
||||
|
||||
// Calling read after the stream is closed should throw an exception.
|
||||
|
@ -1,17 +1,17 @@
|
||||
package org.oscim.tiling.source;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.oscim.tiling.ITileDataSource;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
public class UrlTileSourceTest {
|
||||
private UrlTileSource tileSource;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
tileSource = new TestTileSource("http://example.org/tiles/vtm");
|
||||
tileSource = new TestTileSource("http://example.org/tiles/vtm", "/{Z}/{X}/{Z}.vtm");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -33,8 +33,8 @@ public class UrlTileSourceTest {
|
||||
}
|
||||
|
||||
class TestTileSource extends UrlTileSource {
|
||||
public TestTileSource(String urlString) {
|
||||
super(urlString);
|
||||
public TestTileSource(String urlString, String tilePath) {
|
||||
super(urlString, tilePath);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -45,7 +45,7 @@ public class UrlTileSourceTest {
|
||||
|
||||
class TestTileDataSource extends UrlTileDataSource {
|
||||
public TestTileDataSource(UrlTileSource tileSource, ITileDecoder tileDecoder,
|
||||
HttpEngine conn) {
|
||||
HttpEngine conn) {
|
||||
super(tileSource, tileDecoder, conn);
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ import org.oscim.tiling.source.HttpEngine;
|
||||
import org.oscim.tiling.source.LwHttp;
|
||||
import org.oscim.tiling.source.OkHttpEngine;
|
||||
import org.oscim.tiling.source.UrlTileDataSource;
|
||||
import org.oscim.tiling.source.UrlTileSource;
|
||||
|
||||
public class BitmapTileSourceTest {
|
||||
private BitmapTileSource tileSource;
|
||||
@ -43,7 +44,8 @@ public class BitmapTileSourceTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test factory that allows the specific {@link HttpEngine} instance to be set.
|
||||
* Test factory that allows the specific {@link HttpEngine} instance to be
|
||||
* set.
|
||||
*/
|
||||
class TestHttpFactory implements HttpEngine.Factory {
|
||||
final HttpEngine engine;
|
||||
@ -53,7 +55,7 @@ public class BitmapTileSourceTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpEngine create() {
|
||||
public HttpEngine create(UrlTileSource tileSource) {
|
||||
return engine;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package org.oscim.tiling.source.oscimap4;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
@ -7,8 +9,7 @@ import org.oscim.tiling.ITileDataSource;
|
||||
import org.oscim.tiling.source.HttpEngine;
|
||||
import org.oscim.tiling.source.LwHttp;
|
||||
import org.oscim.tiling.source.OkHttpEngine;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import org.oscim.tiling.source.UrlTileSource;
|
||||
|
||||
public class OSciMap4TileSourceTest {
|
||||
private OSciMap4TileSource tileSource;
|
||||
@ -42,7 +43,8 @@ public class OSciMap4TileSourceTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test factory that allows the specific {@link HttpEngine} instance to be set.
|
||||
* Test factory that allows the specific {@link HttpEngine} instance to be
|
||||
* set.
|
||||
*/
|
||||
class TestHttpFactory implements HttpEngine.Factory {
|
||||
final HttpEngine engine;
|
||||
@ -52,7 +54,7 @@ public class OSciMap4TileSourceTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpEngine create() {
|
||||
public HttpEngine create(UrlTileSource tileSource) {
|
||||
return engine;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user