package org.nextrtc.server;

import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.nextrtc.server.domain.signal.SignalRegistry.DefaultSignal.create;

import javax.websocket.RemoteEndpoint.Async;
import javax.websocket.Session;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.nextrtc.server.dao.Members;
import org.nextrtc.server.domain.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@ContextConfiguration(classes = Config.class)
@RunWith(SpringJUnit4ClassRunner.class)
public class NextRTCEndpointTest {

	@Autowired
	private NextRTCEndpoint endpoint;

	@Autowired
	private Members members;

	@Test
	public void shouldAutowireDependency() {
		assertNotNull(endpoint);
		assertNotNull(members);
	}

	@Test
	public void shouldAllowToExecuteRequest() throws Exception {
		// given
		Session incomming = mock(Session.class);
		Async async = mock(Async.class);
		when(incomming.getAsyncRemote()).thenReturn(async);

		endpoint.onOpen(incomming);

		// when
		endpoint.onMessage(Message.createWith(create).build(), incomming);
		endpoint.onClose(incomming);

		// then
		verify(async).sendObject(Mockito.anyObject());
		verify(incomming).close();
	}

}

@@ -441,47 +441,8 @@
 to;%0A
-import org.nextrtc.server.dao.Members;%0A
 impo
@@ -851,47 +851,8 @@
 t;%0A%0A
-%09@Autowired%0A%09private Members members;%0A%0A
 %09@Te
@@ -927,34 +927,8 @@
 t);%0A
-%09%09assertNotNull(members);%0A
 %09%7D%0A%0A
@@ -1140,16 +1140,27 @@
 sync);%0A%0A
+%0A%09%09// when%0A
 %09%09endpoi
@@ -1180,27 +1180,16 @@
 omming);
-%0A%0A%09%09// when
 %0A%09%09endpo

remove redundant line