/** * {@inheritDoc} */ @Override @MethodLog public List<? extends DefaultData> getTemplatesDataObjectsFromToDate(Collection<DefaultData> templates, Date fromDate, Date toDate) { if (fromDate.after(toDate)) { return Collections.emptyList(); } List<DefaultData> result = new ArrayList<>(); for (DefaultData template : templates) { result.addAll(this.getDataObjectsFromToDate(template, fromDate, toDate)); } return result; }
/** * No delete enabled when platform ident can not be found. */ @Test(expectedExceptions = { BusinessException.class }) public void testNonExistingAgentDelete() throws BusinessException { long platformId = 10L; when(platformIdentDao.load(Long.valueOf(platformId))).thenReturn(null); globalDataAccessService.deleteAgent(platformId); }
/** * No delete enabled when agent is connected. */ @Test(expectedExceptions = { BusinessException.class }) public void testConnectedAgentDelete() throws BusinessException { long platformId = 10L; PlatformIdent platformIdent = new PlatformIdent(); platformIdent.setId(platformId); when(platformIdentDao.load(Long.valueOf(platformId))).thenReturn(platformIdent); Map<Long, AgentStatusData> map = new HashMap<>(1); AgentStatusData agentStatusData = new AgentStatusData(AgentConnection.CONNECTED); map.put(platformId, agentStatusData); when(agentStatusProvider.getAgentStatusDataMap()).thenReturn(map); globalDataAccessService.deleteAgent(platformId); }
/** * Delete enabled when Agent is not connected. */ @Test public void testAgentDelete() throws BusinessException { long platformId = 10L; PlatformIdent platformIdent = new PlatformIdent(); platformIdent.setId(platformId); when(platformIdentDao.load(Long.valueOf(platformId))).thenReturn(platformIdent); Map<Long, AgentStatusData> map = new HashMap<>(1); AgentStatusData agentStatusData = new AgentStatusData(AgentConnection.DISCONNECTED); map.put(platformId, agentStatusData); when(agentStatusProvider.getAgentStatusDataMap()).thenReturn(map); globalDataAccessService.deleteAgent(platformId); verify(platformIdentDao, times(1)).delete(platformIdent); verify(defaultDataDao, times(1)).deleteAll(platformId); ArgumentCaptor<ApplicationEvent> captor = ArgumentCaptor.forClass(ApplicationEvent.class); verify(eventPublisher, times(1)).publishEvent(captor.capture()); AgentDeletedEvent event = (AgentDeletedEvent) captor.getValue(); assertThat(event.getPlatformId(), is(platformId)); } }