Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not force nodeId configured when checking nexus webhook #878

Merged
merged 4 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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)));
}
}