@SuppressWarnings("unchecked")
  @Test
  public void createLockAll() {
    ContentManipulationLockService tested = getTested();

    Mockito.reset(tested.configService);
    Mockito.doAnswer(new StoreValidationgAnswer(ContentManipulationLockService.API_ID_ALL))
        .when(tested.configService)
        .create(Mockito.eq(ContentManipulationLockService.CFGFILE_NAME), Mockito.anyMap());
    tested.createLockAll();
    Mockito.verify(tested.configService)
        .create(Mockito.eq(ContentManipulationLockService.CFGFILE_NAME), Mockito.anyMap());
    Mockito.verifyNoMoreInteractions(tested.configService);
  }
  @SuppressWarnings("unchecked")
  @Test
  public void createLock() {
    ContentManipulationLockService tested = getTested();

    // no any lock exists, so new is created
    Mockito.when(tested.configService.get(ContentManipulationLockService.CFGFILE_NAME))
        .thenReturn(null);
    Mockito.doAnswer(new StoreValidationgAnswer(PROVIDER_1))
        .when(tested.configService)
        .create(Mockito.eq(ContentManipulationLockService.CFGFILE_NAME), Mockito.anyMap());
    Assert.assertTrue(tested.createLock(PROVIDER_1));
    Mockito.verify(tested.configService).get(ContentManipulationLockService.CFGFILE_NAME);
    Mockito.verify(tested.configService)
        .create(Mockito.eq(ContentManipulationLockService.CFGFILE_NAME), Mockito.anyMap());
    Mockito.verifyNoMoreInteractions(tested.configService);

    // another lock exists so new one is added
    Mockito.reset(tested.configService);
    Mockito.when(tested.configService.get(ContentManipulationLockService.CFGFILE_NAME))
        .thenReturn(createCfgFileP1P2());
    Mockito.doAnswer(new StoreValidationgAnswer(PROVIDER_1, PROVIDER_2, PROVIDER_3))
        .when(tested.configService)
        .create(Mockito.eq(ContentManipulationLockService.CFGFILE_NAME), Mockito.anyMap());
    Assert.assertTrue(tested.createLock(PROVIDER_3));
    Mockito.verify(tested.configService).get(ContentManipulationLockService.CFGFILE_NAME);
    Mockito.verify(tested.configService)
        .create(Mockito.eq(ContentManipulationLockService.CFGFILE_NAME), Mockito.anyMap());
    Mockito.verifyNoMoreInteractions(tested.configService);

    // given lock exists so no new one is added
    Mockito.reset(tested.configService);
    Mockito.when(tested.configService.get(ContentManipulationLockService.CFGFILE_NAME))
        .thenReturn(createCfgFileP1P2());
    Assert.assertFalse(tested.createLock(PROVIDER_2));
    Mockito.verify(tested.configService).get(ContentManipulationLockService.CFGFILE_NAME);
    Mockito.verifyNoMoreInteractions(tested.configService);

    // all lock exists so no new one is added
    Mockito.reset(tested.configService);
    Mockito.when(tested.configService.get(ContentManipulationLockService.CFGFILE_NAME))
        .thenReturn(createCfgFileAll());
    Assert.assertFalse(tested.createLock(PROVIDER_2));
    Mockito.verify(tested.configService).get(ContentManipulationLockService.CFGFILE_NAME);
    Mockito.verifyNoMoreInteractions(tested.configService);
  }
  @SuppressWarnings("unchecked")
  @Test
  public void removeLock() {
    ContentManipulationLockService tested = getTested();

    // case - no any lock exists
    Mockito.when(tested.configService.get(ContentManipulationLockService.CFGFILE_NAME))
        .thenReturn(null);
    Assert.assertTrue(tested.removeLock(PROVIDER_1));
    Mockito.verify(tested.configService).get(ContentManipulationLockService.CFGFILE_NAME);
    Mockito.verifyNoMoreInteractions(tested.configService);

    // case - all lock exists so nothing removed
    Mockito.reset(tested.configService);
    Mockito.when(tested.configService.get(ContentManipulationLockService.CFGFILE_NAME))
        .thenReturn(createCfgFileAll());
    Assert.assertFalse(tested.removeLock(PROVIDER_1));
    Mockito.verify(tested.configService).get(ContentManipulationLockService.CFGFILE_NAME);
    Mockito.verifyNoMoreInteractions(tested.configService);

    // case - p1 removed from two
    Mockito.reset(tested.configService);
    Mockito.when(tested.configService.get(ContentManipulationLockService.CFGFILE_NAME))
        .thenReturn(createCfgFileP1P2());
    Mockito.doAnswer(new StoreValidationgAnswer(PROVIDER_2))
        .when(tested.configService)
        .create(Mockito.eq(ContentManipulationLockService.CFGFILE_NAME), Mockito.anyMap());
    Assert.assertTrue(tested.removeLock(PROVIDER_1));
    Mockito.verify(tested.configService).get(ContentManipulationLockService.CFGFILE_NAME);
    Mockito.verify(tested.configService)
        .create(Mockito.eq(ContentManipulationLockService.CFGFILE_NAME), Mockito.anyMap());
    Mockito.verifyNoMoreInteractions(tested.configService);

    // case - last one removed
    Mockito.reset(tested.configService);
    Mockito.when(tested.configService.get(ContentManipulationLockService.CFGFILE_NAME))
        .thenReturn(createCfgFile(PROVIDER_1));
    Assert.assertTrue(tested.removeLock(PROVIDER_1));
    Mockito.verify(tested.configService).get(ContentManipulationLockService.CFGFILE_NAME);
    Mockito.verify(tested.configService)
        .delete(Mockito.eq(ContentManipulationLockService.CFGFILE_NAME));
    Mockito.verifyNoMoreInteractions(tested.configService);
  }
