HistoryUtil { protected void createPath(String path, ResourceResolver resolver, String primaryType) throws AecuException { Resource folder = resolver.getResource(path); if (folder == null) { String parent = path.substring(0, path.lastIndexOf('/')); String name = path.substring(path.lastIndexOf('/') + 1); if (resolver.getResource(parent) == null) { createPath(parent, resolver, primaryType); } Map<String, Object> properties = new HashMap<>(); properties.put(JcrConstants.JCR_PRIMARYTYPE, primaryType); try { resolver.create(resolver.getResource(parent), name, properties); } catch (PersistenceException e) { throw new AecuException("Unable to create " + path, e); } } }  HistoryEntry createHistoryEntry(ResourceResolver resolver); void storeExecutionInHistory(HistoryEntry history, ExecutionResult result, ResourceResolver resolver); void finishHistoryEntry(HistoryEntry history, ResourceResolver resolver); List<HistoryEntry> getHistory(int startIndex, int count, ResourceResolver resolver); Resource getHistoryEntryResource(Resource child); HistoryEntry readHistoryEntry(Resource resource); ExecutionResult readHistorySingleResult(Resource resource); void purgeHistory(ResourceResolver resolver, int daysToKeep); void selfCheck(ResourceResolver resolver); static final String HISTORY_BASE; static final String NODE_FALLBACK; static final String ATTR_PATH; }
@Test public void createPath_Existing() throws AecuException { String path = "/var/aecu/2018/5"; when(resolver.getResource(path)).thenReturn(mock(Resource.class)); historyUtil.createPath(path, resolver, JcrResourceConstants.NT_SLING_FOLDER); verify(historyUtil, times(1)).createPath(anyString(), eq(resolver), eq(JcrResourceConstants.NT_SLING_FOLDER)); }
@Test public void createPath_NotExisting() throws AecuException, PersistenceException { String path = "/var/aecu/2018/5"; when(resolver.getResource("/var/aecu/2018")).thenReturn(mock(Resource.class)); historyUtil.createPath(path, resolver, JcrResourceConstants.NT_SLING_FOLDER); verify(historyUtil, times(1)).createPath(anyString(), eq(resolver), eq(JcrResourceConstants.NT_SLING_FOLDER)); verify(resolver, times(1)).create(any(Resource.class), eq("5"), any()); }