Package de.timefinder.core.io.xml

Source Code of de.timefinder.core.io.xml.AbstractIOTester

/*
*  Copyright 2009 Peter Karich, peat_hal ‘at’ users ‘dot’ sourceforge ‘dot’ net.
*
*  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.
*  under the License.
*/
package de.timefinder.core.io.xml;

import de.timefinder.algo.constraint.DifferentDayConstraint;
import de.timefinder.algo.constraint.EventOrderConstraint;
import de.timefinder.algo.constraint.MinGapsConstraint;
import de.timefinder.algo.constraint.PersonITCRasterConstraint;
import de.timefinder.algo.constraint.RasterConstraint;
import de.timefinder.algo.util.TimeFinder2Tester;
import de.timefinder.core.io.text.ObjectParsing;
import de.timefinder.data.Event;
import de.timefinder.data.Feature;
import de.timefinder.data.Location;
import de.timefinder.data.Person;
import de.timefinder.data.Role;
import de.timefinder.data.set.RasterEnum;
import de.timefinder.data.set.WeekRaster;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.text.ParseException;
import java.util.Arrays;

/**
* @author Peter Karich, peat_hal ‘at’ users ‘dot’ sourceforge ‘dot’ net
*/
public class AbstractIOTester extends TimeFinder2Tester {

    protected Event ev1;
    protected Event ev2;
    protected Event ev3;
    protected Event ev4;
    protected Person person1;
    protected Person person2;
    protected Person person3;
    protected Person person4;
    protected Location loc1;
    protected Location loc2;
    protected Location loc3;
    protected Location loc4;
    protected Feature feature1;
    protected Feature feature2;
    protected Feature feature3;
    protected Feature feature4;
    protected Writer writer;

    @Override
    public void setUp() {
        super.setUp();
        writer = new StringWriter();
        ev1 = new Event();
        ev2 = new Event();
        ev3 = new Event();
        ev4 = new Event();
        person1 = new Person();
        person2 = new Person();
        person3 = new Person();
        person4 = new Person();
        loc1 = new Location();
        loc1.setCapacity(20);
        loc2 = new Location();
        loc2.setCapacity(20);
        loc3 = new Location();
        loc3.setCapacity(20);
        loc4 = new Location();
        loc4.setCapacity(20);
        feature1 = new Feature();
        feature2 = new Feature();
        feature3 = new Feature();
        feature4 = new Feature();

        ev1.setName("event1");
        ev2.setName("event2");
        ev3.setName("event3");
        ev4.setName("event4");
        ev1.setInterval(0, 1);
        ev2.setInterval(0, 1);
        ev3.setInterval(0, 1);
        ev4.setInterval(0, 1);
        eDao.attach(ev1);
        eDao.attach(ev2);
        eDao.attach(ev3);
        eDao.attach(ev4);

        person1.setName("person1");
        person1.setDescription("description");
        try {
            person1.setBirthDay(ObjectParsing.dateTimeFormatter.parse("2009-10-01T20:10:00"));
        } catch (ParseException ex) {
            throw new RuntimeException(ex);
        }
        person2.setName("person2");
        person3.setName("person3");
        person4.setName("person4");
        pDao.attach(person1);
        pDao.attach(person2);
        pDao.attach(person3);
        pDao.attach(person4);

        loc1.setName("location1");
        loc2.setName("location2");
        loc3.setName("location3");
        loc4.setName("location4");
        lDao.attach(loc1);
        lDao.attach(loc2);
        lDao.attach(loc3);
        lDao.attach(loc4);

        feature1.setName("feature1");
        feature2.setName("feature2");
        feature3.setName("feature3");
        feature4.setName("feature4");
        fDao.attach(feature1);
        fDao.attach(feature2);
        fDao.attach(feature3);
        fDao.attach(feature4);
    }

    public void setupExport() throws IOException {
        person1.addEvent(ev1, true);
        person1.addEvent(ev2, true);
        person2.addEvent(ev3, true);
        person2.addEvent(ev4, true);
        person3.addEvent(ev3, true);
        person4.addEvent(ev1, Role.TEACHER, true);

        loc1.addEvent(ev1, true);
        loc1.addEvent(ev2, true);
        loc3.addEvent(ev4, true);
        loc4.addEvent(ev3, true);
        loc1.addFeature(feature1);
        loc4.addFeature(feature2);

        WeekRaster raster = settings.createWeekRaster();
        RasterConstraint rasterC1 = new RasterConstraint(raster);
        raster.set(1, RasterEnum.FORBIDDEN);
        raster.set(7, RasterEnum.FORBIDDEN);

        ev1.putConstraint(rasterC1);
        DifferentDayConstraint ddc = new DifferentDayConstraint(settings, Arrays.asList(ev2));
        ev1.putConstraint(ddc);

        MinGapsConstraint mgc = new MinGapsConstraint(settings, Arrays.asList(ev3));
        mgc.setCountEarly(true);
        ev1.putConstraint(mgc);

        EventOrderConstraint orderC1 = new EventOrderConstraint(ev2);
        orderC1.addBefore(ev1);
        orderC1.addFollow(ev4);
        ev2.putConstraint(orderC1);

        PersonITCRasterConstraint personRasterC1 = new PersonITCRasterConstraint(person1, settings);
        personRasterC1.setWeight(3.4f);
        person1.putConstraint(personRasterC1);

        PersonITCRasterConstraint onlyForTestC = new PersonITCRasterConstraint(person1, settings);
        onlyForTestC.setWeight(3.4f);
        ev2.putConstraint(onlyForTestC);
    }
}
TOP

Related Classes of de.timefinder.core.io.xml.AbstractIOTester

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.