Browse Source

Assert JmsAccessor.setSessionAcknowledgeMode() values

See gh-30851
pull/28156/merge
Sam Brannen 1 year ago
parent
commit
3b8dd0a5ac
  1. 8
      spring-jms/src/main/java/org/springframework/jms/support/JmsAccessor.java
  2. 25
      spring-jms/src/test/java/org/springframework/jms/support/JmsAccessorTests.java

8
spring-jms/src/main/java/org/springframework/jms/support/JmsAccessor.java

@ -144,9 +144,9 @@ public abstract class JmsAccessor implements InitializingBean { @@ -144,9 +144,9 @@ public abstract class JmsAccessor implements InitializingBean {
*/
public void setSessionAcknowledgeModeName(String constantName) {
Assert.hasText(constantName, "'constantName' must not be null or blank");
Integer acknowledgeMode = sessionConstants.get(constantName);
Assert.notNull(acknowledgeMode, "Only acknowledge mode constants allowed");
setSessionAcknowledgeMode(acknowledgeMode);
Integer sessionAcknowledgeMode = sessionConstants.get(constantName);
Assert.notNull(sessionAcknowledgeMode, "Only acknowledge mode constants allowed");
this.sessionAcknowledgeMode = sessionAcknowledgeMode;
}
/**
@ -167,6 +167,8 @@ public abstract class JmsAccessor implements InitializingBean { @@ -167,6 +167,8 @@ public abstract class JmsAccessor implements InitializingBean {
* @see jakarta.jms.Connection#createSession(boolean, int)
*/
public void setSessionAcknowledgeMode(int sessionAcknowledgeMode) {
Assert.isTrue(sessionConstants.containsValue(sessionAcknowledgeMode),
"Only values of acknowledge mode constants allowed");
this.sessionAcknowledgeMode = sessionAcknowledgeMode;
}

25
spring-jms/src/test/java/org/springframework/jms/support/JmsAccessorTests.java

@ -96,11 +96,21 @@ class JmsAccessorTests { @@ -96,11 +96,21 @@ class JmsAccessorTests {
assertThat(uniqueValues).hasSize(4);
}
@Test
void setSessionAcknowledgeMode() {
assertThatIllegalArgumentException().isThrownBy(() -> accessor.setSessionAcknowledgeMode(999));
private static Stream<String> streamAcknowledgeModeConstants() {
return Arrays.stream(Session.class.getFields())
.filter(ReflectionUtils::isPublicStaticFinal)
.map(Field::getName);
accessor.setSessionAcknowledgeMode(Session.AUTO_ACKNOWLEDGE);
assertThat(accessor.getSessionAcknowledgeMode()).isEqualTo(Session.AUTO_ACKNOWLEDGE);
accessor.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
assertThat(accessor.getSessionAcknowledgeMode()).isEqualTo(Session.CLIENT_ACKNOWLEDGE);
accessor.setSessionAcknowledgeMode(Session.DUPS_OK_ACKNOWLEDGE);
assertThat(accessor.getSessionAcknowledgeMode()).isEqualTo(Session.DUPS_OK_ACKNOWLEDGE);
accessor.setSessionAcknowledgeMode(Session.SESSION_TRANSACTED);
assertThat(accessor.getSessionAcknowledgeMode()).isEqualTo(Session.SESSION_TRANSACTED);
}
@Test
@ -110,4 +120,11 @@ class JmsAccessorTests { @@ -110,4 +120,11 @@ class JmsAccessorTests {
assertThat(accessor.isClientAcknowledge(session)).isTrue();
}
private static Stream<String> streamAcknowledgeModeConstants() {
return Arrays.stream(Session.class.getFields())
.filter(ReflectionUtils::isPublicStaticFinal)
.map(Field::getName);
}
}

Loading…
Cancel
Save