csv-comparator

Utils for comparison and assertion CSV files in Java

Лицензия

Лицензия

MIT
Категории

Категории

H2 Данные Базы данных CSV Data Formats
Группа

Группа

com.github.ngoanh2n
Идентификатор

Идентификатор

csv-comparator
Последняя версия

Последняя версия

1.2.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

csv-comparator
Utils for comparison and assertion CSV files in Java
Ссылка на сайт

Ссылка на сайт

https://github.com/ngoanh2n/csv-comparator
Система контроля версий

Система контроля версий

http://github.com/ngoanh2n/csv-comparator/tree/master

Скачать csv-comparator

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.github.ngoanh2n/csv-comparator/ -->
<dependency>
    <groupId>com.github.ngoanh2n</groupId>
    <artifactId>csv-comparator</artifactId>
    <version>1.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.ngoanh2n/csv-comparator/
implementation 'com.github.ngoanh2n:csv-comparator:1.2.0'
// https://jarcasting.com/artifacts/com.github.ngoanh2n/csv-comparator/
implementation ("com.github.ngoanh2n:csv-comparator:1.2.0")
'com.github.ngoanh2n:csv-comparator:jar:1.2.0'
<dependency org="com.github.ngoanh2n" name="csv-comparator" rev="1.2.0">
  <artifact name="csv-comparator" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.ngoanh2n', module='csv-comparator', version='1.2.0')
)
libraryDependencies += "com.github.ngoanh2n" % "csv-comparator" % "1.2.0"
[com.github.ngoanh2n/csv-comparator "1.2.0"]

Зависимости

runtime (4)

Идентификатор библиотеки Тип Версия
org.slf4j : slf4j-api jar 1.7.30
com.google.guava : guava jar 28.2-jre
com.univocity : univocity-parsers jar 2.8.4
com.github.albfernandez : juniversalchardet jar 2.3.2

test (3)

Идентификатор библиотеки Тип Версия
org.slf4j : slf4j-log4j12 jar 1.7.30
org.junit.jupiter : junit-jupiter-api jar 5.7.0
org.junit.jupiter : junit-jupiter-engine jar 5.7.0

Модули Проекта

Данный проект не имеет модулей.

GitHub stars GitHub watchers GitHub forks

Maven Central GitHub release javadoc Build Status License: MIT badge-jdk GitHub contributors GitHub issues GitHub issues-closed GitHub pull-requests GitHub pull-requests closed

CSV Comparator

Table of Contents generated with DocToc

How To Use

Gradle Project

Add the csv-comparator dependency to your build.gradle

dependencies {
    testImplementation("com.github.ngoanh2n:csv-comparator:1.2.0")
}

Maven Project

Add the csv-comparator dependency to your pom

<dependencies>
    [...]
    <dependency>
        <groupId>com.github.ngoanh2n</groupId>
        <artifactId>csv-comparator</artifactId>
        <version>1.2.0</version>
        <scope>test</scope>
    </dependency>
    [...]
</dependencies>

How To Apply

Compare 2 CSV files formatted columns:

id,email,firstname,lastname,age,note

Provide CsvComparisonSource

CsvComparisonSource<File> source = CsvComparisonSource.create(expectedCsv, actualCsv);

Build CsvComparisonOptions

CsvComparisonOptions options = CsvComparisonOptions
                .builder()
                .setColumns(1, 2, 3)
                .setIdentityColumn(0) // position starts with 0 in array [1, 2, 3]
                .build();

If you want to use column names:

CsvComparisonOptions options = CsvComparisonOptions
                .builder()
                .setColumns("email", "firstname", "lastname")
                .setIdentityColumn("email")
                .build();

Do CsvComparator

CsvComparisonResult result = new CsvComparator(source, options).compare();

Asssert CsvComparisonResult

CsvComparisonResult.hasDiff()
CsvComparisonResult.hasDeleted()
CsvComparisonResult.hasInserted()
CsvComparisonResult.hasModified()
CsvComparisonResult.rowsKept()
CsvComparisonResult.rowsDeleted()
CsvComparisonResult.rowsInserted()
CsvComparisonResult.rowsModified()

By default, result files which is created after comparing is located at build/comparator/csv/{yyyyMMdd.HHmmss.SSS}/

Use CsvComparisonVisitor To Walk Through CsvComparator

CsvComparisonVisitor.visitStarted(CsvComparisonSource<?> source)
CsvComparisonVisitor.visitEnded(CsvComparisonSource<?> source)
CsvComparisonVisitor.rowKept(String[] row, String[] headers, CsvComparisonOptions options)
CsvComparisonVisitor.rowDeleted(String[] row, String[] headers, CsvComparisonOptions options)
CsvComparisonVisitor.rowInserted(String[] row, String[] headers, CsvComparisonOptions options)
CsvComparisonVisitor.rowModified(String[] row, String[] headers, CsvComparisonOptions options)
CsvComparisonResult result = new CsvComparator(source, options, visitor).compare();

Версии библиотеки

Версия
1.2.0
1.1.0
1.0.0
v1.0.0