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));
}
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();
}
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();
}
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"));
}
}
Aggregations