Search in sources :

Example 1 with FilterBuilderFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.FilterBuilderFilter in project CzechIdMng by bcvsolutions.

the class FilterBuilderControllerRestTest method testEnable.

@Test
public void testEnable() throws Exception {
    try {
        getHelper().enableFilter(defaultManagersFilter.getClass());
        // 
        FilterBuilderFilter filter = new FilterBuilderFilter();
        filter.setFilterBuilderClass(AutowireHelper.getTargetType(defaultManagersFilter));
        List<FilterBuilderDto> results = find(filter);
        // 
        Assert.assertEquals(1, results.size());
        Assert.assertEquals(defaultManagersFilter.getName(), results.get(0).getName());
        Assert.assertEquals(defaultManagersFilter.getEntityClass(), results.get(0).getEntityClass());
        Assert.assertFalse(results.get(0).isDisabled());
        // 
        filter.setFilterBuilderClass(AutowireHelper.getTargetType(guaranteeManagersFilter));
        results = find(filter);
        Assert.assertEquals(1, results.size());
        Assert.assertEquals(guaranteeManagersFilter.getName(), results.get(0).getName());
        Assert.assertEquals(guaranteeManagersFilter.getEntityClass(), results.get(0).getEntityClass());
        Assert.assertTrue(results.get(0).isDisabled());
        // 
        getMockMvc().perform(put(BaseController.BASE_PATH + "/filter-builders/" + results.get(0).getId() + "/enable").with(authentication(getAdminAuthentication())).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().is2xxSuccessful());
        // 
        filter.setFilterBuilderClass(AutowireHelper.getTargetType(defaultManagersFilter));
        results = find(filter);
        Assert.assertEquals(1, results.size());
        Assert.assertEquals(defaultManagersFilter.getName(), results.get(0).getName());
        Assert.assertEquals(defaultManagersFilter.getEntityClass(), results.get(0).getEntityClass());
        Assert.assertTrue(results.get(0).isDisabled());
        // 
        filter.setFilterBuilderClass(AutowireHelper.getTargetType(guaranteeManagersFilter));
        results = find(filter);
        Assert.assertEquals(1, results.size());
        Assert.assertEquals(guaranteeManagersFilter.getName(), results.get(0).getName());
        Assert.assertEquals(guaranteeManagersFilter.getEntityClass(), results.get(0).getEntityClass());
        Assert.assertFalse(results.get(0).isDisabled());
    } finally {
        getHelper().enableFilter(defaultManagersFilter.getClass());
    }
}
Also used : FilterBuilderFilter(eu.bcvsolutions.idm.core.api.dto.filter.FilterBuilderFilter) FilterBuilderDto(eu.bcvsolutions.idm.core.api.dto.FilterBuilderDto) Test(org.junit.Test) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest)

Example 2 with FilterBuilderFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.FilterBuilderFilter in project CzechIdMng by bcvsolutions.

the class DefaultFilterManagerUnitTest method testFindByFilterBuilderClass.

