1

I am writing simple spring-boot app and want to test it. I have User class:

@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;
}

And Label class (consider it's an organization, where User works):

@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;
}

Those entities are managed by @RepositoryRestResources.

What should I write in my test with MockMvc to add relation between a User and a Label?

Leonid Bor
  • 2,064
  • 6
  • 27
  • 47

1 Answers1

0

"By using "Content-Type: text/uri-list" instead of JSON, it is possible to "add" a resource to the collection with a PUT and pass in the URI. You can remove the resource with a DELETE."

Review the answer to the following question: How to add elements in a many-to-many relationship via Spring's @RepositoryRestResource REST API?

Ilya Zinkovich
  • 4,082
  • 4
  • 25
  • 43