Skip to content

Commit

Permalink
refactor: update Spring Boot to 3.1.3 and Spring Cloud to 2022.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed Sep 8, 2023
1 parent 7cdfab3 commit 82e5c88
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import com.jmsoftware.maf.common.bean.ResponseBodyBean
import com.jmsoftware.maf.common.domain.authcenter.permission.GetPermissionListByRoleIdListPayload
import com.jmsoftware.maf.common.domain.authcenter.permission.PermissionType.BUTTON
import com.jmsoftware.maf.common.domain.springbootstarter.HttpApiResourcesResponse
import com.jmsoftware.maf.common.test.jsonStringify
import com.jmsoftware.maf.common.test.parseJson
import com.jmsoftware.maf.common.util.Slf4j
import com.jmsoftware.maf.common.util.Slf4j.Companion.log
import org.junit.jupiter.api.Assertions.*
Expand Down Expand Up @@ -52,7 +54,6 @@ import org.springframework.web.client.RestTemplate
* @see <a href='https://www.youtube.com/watch?v=p7_cTAF39A8/'>YouTube - Using Mockito with JUnit 5</a>
*/
@Slf4j
@Suppress("unused")
@ExtendWith(MockitoExtension::class)
class PermissionServiceImplTest {
@InjectMocks
Expand All @@ -79,17 +80,15 @@ class PermissionServiceImplTest {
@Test
fun getPermissionListByRoleIdList_whenItsNonAdmin_thenReturnConfiguredPermission() {
whenever(roleDomainService.checkAdmin(anyList())).thenReturn(false)
val permission = Permission().apply {
this.url = "/fake/permissions"
this.method = "GET"
this.type = BUTTON.type
this.permissionExpression = "FakePermissionExpression"
}
val permission = parseJson<Permission>(PermissionServiceImplTest::class, "permission/permission.json")
log.info("Permission: ${jsonStringify(permission)}")
whenever(permissionDomainService.getPermissionListByRoleIdList(anyList(), anyList()))
.thenReturn(listOf(permission))
val payload = GetPermissionListByRoleIdListPayload()
payload.roleIdList = listOf(1L)
payload.permissionTypeList = listOf(BUTTON)
val payload = parseJson<GetPermissionListByRoleIdListPayload>(
this,
"permission/get-permission-list-by-role-id-list-payload.json"
)
log.info("payload: ${jsonStringify(payload)}")
val response = assertDoesNotThrow { permissionService.getPermissionListByRoleIdList(payload) }
assertNotNull(response)
assertEquals(1, response.permissionList.size)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"roleIdList": [
1
],
"permissionTypeList": [
"BUTTON"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"deleted": "N",
"url": "/fake/permissions",
"type": 2,
"permissionExpression": "FakePermissionExpression",
"method": "GET"
}
1 change: 0 additions & 1 deletion auth-center/auth-center-infra/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ dependencies {
testImplementation("org.springframework.amqp:spring-rabbit-test") {
exclude("org.codehaus.groovy", "groovy")
}
testImplementation("org.mockito:mockito-inline")
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,31 @@ class Permission : BasePersistenceEntity() {
* Permission description
*/
@TableField(value = COL_DESCRIPTION)
lateinit var description: String
var description: String? = null

/**
* Permission type. 1 - page; 2 - button
*/
@TableField(value = COL_TYPE)
var type: Byte = 0
var type: Byte? = null

/**
* Permission expression
*/
@TableField(value = COL_PERMISSION_EXPRESSION)
lateinit var permissionExpression: String
var permissionExpression: String? = null

/**
* HTTP method of API
*/
@TableField(value = COL_METHOD)
lateinit var method: String
var method: String? = null

/**
* Sort number
*/
@TableField(value = COL_SORT)
var sort: Int = 0
var sort: Int? = null

/**
* Primary key of parent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import jakarta.validation.constraints.NotEmpty
* @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/16/22 6:41 PM
*/
class GetPermissionListByRoleIdListPayload {
@field:NotEmpty
@NotEmpty
lateinit var roleIdList: List<Long>

@field:NotEmpty
@NotEmpty
lateinit var permissionTypeList: List<PermissionType>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.jmsoftware.maf.common.test

import com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.KotlinFeature
import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.fasterxml.jackson.module.kotlin.readValue
import com.jmsoftware.maf.common.test.UnitTestHelper.Companion.OBJECT_MAPPER
import com.jmsoftware.maf.common.test.UnitTestHelper.Companion.log
import com.jmsoftware.maf.common.util.logger

/**
* # UnitTestHelper
*
* change description here.
*
* @author Johnny Miller, email: johnnysviva@outlook.com, date: 7/25/2023 8:52 PM
**/
class UnitTestHelper {
companion object {
val log = logger()
val OBJECT_MAPPER: ObjectMapper = ObjectMapper().registerModules(
JavaTimeModule(),
KotlinModule.Builder()
.withReflectionCacheSize(512)
.configure(KotlinFeature.NullToEmptyCollection, false)
.configure(KotlinFeature.NullToEmptyMap, false)
.configure(KotlinFeature.NullIsSameAsDefault, false)
.configure(KotlinFeature.SingletonSupport, false)
.configure(KotlinFeature.StrictNullChecks, false)
.build()
).also {
it.setSerializationInclusion(NON_NULL)
}
}
}

/**
* Parse JSON string to an object.
*
* @param T the type of the object
* @param context the context object, which could be an instance of KClass, or `this` when calling this method
* @param jsonPath the path to the JSON file under `resources` directory
* @return the object deserialized from the JSON file
*/
inline fun <reified T : Any> parseJson(context: Any, jsonPath: String): T {
return context.javaClass.classLoader.getResourceAsStream(jsonPath).use {
if (it == null) {
log.warn("Could not find the resource: $jsonPath")
throw IllegalArgumentException("Could not find the resource: $jsonPath")
}
OBJECT_MAPPER.readValue<T>(it.readBytes())
}
}

/**
* Stringify an object to a JSON string.
*
* @param any the object
* @return the JSON string
*/
fun jsonStringify(any: Any): String = OBJECT_MAPPER.writeValueAsString(any)
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ snakeyaml = "1.33"
jjwt = "0.11.5"
poi = "5.2.3"
kotlin = "1.8.21"
spring-boot = "3.1.1"
spring-cloud = "2022.0.3"
spring-boot = "3.1.3"
spring-cloud = "2022.0.4"
spring-dependency-management = "1.1.0"
jib = "3.3.2"
git-version = "0.15.0"
Expand Down
1 change: 0 additions & 1 deletion maf-mis/maf-mis-infra/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ dependencies {
testImplementation("org.springframework.amqp:spring-rabbit-test") {
exclude("org.codehaus.groovy", "groovy")
}
testImplementation("org.mockito:mockito-inline")
}
3 changes: 0 additions & 3 deletions oss-center/oss-center-infra/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,4 @@ dependencies {

api(libs.minio.get())
api(libs.tika.core.get())

// Testing
testImplementation("org.mockito:mockito-inline")
}

0 comments on commit 82e5c88

Please sign in to comment.