// Path: action/src/main/java/io/cettia/asity/action/Action.java
// @FunctionalInterface
// public interface Action<T> {
// 
//   /**
//    * Some action is taken.
//    */
//   void on(T object);
// 
// }
// 
// Path: websocket/src/main/java/io/cettia/asity/websocket/ServerWebSocket.java
// public interface ServerWebSocket {
// 
//   /**
//    * The URI used to connect.
//    */
//   String uri();
// 
//   /**
//    * The names of the handshake request headers. HTTP header is not case-sensitive
//    * but {@link Set} is case-sensitive.
//    */
//   Set<String> headerNames();
// 
//   /**
//    * Returns the first handshake request header associated with the given name.
//    */
//   String header(String name);
// 
//   /**
//    * Returns the handshake request headers associated with the given name or empty list
//    * if no header is found.
//    */
//   List<String> headers(String name);
// 
//   /**
//    * Closes the connection. This method has no side effect if called more than
//    * once.
//    */
//   void close();
// 
//   /**
//    * Sends a text frame through the connection.
//    */
//   ServerWebSocket send(String data);
// 
//   /**
//    * Sends a binary frame through the connection.
//    */
//   ServerWebSocket send(ByteBuffer byteBuffer);
// 
//   /**
//    * Attaches an action for the text frame.
//    */
//   ServerWebSocket ontext(Action<String> action);
// 
//   /**
//    * Attaches an action for the binary frame.
//    */
//   ServerWebSocket onbinary(Action<ByteBuffer> action);
// 
//   /**
//    * Attaches an action for the close event. After this event, the instance
//    * shouldn't be used and all the other events will be disabled.
//    */
//   ServerWebSocket onclose(Action<Void> action);
// 
//   /**
//    * Attaches an action to handle error from various things. Its exact
//    * behavior is platform-specific and error created by the platform is
//    * propagated.
//    */
//   ServerWebSocket onerror(Action<Throwable> action);
// 
//   /**
//    * Returns the provider-specific component.
//    */
//   <T> T unwrap(Class<T> clazz);
// 
// }


import java.net.ServerSocket;
import java.net.URI;
import java.nio.ByteBuffer;
import java.util.Arrays;
import io.cettia.asity.action.Action;
import io.cettia.asity.websocket.ServerWebSocket;
import net.jodah.concurrentunit.ConcurrentTestCase;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.api.WebSocketListener;
import org.eclipse.jetty.websocket.api.WriteCallback;
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
/*
 * Copyright 2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.cettia.asity.test;



/**
 * @author Donghwan Kim
 */
public abstract class ServerWebSocketTestBase extends ConcurrentTestCase {

  public static final String TEST_PATH = "/websocket";
  private static final WebSocketListener NOOP = new WebSocketAdapter();
  private static final WriteCallback ASYNC = new WriteCallback() {
    @Override
    public void writeSuccess() {
    }

    @Override
    public void writeFailed(Throwable throwable) {
    }
  };

  @Rule
  public Timeout globalTimeout = Timeout.seconds(60);
  protected WebSocketClient client = new WebSocketClient();

  private int port;
// Path: action/src/main/java/io/cettia/asity/action/Action.java
// @FunctionalInterface
// public interface Action<T> {
// 
//   /**
//    * Some action is taken.
//    */
//   void on(T object);
// 
// }
// 
// Path: websocket/src/main/java/io/cettia/asity/websocket/ServerWebSocket.java
// public interface ServerWebSocket {
// 
//   /**
//    * The URI used to connect.
//    */
//   String uri();
// 
//   /**
//    * The names of the handshake request headers. HTTP header is not case-sensitive
//    * but {@link Set} is case-sensitive.
//    */
//   Set<String> headerNames();
// 
//   /**
//    * Returns the first handshake request header associated with the given name.
//    */
//   String header(String name);
// 
//   /**
//    * Returns the handshake request headers associated with the given name or empty list
//    * if no header is found.
//    */
//   List<String> headers(String name);
// 
//   /**
//    * Closes the connection. This method has no side effect if called more than
//    * once.
//    */
//   void close();
// 
//   /**
//    * Sends a text frame through the connection.
//    */
//   ServerWebSocket send(String data);
// 
//   /**
//    * Sends a binary frame through the connection.
//    */
//   ServerWebSocket send(ByteBuffer byteBuffer);
// 
//   /**
//    * Attaches an action for the text frame.
//    */
//   ServerWebSocket ontext(Action<String> action);
// 
//   /**
//    * Attaches an action for the binary frame.
//    */
//   ServerWebSocket onbinary(Action<ByteBuffer> action);
// 
//   /**
//    * Attaches an action for the close event. After this event, the instance
//    * shouldn't be used and all the other events will be disabled.
//    */
//   ServerWebSocket onclose(Action<Void> action);
// 
//   /**
//    * Attaches an action to handle error from various things. Its exact
//    * behavior is platform-specific and error created by the platform is
//    * propagated.
//    */
//   ServerWebSocket onerror(Action<Throwable> action);
// 
//   /**
//    * Returns the provider-specific component.
//    */
//   <T> T unwrap(Class<T> clazz);
// 
// }


// Path: test/src/main/java/io/cettia/asity/test/ServerWebSocketTestBase.java
import java.net.ServerSocket;
import java.net.URI;
import java.nio.ByteBuffer;
import java.util.Arrays;
import io.cettia.asity.action.Action;
import io.cettia.asity.websocket.ServerWebSocket;
import net.jodah.concurrentunit.ConcurrentTestCase;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
import org.eclipse.jetty.websocket.api.WebSocketListener;
import org.eclipse.jetty.websocket.api.WriteCallback;
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;

/*
 * Copyright 2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.cettia.asity.test;



/**
 * @author Donghwan Kim
 */
public abstract class ServerWebSocketTestBase extends ConcurrentTestCase {

  public static final String TEST_PATH = "/websocket";
  private static final WebSocketListener NOOP = new WebSocketAdapter();
  private static final WriteCallback ASYNC = new WriteCallback() {
    @Override
    public void writeSuccess() {
    }

    @Override
    public void writeFailed(Throwable throwable) {
    }
  };

  @Rule
  public Timeout globalTimeout = Timeout.seconds(60);
  protected WebSocketClient client = new WebSocketClient();

  private int port;
  private Action<ServerWebSocket> websocketAction;