Package com.sivalabs.springapp

Source Code of com.sivalabs.springapp.UserServiceTest

/**
*
*/
package com.sivalabs.springapp;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.sivalabs.springapp.config.AppConfig;
import com.sivalabs.springapp.entities.User;
import com.sivalabs.springapp.services.UserService;

/**
* @author Siva
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes=AppConfig.class)
public class UserServiceTest
{
  @Autowired
  private UserService userService;
 
  @Test
  public void findAllUsers()  {
    List<User> users = userService.findAll();
    assertNotNull(users);
    assertTrue(!users.isEmpty());
  }
 
  @Test
  public void findUserById()  {
    User user = userService.findUserById(1);
    assertNotNull(user);
  }
 
  @Test
  public void createUser() {
    User user = new User(0, "Siva", "siva@gmail.com", "siva", null);
    User savedUser = userService.create(user);
    User newUser = userService.findUserById(savedUser.getId());
    assertEquals("Siva", newUser.getName());
    assertEquals("siva@gmail.com", newUser.getEmail());
  }
 
 
}
TOP

Related Classes of com.sivalabs.springapp.UserServiceTest

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.