From 13bf36ce496c88874a8b33316b3950589b74b8d8 Mon Sep 17 00:00:00 2001 From: mposolda Date: Fri, 3 Jun 2016 10:18:33 +0200 Subject: [PATCH] KEYCLOAK-3074 Change the signature of TestingResourceProvider.getAdminEvents to use String instead of java.util.Date --- .../rest/TestingResourceProvider.java | 26 ++++++++++++---- .../client/resources/TestingResource.java | 4 +-- .../events/AdminEventStoreProviderTest.java | 30 ++++++++----------- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/rest/TestingResourceProvider.java b/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/rest/TestingResourceProvider.java index a9914c3795..3612317bcf 100644 --- a/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/rest/TestingResourceProvider.java +++ b/testsuite/integration-arquillian/servers/auth-server/services/testsuite-providers/src/main/java/org/keycloak/testsuite/rest/TestingResourceProvider.java @@ -61,9 +61,7 @@ import org.keycloak.events.EventType; import org.keycloak.events.admin.AdminEventQuery; import org.keycloak.events.admin.AuthDetails; import org.keycloak.events.admin.OperationType; -import org.keycloak.models.utils.RepresentationToModel; import org.keycloak.representations.idm.AuthDetailsRepresentation; -import org.keycloak.services.resources.admin.RealmAuth; /** * @author Stian Thorgersen @@ -386,8 +384,8 @@ public class TestingResourceProvider implements RealmResourceProvider { @Produces(MediaType.APPLICATION_JSON) public List getAdminEvents(@QueryParam("realmId") String realmId, @QueryParam("operationTypes") List operationTypes, @QueryParam("authRealm") String authRealm, @QueryParam("authClient") String authClient, @QueryParam("authUser") String authUser, @QueryParam("authIpAddress") String authIpAddress, - @QueryParam("resourcePath") String resourcePath, @QueryParam("dateFrom") Date dateFrom, - @QueryParam("dateTo") Date dateTo, @QueryParam("first") Integer firstResult, + @QueryParam("resourcePath") String resourcePath, @QueryParam("dateFrom") String dateFrom, + @QueryParam("dateTo") String dateTo, @QueryParam("first") Integer firstResult, @QueryParam("max") Integer maxResults) { EventStoreProvider eventStore = session.getProvider(EventStoreProvider.class); @@ -426,11 +424,27 @@ public class TestingResourceProvider implements RealmResourceProvider { } if(dateFrom != null) { - query.fromTime(dateFrom); + 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"); + } + + query.fromTime(from); } if(dateTo != null) { - query.toTime(dateTo); + 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"); + } + + query.toTime(to); } if (firstResult != null) { diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/client/resources/TestingResource.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/client/resources/TestingResource.java index 7fc6085edb..81e4adddbc 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/client/resources/TestingResource.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/client/resources/TestingResource.java @@ -159,8 +159,8 @@ public interface TestingResource { @Produces(MediaType.APPLICATION_JSON) public List getAdminEvents(@QueryParam("realmId") String realmId, @QueryParam("operationTypes") List operationTypes, @QueryParam("authRealm") String authRealm, @QueryParam("authClient") String authClient, @QueryParam("authUser") String authUser, @QueryParam("authIpAddress") String authIpAddress, - @QueryParam("resourcePath") String resourcePath, @QueryParam("dateFrom") Date dateFrom, - @QueryParam("dateTo") Date dateTo, @QueryParam("first") Integer firstResult, + @QueryParam("resourcePath") String resourcePath, @QueryParam("dateFrom") String dateFrom, + @QueryParam("dateTo") String dateTo, @QueryParam("first") Integer firstResult, @QueryParam("max") Integer maxResults); @POST diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/events/AdminEventStoreProviderTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/events/AdminEventStoreProviderTest.java index bb3368cd4f..497fe97658 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/events/AdminEventStoreProviderTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/events/AdminEventStoreProviderTest.java @@ -87,18 +87,12 @@ public class AdminEventStoreProviderTest 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(); } @@ -127,22 +121,22 @@ public class AdminEventStoreProviderTest extends AbstractEventsTest { Assert.assertEquals(1, testing().getAdminEvents(null, toList(OperationType.DELETE), null, null, null, null, null, null, null, null, null).size()); Assert.assertEquals(4, testing().getAdminEvents(null, toList(OperationType.CREATE), null, null, null, null, null, null, null, null, null).size()); - Assert.assertEquals(8, testing().getAdminEvents(null, null, null, null, null, null, null, date1, null, null, null).size()); - Assert.assertEquals(8, testing().getAdminEvents(null, null, null, null, null, null, null, null, date4, null, null).size()); + Assert.assertEquals(8, testing().getAdminEvents(null, null, null, null, null, null, null, d1, null, null, null).size()); + Assert.assertEquals(8, testing().getAdminEvents(null, null, null, null, null, null, null, null, d4, null, null).size()); - Assert.assertEquals(4, testing().getAdminEvents(null, null, null, null, null, null, null, date3, null, null, null).size()); - Assert.assertEquals(4, testing().getAdminEvents(null, null, null, null, null, null, null, null, date2, null, null).size()); + Assert.assertEquals(4, testing().getAdminEvents(null, null, null, null, null, null, null, d3, null, null, null).size()); + Assert.assertEquals(4, testing().getAdminEvents(null, null, null, null, null, null, null, null, d2, null, null).size()); - Assert.assertEquals(0, testing().getAdminEvents(null, null, null, null, null, null, null, date7, null, null, null).size()); - Assert.assertEquals(0, testing().getAdminEvents(null, null, null, null, null, null, null, null, date6, null, null).size()); + Assert.assertEquals(0, testing().getAdminEvents(null, null, null, null, null, null, null, d7, null, null, null).size()); + Assert.assertEquals(0, testing().getAdminEvents(null, null, null, null, null, null, null, null, d6, null, null).size()); - Assert.assertEquals(8, testing().getAdminEvents(null, null, null, null, null, null, null, date1, date4, null, null).size()); - Assert.assertEquals(6, testing().getAdminEvents(null, null, null, null, null, null, null, date2, date4, null, null).size()); - Assert.assertEquals(4, testing().getAdminEvents(null, null, null, null, null, null, null, date1, date2, null, null).size()); - Assert.assertEquals(4, testing().getAdminEvents(null, null, null, null, null, null, null, date3, date4, null, null).size()); + Assert.assertEquals(8, testing().getAdminEvents(null, null, null, null, null, null, null, d1, d4, null, null).size()); + Assert.assertEquals(6, testing().getAdminEvents(null, null, null, null, null, null, null, d2, d4, null, null).size()); + Assert.assertEquals(4, testing().getAdminEvents(null, null, null, null, null, null, null, d1, d2, null, null).size()); + Assert.assertEquals(4, testing().getAdminEvents(null, null, null, null, null, null, null, d3, d4, null, null).size()); - Assert.assertEquals(0, testing().getAdminEvents(null, null, null, null, null, null, null, date5, date6, null, null).size()); - Assert.assertEquals(0, testing().getAdminEvents(null, null, null, null, null, null, null, date7, date8, null, null).size()); + Assert.assertEquals(0, testing().getAdminEvents(null, null, null, null, null, null, null, d5, d6, null, null).size()); + Assert.assertEquals(0, testing().getAdminEvents(null, null, null, null, null, null, null, d7, d8, null, null).size()); }