Package com.stripbandunk.tutorial.simpleapp.controller

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

/*
*  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.entity.User;
import com.stripbandunk.tutorial.simpleapp.repository.GroupRepository;
import com.stripbandunk.tutorial.simpleapp.repository.UserRepository;
import com.stripbandunk.tutorial.simpleapp.util.SpringUtilities;
import java.util.Date;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
*
* @author echo
*/
public class UserControllerTest {

    private UserController controller;

    private UserRepository repository;

    private GroupRepository groupRepository;

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

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

        repository = SpringUtilities.getBean(UserRepository.class);
        Assert.assertNotNull(repository);

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

    @Test
    public void testProcessCreate() {
        Group group = new Group("Sample Group");
        group.setCreatedDate(new Date());
        group.setLastModifiedDate(new Date());
        groupRepository.save(group);

        User user = new User();
        user.setAddress("Address");
        user.setBirthDate(new Date());
        user.setEmail("echo.khannedy@gmail.com");
        user.setFirstName("Eko Kurniawan");
        user.setLastName("Khannedy");
        user.setGroup(group);

        long count = repository.count();

        controller.processCreate(user);

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

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

        repository.delete(user);

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

        repository.deleteAll();
        groupRepository.deleteAll();
    }

    @Test
    public void testProcessEdit() {
        Group group = new Group("Sample Group");
        group.setCreatedDate(new Date());
        group.setLastModifiedDate(new Date());
        groupRepository.save(group);

        User user = new User();
        user.setAddress("Address");
        user.setBirthDate(new Date());
        user.setEmail("echo.khannedy@gmail.com");
        user.setFirstName("Eko Kurniawan");
        user.setLastName("Khannedy");
        user.setCreatedDate(new Date());
        user.setLastModifiedDate(new Date());
        user.setGroup(group);

        repository.save(user);

        long edit = user.getLastModifiedDate().getTime();

        user.setAddress("Address Edit");
        user.setFirstName("Nesia");
        user.setLastName("Oktiana");

        controller.processEdit(user);

        if (edit == user.getLastModifiedDate().getTime()) {
            Assert.fail();
        }

        repository.deleteAll();
        groupRepository.deleteAll();
    }

    @Test
    public void testProcessMoveToGroup() {
    }

    @Test
    public void testProcessDelete() {
    }

    @Test
    public void testProcessLoad() {
    }
}
TOP

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

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.