Package server.repo

Source Code of server.repo.JpaEmployeeRepositoryTest

package server.repo;

import com.google.inject.Guice;
import com.google.inject.Injector;

import org.junit.*;
import server.config.JpaUtModule;
import server.model.Employee;

public class JpaEmployeeRepositoryTest {

    Repository<Employee> repository;

    @Before
    public void up() {
        Injector injector = Guice.createInjector(new JpaUtModule());
        repository = injector.getInstance(JpaEmployeeRepository.class);
    }

    @Test
    @Ignore
    public void testSave() {
        Employee employee = new Employee();
        employee.name = "Ivan";
        employee.age = 23;

        Employee saved = repository.save(employee);

        Assert.assertNotEquals(0l, saved.id);
        Assert.assertEquals(employee.age, saved.age);
        Assert.assertEquals(employee.name, saved.name);
    }

    @Test
    @Ignore
    public void testUpdate() {
        Employee employee = new Employee();
        employee.name = "A";
        employee.age = 21;
        long id = repository.save(employee).id;

        employee.age = 12;
        repository.save(employee);
        Employee updated = repository.read(id);
        Assert.assertEquals(employee.name, updated.name);
        Assert.assertEquals(employee.age, updated.age);

        employee.name = "B";
        repository.save(employee);
        updated = repository.read(id);
        Assert.assertEquals(employee.name, updated.name);
        Assert.assertEquals(employee.age, updated.age);
    }

    @Test
    public void testRead() {
        Employee employee = new Employee();
        employee.name = "C";
        long id = repository.save(employee).id;

        Employee saved = repository.read(id);
        Assert.assertNotEquals(0l, saved.id);
        Assert.assertEquals(employee.name, saved.name);
    }
}
TOP

Related Classes of server.repo.JpaEmployeeRepositoryTest

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.