Skip to content

Commit

Permalink
The original code would use TaskServiceUtils to return a false if it …
Browse files Browse the repository at this point in the history
…was null.

Add Tests

Signed-off-by: Glenn Renfro <[email protected]>

Resolve code review comments

Updated tests based on code review

Signed-off-by: Glenn Renfro <[email protected]>
  • Loading branch information
cppwfs committed Nov 14, 2024
1 parent 9aa645c commit 163963a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.dataflow.core.DataFlowPropertyKeys;
import org.springframework.util.Assert;

/**
* Properties used to define the behavior of the composed task runner.
Expand All @@ -44,7 +45,7 @@ public class ComposedTaskRunnerConfigurationProperties {
* If true SCDF will set the dataflow-server-access-token for the composed
* task runner to the user's token when launching composed tasks.
*/
private Boolean useUserAccessToken;
private Boolean useUserAccessToken = false;

public String getUri() {
return uri;
Expand All @@ -67,6 +68,7 @@ public Boolean isUseUserAccessToken() {
}

public void setUseUserAccessToken(Boolean useUserAccessToken) {
Assert.notNull(useUserAccessToken, "'useUserAccessToken' cannot be null");
this.useUserAccessToken = useUserAccessToken;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;

public class ComposedTaskRunnerConfigurationPropertiesTests {

Expand All @@ -36,14 +38,23 @@ void useUserAccessTokenFromCTRPropFalse() {
ComposedTaskRunnerConfigurationProperties composedTaskRunnerConfigurationProperties =
new ComposedTaskRunnerConfigurationProperties();
composedTaskRunnerConfigurationProperties.setUseUserAccessToken(false);
assertThat(composedTaskRunnerConfigurationProperties.isUseUserAccessToken()).as("Use user access token should be false").isFalse();
assertThat(composedTaskRunnerConfigurationProperties.isUseUserAccessToken()).isFalse();
}

@Test
void useUserAccessTokenFromCTRPropNotSet() {
ComposedTaskRunnerConfigurationProperties composedTaskRunnerConfigurationProperties =
new ComposedTaskRunnerConfigurationProperties();
assertThat(composedTaskRunnerConfigurationProperties.isUseUserAccessToken()).as("Use user access token should be false").isNull();
assertThat(composedTaskRunnerConfigurationProperties.isUseUserAccessToken()).isFalse();
}

@Test
void setUserAccessTokenFromCTRToNull() {
ComposedTaskRunnerConfigurationProperties composedTaskRunnerConfigurationProperties =
new ComposedTaskRunnerConfigurationProperties();
assertThatIllegalArgumentException().isThrownBy(() -> composedTaskRunnerConfigurationProperties.setUseUserAccessToken(null)).
withMessageContaining("'useUserAccessToken' cannot be null")
;
}

@Test
Expand Down

0 comments on commit 163963a

Please sign in to comment.