Java: Upload A File For Future Use Using UploadFile()

Download
Download our Java samples from this page.
Find this sample in directory /test/com/postalmethods/client
package com.postalmethods.client;
 
import static org.junit.Assert.assertEquals;
 
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
 
import com.postalmethods.client.api.DeleteUploadedFileResponse;
import com.postalmethods.client.api.UploadFileResponse;
 
/**
 * Integration test that calls the UploadFile web method.
 * <p>
 * For details about PostalMethods.UploadFile see
 * <a href="http://www.postalmethods.com/method/2009-02-26/UploadFile">the PostalMethods.UploadFile reference</a>
 */
public class UploadFileTest {
 
    private PostalMethodsClient client;
 
    @Before
    public void setUp() {
        client = new PostalMethodsClientFactory().build();
    }
 
    @After
    public void tearDown() {
 
        // Delete the file we uploaded during our test.
        System.out.println("Making call to DeleteUploadedFile...");
 
        DeleteUploadedFileResponse response = client.deleteUploadedFile(TestConstants.SAMPLE_UPLOAD_FILE);
        System.out.println("Service call completed:\n" + response.getResult().toString());
 
        int code = response.getResult().getCode();
        assertEquals(-3000, code); // success
    }
 
    @Test
    public void testUploadFile() {
        System.out.println("Making call to UploadFile...");
 
        String description = "This is only a test.";
        UploadFileResponse response = client.uploadFile(TestConstants.SAMPLE_UPLOAD_FILE, TestConstants.SAMPLE_POSTCARD_IMAGE_FRONT_LOCAL, "User", description, true);
        System.out.println("Service call completed:\n" + response.getResult().toString());
 
        int code = response.getResult().getCode();
        assertEquals(-3000, code); // success
    }
}