|
| 1 | +/* |
| 2 | + * Copyright 2012-2023 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.autoconfigure.jms; |
| 18 | + |
| 19 | +import jakarta.jms.Session; |
| 20 | +import org.junit.jupiter.api.Test; |
| 21 | +import org.junit.jupiter.params.ParameterizedTest; |
| 22 | +import org.junit.jupiter.params.provider.EnumSource; |
| 23 | + |
| 24 | +import org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException; |
| 25 | + |
| 26 | +import static org.assertj.core.api.Assertions.assertThat; |
| 27 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
| 28 | + |
| 29 | +/** |
| 30 | + * Tests for {@link JmsAcknowledgeModeMapper}. |
| 31 | + * |
| 32 | + * @author Andy Wilkinson |
| 33 | + */ |
| 34 | +class JmsAcknowledgeModeMapperTests { |
| 35 | + |
| 36 | + @ParameterizedTest |
| 37 | + @EnumSource(Mapping.class) |
| 38 | + void stringIsMappedToInt(Mapping mapping) { |
| 39 | + assertThat(JmsAcknowledgeModeMapper.map(mapping.actual)).isEqualTo(mapping.expected); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + void mapShouldThrowWhenMapIsCalledWithUnknownNonIntegerString() { |
| 44 | + assertThatExceptionOfType(InvalidConfigurationPropertyValueException.class) |
| 45 | + .isThrownBy(() -> JmsAcknowledgeModeMapper.map("some-string")); |
| 46 | + } |
| 47 | + |
| 48 | + private enum Mapping { |
| 49 | + |
| 50 | + AUTO_LOWER_CASE("auto", Session.AUTO_ACKNOWLEDGE), |
| 51 | + |
| 52 | + CLIENT_LOWER_CASE("client", Session.CLIENT_ACKNOWLEDGE), |
| 53 | + |
| 54 | + DUPS_OK_LOWER_CASE("dups_ok", Session.DUPS_OK_ACKNOWLEDGE), |
| 55 | + |
| 56 | + AUTO_UPPER_CASE("AUTO", Session.AUTO_ACKNOWLEDGE), |
| 57 | + |
| 58 | + CLIENT_UPPER_CASE("CLIENT", Session.CLIENT_ACKNOWLEDGE), |
| 59 | + |
| 60 | + DUPS_OK_UPPER_CASE("DUPS_OK", Session.DUPS_OK_ACKNOWLEDGE), |
| 61 | + |
| 62 | + AUTO_MIXED_CASE("AuTo", Session.AUTO_ACKNOWLEDGE), |
| 63 | + |
| 64 | + CLIENT_MIXED_CASE("CliEnT", Session.CLIENT_ACKNOWLEDGE), |
| 65 | + |
| 66 | + DUPS_OK_MIXED_CASE("dUPs_Ok", Session.DUPS_OK_ACKNOWLEDGE), |
| 67 | + |
| 68 | + DUPS_OK_KEBAB_CASE("DUPS-OK", Session.DUPS_OK_ACKNOWLEDGE), |
| 69 | + |
| 70 | + DUPS_OK_NO_SEPARATOR_UPPER_CASE("DUPSOK", Session.DUPS_OK_ACKNOWLEDGE), |
| 71 | + |
| 72 | + DUPS_OK_NO_SEPARATOR_LOWER_CASE("dupsok", Session.DUPS_OK_ACKNOWLEDGE), |
| 73 | + |
| 74 | + DUPS_OK_NO_SEPARATOR_MIXED_CASE("duPSok", Session.DUPS_OK_ACKNOWLEDGE), |
| 75 | + |
| 76 | + INTEGER("36", 36); |
| 77 | + |
| 78 | + private final String actual; |
| 79 | + |
| 80 | + private final int expected; |
| 81 | + |
| 82 | + Mapping(String actual, int expected) { |
| 83 | + this.actual = actual; |
| 84 | + this.expected = expected; |
| 85 | + } |
| 86 | + |
| 87 | + } |
| 88 | + |
| 89 | +} |
0 commit comments