示例#4
0
 @SuppressWarnings({"unchecked"})
 @Test
 public void addFailFieldValidator_ShouldNotCallFormValidator() {
   AttributeDefinition attrib1 =
       newAttribute("attrib1", "name1", "desc1").validator(new FailValidator()).build();
   FormValidator mock = Mockito.mock(FormValidator.class);
   Mockito.when(mock.fieldsToValidate()).thenReturn(Arrays.asList(new String[] {"attrib1"}));
   startEditorPanel(mock, attrib1);
   FormTester formTester = tester.newFormTester(editor.getId() + ":form");
   String component1Id = buildFormComponentId(attrib1.getId());
   formTester.setValue(component1Id, "a");
   tester.executeAjaxEvent(editor.getId() + ":form:submitButton", "onclick");
   Mockito.verify(mock, Mockito.never()).validate(Mockito.anyMap());
 }
示例#5
0
 /** Creates a standard hash of common test values for use with testing getters and setters. */
 private static void createTestValues() {
   testValues.put(Long.class, Long.valueOf(123L));
   testValues.put(Integer.class, Integer.valueOf(456));
   testValues.put(String.class, "FOOBAR");
   testValues.put(Double.class, Double.valueOf(123.456));
   testValues.put(Float.class, Float.valueOf(789.123f));
   testValues.put(BigDecimal.class, BigDecimal.ZERO);
   testValues.put(Boolean.class, Boolean.TRUE);
   testValues.put(Byte.class, Mockito.anyByte());
   testValues.put(Character.class, Mockito.anyChar());
   testValues.put(Collection.class, Mockito.anyCollection());
   testValues.put(List.class, Mockito.anyList());
   testValues.put(Set.class, Mockito.anySet());
   testValues.put(Map.class, Mockito.anyMap());
   testValues.put(JobStatus.class, JobStatus.PENDING);
   testValues.put(ReportType.class, ReportType.PDF);
 }