private void checkChannelInfoAgainstPreparedMessages(ChannelInfoListResult chnInfo, List<KapuaDataMessage> msgLst) { Set<String> msgTopics = new HashSet<>(); Set<String> msgClients = new HashSet<>(); Set<String> infoTopics = new HashSet<>(); Set<String> infoClients = new HashSet<>(); assertNotNull("No channel info data!", chnInfo); assertNotNull("No messages to compare to!", msgLst); for (KapuaDataMessage tmpMsg : msgLst) { msgClients.add(tmpMsg.getClientId()); msgTopics.add(tmpMsg.getChannel().toString()); } for (ChannelInfo tmpInfo : chnInfo.getItems()) { infoClients.add(tmpInfo.getClientId()); infoTopics.add(tmpInfo.getName()); } assertEquals("The number of clients does not match!", msgClients.size(), infoClients.size()); assertEquals("The number of topics does not match!", msgTopics.size(), infoTopics.size()); for (String tmpTopic : msgTopics) { assertTrue(String.format("The topic [%s] is not found in the info list!", tmpTopic), infoTopics.contains(tmpTopic)); } for (String tmpClient : msgClients) { assertTrue(String.format("The client id [%s] is not found in the info list!", tmpClient), infoClients.contains(tmpClient)); } }
@Then("^The channel list \"(.+)\" contains the following topics$") public void checkThattheChannelInfoContainsTheSpecifiedTopics(String lstKey, List<TestTopic> topics) { ChannelInfoListResult tmpList = (ChannelInfoListResult) stepData.get(lstKey); Set<String> infoTopics = new HashSet<>(); assertEquals("Wrong number of topics found!", tmpList.getSize(), topics.size()); for (ChannelInfo tmpInfo : tmpList.getItems()) { infoTopics.add(tmpInfo.getName()); } for (TestTopic tmpTop : topics) { assertTrue(String.format("The topic [%s] was not found!", tmpTop.getTopic()), infoTopics.contains(tmpTop.getTopic())); } }
@Then("^Client \"(.+)\" first published on a channel in the list \"(.+)\" on \"(.+)\"$") public void checkFirstPublishDateOnChannel(String clientId, String lstKey, String date) throws Exception { ChannelInfoListResult chnList = (ChannelInfoListResult) stepData.get(lstKey); Date tmpCaptured = KapuaDateUtils.parseDate(date); for (ChannelInfo tmpInfo : chnList.getItems()) { if (tmpInfo.getClientId().equals(clientId)) { assertEquals(tmpCaptured, tmpInfo.getFirstMessageOn()); return; } } fail(String.format("No channel matches the client id [%s]", clientId)); }
@Then("^Client \"(.+)\" last published on a channel in the list \"(.+)\" on \"(.+)\"$") public void checkLastPublishDateOnChannel(String clientId, String lstKey, String date) throws Exception { ChannelInfoListResult chnList = (ChannelInfoListResult) stepData.get(lstKey); Date tmpCaptured = KapuaDateUtils.parseDate(date); for (ChannelInfo tmpInfo : chnList.getItems()) { if (tmpInfo.getClientId().equals(clientId)) { assertEquals(tmpCaptured, tmpInfo.getLastMessageOn()); return; } } fail(String.format("No channel matches the client id [%s]", clientId)); }
@When("^I delete all channels from the list \"(.*)\"$") public void deleteAllChannelsFromList(String lstKey) throws KapuaException { Account account = (Account) stepData.get("LastAccount"); ChannelInfoListResult tmpList = (ChannelInfoListResult) stepData.get(lstKey); for (ChannelInfo tmpItem : tmpList.getItems()) { channelInfoRegistryServiceProxy.delete(account.getId(), tmpItem.getId()); } }
@Override public ChannelInfoListResult query(ChannelInfoQuery query) throws KapuaException { ArgumentValidator.notNull(query, "query"); ArgumentValidator.notNull(query.getScopeId(), "query.scopeId"); checkDataAccess(query.getScopeId(), Actions.read); try { ChannelInfoListResult result = channelInfoRegistryFacade.query(query); if (result != null && query.getFetchAttributes().contains(ChannelInfoField.TIMESTAMP.field())) { // populate the lastMessageTimestamp for (ChannelInfo channelInfo : result.getItems()) { updateLastPublishedFields(channelInfo); } } return result; } catch (Exception e) { throw KapuaException.internalError(e); } }
ChannelInfoListResult channels = query(query); for (ChannelInfo channelInfo : channels.getItems()) { mediator.onBeforeChannelInfoDelete(channelInfo);