Commit af60b9d25d73c459e8d93727b5890947b5371796

Authored by Rémi Vangrevelynghe
2 parents fff53c0a b6a31a21

merge updates from prof

1 *.iml 1 *.iml
2 -*/target/ 2 +target/
3 .idea/ 3 .idea/
4 */.idea/ 4 */.idea/
5 /target/ 5 /target/
6 \ No newline at end of file 6 \ No newline at end of file
1 -<project xmlns="http://maven.apache.org/POM/4.0.0"  
2 - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 1 +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2 + xmlns="http://maven.apache.org/POM/4.0.0"
3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
4 http://maven.apache.org/maven-v4_0_0.xsd"> 4 http://maven.apache.org/maven-v4_0_0.xsd">
5 <modelVersion>4.0.0</modelVersion> 5 <modelVersion>4.0.0</modelVersion>
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 <parent> 11 <parent>
12 <groupId>org.springframework.boot</groupId> 12 <groupId>org.springframework.boot</groupId>
13 <artifactId>spring-boot-starter-parent</artifactId> 13 <artifactId>spring-boot-starter-parent</artifactId>
14 - <version>1.3.6.RELEASE</version> 14 + <version>1.4.0.RELEASE</version>
15 </parent> 15 </parent>
16 16
17 <dependencies> 17 <dependencies>
@@ -22,6 +22,7 @@ @@ -22,6 +22,7 @@
22 <dependency> 22 <dependency>
23 <groupId>com.h2database</groupId> 23 <groupId>com.h2database</groupId>
24 <artifactId>h2</artifactId> 24 <artifactId>h2</artifactId>
  25 + <scope>runtime</scope>
25 </dependency> 26 </dependency>
26 <dependency> 27 <dependency>
27 <groupId>org.springframework.boot</groupId> 28 <groupId>org.springframework.boot</groupId>
src/main/java/fr/plil/sio/persistence/jdbc/JdbcApplication.java renamed to src/main/java/fr/plil/sio/persistence/JdbcApplication.java
1 -package fr.plil.sio.persistence.jdbc; 1 +package fr.plil.sio.persistence;
2 2
3 import org.springframework.boot.autoconfigure.SpringBootApplication; 3 import org.springframework.boot.autoconfigure.SpringBootApplication;
4 4
src/main/java/fr/plil/sio/persistence/api/Group.java
@@ -2,9 +2,11 @@ package fr.plil.sio.persistence.api; @@ -2,9 +2,11 @@ package fr.plil.sio.persistence.api;
2 2
3 import java.util.LinkedList; 3 import java.util.LinkedList;
4 import java.util.List; 4 import java.util.List;
5 -import java.util.Set;  
6 -import java.util.TreeSet;  
7 5
  6 +/**
  7 + * A group is unique by its name (no two groups with the same name or the same ID can exist in the database).
  8 + * A group contains a list of rights unique by their ID (no two groups with the same ID can exist in the database).
  9 + */