@Test
@SuppressWarnings("serial")
public void testFindByFilterBuilderClass() {
    FilterBuilderDto dto = new FilterBuilderDto();
    dto.setModule("test");
    dto.setEntityClass(IdmIdentity.class);
    dto.setFilterBuilderClass(IdmIdentityService.class);
    // 
    FilterBuilderFilter filter = new FilterBuilderFilter();
    filter.setFilterBuilderClass(IdmIdentityService.class.getCanonicalName());
    Assert.assertTrue(manager.passFilter(dto, filter));
    filter.setFilterBuilderClass(IdmIdentityService.class.getSimpleName());
    Assert.assertFalse(manager.passFilter(dto, filter));
    // inline classes with null cannonical name
    dto.setFilterBuilderClass((new IdmIdentity() {
    }).getClass());
    filter.setFilterBuilderClass(IdmIdentity.class.getCanonicalName());
    Assert.assertFalse(manager.passFilter(dto, filter));
}
Also used : FilterBuilderFilter(eu.bcvsolutions.idm.core.api.dto.filter.FilterBuilderFilter) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) FilterBuilderDto(eu.bcvsolutions.idm.core.api.dto.FilterBuilderDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 3 with FilterBuilderFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.FilterBuilderFilter in project CzechIdMng by bcvsolutions.

the class DefaultFilterManagerUnitTest method testEmptyFilter.

@Test
public void testEmptyFilter() {
    Assert.assertTrue(manager.passFilter(new FilterBuilderDto(), null));
    FilterBuilderFilter filter = new FilterBuilderFilter();
    Assert.assertTrue(manager.passFilter(new FilterBuilderDto(), filter));
}
Also used : FilterBuilderFilter(eu.bcvsolutions.idm.core.api.dto.filter.FilterBuilderFilter) FilterBuilderDto(eu.bcvsolutions.idm.core.api.dto.FilterBuilderDto) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 4 with FilterBuilderFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.FilterBuilderFilter in project CzechIdMng by bcvsolutions.

the class FilterBuilderControllerRestTest method testFindByName.

@Test
public void testFindByName() {
    FilterBuilderFilter filter = new FilterBuilderFilter();
    filter.setName(defaultManagersFilter.getName());
    filter.setEntityClass(IdmIdentity.class.getCanonicalName());
    List<FilterBuilderDto> results = find(filter);
    // 
    Assert.assertFalse(results.isEmpty());
    Assert.assertTrue(results.stream().anyMatch(f -> f.getFilterBuilderClass().equals(AutowireHelper.getTargetClass(defaultManagersFilter))));
    Assert.assertTrue(results.stream().anyMatch(f -> f.getFilterBuilderClass().equals(AutowireHelper.getTargetClass(guaranteeManagersFilter))));
    Assert.assertTrue(results.stream().allMatch(f -> f.getEntityClass().equals(IdmIdentity.class)));
    Assert.assertTrue(results.stream().allMatch(f -> f.getName().equals(defaultManagersFilter.getName())));
    // 
    // not-exists
    filter.setName(getHelper().createName());
    filter.setEntityClass(IdmIdentity.class.getCanonicalName());
    results = find(filter);
    Assert.assertTrue(results.isEmpty());
}
Also used : MockMvcRequestBuilders.put(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put) FilterBuilderFilter(eu.bcvsolutions.idm.core.api.dto.filter.FilterBuilderFilter) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) MockMvcResultMatchers.content(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content) GuaranteeManagersFilter(eu.bcvsolutions.idm.core.model.repository.filter.GuaranteeManagersFilter) AutowireHelper(eu.bcvsolutions.idm.core.api.utils.AutowireHelper) List(java.util.List) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) DefaultManagersFilter(eu.bcvsolutions.idm.core.model.repository.filter.DefaultManagersFilter) FilterBuilderDto(eu.bcvsolutions.idm.core.api.dto.FilterBuilderDto) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) BaseController(eu.bcvsolutions.idm.core.api.rest.BaseController) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Assert(org.junit.Assert) Transactional(org.springframework.transaction.annotation.Transactional) FilterBuilderFilter(eu.bcvsolutions.idm.core.api.dto.filter.FilterBuilderFilter) FilterBuilderDto(eu.bcvsolutions.idm.core.api.dto.FilterBuilderDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Test(org.junit.Test) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest)

Example 5 with FilterBuilderFilter

use of eu.bcvsolutions.idm.core.api.dto.filter.FilterBuilderFilter in project CzechIdMng by bcvsolutions.

the class DefaultFilterManagerUnitTest method testFindByDescription.

@Test
public void testFindByDescription() {
    FilterBuilderDto dto = new FilterBuilderDto();
    dto.setDescription("tesT-x");
    dto.setEntityClass(IdmIdentity.class);
    // 
    FilterBuilderFilter filter = new FilterBuilderFilter();
    filter.setDescription("Test-x");
    Assert.assertTrue(manager.passFilter(dto, filter));
    filter.setDescription("test-");
    Assert.assertTrue(manager.passFilter(dto, filter));
    filter.setDescription("tee");
    Assert.assertFalse(manager.passFilter(dto, filter));
    dto.setDescription(null);
    Assert.assertFalse(manager.passFilter(dto, filter));
}
Also used : FilterBuilderFilter(eu.bcvsolutions.idm.core.api.dto.filter.FilterBuilderFilter) FilterBuilderDto(eu.bcvsolutions.idm.core.api.dto.FilterBuilderDto) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Aggregations

FilterBuilderDto (eu.bcvsolutions.idm.core.api.dto.FilterBuilderDto)10 FilterBuilderFilter (eu.bcvsolutions.idm.core.api.dto.filter.FilterBuilderFilter)10 Test (org.junit.Test)10 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)8 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)4 AbstractRestTest (eu.bcvsolutions.idm.test.api.AbstractRestTest)2 BaseController (eu.bcvsolutions.idm.core.api.rest.BaseController)1 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)1 AutowireHelper (eu.bcvsolutions.idm.core.api.utils.AutowireHelper)1 DefaultManagersFilter (eu.bcvsolutions.idm.core.model.repository.filter.DefaultManagersFilter)1 GuaranteeManagersFilter (eu.bcvsolutions.idm.core.model.repository.filter.GuaranteeManagersFilter)1 TestHelper (eu.bcvsolutions.idm.test.api.TestHelper)1 List (java.util.List)1 Assert (org.junit.Assert)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 SecurityMockMvcRequestPostProcessors.authentication (org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication)1 MockMvcRequestBuilders.get (org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get)1 MockMvcRequestBuilders.put (org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put)1 MockMvcResultMatchers.content (org.springframework.test.web.servlet.result.MockMvcResultMatchers.content)1 MockMvcResultMatchers.status (org.springframework.test.web.servlet.result.MockMvcResultMatchers.status)1