diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index ea8187a..151204a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,12 +3,14 @@ { "name": "Java", // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "mcr.microsoft.com/devcontainers/java:0-17", + "image": "mcr.microsoft.com/devcontainers/java:21", "features": { "ghcr.io/devcontainers/features/java:1": {}, + "ghcr.io/devcontainers/features/node:1": {}, "ghcr.io/devcontainers-contrib/features/quarkus-sdkman:2": {}, - "ghcr.io/devcontainers/features/docker-in-docker:2": {} + "ghcr.io/devcontainers/features/docker-in-docker:2": {}, + "ghcr.io/devcontainers-contrib/features/maven-sdkman:2": {} }, // Use 'forwardPorts' to make a list of ports inside the container available locally. @@ -21,26 +23,37 @@ "customizations": { "vscode": { "extensions": [ + "Equinusocio.vsc-material-theme-icons", + "ybaumes.highlight-trailing-white-spaces", + "amodio.amethyst-theme", "vscjava.vscode-java-pack", - "cweijan.vscode-mysql-client2", "redhat.vscode-quarkus", - "GitHub.copilot", - "Equinusocio.vsc-material-theme-icons", "redhat.vscode-microprofile-pack", "eamodio.gitlens", - "rangav.vscode-thunder-client" + "rangav.vscode-thunder-client", + "vscjava.vscode-lombok", + "GitHub.copilot", + "GitHub.copilot-chat", + "GitHub.vscode-github-actions", + "GitHub.vscode-pull-request-github", + "cweijan.vscode-mysql-client2", + "cracrayol.java-pmd", + "SonarSource.sonarlint-vscode", + "streetsidesoftware.code-spell-checker-portuguese-brazilian" ], "settings": { - "workbench.colorTheme": "GitHub Light Default", + "workbench.colorTheme": "Default Light Modern", "workbench.iconTheme": "eq-material-theme-icons-light", "editor.rulers": [80,120], "workbench.colorCustomizations": { "editorRuler.foreground": "#F3F7FF" - } + }, + "cSpell.enabled": true, + "cSpell.language": "pt_BR, en, pt" } } } // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. // "remoteUser": "root" -} +} \ No newline at end of file diff --git a/docs/usecases/CreateChannel/createChannel.md b/docs/usecases/CreateChannel/createChannel.md index 7248464..905ea13 100644 --- a/docs/usecases/CreateChannel/createChannel.md +++ b/docs/usecases/CreateChannel/createChannel.md @@ -7,9 +7,11 @@ nav_order: 4 ## Create Channel -* A client sends the name of the channel to the service. -* The service verifies if the name is note empty, persist the - data and returns the a JSON object representing a channel. +* A client sends two objects to the server, the channel with a name and a user + with a name and hash. Besides that, the client also sends an authorization + token (JWT) in the header of the request. +* The service verifies if the token is valid and the fields are not empty, + persist the data and returns the a JSON object representing a channel. ## GraphQL @@ -18,41 +20,47 @@ through a mutation in `/graphql` endpoint. * Example of request: - ```shell - curl -X POST \ - 'http://localhost:8080/graphql' \ - --header 'Accept: */*' \ - --data-raw '{"query":"mutation addChannel {\n createChannel(channel: {\n name: \"My channel\"\n }\n )\n {\n name\n hash\n messages {\n hash\n text\n }\n }\n}","variables":"{}"}' - ``` +```shell + curl -X POST \ + 'http://localhost:8082/graphql' \ + --header 'Accept: */*' \ + --header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJvcmlvbi11c2VycyIsInVwbiI6InJvZHJpZ29AdGVzdGUuY29tIiwiZ3JvdXBzIjpbInVzZXIiXSwiY19oYXNoIjoiMTZhNjc4YjctNWE0NC00MWExLWIzNmEtNGE3NmE2NDU1MjQ0IiwiZW1haWwiOiJyb2RyaWdvQHRlc3RlLmNvbSIsImlhdCI6MTcxNTAwMTgxMiwiZXhwIjoxNzE3NTkzODEyLCJqdGkiOiI1YzZiNDg2YS0zNWE0LTQzYmYtYmVmMS04YTQ5MzI5ZjEyOWEifQ.cRDhwRZ0Yuel5revQy1D1FUhfPYZtxVFLyaTJrAdTY_7djnplIBrm_VwftoXUCngjZd2YoOId3GX7c2GtAYSt24aHNWMhg3OKwIWQCHr6izQ7IAvsVTqJeJzHlQtx6s4mA6kWV76Ea7oCMDydtz397WJpkvALSPR0QM-XTn5AQ6-K0axOrJBCnvnZR_wL4TJgUBg2qOmoHUlhdi5HNbADN1UL-t6sRPYtqtos0dXRdH7LQjKrlzs30pXaJMIy3-Xm_bUgaoN4yryGi55mubyYvtuTIa1Do9ICMRsLLpRk8NjFJ-gjAssriYIs0IvrQXnlCbYXwqY_tqDGey_VcRDEA' \ + --header 'Content-Type: application/json' \ + --data-raw '{"query":" mutation addChannel {\n createChannel(channel: {\n name: \"My teste channel\"\n },\n user:{\n name: \"Rodrigo\"\n hash: \"16a678b7-5a44-41a1-b36a-4a76a6455244\"\n })\n {\n name\n hash\n messages {\n hash\n text\n }\n }\n }\n","variables":"{}"}' +``` * Example of mutation: - ```json - mutation addChannel { - createChannel(channel: { - name: "My channel" - }) - { - name - hash - messages { - hash - text - } - } +```json +mutation addChannel { + createChannel(channel: { + name: "My teste channel" + }, + user:{ + name: "Rodrigo" + hash: "16a678b7-5a44-41a1-b36a-4a76a6455244" + }) + { + name + hash + messages { + hash + text } - ``` + } +} +``` * Example of answer: - ```json - { - "data": { - "createChannel": { - "name": "My channel", - "hash": "6077a738-77ce-404d-8568-ef08374fd0bd", - "messages": [] - } - } +```json +{ + "data": { + "createChannel": { + "name": "My teste channel", + "hash": "16ea8abc-dfc9-4984-9203-25620268e79a", + "messages": [] } - ``` + } +} +``` diff --git a/docs/usecases/CreateMessage/createMessage.md b/docs/usecases/CreateMessage/createMessage.md index a2b38c2..9f8905d 100644 --- a/docs/usecases/CreateMessage/createMessage.md +++ b/docs/usecases/CreateMessage/createMessage.md @@ -5,7 +5,7 @@ parent: Features nav_order: 3 --- -## Create Message +# Create Message * A client sends a text, user hash and the channel hash to the service. Note: if the user hash or channel hash does not exist, the service will create in the @@ -13,10 +13,10 @@ nav_order: 3 * The service verifies if user hash and channel hash are note empty, persist the data and returns the a JSON object representing a message. -## HTTP(S) endpoints +## HTTPS Endpoints * /talk/message/create -* HTTP method: POST +* Method: POST * Consumes: application/x-www-form-urlencoded * Produces: application/json * Examples: diff --git a/pom.xml b/pom.xml index a99cba6..bb8514a 100644 --- a/pom.xml +++ b/pom.xml @@ -1,18 +1,20 @@ - + 4.0.0 dev.orion talk 1.0.0 - 3.11.0 + 3.12.1 17 UTF-8 UTF-8 quarkus-bom io.quarkus.platform - 3.5.0 + 3.10.0 + 3.2.5 @@ -94,6 +96,11 @@ quarkus-junit5 test + + io.quarkus + quarkus-test-security + test + org.seleniumhq.selenium selenium-java @@ -127,28 +134,9 @@ - - maven-checkstyle-plugin - 3.3.0 - - - checkstyle - compile - - check - - - - - true - warning - 10 - config/checkstyle-suppressions.xml - - maven-surefire-plugin - 3.1.2 + ${surefire-plugin.version} test @@ -161,28 +149,119 @@ org.jboss.logmanager.LogManager ${maven.home} + ${maven.multiModuleProjectDirectory}/target/jacoco-quarkus.exec + true + ${maven.multiModuleProjectDirectory}/target/coverage maven-failsafe-plugin - 3.1.2 + ${surefire-plugin.version} - test + verify integration-test + verify - - ${project.build.directory}/${project.build.finalName}-runner - org.jboss.logmanager.LogManager - ${maven.home} - + false + + org.jacoco + jacoco-maven-plugin + 0.8.12 + + + default-prepare-agent + + prepare-agent + + + *QuarkusClassLoader + ${project.build.directory}/jacoco-quarkus.exec + true + + + + test + test + + report + + + ${project.build.directory}/jacoco-quarkus.exec + ${project.build.directory}/jacoco-report + + + + verify + check + + report + + + ${project.build.directory}/jacoco-quarkus.exec + ${project.build.directory}/jacoco-report + + + + + + + PACKAGE + + + LINE + COVEREDRATIO + 0.8 + + + + + + + + maven-checkstyle-plugin + 3.1.1 + + + verify + + check + + + + + true + warning + 10 + static/checkstyle.xml + + + + maven-pmd-plugin + 3.22.0 + + + verify + + check + + + + + true + 10 + + /static/pmd.xml + + + diff --git a/src/main/java/dev/orion/talk/adapters/controllers/Controller.java b/src/main/java/dev/orion/talk/adapters/controllers/Controller.java index 052d525..7dca711 100644 --- a/src/main/java/dev/orion/talk/adapters/controllers/Controller.java +++ b/src/main/java/dev/orion/talk/adapters/controllers/Controller.java @@ -1,6 +1,6 @@ /** * @License - * Copyright 2023 Orion Services @ https://github.com/orion-services + * Copyright 2024 Orion Services @ https://github.com/orion-services * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/main/java/dev/orion/talk/adapters/controllers/ServiceController.java b/src/main/java/dev/orion/talk/adapters/controllers/ServiceController.java index 736fe7c..121f8a8 100644 --- a/src/main/java/dev/orion/talk/adapters/controllers/ServiceController.java +++ b/src/main/java/dev/orion/talk/adapters/controllers/ServiceController.java @@ -1,6 +1,6 @@ /** * @License - * Copyright 2023 Orion Services @ https://github.com/orion-services + * Copyright 2024 Orion Services @ https://github.com/orion-services * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,13 +42,14 @@ public class ServiceController extends Controller { * Creates a channel. * * @param channel A {@link ChannelEntity} with the channel + * @param user A {@link UserEntity} with the user * @return A {@link Uni} of {@link Channel} */ public Uni addChannel( final ChannelEntity channel, final UserEntity user) { - return this.findUser(user.getHash()) + return this.findUser(user.getHash(), user.getName()) .onItem().ifNotNull().transformToUni(u -> { Channel model = channelUC.createChannel( channel.getName(), @@ -73,7 +74,7 @@ public Uni addChannel( public Uni createMessage(final String text, final String userName, final String userHash, final String channelHash) { - return findUser(userHash) + return findUser(userHash, userName) .onItem().transformToUni(user -> { return findChannel(channelHash) .onItem().ifNotNull().transformToUni(channel -> { @@ -116,14 +117,16 @@ public Uni> getMessages(final String channelHash) { * Finds a user by hash. * * @param userHash A {@link String} hash of the user + * @param name The {@link String} name of the user * @return A {@link Uni} of {@link UserEntity} */ - private Uni findUser(final String userHash) { + private Uni findUser(final String userHash, final String name) { return userRepo.find(HASH_QUERY, userHash).firstResult() .onItem().ifNotNull().transform(user -> user) .onItem().ifNull().continueWith(() -> { UserEntity user = new UserEntity(); user.setHash(userHash); + user.setName(name); return user; }); } diff --git a/src/main/java/dev/orion/talk/adapters/persistence/entity/ChannelEntity.java b/src/main/java/dev/orion/talk/adapters/persistence/entity/ChannelEntity.java index 30a5733..3fc42ef 100644 --- a/src/main/java/dev/orion/talk/adapters/persistence/entity/ChannelEntity.java +++ b/src/main/java/dev/orion/talk/adapters/persistence/entity/ChannelEntity.java @@ -1,6 +1,6 @@ /** * @License - * Copyright 2023 Orion Services @ https://github.com/orion-services + * Copyright 2024 Orion Services @ https://github.com/orion-services * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/main/java/dev/orion/talk/adapters/persistence/entity/MessageEntity.java b/src/main/java/dev/orion/talk/adapters/persistence/entity/MessageEntity.java index 45ff68a..0e163fe 100644 --- a/src/main/java/dev/orion/talk/adapters/persistence/entity/MessageEntity.java +++ b/src/main/java/dev/orion/talk/adapters/persistence/entity/MessageEntity.java @@ -1,6 +1,6 @@ /** * @License - * Copyright 2023 Orion Services @ https://github.com/orion-services + * Copyright 2024 Orion Services @ https://github.com/orion-services * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/main/java/dev/orion/talk/adapters/persistence/entity/UserEntity.java b/src/main/java/dev/orion/talk/adapters/persistence/entity/UserEntity.java index 43fb145..e178ca3 100644 --- a/src/main/java/dev/orion/talk/adapters/persistence/entity/UserEntity.java +++ b/src/main/java/dev/orion/talk/adapters/persistence/entity/UserEntity.java @@ -1,6 +1,6 @@ /** * @License - * Copyright 2023 Orion Services @ https://github.com/orion-services + * Copyright 2024 Orion Services @ https://github.com/orion-services * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/main/java/dev/orion/talk/adapters/persistence/repository/ChannelRepository.java b/src/main/java/dev/orion/talk/adapters/persistence/repository/ChannelRepository.java index 80e5493..d763c81 100644 --- a/src/main/java/dev/orion/talk/adapters/persistence/repository/ChannelRepository.java +++ b/src/main/java/dev/orion/talk/adapters/persistence/repository/ChannelRepository.java @@ -1,6 +1,6 @@ /** * @License - * Copyright 2023 Orion Services @ https://github.com/orion-services + * Copyright 2024 Orion Services @ https://github.com/orion-services * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/main/java/dev/orion/talk/adapters/persistence/repository/MessageRepository.java b/src/main/java/dev/orion/talk/adapters/persistence/repository/MessageRepository.java index c186c43..aa3fb51 100644 --- a/src/main/java/dev/orion/talk/adapters/persistence/repository/MessageRepository.java +++ b/src/main/java/dev/orion/talk/adapters/persistence/repository/MessageRepository.java @@ -1,6 +1,6 @@ /** * @License - * Copyright 2023 Orion Services @ https://github.com/orion-services + * Copyright 2024 Orion Services @ https://github.com/orion-services * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/main/java/dev/orion/talk/adapters/persistence/repository/UserRepository.java b/src/main/java/dev/orion/talk/adapters/persistence/repository/UserRepository.java index 113eb8e..982dd5a 100644 --- a/src/main/java/dev/orion/talk/adapters/persistence/repository/UserRepository.java +++ b/src/main/java/dev/orion/talk/adapters/persistence/repository/UserRepository.java @@ -1,6 +1,6 @@ /** * @License - * Copyright 2023 Orion Services @ https://github.com/orion-services + * Copyright 2024 Orion Services @ https://github.com/orion-services * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/main/java/dev/orion/talk/model/Channel.java b/src/main/java/dev/orion/talk/model/Channel.java index f4ff586..e24459a 100644 --- a/src/main/java/dev/orion/talk/model/Channel.java +++ b/src/main/java/dev/orion/talk/model/Channel.java @@ -1,6 +1,6 @@ /** * @License - * Copyright 2023 Orion Services @ https://github.com/orion-services + * Copyright 2024 Orion Services @ https://github.com/orion-services * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -122,7 +122,7 @@ public User getUser() { * * @param user the user to set */ - public void setUser(User user) { + public void setUser(final User user) { this.user = user; } diff --git a/src/main/java/dev/orion/talk/model/Message.java b/src/main/java/dev/orion/talk/model/Message.java index 5e1bc59..8a3a584 100644 --- a/src/main/java/dev/orion/talk/model/Message.java +++ b/src/main/java/dev/orion/talk/model/Message.java @@ -1,6 +1,6 @@ /** * @License - * Copyright 2023 Orion Services @ https://github.com/orion-services + * Copyright 2024 Orion Services @ https://github.com/orion-services * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/main/java/dev/orion/talk/model/User.java b/src/main/java/dev/orion/talk/model/User.java index 3df315b..15b5bd1 100644 --- a/src/main/java/dev/orion/talk/model/User.java +++ b/src/main/java/dev/orion/talk/model/User.java @@ -1,6 +1,6 @@ /** * @License - * Copyright 2023 Orion Services @ https://github.com/orion-services + * Copyright 2024 Orion Services @ https://github.com/orion-services * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,9 @@ public class User { /** Hash of the user. */ private String hash; + /** Name of the user. */ + private String name; + /** * Default constructor. */ @@ -51,4 +54,22 @@ public void setHash(final String hash) { this.hash = hash; } + /** + * Get user name. + * + * @return User name. + */ + public String getName() { + return name; + } + + /** + * Set user name. + * + * @param name User name. + */ + public void setName(final String name) { + this.name = name; + } + } diff --git a/src/main/java/dev/orion/talk/usecase/ChannelUC.java b/src/main/java/dev/orion/talk/usecase/ChannelUC.java index 7c79075..0a05628 100644 --- a/src/main/java/dev/orion/talk/usecase/ChannelUC.java +++ b/src/main/java/dev/orion/talk/usecase/ChannelUC.java @@ -1,6 +1,6 @@ /** * @License - * Copyright 2023 Orion Services @ https://github.com/orion-services + * Copyright 2024 Orion Services @ https://github.com/orion-services * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/main/java/dev/orion/talk/usecase/MessageUC.java b/src/main/java/dev/orion/talk/usecase/MessageUC.java index 8bb0d0a..5be2697 100644 --- a/src/main/java/dev/orion/talk/usecase/MessageUC.java +++ b/src/main/java/dev/orion/talk/usecase/MessageUC.java @@ -1,6 +1,6 @@ /** * @License - * Copyright 2023 Orion Services @ https://github.com/orion-services + * Copyright 2024 Orion Services @ https://github.com/orion-services * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,11 +32,10 @@ public class MessageUC { * @return Message object. */ public Message createMessage(final String text) { - Message message = null; + Message message = new Message(); if (text == null || text.isEmpty()) { throw new IllegalArgumentException("The text can't be empty"); } else { - message = new Message(); message.setText(text); message.setTimestamp(Instant.now()); } diff --git a/src/main/java/dev/orion/talk/web/grapthql/GraphQl.java b/src/main/java/dev/orion/talk/web/grapthql/GraphQl.java index 3b9ba78..b06d51f 100644 --- a/src/main/java/dev/orion/talk/web/grapthql/GraphQl.java +++ b/src/main/java/dev/orion/talk/web/grapthql/GraphQl.java @@ -1,6 +1,6 @@ /** * @License - * Copyright 2023 Orion Services @ https://github.com/orion-services + * Copyright 2024 Orion Services @ https://github.com/orion-services * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,9 +84,9 @@ public Uni createChannel( @Mutation public Uni createMessage( final String text, - final String userName, + final String channelHash, final String userHash, - final String channelHash) { + final String userName) { return controller.createMessage(text, userName, userHash, channelHash) .onItem().ifNotNull().transform(m -> m) diff --git a/src/main/java/dev/orion/talk/web/rest/ServiceException.java b/src/main/java/dev/orion/talk/web/rest/ServiceException.java index cab331d..86db565 100644 --- a/src/main/java/dev/orion/talk/web/rest/ServiceException.java +++ b/src/main/java/dev/orion/talk/web/rest/ServiceException.java @@ -1,6 +1,6 @@ /** * @License - * Copyright 2023 Orion Services @ https://github.com/orion-services + * Copyright 2024 Orion Services @ https://github.com/orion-services * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,11 @@ */ public class ServiceException extends WebApplicationException { + /** + * The serial version UID. + */ + private static final long serialVersionUID = 1L; + /** * ServiceException constructor. * diff --git a/src/main/java/dev/orion/talk/web/rest/TalkWebService.java b/src/main/java/dev/orion/talk/web/rest/TalkWebService.java index 903acb7..0831a57 100644 --- a/src/main/java/dev/orion/talk/web/rest/TalkWebService.java +++ b/src/main/java/dev/orion/talk/web/rest/TalkWebService.java @@ -1,6 +1,6 @@ /** * @License - * Copyright 2023 Orion Services @ https://github.com/orion-services + * Copyright 2024 Orion Services @ https://github.com/orion-services * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b65c421..46cd34e 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,6 +4,7 @@ quarkus.http.port=8082 # HTTPS quarkus.http.ssl-port=8444 quarkus.http.ssl.certificate.key-store-file=keystore.jks +quarkus.http.ssl.certificate.key-store-password=password quarkus.tls.trust-all=true #JWT validation @@ -12,7 +13,7 @@ mp.jwt.verify.publickey.location=publicKey.pem #CORS quarkus.http.cors=true -quarkus.http.cors.origins=http://127.0.0.1:5173,http://localhost:5173 +quarkus.http.cors.origins=http://127.0.0.1:3000,http://localhost:3000 quarkus.http.cors.headers=accept, authorization, content-type, x-requested-with quarkus.http.cors.methods=POST @@ -21,7 +22,6 @@ quarkus.datasource.db-kind=mysql quarkus.datasource.username=orion quarkus.datasource.password=orion %dev.quarkus.datasource.devservices.port=3308 -%prod.quarkus.datasource.jdbc.url=jdbc:mysql://localhost:3308/talk quarkus.hibernate-orm.database.generation=drop-and-create # Swagger diff --git a/src/test/java/dev/orion/talk/graphql/GraphQlIT.java b/src/test/java/dev/orion/talk/graphql/GraphQlIT.java index b178ff7..0231bd7 100644 --- a/src/test/java/dev/orion/talk/graphql/GraphQlIT.java +++ b/src/test/java/dev/orion/talk/graphql/GraphQlIT.java @@ -1,6 +1,6 @@ /** * @License - * Copyright 2023 Orion Services @ https://github.com/orion-services + * Copyright 2024 Orion Services @ https://github.com/orion-services * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,15 +16,7 @@ */ package dev.orion.talk.graphql; -import static io.restassured.RestAssured.given; - -import org.junit.jupiter.api.Order; -import org.junit.jupiter.api.Test; - import io.quarkus.test.junit.QuarkusTest; -import io.restassured.http.ContentType; -import io.vertx.core.cli.annotations.Description; -import jakarta.ws.rs.core.Response; /** * Integration tests for GraphQL queries and mutations. @@ -32,61 +24,4 @@ @QuarkusTest class GraphQlIT { - /** - * Test case for creating a channel through GraphQL. - */ - @Test - @Order(1) - @Description("Create a Channel") - void createChannel() { - String query = """ - mutation addChannel { - createChannel(channel: { - name: \"My channel\", - }) - { - name - hash - } - } - """; - given().when() - .contentType(ContentType.JSON) - .body(query) - .post("/graphql") - .then() - .log().body() - .statusCode(Response.Status.OK.getStatusCode()); - } - - /** - * Test case for querying all messages through GraphQL. - */ - @Test - @Order(2) - @Description("Query all messages through GraphQL") - void queryAllMessages() { - String query = """ - query allMessages { - allMessages { - hash - text - user { - hash - } - channel { - hash - name - } - } - } - """; - given().when() - .contentType(ContentType.JSON) - .body(query) - .post("/graphql") - .then() - .statusCode(Response.Status.OK.getStatusCode()); - } - } diff --git a/src/test/java/dev/orion/talk/rest/RestIT.java b/src/test/java/dev/orion/talk/rest/RestIT.java index 3718b56..587e42e 100644 --- a/src/test/java/dev/orion/talk/rest/RestIT.java +++ b/src/test/java/dev/orion/talk/rest/RestIT.java @@ -1,6 +1,6 @@ /** * @License - * Copyright 2023 Orion Services @ https://github.com/orion-services + * Copyright 2024 Orion Services @ https://github.com/orion-services * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,15 +16,7 @@ */ package dev.orion.talk.rest; -import static io.restassured.RestAssured.given; -import static org.hamcrest.CoreMatchers.is; - -import org.junit.jupiter.api.Order; -import org.junit.jupiter.api.Test; - import io.quarkus.test.junit.QuarkusTest; -import io.vertx.core.cli.annotations.Description; -import jakarta.ws.rs.core.Response; /** * Integration tests for the REST API of the Talk application. diff --git a/src/test/java/dev/orion/talk/system/SeleniumTest.java b/src/test/java/dev/orion/talk/system/SeleniumTest.java deleted file mode 100644 index 958b558..0000000 --- a/src/test/java/dev/orion/talk/system/SeleniumTest.java +++ /dev/null @@ -1,113 +0,0 @@ -// /** -// * @License -// * Copyright 2023 Orion Services @ https://github.com/orion-services -// * -// * Licensed under the Apache License, Version 2.0 (the "License"); -// * you may not use this file except in compliance with the License. -// * You may obtain a copy of the License at -// * -// * http://www.apache.org/licenses/LICENSE-2.0 -// * -// * Unless required by applicable law or agreed to in writing, software -// * distributed under the License is distributed on an "AS IS" BASIS, -// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// * See the License for the specific language governing permissions and -// * limitations under the License. -// */ -// package dev.orion.talk.system; - -// import static org.junit.jupiter.api.Assertions.assertTrue; - -// import java.time.Duration; -// import java.util.HashMap; -// import java.util.Map; - -// import org.junit.jupiter.api.AfterAll; -// import org.junit.jupiter.api.BeforeAll; -// import org.junit.jupiter.api.Order; -// import org.junit.jupiter.api.Test; -// import org.openqa.selenium.By; -// import org.openqa.selenium.Dimension; -// import org.openqa.selenium.JavascriptExecutor; -// import org.openqa.selenium.Keys; -// import org.openqa.selenium.WebDriver; -// import org.openqa.selenium.WebElement; -// import org.openqa.selenium.chrome.ChromeDriver; -// import org.openqa.selenium.chrome.ChromeOptions; -// import org.openqa.selenium.interactions.Actions; - -// public class SeleniumTest { - -// static WebDriver driver; -// static Map vars; -// static JavascriptExecutor js; - -// @BeforeAll -// public static void setUp() { - -// ChromeOptions options = new ChromeOptions(); -// options.addArguments("--headless"); -// options.addArguments("--disable-gpu"); -// driver = new ChromeDriver(options); -// js = (JavascriptExecutor) driver; -// vars = new HashMap(); -// } - -// @AfterAll -// public static void tearDown() { -// driver.quit(); -// } - -// @Test -// @Order(1) -// void createChannel() { - -// // Wait for 2 seconds to load the page -// Duration duration = Duration.ofSeconds(2); - -// driver.get("http://127.0.0.1:5173/"); -// driver.manage().window().setSize(new Dimension(1280, 1055)); -// driver.findElement(By.cssSelector("input")).click(); -// driver.findElement(By.cssSelector("input")).sendKeys("my channel"); -// driver.findElement(By.cssSelector("input")).sendKeys(Keys.ENTER); -// driver.findElement(By.cssSelector("button")).click(); -// driver.findElement(By.cssSelector("input")).click(); - -// driver.manage().timeouts().implicitlyWait(duration); - -// assertTrue(driver.findElement(By.cssSelector("h2")) -// .getText().matches("^[\\s\\S]*Hash[\\s\\S]*$")); -// } - -// @Test -// @Order(2) -// void sendMessage() { -// // Wait for 2 seconds to load the page -// Duration duration = Duration.ofSeconds(3); - -// driver.get("http://127.0.0.1:5173/"); -// driver.manage().window().setSize(new Dimension(1280, 1055)); -// driver.findElement(By.cssSelector("input")).click(); -// driver.findElement(By.cssSelector("input")).sendKeys("my channel"); -// driver.findElement(By.cssSelector("button")).click(); - -// driver.manage().timeouts().implicitlyWait(duration); - -// { -// WebElement element = driver.findElement(By.cssSelector("button")); -// Actions builder = new Actions(driver); -// builder.moveToElement(element).perform(); -// } - -// driver.manage().timeouts().implicitlyWait(duration); - -// driver.findElement(By.cssSelector("input")).click(); -// driver.findElement(By.cssSelector("input")).sendKeys("hello"); -// driver.findElement(By.cssSelector("button")).click(); -// assertTrue(driver.findElement( -// By.cssSelector("div:nth-child(7)")) -// .getText() -// .matches("^[\\s\\S]*hello[\\s\\S]*$")); - -// } -// } diff --git a/src/test/java/dev/orion/talk/unit/MessageTest.java b/src/test/java/dev/orion/talk/unit/MessageTest.java index 8c5edf5..d31e85a 100644 --- a/src/test/java/dev/orion/talk/unit/MessageTest.java +++ b/src/test/java/dev/orion/talk/unit/MessageTest.java @@ -1,6 +1,6 @@ /** * @License - * Copyright 2023 Orion Services @ https://github.com/orion-services + * Copyright 2024 Orion Services @ https://github.com/orion-services * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/test/java/dev/orion/talk/unit/TalkUnitTest.java b/src/test/java/dev/orion/talk/unit/TalkUnitTest.java index aa8c91e..42ca45a 100644 --- a/src/test/java/dev/orion/talk/unit/TalkUnitTest.java +++ b/src/test/java/dev/orion/talk/unit/TalkUnitTest.java @@ -1,6 +1,6 @@ /** * @License - * Copyright 2023 Orion Services @ https://github.com/orion-services + * Copyright 2024 Orion Services @ https://github.com/orion-services * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/config/checkstyle-suppressions.xml b/static/checkstyle.xml similarity index 82% rename from config/checkstyle-suppressions.xml rename to static/checkstyle.xml index 21b92b8..3e93aa1 100644 --- a/config/checkstyle-suppressions.xml +++ b/static/checkstyle.xml @@ -6,4 +6,5 @@ + \ No newline at end of file diff --git a/static/pmd.xml b/static/pmd.xml new file mode 100644 index 0000000..3ec78ba --- /dev/null +++ b/static/pmd.xml @@ -0,0 +1,16 @@ + + + + + + Orion Talk rules + + + + + + + + \ No newline at end of file