@Test public void testReadJsonManifestDuplicateAttributeNames() throws IOException { // Try to create and read the uploader input manifest that contains duplicate attribute names. UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto(); HashMap<String, String> attributes = new HashMap<>(); uploaderInputManifestDto.setAttributes(attributes); attributes.put(ATTRIBUTE_NAME_1_MIXED_CASE.toLowerCase(), ATTRIBUTE_VALUE_1); attributes.put(ATTRIBUTE_NAME_1_MIXED_CASE.toUpperCase(), ATTRIBUTE_VALUE_2); try { uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto)); fail("Should throw an IllegalArgumentException when manifest contains duplicate attribute names"); } catch (IllegalArgumentException e) { assertEquals(String.format("Duplicate manifest attribute name found: %s", ATTRIBUTE_NAME_1_MIXED_CASE).toUpperCase(), e.getMessage().toUpperCase()); } }
@Test public void testReadJsonManifestEmptyAttributesMap() throws IOException { // Get an instance of uploader input manifest object. UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto(); // Create and read the uploaderInputManifestDto file with an empty list of attributes. uploaderInputManifestDto.setAttributes(new HashMap<String, String>()); UploaderInputManifestDto resultManifest = uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto)); // Validate the results. assertUploaderManifest(uploaderInputManifestDto, resultManifest); }
@Test public void testReadJsonManifestEmptyParentsList() throws IOException { // Create and read the uploaderInputManifestDto file with an empty list of parents. UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto(); uploaderInputManifestDto.setBusinessObjectDataParents(new ArrayList<BusinessObjectDataKey>()); UploaderInputManifestDto resultManifest = uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto)); // Validate the results. assertUploaderManifest(uploaderInputManifestDto, resultManifest); }
@Test public void testReadJsonManifestMaxAttributeNameLength() throws IOException { UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto(); HashMap<String, String> attributes = new HashMap<>(); uploaderInputManifestDto.setAttributes(attributes); String attributeKey = StringUtils.leftPad("key", UploaderManifestReader.MAX_ATTRIBUTE_NAME_LENGTH, '*'); // Returns "*...*key" assertTrue(attributeKey.length() == UploaderManifestReader.MAX_ATTRIBUTE_NAME_LENGTH); attributes.put(attributeKey, ATTRIBUTE_VALUE_1); UploaderInputManifestDto resultManifest = uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto)); // Validate the results. assertUploaderManifest(uploaderInputManifestDto, resultManifest); }
@Test public void testReadJsonManifestMaxAttributeValueLength() throws IOException { UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto(); HashMap<String, String> attributes = new HashMap<>(); uploaderInputManifestDto.setAttributes(attributes); String attributeKey = ATTRIBUTE_NAME_1_MIXED_CASE; String attributeValue = StringUtils.leftPad("value", UploaderManifestReader.MAX_ATTRIBUTE_VALUE_LENGTH, '*'); // Returns "*...*value" assertTrue(attributeValue.length() == UploaderManifestReader.MAX_ATTRIBUTE_VALUE_LENGTH); attributes.put(attributeKey, attributeValue); UploaderInputManifestDto resultManifest = uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto)); // Validate the results. assertUploaderManifest(uploaderInputManifestDto, resultManifest); }
@Test public void testReadJsonManifest() throws IOException { // Create and read an uploaderInputManifestDto file. UploaderInputManifestDto resultManifest = uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), getTestUploaderInputManifestDto())); // Validate the results. assertUploaderManifest(getTestUploaderInputManifestDto(), resultManifest); }
@Test public void testReadJsonManifestNullParentsList() throws IOException { // Create and read the uploaderInputManifestDto file with the list of parents set to null. UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto(); uploaderInputManifestDto.setBusinessObjectDataParents(null); UploaderInputManifestDto resultManifest = uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto)); // Validate the results. assertUploaderManifest(uploaderInputManifestDto, resultManifest); }
@Test public void testReadJsonManifestNullAttributesMap() throws IOException { // Get an instance of uploader input manifest object. UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto(); // Create and read the uploaderInputManifestDto file with the list of attributes set to null. uploaderInputManifestDto.setAttributes(null); UploaderInputManifestDto resultManifest = uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto)); // Validate the results. assertUploaderManifest(uploaderInputManifestDto, resultManifest); }
@Test public void testReadJsonManifestNoAttributeValue() throws IOException { UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto(); HashMap<String, String> attributes = new HashMap<>(); uploaderInputManifestDto.setAttributes(attributes); attributes.put(ATTRIBUTE_NAME_1_MIXED_CASE, null); attributes.put(ATTRIBUTE_NAME_2_MIXED_CASE, ""); attributes.put(ATTRIBUTE_NAME_3_MIXED_CASE, BLANK_TEXT); UploaderInputManifestDto resultManifest = uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto)); // Validate the results. assertUploaderManifest(uploaderInputManifestDto, resultManifest); assertEquals(attributes.size(), resultManifest.getAttributes().size()); assertEquals(null, resultManifest.getAttributes().get(ATTRIBUTE_NAME_1_MIXED_CASE)); assertEquals("", resultManifest.getAttributes().get(ATTRIBUTE_NAME_2_MIXED_CASE)); assertEquals(BLANK_TEXT, resultManifest.getAttributes().get(ATTRIBUTE_NAME_3_MIXED_CASE)); }
@Test public void testReadJsonManifestAttributeNameTooLong() throws IOException { // Try to create and read the uploader input manifest that contains an attribute name which is too long. UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto(); HashMap<String, String> attributes = new HashMap<>(); uploaderInputManifestDto.setAttributes(attributes); String attributeKey = StringUtils.leftPad("value", UploaderManifestReader.MAX_ATTRIBUTE_NAME_LENGTH + 1, '*'); // Returns "*...*key" assertTrue(attributeKey.length() == UploaderManifestReader.MAX_ATTRIBUTE_NAME_LENGTH + 1); attributes.put(attributeKey, ATTRIBUTE_VALUE_1); try { uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto)); fail("Should throw an IllegalArgumentException when an attribute name is too long."); } catch (IllegalArgumentException e) { assertEquals(String.format("Manifest attribute name is longer than %d characters.", UploaderManifestReader.MAX_ATTRIBUTE_NAME_LENGTH), e.getMessage()); } }
@Test public void testReadJsonManifestAttributeValueTooLong() throws IOException { // Try to create and read the uploader input manifest that contains an attribute value which is too long. UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto(); HashMap<String, String> attributes = new HashMap<>(); uploaderInputManifestDto.setAttributes(attributes); String attributeValue = StringUtils.leftPad("value", UploaderManifestReader.MAX_ATTRIBUTE_VALUE_LENGTH + 1, '*'); // Returns "*...*value" assertTrue(attributeValue.length() == UploaderManifestReader.MAX_ATTRIBUTE_VALUE_LENGTH + 1); attributes.put(ATTRIBUTE_NAME_1_MIXED_CASE, attributeValue); try { uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto)); fail("Should throw an IllegalArgumentException when an attribute value is too long."); } catch (IllegalArgumentException e) { assertEquals(String.format("Manifest attribute value is longer than %s characters.", UploaderManifestReader.MAX_ATTRIBUTE_VALUE_LENGTH), e.getMessage()); } }
@Test public void testReadJsonManifestNoRowCount() throws IOException { // Get an instance of uploader input manifest object. UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto(); // Make all the row counts null. for (ManifestFile manifestFile : uploaderInputManifestDto.getManifestFiles()) { manifestFile.setRowCount(null); } // Create and read a uploaderInputManifestDto file. UploaderInputManifestDto resultManifest = uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto)); // Validate the results. assertUploaderManifest(uploaderInputManifestDto, resultManifest); }
try uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto)); fail("Should throw an IllegalArgumentException when business object definition name is not specified."); try uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto)); fail("Should throw an IllegalArgumentException when business object format usage is not specified."); uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto)); fail("Should throw an IllegalArgumentException when business object format file type is not specified."); uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto)); fail("Should throw an IllegalArgumentException when business object format version is not specified."); uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto)); fail("Should throw an IllegalArgumentException when partition key is not specified."); uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto)); fail("Should throw an IllegalArgumentException when partition value is not specified."); uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto)); fail("Should throw an IllegalArgumentException when partition value is not specified."); uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto)); fail("Should throw an IllegalArgumentException when an attribute name is not specified.");
UploaderInputManifestDto manifest = manifestReader.readJsonManifest(manifestPath);
@Test public void testReadJsonManifestDuplicateParents() throws IOException { // Add a duplicate business object data parents to the manifest. UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto(); BusinessObjectDataKey parent = new BusinessObjectDataKey(); uploaderInputManifestDto.getBusinessObjectDataParents().add(parent); parent.setNamespace(NAMESPACE_CD.toLowerCase()); parent.setBusinessObjectDefinitionName(TEST_BUSINESS_OBJECT_DEFINITION.toLowerCase()); parent.setBusinessObjectFormatUsage(TEST_BUSINESS_OBJECT_FORMAT_USAGE.toLowerCase()); parent.setBusinessObjectFormatFileType(TEST_BUSINESS_OBJECT_FORMAT_FILE_TYPE.toLowerCase()); parent.setBusinessObjectFormatVersion(TEST_BUSINESS_OBJECT_FORMAT_VERSION); parent.setPartitionValue(TEST_PARENT_PARTITION_VALUE); parent.setBusinessObjectDataVersion(TEST_DATA_VERSION_V0); try { // Try to read and validate a JSON manifest file that has duplicate business object data parents. uploaderManifestReader.readJsonManifest(createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto)); fail("Suppose to throw an IllegalArgumentException when the uploader manifest file contains duplicate business object data parents."); } catch (IllegalArgumentException e) { assertEquals(String.format("Duplicate manifest business object data parent found: {namespace: \"%s\", " + "businessObjectDefinitionName: \"%s\", businessObjectFormatUsage: \"%s\", businessObjectFormatFileType: \"%s\", " + "businessObjectFormatVersion: %d, businessObjectDataPartitionValue: \"%s\", businessObjectDataSubPartitionValues: \"\", " + "businessObjectDataVersion: %d}", parent.getNamespace(), parent.getBusinessObjectDefinitionName(), parent.getBusinessObjectFormatUsage(), parent.getBusinessObjectFormatFileType(), parent.getBusinessObjectFormatVersion(), parent.getPartitionValue(), parent.getBusinessObjectDataVersion()), e.getMessage()); } }