diff --git a/.gitignore b/.gitignore index a2c7ee9d..6bf8daea 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ build/* # IntelliJ customizations !.idea/checkstyle-idea.xml !.idea/saveactions_settings.xml -!.idea/codeStyles/codeStyleConfig.xml +!.idea/codeStyles/* !.idea/codeStyleSettings.xml !.idea/externalDependencies.xml -!.idea/codeStyles \ No newline at end of file +!.idea/google-java-format.xml \ No newline at end of file diff --git a/.idea/google-java-format.xml b/.idea/google-java-format.xml new file mode 100644 index 00000000..8b57f452 --- /dev/null +++ b/.idea/google-java-format.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/saveactions_settings.xml b/.idea/saveactions_settings.xml new file mode 100644 index 00000000..656c27ff --- /dev/null +++ b/.idea/saveactions_settings.xml @@ -0,0 +1,27 @@ + + + + + + + diff --git a/README.md b/README.md index 4639f9da..46f7c657 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,11 @@ * [Setup](#setup) * [JAVA 21 with SDKMAN](#java-21-with-sdkman) * [Setup IntelliJ](#setup-intellij) + * [Lombok](#lombok) + * [Enable Save Actions](#enable-save-actions) + * [Enable Checkstyle Warnings](#enable-checkstyle-warnings) + * [Google Format](#google-format) + * [IntelliJ JRE Config](#intellij-jre-config) * [Run Locally](#run-locally) * [Open API Documentation](#open-api-documentation) @@ -17,8 +22,6 @@ This project uses Java 21, you can run in 21.0.2 or 21.0.3. If you have installed a different version on your machine and don't want to remove it, you can use **SDKMAN** development tool. -It will allow you to switch based on the Java version you want to use. -Here is the [link](https://sdkman.io). * Install SDKMAN @@ -55,7 +58,8 @@ Set the default Java version for your system: sdk default java 21.0.2-open ``` -To verify if the java version is correct use: +* To verify if the java version is correct use: + ```shell java -version ``` @@ -64,93 +68,74 @@ java -version #### Lombok -Install lombok plugin and enable Annotation Processing, as the image below: +Install lombok plugin and enable Annotation Processing, as the image below: ![image](docs/images/annotation-procession.png) #### Enable Save Actions - ![image](docs/images/save-actions.png) +![image](docs/images/save-actions.png) #### Enable Checkstyle Warnings Install checkstyle plugin and the configuration will be enabled -## Run Locally +#### Google Format -* Build and run tests +A google-java-format IntelliJ plugin is available from the plugin repository. To install it, go to +your IDE's settings and select the Plugins category. Click the Marketplace tab, search for the +google-java-format plugin, and click the Install button. -```shell -./gradlew clean build -``` +The plugin will be disabled by default. To enable it in the current project, go to +File→Settings...→google-java-format Settings (or IntelliJ IDEA→Preferences...→Other +Settings→google-java-format Settings on macOS) and check the Enable google-java-format checkbox. (A +notification will be presented when you first open a project offering to do this for you.) -* Create Jar +To enable it by default in new projects, use File→Other Settings→Default Settings.... -```shell -./gradlew clean bootJar -``` +When enabled, it will replace the normal Reformat Code and Optimize Imports actions. -* Start Spring Boot Application: +![image](docs/images/google-format.png) -```shell -./gradlew bootRun -``` - -* Access application on http://localhost:8080/api/cms/v1/team +##### IntelliJ JRE Config -<<<<<<< HEAD -## Open API Documentation +The google-java-format plugin uses some internal classes that aren't available without extra +configuration. To use the plugin, go to Help→Edit Custom VM Options... and paste in these lines: -* Access swagger at http://localhost:8080/swagger-ui/index.html -======= -## JAVA 21 - -This project uses Java 21, you can run in 21.0.2 or 21.0.3. If you have installed a different version on your machine -and don't want to remove it, you can use **SDKMAN** development tool. -It will allow you to switch based on the Java version you want to use. -Here is the [link](https://sdkman.io). - -* Install SDKMAN - -Open your terminal and run the following command: - -```shell -curl -s "https://get.sdkman.io" | bash -source "$HOME/.sdkman/bin/sdkman-init.sh" ``` - -* Check the list of available Java versions: - -```shell -sdk list java +--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED +--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED +--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED +--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED +--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED +--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED ``` -* Install the desired Java version +Once you've done that, restart the IDE. -```shell -sdk install java 21.0.2-open -``` +## Run Locally -* Use the specific java version in the current session on your terminal +* Build and run tests ```shell -sdk use java 21.0.2-open +./gradlew clean build ``` -## Set the default Java version for your system: - -* To set the newly installed Java version as the default: +* Create Jar ```shell -sdk default java 21.0.2-open +./gradlew clean bootJar ``` -* To verify if the java version is correct use: +* Start Spring Boot Application: ```shell -java -version +./gradlew bootRun ``` -## Api documentation +* Access application on http://localhost:8080/api/cms/v1/team + +## Open API Documentation -* [Access swagger api](http://localhost:8080/swagger-ui/index.html) and corresponding [openAPI docs here](http://localhost:8080/api-docs) +* [Access swagger api](http://localhost:8080/swagger-ui/index.html) and + corresponding [openAPI docs here](http://localhost:8080/api-docs) \ No newline at end of file diff --git a/docs/images/google-format.png b/docs/images/google-format.png new file mode 100644 index 00000000..ba9e7def Binary files /dev/null and b/docs/images/google-format.png differ diff --git a/src/main/java/com/wcc/platform/PlatformApplication.java b/src/main/java/com/wcc/platform/PlatformApplication.java index f6134c09..3f3d9a58 100644 --- a/src/main/java/com/wcc/platform/PlatformApplication.java +++ b/src/main/java/com/wcc/platform/PlatformApplication.java @@ -5,12 +5,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Import; +/** Spring application service. */ @SpringBootApplication @Import(ObjectMapperConfig.class) public class PlatformApplication { - public static void main(String[] args) { - SpringApplication.run(PlatformApplication.class, args); - } - + public static void main(String[] args) { + SpringApplication.run(PlatformApplication.class, args); + } } diff --git a/src/main/java/com/wcc/platform/configuration/GlobalExceptionHandler.java b/src/main/java/com/wcc/platform/configuration/GlobalExceptionHandler.java index b70d608c..14944ee2 100644 --- a/src/main/java/com/wcc/platform/configuration/GlobalExceptionHandler.java +++ b/src/main/java/com/wcc/platform/configuration/GlobalExceptionHandler.java @@ -13,24 +13,27 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.context.request.WebRequest; +/** Global controller to handle all exceptions for the API. */ @RestControllerAdvice public class GlobalExceptionHandler { - @ExceptionHandler(ContentNotFoundException.class) - @ResponseStatus(HttpStatus.NOT_FOUND) - public ResponseEntity handleNotFoundException( - ContentNotFoundException ex, WebRequest request) { - var errorDetails = - new ErrorDetails(NOT_FOUND.value(), ex.getMessage(), request.getDescription(false)); - return new ResponseEntity<>(errorDetails, NOT_FOUND); - } + /** Receive ContentNotFoundException and return {@link HttpStatus#NOT_FOUND}. */ + @ExceptionHandler(ContentNotFoundException.class) + @ResponseStatus(HttpStatus.NOT_FOUND) + public ResponseEntity handleNotFoundException( + ContentNotFoundException ex, WebRequest request) { + var errorDetails = + new ErrorDetails(NOT_FOUND.value(), ex.getMessage(), request.getDescription(false)); + return new ResponseEntity<>(errorDetails, NOT_FOUND); + } - @ExceptionHandler(PlatformInternalException.class) - @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) - public ResponseEntity handleInternalError(PlatformInternalException ex, WebRequest request) { - var errorDetails = - new ErrorDetails( - INTERNAL_SERVER_ERROR.value(), ex.getMessage(), request.getDescription(false)); - return new ResponseEntity<>(errorDetails, INTERNAL_SERVER_ERROR); - } + /** Receive PlatformInternalException and return {@link HttpStatus#INTERNAL_SERVER_ERROR}. */ + @ExceptionHandler(PlatformInternalException.class) + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + public ResponseEntity handleInternalError(PlatformInternalException ex, WebRequest request) { + var errorDetails = + new ErrorDetails( + INTERNAL_SERVER_ERROR.value(), ex.getMessage(), request.getDescription(false)); + return new ResponseEntity<>(errorDetails, INTERNAL_SERVER_ERROR); + } } diff --git a/src/main/java/com/wcc/platform/configuration/ObjectMapperConfig.java b/src/main/java/com/wcc/platform/configuration/ObjectMapperConfig.java index 0d7cac3d..cc3b8b14 100644 --- a/src/main/java/com/wcc/platform/configuration/ObjectMapperConfig.java +++ b/src/main/java/com/wcc/platform/configuration/ObjectMapperConfig.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.wcc.platform.deserializers.ImageTypeDeserializer; import com.wcc.platform.deserializers.MemberTypeDeserializer; import com.wcc.platform.deserializers.SocialNetworkTypeDeserializer; @@ -12,24 +13,28 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +/** ObjectMapperConfig. */ @Configuration public class ObjectMapperConfig { - @Bean - public ObjectMapper objectMapper() { - ObjectMapper objectMapper = new ObjectMapper(); + /** Create ObjectMapper bean and include custom serializer. */ + @Bean + public ObjectMapper objectMapper() { + ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); + objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); - registerCustomDeserializers(objectMapper); - return objectMapper; - } + registerCustomDeserializers(objectMapper); + return objectMapper; + } - private void registerCustomDeserializers(ObjectMapper objectMapper) { - objectMapper.registerModule( + private void registerCustomDeserializers(ObjectMapper objectMapper) { + objectMapper + .registerModule(new JavaTimeModule()) + .registerModule( new SimpleModule() .addDeserializer(MemberType.class, new MemberTypeDeserializer()) .addDeserializer(ImageType.class, new ImageTypeDeserializer()) .addDeserializer(SocialNetworkType.class, new SocialNetworkTypeDeserializer())); - } -} \ No newline at end of file + } +} diff --git a/src/main/java/com/wcc/platform/controller/AboutController.java b/src/main/java/com/wcc/platform/controller/AboutController.java index 1403f58c..31b0cdff 100644 --- a/src/main/java/com/wcc/platform/controller/AboutController.java +++ b/src/main/java/com/wcc/platform/controller/AboutController.java @@ -1,8 +1,8 @@ package com.wcc.platform.controller; +import com.wcc.platform.domain.cms.pages.CodeOfConductPage; import com.wcc.platform.domain.cms.pages.CollaboratorPage; import com.wcc.platform.domain.cms.pages.TeamPage; -import com.wcc.platform.domain.cms.pages.CodeOfConductPage; import com.wcc.platform.service.CmsService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -14,51 +14,52 @@ import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; +/** Rest controller for about pages apis. */ @RestController @RequestMapping("/api/cms/v1/") @Tag(name = "APIs relevant About Us section") public class AboutController { - private final CmsService cmsService; + private final CmsService cmsService; - @Autowired - public AboutController(CmsService service) { - this.cmsService = service; - } + @Autowired + public AboutController(CmsService service) { + this.cmsService = service; + } - /** - * API to retrieve information about leadership team members. - * - * @return Leadership team page content. - */ - @GetMapping("/team") - @Operation(summary = "API to retrieve information about leadership team members") - @ResponseStatus(HttpStatus.OK) - public ResponseEntity getTeamPage() { - return ResponseEntity.ok(cmsService.getTeam()); - } + /** + * API to retrieve information about leadership team members. + * + * @return Leadership team page content. + */ + @GetMapping("/team") + @Operation(summary = "API to retrieve information about leadership team members") + @ResponseStatus(HttpStatus.OK) + public ResponseEntity getTeamPage() { + return ResponseEntity.ok(cmsService.getTeam()); + } - /** - * API to retrieve information about collaborators. - * - * @return Collaborators page content. - */ - @GetMapping("/collaborators") - @Operation(summary = "API to retrieve information about collaborators") - @ResponseStatus(HttpStatus.OK) - public ResponseEntity getCollaboratorPage() { - return ResponseEntity.ok(cmsService.getCollaborator()); - } + /** + * API to retrieve information about collaborators. + * + * @return Collaborators page content. + */ + @GetMapping("/collaborators") + @Operation(summary = "API to retrieve information about collaborators") + @ResponseStatus(HttpStatus.OK) + public ResponseEntity getCollaboratorPage() { + return ResponseEntity.ok(cmsService.getCollaborator()); + } - /** - * API to retrieve information about Code of conduct. - * - * @return Code of conduct page content. - */ - @GetMapping("/code-of-conduct") - @Operation(summary = "API to retrieve information about Code of conduct") - @ResponseStatus(HttpStatus.OK) - public ResponseEntity getCodeOfConductPage() { - return ResponseEntity.ok(cmsService.getCodeOfConduct()); - } + /** + * API to retrieve information about Code of conduct. + * + * @return Code of conduct page content. + */ + @GetMapping("/code-of-conduct") + @Operation(summary = "API to retrieve information about Code of conduct") + @ResponseStatus(HttpStatus.OK) + public ResponseEntity getCodeOfConductPage() { + return ResponseEntity.ok(cmsService.getCodeOfConduct()); + } } diff --git a/src/main/java/com/wcc/platform/controller/FooterController.java b/src/main/java/com/wcc/platform/controller/FooterController.java index 683f6bdf..ed10120b 100644 --- a/src/main/java/com/wcc/platform/controller/FooterController.java +++ b/src/main/java/com/wcc/platform/controller/FooterController.java @@ -12,27 +12,28 @@ import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; +/** Rest controller for footer api. */ @RestController @RequestMapping("/api/cms/v1/") @Tag(name = "API relevant to footer section") public class FooterController { - private final CmsService cmsService; + private final CmsService cmsService; - @Autowired - public FooterController(CmsService cmsService) { - this.cmsService = cmsService; - } + @Autowired + public FooterController(CmsService cmsService) { + this.cmsService = cmsService; + } - /** - * API to retrieve footer section details. - * - * @return Footer content. - */ - @GetMapping("/footer") - @Operation(summary = "API to retrieve footer section details") - @ResponseStatus(HttpStatus.OK) - public ResponseEntity getFooterPage() { - return ResponseEntity.ok(cmsService.getFooter()); - } + /** + * API to retrieve footer section details. + * + * @return Footer content. + */ + @GetMapping("/footer") + @Operation(summary = "API to retrieve footer section details") + @ResponseStatus(HttpStatus.OK) + public ResponseEntity getFooterPage() { + return ResponseEntity.ok(cmsService.getFooter()); + } } diff --git a/src/main/java/com/wcc/platform/controller/MentorshipController.java b/src/main/java/com/wcc/platform/controller/MentorshipController.java index da1bc701..371e4d3b 100644 --- a/src/main/java/com/wcc/platform/controller/MentorshipController.java +++ b/src/main/java/com/wcc/platform/controller/MentorshipController.java @@ -12,23 +12,23 @@ import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; +/** Rest controller for mentorship apis. */ @RestController @RequestMapping("/api/cms/v1/mentorship") @Tag(name = "APIs relevant Mentorship pages") public class MentorshipController { - private final MentorshipService service; + private final MentorshipService service; - @Autowired - public MentorshipController(MentorshipService service) { - this.service = service; - } - - @GetMapping("/overview") - @Operation(summary = "API to retrieve mentorship overview page") - @ResponseStatus(HttpStatus.OK) - public ResponseEntity getMentorshipOverview() { - return ResponseEntity.ok(service.getOverview()); - } + @Autowired + public MentorshipController(MentorshipService service) { + this.service = service; + } + @GetMapping("/overview") + @Operation(summary = "API to retrieve mentorship overview page") + @ResponseStatus(HttpStatus.OK) + public ResponseEntity getMentorshipOverview() { + return ResponseEntity.ok(service.getOverview()); + } } diff --git a/src/main/java/com/wcc/platform/deserializers/ImageTypeDeserializer.java b/src/main/java/com/wcc/platform/deserializers/ImageTypeDeserializer.java index 8da04280..b233f38c 100644 --- a/src/main/java/com/wcc/platform/deserializers/ImageTypeDeserializer.java +++ b/src/main/java/com/wcc/platform/deserializers/ImageTypeDeserializer.java @@ -7,17 +7,18 @@ import java.io.IOException; import java.util.Arrays; +/** Custom deserializer for ImageType Enum. */ public class ImageTypeDeserializer extends JsonDeserializer { - @Override - public ImageType deserialize(JsonParser jsonParser, DeserializationContext context) - throws IOException { + @Override + public ImageType deserialize(JsonParser jsonParser, DeserializationContext context) + throws IOException { - var value = jsonParser.getText(); + var value = jsonParser.getText(); - return Arrays.stream(ImageType.values()) - .filter(type -> type.name().equalsIgnoreCase(value)) - .findFirst() - .orElse(ImageType.DESKTOP); - } -} \ No newline at end of file + return Arrays.stream(ImageType.values()) + .filter(type -> type.name().equalsIgnoreCase(value)) + .findFirst() + .orElse(ImageType.DESKTOP); + } +} diff --git a/src/main/java/com/wcc/platform/deserializers/MemberTypeDeserializer.java b/src/main/java/com/wcc/platform/deserializers/MemberTypeDeserializer.java index 4f0700a2..c525cfd2 100644 --- a/src/main/java/com/wcc/platform/deserializers/MemberTypeDeserializer.java +++ b/src/main/java/com/wcc/platform/deserializers/MemberTypeDeserializer.java @@ -7,17 +7,18 @@ import java.io.IOException; import java.util.Arrays; +/** Custom deserializer for {@code MemberType} enum. */ public class MemberTypeDeserializer extends JsonDeserializer { - @Override - public MemberType deserialize(JsonParser jsonParser, DeserializationContext context) - throws IOException { + @Override + public MemberType deserialize(JsonParser jsonParser, DeserializationContext context) + throws IOException { - var value = jsonParser.getText(); + var value = jsonParser.getText(); - return Arrays.stream(MemberType.values()) - .filter(memberType -> memberType.name().equalsIgnoreCase(value)) - .findFirst() - .orElse(MemberType.MEMBER); - } -} \ No newline at end of file + return Arrays.stream(MemberType.values()) + .filter(memberType -> memberType.name().equalsIgnoreCase(value)) + .findFirst() + .orElse(MemberType.MEMBER); + } +} diff --git a/src/main/java/com/wcc/platform/deserializers/SocialNetworkTypeDeserializer.java b/src/main/java/com/wcc/platform/deserializers/SocialNetworkTypeDeserializer.java index 1fba37d2..2f872f08 100644 --- a/src/main/java/com/wcc/platform/deserializers/SocialNetworkTypeDeserializer.java +++ b/src/main/java/com/wcc/platform/deserializers/SocialNetworkTypeDeserializer.java @@ -7,20 +7,21 @@ import java.io.IOException; import java.util.Arrays; +/** Custom deserializer for {@link SocialNetworkType} enum. */ public class SocialNetworkTypeDeserializer extends JsonDeserializer { - @Override - public SocialNetworkType deserialize(JsonParser jsonParser, DeserializationContext context) { - try { - var value = jsonParser.getText(); + @Override + public SocialNetworkType deserialize(JsonParser jsonParser, DeserializationContext context) { + try { + var value = jsonParser.getText(); - return Arrays.stream(SocialNetworkType.values()) - .filter(memberType -> memberType.name().equalsIgnoreCase(value)) - .findFirst() - .orElse(SocialNetworkType.UNKNOWN); + return Arrays.stream(SocialNetworkType.values()) + .filter(memberType -> memberType.name().equalsIgnoreCase(value)) + .findFirst() + .orElse(SocialNetworkType.UNKNOWN); - } catch (IOException ex) { - return SocialNetworkType.UNKNOWN; - } + } catch (IOException ex) { + return SocialNetworkType.UNKNOWN; } -} \ No newline at end of file + } +} 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 114f23ac..3c66acdf 100644 --- a/src/main/java/com/wcc/platform/domain/cms/ApiResourcesFile.java +++ b/src/main/java/com/wcc/platform/domain/cms/ApiResourcesFile.java @@ -19,4 +19,5 @@ public enum ApiResourcesFile { public String getFileName() { return fileName; } -} + +} \ No newline at end of file diff --git a/src/main/java/com/wcc/platform/domain/cms/attributes/Contact.java b/src/main/java/com/wcc/platform/domain/cms/attributes/Contact.java index 59e6f4a3..8365fee0 100644 --- a/src/main/java/com/wcc/platform/domain/cms/attributes/Contact.java +++ b/src/main/java/com/wcc/platform/domain/cms/attributes/Contact.java @@ -3,6 +3,5 @@ import com.wcc.platform.domain.platform.SocialNetwork; import java.util.List; -public record Contact(String title, List links) { - -} +/** Record for Contact CMS data. */ +public record Contact(String title, List links) {} diff --git a/src/main/java/com/wcc/platform/domain/cms/attributes/Image.java b/src/main/java/com/wcc/platform/domain/cms/attributes/Image.java index 07896740..f4664fe5 100644 --- a/src/main/java/com/wcc/platform/domain/cms/attributes/Image.java +++ b/src/main/java/com/wcc/platform/domain/cms/attributes/Image.java @@ -1,5 +1,4 @@ package com.wcc.platform.domain.cms.attributes; -public record Image(String path, String alt, ImageType type) { - -} +/** Record for Image CMS data. */ +public record Image(String path, String alt, ImageType type) {} diff --git a/src/main/java/com/wcc/platform/domain/cms/attributes/ImageType.java b/src/main/java/com/wcc/platform/domain/cms/attributes/ImageType.java index 99132947..366b6134 100644 --- a/src/main/java/com/wcc/platform/domain/cms/attributes/ImageType.java +++ b/src/main/java/com/wcc/platform/domain/cms/attributes/ImageType.java @@ -1,5 +1,8 @@ package com.wcc.platform.domain.cms.attributes; +/** Allowed image types formats to be shown in the frontend. */ public enum ImageType { - MOBILE, DESKTOP, TABLET + MOBILE, + DESKTOP, + TABLET } diff --git a/src/main/java/com/wcc/platform/domain/cms/attributes/LabelLink.java b/src/main/java/com/wcc/platform/domain/cms/attributes/LabelLink.java index 344e624f..557cc76a 100644 --- a/src/main/java/com/wcc/platform/domain/cms/attributes/LabelLink.java +++ b/src/main/java/com/wcc/platform/domain/cms/attributes/LabelLink.java @@ -1,5 +1,4 @@ package com.wcc.platform.domain.cms.attributes; -public record LabelLink(String title, String label, String uri) { - -} +/** Web link attributes to be shown in the frontend. */ +public record LabelLink(String title, String label, String uri) {} diff --git a/src/main/java/com/wcc/platform/domain/cms/attributes/MemberByType.java b/src/main/java/com/wcc/platform/domain/cms/attributes/MemberByType.java index d5207753..0864b53b 100644 --- a/src/main/java/com/wcc/platform/domain/cms/attributes/MemberByType.java +++ b/src/main/java/com/wcc/platform/domain/cms/attributes/MemberByType.java @@ -3,8 +3,8 @@ import com.wcc.platform.domain.platform.LeadershipMember; import java.util.List; -public record MemberByType(List directors, - List leads, - List evangelists) { - -} +/** Community core team members grouped by types. */ +public record MemberByType( + List directors, + List leads, + List evangelists) {} diff --git a/src/main/java/com/wcc/platform/domain/cms/attributes/Network.java b/src/main/java/com/wcc/platform/domain/cms/attributes/Network.java index a43d7a05..17103d86 100644 --- a/src/main/java/com/wcc/platform/domain/cms/attributes/Network.java +++ b/src/main/java/com/wcc/platform/domain/cms/attributes/Network.java @@ -1,5 +1,10 @@ package com.wcc.platform.domain.cms.attributes; -public record Network(String type, String link) { - -} +/** + * Network Pojo class to be returned to frontend. + * + * @param type class name of the network based in the frontend pre-defined types. + * @param link uri link to the specific network. + */ +public record Network(String type, String link) {} +// TODO change network type to an enum of avaialables classNames. diff --git a/src/main/java/com/wcc/platform/domain/cms/attributes/PageSection.java b/src/main/java/com/wcc/platform/domain/cms/attributes/PageSection.java index f53d22ba..aa0f3f6a 100644 --- a/src/main/java/com/wcc/platform/domain/cms/attributes/PageSection.java +++ b/src/main/java/com/wcc/platform/domain/cms/attributes/PageSection.java @@ -2,5 +2,5 @@ import java.util.List; -public record PageSection(String title, String description, SimpleLink link, List topics) { -} +/** CMS Page Section which allows to listed related topics. */ +public record PageSection(String title, String description, SimpleLink link, List topics) {} diff --git a/src/main/java/com/wcc/platform/domain/cms/attributes/SimpleLink.java b/src/main/java/com/wcc/platform/domain/cms/attributes/SimpleLink.java index 4da0e27f..6fb5da8a 100644 --- a/src/main/java/com/wcc/platform/domain/cms/attributes/SimpleLink.java +++ b/src/main/java/com/wcc/platform/domain/cms/attributes/SimpleLink.java @@ -1,5 +1,4 @@ package com.wcc.platform.domain.cms.attributes; -public record SimpleLink(String label, String uri) { - -} +/** CMS Simple Link attributes. */ +public record SimpleLink(String label, String uri) {} diff --git a/src/main/java/com/wcc/platform/domain/cms/pages/CmsPage.java b/src/main/java/com/wcc/platform/domain/cms/pages/CmsPage.java deleted file mode 100644 index c81baf89..00000000 --- a/src/main/java/com/wcc/platform/domain/cms/pages/CmsPage.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.wcc.platform.domain.cms.pages; - -public class CmsPage { - - private final PageMetadata metadata; - private final PageData data; - - public CmsPage(PageMetadata metadata, PageData data) { - this.metadata = metadata; - this.data = data; - } - - public PageMetadata getMetadata() { - return metadata; - } - - public PageData getData() { - return data; - } -} diff --git a/src/main/java/com/wcc/platform/domain/cms/pages/CmsPaginatedPage.java b/src/main/java/com/wcc/platform/domain/cms/pages/CmsPaginatedPage.java new file mode 100644 index 00000000..fad6233c --- /dev/null +++ b/src/main/java/com/wcc/platform/domain/cms/pages/CmsPaginatedPage.java @@ -0,0 +1,21 @@ +package com.wcc.platform.domain.cms.pages; + +/** Generic CMS Paginated Page. */ +public class CmsPaginatedPage { + + private final PageMetadata metadata; + private final PageData data; + + public CmsPaginatedPage(PageMetadata metadata, PageData data) { + this.metadata = metadata; + this.data = data; + } + + public PageMetadata getMetadata() { + return metadata; + } + + public PageData getData() { + return data; + } +} diff --git a/src/main/java/com/wcc/platform/domain/cms/pages/CodeOfConductPage.java b/src/main/java/com/wcc/platform/domain/cms/pages/CodeOfConductPage.java index 9e71bf0c..50b8a6a5 100644 --- a/src/main/java/com/wcc/platform/domain/cms/pages/CodeOfConductPage.java +++ b/src/main/java/com/wcc/platform/domain/cms/pages/CodeOfConductPage.java @@ -2,5 +2,10 @@ import java.util.List; -public record CodeOfConductPage(Page page, List
items) { -} +/** + * CMS Code of conduct page. + * + * @param page Page details as title and description + * @param items all details + */ +public record CodeOfConductPage(Page page, List
items) {} diff --git a/src/main/java/com/wcc/platform/domain/cms/pages/CollaboratorPage.java b/src/main/java/com/wcc/platform/domain/cms/pages/CollaboratorPage.java index d9a2941a..17fb58cd 100644 --- a/src/main/java/com/wcc/platform/domain/cms/pages/CollaboratorPage.java +++ b/src/main/java/com/wcc/platform/domain/cms/pages/CollaboratorPage.java @@ -4,6 +4,5 @@ import com.wcc.platform.domain.platform.Member; import java.util.List; -public record CollaboratorPage(Page page, Contact contact, List collaborators) { - -} +/** CMS Collaborators Page to highlight volunteers in the community. */ +public record CollaboratorPage(Page page, Contact contact, List collaborators) {} diff --git a/src/main/java/com/wcc/platform/domain/cms/pages/FooterPage.java b/src/main/java/com/wcc/platform/domain/cms/pages/FooterPage.java index 7d5e134b..b38da47c 100644 --- a/src/main/java/com/wcc/platform/domain/cms/pages/FooterPage.java +++ b/src/main/java/com/wcc/platform/domain/cms/pages/FooterPage.java @@ -4,7 +4,6 @@ import com.wcc.platform.domain.cms.attributes.Network; import java.util.List; -public record FooterPage(String title, String subtitle, String description, List network, - LabelLink link) { - -} +/** CMS Footer section details. */ +public record FooterPage( + String title, String subtitle, String description, List network, LabelLink link) {} diff --git a/src/main/java/com/wcc/platform/domain/cms/pages/Page.java b/src/main/java/com/wcc/platform/domain/cms/pages/Page.java index efc20c2d..67a73d1b 100644 --- a/src/main/java/com/wcc/platform/domain/cms/pages/Page.java +++ b/src/main/java/com/wcc/platform/domain/cms/pages/Page.java @@ -1,5 +1,4 @@ package com.wcc.platform.domain.cms.pages; -public record Page(String title, String subtitle, String description) { - -} +/** CMS Page attributes. */ +public record Page(String title, String subtitle, String description) {} diff --git a/src/main/java/com/wcc/platform/domain/cms/pages/PageData.java b/src/main/java/com/wcc/platform/domain/cms/pages/PageData.java index ca370f77..1fbe57b4 100644 --- a/src/main/java/com/wcc/platform/domain/cms/pages/PageData.java +++ b/src/main/java/com/wcc/platform/domain/cms/pages/PageData.java @@ -2,6 +2,5 @@ import java.util.List; -public record PageData(String title, String subtitle, String description, List items) { - -} +/** Generic Page data to be returned in {@link CmsPaginatedPage}. */ +public record PageData(String title, String subtitle, String description, List items) {} diff --git a/src/main/java/com/wcc/platform/domain/cms/pages/PageMetadata.java b/src/main/java/com/wcc/platform/domain/cms/pages/PageMetadata.java index 2f3277f8..e2b7cdf5 100644 --- a/src/main/java/com/wcc/platform/domain/cms/pages/PageMetadata.java +++ b/src/main/java/com/wcc/platform/domain/cms/pages/PageMetadata.java @@ -1,5 +1,4 @@ package com.wcc.platform.domain.cms.pages; -public record PageMetadata(Pagination pagination) { - -} +/** CMS Page metadata attributes to be used to debug and to apply pagination. */ +public record PageMetadata(Pagination pagination) {} diff --git a/src/main/java/com/wcc/platform/domain/cms/pages/Pagination.java b/src/main/java/com/wcc/platform/domain/cms/pages/Pagination.java index 941f2e73..d6b0720c 100644 --- a/src/main/java/com/wcc/platform/domain/cms/pages/Pagination.java +++ b/src/main/java/com/wcc/platform/domain/cms/pages/Pagination.java @@ -1,5 +1,4 @@ package com.wcc.platform.domain.cms.pages; -public record Pagination(int totalItems, int totalPages, int currentPage, int pageSize) { - -} +/** CMS Pagination attributes. */ +public record Pagination(int totalItems, int totalPages, int currentPage, int pageSize) {} diff --git a/src/main/java/com/wcc/platform/domain/cms/pages/Section.java b/src/main/java/com/wcc/platform/domain/cms/pages/Section.java index 77d87e06..a59684c4 100644 --- a/src/main/java/com/wcc/platform/domain/cms/pages/Section.java +++ b/src/main/java/com/wcc/platform/domain/cms/pages/Section.java @@ -2,5 +2,5 @@ import java.util.List; -public record Section(String title, String description, List items) { -} +/** CMS Simple Section to be included in the pages. */ +public record Section(String title, String description, List items) {} diff --git a/src/main/java/com/wcc/platform/domain/cms/pages/TeamPage.java b/src/main/java/com/wcc/platform/domain/cms/pages/TeamPage.java index 8356d48c..98a680c2 100644 --- a/src/main/java/com/wcc/platform/domain/cms/pages/TeamPage.java +++ b/src/main/java/com/wcc/platform/domain/cms/pages/TeamPage.java @@ -3,6 +3,5 @@ import com.wcc.platform.domain.cms.attributes.Contact; import com.wcc.platform.domain.cms.attributes.MemberByType; -public record TeamPage(Page page, Contact contact, MemberByType membersByType) { - -} \ No newline at end of file +/** CMS Community Core Team Page grouped by members types. */ +public record TeamPage(Page page, Contact contact, MemberByType membersByType) {} diff --git a/src/main/java/com/wcc/platform/domain/cms/pages/mentorship/FeedbackItem.java b/src/main/java/com/wcc/platform/domain/cms/pages/mentorship/FeedbackItem.java index 22d7cb7f..dd24b1f6 100644 --- a/src/main/java/com/wcc/platform/domain/cms/pages/mentorship/FeedbackItem.java +++ b/src/main/java/com/wcc/platform/domain/cms/pages/mentorship/FeedbackItem.java @@ -2,5 +2,12 @@ import java.time.Year; -public record FeedbackItem(String name, String feedback, boolean mentee, Year year) { -} +/** + * Mentorship individual Feedbacks. + * + * @param name Mentee/Mentor Name + * @param feedback description of the feedback + * @param mentee flag to identify if it was a mentee or mentor feedback. + * @param year which year the feedback was given. + */ +public record FeedbackItem(String name, String feedback, boolean mentee, Year year) {} diff --git a/src/main/java/com/wcc/platform/domain/cms/pages/mentorship/FeedbackSection.java b/src/main/java/com/wcc/platform/domain/cms/pages/mentorship/FeedbackSection.java index 992127a0..fbb05045 100644 --- a/src/main/java/com/wcc/platform/domain/cms/pages/mentorship/FeedbackSection.java +++ b/src/main/java/com/wcc/platform/domain/cms/pages/mentorship/FeedbackSection.java @@ -2,5 +2,10 @@ import java.util.List; -public record FeedbackSection(String title, List feedbacks) { -} +/** + * CMS Feedback Section. + * + * @param title title to be shown in the feedback section + * @param feedbacks list of all feedbacks + */ +public record FeedbackSection(String title, List feedbacks) {} diff --git a/src/main/java/com/wcc/platform/domain/cms/pages/mentorship/MentorshipPage.java b/src/main/java/com/wcc/platform/domain/cms/pages/mentorship/MentorshipPage.java index 4ba1f0ed..d6785119 100644 --- a/src/main/java/com/wcc/platform/domain/cms/pages/mentorship/MentorshipPage.java +++ b/src/main/java/com/wcc/platform/domain/cms/pages/mentorship/MentorshipPage.java @@ -3,6 +3,16 @@ import com.wcc.platform.domain.cms.attributes.PageSection; import com.wcc.platform.domain.cms.pages.Page; -public record MentorshipPage(Page page, PageSection becomeMentorSection, PageSection becomeMenteeSection, - FeedbackSection feedbackSection) { -} +/** + * CMS Mentorship Page Overview details. + * + * @param page basic page details + * @param becomeMentorSection section to highlight why you apply to a become a mentor + * @param becomeMenteeSection section to highlight why you apply to a become a mentee + * @param feedbackSection section related to mentorship feedbacks + */ +public record MentorshipPage( + Page page, + PageSection becomeMentorSection, + PageSection becomeMenteeSection, + FeedbackSection feedbackSection) {} diff --git a/src/main/java/com/wcc/platform/domain/exceptions/ContentNotFoundException.java b/src/main/java/com/wcc/platform/domain/exceptions/ContentNotFoundException.java index 8f0405a5..1c690bac 100644 --- a/src/main/java/com/wcc/platform/domain/exceptions/ContentNotFoundException.java +++ b/src/main/java/com/wcc/platform/domain/exceptions/ContentNotFoundException.java @@ -1,8 +1,9 @@ package com.wcc.platform.domain.exceptions; +/** CMS Content not found exception. */ public class ContentNotFoundException extends RuntimeException { - public ContentNotFoundException(String message) { - super(message); - } + public ContentNotFoundException(String message) { + super(message); + } } diff --git a/src/main/java/com/wcc/platform/domain/exceptions/ErrorDetails.java b/src/main/java/com/wcc/platform/domain/exceptions/ErrorDetails.java index 3f60be51..f61c29d7 100644 --- a/src/main/java/com/wcc/platform/domain/exceptions/ErrorDetails.java +++ b/src/main/java/com/wcc/platform/domain/exceptions/ErrorDetails.java @@ -1,5 +1,4 @@ package com.wcc.platform.domain.exceptions; -public record ErrorDetails(int status, String message, String details) { - -} +/** CMS error details to give more context when some exception is trigger. */ +public record ErrorDetails(int status, String message, String details) {} diff --git a/src/main/java/com/wcc/platform/domain/exceptions/PlatformInternalException.java b/src/main/java/com/wcc/platform/domain/exceptions/PlatformInternalException.java index 48b0bfb8..f4651fb2 100644 --- a/src/main/java/com/wcc/platform/domain/exceptions/PlatformInternalException.java +++ b/src/main/java/com/wcc/platform/domain/exceptions/PlatformInternalException.java @@ -1,8 +1,9 @@ package com.wcc.platform.domain.exceptions; +/** Platform generic exception. */ public class PlatformInternalException extends RuntimeException { - public PlatformInternalException(String message, Throwable cause) { - super(message, cause); - } + public PlatformInternalException(String message, Throwable cause) { + super(message, cause); + } } diff --git a/src/main/java/com/wcc/platform/domain/platform/LeadershipMember.java b/src/main/java/com/wcc/platform/domain/platform/LeadershipMember.java index 19f5c7c2..e9da6b56 100644 --- a/src/main/java/com/wcc/platform/domain/platform/LeadershipMember.java +++ b/src/main/java/com/wcc/platform/domain/platform/LeadershipMember.java @@ -7,14 +7,12 @@ /** * Represents the core team of the community: {@link MemberType#DIRECTOR}, {@link MemberType#LEADER} - * and {@link MemberType#EVANGELIST} + * and {@link MemberType#EVANGELIST}. */ @Data @NoArgsConstructor @EqualsAndHashCode(callSuper = true) public class LeadershipMember extends Member { - @JsonIgnore - private MemberType memberType; - -} \ No newline at end of file + @JsonIgnore private MemberType memberType; +} diff --git a/src/main/java/com/wcc/platform/domain/platform/Member.java b/src/main/java/com/wcc/platform/domain/platform/Member.java index a0ff09ee..1ba884d2 100644 --- a/src/main/java/com/wcc/platform/domain/platform/Member.java +++ b/src/main/java/com/wcc/platform/domain/platform/Member.java @@ -5,13 +5,13 @@ import lombok.Data; import lombok.NoArgsConstructor; +/** Member Domain class with all attributes for all types of members. */ @Data @NoArgsConstructor public class Member { - - private String fullName; - private String position; - private MemberType memberType; - private List images; - private List network; -} \ No newline at end of file + private String fullName; + private String position; + private MemberType memberType; + private List images; + private List network; +} diff --git a/src/main/java/com/wcc/platform/domain/platform/MemberType.java b/src/main/java/com/wcc/platform/domain/platform/MemberType.java index 5becc226..c7c2b4b7 100644 --- a/src/main/java/com/wcc/platform/domain/platform/MemberType.java +++ b/src/main/java/com/wcc/platform/domain/platform/MemberType.java @@ -1,13 +1,14 @@ package com.wcc.platform.domain.platform; +/** All available member types in the community. */ public enum MemberType { - DIRECTOR, - LEADER, - EVANGELIST, - VOLUNTEER, - MENTOR, - MENTEE, - MEMBER, - SPEAKER, - COLLABORATOR -} \ No newline at end of file + DIRECTOR, + LEADER, + EVANGELIST, + VOLUNTEER, + MENTOR, + MENTEE, + MEMBER, + SPEAKER, + COLLABORATOR +} diff --git a/src/main/java/com/wcc/platform/domain/platform/SocialNetwork.java b/src/main/java/com/wcc/platform/domain/platform/SocialNetwork.java index a80b5d4c..fb3c0d61 100644 --- a/src/main/java/com/wcc/platform/domain/platform/SocialNetwork.java +++ b/src/main/java/com/wcc/platform/domain/platform/SocialNetwork.java @@ -1,5 +1,4 @@ package com.wcc.platform.domain.platform; -public record SocialNetwork(SocialNetworkType type, String link) { - -} \ No newline at end of file +/** Pojo of social network data of member, event or programme. */ +public record SocialNetwork(SocialNetworkType type, String link) {} diff --git a/src/main/java/com/wcc/platform/domain/platform/SocialNetworkType.java b/src/main/java/com/wcc/platform/domain/platform/SocialNetworkType.java index 5499349a..dd6d3784 100644 --- a/src/main/java/com/wcc/platform/domain/platform/SocialNetworkType.java +++ b/src/main/java/com/wcc/platform/domain/platform/SocialNetworkType.java @@ -1,21 +1,21 @@ package com.wcc.platform.domain.platform; +/** Community available network types. */ public enum SocialNetworkType { - YOUTUBE, - GITHUB, - LINKEDIN, - INSTAGRAM, - FACEBOOK, - X, - MEDIUM, - SLACK, - MEETUP, - EMAIL, - UNKNOWN; + YOUTUBE, + GITHUB, + LINKEDIN, + INSTAGRAM, + FACEBOOK, + X, + MEDIUM, + SLACK, + MEETUP, + EMAIL, + UNKNOWN; - - @Override - public String toString() { - return this.name().toLowerCase(); - } -} \ No newline at end of file + @Override + public String toString() { + return this.name().toLowerCase(); + } +} diff --git a/src/main/java/com/wcc/platform/service/CmsService.java b/src/main/java/com/wcc/platform/service/CmsService.java index 120e5bf2..33340f1a 100644 --- a/src/main/java/com/wcc/platform/service/CmsService.java +++ b/src/main/java/com/wcc/platform/service/CmsService.java @@ -18,69 +18,69 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +/** CMS service responsible for simple pages. */ @Service public class CmsService { + private final ObjectMapper objectMapper; - private final ObjectMapper objectMapper; + @Autowired + public CmsService(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } - @Autowired - public CmsService(ObjectMapper objectMapper) { - this.objectMapper = objectMapper; + /** + * Read JSON and convert to Pojo TeamPage. + * + * @return Pojo TeamPage. + */ + public TeamPage getTeam() { + try { + 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 { - 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 { + 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 { - 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 { + 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 { - 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 { + 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 { - 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); - } - } -} \ No newline at end of file + } +} diff --git a/src/main/java/com/wcc/platform/service/MentorshipService.java b/src/main/java/com/wcc/platform/service/MentorshipService.java index 42c164f5..17d6f25a 100644 --- a/src/main/java/com/wcc/platform/service/MentorshipService.java +++ b/src/main/java/com/wcc/platform/service/MentorshipService.java @@ -1,38 +1,38 @@ package com.wcc.platform.service; +import static com.wcc.platform.domain.cms.ApiResourcesFile.MENTORSHIP; + import com.fasterxml.jackson.databind.ObjectMapper; import com.wcc.platform.domain.cms.pages.mentorship.MentorshipPage; 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; - import java.io.File; import java.io.IOException; import java.nio.file.Path; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; -import static com.wcc.platform.domain.cms.ApiResourcesFile.MENTORSHIP; - +/** Mentorship service. */ @Service public class MentorshipService { - private final ObjectMapper objectMapper; + private final ObjectMapper objectMapper; - @Autowired - public MentorshipService(ObjectMapper objectMapper) { - this.objectMapper = objectMapper; - } + @Autowired + public MentorshipService(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } - /** - * API to retrieve information about mentorship overview. - * - * @return Mentorship overview page. - */ - public MentorshipPage getOverview() { - try { - File file = Path.of(FileUtil.getFileUri(MENTORSHIP.getFileName())).toFile(); - return objectMapper.readValue(file, MentorshipPage.class); - } catch (IOException e) { - throw new PlatformInternalException(e.getMessage(), e); - } + /** + * API to retrieve information about mentorship overview. + * + * @return Mentorship overview page. + */ + public MentorshipPage getOverview() { + try { + File file = Path.of(FileUtil.getFileUri(MENTORSHIP.getFileName())).toFile(); + return objectMapper.readValue(file, MentorshipPage.class); + } catch (IOException e) { + throw new PlatformInternalException(e.getMessage(), e); } -} \ No newline at end of file + } +} diff --git a/src/main/java/com/wcc/platform/utils/FileUtil.java b/src/main/java/com/wcc/platform/utils/FileUtil.java index a1423920..71564233 100644 --- a/src/main/java/com/wcc/platform/utils/FileUtil.java +++ b/src/main/java/com/wcc/platform/utils/FileUtil.java @@ -1,5 +1,7 @@ package com.wcc.platform.utils; +import static java.nio.charset.StandardCharsets.UTF_8; + import com.wcc.platform.domain.exceptions.ContentNotFoundException; import com.wcc.platform.domain.exceptions.PlatformInternalException; import java.io.BufferedReader; @@ -13,53 +15,52 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static java.nio.charset.StandardCharsets.UTF_8; - +/** Util class to read and write files. */ public class FileUtil { - private static final Logger logger = LoggerFactory.getLogger(FileUtil.class); - - /** - * Read content from file and convert to String. - * - * @param fileName file name path - * @return content of the file as String object - */ - public static String readFileAsString(String fileName) { - var classLoader = FileUtil.class.getClassLoader(); + private static final Logger logger = LoggerFactory.getLogger(FileUtil.class); - try { - InputStream inputStream = classLoader.getResourceAsStream(fileName); - if (inputStream != null) { - BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, UTF_8)); + /** + * Read content from file and convert to String. + * + * @param fileName file name path + * @return content of the file as String object + */ + public static String readFileAsString(String fileName) { + var classLoader = FileUtil.class.getClassLoader(); - return reader.lines().collect(Collectors.joining(System.lineSeparator())); - } + try { + InputStream inputStream = classLoader.getResourceAsStream(fileName); + if (inputStream != null) { + BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, UTF_8)); - } catch (Exception e) { - logger.error("Exception to read file {}", e.getMessage()); - } + return reader.lines().collect(Collectors.joining(System.lineSeparator())); + } - return Strings.EMPTY; + } catch (Exception e) { + logger.error("Exception to read file {}", e.getMessage()); } - /** - * Get file absolut path based in project resource folder. - * - * @param fileName file name path - * @return file URI from resource class loader - */ - public static URI getFileUri(String fileName) { - URL resourceUrl = FileUtil.class.getClassLoader().getResource(fileName); + return Strings.EMPTY; + } - if (resourceUrl != null) { - try { - return resourceUrl.toURI(); - } catch (URISyntaxException e) { - throw new PlatformInternalException("File URI syntax invalid", e); - } - } + /** + * Get file absolut path based in project resource folder. + * + * @param fileName file name path + * @return file URI from resource class loader + */ + public static URI getFileUri(String fileName) { + URL resourceUrl = FileUtil.class.getClassLoader().getResource(fileName); - throw new ContentNotFoundException("File " + fileName + " not found."); + if (resourceUrl != null) { + try { + return resourceUrl.toURI(); + } catch (URISyntaxException e) { + throw new PlatformInternalException("File URI syntax invalid", e); + } } -} \ No newline at end of file + + throw new ContentNotFoundException("File " + fileName + " not found."); + } +} diff --git a/src/main/resources/checkstyle/checkstyle.xml b/src/main/resources/checkstyle/checkstyle.xml new file mode 100644 index 00000000..bc97a4d8 --- /dev/null +++ b/src/main/resources/checkstyle/checkstyle.xml @@ -0,0 +1,499 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .*:.*Style + + http://schemas.android.com/apk/res/android + + + BY_NAME + +
+
+ + + + .*:layout_width + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:layout_height + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:layout_weight + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:layout_margin + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:layout_marginTop + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:layout_marginBottom + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:layout_marginStart + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:layout_marginEnd + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:layout_marginLeft + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:layout_marginRight + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:layout_.* + + http://schemas.android.com/apk/res/android + + + BY_NAME + +
+
+ + + + .*:padding + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:paddingTop + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:paddingBottom + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:paddingStart + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:paddingEnd + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:paddingLeft + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:paddingRight + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .* + http://schemas.android.com/apk/res/android + + + BY_NAME + +
+
+ + + + .* + http://schemas.android.com/apk/res-auto + + + BY_NAME + +
+
+ + + + .* + http://schemas.android.com/tools + + + BY_NAME + +
+
+ + + + .* + .* + + + BY_NAME + +
+
+
+ + +
+ + + +
+
\ No newline at end of file diff --git a/src/test/java/com/wcc/platform/PlatformApplicationTests.java b/src/test/java/com/wcc/platform/PlatformApplicationTests.java index 736defaa..066f5daf 100644 --- a/src/test/java/com/wcc/platform/PlatformApplicationTests.java +++ b/src/test/java/com/wcc/platform/PlatformApplicationTests.java @@ -7,5 +7,7 @@ class PlatformApplicationTests { @Test - void contextLoads() {} + void contextLoads() { + // test the application is starting without any problem. + } } diff --git a/src/test/java/com/wcc/platform/controller/AboutControllerTest.java b/src/test/java/com/wcc/platform/controller/AboutControllerTest.java index 78a7973c..f1719351 100644 --- a/src/test/java/com/wcc/platform/controller/AboutControllerTest.java +++ b/src/test/java/com/wcc/platform/controller/AboutControllerTest.java @@ -1,5 +1,15 @@ package com.wcc.platform.controller; +import static com.wcc.platform.domain.cms.ApiResourcesFile.CODE_OF_CONDUCT; +import static com.wcc.platform.factories.TestFactories.createCodeOfConductPageTest; +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.Contact; import com.wcc.platform.domain.cms.attributes.Image; import com.wcc.platform.domain.cms.attributes.ImageType; @@ -13,153 +23,147 @@ import com.wcc.platform.domain.platform.SocialNetworkType; import com.wcc.platform.service.CmsService; import com.wcc.platform.utils.FileUtil; +import java.util.List; 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; -import java.util.List; - -import static com.wcc.platform.domain.cms.ApiResourcesFile.CODE_OF_CONDUCT; -import static com.wcc.platform.factories.TestFactories.createCodeOfConductPageTest; -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.*; - - @WebMvcTest(AboutController.class) class AboutControllerTest { - private static final String API_CODE_OF_CONDUCT = "/api/cms/v1/code-of-conduct"; - - @Autowired - private MockMvc mockMvc; - @MockBean - private CmsService service; - - @Test - void testNotFound() throws Exception { - when(service.getTeam()).thenThrow(new ContentNotFoundException("Not Found Exception")); - - mockMvc.perform(get("/api/cms/v1/team") - .contentType(APPLICATION_JSON)) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.status", is(404))) - .andExpect(jsonPath("$.message", is("Not Found Exception"))) - .andExpect(jsonPath("$.details", is("uri=/api/cms/v1/team"))); - } - - @Test - void testInternalError() throws Exception { - var internalError = new PlatformInternalException("internal error", new RuntimeException()); - when(service.getTeam()).thenThrow(internalError); - - mockMvc.perform(get("/api/cms/v1/team").contentType(APPLICATION_JSON)) - .andExpect(status().isInternalServerError()) - .andExpect(jsonPath("$.status", is(500))) - .andExpect(jsonPath("$.message", is("internal error"))) - .andExpect(jsonPath("$.details", is("uri=/api/cms/v1/team"))); - } - - @Test - void testCollaboratorNotFound() throws Exception { - when(service.getCollaborator()).thenThrow(new ContentNotFoundException("Not Found Exception")); - - mockMvc.perform(get("/api/cms/v1/collaborators") - .contentType(APPLICATION_JSON)) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.status", is(404))) - .andExpect(jsonPath("$.message", is("Not Found Exception"))) - .andExpect(jsonPath("$.details", is("uri=/api/cms/v1/collaborators"))); - } - - @Test - void testCollaboratorInternalError() throws Exception { - var internalError = new PlatformInternalException("internal Json", new RuntimeException()); - when(service.getCollaborator()).thenThrow(internalError); - - mockMvc.perform(get("/api/cms/v1/collaborators") - .contentType(APPLICATION_JSON)) - .andExpect(status().isInternalServerError()) - .andExpect(jsonPath("$.status", is(500))) - .andExpect(jsonPath("$.message", is("internal Json"))) - .andExpect(jsonPath("$.details", is("uri=/api/cms/v1/collaborators"))); - } - - @Test - void testCollaboratorOKResponse() throws Exception { - var collaborator = new Member(); - - collaborator.setFullName("fullName"); - collaborator.setPosition("position"); - collaborator.setMemberType(MemberType.COLLABORATOR); - collaborator.setImages(List.of(new Image("image.png", "alt image", ImageType.DESKTOP))); - collaborator.setNetwork(List.of(new SocialNetwork(SocialNetworkType.LINKEDIN, "collaborator_link"))); - - var collaboratorPage = new CollaboratorPage( - new Page("collaborator_title", "collaborator_subtitle", "collaborator_desc"), - new Contact("contact_title", List.of(new SocialNetwork(SocialNetworkType.LINKEDIN, "page_link"))), - List.of(collaborator)); - - when(service.getCollaborator()).thenReturn(collaboratorPage); - - mockMvc.perform(get("/api/cms/v1/collaborators") - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.page.title", is("collaborator_title"))) - .andExpect(jsonPath("$.page.subtitle", is("collaborator_subtitle"))) - .andExpect(jsonPath("$.page.description", is("collaborator_desc"))) - .andExpect(jsonPath("$.contact.title", is("contact_title"))) - .andExpect(jsonPath("$.contact.links[0].type", is("LINKEDIN"))) - .andExpect(jsonPath("$.contact.links[0].link", is("page_link"))) - .andExpect(jsonPath("$.collaborators[0].fullName", is("fullName"))) - .andExpect(jsonPath("$.collaborators[0].position", is("position"))) - .andExpect(jsonPath("$.collaborators[0].memberType", is("COLLABORATOR"))) - .andExpect(jsonPath("$.collaborators[0].images[0].path", is("image.png"))) - .andExpect(jsonPath("$.collaborators[0].images[0].alt", is("alt image"))) - .andExpect(jsonPath("$.collaborators[0].images[0].type", is("DESKTOP"))) - .andExpect(jsonPath("$.collaborators[0].network[0].type", is("LINKEDIN"))) - .andExpect(jsonPath("$.collaborators[0].network[0].link", is("collaborator_link"))); - } - - @Test - void testCodeOfConductNotFound() throws Exception { - when(service.getCodeOfConduct()).thenThrow(new ContentNotFoundException("Not Found Exception")); - - mockMvc.perform(get(API_CODE_OF_CONDUCT) - .contentType(APPLICATION_JSON)) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.status", is(404))) - .andExpect(jsonPath("$.message", is("Not Found Exception"))) - .andExpect(jsonPath("$.details", is("uri=/api/cms/v1/code-of-conduct"))); - } - - @Test - void testCodeOfConductInternalError() throws Exception { - var internalError = new PlatformInternalException("internal Json", new RuntimeException()); - when(service.getCodeOfConduct()).thenThrow(internalError); - - mockMvc.perform(get(API_CODE_OF_CONDUCT) - .contentType(APPLICATION_JSON)) - .andExpect(status().isInternalServerError()) - .andExpect(jsonPath("$.status", is(500))) - .andExpect(jsonPath("$.message", is("internal Json"))) - .andExpect(jsonPath("$.details", is("uri=/api/cms/v1/code-of-conduct"))); - } - - @Test - void testCodeOfConductOKResponse() throws Exception { - - var fileName = CODE_OF_CONDUCT.getFileName(); - var expectedJson = FileUtil.readFileAsString(fileName); - - when(service.getCodeOfConduct()).thenReturn(createCodeOfConductPageTest(fileName)); - - mockMvc.perform(get(API_CODE_OF_CONDUCT).contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().json(expectedJson)); - } -} \ No newline at end of file + private static final String API_CODE_OF_CONDUCT = "/api/cms/v1/code-of-conduct"; + + @Autowired private MockMvc mockMvc; + @MockBean private CmsService service; + + @Test + void testNotFound() throws Exception { + when(service.getTeam()).thenThrow(new ContentNotFoundException("Not Found Exception")); + + mockMvc + .perform(get("/api/cms/v1/team").contentType(APPLICATION_JSON)) + .andExpect(status().isNotFound()) + .andExpect(jsonPath("$.status", is(404))) + .andExpect(jsonPath("$.message", is("Not Found Exception"))) + .andExpect(jsonPath("$.details", is("uri=/api/cms/v1/team"))); + } + + @Test + void testInternalError() throws Exception { + var internalError = new PlatformInternalException("internal error", new RuntimeException()); + when(service.getTeam()).thenThrow(internalError); + + mockMvc + .perform(get("/api/cms/v1/team").contentType(APPLICATION_JSON)) + .andExpect(status().isInternalServerError()) + .andExpect(jsonPath("$.status", is(500))) + .andExpect(jsonPath("$.message", is("internal error"))) + .andExpect(jsonPath("$.details", is("uri=/api/cms/v1/team"))); + } + + @Test + void testCollaboratorNotFound() throws Exception { + when(service.getCollaborator()).thenThrow(new ContentNotFoundException("Not Found Exception")); + + mockMvc + .perform(get("/api/cms/v1/collaborators").contentType(APPLICATION_JSON)) + .andExpect(status().isNotFound()) + .andExpect(jsonPath("$.status", is(404))) + .andExpect(jsonPath("$.message", is("Not Found Exception"))) + .andExpect(jsonPath("$.details", is("uri=/api/cms/v1/collaborators"))); + } + + @Test + void testCollaboratorInternalError() throws Exception { + var internalError = new PlatformInternalException("internal Json", new RuntimeException()); + when(service.getCollaborator()).thenThrow(internalError); + + mockMvc + .perform(get("/api/cms/v1/collaborators").contentType(APPLICATION_JSON)) + .andExpect(status().isInternalServerError()) + .andExpect(jsonPath("$.status", is(500))) + .andExpect(jsonPath("$.message", is("internal Json"))) + .andExpect(jsonPath("$.details", is("uri=/api/cms/v1/collaborators"))); + } + + @Test + void testCollaboratorOkResponse() throws Exception { + var collaborator = new Member(); + + collaborator.setFullName("fullName"); + collaborator.setPosition("position"); + collaborator.setMemberType(MemberType.COLLABORATOR); + collaborator.setImages(List.of(new Image("image.png", "alt image", ImageType.DESKTOP))); + collaborator.setNetwork( + List.of(new SocialNetwork(SocialNetworkType.LINKEDIN, "collaborator_link"))); + + var collaboratorPage = + new CollaboratorPage( + new Page("collaborator_title", "collaborator_subtitle", "collaborator_desc"), + new Contact( + "contact_title", + List.of(new SocialNetwork(SocialNetworkType.LINKEDIN, "page_link"))), + List.of(collaborator)); + + when(service.getCollaborator()).thenReturn(collaboratorPage); + + mockMvc + .perform(get("/api/cms/v1/collaborators").contentType(APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.page.title", is("collaborator_title"))) + .andExpect(jsonPath("$.page.subtitle", is("collaborator_subtitle"))) + .andExpect(jsonPath("$.page.description", is("collaborator_desc"))) + .andExpect(jsonPath("$.contact.title", is("contact_title"))) + .andExpect(jsonPath("$.contact.links[0].type", is("LINKEDIN"))) + .andExpect(jsonPath("$.contact.links[0].link", is("page_link"))) + .andExpect(jsonPath("$.collaborators[0].fullName", is("fullName"))) + .andExpect(jsonPath("$.collaborators[0].position", is("position"))) + .andExpect(jsonPath("$.collaborators[0].memberType", is("COLLABORATOR"))) + .andExpect(jsonPath("$.collaborators[0].images[0].path", is("image.png"))) + .andExpect(jsonPath("$.collaborators[0].images[0].alt", is("alt image"))) + .andExpect(jsonPath("$.collaborators[0].images[0].type", is("DESKTOP"))) + .andExpect(jsonPath("$.collaborators[0].network[0].type", is("LINKEDIN"))) + .andExpect(jsonPath("$.collaborators[0].network[0].link", is("collaborator_link"))); + } + + @Test + void testCodeOfConductNotFound() throws Exception { + when(service.getCodeOfConduct()).thenThrow(new ContentNotFoundException("Not Found Exception")); + + mockMvc + .perform(get(API_CODE_OF_CONDUCT).contentType(APPLICATION_JSON)) + .andExpect(status().isNotFound()) + .andExpect(jsonPath("$.status", is(404))) + .andExpect(jsonPath("$.message", is("Not Found Exception"))) + .andExpect(jsonPath("$.details", is("uri=/api/cms/v1/code-of-conduct"))); + } + + @Test + void testCodeOfConductInternalError() throws Exception { + var internalError = new PlatformInternalException("internal Json", new RuntimeException()); + when(service.getCodeOfConduct()).thenThrow(internalError); + + mockMvc + .perform(get(API_CODE_OF_CONDUCT).contentType(APPLICATION_JSON)) + .andExpect(status().isInternalServerError()) + .andExpect(jsonPath("$.status", is(500))) + .andExpect(jsonPath("$.message", is("internal Json"))) + .andExpect(jsonPath("$.details", is("uri=/api/cms/v1/code-of-conduct"))); + } + + @Test + void testCodeOfConductOkResponse() throws Exception { + + var fileName = CODE_OF_CONDUCT.getFileName(); + var expectedJson = FileUtil.readFileAsString(fileName); + + when(service.getCodeOfConduct()).thenReturn(createCodeOfConductPageTest(fileName)); + + mockMvc + .perform(get(API_CODE_OF_CONDUCT).contentType(APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().json(expectedJson)); + } +} diff --git a/src/test/java/com/wcc/platform/controller/FooterControllerTest.java b/src/test/java/com/wcc/platform/controller/FooterControllerTest.java index 172a88c5..ac06e69e 100644 --- a/src/test/java/com/wcc/platform/controller/FooterControllerTest.java +++ b/src/test/java/com/wcc/platform/controller/FooterControllerTest.java @@ -1,62 +1,65 @@ package com.wcc.platform.controller; +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.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + import com.wcc.platform.domain.cms.attributes.LabelLink; import com.wcc.platform.domain.cms.attributes.Network; import com.wcc.platform.domain.cms.pages.FooterPage; import com.wcc.platform.domain.exceptions.PlatformInternalException; import com.wcc.platform.service.CmsService; +import java.util.List; 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; -import java.util.List; - -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.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - +/** Unit test for footer api. */ @WebMvcTest(FooterController.class) public class FooterControllerTest { + @Autowired private MockMvc mockMvc; - @Autowired - private MockMvc mockMvc; - - @MockBean - private CmsService mockCmsService; + @MockBean private CmsService mockCmsService; - @Test - void testInternalServerError() throws Exception { - when(mockCmsService.getFooter()).thenThrow(new PlatformInternalException("Invalid Json", new RuntimeException())); + @Test + void testInternalServerError() throws Exception { + when(mockCmsService.getFooter()) + .thenThrow(new PlatformInternalException("Invalid Json", new RuntimeException())); - mockMvc.perform(get("/api/cms/v1/footer") - .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/footer"))); - } + mockMvc + .perform(get("/api/cms/v1/footer").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/footer"))); + } - @Test - void testOKResponse() throws Exception { - when(mockCmsService.getFooter()).thenReturn(new FooterPage("footer_title","footer_subtitle", - "footer_desc", List.of(new Network("net_type","net_link" )), + @Test + void testOKResponse() throws Exception { + when(mockCmsService.getFooter()) + .thenReturn( + new FooterPage( + "footer_title", + "footer_subtitle", + "footer_desc", + List.of(new Network("net_type", "net_link")), new LabelLink("label_title", "label", "label_uri"))); - mockMvc.perform(get("/api/cms/v1/footer") - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.title", is("footer_title"))) - .andExpect(jsonPath("$.subtitle", is("footer_subtitle"))) - .andExpect(jsonPath("$.description", is("footer_desc"))) - .andExpect(jsonPath("$.network[0].type", is("net_type"))) - .andExpect(jsonPath("$.network[0].link", is("net_link"))) - .andExpect(jsonPath("$.link.title", is("label_title"))) - .andExpect(jsonPath("$.link.label", is("label"))) - .andExpect(jsonPath("$.link.uri", is("label_uri"))); - } + mockMvc + .perform(get("/api/cms/v1/footer").contentType(APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.title", is("footer_title"))) + .andExpect(jsonPath("$.subtitle", is("footer_subtitle"))) + .andExpect(jsonPath("$.description", is("footer_desc"))) + .andExpect(jsonPath("$.network[0].type", is("net_type"))) + .andExpect(jsonPath("$.network[0].link", is("net_link"))) + .andExpect(jsonPath("$.link.title", is("label_title"))) + .andExpect(jsonPath("$.link.label", is("label"))) + .andExpect(jsonPath("$.link.uri", is("label_uri"))); + } } diff --git a/src/test/java/com/wcc/platform/controller/MentorshipControllerTest.java b/src/test/java/com/wcc/platform/controller/MentorshipControllerTest.java index 141d5677..ae1714ce 100644 --- a/src/test/java/com/wcc/platform/controller/MentorshipControllerTest.java +++ b/src/test/java/com/wcc/platform/controller/MentorshipControllerTest.java @@ -1,5 +1,15 @@ package com.wcc.platform.controller; +import static com.wcc.platform.domain.cms.ApiResourcesFile.MENTORSHIP; +import static com.wcc.platform.factories.TestMentorshipFactories.createMentorshipPageTest; +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.exceptions.PlatformInternalException; import com.wcc.platform.service.MentorshipService; import com.wcc.platform.utils.FileUtil; @@ -9,44 +19,38 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.web.servlet.MockMvc; -import static com.wcc.platform.domain.cms.ApiResourcesFile.MENTORSHIP; -import static com.wcc.platform.factories.TestMentorshipFactories.createMentorshipPageTest; -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.*; - +/** Unit test for mentorship apis. */ @WebMvcTest(MentorshipController.class) public class MentorshipControllerTest { - public static final String API_MENTORSHIP_OVERVIEW = "/api/cms/v1/mentorship/overview"; - @Autowired - private MockMvc mockMvc; + public static final String API_MENTORSHIP_OVERVIEW = "/api/cms/v1/mentorship/overview"; + @Autowired private MockMvc mockMvc; - @MockBean - private MentorshipService service; + @MockBean private MentorshipService service; - @Test - void testInternalServerError() throws Exception { - when(service.getOverview()).thenThrow(new PlatformInternalException("Invalid Json", new RuntimeException())); + @Test + void testInternalServerError() throws Exception { + when(service.getOverview()) + .thenThrow(new PlatformInternalException("Invalid Json", new RuntimeException())); - mockMvc.perform(get(API_MENTORSHIP_OVERVIEW).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/mentorship/overview"))); - } + mockMvc + .perform(get(API_MENTORSHIP_OVERVIEW).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/mentorship/overview"))); + } - @Test - void testOKResponse() throws Exception { - var fileName = MENTORSHIP.getFileName(); - var expectedJson = FileUtil.readFileAsString(fileName); + @Test + void testOkResponse() throws Exception { + var fileName = MENTORSHIP.getFileName(); + var expectedJson = FileUtil.readFileAsString(fileName); - when(service.getOverview()).thenReturn(createMentorshipPageTest(fileName)); + when(service.getOverview()).thenReturn(createMentorshipPageTest(fileName)); - mockMvc.perform(get(API_MENTORSHIP_OVERVIEW).contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().json(expectedJson)); - } + mockMvc + .perform(get(API_MENTORSHIP_OVERVIEW).contentType(APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().json(expectedJson)); + } } diff --git a/src/test/java/com/wcc/platform/deserializers/MemberTypeDeserializerTest.java b/src/test/java/com/wcc/platform/deserializers/MemberTypeDeserializerTest.java index 0af51af9..99ee37a9 100644 --- a/src/test/java/com/wcc/platform/deserializers/MemberTypeDeserializerTest.java +++ b/src/test/java/com/wcc/platform/deserializers/MemberTypeDeserializerTest.java @@ -1,8 +1,12 @@ package com.wcc.platform.deserializers; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.when; + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; import com.wcc.platform.domain.platform.MemberType; +import java.io.IOException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; @@ -10,42 +14,34 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import java.io.IOException; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.when; - class MemberTypeDeserializerTest { - @Mock - private JsonParser jsonParser; + @Mock private JsonParser jsonParser; - @Mock - private DeserializationContext context; + @Mock private DeserializationContext context; - @InjectMocks - private MemberTypeDeserializer deserializer; + @InjectMocks private MemberTypeDeserializer deserializer; - @BeforeEach - public void setUp() { - MockitoAnnotations.openMocks(this); - } + @BeforeEach + public void setUp() { + MockitoAnnotations.openMocks(this); + } - @ParameterizedTest - @EnumSource(MemberType.class) - void testDeserialize(MemberType type) throws IOException { - when(jsonParser.getText()).thenReturn(type.name()); + @ParameterizedTest + @EnumSource(MemberType.class) + void testDeserialize(MemberType type) throws IOException { + when(jsonParser.getText()).thenReturn(type.name()); - var response = deserializer.deserialize(jsonParser, context); + var response = deserializer.deserialize(jsonParser, context); - assertEquals(type, response); - } + assertEquals(type, response); + } - void testDeserializeInvalid() throws IOException { - when(jsonParser.getText()).thenReturn("UNDEFINED"); + void testDeserializeInvalid() throws IOException { + when(jsonParser.getText()).thenReturn("UNDEFINED"); - var response = deserializer.deserialize(jsonParser, context); + var response = deserializer.deserialize(jsonParser, context); - assertEquals(MemberType.MEMBER, response); - } -} \ No newline at end of file + assertEquals(MemberType.MEMBER, response); + } +} diff --git a/src/test/java/com/wcc/platform/deserializers/SocialNetworkTypeDeserializerTest.java b/src/test/java/com/wcc/platform/deserializers/SocialNetworkTypeDeserializerTest.java index cd843426..2e5cba2c 100644 --- a/src/test/java/com/wcc/platform/deserializers/SocialNetworkTypeDeserializerTest.java +++ b/src/test/java/com/wcc/platform/deserializers/SocialNetworkTypeDeserializerTest.java @@ -1,9 +1,12 @@ package com.wcc.platform.deserializers; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.when; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; import com.wcc.platform.domain.platform.SocialNetworkType; +import java.io.IOException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -12,43 +15,35 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import java.io.IOException; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.when; - class SocialNetworkTypeDeserializerTest { - @Mock - private JsonParser jsonParser; + @Mock private JsonParser jsonParser; - @Mock - private DeserializationContext context; + @Mock private DeserializationContext context; - @InjectMocks - private SocialNetworkTypeDeserializer deserializer; + @InjectMocks private SocialNetworkTypeDeserializer deserializer; - @BeforeEach - public void setUp() { - MockitoAnnotations.openMocks(this); - } + @BeforeEach + public void setUp() { + MockitoAnnotations.openMocks(this); + } - @ParameterizedTest - @EnumSource(SocialNetworkType.class) - void testDeserialize(SocialNetworkType type) throws IOException { - when(jsonParser.getText()).thenReturn(type.name()); + @ParameterizedTest + @EnumSource(SocialNetworkType.class) + void testDeserialize(SocialNetworkType type) throws IOException { + when(jsonParser.getText()).thenReturn(type.name()); - var response = deserializer.deserialize(jsonParser, context); + var response = deserializer.deserialize(jsonParser, context); - assertEquals(type, response); - } + assertEquals(type, response); + } - @Test - void testDeserializeInvalid() throws IOException { - when(jsonParser.getText()).thenReturn("UNDEFINED"); + @Test + void testDeserializeInvalid() throws IOException { + when(jsonParser.getText()).thenReturn("UNDEFINED"); - var response = deserializer.deserialize(jsonParser, context); + var response = deserializer.deserialize(jsonParser, context); - assertEquals(SocialNetworkType.UNKNOWN, response); - } -} \ No newline at end of file + assertEquals(SocialNetworkType.UNKNOWN, response); + } +} diff --git a/src/test/java/com/wcc/platform/factories/ObjectMapperTestFactory.java b/src/test/java/com/wcc/platform/factories/ObjectMapperTestFactory.java index 81cd5329..717187c7 100644 --- a/src/test/java/com/wcc/platform/factories/ObjectMapperTestFactory.java +++ b/src/test/java/com/wcc/platform/factories/ObjectMapperTestFactory.java @@ -3,18 +3,19 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.wcc.platform.configuration.ObjectMapperConfig; +/** Object mapper factory test. */ public class ObjectMapperTestFactory { - private static ObjectMapper objectMapper; + private static ObjectMapper objectMapper; - private ObjectMapperTestFactory() { - } - - public static ObjectMapper getInstance() { - if (objectMapper == null) { - objectMapper = new ObjectMapperConfig().objectMapper(); - } + private ObjectMapperTestFactory() {} - return objectMapper; + /** initialize the test mapper with the same config used by spring. */ + public static ObjectMapper getInstance() { + if (objectMapper == null) { + objectMapper = new ObjectMapperConfig().objectMapper(); } + + return objectMapper; + } } diff --git a/src/test/java/com/wcc/platform/factories/TestMentorshipFactories.java b/src/test/java/com/wcc/platform/factories/TestMentorshipFactories.java index 5eb50883..62194cd2 100644 --- a/src/test/java/com/wcc/platform/factories/TestMentorshipFactories.java +++ b/src/test/java/com/wcc/platform/factories/TestMentorshipFactories.java @@ -1,39 +1,44 @@ package com.wcc.platform.factories; +import static com.wcc.platform.factories.TestFactories.createPageSectionTest; +import static com.wcc.platform.factories.TestFactories.createPageTest; + import com.fasterxml.jackson.core.JsonProcessingException; import com.wcc.platform.domain.cms.pages.mentorship.FeedbackItem; import com.wcc.platform.domain.cms.pages.mentorship.FeedbackSection; import com.wcc.platform.domain.cms.pages.mentorship.MentorshipPage; import com.wcc.platform.utils.FileUtil; - import java.time.Year; import java.util.List; -import static com.wcc.platform.factories.TestFactories.createPageSectionTest; -import static com.wcc.platform.factories.TestFactories.createPageTest; - +/** Mentorship test factories. */ public class TestMentorshipFactories { - public static MentorshipPage createMentorshipPageTest(String fileName) { - try { - String content = FileUtil.readFileAsString(fileName); - return ObjectMapperTestFactory.getInstance().readValue(content, MentorshipPage.class); - } catch (JsonProcessingException e) { - return createMentorshipPageTest(); - } - } - - public static MentorshipPage createMentorshipPageTest() { - return new MentorshipPage(createPageTest(), createPageSectionTest("Mentor"), - createPageSectionTest("Mentee"), createFeedbackSectionTest()); - } - - public static FeedbackItem createFeedbackItemTest(boolean isMentor) { - return new FeedbackItem("Person Name", "Nice feedback", isMentor, Year.of(2023)); - } - - public static FeedbackSection createFeedbackSectionTest() { - return new FeedbackSection("Feedback1", - List.of(createFeedbackItemTest(true), createFeedbackItemTest(false))); + /** Test factory. */ + public static MentorshipPage createMentorshipPageTest(String fileName) { + try { + String content = FileUtil.readFileAsString(fileName); + return ObjectMapperTestFactory.getInstance().readValue(content, MentorshipPage.class); + } catch (JsonProcessingException e) { + return createMentorshipPageTest(); } + } + + /** Test factory. */ + public static MentorshipPage createMentorshipPageTest() { + return new MentorshipPage( + createPageTest(), + createPageSectionTest("Mentor"), + createPageSectionTest("Mentee"), + createFeedbackSectionTest()); + } + + public static FeedbackItem createFeedbackItemTest(boolean isMentor) { + return new FeedbackItem("Person Name", "Nice feedback", isMentor, Year.of(2023)); + } + + public static FeedbackSection createFeedbackSectionTest() { + return new FeedbackSection( + "Feedback1", List.of(createFeedbackItemTest(true), createFeedbackItemTest(false))); + } } diff --git a/src/test/java/com/wcc/platform/service/CmsServiceIntegrationTest.java b/src/test/java/com/wcc/platform/service/CmsServiceIntegrationTest.java index b0e07409..137ea947 100644 --- a/src/test/java/com/wcc/platform/service/CmsServiceIntegrationTest.java +++ b/src/test/java/com/wcc/platform/service/CmsServiceIntegrationTest.java @@ -1,71 +1,70 @@ package com.wcc.platform.service; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - import static com.wcc.platform.domain.cms.ApiResourcesFile.*; import static com.wcc.platform.factories.TestFactories.*; import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + @SpringBootTest class CmsServiceIntegrationTest { - @Autowired - private CmsService service; + @Autowired private CmsService service; - @Test - void getTeamPageTest() { - var result = service.getTeam(); + @Test + void getTeamPageTest() { + var result = service.getTeam(); - var expectedTeamPage = createTeamPageTest(TEAM.getFileName()); + var expectedTeamPage = createTeamPageTest(TEAM.getFileName()); - assertEquals(expectedTeamPage.page(), result.page()); - assertEquals(expectedTeamPage.contact(), result.contact()); + assertEquals(expectedTeamPage.page(), result.page()); + assertEquals(expectedTeamPage.contact(), result.contact()); - assertEquals(1, result.membersByType().directors().size()); - assertEquals(1, result.membersByType().leads().size()); - assertEquals(1, result.membersByType().evangelists().size()); + assertEquals(1, result.membersByType().directors().size()); + assertEquals(1, result.membersByType().leads().size()); + assertEquals(1, result.membersByType().evangelists().size()); - assertNull(result.membersByType().directors().get(0).getMemberType()); - assertNull(result.membersByType().leads().get(0).getMemberType()); - assertNull(result.membersByType().evangelists().get(0).getMemberType()); - } + assertNull(result.membersByType().directors().get(0).getMemberType()); + assertNull(result.membersByType().leads().get(0).getMemberType()); + assertNull(result.membersByType().evangelists().get(0).getMemberType()); + } - @Test - void getFooterPageTest() { - var result = service.getFooter(); + @Test + void getFooterPageTest() { + var result = service.getFooter(); - var expectedTeamPage = createFooterPageTest(FOOTER.getFileName()); + var expectedTeamPage = createFooterPageTest(FOOTER.getFileName()); - assertEquals(expectedTeamPage.title(), result.title()); - assertEquals(expectedTeamPage.subtitle(), result.subtitle()); - assertEquals(expectedTeamPage.description(), result.description()); + assertEquals(expectedTeamPage.title(), result.title()); + assertEquals(expectedTeamPage.subtitle(), result.subtitle()); + assertEquals(expectedTeamPage.description(), result.description()); - assertEquals(6, result.network().size()); - assertEquals(expectedTeamPage.link(), result.link()); - } + assertEquals(6, result.network().size()); + assertEquals(expectedTeamPage.link(), result.link()); + } - @Test - void getCollaboratorPageTest() { - var result = service.getCollaborator(); + @Test + void getCollaboratorPageTest() { + var result = service.getCollaborator(); - var expectedCollaboratorPage = createCollaboratorPageTest(COLLABORATOR.getFileName()); + var expectedCollaboratorPage = createCollaboratorPageTest(COLLABORATOR.getFileName()); - assertEquals(expectedCollaboratorPage.page(), result.page()); - assertEquals(expectedCollaboratorPage.contact(), result.contact()); + assertEquals(expectedCollaboratorPage.page(), result.page()); + assertEquals(expectedCollaboratorPage.contact(), result.contact()); - assertEquals(1, result.collaborators().size()); + assertEquals(1, result.collaborators().size()); - assertNotNull(result.collaborators().get(0).getMemberType()); - } + assertNotNull(result.collaborators().get(0).getMemberType()); + } - @Test - void getCodeOfConductPageTest() { - var result = service.getCodeOfConduct(); + @Test + void getCodeOfConductPageTest() { + var result = service.getCodeOfConduct(); - var expectedCodeOfConductPage = createCodeOfConductPageTest(CODE_OF_CONDUCT.getFileName()); + var expectedCodeOfConductPage = createCodeOfConductPageTest(CODE_OF_CONDUCT.getFileName()); - assertEquals(expectedCodeOfConductPage, result); - } -} \ No newline at end of file + assertEquals(expectedCodeOfConductPage, result); + } +} diff --git a/src/test/java/com/wcc/platform/service/CmsServiceTest.java b/src/test/java/com/wcc/platform/service/CmsServiceTest.java index 34473f77..72dc7a17 100644 --- a/src/test/java/com/wcc/platform/service/CmsServiceTest.java +++ b/src/test/java/com/wcc/platform/service/CmsServiceTest.java @@ -1,111 +1,113 @@ package com.wcc.platform.service; +import static com.wcc.platform.factories.TestFactories.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + import com.fasterxml.jackson.databind.ObjectMapper; +import com.wcc.platform.domain.cms.pages.CodeOfConductPage; import com.wcc.platform.domain.cms.pages.CollaboratorPage; import com.wcc.platform.domain.cms.pages.FooterPage; import com.wcc.platform.domain.cms.pages.TeamPage; -import com.wcc.platform.domain.cms.pages.CodeOfConductPage; -import com.wcc.platform.domain.cms.pages.CollaboratorPage; import com.wcc.platform.domain.exceptions.PlatformInternalException; +import java.io.File; +import java.io.IOException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import java.io.File; -import java.io.IOException; - -import static com.wcc.platform.factories.TestFactories.*; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.when; - class CmsServiceTest { - private ObjectMapper objectMapper; - private CmsService service; + private ObjectMapper objectMapper; + private CmsService service; - @BeforeEach - void setUp() { - objectMapper = Mockito.mock(ObjectMapper.class); - service = new CmsService(objectMapper); - } + @BeforeEach + void setUp() { + objectMapper = Mockito.mock(ObjectMapper.class); + service = new CmsService(objectMapper); + } - @Test - void whenGetTeamGivenInvalidJsonThenThrowsInternalException() throws IOException { - when(objectMapper.readValue(any(File.class), eq(TeamPage.class))).thenThrow(new IOException("Invalid JSON")); + @Test + void whenGetTeamGivenInvalidJsonThenThrowsInternalException() throws IOException { + when(objectMapper.readValue(any(File.class), eq(TeamPage.class))) + .thenThrow(new IOException("Invalid JSON")); - var exception = assertThrows(PlatformInternalException.class, () -> service.getTeam()); + var exception = assertThrows(PlatformInternalException.class, () -> service.getTeam()); - assertEquals("Invalid JSON", exception.getMessage()); - } + assertEquals("Invalid JSON", exception.getMessage()); + } - @Test - void whenGetTeamGivenValidResourceThenReturnValidObjectResponse() throws IOException { - var teamPage = createTeamPageTest(); - when(objectMapper.readValue(any(File.class), eq(TeamPage.class))).thenReturn(teamPage); + @Test + void whenGetTeamGivenValidResourceThenReturnValidObjectResponse() throws IOException { + var teamPage = createTeamPageTest(); + when(objectMapper.readValue(any(File.class), eq(TeamPage.class))).thenReturn(teamPage); - var response = service.getTeam(); + var response = service.getTeam(); - assertEquals(teamPage, response); - } + assertEquals(teamPage, response); + } - @Test - void whenGetFooterGivenInvalidJson() throws IOException { - when(objectMapper.readValue(any(File.class), eq(FooterPage.class))).thenThrow(new IOException("Invalid JSON")); - var exception = assertThrows(PlatformInternalException.class, () -> service.getFooter()); + @Test + void whenGetFooterGivenInvalidJson() throws IOException { + when(objectMapper.readValue(any(File.class), eq(FooterPage.class))) + .thenThrow(new IOException("Invalid JSON")); + var exception = assertThrows(PlatformInternalException.class, () -> service.getFooter()); - assertEquals("Invalid JSON", exception.getMessage()); - } + assertEquals("Invalid JSON", exception.getMessage()); + } - @Test - void whenGetFooterGivenValidJson() throws IOException { - var footer = createFooterPageTest(); - when(objectMapper.readValue(any(File.class), eq(FooterPage.class))).thenReturn(footer); + @Test + void whenGetFooterGivenValidJson() throws IOException { + var footer = createFooterPageTest(); + when(objectMapper.readValue(any(File.class), eq(FooterPage.class))).thenReturn(footer); - var response = service.getFooter(); + var response = service.getFooter(); - assertEquals(footer, response); - } + assertEquals(footer, response); + } - @Test - void whenGetCollaboratorGivenInvalidJsonThenThrowsInternalException() throws IOException { - when(objectMapper.readValue(any(File.class), eq(CollaboratorPage.class))) - .thenThrow(new IOException("Invalid JSON")); + @Test + void whenGetCollaboratorGivenInvalidJsonThenThrowsInternalException() throws IOException { + when(objectMapper.readValue(any(File.class), eq(CollaboratorPage.class))) + .thenThrow(new IOException("Invalid JSON")); - var exception = assertThrows(PlatformInternalException.class, () -> service.getCollaborator()); + var exception = assertThrows(PlatformInternalException.class, () -> service.getCollaborator()); - assertEquals("Invalid JSON", exception.getMessage()); - } + assertEquals("Invalid JSON", exception.getMessage()); + } - @Test - void whenGetCollaboratorGivenValidResourceThenReturnValidObjectResponse() throws IOException { - var collaboratorPage = createCollaboratorPageTest(); - when(objectMapper.readValue(any(File.class), eq(CollaboratorPage.class))).thenReturn(collaboratorPage); + @Test + void whenGetCollaboratorGivenValidResourceThenReturnValidObjectResponse() throws IOException { + var collaboratorPage = createCollaboratorPageTest(); + when(objectMapper.readValue(any(File.class), eq(CollaboratorPage.class))) + .thenReturn(collaboratorPage); - var response = service.getCollaborator(); + var response = service.getCollaborator(); - assertEquals(collaboratorPage, response); - } + assertEquals(collaboratorPage, response); + } - @Test - void whenGetCodeOfConductGivenInvalidJson() throws IOException { - when(objectMapper.readValue(any(File.class), Mockito.eq(CodeOfConductPage.class))).thenThrow(new IOException("Invalid JSON")); + @Test + void whenGetCodeOfConductGivenInvalidJson() throws IOException { + when(objectMapper.readValue(any(File.class), Mockito.eq(CodeOfConductPage.class))) + .thenThrow(new IOException("Invalid JSON")); - var exception = assertThrows(PlatformInternalException.class, () -> service.getCodeOfConduct()); + var exception = assertThrows(PlatformInternalException.class, () -> service.getCodeOfConduct()); - assertEquals("Invalid JSON", exception.getMessage()); - } + assertEquals("Invalid JSON", exception.getMessage()); + } - @Test - void whenGetCodeOfConductGivenValidJson() throws IOException { - var codeOfConductPage = createCodeOfConductPageTest(); - when(objectMapper.readValue(any(File.class), Mockito.eq(CodeOfConductPage.class))).thenReturn(codeOfConductPage); + @Test + void whenGetCodeOfConductGivenValidJson() throws IOException { + var codeOfConductPage = createCodeOfConductPageTest(); + when(objectMapper.readValue(any(File.class), Mockito.eq(CodeOfConductPage.class))) + .thenReturn(codeOfConductPage); - var response = service.getCodeOfConduct(); + var response = service.getCodeOfConduct(); - assertEquals(codeOfConductPage, response); - } -} \ No newline at end of file + assertEquals(codeOfConductPage, response); + } +} diff --git a/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java b/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java index 0a568780..94090f62 100644 --- a/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java +++ b/src/test/java/com/wcc/platform/service/MentorshipServiceTest.java @@ -1,15 +1,5 @@ package com.wcc.platform.service; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.wcc.platform.domain.cms.pages.mentorship.MentorshipPage; -import com.wcc.platform.domain.exceptions.PlatformInternalException; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; - -import java.io.File; -import java.io.IOException; - import static com.wcc.platform.factories.TestMentorshipFactories.createMentorshipPageTest; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -17,33 +7,42 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; -class MentorshipServiceTest { +import com.fasterxml.jackson.databind.ObjectMapper; +import com.wcc.platform.domain.cms.pages.mentorship.MentorshipPage; +import com.wcc.platform.domain.exceptions.PlatformInternalException; +import java.io.File; +import java.io.IOException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; - private ObjectMapper objectMapper; +class MentorshipServiceTest { + private ObjectMapper objectMapper; - private MentorshipService service; + private MentorshipService service; - @BeforeEach - void setUp() { - objectMapper = Mockito.mock(ObjectMapper.class); - service = new MentorshipService(objectMapper); - } + @BeforeEach + void setUp() { + objectMapper = Mockito.mock(ObjectMapper.class); + service = new MentorshipService(objectMapper); + } - @Test - void whenGetOverviewGivenValidJson() throws IOException { - var page = createMentorshipPageTest("mentorshipPage.json"); - when(objectMapper.readValue(any(File.class), eq(MentorshipPage.class))).thenReturn(page); + @Test + void whenGetOverviewGivenValidJson() throws IOException { + var page = createMentorshipPageTest("mentorshipPage.json"); + when(objectMapper.readValue(any(File.class), eq(MentorshipPage.class))).thenReturn(page); - var response = service.getOverview(); + var response = service.getOverview(); - assertEquals(page, response); - } + assertEquals(page, response); + } - @Test - void whenGetOverviewGivenInvalidJson() throws IOException { - when(objectMapper.readValue(any(File.class), eq(MentorshipPage.class))).thenThrow(new IOException("Invalid JSON")); - var exception = assertThrows(PlatformInternalException.class, () -> service.getOverview()); + @Test + void whenGetOverviewGivenInvalidJson() throws IOException { + when(objectMapper.readValue(any(File.class), eq(MentorshipPage.class))) + .thenThrow(new IOException("Invalid JSON")); + var exception = assertThrows(PlatformInternalException.class, () -> service.getOverview()); - assertEquals("Invalid JSON", exception.getMessage()); - } -} \ No newline at end of file + assertEquals("Invalid JSON", exception.getMessage()); + } +}