Commit e9c3988d authored by Gerrit Hübbers's avatar Gerrit Hübbers 🃏
Browse files

WIP test

parent 1d2b268a
......@@ -22,7 +22,6 @@ import javax.xml.transform.stream.StreamSource;
import org.gesis.dda.publishing.domain.Bundle;
import org.gesis.dda.publishing.domain.BundlesStreamSource;
import org.gesis.dda.publishing.domain.Metadatum;
import org.gesis.dda.transformer.XmlBundles;
import org.gesis.dda.xslt.XsltUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -53,19 +52,8 @@ public class XmlXsltBundlesStreamSource implements BundlesStreamSource {
@Override
public Stream<Bundle> getBundlesStream() {
try {
//TransformerFactory factory = TransformerFactory.newInstance();
TransformerFactory factory = TransformerFactory.newInstance("org.apache.xalan.processor.TransformerFactoryImpl", TransformerFactoryImpl.class.getClassLoader() );
/*
net.sf.saxon.TransformerFactoryImpl factory = (TransformerFactoryImpl) TransformerFactory.newInstance("net.sf.saxon.TransformerFactoryImpl", net.sf.saxon.TransformerFactoryImpl.class.getClassLoader() );
net.sf.saxon.Configuration saxonConfig = factory.getConfiguration();
Processor processor = (Processor) saxonConfig.getProcessor();
ExtensionFunction test = new Test();
processor.registerExtensionFunction(test);
ExtensionFunction callJava = new CallJavaExtensionFunction();
processor.registerExtensionFunction(callJava);
*/
Templates xslTemplate = factory.newTemplates( new StreamSource( new StringReader(xslt) ) );
Source xmlInput = new StreamSource( new StringReader(xmlPayload) );
......
package org.gesis.dda.publishing.domain.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.io.StringReader;
......@@ -26,6 +27,8 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.sf.saxon.TransformerFactoryImpl;
public class XmlXsltBundlesStreamSourceTest {
......@@ -47,9 +50,7 @@ public class XmlXsltBundlesStreamSourceTest {
LOG.info("xsltString={}", xsltString);
// --- STEP 2: convert XML input according to XSLT
TransformerFactory factory = TransformerFactory.newInstance();
TransformerFactory factory = TransformerFactory.newInstance("org.apache.xalan.processor.TransformerFactoryImpl", TransformerFactoryImpl.class.getClassLoader() );
Templates xslTemplate = factory.newTemplates( new StreamSource( new StringReader(xsltString) ) );
Source xmlInput = new StreamSource( new StringReader(onixXmlString) );
......@@ -64,30 +65,6 @@ public class XmlXsltBundlesStreamSourceTest {
LOG.info("---CONVERTED-----------------------");
LOG.info("{}", xsltConvertedXmlOutput);
/*
// STEP 3: convert XSLT-converted XML output to Java JAXB object
JAXBContext jaxbContext = JAXBContext.newInstance(XmlBundle.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
InputStream convertedXmlInputStream = new ByteArrayInputStream(xsltConvertedXmlOutput.getBytes(StandardCharsets.UTF_8) );
Bundle currentPartBundle = (Bundle) unmarshaller.unmarshal(convertedXmlInputStream);
bundleMetadata.addAll( currentPartBundle.getMetadata() );
// STEP 4: extract lastModifiedDate
StringReader sr = new StringReader(getRecordXmlDocumentResponseString);
//LOG.info("sr=\n{}", getRecordXmlDocumentResponseString);
JAXBContext oaiPmhjaxbContext = JAXBContext.newInstance(OAIPMHtype.class);
Unmarshaller oaiPmhUnmarshaller = oaiPmhjaxbContext.createUnmarshaller();
@SuppressWarnings("unchecked")
JAXBElement<OAIPMHtype> wrappedResponseObject = (JAXBElement<OAIPMHtype>) oaiPmhUnmarshaller.unmarshal(sr);
OAIPMHtype response = wrappedResponseObject.getValue();
lastModifiedString = response.getGetRecord().getRecord().getHeader().getDatestamp();
// STEP 5: add identifier metadatum
Metadatum reference = new SimpleMetadatum("internal.dda.reference", oaiPmhEndpoint + "@@" + oaiPmhIdentifier);
bundleMetadata.add(reference);
resultBundle = BundleBuilder.create().withMetadata(bundleMetadata).withLastModifiedString(lastModifiedString).build();
*/
}
@Test
......@@ -201,4 +178,11 @@ public class XmlXsltBundlesStreamSourceTest {
assertEquals("collection", bildungsforschungBundle.getMetadata().stream().filter(m -> m.getKey().equals("dc.type.stock")).findFirst().get().getValue() );
}
}
@Test
public void testGetAllMetadata() {
// TODO to be implemented
fail();
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment