/*
* CountryControllerTest.java
* JUnit based test
*
* Created on 28 July 2007, 18:39
*/
package org.spw.controller;
import junit.framework.*;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.NoResultException;
import javax.persistence.Persistence;
import javax.persistence.Query;
import org.spw.model.Country;
/**
*
* @author PSe
*/
public class CountryControllerTest extends TestCase {
public CountryControllerTest(String testName) {
super(testName);
}
protected void setUp() throws Exception {
}
protected void tearDown() throws Exception {
}
/**
* Test of getCountries method, of class org.spw.controller.CountryController.
*/
public void testGetCountries() {
System.out.println("getCountries");
CountryController instance = new CountryController();
List<Country> result = instance.getCountries();
assertNotNull(result);
assertTrue(result.size() > 0);
Country[] countries = result.toArray(new Country[0]);
//basic check that the table has the correct order
for(int i = 0; i < (countries.length-1); i++) {
assertFalse("The order by name is incorrect.", countries[i].getCountryName().
compareTo(countries[i+1].getCountryName())> 0);
}
}
/**
* Test of getCountryByName method, of class org.spw.controller.CountryController.
*/
public void testGetCountryByName() {
System.out.println("getCountryByName");
String key = "AUSTRALIA";
CountryController instance = new CountryController();
Country expResult = new Country();
expResult.setCountryCode("AU");
expResult.setCountryName("AUSTRALIA");
Country result = instance.getCountryByName(key);
assertEquals(expResult, result);
}
/**
* Test of read method, of class org.spw.controller.CountryController.
*/
public void testRead() {
System.out.println("read");
String key = "AU";
CountryController instance = new CountryController();
Country expResult = new Country();
expResult.setCountryCode("AU");
expResult.setCountryName("AUSTRALIA");
Country result = instance.read(key);
assertEquals(expResult, result);
}
}