findUserById(Integer id) {
+ log.info("User with id: " + id + " retrieved from database");
+ return userRepository.findById(id);
+ }
+
+ public User saveUser(User user) {
+ log.info("User: " + user.toString() + " saved in database");
+ return userRepository.save(user);
+ }
+
+ public void deleteUser(User user) {
+ log.info("User: " + user.toString() + " deleted in database");
+ userRepository.delete(user);;
+ }
+}
diff --git a/Poseiden-skeleton/src/main/resources/application.properties b/Poseiden-skeleton/src/main/resources/application.properties
index 8b194cc76e..4ab59c6298 100644
--- a/Poseiden-skeleton/src/main/resources/application.properties
+++ b/Poseiden-skeleton/src/main/resources/application.properties
@@ -1,14 +1,23 @@
+######################### Log Configuration ##########################
logging.level.org.springframework=INFO
+logging.level.root=error
+logging.level.com.nnk=info
################### DataSource Configuration ##########################
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
-spring.datasource.url=jdbc:mysql://localhost:3306/demo
+spring.datasource.url=jdbc:mysql://localhost:3306/demo?allowPublicKeyRetrieval=true&useSSL=false
spring.datasource.username=root
-spring.datasource.password=
+spring.datasource.password=rootroot
################### Hibernate Configuration ##########################
+spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
+spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
+################ Spring Security oauth2 Configuration ################
+
+spring.security.oauth2.client.registration.github.client-id=202d8986dff4305d54d0
+spring.security.oauth2.client.registration.github.client-secret=43c832c0613d3d259572f890cce88e4b1329f852
\ No newline at end of file
diff --git a/Poseiden-skeleton/src/main/resources/logback.xml b/Poseiden-skeleton/src/main/resources/logback.xml
new file mode 100644
index 0000000000..5f2bead19d
--- /dev/null
+++ b/Poseiden-skeleton/src/main/resources/logback.xml
@@ -0,0 +1,14 @@
+
+
+
+ src/main/resources/logsfile.log
+ true
+
+ %d [%thread] %-5level %logger{35} - %msg%n
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Poseiden-skeleton/src/main/resources/templates/403.html b/Poseiden-skeleton/src/main/resources/templates/403.html
index c0c3740bd2..4301003e80 100644
--- a/Poseiden-skeleton/src/main/resources/templates/403.html
+++ b/Poseiden-skeleton/src/main/resources/templates/403.html
@@ -6,8 +6,8 @@
Access Denied Exception
- Logged in user: [[${#httpServletRequest.remoteUser}]]
-
diff --git a/Poseiden-skeleton/src/main/resources/templates/bidList/add.html b/Poseiden-skeleton/src/main/resources/templates/bidList/add.html
index c0fb91a99e..4506b8249b 100644
--- a/Poseiden-skeleton/src/main/resources/templates/bidList/add.html
+++ b/Poseiden-skeleton/src/main/resources/templates/bidList/add.html
@@ -1,26 +1,74 @@
-
+
-
+
Home
-
+
-
+
-
-
Add New Bid
-
+
+
+
-
\ No newline at end of file
diff --git a/Poseiden-skeleton/src/main/resources/templates/bidList/list.html b/Poseiden-skeleton/src/main/resources/templates/bidList/list.html
index 84a1d14a12..b94a16d443 100644
--- a/Poseiden-skeleton/src/main/resources/templates/bidList/list.html
+++ b/Poseiden-skeleton/src/main/resources/templates/bidList/list.html
@@ -17,8 +17,8 @@
Rule
- Logged in user: [[${#httpServletRequest.remoteUser}]]
-
+ Logged in user: [[${#httpServletRequest.getUserPrincipal().getName()}]]
+
@@ -37,7 +37,16 @@
-
+
+ Id
+
+
+
+
+ Edit |
+ Delete
+
+
diff --git a/Poseiden-skeleton/src/main/resources/templates/bidList/update.html b/Poseiden-skeleton/src/main/resources/templates/bidList/update.html
index 7786ebd1ff..f439b83783 100644
--- a/Poseiden-skeleton/src/main/resources/templates/bidList/update.html
+++ b/Poseiden-skeleton/src/main/resources/templates/bidList/update.html
@@ -8,18 +8,62 @@
-
+
\ No newline at end of file
diff --git a/Poseiden-skeleton/src/main/resources/templates/curvePoint/add.html b/Poseiden-skeleton/src/main/resources/templates/curvePoint/add.html
index 28d17cb645..a25b3ed379 100644
--- a/Poseiden-skeleton/src/main/resources/templates/curvePoint/add.html
+++ b/Poseiden-skeleton/src/main/resources/templates/curvePoint/add.html
@@ -1,27 +1,70 @@
-
+
-
+
Home
-
+
-
+
-
-
Add New Curve Point
-
+
+
+
Add New Curve Point
+
+
-
+
+
+
\ No newline at end of file
diff --git a/Poseiden-skeleton/src/main/resources/templates/curvePoint/list.html b/Poseiden-skeleton/src/main/resources/templates/curvePoint/list.html
index 469836149b..2d736a52ae 100644
--- a/Poseiden-skeleton/src/main/resources/templates/curvePoint/list.html
+++ b/Poseiden-skeleton/src/main/resources/templates/curvePoint/list.html
@@ -17,8 +17,8 @@
Rule
- Logged in user: [[${#httpServletRequest.remoteUser}]]
-
+ Logged in user: [[${#httpServletRequest.getUserPrincipal().getName()}]]
+
@@ -37,6 +37,17 @@
+
+
+
+
+
+
+ Edit |
+ Delete
+
+
+
diff --git a/Poseiden-skeleton/src/main/resources/templates/curvePoint/update.html b/Poseiden-skeleton/src/main/resources/templates/curvePoint/update.html
index e7f5a0d330..21c7520a88 100644
--- a/Poseiden-skeleton/src/main/resources/templates/curvePoint/update.html
+++ b/Poseiden-skeleton/src/main/resources/templates/curvePoint/update.html
@@ -9,15 +9,55 @@
diff --git a/Poseiden-skeleton/src/main/resources/templates/rating/add.html b/Poseiden-skeleton/src/main/resources/templates/rating/add.html
index 8090e5382e..527258fdc4 100644
--- a/Poseiden-skeleton/src/main/resources/templates/rating/add.html
+++ b/Poseiden-skeleton/src/main/resources/templates/rating/add.html
@@ -1,27 +1,83 @@
-
+
-
+
Home
-
+
-
+
-
-
Add New Rating
-
+
+
+
+
+
\ No newline at end of file
diff --git a/Poseiden-skeleton/src/main/resources/templates/rating/list.html b/Poseiden-skeleton/src/main/resources/templates/rating/list.html
index bfbb403b84..49d0457bcd 100644
--- a/Poseiden-skeleton/src/main/resources/templates/rating/list.html
+++ b/Poseiden-skeleton/src/main/resources/templates/rating/list.html
@@ -17,8 +17,8 @@
Rule
- Logged in user: [[${#httpServletRequest.remoteUser}]]
-
+ Logged in user: [[${#httpServletRequest.getUserPrincipal().getName()}]]
+
@@ -38,7 +38,17 @@
-
+
+
+
+
+
+
+
+ Edit |
+ Delete
+
+
diff --git a/Poseiden-skeleton/src/main/resources/templates/rating/update.html b/Poseiden-skeleton/src/main/resources/templates/rating/update.html
index 1e1914100a..a812483595 100644
--- a/Poseiden-skeleton/src/main/resources/templates/rating/update.html
+++ b/Poseiden-skeleton/src/main/resources/templates/rating/update.html
@@ -1,26 +1,81 @@
+ xmlns:th="http://www.thymeleaf.org">
-
- Home
-
+
+Home
+
-
+
+
+
+
+
+
+
+
+ FitchRating
-
+
+
+
+
FitchRating error
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Poseiden-skeleton/src/main/resources/templates/ruleName/add.html b/Poseiden-skeleton/src/main/resources/templates/ruleName/add.html
index afb0c2730b..f085c22603 100644
--- a/Poseiden-skeleton/src/main/resources/templates/ruleName/add.html
+++ b/Poseiden-skeleton/src/main/resources/templates/ruleName/add.html
@@ -1,27 +1,101 @@
-
+
-
+
Home
-
+
-
+
-
-
Add New Rule
-
+
+
+
+
+
+
+
+
+ template
-
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Poseiden-skeleton/src/main/resources/templates/ruleName/list.html b/Poseiden-skeleton/src/main/resources/templates/ruleName/list.html
index 2ad3868e82..49078f2e60 100644
--- a/Poseiden-skeleton/src/main/resources/templates/ruleName/list.html
+++ b/Poseiden-skeleton/src/main/resources/templates/ruleName/list.html
@@ -17,8 +17,8 @@
Rule
- Logged in user: [[${#httpServletRequest.remoteUser}]]
-
+ Logged in user: [[${#httpServletRequest.getUserPrincipal().getName()}]]
+
@@ -40,7 +40,19 @@
-
+
+
+
+
+
+
+
+
+
+ Edit |
+ Delete
+
+
diff --git a/Poseiden-skeleton/src/main/resources/templates/ruleName/update.html b/Poseiden-skeleton/src/main/resources/templates/ruleName/update.html
index 34e6c3cc60..f6d1bf1e5f 100644
--- a/Poseiden-skeleton/src/main/resources/templates/ruleName/update.html
+++ b/Poseiden-skeleton/src/main/resources/templates/ruleName/update.html
@@ -1,27 +1,103 @@
+ xmlns:th="http://www.thymeleaf.org">
-
- Home
-
+
+Home
+
-
+
-
-
Update New Rule
-
+
+
+
+
\ No newline at end of file
diff --git a/Poseiden-skeleton/src/main/resources/templates/trade/add.html b/Poseiden-skeleton/src/main/resources/templates/trade/add.html
index 6fafa08c01..1b7cc9a99f 100644
--- a/Poseiden-skeleton/src/main/resources/templates/trade/add.html
+++ b/Poseiden-skeleton/src/main/resources/templates/trade/add.html
@@ -1,27 +1,69 @@
-
+
-
+
Home
-
+
-
+
-
-
Add New Trade
-
+
+
+
+
\ No newline at end of file
diff --git a/Poseiden-skeleton/src/main/resources/templates/trade/list.html b/Poseiden-skeleton/src/main/resources/templates/trade/list.html
index 2a247fa7da..35e1617fca 100644
--- a/Poseiden-skeleton/src/main/resources/templates/trade/list.html
+++ b/Poseiden-skeleton/src/main/resources/templates/trade/list.html
@@ -1,46 +1,56 @@
-
+
-
+
Home
-
+
-
-
-
-
Bid List |
-
Curve Points |
-
Ratings |
-
Trade |
-
Rule
+
+
+
+
+ Logged in user:
+ [[${#httpServletRequest.getUserPrincipal().getName()}]]
+
+
+
+
-
- Logged in user:
[[${#httpServletRequest.remoteUser}]]
-
-
-
+
+
Trade List
+
+
+
Add New
+
+
+
+ Id
+ Account
+ Type
+ Buy Quantity
+ Action
+
+
+
+
+ Id
+
+
+
+ Edit |
+ Delete
+
+
+
+
-
Trade List
-
-
Add New
-
-
-
- Id
- Account
- Type
- Buy Quantity
- Action
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Poseiden-skeleton/src/main/resources/templates/trade/update.html b/Poseiden-skeleton/src/main/resources/templates/trade/update.html
index f4bbc52592..f9957b7728 100644
--- a/Poseiden-skeleton/src/main/resources/templates/trade/update.html
+++ b/Poseiden-skeleton/src/main/resources/templates/trade/update.html
@@ -1,25 +1,71 @@
-
+
-
+
Home
-
+
-
\ No newline at end of file
diff --git a/Poseiden-skeleton/src/main/resources/templates/user/add.html b/Poseiden-skeleton/src/main/resources/templates/user/add.html
index 09246f49b2..1218791adf 100644
--- a/Poseiden-skeleton/src/main/resources/templates/user/add.html
+++ b/Poseiden-skeleton/src/main/resources/templates/user/add.html
@@ -1,61 +1,75 @@
-
+
-
+
Home
-
+
-
+
-
-
Add New User
-
-
-
\ No newline at end of file
diff --git a/Poseiden-skeleton/src/main/resources/templates/user/update.html b/Poseiden-skeleton/src/main/resources/templates/user/update.html
index 0322cfdf39..deb12c428b 100644
--- a/Poseiden-skeleton/src/main/resources/templates/user/update.html
+++ b/Poseiden-skeleton/src/main/resources/templates/user/update.html
@@ -1,61 +1,75 @@
+ xmlns:th="http://www.thymeleaf.org">
-
-
Home
-
+
+
Home
+
-
+
-
-
Update User
-
-
-
\ No newline at end of file
diff --git a/Poseiden-skeleton/src/test/java/com/nnk/springboot/BidTests.java b/Poseiden-skeleton/src/test/java/com/nnk/springboot/BidTests.java
index f1a4f40316..2150bb2323 100644
--- a/Poseiden-skeleton/src/test/java/com/nnk/springboot/BidTests.java
+++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/BidTests.java
@@ -1,7 +1,9 @@
package com.nnk.springboot;
import com.nnk.springboot.domain.BidList;
-import com.nnk.springboot.repositories.BidListRepository;
+import com.nnk.springboot.services.BidListService;
+
+import org.assertj.core.util.Lists;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -17,30 +19,30 @@
public class BidTests {
@Autowired
- private BidListRepository bidListRepository;
+ private BidListService bidListService;
@Test
public void bidListTest() {
BidList bid = new BidList("Account Test", "Type Test", 10d);
// Save
- bid = bidListRepository.save(bid);
+ bid = bidListService.saveBidList(bid);
Assert.assertNotNull(bid.getBidListId());
Assert.assertEquals(bid.getBidQuantity(), 10d, 10d);
// Update
bid.setBidQuantity(20d);
- bid = bidListRepository.save(bid);
+ bid = bidListService.saveBidList(bid);
Assert.assertEquals(bid.getBidQuantity(), 20d, 20d);
// Find
- List
listResult = bidListRepository.findAll();
+ List listResult = Lists.newArrayList(bidListService.findAllBidLists());
Assert.assertTrue(listResult.size() > 0);
// Delete
Integer id = bid.getBidListId();
- bidListRepository.delete(bid);
- Optional bidList = bidListRepository.findById(id);
+ bidListService.deleteBidList(bid);
+ Optional bidList = bidListService.findBidListById(id);
Assert.assertFalse(bidList.isPresent());
}
}
diff --git a/Poseiden-skeleton/src/test/java/com/nnk/springboot/CurvePointTests.java b/Poseiden-skeleton/src/test/java/com/nnk/springboot/CurvePointTests.java
index 854615c0a0..6bd24803ec 100644
--- a/Poseiden-skeleton/src/test/java/com/nnk/springboot/CurvePointTests.java
+++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/CurvePointTests.java
@@ -1,7 +1,9 @@
package com.nnk.springboot;
import com.nnk.springboot.domain.CurvePoint;
-import com.nnk.springboot.repositories.CurvePointRepository;
+import com.nnk.springboot.services.CurvePointService;
+
+import org.assertj.core.util.Lists;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -17,30 +19,30 @@
public class CurvePointTests {
@Autowired
- private CurvePointRepository curvePointRepository;
+ private CurvePointService curvePointService;
@Test
public void curvePointTest() {
CurvePoint curvePoint = new CurvePoint(10, 10d, 30d);
// Save
- curvePoint = curvePointRepository.save(curvePoint);
+ curvePoint = curvePointService.saveCurvePoint(curvePoint);
Assert.assertNotNull(curvePoint.getId());
Assert.assertTrue(curvePoint.getCurveId() == 10);
// Update
curvePoint.setCurveId(20);
- curvePoint = curvePointRepository.save(curvePoint);
+ curvePoint = curvePointService.saveCurvePoint(curvePoint);
Assert.assertTrue(curvePoint.getCurveId() == 20);
// Find
- List listResult = curvePointRepository.findAll();
+ List listResult = Lists.newArrayList(curvePointService.findAllCurvePoints());
Assert.assertTrue(listResult.size() > 0);
// Delete
Integer id = curvePoint.getId();
- curvePointRepository.delete(curvePoint);
- Optional curvePointList = curvePointRepository.findById(id);
+ curvePointService.deleteCurvePoint(curvePoint);
+ Optional curvePointList = curvePointService.findCurvePointById(id);
Assert.assertFalse(curvePointList.isPresent());
}
diff --git a/Poseiden-skeleton/src/test/java/com/nnk/springboot/RatingTests.java b/Poseiden-skeleton/src/test/java/com/nnk/springboot/RatingTests.java
index 6c3ebf0b08..6282a4e26d 100644
--- a/Poseiden-skeleton/src/test/java/com/nnk/springboot/RatingTests.java
+++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/RatingTests.java
@@ -1,7 +1,9 @@
package com.nnk.springboot;
import com.nnk.springboot.domain.Rating;
-import com.nnk.springboot.repositories.RatingRepository;
+import com.nnk.springboot.services.RatingService;
+
+import org.assertj.core.util.Lists;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -17,30 +19,30 @@
public class RatingTests {
@Autowired
- private RatingRepository ratingRepository;
+ private RatingService ratingService;
@Test
public void ratingTest() {
Rating rating = new Rating("Moodys Rating", "Sand PRating", "Fitch Rating", 10);
// Save
- rating = ratingRepository.save(rating);
+ rating = ratingService.saveRating(rating);
Assert.assertNotNull(rating.getId());
Assert.assertTrue(rating.getOrderNumber() == 10);
// Update
rating.setOrderNumber(20);
- rating = ratingRepository.save(rating);
+ rating = ratingService.saveRating(rating);
Assert.assertTrue(rating.getOrderNumber() == 20);
// Find
- List listResult = ratingRepository.findAll();
+ List listResult = Lists.newArrayList(ratingService.findAllRatings());
Assert.assertTrue(listResult.size() > 0);
// Delete
Integer id = rating.getId();
- ratingRepository.delete(rating);
- Optional ratingList = ratingRepository.findById(id);
+ ratingService.deleteRating(rating);
+ Optional ratingList = ratingService.findRatingById(id);
Assert.assertFalse(ratingList.isPresent());
}
}
diff --git a/Poseiden-skeleton/src/test/java/com/nnk/springboot/RuleTests.java b/Poseiden-skeleton/src/test/java/com/nnk/springboot/RuleTests.java
index 541dab5412..a45565beed 100644
--- a/Poseiden-skeleton/src/test/java/com/nnk/springboot/RuleTests.java
+++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/RuleTests.java
@@ -1,7 +1,9 @@
package com.nnk.springboot;
import com.nnk.springboot.domain.RuleName;
-import com.nnk.springboot.repositories.RuleNameRepository;
+import com.nnk.springboot.services.RuleNameService;
+
+import org.assertj.core.util.Lists;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -17,30 +19,30 @@
public class RuleTests {
@Autowired
- private RuleNameRepository ruleNameRepository;
+ private RuleNameService ruleNameService;
@Test
public void ruleTest() {
RuleName rule = new RuleName("Rule Name", "Description", "Json", "Template", "SQL", "SQL Part");
// Save
- rule = ruleNameRepository.save(rule);
+ rule = ruleNameService.saveRuleName(rule);
Assert.assertNotNull(rule.getId());
Assert.assertTrue(rule.getName().equals("Rule Name"));
// Update
rule.setName("Rule Name Update");
- rule = ruleNameRepository.save(rule);
+ rule = ruleNameService.saveRuleName(rule);
Assert.assertTrue(rule.getName().equals("Rule Name Update"));
// Find
- List listResult = ruleNameRepository.findAll();
+ List listResult = Lists.newArrayList(ruleNameService.findAllRuleNames());
Assert.assertTrue(listResult.size() > 0);
// Delete
Integer id = rule.getId();
- ruleNameRepository.delete(rule);
- Optional ruleList = ruleNameRepository.findById(id);
+ ruleNameService.deleteRuleName(rule);
+ Optional ruleList = ruleNameService.findRuleNameById(id);
Assert.assertFalse(ruleList.isPresent());
}
}
diff --git a/Poseiden-skeleton/src/test/java/com/nnk/springboot/TradeTests.java b/Poseiden-skeleton/src/test/java/com/nnk/springboot/TradeTests.java
index ed50409266..c853170e16 100644
--- a/Poseiden-skeleton/src/test/java/com/nnk/springboot/TradeTests.java
+++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/TradeTests.java
@@ -1,7 +1,9 @@
package com.nnk.springboot;
import com.nnk.springboot.domain.Trade;
-import com.nnk.springboot.repositories.TradeRepository;
+import com.nnk.springboot.services.TradeService;
+
+import org.assertj.core.util.Lists;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -17,30 +19,30 @@
public class TradeTests {
@Autowired
- private TradeRepository tradeRepository;
+ private TradeService tradeService;
@Test
public void tradeTest() {
- Trade trade = new Trade("Trade Account", "Type");
+ Trade trade = new Trade("Trade Account", "Type", 10D);
// Save
- trade = tradeRepository.save(trade);
+ trade = tradeService.saveTrade(trade);
Assert.assertNotNull(trade.getTradeId());
Assert.assertTrue(trade.getAccount().equals("Trade Account"));
// Update
trade.setAccount("Trade Account Update");
- trade = tradeRepository.save(trade);
+ trade = tradeService.saveTrade(trade);
Assert.assertTrue(trade.getAccount().equals("Trade Account Update"));
// Find
- List listResult = tradeRepository.findAll();
+ List listResult = Lists.newArrayList(tradeService.findAllTrades());
Assert.assertTrue(listResult.size() > 0);
// Delete
Integer id = trade.getTradeId();
- tradeRepository.delete(trade);
- Optional tradeList = tradeRepository.findById(id);
+ tradeService.deleteTrade(trade);
+ Optional tradeList = tradeService.findTradeById(id);
Assert.assertFalse(tradeList.isPresent());
}
}
diff --git a/Poseiden-skeleton/src/test/java/com/nnk/springboot/UserTests.java b/Poseiden-skeleton/src/test/java/com/nnk/springboot/UserTests.java
new file mode 100644
index 0000000000..70944b5a9a
--- /dev/null
+++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/UserTests.java
@@ -0,0 +1,48 @@
+package com.nnk.springboot;
+
+import com.nnk.springboot.domain.User;
+import com.nnk.springboot.services.UserService;
+
+import org.assertj.core.util.Lists;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.List;
+import java.util.Optional;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class UserTests {
+
+ @Autowired
+ private UserService userService;
+
+ @Test
+ public void userTest() {
+ User user = new User("UserName", "Passw0rd!", "UserTestName", "USER");
+
+ // Save
+ user = userService.saveUser(user);
+ Assert.assertNotNull(user.getId());
+ Assert.assertTrue(user.getUsername().equals("UserName"));
+
+ // Update
+ user.setUsername("UserNameUpdate");;
+ user = userService.saveUser(user);
+ Assert.assertTrue(user.getUsername().equals("UserNameUpdate"));
+
+ // Find
+ List listResult = Lists.newArrayList(userService.findAllUsers());
+ Assert.assertTrue(listResult.size() > 2); // 2 users already saved in initial database
+
+ // Delete
+ Integer id = user.getId();
+ userService.deleteUser(user);
+ Optional userList = userService.findUserById(id);
+ Assert.assertFalse(userList.isPresent());
+ }
+}
diff --git a/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/BidListControllerTest.java b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/BidListControllerTest.java
new file mode 100644
index 0000000000..cd492e9b54
--- /dev/null
+++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/BidListControllerTest.java
@@ -0,0 +1,227 @@
+package com.nnk.springboot.controllers;
+
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.security.test.context.support.WithMockUser;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.web.util.NestedServletException;
+
+import com.nnk.springboot.domain.BidList;
+import com.nnk.springboot.services.BidListService;
+
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+@AutoConfigureMockMvc
+@WebAppConfiguration
+public class BidListControllerTest {
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @Autowired
+ private BidListService bidListService;
+
+ @Test
+ public void test_BidListPages_NeedsAuthentication() throws Exception {
+ mockMvc.perform(get("/bidList/list"))
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("http://localhost/login"));
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_AdminAuthentication_PermitsBidListListAccess() throws Exception{
+ mockMvc.perform(get("/bidList/list"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("bidList/list"));
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_UserAuthentication_PermitBidListListAccess() throws Exception{
+ mockMvc.perform(get("/bidList/list"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("bidList/list"));
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_AdminAuthentication_PermitBidListAddAccess() throws Exception{
+ mockMvc.perform(get("/bidList/add"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("bidList/add"));
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_UserAuthentication_PermitBidListAddAccess() throws Exception{
+ mockMvc.perform(get("/bidList/add"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("bidList/add"));
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_AdminAuthentication_PermitBidListUpdateAccess() throws Exception{
+ // saves a bidList to update in database
+ BidList bid = new BidList("Account Test", "Type Test", 10d);
+ bid = bidListService.saveBidList(bid);
+
+ // tries to access to update page
+ mockMvc.perform(get("/bidList/update/" + bid.getBidListId()))
+ .andExpect(status().isOk())
+ .andExpect(view().name("bidList/update"));
+
+ // deletes the bidList from the database
+ bidListService.deleteBidList(bid);
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_UserAuthentication_PermitBidListUpdateAccess() throws Exception{
+ // saves a bidList to update in database
+ BidList bid = new BidList("Account Test", "Type Test", 10d);
+ bid = bidListService.saveBidList(bid);
+
+ // tries to access to update page
+ mockMvc.perform(get("/bidList/update/" + bid.getBidListId()))
+ .andExpect(status().isOk())
+ .andExpect(view().name("bidList/update"));
+
+ // deletes the bidList from the database
+ bidListService.deleteBidList(bid);
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_DeleteABidList() throws Exception {
+ // saves a bidList to delete in database
+ BidList bid = new BidList("Account Test to delete", "Type Test", 10d);
+ bid = bidListService.saveBidList(bid);
+
+ // deletes the bidList from database
+ mockMvc.perform(get("/bidList/delete/{id}", bid.getBidListId()))
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("/bidList/list"));
+ }
+
+ @Test(expected = NestedServletException.class)
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_NotDeleteABidList_withInvalidId() throws Exception {
+
+ // tries to delete a bidList from database with invalid Id
+ mockMvc.perform(get("/bidList/delete/{id}", 0))
+ .andExpect(status().is5xxServerError());
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_AddANewValidBidList() throws Exception {
+ // creates a bidList to add to database
+ BidList bid = new BidList("New Account Test", "Type Test", 10D);
+
+ // tries to add the bidList to database
+ mockMvc
+ .perform(post("/bidList/validate")
+ .param("account", bid.getAccount())
+ .param("type", bid.getType())
+ .param("bidQuantity", bid.getBidQuantity().toString()))
+ .andExpect(model().hasNoErrors())
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("/bidList/list"));
+
+ // retrieves the bidList from database
+ Iterable bidListsIterable = new ArrayList<>();
+ bidListsIterable = bidListService.findAllBidLists();
+ List bidLists = new ArrayList<>();
+ bidListsIterable.forEach(bidList -> bidLists.add(bidList));
+ bid = bidLists.get(bidLists.size() - 1);
+
+ // deletes the bidList from database
+ bidListService.deleteBidList(bid);
+
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_NotAddANewInvalidBidList() throws Exception {
+ // creates an invalid bidList to add to database
+ BidList bid = new BidList("Account Test", "Type Test", 0D);
+
+ // tries to add the bidList to database
+ mockMvc
+ .perform(post("/bidList/validate")
+ .param("account", bid.getAccount())
+ .param("type", bid.getType())
+ .param("bidQuantity", bid.getBidQuantity().toString()))
+ .andExpect(model().hasErrors())
+ .andExpect(view().name("/bidList/add"));
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_UpdateValidBidList() throws Exception {
+ // creates a bidList to update
+ BidList bid = new BidList("Account test", "Type Test", 10d);
+ bid = bidListService.saveBidList(bid);
+
+ // tries to update the bidList
+ mockMvc
+ .perform(post("/bidList/update/{id}", bid.getBidListId())
+ .param("account", "Account updated")
+ .param("type", bid.getType())
+ .param("bidQuantity", bid.getBidQuantity().toString()))
+ .andExpect(model().hasNoErrors())
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("/bidList/list"));
+
+ // deletes the bidList
+ bidListService.deleteBidList(bid);
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_NotUpdateInvalidBidList() throws Exception {
+ // creates a bidList to update
+ BidList bid = new BidList("Account test", "Type Test", 10d);
+ bid = bidListService.saveBidList(bid);
+
+ // tries to update the bidList with invalid account
+ mockMvc
+ .perform(post("/bidList/update/{id}", bid.getBidListId())
+ .param("account", "")
+ .param("type", bid.getType())
+ .param("bidQuantity", bid.getBidQuantity().toString()))
+ .andExpect(model().hasErrors())
+ .andExpect(view().name("/bidList/update"));
+
+ // deletes the bidList to update
+ bidListService.deleteBidList(bid);
+ }
+
+ @Test(expected = NestedServletException.class)
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_NotUpdateBidList_withInvalidId() throws Exception {
+ // tries to update a bidList with invalid Id
+ mockMvc
+ .perform(get("/bidList/update/{id}", 0))
+ .andExpect(status().is5xxServerError());
+ }
+
+}
diff --git a/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/CurvePointControllerTest.java b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/CurvePointControllerTest.java
new file mode 100644
index 0000000000..f659738bc7
--- /dev/null
+++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/CurvePointControllerTest.java
@@ -0,0 +1,224 @@
+package com.nnk.springboot.controllers;
+
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.security.test.context.support.WithMockUser;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.web.util.NestedServletException;
+
+import com.nnk.springboot.domain.CurvePoint;
+import com.nnk.springboot.services.CurvePointService;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+@AutoConfigureMockMvc
+@WebAppConfiguration
+public class CurvePointControllerTest {
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @Autowired
+ private CurvePointService curvePointService;
+
+ @Test
+ public void test_CurvePointPages_NeedAuthentication() throws Exception {
+ mockMvc.perform(get("curvePoint/list"))
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("http://localhost/login"));
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_AdminAuthentication_PermitCurvePointListAccess() throws Exception{
+ mockMvc.perform(get("/curvePoint/list"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("curvePoint/list"));
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_UserAuthentication_PermitCurvePointListAccess() throws Exception{
+ mockMvc.perform(get("/curvePoint/list"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("curvePoint/list"));
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_AdminAuthentication_PermitCurvePointAddAccess() throws Exception{
+ mockMvc.perform(get("/curvePoint/add"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("curvePoint/add"));
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_UserAuthentication_PermitCurvePointAddAccess() throws Exception{
+ mockMvc.perform(get("/curvePoint/add"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("curvePoint/add"));
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_AdminAuthentication_PermitCurvePointUpdateAccess() throws Exception{
+ // saves a curvePoint to update in database
+ CurvePoint curvePoint = new CurvePoint(10, 10d, 30d);
+ curvePoint = curvePointService.saveCurvePoint(curvePoint);
+
+ // tries to access to update page
+ mockMvc.perform(get("/curvePoint/update/" + curvePoint.getId()))
+ .andExpect(status().isOk())
+ .andExpect(view().name("curvePoint/update"));
+
+ // deletes the curvePoint from the database
+ curvePointService.deleteCurvePoint(curvePoint);
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_UserAuthentication_PermitCurvePointUpdateAccess() throws Exception{
+ // saves a curvePoint to update in database
+ CurvePoint curvePoint = new CurvePoint(10, 10d, 30d);
+ curvePoint = curvePointService.saveCurvePoint(curvePoint);
+
+ // tries to access to update page
+ mockMvc.perform(get("/curvePoint/update/" + curvePoint.getId()))
+ .andExpect(status().isOk())
+ .andExpect(view().name("curvePoint/update"));
+
+ // deletes the curvePoint from the database
+ curvePointService.deleteCurvePoint(curvePoint);
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_DeleteACurvePoint() throws Exception {
+ // saves a curvePoint to delete in database
+ CurvePoint curvePoint = new CurvePoint(10, 10d, 30d);
+ curvePoint = curvePointService.saveCurvePoint(curvePoint);
+
+ // deletes the curvePoint from database
+ mockMvc.perform(get("/curvePoint/delete/{id}", curvePoint.getId()))
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("/curvePoint/list"));
+ }
+
+ @Test(expected = NestedServletException.class)
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_NotDeleteACurvePoint_withInvalidId() throws Exception {
+
+ // tries to delete a curvePoint from database with invalid Id
+ mockMvc.perform(get("/curvePoint/delete/{id}", 0))
+ .andExpect(status().is5xxServerError());
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_AddANewValidCurvePoint() throws Exception {
+ // creates a curvePoint to add to database
+ CurvePoint curvePoint = new CurvePoint(10, 10D, 30D);
+
+ // tries to add the curvePoint to database
+ mockMvc
+ .perform(post("/curvePoint/validate")
+ .param("curveId", curvePoint.getCurveId().toString())
+ .param("term", curvePoint.getTerm().toString())
+ .param("value", curvePoint.getValue().toString()))
+ .andExpect(model().hasNoErrors())
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("/curvePoint/list"));
+
+ // retrieves the curvePoint from database
+ Iterable curvePointsIterable = new ArrayList<>();
+ curvePointsIterable = curvePointService.findAllCurvePoints();
+ List curvePoints = new ArrayList<>();
+ curvePointsIterable.forEach(curve -> curvePoints.add(curve));
+ curvePoint = curvePoints.get(curvePoints.size() - 1);
+
+ // deletes the curvePoint from database
+ curvePointService.deleteCurvePoint(curvePoint);
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_NotAddANewInvalidCurvePoint() throws Exception {
+ // creates an invalid curvePoint to add to database
+ CurvePoint curvePoint = new CurvePoint(0, 10d, 30d);
+
+ // tries to add the curvePoint to database
+ mockMvc
+ .perform(post("/curvePoint/validate")
+ .param("curveId", curvePoint.getCurveId().toString())
+ .param("term", curvePoint.getTerm().toString())
+ .param("value", curvePoint.getValue().toString()))
+ .andExpect(model().hasErrors())
+ .andExpect(view().name("curvePoint/add"));
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_UpdateValidCurvePoint() throws Exception {
+ // creates a curvePoint to update
+ CurvePoint curvePoint = new CurvePoint(10, 10d, 30d);
+ curvePoint = curvePointService.saveCurvePoint(curvePoint);
+
+ // tries to update the curvePoint
+ mockMvc
+ .perform(post("/curvePoint/update/{id}", curvePoint.getId())
+ .param("curveId", curvePoint.getCurveId().toString())
+ .param("term", curvePoint.getTerm().toString())
+ .param("value", "20D"))
+ .andExpect(model().hasNoErrors())
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("/curvePoint/list"));
+
+ // deletes the curvePoint
+ curvePointService.deleteCurvePoint(curvePoint);
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_NotUpdateInvalidCurvePoint() throws Exception {
+ // creates a curvePoint to update
+ CurvePoint curvePoint = new CurvePoint(10, 10d, 30d);
+ curvePoint = curvePointService.saveCurvePoint(curvePoint);
+
+ // tries to update the curvePoint with invalid value
+ mockMvc
+ .perform(post("/curvePoint/update/{id}", curvePoint.getId())
+ .param("curveId", curvePoint.getCurveId().toString())
+ .param("term", curvePoint.getTerm().toString())
+ .param("value", ""))
+ .andExpect(model().hasErrors())
+ .andExpect(view().name("/curvePoint/update"));
+
+ // deletes the curvePoint to update
+ curvePointService.deleteCurvePoint(curvePoint);
+ }
+
+ @Test(expected = NestedServletException.class)
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_NotUpdateCurvePoint_withInvalidId() throws Exception {
+ // tries to update a curvePoint with invalid Id
+ mockMvc
+ .perform(get("/curvePoint/update/{id}", 0))
+ .andExpect(status().is5xxServerError());
+ }
+}
diff --git a/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/LoginControllerTest.java b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/LoginControllerTest.java
new file mode 100644
index 0000000000..5e4f4654d6
--- /dev/null
+++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/LoginControllerTest.java
@@ -0,0 +1,42 @@
+package com.nnk.springboot.controllers;
+
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.security.test.context.support.WithMockUser;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.test.web.servlet.MockMvc;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+@AutoConfigureMockMvc
+@WebAppConfiguration
+public class LoginControllerTest {
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @Test
+ public void test_loginPageDisplaying() throws Exception {
+ mockMvc.perform(get("/app/login"))
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("http://localhost/login"));
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_allUserArticles() throws Exception {
+ mockMvc.perform(get("/app/secure/article-details"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("user/list"));
+ }
+
+}
diff --git a/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/RatingControllerTest.java b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/RatingControllerTest.java
new file mode 100644
index 0000000000..35d250964f
--- /dev/null
+++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/RatingControllerTest.java
@@ -0,0 +1,228 @@
+package com.nnk.springboot.controllers;
+
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.security.test.context.support.WithMockUser;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.web.util.NestedServletException;
+
+import com.nnk.springboot.domain.Rating;
+import com.nnk.springboot.services.RatingService;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+@AutoConfigureMockMvc
+@WebAppConfiguration
+public class RatingControllerTest {
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @Autowired
+ private RatingService ratingService;
+
+ @Test
+ public void test_RatingPages_NeedAuthentication() throws Exception {
+ mockMvc.perform(get("curvePoint/list"))
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("http://localhost/login"));
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_AdminAuthentication_PermitRatingListAccess() throws Exception{
+ mockMvc.perform(get("/rating/list"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("rating/list"));
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_UserAuthentication_PermitRatingListAccess() throws Exception{
+ mockMvc.perform(get("/rating/list"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("rating/list"));
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_AdminAuthentication_PermitRatingAddAccess() throws Exception{
+ mockMvc.perform(get("/rating/add"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("rating/add"));
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_UserAuthentication_PermitRatingAddAccess() throws Exception{
+ mockMvc.perform(get("/rating/add"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("rating/add"));
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_AdminAuthentication_PermitRatingUpdateAccess() throws Exception{
+ // saves a rating to update in database
+ Rating rating = new Rating("Moodys Rating", "Sand PRating", "Fitch Rating", 10);
+ rating = ratingService.saveRating(rating);
+
+ // tries to access to update page
+ mockMvc.perform(get("/rating/update/" + rating.getId()))
+ .andExpect(status().isOk())
+ .andExpect(view().name("rating/update"));
+
+ // deletes the rating from the database
+ ratingService.deleteRating(rating);
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_UserAuthenticationPermit_RatingUpdateAccess() throws Exception{
+ // saves a rating to update in database
+ Rating rating = new Rating("Moodys Rating Test", "Sand PRating Test", "Fitch Rating", 10);
+ rating = ratingService.saveRating(rating);
+
+ // tries to access to update page
+ mockMvc.perform(get("/rating/update/" + rating.getId()))
+ .andExpect(status().isOk())
+ .andExpect(view().name("rating/update"));
+
+ // deletes the rating from the database
+ ratingService.deleteRating(rating);
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_DeleteARating() throws Exception {
+ // saves a rating to delete in database
+ Rating rating = new Rating("Moodys Rating Test", "Sand PRating Test", "Fitch Rating Test", 10);
+ rating = ratingService.saveRating(rating);
+
+ // deletes the rating from database
+ mockMvc.perform(get("/rating/delete/{id}", rating.getId()))
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("/rating/list"));
+ }
+
+ @Test(expected = NestedServletException.class)
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_NotDeleteARating_withInvalidId() throws Exception {
+
+ // tries to delete a rating from database with invalid Id
+ mockMvc.perform(get("/rating/delete/{id}", 0))
+ .andExpect(status().is5xxServerError());
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_AddANewValidRating() throws Exception {
+ // creates a rating to add to database
+ Rating rating = new Rating("Moodys Rating Test", "Sand PRating Test", "Fitch Rating Test", 10);
+
+ // tries to add the rating to database
+ mockMvc
+ .perform(post("/rating/validate")
+ .param("moodysRating", rating.getMoodysRating())
+ .param("sandPRating", rating.getSandPRating())
+ .param("fitchRating", rating.getFitchRating())
+ .param("orderNumber", rating.getOrderNumber().toString()))
+ .andExpect(model().hasNoErrors())
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("/rating/list"));
+
+ // retrieves the rating from database
+ Iterable ratingsIterable = new ArrayList<>();
+ ratingsIterable = ratingService.findAllRatings();
+ List ratings = new ArrayList<>();
+ ratingsIterable.forEach(r -> ratings.add(r));
+ rating = ratings.get(ratings.size() - 1);
+
+ // deletes the rating from database
+ ratingService.deleteRating(rating);
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_NotAddANewInvalidRating() throws Exception {
+ // creates an invalid rating to add to database
+ Rating rating = new Rating("Moodys Rating Test", "Sand PRating Test", "Fitch Rating Test", 10);
+
+ // tries to add the rating to database
+ mockMvc
+ .perform(post("/rating/validate")
+ .param("moodysRating", "")
+ .param("sandPRating", rating.getSandPRating())
+ .param("fitchRating", rating.getFitchRating())
+ .param("orderNumber", rating.getOrderNumber().toString()))
+ .andExpect(model().hasErrors())
+ .andExpect(view().name("rating/add"));
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_UpdateValidRating() throws Exception {
+ // creates a rating to update
+ Rating rating = new Rating("Moodys Rating Test", "Sand PRating Test", "Fitch Rating Test", 10);
+ rating = ratingService.saveRating(rating);
+
+ // tries to update the rating
+ mockMvc
+ .perform(post("/rating/update/{id}", rating.getId())
+ .param("moodysRating", rating.getMoodysRating())
+ .param("sandPRating", rating.getSandPRating())
+ .param("fitchRating", rating.getFitchRating())
+ .param("orderNumber", "20"))
+ .andExpect(model().hasNoErrors())
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("/rating/list"));
+
+ // deletes the rating
+ ratingService.deleteRating(rating);
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_NotUpdateInvalidRating() throws Exception {
+ // creates a rating to update
+ Rating rating = new Rating("Moodys Rating Test", "Sand PRating Test", "Fitch Rating Test", 10);
+ rating = ratingService.saveRating(rating);
+
+ // tries to update the rating with invalid order number
+ mockMvc
+ .perform(post("/rating/update/{id}", rating.getId())
+ .param("moodysRating", rating.getMoodysRating())
+ .param("sandPRating", rating.getSandPRating())
+ .param("fitchRating", rating.getFitchRating())
+ .param("orderNumber", "0"))
+ .andExpect(model().hasErrors())
+ .andExpect(view().name("/rating/update"));
+
+ // deletes the rating to update
+ ratingService.deleteRating(rating);
+ }
+
+ @Test(expected = NestedServletException.class)
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_NotUpdateRating_withInvalidId() throws Exception {
+ // tries to update a rating with invalid Id
+ mockMvc
+ .perform(get("/rating/update/{id}", 0))
+ .andExpect(status().is5xxServerError());
+ }
+}
diff --git a/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/RuleNameControllerTest.java b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/RuleNameControllerTest.java
new file mode 100644
index 0000000000..5cdb76615a
--- /dev/null
+++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/RuleNameControllerTest.java
@@ -0,0 +1,237 @@
+package com.nnk.springboot.controllers;
+
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.security.test.context.support.WithMockUser;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.web.util.NestedServletException;
+
+import com.nnk.springboot.domain.RuleName;
+import com.nnk.springboot.services.RuleNameService;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+@AutoConfigureMockMvc
+@WebAppConfiguration
+
+public class RuleNameControllerTest {
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @Autowired
+ private RuleNameService ruleNameService;
+
+ @Test
+ public void test_RuleNamePages_NeedAuthentication() throws Exception {
+ mockMvc.perform(get("ruleName/list"))
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("http://localhost/login"));
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_AdminAuthentication_PermitRuleNameListAccess() throws Exception{
+ mockMvc.perform(get("/ruleName/list"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("ruleName/list"));
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_UserAuthentication_PermitRuleNameListAccess() throws Exception{
+ mockMvc.perform(get("/ruleName/list"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("ruleName/list"));
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_AdminAuthentication_PermitRuleNameAddAccess() throws Exception{
+ mockMvc.perform(get("/ruleName/add"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("ruleName/add"));
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_UserAuthentication_PermitRuleNameAddAccess() throws Exception{
+ mockMvc.perform(get("/ruleName/add"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("ruleName/add"));
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_AdminAuthentication_PermitRuleNameUpdateAccess() throws Exception{
+ // saves a rule to update in database
+ RuleName ruleName = new RuleName("Rule Name", "Description", "Json", "Template", "SQL", "SQL Part");
+ ruleName = ruleNameService.saveRuleName(ruleName);
+
+ // tries to access to update page
+ mockMvc.perform(get("/ruleName/update/" + ruleName.getId()))
+ .andExpect(status().isOk())
+ .andExpect(view().name("ruleName/update"));
+
+ // deletes the rule from the database
+ ruleNameService.deleteRuleName(ruleName);
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_UserAuthentication_PermitRuleNameUpdateAccess() throws Exception{
+ // saves a rule to update in database
+ RuleName ruleName = new RuleName("Rule Name", "Description", "Json", "Template", "SQL", "SQL Part");
+ ruleName = ruleNameService.saveRuleName(ruleName);
+
+ // tries to access to update page
+ mockMvc.perform(get("/ruleName/update/" + ruleName.getId()))
+ .andExpect(status().isOk())
+ .andExpect(view().name("ruleName/update"));
+
+ // deletes the rule from the database
+ ruleNameService.deleteRuleName(ruleName);
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_DeleteARuleName() throws Exception {
+ // saves a rule to delete in database
+ RuleName ruleName = new RuleName("Rule Name", "Description", "Json", "Template", "SQL", "SQL Part");
+ ruleName = ruleNameService.saveRuleName(ruleName);
+
+ // deletes the rule from database
+ mockMvc.perform(get("/ruleName/delete/{id}", ruleName.getId()))
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("/ruleName/list"));
+ }
+
+ @Test(expected = NestedServletException.class)
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_NotDeleteARuleName_withInvalidId() throws Exception {
+
+ // tries to delete a rule from database with invalid Id
+ mockMvc.perform(get("/ruleName/delete/{id}", 0))
+ .andExpect(status().is5xxServerError());
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_AddANewValidRuleName() throws Exception {
+ // creates a rule to add to database
+ RuleName ruleName = new RuleName("Rule Name", "Description", "Json", "Template", "SQL", "SQL Part");
+
+ // tries to add the rule to database
+ mockMvc
+ .perform(post("/ruleName/validate")
+ .param("name", ruleName.getName())
+ .param("description", ruleName.getDescription())
+ .param("json", ruleName.getJson())
+ .param("template", ruleName.getTemplate())
+ .param("sqlStr", ruleName.getSqlStr())
+ .param("sqlPart", ruleName.getSqlPart()))
+ .andExpect(model().hasNoErrors())
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("/ruleName/list"));
+
+ // retrieves the rule from database
+ Iterable ruleNamesIterable = new ArrayList<>();
+ ruleNamesIterable = ruleNameService.findAllRuleNames();
+ List ruleNames = new ArrayList<>();
+ ruleNamesIterable.forEach(bidList -> ruleNames.add(bidList));
+ ruleName = ruleNames.get(ruleNames.size() - 1);
+
+ // deletes the rule from database
+ ruleNameService.deleteRuleName(ruleName);
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_NotAddANewInvalidRuleName() throws Exception {
+ // creates an invalid rule to add to database
+ RuleName ruleName = new RuleName("", "Description", "Json", "Template", "SQL", "SQL Part");
+
+ // tries to add the rule to database
+ mockMvc
+ .perform(post("/ruleName/validate")
+ .param("name", ruleName.getName())
+ .param("description", ruleName.getDescription())
+ .param("json", ruleName.getJson())
+ .param("template", ruleName.getTemplate())
+ .param("sqlStr", ruleName.getSqlStr())
+ .param("sqlPart", ruleName.getSqlPart()))
+ .andExpect(model().hasErrors())
+ .andExpect(view().name("ruleName/add"));
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_UpdateValidRuleName() throws Exception {
+ // creates a rule to update
+ RuleName ruleName = new RuleName("Rule Name", "Description", "Json", "Template", "SQL", "SQL Part");
+ ruleName = ruleNameService.saveRuleName(ruleName);
+
+ // tries to update the rule
+ mockMvc
+ .perform(post("/ruleName/update/{id}", ruleName.getId())
+ .param("name", "Rule Name updated")
+ .param("description", ruleName.getDescription())
+ .param("json", ruleName.getJson())
+ .param("template", ruleName.getTemplate())
+ .param("sqlStr", ruleName.getSqlStr())
+ .param("sqlPart", ruleName.getSqlPart()))
+ .andExpect(model().hasNoErrors())
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("/ruleName/list"));
+
+ // deletes the rule
+ ruleNameService.deleteRuleName(ruleName);
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_NotUpdateInvalidRuleName() throws Exception {
+ // creates a rule to update
+ RuleName ruleName = new RuleName("Rule Name", "Description", "Json", "Template", "SQL", "SQL Part");
+ ruleName = ruleNameService.saveRuleName(ruleName);
+
+ // tries to update the rule with invalid name
+ mockMvc
+ .perform(post("/ruleName/update/{id}", ruleName.getId())
+ .param("name", "")
+ .param("description", ruleName.getDescription())
+ .param("json", ruleName.getJson())
+ .param("template", ruleName.getTemplate())
+ .param("sqlStr", ruleName.getSqlStr())
+ .param("sqlPart", ruleName.getSqlPart()))
+ .andExpect(model().hasErrors())
+ .andExpect(view().name("/ruleName/update"));
+
+ // deletes the rule to update
+ ruleNameService.deleteRuleName(ruleName);
+ }
+
+ @Test(expected = NestedServletException.class)
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_NotUpdateRuleName_withInvalidId() throws Exception {
+ // tries to update a rule with invalid Id
+ mockMvc
+ .perform(get("/ruleName/update/{id}", 0))
+ .andExpect(status().is5xxServerError());
+ }
+}
diff --git a/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/TradeControllerTest.java b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/TradeControllerTest.java
new file mode 100644
index 0000000000..0da3319f29
--- /dev/null
+++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/TradeControllerTest.java
@@ -0,0 +1,226 @@
+package com.nnk.springboot.controllers;
+
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.security.test.context.support.WithMockUser;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.web.util.NestedServletException;
+
+import com.nnk.springboot.domain.Trade;
+import com.nnk.springboot.services.TradeService;
+
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+@AutoConfigureMockMvc
+@WebAppConfiguration
+
+public class TradeControllerTest {
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @Autowired
+ private TradeService tradeService;
+
+ @Test
+ public void test_TradePages_NeedAuthentication() throws Exception {
+ mockMvc.perform(get("trade/list"))
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("http://localhost/login"));
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_AdminAuthentication_PermitTradeListAccess() throws Exception{
+ mockMvc.perform(get("/trade/list"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("trade/list"));
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_UserAuthentication_PermitTradeListAccess() throws Exception{
+ mockMvc.perform(get("/trade/list"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("trade/list"));
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_AdminAuthentication_PermitTradeAddAccess() throws Exception{
+ mockMvc.perform(get("/trade/add"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("trade/add"));
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_UserAuthentication_PermitTradeAddAccess() throws Exception{
+ mockMvc.perform(get("/trade/add"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("trade/add"));
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_AdminAuthentication_PermitTradeUpdateAccess() throws Exception{
+ // saves a trade to update in database
+ Trade trade = new Trade("Trade Account", "Type", 10D);
+ trade = tradeService.saveTrade(trade);
+
+ // tries to access to update page
+ mockMvc.perform(get("/trade/update/" + trade.getTradeId()))
+ .andExpect(status().isOk())
+ .andExpect(view().name("trade/update"));
+
+ // deletes the trade from the database
+ tradeService.deleteTrade(trade);
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_UserAuthentication_PermitTradeUpdateAccess() throws Exception{
+ // saves a trade to update in database
+ Trade trade = new Trade("Trade Account", "Type", 10D);
+ trade = tradeService.saveTrade(trade);
+
+ // tries to access to update page
+ mockMvc.perform(get("/trade/update/" + trade.getTradeId()))
+ .andExpect(status().isOk())
+ .andExpect(view().name("trade/update"));
+
+ // deletes the trade from the database
+ tradeService.deleteTrade(trade);
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_DeleteATrade() throws Exception {
+ // saves a trade to update in database
+ Trade trade = new Trade("Trade Account", "Type", 10D);
+ trade = tradeService.saveTrade(trade);
+
+ // deletes the trade from database
+ mockMvc.perform(get("/trade/delete/{id}", trade.getTradeId()))
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("/trade/list"));
+ }
+
+ @Test(expected = NestedServletException.class)
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_NotDeleteATrade_withInvalidId() throws Exception {
+
+ // tries to delete a trade from database with invalid Id
+ mockMvc.perform(get("/trade/delete/{id}", 0))
+ .andExpect(status().is5xxServerError());
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_AddANewValidTrade() throws Exception {
+ // creates a trade to add to database
+ Trade trade = new Trade("Trade Account", "Type", 10D);
+
+ // tries to add the trade to database
+ mockMvc
+ .perform(post("/trade/validate")
+ .param("account", trade.getAccount())
+ .param("type", trade.getType())
+ .param("buyQuantity", trade.getBuyQuantity().toString()))
+ .andExpect(model().hasNoErrors())
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("/trade/list"));
+
+ // retrieves the trade from database
+ Iterable tradesIterable = new ArrayList<>();
+ tradesIterable = tradeService.findAllTrades();
+ List trades = new ArrayList<>();
+ tradesIterable.forEach(t -> trades.add(t));
+ trade = trades.get(trades.size() - 1);
+
+ // deletes the trade from database
+ tradeService.deleteTrade(trade);
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_NotAddANewInvalidTrade() throws Exception {
+ // creates an invalid trade to add to database
+ Trade trade = new Trade("Account", "Type", 0D);
+
+ // tries to add the trade to database
+ mockMvc
+ .perform(post("/trade/validate")
+ .param("account", trade.getAccount())
+ .param("type", trade.getType())
+ .param("buyQuantity", trade.getBuyQuantity().toString()))
+ .andExpect(model().hasErrors())
+ .andExpect(view().name("trade/add"));
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_UpdateValidTrade() throws Exception {
+ // creates a trade to update
+ Trade trade = new Trade("Trade Account", "Type", 10D);
+ trade = tradeService.saveTrade(trade);
+
+ // tries to update the trade
+ mockMvc
+ .perform(post("/trade/update/{id}", trade.getTradeId())
+ .param("account", "Trade Account updated")
+ .param("type", trade.getType())
+ .param("buyQuantity", trade.getBuyQuantity().toString()))
+ .andExpect(model().hasNoErrors())
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("/trade/list"));
+
+ // deletes the trade
+ tradeService.deleteTrade(trade);
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_NotUpdateInvalidTrade() throws Exception {
+ // creates a trade to update
+ Trade trade = new Trade("Trade Account", "Type", 10D);
+ trade = tradeService.saveTrade(trade);
+
+ // tries to update the trade with invalid account
+ mockMvc
+ .perform(post("/trade/update/{id}", trade.getTradeId())
+ .param("account", "")
+ .param("type", trade.getType())
+ .param("buyQuantity", trade.getBuyQuantity().toString()))
+ .andExpect(model().hasErrors())
+ .andExpect(view().name("trade/update"));
+
+ // deletes the trade to update
+ tradeService.deleteTrade(trade);
+ }
+
+ @Test(expected = NestedServletException.class)
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_NotUpdateTrade_withInvalidId() throws Exception {
+ // tries to update a bidList with invalid Id
+ mockMvc
+ .perform(get("/trade/update/{id}", 0))
+ .andExpect(status().is5xxServerError());
+ }
+}
diff --git a/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/UserControllerTest.java b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/UserControllerTest.java
new file mode 100644
index 0000000000..afd3b7507e
--- /dev/null
+++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/UserControllerTest.java
@@ -0,0 +1,248 @@
+package com.nnk.springboot.controllers;
+
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.forwardedUrl;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.security.test.context.support.WithMockUser;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.web.util.NestedServletException;
+
+import com.nnk.springboot.domain.User;
+import com.nnk.springboot.services.UserService;
+
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+@AutoConfigureMockMvc
+@WebAppConfiguration
+public class UserControllerTest {
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @Autowired
+ private UserService userService;
+
+ @Test
+ public void test_UserPages_NeedAuthentication() throws Exception {
+ mockMvc.perform(get("user/list"))
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("http://localhost/login"));
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_AdminAuthentication_PermitUserListAccess() throws Exception{
+ mockMvc.perform(get("/user/list"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("user/list"));
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_UserAuthentication_NotPermitUserListAccess() throws Exception{
+ mockMvc.perform(get("/user/list"))
+ .andExpect(status().is4xxClientError())
+ .andExpect(forwardedUrl("/app/error"));
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_AdminAuthentication_PermitUserAddAccess() throws Exception{
+ mockMvc.perform(get("/user/add"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("user/add"));
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_UserAuthentication_NotPermitUserAddAccess() throws Exception{
+ mockMvc.perform(get("/user/add"))
+ .andExpect(status().is4xxClientError())
+ .andExpect(forwardedUrl("/app/error"));
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_AdminAuthentication_PermitUserUpdateAccess() throws Exception{
+ // saves a user to update in database
+ User user = new User("UserName", "Passw0rd!", "UserTestName", "USER");
+ user = userService.saveUser(user);
+
+ // tries to access to update page
+ mockMvc.perform(get("/user/update/" + user.getId()))
+ .andExpect(status().isOk())
+ .andExpect(view().name("user/update"));
+
+ // deletes the user from the database
+ userService.deleteUser(user);
+ }
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER")
+ public void test_UserAuthentication_NotPermitUserUpdateAccess() throws Exception{
+ // saves a user to update in database
+ User user = new User("UserName", "Passw0rd!", "UserTestName", "USER");
+ user = userService.saveUser(user);
+
+ // tries to access to update page
+ mockMvc.perform(get("/user/update/" + user.getId()))
+ .andExpect(status().is4xxClientError())
+ .andExpect(forwardedUrl("/app/error"));
+
+ // deletes the user from the database
+ userService.deleteUser(user);
+ }
+
+
+ @Test
+ @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_DeleteAnUser() throws Exception {
+ // saves a user to delete in database
+ User user = new User("UserName", "Passw0rd!", "UserTestName", "USER");
+ user = userService.saveUser(user);
+
+ // deletes the user from database
+ mockMvc.perform(get("/user/delete/{id}", user.getId()))
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("/user/list"));
+ }
+
+ @Test(expected = NestedServletException.class)
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_NotDeleteAnUser_withInvalidId() throws Exception {
+
+ // tries to delete a user from database with invalid Id
+ mockMvc.perform(get("/user/delete/{id}", 0))
+ .andExpect(status().is5xxServerError());
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_AddANewValidUser() throws Exception {
+ // creates a user to add to database
+ User user = new User("UserName", "Passw0rd!", "UserTestName", "USER");
+
+ // tries to add the user to database
+ mockMvc
+ .perform(post("/user/validate")
+ .param("username", user.getUsername())
+ .param("password", user.getPassword())
+ .param("fullname", user.getFullname())
+ .param("role", user.getRole()))
+ .andExpect(model().hasNoErrors())
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("/user/list"));
+
+ // retrieves the user from database
+ Iterable usersIterable = new ArrayList<>();
+ usersIterable = userService.findAllUsers();
+ List users = new ArrayList<>();
+ usersIterable.forEach(u -> users.add(u));
+ user = users.get(users.size() - 1);
+
+ // deletes the user from database
+ userService.deleteUser(user);
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_NotAddANewInvalidUser() throws Exception {
+ // creates an invalid user to add to database
+ User user = new User("", "Passw0rd!", "UserTestName", "USER");
+
+ // tries to add the user to database
+ mockMvc
+ .perform(post("/user/validate")
+ .param("username", user.getUsername())
+ .param("password", user.getPassword())
+ .param("fullname", user.getFullname())
+ .param("role", user.getRole()))
+ .andExpect(model().hasErrors())
+ .andExpect(view().name("user/add"));
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_UpdateValidUser() throws Exception {
+ // creates a user to update
+ User user = new User("UserName", "Passw0rd!", "UserTestName", "USER");
+ user = userService.saveUser(user);
+
+ // tries to update the user
+ mockMvc
+ .perform(post("/user/update/{id}", user.getId())
+ .param("username", "UserName updated")
+ .param("password", user.getPassword())
+ .param("fullname", user.getFullname())
+ .param("role", user.getRole()))
+ .andExpect(model().hasNoErrors())
+ .andExpect(status().is3xxRedirection())
+ .andExpect(redirectedUrl("/user/list"));
+
+ // deletes the user
+ userService.deleteUser(user);
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_NotUpdateInvalidUser() throws Exception {
+ // creates a user to update
+ User user = new User("UserName", "Passw0rd!", "UserTestName", "USER");
+ user = userService.saveUser(user);
+
+ // tries to update the user with invalid username
+ mockMvc
+ .perform(post("/user/update/{id}", user.getId())
+ .param("username", "")
+ .param("password", user.getPassword())
+ .param("fullname", user.getFullname())
+ .param("role", user.getRole()))
+ .andExpect(model().hasErrors())
+ .andExpect(view().name("user/update"));
+
+ // deletes the user to update
+ userService.deleteUser(user);
+ }
+
+ @Test
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_NotAddUser_withInvalidPassword() throws Exception {
+ // creates an invalid user to add to database
+ User user = new User("UserName", "password", "UserTestName", "USER");
+
+ // tries to add the user to database
+ mockMvc
+ .perform(post("/user/validate")
+ .param("username", user.getUsername())
+ .param("password", user.getPassword())
+ .param("fullname", user.getFullname())
+ .param("role", user.getRole()))
+ .andExpect(model().hasErrors())
+ .andExpect(view().name("user/add"));
+ }
+
+ @Test(expected = NestedServletException.class)
+ @WithMockUser(username = "adminTest", password = "Passw0rd!", authorities = "ADMIN")
+ public void test_NotUpdateUser_withInvalidId() throws Exception {
+ // tries to update a user with invalid Id
+ mockMvc
+ .perform(get("/user/update/{id}", 0))
+ .andExpect(status().is5xxServerError());
+ }
+}