1
我正在寫簡單的彈簧啓動應用程序,並且想要測試它。我有User
類:如何使用MockMvc更新具有多對多關係的實體?
@Entity
@Table(name = "users")
@NoArgsConstructor
@AllArgsConstructor
public class User extends AbstractEntity {
public enum Type {
ADMIN, USER
}
@Getter
@Setter
private Type type;
@Getter
@Setter
private String username;
@Getter
@Setter
private String password;
@ManyToMany(mappedBy = "managers")
@Getter
@Setter
private Set<Label> label;
}
而且Label
類(認爲它是一個組織,其中User
作品):
@Entity
@Table(name = "labels")
@NoArgsConstructor
@AllArgsConstructor
public class Label extends AbstractEntity {
@Getter
@Setter
private String title;
@OneToOne
@Getter
@Setter
private User creator;
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "label_managers")
@Getter
@Setter
private Set<User> managers;
}
這些實體被@RepositoryRestResource
管理型。
我應該在MockMvc
的測試中寫下什麼來在User
和Label
之間加上關係?