portfoliohandlertest.java.svn-base

来自「rmi server web service for a stock track」· SVN-BASE 代码 · 共 64 行

SVN-BASE
64
字号
package ase.assignment.sts.test;

import java.rmi.RemoteException;

import junit.framework.TestCase;
import ase.assignment.sts.api.HandlerFactoryProxy;
import ase.assignment.sts.api.PortfolioHandler;
import ase.assignment.sts.beans.PortfolioEntity;

public class PortfolioHandlerTest extends TestCase {
	private static final int PORTFOLIO_TEST_ID = 88;

	private PortfolioHandler getHandler() throws RemoteException {
		return HandlerFactoryProxy.instance().getPortfolioHandler();
	}

	public void testCreate() throws RemoteException {
		assertNull(getHandler().findById(PORTFOLIO_TEST_ID));

		PortfolioEntity entity = new PortfolioEntity(PORTFOLIO_TEST_ID);
		entity.setName("testName");
		entity.setCustomerName("test");
		getHandler().create(entity);
		assertNotNull(getHandler().findById(PORTFOLIO_TEST_ID));
	}

	public void testDelete() throws RemoteException {
		assertNotNull(getHandler().findById(PORTFOLIO_TEST_ID));
		getHandler().delete(PORTFOLIO_TEST_ID);
		assertNull(getHandler().findById(PORTFOLIO_TEST_ID));
	}

	public void testUpdate() throws RemoteException {
		PortfolioEntity entity = getHandler().findById(1);
		assertNotNull(entity);
		assertEquals("Software", entity.getName());

		entity.setName("port2");
		getHandler().update(entity);
		entity = getHandler().findById(1);
		assertEquals("port2", entity.getName());

		// Rollback
		entity.setName("Software");
		getHandler().update(entity);
	}

	public void testFind() throws RemoteException {
		PortfolioEntity entity = getHandler().findById(1);
		assertNotNull(entity);
		assertEquals("Software", entity.getName());
		assertEquals("test", entity.getCustomerName());
	}

	public void testGetAllPortfolios() throws RemoteException {
		PortfolioEntity[] pors = getHandler().getAllPortfolios("test");
		assertNotNull(pors);
		assertEquals(2, pors.length);
		for (int i = 0; i < pors.length; i++) {
			assertEquals("test", pors[i].getCustomerName());
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?