From cadcb3b3c8eb904a777ce991b6669e81e0212536 Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Tue, 22 Feb 2022 14:29:27 +0100 Subject: [PATCH 01/34] initializes database creation --- Poseiden-skeleton/doc/data.sql | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Poseiden-skeleton/doc/data.sql b/Poseiden-skeleton/doc/data.sql index 569bdeb432..a7d536ea33 100644 --- a/Poseiden-skeleton/doc/data.sql +++ b/Poseiden-skeleton/doc/data.sql @@ -1,3 +1,6 @@ +DROP database demo; +CREATE database demo; +USE demo; CREATE TABLE BidList ( BidListId tinyint(4) NOT NULL AUTO_INCREMENT, @@ -24,7 +27,7 @@ CREATE TABLE BidList ( side VARCHAR(125), PRIMARY KEY (BidListId) -) +); CREATE TABLE Trade ( TradeId tinyint(4) NOT NULL AUTO_INCREMENT, @@ -50,7 +53,7 @@ CREATE TABLE Trade ( side VARCHAR(125), PRIMARY KEY (TradeId) -) +); CREATE TABLE CurvePoint ( Id tinyint(4) NOT NULL AUTO_INCREMENT, @@ -61,7 +64,7 @@ CREATE TABLE CurvePoint ( creationDate TIMESTAMP , PRIMARY KEY (Id) -) +); CREATE TABLE Rating ( Id tinyint(4) NOT NULL AUTO_INCREMENT, @@ -71,7 +74,7 @@ CREATE TABLE Rating ( orderNumber tinyint, PRIMARY KEY (Id) -) +); CREATE TABLE RuleName ( Id tinyint(4) NOT NULL AUTO_INCREMENT, @@ -83,7 +86,7 @@ CREATE TABLE RuleName ( sqlPart VARCHAR(125), PRIMARY KEY (Id) -) +); CREATE TABLE Users ( Id tinyint(4) NOT NULL AUTO_INCREMENT, @@ -93,7 +96,7 @@ CREATE TABLE Users ( role VARCHAR(125), PRIMARY KEY (Id) -) +); -insert into Users(fullname, username, password, role) values("Administrator", "admin", "$2a$10$pBV8ILO/s/nao4wVnGLrh.sa/rnr5pDpbeC4E.KNzQWoy8obFZdaa", "ADMIN") -insert into Users(fullname, username, password, role) values("User", "user", "$2a$10$pBV8ILO/s/nao4wVnGLrh.sa/rnr5pDpbeC4E.KNzQWoy8obFZdaa", "USER") \ No newline at end of file +insert into Users(fullname, username, password, role) values("Administrator", "admin", "$2a$10$pBV8ILO/s/nao4wVnGLrh.sa/rnr5pDpbeC4E.KNzQWoy8obFZdaa", "ADMIN"); +insert into Users(fullname, username, password, role) values("User", "user", "$2a$10$pBV8ILO/s/nao4wVnGLrh.sa/rnr5pDpbeC4E.KNzQWoy8obFZdaa", "USER"); From e7be9945787b45b17859d8cdbea4d2217457add7 Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Tue, 22 Feb 2022 14:30:13 +0100 Subject: [PATCH 02/34] initializes project for initial run --- Poseiden-skeleton/pom.xml | 22 +++++++++++++++++++ .../com/nnk/springboot/domain/BidList.java | 7 +++++- .../com/nnk/springboot/domain/CurvePoint.java | 6 ++++- .../com/nnk/springboot/domain/Rating.java | 6 ++++- .../com/nnk/springboot/domain/RuleName.java | 6 ++++- .../java/com/nnk/springboot/domain/Trade.java | 6 ++++- .../src/main/resources/application.properties | 7 +++--- 7 files changed, 52 insertions(+), 8 deletions(-) diff --git a/Poseiden-skeleton/pom.xml b/Poseiden-skeleton/pom.xml index a7dcbc04dc..ff1f88c6ca 100644 --- a/Poseiden-skeleton/pom.xml +++ b/Poseiden-skeleton/pom.xml @@ -31,6 +31,11 @@ spring-boot-starter-test test + + org.springframework.security + spring-security-test + test + org.springframework.boot spring-boot-starter-data-jpa @@ -60,6 +65,23 @@ com.h2database h2 + + + javax.xml.bind + jaxb-api + + + org.javassist + javassist + 3.23.1-GA + + + + org.projectlombok + lombok + true + + diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java index 3a0e27efc8..4b572bb042 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java @@ -1,5 +1,6 @@ package com.nnk.springboot.domain; +import org.hibernate.annotations.DynamicUpdate; import org.springframework.beans.factory.annotation.Required; import javax.persistence.*; @@ -9,7 +10,11 @@ import java.sql.Timestamp; @Entity -@Table(name = "bidlist") +@Table(name = "Bidlist") public class BidList { // TODO: Map columns in data table BIDLIST with corresponding java fields + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "BidList") + private Integer BidListId; } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java index 151f80d02f..917fe87cfd 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java @@ -9,7 +9,11 @@ @Entity -@Table(name = "curvepoint") +@Table(name = "Curvepoint") public class CurvePoint { // TODO: Map columns in data table CURVEPOINT with corresponding java fields + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "Id") + private Integer id; } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java index 12d1be58c0..5e0277ec48 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java @@ -6,7 +6,11 @@ import java.sql.Timestamp; @Entity -@Table(name = "rating") +@Table(name = "Rating") public class Rating { // TODO: Map columns in data table RATING with corresponding java fields + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "Id") + private Integer id; } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/RuleName.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/RuleName.java index b8ac970edf..a0dd24048c 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/RuleName.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/RuleName.java @@ -5,7 +5,11 @@ import java.sql.Timestamp; @Entity -@Table(name = "rulename") +@Table(name = "Rulename") public class RuleName { // TODO: Map columns in data table RULENAME with corresponding java fields + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "Id") + private Integer id; } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java index b6db7c13b7..5d16306c3a 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java @@ -6,7 +6,11 @@ @Entity -@Table(name = "trade") +@Table(name = "Trade") public class Trade { // TODO: Map columns in data table TRADE with corresponding java fields + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "TradeId") + private Integer tradeId; } diff --git a/Poseiden-skeleton/src/main/resources/application.properties b/Poseiden-skeleton/src/main/resources/application.properties index 8b194cc76e..c7f1ed6d1a 100644 --- a/Poseiden-skeleton/src/main/resources/application.properties +++ b/Poseiden-skeleton/src/main/resources/application.properties @@ -3,12 +3,13 @@ logging.level.org.springframework=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?useSSL=false spring.datasource.username=root -spring.datasource.password= +spring.datasource.password=rootroot ################### Hibernate Configuration ########################## -spring.jpa.hibernate.ddl-auto=update +spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect +spring.jpa.hibernate.ddl-auto=none spring.jpa.show-sql=true From bd731d6ab35ba53f8448ee98c50797daa09f9040 Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Mon, 28 Feb 2022 10:58:43 +0100 Subject: [PATCH 03/34] adds entities implementations --- .../com/nnk/springboot/domain/BidList.java | 285 +++++++++++++++++- .../com/nnk/springboot/domain/CurvePoint.java | 93 +++++- .../com/nnk/springboot/domain/Rating.java | 69 +++++ .../com/nnk/springboot/domain/RuleName.java | 96 +++++- .../java/com/nnk/springboot/domain/Trade.java | 267 +++++++++++++++- .../java/com/nnk/springboot/domain/User.java | 9 +- 6 files changed, 810 insertions(+), 9 deletions(-) diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java index 4b572bb042..d0d3e12f32 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java @@ -1,20 +1,297 @@ package com.nnk.springboot.domain; -import org.hibernate.annotations.DynamicUpdate; +import org.hibernate.validator.constraints.Length; import org.springframework.beans.factory.annotation.Required; import javax.persistence.*; import javax.validation.constraints.Digits; import javax.validation.constraints.NotBlank; -import java.sql.Date; +import javax.validation.constraints.Past; + import java.sql.Timestamp; @Entity -@Table(name = "Bidlist") +@Table(name = "BidList") public class BidList { // TODO: Map columns in data table BIDLIST with corresponding java fields @Id + @Digits(integer=4, fraction=0) @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "BidList") + @Column(name = "BidListId") private Integer BidListId; + + @NotBlank(message = "Account is mandatory") + @Length(max=30, message = "must have 30 characters max") + @Column(name = "account") + private String account; + + @NotBlank(message = "Type is mandatory") + @Length(max=30, message = "must have 30 characters max") + @Column(name = "type") + private String type; + + @Column(name = "bidQuantity") + @Digits(integer=4, fraction = 2, message = "must be in the form 0000.00") + private Double bidQuantity; + + @Column(name = "askQuantity") + @Digits(integer=4, fraction = 2) + private Double askQuantity; + + @Column(name = "bid") + @Digits(integer=4, fraction = 2) + private Double bid; + + @Column(name = "ask") + @Digits(integer=4, fraction = 2) + private Double ask; + + @Column(name = "benchmark") + @Length(max = 125) + private String benchmark; + + @Column(name = "bidListDate") + @Past + private Timestamp bidListDate; + + @Column(name = "commentary") + @Length(max = 125) + private String commentary; + + @Column(name = "security") + @Length(max = 125) + private String security; + + @Column(name = "status") + @Length(max = 10) + private String status; + + @Column(name = "trader") + @Length(max = 125) + private String trader; + + @Column(name = "book") + @Length(max = 125) + private String book; + + @Column(name = "creationName") + @Length(max = 125) + private String creationName; + + @Column(name = "creationDate") + @Past + private Timestamp creationDate; + + @Column(name = "revisionName") + @Length(max = 125) + private String revisionName; + + @Column(name = "revisionDate") + @Past + private Timestamp revisionDate; + + @Column(name = "dealName") + @Length(max = 125) + private String dealName; + + @Column(name = "dealType") + @Length(max = 125) + private String dealType; + + @Column(name = "sourceListId") + @Length(max = 125) + private String sourceListId; + + @Column(name = "side") + @Length(max = 125) + private String side; + + public Integer getBidListId() { + return BidListId; + } + + public void setBidListId(Integer bidListId) { + BidListId = bidListId; + } + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Double getBidQuantity() { + return bidQuantity; + } + + public void setBidQuantity(Double bidQuantity) { + this.bidQuantity = bidQuantity; + } + + public Double getAskQuantity() { + return askQuantity; + } + + public void setAskQuantity(Double askQuantity) { + this.askQuantity = askQuantity; + } + + public Double getBid() { + return bid; + } + + public void setBid(Double bid) { + this.bid = bid; + } + + public Double getAsk() { + return ask; + } + + public void setAsk(Double ask) { + this.ask = ask; + } + + public String getBenchmark() { + return benchmark; + } + + public void setBenchmark(String benchmark) { + this.benchmark = benchmark; + } + + public Timestamp getBidListDate() { + return bidListDate; + } + + public void setBidListDate(Timestamp bidListDate) { + this.bidListDate = bidListDate; + } + + public String getCommentary() { + return commentary; + } + + public void setCommentary(String commentary) { + this.commentary = commentary; + } + + public String getSecurity() { + return security; + } + + public void setSecurity(String security) { + this.security = security; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getTrader() { + return trader; + } + + public void setTrader(String trader) { + this.trader = trader; + } + + public String getBook() { + return book; + } + + public void setBook(String book) { + this.book = book; + } + + public String getCreationName() { + return creationName; + } + + public void setCreationName(String creationName) { + this.creationName = creationName; + } + + public Timestamp getCreationDate() { + return creationDate; + } + + public void setCreationDate(Timestamp creationDate) { + this.creationDate = creationDate; + } + + public String getRevisionName() { + return revisionName; + } + + public void setRevisionName(String revisionName) { + this.revisionName = revisionName; + } + + public Timestamp getRevisionDate() { + return revisionDate; + } + + public void setRevisionDate(Timestamp revisionDate) { + this.revisionDate = revisionDate; + } + + public String getDealName() { + return dealName; + } + + public void setDealName(String dealName) { + this.dealName = dealName; + } + + public String getDealType() { + return dealType; + } + + public void setDealType(String dealType) { + this.dealType = dealType; + } + + public String getSourceListId() { + return sourceListId; + } + + public void setSourceListId(String sourceListId) { + this.sourceListId = sourceListId; + } + + public String getSide() { + return side; + } + + public void setSide(String side) { + this.side = side; + } + + public BidList(String account, String type, Double bidQuantity) { + super(); + this.account = account; + this.type = type; + this.bidQuantity = bidQuantity; + } + + public BidList() { + super(); + // TODO Auto-generated constructor stub + } + } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java index 917fe87cfd..b4830e5b1c 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java @@ -1,19 +1,108 @@ package com.nnk.springboot.domain; +import org.hibernate.annotations.CreationTimestamp; import org.hibernate.validator.constraints.Length; +import org.springframework.dao.DataAccessResourceFailureException; import javax.persistence.*; +import javax.validation.constraints.Digits; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +import javax.validation.constraints.Past; + import java.sql.Timestamp; @Entity -@Table(name = "Curvepoint") +@Table(name = "CurvePoint") public class CurvePoint { // TODO: Map columns in data table CURVEPOINT with corresponding java fields @Id + @Digits(integer = 4, fraction = 0) @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "Id") private Integer id; -} + + @NotNull(message = "must not be null") + @Digits(integer = 4, fraction = 0, message = "must be an integer number") + @Column(name = "CurveId") + private Integer curveId; + + @Column(name = "asOfDate") + @Past + private Timestamp asOfDate; + + @Column(name = "term") + @Digits(integer = 4, fraction = 2, message = "must be in the form 0000.00") + private Double term; + + @Column(name = "value") + @Digits(integer = 4, fraction = 2, message = "must be in the form 0000.00") + private Double value; + + @CreationTimestamp + @Past + @Column(name = "creationDate") + private Timestamp creationDate; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getCurveId() { + return curveId; + } + + public void setCurveId(Integer curveId) { + this.curveId = curveId; + } + + public Timestamp getAsOfDate() { + return asOfDate; + } + + public void setAsOfDate(Timestamp asOfDate) { + this.asOfDate = asOfDate; + } + + public double getTerm() { + return term; + } + + public void setTerm(Double term) { + this.term = term; + } + + public Double getValue() { + return value; + } + + public void setValue(Double value) { + this.value = value; + } + + public Timestamp getCreationDate() { + return creationDate; + } + + public void setCreationDate(Timestamp creationDate) { + this.creationDate = creationDate; + } + + public CurvePoint(Integer curveId, Double term, Double value) { + super(); + this.curveId = curveId; + this.term = term; + this.value = value; + } + + public CurvePoint() { + super(); + // TODO Auto-generated constructor stub + } + +} \ No newline at end of file diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java index 5e0277ec48..cffd198f01 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java @@ -1,6 +1,7 @@ package com.nnk.springboot.domain; import javax.persistence.*; +import javax.validation.constraints.Digits; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.sql.Timestamp; @@ -11,6 +12,74 @@ public class Rating { // TODO: Map columns in data table RATING with corresponding java fields @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @NotNull + @Digits(integer = 4, fraction = 0) @Column(name = "Id") private Integer id; + + @Column(name = "moodysRating") + private String moodysRating; + + @Column(name = "sandPRating") + private String sandPRating; + + @Column(name = "fitchRating") + private String fitchRating; + + @Column(name = "orderNumber") + private Integer orderNumber; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getMoodysRating() { + return moodysRating; + } + + public void setMoodysRating(String moodysRating) { + this.moodysRating = moodysRating; + } + + public String getSandPRating() { + return sandPRating; + } + + public void setSandPRating(String sandPRating) { + this.sandPRating = sandPRating; + } + + public String getFitchRating() { + return fitchRating; + } + + public void setFitchRating(String fitchRating) { + this.fitchRating = fitchRating; + } + + public Integer getOrderNumber() { + return orderNumber; + } + + public void setOrderNumber(Integer orderNumber) { + this.orderNumber = orderNumber; + } + + public Rating(String moodysRating, String sandPRating, String fitchRating, Integer orderNumber) { + super(); + this.moodysRating = moodysRating; + this.sandPRating = sandPRating; + this.fitchRating = fitchRating; + this.orderNumber = orderNumber; + } + + public Rating() { + super(); + // TODO Auto-generated constructor stub + } + } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/RuleName.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/RuleName.java index a0dd24048c..10961bd6e1 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/RuleName.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/RuleName.java @@ -1,15 +1,109 @@ package com.nnk.springboot.domain; import javax.persistence.*; +import javax.validation.constraints.Digits; import javax.validation.constraints.NotBlank; import java.sql.Timestamp; @Entity -@Table(name = "Rulename") +@Table(name = "RuleName") public class RuleName { // TODO: Map columns in data table RULENAME with corresponding java fields @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Digits(integer = 4, fraction = 0) @Column(name = "Id") private Integer id; + + @Column(name = "name") + @NotBlank + private String name; + + @Column(name = "description") + @NotBlank + private String description; + + @Column(name = "json") + private String json; + + @Column(name = "template") + private String template; + + @Column(name = "sqlStr") + private String sqlStr; + + @Column(name = "sqlPart") + private String sqlPart; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getJson() { + return json; + } + + public void setJson(String json) { + this.json = json; + } + + public String getTemplate() { + return template; + } + + public void setTemplate(String template) { + this.template = template; + } + + public String getSqlStr() { + return sqlStr; + } + + public void setSqlStr(String sqlStr) { + this.sqlStr = sqlStr; + } + + public String getSqlPart() { + return sqlPart; + } + + public void setSqlPart(String sqlPart) { + this.sqlPart = sqlPart; + } + + public RuleName(String name, String description, String json, String template, String sqlStr, String sqlPart) { + super(); + this.name = name; + this.description = description; + this.json = json; + this.template = template; + this.sqlStr = sqlStr; + this.sqlPart = sqlPart; + } + + public RuleName() { + super(); + // TODO Auto-generated constructor stub + } + } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java index 5d16306c3a..8ba0ac3e21 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java @@ -1,7 +1,13 @@ package com.nnk.springboot.domain; import javax.persistence.*; +import javax.validation.constraints.Digits; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Past; + +import org.hibernate.validator.constraints.Length; +import org.springframework.dao.DataAccessResourceFailureException; + import java.sql.Timestamp; @@ -11,6 +17,265 @@ public class Trade { // TODO: Map columns in data table TRADE with corresponding java fields @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "TradeId") + @Digits(integer = 4, fraction = 0) + @Column(name = "tradeId") private Integer tradeId; + + @NotBlank + @Length(max = 30) + @Column(name = "account") + private String account; + + @NotBlank + @Length(max = 30) + @Column(name = "type") + private String type; + + @Column(name = "buyQuantity") + private Double buyQuantity; + + @Column(name = "sellQuantity") + private Double sellQuantity; + + @Column(name = "buyPrice") + private Double buyPrice; + + @Column(name = "sellPrice") + private Double sellPrice; + + @Past + @Column(name = "tradeDate") + private Timestamp tradeDate; + + @Length(max = 125) + @Column(name = "security") + private String security; + + @Length(max = 10) + @Column(name = "status") + private String status; + + @Length(max = 125) + @Column(name = "trader") + private String trader; + + @Length(max = 125) + @Column(name = "benchmark") + private String benchmark; + + @Length(max = 125) + @Column(name = "book") + private String book; + + @Length(max = 125) + @Column(name = "creationName") + private String creationName; + + @Past + @Column(name = "creationDate") + private Timestamp creationDate; + + @Length(max = 125) + @Column(name = "revisionName") + private String revisionName; + + @Past + @Column(name = "revisionDate") + private Timestamp revisionDate; + + @Length(max = 125) + @Column(name = "dealName") + private String dealName; + + @Length(max = 125) + @Column(name = "dealType") + private String dealType; + + @Length(max = 125) + @Column(name = "sourceListId") + private String sourceListId; + + @Length(max = 125) + @Column(name = "side") + private String side; + + public Integer getTradeId() { + return tradeId; + } + + public void setTradeId(Integer tradeId) { + this.tradeId = tradeId; + } + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public double getBuyQuantity() { + return buyQuantity; + } + + public void setBuyQuantity(Double buyQuantity) { + this.buyQuantity = buyQuantity; + } + + public Double getSellQuantity() { + return sellQuantity; + } + + public void setSellQuantity(Double sellQuantity) { + this.sellQuantity = sellQuantity; + } + + public Double getBuyPrice() { + return buyPrice; + } + + public void setBuyPrice(Double buyPrice) { + this.buyPrice = buyPrice; + } + + public Double getSellPrice() { + return sellPrice; + } + + public void setSellPrice(Double sellPrice) { + this.sellPrice = sellPrice; + } + + public Timestamp getTradeDate() { + return tradeDate; + } + + public void setTradeDate(Timestamp tradeDate) { + this.tradeDate = tradeDate; + } + + public String getSecurity() { + return security; + } + + public void setSecurity(String security) { + this.security = security; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getTrader() { + return trader; + } + + public void setTrader(String trader) { + this.trader = trader; + } + + public String getBenchmark() { + return benchmark; + } + + public void setBenchmark(String benchmark) { + this.benchmark = benchmark; + } + + public String getBook() { + return book; + } + + public void setBook(String book) { + this.book = book; + } + + public String getCreationName() { + return creationName; + } + + public void setCreationName(String creationName) { + this.creationName = creationName; + } + + public Timestamp getCreationDate() { + return creationDate; + } + + public void setCreationDate(Timestamp creationDate) { + this.creationDate = creationDate; + } + + public String getRevisionName() { + return revisionName; + } + + public void setRevisionName(String revisionName) { + this.revisionName = revisionName; + } + + public Timestamp getRevisionDate() { + return revisionDate; + } + + public void setRevisionDate(Timestamp revisionDate) { + this.revisionDate = revisionDate; + } + + public String getDealName() { + return dealName; + } + + public void setDealName(String dealName) { + this.dealName = dealName; + } + + public String getDealType() { + return dealType; + } + + public void setDealType(String dealType) { + this.dealType = dealType; + } + + public String getSourceListId() { + return sourceListId; + } + + public void setSourceListId(String sourceListId) { + this.sourceListId = sourceListId; + } + + public String getSide() { + return side; + } + + public void setSide(String side) { + this.side = side; + } + + public Trade(String account, String type) { + super(); + this.account = account; + this.type = type; + } + + public Trade() { + super(); + // TODO Auto-generated constructor stub + } + } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/User.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/User.java index 2be0b8c4ab..9172e77d66 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/User.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/User.java @@ -3,19 +3,26 @@ import javax.persistence.*; import javax.validation.constraints.NotBlank; +import org.hibernate.validator.constraints.Length; + @Entity -@Table(name = "users") +@Table(name = "Users") public class User { @Id @GeneratedValue(strategy= GenerationType.AUTO) + @Column(name = "Id") private Integer id; @NotBlank(message = "Username is mandatory") + @Length(max = 125, message = "must have 125 caracters max") private String username; @NotBlank(message = "Password is mandatory") + @Length(max = 125, message = "must have 125 caracters max") private String password; @NotBlank(message = "FullName is mandatory") + @Length(max = 125, message = "must have 125 caracters max") private String fullname; @NotBlank(message = "Role is mandatory") + @Length(max = 125, message = "must have 125 caracters max") private String role; public Integer getId() { From 049f14cbf9fb8878f21e6504baa5ea75a798c489 Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Mon, 28 Feb 2022 11:03:23 +0100 Subject: [PATCH 04/34] configures logs --- .../src/main/resources/application.properties | 5 ++++- Poseiden-skeleton/src/main/resources/logback.xml | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 Poseiden-skeleton/src/main/resources/logback.xml diff --git a/Poseiden-skeleton/src/main/resources/application.properties b/Poseiden-skeleton/src/main/resources/application.properties index c7f1ed6d1a..198ab1ec31 100644 --- a/Poseiden-skeleton/src/main/resources/application.properties +++ b/Poseiden-skeleton/src/main/resources/application.properties @@ -1,5 +1,7 @@ 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 @@ -10,6 +12,7 @@ spring.datasource.password=rootroot ################### Hibernate Configuration ########################## spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect -spring.jpa.hibernate.ddl-auto=none +spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true +spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 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 From 4f6461961e6d7dc3ac5cd38a5524cd77bc7f2857 Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Mon, 28 Feb 2022 11:11:44 +0100 Subject: [PATCH 05/34] implements crud for repository package --- .../nnk/springboot/repositories/BidListRepository.java | 4 ++-- .../nnk/springboot/repositories/CurvePointRepository.java | 4 ++-- .../com/nnk/springboot/repositories/RatingRepository.java | 4 ++-- .../nnk/springboot/repositories/RuleNameRepository.java | 4 ++-- .../com/nnk/springboot/repositories/TradeRepository.java | 4 ++-- .../com/nnk/springboot/repositories/UserRepository.java | 8 +++----- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/BidListRepository.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/BidListRepository.java index f74b94e51d..1fdf3e743b 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/BidListRepository.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/BidListRepository.java @@ -1,9 +1,9 @@ package com.nnk.springboot.repositories; import com.nnk.springboot.domain.BidList; -import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.repository.CrudRepository; -public interface BidListRepository extends JpaRepository { +public interface BidListRepository extends CrudRepository { } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/CurvePointRepository.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/CurvePointRepository.java index b01751b53e..bac9c0f983 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/CurvePointRepository.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/CurvePointRepository.java @@ -1,9 +1,9 @@ package com.nnk.springboot.repositories; import com.nnk.springboot.domain.CurvePoint; -import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.repository.CrudRepository; -public interface CurvePointRepository extends JpaRepository { +public interface CurvePointRepository extends CrudRepository { } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/RatingRepository.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/RatingRepository.java index 7ded405e6d..85e14ef4b8 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/RatingRepository.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/RatingRepository.java @@ -1,8 +1,8 @@ package com.nnk.springboot.repositories; import com.nnk.springboot.domain.Rating; -import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.repository.CrudRepository; -public interface RatingRepository extends JpaRepository { +public interface RatingRepository extends CrudRepository { } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/RuleNameRepository.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/RuleNameRepository.java index 8053d1612e..6aa44db739 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/RuleNameRepository.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/RuleNameRepository.java @@ -1,8 +1,8 @@ package com.nnk.springboot.repositories; import com.nnk.springboot.domain.RuleName; -import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.repository.CrudRepository; -public interface RuleNameRepository extends JpaRepository { +public interface RuleNameRepository extends CrudRepository { } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/TradeRepository.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/TradeRepository.java index e8da38af02..bc80bc624e 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/TradeRepository.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/TradeRepository.java @@ -1,8 +1,8 @@ package com.nnk.springboot.repositories; import com.nnk.springboot.domain.Trade; -import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.repository.CrudRepository; -public interface TradeRepository extends JpaRepository { +public interface TradeRepository extends CrudRepository { } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/UserRepository.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/UserRepository.java index b6a3363949..33975a332e 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/UserRepository.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/UserRepository.java @@ -1,12 +1,10 @@ package com.nnk.springboot.repositories; import com.nnk.springboot.domain.User; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; +import org.springframework.data.repository.CrudRepository; -public interface UserRepository extends JpaRepository, JpaSpecificationExecutor { + +public interface UserRepository extends CrudRepository { } From c3555212e383a5c2c8a0309ff0e7c5c44da1dddf Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Mon, 28 Feb 2022 11:43:38 +0100 Subject: [PATCH 06/34] implements code to pass tests from BidTests --- .../com/nnk/springboot/domain/BidList.java | 6 +++ .../springboot/services/BidListService.java | 39 +++++++++++++++++++ .../src/main/resources/application.properties | 2 +- .../java/com/nnk/springboot/BidTests.java | 16 ++++---- 4 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 Poseiden-skeleton/src/main/java/com/nnk/springboot/services/BidListService.java diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java index d0d3e12f32..b4bf6f5f88 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java @@ -293,5 +293,11 @@ public BidList() { super(); // TODO Auto-generated constructor stub } + + @Override + public String toString() { + return "BidList [account=" + account + ", type=" + type + ", bidQuantity=" + + bidQuantity + "]"; + } } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/BidListService.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/BidListService.java new file mode 100644 index 0000000000..1d330659ad --- /dev/null +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/BidListService.java @@ -0,0 +1,39 @@ +package com.nnk.springboot.services; + +import java.util.Optional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.nnk.springboot.domain.BidList; +import com.nnk.springboot.repositories.BidListRepository; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Service +public class BidListService { + + @Autowired + private BidListRepository bidListRepository; + + public Iterable findAllBidLists() { + log.info("All BidLists retrieved from database"); + return bidListRepository.findAll(); + } + + public Optional findBidListById(Integer id) { + log.info("BidList with id: " + id + " retrieved from database"); + return bidListRepository.findById(id); + } + + public BidList saveBidList(BidList bidList) { + log.info("BidList: " + bidList.toString() + " saved in database"); + return bidListRepository.save(bidList); + } + + public void deleteBidList(BidList bidList) { + log.info("BidList: " + bidList.toString() + " deleted in database"); + bidListRepository.delete(bidList); + } +} diff --git a/Poseiden-skeleton/src/main/resources/application.properties b/Poseiden-skeleton/src/main/resources/application.properties index 198ab1ec31..e8de928cfd 100644 --- a/Poseiden-skeleton/src/main/resources/application.properties +++ b/Poseiden-skeleton/src/main/resources/application.properties @@ -5,7 +5,7 @@ logging.level.com.nnk=info ################### DataSource Configuration ########################## spring.datasource.driver-class-name=com.mysql.jdbc.Driver -spring.datasource.url=jdbc:mysql://localhost:3306/demo?useSSL=false +spring.datasource.url=jdbc:mysql://localhost:3306/demo?allowPublicKeyRetrieval=true&useSSL=false spring.datasource.username=root spring.datasource.password=rootroot 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()); } } From c9b294af6f63fa06c09f3e15e0c2d601ccdba147 Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Mon, 28 Feb 2022 11:51:54 +0100 Subject: [PATCH 07/34] implements code to pass tests from CurvePointTests --- .../com/nnk/springboot/domain/CurvePoint.java | 7 +++- .../services/CurvePointService.java | 39 +++++++++++++++++++ .../com/nnk/springboot/CurvePointTests.java | 16 ++++---- 3 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 Poseiden-skeleton/src/main/java/com/nnk/springboot/services/CurvePointService.java diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java index b4830e5b1c..b0dc8aadb0 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java @@ -104,5 +104,10 @@ public CurvePoint() { super(); // TODO Auto-generated constructor stub } - + + @Override + public String toString() { + return "CurvePoint [curveId=" + curveId + ", term=" + term + ", value=" + value + "]"; + } + } \ No newline at end of file diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/CurvePointService.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/CurvePointService.java new file mode 100644 index 0000000000..6a9999ebf9 --- /dev/null +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/CurvePointService.java @@ -0,0 +1,39 @@ +package com.nnk.springboot.services; + +import java.util.Optional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.nnk.springboot.domain.CurvePoint; +import com.nnk.springboot.repositories.CurvePointRepository; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Service +public class CurvePointService { + + @Autowired + private CurvePointRepository curvePointRepository; + + public Iterable findAllCurvePoints() { + log.info("All CurvePoint retrieved from database"); + return curvePointRepository.findAll(); + } + + public Optional findCurvePointById(Integer id) { + log.info("CurvePoint with id: " + id + " retrieved from database"); + return curvePointRepository.findById(id); + } + + public CurvePoint saveCurvePoint(CurvePoint curvePoint) { + log.info("CurvePoint: " + curvePoint.toString() + " saved in database"); + return curvePointRepository.save(curvePoint); + } + + public void deleteCurvePoint(CurvePoint curvePoint) { + log.info("CurvePoint: " + curvePoint.toString() + " deleted in database"); + curvePointRepository.delete(curvePoint); + } +} 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()); } From 973bd7dc1fe901778a66b007a7eebab51d8cab21 Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Mon, 28 Feb 2022 11:56:52 +0100 Subject: [PATCH 08/34] implements code to pass tests from RatingTests --- .../com/nnk/springboot/domain/Rating.java | 6 +++ .../springboot/services/RatingService.java | 39 +++++++++++++++++++ .../java/com/nnk/springboot/RatingTests.java | 16 ++++---- 3 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 Poseiden-skeleton/src/main/java/com/nnk/springboot/services/RatingService.java diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java index cffd198f01..5a460efd0e 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java @@ -81,5 +81,11 @@ public Rating() { super(); // TODO Auto-generated constructor stub } + + @Override + public String toString() { + return "Rating [moodysRating=" + moodysRating + ", sandPRating=" + sandPRating + ", fitchRating=" + fitchRating + + ", orderNumber=" + orderNumber + "]"; + } } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/RatingService.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/RatingService.java new file mode 100644 index 0000000000..308fa76cef --- /dev/null +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/RatingService.java @@ -0,0 +1,39 @@ +package com.nnk.springboot.services; + +import java.util.Optional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.nnk.springboot.domain.Rating; +import com.nnk.springboot.repositories.RatingRepository; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Service +public class RatingService { + + @Autowired + private RatingRepository ratingRepository; + + public Iterable findAllRatings() { + log.info("All Rating retrieved from database"); + return ratingRepository.findAll(); + } + + public Optional findRatingById(Integer id) { + log.info("Rating with id: " + id + " retrieved from database"); + return ratingRepository.findById(id); + } + + public Rating saveRating(Rating rating) { + log.info("Rating: " + rating.toString() + " saved in database"); + return ratingRepository.save(rating); + } + + public void deleteRating(Rating rating) { + log.info("Rating: " + rating.toString() + " deleted in database"); + ratingRepository.delete(rating); + } +} 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()); } } From a2f07e80c00010eaf2fc01a648c8aef4f44e2f31 Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Mon, 28 Feb 2022 12:05:42 +0100 Subject: [PATCH 09/34] implements code to pass tests from RuleTests --- .../com/nnk/springboot/domain/RuleName.java | 9 ++++- .../springboot/services/RuleNameService.java | 40 +++++++++++++++++++ .../java/com/nnk/springboot/RuleTests.java | 16 ++++---- 3 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 Poseiden-skeleton/src/main/java/com/nnk/springboot/services/RuleNameService.java diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/RuleName.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/RuleName.java index 10961bd6e1..018a415e12 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/RuleName.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/RuleName.java @@ -91,7 +91,8 @@ public void setSqlPart(String sqlPart) { this.sqlPart = sqlPart; } - public RuleName(String name, String description, String json, String template, String sqlStr, String sqlPart) { + public RuleName(String name, String description, String json, String template, String sqlStr, + String sqlPart) { super(); this.name = name; this.description = description; @@ -105,5 +106,11 @@ public RuleName() { super(); // TODO Auto-generated constructor stub } + + @Override + public String toString() { + return "RuleName [name=" + name + ", description=" + description + ", json=" + json + ", template=" + template + + ", sqlStr=" + sqlStr + ", sqlPart=" + sqlPart + "]"; + } } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/RuleNameService.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/RuleNameService.java new file mode 100644 index 0000000000..9b90285366 --- /dev/null +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/RuleNameService.java @@ -0,0 +1,40 @@ +package com.nnk.springboot.services; + +import java.util.Optional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.nnk.springboot.domain.RuleName; +import com.nnk.springboot.repositories.RuleNameRepository; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Service +public class RuleNameService { + + @Autowired + private RuleNameRepository ruleNameRepository; + + public Iterable findAllRuleNames() { + log.info("All RuleName retrieved from database"); + return ruleNameRepository.findAll(); + } + + // a revoir + public Optional findRuleNameById(Integer id) { + log.info("RuleName with id: " + id + " retrieved from database"); + return ruleNameRepository.findById(id); + } + + public RuleName saveRuleName(RuleName ruleName) { + log.info("RuleName: " + ruleName.toString() + " saved in database"); + return ruleNameRepository.save(ruleName); + } + + public void deleteRuleName(RuleName ruleName) { + log.info("RuleName: " + ruleName.toString() + " deleted in database"); + ruleNameRepository.delete(ruleName); + } +} 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()); } } From 1cbabe925daa18d5e5118295ed8c12cee721ad1a Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Mon, 28 Feb 2022 12:09:07 +0100 Subject: [PATCH 10/34] implements code to pass tests from TradeTests --- .../java/com/nnk/springboot/domain/Trade.java | 5 +++ .../nnk/springboot/services/TradeService.java | 39 +++++++++++++++++++ .../java/com/nnk/springboot/TradeTests.java | 16 ++++---- 3 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 Poseiden-skeleton/src/main/java/com/nnk/springboot/services/TradeService.java diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java index 8ba0ac3e21..0d53554921 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java @@ -277,5 +277,10 @@ public Trade() { super(); // TODO Auto-generated constructor stub } + + @Override + public String toString() { + return "Trade [account=" + account + ", type=" + type + "]"; + } } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/TradeService.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/TradeService.java new file mode 100644 index 0000000000..9c515bfbc6 --- /dev/null +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/TradeService.java @@ -0,0 +1,39 @@ +package com.nnk.springboot.services; + +import java.util.Optional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.nnk.springboot.domain.Trade; +import com.nnk.springboot.repositories.TradeRepository; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Service +public class TradeService { + + @Autowired + private TradeRepository tradeRepository; + + public Iterable findAllTrades() { + log.info("All Trade retrieved from database"); + return tradeRepository.findAll(); + } + + public Optional findTradeById(Integer id) { + log.info("Trade with id: " + id + " from database"); + return tradeRepository.findById(id); + } + + public Trade saveTrade(Trade trade) { + log.info("Trade: " + trade.toString() + " saved in database"); + return tradeRepository.save(trade); + } + + public void deleteTrade(Trade trade) { + log.info("Trade: " + trade.toString() + " deleted in database"); + tradeRepository.delete(trade); + } +} 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..e69c4538a3 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"); // 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()); } } From f881360409a5df7cbfcade7ffef949300b2fda15 Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Mon, 28 Feb 2022 12:43:18 +0100 Subject: [PATCH 11/34] implements code to pass tests from UserTests --- .../java/com/nnk/springboot/domain/User.java | 24 +++++++++ .../nnk/springboot/services/UserService.java | 39 +++++++++++++++ .../java/com/nnk/springboot/UserTests.java | 50 +++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 Poseiden-skeleton/src/main/java/com/nnk/springboot/services/UserService.java create mode 100644 Poseiden-skeleton/src/test/java/com/nnk/springboot/UserTests.java diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/User.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/User.java index 9172e77d66..7eaf74303e 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/User.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/User.java @@ -64,4 +64,28 @@ public String getRole() { public void setRole(String role) { this.role = role; } + + public User( + @NotBlank(message = "Username is mandatory") @Length(max = 125, message = "must have 125 caracters max") String username, + @NotBlank(message = "Password is mandatory") @Length(max = 125, message = "must have 125 caracters max") String password, + @NotBlank(message = "FullName is mandatory") @Length(max = 125, message = "must have 125 caracters max") String fullname, + @NotBlank(message = "Role is mandatory") @Length(max = 125, message = "must have 125 caracters max") String role) { + super(); + this.username = username; + this.password = password; + this.fullname = fullname; + this.role = role; + } + + public User() { + super(); + // TODO Auto-generated constructor stub + } + + @Override + public String toString() { + return "User [username=" + username + ", password=" + password + ", fullname=" + fullname + ", role=" + role + + "]"; + } + } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/UserService.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/UserService.java new file mode 100644 index 0000000000..d46a9a1cd0 --- /dev/null +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/UserService.java @@ -0,0 +1,39 @@ +package com.nnk.springboot.services; + +import java.util.Optional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.nnk.springboot.domain.User; +import com.nnk.springboot.repositories.UserRepository; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Service +public class UserService { + + @Autowired + private UserRepository userRepository; + + public Iterable findAllUsers() { + log.info("All User retrieved from database"); + return userRepository.findAll(); + } + + public Optional 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/test/java/com/nnk/springboot/UserTests.java b/Poseiden-skeleton/src/test/java/com/nnk/springboot/UserTests.java new file mode 100644 index 0000000000..99316107ce --- /dev/null +++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/UserTests.java @@ -0,0 +1,50 @@ +package com.nnk.springboot; + +import com.nnk.springboot.domain.Trade; +import com.nnk.springboot.domain.User; +import com.nnk.springboot.services.TradeService; +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", "password", "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()); + } +} From ae2bea718662c51553af784dc876401f396d1c05 Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Thu, 3 Mar 2022 11:21:40 +0100 Subject: [PATCH 12/34] deactivates security --- Poseiden-skeleton/pom.xml | 2 ++ .../com/nnk/springboot/controllers/UserController.java | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Poseiden-skeleton/pom.xml b/Poseiden-skeleton/pom.xml index ff1f88c6ca..9073a27a7d 100644 --- a/Poseiden-skeleton/pom.xml +++ b/Poseiden-skeleton/pom.xml @@ -48,10 +48,12 @@ org.springframework.boot spring-boot-starter-thymeleaf + org.springframework.boot spring-boot-devtools diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/UserController.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/UserController.java index 29e30be3d6..cd39657e00 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/UserController.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/UserController.java @@ -1,9 +1,10 @@ package com.nnk.springboot.controllers; import com.nnk.springboot.domain.User; + import com.nnk.springboot.repositories.UserRepository; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; @@ -31,6 +32,7 @@ public String addUser(User bid) { return "user/add"; } + /* @PostMapping("/user/validate") public String validate(@Valid User user, BindingResult result, Model model) { if (!result.hasErrors()) { @@ -42,6 +44,7 @@ public String validate(@Valid User user, BindingResult result, Model model) { } return "user/add"; } + */ @GetMapping("/user/update/{id}") public String showUpdateForm(@PathVariable("id") Integer id, Model model) { @@ -51,6 +54,7 @@ public String showUpdateForm(@PathVariable("id") Integer id, Model model) { return "user/update"; } + /* @PostMapping("/user/update/{id}") public String updateUser(@PathVariable("id") Integer id, @Valid User user, BindingResult result, Model model) { @@ -65,6 +69,7 @@ public String updateUser(@PathVariable("id") Integer id, @Valid User user, model.addAttribute("users", userRepository.findAll()); return "redirect:/user/list"; } + */ @GetMapping("/user/delete/{id}") public String deleteUser(@PathVariable("id") Integer id, Model model) { From 54864175f1ed328413cf09d5230c93f5b310ab98 Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Thu, 3 Mar 2022 12:58:34 +0100 Subject: [PATCH 13/34] implements front for BidList entity --- .../controllers/BidListController.java | 129 ++++++++++++------ .../com/nnk/springboot/domain/BidList.java | 2 + .../main/resources/templates/bidList/add.html | 78 +++++++++-- .../resources/templates/bidList/list.html | 11 +- .../resources/templates/bidList/update.html | 56 +++++++- 5 files changed, 215 insertions(+), 61 deletions(-) diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/BidListController.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/BidListController.java index a31b9b53ca..aeed6dfeaa 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/BidListController.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/BidListController.java @@ -1,6 +1,11 @@ package com.nnk.springboot.controllers; import com.nnk.springboot.domain.BidList; + + +import com.nnk.springboot.services.BidListService; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; @@ -11,45 +16,91 @@ import javax.validation.Valid; - @Controller public class BidListController { - // TODO: Inject Bid service - - @RequestMapping("/bidList/list") - public String home(Model model) - { - // TODO: call service find all bids to show to the view - return "bidList/list"; - } - - @GetMapping("/bidList/add") - public String addBidForm(BidList bid) { - return "bidList/add"; - } - - @PostMapping("/bidList/validate") - public String validate(@Valid BidList bid, BindingResult result, Model model) { - // TODO: check data valid and save to db, after saving return bid list - return "bidList/add"; - } - - @GetMapping("/bidList/update/{id}") - public String showUpdateForm(@PathVariable("id") Integer id, Model model) { - // TODO: get Bid by Id and to model then show to the form - return "bidList/update"; - } - - @PostMapping("/bidList/update/{id}") - public String updateBid(@PathVariable("id") Integer id, @Valid BidList bidList, - BindingResult result, Model model) { - // TODO: check required fields, if valid call service to update Bid and return list Bid - return "redirect:/bidList/list"; - } - - @GetMapping("/bidList/delete/{id}") - public String deleteBid(@PathVariable("id") Integer id, Model model) { - // TODO: Find Bid by Id and delete the bid, return to Bid list - return "redirect:/bidList/list"; - } + + @Autowired + private BidListService bidListService; + + /** + * displays BidList list retrieved from database + */ + @RequestMapping("/bidList/list") + public String home(Model model) { + model.addAttribute("bidLists", bidListService.findAllBidLists()); + return "bidList/list"; + } + + /** + * displays form for new BidList to add + */ + @GetMapping("/bidList/add") + public String addBidForm(BidList bid) { + return "bidList/add"; + } + + /** + * validates new BidList + * + * @param bid: BidList to create and save + * @param result: form result to validate + * @return BidList list displayed if validated, new add form with errors + * displayed else + */ + @PostMapping("/bidList/validate") + public String validate(@Valid BidList bid, BindingResult result, Model model) { + if(!result.hasErrors()) { + bidListService.saveBidList(bid); + model.addAttribute("bidLists", bidListService.findAllBidLists()); + return "redirect:/bidList/list"; + } + return "/bidList/add"; + } + + /** + * displays BidList form to update + * + * @param id : id of the BidList to update + * @return return BidList form to update + */ + @GetMapping("/bidList/update/{id}") + public String showUpdateForm(@PathVariable("id") Integer id, Model model) { + BidList bidList = bidListService.findBidListById(id).orElseThrow(() -> new IllegalArgumentException("Invalid bidList Id:" + id)); + model.addAttribute("bidList", bidList); + return "bidList/update"; + } + + /** + * validates updated BidList + * + * @param id : id of the BidList to update + * @param bidList : BidList to validate + * @param result : form result to validate + * @return BidList list with this BidList updated, BidList to update form + * with errors displayed else + */ + @PostMapping("/bidList/update/{id}") + public String updateBid(@PathVariable("id") Integer id, @Valid BidList bidList, + BindingResult result, Model model) { + if(result.hasErrors()) { + return "/bidList/update"; + } + bidList.setBidListId(id); + bidListService.saveBidList(bidList); + return "redirect:/bidList/list"; + } + + /** + * deletes selected BidList from database + * + * @param id: id of the BidList to delete + * @return the BidList list after selected BidList deleted + */ + @GetMapping("/bidList/delete/{id}") + public String deleteBid(@PathVariable("id") Integer id, Model model) { + BidList bidList = bidListService.findBidListById(id).orElseThrow(() -> new IllegalArgumentException("Invalid bidList Id:" + id)); + bidListService.deleteBidList(bidList); + model.addAttribute("bidList", bidList); + return "redirect:/bidList/list"; + } } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java index b4bf6f5f88..cfe594405d 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java @@ -6,6 +6,7 @@ import javax.persistence.*; import javax.validation.constraints.Digits; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; import javax.validation.constraints.Past; import java.sql.Timestamp; @@ -31,6 +32,7 @@ public class BidList { private String type; @Column(name = "bidQuantity") + @NotNull(message = "must not be null") @Digits(integer=4, fraction = 2, message = "must be in the form 0000.00") private Double bidQuantity; 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

-
+
+
+

Add New Bid

+
+
+ +
+
+
+ +
+ + +
+ + +

Account error

+
+
+
+ + +
+ + +

Type error

+
+
+
+ + +
+ -
- - - +

Bid Quantity error

+
+
+
+
+ Cancel + +
+
+ +
+
-
\ 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..d6ad88a075 100644 --- a/Poseiden-skeleton/src/main/resources/templates/bidList/list.html +++ b/Poseiden-skeleton/src/main/resources/templates/bidList/list.html @@ -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 @@
+

Update Bid

+
-
- -
+
+
+
+ + +
+ + +

Account error

+
+
+
+ + +
+ + +

Type error

+
+
+
+ + +
+ + +

Bid Quantity error

+
+
+
+
+ Cancel + +
+
+
+
+
- + \ No newline at end of file From 870bf75a32eaad51d6fed9283157a910d6514fa9 Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Thu, 3 Mar 2022 14:55:36 +0100 Subject: [PATCH 14/34] implements front for CurvePoint entity --- .../controllers/CurveController.java | 66 ++++++++++++++-- .../com/nnk/springboot/domain/CurvePoint.java | 6 +- .../resources/templates/curvePoint/add.html | 75 +++++++++++++++---- .../resources/templates/curvePoint/list.html | 11 +++ .../templates/curvePoint/update.html | 48 +++++++++++- 5 files changed, 176 insertions(+), 30 deletions(-) diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/CurveController.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/CurveController.java index db69caf549..cf997d37f7 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/CurveController.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/CurveController.java @@ -1,6 +1,9 @@ package com.nnk.springboot.controllers; import com.nnk.springboot.domain.CurvePoint; +import com.nnk.springboot.services.CurvePointService; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; @@ -13,42 +16,91 @@ @Controller public class CurveController { - // TODO: Inject Curve Point service + @Autowired + private CurvePointService curvePointService; + /** + * + * displays CurvePoint list retrieved from database + * + */ @RequestMapping("/curvePoint/list") public String home(Model model) { - // TODO: find all Curve Point, add to model + model.addAttribute("curvePoints", curvePointService.findAllCurvePoints()); return "curvePoint/list"; } + /** + * displays CurvePoint to add + */ @GetMapping("/curvePoint/add") - public String addBidForm(CurvePoint bid) { + public String addBidForm(CurvePoint curvePoint) { return "curvePoint/add"; } + /** + * validates new CurvePoint + * + * @param curvePoint: CurvePoint to create and save + * @param result: form result to validate + * @return CurvePoint list displayed if validated, new add form with errors + * displayed else + */ @PostMapping("/curvePoint/validate") public String validate(@Valid CurvePoint curvePoint, BindingResult result, Model model) { - // TODO: check data valid and save to db, after saving return Curve list + if(!result.hasErrors()) { + curvePointService.saveCurvePoint(curvePoint); + model.addAttribute("curvePoints", curvePointService.findAllCurvePoints()); + return "redirect:/curvePoint/list"; + } return "curvePoint/add"; } + /** + * displays CurvePoint form to update + * + * @param id : id of the CurvePoint to update + * @return return CurvePoint form to update + */ @GetMapping("/curvePoint/update/{id}") public String showUpdateForm(@PathVariable("id") Integer id, Model model) { - // TODO: get CurvePoint by Id and to model then show to the form + CurvePoint curvePoint = curvePointService.findCurvePointById(id).orElseThrow(() -> new IllegalArgumentException("Invalid bidList Id:" + id)); + model.addAttribute("curvePoint", curvePoint); return "curvePoint/update"; } + /** + * validates updated CurvePoint + * + * @param id : id of the CurvePoint to update + * @param curvePoint : CurvePoint to validate + * @param result : form result to validate + * @return CurvePoint list with this CurvePoint updated, CurvePoint to + * update form with errors displayed else + */ @PostMapping("/curvePoint/update/{id}") public String updateBid(@PathVariable("id") Integer id, @Valid CurvePoint curvePoint, BindingResult result, Model model) { - // TODO: check required fields, if valid call service to update Curve and return Curve list + if(result.hasErrors()) { + return "/curvePoint/update"; + } + curvePoint.setId(id); + curvePointService.saveCurvePoint(curvePoint); return "redirect:/curvePoint/list"; } + /** + * deletes selected CurvePoint from database + * + * @param id: id of the CurvePoint to delete + * @return the CurvePoint list after selected CurvePoint deleted + */ @GetMapping("/curvePoint/delete/{id}") public String deleteBid(@PathVariable("id") Integer id, Model model) { - // TODO: Find Curve by Id and delete the Curve, return to Curve list + CurvePoint curvePoint = curvePointService.findCurvePointById(id).orElseThrow(() -> new IllegalArgumentException("Invalid bidList Id:" + id)); + curvePointService.deleteCurvePoint(curvePoint); + model.addAttribute("curvePoint", curvePoint); return "redirect:/curvePoint/list"; } } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java index b0dc8aadb0..831daba957 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java @@ -1,12 +1,10 @@ package com.nnk.springboot.domain; import org.hibernate.annotations.CreationTimestamp; -import org.hibernate.validator.constraints.Length; import org.springframework.dao.DataAccessResourceFailureException; import javax.persistence.*; import javax.validation.constraints.Digits; -import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Past; @@ -32,10 +30,12 @@ public class CurvePoint { @Past private Timestamp asOfDate; + @NotNull(message = "must not be null") @Column(name = "term") @Digits(integer = 4, fraction = 2, message = "must be in the form 0000.00") private Double term; + @NotNull(message = "must not be null") @Column(name = "value") @Digits(integer = 4, fraction = 2, message = "must be in the form 0000.00") private Double value; @@ -69,7 +69,7 @@ public void setAsOfDate(Timestamp asOfDate) { this.asOfDate = asOfDate; } - public double getTerm() { + public Double getTerm() { return term; } 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

+
+
-
-
- +
+
+ +
+ - -
+
+ + +

Curve Id error

+
+
+
+ + +
+ + +

Term error

+
+
+
+ -
+
+ + +

Value error

+
+
+
+
+ Cancel + +
+
+ + +
+
+ +
\ 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..ffed1a6156 100644 --- a/Poseiden-skeleton/src/main/resources/templates/curvePoint/list.html +++ b/Poseiden-skeleton/src/main/resources/templates/curvePoint/list.html @@ -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 @@
+

Update CurvePoint

- +
+
+
- +
+ + +
+ + +

Curve Id error

+
+
+
+ + +
+ + +

Term error

+
+
+
+ + +
+ + +

Value error

+
+
+
+
+ Cancel + +
+
+
From 95e16081e4281a21aaa5037a10d0e6bf0bf5b08e Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Fri, 4 Mar 2022 10:08:42 +0100 Subject: [PATCH 15/34] implements front for Rating entity --- .../controllers/RatingController.java | 67 ++++++++++++-- .../com/nnk/springboot/domain/Rating.java | 8 +- .../main/resources/templates/rating/add.html | 88 +++++++++++++++---- .../main/resources/templates/rating/list.html | 12 ++- .../resources/templates/rating/update.html | 87 ++++++++++++++---- 5 files changed, 218 insertions(+), 44 deletions(-) diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/RatingController.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/RatingController.java index 5e15e68fbc..c721b26c34 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/RatingController.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/RatingController.java @@ -1,6 +1,9 @@ package com.nnk.springboot.controllers; import com.nnk.springboot.domain.Rating; +import com.nnk.springboot.services.RatingService; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; @@ -13,42 +16,90 @@ @Controller public class RatingController { - // TODO: Inject Rating service + @Autowired + private RatingService ratingService; + /** + * displays Rating list retrieved from database + */ @RequestMapping("/rating/list") - public String home(Model model) - { - // TODO: find all Rating, add to model + public String home(Model model) { + model.addAttribute("ratings", ratingService.findAllRatings()); return "rating/list"; } + /** + * displays form for new Rating to add + */ @GetMapping("/rating/add") public String addRatingForm(Rating rating) { return "rating/add"; } + /** + * validates new Rating + * + * @param rating: Rating to create and save + * @param result: form result to validate + * @return Rating list displayed if validated, new add form with errors + * displayed else + */ @PostMapping("/rating/validate") public String validate(@Valid Rating rating, BindingResult result, Model model) { - // TODO: check data valid and save to db, after saving return Rating list + if(!result.hasErrors()) { + ratingService.saveRating(rating); + model.addAttribute("ratings", ratingService.findAllRatings()); + return "redirect:/rating/list"; + } return "rating/add"; } + /** + * displays Rating form to update + * + * @param id : id of the Rating to update + * @return return Rating form to update + */ @GetMapping("/rating/update/{id}") public String showUpdateForm(@PathVariable("id") Integer id, Model model) { - // TODO: get Rating by Id and to model then show to the form + Rating rating = ratingService.findRatingById(id).orElseThrow(() -> new IllegalArgumentException("Invalid rating Id:" + id)); + model.addAttribute("rating", rating); return "rating/update"; } + + /** + * validates updated Rating + * + * @param id : id of the Rating to update + * @param rating : Rating to validate + * @param result : form result to validate + * @return Rating list with this Rating updated, Rating to update form + * with errors displayed else + */ @PostMapping("/rating/update/{id}") public String updateRating(@PathVariable("id") Integer id, @Valid Rating rating, BindingResult result, Model model) { - // TODO: check required fields, if valid call service to update Rating and return Rating list + if(result.hasErrors()) { + return "/rating/update"; + } + rating.setId(id); + ratingService.saveRating(rating); + model.addAttribute("ratings", ratingService.findAllRatings()); return "redirect:/rating/list"; } + /** + * deletes selected Rating from database + * + * @param id: id of the Rating to delete + * @return the Rating list after selected Rating deleted + */ @GetMapping("/rating/delete/{id}") public String deleteRating(@PathVariable("id") Integer id, Model model) { - // TODO: Find Rating by Id and delete the Rating, return to Rating list + Rating rating = ratingService.findRatingById(id).orElseThrow(() -> new IllegalArgumentException("Invalid rating Id:" + id)); + ratingService.deleteRating(rating); + model.addAttribute("ratings", ratingService.findAllRatings()); return "redirect:/rating/list"; } } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java index 5a460efd0e..bd4d91d03f 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java @@ -1,31 +1,33 @@ package com.nnk.springboot.domain; import javax.persistence.*; + import javax.validation.constraints.Digits; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; -import java.sql.Timestamp; @Entity @Table(name = "Rating") public class Rating { - // TODO: Map columns in data table RATING with corresponding java fields @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @NotNull @Digits(integer = 4, fraction = 0) @Column(name = "Id") private Integer id; + @NotBlank(message = "MoodysRating is mandatory") @Column(name = "moodysRating") private String moodysRating; + @NotBlank(message = "SandRating is mandatory") @Column(name = "sandPRating") private String sandPRating; + @NotBlank(message = "FitchRating is mandatory") @Column(name = "fitchRating") private String fitchRating; + @NotNull(message = "must not be null") @Column(name = "orderNumber") private Integer orderNumber; 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

-
+
+
+

Add New Rating

+
+
+
+
+
+
+ -
- - +
+ - -
+

MoodysRating + error

+
+
+
+ + +
+ + +

SandPRating + error

+
+
+
+ + +
+ -
+

FitchRating + error

+
+
+
+ + +
+ + +

Order + Number error

+
+
+
+
+ Cancel +
+
+ + +
+
+ +
\ 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..643f484c04 100644 --- a/Poseiden-skeleton/src/main/resources/templates/rating/list.html +++ b/Poseiden-skeleton/src/main/resources/templates/rating/list.html @@ -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 + -
+
+
+
+

Update Rating

+
+
+
+
+
+
+ -
-

Update Rating

-
+
+ -
- - - -
+

MoodysRating error

+
+
+
+ + +
+ + +

SandPRating error

+
+
+
+ -
+
+ + +

FitchRating error

+
+
+
+ + +
+ + +

Order Number error

+
+
+
+
+ Cancel +
+
+ +
+
+
\ No newline at end of file From 97e7c608e32eff1fc2905b04959b5dadaca7f04e Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Fri, 4 Mar 2022 10:50:45 +0100 Subject: [PATCH 16/34] implements front for RuleName entity --- .../controllers/RuleNameController.java | 128 ++++++++++++------ .../com/nnk/springboot/domain/RuleName.java | 8 +- .../resources/templates/ruleName/add.html | 106 ++++++++++++--- .../resources/templates/ruleName/list.html | 14 +- .../resources/templates/ruleName/update.html | 108 ++++++++++++--- 5 files changed, 291 insertions(+), 73 deletions(-) diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/RuleNameController.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/RuleNameController.java index b9e72b1ba6..74ed599014 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/RuleNameController.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/RuleNameController.java @@ -1,6 +1,9 @@ package com.nnk.springboot.controllers; import com.nnk.springboot.domain.RuleName; +import com.nnk.springboot.services.RuleNameService; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; @@ -13,42 +16,91 @@ @Controller public class RuleNameController { - // TODO: Inject RuleName service - - @RequestMapping("/ruleName/list") - public String home(Model model) - { - // TODO: find all RuleName, add to model - return "ruleName/list"; - } - - @GetMapping("/ruleName/add") - public String addRuleForm(RuleName bid) { - return "ruleName/add"; - } - - @PostMapping("/ruleName/validate") - public String validate(@Valid RuleName ruleName, BindingResult result, Model model) { - // TODO: check data valid and save to db, after saving return RuleName list - return "ruleName/add"; - } - - @GetMapping("/ruleName/update/{id}") - public String showUpdateForm(@PathVariable("id") Integer id, Model model) { - // TODO: get RuleName by Id and to model then show to the form - return "ruleName/update"; - } - - @PostMapping("/ruleName/update/{id}") - public String updateRuleName(@PathVariable("id") Integer id, @Valid RuleName ruleName, - BindingResult result, Model model) { - // TODO: check required fields, if valid call service to update RuleName and return RuleName list - return "redirect:/ruleName/list"; - } - - @GetMapping("/ruleName/delete/{id}") - public String deleteRuleName(@PathVariable("id") Integer id, Model model) { - // TODO: Find RuleName by Id and delete the RuleName, return to Rule list - return "redirect:/ruleName/list"; - } + @Autowired + private RuleNameService ruleNameService; + + /** + * displays RuleName list retrieved from database + */ + @RequestMapping("/ruleName/list") + public String home(Model model) { + model.addAttribute("ruleNames", ruleNameService.findAllRuleNames()); + return "ruleName/list"; + } + + /** + * displays RuleName to add + */ + @GetMapping("/ruleName/add") + public String addRuleForm(RuleName bid) { + return "ruleName/add"; + } + + /** + * validates new RuleName + * + * @param ruleName: RuleName to create and save + * @param result: form result to validate + * @return RuleName list displayed if validated, new add form with errors + * displayed else + */ + @PostMapping("/ruleName/validate") + public String validate(@Valid RuleName ruleName, BindingResult result, Model model) { + if (!result.hasErrors()) { + ruleNameService.saveRuleName(ruleName); + model.addAttribute("ruleNames", ruleNameService.findAllRuleNames()); + return "redirect:/ruleName/list"; + } + return "ruleName/add"; + } + + /** + * displays RuleName form to update + * + * @param id : id of the RuleName to update + * @return return RuleName form to update + */ + @GetMapping("/ruleName/update/{id}") + public String showUpdateForm(@PathVariable("id") Integer id, Model model) { + RuleName ruleName = ruleNameService.findRuleNameById(id) + .orElseThrow(() -> new IllegalArgumentException("Invalid ruleName Id:" + id)); + model.addAttribute("ruleName", ruleName); + return "ruleName/update"; + } + + /** + * validates updated RuleName + * + * @param id : id of the RuleName to update + * @param rulName : RuleName to validate + * @param result : form result to validate + * @return RuleName list with this RuleName updated, RuleName to update form + * with errors displayed else + */ + @PostMapping("/ruleName/update/{id}") + public String updateRuleName(@PathVariable("id") Integer id, @Valid RuleName ruleName, + BindingResult result, Model model) { + if (result.hasErrors()) { + return "/ruleName/update"; + } + ruleName.setId(id); + ruleNameService.saveRuleName(ruleName); + model.addAttribute("ruleNames", ruleNameService.findAllRuleNames()); + return "redirect:/ruleName/list"; + } + + /** + * deletes selected RuleName from database + * + * @param id: id of the RuleName to delete + * @return the RuleName list after selected RuleName deleted + */ + @GetMapping("/ruleName/delete/{id}") + public String deleteRuleName(@PathVariable("id") Integer id, Model model) { + RuleName ruleName = ruleNameService.findRuleNameById(id) + .orElseThrow(() -> new IllegalArgumentException("Invalid ruleName Id:" + id)); + ruleNameService.deleteRuleName(ruleName); + model.addAttribute("ruleNames", ruleNameService.findAllRuleNames()); + return "redirect:/ruleName/list"; + } } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/RuleName.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/RuleName.java index 018a415e12..26c63b1fef 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/RuleName.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/RuleName.java @@ -15,23 +15,27 @@ public class RuleName { @Column(name = "Id") private Integer id; + @NotBlank(message = "Name is mandatory") @Column(name = "name") - @NotBlank private String name; + @NotBlank(message = "Description is mandatory") @Column(name = "description") - @NotBlank private String description; + @NotBlank(message = "json is mandatory") @Column(name = "json") private String json; + @NotBlank(message = "template is mandatory") @Column(name = "template") private String template; + @NotBlank(message = "sql is mandatory") @Column(name = "sqlStr") private String sqlStr; + @NotBlank(message = "sqlPart is mandatory") @Column(name = "sqlPart") private String sqlPart; 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

-
+
+
+

Add New Rule

+
+
+
+
+
+
+ -
- - +
+ - -
+

Name error

+
+
+
+ + +
+ + +

Description error

+
+
+
+ + +
+ + +

json error

+
+
+
+ -
+
+ + +

template error

+
+
+
+ + +
+ + +

sql error

+
+
+
+ + +
+ + +

sqlPart error

+
+
+
+
+ Cancel + +
+
+ +
+
+
\ 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..9c8a4a1af4 100644 --- a/Poseiden-skeleton/src/main/resources/templates/ruleName/list.html +++ b/Poseiden-skeleton/src/main/resources/templates/ruleName/list.html @@ -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

-
+
+
+

Update New Rule

+
+
+
+
+
+
+ -
- - +
+ - -
+

Name error

+
+
+
+ + +
+ + +

Description error

+
+
+
+ + +
+ + +

json error

+
+
+
+ + +
+ -
+

template error

+
+
+
+ + +
+ + +

sql error

+
+
+
+ + +
+ + +

sqlPart error

+
+
+
+
+ Cancel + +
+
+ + +
+
+
\ No newline at end of file From ee11fe232aeda6dfb931afc4c1d7d592367077ba Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Fri, 4 Mar 2022 11:30:03 +0100 Subject: [PATCH 17/34] implements front for Trade entity --- .../controllers/TradeController.java | 66 +++++++++++++-- .../java/com/nnk/springboot/domain/Trade.java | 19 +++-- .../main/resources/templates/trade/add.html | 74 +++++++++++++---- .../main/resources/templates/trade/list.html | 82 +++++++++++-------- .../resources/templates/trade/update.html | 78 ++++++++++++++---- .../java/com/nnk/springboot/TradeTests.java | 2 +- 6 files changed, 236 insertions(+), 85 deletions(-) diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/TradeController.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/TradeController.java index 4e667eec22..0d1b82421f 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/TradeController.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/TradeController.java @@ -1,6 +1,9 @@ package com.nnk.springboot.controllers; import com.nnk.springboot.domain.Trade; +import com.nnk.springboot.services.TradeService; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; @@ -13,42 +16,89 @@ @Controller public class TradeController { - // TODO: Inject Trade service + @Autowired + private TradeService tradeService; + /** + * displays Trade list retrieved from database + */ @RequestMapping("/trade/list") - public String home(Model model) - { - // TODO: find all Trade, add to model + public String home(Model model) { + model.addAttribute("trades", tradeService.findAllTrades()); return "trade/list"; } + /** + * displays form for Trade to add + */ @GetMapping("/trade/add") public String addUser(Trade bid) { return "trade/add"; } + /** + * validates new Trade + * + * @param trade: Trade to create and save + * @param result: form result to validate + * @return Trade list displayed if validated, new add form with errors + * displayed else + */ @PostMapping("/trade/validate") public String validate(@Valid Trade trade, BindingResult result, Model model) { - // TODO: check data valid and save to db, after saving return Trade list + if(!result.hasErrors()) { + tradeService.saveTrade(trade); + model.addAttribute("trades", tradeService.findAllTrades()); + return "redirect:/trade/list"; + } return "trade/add"; } + /** + * displays Trade form to update + * + * @param id : id of the Trade to update + * @return return Trade form to update + */ @GetMapping("/trade/update/{id}") public String showUpdateForm(@PathVariable("id") Integer id, Model model) { - // TODO: get Trade by Id and to model then show to the form + Trade trade = tradeService.findTradeById(id).orElseThrow(() -> new IllegalArgumentException("Invalid trade Id:" + id)); + model.addAttribute("trade", trade); return "trade/update"; } + /** + * validates updated Trade + * + * @param id : id of the Trade to update + * @param trade : Trade to validate + * @param result : form result to validate + * @return Trade list with this Trade updated, Trade to update form + * with errors displayed else + */ @PostMapping("/trade/update/{id}") public String updateTrade(@PathVariable("id") Integer id, @Valid Trade trade, BindingResult result, Model model) { - // TODO: check required fields, if valid call service to update Trade and return Trade list + if(result.hasErrors()) { + return "trade/update"; + } + trade.setTradeId(id); + tradeService.saveTrade(trade); + model.addAttribute("trades", tradeService.findAllTrades()); return "redirect:/trade/list"; } + /** + * deletes selected Trade from database + * + * @param id: id of the Trade to delete + * @return the Trade list after selected Trade deleted + */ @GetMapping("/trade/delete/{id}") public String deleteTrade(@PathVariable("id") Integer id, Model model) { - // TODO: Find Trade by Id and delete the Trade, return to Trade list + Trade trade = tradeService.findTradeById(id).orElseThrow(() -> new IllegalArgumentException("Invalid trade Id:" + id)); + tradeService.deleteTrade(trade); + model.addAttribute("trades", tradeService.findAllTrades()); return "redirect:/trade/list"; } } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java index 0d53554921..a8892f38fd 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java @@ -3,6 +3,7 @@ import javax.persistence.*; import javax.validation.constraints.Digits; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; import javax.validation.constraints.Past; import org.hibernate.validator.constraints.Length; @@ -14,23 +15,24 @@ @Entity @Table(name = "Trade") public class Trade { - // TODO: Map columns in data table TRADE with corresponding java fields @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Digits(integer = 4, fraction = 0) @Column(name = "tradeId") private Integer tradeId; - @NotBlank - @Length(max = 30) + @NotBlank(message = "Account is mandatory") + @Length(max = 30, message = "must have 30 characters max") @Column(name = "account") private String account; - @NotBlank - @Length(max = 30) + @NotBlank(message = "Type is mandatory") + @Length(max = 30, message = "must have 30 characters max") @Column(name = "type") private String type; + @NotNull(message = "must not be null") + @Digits(integer=4, fraction = 2, message = "must be in the form 0000.00") @Column(name = "buyQuantity") private Double buyQuantity; @@ -123,7 +125,7 @@ public void setType(String type) { this.type = type; } - public double getBuyQuantity() { + public Double getBuyQuantity() { return buyQuantity; } @@ -267,10 +269,11 @@ public void setSide(String side) { this.side = side; } - public Trade(String account, String type) { + public Trade(String account, String type, Double buyQuantity) { super(); this.account = account; this.type = type; + this.buyQuantity = buyQuantity; } public Trade() { @@ -280,7 +283,7 @@ public Trade() { @Override public String toString() { - return "Trade [account=" + account + ", type=" + type + "]"; + return "Trade [account=" + account + ", type=" + type + ", buy quantity=" + buyQuantity + "]"; } } 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

-
+
+
+

Add New Trade

+
+
+
+
+
+
+ -
- - +
+ - -
+

Account error

+
+
+
+ + +
+ -
+

Type error

+
+
+
+ + +
+ + +

Bid Quantity error

+
+
+
+
+ Cancel +
+
+ +
+
+
\ 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..902c45a342 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 +
+
+
+ Bid List |  Curve Points |  Ratings |  Trade |  + Rule +
+
+ Logged in user: + [[${#httpServletRequest.remoteUser}]] +
+ +
+
-
- Logged in user: [[${#httpServletRequest.remoteUser}]] -
- -
+
+

Trade List

+
+
+ Add New + + + + + + + + + + + + + + + + + + + +
IdAccountTypeBuy QuantityAction
IdEdit |  + Delete +
-

Trade List

-
- Add New - - - - - - - - - - - - - -
IdAccountTypeBuy QuantityAction
-
-
\ 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 - + -
-
-

Update Trade

-
+
+
+
+

Update Trade

+
+
+
+
+
+
+ -
- - - -
+
+ + +

Account error

+
+
+
+ + +
+ -
+

Type error

+
+
+
+ + +
+ + +

Bid Quantity error

+
+
+
+
+ Cancel +
+
+ + +
+
+
\ No newline at end of file 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 e69c4538a3..c853170e16 100644 --- a/Poseiden-skeleton/src/test/java/com/nnk/springboot/TradeTests.java +++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/TradeTests.java @@ -23,7 +23,7 @@ public class TradeTests { @Test public void tradeTest() { - Trade trade = new Trade("Trade Account", "Type"); + Trade trade = new Trade("Trade Account", "Type", 10D); // Save trade = tradeService.saveTrade(trade); From 925ef3424584048725c0184d10c7d6d45c66c7dd Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Fri, 4 Mar 2022 12:03:18 +0100 Subject: [PATCH 18/34] updates controllers to redirect to list.htnl --- .../java/com/nnk/springboot/controllers/BidListController.java | 3 ++- .../java/com/nnk/springboot/controllers/CurveController.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/BidListController.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/BidListController.java index aeed6dfeaa..6f059473c7 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/BidListController.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/BidListController.java @@ -87,6 +87,7 @@ public String updateBid(@PathVariable("id") Integer id, @Valid BidList bidList, } bidList.setBidListId(id); bidListService.saveBidList(bidList); + model.addAttribute("bidLists", bidListService.findAllBidLists()); return "redirect:/bidList/list"; } @@ -100,7 +101,7 @@ public String updateBid(@PathVariable("id") Integer id, @Valid BidList bidList, public String deleteBid(@PathVariable("id") Integer id, Model model) { BidList bidList = bidListService.findBidListById(id).orElseThrow(() -> new IllegalArgumentException("Invalid bidList Id:" + id)); bidListService.deleteBidList(bidList); - model.addAttribute("bidList", bidList); + model.addAttribute("bidLists", bidListService.findAllBidLists()); return "redirect:/bidList/list"; } } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/CurveController.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/CurveController.java index cf997d37f7..f4e47e91ad 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/CurveController.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/CurveController.java @@ -87,6 +87,7 @@ public String updateBid(@PathVariable("id") Integer id, @Valid CurvePoint curveP } curvePoint.setId(id); curvePointService.saveCurvePoint(curvePoint); + model.addAttribute("curvePoints", curvePointService.findAllCurvePoints()); return "redirect:/curvePoint/list"; } @@ -100,7 +101,7 @@ public String updateBid(@PathVariable("id") Integer id, @Valid CurvePoint curveP public String deleteBid(@PathVariable("id") Integer id, Model model) { CurvePoint curvePoint = curvePointService.findCurvePointById(id).orElseThrow(() -> new IllegalArgumentException("Invalid bidList Id:" + id)); curvePointService.deleteCurvePoint(curvePoint); - model.addAttribute("curvePoint", curvePoint); + model.addAttribute("curvePoints", curvePointService.findAllCurvePoints()); return "redirect:/curvePoint/list"; } } From e061dab9ed4cdb9486c384f6a042123fea0f0291 Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Fri, 4 Mar 2022 12:20:06 +0100 Subject: [PATCH 19/34] implements front for User entity --- .../main/resources/templates/user/add.html | 110 ++++++++++-------- .../main/resources/templates/user/update.html | 110 ++++++++++-------- 2 files changed, 124 insertions(+), 96 deletions(-) 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

-
- -
-
-
- -
- -

-
-
-
- -
- -

-
-
-
- -
- -

-
-
-
- -
- - -

-
+
+
+

Add New User

+
+
+
+ +
+ +
+ +

+
+
+
+ +
+ +

+
+
+
+ +
+ +

+
+
+
+ +
+ +

+
+
-
-
- Cancel - -
-
+
+
+ Cancel +
+
- + +
+
- -
\ 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

-
- -
-
-
- -
- -

-
-
-
- -
- -

-
-
-
- -
- -

-
-
-
- -
- - -
+
+
+

Update User

+
+
+
+ +
+ +
+ +

+
+
+
+ +
+ +

+
+
+
+ +
+ +

+
+
+
+ +
+ +
+
-
-
- - Cancel - -
-
+
+
+ Cancel +
+
- + +
+
- -
\ No newline at end of file From 64c6458a03245e95793e2a9879e7f4a4d26e9253 Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Sat, 5 Mar 2022 11:51:19 +0100 Subject: [PATCH 20/34] reactivates Spring Security --- Poseiden-skeleton/pom.xml | 4 +-- .../controllers/UserController.java | 30 +++++++++---------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/Poseiden-skeleton/pom.xml b/Poseiden-skeleton/pom.xml index 9073a27a7d..88771a438c 100644 --- a/Poseiden-skeleton/pom.xml +++ b/Poseiden-skeleton/pom.xml @@ -47,13 +47,11 @@ org.springframework.boot spring-boot-starter-thymeleaf - - org.springframework.boot spring-boot-devtools diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/UserController.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/UserController.java index cd39657e00..a8d76b490c 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/UserController.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/UserController.java @@ -2,9 +2,10 @@ import com.nnk.springboot.domain.User; -import com.nnk.springboot.repositories.UserRepository; +import com.nnk.springboot.services.UserService; + import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; @@ -18,12 +19,13 @@ @Controller public class UserController { @Autowired - private UserRepository userRepository; + private UserService userService; + @RequestMapping("/user/list") public String home(Model model) { - model.addAttribute("users", userRepository.findAll()); + model.addAttribute("users", userService.findAllUsers()); return "user/list"; } @@ -32,29 +34,26 @@ public String addUser(User bid) { return "user/add"; } - /* @PostMapping("/user/validate") public String validate(@Valid User user, BindingResult result, Model model) { if (!result.hasErrors()) { BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); user.setPassword(encoder.encode(user.getPassword())); - userRepository.save(user); - model.addAttribute("users", userRepository.findAll()); + userService.saveUser(user); + model.addAttribute("users", userService.findAllUsers()); return "redirect:/user/list"; } return "user/add"; } - */ @GetMapping("/user/update/{id}") public String showUpdateForm(@PathVariable("id") Integer id, Model model) { - User user = userRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("Invalid user Id:" + id)); + User user = userService.findUserById(id).orElseThrow(() -> new IllegalArgumentException("Invalid user Id:" + id)); user.setPassword(""); model.addAttribute("user", user); return "user/update"; } - /* @PostMapping("/user/update/{id}") public String updateUser(@PathVariable("id") Integer id, @Valid User user, BindingResult result, Model model) { @@ -65,17 +64,16 @@ public String updateUser(@PathVariable("id") Integer id, @Valid User user, BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); user.setPassword(encoder.encode(user.getPassword())); user.setId(id); - userRepository.save(user); - model.addAttribute("users", userRepository.findAll()); + userService.saveUser(user); + model.addAttribute("users", userService.findAllUsers()); return "redirect:/user/list"; } - */ @GetMapping("/user/delete/{id}") public String deleteUser(@PathVariable("id") Integer id, Model model) { - User user = userRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("Invalid user Id:" + id)); - userRepository.delete(user); - model.addAttribute("users", userRepository.findAll()); + User user = userService.findUserById(id).orElseThrow(() -> new IllegalArgumentException("Invalid user Id:" + id)); + userService.deleteUser(user); + model.addAttribute("users", userService.findAllUsers()); return "redirect:/user/list"; } } From 87cf0273d879b220a0314be14e06ebce5d3c2450 Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Thu, 10 Mar 2022 16:10:53 +0100 Subject: [PATCH 21/34] adds Spring Security configuration for session based authentication --- .../configurations/SpringSecurityConfig.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Poseiden-skeleton/src/main/java/com/nnk/springboot/configurations/SpringSecurityConfig.java diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/configurations/SpringSecurityConfig.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/configurations/SpringSecurityConfig.java new file mode 100644 index 0000000000..f64236ee50 --- /dev/null +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/configurations/SpringSecurityConfig.java @@ -0,0 +1,57 @@ +package com.nnk.springboot.configurations; + +import javax.sql.DataSource; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; + +@Configuration +@EnableWebSecurity +public class SpringSecurityConfig extends WebSecurityConfigurerAdapter { + + @Autowired + private DataSource dataSource; + + @Bean + public PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } + + @Override + public void configure(HttpSecurity http) throws Exception { + http + .csrf().disable() + .authorizeRequests() + .antMatchers("/", "/login").permitAll() + .antMatchers("/css/**").permitAll() + .antMatchers("/user/**").hasAuthority("ADMIN") + .antMatchers("/app/**").hasAuthority("ADMIN") + .antMatchers("/admin/home").hasAuthority("ADMIN") + .anyRequest().authenticated() + .and() + .exceptionHandling().accessDeniedPage("/app/error") + .and() + .formLogin() + .defaultSuccessUrl("/bidList/list"); + } + + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + + auth + .jdbcAuthentication() + .dataSource(dataSource) + .passwordEncoder(passwordEncoder()) + .usersByUsernameQuery( + "SELECT username as username, password as password, 1 FROM Users WHERE username =?") + .authoritiesByUsernameQuery( + "SELECT username, role FROM Users WHERE username=?"); + } +} From 6febc279faf035b2bc4bdeb3305fa9396e8cfbf7 Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Thu, 10 Mar 2022 16:20:06 +0100 Subject: [PATCH 22/34] adds configuration for Spring Security Oauth2 --- Poseiden-skeleton/pom.xml | 28 +++++++++++-------- .../configurations/SpringSecurityConfig.java | 3 ++ .../src/main/resources/application.properties | 5 ++++ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Poseiden-skeleton/pom.xml b/Poseiden-skeleton/pom.xml index 88771a438c..d018bb2533 100644 --- a/Poseiden-skeleton/pom.xml +++ b/Poseiden-skeleton/pom.xml @@ -28,14 +28,14 @@ org.springframework.boot - spring-boot-starter-test - test + spring-boot-starter-oauth2-client + 2.6.4 - org.springframework.security - spring-security-test - test + org.springframework.boot + spring-boot-starter-security + org.springframework.boot spring-boot-starter-data-jpa @@ -47,11 +47,8 @@ org.springframework.boot spring-boot-starter-thymeleaf - - - org.springframework.boot - spring-boot-starter-security + org.springframework.boot spring-boot-devtools @@ -75,13 +72,22 @@ javassist 3.23.1-GA - + org.projectlombok lombok true - + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/configurations/SpringSecurityConfig.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/configurations/SpringSecurityConfig.java index f64236ee50..e719dd257e 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/configurations/SpringSecurityConfig.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/configurations/SpringSecurityConfig.java @@ -39,6 +39,9 @@ public void configure(HttpSecurity http) throws Exception { .exceptionHandling().accessDeniedPage("/app/error") .and() .formLogin() + .defaultSuccessUrl("/bidList/list") + .and() + .oauth2Login() .defaultSuccessUrl("/bidList/list"); } diff --git a/Poseiden-skeleton/src/main/resources/application.properties b/Poseiden-skeleton/src/main/resources/application.properties index e8de928cfd..4ab59c6298 100644 --- a/Poseiden-skeleton/src/main/resources/application.properties +++ b/Poseiden-skeleton/src/main/resources/application.properties @@ -1,3 +1,4 @@ +######################### Log Configuration ########################## logging.level.org.springframework=INFO logging.level.root=error @@ -16,3 +17,7 @@ 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 From 57be36f5af61235ff832146d6840f00b70df649f Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Thu, 10 Mar 2022 16:22:00 +0100 Subject: [PATCH 23/34] modifies templates for oauth2 and logout --- Poseiden-skeleton/src/main/resources/templates/403.html | 4 ++-- .../src/main/resources/templates/bidList/list.html | 4 ++-- .../src/main/resources/templates/curvePoint/list.html | 4 ++-- .../src/main/resources/templates/rating/list.html | 4 ++-- .../src/main/resources/templates/ruleName/list.html | 4 ++-- .../src/main/resources/templates/trade/list.html | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) 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}]] -
+ Logged in user: [[${#httpServletRequest.getUserPrincipal().getName()}]] +
diff --git a/Poseiden-skeleton/src/main/resources/templates/bidList/list.html b/Poseiden-skeleton/src/main/resources/templates/bidList/list.html index d6ad88a075..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()}]] +
diff --git a/Poseiden-skeleton/src/main/resources/templates/curvePoint/list.html b/Poseiden-skeleton/src/main/resources/templates/curvePoint/list.html index ffed1a6156..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()}]] +
diff --git a/Poseiden-skeleton/src/main/resources/templates/rating/list.html b/Poseiden-skeleton/src/main/resources/templates/rating/list.html index 643f484c04..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()}]] +
diff --git a/Poseiden-skeleton/src/main/resources/templates/ruleName/list.html b/Poseiden-skeleton/src/main/resources/templates/ruleName/list.html index 9c8a4a1af4..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()}]] +
diff --git a/Poseiden-skeleton/src/main/resources/templates/trade/list.html b/Poseiden-skeleton/src/main/resources/templates/trade/list.html index 902c45a342..35e1617fca 100644 --- a/Poseiden-skeleton/src/main/resources/templates/trade/list.html +++ b/Poseiden-skeleton/src/main/resources/templates/trade/list.html @@ -17,8 +17,8 @@
Logged in user: - [[${#httpServletRequest.remoteUser}]] -
+ [[${#httpServletRequest.getUserPrincipal().getName()}]] +
From bcc30eae6008628e5daa8653ae5be3a1f8dee65c Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Thu, 10 Mar 2022 17:16:00 +0100 Subject: [PATCH 24/34] modifies User entity --- .../com/nnk/springboot/controllers/LoginController.java | 7 ++++--- .../src/main/java/com/nnk/springboot/domain/User.java | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/LoginController.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/LoginController.java index ef0c657c72..0eb2181cfa 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/LoginController.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/LoginController.java @@ -1,6 +1,7 @@ package com.nnk.springboot.controllers; -import com.nnk.springboot.repositories.UserRepository; +import com.nnk.springboot.services.UserService; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @@ -12,7 +13,7 @@ public class LoginController { @Autowired - private UserRepository userRepository; + private UserService userService; @GetMapping("login") public ModelAndView login() { @@ -24,7 +25,7 @@ public ModelAndView login() { @GetMapping("secure/article-details") public ModelAndView getAllUserArticles() { ModelAndView mav = new ModelAndView(); - mav.addObject("users", userRepository.findAll()); + mav.addObject("users", userService.findAllUsers()); mav.setViewName("user/list"); return mav; } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/User.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/User.java index 7eaf74303e..5a1a5d5883 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/User.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/User.java @@ -2,6 +2,7 @@ import javax.persistence.*; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Pattern; import org.hibernate.validator.constraints.Length; @@ -14,15 +15,20 @@ public class User { private Integer id; @NotBlank(message = "Username is mandatory") @Length(max = 125, message = "must have 125 caracters max") + @Column(name = "username") private String username; @NotBlank(message = "Password is mandatory") + @Pattern(regexp = "(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$", message = "must contain at least 8 characters with a lowercase, an uppercase, a number and a special character (#?!@$%^&*-)") @Length(max = 125, message = "must have 125 caracters max") + @Column(name = "password") private String password; @NotBlank(message = "FullName is mandatory") @Length(max = 125, message = "must have 125 caracters max") + @Column(name = "fullname") private String fullname; @NotBlank(message = "Role is mandatory") @Length(max = 125, message = "must have 125 caracters max") + @Column(name = "role") private String role; public Integer getId() { From c3461b4acf5b1e2f4b1c1cc7d31c3720a85222bd Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Mon, 14 Mar 2022 14:41:17 +0100 Subject: [PATCH 25/34] adds tests for BidListController --- .../com/nnk/springboot/domain/BidList.java | 67 +++--- .../controllers/BidListControllerTest.java | 209 ++++++++++++++++++ 2 files changed, 244 insertions(+), 32 deletions(-) create mode 100644 Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/BidListControllerTest.java diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java index cfe594405d..a77e03f08e 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java @@ -1,7 +1,6 @@ package com.nnk.springboot.domain; import org.hibernate.validator.constraints.Length; -import org.springframework.beans.factory.annotation.Required; import javax.persistence.*; import javax.validation.constraints.Digits; @@ -14,96 +13,96 @@ @Entity @Table(name = "BidList") public class BidList { - // TODO: Map columns in data table BIDLIST with corresponding java fields + // TODO: Map columns in data table BIDLIST with corresponding java fields @Id - @Digits(integer=4, fraction=0) + @Digits(integer = 4, fraction = 0) @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "BidListId") private Integer BidListId; - + @NotBlank(message = "Account is mandatory") - @Length(max=30, message = "must have 30 characters max") + @Length(max = 30, message = "must have 30 characters max") @Column(name = "account") private String account; - + @NotBlank(message = "Type is mandatory") - @Length(max=30, message = "must have 30 characters max") + @Length(max = 30, message = "must have 30 characters max") @Column(name = "type") private String type; - + @Column(name = "bidQuantity") @NotNull(message = "must not be null") - @Digits(integer=4, fraction = 2, message = "must be in the form 0000.00") + @Digits(integer = 4, fraction = 2, message = "must be in the form 0000.00") private Double bidQuantity; - + @Column(name = "askQuantity") - @Digits(integer=4, fraction = 2) + @Digits(integer = 4, fraction = 2) private Double askQuantity; - + @Column(name = "bid") - @Digits(integer=4, fraction = 2) + @Digits(integer = 4, fraction = 2) private Double bid; - + @Column(name = "ask") - @Digits(integer=4, fraction = 2) + @Digits(integer = 4, fraction = 2) private Double ask; - + @Column(name = "benchmark") @Length(max = 125) private String benchmark; - + @Column(name = "bidListDate") @Past private Timestamp bidListDate; - + @Column(name = "commentary") @Length(max = 125) private String commentary; - + @Column(name = "security") @Length(max = 125) private String security; - + @Column(name = "status") @Length(max = 10) private String status; - + @Column(name = "trader") @Length(max = 125) private String trader; - + @Column(name = "book") @Length(max = 125) private String book; - + @Column(name = "creationName") @Length(max = 125) private String creationName; - + @Column(name = "creationDate") @Past private Timestamp creationDate; - + @Column(name = "revisionName") @Length(max = 125) private String revisionName; - + @Column(name = "revisionDate") @Past private Timestamp revisionDate; - + @Column(name = "dealName") @Length(max = 125) private String dealName; - + @Column(name = "dealType") @Length(max = 125) private String dealType; - + @Column(name = "sourceListId") @Length(max = 125) private String sourceListId; - + @Column(name = "side") @Length(max = 125) private String side; @@ -137,7 +136,11 @@ public Double getBidQuantity() { } public void setBidQuantity(Double bidQuantity) { - this.bidQuantity = bidQuantity; + if (bidQuantity > 0) { + this.bidQuantity = bidQuantity; + } else { + this.bidQuantity = null; + } } public Double getAskQuantity() { @@ -301,5 +304,5 @@ public String toString() { return "BidList [account=" + account + ", type=" + type + ", bidQuantity=" + bidQuantity + "]"; } - + } 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..8979195da1 --- /dev/null +++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/BidListControllerTest.java @@ -0,0 +1,209 @@ +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 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 + @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); + } + +} From 0b85a6fa7d12de97271e3a1dc2b868468a2bdd01 Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Mon, 14 Mar 2022 15:59:43 +0100 Subject: [PATCH 26/34] adds tests for CurvePointController --- ...troller.java => CurvePointController.java} | 4 +- .../com/nnk/springboot/domain/CurvePoint.java | 34 ++- .../controllers/CurvePointControllerTest.java | 206 ++++++++++++++++++ 3 files changed, 230 insertions(+), 14 deletions(-) rename Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/{CurveController.java => CurvePointController.java} (94%) create mode 100644 Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/CurvePointControllerTest.java diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/CurveController.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/CurvePointController.java similarity index 94% rename from Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/CurveController.java rename to Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/CurvePointController.java index f4e47e91ad..ad713dc481 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/CurveController.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/CurvePointController.java @@ -15,7 +15,7 @@ import javax.validation.Valid; @Controller -public class CurveController { +public class CurvePointController { @Autowired private CurvePointService curvePointService; @@ -65,7 +65,7 @@ public String validate(@Valid CurvePoint curvePoint, BindingResult result, Model */ @GetMapping("/curvePoint/update/{id}") public String showUpdateForm(@PathVariable("id") Integer id, Model model) { - CurvePoint curvePoint = curvePointService.findCurvePointById(id).orElseThrow(() -> new IllegalArgumentException("Invalid bidList Id:" + id)); + CurvePoint curvePoint = curvePointService.findCurvePointById(id).orElseThrow(() -> new IllegalArgumentException("Invalid curvePoint Id:" + id)); model.addAttribute("curvePoint", curvePoint); return "curvePoint/update"; } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java index 831daba957..75fedaf371 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java @@ -1,7 +1,6 @@ package com.nnk.springboot.domain; import org.hibernate.annotations.CreationTimestamp; -import org.springframework.dao.DataAccessResourceFailureException; import javax.persistence.*; import javax.validation.constraints.Digits; @@ -10,36 +9,35 @@ import java.sql.Timestamp; - @Entity @Table(name = "CurvePoint") public class CurvePoint { - // TODO: Map columns in data table CURVEPOINT with corresponding java fields + // TODO: Map columns in data table CURVEPOINT with corresponding java fields @Id @Digits(integer = 4, fraction = 0) @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "Id") private Integer id; - + @NotNull(message = "must not be null") @Digits(integer = 4, fraction = 0, message = "must be an integer number") @Column(name = "CurveId") private Integer curveId; - + @Column(name = "asOfDate") @Past private Timestamp asOfDate; - + @NotNull(message = "must not be null") @Column(name = "term") @Digits(integer = 4, fraction = 2, message = "must be in the form 0000.00") private Double term; - + @NotNull(message = "must not be null") @Column(name = "value") @Digits(integer = 4, fraction = 2, message = "must be in the form 0000.00") private Double value; - + @CreationTimestamp @Past @Column(name = "creationDate") @@ -58,7 +56,11 @@ public Integer getCurveId() { } public void setCurveId(Integer curveId) { - this.curveId = curveId; + if (curveId > 0) { + this.curveId = curveId; + } else { + this.curveId = null; + } } public Timestamp getAsOfDate() { @@ -74,7 +76,11 @@ public Double getTerm() { } public void setTerm(Double term) { - this.term = term; + if (term > 0) { + this.term = term; + } else { + this.term = null; + } } public Double getValue() { @@ -82,7 +88,11 @@ public Double getValue() { } public void setValue(Double value) { - this.value = value; + if (value > 0) { + this.value = value; + } else { + this.value = null; + } } public Timestamp getCreationDate() { @@ -109,5 +119,5 @@ public CurvePoint() { public String toString() { return "CurvePoint [curveId=" + curveId + ", term=" + term + ", value=" + value + "]"; } - + } \ No newline at end of file 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..e35e6c4c04 --- /dev/null +++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/CurvePointControllerTest.java @@ -0,0 +1,206 @@ +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 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 + @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); + } +} From 26d2729cb97c45fcaa9cbb81186ca2a50e1cc9ca Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Mon, 14 Mar 2022 16:20:38 +0100 Subject: [PATCH 27/34] adds tests for RatingController --- .../com/nnk/springboot/domain/Rating.java | 16 +- .../controllers/RatingControllerTest.java | 209 ++++++++++++++++++ 2 files changed, 219 insertions(+), 6 deletions(-) create mode 100644 Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/RatingControllerTest.java diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java index bd4d91d03f..3f2fdf04f7 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java @@ -14,19 +14,19 @@ public class Rating { @Digits(integer = 4, fraction = 0) @Column(name = "Id") private Integer id; - + @NotBlank(message = "MoodysRating is mandatory") @Column(name = "moodysRating") private String moodysRating; - + @NotBlank(message = "SandRating is mandatory") @Column(name = "sandPRating") private String sandPRating; - + @NotBlank(message = "FitchRating is mandatory") @Column(name = "fitchRating") private String fitchRating; - + @NotNull(message = "must not be null") @Column(name = "orderNumber") private Integer orderNumber; @@ -68,7 +68,11 @@ public Integer getOrderNumber() { } public void setOrderNumber(Integer orderNumber) { - this.orderNumber = orderNumber; + if (orderNumber > 0) { + this.orderNumber = orderNumber; + } else { + this.orderNumber = null; + } } public Rating(String moodysRating, String sandPRating, String fitchRating, Integer orderNumber) { @@ -89,5 +93,5 @@ public String toString() { return "Rating [moodysRating=" + moodysRating + ", sandPRating=" + sandPRating + ", fitchRating=" + fitchRating + ", orderNumber=" + orderNumber + "]"; } - + } 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..83d99c3fa1 --- /dev/null +++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/RatingControllerTest.java @@ -0,0 +1,209 @@ +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 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 + @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); + } +} From 312424b9b95d60a2f4ddde82f1a4528339d01109 Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Mon, 14 Mar 2022 16:36:55 +0100 Subject: [PATCH 28/34] adds tests for RuleNameController --- .../controllers/RuleNameControllerTest.java | 205 ++++++++++++++++++ 1 file changed, 205 insertions(+) create mode 100644 Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/RuleNameControllerTest.java 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..d500a7ad4e --- /dev/null +++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/RuleNameControllerTest.java @@ -0,0 +1,205 @@ +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 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_AddANewValidRuleName() throws Exception { + // creates an invalid 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); + } +} From 6eb0c476089f0dd62a6dca5558e29d829183457e Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Mon, 14 Mar 2022 16:54:05 +0100 Subject: [PATCH 29/34] adds tests for TradeController --- .../java/com/nnk/springboot/domain/Trade.java | 49 +++-- .../controllers/TradeControllerTest.java | 207 ++++++++++++++++++ 2 files changed, 232 insertions(+), 24 deletions(-) create mode 100644 Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/TradeControllerTest.java diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java index a8892f38fd..7699c232b0 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java @@ -11,7 +11,6 @@ import java.sql.Timestamp; - @Entity @Table(name = "Trade") public class Trade { @@ -20,83 +19,83 @@ public class Trade { @Digits(integer = 4, fraction = 0) @Column(name = "tradeId") private Integer tradeId; - + @NotBlank(message = "Account is mandatory") @Length(max = 30, message = "must have 30 characters max") @Column(name = "account") private String account; - + @NotBlank(message = "Type is mandatory") @Length(max = 30, message = "must have 30 characters max") @Column(name = "type") private String type; - + @NotNull(message = "must not be null") - @Digits(integer=4, fraction = 2, message = "must be in the form 0000.00") + @Digits(integer = 4, fraction = 2, message = "must be in the form 0000.00") @Column(name = "buyQuantity") private Double buyQuantity; - + @Column(name = "sellQuantity") private Double sellQuantity; - + @Column(name = "buyPrice") private Double buyPrice; - + @Column(name = "sellPrice") private Double sellPrice; - + @Past @Column(name = "tradeDate") private Timestamp tradeDate; - + @Length(max = 125) @Column(name = "security") private String security; - + @Length(max = 10) @Column(name = "status") private String status; - + @Length(max = 125) @Column(name = "trader") private String trader; - + @Length(max = 125) @Column(name = "benchmark") private String benchmark; - + @Length(max = 125) @Column(name = "book") private String book; - + @Length(max = 125) @Column(name = "creationName") private String creationName; - + @Past @Column(name = "creationDate") private Timestamp creationDate; - + @Length(max = 125) @Column(name = "revisionName") private String revisionName; - + @Past @Column(name = "revisionDate") private Timestamp revisionDate; - + @Length(max = 125) @Column(name = "dealName") private String dealName; - + @Length(max = 125) @Column(name = "dealType") private String dealType; - + @Length(max = 125) @Column(name = "sourceListId") private String sourceListId; - + @Length(max = 125) @Column(name = "side") private String side; @@ -130,7 +129,9 @@ public Double getBuyQuantity() { } public void setBuyQuantity(Double buyQuantity) { - this.buyQuantity = buyQuantity; + if (buyQuantity > 0) { + this.buyQuantity = buyQuantity; + } } public Double getSellQuantity() { @@ -285,5 +286,5 @@ public Trade() { public String toString() { return "Trade [account=" + account + ", type=" + type + ", buy quantity=" + buyQuantity + "]"; } - + } 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..5055a34099 --- /dev/null +++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/TradeControllerTest.java @@ -0,0 +1,207 @@ +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 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 + @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); + } +} From 6b384735af7ea1831d188e8a9bc32d070bdfc128 Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Mon, 14 Mar 2022 17:09:16 +0100 Subject: [PATCH 30/34] adds tests for UserController --- .../controllers/UserControllerTest.java | 229 ++++++++++++++++++ 1 file changed, 229 insertions(+) create mode 100644 Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/UserControllerTest.java 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..286c654a43 --- /dev/null +++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/UserControllerTest.java @@ -0,0 +1,229 @@ +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 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 + @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")); + } +} From a2074d3617bbd519eb4f320d1f6bc4f6af4cc6ed Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Mon, 14 Mar 2022 18:04:24 +0100 Subject: [PATCH 31/34] tests invalid id use to delete and update --- .../controllers/BidListControllerTest.java | 18 ++++++++++ .../controllers/CurvePointControllerTest.java | 18 ++++++++++ .../controllers/RatingControllerTest.java | 19 +++++++++++ .../controllers/RuleNameControllerTest.java | 34 ++++++++++++++++++- .../controllers/TradeControllerTest.java | 21 +++++++++++- .../controllers/UserControllerTest.java | 19 +++++++++++ 6 files changed, 127 insertions(+), 2 deletions(-) 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 index 8979195da1..cd492e9b54 100644 --- a/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/BidListControllerTest.java +++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/BidListControllerTest.java @@ -19,6 +19,7 @@ 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; @@ -120,6 +121,14 @@ public void test_DeleteABidList() throws Exception { .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") @@ -206,4 +215,13 @@ public void test_NotUpdateInvalidBidList() throws Exception { 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 index e35e6c4c04..f659738bc7 100644 --- a/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/CurvePointControllerTest.java +++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/CurvePointControllerTest.java @@ -19,6 +19,7 @@ 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; @@ -119,6 +120,14 @@ public void test_DeleteACurvePoint() throws Exception { .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") @@ -203,4 +212,13 @@ public void test_NotUpdateInvalidCurvePoint() throws Exception { // 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/RatingControllerTest.java b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/RatingControllerTest.java index 83d99c3fa1..35d250964f 100644 --- a/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/RatingControllerTest.java +++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/RatingControllerTest.java @@ -19,6 +19,7 @@ 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; @@ -119,6 +120,15 @@ public void test_DeleteARating() throws Exception { .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 { @@ -206,4 +216,13 @@ public void test_NotUpdateInvalidRating() throws Exception { // 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 index d500a7ad4e..5cdb76615a 100644 --- a/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/RuleNameControllerTest.java +++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/RuleNameControllerTest.java @@ -19,6 +19,7 @@ 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; @@ -107,10 +108,32 @@ public void test_UserAuthentication_PermitRuleNameUpdateAccess() throws Exceptio 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 an invalid rule to add to database + // 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 @@ -202,4 +225,13 @@ public void test_NotUpdateInvalidRuleName() throws Exception { // 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 index 5055a34099..0da3319f29 100644 --- a/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/TradeControllerTest.java +++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/TradeControllerTest.java @@ -19,6 +19,7 @@ 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; @@ -107,7 +108,7 @@ public void test_UserAuthentication_PermitTradeUpdateAccess() throws Exception{ // deletes the trade from the database tradeService.deleteTrade(trade); } - // + @Test @WithMockUser(username = "userTest", password = "Passw0rd!", authorities = "USER") public void test_DeleteATrade() throws Exception { @@ -121,6 +122,15 @@ public void test_DeleteATrade() throws Exception { .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 { @@ -204,4 +214,13 @@ public void test_NotUpdateInvalidTrade() throws Exception { // 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 index 286c654a43..afd3b7507e 100644 --- a/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/UserControllerTest.java +++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/UserControllerTest.java @@ -20,6 +20,7 @@ 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; @@ -122,6 +123,15 @@ public void test_DeleteAnUser() throws Exception { .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 { @@ -226,4 +236,13 @@ public void test_NotAddUser_withInvalidPassword() throws Exception { .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()); + } } From 4c83d0beccc33fdfb98065df2b5a123e4eb1a4cc Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Wed, 16 Mar 2022 13:54:20 +0100 Subject: [PATCH 32/34] adds tests for LoginController --- .../controllers/LoginControllerTest.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Poseiden-skeleton/src/test/java/com/nnk/springboot/controllers/LoginControllerTest.java 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")); + } + +} From 588131c6e49cd3a323ca82edf97b225e08f0f7db Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Wed, 16 Mar 2022 13:55:37 +0100 Subject: [PATCH 33/34] modifies for password constraint --- .../src/test/java/com/nnk/springboot/UserTests.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Poseiden-skeleton/src/test/java/com/nnk/springboot/UserTests.java b/Poseiden-skeleton/src/test/java/com/nnk/springboot/UserTests.java index 99316107ce..70944b5a9a 100644 --- a/Poseiden-skeleton/src/test/java/com/nnk/springboot/UserTests.java +++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/UserTests.java @@ -1,8 +1,6 @@ package com.nnk.springboot; -import com.nnk.springboot.domain.Trade; import com.nnk.springboot.domain.User; -import com.nnk.springboot.services.TradeService; import com.nnk.springboot.services.UserService; import org.assertj.core.util.Lists; @@ -25,7 +23,7 @@ public class UserTests { @Test public void userTest() { - User user = new User("UserName", "password", "UserTestName", "USER"); + User user = new User("UserName", "Passw0rd!", "UserTestName", "USER"); // Save user = userService.saveUser(user); From f0ff6ecaa84cfeccaf0aad32cf5f7f7172b5a480 Mon Sep 17 00:00:00 2001 From: Fabien De deken Date: Wed, 16 Mar 2022 13:57:21 +0100 Subject: [PATCH 34/34] configures for test coverage with Jacoco report --- Poseiden-skeleton/pom.xml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Poseiden-skeleton/pom.xml b/Poseiden-skeleton/pom.xml index d018bb2533..9d3ec825fe 100644 --- a/Poseiden-skeleton/pom.xml +++ b/Poseiden-skeleton/pom.xml @@ -96,6 +96,25 @@ org.springframework.boot spring-boot-maven-plugin + + org.jacoco + jacoco-maven-plugin + 0.8.7 + + + + prepare-agent + + + + jacoco-report + test + + report + + + +