Search in sources :

Example 1 with XmlPath

use of com.jayway.restassured.path.xml.XmlPath in project ddf by codice.

the class TestFederation method getEvents.

private Set<String> getEvents(String subscriptionId) {
    HashSet<String> foundIds = new HashSet<>();
    List<Call> calls = new ArrayList<>(server.getCalls());
    if (CollectionUtils.isNotEmpty(calls)) {
        for (Call call : calls) {
            if (call.getMethod().matchesMethod(Method.POST.name()) && StringUtils.isNotEmpty(call.getPostBody())) {
                LOGGER.debug("Event received '{}'", call.getPostBody());
                XmlPath xmlPath = new XmlPath(call.getPostBody());
                String id;
                try {
                    String foundSubscriptionId = xmlPath.get("GetRecordsResponse.RequestId");
                    if (StringUtils.isNotBlank(foundSubscriptionId) && subscriptionId.equals(foundSubscriptionId)) {
                        id = xmlPath.get("GetRecordsResponse.SearchResults.Record.identifier");
                        if (StringUtils.isNotEmpty(id)) {
                            foundIds.add(StringUtils.trim(id));
                        }
                    } else {
                        LOGGER.info("event for id {} not found.", subscriptionId);
                    }
                } catch (ClassCastException e) {
                    // not necessarily a problem that an particular path (event) wasn't found
                    LOGGER.info("Unable to evaluate path for event {}", subscriptionId);
                }
            }
        }
        LOGGER.debug("Id {}, Event Found Ids: {}", subscriptionId, Arrays.toString(foundIds.toArray()));
    }
    return foundIds;
}
Also used : XmlPath(com.jayway.restassured.path.xml.XmlPath) Call(com.xebialabs.restito.semantics.Call) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) HashSet(java.util.HashSet)

Example 2 with XmlPath

use of com.jayway.restassured.path.xml.XmlPath in project dataverse by IQSS.

the class BatchImportIT method roundTripDdi.

@Test
public void roundTripDdi() throws Exception {
    String directoryPath = "scripts/issues/907/" + importDirectoryAndDataverseAliasMustMatch;
    String absoluteDirectoryPath = new File(directoryPath).getAbsolutePath();
    String parentDataverse = dataverseAlias;
    Response migrateResponse = migrate(absoluteDirectoryPath, parentDataverse, apiToken1);
    // migrateResponse.prettyPrint();
    Thread.sleep(500);
    Response listDatasetsResponse = listDatasets(parentDataverse, apiToken1);
    // listDatasetsResponse.prettyPrint();
    XmlPath xmlPath = new XmlPath(listDatasetsResponse.body().asString());
    String datasetUrlFromSword = xmlPath.getString("feed.entry[0].id");
    if (datasetUrlFromSword != null && !datasetUrlFromSword.isEmpty()) {
        String persistentIdentifier = datasetUrlFromSword.substring(68);
        Response indexDatasetResponse = indexDataset(persistentIdentifier);
        // indexDatasetResponse.prettyPrint();
        datasetId = JsonPath.from(indexDatasetResponse.body().asString()).getInt("data.id");
        Response datasetAsJsonResponse = getDatasetAsJson(datasetId, apiToken1);
        // datasetAsJsonResponse.prettyPrint();
        String title = JsonPath.from(datasetAsJsonResponse.body().asString()).getString("data.latestVersion.metadataBlocks.citation.fields[0].value");
        String persistentUrl = JsonPath.from(datasetAsJsonResponse.body().asString()).getString("data.persistentUrl");
        logger.info(title + " - " + persistentUrl);
        boolean ddiFromDto = false;
        Response datasetAsDdi = getDatasetAsDdi(persistentIdentifier, ddiFromDto, apiToken1);
        String minimalDdiMethod = datasetAsDdi.prettyPrint();
        ddiFromDto = true;
        Response datasetAsDdiFromDto = getDatasetAsDdi(persistentIdentifier, ddiFromDto, apiToken1);
        String fromDto = datasetAsDdiFromDto.prettyPrint();
        /**
         * Parity with the minimal DDI export is a step along the way. It
         * demonstrates that we are producing valid DDI according to
         * http://guides.dataverse.org/en/latest/developers/tools.html#msv
         * but the next step will be producing a full DDI similar to what is
         * being imported in this round trip test.
         */
        boolean parityWithMinimalDdiExport = false;
        if (parityWithMinimalDdiExport) {
            assertEquals(minimalDdiMethod, fromDto);
        }
        // File originalFile = new File(absoluteDirectoryPath).listFiles()[0];
        // String originalPretty = prettyFormat(new String(Files.readAllBytes(Paths.get(originalFile.getAbsolutePath()))));
        // String exportedPretty = prettyFormat(datasetAsDdi.body().asString());
        // logger.fine("original: " + originalPretty);
        // logger.fine("exported: " + exportedPretty);
        boolean doneWithDdiExportIssue2579 = false;
        if (doneWithDdiExportIssue2579) {
        /**
         * @todo Implement DDI export
         * https://github.com/IQSS/dataverse/issues/2579
         */
        // assertEquals(exportedPretty, originalPretty);
        }
    } else {
        boolean ddiFromDto = false;
        Response datasetAsDdi = getDatasetAsDdi("junkDoi", ddiFromDto, apiToken1);
        datasetAsDdi.prettyPrint();
        assertEquals(404, datasetAsDdi.getStatusCode());
    }
}
Also used : Response(com.jayway.restassured.response.Response) XmlPath(com.jayway.restassured.path.xml.XmlPath) File(java.io.File) Test(org.junit.Test)

