PypiMetadataParser { public PypiPackageInfo parseMetadataFile(InputStream is) throws IllegalAccessException, IOException, ConstraintViolationException { Map<String, String> keyValueMap = generateKeyValueMap(is); PypiPackageInfo packageInfo = populateAnnotatedFields(new PypiPackageInfo(), keyValueMap); pypiPackageInfoValidator.validate(packageInfo); return packageInfo; }  PypiPackageInfo parseMetadataFile(InputStream is); PypiPackageInfo populateAnnotatedFields(PypiPackageInfo object,
                                                   Map<String, String> keyValueMap);  }
@Test public void testParseFileToPypiMetadataDto() throws IllegalAccessException, IOException { PypiPackageInfo testDao = pypiMetadataParser.parseMetadataFile( new FileInputStream("src/test/resources/org.carlspring.strongbox.util/PKG-INFO")); assertThat("hello-strongbox-pip").isEqualTo(testDao.getName()); assertThat("1.0").isEqualTo(testDao.getMetadataVersion().getVersionString()); assertThat("1.0.0").isEqualTo(testDao.getVersion()); assertThat("Hello, Strongbox [pip]!").isEqualTo(testDao.getSummary()); assertThat("https: assertThat("Martin Todorov").isEqualTo(testDao.getAuthor()); assertThat("foo@bar.com").isEqualTo(testDao.getAuthorEmail()); assertThat("Apache 2.0").isEqualTo(testDao.getLicense()); assertThat("UNKNOWN").isEqualTo(testDao.getDescriptionContentType()); assertThat("UNKNOWN").isEqualTo(testDao.getDescription()); assertThat("UNKNOWN").isEqualTo(testDao.getPlatform()); }
@Test public void testParseFileWithEmptyValuesToPypiMetadataDto() { assertThatExceptionOfType(ConstraintViolationException.class) .isThrownBy(() -> pypiMetadataParser.parseMetadataFile( new FileInputStream("src/test/resources/org.carlspring.strongbox.util/PKG-INFO-empty-values"))); }
@Test public void testParseFileWithInvalidMetadataVersion() { assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> pypiMetadataParser.parseMetadataFile(new FileInputStream( "src/test/resources/org.carlspring.strongbox.util/PKG-INFO-invalid-metadata-version"))); }
@Test public void testParseFileWithInvalidName() { assertThatExceptionOfType(ConstraintViolationException.class) .isThrownBy(() -> pypiMetadataParser.parseMetadataFile( new FileInputStream("src/test/resources/org.carlspring.strongbox.util/PKG-INFO-invalid-name"))); }