Skip to content

Commit

Permalink
Update deprecated code to recommended strategy
Browse files Browse the repository at this point in the history
This is part one of an epic to replace deprecated method calls
with the recommended solution.

Signed-off-by: Glenn Renfro <[email protected]>
  • Loading branch information
cppwfs committed Nov 14, 2024
1 parent 163963a commit 6c40236
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.springframework.security.oauth2.core.AuthorizationGrantType;
import org.springframework.security.oauth2.core.OAuth2AuthorizationException;
import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse;
import org.springframework.security.oauth2.server.resource.BearerTokenAuthenticationToken;
import org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthenticationToken;
import org.springframework.security.oauth2.server.resource.authentication.OpaqueTokenAuthenticationProvider;
import org.springframework.security.oauth2.server.resource.introspection.OpaqueTokenIntrospector;
import org.springframework.web.client.ResourceAccessException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private Optional<String> id(String containerName) throws IOException, Interrupte
}

private Process followLogs(String container) throws IOException, InterruptedException {
if (version().greaterThanOrEqualTo(VERSION_1_7_0)) {
if (version().isHigherThanOrEquivalentTo(VERSION_1_7_0)) {
return rawExecutable.execute(true, "logs", "--no-color", "--follow", container);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Version configuredVersion() throws IOException, InterruptedException {
String versionString = command.execute(Command.throwingOnError(), false, "-v");
Matcher matcher = VERSION_PATTERN.matcher(versionString);
Assert.state(matcher.matches(), "Unexpected output of docker -v: " + versionString);
return Version.forIntegers(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)),
return Version.of(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)),
Integer.parseInt(matcher.group(3)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.cloud.task.listener.TaskExecutionListenerSupport;
import org.springframework.cloud.task.listener.TaskExecutionListener;
import org.springframework.cloud.task.repository.TaskExecution;

public class ComposedTaskRunnerTaskListener extends TaskExecutionListenerSupport {
public class ComposedTaskRunnerTaskListener implements TaskExecutionListener {
private final static Logger logger = LoggerFactory.getLogger(ComposedTaskRunnerTaskListener.class);

private static Long executionId = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public Optional<String> getDockerTokenServiceUri(String registryHost, boolean di
return Optional.empty();
} catch (HttpClientErrorException httpError) {

if (httpError.getRawStatusCode() != 401) {
if (httpError.getStatusCode().value() != 401) {
return Optional.empty();
}
if (httpError.getResponseHeaders() == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.core5.http.HttpHeaders;
import org.apache.hc.core5.http.io.HttpClientResponseHandler;
import org.junit.jupiter.api.Test;

import org.springframework.boot.SpringBootConfiguration;
Expand Down Expand Up @@ -61,14 +62,12 @@ void resourceBasedAuthorizationHeader() throws Exception {
throw new Passed();
})
.buildHttpClient()) {
assertThatExceptionOfType(Passed.class).isThrownBy(() -> client.execute(new HttpGet(targetHost)));
assertThatExceptionOfType(Passed.class).isThrownBy(() -> client.execute(new HttpGet(targetHost), getNoOpResponseHandler()));
}
}

static final class TestException extends IOException {
TestException() {
super("It broke");
}
private HttpClientResponseHandler<String> getNoOpResponseHandler() {
return response -> "noOp";
}

static final class ByteArrayCheckableResource extends ByteArrayResource implements CheckableResource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport;
import org.springframework.http.HttpStatus;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -168,7 +167,7 @@ public void save(
) {
Map<String, String> propertiesToUse = DeploymentPropertiesUtils.parse(properties);
List<String> argumentsToUse = DeploymentPropertiesUtils.parseArgumentList(arguments, " ");
this.schedulerService.schedule(StringUtils.trimWhitespace(scheduleName), taskDefinitionName,
this.schedulerService.schedule(scheduleName.strip(), taskDefinitionName,
propertiesToUse, argumentsToUse, platform);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,21 @@ void serverDoesNotStartWhenUrlIsH2ButInvalidForm() {
"spring.datasource.url=jdbc:h2:tcp://localhost:-1/mem:dataflow;DATABASE_TO_UPPER=FALSE",
"spring.dataflow.embedded.database.enabled=true")
.run(context -> assertThat(context)
.getFailure().getRootCause().isInstanceOf(IllegalArgumentException.class)
.getFailure().rootCause().isInstanceOf(IllegalArgumentException.class)
.hasMessageMatching("DataSource URL .* does not match regex pattern: .*"));

runner.withPropertyValues(
"spring.datasource.url=jdbc:h2:tcp://localhost:port/mem:dataflow;DATABASE_TO_UPPER=FALSE",
"spring.dataflow.embedded.database.enabled=true")
.run(context -> assertThat(context)
.getFailure().getRootCause().isInstanceOf(IllegalArgumentException.class)
.getFailure().rootCause().isInstanceOf(IllegalArgumentException.class)
.hasMessageMatching("DataSource URL .* does not match regex pattern: .*"));

runner.withPropertyValues(
"spring.datasource.url=jdbc:h2:tcp://localhost:99999/mem:dataflow;DATABASE_TO_UPPER=FALSE",
"spring.dataflow.embedded.database.enabled=true")
.run(context -> assertThat(context)
.getFailure().getRootCause().isInstanceOf(IllegalArgumentException.class)
.getFailure().rootCause().isInstanceOf(IllegalArgumentException.class)
.hasMessage("Port value out of range: 99999"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ public interface DeriveType {
}

public static int loadCSV(String tableName, DataSource dataSource, Resource cvsResource, DeriveType deriveType) throws IOException {
CSVParser parser = CSVFormat.RFC4180.withFirstRecordAsHeader()
CSVParser parser = CSVFormat.RFC4180.builder()
.setHeader()
.setSkipHeaderRecord(true)
.build()
.parse(new InputStreamReader(cvsResource.getInputStream()));
List<String> headerNames = parser.getHeaderNames();
final List<CSVRecord> records = parser.getRecords();
Expand Down

0 comments on commit 6c40236

Please sign in to comment.