Package com.agilebooster.data.jpa

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

/*
* (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.BacklogItem;
import com.agilebooster.data.entity.Project;
import com.agilebooster.data.entity.Release;
import com.agilebooster.data.entity.Sprint;
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.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.BeforeClass;
import org.junit.Test;

/**
* Test class for BacklogItemController.
*
* @author Maxime ESCOURBIAC
*/
public class BacklogItemControllerTest {

    private static User scrumMaster;
    private static User productOwner;
    private static User creator;
    private static User assignedUser1;
    private static User assignedUser2;
    private static User assignedUser3;
    private static Project project;
    private static Release release;
    private static Sprint sprint;
    private static UserController userController;
    private static ProjectController projectController;
    private static ReleaseController releaseController;
    private static SprintController sprintController;

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

    /**
     * Init the test environment.
     */
    @BeforeClass
    public static void initContext() {
        Date date = new Date();

        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);
        creator = new User("Creator@agilebooster.fr", "Forename", "Last Name", "password", true);
        creator = userController.create(creator);
        assignedUser1 = new User("AssignedUser1@agilebooster.fr", "Forename", "Last Name", "password", true);
        assignedUser1 = userController.create(assignedUser1);
        assignedUser2 = new User("AssignedUser2@agilebooster.fr", "Forename", "Last Name", "password", true);
        assignedUser2 = userController.create(assignedUser2);
        assignedUser3 = new User("AssignedUser3@agilebooster.fr", "Forename", "Last Name", "password", true);
        assignedUser3 = userController.create(assignedUser3);

        projectController = new ProjectController();
        project = new Project("Test BacklogItem", "TBM", "Project BacklogItem test.", date, "http://www.testBacklogItem.com", "http://www.testBacklogItem.git", scrumMaster, productOwner);
        project = projectController.create(project);

        releaseController = new ReleaseController();
        release = new Release("Release Test Backlog Item", date, date, true, project);
        release = releaseController.create(release);

        sprintController = new SprintController();
        sprint = new Sprint("Sprint Test Backlog Item", date, date, true, release);
        sprint = sprintController.create(sprint);
    }

    /**
     * Destroy the test environment.
     */
    @AfterClass
    public static void destroyContext() {
        sprintController.destroy(sprint);
        releaseController.destroy(release);
        projectController.destroy(project);
        userController.destroy(assignedUser1);
        userController.destroy(assignedUser2);
        userController.destroy(assignedUser3);
        userController.destroy(scrumMaster);
        userController.destroy(productOwner);
        userController.destroy(creator);
    }

    /**
     * Clean the users after each test.
     */
    @After
    public void cleanData() {
        assignedUser1 = userController.refresh(assignedUser1);
        assignedUser2 = userController.refresh(assignedUser2);
        assignedUser3 = userController.refresh(assignedUser3);
        creator = userController.refresh(creator);
        scrumMaster = userController.refresh(scrumMaster);
        productOwner = userController.refresh(productOwner);
        sprint = sprintController.refresh(sprint);
        release = releaseController.refresh(release);
        project = projectController.refresh(project);
    }

    /**
     * Test of create method, of class SprintController.
     */
    @Test
    public void testCreate() {
        System.out.println("BacklogItemController:Create");
        BacklogItemController backlogItemController = new BacklogItemController();
        Date creationDate = new Date();
        Date lastUpdateDate = new Date();
        BacklogItem backlogItem = new BacklogItem("Test Create BI", 0, 1, "Test Create BI Description", "UF1", "UF2",
                creationDate, lastUpdateDate, project, release, sprint, creator);
        backlogItem.addAssignedUser(assignedUser1);
        backlogItem.addAssignedUser(assignedUser2);
        backlogItem.addAssignedUser(assignedUser3);
        BacklogItem backlogItemResult = backlogItemController.create(backlogItem);

        //Check Sprint properties.
        assertNotNull(backlogItemResult.getId());
        assertEquals(backlogItem.getTitle(), backlogItemResult.getTitle());
        assertEquals(backlogItem.getStatus(), backlogItemResult.getStatus());
        assertEquals(backlogItem.getDescription(), backlogItemResult.getDescription());
        assertEquals(backlogItem.getBacklogItemType(), backlogItemResult.getBacklogItemType());
        assertEquals(backlogItem.getUserField1(), backlogItemResult.getUserField1());
        assertEquals(backlogItem.getUserField2(), backlogItemResult.getUserField2());
        assertEquals(backlogItem.getCreationDate(), backlogItemResult.getCreationDate());
        assertEquals(backlogItem.getLastUpdateDate(), backlogItemResult.getLastUpdateDate());
        assertEquals(backlogItem.getProject(), backlogItemResult.getProject());
        assertEquals(backlogItem.getRelease(), backlogItemResult.getRelease());
        assertEquals(backlogItem.getSprint(), backlogItemResult.getSprint());
        assertEquals(backlogItem.getCreator(), backlogItemResult.getCreator());
        assertEquals(backlogItem.getAssignedUsers(), backlogItemResult.getAssignedUsers());

        //Check project properties.
        project = projectController.refresh(project);
        assertTrue(project.getBacklogItems().contains(backlogItemResult));

        //Check release properties.
        release = releaseController.refresh(release);
        assertTrue(release.getBacklogItems().contains(backlogItemResult));

        //Check sprint properties.
        sprint = sprintController.refresh(sprint);
        assertTrue(sprint.getBacklogItems().contains(backlogItemResult));

        //Check creator properties.
        creator = userController.refresh(creator);
        assertTrue(creator.getBacklogItemsCreated().contains(backlogItemResult));

        //Check assigned users properties.
        assignedUser1 = userController.refresh(assignedUser1);
        assertTrue(assignedUser1.getAssignedBacklogItems().contains(backlogItemResult));
        assignedUser2 = userController.refresh(assignedUser2);
        assertTrue(assignedUser2.getAssignedBacklogItems().contains(backlogItemResult));
        assignedUser3 = userController.refresh(assignedUser3);
        assertTrue(assignedUser3.getAssignedBacklogItems().contains(backlogItemResult));

        backlogItemController.destroy(backlogItemResult);
    }

    /**
     * Test of destroy method, of class BacklogItemController.
     */
    @Test
    public void testDestroy() {
        System.out.println("BacklogItemController:Destroy");
        BacklogItemController backlogItemController = new BacklogItemController();
        Date creationDate = new Date();
        Date lastUpdateDate = new Date();
        BacklogItem backlogItem = new BacklogItem("Test Destroy BI", 0, 1, "Test Destroy BI Description", "UF1", "UF2",
                creationDate, lastUpdateDate, project, release, sprint, creator);
        backlogItem = backlogItemController.create(backlogItem);
        assertTrue(backlogItemController.destroy(backlogItem));
    }
}
TOP

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

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.