Skip to content

Commit

Permalink
Assert JmsActivationSpecConfig.setAcknowledgeMode() values
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Jul 31, 2023
1 parent b45bfca commit 9da318a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public void setAcknowledgeModeName(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");
setAcknowledgeMode(acknowledgeMode);
this.acknowledgeMode = acknowledgeMode;
}

/**
Expand All @@ -217,6 +217,8 @@ public void setAcknowledgeModeName(String constantName) {
* @see jakarta.jms.Session#SESSION_TRANSACTED
*/
public void setAcknowledgeMode(int acknowledgeMode) {
Assert.isTrue(sessionConstants.containsValue(acknowledgeMode),
"Only values of acknowledge mode constants allowed");
this.acknowledgeMode = acknowledgeMode;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ void setAcknowledgeModeNameToAllSupportedValues() {
assertThat(uniqueValues).hasSize(4);
}

@Test
void setSessionAcknowledgeMode() {
assertThatIllegalArgumentException().isThrownBy(() -> specConfig.setAcknowledgeMode(999));

specConfig.setAcknowledgeMode(Session.AUTO_ACKNOWLEDGE);
assertThat(specConfig.getAcknowledgeMode()).isEqualTo(Session.AUTO_ACKNOWLEDGE);

specConfig.setAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
assertThat(specConfig.getAcknowledgeMode()).isEqualTo(Session.CLIENT_ACKNOWLEDGE);

specConfig.setAcknowledgeMode(Session.DUPS_OK_ACKNOWLEDGE);
assertThat(specConfig.getAcknowledgeMode()).isEqualTo(Session.DUPS_OK_ACKNOWLEDGE);

specConfig.setAcknowledgeMode(Session.SESSION_TRANSACTED);
assertThat(specConfig.getAcknowledgeMode()).isEqualTo(Session.SESSION_TRANSACTED);
}


private static Stream<String> streamAcknowledgeModeConstants() {
return Arrays.stream(Session.class.getFields())
Expand Down

0 comments on commit 9da318a

Please sign in to comment.