-
-
Save okihouse/f5e2fe8fa4c17d6a6be9 to your computer and use it in GitHub Desktop.
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
@RunWith(SpringJUnit4ClassRunner.class) | |
@SpringApplicationConfiguration(classes = Application.class) | |
@WebAppConfiguration | |
@IntegrationTest("server.port:0") | |
public class UserTest { | |
@Autowired | |
private WebApplicationContext webApplicationContext; | |
@Autowired | |
private UserRepository userRepository; | |
@Autowired | |
private UserInfoRepository userInfoRepository; | |
private MockMvc mockMvc; | |
@Before | |
public void before(){ | |
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.webApplicationContext).build(); | |
} | |
@Test | |
public void test() throws Exception { | |
// create temporary user for test. | |
User user = new User(); | |
user.setType(Type.User); | |
UserInfo userInfo = new UserInfo(); | |
userInfo.setEmail("temporary_user@test.com"); | |
userInfo.setUser(user); | |
user.setUserInfo(userInfo); | |
// persist | |
userRepository.save(user); | |
// request post | |
mockMvc.perform( | |
post("/user") | |
.param("email", "temporary_user@test.com") | |
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) | |
.andDo(print()); | |
} | |
} |
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
@Entity | |
@Table(name = "USER") | |
@Data | |
public class User { | |
@Id | |
@GeneratedValue(strategy = GenerationType.IDENTITY) | |
@Column(name = "UNO") | |
private Long userNo; | |
@Column(name = "USER_TYPE") | |
@Enumerated(EnumType.STRING) | |
private USER_TYPE type; | |
@OneToOne(mappedBy = "user", cascade = CascadeType.ALL) | |
private UserInfo userInfo; | |
} |
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
@Entity | |
@Table(name = "USER_INFO") | |
@Data | |
public class UserInfo { | |
@Id | |
private Long userNo; | |
@Column(name = "EMAIL") | |
private String email; | |
@MapsId | |
@OneToOne(cascade = CascadeType.ALL) | |
@JoinColumn(name = "UNO") | |
private User user; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment