@Before public void setUp() throws Exception { request = new MockHttpServletRequest(); MockHttpSession session = new MockHttpSession(); session.setAttribute(UserAuthenticationSuccessHandler.USER, USER); session.setAttribute(UserAuthenticationSuccessHandler.USER_ID, USER_ID); when(permissionService.hasPermissionOnZone(USER_ID, ZONE_ID)).thenReturn(true); request.setSession(session); }
@Test public void shouldReturnErrorResponse() throws Exception { List<ProcessingPeriod> expectedPeriods = new ArrayList<>(); when(scheduleService.getPeriodsForDeliveryZoneAndProgram(1l, 3l)).thenReturn(expectedPeriods); Long invalidZoneId = 67l; when(permissionService.hasPermissionOnZone(USER_ID, invalidZoneId)).thenReturn(false); ResponseEntity<OpenLmisResponse> response = controller.getPeriodsForProgramInDeliveryZone(request, invalidZoneId, 3l); assertThat(response.getStatusCode(), is(UNAUTHORIZED)); assertThat(response.getBody().getErrorMsg(), is(FORBIDDEN_EXCEPTION)); }