j2semsgserviceproxytests.java
来自「cqME :java framework for TCK test.」· Java 代码 · 共 125 行
JAVA
125 行
/* * $Id$ * * Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. * */package com.sun.tck.j2me.services.messagingService.tests;import java.io.DataInputStream;import java.io.IOException;import java.net.ServerSocket;import java.net.Socket;import java.net.SocketTimeoutException;import junit.framework.Test;import junit.framework.TestCase;import junit.framework.TestSuite;import com.sun.tck.j2me.services.messagingService.J2SEMsgServiceProxy;import com.sun.tck.j2me.services.messagingService.Message;/** * JUnit tests for J2SEMsgServiceProxy * */public class J2SEMsgServiceProxyTests extends TestCase { protected void setUp() throws Exception { } protected void tearDown() throws Exception { } /** * Tests that J2SEMsgServiceProxy is not a singleton. */ public void testNonSingleton() { assertNotNull("getInstance method returns null!", J2SEMsgServiceProxy.getInstance()); assertTrue("getInstance method returns the same values!", J2SEMsgServiceProxy.getInstance() != J2SEMsgServiceProxy.getInstance()); } /** * Inits the J2SEMsgServiceProxy with particular Socket, * calls exchangeMessages * waits for connection * and checks that some data was transfered * */ public void testsWorking() { final J2SEMsgServiceProxy proxy = J2SEMsgServiceProxy.getInstance(); try { final ServerSocket service = new ServerSocket(0); service.setSoTimeout(10000); final int portNumber = service.getLocalPort(); new Thread() { public void run() { try { proxy.init("localhost:" + portNumber); proxy.exchangeMessages("from", new Message[] { new Message ( 1, "message_from", "message_to", new String[] { "args" }) } ); } catch (IOException e) { e.printStackTrace(); } finally { proxy.close(); } } }.start(); Socket serviceSocket = service.accept(); serviceSocket.setSoTimeout(10000); DataInputStream input = new DataInputStream(serviceSocket.getInputStream()); byte[] data = new byte[1]; // check that some data were transfered input.readFully(data); } catch (SocketTimeoutException e) { fail("Data is not received" + e); } catch (IOException e) { System.out.println(e); } } public static Test suite() { return new TestSuite(J2SEMsgServiceProxyTests.class, "J2SEMsgServiceProxy Tests"); } /** * @param args */ public static void main(String[] args) { junit.textui.TestRunner.run(J2SEMsgServiceProxyTests.class); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?