From 3f2b9903fb6134ab5c722d8b44350f5c10aaca65 Mon Sep 17 00:00:00 2001 From: zaza Date: Thu, 20 Apr 2023 12:46:26 +0200 Subject: [PATCH] Fix #33 by removing redundant parameter in CDEventTypes.createXEvent --- src/main/java/dev/cdevents/CDEventTypes.java | 209 +++++++++--------- .../java/dev/cdevents/CDEventTypesTest.java | 75 +------ 2 files changed, 110 insertions(+), 174 deletions(-) diff --git a/src/main/java/dev/cdevents/CDEventTypes.java b/src/main/java/dev/cdevents/CDEventTypes.java index 6a55731..63852a9 100644 --- a/src/main/java/dev/cdevents/CDEventTypes.java +++ b/src/main/java/dev/cdevents/CDEventTypes.java @@ -1,21 +1,57 @@ package dev.cdevents; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.ArtifactPackagedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.ArtifactPublishedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.BranchCreatedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.BranchDeletedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.BuildFinishedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.BuildQueuedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.BuildStartedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.ChangeAbandonedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.ChangeCreatedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.ChangeMergedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.ChangeReviewedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.ChangeUpdatedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.EnvironmentCreatedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.EnvironmentDeletedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.EnvironmentModifiedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.PipelineRunFinishedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.PipelineRunQueuedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.PipelineRunStartedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.RepositoryCreatedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.RepositoryDeletedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.RepositoryModifiedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.ServiceDeployedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.ServicePublishedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.ServiceRemovedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.ServiceRolledBackEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.ServiceUpgradedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.TaskRunFinishedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.TaskRunStartedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.TestCaseFinishedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.TestCaseQueuedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.TestCaseStartedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.TestSuiteFinishedEvent; +import static dev.cdevents.constants.CDEventConstants.CDEventTypes.TestSuiteStartedEvent; + import java.net.URI; import java.net.URL; import java.nio.charset.StandardCharsets; import java.time.OffsetDateTime; import java.util.UUID; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; + import dev.cdevents.constants.CDEventConstants; import dev.cdevents.models.Environment; import dev.cdevents.models.PipelineRun; import dev.cdevents.models.Repository; import io.cloudevents.CloudEvent; import io.cloudevents.core.v03.CloudEventBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public final class CDEventTypes { @@ -39,7 +75,6 @@ private CDEventTypes() { * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param pipelineName @@ -53,12 +88,11 @@ private CDEventTypes() { public static CloudEvent createPipelineRunFinishedEvent( - final String eventType, final String id, final URI source, final String pipelineName, final URI url, final CDEventConstants.Outcome outcome, final String errors, final String pipelineRunData) { CloudEvent ceToSend = - buildCloudEvent(eventType, pipelineRunData) + buildCloudEvent(PipelineRunFinishedEvent, pipelineRunData) .withExtension("id", id) .withExtension("source", source) .withExtension("pipelinename", pipelineName) @@ -74,7 +108,6 @@ public static CloudEvent createPipelineRunFinishedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param pipelineName @@ -86,12 +119,11 @@ public static CloudEvent createPipelineRunFinishedEvent( public static CloudEvent createPipelineRunQueuedEvent( - final String eventType, final String id, final URI source, final String pipelineName, final URI url, final String pipelineRunData) { CloudEvent ceToSend = - buildCloudEvent(eventType, pipelineRunData) + buildCloudEvent(PipelineRunQueuedEvent, pipelineRunData) .withExtension("id", id) .withExtension("source", source) .withExtension("pipelinename", pipelineName) @@ -105,7 +137,6 @@ public static CloudEvent createPipelineRunQueuedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param pipelineName @@ -117,12 +148,11 @@ public static CloudEvent createPipelineRunQueuedEvent( public static CloudEvent createPipelineRunStartedEvent( - final String eventType, final String id, final URI source, final String pipelineName, final URI url, final String pipelineRunData) { CloudEvent ceToSend = - buildCloudEvent(eventType, pipelineRunData) + buildCloudEvent(PipelineRunStartedEvent, pipelineRunData) .withExtension("id", id) .withExtension("source", source) .withExtension("pipelinename", pipelineName) @@ -136,7 +166,6 @@ public static CloudEvent createPipelineRunStartedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param taskName @@ -148,14 +177,14 @@ public static CloudEvent createPipelineRunStartedEvent( */ public static CloudEvent createTaskRunStartedEvent( - final String eventType, final String id, + final String id, final URI source, final String taskName, final PipelineRun pipelineRun, final URI url, final String taskRunData) { CloudEvent ceToSend = null; try { - ceToSend = buildCloudEvent(eventType, taskRunData) + ceToSend = buildCloudEvent(TaskRunStartedEvent, taskRunData) .withExtension("id", id) .withExtension("source", source) .withExtension("taskname", taskName) @@ -175,7 +204,6 @@ public static CloudEvent createTaskRunStartedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param taskName @@ -190,7 +218,7 @@ public static CloudEvent createTaskRunStartedEvent( public static CloudEvent createTaskRunFinishedEvent( - final String eventType, final String id, + final String id, final URI source, final String taskName, final PipelineRun pipelineRun, final URI url, final CDEventConstants.Outcome outcome, final String errors, @@ -198,7 +226,7 @@ public static CloudEvent createTaskRunFinishedEvent( CloudEvent ceToSend = null; try { - ceToSend = buildCloudEvent(eventType, taskRunData) + ceToSend = buildCloudEvent(TaskRunFinishedEvent, taskRunData) .withExtension("id", id) .withExtension("source", source) .withExtension("taskname", taskName) @@ -221,7 +249,6 @@ public static CloudEvent createTaskRunFinishedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param name @@ -234,12 +261,12 @@ public static CloudEvent createTaskRunFinishedEvent( */ public static CloudEvent createRepositoryCreatedEvent( - final String eventType, final String id, + final String id, final URI source, final String name, final String owner, final URI url, final URI viewUrl, final String data) { CloudEvent ceToSend = - buildCloudEvent(eventType, data) + buildCloudEvent(RepositoryCreatedEvent, data) .withExtension("id", id) .withExtension("source", source) .withExtension("name", name) @@ -255,7 +282,6 @@ public static CloudEvent createRepositoryCreatedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param name @@ -268,12 +294,12 @@ public static CloudEvent createRepositoryCreatedEvent( */ public static CloudEvent createRepositoryModifiedEvent( - final String eventType, final String id, + final String id, final URI source, final String name, final String owner, final URI url, final URI viewUrl, final String data) { CloudEvent ceToSend = - buildCloudEvent(eventType, data) + buildCloudEvent(RepositoryModifiedEvent, data) .withExtension("id", id) .withExtension("source", source) .withExtension("name", name) @@ -289,7 +315,6 @@ public static CloudEvent createRepositoryModifiedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param name @@ -302,12 +327,12 @@ public static CloudEvent createRepositoryModifiedEvent( */ public static CloudEvent createRepositoryDeletedEvent( - final String eventType, final String id, + final String id, final URI source, final String name, final String owner, final URI url, final URI viewUrl, final String data) { CloudEvent ceToSend = - buildCloudEvent(eventType, data) + buildCloudEvent(RepositoryDeletedEvent, data) .withExtension("id", id) .withExtension("source", source) .withExtension("name", name) @@ -323,7 +348,6 @@ public static CloudEvent createRepositoryDeletedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param repository @@ -332,13 +356,13 @@ public static CloudEvent createRepositoryDeletedEvent( * branch created event extensions */ public static CloudEvent createBranchCreatedEvent( - final String eventType, final String id, + final String id, final URI source, final Repository repository, final String data) { CloudEvent cdToSend = null; try { - cdToSend = buildCloudEvent(eventType, data) + cdToSend = buildCloudEvent(BranchCreatedEvent, data) .withExtension("id", id) .withExtension("source", source) .withExtension("repository", @@ -357,7 +381,6 @@ public static CloudEvent createBranchCreatedEvent( * and returns {@link CloudEvent} object. * * - * @param eventType * @param id * @param source * @param repository @@ -367,13 +390,13 @@ public static CloudEvent createBranchCreatedEvent( */ public static CloudEvent createBranchDeletedEvent( - final String eventType, final String id, + final String id, final URI source, final Repository repository, final String data) { CloudEvent cdToSend = null; try { - cdToSend = buildCloudEvent(eventType, data) + cdToSend = buildCloudEvent(BranchDeletedEvent, data) .withExtension("id", id) .withExtension("source", source) .withExtension("repository", @@ -391,7 +414,6 @@ public static CloudEvent createBranchDeletedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param repository @@ -401,13 +423,13 @@ public static CloudEvent createBranchDeletedEvent( */ public static CloudEvent createChangeCreatedEvent( - final String eventType, final String id, + final String id, final URI source, final Repository repository, final String data) { CloudEvent cdToSend = null; try { - cdToSend = buildCloudEvent(eventType, data) + cdToSend = buildCloudEvent(ChangeCreatedEvent, data) .withExtension("id", id) .withExtension("source", source) .withExtension("repository", @@ -425,7 +447,6 @@ public static CloudEvent createChangeCreatedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param repository @@ -435,13 +456,13 @@ public static CloudEvent createChangeCreatedEvent( */ public static CloudEvent createChangeReviewedEvent( - final String eventType, final String id, + final String id, final URI source, final Repository repository, final String data) { CloudEvent cdToSend = null; try { - cdToSend = buildCloudEvent(eventType, data) + cdToSend = buildCloudEvent(ChangeReviewedEvent, data) .withExtension("id", id) .withExtension("source", source) .withExtension("repository", @@ -459,7 +480,6 @@ public static CloudEvent createChangeReviewedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param repository @@ -469,13 +489,13 @@ public static CloudEvent createChangeReviewedEvent( */ public static CloudEvent createChangeMergedEvent( - final String eventType, final String id, + final String id, final URI source, final Repository repository, final String data) { CloudEvent cdToSend = null; try { - cdToSend = buildCloudEvent(eventType, data) + cdToSend = buildCloudEvent(ChangeMergedEvent, data) .withExtension("id", id) .withExtension("source", source) .withExtension("repository", @@ -493,7 +513,6 @@ public static CloudEvent createChangeMergedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param repository @@ -503,13 +522,13 @@ public static CloudEvent createChangeMergedEvent( */ public static CloudEvent createChangeAbandonedEvent( - final String eventType, final String id, + final String id, final URI source, final Repository repository, final String data) { CloudEvent cdToSend = null; try { - cdToSend = buildCloudEvent(eventType, data) + cdToSend = buildCloudEvent(ChangeAbandonedEvent, data) .withExtension("id", id) .withExtension("source", source) .withExtension("repository", @@ -527,7 +546,6 @@ public static CloudEvent createChangeAbandonedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param repository @@ -537,13 +555,13 @@ public static CloudEvent createChangeAbandonedEvent( */ public static CloudEvent createChangeUpdatedEvent( - final String eventType, final String id, + final String id, final URI source, final Repository repository, final String data) { CloudEvent cdToSend = null; try { - cdToSend = buildCloudEvent(eventType, data) + cdToSend = buildCloudEvent(ChangeUpdatedEvent, data) .withExtension("id", id) .withExtension("source", source) .withExtension("repository", @@ -561,7 +579,6 @@ public static CloudEvent createChangeUpdatedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param data @@ -570,10 +587,10 @@ public static CloudEvent createChangeUpdatedEvent( */ public static CloudEvent createBuildQueuedEvent( - final String eventType, final String id, + final String id, final URI source, final String data) { CloudEvent cdToSend = - buildCloudEvent(eventType, data) + buildCloudEvent(BuildQueuedEvent, data) .withExtension("id", id) .withExtension("source", source) .build(); @@ -585,7 +602,6 @@ public static CloudEvent createBuildQueuedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param data @@ -594,10 +610,10 @@ public static CloudEvent createBuildQueuedEvent( */ public static CloudEvent createBuildStartedEvent( - final String eventType, final String id, + final String id, final URI source, final String data) { CloudEvent cdToSend = - buildCloudEvent(eventType, data) + buildCloudEvent(BuildStartedEvent, data) .withExtension("id", id) .withExtension("source", source) .build(); @@ -609,7 +625,6 @@ public static CloudEvent createBuildStartedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param artifactId @@ -619,11 +634,11 @@ public static CloudEvent createBuildStartedEvent( */ public static CloudEvent createBuildFinishedEvent( - final String eventType, final String id, + final String id, final URI source, final URI artifactId, final String data) { CloudEvent cdToSend = - buildCloudEvent(eventType, data) + buildCloudEvent(BuildFinishedEvent, data) .withExtension("id", id) .withExtension("source", source) .withExtension("artifactid", artifactId) @@ -636,7 +651,6 @@ public static CloudEvent createBuildFinishedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param data @@ -645,10 +659,10 @@ public static CloudEvent createBuildFinishedEvent( */ public static CloudEvent createTestCaseQueuedEvent( - final String eventType, final String id, + final String id, final URI source, final String data) { CloudEvent cdToSend = - buildCloudEvent(eventType, data) + buildCloudEvent(TestCaseQueuedEvent, data) .withExtension("id", id) .withExtension("source", source) .build(); @@ -660,7 +674,6 @@ public static CloudEvent createTestCaseQueuedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param data @@ -669,10 +682,10 @@ public static CloudEvent createTestCaseQueuedEvent( */ public static CloudEvent createTestCaseStartedEvent( - final String eventType, final String id, + final String id, final URI source, final String data) { CloudEvent cdToSend = - buildCloudEvent(eventType, data) + buildCloudEvent(TestCaseStartedEvent, data) .withExtension("id", id) .withExtension("source", source) .build(); @@ -684,7 +697,6 @@ public static CloudEvent createTestCaseStartedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param data @@ -693,10 +705,10 @@ public static CloudEvent createTestCaseStartedEvent( */ public static CloudEvent createTestCaseFinishedEvent( - final String eventType, final String id, + final String id, final URI source, final String data) { CloudEvent cdToSend = - buildCloudEvent(eventType, data) + buildCloudEvent(TestCaseFinishedEvent, data) .withExtension("id", id) .withExtension("source", source) .build(); @@ -708,7 +720,6 @@ public static CloudEvent createTestCaseFinishedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param data @@ -717,10 +728,10 @@ public static CloudEvent createTestCaseFinishedEvent( */ public static CloudEvent createTestSuiteStartedEvent( - final String eventType, final String id, + final String id, final URI source, final String data) { CloudEvent cdToSend = - buildCloudEvent(eventType, data) + buildCloudEvent(TestSuiteStartedEvent, data) .withExtension("id", id) .withExtension("source", source) .build(); @@ -732,7 +743,6 @@ public static CloudEvent createTestSuiteStartedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param data @@ -741,10 +751,10 @@ public static CloudEvent createTestSuiteStartedEvent( */ public static CloudEvent createTestSuiteFinishedEvent( - final String eventType, final String id, + final String id, final URI source, final String data) { CloudEvent cdToSend = - buildCloudEvent(eventType, data) + buildCloudEvent(TestSuiteFinishedEvent, data) .withExtension("id", id) .withExtension("source", source) .build(); @@ -756,7 +766,6 @@ public static CloudEvent createTestSuiteFinishedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param data @@ -765,10 +774,10 @@ public static CloudEvent createTestSuiteFinishedEvent( */ public static CloudEvent createArtifactPackagedEvent( - final String eventType, final String id, + final String id, final URI source, final String data) { CloudEvent cdToSend = - buildCloudEvent(eventType, data) + buildCloudEvent(ArtifactPackagedEvent, data) .withExtension("id", id) .withExtension("source", source) .build(); @@ -780,7 +789,6 @@ public static CloudEvent createArtifactPackagedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param data @@ -789,10 +797,10 @@ public static CloudEvent createArtifactPackagedEvent( */ public static CloudEvent createArtifactPublishedEvent( - final String eventType, final String id, + final String id, final URI source, final String data) { CloudEvent cdToSend = - buildCloudEvent(eventType, data) + buildCloudEvent(ArtifactPublishedEvent, data) .withExtension("id", id) .withExtension("source", source) .build(); @@ -804,7 +812,6 @@ public static CloudEvent createArtifactPublishedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param name @@ -815,11 +822,11 @@ public static CloudEvent createArtifactPublishedEvent( */ public static CloudEvent createEnvironmentCreatedEvent( - final String eventType, final String id, + final String id, final URI source, final String name, final String url, final String data) { CloudEvent cdToSend = - buildCloudEvent(eventType, data) + buildCloudEvent(EnvironmentCreatedEvent, data) .withExtension("id", id) .withExtension("source", source) .withExtension("name", name) @@ -833,7 +840,6 @@ public static CloudEvent createEnvironmentCreatedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param name @@ -844,11 +850,11 @@ public static CloudEvent createEnvironmentCreatedEvent( */ public static CloudEvent createEnvironmentModifiedEvent( - final String eventType, final String id, + final String id, final URI source, final String name, final String url, final String data) { CloudEvent cdToSend = - buildCloudEvent(eventType, data) + buildCloudEvent(EnvironmentModifiedEvent, data) .withExtension("id", id) .withExtension("source", source) .withExtension("name", name) @@ -862,7 +868,6 @@ public static CloudEvent createEnvironmentModifiedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param source * @param name @@ -872,11 +877,11 @@ public static CloudEvent createEnvironmentModifiedEvent( */ public static CloudEvent createEnvironmentDeletedEvent( - final String eventType, final String id, + final String id, final URI source, final String name, final String data) { CloudEvent cdToSend = - buildCloudEvent(eventType, data) + buildCloudEvent(EnvironmentDeletedEvent, data) .withExtension("id", id) .withExtension("source", source) .withExtension("name", name) @@ -889,7 +894,6 @@ public static CloudEvent createEnvironmentDeletedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param environment * @param artifactId @@ -899,13 +903,13 @@ public static CloudEvent createEnvironmentDeletedEvent( */ public static CloudEvent createServiceDeployedEvent( - final String eventType, final String id, + final String id, final Environment environment, final URL artifactId, final String data) { CloudEvent cdToSend = null; try { - cdToSend = buildCloudEvent(eventType, data) + return buildCloudEvent(ServiceDeployedEvent, data) .withExtension("id", id) .withExtension("environment", objectMapper.writeValueAsString(environment)) @@ -923,7 +927,6 @@ public static CloudEvent createServiceDeployedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param environment * @param artifactId @@ -933,13 +936,13 @@ public static CloudEvent createServiceDeployedEvent( */ public static CloudEvent createServiceUpgradedEvent( - final String eventType, final String id, + final String id, final Environment environment, final URL artifactId, final String data) { CloudEvent cdToSend = null; try { - cdToSend = buildCloudEvent(eventType, data) + cdToSend = buildCloudEvent(ServiceUpgradedEvent, data) .withExtension("id", id) .withExtension("environment", objectMapper.writeValueAsString(environment)) @@ -957,7 +960,6 @@ public static CloudEvent createServiceUpgradedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param environment * @param artifactId @@ -967,13 +969,13 @@ public static CloudEvent createServiceUpgradedEvent( */ public static CloudEvent createServiceRolledBackEvent( - final String eventType, final String id, + final String id, final Environment environment, final URL artifactId, final String data) { CloudEvent cdToSend = null; try { - cdToSend = buildCloudEvent(eventType, data) + cdToSend = buildCloudEvent(ServiceRolledBackEvent, data) .withExtension("id", id) .withExtension("environment", objectMapper.writeValueAsString(environment)) @@ -991,7 +993,6 @@ public static CloudEvent createServiceRolledBackEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param environment * @param data @@ -1000,12 +1001,12 @@ public static CloudEvent createServiceRolledBackEvent( */ public static CloudEvent createServiceRemovedEvent( - final String eventType, final String id, + final String id, final Environment environment, final String data) { CloudEvent cdToSend = null; try { - cdToSend = buildCloudEvent(eventType, data) + cdToSend = buildCloudEvent(ServiceRemovedEvent, data) .withExtension("id", id) .withExtension("environment", objectMapper.writeValueAsString(environment)) @@ -1022,7 +1023,6 @@ public static CloudEvent createServiceRemovedEvent( * using {@link CloudEventBuilder} * and returns {@link CloudEvent} object. * - * @param eventType * @param id * @param environment * @param data @@ -1031,12 +1031,12 @@ public static CloudEvent createServiceRemovedEvent( */ public static CloudEvent createServicePublishedEvent( - final String eventType, final String id, + final String id, final Environment environment, final String data) { CloudEvent cdToSend = null; try { - cdToSend = buildCloudEvent(eventType, data) + cdToSend = buildCloudEvent(ServicePublishedEvent, data) .withExtension("id", id) .withExtension("environment", objectMapper.writeValueAsString(environment)) @@ -1050,13 +1050,12 @@ public static CloudEvent createServicePublishedEvent( private static CloudEventBuilder buildCloudEvent( - final String eventType, final String eventData) { - CloudEventBuilder ceBuilder = new CloudEventBuilder() + final dev.cdevents.constants.CDEventConstants.CDEventTypes eventType, final String eventData) { + return new CloudEventBuilder() .withId(UUID.randomUUID().toString()) .withSource(URI.create("cdevents-sdk-java")) - .withType(eventType) + .withType(eventType.getEventType()) .withData(eventData.getBytes(StandardCharsets.UTF_8)) .withTime(OffsetDateTime.now()); - return ceBuilder; } } diff --git a/src/test/java/dev/cdevents/CDEventTypesTest.java b/src/test/java/dev/cdevents/CDEventTypesTest.java index ced5c1c..2f1a704 100644 --- a/src/test/java/dev/cdevents/CDEventTypesTest.java +++ b/src/test/java/dev/cdevents/CDEventTypesTest.java @@ -46,12 +46,9 @@ public class CDEventTypesTest { void createPipelineRunFinishedEventTest() throws URISyntaxException { URI url = new URI("cdevents.dev"); CloudEvent cdEvent = CDEventTypes.createPipelineRunFinishedEvent( - CDEventConstants.CDEventTypes. - PipelineRunFinishedEvent.getEventType(), "id", url, "name", url, CDEventConstants.Outcome.OutcomeSuccess, "errors", "data"); - assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source", "pipelinename", "url", "outcome", "errors"); @@ -69,8 +66,6 @@ void createPipelineRunFinishedEventTest() throws URISyntaxException { void createPipelineRunStartedEventTest() throws URISyntaxException { URI url = new URI("cdevents.dev"); CloudEvent cdEvent = CDEventTypes.createPipelineRunStartedEvent( - CDEventConstants.CDEventTypes. - PipelineRunStartedEvent.getEventType(), "id", url, "name", url, "data"); assertThat(cdEvent.getExtensionNames()) @@ -87,8 +82,6 @@ void createPipelineRunStartedEventTest() throws URISyntaxException { void createPipelineRunQueuedEventTest() throws URISyntaxException { URI url = new URI("cdevents.dev"); CloudEvent cdEvent = CDEventTypes.createPipelineRunQueuedEvent( - CDEventConstants.CDEventTypes. - PipelineRunQueuedEvent.getEventType(), "id", url, "name", url, "data"); assertThat(cdEvent.getExtensionNames()) @@ -106,9 +99,8 @@ void createTaskRunStartedTest() throws URISyntaxException, JsonProcessingException { URI url = new URI("cdevents.dev"); PipelineRun pipelineRun = new PipelineRun(); + CloudEvent cdEvent = CDEventTypes.createTaskRunStartedEvent( - CDEventConstants.CDEventTypes. - TaskRunStartedEvent.getEventType(), "id", url, "taskname", pipelineRun, url, "data"); assertThat(cdEvent.getExtensionNames()) @@ -129,8 +121,7 @@ void createTaskRunFinishedTest() URI url = new URI("cdevents.dev"); PipelineRun pipelineRun = new PipelineRun(); CloudEvent cdEvent = CDEventTypes.createTaskRunFinishedEvent( - CDEventConstants.CDEventTypes. - TaskRunFinishedEvent.getEventType(), "id", url, + "id", url, "taskname", pipelineRun, url, CDEventConstants.Outcome. OutcomeSuccess, "errors", "data"); @@ -153,8 +144,6 @@ void createTaskRunFinishedTest() void createRepositoryCreatedEventTest() throws URISyntaxException { URI url = new URI("cdevents.dev"); CloudEvent cdEvent = CDEventTypes.createRepositoryCreatedEvent( - CDEventConstants.CDEventTypes. - RepositoryCreatedEvent.getEventType(), "id", url, "name", "owner", url, url, "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source", "name", @@ -172,8 +161,6 @@ void createRepositoryCreatedEventTest() throws URISyntaxException { void createRepositoryModifiedEventTest() throws URISyntaxException { URI url = new URI("cdevents.dev"); CloudEvent cdEvent = CDEventTypes.createRepositoryModifiedEvent( - CDEventConstants.CDEventTypes. - RepositoryModifiedEvent.getEventType(), "id", url, "name", "owner", url, url, "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source", "name", @@ -191,8 +178,6 @@ void createRepositoryModifiedEventTest() throws URISyntaxException { void createRepositoryDeletedEventTest() throws URISyntaxException { URI url = new URI("cdevents.dev"); CloudEvent cdEvent = CDEventTypes.createRepositoryDeletedEvent( - CDEventConstants.CDEventTypes. - RepositoryDeletedEvent.getEventType(), "id", url, "name", "owner", url, url, "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source", "name", @@ -212,8 +197,6 @@ void createBranchCreatedEventTest() URI url = new URI("cdevents.dev"); Repository repository = new Repository(); CloudEvent cdEvent = CDEventTypes.createBranchCreatedEvent( - CDEventConstants.CDEventTypes. - BranchCreatedEvent.getEventType(), "id", url, repository, "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source", "repository"); @@ -230,8 +213,6 @@ void createBranchDeletedEventTest() URI url = new URI("cdevents.dev"); Repository repository = new Repository(); CloudEvent cdEvent = CDEventTypes.createBranchDeletedEvent( - CDEventConstants.CDEventTypes. - BranchDeletedEvent.getEventType(), "id", url, repository, "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source", "repository"); @@ -248,8 +229,6 @@ void createChangeCreatedEventTest() URI url = new URI("cdevents.dev"); Repository repository = new Repository(); CloudEvent cdEvent = CDEventTypes.createChangeCreatedEvent( - CDEventConstants.CDEventTypes. - ChangeCreatedEvent.getEventType(), "id", url, repository, "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source", "repository"); @@ -266,8 +245,6 @@ void createChangeReviewedEventTest() URI url = new URI("cdevents.dev"); Repository repository = new Repository(); CloudEvent cdEvent = CDEventTypes.createChangeReviewedEvent( - CDEventConstants.CDEventTypes. - ChangeReviewedEvent.getEventType(), "id", url, repository, "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source", "repository"); @@ -284,8 +261,6 @@ void createChangeMergedEventTest() URI url = new URI("cdevents.dev"); Repository repository = new Repository(); CloudEvent cdEvent = CDEventTypes.createChangeMergedEvent( - CDEventConstants.CDEventTypes. - ChangeMergedEvent.getEventType(), "id", url, repository, "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source", "repository"); @@ -302,8 +277,6 @@ void createChangeAbandonedEventTest() URI url = new URI("cdevents.dev"); Repository repository = new Repository(); CloudEvent cdEvent = CDEventTypes.createChangeAbandonedEvent( - CDEventConstants.CDEventTypes. - ChangeAbandonedEvent.getEventType(), "id", url, repository, "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source", "repository"); @@ -320,8 +293,6 @@ void createChangeUpdatedEventTest() URI url = new URI("cdevents.dev"); Repository repository = new Repository(); CloudEvent cdEvent = CDEventTypes.createChangeUpdatedEvent( - CDEventConstants.CDEventTypes. - ChangeUpdatedEvent.getEventType(), "id", url, repository, "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source", "repository"); @@ -336,8 +307,6 @@ void createChangeUpdatedEventTest() void createBuildQueuedEventTest() throws URISyntaxException { URI url = new URI("cdevents.dev"); CloudEvent cdEvent = CDEventTypes.createBuildQueuedEvent( - CDEventConstants.CDEventTypes. - BuildQueuedEvent.getEventType(), "id", url, "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source"); @@ -350,8 +319,6 @@ void createBuildQueuedEventTest() throws URISyntaxException { void createBuildStartedEventTest() throws URISyntaxException { URI url = new URI("cdevents.dev"); CloudEvent cdEvent = CDEventTypes.createBuildStartedEvent( - CDEventConstants.CDEventTypes. - BuildStartedEvent.getEventType(), "id", url, "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source"); @@ -364,8 +331,6 @@ void createBuildStartedEventTest() throws URISyntaxException { void createBuildFinishedEventTest() throws URISyntaxException { URI url = new URI("cdevents.dev"); CloudEvent cdEvent = CDEventTypes.createBuildFinishedEvent( - CDEventConstants.CDEventTypes. - BuildFinishedEvent.getEventType(), "id", url, url, "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source", "artifactid"); @@ -379,8 +344,6 @@ void createBuildFinishedEventTest() throws URISyntaxException { void createTestCaseQueuedEventTest() throws URISyntaxException { URI url = new URI("cdevents.dev"); CloudEvent cdEvent = CDEventTypes.createTestCaseQueuedEvent( - CDEventConstants.CDEventTypes. - TestCaseQueuedEvent.getEventType(), "id", url, "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source"); @@ -393,8 +356,6 @@ void createTestCaseQueuedEventTest() throws URISyntaxException { void createTestCaseStartedEventTest() throws URISyntaxException { URI url = new URI("cdevents.dev"); CloudEvent cdEvent = CDEventTypes.createTestCaseStartedEvent( - CDEventConstants.CDEventTypes. - TestCaseStartedEvent.getEventType(), "id", url, "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source"); @@ -407,8 +368,6 @@ void createTestCaseStartedEventTest() throws URISyntaxException { void createTestCaseFinishedEventTest() throws URISyntaxException { URI url = new URI("cdevents.dev"); CloudEvent cdEvent = CDEventTypes.createTestCaseFinishedEvent( - CDEventConstants.CDEventTypes. - TestCaseFinishedEvent.getEventType(), "id", url, "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source"); @@ -421,8 +380,6 @@ void createTestCaseFinishedEventTest() throws URISyntaxException { void createTestSuiteStartedEventTest() throws URISyntaxException { URI url = new URI("cdevents.dev"); CloudEvent cdEvent = CDEventTypes.createTestSuiteStartedEvent( - CDEventConstants.CDEventTypes. - TestSuiteStartedEvent.getEventType(), "id", url, "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source"); @@ -435,8 +392,6 @@ void createTestSuiteStartedEventTest() throws URISyntaxException { void createTestSuiteFinishedEventTest() throws URISyntaxException { URI url = new URI("cdevents.dev"); CloudEvent cdEvent = CDEventTypes.createTestSuiteFinishedEvent( - CDEventConstants.CDEventTypes. - TestSuiteFinishedEvent.getEventType(), "id", url, "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source"); @@ -449,8 +404,6 @@ void createTestSuiteFinishedEventTest() throws URISyntaxException { void createArtifactPackagedEventTest() throws URISyntaxException { URI url = new URI("cdevents.dev"); CloudEvent cdEvent = CDEventTypes.createArtifactPackagedEvent( - CDEventConstants.CDEventTypes. - ArtifactPackagedEvent.getEventType(), "id", url, "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source"); @@ -463,8 +416,6 @@ void createArtifactPackagedEventTest() throws URISyntaxException { void createArtifactPublishedEventTest() throws URISyntaxException { URI url = new URI("cdevents.dev"); CloudEvent cdEvent = CDEventTypes.createArtifactPublishedEvent( - CDEventConstants.CDEventTypes. - ArtifactPublishedEvent.getEventType(), "id", url, "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source"); @@ -477,8 +428,6 @@ void createArtifactPublishedEventTest() throws URISyntaxException { void createEnvironmentCreatedEventTest() throws URISyntaxException { URI url = new URI("cdevents.dev"); CloudEvent cdEvent = CDEventTypes.createEnvironmentCreatedEvent( - CDEventConstants.CDEventTypes. - EnvironmentCreatedEvent.getEventType(), "id", url, "name", "url", "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source", "name", "url"); @@ -493,8 +442,6 @@ void createEnvironmentCreatedEventTest() throws URISyntaxException { void createEnvironmentModifiedEventTest() throws URISyntaxException { URI url = new URI("cdevents.dev"); CloudEvent cdEvent = CDEventTypes.createEnvironmentModifiedEvent( - CDEventConstants.CDEventTypes. - EnvironmentModifiedEvent.getEventType(), "id", url, "name", "url", "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source", "name", "url"); @@ -509,8 +456,6 @@ void createEnvironmentModifiedEventTest() throws URISyntaxException { void createEnvironmentDeletedEventTest() throws URISyntaxException { URI url = new URI("cdevents.dev"); CloudEvent cdEvent = CDEventTypes.createEnvironmentDeletedEvent( - CDEventConstants.CDEventTypes. - EnvironmentDeletedEvent.getEventType(), "id", url, "name", "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "source", "name"); @@ -528,8 +473,6 @@ void createServiceDeployedTest() URL purl = new URL("https://www.cdevents.dev"); Environment environment = new Environment("id", url, "name", "url"); CloudEvent cdEvent = CDEventTypes.createServiceDeployedEvent( - CDEventConstants.CDEventTypes. - ServiceDeployedEvent.getEventType(), "id", environment, purl, "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "environment", "artifactid"); @@ -550,8 +493,6 @@ void createServiceUpgradedTest() URL purl = new URL("https://www.cdevents.dev"); Environment environment = new Environment("id", url, "name", "url"); CloudEvent cdEvent = CDEventTypes.createServiceUpgradedEvent( - CDEventConstants.CDEventTypes. - ServiceUpgradedEvent.getEventType(), "id", environment, purl, "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "environment", "artifactid"); @@ -571,8 +512,6 @@ void createServiceRolledBackTest() URL purl = new URL("https://www.cdevents.dev"); Environment environment = new Environment("id", url, "name", "url"); CloudEvent cdEvent = CDEventTypes.createServiceRolledBackEvent( - CDEventConstants.CDEventTypes. - ServiceRolledBackEvent.getEventType(), "id", environment, purl, "data"); assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "environment", "artifactid"); @@ -590,13 +529,12 @@ void createServiceRemovedTest() throws URISyntaxException, JsonProcessingException { URI url = new URI("cdevents.dev"); Environment environment = new Environment("id", url, "name", "url"); + CloudEvent cdEvent = CDEventTypes.createServiceRemovedEvent( - CDEventConstants.CDEventTypes. - ServiceRemovedEvent.getEventType(), "id", environment, "data"); + assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "environment"); - assertThat(cdEvent.getExtension("id")).isEqualTo("id"); assertThat(cdEvent.getExtension("environment")). isEqualTo(objectMapper.writeValueAsString(environment)); @@ -607,13 +545,12 @@ void createServicePublishedTest() throws URISyntaxException, JsonProcessingException { URI url = new URI("cdevents.dev"); Environment environment = new Environment("id", url, "name", "url"); + CloudEvent cdEvent = CDEventTypes.createServicePublishedEvent( - CDEventConstants.CDEventTypes. - ServicePublishedEvent.getEventType(), "id", environment, "data"); + assertThat(cdEvent.getExtensionNames()) .containsExactlyInAnyOrder("id", "environment"); - assertThat(cdEvent.getExtension("id")).isEqualTo("id"); assertThat(cdEvent.getExtension("environment")). isEqualTo(objectMapper.writeValueAsString(environment));