-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
intial commit for publishing collection exercise end event (#281)
* intial commit for publishing collection exercise end event * collection exercise end publisher * formatting * test fix * format * fix test for collection exericise end * auto patch increment * Add .editorconfig to .gitignore * version bump Co-authored-by: ras-rm-pr-bot <[email protected]> Co-authored-by: Matt <[email protected]>
- Loading branch information
1 parent
36aba21
commit 7864322
Showing
14 changed files
with
123 additions
and
11 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,3 +65,5 @@ diagrams/*.svg | |
|
||
# Mac | ||
*.DS_Store | ||
|
||
.editorconfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...a/uk/gov/ons/ctp/response/collection/exercise/message/CollectionExerciseEndPublisher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package uk.gov.ons.ctp.response.collection.exercise.message; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.util.UUID; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import uk.gov.ons.ctp.response.collection.exercise.CollectionExerciseApplication.CollectionExerciseEndOutboundGateway; | ||
import uk.gov.ons.ctp.response.collection.exercise.message.dto.CollectionExerciseEndEventDTO; | ||
|
||
@Component | ||
public class CollectionExerciseEndPublisher { | ||
|
||
private static final Logger LOGGER = | ||
LoggerFactory.getLogger(CollectionExerciseEndPublisher.class); | ||
|
||
@Autowired private ObjectMapper objectMapper; | ||
|
||
@Autowired private CollectionExerciseEndOutboundGateway messagingGateway; | ||
|
||
public void sendCollectionExerciseEnd(UUID collectionExerciseId) { | ||
CollectionExerciseEndEventDTO collectionExerciseEndEventDTO = | ||
new CollectionExerciseEndEventDTO(); | ||
collectionExerciseEndEventDTO.setCollectionExerciseId(collectionExerciseId); | ||
|
||
try { | ||
String payload = objectMapper.writeValueAsString(collectionExerciseEndEventDTO); | ||
messagingGateway.sendToPubsub(payload); | ||
} catch (JsonProcessingException e) { | ||
LOGGER.error("Failed to serialise collection exercise end event", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...k/gov/ons/ctp/response/collection/exercise/message/dto/CollectionExerciseEndEventDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package uk.gov.ons.ctp.response.collection.exercise.message.dto; | ||
|
||
import java.util.UUID; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor(access = AccessLevel.PUBLIC) | ||
public class CollectionExerciseEndEventDTO { | ||
private UUID collectionExerciseId; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
.../gov/ons/ctp/response/collection/exercise/message/CollectionExerciseEndPublisherTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package uk.gov.ons.ctp.response.collection.exercise.message; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.util.UUID; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import uk.gov.ons.ctp.response.collection.exercise.CollectionExerciseApplication; | ||
import uk.gov.ons.ctp.response.collection.exercise.message.dto.CollectionExerciseEndEventDTO; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class CollectionExerciseEndPublisherTest { | ||
|
||
@Mock private CollectionExerciseApplication.CollectionExerciseEndOutboundGateway messagingGateway; | ||
|
||
@Mock private ObjectMapper objectMapper; | ||
|
||
@InjectMocks CollectionExerciseEndPublisher collectionExerciseEndPublisher; | ||
|
||
@Test | ||
public void testSendCollectionExerciseEnd() throws Exception { | ||
UUID collectionExerciseId = UUID.randomUUID(); | ||
|
||
ObjectMapper mapper = new ObjectMapper(); | ||
String payload = | ||
mapper.writeValueAsString(new CollectionExerciseEndEventDTO(collectionExerciseId)); | ||
when(objectMapper.writeValueAsString(any(CollectionExerciseEndEventDTO.class))) | ||
.thenReturn(payload); | ||
|
||
collectionExerciseEndPublisher.sendCollectionExerciseEnd(collectionExerciseId); | ||
|
||
verify(objectMapper, times(1)).writeValueAsString(any(CollectionExerciseEndEventDTO.class)); | ||
verify(messagingGateway, times(1)).sendToPubsub(payload); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters