Commit d41edfbc1e4a33c7057aa64979f3d8790c307857

Authored by jcartign
1 parent e5e76a48

Migrate modifications form spring-jdbc

- add javadocs in Group, Right and User
- fixing few mistakes in Group and Right service tests
- update application properties to increase JDBC connection tomcat pool
src/main/java/fr/plil/sio/persistence/api/Group.java
... ... @@ -3,8 +3,11 @@ package fr.plil.sio.persistence.api;
3 3 import javax.persistence.*;
4 4 import java.util.LinkedList;
5 5 import java.util.List;
6   -import java.util.Set;
7   -import java.util.TreeSet;
  6 +
  7 +/**
  8 + * A group is unique by its name (no two groups with the same name or the same ID can exist in the database).
  9 + * A group contains a list of rights unique by their ID (no two groups with the same ID can exist in the database).
  10 + */
8 11  
9 12 @Entity
10 13 @Table(name = "GROUP_T")
... ... @@ -22,7 +25,7 @@ public class Group {
22 25 * Users in the group.
23 26 */
24 27 @OneToMany(mappedBy = "group")
25   - private Set<User> users = new TreeSet<>();
  28 + private List<User> users = new LinkedList<>();
26 29  
27 30 /**
28 31 * List of rights. The list CANNOT contains duplicate rights.
... ... @@ -54,11 +57,11 @@ public class Group {
54 57 this.name = name;
55 58 }
56 59  
57   - public Set<User> getUsers() {
  60 + public List<User> getUsers() {
58 61 return users;
59 62 }
60 63  
61   - public void setUsers(Set<User> users) {
  64 + public void setUsers(List<User> users) {
62 65 this.users = users;
63 66 }
64 67 }
... ...
src/main/java/fr/plil/sio/persistence/api/Right.java
1 1 package fr.plil.sio.persistence.api;
2 2  
3 3 import javax.persistence.*;
4   -import java.util.HashSet;
5   -import java.util.Set;
  4 +import java.util.LinkedList;
  5 +import java.util.List;
  6 +
  7 +/**
  8 + * A right is unique by itd ID, i.e. it can exist two rights with the same name in the database.
  9 + * A right may have a parent, null else.
  10 + * A right can have zero, one or more siblings.
  11 + */
6 12  
7 13 @Entity
8 14 @Table(name = "RIGHT_T")
... ... @@ -23,13 +29,13 @@ public class Right {
23 29  
24 30 /// the sibling right(s), eventually empty
25 31 @OneToMany(mappedBy = "parent")
26   - private Set<Right> siblings = new HashSet<>();
  32 + private List<Right> siblings = new LinkedList<>();
27 33  
28   - public Set<Right> getSiblings() {
  34 + public List<Right> getSiblings() {
29 35 return siblings;
30 36 }
31 37  
32   - public void setSiblings(Set<Right> siblings) {
  38 + public void setSiblings(List<Right> siblings) {
33 39 this.siblings = siblings;
34 40 }
35 41  
... ...
src/main/java/fr/plil/sio/persistence/api/User.java
... ... @@ -2,6 +2,11 @@ package fr.plil.sio.persistence.api;
2 2  
3 3 import javax.persistence.*;
4 4  
  5 +/**
  6 + * An user MUST have a group in the database.
  7 + * An user is unique by it name, i.e. database cannot contain two user with the same name or the same ID.
  8 + */
  9 +
5 10 @Entity
6 11 @Table(name = "USER_T")
7 12 public class User {
... ...
src/test/java/fr/plil/sio/persistence/jpa/GroupServiceTest.java
... ... @@ -69,7 +69,7 @@ public class GroupServiceTest {
69 69 @Test
70 70 public void deleteGroupDoesDeleteUsers() {
71 71 userService.create("user1", "group");
72   - userService.create("user1", "group");
  72 + userService.create("user2", "group");
73 73 assertNotNull(userService.findByName("user1"));
74 74 assertNotNull(userService.findByName("user2"));
75 75 groupService.delete("group");
... ...
src/test/java/fr/plil/sio/persistence/jpa/RightServiceTest.java
... ... @@ -86,8 +86,8 @@ public class RightServiceTest {
86 86 assertEquals(0, rightService.findByName("parent").size());
87 87 }
88 88  
89   - @Test
90   - public void testDeleteRightIfNotFound() {
  89 + @Test(expected = IllegalArgumentException.class)
  90 + public void testDeleteRightIfNotInDatabase() {
91 91 Right right = new Right();
92 92 right.setName("not-a-right");
93 93 assertFalse(rightService.delete(right));
... ...
src/test/resources/application.properties
1 1 logging.level.org.springframework=INFO
2 2 logging.level.org.hibernate.SQL=DEBUG
3 3 logging.level.org.hibernate=INFO
4   -spring.datasource.url=jdbc:h2:mem:persistence;TRACE_LEVEL_FILE=4
5 4 \ No newline at end of file
  5 +spring.datasource.url=jdbc:h2:mem:persistence;TRACE_LEVEL_FILE=4;
  6 +spring.datasource.tomcat.max-active=300
6 7 \ No newline at end of file
... ...