Skip to content

Commit

Permalink
14 dates default output format causes deserialization error (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
jemacineiras authored Jan 8, 2024
1 parent 310ca70 commit 7f64a90
Show file tree
Hide file tree
Showing 33 changed files with 735 additions and 125 deletions.
61 changes: 50 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,42 @@ Specially useful when defining body validations for interactions with complex mo
- [Contact](#contact)

## Getting Started

### Requirements

- JDK +17

- Having inside your project a verification library of your choice to have the `@Max` and `@Min` annotations available, such as [Jakarta](https://central.sonatype.com/artifact/jakarta.validation/jakarta.validation-api), [Spring Boot](https://central.sonatype.com/artifact/org.springframework.boot/spring-boot-starter-validation) or similar.

### Compatibility with pact-jvm

| Pact DSL Builder | Pact JVM |
|:------------------------------------------------------------------------------------:|:----------:|
| [1.1.0](https://central.sonatype.com/artifact/com.sngular/pact-annotation-processor/1.1.0) | +4.6.3 |
| [1.1.7](https://central.sonatype.com/artifact/com.sngular/pact-annotation-processor) | +4.6.3 |

| [1.2.0](https://central.sonatype.com/artifact/com.sngular/pact-annotation-processor/1.1.0) | +4.6.3 |
### Configuration

The only configuration needed for starting using the library is adding the dependency to your build automation tool:

Maven

```xml
<dependencies>
...
<dependency>
<groupId>com.sngular</groupId>
<artifactId>pact-annotation-processor</artifactId>
<version>1.0.0</version>
<version>1.2.0</version>
</dependency>
...
</dependencies>
```

Gradle

```groovy
implementation('com.sngular:pact-annotation-processor:1.0.0')
implementation('com.sngular:pact-annotation-processor:1.2.0')
```

## Usage
Expand All @@ -63,6 +70,18 @@ That is the only requirement, all other annotations are optional and used for cu

### Annotations

We have developed 3 annotations to give support to your needs,

- `@PactDslBodyBuilder` : To indicate which class you need to generate pact to.
- `@Example`: To define constants values to set in your Pact Body.
- `DslExclude`: To Exclude some property to be included in the builder.

and support 2 standard Java annotations for validation

- `@Min`: From Jakarta or Javax (or other validation tools) to indicate the
minimum value to be cover for this property.
- `@Max`: From Jakarta or Javax (or other validation tools) to indicate the
maximum value to be cover for this property.

| Annotation | Required | Level | Description |
|----------------------:|:--------:|:-----:|:--------------------------------------------------------------------------------------------------------------------------------------------|
Expand All @@ -72,8 +91,15 @@ That is the only requirement, all other annotations are optional and used for cu
| `@Max` | false | Field | Defines the minimum value for numeric fields, or number of elements if applied to collections. Will be ignored if an `@Example` is present. |
| `@DslExclude` | false | Field | Ignore de generation of example values. |

`@Example` values are always provided as String. For Dates and ZonedDateTime the only format supported in this version is the one shown in the example below.
Support for custom date formats will be included in following releases.
> `@Example` values are always provided as String. If a specific format is
required lets say for date
> and datetime properties, then a format field should be provided,
otherwise it will fall back to default
> format. For date and datetime default format are:
>
> - `yyyy-MM-dd['['ZZZ']']` : for dates
>
> - `yyyy-MM-dd'T'HH:mm:ss[.SSSSSS][.SSS]XXX['['VV']']` : for datetimes. Zone should be provided with this format.
#### Example

Expand All @@ -93,7 +119,7 @@ public class Address {
@Example("2023-12-03T10:15:30+01:00[Europe/Madrid]")
private ZonedDateTime deliveryTime;

@Example("Sep 27, 2022, 11:02:00 AM")
@Example("2023-12-13")
private Date creationDate;

@Example("Jose")
Expand Down Expand Up @@ -145,6 +171,19 @@ public RequestResponsePact getStudents(PactDslWithProvider builder) {
}
```

## Notes

- Dates: Regarding Timestamp and Date, we should use keep in mind the default
formats will be used to parse those values:
- For Dates, we are using `"yyyy-MM-dd['['ZZZ']']"` as default format
- For Timestamps, we are using
`"yyyy-MM-dd'T'HH:mm:ss[.SSSSSS][.SSS]XXX['['VV']']"`
as default format for datetime (ZonedDateTime)
If you need and specific format the `@Example` support a format property
to handle them.

=======

### Expected Instance Builder

In certain situations, especially when using the `@Example` annotation in all
Expand All @@ -165,7 +204,7 @@ void getAddressTest(MockServer mockServer) {
// ...

assertEquals(expectedAddress, response);
}
}
```

However, in many situations, especially when dealing with random values being generated,
Expand Down Expand Up @@ -200,9 +239,10 @@ See the [open issues](https://github.com/sngular/pact-annotation-processor/issue

Contributions are what makes the open source community special. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this library better, please [review our contributing guidelines](#https://github.com/sngular/pact-annotation-processor/blob/main/CONTRIBUTING.md).
If you have a suggestion that would make this library better,
please [review our contributing guidelines](https://github.com/sngular/pact-annotation-processor/blob/main/CONTRIBUTING.md).

Or you can simply [open a feature request issue](#https://github.com/sngular/pact-annotation-processor/issues/new/choose).
Or you can simply [open a feature request issue](https://github.com/sngular/pact-annotation-processor/issues/new/choose).

## License

Expand All @@ -214,5 +254,4 @@ OS3 team: [[email protected]](mailto:[email protected])

Sngular - [GitHub Org](https://github.com/sngular)

https://www.sngular.com

<https://www.sngular.com>
71 changes: 56 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.sngular</groupId>
<artifactId>pact-annotation-processor</artifactId>
<version>1.1.9</version>
<version>1.2.0</version>

<name>PactDslBuilder - Annotation Processor</name>
<description>Pact DSL Builder annotation processor.</description>
Expand Down Expand Up @@ -54,7 +54,7 @@
<id>tfdsimoes</id>
<name>Tiago Filipe Domingues Simoes</name>
<email>[email protected]</email>
<organizationUrl></organizationUrl>
<organizationUrl />
<roles>
<role>Software Engineer</role>
</roles>
Expand Down Expand Up @@ -98,6 +98,10 @@
<maven-javadoc-plugin.version>3.6.0</maven-javadoc-plugin.version>
<maven-source-plugin.version>3.0.0</maven-source-plugin.version>
<apache-commons-rng.version>1.5</apache-commons-rng.version>

<assertj-core.version>3.24.2</assertj-core.version>
<junit-jupiter-engine.version>5.9.2</junit-jupiter-engine.version>
<mockito.version>5.3.1</mockito.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -158,6 +162,49 @@
<artifactId>guava</artifactId>
<version>${google-guava.version}</version>
</dependency>
<!-- TESTING DEPENDENCIES -->
<dependency>
<groupId>com.google.testing.compile</groupId>
<artifactId>compile-testing</artifactId>
<version>0.21.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj-core.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter-engine.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit-jupiter-engine.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -194,6 +241,13 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<argLine>
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
</argLine>
</configuration>
<executions>
<execution>
<id>default-test</id>
Expand All @@ -203,23 +257,10 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.ekryd.sortpom</groupId>
<artifactId>sortpom-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>sort</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>

<configLocation>checkstyle.xml</configLocation>
</configuration>
<dependencies>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/sngular/annotation/pact/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@
public @interface Example {

String value() default "";

String format() default "";
}
Loading

0 comments on commit 7f64a90

Please sign in to comment.