Example 3 with XmlPath

use of com.jayway.restassured.path.xml.XmlPath in project ddf by codice.

the class TestConfiguration method assertMetacardsIngested.

private void assertMetacardsIngested(int expectedumberOfMetacards) throws Exception {
    String queryUrl = OPENSEARCH_PATH.getUrl() + "?q=*&format=xml&src=local";
    Response response = when().get(queryUrl);
    String bodyXml = response.body().asString();
    NodeChildren metacards = new XmlPath(bodyXml).get("metacards.metacard");
    assertThat(metacards.size(), is(expectedumberOfMetacards));
}
Also used : Response(com.jayway.restassured.response.Response) XmlPath(com.jayway.restassured.path.xml.XmlPath) Matchers.containsString(org.hamcrest.Matchers.containsString) NodeChildren(com.jayway.restassured.path.xml.element.NodeChildren)

Example 4 with XmlPath

use of com.jayway.restassured.path.xml.XmlPath in project ddf by codice.

the class TestCatalog method testIngestXmlNoExtension.

@Test
public void testIngestXmlNoExtension() throws Exception {
    final String TMP_PREFIX = "tcdm_";
    Path tmpDir = Files.createTempDirectory(TMP_PREFIX);
    tmpDir.toFile().deleteOnExit();
    Path tmpFile = Files.createTempFile(tmpDir, TMP_PREFIX, "_tmp");
    tmpFile.toFile().deleteOnExit();
    Files.copy(getFileContentAsStream("metacard5.xml"), tmpFile, StandardCopyOption.REPLACE_EXISTING);
    Map<String, Object> cdmProperties = new HashMap<>();
    cdmProperties.putAll(getServiceManager().getMetatypeDefaults("content-core-directorymonitor", "org.codice.ddf.catalog.content.monitor.ContentDirectoryMonitor"));
    cdmProperties.put("monitoredDirectoryPath", tmpDir.toString() + "/");
    cdmProperties.put("processingMechanism", ContentDirectoryMonitor.IN_PLACE);
    Configuration managedService = getServiceManager().createManagedService("org.codice.ddf.catalog.content.monitor.ContentDirectoryMonitor", cdmProperties);
    ValidatableResponse response = assertIngestedDirectoryMonitor("SysAdmin", 1);
    response.extract().xmlPath().getString("metacards.metacard.type").equals("ddf.metacard");
    getServiceManager().stopManagedService(managedService.getPid());
    given().header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML).body(getFileContent(CSW_REQUEST_RESOURCE_PATH + "/CswCqlDeleteRequest", ImmutableMap.of("title", "Metacard-5"))).post(CSW_PATH.getUrl()).then().body(hasXPath("//TransactionResponse/TransactionSummary/totalDeleted", is("1")), hasXPath("//TransactionResponse/TransactionSummary/totalInserted", is("0")), hasXPath("//TransactionResponse/TransactionSummary/totalUpdated", is("0")));
}
Also used : Path(java.nio.file.Path) XmlPath(com.jayway.restassured.path.xml.XmlPath) HasXPath.hasXPath(org.hamcrest.xml.HasXPath.hasXPath) ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) Configuration(org.osgi.service.cm.Configuration) HashMap(java.util.HashMap) JSONObject(org.json.simple.JSONObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) SkipUnstableTest(org.codice.ddf.itests.common.annotations.SkipUnstableTest) Test(org.junit.Test) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest)

Example 5 with XmlPath

use of com.jayway.restassured.path.xml.XmlPath in project dataverse by IQSS.

the class UtilIT method getFileIdFromSwordStatementBody.

private static Integer getFileIdFromSwordStatementBody(String swordStatement) {
    XmlPath xmlPath = new XmlPath(swordStatement);
    try {
        String fileIdAsString = xmlPath.get("feed.entry[0].id").toString().split("/")[10];
        Integer fileIdAsInt = Integer.parseInt(fileIdAsString);
        return fileIdAsInt;
    } catch (IndexOutOfBoundsException ex) {
        return null;
    }
}
Also used : XmlPath(com.jayway.restassured.path.xml.XmlPath)

Aggregations

XmlPath (com.jayway.restassured.path.xml.XmlPath)6 Response (com.jayway.restassured.response.Response)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Test (org.junit.Test)2 NodeChildren (com.jayway.restassured.path.xml.element.NodeChildren)1 ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)1 Call (com.xebialabs.restito.semantics.Call)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 InputStreamReader (java.io.InputStreamReader)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)1 SkipUnstableTest (org.codice.ddf.itests.common.annotations.SkipUnstableTest)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 HasXPath.hasXPath (org.hamcrest.xml.HasXPath.hasXPath)1