BAEL-5288 Code for the Map Date Types With openapi generator article (#13467)
Co-authored-by: thibault.faure <thibault.faure@mimacom.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
openapi: 3.0.0
|
||||
info:
|
||||
title: an example api with dates
|
||||
version: 0.1.0
|
||||
paths:
|
||||
components:
|
||||
schemas:
|
||||
Event:
|
||||
type: object
|
||||
properties:
|
||||
organizer:
|
||||
type: string
|
||||
startDate:
|
||||
type: string
|
||||
format: date
|
||||
endDate:
|
||||
type: string
|
||||
format: date-time
|
||||
ticketSales:
|
||||
type: string
|
||||
description: Beginning of the ticket sales
|
||||
example: "01-01-2023"
|
||||
pattern: "[0-9]{2}-[0-9]{2}-[0-9]{4}"
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package com.baeldung.dates;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.Validation;
|
||||
import javax.validation.Validator;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import io.swagger.model.Event;
|
||||
|
||||
class EventUnitTest {
|
||||
|
||||
private static final Validator VALIDATOR = Validation.buildDefaultValidatorFactory()
|
||||
.getValidator();
|
||||
|
||||
@Test
|
||||
void givenACorrectlyFormattedTicketSales_WhenBuildingEvent_ThenSuccess() {
|
||||
Set<ConstraintViolation<Event>> violations = VALIDATOR.validate(new Event().ticketSales("01-01-2024"));
|
||||
assertTrue(violations.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenAWronglyFormattedTicketSales_WhenBuildingEvent_ThenSuccess() {
|
||||
Set<ConstraintViolation<Event>> violations = VALIDATOR.validate(new Event().ticketSales("2024-01-01"));
|
||||
assertEquals(1, violations.size());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user