Package com.agilebooster.data.jpa

Source Code of com.agilebooster.data.jpa.EventControllerTest

/*
* (C) Copyright 2014 Agile Booster.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     Maxime ESCOURBIAC
*/
package com.agilebooster.data.jpa;

import com.agilebooster.data.entity.Event;
import com.agilebooster.data.entity.Project;
import com.agilebooster.data.entity.Release;
import com.agilebooster.data.entity.User;
import java.util.Date;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.BeforeClass;
import org.junit.Test;

/**
* Test class for EventController.
*
* @author Maxime ESCOURBIAC
*/
public class EventControllerTest {

    private static User scrumMaster;
    private static User productOwner;
    private static User guest1;
    private static User guest2;
    private static User guest3;
    private static Project project;
    private static UserController userController;
    private static ProjectController projectController;

    /**
     * Default constructor.
     */
    public EventControllerTest() {
    }

    /**
     * Init the test environment.
     */
    @BeforeClass
    public static void initContext() {
        userController = new UserController();
        scrumMaster = new User("ScrumMaster@agilebooster.fr", "Forename", "Last Name", "password", true);
        scrumMaster = userController.create(scrumMaster);
        productOwner = new User("ProductOwner@agilebooster.fr", "Forename", "Last Name", "password", true);
        productOwner = userController.create(productOwner);
        guest1 = new User("Guest1@agilebooster.fr", "Forename", "Last Name", "password", true);
        guest1 = userController.create(guest1);
        guest2 = new User("Guest2@agilebooster.fr", "Forename", "Last Name", "password", true);
        guest2 = userController.create(guest2);
        guest3 = new User("Guest3@agilebooster.fr", "Forename", "Last Name", "password", true);
        guest3 = userController.create(guest3);

        projectController = new ProjectController();
        Date date = new Date();
        project = new Project("Test Event", "TET", "Project Event test.", date, "http://www.testEvent.com", "http://www.testEvent.git", scrumMaster, productOwner);
        project = projectController.create(project);
    }

    /**
     * Destroy the test environment.
     */
    @AfterClass
    public static void destroyContext() {
        projectController.destroy(project);
        userController.destroy(scrumMaster);
        userController.destroy(productOwner);
        userController.destroy(guest1);
        userController.destroy(guest2);
        userController.destroy(guest3);
    }

    /**
     * Clean the users after each test.
     */
    @After
    public void cleanUsers() {
        project = projectController.refresh(project);
        scrumMaster = userController.refresh(scrumMaster);
        productOwner = userController.refresh(productOwner);
        guest1 = userController.refresh(guest1);
        guest2 = userController.refresh(guest2);
        guest3 = userController.refresh(guest3);
    }

    /**
     * Test of create method, of class EventController.
     */
    @Test
    public void testCreate() {
        System.out.println("EventController:Create");
        EventController eventController = new EventController();
        Date eventDate = new Date();
        Event event = new Event("Title", 0, "Your Desk", eventDate, 1, "Unit tests point", project, scrumMaster);
        event.addGuest(guest1);
        event.addGuest(guest2);
        event.addGuest(guest3);
        Event eventResult = eventController.create(event);

        //Check Release properties.
        assertNotNull(eventResult.getId());
        assertEquals(event.getTitle(), eventResult.getTitle());
        assertEquals(event.getEventType(), eventResult.getEventType());
        assertEquals(event.getPlace(), eventResult.getPlace());
        assertEquals(event.getDuration(), eventResult.getDuration());
        assertEquals(event.getDescription(), eventResult.getDescription());
        assertEquals(event.getProject(), eventResult.getProject());
        assertEquals(event.getOrganizer(), eventResult.getOrganizer());
        assertEquals(3, eventResult.getGuests().size());
        assertTrue(eventResult.getGuests().contains(guest1));
        assertTrue(eventResult.getGuests().contains(guest2));
        assertTrue(eventResult.getGuests().contains(guest3));
        assertFalse(eventResult.getGuests().contains(scrumMaster));

        //Check project properties.
        project = projectController.refresh(project);
        assertTrue(project.getEvents().contains(eventResult));

        //Check users properties.
        scrumMaster = userController.refresh(scrumMaster);
        guest1 = userController.refresh(guest1);
        guest2 = userController.refresh(guest2);
        guest3 = userController.refresh(guest3);
        assertTrue(scrumMaster.getEventsOrganized().contains(eventResult));
        assertTrue(guest1.getInvitedEvents().contains(eventResult));
        assertTrue(guest2.getInvitedEvents().contains(eventResult));
        assertTrue(guest3.getInvitedEvents().contains(eventResult));

        eventController.destroy(event);
    }
   
    /**
     * Test of destroy method, of class EventController.
     */
    @Test
    public void testDestroy() {
        System.out.println("EventController:Destroy");
        EventController eventController = new EventController();
        Date eventDate = new Date();
        Event event = new Event("Title", 0, "Your Desk", eventDate, 1, "Unit tests point", project, scrumMaster);
        event.addGuest(guest1);
        event.addGuest(guest2);
        event.addGuest(guest3);
        event = eventController.create(event);
        assertTrue(eventController.destroy(event));
    }
}
TOP

Related Classes of com.agilebooster.data.jpa.EventControllerTest

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.