org.apache.mina.core.service.DefaultTransportMetadata Java Examples

The following examples show how to use org.apache.mina.core.service.DefaultTransportMetadata. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FrameDecoderTest.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
protected void testFrames ( final String resourceName, final Frame... expectedFrames ) throws Exception
{
    final FrameDecoder decoder = new FrameDecoder ();
    final MockProtocolDecoderOutput out = new MockProtocolDecoderOutput ();
    final DummySession session = new DummySession ();

    session.setTransportMetadata ( new DefaultTransportMetadata ( "eclipse.scada", "test", false, true, SocketAddress.class, IoSessionConfig.class, Object.class ) );

    for ( final IoBuffer data : BufferLoader.loadBuffersFromResource ( FrameDecoderTest.class, resourceName ) )
    {
        System.out.println ( "Pushing data packet - " + data.getHexDump () );
        decoder.decode ( session, data, out );
    }

    out.assertMessages ( expectedFrames );
}
 
Example #2
Source File: GameProtocolCodecFilterTest.java    From gameserver with Apache License 2.0 5 votes vote down vote up
private void encodeAndDecodeProxyMessage(XinqiProxyMessage response, boolean checkDecoder) throws Exception {
	ProtobufEncoder encoder = new ProtobufEncoder();
	ProtobufDecoder decoder = new ProtobufDecoder();
	final ArrayList<Object> results = new ArrayList<Object>();
	
	IoSession session = createNiceMock(IoSession.class);
	expect(session.getTransportMetadata()).andReturn(
			new DefaultTransportMetadata("testprovider", "default", 
					false, true, InetSocketAddress.class, DefaultSocketSessionConfig.class, 
					SessionMessage.class)).anyTimes();
	
	IoBuffer buffer = (IoBuffer)ProtobufEncoder.encodeXinqiProxyMessage(response);
	
	ProtocolDecoderOutput deout = createNiceMock(ProtocolDecoderOutput.class);
	if ( checkDecoder ) {
		deout.write(anyObject());
		expectLastCall().andAnswer(new IAnswer<Object>() {
			@Override
			public Object answer() throws Throwable {
				results.add(getCurrentArguments()[0]);
				return null;
			}
		}).times(1);
	}
	
	replay(session);
	replay(deout);
	
	decoder.decode(session, buffer, deout);
	
	verify(session);
	verify(deout);
	
	if ( checkDecoder ) {
		XinqiProxyMessage decodeMsg = (XinqiProxyMessage)results.get(0);
		assertEquals(response.userSessionKey, decodeMsg.userSessionKey);
		assertEquals(response.xinqi.payload.getClass(), decodeMsg.xinqi.payload.getClass());
	}
}
 
Example #3
Source File: AIProtocolCodecFilterTest.java    From gameserver with Apache License 2.0 4 votes vote down vote up
private SessionAIMessage encodeAndDecode(SessionAIMessage sessionMessage) throws Exception {
	
	AIProtobufEncoder encoder = new AIProtobufEncoder();
	AIProtobufDecoder decoder = new AIProtobufDecoder();
	final ArrayList<Object> results = new ArrayList<Object>();
	
	IoSession session = createNiceMock(IoSession.class);
	expect(session.getTransportMetadata()).andReturn(
			new DefaultTransportMetadata("testprovider", "default", 
					false, true, InetSocketAddress.class, DefaultSocketSessionConfig.class, 
					SessionMessage.class)).anyTimes();
	
	ProtocolEncoderOutput out = createNiceMock(ProtocolEncoderOutput.class);
	out.write(anyObject());
	expectLastCall().andAnswer(new IAnswer<Object>() {
		@Override
		public Object answer() throws Throwable {
			results.add(getCurrentArguments()[0]);
			return null;
		}
	}).anyTimes();
	
	replay(session);
	replay(out);
	
	encoder.encode(session, sessionMessage, out);
	
	verify(session);
	verify(out);
	
	assertTrue(results.get(0) instanceof IoBuffer );
	
	IoBuffer buffer = (IoBuffer)results.get(0);
	results.remove(0);
	
	ProtocolDecoderOutput deout = createNiceMock(ProtocolDecoderOutput.class);
	deout.write(anyObject());
	expectLastCall().andAnswer(new IAnswer<Object>() {
		@Override
		public Object answer() throws Throwable {
			results.add(getCurrentArguments()[0]);
			return null;
		}
	}).times(1);
	replay(deout);
	
	decoder.decode(session, buffer, deout);
	
	verify(deout);
	
	SessionAIMessage decodeMsg = (SessionAIMessage)results.get(0);
	return decodeMsg;
}
 
Example #4
Source File: GameProtocolCodecFilterTest.java    From gameserver with Apache License 2.0 4 votes vote down vote up
private void encodeAndDecode(XinqiMessage response, boolean checkDecoder) throws Exception {
	ProtobufEncoder encoder = new ProtobufEncoder();
	ProtobufDecoder decoder = new ProtobufDecoder();
	final ArrayList<Object> results = new ArrayList<Object>();
	
	IoSession session = createNiceMock(IoSession.class);
	expect(session.getTransportMetadata()).andReturn(
			new DefaultTransportMetadata("testprovider", "default", 
					false, true, InetSocketAddress.class, DefaultSocketSessionConfig.class, 
					SessionMessage.class)).anyTimes();
	
	ProtocolEncoderOutput out = createNiceMock(ProtocolEncoderOutput.class);
	out.write(anyObject());
	expectLastCall().andAnswer(new IAnswer<Object>() {
		@Override
		public Object answer() throws Throwable {
			results.add(getCurrentArguments()[0]);
			return null;
		}
	});
	
	replay(session);
	replay(out);
	
	encoder.encode(session, response, out);
	
	verify(session);
	verify(out);
	
	assertTrue(results.get(0) instanceof IoBuffer );
	
	IoBuffer buffer = (IoBuffer)results.get(0);
	results.remove(0);
	
	ProtocolDecoderOutput deout = createNiceMock(ProtocolDecoderOutput.class);
	if ( checkDecoder ) {
		deout.write(anyObject());
		expectLastCall().andAnswer(new IAnswer<Object>() {
			@Override
			public Object answer() throws Throwable {
				results.add(getCurrentArguments()[0]);
				return null;
			}
		}).times(1);
	}
	replay(deout);
	
	decoder.decode(session, buffer, deout);
	
	verify(deout);
	
	if ( checkDecoder ) {
		XinqiMessage decodeMsg = (XinqiMessage)results.get(0);
		assertEquals(response.payload.getClass(), decodeMsg.payload.getClass());
	}
}