Ejemplo n.º 1
0
  @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());
  }
Ejemplo n.º 2
0
  @Test
  public void shouldLoadBlobField() throws InstanceNotFoundException {
    EntityDto entityDto = new EntityDto();
    entityDto.setReadOnlySecurityMode(null);
    entityDto.setSecurityMode(null);
    entityDto.setClassName(TestSample.class.getName());

    when(entityService.getEntity(ENTITY_ID + 1)).thenReturn(entityDto);
    mockDataService();
    TestSample instance = Mockito.mock(TestSample.class);
    when(motechDataService.findById(ENTITY_ID + 1)).thenReturn(instance);

    instanceService.getInstanceField(12l, ENTITY_ID + 1, "blobField");
    verify(motechDataService).getDetachedField(instance, "blobField");
  }
Ejemplo n.º 3
0
  @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);
  }
Ejemplo n.º 4
0
  @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());
  }
Ejemplo n.º 5
0
  @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);
  }