Search in sources :

Example 1 with DepartmentManageService

use of org.mx.comps.rbac.service.DepartmentManageService in project main by JohnPeng739.

the class TestDepartment method testDepartmentCrud.

@Test
public void testDepartmentCrud() {
    GeneralDictAccessor service = context.getBean("generalDictAccessor", GeneralDictAccessor.class);
    assertNotNull(service);
    DepartmentManageService departService = context.getBean(DepartmentManageService.class);
    assertNotNull(service);
    try {
        assertEquals(service.count(User.class), 0);
        // insert
        testInsertDepartment(service, departService);
        // edit
        testEditDepartment(service, departService);
        // delete
        testDeleteDepartment(service);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail(ex.getMessage());
    }
}
Also used : User(org.mx.comps.rbac.dal.entity.User) DepartmentManageService(org.mx.comps.rbac.service.DepartmentManageService) GeneralDictAccessor(org.mx.dal.service.GeneralDictAccessor) Test(org.junit.Test)

Example 2 with DepartmentManageService

use of org.mx.comps.rbac.service.DepartmentManageService in project main by JohnPeng739.

the class TestDepartment method testDepartmentManager.

@Test
public void testDepartmentManager() {
    GeneralDictAccessor service = context.getBean("generalDictAccessor", GeneralDictAccessor.class);
    assertNotNull(service);
    DepartmentManageService departService = context.getBean(DepartmentManageService.class);
    assertNotNull(service);
    UserManageService userManageService = context.getBean(UserManageService.class);
    assertNotNull(userManageService);
    try {
        TestUser.testInsertUser(service, userManageService);
        TestUser.testEditUser(service, userManageService);
        testInsertDepartment(service, departService);
        testEditDepartment(service, departService);
        assertEquals(3, service.count(User.class));
        assertEquals(3, service.count(Department.class));
        Department depart1 = service.getById(depart1Id, Department.class);
        assertNotNull(depart1);
        assertTrue(depart1.isValid());
        assertNull(depart1.getManager());
        User john = service.getById(TestUser.johnId, User.class);
        assertNotNull(john);
        assertTrue(john.isValid());
        DepartmentManageService.DepartInfo departInfo = DepartmentManageService.DepartInfo.valueOf(depart1.getCode(), depart1.getName(), depart1.getDesc(), depart1.getId(), john.getId(), Arrays.asList(), true);
        depart1 = departService.saveDepartment(departInfo);
        assertEquals(3, service.count(Department.class));
        assertNotNull(depart1);
        depart1 = service.getById(depart1Id, Department.class);
        assertNotNull(depart1);
        assertNotNull(depart1.getManager());
        assertEquals(john, depart1.getManager());
        departInfo = DepartmentManageService.DepartInfo.valueOf(depart1.getCode(), depart1.getName(), depart1.getDesc(), depart1.getId(), null, Arrays.asList(), true);
        departService.saveDepartment(departInfo);
        depart1 = service.getById(depart1Id, Department.class);
        assertEquals(3, service.count(Department.class));
        assertNull(depart1.getManager());
    } catch (Exception ex) {
        ex.printStackTrace();
        fail(ex.getMessage());
    }
}
Also used : Department(org.mx.comps.rbac.dal.entity.Department) User(org.mx.comps.rbac.dal.entity.User) DepartmentManageService(org.mx.comps.rbac.service.DepartmentManageService) GeneralDictAccessor(org.mx.dal.service.GeneralDictAccessor) UserManageService(org.mx.comps.rbac.service.UserManageService) Test(org.junit.Test)

Example 3 with DepartmentManageService

use of org.mx.comps.rbac.service.DepartmentManageService in project main by JohnPeng739.

the class TestDepartment method testInsertDepartment.

public static void testInsertDepartment(GeneralDictAccessor service, DepartmentManageService departService) {
    DepartmentManageService.DepartInfo departInfo = DepartmentManageService.DepartInfo.valueOf("depart1", "depart1", "description");
    Department depart1 = departService.saveDepartment(departInfo);
    assertNotNull(depart1);
    assertNotNull(depart1.getId());
    depart1Id = depart1.getId();
    assertEquals(1, service.count(Department.class));
    depart1 = service.getById(depart1Id, Department.class);
    assertNotNull(depart1);
    assertEquals("depart1", depart1.getCode());
    assertEquals("depart1", depart1.getName());
    assertEquals("description", depart1.getDesc());
    depart1 = service.getByCode("depart1", Department.class);
    assertNotNull(depart1);
    assertEquals("depart1", depart1.getCode());
    assertEquals("depart1", depart1.getName());
    assertEquals("description", depart1.getDesc());
    departInfo = DepartmentManageService.DepartInfo.valueOf("depart2", "depart2", "description");
    Department depart2 = departService.saveDepartment(departInfo);
    assertEquals(2, service.count(Department.class));
    assertNotNull(depart2);
    depart2Id = depart2.getId();
    assertNotNull(depart2.getId());
}
Also used : Department(org.mx.comps.rbac.dal.entity.Department) DepartmentManageService(org.mx.comps.rbac.service.DepartmentManageService)

Example 4 with DepartmentManageService

use of org.mx.comps.rbac.service.DepartmentManageService in project main by JohnPeng739.

the class TestUser method testUserDepartment.

