2017-02-23 66 views
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的測試中寫下什麼來在UserLabel之間加上關係?

回答

相關問題