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,8 +3,11 @@ package fr.plil.sio.persistence.api;
3 import javax.persistence.*; 3 import javax.persistence.*;
4 import java.util.LinkedList; 4 import java.util.LinkedList;
5 import java.util.List; 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 @Entity 12 @Entity
10 @Table(name = "GROUP_T") 13 @Table(name = "GROUP_T")
@@ -22,7 +25,7 @@ public class Group { @@ -22,7 +25,7 @@ public class Group {
22 * Users in the group. 25 * Users in the group.
23 */ 26 */
24 @OneToMany(mappedBy = "group") 27 @OneToMany(mappedBy = "group")
25 - private Set<User> users = new TreeSet<>(); 28 + private List<User> users = new LinkedList<>();
26 29
27 /** 30 /**
28 * List of rights. The list CANNOT contains duplicate rights. 31 * List of rights. The list CANNOT contains duplicate rights.
@@ -54,11 +57,11 @@ public class Group { @@ -54,11 +57,11 @@ public class Group {
54 this.name = name; 57 this.name = name;
55 } 58 }
56 59
57 - public Set<User> getUsers() { 60 + public List<User> getUsers() {
58 return users; 61 return users;
59 } 62 }
60 63
61 - public void setUsers(Set<User> users) { 64 + public void setUsers(List<User> users) {
62 this.users = users; 65 this.users = users;
63 } 66 }
64 } 67 }
src/main/java/fr/plil/sio/persistence/api/Right.java
1 package fr.plil.sio.persistence.api; 1 package fr.plil.sio.persistence.api;
2 2
3 import javax.persistence.*; 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 @Entity 13 @Entity
8 @Table(name = "RIGHT_T") 14 @Table(name = "RIGHT_T")
@@ -23,13 +29,13 @@ public class Right { @@ -23,13 +29,13 @@ public class Right {
23 29
24 /// the sibling right(s), eventually empty 30 /// the sibling right(s), eventually empty
25 @OneToMany(mappedBy = "parent") 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 return siblings; 35 return siblings;
30 } 36 }
31 37
32 - public void setSiblings(Set<Right> siblings) { 38 + public void setSiblings(List<Right> siblings) {
33 this.siblings = siblings; 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,6 +2,11 @@ package fr.plil.sio.persistence.api;
2 2
3 import javax.persistence.*; 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 @Entity 10 @Entity
6 @Table(name = "USER_T") 11 @Table(name = "USER_T")
7 public class User { 12 public class User {
src/test/java/fr/plil/sio/persistence/jpa/GroupServiceTest.java
@@ -69,7 +69,7 @@ public class GroupServiceTest { @@ -69,7 +69,7 @@ public class GroupServiceTest {
69 @Test 69 @Test
70 public void deleteGroupDoesDeleteUsers() { 70 public void deleteGroupDoesDeleteUsers() {
71 userService.create("user1", "group"); 71 userService.create("user1", "group");
72 - userService.create("user1", "group"); 72 + userService.create("user2", "group");
73 assertNotNull(userService.findByName("user1")); 73 assertNotNull(userService.findByName("user1"));
74 assertNotNull(userService.findByName("user2")); 74 assertNotNull(userService.findByName("user2"));
75 groupService.delete("group"); 75 groupService.delete("group");
src/test/java/fr/plil/sio/persistence/jpa/RightServiceTest.java
@@ -86,8 +86,8 @@ public class RightServiceTest { @@ -86,8 +86,8 @@ public class RightServiceTest {
86 assertEquals(0, rightService.findByName("parent").size()); 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 Right right = new Right(); 91 Right right = new Right();
92 right.setName("not-a-right"); 92 right.setName("not-a-right");
93 assertFalse(rightService.delete(right)); 93 assertFalse(rightService.delete(right));
src/test/resources/application.properties
1 logging.level.org.springframework=INFO 1 logging.level.org.springframework=INFO
2 logging.level.org.hibernate.SQL=DEBUG 2 logging.level.org.hibernate.SQL=DEBUG
3 logging.level.org.hibernate=INFO 3 logging.level.org.hibernate=INFO
4 -spring.datasource.url=jdbc:h2:mem:persistence;TRACE_LEVEL_FILE=4  
5 \ No newline at end of file 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 \ No newline at end of file 7 \ No newline at end of file