-
-
Notifications
You must be signed in to change notification settings - Fork 0
GH-127 Add integration tests for each repository #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Jakubk15
wants to merge
9
commits into
master
Choose a base branch
from
add-integration-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5cf2db5
Add integration tests for each repository
Jakubk15 83bc093
Adjust to coderabbit suggestions
Jakubk15 b4c8b62
Change runServer minecraftVersion property to 1.21.8
Jakubk15 1bf656e
Add missing @Testcontainers annotations
Jakubk15 1956385
Revert minecraftVersion to 1.21.7
Jakubk15 03cef34
Downgrade minecraft to 1.21.5 due to adventure incompatibility
Jakubk15 02fdde7
Merge branch 'master' into add-integration-tests
Jakubk15 5526bf4
Explicitly specify the database type as MYSQL in config
Jakubk15 818cecf
Merge branch 'master' into add-integration-tests
Jakubk15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/test/java/com/eternalcode/parcellockers/database/DeliveryRepositoryIntegrationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.eternalcode.parcellockers.database; | ||
|
||
import com.eternalcode.parcellockers.TestScheduler; | ||
import com.eternalcode.parcellockers.configuration.ConfigurationManager; | ||
import com.eternalcode.parcellockers.configuration.implementation.PluginConfiguration; | ||
import com.eternalcode.parcellockers.delivery.Delivery; | ||
import com.eternalcode.parcellockers.delivery.repository.DeliveryRepository; | ||
import com.eternalcode.parcellockers.delivery.repository.DeliveryRepositoryOrmLite; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
import org.testcontainers.containers.MySQLContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.time.Instant; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.logging.Logger; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@Testcontainers | ||
class DeliveryRepositoryIntegrationTest extends IntegrationTestSpec{ | ||
|
||
@Container | ||
private static final MySQLContainer mySQLContainer = new MySQLContainer(DockerImageName.parse("mysql:latest")); | ||
|
||
@TempDir | ||
private Path tempDir; | ||
|
||
private DatabaseManager databaseManager; | ||
|
||
@Test | ||
void test() { | ||
File dataFolder = tempDir.resolve("ParcelLockers").toFile(); | ||
PluginConfiguration config = new ConfigurationManager(dataFolder).load(new PluginConfiguration()); | ||
config.settings.databaseType = DatabaseType.MYSQL; | ||
DatabaseManager databaseManager = new DatabaseManager(config, Logger.getLogger("ParcelLockers"), dataFolder); | ||
this.databaseManager = databaseManager; | ||
DeliveryRepository deliveryRepository = new DeliveryRepositoryOrmLite(databaseManager, new TestScheduler()); | ||
|
||
Delivery delivery = new Delivery(UUID.randomUUID(), Instant.now()); | ||
deliveryRepository.save(delivery); | ||
|
||
Optional<Delivery> deliveryOptional = await(deliveryRepository.find(delivery.parcel())); | ||
assertTrue(deliveryOptional.isPresent(), "Delivery should be present"); | ||
assertEquals(delivery.parcel(), deliveryOptional.get().parcel()); | ||
|
||
deliveryRepository.remove(delivery.parcel()); | ||
Optional<Delivery> removedDelivery = await(deliveryRepository.find(delivery.parcel())); | ||
assertTrue(removedDelivery.isEmpty(), "Delivery should be removed"); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
if (this.databaseManager != null) { | ||
this.databaseManager.disconnect(); | ||
} | ||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
...est/java/com/eternalcode/parcellockers/database/ItemStorageRepositoryIntegrationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.eternalcode.parcellockers.database; | ||
|
||
import com.eternalcode.parcellockers.TestScheduler; | ||
import com.eternalcode.parcellockers.configuration.ConfigurationManager; | ||
import com.eternalcode.parcellockers.configuration.implementation.PluginConfiguration; | ||
import com.eternalcode.parcellockers.itemstorage.ItemStorage; | ||
import com.eternalcode.parcellockers.itemstorage.repository.ItemStorageRepository; | ||
import com.eternalcode.parcellockers.itemstorage.repository.ItemStorageRepositoryOrmLite; | ||
import org.bukkit.Material; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
import org.testcontainers.containers.MySQLContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.logging.Logger; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@Testcontainers | ||
class ItemStorageRepositoryIntegrationTest extends IntegrationTestSpec { | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@Container | ||
private static final MySQLContainer mySQLContainer = new MySQLContainer(DockerImageName.parse("mysql:latest")); | ||
|
||
@TempDir | ||
private Path tempDir; | ||
|
||
private DatabaseManager databaseManager; | ||
|
||
@Test | ||
void test() { | ||
File dataFolder = tempDir.resolve("ParcelLockers").toFile(); | ||
PluginConfiguration config = new ConfigurationManager(dataFolder).load(new PluginConfiguration()); | ||
config.settings.databaseType = DatabaseType.MYSQL; | ||
this.databaseManager = new DatabaseManager(config, Logger.getLogger("ParcelLockers"), dataFolder); | ||
ItemStorageRepository itemStorageRepository = new ItemStorageRepositoryOrmLite(databaseManager, new TestScheduler()); | ||
|
||
ItemStorage itemStorage = new ItemStorage(UUID.randomUUID(), List.of(new ItemStack(Material.GOLD_BLOCK, 64))); | ||
itemStorageRepository.save(itemStorage); | ||
Optional<ItemStorage> retrievedItemStorage = await(itemStorageRepository.find(itemStorage.owner())); | ||
assertTrue(retrievedItemStorage.isPresent(), "ItemStorage should be present"); | ||
assertTrue(retrievedItemStorage.get().items().contains(new ItemStack(Material.GOLD_BLOCK, 64)), | ||
"ItemStorage should contain the saved item"); | ||
|
||
itemStorageRepository.remove(itemStorage.owner()); | ||
Optional<ItemStorage> removedItemStorage = await(itemStorageRepository.find(itemStorage.owner())); | ||
assertTrue(removedItemStorage.isEmpty(), "ItemStorage should be removed"); | ||
} | ||
|
||
|
||
@AfterEach | ||
void tearDown() { | ||
if (this.databaseManager != null) { | ||
this.databaseManager.disconnect(); | ||
} | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...t/java/com/eternalcode/parcellockers/database/ParcelContentRepositoryIntegrationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.eternalcode.parcellockers.database; | ||
|
||
import com.eternalcode.parcellockers.TestScheduler; | ||
import com.eternalcode.parcellockers.configuration.ConfigurationManager; | ||
import com.eternalcode.parcellockers.configuration.implementation.PluginConfiguration; | ||
import com.eternalcode.parcellockers.content.ParcelContent; | ||
import com.eternalcode.parcellockers.content.repository.ParcelContentRepository; | ||
import com.eternalcode.parcellockers.content.repository.ParcelContentRepositoryOrmLite; | ||
import org.bukkit.Material; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
import org.testcontainers.containers.MySQLContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.logging.Logger; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@Testcontainers | ||
class ParcelContentRepositoryIntegrationTest extends IntegrationTestSpec { | ||
|
||
@Container | ||
private static final MySQLContainer mySQLContainer = new MySQLContainer(DockerImageName.parse("mysql:latest")); | ||
|
||
@TempDir | ||
private Path tempDir; | ||
|
||
private DatabaseManager databaseManager; | ||
|
||
@Test | ||
void test() { | ||
File dataFolder = tempDir.resolve("ParcelLockers").toFile(); | ||
PluginConfiguration config = new ConfigurationManager(dataFolder).load(new PluginConfiguration()); | ||
this.databaseManager = new DatabaseManager(config, Logger.getLogger("ParcelLockers"), dataFolder); | ||
|
||
ParcelContentRepository parcelContentRepository = new ParcelContentRepositoryOrmLite(databaseManager, new TestScheduler()); | ||
|
||
ParcelContent parcelContent = new ParcelContent(UUID.randomUUID(), List.of(new ItemStack(Material.GOLD_BLOCK, 64))); | ||
parcelContentRepository.save(parcelContent); | ||
Optional<ParcelContent> retrievedParcelContent = await(parcelContentRepository.findByUUID(parcelContent.uniqueId())); | ||
assertTrue(retrievedParcelContent.isPresent(), "ParcelContent should be present"); | ||
|
||
parcelContentRepository.remove(parcelContent.uniqueId()); | ||
Optional<ParcelContent> removedParcelContent = await(parcelContentRepository.findByUUID(parcelContent.uniqueId())); | ||
assertFalse(removedParcelContent.isPresent(), "ParcelContent should be removed"); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
if (this.databaseManager != null) { | ||
this.databaseManager.disconnect(); | ||
} | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/test/java/com/eternalcode/parcellockers/database/UserRepositoryIntegrationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.eternalcode.parcellockers.database; | ||
|
||
import com.eternalcode.parcellockers.TestScheduler; | ||
import com.eternalcode.parcellockers.configuration.ConfigurationManager; | ||
import com.eternalcode.parcellockers.configuration.implementation.PluginConfiguration; | ||
import com.eternalcode.parcellockers.shared.Page; | ||
import com.eternalcode.parcellockers.user.User; | ||
import com.eternalcode.parcellockers.user.repository.UserPageResult; | ||
import com.eternalcode.parcellockers.user.repository.UserRepository; | ||
import com.eternalcode.parcellockers.user.repository.UserRepositoryOrmLite; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
import org.testcontainers.containers.MySQLContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@Testcontainers | ||
class UserRepositoryIntegrationTest extends IntegrationTestSpec { | ||
|
||
@Container | ||
private static final MySQLContainer container = new MySQLContainer(); | ||
|
||
@TempDir | ||
private Path tempDir; | ||
|
||
private DatabaseManager databaseManager; | ||
|
||
@Test | ||
void test() { | ||
File dataFolder = tempDir.resolve("ParcelLockers").toFile(); | ||
PluginConfiguration config = new ConfigurationManager(dataFolder).load(new PluginConfiguration()); | ||
config.settings.databaseType = DatabaseType.MYSQL; | ||
DatabaseManager databaseManager = new DatabaseManager(config, null, dataFolder); | ||
this.databaseManager = databaseManager; | ||
|
||
UserRepository userRepository = new UserRepositoryOrmLite(databaseManager, new TestScheduler()); | ||
|
||
UUID userUuid = UUID.randomUUID(); | ||
String username = "testUser"; | ||
User user = new User(userUuid, username); | ||
|
||
userRepository.save(user); | ||
|
||
Optional<User> userOptional = await(userRepository.getUser(userUuid)); | ||
assertTrue(userOptional.isPresent()); | ||
User retrievedUser = userOptional.get(); | ||
assertEquals(retrievedUser.uuid(), userUuid); | ||
|
||
UserPageResult pageResult = await(userRepository.getPage(new Page(0, 10))); | ||
assertTrue(pageResult.users().stream().anyMatch(u -> u.uuid().equals(userUuid))); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
if (this.databaseManager != null) { | ||
this.databaseManager.disconnect(); | ||
} | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.