From 6f3277a2a35529cadbbccd019c56a863170bc980 Mon Sep 17 00:00:00 2001 From: Volodymyr Date: Sun, 18 Aug 2024 18:36:21 +0300 Subject: [PATCH] [bq] refactoring & dependency upgrade --- .github/workflows/spring-batch-bigquery.yml | 6 +-- spring-batch-bigquery/README.adoc | 22 ++++++----- spring-batch-bigquery/pom.xml | 37 +++++++++---------- .../reader/BigQueryQueryItemReader.java | 9 ++--- .../BigQueryQueryItemReaderBuilder.java | 16 ++++---- .../writer/BigQueryBaseItemWriter.java | 31 ++++++++-------- .../writer/BigQueryCsvItemWriter.java | 31 ++++++++-------- .../writer/BigQueryJsonItemWriter.java | 33 +++++++++-------- .../builder/BigQueryCsvItemWriterBuilder.java | 6 +-- .../BigQueryJsonItemWriterBuilder.java | 8 ++-- .../bigquery/writer/package-info.java | 6 +-- .../bigquery/common/BigQueryDataLoader.java | 4 +- .../extensions/bigquery/common/PersonDto.java | 4 +- .../bigquery/common/TestConstants.java | 4 +- .../base/BaseBigQueryIntegrationTest.java | 6 +-- .../bigquery/integration/package-info.java | 10 ++--- ...CsvJsonInteractiveQueryItemReaderTest.java | 10 ++--- .../BigQueryBatchQueryCsvItemReaderTest.java | 11 +++--- .../BigQueryBatchQueryJsonItemReaderTest.java | 11 +++--- ...ueryInteractiveQueryCsvItemReaderTest.java | 11 +++--- ...eryInteractiveQueryJsonItemReaderTest.java | 11 +++--- .../writer/BigQueryCsvItemWriterTest.java | 11 +++--- .../writer/BigQueryJsonItemWriterTest.java | 11 +++--- .../base/BaseBigQueryItemWriterTest.java | 10 ++--- .../unit/base/AbstractBigQueryTest.java | 4 +- ...QueryBatchQueryItemReaderBuilderTests.java | 4 +- ...nteractiveQueryItemReaderBuilderTests.java | 4 +- .../BigQueryCsvItemWriterBuilderTests.java | 4 +- .../BigQueryJsonItemWriterBuilderTests.java | 4 +- 29 files changed, 163 insertions(+), 176 deletions(-) diff --git a/.github/workflows/spring-batch-bigquery.yml b/.github/workflows/spring-batch-bigquery.yml index 7cb6de93..3cc17d19 100644 --- a/.github/workflows/spring-batch-bigquery.yml +++ b/.github/workflows/spring-batch-bigquery.yml @@ -11,13 +11,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout source code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: 17 cache: 'maven' - name: Build with Maven run: mvn -B package --file pom.xml - working-directory: spring-batch-bigquery + working-directory: spring-batch-bigquery \ No newline at end of file diff --git a/spring-batch-bigquery/README.adoc b/spring-batch-bigquery/README.adoc index 7b5c161e..04a597da 100644 --- a/spring-batch-bigquery/README.adoc +++ b/spring-batch-bigquery/README.adoc @@ -1,12 +1,14 @@ -# spring-batch-bigquery += spring-batch-bigquery -Spring Batch extension which contains an `ItemWriter` implementation for https://cloud.google.com/bigquery[BigQuery] based on https://github.com/googleapis/java-bigquery[Java BigQuery]. It supports writing https://en.wikipedia.org/wiki/Comma-separated_values[CSV], https://en.wikipedia.org/wiki/JSON[JSON] using https://cloud.google.com/bigquery/docs/batch-loading-data[load jobs]. +Spring Batch extension which contains an `ItemWriter` implementation for https://cloud.google.com/bigquery[BigQuery] based on https://github.com/googleapis/java-bigquery[Java BigQuery]. +It supports writing https://en.wikipedia.org/wiki/Comma-separated_values[CSV], https://en.wikipedia.org/wiki/JSON[JSON] using https://cloud.google.com/bigquery/docs/batch-loading-data[load jobs]. -## Configuration of `BigQueryCsvItemWriter` +== Configuration of `BigQueryCsvItemWriter` Next to the https://docs.spring.io/spring-batch/reference/html/configureJob.html[configuration of Spring Batch] one needs to configure the `BigQueryCsvItemWriter`. -```javaBigQueryCsv +[source,java] +---- @Bean BigQueryCsvItemWriter bigQueryCsvWriter() { WriteChannelConfiguration writeConfiguration = WriteChannelConfiguration @@ -20,19 +22,19 @@ BigQueryCsvItemWriter bigQueryCsvWriter() { .writeChannelConfig(writeConfiguration) .build(); } -``` +---- Additional examples could be found in https://github.com/spring-projects/spring-batch-extensions/blob/main/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/writer/builder/[here]. -## Configuration properties +== Configuration properties [cols="1,1,4"] -.Properties for item writer +.Properties for an item writer |=== | Property | Required | Description | `bigQuery` | yes | BigQuery object that provided by BigQuery Java Library. Responsible for connection with BigQuery. | `writeChannelConfig` | yes | BigQuery write channel config provided by BigQuery Java Library. Responsible for configuring data type, data channel, jobs that will be sent to BigQuery. -| `rowMapper` | no | Your own converter that specifies how to convert input CSV / JSON to byte array. -| `datasetInfo` | no | Your way to customize to how to create BigQuery dataset. +| `rowMapper` | no | Your own converter that specifies how to convert input CSV / JSON to a byte array. +| `datasetInfo` | no | Your way to customize how to create BigQuery dataset. | `jobConsumer` | no | Your custom handler for BigQuery Job provided by BigQuery Java Library. -|=== +|=== \ No newline at end of file diff --git a/spring-batch-bigquery/pom.xml b/spring-batch-bigquery/pom.xml index a28fabba..247e8ae9 100644 --- a/spring-batch-bigquery/pom.xml +++ b/spring-batch-bigquery/pom.xml @@ -1,6 +1,6 @@ + --> 4.0.0 @@ -51,36 +53,31 @@ 17 - 1.4.14 + 1.5.7 org.springframework.batch spring-batch-core - 5.1.0 + 5.1.2 com.google.cloud google-cloud-bigquery - 2.35.0 + 2.42.0 com.fasterxml.jackson.dataformat jackson-dataformat-csv - 2.16.0 + 2.17.2 org.apache.commons commons-lang3 - 3.14.0 - - - org.apache.commons - commons-collections4 - 4.4 + 3.16.0 @@ -88,13 +85,13 @@ org.junit.jupiter junit-jupiter-api - 5.10.1 + 5.11.0 test org.mockito mockito-core - 5.8.0 + 5.12.0 test @@ -112,7 +109,7 @@ org.slf4j slf4j-api - 2.0.9 + 2.0.16 test @@ -125,7 +122,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.11.0 + 3.13.0 ${java.version} ${java.version} @@ -136,7 +133,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.2.2 + 3.3.1 @@ -149,7 +146,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.6.3 + 3.8.0 attach-javadocs @@ -162,7 +159,7 @@ org.apache.maven.plugins maven-source-plugin - 3.3.0 + 3.3.1 attach-sources @@ -175,4 +172,4 @@ - + \ No newline at end of file diff --git a/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/reader/BigQueryQueryItemReader.java b/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/reader/BigQueryQueryItemReader.java index fb30e14d..84cb9928 100644 --- a/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/reader/BigQueryQueryItemReader.java +++ b/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/reader/BigQueryQueryItemReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,6 @@ import org.springframework.util.Assert; import java.util.Iterator; -import java.util.Objects; /** * BigQuery {@link ItemReader} that accepts simple query as the input. @@ -37,7 +36,7 @@ *

