1
0
mirror of https://github.com/jetty/jetty.project.git synced 2025-02-26 09:34:56 +00:00

Updating EventMethodsCache (and tests) for new OnWebSocketMessage annotation

This commit is contained in:
Joakim Erdfelt 2012-07-05 15:04:20 -07:00
parent c7fcb6e694
commit d163fb4414
6 changed files with 118 additions and 38 deletions
jetty-websocket/websocket-core/src
main/java/org/eclipse/jetty/websocket/api
test/java/org/eclipse/jetty/websocket

@ -274,9 +274,21 @@ public class EventMethodsCache
return true;
}
private boolean isSignatureMatch(Method method, ParamList validbinaryparams2)
private boolean isSignatureMatch(Method method, ParamList validParams)
{
// TODO Auto-generated method stub
assertIsPublicNonStatic(method);
assertIsReturn(method,Void.TYPE);
// validate parameters
Class<?> actual[] = method.getParameterTypes();
for (Class<?>[] params : validParams)
{
if (isSameParameters(actual,params))
{
return true;
}
}
return false;
}

@ -1,25 +1,15 @@
package org.eclipse.jetty.websocket.annotations;
import org.eclipse.jetty.websocket.frames.BaseFrame;
import org.eclipse.jetty.websocket.frames.TextFrame;
import org.eclipse.jetty.websocket.api.Frame;
@WebSocket
public class BadDuplicateFrameSocket
{
/**
* The most basic frame type
* The get a frame
*/
@OnWebSocketFrame
public void frameMe(BaseFrame frame)
{
/* ignore */
}
/**
* Should allow for a more specific frame type as well.
*/
@OnWebSocketFrame
public void messageMe(TextFrame frame)
public void frameMe(Frame frame)
{
/* ignore */
}
@ -28,7 +18,7 @@ public class BadDuplicateFrameSocket
* This is a duplicate frame type (should throw an exception attempting to use)
*/
@OnWebSocketFrame
public void textMe(TextFrame frame)
public void watchMe(Frame frame)
{
/* ignore */
}

@ -1,25 +1,15 @@
package org.eclipse.jetty.websocket.annotations;
import org.eclipse.jetty.websocket.frames.BaseFrame;
import org.eclipse.jetty.websocket.frames.TextFrame;
import org.eclipse.jetty.websocket.api.Frame;
@WebSocket
public class FrameSocket
{
/**
* The most basic frame type
* A frame
*/
@OnWebSocketFrame
public void frameMe(BaseFrame frame)
{
/* ignore */
}
/**
* Should allow for a more specific frame type as well.
*/
@OnWebSocketFrame
public void textMe(TextFrame frame)
public void frameMe(Frame frame)
{
/* ignore */
}

@ -14,6 +14,10 @@ import org.eclipse.jetty.websocket.annotations.NoopSocket;
import org.eclipse.jetty.websocket.annotations.NotASocket;
import org.eclipse.jetty.websocket.annotations.WebSocket;
import org.eclipse.jetty.websocket.api.samples.AdapterConnectCloseSocket;
import org.eclipse.jetty.websocket.api.samples.AnnotatedBinaryArraySocket;
import org.eclipse.jetty.websocket.api.samples.AnnotatedBinaryStreamSocket;
import org.eclipse.jetty.websocket.api.samples.AnnotatedTextSocket;
import org.eclipse.jetty.websocket.api.samples.AnnotatedTextStreamSocket;
import org.eclipse.jetty.websocket.api.samples.ListenerBasicSocket;
import org.junit.Assert;
import org.junit.Test;
@ -75,7 +79,7 @@ public class EventMethodsCacheTest
catch (InvalidWebSocketException e)
{
// Validate that we have clear error message to the developer
Assert.assertThat(e.getMessage(),containsString("Duplicate @OnWebSocketBinary declaration"));
Assert.assertThat(e.getMessage(),containsString("Duplicate @OnWebSocketMessage declaration"));
}
}
@ -95,7 +99,7 @@ public class EventMethodsCacheTest
catch (InvalidWebSocketException e)
{
// Validate that we have clear error message to the developer
Assert.assertThat(e.getMessage(),containsString("Duplicate Frame Type"));
Assert.assertThat(e.getMessage(),containsString("Duplicate @OnWebSocketFrame"));
}
}
@ -139,6 +143,48 @@ public class EventMethodsCacheTest
}
}
/**
* Test Case for socket for binary array messages
*/
@Test
public void testAnnotatedBinaryArraySocket()
{
EventMethodsCache cache = new EventMethodsCache();
EventMethods methods = cache.getMethods(AnnotatedBinaryArraySocket.class);
String classId = AnnotatedBinaryArraySocket.class.getSimpleName();
Assert.assertThat("EventMethods for " + classId,methods,notNullValue());
assertHasEventMethod(classId + ".onBinary",methods.onBinary);
assertHasEventMethod(classId + ".onClose",methods.onClose);
assertHasEventMethod(classId + ".onConnect",methods.onConnect);
assertNoEventMethod(classId + ".onException",methods.onException);
assertNoEventMethod(classId + ".onText",methods.onText);
assertNoEventMethod(classId + ".onFrame",methods.onFrame);
}
/**
* Test Case for socket for binary stream messages
*/
@Test
public void testAnnotatedBinaryStreamSocket()
{
EventMethodsCache cache = new EventMethodsCache();
EventMethods methods = cache.getMethods(AnnotatedBinaryStreamSocket.class);
String classId = AnnotatedBinaryStreamSocket.class.getSimpleName();
Assert.assertThat("EventMethods for " + classId,methods,notNullValue());
assertHasEventMethod(classId + ".onBinary",methods.onBinary);
assertHasEventMethod(classId + ".onClose",methods.onClose);
assertHasEventMethod(classId + ".onConnect",methods.onConnect);
assertNoEventMethod(classId + ".onException",methods.onException);
assertNoEventMethod(classId + ".onText",methods.onText);
assertNoEventMethod(classId + ".onFrame",methods.onFrame);
}
/**
* Test Case for no exceptions and 4 methods (3 methods from parent)
*/
@ -244,6 +290,48 @@ public class EventMethodsCacheTest
assertHasEventMethod(classId + ".onFrame",methods.onFrame);
}
/**
* Test Case for socket for simple text messages
*/
@Test
public void testAnnotatedTextSocket()
{
EventMethodsCache cache = new EventMethodsCache();
EventMethods methods = cache.getMethods(AnnotatedTextSocket.class);
String classId = AnnotatedTextSocket.class.getSimpleName();
Assert.assertThat("EventMethods for " + classId,methods,notNullValue());
assertNoEventMethod(classId + ".onBinary",methods.onBinary);
assertHasEventMethod(classId + ".onClose",methods.onClose);
assertHasEventMethod(classId + ".onConnect",methods.onConnect);
assertNoEventMethod(classId + ".onException",methods.onException);
assertHasEventMethod(classId + ".onText",methods.onText);
assertNoEventMethod(classId + ".onFrame",methods.onFrame);
}
/**
* Test Case for socket for text stream messages
*/
@Test
public void testAnnotatedTextStreamSocket()
{
EventMethodsCache cache = new EventMethodsCache();
EventMethods methods = cache.getMethods(AnnotatedTextStreamSocket.class);
String classId = AnnotatedTextStreamSocket.class.getSimpleName();
Assert.assertThat("EventMethods for " + classId,methods,notNullValue());
assertNoEventMethod(classId + ".onBinary",methods.onBinary);
assertHasEventMethod(classId + ".onClose",methods.onClose);
assertHasEventMethod(classId + ".onConnect",methods.onConnect);
assertNoEventMethod(classId + ".onException",methods.onException);
assertHasEventMethod(classId + ".onText",methods.onText);
assertNoEventMethod(classId + ".onFrame",methods.onFrame);
}
/**
* Test Case for bad declaration (duplicate OnWebSocketBinary declarations)
*/

@ -1,6 +1,5 @@
package org.eclipse.jetty.websocket.api.samples;
import java.awt.Frame;
import java.io.InputStream;
import java.io.Reader;
@ -10,6 +9,7 @@ import org.eclipse.jetty.websocket.annotations.OnWebSocketFrame;
import org.eclipse.jetty.websocket.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.annotations.WebSocket;
import org.eclipse.jetty.websocket.api.EventCapture;
import org.eclipse.jetty.websocket.api.Frame;
import org.eclipse.jetty.websocket.api.WebSocketConnection;
@WebSocket

@ -12,12 +12,6 @@ public class AnnotatedTextSocket
{
public EventCapture capture = new EventCapture();
@OnWebSocketMessage
public void onBinary(byte payload[], int offset, int length)
{
capture.add("onBinary([%d],%d,%d)",payload.length,offset,length);
}
@OnWebSocketClose
public void onClose(int statusCode, String reason)
{
@ -30,4 +24,10 @@ public class AnnotatedTextSocket
capture.add("onConnect(%s)", conn);
}
@OnWebSocketMessage
public void onText(String message)
{
capture.add("onText(%s)",capture.q(message));
}
}