@When("^I search for device with tag \"([^\"]*)\"$") public void iSearchForDeviceWithTag(String deviceTagName) throws Throwable { Account lastAcc = (Account) stepData.get("LastAccount"); DeviceQueryImpl deviceQuery = new DeviceQueryImpl(lastAcc.getId()); KapuaQuery<Tag> tagQuery = new TagFactoryImpl().newQuery(lastAcc.getId()); tagQuery.setPredicate(new AttributePredicateImpl<>(TagAttributes.NAME, deviceTagName, AttributePredicate.Operator.EQUAL)); TagListResult tagQueryResult = tagService.query(tagQuery); Tag tag = tagQueryResult.getFirstItem(); deviceQuery.setPredicate(AttributePredicateImpl.attributeIsEqualTo(DeviceAttributes.TAG_IDS, tag.getId())); DeviceListResult deviceList = deviceRegistryService.query(deviceQuery); stepData.put("DeviceList", deviceList); }
@When("^I search for events from device \"(.+)\" in account \"(.+)\"$") public void searchForEventsFromDeviceWithClientID(String clientId, String account) throws KapuaException { DeviceEventQuery tmpQuery; Device tmpDev; DeviceEventListResult tmpList; Account tmpAcc; tmpAcc = KapuaLocator.getInstance().getService(AccountService.class).findByName(account); Assert.assertNotNull(tmpAcc); Assert.assertNotNull(tmpAcc.getId()); tmpDev = deviceRegistryService.findByClientId(tmpAcc.getId(), clientId); Assert.assertNotNull(tmpDev); Assert.assertNotNull(tmpDev.getId()); tmpQuery = new DeviceEventQueryImpl(tmpAcc.getId()); tmpQuery.setPredicate(AttributePredicateImpl.attributeIsEqualTo("deviceId", tmpDev.getId())); tmpQuery.setSortCriteria(new FieldSortCriteria("receivedOn", FieldSortCriteria.SortOrder.ASCENDING)); tmpList = deviceEventsService.query(tmpQuery); Assert.assertNotNull(tmpList); stepData.put("DeviceEventList", tmpList); }