Search in sources :

Example 1 with MemoryBuffer

use of com.opentext.ia.sdk.support.io.MemoryBuffer in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class WhenAssemblingFromTemplate method shouldWriteTemplatedValues.

@Test
public void shouldWriteTemplatedValues() throws IOException {
    Person p1 = newPerson(aName(), anEmail());
    Person p2 = newPerson(aName(), anEmail());
    @SuppressWarnings("unchecked") Template<Person> template = mock(Template.class);
    MemoryBuffer buffer = new MemoryBuffer();
    TemplatePdiAssembler<Person> assembler = new TemplatePdiAssembler<Person>(template, null);
    assembler.start(buffer);
    assembler.add(hashedContents(p1));
    assembler.add(hashedContents(p2));
    assembler.end();
    verify(template).writeHeader(any(PrintWriter.class));
    verify(template).writeRow(eq(p1), eq(Collections.emptyMap()), any(PrintWriter.class));
    verify(template).writeRow(eq(p2), eq(Collections.emptyMap()), any(PrintWriter.class));
    verify(template).writeFooter(any(PrintWriter.class));
}
Also used : MemoryBuffer(com.opentext.ia.sdk.support.io.MemoryBuffer) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 2 with MemoryBuffer

use of com.opentext.ia.sdk.support.io.MemoryBuffer in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class WhenAssemblingXmlPdis method assemblePdi.

private void assemblePdi(InputStream schema) throws IOException {
    Assembler<HashedContents<String>> pdiAssembler = new TestPdiAssembler(schema);
    pdiAssembler.start(new MemoryBuffer());
    pdiAssembler.end();
}
Also used : MemoryBuffer(com.opentext.ia.sdk.support.io.MemoryBuffer)

Example 3 with MemoryBuffer

use of com.opentext.ia.sdk.support.io.MemoryBuffer in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class WhenAssemblingSipsWithDedup method before.

@Before
public void before() {
    buffer = new MemoryBuffer();
    pdiAssembler = new XmlPdiAssembler<TestObject>(URI.create("test"), "objects") {

        @Override
        protected void doAdd(TestObject domainObject, Map<String, ContentInfo> contentInfo) {
            getBuilder().element("object").element("id", domainObject.getId()).elements("contents", "content", domainObject.getContentId(), (cid, builder) -> builder.attribute("cid", contentInfo.get(cid).getReferenceInformation()));
        }
    };
    prototype = PackagingInformation.builder().dss().application("app").schema("test").holding("holding").entity("entity").end().build();
    // default mapping
    contentIdToResourceName = new HashMap<>();
    contentIdToResourceName.put(OBJECT_ID_1, CONTENT_1);
    contentIdToResourceName.put(OBJECT_ID_2, CONTENT_2);
    contentIdToResourceName.put(OBJECT_ID_3, CONTENT_3);
    contentIdToResourceName.put(OBJECT_ID_4, CONTENT_4);
    contentIdToResourceName.put(OBJECT_ID_5, CONTENT_5);
    contentsExtraction = t -> t.getContentId().stream().map(cid -> DigitalObject.fromResource(cid, getClass(), contentIdToResourceName.get(cid))).collect(Collectors.toList()).iterator();
}
Also used : java.util(java.util) MemoryBuffer(com.opentext.ia.sdk.support.io.MemoryBuffer) DataBuffer(com.opentext.ia.sdk.support.io.DataBuffer) SipFileValidator(com.opentext.ia.sdk.support.test.validation.SipFileValidator) Objects.requireNonNull(java.util.Objects.requireNonNull) SingleHashAssembler(com.opentext.ia.sdk.support.io.SingleHashAssembler) IOException(java.io.IOException) Test(org.junit.Test) URI(java.net.URI) Collectors(java.util.stream.Collectors) Before(org.junit.Before) MemoryBuffer(com.opentext.ia.sdk.support.io.MemoryBuffer) Before(org.junit.Before)

Example 4 with MemoryBuffer

use of com.opentext.ia.sdk.support.io.MemoryBuffer in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class WhenAssemblingPackagingInformation method shouldGenerateValidXml.

@Test
public void shouldGenerateValidXml() throws IOException {
    String application = "a_" + randomString(62);
    String holding = "h_" + randomString(62);
    String producer = "p_" + randomString(62);
    String dssId = "i_" + randomString(30);
    String pdiSchema = "s_" + randomString(254);
    String entity = "e_" + randomString(62);
    int aiuCount = randomInt(20);
    PackagingInformationFactory packagingInformationFactory = new DefaultPackagingInformationFactory(PackagingInformation.builder().dss().id(dssId).application(application).holding(holding).entity(entity).producer(producer).schema(pdiSchema).end().build());
    PackagingInformation packagingInformation = packagingInformationFactory.newInstance(aiuCount, Optional.empty());
    DataBuffer buffer = new MemoryBuffer();
    assembler.start(buffer);
    assembler.add(packagingInformation);
    assembler.end();
    try (InputStream stream = buffer.openForReading()) {
        Element dss = assertValidPackagingInformation(stream);
        assertEquals("ID", dssId, getText(dss, "id"));
        assertEquals("Application", application, getText(dss, "application"));
        assertEquals("Holding", holding, getText(dss, "holding"));
        assertEquals("PDI entity", entity, getText(dss, "entity"));
        assertEquals("Producer", producer, getText(dss, "producer"));
        assertEquals("PDI schema", pdiSchema, getText(dss, "pdi_schema"));
        assertEquals("# AIUs", Integer.toString(aiuCount), getText(dss.getParentNode(), "aiu_count"));
    }
}
Also used : MemoryBuffer(com.opentext.ia.sdk.support.io.MemoryBuffer) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) DataBuffer(com.opentext.ia.sdk.support.io.DataBuffer) Test(org.junit.Test)

Aggregations

MemoryBuffer (com.opentext.ia.sdk.support.io.MemoryBuffer)4 Test (org.junit.Test)3 DataBuffer (com.opentext.ia.sdk.support.io.DataBuffer)2 SingleHashAssembler (com.opentext.ia.sdk.support.io.SingleHashAssembler)1 SipFileValidator (com.opentext.ia.sdk.support.test.validation.SipFileValidator)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 PrintWriter (java.io.PrintWriter)1 URI (java.net.URI)1 java.util (java.util)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Collectors (java.util.stream.Collectors)1 Before (org.junit.Before)1 Element (org.w3c.dom.Element)1