com.gantzgulch.sharing.controller.UsersControllerTest.java Source code

Java tutorial

Introduction

Here is the source code for com.gantzgulch.sharing.controller.UsersControllerTest.java

Source

/*
 * Copyright 2011 GantzGulch, Inc.
 * 
 * This file is part of GantzFileSharing.
 * 
 * GantzFileSharing is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GantzFileSharing is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with GantzFileSharing.  If not, see <http://www.gnu.org/licenses/>. 
 */
package com.gantzgulch.sharing.controller;

import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;

import java.util.List;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.ModelAndView;

import com.gantzgulch.sharing.AbstractSpringTest;
import com.gantzgulch.sharing.domain.User;
import com.gantzgulch.sharing.matchers.UserMatcher;
import com.gantzgulch.sharing.util.Cast;

public class UsersControllerTest extends AbstractSpringTest {

    @Autowired
    private UsersController controller;

    @Test
    public void getUsers() {
        ModelAndView modelAndView = controller.doGet();

        assertThat(modelAndView, notNullValue());

        List<User> users = Cast.cast(modelAndView.getModel().get("users"));
        assertThat(users, notNullValue());
        assertThat(users, UserMatcher.containsUsername("admin"));
        assertThat(users, UserMatcher.containsId("0"));
        assertThat(users, not(UserMatcher.containsUsername("unknown")));
    }
}