두 가지 클래스가 있습니다. 소프트웨어, 태그 - ManyToMany와 관련이 있습니다. 우리는 태그를 넣지 않고 소프트웨어를 만들 수 없습니다.무수히 많은 것을 보존하고 무결성을 보존 할 때
@Test public void createSoftwareWithNullTags() {
List<Tag> tags = null;
Software software = new Software("software1", "description1", tags);
try {
software.save();
fail("tags should not be null");
} catch (Exception ex) {
// NEVER COME HERE !!!
}
}
그래서,이 테스트가 실패 :
나는 확인 테스트를 작성하고자합니다. 나는 그것이 SOFTWARE_TAG 테이블에 데이터를 저장하려고 시도하지 않기 때문에 그 경우에는 좋은 테스트가 아닐 것이라고 생각한다. 물론 수동으로 유효성 검사를 할 수 있지만 일부 주석이나 무언가를 사용하여 최대 절전 모드로 구현하고 싶습니다. 가능한가? 아니면 어떻게할까요?
내 엔티티 :
@Entity public class Tag extends Model {
public String title;
public Tag(String title) {
this.title = title;
}
@ManyToMany(
cascade = {CascadeType.ALL},
mappedBy = "tags",
targetEntity = Software.class
)
public List<Software> softwares;
}
@Entity public class Software extends Model {
public String title;
public String description;
@ManyToOne(optional = false)
public Author author;
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(
name = "SOFTWARE_TAG",
joinColumns = @JoinColumn(name = "Software_id"),
inverseJoinColumns = @JoinColumn(name = "Tag_id")
)
public List<Tag> tags;
public Software(String title, String description, Author author, List<Tag> tags) {
this.title = title;
this.description = description;
this.author = author;
this.tags = tags;
}
}
플레이 프레임 워크는 임베디드 된 최대 절전 모드를 사용하므로 어떤 버전의 유효성 검사 프레임 워크를 사용해야하는지 생각해야하므로 추가 프레임 워크를 사용하고 싶지 않습니다. 하지만 그것은 문제가되지 않을 수도 있습니다 ... 그리고 나는 어디에 넣어야하는지 모르겠다. – ses