* Also, worth mentioning that you should take into account concurrency limits. *

- * Results of this query by default are stored in a shape of temporary table. + * Results of this query by default are stored in the shape of a temporary table. * * @param your DTO type * @author Volodymyr Perebykivskyi @@ -84,7 +83,7 @@ public void setJobConfiguration(QueryJobConfiguration jobConfiguration) { @Override public T read() throws Exception { - if (Objects.isNull(iterator)) { + if (iterator == null) { doOpen(); } @@ -109,4 +108,4 @@ public void afterPropertiesSet() { Assert.notNull(this.jobConfiguration, "Job configuration must be provided"); } -} +} \ No newline at end of file diff --git a/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/reader/builder/BigQueryQueryItemReaderBuilder.java b/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/reader/builder/BigQueryQueryItemReaderBuilder.java index 811ea3ce..a882ffa3 100644 --- a/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/reader/builder/BigQueryQueryItemReaderBuilder.java +++ b/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/reader/builder/BigQueryQueryItemReaderBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,8 +24,6 @@ import org.springframework.core.convert.converter.Converter; import org.springframework.util.Assert; -import java.util.Objects; - /** * A builder for {@link BigQueryQueryItemReader}. * @@ -70,7 +68,7 @@ public BigQueryQueryItemReaderBuilder query(String query) { } /** - * Row mapper which transforms single BigQuery row into desired type. + * Row mapper which transforms single BigQuery row into a desired type. * * @param rowMapper your row mapper * @return {@link BigQueryQueryItemReaderBuilder} @@ -94,7 +92,7 @@ public BigQueryQueryItemReaderBuilder jobConfiguration(QueryJobConfiguration } /** - * Please do not forget about {@link BigQueryQueryItemReader#afterPropertiesSet()}. + * Please remember about {@link BigQueryQueryItemReader#afterPropertiesSet()}. * * @return {@link BigQueryQueryItemReader} */ @@ -104,14 +102,14 @@ public BigQueryQueryItemReader build() { reader.setBigQuery(this.bigQuery); reader.setRowMapper(this.rowMapper); - if (Objects.nonNull(this.jobConfiguration)) { - reader.setJobConfiguration(this.jobConfiguration); - } else { + if (this.jobConfiguration == null) { Assert.isTrue(StringUtils.isNotBlank(this.query), "No query provided"); reader.setJobConfiguration(QueryJobConfiguration.newBuilder(this.query).build()); + } else { + reader.setJobConfiguration(this.jobConfiguration); } return reader; } -} +} \ No newline at end of file diff --git a/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/BigQueryBaseItemWriter.java b/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/BigQueryBaseItemWriter.java index 9d721c18..07bd6087 100644 --- a/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/BigQueryBaseItemWriter.java +++ b/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/BigQueryBaseItemWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,6 +54,7 @@ public abstract class BigQueryBaseItemWriter implements ItemWriter { /** Logger that can be reused */ protected final Log logger = LogFactory.getLog(getClass()); + private final AtomicLong bigQueryWriteCounter = new AtomicLong(); /** @@ -77,7 +78,7 @@ public abstract class BigQueryBaseItemWriter implements ItemWriter { /** - * Fetches table from provided configuration. + * Fetches table from the provided configuration. * * @return {@link Table} that is described in {@link BigQueryBaseItemWriter#writeChannelConfig} */ @@ -123,7 +124,7 @@ public void setBigQuery(BigQuery bigQuery) { @Override public void write(Chunk chunk) throws Exception { - if (BooleanUtils.isFalse(chunk.isEmpty())) { + if (!chunk.isEmpty()) { List items = chunk.getItems(); doInitializeProperties(items); @@ -147,8 +148,8 @@ private ByteBuffer mapDataToBigQueryFormat(List items) throws IOExc } /* - * It is extremely important to create larger ByteBuffer, - * if you call TableDataWriteChannel too many times, it leads to BigQuery exceptions. + * It is extremely important to create larger ByteBuffer. + * If you call TableDataWriteChannel too many times, it leads to BigQuery exceptions. */ byteBuffer = ByteBuffer.wrap(outputStream.toByteArray()); } @@ -170,9 +171,9 @@ private void doWriteDataToBigQuery(ByteBuffer byteBuffer) throws IOException { finally { String logMessage = "Write operation submitted: " + bigQueryWriteCounter.incrementAndGet(); - if (Objects.nonNull(writeChannel)) { + if (writeChannel != null) { logMessage += " -- Job ID: " + writeChannel.getJob().getJobId().getJob(); - if (Objects.nonNull(this.jobConsumer)) { + if (this.jobConsumer != null) { this.jobConsumer.accept(writeChannel.getJob()); } } @@ -212,7 +213,7 @@ protected void baseAfterPropertiesSet(Supplier formatSpecificChecks) { Assert.notNull(this.writeChannelConfig.getFormat(), "Data format must be provided"); String dataset = this.writeChannelConfig.getDestinationTable().getDataset(); - if (Objects.isNull(this.datasetInfo)) { + if (this.datasetInfo == null) { this.datasetInfo = DatasetInfo.newBuilder(dataset).build(); } @@ -228,13 +229,11 @@ private void createDataset() { TableId tableId = this.writeChannelConfig.getDestinationTable(); String datasetToCheck = tableId.getDataset(); - if (Objects.nonNull(datasetToCheck)) { + if (datasetToCheck != null) { Dataset foundDataset = this.bigQuery.getDataset(datasetToCheck); - if (Objects.isNull(foundDataset)) { - if (Objects.nonNull(this.datasetInfo)) { - this.bigQuery.create(this.datasetInfo); - } + if (foundDataset == null && this.datasetInfo != null) { + this.bigQuery.create(this.datasetInfo); } } } @@ -264,7 +263,7 @@ private boolean isDatastore() { } /** - * Schema can be computed on BigQuery side during upload, + * Schema can be computed on the BigQuery side during upload, * so it is good to know when schema is supplied by user manually. * * @param table BigQuery table @@ -287,7 +286,7 @@ protected boolean tableHasDefinedSchema(Table table) { protected abstract void doInitializeProperties(List items); /** - * Converts chunk into byte array. + * Converts chunk into a byte array. * Each data type should be converted with respect to its specification. * * @param items current chunk @@ -295,4 +294,4 @@ protected boolean tableHasDefinedSchema(Table table) { */ protected abstract List convertObjectsToByteArrays(List items); -} +} \ No newline at end of file diff --git a/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/BigQueryCsvItemWriter.java b/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/BigQueryCsvItemWriter.java index d3efb45a..98798d70 100644 --- a/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/BigQueryCsvItemWriter.java +++ b/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/BigQueryCsvItemWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import com.fasterxml.jackson.dataformat.csv.CsvMapper; import com.google.cloud.bigquery.Table; import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.BooleanUtils; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.convert.converter.Converter; import org.springframework.util.Assert; @@ -31,7 +30,6 @@ import java.util.List; import java.util.Objects; import java.util.function.Predicate; -import java.util.stream.Collectors; /** * CSV writer for BigQuery. @@ -45,18 +43,21 @@ public class BigQueryCsvItemWriter extends BigQueryBaseItemWriter implemen private Converter rowMapper; private ObjectWriter objectWriter; - private Class itemClass; + private Class itemClass; /** * Actual type of incoming data can be obtained only in runtime */ @Override protected synchronized void doInitializeProperties(List items) { - if (Objects.isNull(this.itemClass)) { - T firstItem = items.stream().findFirst().orElseThrow(RuntimeException::new); + if (this.itemClass == null) { + T firstItem = items.stream().findFirst().orElseThrow(() -> { + logger.warn("Class type was not found"); + return new IllegalStateException("Class type was not found"); + }); this.itemClass = firstItem.getClass(); - if (Objects.isNull(this.rowMapper)) { + if (this.rowMapper == null) { this.objectWriter = new CsvMapper().writerWithTypedSchemaFor(this.itemClass); } @@ -65,7 +66,7 @@ protected synchronized void doInitializeProperties(List items) { } /** - * Row mapper which transforms single BigQuery row into desired type. + * Row mapper which transforms single BigQuery row into a desired type. * * @param rowMapper your row mapper */ @@ -83,7 +84,7 @@ protected List convertObjectsToByteArrays(List items) { .map(String::new) .filter(Predicate.not(ObjectUtils::isEmpty)) .map(row -> row.getBytes(StandardCharsets.UTF_8)) - .collect(Collectors.toList()); + .toList(); } @Override @@ -91,16 +92,16 @@ public void afterPropertiesSet() { super.baseAfterPropertiesSet(() -> { Table table = getTable(); - if (BooleanUtils.toBoolean(super.writeChannelConfig.getAutodetect())) { - if ((tableHasDefinedSchema(table) && super.logger.isWarnEnabled())) { - super.logger.warn("Mixing autodetect mode with already defined schema may lead to errors on BigQuery side"); + if (Boolean.TRUE.equals(super.writeChannelConfig.getAutodetect())) { + if (tableHasDefinedSchema(table) && super.logger.isWarnEnabled()) { + logger.warn("Mixing autodetect mode with already defined schema may lead to errors on BigQuery side"); } } else { Assert.notNull(super.writeChannelConfig.getSchema(), "Schema must be provided"); if (tableHasDefinedSchema(table)) { Assert.isTrue( - table.getDefinition().getSchema().equals(super.writeChannelConfig.getSchema()), + Objects.equals(table.getDefinition().getSchema(), super.writeChannelConfig.getSchema()), "Schema should be the same" ); } @@ -112,7 +113,7 @@ public void afterPropertiesSet() { private byte[] mapItemToCsv(T t) { try { - return Objects.isNull(rowMapper) ? objectWriter.writeValueAsBytes(t) : rowMapper.convert(t); + return rowMapper == null ? objectWriter.writeValueAsBytes(t) : rowMapper.convert(t); } catch (JsonProcessingException e) { logger.error("Error during processing of the line: ", e); @@ -120,4 +121,4 @@ private byte[] mapItemToCsv(T t) { } } -} +} \ No newline at end of file diff --git a/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/BigQueryJsonItemWriter.java b/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/BigQueryJsonItemWriter.java index 34a773f1..c159cf16 100644 --- a/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/BigQueryJsonItemWriter.java +++ b/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/BigQueryJsonItemWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import com.fasterxml.jackson.databind.ObjectWriter; import com.google.cloud.bigquery.Table; import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.BooleanUtils; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.convert.converter.Converter; import org.springframework.util.Assert; @@ -31,7 +30,6 @@ import java.util.List; import java.util.Objects; import java.util.function.Predicate; -import java.util.stream.Collectors; /** * JSON writer for BigQuery. @@ -45,24 +43,27 @@ public class BigQueryJsonItemWriter extends BigQueryBaseItemWriter impleme private Converter rowMapper; private ObjectWriter objectWriter; - private Class itemClass; + private Class itemClass; @Override protected void doInitializeProperties(List items) { - if (Objects.isNull(this.itemClass)) { - T firstItem = items.stream().findFirst().orElseThrow(RuntimeException::new); + if (this.itemClass == null) { + T firstItem = items.stream().findFirst().orElseThrow(() -> { + logger.warn("Class type was not found"); + return new IllegalStateException("Class type was not found"); + }); this.itemClass = firstItem.getClass(); - if (Objects.isNull(this.rowMapper)) { + if (this.rowMapper == null) { this.objectWriter = new ObjectMapper().writerFor(this.itemClass); } - super.logger.debug("Writer setup is completed"); + logger.debug("Writer setup is completed"); } } /** - * Converter that transforms a single row into byte array. + * Converter that transforms a single row into a byte array. * * @param rowMapper your JSON row mapper */ @@ -80,7 +81,7 @@ protected List convertObjectsToByteArrays(List items) { .map(this::convertToNdJson) .filter(Predicate.not(ObjectUtils::isEmpty)) .map(row -> row.getBytes(StandardCharsets.UTF_8)) - .collect(Collectors.toList()); + .toList(); } @Override @@ -88,16 +89,16 @@ public void afterPropertiesSet() { super.baseAfterPropertiesSet(() -> { Table table = getTable(); - if (BooleanUtils.toBoolean(super.writeChannelConfig.getAutodetect())) { - if ((tableHasDefinedSchema(table) && super.logger.isWarnEnabled())) { - super.logger.warn("Mixing autodetect mode with already defined schema may lead to errors on BigQuery side"); + if (Boolean.TRUE.equals(writeChannelConfig.getAutodetect())) { + if (tableHasDefinedSchema(table) && super.logger.isWarnEnabled()) { + logger.warn("Mixing autodetect mode with already defined schema may lead to errors on BigQuery side"); } } else { - Assert.notNull(super.writeChannelConfig.getSchema(), "Schema must be provided"); + Assert.notNull(writeChannelConfig.getSchema(), "Schema must be provided"); if (tableHasDefinedSchema(table)) { Assert.isTrue( - table.getDefinition().getSchema().equals(super.writeChannelConfig.getSchema()), + Objects.equals(table.getDefinition().getSchema(), writeChannelConfig.getSchema()), "Schema should be the same" ); } @@ -126,4 +127,4 @@ private String convertToNdJson(String json) { return json.concat(org.apache.commons.lang3.StringUtils.LF); } -} +} \ No newline at end of file diff --git a/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/builder/BigQueryCsvItemWriterBuilder.java b/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/builder/BigQueryCsvItemWriterBuilder.java index 81e9c64a..73dbae3a 100644 --- a/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/builder/BigQueryCsvItemWriterBuilder.java +++ b/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/builder/BigQueryCsvItemWriterBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -103,7 +103,7 @@ public BigQueryCsvItemWriterBuilder bigQuery(BigQuery bigQuery) { } /** - * Please do not forget about {@link BigQueryCsvItemWriter#afterPropertiesSet()}. + * Please remember about {@link BigQueryCsvItemWriter#afterPropertiesSet()}. * * @return {@link BigQueryCsvItemWriter} */ @@ -119,4 +119,4 @@ public BigQueryCsvItemWriter build() { return writer; } -} +} \ No newline at end of file diff --git a/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/builder/BigQueryJsonItemWriterBuilder.java b/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/builder/BigQueryJsonItemWriterBuilder.java index 0fdfa51b..09e4578f 100644 --- a/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/builder/BigQueryJsonItemWriterBuilder.java +++ b/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/builder/BigQueryJsonItemWriterBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,7 +43,7 @@ public class BigQueryJsonItemWriterBuilder { private BigQuery bigQuery; /** - * Converts your DTO into byte array. + * Converts your DTO into a byte array. * * @param rowMapper your mapping * @return {@link BigQueryJsonItemWriter} @@ -103,7 +103,7 @@ public BigQueryJsonItemWriterBuilder bigQuery(BigQuery bigQuery) { } /** - * Please do not forget about {@link BigQueryJsonItemWriter#afterPropertiesSet()}. + * Please remember about {@link BigQueryJsonItemWriter#afterPropertiesSet()}. * * @return {@link BigQueryJsonItemWriter} */ @@ -119,4 +119,4 @@ public BigQueryJsonItemWriter build() { return writer; } -} +} \ No newline at end of file diff --git a/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/package-info.java b/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/package-info.java index e5c61f71..69aa0eeb 100644 --- a/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/package-info.java +++ b/spring-batch-bigquery/src/main/java/org/springframework/batch/extensions/bigquery/writer/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ /** * Google BigQuery related functionality. *

- * These writers use java client from Google, so we cannot control this flow fully. + * These writers use a Java client from Google, so we cannot control this flow fully. * Take into account that this writer produces {@link com.google.cloud.bigquery.JobConfiguration.Type#LOAD} {@link com.google.cloud.bigquery.Job}. * *

Supported formats: @@ -43,4 +43,4 @@ @NonNullApi package org.springframework.batch.extensions.bigquery.writer; -import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullApi; \ No newline at end of file diff --git a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/common/BigQueryDataLoader.java b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/common/BigQueryDataLoader.java index 6a3dcaf1..485c3960 100644 --- a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/common/BigQueryDataLoader.java +++ b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/common/BigQueryDataLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -90,4 +90,4 @@ public void loadJsonSample(String tableName) throws Exception { job.get().waitFor(); } -} +} \ No newline at end of file diff --git a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/common/PersonDto.java b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/common/PersonDto.java index 2d776e31..fbc3484b 100644 --- a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/common/PersonDto.java +++ b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/common/PersonDto.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,4 +30,4 @@ public static Schema getBigQuerySchema() { return Schema.of(nameField, ageField); } -} +} \ No newline at end of file diff --git a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/common/TestConstants.java b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/common/TestConstants.java index 2835245c..dc931c1f 100644 --- a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/common/TestConstants.java +++ b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/common/TestConstants.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,4 +31,4 @@ private TestConstants() {} res.get(NAME).getStringValue(), Long.valueOf(res.get(AGE).getLongValue()).intValue() ); -} +} \ No newline at end of file diff --git a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/base/BaseBigQueryIntegrationTest.java b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/base/BaseBigQueryIntegrationTest.java index 0a8ce8c0..e2f6c2f2 100644 --- a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/base/BaseBigQueryIntegrationTest.java +++ b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/base/BaseBigQueryIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,8 +31,8 @@ public abstract class BaseBigQueryIntegrationTest { protected String getTableName(TestInfo testInfo) { return String.format( TABLE_PATTERN, - testInfo.getTags().stream().findFirst().orElseThrow(), + testInfo.getTags().iterator().next(), testInfo.getTestMethod().map(Method::getName).orElseThrow() ); } -} +} \ No newline at end of file diff --git a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/package-info.java b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/package-info.java index aae6410d..e5aced08 100644 --- a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/package-info.java +++ b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ */ /** - * In order to launch these tests you should provide a way how to authorize to Google BigQuery. - * A simple way is to create service account, store credentials as JSON file and provide environment variable. - * Example: GOOGLE_APPLICATION_CREDENTIALS=/home/dgray/Downloads/bq-key.json + * To launch these tests, you should provide a way how to authorize to Google BigQuery. + * A simple way is to create a service account, store credentials as JSON file and provide environment variable. + * Example: GOOGLE_APPLICATION_CREDENTIALS=/home/user/Downloads/bq-key.json *

* Test names should follow this pattern: test1, test2, testN. * So later in BigQuery you will see generated table name: csv_test1, csv_test2, csv_testN. - * This way it will be easier to trace errors in BigQuery. + * This way, it will be easier to trace errors in BigQuery. * * @see Authentication */ diff --git a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/reader/base/BaseCsvJsonInteractiveQueryItemReaderTest.java b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/reader/base/BaseCsvJsonInteractiveQueryItemReaderTest.java index 97657ede..27035cbc 100644 --- a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/reader/base/BaseCsvJsonInteractiveQueryItemReaderTest.java +++ b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/reader/base/BaseCsvJsonInteractiveQueryItemReaderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,19 +28,17 @@ import org.springframework.batch.extensions.bigquery.common.TestConstants; import org.springframework.batch.extensions.bigquery.integration.base.BaseBigQueryIntegrationTest; -import java.util.Objects; - public abstract class BaseCsvJsonInteractiveQueryItemReaderTest extends BaseBigQueryIntegrationTest { @BeforeEach void prepareTest(TestInfo testInfo) { - if (Objects.isNull(bigQuery.getDataset(TestConstants.DATASET))) { + if (bigQuery.getDataset(TestConstants.DATASET) == null) { bigQuery.create(DatasetInfo.of(TestConstants.DATASET)); } String tableName = getTableName(testInfo); - if (Objects.isNull(bigQuery.getTable(TestConstants.DATASET, tableName))) { + if (bigQuery.getTable(TestConstants.DATASET, tableName) == null) { TableDefinition tableDefinition = StandardTableDefinition.of(PersonDto.getBigQuerySchema()); bigQuery.create(TableInfo.of(TableId.of(TestConstants.DATASET, tableName), tableDefinition)); } @@ -51,4 +49,4 @@ void cleanupTest(TestInfo testInfo) { bigQuery.delete(TableId.of(TestConstants.DATASET, getTableName(testInfo))); } -} +} \ No newline at end of file diff --git a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/reader/batch/BigQueryBatchQueryCsvItemReaderTest.java b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/reader/batch/BigQueryBatchQueryCsvItemReaderTest.java index 8d39e58f..7cfef0e5 100644 --- a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/reader/batch/BigQueryBatchQueryCsvItemReaderTest.java +++ b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/reader/batch/BigQueryBatchQueryCsvItemReaderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ import com.google.cloud.bigquery.QueryJobConfiguration; import com.google.cloud.bigquery.TableId; -import org.apache.commons.lang3.math.NumberUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -32,7 +31,7 @@ import org.springframework.batch.item.Chunk; @Tag("csv") -public class BigQueryBatchQueryCsvItemReaderTest extends BaseCsvJsonInteractiveQueryItemReaderTest { +class BigQueryBatchQueryCsvItemReaderTest extends BaseCsvJsonInteractiveQueryItemReaderTest { @Test void batchQueryTest1(TestInfo testInfo) throws Exception { @@ -64,13 +63,13 @@ void batchQueryTest1(TestInfo testInfo) throws Exception { Assertions.assertNotNull(actualFirstPerson); Assertions.assertEquals(expectedFirstPerson.name(), actualFirstPerson.name()); - Assertions.assertEquals(expectedFirstPerson.age().compareTo(actualFirstPerson.age()), NumberUtils.INTEGER_ZERO); + Assertions.assertEquals(0, expectedFirstPerson.age().compareTo(actualFirstPerson.age())); Assertions.assertNotNull(actualSecondPerson); Assertions.assertEquals(expectedSecondPerson.name(), actualSecondPerson.name()); - Assertions.assertEquals(expectedSecondPerson.age().compareTo(actualSecondPerson.age()), NumberUtils.INTEGER_ZERO); + Assertions.assertEquals(0, expectedSecondPerson.age().compareTo(actualSecondPerson.age())); Assertions.assertNull(actualThirdPerson); } -} +} \ No newline at end of file diff --git a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/reader/batch/BigQueryBatchQueryJsonItemReaderTest.java b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/reader/batch/BigQueryBatchQueryJsonItemReaderTest.java index 5c269037..285816d2 100644 --- a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/reader/batch/BigQueryBatchQueryJsonItemReaderTest.java +++ b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/reader/batch/BigQueryBatchQueryJsonItemReaderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ import com.google.cloud.bigquery.QueryJobConfiguration; import com.google.cloud.bigquery.TableId; -import org.apache.commons.lang3.math.NumberUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -32,7 +31,7 @@ import org.springframework.batch.item.Chunk; @Tag("json") -public class BigQueryBatchQueryJsonItemReaderTest extends BaseCsvJsonInteractiveQueryItemReaderTest { +class BigQueryBatchQueryJsonItemReaderTest extends BaseCsvJsonInteractiveQueryItemReaderTest { @Test void batchQueryTest1(TestInfo testInfo) throws Exception { @@ -64,13 +63,13 @@ void batchQueryTest1(TestInfo testInfo) throws Exception { Assertions.assertNotNull(actualFirstPerson); Assertions.assertEquals(expectedFirstPerson.name(), actualFirstPerson.name()); - Assertions.assertEquals(expectedFirstPerson.age().compareTo(actualFirstPerson.age()), NumberUtils.INTEGER_ZERO); + Assertions.assertEquals(0, expectedFirstPerson.age().compareTo(actualFirstPerson.age())); Assertions.assertNotNull(actualSecondPerson); Assertions.assertEquals(expectedSecondPerson.name(), actualSecondPerson.name()); - Assertions.assertEquals(expectedSecondPerson.age().compareTo(actualSecondPerson.age()), NumberUtils.INTEGER_ZERO); + Assertions.assertEquals(0, expectedSecondPerson.age().compareTo(actualSecondPerson.age())); Assertions.assertNull(actualThirdPerson); } -} +} \ No newline at end of file diff --git a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/reader/interactive/BigQueryInteractiveQueryCsvItemReaderTest.java b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/reader/interactive/BigQueryInteractiveQueryCsvItemReaderTest.java index ef9c3fe6..63aeed8a 100644 --- a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/reader/interactive/BigQueryInteractiveQueryCsvItemReaderTest.java +++ b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/reader/interactive/BigQueryInteractiveQueryCsvItemReaderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package org.springframework.batch.extensions.bigquery.integration.reader.interactive; -import org.apache.commons.lang3.math.NumberUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -30,7 +29,7 @@ import org.springframework.batch.item.Chunk; @Tag("csv") -public class BigQueryInteractiveQueryCsvItemReaderTest extends BaseCsvJsonInteractiveQueryItemReaderTest { +class BigQueryInteractiveQueryCsvItemReaderTest extends BaseCsvJsonInteractiveQueryItemReaderTest { @Test void interactiveQueryTest1(TestInfo testInfo) throws Exception { @@ -56,13 +55,13 @@ void interactiveQueryTest1(TestInfo testInfo) throws Exception { Assertions.assertNotNull(actualFirstPerson); Assertions.assertEquals(expectedFirstPerson.name(), actualFirstPerson.name()); - Assertions.assertEquals(expectedFirstPerson.age().compareTo(actualFirstPerson.age()), NumberUtils.INTEGER_ZERO); + Assertions.assertEquals(0, expectedFirstPerson.age().compareTo(actualFirstPerson.age())); Assertions.assertNotNull(actualSecondPerson); Assertions.assertEquals(expectedSecondPerson.name(), actualSecondPerson.name()); - Assertions.assertEquals(expectedSecondPerson.age().compareTo(actualSecondPerson.age()), NumberUtils.INTEGER_ZERO); + Assertions.assertEquals(0, expectedSecondPerson.age().compareTo(actualSecondPerson.age())); Assertions.assertNull(actualThirdPerson); } -} +} \ No newline at end of file diff --git a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/reader/interactive/BigQueryInteractiveQueryJsonItemReaderTest.java b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/reader/interactive/BigQueryInteractiveQueryJsonItemReaderTest.java index ba5f6140..ddf7d915 100644 --- a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/reader/interactive/BigQueryInteractiveQueryJsonItemReaderTest.java +++ b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/reader/interactive/BigQueryInteractiveQueryJsonItemReaderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package org.springframework.batch.extensions.bigquery.integration.reader.interactive; -import org.apache.commons.lang3.math.NumberUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -30,7 +29,7 @@ import org.springframework.batch.item.Chunk; @Tag("json") -public class BigQueryInteractiveQueryJsonItemReaderTest extends BaseCsvJsonInteractiveQueryItemReaderTest { +class BigQueryInteractiveQueryJsonItemReaderTest extends BaseCsvJsonInteractiveQueryItemReaderTest { @Test void interactiveQueryTest1(TestInfo testInfo) throws Exception { @@ -56,13 +55,13 @@ void interactiveQueryTest1(TestInfo testInfo) throws Exception { Assertions.assertNotNull(actualFirstPerson); Assertions.assertEquals(expectedFirstPerson.name(), actualFirstPerson.name()); - Assertions.assertEquals(expectedFirstPerson.age().compareTo(actualFirstPerson.age()), NumberUtils.INTEGER_ZERO); + Assertions.assertEquals(0, expectedFirstPerson.age().compareTo(actualFirstPerson.age())); Assertions.assertNotNull(actualSecondPerson); Assertions.assertEquals(expectedSecondPerson.name(), actualSecondPerson.name()); - Assertions.assertEquals(expectedSecondPerson.age().compareTo(actualSecondPerson.age()), NumberUtils.INTEGER_ZERO); + Assertions.assertEquals(0, expectedSecondPerson.age().compareTo(actualSecondPerson.age())); Assertions.assertNull(actualThirdPerson); } -} +} \ No newline at end of file diff --git a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/writer/BigQueryCsvItemWriterTest.java b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/writer/BigQueryCsvItemWriterTest.java index 1819b2be..11c3f096 100644 --- a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/writer/BigQueryCsvItemWriterTest.java +++ b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/writer/BigQueryCsvItemWriterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import com.google.cloud.bigquery.Table; import com.google.cloud.bigquery.TableId; import com.google.cloud.bigquery.TableResult; -import org.apache.commons.lang3.math.NumberUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -33,7 +32,7 @@ import org.springframework.batch.item.Chunk; @Tag("csv") -public class BigQueryCsvItemWriterTest extends BaseBigQueryItemWriterTest { +class BigQueryCsvItemWriterTest extends BaseBigQueryItemWriterTest { @Test void test1(TestInfo testInfo) throws Exception { @@ -54,7 +53,7 @@ void test1(TestInfo testInfo) throws Exception { .getValues() .forEach(field -> { Assertions.assertTrue( - chunk.getItems().stream().map(PersonDto::name).anyMatch(name -> field.get(NumberUtils.INTEGER_ZERO).getStringValue().equals(name)) + chunk.getItems().stream().map(PersonDto::name).anyMatch(name -> field.get(0).getStringValue().equals(name)) ); boolean ageCondition = chunk @@ -62,10 +61,10 @@ void test1(TestInfo testInfo) throws Exception { .stream() .map(PersonDto::age) .map(Long::valueOf) - .anyMatch(age -> age.compareTo(field.get(NumberUtils.INTEGER_ONE).getLongValue()) == NumberUtils.INTEGER_ZERO); + .anyMatch(age -> age.compareTo(field.get(1).getLongValue()) == 0); Assertions.assertTrue(ageCondition); }); } -} +} \ No newline at end of file diff --git a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/writer/BigQueryJsonItemWriterTest.java b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/writer/BigQueryJsonItemWriterTest.java index ed577c48..70e16bbc 100644 --- a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/writer/BigQueryJsonItemWriterTest.java +++ b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/writer/BigQueryJsonItemWriterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import com.google.cloud.bigquery.Table; import com.google.cloud.bigquery.TableId; import com.google.cloud.bigquery.TableResult; -import org.apache.commons.lang3.math.NumberUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -33,7 +32,7 @@ import org.springframework.batch.item.Chunk; @Tag("json") -public class BigQueryJsonItemWriterTest extends BaseBigQueryItemWriterTest { +class BigQueryJsonItemWriterTest extends BaseBigQueryItemWriterTest { @Test void test1(TestInfo testInfo) throws Exception { @@ -54,7 +53,7 @@ void test1(TestInfo testInfo) throws Exception { .getValues() .forEach(field -> { Assertions.assertTrue( - chunk.getItems().stream().map(PersonDto::name).anyMatch(name -> field.get(NumberUtils.INTEGER_ZERO).getStringValue().equals(name)) + chunk.getItems().stream().map(PersonDto::name).anyMatch(name -> field.get(0).getStringValue().equals(name)) ); boolean ageCondition = chunk @@ -62,10 +61,10 @@ void test1(TestInfo testInfo) throws Exception { .stream() .map(PersonDto::age) .map(Long::valueOf) - .anyMatch(age -> age.compareTo(field.get(NumberUtils.INTEGER_ONE).getLongValue()) == NumberUtils.INTEGER_ZERO); + .anyMatch(age -> age.compareTo(field.get(1).getLongValue()) == 0); Assertions.assertTrue(ageCondition); }); } -} +} \ No newline at end of file diff --git a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/writer/base/BaseBigQueryItemWriterTest.java b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/writer/base/BaseBigQueryItemWriterTest.java index 4b24f8ec..402b713c 100644 --- a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/writer/base/BaseBigQueryItemWriterTest.java +++ b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/integration/writer/base/BaseBigQueryItemWriterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,17 +28,15 @@ import org.springframework.batch.extensions.bigquery.common.TestConstants; import org.springframework.batch.extensions.bigquery.integration.base.BaseBigQueryIntegrationTest; -import java.util.Objects; - public abstract class BaseBigQueryItemWriterTest extends BaseBigQueryIntegrationTest { @BeforeEach void prepareTest(TestInfo testInfo) { - if (Objects.isNull(bigQuery.getDataset(TestConstants.DATASET))) { + if (bigQuery.getDataset(TestConstants.DATASET) == null) { bigQuery.create(DatasetInfo.of(TestConstants.DATASET)); } - if (Objects.isNull(bigQuery.getTable(TestConstants.DATASET, getTableName(testInfo)))) { + if (bigQuery.getTable(TestConstants.DATASET, getTableName(testInfo)) == null) { TableDefinition tableDefinition = StandardTableDefinition.of(PersonDto.getBigQuerySchema()); bigQuery.create(TableInfo.of(TableId.of(TestConstants.DATASET, getTableName(testInfo)), tableDefinition)); } @@ -49,4 +47,4 @@ void cleanupTest(TestInfo testInfo) { bigQuery.delete(TableId.of(TestConstants.DATASET, getTableName(testInfo))); } -} +} \ No newline at end of file diff --git a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/unit/base/AbstractBigQueryTest.java b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/unit/base/AbstractBigQueryTest.java index 018a5356..e91fcdd5 100644 --- a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/unit/base/AbstractBigQueryTest.java +++ b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/unit/base/AbstractBigQueryTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,4 +35,4 @@ protected BigQuery prepareMockedBigQuery() { return mockedBigQuery; } -} +} \ No newline at end of file diff --git a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/unit/reader/builder/BigQueryBatchQueryItemReaderBuilderTests.java b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/unit/reader/builder/BigQueryBatchQueryItemReaderBuilderTests.java index b8a6a35e..ec9b9567 100644 --- a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/unit/reader/builder/BigQueryBatchQueryItemReaderBuilderTests.java +++ b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/unit/reader/builder/BigQueryBatchQueryItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,4 +50,4 @@ void testCustomQueryItemReader() { Assertions.assertNotNull(reader); } -} +} \ No newline at end of file diff --git a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/unit/reader/builder/BigQueryInteractiveQueryItemReaderBuilderTests.java b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/unit/reader/builder/BigQueryInteractiveQueryItemReaderBuilderTests.java index a003c5e5..3ff4caf0 100644 --- a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/unit/reader/builder/BigQueryInteractiveQueryItemReaderBuilderTests.java +++ b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/unit/reader/builder/BigQueryInteractiveQueryItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -64,4 +64,4 @@ void testCustomQueryItemReader() { Assertions.assertNotNull(reader); } -} +} \ No newline at end of file diff --git a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/unit/writer/builder/BigQueryCsvItemWriterBuilderTests.java b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/unit/writer/builder/BigQueryCsvItemWriterBuilderTests.java index 9b18b993..19b59511 100644 --- a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/unit/writer/builder/BigQueryCsvItemWriterBuilderTests.java +++ b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/unit/writer/builder/BigQueryCsvItemWriterBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -96,4 +96,4 @@ private byte[] convertDtoToCsvByteArray(CsvMapper csvMapper, PersonDto dto) { } } -} +} \ No newline at end of file diff --git a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/unit/writer/builder/BigQueryJsonItemWriterBuilderTests.java b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/unit/writer/builder/BigQueryJsonItemWriterBuilderTests.java index 0eb463e4..90973a96 100644 --- a/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/unit/writer/builder/BigQueryJsonItemWriterBuilderTests.java +++ b/spring-batch-bigquery/src/test/java/org/springframework/batch/extensions/bigquery/unit/writer/builder/BigQueryJsonItemWriterBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -97,4 +97,4 @@ private byte[] convertDtoToJsonByteArray(ObjectMapper objectMapper, PersonDto dt } } -} +} \ No newline at end of file