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)); } }
@When("^I pick the ID of the channel number (\\d+) in the list \"(.*)\" and remember it as \"(.*)\"$") public void pickAChannelIdFromAList(int index, String lstKey, String idKey) { ChannelInfoListResult tmpLst = (ChannelInfoListResult) stepData.get(lstKey); StorableId tmpId = tmpLst.getItem(index).getId(); stepData.put(idKey, tmpId); }
@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())); } }
private void isChannelForFirstMessageInStoreOK(StorableId msgId, Date storedOn) throws KapuaException { KapuaId tmpAccId = ((Account) stepData.get("LastAccount")).getId(); String tmpClId = ((Device) stepData.get("LastDevice")).getClientId(); AndPredicate andPredicate = new AndPredicateImpl(); andPredicate.getPredicates().add(new TermPredicateImpl(ChannelInfoField.CLIENT_ID, tmpClId)); ChannelInfoQuery channelInfoQuery = DatastoreQueryFactory.createBaseChannelInfoQuery(tmpAccId, 100); channelInfoQuery.setPredicate(andPredicate); channelInfoQuery.addFetchAttributes(ChannelInfoField.TIMESTAMP.field()); ChannelInfoListResult channelInfoList = channelInfoRegistryService.query(channelInfoQuery); assertNotNull("Cannot find the channel info registry!", channelInfoList); assertNotEquals("Cannot find the channel info registry!", channelInfoList.getSize(), 0); assertNotNull("Cannot find the channel info registry!", channelInfoList.getFirstItem()); assertEquals("Wrong channel info message id!", channelInfoList.getFirstItem().getFirstMessageId(), msgId); assertEquals("Wrong channel info message on!", channelInfoList.getFirstItem().getFirstMessageOn(), storedOn); }
/** * Find channel information by identifier * * @param scopeId * @param id * @return * @throws KapuaIllegalArgumentException * @throws ConfigurationException * @throws QueryMappingException * @throws ClientException */ public ChannelInfo find(KapuaId scopeId, StorableId id) throws KapuaIllegalArgumentException, ConfigurationException, QueryMappingException, ClientException { ArgumentValidator.notNull(scopeId, "scopeId"); ArgumentValidator.notNull(id, "id"); ChannelInfoQueryImpl idsQuery = new ChannelInfoQueryImpl(scopeId); idsQuery.setLimit(1); IdsPredicateImpl idsPredicate = new IdsPredicateImpl(ChannelInfoSchema.CHANNEL_TYPE_NAME); idsPredicate.addValue(id); idsQuery.setPredicate(idsPredicate); ChannelInfoListResult result = query(idsQuery); return result.getFirstItem(); }
@Then("^I get empty channel info list result$") public void getEmptyChannelInfoListResult() { ChannelInfoListResult result = (ChannelInfoListResult) stepData.get("channelInfoListResult"); assertTrue(result.isEmpty()); }
@Then("^There (?:is|are) exactly (\\d+) channel(?:|s) in the list \"(.*)\"$") public void checkNumberOfQueriedChannels(int cnt, String lstKey) { assertEquals(cnt, ((ChannelInfoListResult) stepData.get(lstKey)).getSize()); }
@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);