TeamCityCustomDataStoreService implements DataStoreService<HighlightData> { @Override public void saveData(@NotNull SBuild sBuild, HighlightData data) { if (sBuild == null || sBuild.getBuildType() == null) { LOG.warning("Couldn't save data as build or associated build type was null."); return; } if (data == null) { LOG.warning("Couldn't save data as it was empty."); return; } if (data.getKey() == null) { LOG.warning("Couldn't save data as the message title was not given"); return; } final CustomDataStorage customDataStorage = sBuild.getBuildType().getCustomDataStorage(STORAGE_PREFIX + sBuild.getBuildId()); final CustomStorageMap customStorageMap = new CustomStorageMap(loadDataInternal(sBuild), data.getLevel(), data.getBlock(), data.getOrder()); customStorageMap.put(data.getKey(), data.getSingleValue()); final Set<String> keys = customStorageMap.keySet(); for (String key : keys) { customDataStorage.putValue(key, customStorageMap.get(key)); } customDataStorage.flush(); }  @Override void saveData(@NotNull SBuild sBuild, HighlightData data); @Override Collection<HighlightData> loadData(@NotNull SBuild sBuild);  }
@Test public void testSaveData() throws Exception { when(highlightData.getKey()).thenReturn("Some title"); when(highlightData.getSingleValue()).thenReturn("Some text"); when(highlightData.getLevel()).thenReturn(Level.error); when(highlightData.getBlock()).thenReturn(Block.collapsed); dataStoreService.saveData(sBuild, highlightData); verify(customDataStorage).putValue(eq("text"), eq("Some text")); verify(customDataStorage).putValue(eq("title"), eq("Some title")); verify(customDataStorage).putValue(eq("level"), eq("error")); verify(customDataStorage).putValue(eq("Some title::error::collapsed"), eq("Some text")); verify(customDataStorage).flush(); }
@Test public void testSaveData_null_sbuild_type() throws Exception { when(sBuild.getBuildType()).thenReturn(null); dataStoreService.saveData(sBuild, highlightData); verify(customDataStorage, never()).putValue(anyString(), anyString()); verify(customDataStorage, never()).flush(); }
@Test public void testSaveData_empty_data() throws Exception { dataStoreService.saveData(sBuild, highlightData); verify(customDataStorage, never()).putValue(anyString(), anyString()); verify(customDataStorage, never()).flush(); }
@Test public void testSaveData_no_title_in_data() throws Exception { when(highlightData.getKey()).thenReturn(null); dataStoreService.saveData(sBuild, highlightData); verify(customDataStorage, never()).putValue(anyString(), anyString()); verify(customDataStorage, never()).flush(); }