-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDogServiceTest.java
More file actions
124 lines (111 loc) · 3.98 KB
/
DogServiceTest.java
File metadata and controls
124 lines (111 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package com.fulgent.data;
import com.fulgent.data.repository.entity.DogEntity;
import com.fulgent.data.repository.DogRepository;
import com.fulgent.data.repository.UserFavoritedRepository;
import com.fulgent.data.rest.model.ApplicationMessage;
import com.fulgent.data.rest.model.Dog;
import com.fulgent.data.rest.model.VoteUpDown;
import com.fulgent.data.service.impl.DogServiceImpl;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import java.util.Optional;
// unit testing
@RunWith(SpringRunner.class)
//@SpringBootTest
@DataJpaTest
public class DogServiceTest {
//@Transactional(propagation = Propagation.NOT_SUPPORTED)
@Autowired
private TestEntityManager entityManager;
@Autowired
private DogRepository dogRepository;
@Autowired
private DogServiceImpl dogServiceImpl;
@Autowired
private UserFavoritedRepository dogFavoriteRepository;
@Test
@Ignore
public void contextLoads() {
}
@Test
public void addDogs() {
// given
DogEntity dog = new DogEntity("pug", "http://i.imgur.com/ozJD7SC.png","pug desc");
entityManager.persist(dog);
entityManager.flush();
List<DogEntity> allDogs = dogRepository.findDogsByBreed("pug");
assertThat(allDogs.size()).isEqualTo(1);
}
// //public List<DogEntity> findDogsByBreed(@Param("breed") String breed);
// @Test
// public void whenFindByBreed_thenReturnDogs() {
// // given
// DogEntity dog = new DogEntity("pug", "http://i.imgur.com/ozJD7SC.png","pug desc");
// entityManager.persist(dog);
// entityManager.flush();
//
// // when
// List<Dog> foundDogsList = dogServiceImpl.findDogsByBreed(dog.getBreed());
//
// // then
// assertThat(foundDogsList.get(0).getBreed()).isEqualTo(dog.getBreed());
// }
//
// //public List<DogEntity> findDogsGroupByBreed();
// @Test
// public void whenFindGroupsByBreed_thenReturnDogs() {
// // given
// DogEntity dog1 = new DogEntity("pug", "http://i.imgur.com/ozJD7SC.png","pug desc");
// DogEntity dog2 = new DogEntity("labrador", "http://i.imgur.com/eE29vX4.png","labrador desc");
// entityManager.persist(dog1);
// entityManager.persist(dog2);
// entityManager.flush();
//
// // when
// List<Dog> foundDogsGroups = dogServiceImpl.findDogsGroupByBreed();
//
// // then
// assertThat(foundDogsGroups.size()).isEqualTo(2);
// }
//
// //public DogEntity findDogDetail(@Param("123") long dogId);
// @Test
// public void whenFindDetailById_thenReturnDogs() {
// // given
// DogEntity dog = new DogEntity("pug", "http://i.imgur.com/ozJD7SC.png","TEST");
// long dogId = dog.getDid();
// entityManager.persist(dog);
// entityManager.flush();
//
// // when
// Dog foundDog = dogServiceImpl.findDogDetail(dogId);
//
// // then
// assertThat(foundDog.getDescription()).isEqualTo(dog.getDescription());
// }
//
// //public ApplicationMessage voteUpDown(@RequestBody VoteUpDown voteUpDown);
// @Test
// public void whenVoteUpDown_thenReturnVotes() {
// // given
// DogEntity dog = new DogEntity("pug", "http://i.imgur.com/ozJD7SC.png","TEST");
// long dogId = dog.getDid();
// entityManager.persist(dog);
// entityManager.flush();
//
// VoteUpDown vote = new VoteUpDown("user123", dogId, Boolean.TRUE);
// // when
// String voteDog = dogServiceImpl.voteUpDown(vote);
//
// // then
// assertThat(voteDog.equals("success"));
// }
}