diff --git a/README.md b/README.md index 448a4058..d117e03a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# th2 common library (Java) (3.29.0) +# th2 common library (Java) (3.29.1) ## Usage @@ -274,6 +274,10 @@ EVENTS METRICS: ## Release notes +### 3.29.1 + ++ Fix problem with filtering by `message_type` in MessageGroupBatch router + ### 3.29.0 + Update Cradle version from `2.13.0` to `2.20.0` diff --git a/build.gradle b/build.gradle index f6fbfdca..40620764 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ targetCompatibility = 11 ext { cradleVersion = '2.20.0' - junitVersion = '5.4.2' + junitVersion = '5.7.2' sharedDir = file("${project.rootDir}/shared") } @@ -201,9 +201,7 @@ dependencies { implementation 'io.fabric8:kubernetes-client:4.13.0' - testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}" - testImplementation "org.junit.jupiter:junit-jupiter-params:${junitVersion}" - testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}" + testImplementation "org.junit.jupiter:junit-jupiter:${junitVersion}" } jar { diff --git a/gradle.properties b/gradle.properties index 11022d0b..21850535 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ # limitations under the License. # -release_version=3.29.0 +release_version=3.29.1 description = 'th2 common library (Java)' diff --git a/src/main/kotlin/com/exactpro/th2/common/schema/filter/strategy/impl/AnyMessageFilterStrategy.kt b/src/main/kotlin/com/exactpro/th2/common/schema/filter/strategy/impl/AnyMessageFilterStrategy.kt index 0ce4aea0..d39f229d 100644 --- a/src/main/kotlin/com/exactpro/th2/common/schema/filter/strategy/impl/AnyMessageFilterStrategy.kt +++ b/src/main/kotlin/com/exactpro/th2/common/schema/filter/strategy/impl/AnyMessageFilterStrategy.kt @@ -33,7 +33,7 @@ class AnyMessageFilterStrategy : AbstractFilterStrategy() { val metadata = message.message.metadata result[AbstractTh2MsgFilterStrategy.SESSION_ALIAS_KEY] = metadata.id.connectionId.sessionAlias - result[AbstractTh2MsgFilterStrategy.MESSAGE_TYPE_KEY] = message.message.descriptorForType.name + result[AbstractTh2MsgFilterStrategy.MESSAGE_TYPE_KEY] = metadata.messageType result[AbstractTh2MsgFilterStrategy.DIRECTION_KEY] = metadata.id.direction.name } message.hasRawMessage() -> { diff --git a/src/test/kotlin/com/exactpro/th2/common/schema/filter/strategy/impl/TestAnyMessageFilterStrategy.kt b/src/test/kotlin/com/exactpro/th2/common/schema/filter/strategy/impl/TestAnyMessageFilterStrategy.kt new file mode 100644 index 00000000..be2cb2a9 --- /dev/null +++ b/src/test/kotlin/com/exactpro/th2/common/schema/filter/strategy/impl/TestAnyMessageFilterStrategy.kt @@ -0,0 +1,133 @@ +/* + * Copyright 2021 Exactpro (Exactpro Systems Limited) + * + * 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 com.exactpro.th2.common.schema.filter.strategy.impl + +import com.exactpro.th2.common.grpc.AnyMessage +import com.exactpro.th2.common.grpc.Direction +import com.exactpro.th2.common.grpc.RawMessage +import com.exactpro.th2.common.message.message +import com.exactpro.th2.common.message.toJson +import com.exactpro.th2.common.schema.message.configuration.FieldFilterConfiguration +import com.exactpro.th2.common.schema.message.configuration.FieldFilterOperation +import com.exactpro.th2.common.schema.message.configuration.MqRouterFilterConfiguration +import org.apache.commons.collections4.MultiMapUtils +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.Arguments +import org.junit.jupiter.params.provider.Arguments.arguments +import org.junit.jupiter.params.provider.MethodSource +import org.junit.jupiter.params.provider.ValueSource + +class TestAnyMessageFilterStrategy { + private val strategy = AnyMessageFilterStrategy() + + @ParameterizedTest + @MethodSource("parsedMessages") + fun `matches the parsed message by message type with single filter`(anyMessage: AnyMessage, expectMatch: Boolean) { + val match = strategy.verify( + anyMessage, + MqRouterFilterConfiguration( + metadata = MultiMapUtils.newListValuedHashMap().apply { + put("message_type", FieldFilterConfiguration( + fieldName = "message_type", + operation = FieldFilterOperation.EQUAL, + expectedValue = "test" + )) + } + )) + + assertEquals(expectMatch, match) { "The message ${anyMessage.toJson()} was${if (expectMatch) "" else " not"} matched" } + } + + @ParameterizedTest + @MethodSource("messages") + fun `matches the parsed message by direction with single filter`(message: AnyMessage, expectMatch: Boolean) { + val match = strategy.verify( + message, + MqRouterFilterConfiguration( + metadata = MultiMapUtils.newListValuedHashMap().apply { + put("direction", FieldFilterConfiguration( + fieldName = "direction", + operation = FieldFilterOperation.EQUAL, + expectedValue = "FIRST" + )) + } + )) + + assertEquals(expectMatch, match) { "The message ${message.toJson()} was${if (expectMatch) "" else " not"} matched" } + } + + @ParameterizedTest + @MethodSource("messages") + fun `matches the parsed message by alias with single filter`(message: AnyMessage, expectMatch: Boolean) { + val match = strategy.verify( + message, + MqRouterFilterConfiguration( + metadata = MultiMapUtils.newListValuedHashMap().apply { + put("session_alias", FieldFilterConfiguration( + fieldName = "session_alias", + operation = FieldFilterOperation.EQUAL, + expectedValue = "test-alias" + )) + } + )) + + assertEquals(expectMatch, match) { "The message ${message.toJson()} was${if (expectMatch) "" else " not"} matched" } + } + + companion object { + private val PARSED_MESSAGE_MATCH = AnyMessage.newBuilder().setMessage( + message("test", Direction.FIRST, "test-alias") + ).build() + + private val RAW_MESSAGE_MATCH = AnyMessage.newBuilder().setRawMessage( + RawMessage.newBuilder().apply { + metadataBuilder.idBuilder.apply { + connectionIdBuilder.sessionAlias = "test-alias" + direction = Direction.FIRST + } + } + ).build() + + private val PARSED_MESSAGE_MISS_MATCH = AnyMessage.newBuilder().setMessage( + message("test1", Direction.SECOND, "test-alias1") + ).build() + + private val RAW_MESSAGE_MISS_MATCH = AnyMessage.newBuilder().setRawMessage( + RawMessage.newBuilder().apply { + metadataBuilder.idBuilder.apply { + connectionIdBuilder.sessionAlias = "test-alias1" + direction = Direction.SECOND + } + } + ).build() + + @JvmStatic + fun parsedMessages(): List = listOf( + arguments(PARSED_MESSAGE_MATCH, true), + arguments(PARSED_MESSAGE_MISS_MATCH, false) + ) + + @JvmStatic + fun messages(): List = listOf( + arguments(RAW_MESSAGE_MATCH, true), + arguments(RAW_MESSAGE_MISS_MATCH, false) + ) + parsedMessages() + } +} \ No newline at end of file