Skip to content

Commit

Permalink
refactor/remove-org.reflections.reflections-dependency
Browse files Browse the repository at this point in the history
- Utilized JPA's Metamodel API to retrieve all managed entity classes.
- Prefixed instance variables and methods with `this.` to enhance code clarity.
- Rename `AbstractIntegrationTest` to `IntegrationTestUtil`, and make
  its methods public so it can be used without requiring class inheritance.
- Move `createNewArticle` method from `ArticlesResourceIntegrationTest` to `IntegrationTestUtil`.

Signed-off-by: Pedro Aguiar <[email protected]>
  • Loading branch information
codespearhead committed Oct 16, 2024
1 parent 1d17379 commit 366974b
Show file tree
Hide file tree
Showing 8 changed files with 349 additions and 256 deletions.
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.10.2</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
Expand Down

This file was deleted.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,28 @@
import static org.example.realworldapi.constants.TestConstants.*;
import static org.hamcrest.Matchers.is;

import io.quarkus.test.TestTransaction;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import jakarta.ws.rs.core.MediaType;
import org.apache.http.HttpStatus;
import org.example.realworldapi.AbstractIntegrationTest;
import org.example.realworldapi.util.IntegrationTestUtil;
import org.junit.jupiter.api.Test;

@QuarkusTest
public class ProfilesResourceIntegrationTest extends AbstractIntegrationTest {
@TestTransaction
public class ProfilesResourceIntegrationTest {

@Inject IntegrationTestUtil integrationTestUtil;

private final String PROFILES_PATH = API_PREFIX + "/profiles";

@Test
public void
givenExistentUser_whenExecuteGetProfileEndpointWithoutAuth_shouldReturnAUserProfile() {

final var existentUser = createUserEntity("user1", "[email protected]", "bio", "image", "user123");
final var existentUser =
integrationTestUtil.createUserEntity("user1", "[email protected]", "bio", "image", "user123");

given()
.contentType(MediaType.APPLICATION_JSON)
Expand All @@ -44,14 +50,18 @@ public class ProfilesResourceIntegrationTest extends AbstractIntegrationTest {
givenExistentUserWithFollows_whenExecuteGetProfileEndpointWithAuth_shouldReturnAUserProfileWithFollowingTrue() {

final var loggedUser =
createUserEntity("loggeduser", "[email protected]", "bio", "image", "user123");
final var user = createUserEntity("user", "[email protected]", "bio", "image", "user123");
integrationTestUtil.createUserEntity(
"loggeduser", "[email protected]", "bio", "image", "user123");
final var user =
integrationTestUtil.createUserEntity("user", "[email protected]", "bio", "image", "user123");

follow(loggedUser, user);
integrationTestUtil.follow(loggedUser, user);

given()
.contentType(MediaType.APPLICATION_JSON)
.header(AUTHORIZATION_HEADER, AUTHORIZATION_HEADER_VALUE_PREFIX + token(loggedUser))
.header(
AUTHORIZATION_HEADER,
AUTHORIZATION_HEADER_VALUE_PREFIX + integrationTestUtil.token(loggedUser))
.get(PROFILES_PATH + "/" + user.getUsername())
.then()
.statusCode(HttpStatus.SC_OK)
Expand All @@ -73,12 +83,16 @@ public class ProfilesResourceIntegrationTest extends AbstractIntegrationTest {
givenExistentUserWithoutFollows_whenExecuteGetProfileEndpointWithAuth_shouldReturnAUserProfileWithFollowingFalse() {

final var loggedUser =
createUserEntity("loggeduser", "[email protected]", "bio", "image", "user123");
final var user = createUserEntity("user", "[email protected]", "bio", "image", "user123");
integrationTestUtil.createUserEntity(
"loggeduser", "[email protected]", "bio", "image", "user123");
final var user =
integrationTestUtil.createUserEntity("user", "[email protected]", "bio", "image", "user123");

given()
.contentType(MediaType.APPLICATION_JSON)
.header(AUTHORIZATION_HEADER, AUTHORIZATION_HEADER_VALUE_PREFIX + token(loggedUser))
.header(
AUTHORIZATION_HEADER,
AUTHORIZATION_HEADER_VALUE_PREFIX + integrationTestUtil.token(loggedUser))
.get(PROFILES_PATH + "/" + user.getUsername())
.then()
.statusCode(HttpStatus.SC_OK)
Expand All @@ -99,13 +113,17 @@ public class ProfilesResourceIntegrationTest extends AbstractIntegrationTest {
public void
givenExistentUsers_whenExecuteFollowEndpoint_shouldReturnProfileWithFollowingFieldTrue() {

final var user = createUserEntity("user", "[email protected]", "bio", "image", "user123");
final var user =
integrationTestUtil.createUserEntity("user", "[email protected]", "bio", "image", "user123");
final var loggedUser =
createUserEntity("loggeduser", "[email protected]", "bio", "image", "user123");
integrationTestUtil.createUserEntity(
"loggeduser", "[email protected]", "bio", "image", "user123");

given()
.contentType(MediaType.APPLICATION_JSON)
.header(AUTHORIZATION_HEADER, AUTHORIZATION_HEADER_VALUE_PREFIX + token(loggedUser))
.header(
AUTHORIZATION_HEADER,
AUTHORIZATION_HEADER_VALUE_PREFIX + integrationTestUtil.token(loggedUser))
.post(PROFILES_PATH + "/" + user.getUsername() + "/follow")
.then()
.statusCode(HttpStatus.SC_OK)
Expand All @@ -126,15 +144,19 @@ public class ProfilesResourceIntegrationTest extends AbstractIntegrationTest {
public void
givenExistentUserWithFollower_whenExecuteUnfollowEndpoint_shouldReturnProfileWithFollowingFieldFalse() {

final var user = createUserEntity("user", "[email protected]", "bio", "image", "user123");
final var user =
integrationTestUtil.createUserEntity("user", "[email protected]", "bio", "image", "user123");
final var loggedUser =
createUserEntity("loggeduser", "[email protected]", "bio", "image", "user123");
integrationTestUtil.createUserEntity(
"loggeduser", "[email protected]", "bio", "image", "user123");

follow(loggedUser, user);
integrationTestUtil.follow(loggedUser, user);

given()
.contentType(MediaType.APPLICATION_JSON)
.header(AUTHORIZATION_HEADER, AUTHORIZATION_HEADER_VALUE_PREFIX + token(loggedUser))
.header(
AUTHORIZATION_HEADER,
AUTHORIZATION_HEADER_VALUE_PREFIX + integrationTestUtil.token(loggedUser))
.delete(PROFILES_PATH + "/" + user.getUsername() + "/follow")
.then()
.statusCode(HttpStatus.SC_OK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.is;

import io.quarkus.test.TestTransaction;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import jakarta.ws.rs.core.MediaType;
import org.apache.http.HttpStatus;
import org.example.realworldapi.AbstractIntegrationTest;
import org.example.realworldapi.util.IntegrationTestUtil;
import org.junit.jupiter.api.Test;

@QuarkusTest
public class TagsResourceIntegrationTest extends AbstractIntegrationTest {
@TestTransaction
public class TagsResourceIntegrationTest {

@Inject IntegrationTestUtil integrationTestUtil;

private final String TAGS_PATH = API_PREFIX + "/tags";

@Test
public void givenExistentTags_whenExecuteGetTagsEndpoint_shouldReturnTagListWithStatusCode200() {

final var tag1 = createTagEntity("tag 1");
final var tag2 = createTagEntity("tag 2");
final var tag3 = createTagEntity("tag 3");
final var tag4 = createTagEntity("tag 4");
final var tag1 = integrationTestUtil.createTagEntity("tag 1");
final var tag2 = integrationTestUtil.createTagEntity("tag 2");
final var tag3 = integrationTestUtil.createTagEntity("tag 3");
final var tag4 = integrationTestUtil.createTagEntity("tag 4");

given()
.contentType(MediaType.APPLICATION_JSON)
Expand Down
Loading

0 comments on commit 366974b

Please sign in to comment.