use of org.glassfish.api.admin.Payload in project Payara by payara.
the class PayloadImplTest method testAddFiles.
@Test
public void testAddFiles() {
System.out.println("testAddFiles");
File fileToBeAddedToPayload = null;
File zipFile = null;
try {
Payload.Outbound outboundPayload = PayloadImpl.Outbound.newInstance();
fileToBeAddedToPayload = populateFile(File.createTempFile("payload", ".txt"), ADDED_FILE_Z.content);
log(" Populated " + fileToBeAddedToPayload.getAbsolutePath());
/*
* Use application/octet-stream here. text/plain might seem more
* logical, but the payload implementation correctly treats a
* payload containing a single text entry differently from a
* multi-part payload or a payload containing a single non-text part.
* (This is because admin operations return their results in a text
* entry in the payload of the HTTP request. If no other data is
* being streamed then the requirement is to return regular text in
* the payload which makes non-asadmin clients - such as IDEs and
* web browsers - happier.)
*/
outboundPayload.attachFile("application/octet-stream", new URI(ADDED_FILE_Z.path), "addText", fileToBeAddedToPayload);
log(" Attached " + ADDED_FILE_Z.path);
zipFile = writePayloadToFile(outboundPayload, File.createTempFile("payloadZip", ".zip"));
log(" Wrote payload to " + zipFile.getAbsolutePath());
// XXX consume the map; check for the new file and contents
boolean isFileProcessed = false;
for (Map.Entry<File, Properties> entry : preparePFM(zipFile).entrySet()) {
final File processedFile = entry.getKey();
if (processedFile.toURI().getPath().endsWith(ADDED_FILE_Z.path)) {
isFileProcessed = true;
/*
* Make sure the file exists and contains what we expect.
*/
assertTrue("Expected output file " + ADDED_FILE_Z.path + " does not exist", processedFile.exists());
assertEquals("Expected new file contents for " + ADDED_FILE_Z.path + "not correct", ADDED_FILE_Z.content, readFromFile(processedFile));
}
}
assertTrue("Added file " + ADDED_FILE_Z.path + " did not appear in the processed output", isFileProcessed);
/*
* Make sure the original file still exists and contains what it should.
*/
final File originalFile = new File(workingDir.toURI().resolve(ORIGINAL_FILE_X.path));
assertTrue("Original file " + ORIGINAL_FILE_X.path + " no longer exists but it should", originalFile.exists());
assertEquals("Original file " + ORIGINAL_FILE_X.path + " exists as expected but no longer contains what it should", ORIGINAL_FILE_X.content, readFromFile(originalFile));
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
deleteAndLogFailure(fileToBeAddedToPayload);
deleteAndLogFailure(zipFile);
}
}
use of org.glassfish.api.admin.Payload in project Payara by payara.
the class PayloadImplTest method testSingleFileReplaceRequest.
@Test
public void testSingleFileReplaceRequest() {
System.out.println("testSingleFileReplaceRequest");
File newVersion = null;
File zipFile = null;
try {
Payload.Outbound outboundPayload = PayloadImpl.Outbound.newInstance();
newVersion = populateFile(File.createTempFile("payload", ".txt"), REPLACED_FILE_X.content);
outboundPayload.requestFileReplacement("application/octet-stream", new URI(REPLACED_FILE_X.path), "replacement", null, newVersion, false);
zipFile = writePayloadToFile(outboundPayload, File.createTempFile("payloadZip", ".zip"));
boolean isFileProcessed = false;
for (Map.Entry<File, Properties> entry : preparePFM(zipFile).entrySet()) {
final File processedFile = entry.getKey();
if (processedFile.toURI().getPath().endsWith(REPLACED_FILE_X.path)) {
isFileProcessed = true;
/*
* Make sure the file exists and contains the new content.
*/
assertTrue("Expected original output file " + REPLACED_FILE_X.path + " does not exist", processedFile.exists());
assertEquals("Expected new file contents for " + REPLACED_FILE_X.path + " not correct", REPLACED_FILE_X.content, readFromFile(processedFile));
}
}
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
deleteAndLogFailure(newVersion);
deleteAndLogFailure(zipFile);
}
}
Aggregations