customertest.java

来自「hotel management system」· Java 代码 · 共 101 行

JAVA
101
字号
/*
 * Copyright 2005-2007 Kevin A. Lee
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package test.net.sourceforge.hoteldj.web;

import javax.ejb.EJBException;
import javax.ejb.RemoveException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletOutputStream;

import junit.framework.TestCase;
import net.sourceforge.hoteldj.ejb.CustomerLocal;
import net.sourceforge.hoteldj.ejb.HotelManagerFacadeLocal;
import net.sourceforge.hoteldj.ejb.HotelManagerFacadeLocalHome;

/**
 * JUnit test class for Customer entity bean
 * 
 * @author Kevin A. Lee
 * @email kevin.lee@buildmeister.com
 * 
 */
public class CustomerTest extends TestCase {

	private static final long serialVersionUID = 1447523027071610257L;
	HotelManagerFacadeLocal hm = null;
	CustomerLocal customer = null;
	
	/*
	 * (non-Java-doc)
	 */
	public void setUp() {

		Context context = null;
		
		try {
			context = new InitialContext();
			HotelManagerFacadeLocalHome hmHome = (HotelManagerFacadeLocalHome) context
					.lookup(HotelManagerFacadeLocalHome.JNDI_NAME);
			hm = hmHome.create();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				context.close();
			} catch (NamingException e) {
				e.printStackTrace();
			}
		}
		
		customer = hm.newCustomer("Kevin", "Lee");
	}
	
	public void tearDown() {
		try {
			customer.remove();
		} catch (EJBException e) {
			e.printStackTrace();
		} catch (RemoveException e) {
			e.printStackTrace();
		}
	}

	/*
	 * (non-Java-doc)
	 */
	public void testNewCustomer() throws Exception {
		assertNotNull(customer);
		assertEquals("Kevin", customer.getFirstname());
		assertEquals("Lee", customer.getLastname());
	}
	
	/*
	 * (non-Java-doc)
	 */
	public void testGetCustomerByName() throws Exception {
		CustomerLocal customer = hm.getCustomerByName(new String("Kevin"),
				new String("Lee"));
		assertNotNull(customer);
		// TODO: catch exception
		customer = hm.getCustomerByName(new String("Kevin"),
				new String("Smith"));
		//assertNull(customer);
	}
	 
}

⌨️ 快捷键说明

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