Skip to content

Commit

Permalink
Do not force nodeId configured when checking nexus webhook (#878)
Browse files Browse the repository at this point in the history
* fix(nexus): Do not force nodeId check if there is no repository with nodeId configured

* fix(nexus): Add test to check behaviour
  • Loading branch information
jmalvarezf-lmes committed Oct 6, 2020
1 parent 0443638 commit 6039886
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Expand Up @@ -26,6 +26,8 @@
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;

public class NexusEventPoster {
Expand Down Expand Up @@ -96,7 +98,11 @@ public void postEvent(NexusAssetWebhookPayload payload) {
}

private Optional<NexusRepo> findNexusRepo(NexusAssetWebhookPayload payload) {
if (payload.getNodeId() != null) {
List<NexusRepo> repoWithId =
nexusProperties.getSearches().stream()
.filter(repo -> StringUtils.isNotBlank(repo.getNodeId()))
.collect(Collectors.toList());
if (payload.getNodeId() != null && !repoWithId.isEmpty()) {
return nexusProperties.getSearches().stream()
.filter(
repo -> {
Expand Down
Expand Up @@ -33,6 +33,7 @@ class NexusEventPosterTest {

private EchoService echoService = mock(EchoService.class);
private NexusProperties nexusProperties = new NexusProperties();
private NexusProperties nexusPropertiesWithoutNodeId = new NexusProperties();

{
final NexusRepo nexusRepo = new NexusRepo();
Expand All @@ -43,7 +44,17 @@ class NexusEventPosterTest {
nexusProperties.setSearches(Collections.singletonList(nexusRepo));
}

{
final NexusRepo nexusRepoWithoutNodeId = new NexusRepo();
nexusRepoWithoutNodeId.setName("nexus-snapshots");
nexusRepoWithoutNodeId.setRepo("maven-snapshots");
nexusRepoWithoutNodeId.setBaseUrl("http://localhost:8082/repository/");
nexusPropertiesWithoutNodeId.setSearches(Collections.singletonList(nexusRepoWithoutNodeId));
}

private NexusEventPoster nexusEventPoster = new NexusEventPoster(nexusProperties, echoService);
private NexusEventPoster nexusEventPosterWithoutNodeId =
new NexusEventPoster(nexusPropertiesWithoutNodeId, echoService);
final NexusAssetWebhookPayload payload = new NexusAssetWebhookPayload();

{
Expand Down Expand Up @@ -150,4 +161,27 @@ void postNonMatchingRepoArtifactWithRepoId() {
.postEvent(
new NexusAssetEvent(new NexusAssetEvent.Content("nexus-snapshots", expectedArtifact)));
}

@Test
void findRepoWithNodeIdInConfig() {
payload.setRepositoryName("maven-snapshots");
payload.setNodeId("123");
payload.getAsset().setName("com/example/demo/0.0.1-SNAPSHOT/demo-0.0.1-20190828.022502-3.pom");

nexusEventPosterWithoutNodeId.postEvent(payload);

final Artifact expectedArtifact =
Artifact.builder()
.type("maven/file")
.reference("com.example" + ":" + "demo" + ":" + "0.0.1-SNAPSHOT")
.name("com.example" + ":" + "demo")
.version("0.0.1-SNAPSHOT")
.provenance("maven-snapshots")
.location(
"http://localhost:8082/service/rest/repository/browse/maven-snapshots/com/example/demo/0.0.1-SNAPSHOT/0.0.1-20190828.022502-3/")
.build();
verify(echoService)
.postEvent(
new NexusAssetEvent(new NexusAssetEvent.Content("nexus-snapshots", expectedArtifact)));
}
}

0 comments on commit 6039886

Please sign in to comment.