Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cancelled work on AudioStreamTest until we really need it, pulled up …

…utility methods to HttpServer
  • Loading branch information...
commit 5b180ecb68004d1251cf700e829676e0d2c22146 1 parent 06e833d
@tindandelion authored
View
20 Radio-T-Test/src/org/dandelion/radiot/helpers/HttpServer.java
@@ -1,16 +1,34 @@
package org.dandelion.radiot.helpers;
+import org.dandelion.radiot.integration.helpers.NotificationTrace;
+import org.hamcrest.Matcher;
+
import java.io.File;
import java.io.IOException;
+import java.util.Properties;
-public class HttpServer extends NanoHTTPD {
+public abstract class HttpServer extends NanoHTTPD {
public static int PORT = 32768;
+ protected NotificationTrace<String> requests;
public HttpServer() throws IOException {
super(PORT, new File(""));
+ this.requests = new NotificationTrace<String>();
}
public static String addressForUrl(String part) {
return String.format("http://localhost:%d", PORT) + part;
}
+
+ public void hasReceivedRequest(Matcher<String> matcher) throws InterruptedException {
+ requests.containsNotification(matcher);
+ }
+
+ protected abstract Response serveUri(String uri);
+
+ @Override
+ public Response serve(String uri, String method, Properties header, Properties parms, Properties files) {
+ requests.append(uri);
+ return serveUri(uri);
+ }
}
View
71 Radio-T-Test/src/org/dandelion/radiot/integration/AudioStreamTest.java
@@ -1,71 +0,0 @@
-package org.dandelion.radiot.integration;
-
-import android.test.InstrumentationTestCase;
-import org.dandelion.radiot.integration.helpers.LiveStreamServer;
-import org.dandelion.radiot.integration.helpers.NotificationTrace;
-import org.dandelion.radiot.live.MediaPlayerStream;
-import org.dandelion.radiot.live.core.AudioStream;
-
-import java.io.IOException;
-
-import static org.hamcrest.CoreMatchers.equalTo;
-
-public class AudioStreamTest extends InstrumentationTestCase {
- private LiveStreamServer backend;
-
- public void testWhenStartingPlayback_ShouldRequestStreamFromServer() throws Exception {
- AudioStream stream = new MediaPlayerStream(LiveStreamServer.DIRECT_URL);
- MyListener listener = new MyListener();
- stream.setStateListener(listener);
- startPlayback(stream);
- backend.hasReceivedRequest(equalTo(LiveStreamServer.DIRECT_RESOURCE));
- listener.hasStarted();
- }
-
- private void startPlayback(final AudioStream stream) {
- getInstrumentation().runOnMainSync(new Runnable() {
- @Override
- public void run() {
- try {
- stream.play();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- });
-
- }
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- backend = new LiveStreamServer(getInstrumentation().getContext());
- }
-
- @Override
- public void tearDown() throws Exception {
- backend.stop();
- super.tearDown();
- }
-
- private static class MyListener implements AudioStream.Listener {
- private NotificationTrace<String> messages = new NotificationTrace<String>(30000);
-
- @Override
- public void onStarted() {
- messages.append("onStarted");
- }
-
- @Override
- public void onError() {
- }
-
- @Override
- public void onStopped() {
- }
-
- public void hasStarted() throws InterruptedException {
- messages.containsNotification(equalTo("onStarted"));
- }
- }
-}
View
6 Radio-T-Test/src/org/dandelion/radiot/integration/HttpServerTest.java
@@ -8,7 +8,8 @@
import org.dandelion.radiot.helpers.HttpServer;
import java.io.IOException;
-import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.equalTo;
public class HttpServerTest extends TestCase {
public static final String URL = HttpServer.addressForUrl("/");
@@ -17,6 +18,7 @@
public void testExecuteGetRequest() throws Exception {
HttpResponse response = client.execute(new HttpGet(URL));
+ server.hasReceivedRequest(equalTo("/"));
assertEquals(200, response.getStatusLine().getStatusCode());
}
@@ -47,7 +49,7 @@ public MyHttpServer() throws IOException {
}
@Override
- public Response serve(String uri, String method, Properties header, Properties parms, Properties files) {
+ protected Response serveUri(String uri) {
return new Response(HTTP_OK, MIME_HTML, BODY_TEXT);
}
}
View
10 Radio-T-Test/src/org/dandelion/radiot/integration/helpers/LiveStreamServer.java
@@ -2,11 +2,9 @@
import android.content.Context;
import org.dandelion.radiot.helpers.HttpServer;
-import org.hamcrest.Matcher;
import java.io.IOException;
import java.io.InputStream;
-import java.util.Properties;
public class LiveStreamServer extends HttpServer {
public static final String REDIRECT_RESOURCE = "/stream";
@@ -14,17 +12,14 @@
public static final String REDIRECT_URL = HttpServer.addressForUrl(REDIRECT_RESOURCE);
public static final String DIRECT_URL = HttpServer.addressForUrl(DIRECT_RESOURCE);
private Context context;
- private NotificationTrace<String> requests;
public LiveStreamServer(Context context) throws IOException {
super();
this.context = context;
- this.requests = new NotificationTrace<String>();
}
@Override
- public Response serve(String uri, String method, Properties header, Properties parms, Properties files) {
- requests.append(uri);
+ protected Response serveUri(String uri) {
if (uri.equals(REDIRECT_RESOURCE)) {
return redirectToStream();
}
@@ -52,7 +47,4 @@ private Response redirectToStream() {
return response;
}
- public void hasReceivedRequest(Matcher<String> matcher) throws InterruptedException {
- requests.containsNotification(matcher);
- }
}
Please sign in to comment.
Something went wrong with that request. Please try again.