Search in sources :

Example 1 with EntryVelocityBasedStreamWriter

use of org.nextprot.api.web.service.impl.writer.EntryVelocityBasedStreamWriter in project nextprot-api by calipho-sib.

the class ExportXMLHeaderTest method testXMLExportHeaderRelease.

@Test
public void testXMLExportHeaderRelease() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Writer writer = new PrintWriter(out);
    EntryVelocityBasedStreamWriter exporter = new EntryXMLStreamWriter(writer, "overview");
    ReleaseInfoVersions rc = new ReleaseInfoVersions();
    rc.setApiRelease("api-test-version");
    rc.setDatabaseRelease("database-test-version");
    Map<String, Object> infos = new HashMap<>();
    infos.put(EntryStreamWriter.getReleaseInfoKey(), rc);
    exporter.write(Collections.emptyList(), infos);
    NodeList dbReleaseNodes = XMLUnitUtils.getMatchingNodes(out.toString(), "//*[local-name()='database-release']");
    assertEquals("database-test-version", dbReleaseNodes.item(0).getTextContent());
    NodeList apiReleaseNodes = XMLUnitUtils.getMatchingNodes(out.toString(), "//*[local-name()='api-release']");
    assertEquals("api-test-version", apiReleaseNodes.item(0).getTextContent());
    NodeList entriesCountNode = XMLUnitUtils.getMatchingNodes(out.toString(), "//*[local-name()='number-of-entries']");
    assertEquals("0", entriesCountNode.item(0).getTextContent());
}
Also used : ReleaseInfoVersions(org.nextprot.api.core.domain.release.ReleaseInfoVersions) HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) EntryXMLStreamWriter(org.nextprot.api.web.service.impl.writer.EntryXMLStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EntryVelocityBasedStreamWriter(org.nextprot.api.web.service.impl.writer.EntryVelocityBasedStreamWriter) PrintWriter(java.io.PrintWriter) EntryVelocityBasedStreamWriter(org.nextprot.api.web.service.impl.writer.EntryVelocityBasedStreamWriter) EntryXMLStreamWriter(org.nextprot.api.web.service.impl.writer.EntryXMLStreamWriter) Writer(java.io.Writer) EntryStreamWriter(org.nextprot.api.web.service.impl.writer.EntryStreamWriter) PrintWriter(java.io.PrintWriter) WebUnitBaseTest(org.nextprot.api.web.dbunit.base.mvc.WebUnitBaseTest) Test(org.junit.Test)

Example 2 with EntryVelocityBasedStreamWriter

use of org.nextprot.api.web.service.impl.writer.EntryVelocityBasedStreamWriter in project nextprot-api by calipho-sib.

the class ExportTXTHeaderTest method shouldContainTheNumberOfEntriesInTheHeader.

// TEST for https://issues.isb-sib.ch/browse/CALIPHOMISC-330
@Test
public void shouldContainTheNumberOfEntriesInTheHeader() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Writer writer = new PrintWriter(out);
    EntryVelocityBasedStreamWriter exporter = new EntryTXTStreamWriter(writer);
    exporter.setEntryBuilderService(entryBuilderMockService);
    when(entryBuilderMockService.build(any(EntryConfig.class))).thenReturn(new Entry("NX_1")).thenReturn(new Entry("NX_2"));
    Map<String, Object> infos = new HashMap<>();
    infos.put(EntryStreamWriter.getReleaseInfoKey(), Mockito.mock(ReleaseInfoVersions.class));
    exporter.write(Arrays.asList("NX_1", "NX_2"), infos);
    String[] rows = out.toString().split(StringUtils.CR_LF);
    assertEquals(rows[0], "#nb entries=2");
    assertEquals(rows[1], "NX_1");
    assertEquals(rows[2], "NX_2");
}
Also used : Entry(org.nextprot.api.core.domain.Entry) ReleaseInfoVersions(org.nextprot.api.core.domain.release.ReleaseInfoVersions) EntryTXTStreamWriter(org.nextprot.api.web.service.impl.writer.EntryTXTStreamWriter) HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EntryVelocityBasedStreamWriter(org.nextprot.api.web.service.impl.writer.EntryVelocityBasedStreamWriter) PrintWriter(java.io.PrintWriter) EntryTXTStreamWriter(org.nextprot.api.web.service.impl.writer.EntryTXTStreamWriter) EntryVelocityBasedStreamWriter(org.nextprot.api.web.service.impl.writer.EntryVelocityBasedStreamWriter) Writer(java.io.Writer) EntryStreamWriter(org.nextprot.api.web.service.impl.writer.EntryStreamWriter) PrintWriter(java.io.PrintWriter) WebUnitBaseTest(org.nextprot.api.web.dbunit.base.mvc.WebUnitBaseTest) Test(org.junit.Test)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintWriter (java.io.PrintWriter)2 Writer (java.io.Writer)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 ReleaseInfoVersions (org.nextprot.api.core.domain.release.ReleaseInfoVersions)2 WebUnitBaseTest (org.nextprot.api.web.dbunit.base.mvc.WebUnitBaseTest)2 EntryStreamWriter (org.nextprot.api.web.service.impl.writer.EntryStreamWriter)2 EntryVelocityBasedStreamWriter (org.nextprot.api.web.service.impl.writer.EntryVelocityBasedStreamWriter)2 Entry (org.nextprot.api.core.domain.Entry)1 EntryTXTStreamWriter (org.nextprot.api.web.service.impl.writer.EntryTXTStreamWriter)1 EntryXMLStreamWriter (org.nextprot.api.web.service.impl.writer.EntryXMLStreamWriter)1 NodeList (org.w3c.dom.NodeList)1