From 8e63f07401aeeaae7bb02f7cabea23462f8321a7 Mon Sep 17 00:00:00 2001 From: Sonali Goel <112942761+goelsonali@users.noreply.github.com> Date: Wed, 31 Jul 2024 00:25:02 +0100 Subject: [PATCH 1/7] Squashed commit of the following: commit 777f5d5a53f908c76d553a3c47d45322fb5fdf1d Author: Sonali Goel <112942761+goelsonali@users.noreply.github.com> Date: Wed Jul 31 00:10:05 2024 +0100 Removed commented json commit b097ddab23c41c82ee9368d6cfffe3bebc1ed117 Author: Sonali Goel <112942761+goelsonali@users.noreply.github.com> Date: Wed Jul 31 00:05:32 2024 +0100 Revert the unwanted change commit ae394db7820ae3d7da0f91d8db40d92b96af72d6 Author: Sonali Goel <112942761+goelsonali@users.noreply.github.com> Date: Tue Jul 30 23:57:41 2024 +0100 Add BookClub api commit 2da0f3f4264f7f51e33ed02a8f2a180f3fe39baa Author: Afsha <115444059+Afsha10@users.noreply.github.com> Date: Mon Jul 29 19:11:33 2024 +0100 Create studyGroup Json file and ProgrammeController --- .../controller/ProgrammeController.java | 34 ++++++++ .../platform/domain/cms/ApiResourcesFile.java | 10 ++- .../platform/domain/cms/attributes/Card.java | 11 +++ .../domain/cms/attributes/SimpleDetails.java | 10 +++ .../cms/pages/programme/BookClubPage.java | 13 +++ .../domain/cms/pages/programme/Programme.java | 11 +++ .../platform/service/ProgrammeService.java | 37 +++++++++ src/main/resources/bookClubPage.json | 43 ++++++++++ src/main/resources/studyGroupPage.json | 81 +++++++++++++++++++ 9 files changed, 246 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/wcc/platform/controller/ProgrammeController.java create mode 100644 src/main/java/com/wcc/platform/domain/cms/attributes/Card.java create mode 100644 src/main/java/com/wcc/platform/domain/cms/attributes/SimpleDetails.java create mode 100644 src/main/java/com/wcc/platform/domain/cms/pages/programme/BookClubPage.java create mode 100644 src/main/java/com/wcc/platform/domain/cms/pages/programme/Programme.java create mode 100644 src/main/java/com/wcc/platform/service/ProgrammeService.java create mode 100644 src/main/resources/bookClubPage.json create mode 100644 src/main/resources/studyGroupPage.json diff --git a/src/main/java/com/wcc/platform/controller/ProgrammeController.java b/src/main/java/com/wcc/platform/controller/ProgrammeController.java new file mode 100644 index 00000000..9a125856 --- /dev/null +++ b/src/main/java/com/wcc/platform/controller/ProgrammeController.java @@ -0,0 +1,34 @@ +package com.wcc.platform.controller; + +import com.wcc.platform.domain.cms.pages.programme.BookClubPage; +import com.wcc.platform.service.ProgrammeService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +/** Rest controller for all the programme apis */ +@RestController +@RequestMapping("/api/cms/v1/programme") +@Tag(name = "APIs relevant to Programme pages") +public class ProgrammeController { + + private final ProgrammeService service; + + @Autowired + public ProgrammeController(final ProgrammeService programmeService) { + this.service = programmeService; + } + + @GetMapping("/bookClub") + @Operation(summary = "API to retrieve book club programme page") + @ResponseStatus(HttpStatus.OK) + public ResponseEntity getBookClubPage() { + return ResponseEntity.ok(service.getBookClub()); + } +} diff --git a/src/main/java/com/wcc/platform/domain/cms/ApiResourcesFile.java b/src/main/java/com/wcc/platform/domain/cms/ApiResourcesFile.java index 47950cde..481f620b 100644 --- a/src/main/java/com/wcc/platform/domain/cms/ApiResourcesFile.java +++ b/src/main/java/com/wcc/platform/domain/cms/ApiResourcesFile.java @@ -2,11 +2,13 @@ /** Create custom api configurations. */ public enum ApiResourcesFile { - TEAM("teamPage.json"), - MENTORSHIP("mentorshipPage.json"), - FOOTER("footerPage.json"), + CODE_OF_CONDUCT("codeOfConductPage.json"), COLLABORATOR("collaboratorPage.json"), - CODE_OF_CONDUCT("codeOfConductPage.json"); + FOOTER("footerPage.json"), + MENTORSHIP("mentorshipPage.json"), + + PROG_BOOK_CLUB("bookClubPage.json"), + TEAM("teamPage.json"); private final String fileName; diff --git a/src/main/java/com/wcc/platform/domain/cms/attributes/Card.java b/src/main/java/com/wcc/platform/domain/cms/attributes/Card.java new file mode 100644 index 00000000..81ad957a --- /dev/null +++ b/src/main/java/com/wcc/platform/domain/cms/attributes/Card.java @@ -0,0 +1,11 @@ +package com.wcc.platform.domain.cms.attributes; + +/** + * Basic card details for a page or section + * + * @param title of the card + * @param subtitle on the card + * @param description shortened description + * @param link link for any external or internal resource + */ +public record Card(String title, String subtitle, String description, SimpleLink link) {} diff --git a/src/main/java/com/wcc/platform/domain/cms/attributes/SimpleDetails.java b/src/main/java/com/wcc/platform/domain/cms/attributes/SimpleDetails.java new file mode 100644 index 00000000..5d1a211a --- /dev/null +++ b/src/main/java/com/wcc/platform/domain/cms/attributes/SimpleDetails.java @@ -0,0 +1,10 @@ +package com.wcc.platform.domain.cms.attributes; + +/** + * Details of a section or page. + * + * @param title + * @param description + * @param card + */ +public record SimpleDetails(String title, String description, Card card) {} diff --git a/src/main/java/com/wcc/platform/domain/cms/pages/programme/BookClubPage.java b/src/main/java/com/wcc/platform/domain/cms/pages/programme/BookClubPage.java new file mode 100644 index 00000000..e6a882d4 --- /dev/null +++ b/src/main/java/com/wcc/platform/domain/cms/pages/programme/BookClubPage.java @@ -0,0 +1,13 @@ +package com.wcc.platform.domain.cms.pages.programme; + +import com.wcc.platform.domain.cms.attributes.Contact; +import com.wcc.platform.domain.cms.pages.Page; + +/** + * BookClub programme details. + * + * @param page basic information of the page + * @param contact social network contact information + * @param programme programme details section + */ +public record BookClubPage(Page page, Contact contact, Programme programme) {} diff --git a/src/main/java/com/wcc/platform/domain/cms/pages/programme/Programme.java b/src/main/java/com/wcc/platform/domain/cms/pages/programme/Programme.java new file mode 100644 index 00000000..a5c22b69 --- /dev/null +++ b/src/main/java/com/wcc/platform/domain/cms/pages/programme/Programme.java @@ -0,0 +1,11 @@ +package com.wcc.platform.domain.cms.pages.programme; + +import com.wcc.platform.domain.cms.attributes.SimpleDetails; +import java.util.List; + +/** + * Common programme information + * + * @param details for the programme + */ +public record Programme(List details) {} diff --git a/src/main/java/com/wcc/platform/service/ProgrammeService.java b/src/main/java/com/wcc/platform/service/ProgrammeService.java new file mode 100644 index 00000000..8f329a84 --- /dev/null +++ b/src/main/java/com/wcc/platform/service/ProgrammeService.java @@ -0,0 +1,37 @@ +package com.wcc.platform.service; + +import static com.wcc.platform.domain.cms.ApiResourcesFile.PROG_BOOK_CLUB; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.wcc.platform.domain.cms.pages.programme.BookClubPage; +import com.wcc.platform.domain.exceptions.PlatformInternalException; +import com.wcc.platform.utils.FileUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** Programme Service. */ +@Service +public class ProgrammeService { + + private final ObjectMapper objectMapper; + + @Autowired + public ProgrammeService(final ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + + /** + * API to fetch the information about BookClub programme. + * + * @return BookClub json response + */ + public BookClubPage getBookClub() { + try { + final String data = FileUtil.readFileAsString(PROG_BOOK_CLUB.getFileName()); + return objectMapper.readValue(data, BookClubPage.class); + } catch (JsonProcessingException e) { + throw new PlatformInternalException(e.getMessage(), e); + } + } +} diff --git a/src/main/resources/bookClubPage.json b/src/main/resources/bookClubPage.json new file mode 100644 index 00000000..d8611efe --- /dev/null +++ b/src/main/resources/bookClubPage.json @@ -0,0 +1,43 @@ +{ + "page": { + "title": "WCC Book Club", + "subtitle": "", + "description": "What sets our book club apart are the lively conversations, valuable insights and an opportunity to connect with like-minded individuals. The books we read are selected by the community, offering a diverse selection of tech books and essential soft skills topics.The book club meets monthly to share views, exchange ideas, and inspire personal and professional growth." + }, + "contact": { + "title": "Join us in our Study Group Slack channel", + "links": [ + { + "type": "slack", + "link": "http://shortlink_to_slack.com/#prog_book_club" + } + ] + }, + "programme": { + "details": [ + { + "title": "How It Works", + "description": "Every month we vote for a book to read, and at the end of the month we review the book together in our bookclub. In order to participate join us n slack.", + "card": null + }, + { + "title": "Benefits of Joining", + "description": "Dedication, networking and always knowing what is happening in tech market.", + "card": null + }, + { + "title": "What We Are Reading", + "description": "", + "card": { + "title": "The Pragmatic Programmer From Journeyman to Master", + "subtitle": "Andrew Hunt & David Thomas", + "description": "Essential guide for creating working and maintainable code amidst the complexities of modern software development.", + "link": { + "label": "View Book On GoodReads", + "uri": "http://goodread/book_link" + } + } + } + ] + } +} diff --git a/src/main/resources/studyGroupPage.json b/src/main/resources/studyGroupPage.json new file mode 100644 index 00000000..eadd559f --- /dev/null +++ b/src/main/resources/studyGroupPage.json @@ -0,0 +1,81 @@ +{ + "page": { + "title": "Technical Study Groups", + "subtitle": "", + "description": "Explore our technical study groups, created in collaboration with available mentors, to deepen your knowledge and skills in specific areas of interest.\n\nOur study groups cover a variety of topics and are designed to accommodate different schedules and experience levels. Whether you're a beginner looking to dive into a new technology or an experienced professional seeking to expand your expertise, there's a study group for you.\n\nThese study groups typically last anywhere from 1-2 months to longer durations, allowing participants to delve deeply into the subject matter and benefit from the guidance of experienced mentors." + }, + "contact": { + "title": "Join us in our Study Group Slack channel", + "links": [ + { + "type": "slack", + "link": "http://shortlink_to_slack.com" + } + ] + }, + "studyGroups": { + "title": "Active study Groups", + "groups": [ + { + "groupName": "Data Analytics and Generative AI concepts", + "description": "The study group focuses more on the Data Analytics and Generative AI concepts and guiding on the insights across the span of industries upskilling on relevant knowledge and practical work.", + "howItWorks": "", + "benefitsOfJoining": "", + "join": "", + "resources": "", + "events": "", + "mentorFullName": "Kirthikka Devi Venkataram", + "mentorProfile": "", + "participants": 3 + }, + { + "groupName": "Frontend React", + "description": "Project based study group, working towards a shared application (including SDLC introduction, gaining more experience in reviewing PR, git etc), with guidance on different aspects like testing, CI/CD.", + "howItWorks": "", + "benefitsOfJoining": "", + "join": "", + "resources": "", + "events": "", + "mentorFullName": "Stephanie Senoner", + "mentorProfile": "", + "participants": 3 + }, + { + "groupName": "Backend with Java and Rust", + "description": "Focus on Java including the whole developing process with creating projects and push them to git doing pairing review.", + "howItWorks": "", + "benefitsOfJoining": "", + "join": "", + "resources": "", + "events": "", + "mentorFullName": "Liliia Rafikova", + "mentorProfile": "", + "participants": 5 + }, + { + "groupName": "Full Stack- ReactJs and Java (Spring Boot)", + "description": "Group study on project-based learning, including pair programming. Gain deep knowledge of web-based microservice architecture, system design, and CI/CD best practices. Integrate backend services with ReactJS frontend to craft full-stack projects.", + "howItWorks": "", + "benefitsOfJoining": "", + "join": "", + "resources": "", + "events": "", + "mentorFullName": "Hersi Kopani", + "mentorProfile": "", + "participants": 7 + }, + { + "groupName": "API Test Automation", + "description": "The study group focuses on mastering API testing using Postman, a popular API development and testing tool. Sessions feature hands-on exercises and real-world scenarios to deepen understanding of testing techniques and gain practical knowledge on API automation.", + "howItWorks": "", + "benefitsOfJoining": "", + "join": "", + "resources": "", + "events": "", + "mentorFullName": "", + "mentorProfile": "Eleonora Belova", + "participants": 3 + } + ] + } +} From 29ad297c4c5232493b170fda50bb284d2043d5c8 Mon Sep 17 00:00:00 2001 From: Sonali Goel <112942761+goelsonali@users.noreply.github.com> Date: Wed, 31 Jul 2024 00:27:09 +0100 Subject: [PATCH 2/7] Remove studyGroup json file --- src/main/resources/studyGroupPage.json | 81 -------------------------- 1 file changed, 81 deletions(-) delete mode 100644 src/main/resources/studyGroupPage.json diff --git a/src/main/resources/studyGroupPage.json b/src/main/resources/studyGroupPage.json deleted file mode 100644 index eadd559f..00000000 --- a/src/main/resources/studyGroupPage.json +++ /dev/null @@ -1,81 +0,0 @@ -{ - "page": { - "title": "Technical Study Groups", - "subtitle": "", - "description": "Explore our technical study groups, created in collaboration with available mentors, to deepen your knowledge and skills in specific areas of interest.\n\nOur study groups cover a variety of topics and are designed to accommodate different schedules and experience levels. Whether you're a beginner looking to dive into a new technology or an experienced professional seeking to expand your expertise, there's a study group for you.\n\nThese study groups typically last anywhere from 1-2 months to longer durations, allowing participants to delve deeply into the subject matter and benefit from the guidance of experienced mentors." - }, - "contact": { - "title": "Join us in our Study Group Slack channel", - "links": [ - { - "type": "slack", - "link": "http://shortlink_to_slack.com" - } - ] - }, - "studyGroups": { - "title": "Active study Groups", - "groups": [ - { - "groupName": "Data Analytics and Generative AI concepts", - "description": "The study group focuses more on the Data Analytics and Generative AI concepts and guiding on the insights across the span of industries upskilling on relevant knowledge and practical work.", - "howItWorks": "", - "benefitsOfJoining": "", - "join": "", - "resources": "", - "events": "", - "mentorFullName": "Kirthikka Devi Venkataram", - "mentorProfile": "", - "participants": 3 - }, - { - "groupName": "Frontend React", - "description": "Project based study group, working towards a shared application (including SDLC introduction, gaining more experience in reviewing PR, git etc), with guidance on different aspects like testing, CI/CD.", - "howItWorks": "", - "benefitsOfJoining": "", - "join": "", - "resources": "", - "events": "", - "mentorFullName": "Stephanie Senoner", - "mentorProfile": "", - "participants": 3 - }, - { - "groupName": "Backend with Java and Rust", - "description": "Focus on Java including the whole developing process with creating projects and push them to git doing pairing review.", - "howItWorks": "", - "benefitsOfJoining": "", - "join": "", - "resources": "", - "events": "", - "mentorFullName": "Liliia Rafikova", - "mentorProfile": "", - "participants": 5 - }, - { - "groupName": "Full Stack- ReactJs and Java (Spring Boot)", - "description": "Group study on project-based learning, including pair programming. Gain deep knowledge of web-based microservice architecture, system design, and CI/CD best practices. Integrate backend services with ReactJS frontend to craft full-stack projects.", - "howItWorks": "", - "benefitsOfJoining": "", - "join": "", - "resources": "", - "events": "", - "mentorFullName": "Hersi Kopani", - "mentorProfile": "", - "participants": 7 - }, - { - "groupName": "API Test Automation", - "description": "The study group focuses on mastering API testing using Postman, a popular API development and testing tool. Sessions feature hands-on exercises and real-world scenarios to deepen understanding of testing techniques and gain practical knowledge on API automation.", - "howItWorks": "", - "benefitsOfJoining": "", - "join": "", - "resources": "", - "events": "", - "mentorFullName": "", - "mentorProfile": "Eleonora Belova", - "participants": 3 - } - ] - } -} From 1b83589a6e89222d683bc420d81c3c8305e48b42 Mon Sep 17 00:00:00 2001 From: Sonali Goel <112942761+goelsonali@users.noreply.github.com> Date: Fri, 2 Aug 2024 10:15:41 +0100 Subject: [PATCH 3/7] Review comments incorporated Review comments --- .../controller/ProgrammeController.java | 6 +-- .../platform/domain/cms/attributes/Card.java | 2 +- .../{Programme.java => ProgrammeInfo.java} | 4 +- .../{BookClubPage.java => ProgrammePage.java} | 4 +- .../platform/service/ProgrammeService.java | 6 +-- src/main/resources/bookClubPage.json | 39 +++++++++++++++++++ 6 files changed, 50 insertions(+), 11 deletions(-) rename src/main/java/com/wcc/platform/domain/cms/pages/programme/{Programme.java => ProgrammeInfo.java} (66%) rename src/main/java/com/wcc/platform/domain/cms/pages/programme/{BookClubPage.java => ProgrammePage.java} (68%) diff --git a/src/main/java/com/wcc/platform/controller/ProgrammeController.java b/src/main/java/com/wcc/platform/controller/ProgrammeController.java index 9a125856..dab950d6 100644 --- a/src/main/java/com/wcc/platform/controller/ProgrammeController.java +++ b/src/main/java/com/wcc/platform/controller/ProgrammeController.java @@ -1,6 +1,6 @@ package com.wcc.platform.controller; -import com.wcc.platform.domain.cms.pages.programme.BookClubPage; +import com.wcc.platform.domain.cms.pages.programme.ProgrammePage; import com.wcc.platform.service.ProgrammeService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; -/** Rest controller for all the programme apis */ +/** Rest controller for all the programme apis. */ @RestController @RequestMapping("/api/cms/v1/programme") @Tag(name = "APIs relevant to Programme pages") @@ -28,7 +28,7 @@ public ProgrammeController(final ProgrammeService programmeService) { @GetMapping("/bookClub") @Operation(summary = "API to retrieve book club programme page") @ResponseStatus(HttpStatus.OK) - public ResponseEntity getBookClubPage() { + public ResponseEntity getBookClubPage() { return ResponseEntity.ok(service.getBookClub()); } } diff --git a/src/main/java/com/wcc/platform/domain/cms/attributes/Card.java b/src/main/java/com/wcc/platform/domain/cms/attributes/Card.java index 81ad957a..fc290272 100644 --- a/src/main/java/com/wcc/platform/domain/cms/attributes/Card.java +++ b/src/main/java/com/wcc/platform/domain/cms/attributes/Card.java @@ -1,7 +1,7 @@ package com.wcc.platform.domain.cms.attributes; /** - * Basic card details for a page or section + * Basic card details for a page or section. * * @param title of the card * @param subtitle on the card diff --git a/src/main/java/com/wcc/platform/domain/cms/pages/programme/Programme.java b/src/main/java/com/wcc/platform/domain/cms/pages/programme/ProgrammeInfo.java similarity index 66% rename from src/main/java/com/wcc/platform/domain/cms/pages/programme/Programme.java rename to src/main/java/com/wcc/platform/domain/cms/pages/programme/ProgrammeInfo.java index a5c22b69..0803e530 100644 --- a/src/main/java/com/wcc/platform/domain/cms/pages/programme/Programme.java +++ b/src/main/java/com/wcc/platform/domain/cms/pages/programme/ProgrammeInfo.java @@ -4,8 +4,8 @@ import java.util.List; /** - * Common programme information + * Common programme information. * * @param details for the programme */ -public record Programme(List details) {} +public record ProgrammeInfo(List details) {} diff --git a/src/main/java/com/wcc/platform/domain/cms/pages/programme/BookClubPage.java b/src/main/java/com/wcc/platform/domain/cms/pages/programme/ProgrammePage.java similarity index 68% rename from src/main/java/com/wcc/platform/domain/cms/pages/programme/BookClubPage.java rename to src/main/java/com/wcc/platform/domain/cms/pages/programme/ProgrammePage.java index e6a882d4..d6c70f6c 100644 --- a/src/main/java/com/wcc/platform/domain/cms/pages/programme/BookClubPage.java +++ b/src/main/java/com/wcc/platform/domain/cms/pages/programme/ProgrammePage.java @@ -8,6 +8,6 @@ * * @param page basic information of the page * @param contact social network contact information - * @param programme programme details section + * @param programmeInfo programme details section */ -public record BookClubPage(Page page, Contact contact, Programme programme) {} +public record ProgrammePage(Page page, Contact contact, ProgrammeInfo programmeInfo) {} diff --git a/src/main/java/com/wcc/platform/service/ProgrammeService.java b/src/main/java/com/wcc/platform/service/ProgrammeService.java index 8f329a84..26d7e30a 100644 --- a/src/main/java/com/wcc/platform/service/ProgrammeService.java +++ b/src/main/java/com/wcc/platform/service/ProgrammeService.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.wcc.platform.domain.cms.pages.programme.BookClubPage; +import com.wcc.platform.domain.cms.pages.programme.ProgrammePage; import com.wcc.platform.domain.exceptions.PlatformInternalException; import com.wcc.platform.utils.FileUtil; import org.springframework.beans.factory.annotation.Autowired; @@ -26,10 +26,10 @@ public ProgrammeService(final ObjectMapper objectMapper) { * * @return BookClub json response */ - public BookClubPage getBookClub() { + public ProgrammePage getBookClub() { try { final String data = FileUtil.readFileAsString(PROG_BOOK_CLUB.getFileName()); - return objectMapper.readValue(data, BookClubPage.class); + return objectMapper.readValue(data, ProgrammePage.class); } catch (JsonProcessingException e) { throw new PlatformInternalException(e.getMessage(), e); } diff --git a/src/main/resources/bookClubPage.json b/src/main/resources/bookClubPage.json index d8611efe..b6706b30 100644 --- a/src/main/resources/bookClubPage.json +++ b/src/main/resources/bookClubPage.json @@ -38,6 +38,45 @@ } } } + ], + "event": { + "title": "Upcoming events", + "link": { + "label": "View past events", + "uri": "/eventsPage_link" + }, + "eventCard": { + "title": "Book Club: book name", + "description": "Book description", + "host": [ + { + "link": { + "label": "Anna", + "uri": "profile" + } + }, + { + "link": { + "label": "Lana", + "uri": "profile" + } + } + ], + "eventLink": { + "label": "Go to Meetup Event", + "link": "https:/meet-up-link" + } + } + }, + "resources": [ + { + "type": "Presentation files", + "link": "/drive/presentation" + }, + { + "type": "pdf", + "link": "/drive/presentation" + } ] } } From dac0c501e00037c25c5e0b0f0f1cfa519926f67c Mon Sep 17 00:00:00 2001 From: Sonali Goel <112942761+goelsonali@users.noreply.github.com> Date: Mon, 5 Aug 2024 23:59:17 +0100 Subject: [PATCH 4/7] refactor programme Refactor the programme page --- .../controller/ProgrammeController.java | 15 +-- .../domain/cms/attributes/SimpleDetails.java | 10 -- .../cms/pages/programme/ProgrammeInfo.java | 11 -- .../cms/pages/programme/ProgrammePage.java | 13 +- .../wcc/platform/domain/platform/Event.java | 14 ++- .../domain/platform/EventSection.java | 22 ++++ .../platform/domain/platform/Programme.java | 24 ++++ .../platform/service/ProgrammeService.java | 12 +- src/main/resources/bookClubPage.json | 116 +++++++++--------- src/main/resources/eventsPage.json | 4 +- 10 files changed, 142 insertions(+), 99 deletions(-) delete mode 100644 src/main/java/com/wcc/platform/domain/cms/attributes/SimpleDetails.java delete mode 100644 src/main/java/com/wcc/platform/domain/cms/pages/programme/ProgrammeInfo.java create mode 100644 src/main/java/com/wcc/platform/domain/platform/EventSection.java create mode 100644 src/main/java/com/wcc/platform/domain/platform/Programme.java diff --git a/src/main/java/com/wcc/platform/controller/ProgrammeController.java b/src/main/java/com/wcc/platform/controller/ProgrammeController.java index dab950d6..22522ebb 100644 --- a/src/main/java/com/wcc/platform/controller/ProgrammeController.java +++ b/src/main/java/com/wcc/platform/controller/ProgrammeController.java @@ -1,5 +1,6 @@ package com.wcc.platform.controller; +import com.wcc.platform.domain.cms.attributes.ProgramType; import com.wcc.platform.domain.cms.pages.programme.ProgrammePage; import com.wcc.platform.service.ProgrammeService; import io.swagger.v3.oas.annotations.Operation; @@ -8,14 +9,13 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; /** Rest controller for all the programme apis. */ @RestController -@RequestMapping("/api/cms/v1/programme") -@Tag(name = "APIs relevant to Programme pages") +@Tag(name = "APIs relevant Programme pages") public class ProgrammeController { private final ProgrammeService service; @@ -25,10 +25,11 @@ public ProgrammeController(final ProgrammeService programmeService) { this.service = programmeService; } - @GetMapping("/bookClub") - @Operation(summary = "API to retrieve book club programme page") + @GetMapping("/api/cms/v1/programme") + @Operation(summary = "API to retrieve programme page") @ResponseStatus(HttpStatus.OK) - public ResponseEntity getBookClubPage() { - return ResponseEntity.ok(service.getBookClub()); + public ResponseEntity getProgrammePage( + @RequestParam(required = false, name = "type") ProgramType programmeType) { + return ResponseEntity.ok(service.getProgrammePage(programmeType)); } } diff --git a/src/main/java/com/wcc/platform/domain/cms/attributes/SimpleDetails.java b/src/main/java/com/wcc/platform/domain/cms/attributes/SimpleDetails.java deleted file mode 100644 index 5d1a211a..00000000 --- a/src/main/java/com/wcc/platform/domain/cms/attributes/SimpleDetails.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.wcc.platform.domain.cms.attributes; - -/** - * Details of a section or page. - * - * @param title - * @param description - * @param card - */ -public record SimpleDetails(String title, String description, Card card) {} diff --git a/src/main/java/com/wcc/platform/domain/cms/pages/programme/ProgrammeInfo.java b/src/main/java/com/wcc/platform/domain/cms/pages/programme/ProgrammeInfo.java deleted file mode 100644 index 0803e530..00000000 --- a/src/main/java/com/wcc/platform/domain/cms/pages/programme/ProgrammeInfo.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.wcc.platform.domain.cms.pages.programme; - -import com.wcc.platform.domain.cms.attributes.SimpleDetails; -import java.util.List; - -/** - * Common programme information. - * - * @param details for the programme - */ -public record ProgrammeInfo(List details) {} diff --git a/src/main/java/com/wcc/platform/domain/cms/pages/programme/ProgrammePage.java b/src/main/java/com/wcc/platform/domain/cms/pages/programme/ProgrammePage.java index d6c70f6c..1373d424 100644 --- a/src/main/java/com/wcc/platform/domain/cms/pages/programme/ProgrammePage.java +++ b/src/main/java/com/wcc/platform/domain/cms/pages/programme/ProgrammePage.java @@ -2,12 +2,21 @@ import com.wcc.platform.domain.cms.attributes.Contact; import com.wcc.platform.domain.cms.pages.Page; +import com.wcc.platform.domain.platform.EventSection; +import com.wcc.platform.domain.platform.Programme; +import java.util.List; /** * BookClub programme details. * * @param page basic information of the page * @param contact social network contact information - * @param programmeInfo programme details section + * @param programmeDetails programme details section + * @param eventSection event details section */ -public record ProgrammePage(Page page, Contact contact, ProgrammeInfo programmeInfo) {} +public record ProgrammePage( + Page page, + Contact contact, + List programmeDetails, + List eventSection) {} + // TODO Add resources section diff --git a/src/main/java/com/wcc/platform/domain/platform/Event.java b/src/main/java/com/wcc/platform/domain/platform/Event.java index dd53f14a..d370e1b1 100644 --- a/src/main/java/com/wcc/platform/domain/platform/Event.java +++ b/src/main/java/com/wcc/platform/domain/platform/Event.java @@ -22,9 +22,9 @@ public class Event { private ProgramType topics; private List images; private String speaker; - private SimpleLink speakerLink; // linkedin + private SimpleLink speakerProfileLink; private String host; - private SimpleLink hostLink; // linkedin + private SimpleLink hostProfileLink; private SimpleLink eventLink; private List eventResources; @@ -38,20 +38,22 @@ public Event( final ProgramType topics, final List images, final String speaker, - final SimpleLink speakerLink, // linkedin + final SimpleLink speakerProfileLink, final String host, - final SimpleLink hostLink, // linkedin + final SimpleLink hostProfileLink, final SimpleLink eventLink, final List eventResources) { + this.title = title; + this.description = description; this.eventType = eventType; this.startDate = startDate; this.endDate = endDate; this.topics = topics; this.images = images; this.speaker = speaker; - this.speakerLink = speakerLink; // linkedin + this.speakerProfileLink = speakerProfileLink; this.host = host; - this.hostLink = hostLink; // linkedin + this.hostProfileLink = hostProfileLink; this.eventLink = eventLink; this.eventResources = eventResources; } diff --git a/src/main/java/com/wcc/platform/domain/platform/EventSection.java b/src/main/java/com/wcc/platform/domain/platform/EventSection.java new file mode 100644 index 00000000..b2ae7862 --- /dev/null +++ b/src/main/java/com/wcc/platform/domain/platform/EventSection.java @@ -0,0 +1,22 @@ +package com.wcc.platform.domain.platform; + +import com.wcc.platform.domain.cms.attributes.SimpleLink; +import java.util.List; +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class EventSection { + String title; + SimpleLink link; + List events; + + public EventSection(final String title, final SimpleLink link, final List events) { + this.title = title; + this.link = link; + this.events = events; + } + + public EventSection() {} +} diff --git a/src/main/java/com/wcc/platform/domain/platform/Programme.java b/src/main/java/com/wcc/platform/domain/platform/Programme.java new file mode 100644 index 00000000..08339b01 --- /dev/null +++ b/src/main/java/com/wcc/platform/domain/platform/Programme.java @@ -0,0 +1,24 @@ +package com.wcc.platform.domain.platform; + +import com.wcc.platform.domain.cms.attributes.Card; +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class Programme { + + String title; + + String description; + + Card card; + + public Programme(final String title, final String description, final Card card) { + this.title = title; + this.description = description; + this.card = card; + } + + public Programme() {} +} diff --git a/src/main/java/com/wcc/platform/service/ProgrammeService.java b/src/main/java/com/wcc/platform/service/ProgrammeService.java index 26d7e30a..9e2674d8 100644 --- a/src/main/java/com/wcc/platform/service/ProgrammeService.java +++ b/src/main/java/com/wcc/platform/service/ProgrammeService.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.wcc.platform.domain.cms.attributes.ProgramType; import com.wcc.platform.domain.cms.pages.programme.ProgrammePage; import com.wcc.platform.domain.exceptions.PlatformInternalException; import com.wcc.platform.utils.FileUtil; @@ -22,13 +23,16 @@ public ProgrammeService(final ObjectMapper objectMapper) { } /** - * API to fetch the information about BookClub programme. + * API to fetch details about different type of programmes. * - * @return BookClub json response + * @return Programme Page json response */ - public ProgrammePage getBookClub() { + public ProgrammePage getProgrammePage(ProgramType programType) { try { - final String data = FileUtil.readFileAsString(PROG_BOOK_CLUB.getFileName()); + String data = null; + if (ProgramType.BOOK_CLUB.equals(programType)) { + data = FileUtil.readFileAsString(PROG_BOOK_CLUB.getFileName()); + } return objectMapper.readValue(data, ProgrammePage.class); } catch (JsonProcessingException e) { throw new PlatformInternalException(e.getMessage(), e); diff --git a/src/main/resources/bookClubPage.json b/src/main/resources/bookClubPage.json index b6706b30..44e927f4 100644 --- a/src/main/resources/bookClubPage.json +++ b/src/main/resources/bookClubPage.json @@ -13,70 +13,72 @@ } ] }, - "programme": { - "details": [ - { - "title": "How It Works", - "description": "Every month we vote for a book to read, and at the end of the month we review the book together in our bookclub. In order to participate join us n slack.", - "card": null - }, - { - "title": "Benefits of Joining", - "description": "Dedication, networking and always knowing what is happening in tech market.", - "card": null - }, - { - "title": "What We Are Reading", - "description": "", - "card": { - "title": "The Pragmatic Programmer From Journeyman to Master", - "subtitle": "Andrew Hunt & David Thomas", - "description": "Essential guide for creating working and maintainable code amidst the complexities of modern software development.", - "link": { - "label": "View Book On GoodReads", - "uri": "http://goodread/book_link" - } + "programmeDetails": [ + { + "title": "How It Works", + "description": "Every month we vote for a book to read, and at the end of the month we review the book together in our bookclub. In order to participate join us n slack.", + "card": null + }, + { + "title": "Benefits of Joining", + "description": "Dedication, networking and always knowing what is happening in tech market.", + "card": null + }, + { + "title": "What We Are Reading", + "description": "", + "card": { + "title": "The Pragmatic Programmer From Journeyman to Master", + "subtitle": "Andrew Hunt & David Thomas", + "description": "Essential guide for creating working and maintainable code amidst the complexities of modern software development.", + "link": { + "label": "View Book On GoodReads", + "uri": "http://goodread/book_link" } } - ], - "event": { + } + ], + "eventSection": [ + { "title": "Upcoming events", "link": { "label": "View past events", "uri": "/eventsPage_link" }, - "eventCard": { - "title": "Book Club: book name", - "description": "Book description", - "host": [ - { - "link": { - "label": "Anna", - "uri": "profile" - } + "events": [ + { + "topics": "BOOK_CLUB", + "startDate": "THU, MAY 30, 2024, 8:00 PM CEST", + "endDate": "THU, MAY 30, 2024, 9.30 CEST", + "title": "BOOK MONTH AUG", + "description": "Book description", + "host": "Jane Doe", + "hostProfileLink": { + "label": "Jane Doe", + "uri": "https://linkedIn/host" }, - { - "link": { - "label": "Lana", - "uri": "profile" - } + "eventLink": { + "label": "Go to Meetup Event", + "uri": "https://meetup.com/event1" + } + }, + { + "topics": "BOOK_CLUB", + "startDate": "THU, MAY 30, 2024, 8:00 PM CEST", + "endDate": "THU, MAY 30, 2024, 9.30 CEST", + "title": "BOOK MONTH SEP", + "description": "Book description", + "host": "Jane Doe", + "hostProfileLink": { + "label": "Jane Doe", + "uri": "https://linkedIn/host" + }, + "eventLink": { + "label": "Go to Meetup Event", + "uri": "https://meetup.com/event1" } - ], - "eventLink": { - "label": "Go to Meetup Event", - "link": "https:/meet-up-link" } - } - }, - "resources": [ - { - "type": "Presentation files", - "link": "/drive/presentation" - }, - { - "type": "pdf", - "link": "/drive/presentation" - } - ] - } -} + ] + } + ] +} \ No newline at end of file diff --git a/src/main/resources/eventsPage.json b/src/main/resources/eventsPage.json index a7a381b6..b919ddf2 100644 --- a/src/main/resources/eventsPage.json +++ b/src/main/resources/eventsPage.json @@ -29,12 +29,12 @@ "endDate": "THU, MAY 30, 2024, 9.30 CEST", "title": "Book Club: The Pragmatic Programmer", "speaker": "Jane Doe", - "speakerLink": { + "speakerProfileLink": { "label": "John Doe", "uri": "https://meetup.com/event1" }, "host": null, - "hostLink": null, + "hostProfileLink": null, "description": "Join us for a discussion of this essential guide to writing clear and maintainable code!", "images": [ { From 433a250f19138489f597eb3370f727a20a335eb1 Mon Sep 17 00:00:00 2001 From: Sonali Goel <112942761+goelsonali@users.noreply.github.com> Date: Tue, 6 Aug 2024 16:00:34 +0100 Subject: [PATCH 5/7] Add test for programme page Book club programme test --- config/pmd/custom-ruleset.xml | 8 ++ .../controller/ProgrammeController.java | 6 +- .../wcc/platform/domain/platform/Event.java | 23 ++- .../domain/platform/EventSection.java | 10 +- .../platform/domain/platform/Programme.java | 10 +- .../com/wcc/platform/service/CmsService.java | 134 +++++++++--------- .../platform/service/ProgrammeService.java | 2 +- src/main/resources/bookClubPage.json | 8 +- src/main/resources/eventsPage.json | 6 +- .../controller/ProgrammeControllerTest.java | 61 ++++++++ .../factories/SetupEventFactories.java | 23 +++ .../factories/SetupProgrammeFactories.java | 78 ++++++++++ .../service/ProgrammeServiceTest.java | 49 +++++++ src/test/resources/bookClubPage.json | 82 +++++++++++ 14 files changed, 398 insertions(+), 102 deletions(-) create mode 100644 src/test/java/com/wcc/platform/controller/ProgrammeControllerTest.java create mode 100644 src/test/java/com/wcc/platform/factories/SetupEventFactories.java create mode 100644 src/test/java/com/wcc/platform/factories/SetupProgrammeFactories.java create mode 100644 src/test/java/com/wcc/platform/service/ProgrammeServiceTest.java create mode 100644 src/test/resources/bookClubPage.json diff --git a/config/pmd/custom-ruleset.xml b/config/pmd/custom-ruleset.xml index a7a2617f..9b4d3f8f 100644 --- a/config/pmd/custom-ruleset.xml +++ b/config/pmd/custom-ruleset.xml @@ -48,4 +48,12 @@ + + + + + + + + diff --git a/src/main/java/com/wcc/platform/controller/ProgrammeController.java b/src/main/java/com/wcc/platform/controller/ProgrammeController.java index 22522ebb..a3cf351f 100644 --- a/src/main/java/com/wcc/platform/controller/ProgrammeController.java +++ b/src/main/java/com/wcc/platform/controller/ProgrammeController.java @@ -28,8 +28,8 @@ public ProgrammeController(final ProgrammeService programmeService) { @GetMapping("/api/cms/v1/programme") @Operation(summary = "API to retrieve programme page") @ResponseStatus(HttpStatus.OK) - public ResponseEntity getProgrammePage( - @RequestParam(required = false, name = "type") ProgramType programmeType) { - return ResponseEntity.ok(service.getProgrammePage(programmeType)); + public ResponseEntity getProgramme( + @RequestParam(required = false, name = "type") final ProgramType programmeType) { + return ResponseEntity.ok(service.getProgramme(programmeType)); } } diff --git a/src/main/java/com/wcc/platform/domain/platform/Event.java b/src/main/java/com/wcc/platform/domain/platform/Event.java index d370e1b1..78a77459 100644 --- a/src/main/java/com/wcc/platform/domain/platform/Event.java +++ b/src/main/java/com/wcc/platform/domain/platform/Event.java @@ -21,10 +21,8 @@ public class Event { private String endDate; private ProgramType topics; private List images; - private String speaker; - private SimpleLink speakerProfileLink; - private String host; - private SimpleLink hostProfileLink; + private SimpleLink speakerProfile; + private SimpleLink hostProfile; private SimpleLink eventLink; private List eventResources; @@ -37,12 +35,11 @@ public Event( final String endDate, final ProgramType topics, final List images, - final String speaker, - final SimpleLink speakerProfileLink, - final String host, - final SimpleLink hostProfileLink, + final SimpleLink speakerProfile, + final SimpleLink hostProfile, final SimpleLink eventLink, final List eventResources) { + this.id = UUID.randomUUID(); this.title = title; this.description = description; this.eventType = eventType; @@ -50,13 +47,13 @@ public Event( this.endDate = endDate; this.topics = topics; this.images = images; - this.speaker = speaker; - this.speakerProfileLink = speakerProfileLink; - this.host = host; - this.hostProfileLink = hostProfileLink; + this.speakerProfile = speakerProfile; + this.hostProfile = hostProfile; this.eventLink = eventLink; this.eventResources = eventResources; } - public Event() {} + public Event() { + // Necessary constructor for jackson. + } } diff --git a/src/main/java/com/wcc/platform/domain/platform/EventSection.java b/src/main/java/com/wcc/platform/domain/platform/EventSection.java index b2ae7862..d81ce06f 100644 --- a/src/main/java/com/wcc/platform/domain/platform/EventSection.java +++ b/src/main/java/com/wcc/platform/domain/platform/EventSection.java @@ -8,9 +8,9 @@ @Data @Builder public class EventSection { - String title; - SimpleLink link; - List events; + private String title; + private SimpleLink link; + private List events; public EventSection(final String title, final SimpleLink link, final List events) { this.title = title; @@ -18,5 +18,7 @@ public EventSection(final String title, final SimpleLink link, final List this.events = events; } - public EventSection() {} + public EventSection() { + // Necessary constructor for jackson. + } } diff --git a/src/main/java/com/wcc/platform/domain/platform/Programme.java b/src/main/java/com/wcc/platform/domain/platform/Programme.java index 08339b01..89a9cff1 100644 --- a/src/main/java/com/wcc/platform/domain/platform/Programme.java +++ b/src/main/java/com/wcc/platform/domain/platform/Programme.java @@ -8,11 +8,11 @@ @Builder public class Programme { - String title; + private String title; - String description; + private String description; - Card card; + private Card card; public Programme(final String title, final String description, final Card card) { this.title = title; @@ -20,5 +20,7 @@ public Programme(final String title, final String description, final Card card) this.card = card; } - public Programme() {} + public Programme() { + // Necessary constructor for jackson. + } } diff --git a/src/main/java/com/wcc/platform/service/CmsService.java b/src/main/java/com/wcc/platform/service/CmsService.java index a8b7c0b1..c684280a 100644 --- a/src/main/java/com/wcc/platform/service/CmsService.java +++ b/src/main/java/com/wcc/platform/service/CmsService.java @@ -16,86 +16,84 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -/** - * CMS service responsible for simple pages. - */ +/** CMS service responsible for simple pages. */ @Service public class CmsService { - private final ObjectMapper objectMapper; + private final ObjectMapper objectMapper; - @Autowired - public CmsService(final ObjectMapper objectMapper) { - this.objectMapper = objectMapper; - } + @Autowired + public CmsService(final ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } - /** - * Read JSON and convert to Pojo TeamPage. - * - * @return Pojo TeamPage. - */ - public TeamPage getTeam() { - try { - final File file = Path.of(FileUtil.getFileUri(TEAM.getFileName())).toFile(); - return objectMapper.readValue(file, TeamPage.class); - } catch (IOException e) { - throw new PlatformInternalException(e.getMessage(), e); - } + /** + * Read JSON and convert to Pojo TeamPage. + * + * @return Pojo TeamPage. + */ + public TeamPage getTeam() { + try { + final File file = Path.of(FileUtil.getFileUri(TEAM.getFileName())).toFile(); + return objectMapper.readValue(file, TeamPage.class); + } catch (IOException e) { + throw new PlatformInternalException(e.getMessage(), e); } + } - /** - * Read JSON and convert to Pojo FooterPage. - * - * @return Footer page - */ - public FooterPage getFooter() { - try { - final File file = Path.of(FileUtil.getFileUri(FOOTER.getFileName())).toFile(); - return objectMapper.readValue(file, FooterPage.class); - } catch (IOException e) { - throw new PlatformInternalException(e.getMessage(), e); - } + /** + * Read JSON and convert to Pojo FooterPage. + * + * @return Footer page + */ + public FooterPage getFooter() { + try { + final File file = Path.of(FileUtil.getFileUri(FOOTER.getFileName())).toFile(); + return objectMapper.readValue(file, FooterPage.class); + } catch (IOException e) { + throw new PlatformInternalException(e.getMessage(), e); } + } - /** - * Read JSON and convert to Pojo CollaboratorPage. - * - * @return Pojo CollaboratorPage. - */ - public CollaboratorPage getCollaborator() { - try { - final File file = Path.of(FileUtil.getFileUri(COLLABORATOR.getFileName())).toFile(); - return objectMapper.readValue(file, CollaboratorPage.class); - } catch (IOException e) { - throw new PlatformInternalException(e.getMessage(), e); - } + /** + * Read JSON and convert to Pojo CollaboratorPage. + * + * @return Pojo CollaboratorPage. + */ + public CollaboratorPage getCollaborator() { + try { + final File file = Path.of(FileUtil.getFileUri(COLLABORATOR.getFileName())).toFile(); + return objectMapper.readValue(file, CollaboratorPage.class); + } catch (IOException e) { + throw new PlatformInternalException(e.getMessage(), e); } + } - /** - * Read JSON and convert to Pojo CodeOfConductPage. - * - * @return Pojo CodeOfConductPage. - */ - public CodeOfConductPage getCodeOfConduct() { - try { - final File file = Path.of(FileUtil.getFileUri(CODE_OF_CONDUCT.getFileName())).toFile(); - return objectMapper.readValue(file, CodeOfConductPage.class); - } catch (IOException e) { - throw new PlatformInternalException(e.getMessage(), e); - } + /** + * Read JSON and convert to Pojo CodeOfConductPage. + * + * @return Pojo CodeOfConductPage. + */ + public CodeOfConductPage getCodeOfConduct() { + try { + final File file = Path.of(FileUtil.getFileUri(CODE_OF_CONDUCT.getFileName())).toFile(); + return objectMapper.readValue(file, CodeOfConductPage.class); + } catch (IOException e) { + throw new PlatformInternalException(e.getMessage(), e); } + } - /** - * read Json and convert to POJO event page - * - * @return POJO eventsPage - */ - public EventsPage getEvents() { - try { - final File file = Path.of(FileUtil.getFileUri(EVENTS.getFileName())).toFile(); - return objectMapper.readValue(file, EventsPage.class); - } catch (IOException e) { - throw new PlatformInternalException(e.getMessage(), e); - } + /** + * read Json and convert to POJO event page + * + * @return POJO eventsPage + */ + public EventsPage getEvents() { + try { + final String data = FileUtil.readFileAsString(EVENTS.getFileName()); + return objectMapper.readValue(data, EventsPage.class); + } catch (IOException e) { + throw new PlatformInternalException(e.getMessage(), e); } + } } diff --git a/src/main/java/com/wcc/platform/service/ProgrammeService.java b/src/main/java/com/wcc/platform/service/ProgrammeService.java index 9e2674d8..e27c6186 100644 --- a/src/main/java/com/wcc/platform/service/ProgrammeService.java +++ b/src/main/java/com/wcc/platform/service/ProgrammeService.java @@ -27,7 +27,7 @@ public ProgrammeService(final ObjectMapper objectMapper) { * * @return Programme Page json response */ - public ProgrammePage getProgrammePage(ProgramType programType) { + public ProgrammePage getProgramme(final ProgramType programType) { try { String data = null; if (ProgramType.BOOK_CLUB.equals(programType)) { diff --git a/src/main/resources/bookClubPage.json b/src/main/resources/bookClubPage.json index 44e927f4..5b853591 100644 --- a/src/main/resources/bookClubPage.json +++ b/src/main/resources/bookClubPage.json @@ -8,7 +8,7 @@ "title": "Join us in our Study Group Slack channel", "links": [ { - "type": "slack", + "type": "SLACK", "link": "http://shortlink_to_slack.com/#prog_book_club" } ] @@ -52,8 +52,7 @@ "endDate": "THU, MAY 30, 2024, 9.30 CEST", "title": "BOOK MONTH AUG", "description": "Book description", - "host": "Jane Doe", - "hostProfileLink": { + "hostProfile": { "label": "Jane Doe", "uri": "https://linkedIn/host" }, @@ -68,8 +67,7 @@ "endDate": "THU, MAY 30, 2024, 9.30 CEST", "title": "BOOK MONTH SEP", "description": "Book description", - "host": "Jane Doe", - "hostProfileLink": { + "hostProfile": { "label": "Jane Doe", "uri": "https://linkedIn/host" }, diff --git a/src/main/resources/eventsPage.json b/src/main/resources/eventsPage.json index b919ddf2..5f169641 100644 --- a/src/main/resources/eventsPage.json +++ b/src/main/resources/eventsPage.json @@ -28,13 +28,11 @@ "startDate": "THU, MAY 30, 2024, 8:00 PM CEST", "endDate": "THU, MAY 30, 2024, 9.30 CEST", "title": "Book Club: The Pragmatic Programmer", - "speaker": "Jane Doe", - "speakerProfileLink": { + "speakerProfile": { "label": "John Doe", "uri": "https://meetup.com/event1" }, - "host": null, - "hostProfileLink": null, + "hostProfile": null, "description": "Join us for a discussion of this essential guide to writing clear and maintainable code!", "images": [ { diff --git a/src/test/java/com/wcc/platform/controller/ProgrammeControllerTest.java b/src/test/java/com/wcc/platform/controller/ProgrammeControllerTest.java new file mode 100644 index 00000000..5180882a --- /dev/null +++ b/src/test/java/com/wcc/platform/controller/ProgrammeControllerTest.java @@ -0,0 +1,61 @@ +package com.wcc.platform.controller; + +import static com.wcc.platform.domain.cms.ApiResourcesFile.PROG_BOOK_CLUB; +import static com.wcc.platform.factories.SetupProgrammeFactories.createProgrammePageTest; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; +import static org.springframework.http.MediaType.APPLICATION_JSON; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import com.wcc.platform.domain.cms.attributes.ProgramType; +import com.wcc.platform.domain.exceptions.PlatformInternalException; +import com.wcc.platform.service.ProgrammeService; +import com.wcc.platform.utils.FileUtil; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.web.servlet.MockMvc; + +/** Unit test for the programme apis. */ +@WebMvcTest(ProgrammeController.class) +public class ProgrammeControllerTest { + public static final String API_PROGRAMME = "/api/cms/v1/programme"; + public static final String PROG_TYPE_BOOK_CLUB = "?type=BOOK_CLUB"; + @Autowired private MockMvc mockMvc; + + @MockBean private ProgrammeService service; + + @Test + void testInternalServerError() throws Exception { + when(service.getProgramme(ProgramType.BOOK_CLUB)) + .thenThrow(new PlatformInternalException("Invalid Json", new RuntimeException())); + + mockMvc + .perform( + get(String.format("%s%s", API_PROGRAMME, PROG_TYPE_BOOK_CLUB)) + .contentType(APPLICATION_JSON)) + .andExpect(status().isInternalServerError()) + .andExpect(jsonPath("$.status", is(500))) + .andExpect(jsonPath("$.message", is("Invalid Json"))) + .andExpect(jsonPath("$.details", is("uri=/api/cms/v1/programme"))); + } + + @Test + void testOkResponse() throws Exception { + var fileName = PROG_BOOK_CLUB.getFileName(); + var expectedJson = FileUtil.readFileAsString(fileName); + + when(service.getProgramme(ProgramType.BOOK_CLUB)).thenReturn(createProgrammePageTest(fileName)); + + mockMvc + .perform( + get(String.format("%s%s", API_PROGRAMME, PROG_TYPE_BOOK_CLUB)) + .contentType(APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().json(expectedJson)); + } +} diff --git a/src/test/java/com/wcc/platform/factories/SetupEventFactories.java b/src/test/java/com/wcc/platform/factories/SetupEventFactories.java new file mode 100644 index 00000000..c59df6e7 --- /dev/null +++ b/src/test/java/com/wcc/platform/factories/SetupEventFactories.java @@ -0,0 +1,23 @@ +package com.wcc.platform.factories; + +import com.wcc.platform.domain.cms.attributes.ProgramType; +import com.wcc.platform.domain.cms.attributes.SimpleLink; +import com.wcc.platform.domain.platform.Event; + +/** Event test factories. */ +public class SetupEventFactories { + /** + * Test factory for creating an event + * + * @return an object of {@link Event} + */ + public static Event createEventTest() { + return Event.builder() + .title("Test event title for book club") + .topics(ProgramType.BOOK_CLUB) + .hostProfile(new SimpleLink("hostName", "http://host-profile-link")) + .eventLink(new SimpleLink("Meetup", "http://meetup/link")) + .startDate("THU, MAY 30, 2024, 8:00 PM CEST") + .build(); + } +} diff --git a/src/test/java/com/wcc/platform/factories/SetupProgrammeFactories.java b/src/test/java/com/wcc/platform/factories/SetupProgrammeFactories.java new file mode 100644 index 00000000..6018fc9c --- /dev/null +++ b/src/test/java/com/wcc/platform/factories/SetupProgrammeFactories.java @@ -0,0 +1,78 @@ +package com.wcc.platform.factories; + +import static com.wcc.platform.factories.SetupEventFactories.createEventTest; +import static com.wcc.platform.factories.SetupFactories.OBJECT_MAPPER; +import static com.wcc.platform.factories.SetupFactories.createContactTest; +import static com.wcc.platform.factories.SetupFactories.createPageTest; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.wcc.platform.domain.cms.attributes.Card; +import com.wcc.platform.domain.cms.attributes.SimpleLink; +import com.wcc.platform.domain.cms.pages.programme.ProgrammePage; +import com.wcc.platform.domain.platform.EventSection; +import com.wcc.platform.domain.platform.Programme; +import com.wcc.platform.utils.FileUtil; +import java.util.Collections; + +/** Test factories for Programme. */ +public class SetupProgrammeFactories { + + /** + * Create a programme page with test data. + * + * @param fileName of a programme + * @return Programme Page + */ + public static ProgrammePage createProgrammePageTest(final String fileName) { + try { + final String content = FileUtil.readFileAsString(fileName); + return OBJECT_MAPPER.readValue(content, ProgrammePage.class); + } catch (JsonProcessingException e) { + return createProgrammePageTest(); + } + } + + /** + * Create a programme page with test data. + * + * @return Programme Page + */ + public static ProgrammePage createProgrammePageTest() { + return new ProgrammePage( + createPageTest(), + createContactTest(), + Collections.singletonList(createProgrammeDetails()), + Collections.singletonList(createEventSection())); + } + + /** + * Create Programme object with test data. + * + * @return Programme object + */ + public static Programme createProgrammeDetails() { + return Programme.builder() + .title("What We Are Reading") + .description("Every month we vote we read a book this is current month book.") + .card( + new Card( + "Test book title", + "Author of the book", + "test book description", + new SimpleLink("Good read", "htpp/link"))) + .build(); + } + + /** + * Create an EventSection object with test data. + * + * @return EventSection object + */ + public static EventSection createEventSection() { + return EventSection.builder() + .title("Upcoming Events") + .link(new SimpleLink("view events", "/events")) + .events(Collections.singletonList(createEventTest())) + .build(); + } +} diff --git a/src/test/java/com/wcc/platform/service/ProgrammeServiceTest.java b/src/test/java/com/wcc/platform/service/ProgrammeServiceTest.java new file mode 100644 index 00000000..6a5b170d --- /dev/null +++ b/src/test/java/com/wcc/platform/service/ProgrammeServiceTest.java @@ -0,0 +1,49 @@ +package com.wcc.platform.service; + +import static com.wcc.platform.factories.SetupProgrammeFactories.createProgrammePageTest; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.wcc.platform.domain.cms.attributes.ProgramType; +import com.wcc.platform.domain.cms.pages.programme.ProgrammePage; +import com.wcc.platform.domain.exceptions.PlatformInternalException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +/** Test class for ProgrammeService. */ +public class ProgrammeServiceTest { + private ObjectMapper objectMapper; + private ProgrammeService service; + + @BeforeEach + void setUp() { + objectMapper = Mockito.mock(ObjectMapper.class); + service = new ProgrammeService(objectMapper); + } + + @Test + void whenInvalidJsonProvided() throws JsonProcessingException { + when(objectMapper.readValue(anyString(), eq(ProgrammePage.class))) + .thenThrow(new JsonProcessingException("Invalid JSON") {}); + + var exception = + assertThrows( + PlatformInternalException.class, () -> service.getProgramme(ProgramType.BOOK_CLUB)); + assertEquals("Invalid JSON", exception.getMessage()); + } + + @Test + void whenValidJsonProvided() throws JsonProcessingException { + var programmePage = createProgrammePageTest("bookClubPage.json"); + when(objectMapper.readValue(anyString(), eq(ProgrammePage.class))).thenReturn(programmePage); + + var response = service.getProgramme(ProgramType.BOOK_CLUB); + assertEquals(programmePage, response); + } +} diff --git a/src/test/resources/bookClubPage.json b/src/test/resources/bookClubPage.json new file mode 100644 index 00000000..903c73db --- /dev/null +++ b/src/test/resources/bookClubPage.json @@ -0,0 +1,82 @@ +{ + "page": { + "title": "WCC Book Club", + "subtitle": "", + "description": "What sets our book club apart are the lively conversations, valuable insights and an opportunity to connect with like-minded individuals. The books we read are selected by the community, offering a diverse selection of tech books and essential soft skills topics.The book club meets monthly to share views, exchange ideas, and inspire personal and professional growth." + }, + "contact": { + "title": "Join us in our Study Group Slack channel", + "links": [ + { + "type": "SLACK", + "link": "http://shortlink_to_slack.com/prog_book_club" + } + ] + }, + "programmeDetails": [ + { + "title": "How It Works", + "description": "Every month we vote for a book to read, and at the end of the month we review the book together in our bookclub. In order to participate join us n slack.", + "card": null + }, + { + "title": "Benefits of Joining", + "description": "Dedication, networking and always knowing what is happening in tech market.", + "card": null + }, + { + "title": "What We Are Reading", + "description": "", + "card": { + "title": "The Pragmatic Programmer From Journeyman to Master", + "subtitle": "Andrew Hunt & David Thomas", + "description": "Essential guide for creating working and maintainable code amidst the complexities of modern software development.", + "link": { + "label": "View Book On GoodReads", + "uri": "http://goodread/book_link" + } + } + } + ], + "eventSection": [ + { + "title": "Upcoming events", + "link": { + "label": "View past events", + "uri": "/eventsPage_link" + }, + "events": [ + { + "topics": "BOOK_CLUB", + "startDate": "THU, MAY 30, 2024, 8:00 PM CEST", + "endDate": "THU, MAY 30, 2024, 9.30 CEST", + "title": "BOOK MONTH AUG", + "description": "Book description", + "hostProfile": { + "label": "Jane Doe", + "uri": "https://linkedIn/host" + }, + "eventLink": { + "label": "Go to Meetup Event", + "uri": "https://meetup.com/event1" + } + }, + { + "topics": "BOOK_CLUB", + "startDate": "THU, MAY 30, 2024, 8:00 PM CEST", + "endDate": "THU, MAY 30, 2024, 9.30 CEST", + "title": "BOOK MONTH SEP", + "description": "Book description", + "hostProfile": { + "label": "Jane Doe", + "uri": "https://linkedIn/host" + }, + "eventLink": { + "label": "Go to Meetup Event", + "uri": "https://meetup.com/event1" + } + } + ] + } + ] +} \ No newline at end of file From f538bea41f420eb00486f3d7fcc564661d7a7702 Mon Sep 17 00:00:00 2001 From: Sonali Goel <112942761+goelsonali@users.noreply.github.com> Date: Thu, 8 Aug 2024 18:05:52 +0100 Subject: [PATCH 6/7] More test added --- src/main/resources/bookClubPage.json | 2 +- .../domain/platform/ProgrammeTest.java | 41 ++++++++++++++++++- .../factories/SetupProgrammeFactories.java | 26 +++++++++++- .../service/CmsServiceIntegrationTest.java | 11 ++++- .../wcc/platform/service/CmsServiceTest.java | 10 +++++ 5 files changed, 85 insertions(+), 5 deletions(-) diff --git a/src/main/resources/bookClubPage.json b/src/main/resources/bookClubPage.json index 5b853591..6a896837 100644 --- a/src/main/resources/bookClubPage.json +++ b/src/main/resources/bookClubPage.json @@ -67,7 +67,7 @@ "endDate": "THU, MAY 30, 2024, 9.30 CEST", "title": "BOOK MONTH SEP", "description": "Book description", - "hostProfile": { + "speakerProfile": { "label": "Jane Doe", "uri": "https://linkedIn/host" }, diff --git a/src/test/java/com/wcc/platform/domain/platform/ProgrammeTest.java b/src/test/java/com/wcc/platform/domain/platform/ProgrammeTest.java index 18913b30..dd8c8de1 100644 --- a/src/test/java/com/wcc/platform/domain/platform/ProgrammeTest.java +++ b/src/test/java/com/wcc/platform/domain/platform/ProgrammeTest.java @@ -1,2 +1,41 @@ -package com.wcc.platform.domain.platform;public class ProgrammeTest { +package com.wcc.platform.domain.platform; + +import static com.wcc.platform.factories.SetupProgrammeFactories.createProgramme; +import static com.wcc.platform.factories.SetupProgrammeFactories.createProgrammeByType; +import static com.wcc.platform.factories.SetupProgrammeFactories.createProgrammeWithoutCard; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +import com.wcc.platform.domain.cms.attributes.ProgramType; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class ProgrammeTest { + + Programme testProgramme; + + @BeforeEach + void setup() { + testProgramme = createProgramme(); + } + + @Test + void testEquals() { + assertEquals(testProgramme, createProgramme()); + } + + @Test + void testNotEquals() { + assertNotEquals(testProgramme, createProgrammeByType(ProgramType.TECH_TALK)); + } + + @Test + void testHashCode() { + assertEquals(testProgramme.hashCode(), createProgramme().hashCode()); + } + + @Test + void testHashCodeNotEquals() { + assertNotEquals(testProgramme.hashCode(), createProgrammeWithoutCard().hashCode()); + } } diff --git a/src/test/java/com/wcc/platform/factories/SetupProgrammeFactories.java b/src/test/java/com/wcc/platform/factories/SetupProgrammeFactories.java index 6018fc9c..73b5f6ef 100644 --- a/src/test/java/com/wcc/platform/factories/SetupProgrammeFactories.java +++ b/src/test/java/com/wcc/platform/factories/SetupProgrammeFactories.java @@ -7,6 +7,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.wcc.platform.domain.cms.attributes.Card; +import com.wcc.platform.domain.cms.attributes.ProgramType; import com.wcc.platform.domain.cms.attributes.SimpleLink; import com.wcc.platform.domain.cms.pages.programme.ProgrammePage; import com.wcc.platform.domain.platform.EventSection; @@ -41,16 +42,25 @@ public static ProgrammePage createProgrammePageTest() { return new ProgrammePage( createPageTest(), createContactTest(), - Collections.singletonList(createProgrammeDetails()), + Collections.singletonList(createProgramme()), Collections.singletonList(createEventSection())); } + public static Programme createProgrammeByType(final ProgramType type) { + if (ProgramType.BOOK_CLUB.equals(type)) { + createProgramme(); + } else { + return createProgrammeWithoutCard(); + } + return null; + } + /** * Create Programme object with test data. * * @return Programme object */ - public static Programme createProgrammeDetails() { + public static Programme createProgramme() { return Programme.builder() .title("What We Are Reading") .description("Every month we vote we read a book this is current month book.") @@ -63,6 +73,18 @@ public static Programme createProgrammeDetails() { .build(); } + /** + * Create Programme object with test data. + * + * @return Programme object + */ + public static Programme createProgrammeWithoutCard() { + return Programme.builder() + .title("What We Are Reading") + .description("Every month we vote we read a book this is current month book.") + .build(); + } + /** * Create an EventSection object with test data. * diff --git a/src/test/java/com/wcc/platform/service/CmsServiceIntegrationTest.java b/src/test/java/com/wcc/platform/service/CmsServiceIntegrationTest.java index ce08125b..570a7971 100644 --- a/src/test/java/com/wcc/platform/service/CmsServiceIntegrationTest.java +++ b/src/test/java/com/wcc/platform/service/CmsServiceIntegrationTest.java @@ -2,8 +2,10 @@ import static com.wcc.platform.domain.cms.ApiResourcesFile.CODE_OF_CONDUCT; import static com.wcc.platform.domain.cms.ApiResourcesFile.COLLABORATOR; +import static com.wcc.platform.domain.cms.ApiResourcesFile.EVENTS; import static com.wcc.platform.domain.cms.ApiResourcesFile.FOOTER; import static com.wcc.platform.domain.cms.ApiResourcesFile.TEAM; +import static com.wcc.platform.factories.SetupEventFactories.createEventTest; import static com.wcc.platform.factories.SetupFactories.*; import static org.junit.jupiter.api.Assertions.*; @@ -65,9 +67,16 @@ void testGetCollaboratorPage() { @Test void testGetCodeOfConductPage() { var result = service.getCodeOfConduct(); - var expectedCodeOfConductPage = createCodeOfConductPageTest(CODE_OF_CONDUCT.getFileName()); assertEquals(expectedCodeOfConductPage, result); } + + @Test + void testGetEventsPage() { + var result = service.getEvents(); + var expectedEventsPage = createEventTest(EVENTS.getFileName()); + + assertEquals(expectedEventsPage, result); + } } diff --git a/src/test/java/com/wcc/platform/service/CmsServiceTest.java b/src/test/java/com/wcc/platform/service/CmsServiceTest.java index 94a08bd2..be83493f 100644 --- a/src/test/java/com/wcc/platform/service/CmsServiceTest.java +++ b/src/test/java/com/wcc/platform/service/CmsServiceTest.java @@ -125,4 +125,14 @@ void whenGetEventsValidJson() throws IOException { assertEquals(page, response); } + + @Test + void whenGetEventsInValidJson() throws IOException { + when(objectMapper.readValue(anyString(), eq(EventsPage.class))) + .thenThrow(new JsonProcessingException("Invalid JSON") {}); + + var exception = assertThrows(PlatformInternalException.class, service::getEvents); + + assertEquals("Invalid JSON", exception.getMessage()); + } } From 72825f05d219b8aad4c02f9a56fcfadb01d856cf Mon Sep 17 00:00:00 2001 From: Sonali Goel <112942761+goelsonali@users.noreply.github.com> Date: Fri, 9 Aug 2024 10:55:57 +0100 Subject: [PATCH 7/7] Review comments addressed Improvements after review comments incorporated --- config/pmd/custom-ruleset.xml | 8 --- .../controller/ProgrammeController.java | 2 +- .../wcc/platform/domain/platform/Event.java | 3 ++ .../domain/platform/EventSection.java | 8 +++ .../platform/domain/platform/Programme.java | 8 +++ .../com/wcc/platform/service/CmsService.java | 1 + .../domain/platform/EventSectionTest.java | 47 +++++++++++++++++ .../platform/domain/platform/EventTest.java | 50 +++++++++++++++++++ .../platform/domain/platform/MemberTest.java | 1 + .../domain/platform/ProgrammeTest.java | 3 +- .../factories/SetupEventFactories.java | 27 ++++++++++ .../factories/SetupProgrammeFactories.java | 16 +----- .../service/ProgrammeServiceTest.java | 2 +- 13 files changed, 150 insertions(+), 26 deletions(-) create mode 100644 src/test/java/com/wcc/platform/domain/platform/EventSectionTest.java create mode 100644 src/test/java/com/wcc/platform/domain/platform/EventTest.java diff --git a/config/pmd/custom-ruleset.xml b/config/pmd/custom-ruleset.xml index 9b4d3f8f..a7a2617f 100644 --- a/config/pmd/custom-ruleset.xml +++ b/config/pmd/custom-ruleset.xml @@ -48,12 +48,4 @@ - - - - - - - - diff --git a/src/main/java/com/wcc/platform/controller/ProgrammeController.java b/src/main/java/com/wcc/platform/controller/ProgrammeController.java index a3cf351f..2c34d8fe 100644 --- a/src/main/java/com/wcc/platform/controller/ProgrammeController.java +++ b/src/main/java/com/wcc/platform/controller/ProgrammeController.java @@ -29,7 +29,7 @@ public ProgrammeController(final ProgrammeService programmeService) { @Operation(summary = "API to retrieve programme page") @ResponseStatus(HttpStatus.OK) public ResponseEntity getProgramme( - @RequestParam(required = false, name = "type") final ProgramType programmeType) { + @RequestParam(name = "type") final ProgramType programmeType) { return ResponseEntity.ok(service.getProgramme(programmeType)); } } diff --git a/src/main/java/com/wcc/platform/domain/platform/Event.java b/src/main/java/com/wcc/platform/domain/platform/Event.java index e330ed04..5e3ef3a5 100644 --- a/src/main/java/com/wcc/platform/domain/platform/Event.java +++ b/src/main/java/com/wcc/platform/domain/platform/Event.java @@ -10,6 +10,7 @@ import lombok.Builder; import lombok.Data; +/** Event class with all the relevant attributes for an event. */ @Data @Builder public class Event { @@ -26,6 +27,8 @@ public class Event { private SimpleLink eventLink; private List eventResources; + /** Event builder. */ + @SuppressWarnings("PMD.ExcessiveParameterList") public Event( final UUID id, final String title, diff --git a/src/main/java/com/wcc/platform/domain/platform/EventSection.java b/src/main/java/com/wcc/platform/domain/platform/EventSection.java index d81ce06f..5403ffb1 100644 --- a/src/main/java/com/wcc/platform/domain/platform/EventSection.java +++ b/src/main/java/com/wcc/platform/domain/platform/EventSection.java @@ -5,6 +5,7 @@ import lombok.Builder; import lombok.Data; +/** EventSection representing list of events {@link Event}. */ @Data @Builder public class EventSection { @@ -12,6 +13,13 @@ public class EventSection { private SimpleLink link; private List events; + /** + * Builder for the EventSection. + * + * @param title like - "Upcoming Events" or "Past Events" + * @param link link to the Events page + * @param events list of events to show + */ public EventSection(final String title, final SimpleLink link, final List events) { this.title = title; this.link = link; diff --git a/src/main/java/com/wcc/platform/domain/platform/Programme.java b/src/main/java/com/wcc/platform/domain/platform/Programme.java index 89a9cff1..bce97ede 100644 --- a/src/main/java/com/wcc/platform/domain/platform/Programme.java +++ b/src/main/java/com/wcc/platform/domain/platform/Programme.java @@ -4,6 +4,7 @@ import lombok.Builder; import lombok.Data; +/** Programme class representing the structure of any programme section of a programme page. */ @Data @Builder public class Programme { @@ -14,6 +15,13 @@ public class Programme { private Card card; + /** + * Programme Builder. + * + * @param title like - heading of the programme + * @param description details co-relating the title + * @param card if any details to be represented in a card + */ public Programme(final String title, final String description, final Card card) { this.title = title; this.description = description; diff --git a/src/main/java/com/wcc/platform/service/CmsService.java b/src/main/java/com/wcc/platform/service/CmsService.java index 898bfd77..cc21b941 100644 --- a/src/main/java/com/wcc/platform/service/CmsService.java +++ b/src/main/java/com/wcc/platform/service/CmsService.java @@ -19,6 +19,7 @@ import org.springframework.stereotype.Service; /** CMS service responsible for simple pages. */ +@SuppressWarnings("PMD.TooManyStaticImports") @Service public class CmsService { private final ObjectMapper objectMapper; diff --git a/src/test/java/com/wcc/platform/domain/platform/EventSectionTest.java b/src/test/java/com/wcc/platform/domain/platform/EventSectionTest.java new file mode 100644 index 00000000..2b94dbc5 --- /dev/null +++ b/src/test/java/com/wcc/platform/domain/platform/EventSectionTest.java @@ -0,0 +1,47 @@ +package com.wcc.platform.domain.platform; + +import static com.wcc.platform.factories.SetupEventFactories.createEventSection; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.wcc.platform.domain.cms.attributes.ProgramType; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** Test class for the class {@link EventSection}. */ +class EventSectionTest { + + EventSection testEventSection; + + @BeforeEach + void setup() { + testEventSection = createEventSection(); + } + + @Test + void testEquals() { + assertEquals(testEventSection, createEventSection(ProgramType.BOOK_CLUB)); + } + + @Test + void testNotEquals() { + assertNotEquals(testEventSection, createEventSection(ProgramType.TECH_TALK)); + } + + @Test + void testHashCode() { + assertEquals(testEventSection.hashCode(), createEventSection(ProgramType.BOOK_CLUB).hashCode()); + } + + @Test + void testHashCodeNotEquals() { + assertNotEquals( + testEventSection.hashCode(), createEventSection(ProgramType.TECH_TALK).hashCode()); + } + + @Test + void testToString() { + assertTrue(testEventSection.toString().contains(ProgramType.BOOK_CLUB.toString())); + } +} diff --git a/src/test/java/com/wcc/platform/domain/platform/EventTest.java b/src/test/java/com/wcc/platform/domain/platform/EventTest.java new file mode 100644 index 00000000..583bdc16 --- /dev/null +++ b/src/test/java/com/wcc/platform/domain/platform/EventTest.java @@ -0,0 +1,50 @@ +package com.wcc.platform.domain.platform; + +import static com.wcc.platform.factories.SetupEventFactories.createEventTest; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.wcc.platform.domain.cms.attributes.ProgramType; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** Test class for the class {@link Event}. */ +class EventTest { + + Event testEvent; + + @BeforeEach + void setup() { + testEvent = createEventTest(); + } + + @Test + void testEqual() { + assertEquals(testEvent, createEventTest(ProgramType.BOOK_CLUB)); + } + + @Test + void testNotEqual() { + assertNotEquals(testEvent, createEventTest(ProgramType.TECH_TALK)); + assertNotEquals(testEvent, createEventTest(ProgramType.WRITING_CLUB)); + assertNotEquals( + createEventTest(ProgramType.WRITING_CLUB), createEventTest(ProgramType.TECH_TALK)); + } + + @Test + void testHashCode() { + assertEquals(testEvent.hashCode(), createEventTest(ProgramType.BOOK_CLUB).hashCode()); + } + + @Test + void testHashCodeNotEquals() { + assertNotEquals(testEvent.hashCode(), createEventTest(ProgramType.WRITING_CLUB).hashCode()); + } + + @Test + void testToString() { + assertTrue(testEvent.toString().contains(ProgramType.BOOK_CLUB.toString())); + assertTrue(testEvent.toString().contains(ProgramType.BOOK_CLUB.toString())); + } +} diff --git a/src/test/java/com/wcc/platform/domain/platform/MemberTest.java b/src/test/java/com/wcc/platform/domain/platform/MemberTest.java index bf69cc7d..fcf5262a 100644 --- a/src/test/java/com/wcc/platform/domain/platform/MemberTest.java +++ b/src/test/java/com/wcc/platform/domain/platform/MemberTest.java @@ -8,6 +8,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +/** Test for class {@link Member} */ class MemberTest { private Member member; diff --git a/src/test/java/com/wcc/platform/domain/platform/ProgrammeTest.java b/src/test/java/com/wcc/platform/domain/platform/ProgrammeTest.java index dd8c8de1..e8431260 100644 --- a/src/test/java/com/wcc/platform/domain/platform/ProgrammeTest.java +++ b/src/test/java/com/wcc/platform/domain/platform/ProgrammeTest.java @@ -10,7 +10,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class ProgrammeTest { +/** Test class for {@link Programme}. */ +class ProgrammeTest { Programme testProgramme; diff --git a/src/test/java/com/wcc/platform/factories/SetupEventFactories.java b/src/test/java/com/wcc/platform/factories/SetupEventFactories.java index 805e30b0..91bda6f2 100644 --- a/src/test/java/com/wcc/platform/factories/SetupEventFactories.java +++ b/src/test/java/com/wcc/platform/factories/SetupEventFactories.java @@ -10,6 +10,7 @@ import com.wcc.platform.domain.cms.attributes.SimpleLink; import com.wcc.platform.domain.cms.pages.EventsPage; import com.wcc.platform.domain.platform.Event; +import com.wcc.platform.domain.platform.EventSection; import com.wcc.platform.utils.FileUtil; import java.util.Collections; import java.util.List; @@ -51,4 +52,30 @@ public static EventsPage createEventPageTest(final List events) { var hero = new HeroSection("title", "event description", createImageTest()); return new EventsPage(events, hero, createContactTest()); } + + /** + * Create an EventSection object with test data. + * + * @return EventSection object + */ + public static EventSection createEventSection() { + return EventSection.builder() + .title("Upcoming Events") + .link(new SimpleLink("view events", "/events")) + .events(Collections.singletonList(createEventTest())) + .build(); + } + + /** + * Create an EventSection object with test data. + * + * @return EventSection object + */ + public static EventSection createEventSection(final ProgramType programType) { + return EventSection.builder() + .title("Upcoming Events") + .link(new SimpleLink("view events", "/events")) + .events(Collections.singletonList(createEventTest(programType))) + .build(); + } } diff --git a/src/test/java/com/wcc/platform/factories/SetupProgrammeFactories.java b/src/test/java/com/wcc/platform/factories/SetupProgrammeFactories.java index 73b5f6ef..1f75e66a 100644 --- a/src/test/java/com/wcc/platform/factories/SetupProgrammeFactories.java +++ b/src/test/java/com/wcc/platform/factories/SetupProgrammeFactories.java @@ -1,6 +1,6 @@ package com.wcc.platform.factories; -import static com.wcc.platform.factories.SetupEventFactories.createEventTest; +import static com.wcc.platform.factories.SetupEventFactories.createEventSection; import static com.wcc.platform.factories.SetupFactories.OBJECT_MAPPER; import static com.wcc.platform.factories.SetupFactories.createContactTest; import static com.wcc.platform.factories.SetupFactories.createPageTest; @@ -10,7 +10,6 @@ import com.wcc.platform.domain.cms.attributes.ProgramType; import com.wcc.platform.domain.cms.attributes.SimpleLink; import com.wcc.platform.domain.cms.pages.programme.ProgrammePage; -import com.wcc.platform.domain.platform.EventSection; import com.wcc.platform.domain.platform.Programme; import com.wcc.platform.utils.FileUtil; import java.util.Collections; @@ -84,17 +83,4 @@ public static Programme createProgrammeWithoutCard() { .description("Every month we vote we read a book this is current month book.") .build(); } - - /** - * Create an EventSection object with test data. - * - * @return EventSection object - */ - public static EventSection createEventSection() { - return EventSection.builder() - .title("Upcoming Events") - .link(new SimpleLink("view events", "/events")) - .events(Collections.singletonList(createEventTest())) - .build(); - } } diff --git a/src/test/java/com/wcc/platform/service/ProgrammeServiceTest.java b/src/test/java/com/wcc/platform/service/ProgrammeServiceTest.java index 6a5b170d..380b1945 100644 --- a/src/test/java/com/wcc/platform/service/ProgrammeServiceTest.java +++ b/src/test/java/com/wcc/platform/service/ProgrammeServiceTest.java @@ -17,7 +17,7 @@ import org.mockito.Mockito; /** Test class for ProgrammeService. */ -public class ProgrammeServiceTest { +class ProgrammeServiceTest { private ObjectMapper objectMapper; private ProgrammeService service;