Search in sources :

Example 6 with Payload

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);
    }
}
Also used : Payload(org.glassfish.api.admin.Payload) Properties(java.util.Properties) File(java.io.File) URI(java.net.URI) Map(java.util.Map) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test)

Example 7 with Payload

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);
    }
}
Also used : Payload(org.glassfish.api.admin.Payload) Properties(java.util.Properties) File(java.io.File) URI(java.net.URI) Map(java.util.Map) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test)

Aggregations

Payload (org.glassfish.api.admin.Payload)7 File (java.io.File)4 IOException (java.io.IOException)4 Properties (java.util.Properties)4 ActionReport (org.glassfish.api.ActionReport)4 FileNotFoundException (java.io.FileNotFoundException)2 URI (java.net.URI)2 Map (java.util.Map)2 ParameterMap (org.glassfish.api.admin.ParameterMap)2 Test (org.junit.Test)2 ParamsWithPayload (com.sun.enterprise.admin.remote.ParamsWithPayload)1 CliActionReport (com.sun.enterprise.admin.remote.reader.CliActionReport)1 ProprietaryReader (com.sun.enterprise.admin.remote.reader.ProprietaryReader)1 GfSseEventReceiver (com.sun.enterprise.admin.remote.sse.GfSseEventReceiver)1 GfSseEventReceiverProprietaryReader (com.sun.enterprise.admin.remote.sse.GfSseEventReceiverProprietaryReader)1 GfSseInboundEvent (com.sun.enterprise.admin.remote.sse.GfSseInboundEvent)1 ProprietaryWriter (com.sun.enterprise.admin.remote.writer.ProprietaryWriter)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1