rombert commented on code in PR #29:
URL:
https://github.com/apache/sling-org-apache-sling-committer-cli/pull/29#discussion_r3529716903
##########
src/test/java/org/apache/sling/cli/impl/nexus/RepositoryServiceTest.java:
##########
@@ -168,6 +170,138 @@ public void testReleaseLookup() throws IOException {
assertEquals("Sling Adapter Annotations 1.0.0", release.getFullName());
}
+ @Test
+ public void testGetReleasesFromContent() throws IOException {
+ // browses the repository content tree directly (no Lucene index),
recursing into directories
+ // and parsing every .pom leaf it finds
+ StagingRepository repository = new StagingRepository();
+ repository.setRepositoryId("orgapachesling-3");
+ Set<Release> releases =
repositoryService.getReleasesFromContent(repository);
+ assertEquals(1, releases.size());
+ assertEquals(
+ "Sling Adapter Annotations 1.0.0",
releases.iterator().next().getFullName());
+ }
+
+ @Test
+ public void testFindAnyReturnsOpenRepository() throws IOException {
+ // findAny does not require the repository to be closed, so the open
orgapachesling-2 resolves
+ StagingRepository repository = repositoryService.findAny(2);
+ assertNotNull(repository);
+ assertEquals("orgapachesling-2", repository.getRepositoryId());
+ }
+
+ @Test
+ public void testFindAnyUnknownThrows() {
+ try {
+ repositoryService.findAny(999);
+ fail("Expected an IllegalArgumentException for an unknown
repository id.");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("999"));
+ } catch (IOException e) {
+ fail("Unexpected IOException.");
+ }
+ }
+
+ @Test
+ public void testPromote() throws IOException {
+ // exercises the bulk-action POST path; MockNexus answers staging bulk
actions with HTTP 201
+ repositoryService.promote(getStagingRepository());
Review Comment:
What is the benefit of this test and testCloseWithDescription/testDrop? They
don't verify anything
##########
src/test/java/org/apache/sling/cli/impl/nexus/RepositoryServiceTest.java:
##########
@@ -168,6 +170,138 @@ public void testReleaseLookup() throws IOException {
assertEquals("Sling Adapter Annotations 1.0.0", release.getFullName());
}
+ @Test
+ public void testGetReleasesFromContent() throws IOException {
+ // browses the repository content tree directly (no Lucene index),
recursing into directories
+ // and parsing every .pom leaf it finds
+ StagingRepository repository = new StagingRepository();
+ repository.setRepositoryId("orgapachesling-3");
+ Set<Release> releases =
repositoryService.getReleasesFromContent(repository);
+ assertEquals(1, releases.size());
+ assertEquals(
+ "Sling Adapter Annotations 1.0.0",
releases.iterator().next().getFullName());
+ }
+
+ @Test
+ public void testFindAnyReturnsOpenRepository() throws IOException {
+ // findAny does not require the repository to be closed, so the open
orgapachesling-2 resolves
+ StagingRepository repository = repositoryService.findAny(2);
+ assertNotNull(repository);
+ assertEquals("orgapachesling-2", repository.getRepositoryId());
+ }
+
+ @Test
+ public void testFindAnyUnknownThrows() {
+ try {
+ repositoryService.findAny(999);
+ fail("Expected an IllegalArgumentException for an unknown
repository id.");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("999"));
+ } catch (IOException e) {
+ fail("Unexpected IOException.");
+ }
+ }
+
+ @Test
+ public void testPromote() throws IOException {
+ // exercises the bulk-action POST path; MockNexus answers staging bulk
actions with HTTP 201
+ repositoryService.promote(getStagingRepository());
+ }
+
+ @Test
+ public void testCloseWithDescription() throws IOException {
+ repositoryService.close(getStagingRepository(), "voting");
+ }
+
+ @Test
+ public void testDrop() throws IOException {
+ repositoryService.drop(getStagingRepository());
+ }
+
+ @Test
+ public void testParsePomInheritsGroupIdAndVersionFromParent() throws
Exception {
+ // a child module POM omitting <groupId>/<version>/<packaging>
inherits them from <parent>
+ String pomXml = "<project>"
+ + "<name>Apache Sling Child</name>"
+ + "<artifactId>child</artifactId>"
+ + "<parent>"
+ + "<groupId>org.apache.sling</groupId>"
+ + "<artifactId>parent</artifactId>"
+ + "<version>3.4.5</version>"
+ + "</parent>"
+ + "</project>";
+ RepositoryService.PomCoordinates coordinates = invokeParsePom(pomXml);
+ assertNotNull(coordinates);
+ assertEquals("org.apache.sling", coordinates.groupId());
+ assertEquals("3.4.5", coordinates.version());
+ assertEquals("jar", coordinates.packaging());
+ }
+
+ @Test
+ public void testParsePomInvalidXmlReturnsNull() throws Exception {
+ // malformed XML triggers the error branch which logs and returns null
+ assertEquals(null, invokeParsePom("this is not xml"));
+ }
+
+ @Test
+ public void testToReleasesSkipsInvalidReleaseNames() {
+ // a POM whose name/version cannot be parsed into a Release yields an
empty result rather than
+ // throwing, exercising the buildReleases error branch
+ Set<Release> releases = RepositoryService.toReleases(
+ List.of(pom("", "org.apache.sling", "org.apache.sling.broken",
"", "jar", PARENT_POM)));
+ assertTrue(releases.isEmpty());
+ }
+
+ private RepositoryService.PomCoordinates invokeParsePom(String pomXml)
throws Exception {
Review Comment:
I think this hints we need to split the functionality (and test) to a new
class
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]