use of io.crnk.core.engine.filter.ResourceFilter in project crnk-framework by crnk-project.
the class ResourceFilterDirectoryImplTest method checkMergeResourceFilterWithIgnoredNone.
@Test
public void checkMergeResourceFilterWithIgnoredNone() {
ResourceFilter filter2 = Mockito.mock(ResourceFilter.class);
filters.add(filter2);
setResourceBehavior(HttpMethod.GET, FilterBehavior.IGNORED);
Mockito.when(filter2.filterResource(Mockito.eq(resourceInformation), Mockito.eq(HttpMethod.GET))).thenReturn(FilterBehavior.NONE);
Assert.assertEquals(FilterBehavior.IGNORED, directory.get(resourceInformation, HttpMethod.GET));
Mockito.verify(filter, Mockito.times(1)).filterResource(Mockito.eq(resourceInformation), Mockito.any(HttpMethod.class));
Mockito.verify(filter2, Mockito.times(1)).filterResource(Mockito.eq(resourceInformation), Mockito.any(HttpMethod.class));
}
use of io.crnk.core.engine.filter.ResourceFilter in project crnk-framework by crnk-project.
the class ResourceFilterDirectoryImplTest method checkMergeFieldFilterWithIgnoredForbidden.
@Test
public void checkMergeFieldFilterWithIgnoredForbidden() {
ResourceFilter filter2 = Mockito.mock(ResourceFilter.class);
filters.add(filter2);
setFieldBehavior(HttpMethod.GET, FilterBehavior.IGNORED);
Mockito.when(filter2.filterField(Mockito.eq(resourceField), Mockito.eq(HttpMethod.GET))).thenReturn(FilterBehavior.FORBIDDEN);
Assert.assertEquals(FilterBehavior.FORBIDDEN, directory.get(resourceField, HttpMethod.GET));
Mockito.verify(filter, Mockito.times(1)).filterField(Mockito.eq(resourceField), Mockito.any(HttpMethod.class));
Mockito.verify(filter2, Mockito.times(1)).filterField(Mockito.eq(resourceField), Mockito.any(HttpMethod.class));
}
use of io.crnk.core.engine.filter.ResourceFilter in project crnk-framework by crnk-project.
the class ResourceFilterDirectoryImplTest method checkMergeResourceFilterWithNoneForbidden.
@Test
public void checkMergeResourceFilterWithNoneForbidden() {
ResourceFilter filter2 = Mockito.mock(ResourceFilter.class);
filters.add(filter2);
setResourceBehavior(HttpMethod.GET, FilterBehavior.NONE);
Mockito.when(filter2.filterResource(Mockito.eq(resourceInformation), Mockito.eq(HttpMethod.GET))).thenReturn(FilterBehavior.FORBIDDEN);
Assert.assertEquals(FilterBehavior.FORBIDDEN, directory.get(resourceInformation, HttpMethod.GET));
Mockito.verify(filter, Mockito.times(1)).filterResource(Mockito.eq(resourceInformation), Mockito.any(HttpMethod.class));
Mockito.verify(filter2, Mockito.times(1)).filterResource(Mockito.eq(resourceInformation), Mockito.any(HttpMethod.class));
}
use of io.crnk.core.engine.filter.ResourceFilter in project crnk-framework by crnk-project.
the class ResourceFilterDirectoryImplTest method checkMergeResourceFilterWithIgnoredForbidden.
@Test
public void checkMergeResourceFilterWithIgnoredForbidden() {
ResourceFilter filter2 = Mockito.mock(ResourceFilter.class);
filters.add(filter2);
setResourceBehavior(HttpMethod.GET, FilterBehavior.IGNORED);
Mockito.when(filter2.filterResource(Mockito.eq(resourceInformation), Mockito.eq(HttpMethod.GET))).thenReturn(FilterBehavior.FORBIDDEN);
Assert.assertEquals(FilterBehavior.FORBIDDEN, directory.get(resourceInformation, HttpMethod.GET));
Mockito.verify(filter, Mockito.times(1)).filterResource(Mockito.eq(resourceInformation), Mockito.any(HttpMethod.class));
Mockito.verify(filter2, Mockito.times(1)).filterResource(Mockito.eq(resourceInformation), Mockito.any(HttpMethod.class));
}
use of io.crnk.core.engine.filter.ResourceFilter in project crnk-framework by crnk-project.
the class ResourceFilterDirectoryImplTest method checkMergeFieldFilterWithForbiddenNone.
@Test
public void checkMergeFieldFilterWithForbiddenNone() {
ResourceFilter filter2 = Mockito.mock(ResourceFilter.class);
filters.add(filter2);
setFieldBehavior(HttpMethod.GET, FilterBehavior.FORBIDDEN);
Mockito.when(filter2.filterField(Mockito.eq(resourceField), Mockito.eq(HttpMethod.GET))).thenReturn(FilterBehavior.NONE);
Assert.assertEquals(FilterBehavior.FORBIDDEN, directory.get(resourceField, HttpMethod.GET));
Mockito.verify(filter, Mockito.times(1)).filterField(Mockito.eq(resourceField), Mockito.any(HttpMethod.class));
// loop breaks after first filter as FORBIDDEN is hardest filter
Mockito.verify(filter2, Mockito.times(0)).filterField(Mockito.eq(resourceField), Mockito.any(HttpMethod.class));
}
Aggregations