-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
129 additions
and
10 deletions.
There are no files selected for viewing
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
36 changes: 36 additions & 0 deletions
36
src/main/java/mafia/mafiatogether/job/ui/JobV2Controller.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,36 @@ | ||
package mafia.mafiatogether.job.ui; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import mafia.mafiatogether.job.application.JobService; | ||
import mafia.mafiatogether.job.application.dto.request.JobExecuteAbilityRequest; | ||
import mafia.mafiatogether.job.application.dto.response.JobExecuteAbilityResponse; | ||
import org.springframework.data.redis.core.StringRedisTemplate; | ||
import org.springframework.messaging.handler.annotation.DestinationVariable; | ||
import org.springframework.messaging.handler.annotation.MessageMapping; | ||
import org.springframework.messaging.handler.annotation.Payload; | ||
import org.springframework.stereotype.Controller; | ||
|
||
@Slf4j | ||
@Controller | ||
@RequiredArgsConstructor | ||
public class JobV2Controller { | ||
|
||
private final StringRedisTemplate stringRedisTemplate; | ||
private final JobService jobService; | ||
private final ObjectMapper objectMapper; | ||
|
||
@MessageMapping("/jab/skill/{code}/{name}") | ||
public void executeSkill( | ||
@DestinationVariable("code") String code, | ||
@DestinationVariable("name") String name, | ||
@Payload JobExecuteAbilityRequest request | ||
) throws JsonProcessingException { | ||
JobExecuteAbilityResponse response = jobService.executeSkill(code, name, request); | ||
String message = objectMapper.writeValueAsString(response); | ||
stringRedisTemplate.convertAndSend("/sub/jab/skill/" + response.job().toLowerCase() + "/" + code, message); | ||
} | ||
|
||
} |
82 changes: 82 additions & 0 deletions
82
src/test/java/mafia/mafiatogether/job/application/JobServiceTest.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,82 @@ | ||
package mafia.mafiatogether.job.application; | ||
|
||
import static org.mockito.BDDMockito.given; | ||
|
||
import java.util.HashMap; | ||
import java.util.Optional; | ||
import mafia.mafiatogether.job.application.dto.request.JobExecuteAbilityRequest; | ||
import mafia.mafiatogether.job.application.dto.response.JobExecuteAbilityResponse; | ||
import mafia.mafiatogether.job.domain.JobTarget; | ||
import mafia.mafiatogether.job.domain.JobTargetRepository; | ||
import mafia.mafiatogether.job.domain.PlayerJob; | ||
import mafia.mafiatogether.job.domain.PlayerJobRepository; | ||
import mafia.mafiatogether.job.domain.jobtype.Citizen; | ||
import mafia.mafiatogether.job.domain.jobtype.Doctor; | ||
import mafia.mafiatogether.job.domain.jobtype.Mafia; | ||
import mafia.mafiatogether.job.domain.jobtype.Police; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
|
||
@SpringBootTest | ||
class JobServiceTest { | ||
|
||
@Autowired | ||
private JobService jobService; | ||
|
||
@MockBean | ||
private JobTargetRepository jobTargetRepository; | ||
@MockBean | ||
private PlayerJobRepository playerJobRepository; | ||
|
||
@Test | ||
void 마피아_능력을_사용할_수_있다() { | ||
//given | ||
final String code = "test"; | ||
given(jobTargetRepository.findById(code)).willReturn(Optional.of(new JobTarget(code, new HashMap<>()))); | ||
given(playerJobRepository.findById(code)).willReturn(Optional.of(new PlayerJob(code, new HashMap<>() {{ | ||
put("파워", new Mafia()); | ||
put("달리", new Citizen()); | ||
put("매튜", new Doctor()); | ||
put("지윤", new Police()); | ||
}}))); | ||
|
||
//when | ||
JobExecuteAbilityResponse response = jobService.executeSkill( | ||
code, | ||
"파워", | ||
new JobExecuteAbilityRequest("매튜") | ||
); | ||
|
||
//then | ||
Assertions.assertThat(response.job()).isEqualTo("MAFIA"); | ||
Assertions.assertThat(response.result()).isEqualTo("매튜"); | ||
} | ||
|
||
@Test | ||
void 경찰_능력을_사용할_수_있다() { | ||
//given | ||
final String code = "test"; | ||
given(jobTargetRepository.findById(code)).willReturn(Optional.of(new JobTarget(code, new HashMap<>()))); | ||
given(playerJobRepository.findById(code)).willReturn(Optional.of(new PlayerJob(code, new HashMap<>() {{ | ||
put("파워", new Mafia()); | ||
put("달리", new Citizen()); | ||
put("매튜", new Doctor()); | ||
put("지윤", new Police()); | ||
}}))); | ||
|
||
//when | ||
JobExecuteAbilityResponse response = jobService.executeSkill( | ||
code, | ||
"지윤", | ||
new JobExecuteAbilityRequest("파워") | ||
); | ||
|
||
//then | ||
Assertions.assertThat(response.job()).isEqualTo("POLICE"); | ||
Assertions.assertThat(response.result()).isEqualTo("MAFIA"); | ||
|
||
} | ||
} |