http api/service: switch to okhttp
okhttp has websocket support and http/2 support
This commit is contained in:
@@ -24,14 +24,14 @@
|
||||
*/
|
||||
package net.runelite.http.service.hiscore;
|
||||
|
||||
import java.net.URI;
|
||||
import java.io.IOException;
|
||||
import net.runelite.http.api.hiscore.HiscoreResult;
|
||||
import net.runelite.http.service.HttpClient;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Matchers;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class HiscoreServiceTest
|
||||
{
|
||||
@@ -69,15 +69,27 @@ public class HiscoreServiceTest
|
||||
+ "-1,-1\n"
|
||||
+ "-1,-1";
|
||||
|
||||
private final MockWebServer server = new MockWebServer();
|
||||
|
||||
@Before
|
||||
public void before() throws IOException
|
||||
{
|
||||
server.enqueue(new MockResponse().setBody(RESPONSE));
|
||||
|
||||
server.start();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() throws IOException
|
||||
{
|
||||
server.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookup() throws Exception
|
||||
{
|
||||
HttpClient client = mock(HttpClient.class);
|
||||
when(client.get(Matchers.any(URI.class)))
|
||||
.thenReturn(RESPONSE);
|
||||
|
||||
HiscoreService hiscores = new HiscoreService();
|
||||
hiscores.setClient(client);
|
||||
hiscores.setUrl(server.url("/"));
|
||||
|
||||
HiscoreResult result = hiscores.lookup("zezima");
|
||||
|
||||
|
||||
@@ -26,37 +26,45 @@ package net.runelite.http.service.worlds;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import net.runelite.http.api.worlds.WorldResult;
|
||||
import net.runelite.http.service.HttpClient;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okio.Buffer;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Matchers;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import spark.utils.IOUtils;
|
||||
|
||||
public class WorldsServiceTest
|
||||
{
|
||||
private byte[] worldData;
|
||||
private final MockWebServer server = new MockWebServer();
|
||||
|
||||
@Before
|
||||
public void before() throws IOException
|
||||
{
|
||||
InputStream in = WorldsServiceTest.class.getResourceAsStream("worldlist");
|
||||
worldData = IOUtils.toByteArray(in);
|
||||
byte[] worldData = IOUtils.toByteArray(in);
|
||||
|
||||
Buffer buffer = new Buffer();
|
||||
buffer.write(worldData);
|
||||
|
||||
server.enqueue(new MockResponse().setBody(buffer));
|
||||
|
||||
server.start();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() throws IOException
|
||||
{
|
||||
server.shutdown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListWorlds() throws Exception
|
||||
{
|
||||
HttpClient client = mock(HttpClient.class);
|
||||
when(client.getBytes(Matchers.any(URI.class)))
|
||||
.thenReturn(worldData);
|
||||
|
||||
WorldsService worlds = new WorldsService();
|
||||
worlds.setClient(client);
|
||||
worlds.setUrl(server.url("/"));
|
||||
|
||||
WorldResult worldResult = worlds.listWorlds();
|
||||
Assert.assertEquals(82, worldResult.getWorlds().size());
|
||||
|
||||
Reference in New Issue
Block a user