Skip to content

Commit eaaa3e0

Browse files
committed
Integration test is added but unit tests are broken.
1 parent fd803ea commit eaaa3e0

File tree

5 files changed

+49
-4
lines changed

5 files changed

+49
-4
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
<groupId>org.springframework.boot</groupId>
4343
<artifactId>spring-boot-starter-data-mongodb</artifactId>
4444
</dependency>
45+
<dependency>
46+
<groupId>de.flapdoodle.embed</groupId>
47+
<artifactId>de.flapdoodle.embed.mongo</artifactId>
48+
<scope>test</scope>
49+
</dependency>
4550
</dependencies>
4651

4752
<build>

src/main/resources/application.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ server:
33
spring:
44
data:
55
mongodb:
6-
host: localhost
6+
host: mongo1
77
port: 27017
88
database: recom-engine
99
kafka:
1010
template:
1111
default-topic: reviews
1212
producer:
13-
bootstrap-servers: localhost:9092
13+
bootstrap-servers: kafka1:19092
1414
key-serializer: org.apache.kafka.common.serialization.StringSerializer
1515
value-serializer: org.apache.kafka.common.serialization.StringSerializer
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.trendyol.recomengine.webservice.controller;
2+
3+
import com.trendyol.recomengine.webservice.model.Recommendation;
4+
import com.trendyol.recomengine.webservice.repository.RecommendationRepository;
5+
import com.trendyol.recomengine.webservice.service.RecommendationService;
6+
import org.junit.Test;
7+
import org.junit.runner.RunWith;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.boot.test.context.SpringBootTest;
10+
import org.springframework.test.context.ContextConfiguration;
11+
import org.springframework.test.context.junit4.SpringRunner;
12+
import org.springframework.test.context.support.AnnotationConfigContextLoader;
13+
14+
import static org.assertj.core.api.Assertions.assertThat;
15+
16+
@RunWith(SpringRunner.class)
17+
@SpringBootTest
18+
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
19+
public class RecommendationControllerIntegrationTests {
20+
@Autowired
21+
RecommendationRepository recommendationRepository;
22+
23+
@Autowired
24+
RecommendationService recommendationService;
25+
26+
@Test
27+
public void contextLoad() {
28+
29+
}
30+
31+
@Test
32+
public void givenUserObject_whenSave_thenCreateNewUser() {
33+
String userId = "3";
34+
String recommendations[] = new String[] {"1","2","3","4","5","6","7","8","9","10"};
35+
36+
Recommendation recommendation = new Recommendation(userId, recommendations);
37+
recommendationRepository.save(recommendation);
38+
assert(recommendationService.getRecommendations(userId).get_id().equals(userId));
39+
}
40+
}

src/test/java/com/trendyol/recomengine/webservice/controller/RecommendationControllerTests.java renamed to src/test/java/com/trendyol/recomengine/webservice/controller/RecommendationControllerUnitTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
@RunWith(SpringRunner.class)
2323
@SpringBootTest
2424
@AutoConfigureMockMvc
25-
public class RecommendationControllerTests {
25+
public class RecommendationControllerUnitTests {
2626

2727
@Autowired
2828
private MockMvc mockMvc;

src/test/java/com/trendyol/recomengine/webservice/controller/ReviewControllerTests.java renamed to src/test/java/com/trendyol/recomengine/webservice/controller/ReviewControllerUnitTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
@RunWith(SpringRunner.class)
2929
@SpringBootTest
3030
@AutoConfigureMockMvc
31-
public class ReviewControllerTests {
31+
public class ReviewControllerUnitTests {
3232

3333
@Autowired
3434
private MockMvc mockMvc;

0 commit comments

Comments
 (0)