package at.fhj.itm.beans;
import static org.junit.Assert.fail;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import at.fhj.itm.business.ServiceTrip;
import at.fhj.itm.model.Location;
import at.fhj.itm.model.Trip;
import at.fhj.itm.model.User;
import at.fhj.itm.model.Waypoint;
import at.fhj.itm.util.JsfUtilImpl;
/**
*
* @author Christian Tassler
* @author Patrick Winkelmayer
*/
public class SearchTripTest {
List<Trip> mockTrips;
User mockUser;
@Before
public void setup() {
Location a = new Location(8605, "Kapfenberg");
Location b = new Location(8010, "Graz");
Location c = new Location(1020, "Wien");
Location d = new Location(5030, "Salzburg");
User u = new User(-1, "Bert", "Beutel", "bertBeut", "12345",
"bert.beutel@local.at", "004312345678", a, new Date(),
"qweiurioewhu");
User v = new User(-1, "Klara", "Klaustaler", "KK", "12345",
"k.k@local.at", "004312345678", b, new Date(), "nsvjdna");
Waypoint ab = new Waypoint(a, b, u, "", true);
Waypoint ba = new Waypoint(b, a, u, "", true);
Waypoint bc = new Waypoint(b, c, v, "", true);
Waypoint ac = new Waypoint(a, c, v, "", true);
Waypoint cd = new Waypoint(c, d, v, "", true);
Trip trip0 = new Trip(v, new Date(), 5, ab, "");
Trip trip1 = new Trip(v, new Date(), 4, bc, "");
Trip trip2 = new Trip(v, new Date(), 4, ac, "");
Trip trip3 = new Trip(v, new Date(), 5, cd, "");
Trip trip4 = new Trip(u, new Date(), 5, ba, "");
mockTrips = Arrays.asList(trip0, trip1, trip2, trip3, trip4);
mockUser = u;
}
@Test
public void testFrom() {
SearchTrip a = new SearchTrip(new JsfUtilImpl(), EasyMock.createMock(ServiceTrip.class));
Assert.assertNull(a.getFrom());
a.setFrom("Foo");
Assert.assertEquals("Foo", a.getFrom());
}
@Test
public void testTo() {
SearchTrip a = new SearchTrip(new JsfUtilImpl(), EasyMock.createMock(ServiceTrip.class));
Assert.assertNull(a.getTo());
a.setTo("Foo");
Assert.assertEquals("Foo", a.getTo());
}
@Test
public void testTime() {
SearchTrip a = new SearchTrip(new JsfUtilImpl(), EasyMock.createMock(ServiceTrip.class));
Assert.assertNotNull(a.getDate());
a.setDate(new Date(1234));
Assert.assertEquals(new Date(1234), a.getDate());
a.setLeaveTime(false);
Assert.assertFalse(a.isLeaveTime());
a.setLeaveTime(true);
Assert.assertTrue(a.isLeaveTime());
a.setTime("08:10");
Assert.assertEquals("08:10", a.getTime());
Assert.assertEquals(8, a.getDate().getHours());
Assert.assertEquals(10, a.getDate().getMinutes());
}
// @Test
// public void testGetMatchesNoData() {
// JsfUtil mockJsfUtils = new JsfUtil() {
// @Override
// public void redirect(String url) throws IOException {
// }
//
// @Override
// public Map<String, String> getRequestParameterMap() {
// return Collections.emptyMap();
// }
//
// @Override
// public Login getLoginBean() {
// return null;
// }
//
// };
// SearchTrip a = new SearchTrip();
//
// Assert.assertSame(Collections.EMPTY_LIST, a.getMatches());
//
// }
@Test
public void testGetMatchesUsingUrl() {
fail("Not yet implemented");
}
@Test
public void testGetMatchesUsingFields() {
fail("Not yet implemented");
}
@Test
public void testGetUrlForSearchResult() throws ParseException {
SearchTrip a = new SearchTrip(new JsfUtilImpl(), EasyMock.createMock(ServiceTrip.class));
a.setFrom("foo");
a.setTo("boo");
Date date = new Date(12345);
a.setLeaveAt(a.getDateFormatForURL().format(date));
String url = a.getAllInSearchUrl();
Assert.assertTrue(url.startsWith("./foundTrips.jsf"));
Assert.assertTrue(url.contains("from=foo"));
Assert.assertTrue(url.contains("to=boo"));
Assert.assertTrue(url.contains("leaveAt=01.01.70 01:00"));
Assert.assertFalse(url.contains("arriveAt"));
a.setArriveAt(a.getDateFormatForURL().format(date));
url = a.getAllInSearchUrl();
Assert.assertTrue(url.startsWith("./foundTrips.jsf"));
Assert.assertTrue(url.contains("from=foo"));
Assert.assertTrue(url.contains("to=boo"));
Assert.assertTrue(url.contains("arriveAt=01.01.70 01:00"));
Assert.assertFalse(url.contains("leaveAt"));
}
}