@Test(expected = SecurityException.class) public void shouldThrowExceptionWhileReadingInstanceWithoutAnyPermission() { EntityDto entityDto = new EntityDto(); entityDto.setReadOnlySecurityMode(SecurityMode.NO_ACCESS); entityDto.setSecurityMode(SecurityMode.NO_ACCESS); EntityRecord entityRecord = new EntityRecord(ANOTHER_ENTITY_ID, null, new ArrayList<FieldRecord>()); when(entityService.getEntity(ANOTHER_ENTITY_ID)).thenReturn(entityDto); instanceService.getEntityRecords(entityRecord.getId()); }
@Test public void shouldAcceptUserWithNoPermissionWhileReadingInstanceWithNoSecurityMode() { EntityDto entityDto = new EntityDto(); entityDto.setReadOnlySecurityMode(null); entityDto.setSecurityMode(null); entityDto.setClassName(TestSample.class.getName()); EntityRecord entityRecord = new EntityRecord(ANOTHER_ENTITY_ID, null, new ArrayList<>()); when(entityService.getEntity(ANOTHER_ENTITY_ID)).thenReturn(entityDto); mockDataService(); instanceService.getEntityRecords(entityRecord.getId()); verify(entityService).getEntityFieldsForUI(ANOTHER_ENTITY_ID); }
@Test public void shouldNotUpdateGridSizeWhenUsernameIsBlank() { EntityDto entityDto = new EntityDto(); entityDto.setReadOnlySecurityMode(null); entityDto.setSecurityMode(null); entityDto.setClassName(TestSample.class.getName()); EntityRecord entityRecord = new EntityRecord(ENTITY_ID + 1, null, new ArrayList<FieldRecord>()); when(entityService.getEntity(ENTITY_ID + 1)).thenReturn(entityDto); mockDataService(); instanceService.getEntityRecords(entityRecord.getId(), new QueryParams(1, 100)); verify(entityService).getEntityFieldsForUI(ENTITY_ID + 1); verify(userPreferencesService, never()).updateGridSize(anyLong(), anyString(), anyInt()); }
@Test public void shouldUpdateGridSize() { setUpSecurityContext(); EntityDto entityDto = new EntityDto(); entityDto.setReadOnlySecurityMode(null); entityDto.setSecurityMode(null); entityDto.setClassName(TestSample.class.getName()); EntityRecord entityRecord = new EntityRecord(ENTITY_ID + 1, null, new ArrayList<>()); when(entityService.getEntity(ENTITY_ID + 1)).thenReturn(entityDto); mockDataService(); instanceService.getEntityRecords(entityRecord.getId(), new QueryParams(1, 100)); verify(entityService).getEntityFieldsForUI(ENTITY_ID + 1); verify(userPreferencesService).updateGridSize(ENTITY_ID + 1, "motech", 100); }