/** * Test that information can be put in and retrieved from a {@code PackageGenerationParameters} * object */ @Test public void testAddAndGetParams() { PackageGenerationParameters parameters = new PackageGenerationParameters(); Map<String, List<String>> addedParameters = new HashMap<>(); List<String> paramValues = new ArrayList<>(); paramValues.add("Willard Poopa-doodle"); parameters.addParam(BagItParameterNames.CONTACT_NAME, paramValues); addedParameters.put(BagItParameterNames.CONTACT_NAME, paramValues); paramValues = new ArrayList<>(); paramValues.add("*****@*****.**"); parameters.addParam(BagItParameterNames.CONTACT_EMAIL, paramValues); addedParameters.put(BagItParameterNames.CONTACT_EMAIL, paramValues); paramValues = new ArrayList<>(); paramValues.add("org.dataconservancy.packaging.format:borem"); parameters.addParam(BagItParameterNames.PACKAGE_FORMAT_ID, paramValues); addedParameters.put(BagItParameterNames.PACKAGE_FORMAT_ID, paramValues); // assert that there are 3 entry in the parameters map. assertEquals(3, parameters.getKeys().size()); assertEquals(addedParameters.keySet(), parameters.getKeys()); for (String key : addedParameters.keySet()) { assertEquals(addedParameters.get(key), parameters.getParam(key)); } }
@Test public void testRemoveParam() { PackageGenerationParameters parametersOne = new PackageGenerationParameters(); List<String> paramValues = new ArrayList<>(); paramValues.add("Willard Poopa-doodle"); parametersOne.addParam(BagItParameterNames.CONTACT_NAME, paramValues); paramValues = new ArrayList<>(); paramValues.add("*****@*****.**"); parametersOne.addParam(BagItParameterNames.CONTACT_EMAIL, paramValues); paramValues = new ArrayList<>(); paramValues.add("org.dataconservancy.packaging.format:borem"); parametersOne.addParam(BagItParameterNames.PACKAGE_FORMAT_ID, paramValues); // make sure the above params were added assertTrue(parametersOne.getKeys().contains(BagItParameterNames.CONTACT_NAME)); assertTrue(parametersOne.getKeys().contains(BagItParameterNames.CONTACT_EMAIL)); assertTrue(parametersOne.getKeys().contains(BagItParameterNames.PACKAGE_FORMAT_ID)); // remove one param parametersOne.removeParam(BagItParameterNames.PACKAGE_FORMAT_ID); // make sure that the remove params is no longer there. assertTrue(parametersOne.getKeys().contains(BagItParameterNames.CONTACT_NAME)); assertTrue(parametersOne.getKeys().contains(BagItParameterNames.CONTACT_EMAIL)); assertFalse(parametersOne.getKeys().contains(BagItParameterNames.PACKAGE_FORMAT_ID)); // make sure that attempt to remove param that doesn't exist does not cause exception // remove one param parametersOne.removeParam(BagItParameterNames.PACKAGE_FORMAT_ID); // make sure that the remove params is no longer there. assertTrue(parametersOne.getKeys().contains(BagItParameterNames.CONTACT_NAME)); assertTrue(parametersOne.getKeys().contains(BagItParameterNames.CONTACT_EMAIL)); }