-
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.
Merge pull request #458 from depromeet/test/457-greeting
test: Greeting λλ©μΈ ν μ€νΈ μ½λ μμ±
- Loading branch information
Showing
6 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
module-domain/src/test/java/com/depromeet/mock/greeting/FakeAIManager.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,17 @@ | ||
package com.depromeet.mock.greeting; | ||
|
||
import com.depromeet.greeting.port.out.AIPort; | ||
|
||
public class FakeAIManager implements AIPort { | ||
private static final String GENERATED_RESPONSE = "Hello, World!"; | ||
|
||
@Override | ||
public String getSummary(String inputText) { | ||
return GENERATED_RESPONSE; | ||
} | ||
|
||
@Override | ||
public String getChatCompletions() { | ||
return GENERATED_RESPONSE; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
module-domain/src/test/java/com/depromeet/mock/greeting/FakeGreetingCacheManager.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,24 @@ | ||
package com.depromeet.mock.greeting; | ||
|
||
import com.depromeet.greeting.domain.Greeting; | ||
import com.depromeet.greeting.port.out.GreetingCachePort; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class FakeGreetingCacheManager implements GreetingCachePort { | ||
private static final String GREETING_KEY = "greeting"; | ||
private Map<String, String> data = new HashMap<>(); | ||
|
||
@Override | ||
public Greeting saveGreeting(Greeting greeting) { | ||
if (greeting.getMessage() != null) { | ||
data.put(GREETING_KEY, greeting.getMessage()); | ||
} | ||
return greeting; | ||
} | ||
|
||
@Override | ||
public Greeting getGreeting() { | ||
return new Greeting(data.get(GREETING_KEY)); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
module-domain/src/test/java/com/depromeet/service/greeting/GreetingServiceTest.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,34 @@ | ||
package com.depromeet.service.greeting; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import com.depromeet.greeting.domain.Greeting; | ||
import com.depromeet.greeting.port.out.AIPort; | ||
import com.depromeet.greeting.port.out.GreetingCachePort; | ||
import com.depromeet.greeting.service.GreetingService; | ||
import com.depromeet.mock.greeting.FakeAIManager; | ||
import com.depromeet.mock.greeting.FakeGreetingCacheManager; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class GreetingServiceTest { | ||
private AIPort aiPort; | ||
private GreetingCachePort greetingCachePort; | ||
private GreetingService greetingService; | ||
|
||
@BeforeEach | ||
void init() { | ||
aiPort = new FakeAIManager(); | ||
greetingCachePort = new FakeGreetingCacheManager(); | ||
greetingService = new GreetingService(aiPort, greetingCachePort); | ||
} | ||
|
||
@Test | ||
public void μΈμΏλ§μ_μ‘°νν©λλ€() throws Exception { | ||
// when | ||
Greeting greeting = greetingService.getGreeting(); | ||
|
||
// then | ||
assertThat(greeting.getMessage()).isEqualTo("Hello, World!"); | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
module-presentation/src/test/java/com/depromeet/greeting/api/GreetingControllerTest.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,25 @@ | ||
package com.depromeet.greeting.api; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
import com.depromeet.config.ControllerTestConfig; | ||
import com.depromeet.config.mock.WithCustomMockMember; | ||
import com.depromeet.greeting.facade.GreetingFacade; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
|
||
@WebMvcTest(GreetingController.class) | ||
public class GreetingControllerTest extends ControllerTestConfig { | ||
@MockBean GreetingFacade greetingFacade; | ||
|
||
@Test | ||
@WithCustomMockMember | ||
public void μΈμΏλ§μ_μ‘°νν©λλ€() throws Exception { | ||
mockMvc.perform(get("/greeting")) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.code").value("GREETING_1")) | ||
.andExpect(jsonPath("$.message").value("μΈμΏλ§ μ‘°νμ μ±κ³΅νμμ΅λλ€")); | ||
} | ||
} |