use of org.apache.stanbol.entityhub.indexing.core.IndexingDestination in project stanbol by apache.
the class SolrYardIndexingDestinationTest method validateSolrDestination.
/**
* Checks if the SolrYardIndexingDestination returned by the
* {@link IndexingConfig} is valid and functional
* @param config the configuration
* @throws YardException indicates problems while working with the {@link SolrYard}
* returned by {@link IndexingDestination#getYard()}
* @throws IOException indicates problems while validating the SolrArchives
* created by the {@link IndexingDestination#finalise()} method
*/
private void validateSolrDestination(IndexingConfig config) throws YardException, IOException {
// get the destination
IndexingDestination destination = config.getIndexingDestination();
assertNotNull(destination);
assertEquals(destination.getClass(), SolrYardIndexingDestination.class);
// initialise
assertTrue(destination.needsInitialisation());
destination.initialise();
// test that the returned Yard instance is functional
Yard yard = destination.getYard();
assertNotNull(yard);
assertEquals(yard.getClass(), SolrYard.class);
Representation rep = yard.getValueFactory().createRepresentation("http://www.example.com/entity#123");
rep.add(NamespaceEnum.rdfs + "label", "test");
rep.add(NamespaceEnum.rdfs + "description", "Representation to test storage while indexing");
rep.add(RdfResourceEnum.entityRank.getUri(), Float.valueOf(0.8f));
yard.store(rep);
// finalise
destination.finalise();
// test the archives
File expectedSolrArchiveFile = new File(config.getDistributionFolder(), config.getName() + ".solrindex.zip");
assertTrue(expectedSolrArchiveFile.isFile());
// validate the archive
ZipFile archive = new ZipFile(expectedSolrArchiveFile);
Set<String> expected = new HashSet<String>(EXPECTED_INDEX_ARCHIVE_FILE_NAMES);
for (Enumeration<? extends ZipEntry> entries = archive.entries(); entries.hasMoreElements(); ) {
ZipEntry entry = entries.nextElement();
// the name of the index MUST be the root folder within the Archive!
assertTrue(entry.getName().startsWith(config.getName()));
String name = FilenameUtils.getName(entry.getName());
if (expected.remove(name)) {
log.info("found expected Entry '{}'", entry.getName());
}
Assert.assertFalse("found unexpected Entry '" + entry.getName() + "' in " + "SolrIndexArchive", UNEXPECTED_INDEX_ARCHIVE_FILE_NAMES.contains(name));
}
assertTrue("missing Files in index archive: " + expected, expected.isEmpty());
// TODO: reimplement to validate the created bundle!
// //check for the solrArchive reference file and validate required properties
// File expectedSolrArchiveReferenceFile =
// new File(,config.getName()+".solrindex.ref");
// assertTrue(expectedSolrArchiveReferenceFile.isFile());
// Properties solrRefProperties = new Properties();
// solrRefProperties.load(new FileInputStream(expectedSolrArchiveReferenceFile));
// assertTrue(solrRefProperties.getProperty("Index-Archive").equals(expectedSolrArchiveFile.getName()));
// assertTrue(solrRefProperties.getProperty("Name") != null);
}
Aggregations