@Test public void testPerformDownloadBusinessObjectDataHasAttributes() throws Exception { // Add attributes to the test business object data. UploaderInputManifestDto uploaderInputManifestDto = getTestUploaderInputManifestDto(); HashMap<String, String> attributes = new HashMap<>(); uploaderInputManifestDto.setAttributes(attributes); attributes.put(ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_VALUE_1); attributes.put(ATTRIBUTE_NAME_2_MIXED_CASE, ATTRIBUTE_VALUE_2); // Prepare test data and runs a normal download scenario. runDownload(); }
@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 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 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 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 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()); } }
/** * Calls preRegisterBusinessObjectData() method and makes assertions. * * @param attributes a map of business object data attributes * @param useSsl specifies whether to use SSL or not * * @throws JAXBException if a JAXB error was encountered * @throws IOException if an I/O error was encountered * @throws URISyntaxException if a URI syntax error was encountered * @throws KeyStoreException if a key store exception occurs * @throws NoSuchAlgorithmException if a no such algorithm exception occurs * @throws KeyManagementException if key management exception */ private void testPreRegisterBusinessObjectData(HashMap<String, String> attributes, boolean useSsl) throws IOException, JAXBException, URISyntaxException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { dataBridgeWebClient.regServerAccessParamsDto.setUseSsl(useSsl); UploaderInputManifestDto manifest = getUploaderInputManifestDto(); manifest.setAttributes(attributes); String storageName = "testStorage"; Boolean createNewVersion = false; BusinessObjectData businessObjectData = dataBridgeWebClient.preRegisterBusinessObjectData(manifest, storageName, createNewVersion); assertNotNull("businessObjectData", businessObjectData); }
manifest.setAttributes(attributes); return manifest;
manifest.setAttributes(attributes); for (Attribute attribute : getTestAttributes())
uploaderInputManifestDto.setAttributes(attributes); uploaderInputManifestDto.setStorageName(storageName); File manifestFile = createManifestFile(LOCAL_TEMP_PATH_INPUT.toString(), uploaderInputManifestDto);