Search in sources :

Example 11 with ManifestFile

use of org.finra.herd.model.dto.ManifestFile in project herd by FINRAOS.

the class DataBridgeWebClientTest method getUploaderInputManifestDto.

/**
 * Creates a UploaderInputManifestDto.
 *
 * @return the created UploaderInputManifestDto instance
 */
private UploaderInputManifestDto getUploaderInputManifestDto() {
    UploaderInputManifestDto manifest = new UploaderInputManifestDto();
    manifest.setNamespace("testNamespace");
    manifest.setBusinessObjectDefinitionName("testBusinessObjectDefinitionName");
    manifest.setBusinessObjectFormatUsage("testBusinessObjectFormatUsage");
    manifest.setBusinessObjectFormatFileType("testBusinessObjectFormatFileType");
    manifest.setBusinessObjectFormatVersion("0");
    manifest.setPartitionKey("testPartitionKey");
    manifest.setPartitionValue("testPartitionValue");
    manifest.setSubPartitionValues(Arrays.asList("testSubPartitionValue1", "testSubPartitionValue2"));
    List<ManifestFile> manifestFiles = new ArrayList<>();
    {
        ManifestFile manifestFile = new ManifestFile();
        manifestFile.setFileName("testFileName");
        manifestFile.setFileSizeBytes(1l);
        manifestFile.setRowCount(2l);
        manifestFiles.add(manifestFile);
    }
    manifest.setManifestFiles(manifestFiles);
    HashMap<String, String> attributes = new HashMap<>();
    {
        attributes.put("testName", "testValue");
    }
    manifest.setAttributes(attributes);
    return manifest;
}
Also used : UploaderInputManifestDto(org.finra.herd.model.dto.UploaderInputManifestDto) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ManifestFile(org.finra.herd.model.dto.ManifestFile)

Example 12 with ManifestFile

use of org.finra.herd.model.dto.ManifestFile in project herd by FINRAOS.

the class UploaderManifestReaderTest method testReadJsonManifestMissingRequiredParameters.

@Test
public void testReadJsonManifestMissingRequiredParameters() throws IOException {
    UploaderInputManifestDto uploaderInputManifestDto;
    // Try to create and read the uploader input manifest when business object definition name is not specified.
    uploaderInputManifestDto = getTestUploaderInputManifestDto();
    uploaderInputManifestDto.setBusinessObjectDefinitionName(BLANK_TEXT);
    try {
        uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto));
        fail("Should throw an IllegalArgumentException when business object definition name is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("Manifest business object definition name must be specified.", e.getMessage());
    }
    // Try to create and read the uploader input manifest when business object format usage is not specified.
    uploaderInputManifestDto = getTestUploaderInputManifestDto();
    uploaderInputManifestDto.setBusinessObjectFormatUsage(BLANK_TEXT);
    try {
        uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto));
        fail("Should throw an IllegalArgumentException when business object format usage is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("Manifest business object format usage must be specified.", e.getMessage());
    }
    // Try to create and read the uploader input manifest when business object format file type is not specified.
    uploaderInputManifestDto = getTestUploaderInputManifestDto();
    uploaderInputManifestDto.setBusinessObjectFormatFileType(BLANK_TEXT);
    try {
        uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto));
        fail("Should throw an IllegalArgumentException when business object format file type is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("Manifest business object format file type must be specified.", e.getMessage());
    }
    // Try to create and read the uploader input manifest when business object format version is not specified.
    uploaderInputManifestDto = getTestUploaderInputManifestDto();
    uploaderInputManifestDto.setBusinessObjectFormatVersion(BLANK_TEXT);
    try {
        uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto));
        fail("Should throw an IllegalArgumentException when business object format version is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("Manifest business object format version must be specified.", e.getMessage());
    }
    // Try to create and read the uploader input manifest when partition key is not specified.
    uploaderInputManifestDto = getTestUploaderInputManifestDto();
    uploaderInputManifestDto.setPartitionKey(BLANK_TEXT);
    try {
        uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto));
        fail("Should throw an IllegalArgumentException when partition key is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("Manifest business object format partition key must be specified.", e.getMessage());
    }
    // Try to create and read the uploader input manifest when partition value is not specified.
    uploaderInputManifestDto = getTestUploaderInputManifestDto();
    uploaderInputManifestDto.setPartitionValue(BLANK_TEXT);
    try {
        uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto));
        fail("Should throw an IllegalArgumentException when partition value is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("Manifest business object data partition value must be specified.", e.getMessage());
    }
    // Try to create and read the uploader input manifest when manifest files list is empty.
    uploaderInputManifestDto = getTestUploaderInputManifestDto();
    uploaderInputManifestDto.setManifestFiles(new ArrayList<ManifestFile>());
    try {
        uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto));
        fail("Should throw an IllegalArgumentException when partition value is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("Manifest must contain at least 1 file.", e.getMessage());
    }
    // Try to create and read the uploader input manifest when an attribute name is not specified.
    uploaderInputManifestDto = getTestUploaderInputManifestDto();
    uploaderInputManifestDto.getAttributes().put(BLANK_TEXT, ATTRIBUTE_VALUE_1);
    try {
        uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto));
        fail("Should throw an IllegalArgumentException when an attribute name is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("Manifest attribute name must be specified.", e.getMessage());
    }
}
Also used : UploaderInputManifestDto(org.finra.herd.model.dto.UploaderInputManifestDto) ManifestFile(org.finra.herd.model.dto.ManifestFile) Test(org.junit.Test)

Aggregations

ManifestFile (org.finra.herd.model.dto.ManifestFile)12 ArrayList (java.util.ArrayList)6 UploaderInputManifestDto (org.finra.herd.model.dto.UploaderInputManifestDto)6 File (java.io.File)5 Test (org.junit.Test)5 RegServerAccessParamsDto (org.finra.herd.model.dto.RegServerAccessParamsDto)4 HashMap (java.util.HashMap)2 StorageFile (org.finra.herd.model.api.xml.StorageFile)2 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 StringWriter (java.io.StringWriter)1 URI (java.net.URI)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 HttpPost (org.apache.http.client.methods.HttpPost)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1 StringEntity (org.apache.http.entity.StringEntity)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1