KEYCLOAK-3106 EventStoreProviderTest.query is failing in some environments
This commit is contained in:
parent
443772d5ec
commit
e6b3586b87
3 changed files with 29 additions and 38 deletions
|
@ -253,7 +253,7 @@ public class TestingResourceProvider implements RealmResourceProvider {
|
|||
@NoCache
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public List<EventRepresentation> queryEvents(@QueryParam("realmId") String realmId, @QueryParam("type") List<String> types, @QueryParam("client") String client,
|
||||
@QueryParam("user") String user, @QueryParam("dateFrom") Date dateFrom, @QueryParam("dateTo") Date dateTo,
|
||||
@QueryParam("user") String user, @QueryParam("dateFrom") String dateFrom, @QueryParam("dateTo") String dateTo,
|
||||
@QueryParam("ipAddress") String ipAddress, @QueryParam("first") Integer firstResult,
|
||||
@QueryParam("max") Integer maxResults) {
|
||||
|
||||
|
@ -282,11 +282,13 @@ public class TestingResourceProvider implements RealmResourceProvider {
|
|||
}
|
||||
|
||||
if(dateFrom != null) {
|
||||
query.fromDate(dateFrom);
|
||||
Date from = formatDate(dateFrom, "Date(From)");
|
||||
query.fromDate(from);
|
||||
}
|
||||
|
||||
if(dateTo != null) {
|
||||
query.toDate(dateTo);
|
||||
Date to = formatDate(dateTo, "Date(To)");
|
||||
query.toDate(to);
|
||||
}
|
||||
|
||||
if (ipAddress != null) {
|
||||
|
@ -424,26 +426,12 @@ public class TestingResourceProvider implements RealmResourceProvider {
|
|||
}
|
||||
|
||||
if(dateFrom != null) {
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date from;
|
||||
try {
|
||||
from = df.parse(dateFrom);
|
||||
} catch (ParseException e) {
|
||||
throw new BadRequestException("Invalid value for 'Date(From)', expected format is yyyy-MM-dd");
|
||||
}
|
||||
|
||||
Date from = formatDate(dateFrom, "Date(From)");
|
||||
query.fromTime(from);
|
||||
}
|
||||
|
||||
if(dateTo != null) {
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date to;
|
||||
try {
|
||||
to = df.parse(dateTo);
|
||||
} catch (ParseException e) {
|
||||
throw new BadRequestException("Invalid value for 'Date(To)', expected format is yyyy-MM-dd");
|
||||
}
|
||||
|
||||
Date to = formatDate(dateTo, "Date(To)");
|
||||
query.toTime(to);
|
||||
}
|
||||
|
||||
|
@ -461,6 +449,15 @@ public class TestingResourceProvider implements RealmResourceProvider {
|
|||
return toAdminEventRep(query.getResultList());
|
||||
}
|
||||
|
||||
private Date formatDate(String date, String paramName) {
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||
try {
|
||||
return df.parse(date);
|
||||
} catch (ParseException e) {
|
||||
throw new BadRequestException("Invalid value for '" + paramName + "', expected format is yyyy-MM-dd");
|
||||
}
|
||||
}
|
||||
|
||||
private List<AdminEventRepresentation> toAdminEventRep(List<AdminEvent> events) {
|
||||
List<AdminEventRepresentation> reps = new ArrayList<>();
|
||||
for (AdminEvent event : events) {
|
||||
|
|
|
@ -111,7 +111,7 @@ public interface TestingResource {
|
|||
@NoCache
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public List<EventRepresentation> queryEvents(@QueryParam("realmId") String realmId, @QueryParam("type") List<String> types, @QueryParam("client") String client,
|
||||
@QueryParam("user") String user, @QueryParam("dateFrom") Date dateFrom, @QueryParam("dateTo") Date dateTo,
|
||||
@QueryParam("user") String user, @QueryParam("dateFrom") String dateFrom, @QueryParam("dateTo") String dateTo,
|
||||
@QueryParam("ipAddress") String ipAddress, @QueryParam("first") Integer firstResult,
|
||||
@QueryParam("max") Integer maxResults);
|
||||
|
||||
|
|
|
@ -89,18 +89,12 @@ public class EventStoreProviderTest extends AbstractEventsTest {
|
|||
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date date1 = null, date2 = null, date3 = null, date4 = null;
|
||||
Date date5 = null, date6 = null, date7 = null, date8 = null;
|
||||
|
||||
try {
|
||||
date1 = formatter.parse(d1);
|
||||
date2 = formatter.parse(d2);
|
||||
date3 = formatter.parse(d3);
|
||||
date4 = formatter.parse(d4);
|
||||
|
||||
date5 = formatter.parse(d5);
|
||||
date6 = formatter.parse(d6);
|
||||
date7 = formatter.parse(d7);
|
||||
date8 = formatter.parse(d8);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -131,22 +125,22 @@ public class EventStoreProviderTest extends AbstractEventsTest {
|
|||
Assert.assertEquals(1, testing().queryEvents(null, toList(EventType.UPDATE_PROFILE), null, null, null, null, null, null, null).size());
|
||||
Assert.assertEquals(1, testing().queryEvents(null, toList(EventType.UPDATE_EMAIL), null, null, null, null, null, null, null).size());
|
||||
|
||||
Assert.assertEquals(8, testing().queryEvents(null, null, null, null, date1, null, null, null, null).size());
|
||||
Assert.assertEquals(8, testing().queryEvents(null, null, null, null, null, date4, null, null, null).size());
|
||||
Assert.assertEquals(8, testing().queryEvents(null, null, null, null, d1, null, null, null, null).size());
|
||||
Assert.assertEquals(8, testing().queryEvents(null, null, null, null, null, d4, null, null, null).size());
|
||||
|
||||
Assert.assertEquals(4, testing().queryEvents(null, null, null, null, date3, null, null, null, null).size());
|
||||
Assert.assertEquals(4, testing().queryEvents(null, null, null, null, null, date2, null, null, null).size());
|
||||
Assert.assertEquals(4, testing().queryEvents(null, null, null, null, d3, null, null, null, null).size());
|
||||
Assert.assertEquals(4, testing().queryEvents(null, null, null, null, null, d2, null, null, null).size());
|
||||
|
||||
Assert.assertEquals(0, testing().queryEvents(null, null, null, null, date7, null, null, null, null).size());
|
||||
Assert.assertEquals(0, testing().queryEvents(null, null, null, null, null, date6, null, null, null).size());
|
||||
Assert.assertEquals(0, testing().queryEvents(null, null, null, null, d7, null, null, null, null).size());
|
||||
Assert.assertEquals(0, testing().queryEvents(null, null, null, null, null, d6, null, null, null).size());
|
||||
|
||||
Assert.assertEquals(8, testing().queryEvents(null, null, null, null, date1, date4, null, null, null).size());
|
||||
Assert.assertEquals(6, testing().queryEvents(null, null, null, null, date2, date4, null, null, null).size());
|
||||
Assert.assertEquals(4, testing().queryEvents(null, null, null, null, date1, date2, null, null, null).size());
|
||||
Assert.assertEquals(4, testing().queryEvents(null, null, null, null, date3, date4, null, null, null).size());
|
||||
Assert.assertEquals(8, testing().queryEvents(null, null, null, null, d1, d4, null, null, null).size());
|
||||
Assert.assertEquals(6, testing().queryEvents(null, null, null, null, d2, d4, null, null, null).size());
|
||||
Assert.assertEquals(4, testing().queryEvents(null, null, null, null, d1, d2, null, null, null).size());
|
||||
Assert.assertEquals(4, testing().queryEvents(null, null, null, null, d3, d4, null, null, null).size());
|
||||
|
||||
Assert.assertEquals(0, testing().queryEvents(null, null, null, null, date5, date6, null, null, null).size());
|
||||
Assert.assertEquals(0, testing().queryEvents(null, null, null, null, date7, date8, null, null, null).size());
|
||||
Assert.assertEquals(0, testing().queryEvents(null, null, null, null, d5, d6, null, null, null).size());
|
||||
Assert.assertEquals(0, testing().queryEvents(null, null, null, null, d7, d8, null, null, null).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue