From 74581f132ee134ca0c1c047f0aa0af2969d66580 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Thu, 3 Oct 2019 14:54:37 +0200 Subject: [PATCH] Added test --- .../resourceregistry/er/DiscoveryTest.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/test/java/org/gcube/informationsystem/resourceregistry/er/DiscoveryTest.java diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/er/DiscoveryTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/er/DiscoveryTest.java new file mode 100644 index 0000000..b2f771d --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/er/DiscoveryTest.java @@ -0,0 +1,49 @@ +package org.gcube.informationsystem.resourceregistry.er; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.ServiceLoader; + +import org.gcube.informationsystem.model.reference.entities.Resource; +import org.gcube.informationsystem.types.TypeBinder; +import org.gcube.informationsystem.utils.discovery.ISMDiscovery; +import org.gcube.informationsystem.utils.discovery.RegistrationProvider; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DiscoveryTest { + + private static Logger logger = LoggerFactory.getLogger(DiscoveryTest.class); + + @Test + public void discover() throws Exception { + ServiceLoader regsitrationProviders = ServiceLoader + .load(RegistrationProvider.class); + List packages = new ArrayList<>(); + for(RegistrationProvider registrationProvider : regsitrationProviders) { + packages.addAll(registrationProvider.getPackagesToRegister()); + } + Package[] packagesArray = packages.stream().toArray(Package[]::new); + + ISMDiscovery resourceDiscovery = new ISMDiscovery<>(Resource.class); + Arrays.stream(packagesArray).forEach(p -> resourceDiscovery.addPackage(p)); + resourceDiscovery.discover(); + + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("["); + boolean first = true; + for (Class resource : resourceDiscovery.getDiscovered()) { + if(first) { + first = false; + }else { + stringBuilder.append(","); + } + stringBuilder.append(TypeBinder.serializeType(resource)); + } + stringBuilder.append("]"); + logger.debug(stringBuilder.toString()); + } + +}