@Test
public void testUserDepartment() {
    GeneralDictAccessor service = context.getBean("generalDictAccessor", GeneralDictAccessor.class);
    assertNotNull(service);
    UserManageService userService = context.getBean(UserManageService.class);
    assertNotNull(service);
    DepartmentManageService departManageService = context.getBean(DepartmentManageService.class);
    assertNotNull(departManageService);
    try {
        TestDepartment.testInsertDepartment(service, departManageService);
        TestDepartment.testEditDepartment(service, departManageService);
        testInsertUser(service, userService);
        testEditUser(service, userService);
        assertEquals(3, service.count(Department.class));
        assertEquals(3, service.count(User.class));
        User joy = service.getById(joyId, User.class);
        assertNotNull(joy);
        assertNull(joy.getDepartment());
        User josh = service.getById(joshId, User.class);
        assertNotNull(josh);
        assertNull(josh.getDepartment());
        Department depart1 = service.getById(TestDepartment.depart1Id, Department.class);
        assertNotNull(depart1);
        UserManageService.UserInfo userInfo = UserManageService.UserInfo.valueOf(joy.getFirstName(), joy.getMiddleName(), joy.getLastName(), joy.getSex(), joy.getId(), 0, depart1.getId(), joy.getStation(), joy.isValid(), joy.getDesc());
        userService.saveUser(userInfo);
        joy = service.getById(joyId, User.class);
        assertNotNull(joy);
        assertNotNull(joy.getDepartment());
        assertEquals(depart1, joy.getDepartment());
        depart1 = service.getById(TestDepartment.depart1Id, Department.class);
        assertNotNull(depart1);
        assertEquals(1, depart1.getEmployees().size());
        assertEquals(new HashSet<>(Arrays.asList(joy)), depart1.getEmployees());
        userInfo = UserManageService.UserInfo.valueOf(josh.getFirstName(), josh.getMiddleName(), josh.getLastName(), josh.getSex(), josh.getId(), 0, depart1.getId(), josh.getStation(), josh.isValid(), josh.getDesc());
        userService.saveUser(userInfo);
        josh = service.getById(joshId, User.class);
        assertNotNull(josh);
        assertNotNull(josh.getDepartment());
        assertEquals(depart1, josh.getDepartment());
        depart1 = service.getById(TestDepartment.depart1Id, Department.class);
        assertNotNull(depart1);
        assertEquals(2, depart1.getEmployees().size());
        assertEquals(new HashSet<>(Arrays.asList(joy, josh)), depart1.getEmployees());
        userInfo = UserManageService.UserInfo.valueOf(joy.getFirstName(), joy.getMiddleName(), joy.getLastName(), joy.getSex(), joy.getId(), 0, null, joy.getStation(), joy.isValid(), joy.getDesc());
        userService.saveUser(userInfo);
        joy = service.getById(joyId, User.class);
        assertNotNull(joy);
        assertNull(joy.getDepartment());
        depart1 = service.getById(TestDepartment.depart1Id, Department.class);
        assertNotNull(depart1);
        assertEquals(1, depart1.getEmployees().size());
        assertEquals(new HashSet<>(Arrays.asList(josh)), depart1.getEmployees());
    } catch (Exception ex) {
        ex.printStackTrace();
        fail(ex.getMessage());
    }
}
Also used : Department(org.mx.comps.rbac.dal.entity.Department) User(org.mx.comps.rbac.dal.entity.User) DepartmentManageService(org.mx.comps.rbac.service.DepartmentManageService) GeneralDictAccessor(org.mx.dal.service.GeneralDictAccessor) UserManageService(org.mx.comps.rbac.service.UserManageService) UserInterfaceRbacErrorException(org.mx.comps.rbac.error.UserInterfaceRbacErrorException) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 5 with DepartmentManageService

use of org.mx.comps.rbac.service.DepartmentManageService in project main by JohnPeng739.

the class TestDepartment method testEditDepartment.

public static void testEditDepartment(GeneralDictAccessor service, DepartmentManageService departService) {
    DepartmentManageService.DepartInfo departInfo = DepartmentManageService.DepartInfo.valueOf("depart3", "depart3", "description");
    Department depart3 = departService.saveDepartment(departInfo);
    assertEquals(3, service.count(Department.class));
    assertNotNull(depart3);
    assertNotNull(depart3.getId());
    depart3Id = depart3.getId();
    departInfo = DepartmentManageService.DepartInfo.valueOf("depart3", "new name", "description", depart3.getId(), "", Arrays.asList(), false);
    depart3 = departService.saveDepartment(departInfo);
    assertEquals(2, service.count(Department.class));
    assertEquals(3, service.count(Department.class, false));
    assertNotNull(depart3);
    depart3 = service.getById(depart3Id, Department.class);
    assertNotNull(depart3);
    assertEquals("new name", depart3.getName());
    assertFalse(depart3.isValid());
    departInfo = DepartmentManageService.DepartInfo.valueOf("depart3", "depart3", "description", depart3.getId(), "", Arrays.asList(), true);
    departService.saveDepartment(departInfo);
    assertEquals(3, service.count(Department.class));
    assertEquals(3, service.count(Department.class, false));
}
Also used : Department(org.mx.comps.rbac.dal.entity.Department) DepartmentManageService(org.mx.comps.rbac.service.DepartmentManageService)

Aggregations

DepartmentManageService (org.mx.comps.rbac.service.DepartmentManageService)5 Department (org.mx.comps.rbac.dal.entity.Department)4 Test (org.junit.Test)3 User (org.mx.comps.rbac.dal.entity.User)3 GeneralDictAccessor (org.mx.dal.service.GeneralDictAccessor)3 UserManageService (org.mx.comps.rbac.service.UserManageService)2 ParseException (java.text.ParseException)1 UserInterfaceRbacErrorException (org.mx.comps.rbac.error.UserInterfaceRbacErrorException)1