private void checkClientInfoAgainstPreparedMessages(ClientInfoListResult cliInfo, List<KapuaDataMessage> msgLst) { Set<String> msgClients = new HashSet<>(); Set<String> infoClients = new HashSet<>(); assertNotNull("No client info data!", cliInfo); assertNotNull("No messages to compare to!", msgLst); for (KapuaDataMessage tmpMsg : msgLst) { msgClients.add(tmpMsg.getClientId()); } for (ClientInfo tmpClient : cliInfo.getItems()) { infoClients.add(tmpClient.getClientId()); } assertEquals("The number of clients does not match!", msgClients.size(), infoClients.size()); for (String tmpClient : msgClients) { assertTrue(String.format("The client id [%s] is not found in the info list!", tmpClient), infoClients.contains(tmpClient)); } }
@Then("^There (?:is|are) exactly (\\d+) client(?:|s) in the list \"(.*)\"$") public void checkNumberOfQueriedClients(int cnt, String lstKey) { assertEquals(cnt, ((ClientInfoListResult) stepData.get(lstKey)).getSize()); }
@Then("^I get empty client info list result$") public void getEmptyClientInfoListResult() { ClientInfoListResult result = (ClientInfoListResult) stepData.get("clientInfoListResult"); assertTrue(result.isEmpty()); }
private void isClientForFirstMessageInStoreOK(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(ClientInfoField.CLIENT_ID, tmpClId)); ClientInfoQuery clientInfoQuery = DatastoreQueryFactory.createBaseClientInfoQuery(tmpAccId, 100); clientInfoQuery.setPredicate(andPredicate); clientInfoQuery.addFetchAttributes(ClientInfoField.TIMESTAMP.field()); ClientInfoListResult clientInfoList = clientInfoRegistryService.query(clientInfoQuery); assertNotNull("Cannot find the client info registry!", clientInfoList); assertNotEquals("Cannot find the client info registry!", clientInfoList.getSize(), 0); assertNotNull("Cannot find the client info registry!", clientInfoList.getFirstItem()); assertEquals("Wrong client info message id!", clientInfoList.getFirstItem().getFirstMessageId(), msgId); assertEquals("Wrong client info message on!", clientInfoList.getFirstItem().getFirstMessageOn(), storedOn); }
/** * Find client information by identifier * * @param scopeId * @param id * @return * @throws KapuaIllegalArgumentException * @throws ConfigurationException * @throws QueryMappingException * @throws ClientException */ public ClientInfo find(KapuaId scopeId, StorableId id) throws KapuaIllegalArgumentException, ConfigurationException, QueryMappingException, ClientException { ArgumentValidator.notNull(scopeId, "scopeId"); ArgumentValidator.notNull(id, "id"); ClientInfoQueryImpl idsQuery = new ClientInfoQueryImpl(scopeId); idsQuery.setLimit(1); IdsPredicateImpl idsPredicate = new IdsPredicateImpl(ClientInfoSchema.CLIENT_TYPE_NAME); idsPredicate.addValue(id); idsQuery.setPredicate(idsPredicate); ClientInfoListResult result = query(idsQuery); return result.getFirstItem(); }
@When("^I delete client number (\\d+) from the list \"(.*)\"$") public void deleteClientFromList(int index, String lstKey) throws KapuaException { Account account = (Account) stepData.get("LastAccount"); ClientInfoListResult tmpList = (ClientInfoListResult) stepData.get(lstKey); clientInfoRegistryServiceProxy.delete(account.getId(), tmpList.getItem(index).getId()); }
@Then("^Client \"(.+)\" first message in the list \"(.+)\" is on \"(.+)\"$") public void checkFirstPublishDateForClient(String clientId, String lstKey, String date) throws Exception { ClientInfoListResult cliList = (ClientInfoListResult) stepData.get(lstKey); Date tmpCaptured = KapuaDateUtils.parseDate(date); for (ClientInfo tmpInfo : cliList.getItems()) { if (tmpInfo.getClientId().equals(clientId)) { assertEquals(tmpInfo.getFirstMessageOn(), tmpCaptured); return; } } fail(String.format("No client info item matches the client id [%s]", clientId)); }
@Then("^Client \"(.+)\" last message in the list \"(.+)\" is on \"(.+)\"$") public void checkLastPublishDateForClient(String clientId, String lstKey, String date) throws Exception { ClientInfoListResult cliList = (ClientInfoListResult) stepData.get(lstKey); Date tmpCaptured = KapuaDateUtils.parseDate(date); for (ClientInfo tmpInfo : cliList.getItems()) { if (tmpInfo.getClientId().equals(clientId)) { assertEquals(tmpInfo.getLastMessageOn(), tmpCaptured); return; } } fail(String.format("No client info item matches the client id [%s]", clientId)); }
@When("^I delete all clients from the list \"(.*)\"$") public void deleteAllClientsFromList(String lstKey) throws KapuaException { Account account = (Account) stepData.get("LastAccount"); ClientInfoListResult tmpList = (ClientInfoListResult) stepData.get(lstKey); for (ClientInfo tmpItem : tmpList.getItems()) { clientInfoRegistryServiceProxy.delete(account.getId(), tmpItem.getId()); } }
@Override public ClientInfoListResult query(ClientInfoQuery query) throws KapuaException { ArgumentValidator.notNull(query, "query"); ArgumentValidator.notNull(query.getScopeId(), "query.scopeId"); checkAccess(query.getScopeId(), Actions.read); try { ClientInfoListResult result = clientInfoRegistryFacade.query(query); if (result != null && query.getFetchAttributes().contains(ClientInfoField.TIMESTAMP.field())) { // populate the lastMessageTimestamp for (ClientInfo clientInfo : result.getItems()) { updateLastPublishedFields(clientInfo); } } return result; } catch (Exception e) { throw KapuaException.internalError(e); } }