Search in sources :

Example 1 with ByteArrayInputOutputStream

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

the class WhenAssemblingSips method assertPackagingInformation.

private void assertPackagingInformation(ZipInputStream zip, Collection<Object> objects, EncodedHash pdiHash) throws IOException {
    ZipEntry entry = zip.getNextEntry();
    assertNotNull(entry, "Missing Packaging Information");
    assertEquals("eas_sip.xml", entry.getName(), "Zip entry");
    try (ByteArrayInputOutputStream packagingInformation = new ByteArrayInputOutputStream()) {
        IOUtils.copy(zip, packagingInformation);
        Element sipElement = assertValidXml(packagingInformation.getInputStream(), "PackagingInformation", "sip.xsd").getDocumentElement();
        assertTrue(XmlUtil.namedElementsIn(sipElement, "pdi_hash").filter(e -> equals(pdiHash, e)).findAny().isPresent(), "Missing pdi_hash: " + pdiHash);
        String aiuCount = XmlUtil.getFirstChildElement(sipElement, "aiu_count").getTextContent();
        assertEquals(objects.size(), Integer.parseInt(aiuCount), "# AIUs");
    }
    zip.closeEntry();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) ByteArrayInputOutputStream(com.opentext.ia.sdk.support.io.ByteArrayInputOutputStream) ZipInputStream(java.util.zip.ZipInputStream) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) EncodedHash(com.opentext.ia.sdk.support.io.EncodedHash) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) Encoding(com.opentext.ia.sdk.support.io.Encoding) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ZipEntry(java.util.zip.ZipEntry) Iterator(java.util.Iterator) DataBuffer(com.opentext.ia.sdk.support.io.DataBuffer) Collection(java.util.Collection) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) XmlUtil(com.opentext.ia.sdk.support.xml.XmlUtil) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) IOUtils(org.apache.commons.io.IOUtils) HashFunction(com.opentext.ia.sdk.support.io.HashFunction) List(java.util.List) Element(org.w3c.dom.Element) NoHashAssembler(com.opentext.ia.sdk.support.io.NoHashAssembler) MemoryBuffer(com.opentext.ia.sdk.support.io.MemoryBuffer) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Collections(java.util.Collections) HashAssembler(com.opentext.ia.sdk.support.io.HashAssembler) Mockito.mock(org.mockito.Mockito.mock) ZipEntry(java.util.zip.ZipEntry) Element(org.w3c.dom.Element) ByteArrayInputOutputStream(com.opentext.ia.sdk.support.io.ByteArrayInputOutputStream)

Example 2 with ByteArrayInputOutputStream

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

the class SipFileValidator method assertPackagingInformation.

public SipFileValidator assertPackagingInformation(int aiuCount) throws IOException {
    ZipEntry entry = zipFile.getEntry("eas_sip.xml");
    assertNotNull(entry, "Missing Packaging Information");
    try (ByteArrayInputOutputStream packagingInformation = new ByteArrayInputOutputStream();
        InputStream in = zipFile.getInputStream(entry)) {
        IOUtils.copy(in, packagingInformation);
        Element sipElement = assertValidXml(packagingInformation.getInputStream(), "PackagingInformation", "sip.xsd").getDocumentElement();
        String actualAiuCount = XmlUtil.getFirstChildElement(sipElement, "aiu_count").getTextContent();
        assertEquals(aiuCount, Integer.parseInt(actualAiuCount), "# AIUs");
    }
    return this;
}
Also used : RepeatableInputStream(com.opentext.ia.sdk.support.io.RepeatableInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) Element(org.w3c.dom.Element) ByteArrayInputOutputStream(com.opentext.ia.sdk.support.io.ByteArrayInputOutputStream)

Example 3 with ByteArrayInputOutputStream

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

the class WhenWorkingWithHttp method init.

@BeforeEach
public void init() throws IOException {
    server = HttpServer.create(new InetSocketAddress(0), 0);
    int port = server.getAddress().getPort();
    uri = "http://localhost:" + port + PATH;
    server.createContext(PATH, httpExchange -> {
        ByteArrayInputOutputStream content = new ByteArrayInputOutputStream();
        long size = IOUtils.copy(httpExchange.getRequestBody(), content);
        httpExchange.sendResponseHeaders(200, size);
        try (InputStream input = content.getInputStream()) {
            IOUtils.copy(input, httpExchange.getResponseBody());
        }
        httpExchange.close();
    });
    server.setExecutor(null);
    serverThread = new Thread(() -> server.start());
    serverThread.start();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayInputOutputStream(com.opentext.ia.sdk.support.io.ByteArrayInputOutputStream) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ByteArrayInputOutputStream (com.opentext.ia.sdk.support.io.ByteArrayInputOutputStream)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 ZipEntry (java.util.zip.ZipEntry)2 Element (org.w3c.dom.Element)2 DataBuffer (com.opentext.ia.sdk.support.io.DataBuffer)1 EncodedHash (com.opentext.ia.sdk.support.io.EncodedHash)1 Encoding (com.opentext.ia.sdk.support.io.Encoding)1 HashAssembler (com.opentext.ia.sdk.support.io.HashAssembler)1 HashFunction (com.opentext.ia.sdk.support.io.HashFunction)1 MemoryBuffer (com.opentext.ia.sdk.support.io.MemoryBuffer)1 NoHashAssembler (com.opentext.ia.sdk.support.io.NoHashAssembler)1 RepeatableInputStream (com.opentext.ia.sdk.support.io.RepeatableInputStream)1 XmlUtil (com.opentext.ia.sdk.support.xml.XmlUtil)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1