InventoryServiceIspn implements InventoryService { @Override public ResultSet<Resource> getResources(ResourceFilter filter, long startOffset, int maxResults) { QueryBuilder qb = qResource.from(IspnResource.class); FilterConditionContextQueryBuilder fccqb = null; if (filter.isRootOnly()) { fccqb = qb.having("parentId").isNull(); } if (filter.getTypeId() != null) { fccqb = (fccqb == null ? qb : fccqb.and()).having("typeId").equal(filter.getTypeId()); } if (filter.getFeedId() != null) { fccqb = (fccqb == null ? qb : fccqb.and()).having("feedId").equal(filter.getFeedId()); } Query query = (fccqb == null ? qb : fccqb) .maxResults(maxResults) .startOffset(startOffset).build(); List<IspnResource> ispnResources = query.list(); List<Resource> result = ispnResources .stream() .map(r -> r.toResource(this::getResourceType)) .collect(Collectors.toList()); return new ResultSet<>(result, (long) query.getResultSize(), startOffset); } InventoryServiceIspn();   InventoryServiceIspn(Cache<String, Object> resource, Cache<String, Object> resourceType, String configPath, InventoryStatsMBean inventoryStatsMBean, ScrapeConfig scrapeConfig, File scrapeLocation); @Override void addResource(RawResource r); @Override void addResource(Collection<RawResource> resources); @Override void addResourceType(ResourceType rt); @Override void addResourceType(Collection<ResourceType> resourceTypes); @Override void deleteResources(Collection<String> ids); @Override void deleteAllResources(); @Override void deleteResourceTypes(Collection<String> typeIds); @Override void deleteAllTypes(); @Override Optional<Resource> getResourceById(String id); @Override Optional<ResourceNode> getTree(String parentId); @Override ResultSet<Resource> getResources(ResourceFilter filter, long startOffset, int maxResults); @Override ResultSet<Resource> getResources(ResourceFilter filter); @Override ResultSet<ResourceType> getResourceTypes(long startOffset, int maxResults); @Override ResultSet<ResourceType> getResourceTypes(); @Override Optional<ResourceType> getResourceType(String typeId); @Override Optional<String> getAgentConfig(String templateName); @Override Optional<String> getJMXExporterConfig(String templateName); @Override boolean isRunning(); @Override ResultSet<Resource> getChildren(String parentId); @Override ResultSet<Resource> getChildren(String parentId, long startOffset, int maxResults); @Override void buildExport(OutputStream os); @Override InventoryHealth getHealthStatus(); @Override void buildMetricsEndpoints();  }
@Test public void shouldGetAllFOOs() { assertThat(service.getResources(ResourceFilter.ofType("FOO").build()).getResults()) .extracting(Resource::getId) .containsOnly("child-1", "child-3"); }
@Test public void shouldGetAllEAPsPerFeed() { assertThat(service.getResources(ResourceFilter.ofType("EAP").andFeed("feed1").build()).getResults()) .extracting(Resource::getId) .containsOnly("EAP-1"); assertThat(service.getResources(ResourceFilter.ofType("EAP").andFeed("feed2").build()).getResults()) .extracting(Resource::getId) .containsOnly("EAP-2"); }
@Test public void shouldGetTopResources() { Collection<Resource> top = service.getResources(ResourceFilter.rootOnly().build()).getResults(); assertThat(top) .extracting(Resource::getName) .containsOnly("EAP-1", "EAP-2"); assertThat(top) .extracting(Resource::getType) .extracting(ResourceType::getId) .containsOnly("EAP", "EAP"); }
@Test public void shouldGetAllEAPs() { assertThat(service.getResources(ResourceFilter.ofType("EAP").build()).getResults()) .extracting(Resource::getId) .containsOnly("EAP-1", "EAP-2"); }