Search in sources :

Example 6 with ByteArrayInputStream

use of org.apache.activemq.util.ByteArrayInputStream in project timbuctoo by HuygensING.

the class IntegrationTest method resourceSyncShowsAllThePublicDataSets.

@Test
public void resourceSyncShowsAllThePublicDataSets() throws Exception {
    final String dataSetName = "clusius_" + UUID.randomUUID().toString().replace("-", "_");
    final String dataSetId = createDataSetId(dataSetName);
    Response uploadResponse = multipartPost("/v5/" + PREFIX + "/" + dataSetName + "/upload/rdf?forceCreation=true", new File(getResource(IntegrationTest.class, "bia_clusius.nqud").toURI()), "application/vnd.timbuctoo-rdf.nquads_unified_diff", ImmutableMap.of("encoding", "UTF-8", "uri", "http://example.com/clusius.nqud"));
    assertThat(uploadResponse.getStatus(), is(201));
    call("/v5/graphql").accept(MediaType.APPLICATION_JSON).post(Entity.entity(jsnO("query", jsn("mutation Publish($dataSetId: String!) {" + "  publish(dataSetId: $dataSetId) {" + "    dataSetId" + "  }" + "}"), "variables", jsnO("dataSetId", jsn(dataSetId))).toString(), MediaType.valueOf("application/json")));
    Response checkPublishedCall = callWithoutAuthentication("/v5/graphql").accept(MediaType.APPLICATION_JSON).post(Entity.entity(jsnO("query", jsn("query MetaData($dataSetId: ID!) {" + "  dataSetMetadata(dataSetId: $dataSetId) {" + "    dataSetId" + "  }" + "}"), "variables", jsnO("dataSetId", jsn(dataSetId))).toString(), MediaType.valueOf("application/json")));
    assertThat(checkPublishedCall.readEntity(ObjectNode.class), is(jsnO("data", jsnO("dataSetMetadata", jsnO("dataSetId", jsn(dataSetId))))));
    Response resourceSyncCall = callWithoutAuthentication("/v5/resourcesync/sourceDescription.xml").get();
    ByteArrayInputStream value = new ByteArrayInputStream(resourceSyncCall.readEntity(String.class).getBytes());
    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(value);
    XPath xpath = XPathFactory.newInstance().newXPath();
    NodeList uriNodes = (NodeList) xpath.compile("/urlset/url/loc").evaluate(document, XPathConstants.NODESET);
    Set<String> dataSets = new HashSet<>();
    for (int i = 0; i < uriNodes.getLength(); i++) {
        dataSets.add(uriNodes.item(i).getTextContent());
    }
    assertThat(dataSets, hasItem(endsWith(dataSetName + "/capabilitylist.xml")));
}
Also used : Response(javax.ws.rs.core.Response) Matchers.hasXPath(org.hamcrest.Matchers.hasXPath) XPath(javax.xml.xpath.XPath) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ByteArrayInputStream(org.apache.activemq.util.ByteArrayInputStream) NodeList(org.w3c.dom.NodeList) Matchers.containsString(org.hamcrest.Matchers.containsString) Document(org.w3c.dom.Document) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ByteArrayInputStream (org.apache.activemq.util.ByteArrayInputStream)6 DataInputStream (java.io.DataInputStream)4 InputStream (java.io.InputStream)4 InflaterInputStream (java.util.zip.InflaterInputStream)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 HashSet (java.util.HashSet)1 Response (javax.ws.rs.core.Response)1 XPath (javax.xml.xpath.XPath)1 TypedProperties (org.apache.activemq.artemis.utils.collections.TypedProperties)1 HttpEntity (org.apache.http.HttpEntity)1 HttpResponse (org.apache.http.HttpResponse)1 ProtocolVersion (org.apache.http.ProtocolVersion)1 StatusLine (org.apache.http.StatusLine)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.hasXPath (org.hamcrest.Matchers.hasXPath)1 Test (org.junit.Test)1 Document (org.w3c.dom.Document)1