Skip to content

Commit

Permalink
feat(vote-paper) register
Browse files Browse the repository at this point in the history
refactor: VotePaperControllerIT FCM Assertion 추가
  • Loading branch information
habinkim committed Apr 30, 2024
1 parent d2953af commit 9245a60
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public class VoteMessageBrokerAdapter implements ProduceVotePaperUploadEventPort
private static final String VOTE_PAPER_UPLOAD_QUEUE = "send-vote-paper-upload-notification-dev";


/**
* @param produceVotePaperRegisterEvent {@link ProduceVotePaperRegisterEvent}
* @return {@link SendResult}
* @see com.tune_fun.v1.vote.adapter.input.message.VoteMessageConsumer#consumeVotePaperUploadEvent(ProduceVotePaperRegisterEvent)
*/
@Override
public SendResult<?> produceVotePaperUploadEvent(final ProduceVotePaperRegisterEvent produceVotePaperRegisterEvent) {
return sqsProvider.sendMessageRangedQueue(VOTE_PAPER_UPLOAD_QUEUE, produceVotePaperRegisterEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ public void register(final VotePaperCommands.Register command, final User user)
RegisteredVotePaper registeredVotePaper = saveVotePaper(command);
saveVoteChoiceByRegisteredVotePaper(command, registeredVotePaper);

// TODO : Scheduling 정책 수립
ProduceVotePaperRegisterEvent produceVotePaperRegisterEventBehavior = getProduceVotePaperUploadEventBehavior(registeredVotePaper);
SendResult<?> sendResult = produceVotePaperUploadEventPort.produceVotePaperUploadEvent(produceVotePaperRegisterEventBehavior);

log.info("sendResult: {}", objectUtil.objectToPrettyJson(sendResult.message().getPayload()));
log.info("sendResult: \n{}", objectUtil.objectToPrettyJson(sendResult.message().getPayload()));
}

public void validateRegistrableVotePaperCount(final User user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void send(ProduceVotePaperRegisterEvent produceVotePaperRegisterEvent) th
List<NotificationApprovedDevice> notificationApprovedDevices = loadDevicePort.
loadNotificationApprovedDevice(true, null, null);

log.info("notificationApprovedDevices: {}", objectUtil.objectToPrettyJson(notificationApprovedDevices));
log.info("notificationApprovedDevices: \n{}", objectUtil.objectToPrettyJson(notificationApprovedDevices));

SendVotePaperRegisterFcm sendVotePaperRegisterFcmBehavior = voteBehaviorMapper
.sendVotePaperRegisterFcm(produceVotePaperRegisterEvent, notificationApprovedDevices);
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application-test_standalone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ event:
sqs:
test:
queue-name: test
send-vote-paper-upload-notification:
queue-name: send-vote-paper-upload-notification-dev

kms:
jwt-signature-arn:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.tune_fun.v1.vote;

import com.tune_fun.v1.base.architecture.BoundedContextDependencyRuleTest;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;

import static org.junit.jupiter.api.parallel.ExecutionMode.CONCURRENT;

public class VoteBoundedContextDependencyRuleTest extends BoundedContextDependencyRuleTest {

private static final String BOUNDED_CONTEXT_PACKAGE = "vote";

@Override
public String getBoundedContextPackage() {
return BOUNDED_CONTEXT_PACKAGE;
}

@Execution(CONCURRENT)
@Test
@DisplayName("Vote Bounded Context satisfied Hexagonal Architecture.")
void checkAccountDependencyRule() {
checkDependencyRule();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.tune_fun.v1.common.config.Uris;
import com.tune_fun.v1.common.response.MessageCode;
import com.tune_fun.v1.dummy.DummyService;
import com.tune_fun.v1.external.firebase.FirebaseMessagingMediator;
import com.tune_fun.v1.vote.application.port.input.command.VotePaperCommands;
import com.tune_fun.v1.vote.application.port.output.LoadVoteChoicePort;
import com.tune_fun.v1.vote.application.port.output.LoadVotePaperPort;
Expand All @@ -15,6 +16,7 @@
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.restdocs.payload.FieldDescriptor;

import java.time.LocalDateTime;
Expand All @@ -29,6 +31,9 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.oneOf;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.verify;
import static org.springframework.http.HttpHeaders.AUTHORIZATION;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders;
Expand All @@ -48,6 +53,9 @@ class VotePaperControllerIT extends ControllerBaseTest {
@Autowired
private LoadVoteChoicePort loadVoteChoicePort;

@MockBean
private FirebaseMessagingMediator firebaseMessagingMediator;

@Test
@Order(1)
@DisplayName("투표 게시물 등록, 성공")
Expand All @@ -70,6 +78,8 @@ void registerVotePaperSuccess() throws Exception {
VotePaperCommands.Register command = new VotePaperCommands.Register("First Vote Paper", "test",
"deny-add-choices", voteStartAt, voteEndAt, offers);

doNothing().when(firebaseMessagingMediator).sendMulticastMessageByTokens(any());

FieldDescriptor[] requestDescriptors = {
fieldWithPath("title").description("투표 게시물 제목").attributes(constraint("NOT BLANK")),
fieldWithPath("content").description("투표 게시물 내용").attributes(constraint("NOT BLANK")),
Expand Down Expand Up @@ -104,6 +114,8 @@ void registerVotePaperSuccess() throws Exception {
)
);

verify(firebaseMessagingMediator).sendMulticastMessageByTokens(any());

Optional<RegisteredVotePaper> votePaperOptional = loadVotePaperPort.loadRegisteredVotePaper(dummyService.getDefaultUsername());
assertTrue(votePaperOptional.isPresent());

Expand All @@ -123,11 +135,11 @@ void registerVotePaperSuccess() throws Exception {
log.info("readMusic: {}", readMusic);
readMusic.forEach(music -> assertThat(music, oneOf("Love Lee", "Dolphin")));

List<String> readArtistName = JsonPath.parse(registeredVoteChoices).read("$..artistName");
List<String> readArtistName = JsonPath.parse(registeredVoteChoices).read("$[*].artistName");
log.info("readArtistName: {}", readArtistName);
readArtistName.forEach(artistName -> assertThat(artistName, oneOf("AKMU", "오마이걸")));

List<List<String>> readGenres = JsonPath.parse(registeredVoteChoices).read("$..genres");
List<List<String>> readGenres = JsonPath.parse(registeredVoteChoices).read("$[*].genres");
log.info("readGenres: {}", readGenres);
readGenres.forEach(genres -> assertThat(genres, oneOf(List.of("R&B", "Soul"), List.of("Dance", "Pop"))));
}
Expand Down

0 comments on commit 9245a60

Please sign in to comment.