Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate data from Avro schemas that could be used for data validation #24

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
13 changes: 13 additions & 0 deletions .checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">

<suppressions>
<!-- Note that [/\\] must be used as the path separator for cross-platform support -->

<!-- Generated classes which we do not edit -->
<suppress checks=".*"
files="io[/\\]skodjob[/\\]datagenerator[/\\]models[/\\].*\.java"/>
</suppressions>
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ target/

### Mac OS ###
**.DS_Store

# Generated Avro models that should be excluded
src/main/java/io/skodjob/datagenerator/models/*
6 changes: 6 additions & 0 deletions .spotbugs/spotbugs-exclude.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
<Match>
<Class name="~io\.skodjob\.datagenerator\.models\..+(\$.*)?" />
</Match>
</FindBugsFilter>
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import io.skodjob.datagenerator.enums.ETemplateType;
public class Main {
public static void main(String[] args) {
DataGenerator dataGenerator = new DataGenerator(ETemplateType.PAYMENT_FIAT);
String paymentDataString = dataGenerator.generateStringData();
String paymentDataString = dataGenerator.generateData();
JsonNode paymentDataJson = dataGenerator.generateJsonData();
System.out.println(paymentDataString);
}
Expand All @@ -66,7 +66,7 @@ import io.skodjob.datagenerator.enums.ETemplateType;
public class Main {
public static void main(String[] args) {
DataGenerator dataGenerator = new DataGenerator(ETemplateType.FLIGHTS);
String paymentDataString = dataGenerator.generateStringData();
String paymentDataString = dataGenerator.generateData();
JsonNode paymentDataJson = dataGenerator.generateJsonData();
System.out.println(paymentDataString);
}
Expand Down
41 changes: 39 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<junit.platform.version>1.10.3</junit.platform.version>
<maven.surefire.version>3.3.1</maven.surefire.version>
<datafaker.version>2.3.1</datafaker.version>
<avro.version>1.11.3</avro.version>

<jackson-dataformat-yaml.version>2.17.2</jackson-dataformat-yaml.version>

Expand All @@ -100,8 +101,6 @@
<it.skip>true</it.skip>
<!--suppress UnresolvedMavenProperty -->
<ut.skip>${skipTests}</ut.skip>

<checkstyle.config.location>checkstyle.xml</checkstyle.config.location>
</properties>

<dependencies>
Expand Down Expand Up @@ -181,6 +180,18 @@
<artifactId>datafaker</artifactId>
<version>${datafaker.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.avro/avro -->
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
<version>${avro.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.avro/avro-tools -->
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro-tools</artifactId>
<version>${avro.version}</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -213,6 +224,8 @@
<xmlOutput>true</xmlOutput>
<!-- Configures the directory in which the XML report is created -->
<spotbugsXmlOutputDirectory>${project.build.directory}/spotbugs</spotbugsXmlOutputDirectory>
<!-- Configures the file for excluding warnings -->
<excludeFilterFile>${project.basedir}/.spotbugs/spotbugs-exclude.xml</excludeFilterFile>
</configuration>
</plugin>
<plugin>
Expand All @@ -229,6 +242,7 @@
<show>public</show>
<failOnError>true</failOnError>
<failOnWarnings>true</failOnWarnings>
<excludePackageNames>io.skodjob.datagenerator.models.*</excludePackageNames>
</configuration>
</execution>
</executions>
Expand All @@ -244,6 +258,8 @@
<configuration>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<configLocation>.checkstyle/checkstyle.xml</configLocation>
<suppressionsLocation>.checkstyle/suppressions.xml</suppressionsLocation>
</configuration>
<goals>
<goal>check</goal>
Expand Down Expand Up @@ -326,6 +342,27 @@
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>${avro.version}</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDirectory>${project.basedir}/src/main/avro</sourceDirectory>
<outputDirectory>${project.basedir}/src/main/java</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>central-sonatype</id>
Expand Down
81 changes: 81 additions & 0 deletions src/main/avro/Flights.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"type": "record",
"name": "FlightRecord",
"namespace": "io.skodjob.datagenerator.models.flights",
"fields": [
{
"name": "passenger",
"type": {
"type": "record",
"name": "Passenger",
"fields": [
{
"name": "id",
"type": "string"
},
{
"name": "name",
"type": "string"
},
{
"name": "passport_number",
"type": "string"
},
{
"name": "nationality",
"type": "string"
}
]
}
},
{
"name": "flight",
"type": {
"type": "record",
"name": "Flight",
"fields": [
{
"name": "number",
"type": "string"
},
{
"name": "departure_airport",
"type": "string"
},
{
"name": "arrival_airport",
"type": "string"
},
{
"name": "departure_time",
"type": "string"
},
{
"name": "arrival_time",
"type": "string"
},
{
"name": "seat_number",
"type": "string"
},
{
"name": "gate",
"type": "string"
},
{
"name": "boarding_group",
"type": "string"
},
{
"name": "plane_model",
"type": "string"
},
{
"name": "airline",
"type": "string"
}
]
}
}
]
}
171 changes: 171 additions & 0 deletions src/main/avro/IotDevice.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
{
"type": "record",
"name": "IotDevice",
"namespace": "io.skodjob.datagenerator.models.iotdevice",
"fields": [
{
"name": "IPV4",
"type": "string"
},
{
"name": "MAC",
"type": "string"
},
{
"name": "ID",
"type": "string"
},
{
"name": "TYPE",
"type": "string"
},
{
"name": "LAST_UPDATE",
"type": "string"
},
{
"name": "LINK_QUALITY",
"type": "int"
},
{
"name": "DATA",
"type": [
{
"type": "record",
"name": "CustomData",
"fields": [
{
"name": "info",
"type": "string"
},
{
"name": "state",
"type": "string"
}
]
},
{
"type": "record",
"name": "ButtonData",
"fields": [
{
"name": "power",
"type": "string"
},
{
"name": "battery",
"type": {
"type": "record",
"name": "Battery",
"fields": [
{
"name": "value",
"type": "int"
},
{
"name": "unit",
"type": "string"
}
]
}
}
]
},
{
"type": "record",
"name": "PlugData",
"fields": [
{
"name": "power",
"type": "string"
},
{
"name": "energy_current",
"type": {
"type": "record",
"name": "EnergyCurrent",
"fields": [
{
"name": "state",
"type": "float"
},
{
"name": "unit",
"type": "string"
}
]
}
},
{
"name": "energy_today",
"type": {
"type": "record",
"name": "EnergyToday",
"fields": [
{
"name": "state",
"type": "float"
},
{
"name": "unit",
"type": "string"
}
]
}
}
]
},
{
"type": "record",
"name": "ThermometerData",
"fields": [
{
"name": "temperature",
"type": "float"
},
{
"name": "humidity",
"type": "float"
},
{
"name": "battery",
"type": "io.skodjob.datagenerator.models.iotdevice.Battery"
}
]
},
{
"type": "record",
"name": "GateData",
"fields": [
{
"name": "vendor",
"type": "string"
},
{
"name": "state",
"type": "string"
}
]
},
{
"type": "record",
"name": "LightData",
"fields": [
{
"name": "power",
"type": "string"
},
{
"name": "brightness",
"type": "int"
},
{
"name": "power_on_behavior",
"type": "string"
}
]
}
]
}
]
}
Loading