ν μ€νΈ μ½λλ λ¨μ κΈ°λ₯μ΄ μ λλ‘ μλλλμ§ νμΈνκΈ° μν΄ μμ±νλ€.
ν μ€νΈ μ½λμλ μ€ν λ¨κ³, κ²μ¦ λ¨κ³κ° μλ€.
μ€ν λ¨κ³μ κ²°κ³Όλ₯Ό actual μΈμμ λ£κ³ λΉκ΅ λ‘μ§(matcher)λ₯Ό λ£μ΄μ κ²μ¦ λ¨κ³μμ μ€ν λ¨κ³κ° μμν λλ‘, κ°λ°μκ° μκ°ν λλ‘ λμνλμ§ κ²μ¦νλ€.
μ€νλ§ κΈ°μ€μΌλ‘ ν μ€νΈ μ½λλ₯Ό μμ±νμ¬ κ²μ¦νλ κ³Όμ μ μμ±ν΄λ³΄μλ€.
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<version>3.3.0</version>
<scope>test</scope>
</dependency>
@Repository
public interface UserRepository extends MongoRepository<User, String>, CrudRepository<User, String>{
Optional<User> findByNickname(String nickname);
Optional<User> findByIdAndPassword(String id, String password);
}
package org.smu.blood;
import static org.junit.Assert.assertEquals;
import java.util.Optional;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.smu.blood.database.User;
import org.smu.blood.database.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@EnableMongoRepositories
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations= {"file:src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml"})
@Rollback(value = true)
public class UserRepositoryTest {
@Autowired
private UserRepository repository;
@Test
public void existsByNicknameTest() {
User createUser = repository.insert(new User("asdf@naver.com", "qwe123", "asdf", 1, false));
Optional<User> result = repository.findByNickname(createUser.getNickname());
assertEquals(result.equals(Optional.empty()), false);
}
}
package org.smu.blood;
import static org.junit.Assert.*;
import java.util.Optional;
import org.junit.Test;
import org.junit.jupiter.api.DisplayName;
import org.junit.runner.RunWith;
import org.smu.blood.database.User;
import org.smu.blood.database.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@EnableMongoRepositories
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations= {"file:src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml"})
@Rollback(value = true)
public class SignUpTest{
@Autowired
private UserRepository repository;
//private static final Logger logger = LoggerFactory.getLogger(SignUpTest.class);
@Test
@DisplayName("Same id user test")
public void CheckSameId() {
repository.insert(new User("koharin@naver.com", "qwe123", "koharin", 1, false));
User newUser = new User("koharin@naver.com", "qwerty", "asdf", 2, true);
Optional<User> userById = repository.findById(newUser.getId());
assertEquals(userById.equals(Optional.empty()), false);
}
@Test
@DisplayName("Same nickname user test")
public void CheckSameNickname() {
repository.insert(new User("qwe@naver.com", "qwe123", "qwe", 1, false));
User newUser = new User("asdf@naver.com", "qwerty", "qwe", 2, true);
Optional<User> userByNickname = repository.findByNickname(newUser.getNickname());
assertEquals(userByNickname.equals(Optional.empty()), false);
}
}
AWS EC2μ Spring μλ² λ°°ν¬ (1) | 2022.03.04 |
---|---|
[Spring] JWT Token μ¬μ©νκΈ° (0) | 2022.02.27 |
[Spring] μλ΅ λ¬Έμμ΄ νκΈ κΉ¨μ§ λ¬Έμ ν΄κ²° (0) | 2022.02.16 |
JWT (JSON Web Token) (0) | 2022.01.28 |
[Spring] Android, Spring μ°λ (retrofit2) (1) | 2022.01.24 |