ServiceResourceService { @EventListener public void reportArchiveUsage(ArchiveUsageRequestEvent event) { ServiceResource[] serviceResources = alienDAO.buildQuery(ServiceResource.class) .setFilters(fromKeyValueCouples("dependency.name", event.getArchiveName(), "dependency.version", event.getArchiveVersion())).prepareSearch() .search(0, Integer.MAX_VALUE).getData(); for (ServiceResource serviceResource : serviceResources) { Usage usage = new Usage(serviceResource.getName(), ServiceResource.class.getSimpleName().toLowerCase(), serviceResource.getId(), ""); event.addUsage(usage); } }  String create(String serviceName, String serviceVersion, String serviceNodeType, String serviceNodeVersion); String create(String serviceName, String serviceVersion, String serviceNodeType, String serviceNodeVersion, String environmentId); GetMultipleDataResult<ServiceResource> list(int from, int count); FacetedSearchResult<ServiceResource> search(String searchText, Map<String, String[]> filters, String sortField, boolean desc, int from,
            int count); ServiceResource getOrFail(String id); void update(String resourceId, String name, String version, String description, String nodeType, String nodeTypeVersion,
            Map<String, AbstractPropertyValue> nodeProperties, Map<String, Capability> nodeCapabilities, Map<String, String> nodeAttributeValues,
            String[] locations, Map<String, String> capabilitiesRelationshipTypes, Map<String, String> requirementsRelationshipTypes); String duplicate(String serviceId); void patch(String resourceId, String name, String version, String description, String nodeType, String nodeTypeVersion,
            Map<String, AbstractPropertyValue> nodeProperties, Map<String, Capability> nodeCapabilities, Map<String, String> nodeAttributeValues,
            String[] locations, Map<String, String> capabilitiesRelationshipTypes, Map<String, String> requirementsRelationshipTypes); synchronized void save(ServiceResource serviceResource, boolean ensureUniqueness); synchronized void save(ServiceResource serviceResource); synchronized void delete(String id); @EventListener synchronized void handleLocationDeleted(AfterLocationDeleted event); List<ServiceResource> searchByLocation(String locationId); ServiceResource[] getByNodeTypes(String nodeType, String nodeTypeVersion); void isLocationAuthorized(String serviceId, String locationId); @EventListener void reportArchiveUsage(ArchiveUsageRequestEvent event);  }
@Test public void testReportArchiveUsage() { ServiceResource serviceResource = new ServiceResource(); serviceResource.setId("service1"); serviceResource.setName("service name 1"); serviceResource.setDependency(new CSARDependency("org.alien4cloud.archives:my-archive", "1.0.0-SNAPSHOT")); alienDao.save(serviceResource); ArchiveUsageRequestEvent archiveUsageRequestEvent = new ArchiveUsageRequestEvent(this, "org.alien4cloud.archives:my-archive", "1.0.0-SNAPSHOT"); serviceResourceService.reportArchiveUsage(archiveUsageRequestEvent); Assert.assertEquals(1, archiveUsageRequestEvent.getUsages().size()); Assert.assertEquals("service1", archiveUsageRequestEvent.getUsages().get(0).getResourceId()); Assert.assertEquals("serviceresource", archiveUsageRequestEvent.getUsages().get(0).getResourceType()); Assert.assertEquals("service name 1", archiveUsageRequestEvent.getUsages().get(0).getResourceName()); archiveUsageRequestEvent = new ArchiveUsageRequestEvent(this, "org.alien4cloud.archives:other-archive", "1.0.0-SNAPSHOT"); serviceResourceService.reportArchiveUsage(archiveUsageRequestEvent); Assert.assertEquals(0, archiveUsageRequestEvent.getUsages().size()); archiveUsageRequestEvent = new ArchiveUsageRequestEvent(this, "org.alien4cloud.archives:my-archive", "1.0.1-SNAPSHOT"); serviceResourceService.reportArchiveUsage(archiveUsageRequestEvent); Assert.assertEquals(0, archiveUsageRequestEvent.getUsages().size()); }