Package idv.takeshi.application.service.spring

Source Code of idv.takeshi.application.service.spring.PersonServiceImplTest

/**
* Copyright 2011 The Apache Software Foundation
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package idv.takeshi.application.service.spring;

import static org.junit.Assert.*;

import java.util.List;

import idv.takeshi.application.service.PersonService;
import idv.takeshi.application.service.RoleService;
import idv.takeshi.model.Person;
import idv.takeshi.model.Role;
import idv.takeshi.model.RoleAlreadyAssignedException;
import idv.takeshi.test.AbstractSpringTest;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

public class PersonServiceImplTest extends AbstractSpringTest{
 
  @Autowired
  private PersonService PersonService;
  @Autowired
  private RoleService roleService;

  @BeforeClass
  public static void setUpBeforeClass() throws Exception {
  }

  @AfterClass
  public static void tearDownAfterClass() throws Exception {
  }

  @Before
  public void setUp() throws Exception {
  }

  @After
  public void tearDown() throws Exception {
  }

  @Test
  public void testGetPerson() {
    Person person = null;
    Long id = null;
   
    id = new Long("-1");
    person = this.PersonService.getPerson(id);
   
    assertNotNull(person);
    assertEquals(id, person.getId());
  }
  @Test
  public void testGetAll(){
    List<Person> persons = null;
    persons = this.PersonService.getAll();
    assertNotNull(persons);
    assertTrue(persons.size() > 0);
  }
 
  @Test
  public void testValidate(){
    String accountName = null;
    String password = null;
    //1. test with lower-case account name.
    accountName = "test1";
    password = "12345678";
    assertTrue(this.PersonService.validate(accountName, password));
   
    //2. test with upper-case account name.
    accountName = accountName.toUpperCase();
    assertTrue(this.PersonService.validate(accountName, password));
   
    //3.
    password = "asdfgh";
    assertFalse(this.PersonService.validate(accountName, password));
  }
 
  @Test
  public void testDelete(){
    Long id = new Long("-1");
    Person person = null;
   
    person = this.PersonService.getPerson(id);
    assertNotNull(person);
   
    this.PersonService.delete(id);
    person = this.PersonService.getPerson(id);
    assertNull(person);
  }
  @Test
  public void testAdd() throws RoleAlreadyAssignedException{
    Person person = null;
    List<Role> roles = null;
    String lastName = "aaaa";
    String firstName = "bbbb";
    String password = "asdfghjkl";
    String accountName = "aaaaaa";
    roles = this.roleService.getAll();
    assertNotNull(roles);
    assertTrue(roles.size() > 0);
   
    person = new Person();
    person.setLastName(lastName);
    person.setFirstName(firstName);
    person.setAccountName(accountName);
    person.setPassword(password);
    person.addRole(roles.get(1));
    assertNull(person.getId());
   
    this.PersonService.add(person);
    assertNotNull(person.getId());
   
    person = this.PersonService.getPerson(person.getId());
    assertNotNull(person);
   
    assertEquals(firstName, person.getFirstName());
    assertEquals(lastName, person.getLastName());
    assertEquals(accountName.toUpperCase(), person.getAccountName());
    assertEquals(password, person.getPassword());
  }

}
TOP

Related Classes of idv.takeshi.application.service.spring.PersonServiceImplTest

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.