01: /*--------------------------------------------------------------------------*
02: | Copyright (C) 2006 Christopher Kohlhaas |
03: | |
04: | This program is free software; you can redistribute it and/or modify |
05: | it under the terms of the GNU General Public License as published by the |
06: | Free Software Foundation. A copy of the license has been included with |
07: | these distribution in the COPYING file, if not go to www.fsf.org |
08: | |
09: | As a special exception, you are granted the permissions to link this |
10: | program with every library, which license fulfills the Open Source |
11: | Definition as published by the Open Source Initiative (OSI). |
12: *--------------------------------------------------------------------------*/
13: package org.rapla.plugin.tests;
14:
15: import java.util.Collections;
16: import java.util.Locale;
17:
18: import org.rapla.RaplaTestCase;
19: import org.rapla.entities.domain.Allocatable;
20: import org.rapla.entities.domain.Period;
21: import org.rapla.entities.domain.Reservation;
22: import org.rapla.entities.dynamictype.ClassificationFilter;
23: import org.rapla.facade.ClientFacade;
24: import org.rapla.gui.internal.common.CalendarModelImpl;
25: import org.rapla.gui.internal.common.CalendarSelectionModel;
26: import org.rapla.plugin.periodcopy.CopyPluginInit;
27:
28: /** listens for allocation changes */
29: public class CopyPeriodPluginTest extends RaplaTestCase {
30: ClientFacade facade;
31: Locale locale;
32:
33: public CopyPeriodPluginTest(String name) {
34: super (name);
35: }
36:
37: protected void setUp() throws Exception {
38: super .setUp();
39: facade = (ClientFacade) getContext().lookup(
40: ClientFacade.ROLE + "/local-facade");
41: facade.login("homer", "duffs".toCharArray());
42: locale = Locale.getDefault();
43: }
44:
45: private Reservation findReservationWithName(
46: Reservation[] reservations, String name) {
47: for (int i = 0; i < reservations.length; i++) {
48: if (reservations[i].getName(locale).equals(name)) {
49: return reservations[i];
50: }
51: }
52: return null;
53: }
54:
55: public void test() throws Exception {
56: CalendarSelectionModel model = new CalendarModelImpl(
57: getClientService().getContext());
58: ClassificationFilter filter = facade.getDynamicType("room")
59: .newClassificationFilter();
60: filter.addEqualsRule("name", "erwin");
61: Allocatable allocatable = facade
62: .getAllocatables(new ClassificationFilter[] { filter })[0];
63: model
64: .setSelectedObjects(Collections
65: .singletonList(allocatable));
66:
67: Period[] periods = facade.getPeriods();
68: Period sourcePeriod = null;
69: Period destPeriod = null;
70: for (int i = 0; i < periods.length; i++) {
71: if (periods[i].getName().equals("SS 2002")) {
72: sourcePeriod = periods[i];
73: }
74: if (periods[i].getName().equals("SS 2001")) {
75: destPeriod = periods[i];
76: }
77: }
78: assertNotNull("Period not found ", sourcePeriod);
79: assertNotNull("Period not found ", destPeriod);
80: CopyPluginInit init = new CopyPluginInit(getClientService()
81: .getContext());
82: Reservation[] original = model.getReservations(sourcePeriod
83: .getStart(), sourcePeriod.getEnd());
84: assertNotNull(findReservationWithName(original,
85: "power planting"));
86: init.copy(model, sourcePeriod, destPeriod);
87:
88: Reservation[] copy = model.getReservations(destPeriod
89: .getStart(), destPeriod.getEnd());
90: assertNotNull(findReservationWithName(copy, "power planting"));
91:
92: }
93: }
|