8 public class Group { 10 public class Group {
9 11
10 private Long id; 12 private Long id;
@@ -14,7 +16,7 @@ public class Group { @@ -14,7 +16,7 @@ public class Group {
14 /** 16 /**
15 * Users in the group. 17 * Users in the group.
16 */ 18 */
17 - private Set<User> users = new TreeSet<>(); 19 + private List<User> users = new LinkedList<>();
18 20
19 /** 21 /**
20 * List of rights. The list CANNOT contains duplicate rights. 22 * List of rights. The list CANNOT contains duplicate rights.
@@ -45,11 +47,11 @@ public class Group { @@ -45,11 +47,11 @@ public class Group {
45 this.name = name; 47 this.name = name;
46 } 48 }
47 49
48 - public Set<User> getUsers() { 50 + public List<User> getUsers() {
49 return users; 51 return users;
50 } 52 }
51 53
52 - public void setUsers(Set<User> users) { 54 + public void setUsers(List<User> users) {
53 this.users = users; 55 this.users = users;
54 } 56 }
55 } 57 }
src/main/java/fr/plil/sio/persistence/api/GroupService.java
@@ -4,7 +4,7 @@ public interface GroupService { @@ -4,7 +4,7 @@ public interface GroupService {
4 4
5 /** 5 /**
6 * Create a group with a specific name in the database. 6 * Create a group with a specific name in the database.
7 - * There is no two groups with the same name in the database. 7 + * There is no two groups with the same name or the same ID in the database.
8 * 8 *
9 * @param name the name of the group 9 * @param name the name of the group
10 * @return an instance of the group 10 * @return an instance of the group
@@ -23,7 +23,8 @@ public interface GroupService { @@ -23,7 +23,8 @@ public interface GroupService {
23 boolean delete(String name); 23 boolean delete(String name);
24 24
25 /** 25 /**
26 - * Find a group in the database based on its name. 26 + * Find a group in the database based on its name. Only references at one level are loaded (i.e. the users
  27 + * who belong to the group).
27 * 28 *
28 * @param name the name of the group to search for. 29 * @param name the name of the group to search for.
29 * @return an instance of the group if found, else null. 30 * @return an instance of the group if found, else null.
@@ -32,7 +33,7 @@ public interface GroupService { @@ -32,7 +33,7 @@ public interface GroupService {
32 Group findByName(String name); 33 Group findByName(String name);
33 34
34 /** 35 /**
35 - * Add a right in the group. Right is inserted at the end of rights list of the group. 36 + * Add a right in the group.
36 * 37 *
37 * @param groupName the name of the group. 38 * @param groupName the name of the group.
38 * @param right the right to add 39 * @param right the right to add
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 java.util.HashSet;  
4 -import java.util.Set;  
5 - 3 +import java.util.LinkedList;
  4 +import java.util.List;
  5 +
  6 +/**
  7 + * A right is unique by itd ID, i.e. it can exist two rights with the same name in the database.
  8 + * A right may have a parent, null else.
  9 + * A right can have zero, one or more siblings.
  10 + */
6 public class Right { 11 public class Right {
7 12
8 private Long id; 13 private Long id;
9 14
10 private String name; 15 private String name;
11 16
12 - /// the parent group 17 + /// the parent right
13 private Right parent; 18 private Right parent;
14 19
15 - /// the sibling group(s), eventually empty  
16 - private Set<Right> siblings = new HashSet<>(); 20 + /// the sibling right(s), eventually empty
  21 + private List<Right> siblings = new LinkedList<>();
17 22
18 - public Set<Right> getSiblings() { 23 + public List<Right> getSiblings() {
19 return siblings; 24 return siblings;
20 } 25 }
21 26
22 - public void setSiblings(Set<Right> siblings) { 27 + public void setSiblings(List<Right> siblings) {
23 this.siblings = siblings; 28 this.siblings = siblings;
24 } 29 }
25 30
src/main/java/fr/plil/sio/persistence/api/RightService.java
@@ -16,6 +16,8 @@ public interface RightService { @@ -16,6 +16,8 @@ public interface RightService {
16 /** 16 /**
17 * Create a sibling right attached to a parent right with a specific name in the database. 17 * Create a sibling right attached to a parent right with a specific name in the database.
18 * It is possible that two rights has the same name. 18 * It is possible that two rights has the same name.
  19 + * Return only the right with the parent in the field parent.
  20 + *
19 * 21 *
20 * @param name the name of the right 22 * @param name the name of the right
21 * @param parent the parent right 23 * @param parent the parent right
@@ -34,6 +36,7 @@ public interface RightService { @@ -34,6 +36,7 @@ public interface RightService {
34 36
35 /** 37 /**
36 * Find a list of rights in the database based on their name. 38 * Find a list of rights in the database based on their name.
  39 + * All dependencies at one-level are loaded, i.e for each right returned the parent and sibling are present.
37 * 40 *
38 * @param name the name of the rights to search for. 41 * @param name the name of the rights to search for.
39 * @return A list of rights, eventually empty. 42 * @return A list of rights, eventually empty.
@@ -43,6 +46,7 @@ public interface RightService { @@ -43,6 +46,7 @@ public interface RightService {
43 46
44 /** 47 /**
45 * Find a right in the database based on its id. 48 * Find a right in the database based on its id.
  49 + * All dependencies at one-level are loaded, i.e the parent and sibling are present.
46 * 50 *
47 * @param id the name of the right to search for. 51 * @param id the name of the right to search for.
48 * @return an instance of the right if found, else null. 52 * @return an instance of the right if found, else null.
src/main/java/fr/plil/sio/persistence/api/User.java
1 package fr.plil.sio.persistence.api; 1 package fr.plil.sio.persistence.api;
2 2
  3 +/**
  4 + * An user MUST have a group in the database.
  5 + * An user is unique by it name, i.e. database cannot contain two user with the same name or the same ID.
  6 + */
3 public class User { 7 public class User {
4 8
5 private Long id; 9 private Long id;
src/test/java/fr/plil/sio/persistence/jdbc/GroupServiceTest.java
@@ -5,13 +5,13 @@ import org.junit.Before; @@ -5,13 +5,13 @@ import org.junit.Before;
5 import org.junit.Test; 5 import org.junit.Test;
6 import org.junit.runner.RunWith; 6 import org.junit.runner.RunWith;
7 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
8 -import org.springframework.boot.test.SpringApplicationConfiguration; 8 +import org.springframework.boot.test.context.SpringBootTest;
9 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 9 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
10 10
11 import static org.junit.Assert.*; 11 import static org.junit.Assert.*;
12 12
13 @RunWith(SpringJUnit4ClassRunner.class) 13 @RunWith(SpringJUnit4ClassRunner.class)
14 -@SpringApplicationConfiguration(classes = JdbcApplication.class) 14 +@SpringBootTest
15 public class GroupServiceTest extends AbstractServiceSupport { 15 public class GroupServiceTest extends AbstractServiceSupport {
16 16
17 @Autowired 17 @Autowired
src/test/java/fr/plil/sio/persistence/jdbc/RightServiceTest.java
@@ -5,13 +5,13 @@ import fr.plil.sio.persistence.api.RightService; @@ -5,13 +5,13 @@ import fr.plil.sio.persistence.api.RightService;
5 import org.junit.Test; 5 import org.junit.Test;
6 import org.junit.runner.RunWith; 6 import org.junit.runner.RunWith;
7 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
8 -import org.springframework.boot.test.SpringApplicationConfiguration; 8 +import org.springframework.boot.test.context.SpringBootTest;
9 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 9 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
10 10
11 import static org.junit.Assert.*; 11 import static org.junit.Assert.*;
12 12
13 @RunWith(SpringJUnit4ClassRunner.class) 13 @RunWith(SpringJUnit4ClassRunner.class)
14 -@SpringApplicationConfiguration(classes = JdbcApplication.class) 14 +@SpringBootTest
15 public class RightServiceTest extends AbstractServiceSupport { 15 public class RightServiceTest extends AbstractServiceSupport {
16 16
17 @Autowired 17 @Autowired
src/test/java/fr/plil/sio/persistence/jdbc/UserServiceTest.java
@@ -5,13 +5,13 @@ import org.junit.Before; @@ -5,13 +5,13 @@ import org.junit.Before;
5 import org.junit.Test; 5 import org.junit.Test;
6 import org.junit.runner.RunWith; 6 import org.junit.runner.RunWith;
7 import org.springframework.beans.factory.annotation.Autowired; 7 import org.springframework.beans.factory.annotation.Autowired;
8 -import org.springframework.boot.test.SpringApplicationConfiguration; 8 +import org.springframework.boot.test.context.SpringBootTest;
9 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 9 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
10 10
11 import static org.junit.Assert.*; 11 import static org.junit.Assert.*;
12 12
13 @RunWith(SpringJUnit4ClassRunner.class) 13 @RunWith(SpringJUnit4ClassRunner.class)
14 -@SpringApplicationConfiguration(classes = JdbcApplication.class) 14 +@SpringBootTest
15 public class UserServiceTest extends AbstractServiceSupport { 15 public class UserServiceTest extends AbstractServiceSupport {
16 16
17 @Autowired 17 @Autowired
@@ -87,16 +87,19 @@ public class UserServiceTest extends AbstractServiceSupport { @@ -87,16 +87,19 @@ public class UserServiceTest extends AbstractServiceSupport {
87 assertNull(userService.findByName(null)); 87 assertNull(userService.findByName(null));
88 } 88 }
89 89
  90 + @Test
90 public void testIsUserHasExactRight() { 91 public void testIsUserHasExactRight() {
91 Right right = rightService.findByName("parent").get(0); 92 Right right = rightService.findByName("parent").get(0);
92 assertTrue(userService.isUserHasRight("user", right)); 93 assertTrue(userService.isUserHasRight("user", right));
93 } 94 }
94 95
  96 + @Test
95 public void testIsUserHasRightByParents() { 97 public void testIsUserHasRightByParents() {
96 Right right = rightService.findByName("sibling").get(0); 98 Right right = rightService.findByName("sibling").get(0);
97 assertTrue(userService.isUserHasRight("user", right)); 99 assertTrue(userService.isUserHasRight("user", right));
98 } 100 }
99 101
  102 + @Test
100 public void testIsUserHasNotTheExactRight() { 103 public void testIsUserHasNotTheExactRight() {
101 Right right = rightService.findByName("not-for-me").get(0); 104 Right right = rightService.findByName("not-for-me").get(0);
102 assertFalse(userService.isUserHasRight("user", right)); 105 assertFalse(userService.isUserHasRight("user", 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.maxActive=300
6 \ No newline at end of file 7 \ No newline at end of file