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