Package com.stripbandunk.tutorial.simpleapp.controller

Source Code of com.stripbandunk.tutorial.simpleapp.controller.GroupControllerTest

/*
*  Copyright (c) 2011, StripBandunk and/or its affiliates. All rights reserved.
*
*       http://stripbandunk.com/
*
*  STRIPBANDUNK PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
package com.stripbandunk.tutorial.simpleapp.controller;

import com.stripbandunk.tutorial.simpleapp.entity.Group;
import com.stripbandunk.tutorial.simpleapp.repository.GroupRepository;
import com.stripbandunk.tutorial.simpleapp.util.SpringUtilities;
import java.util.ArrayList;
import java.util.List;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
*
* @author Eko Kurniawan Khannedy
*/
public class GroupControllerTest {

    private GroupController controller;

    private GroupRepository repository;

    @BeforeClass
    public static void setUpClass() throws Exception {
        SpringUtilities.getApplicationContext();
    }

    @Before
    public void setUp() {
        controller = SpringUtilities.getBean(GroupController.class);
        Assert.assertNotNull(controller);

        repository = SpringUtilities.getBean(GroupRepository.class);
        Assert.assertNotNull(repository);
    }

    @Test
    public void testProcessCreate() {
        Long size = repository.count();

        Group group = new Group();
        group.setName("Administrator");

        controller.processCreate(group);

        Assert.assertNotNull(group.getId());
        Assert.assertNotNull(group.getCreatedDate());
        Assert.assertNotNull(group.getLastModifiedDate());

        if (size == repository.count()) {
            Assert.fail();
        }

        repository.delete(group);
    }

    @Test
    public void testProcessDelete() {
        Long size = repository.count();

        List<Group> groups = new ArrayList<>(5);
        groups.add(controller.processCreate(new Group("Test 1")));
        groups.add(controller.processCreate(new Group("Test 2")));
        groups.add(controller.processCreate(new Group("Test 3")));
        groups.add(controller.processCreate(new Group("Test 4")));
        groups.add(controller.processCreate(new Group("Test 5")));

        if (size == repository.count()) {
            Assert.fail();
        }

        controller.processDelete(groups.toArray(new Group[groups.size()]));

        if (size != repository.count()) {
            Assert.fail();
        }
    }

    @Test
    public void testProcessEdit() {
        Group group = controller.processCreate(new Group("Test Edit"));
        long time = group.getLastModifiedDate().getTime();

        Assert.assertNotNull(group.getId());

        group.setName("Edit Test");
        controller.processEdit(group);

        if (time == group.getLastModifiedDate().getTime()) {
            Assert.fail();
        }

        repository.deleteAll();
    }

    @Test
    public void testProcessLoad() {
        repository.deleteAll();

        controller.processCreate(new Group("Test 1"));
        controller.processCreate(new Group("Test 2"));
        controller.processCreate(new Group("Test 3"));
        controller.processCreate(new Group("Test 4"));
        controller.processCreate(new Group("Test 5"));

        List<Group> groups = controller.processLoad();

        if (groups.size() != 5) {
            Assert.fail();
        }

        repository.delete(groups);

        if (repository.count() != 0) {
            Assert.fail();
        }
    }
}
TOP

Related Classes of com.stripbandunk.tutorial.simpleapp.controller.GroupControllerTest

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.