package neptulon.client;

import neptulon.client.middleware.Logger;
import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;

public class NeptulonTest {
    public static final String URL = "ws://127.0.0.1:3000";

    @Test
    public void connect() throws InterruptedException {
        if (isTravis()) {
            return;
        }

        class Test {
            final String message;

            Test(String message) {
                this.message = message;
            }
        }

        Conn conn = new ConnImpl(URL);
        conn.connect();

        Thread.sleep(100);
        assertThat("Connection was not established in time.", conn.isConnected());

        conn.middleware(new Logger());

        conn.sendRequest("echo", new Test("Hello from Java client!"), new ResHandler<String>() {
            @Override
            public Class<String> getType() {
                return String.class;
            }

            @Override
            public void handler(Response<String> res) {
                System.out.println("Received response: " + res.result);
            }
        });
    }

    private boolean isTravis() {
        return System.getenv().containsKey("TRAVIS");
    }
}

@@ -221,21 +221,22 @@
  %7B%0A    p
-ublic
+rivate
  static 
@@ -405,164 +405,8 @@
  %7D%0A%0A
-        class Test %7B%0A            final String message;%0A%0A            Test(String message) %7B%0A                this.message = message;%0A            %7D%0A        %7D%0A%0A
     
@@ -464,17 +464,16 @@
 nect();%0A
-%0A
         
@@ -652,20 +652,27 @@
 o%22, new 
-Test
+EchoMessage
 (%22Hello 
@@ -1050,24 +1050,24 @@
 sTravis() %7B%0A
-
         retu
@@ -1113,11 +1113,165 @@
 );%0A    %7D
+%0A%0A    private class EchoMessage %7B%0A        final String message;%0A%0A        EchoMessage(String message) %7B%0A            this.message = message;%0A        %7D%0A    %7D
 %0A%7D%0A

reorder test members