Skip to content
This repository has been archived by the owner on Jul 3, 2018. It is now read-only.

Commit

Permalink
#2 testing on discovery service
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-conway committed Jun 2, 2016
1 parent 48d7790 commit e20de6a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,31 @@ public void setPublisherDiscoveryConfiguration(
public List<PublisherPluginDescription> listPublisherDescriptions() {
log.info("listPublisherDescriptions()");
Set<Class<?>> classes = listPublisherClasses();
List<PublisherPluginDescription> descriptions = new ArrayList<PublisherPluginDescription>();
PublisherPluginDescription description;
PublicationDriver driver;

for (Class<?> clazz : classes) {
log.info("processing class:{}", clazz);
for (Annotation annotation : clazz.getDeclaredAnnotations()) {
log.info("...annotation:{}", annotation.toString());
if (annotation instanceof PublicationDriver) {
driver = clazz.getAnnotation(PublicationDriver.class);
log.info("...annotation:{}", annotation.toString());
log.info("driver name:{}", driver.name());
description = new PublisherPluginDescription();
description.setAsynch(driver.isAsynch());
description.setAuthor(driver.author());
description.setDescription(driver.description());
description.setPublisherClass(clazz);
description.setPublisherName(driver.name());
description.setVersion(driver.version());
descriptions.add(description);
}

}
}

return null;
return descriptions;

}

Expand Down Expand Up @@ -159,8 +175,10 @@ private void loadPublisherClasses(String libDir) {
}
}

DefaultContextLoader context = new DefaultContextLoader(jcl);
context.loadContext();
if (JclContext.get() == null) {
DefaultContextLoader context = new DefaultContextLoader(jcl);
context.loadContext();
}

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.iplantc.de.publish.discovery;

import java.io.File;
import java.util.List;
import java.util.Properties;

Expand Down Expand Up @@ -43,19 +44,37 @@ public void testInitWithConfig() throws PublicationException {
}

@Test
public void testListPublicationDescriptions() throws PublicationException {
public void testListPublicationDescriptions() throws Exception {
File testDriver = PublisherTestingProperties
.getClasspathResourceAsFile("/sample-jars/dummy-publish-1.0.0-SNAPSHOT.jar");
PublisherDiscoveryConfiguration publisherDiscoveryConfiguration = new PublisherDiscoveryConfiguration();
publisherDiscoveryConfiguration
.setJarFilePluginDir(testingProperties
.getProperty(PublisherTestingProperties.TEST_PUBLISHER_DIR_PROPERTY));
publisherDiscoveryConfiguration.setJarFilePluginDir(testDriver
.getParent());
// testingProperties
// .getProperty(PublisherTestingProperties.TEST_PUBLISHER_DIR_PROPERTY));
PublisherDiscoveryService publisherDiscoveryService = new PublisherDiscoveryService();
publisherDiscoveryService
.setPublisherDiscoveryConfiguration(publisherDiscoveryConfiguration);
publisherDiscoveryService.init();
List<PublisherPluginDescription> descriptions = publisherDiscoveryService
.listPublisherDescriptions();
Assert.assertNotNull("null descriptions found:{}", descriptions);
String dummyName = "Dummy Logging";
boolean found = false;

}
for (PublisherPluginDescription description : descriptions) {
if (!description.getPublisherName().equals(dummyName)) {
continue;
}

Assert.assertFalse(description.getAuthor().isEmpty());
Assert.assertFalse(description.getDescription().isEmpty());
Assert.assertFalse(description.getPublisherName().isEmpty());
Assert.assertFalse(description.getVersion().isEmpty());
found = true;
}

Assert.assertTrue("didnt find test driver", found);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
*/
package org.iplantc.de.publish.discovery;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Properties;

import org.irods.jargon.core.exception.JargonException;
import org.irods.jargon.core.utils.LocalFileUtils;
import org.irods.jargon.testutils.TestingUtilsException;

/**
Expand Down Expand Up @@ -52,4 +57,29 @@ public Properties getTestProperties() throws TestingUtilsException {
return properties;
}

public static File getClasspathResourceAsFile(final String resourcePath)
throws JargonException {

if (resourcePath == null || resourcePath.isEmpty()) {
throw new IllegalArgumentException("null or empty resourcePath");
}
// Load the directory as a resource
URL resourceUrl = LocalFileUtils.class.getResource(resourcePath);

if (resourceUrl == null) {
throw new JargonException("null resource, cannot find file");
}

// Turn the resource into a File object
try {
File resourceFile = new File(resourceUrl.toURI());
if (!resourceFile.exists()) {
throw new JargonException("resource file does not exist");
}
return resourceFile;
} catch (URISyntaxException e) {
throw new JargonException("unable to create uri from file path");
}
}

}

0 comments on commit e20de6a

Please sign in to comment.