-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added Develop to all pipelines * Added kotlin jvm plugin * Added Main.kt * Fixing warning error * Migrating Main class to kotlin * Updated tests * Implementing spring data jpa for kotlin * Migrating all repositories to kotlin * Changed some service and object to kotlin * Continuing migration * changing json changelogs to xml changelogs * removing unused import * create gradle.properties to avoid metaspace error in github action * Finishing migrating business code to kotlin * [LT-1] Removed MainClass test * Added tests for LootService class * Added jacoco report for sonarcloud * Added new test for LootController * [LT-2] Optimizing the loot controller (#43) * [LT-3] Cleaning the gradle.build file (#44) * [LT-4] Update README.md (#45) * [LT-2] Optimizing the loot controller (#43) * [LT-3] Cleaning the gradle.build file (#44) * [LT-4] Update README.md (#45)
- Loading branch information
Showing
14 changed files
with
70 additions
and
111 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1 +1 @@ | ||
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m | ||
org.gradle.jvmargs=-Xmx2048m |
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,8 +1,7 @@ | ||
package fr.bfr.api | ||
|
||
import fr.bfr.model.Character | ||
import fr.bfr.model.DropChance | ||
|
||
interface LootApi { | ||
fun pull(data: List<Character>, dropChances: List<DropChance>, numberOfPull: Int): List<Character> | ||
fun pull(numberOfPull: Int): List<Character> | ||
} |
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,16 +1,14 @@ | ||
package fr.bfr.model | ||
|
||
import javax.persistence.Entity | ||
import javax.persistence.GeneratedValue | ||
import javax.persistence.Id | ||
import javax.persistence.Table | ||
|
||
@Entity | ||
@Table(name = "t_character") | ||
class Character( | ||
@Id | ||
@GeneratedValue | ||
var id: Long, | ||
var name: String, | ||
var rarity: Int | ||
var rarity: Int, | ||
) |
This file contains 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 |
---|---|---|
|
@@ -9,5 +9,5 @@ import javax.persistence.Table | |
class DropChance( | ||
@Id | ||
var rarity: Int, | ||
var chance: Double | ||
var chance: Int, | ||
) |
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
CREATE TABLE public.t_character ( | ||
id int8 NOT NULL GENERATED BY DEFAULT AS IDENTITY, | ||
id int8 NOT NULL, | ||
"name" varchar(255) NULL, | ||
rarity int4 NULL, | ||
CONSTRAINT t_character_pkey PRIMARY KEY (id) | ||
); | ||
|
||
CREATE TABLE public.t_drop ( | ||
rarity int4 NOT NULL, | ||
chance float8 NULL, | ||
chance int4 NULL, | ||
CONSTRAINT t_drop_pkey PRIMARY KEY (rarity) | ||
); |
This file contains 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 |
---|---|---|
@@ -1,26 +1,31 @@ | ||
package controller | ||
|
||
import fr.bfr.Main | ||
import fr.bfr.controller.LootController | ||
import fr.bfr.model.Character | ||
import org.assertj.core.api.Assertions | ||
import fr.bfr.services.LootService | ||
import 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 | ||
import org.springframework.boot.test.web.client.TestRestTemplate | ||
import org.springframework.boot.test.web.client.getForEntity | ||
import org.mockito.kotlin.any | ||
import org.mockito.kotlin.mock | ||
import org.mockito.kotlin.whenever | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.test.context.ActiveProfiles | ||
import org.springframework.http.ResponseEntity | ||
|
||
@SpringBootTest(classes = [Main::class], webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
@ActiveProfiles("test") | ||
class LootControllerTest( | ||
@Autowired val restTemplate: TestRestTemplate | ||
) { | ||
class LootControllerTest { | ||
|
||
@Test | ||
fun `Integration test of the Pull endpoint`() { | ||
val entity = restTemplate.getForEntity<List<Character>>("/pull") | ||
Assertions.assertThat(entity.statusCode).isEqualTo(HttpStatus.OK) | ||
Assertions.assertThat(entity.body).isEqualTo(emptyList<Character>()) | ||
fun `Check if pull endpoint is sending correct data`() { | ||
// Mocking | ||
val mockLootService: LootService = mock() | ||
whenever(mockLootService.pull(any())).thenReturn(listOf(Character(1, "bfr", 1))) | ||
val lootController = LootController(mockLootService) | ||
|
||
// Using the method to test | ||
val result: ResponseEntity<List<Character>> = lootController.pull() | ||
|
||
// Assertions | ||
Assertions.assertEquals(HttpStatus.OK, result.statusCode) | ||
result.body?.let { Assertions.assertEquals(1, it.size) } | ||
Assertions.assertEquals(true, result.body?.isNotEmpty() ?: false) | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -1,40 +1,35 @@ | ||
package services | ||
|
||
import fr.bfr.Main | ||
import fr.bfr.api.CharacterRepository | ||
import fr.bfr.api.DropChanceRepository | ||
import fr.bfr.model.Character | ||
import fr.bfr.model.DropChance | ||
import fr.bfr.services.LootService | ||
import 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 | ||
import org.springframework.test.context.ActiveProfiles | ||
import org.mockito.kotlin.mock | ||
import org.mockito.kotlin.whenever | ||
import fr.bfr.model.Character as CharacterBfr | ||
|
||
@SpringBootTest(classes = [Main::class]) | ||
@ActiveProfiles("test") | ||
class LootServiceTest(@Autowired val lootService: LootService) { | ||
class LootServiceTest { | ||
|
||
@Test | ||
fun `Assert pull method is working`() { | ||
//data | ||
val data: List<CharacterBfr> = generateCharacterList() | ||
//DropChance | ||
val dropChance: List<DropChance> = generateDropChanceList() | ||
//NumberOfPull | ||
// Mocking | ||
val mockCharacterRepository: CharacterRepository = mock() | ||
val mockDropChanceRepository: DropChanceRepository = mock() | ||
whenever(mockCharacterRepository.findAll()).thenReturn(listOf(Character(1, "bfr", 1))) | ||
whenever(mockDropChanceRepository.findAll()).thenReturn(listOf(DropChance(1, 100))) | ||
val lootService = LootService(mockCharacterRepository, mockDropChanceRepository) | ||
|
||
// NumberOfPull | ||
val numberOfPull = 1 | ||
val result: List<CharacterBfr> = lootService.pull(data, dropChance, numberOfPull) | ||
val result: List<CharacterBfr> = lootService.pull(numberOfPull) | ||
|
||
// Assertions | ||
Assertions.assertEquals(result.size, 1) | ||
Assertions.assertEquals(result[0].id, 1) | ||
Assertions.assertEquals(result[0].name, "bfr") | ||
Assertions.assertEquals(result[0].rarity, 1) | ||
} | ||
|
||
fun generateCharacterList(): List<CharacterBfr> { | ||
return listOf(Character(1, "bfr", 1)) | ||
} | ||
|
||
fun generateDropChanceList(): List<DropChance> { | ||
return listOf(DropChance(1, 100.0)) | ||
} | ||
} |