From 4974079794078a513a1b8948f52fb820a7fa06b7 Mon Sep 17 00:00:00 2001 From: fkiss Date: Tue, 9 Aug 2016 15:20:40 +0200 Subject: [PATCH] KEYCLOAK-3211 - ExportImportTest fix for Wildfly --- .../rest/TestingResourceProvider.java | 77 +++++++++++++++++++ .../client/resources/TestingResource.java | 50 ++++++++++++ .../exportimport/ExportImportTest.java | 46 +++++------ 3 files changed, 150 insertions(+), 23 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 c65e85cb27..b658d35c3a 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 @@ -17,6 +17,7 @@ package org.keycloak.testsuite.rest; +import java.io.File; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -76,6 +77,8 @@ import org.keycloak.representations.idm.AuthDetailsRepresentation; import org.keycloak.representations.idm.AuthenticationFlowRepresentation; import org.keycloak.representations.idm.UserRepresentation; +import static org.keycloak.exportimport.ExportImportConfig.*; + /** * @author Stian Thorgersen */ @@ -649,4 +652,78 @@ public class TestingResourceProvider implements RealmResourceProvider { return realmProvider.getRealmByName(realmName); } + @GET + @Path("/get-users-per-file") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Integer getUsersPerFile() { + String usersPerFile = System.getProperty(USERS_PER_FILE, String.valueOf(DEFAULT_USERS_PER_FILE)); + return Integer.parseInt(usersPerFile.trim()); + } + + @PUT + @Path("/set-users-per-file") + @Consumes(MediaType.APPLICATION_JSON) + public void setUsersPerFile(@QueryParam("usersPerFile") Integer usersPerFile) { + System.setProperty(USERS_PER_FILE, String.valueOf(usersPerFile)); + } + + @GET + @Path("/get-dir") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public String getDir() { + return System.getProperty(DIR); + } + + @PUT + @Path("/set-dir") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public String setDir(@QueryParam("dir") String dir) { + return System.setProperty(DIR, dir); + } + + @PUT + @Path("/export-import-provider") + @Consumes(MediaType.APPLICATION_JSON) + public void setProvider(@QueryParam("exportImportProvider") String exportImportProvider) { + System.setProperty(PROVIDER, exportImportProvider); + } + + @PUT + @Path("/export-import-file") + @Consumes(MediaType.APPLICATION_JSON) + public void setFile(@QueryParam("file") String file) { + System.setProperty(FILE, file); + } + + @PUT + @Path("/export-import-action") + @Consumes(MediaType.APPLICATION_JSON) + public void setAction(@QueryParam("exportImportAction") String exportImportAction) { + System.setProperty(ACTION, exportImportAction); + } + + @PUT + @Path("/set-realm-name") + @Consumes(MediaType.APPLICATION_JSON) + public void setRealmName(@QueryParam("realmName") String realmName) { + if (realmName != null && !realmName.isEmpty()) { + System.setProperty(REALM_NAME, realmName); + } else { + System.getProperties().remove(REALM_NAME); + } + } + + @GET + @Path("/get-test-dir") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public String getExportImportTestDirectory() { + System.setProperty("project.build.directory", "target"); + String absolutePath = new File(System.getProperty("project.build.directory", "target")).getAbsolutePath(); + return absolutePath; + } + } 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 8bd36f3f64..fcf5d8317a 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 @@ -249,4 +249,54 @@ public interface TestingResource { @Path("/get-user-by-service-account-client") @Produces(MediaType.APPLICATION_JSON) public UserRepresentation getUserByServiceAccountClient(@QueryParam("realmName") String realmName, @QueryParam("clientId") String clientId); + + + @GET + @Path("/get-users-per-file") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Integer getUsersPerFile(); + + @PUT + @Path("/set-users-per-file") + @Consumes(MediaType.APPLICATION_JSON) + public void setUsersPerFile(@QueryParam("usersPerFile") Integer usersPerFile); + + @GET + @Path("/get-dir") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public String getDir(); + + @PUT + @Path("/set-dir") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public String setDir(@QueryParam("dir") String dir); + + @PUT + @Path("/export-import-provider") + @Consumes(MediaType.APPLICATION_JSON) + public void setProvider(@QueryParam("exportImportProvider") String exportImportProvider); + + @PUT + @Path("/export-import-file") + @Consumes(MediaType.APPLICATION_JSON) + public void setFile(@QueryParam("file") String file); + + @PUT + @Path("/export-import-action") + @Consumes(MediaType.APPLICATION_JSON) + public void setAction(@QueryParam("exportImportAction") String exportImportAction); + + @PUT + @Path("/set-realm-name") + @Consumes(MediaType.APPLICATION_JSON) + public void setRealmName(@QueryParam("realmName") String realmName); + + @GET + @Path("/get-test-dir") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public String getExportImportTestDirectory(); } diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/exportimport/ExportImportTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/exportimport/ExportImportTest.java index 3a6a1bbe2b..66baa0781d 100755 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/exportimport/ExportImportTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/exportimport/ExportImportTest.java @@ -73,11 +73,11 @@ public class ExportImportTest extends AbstractExportImportTest { @Test public void testDirFullExportImport() throws Throwable { - ExportImportConfig.setProvider(DirExportProviderFactory.PROVIDER_ID); - String targetDirPath = getExportImportTestDirectory() + File.separator + "dirExport"; + testingClient.testing().setProvider(DirExportProviderFactory.PROVIDER_ID); + String targetDirPath = testingClient.testing().getExportImportTestDirectory()+ File.separator + "dirExport"; DirExportProvider.recursiveDeleteDir(new File(targetDirPath)); - ExportImportConfig.setDir(targetDirPath); - ExportImportConfig.setUsersPerFile(ExportImportConfig.DEFAULT_USERS_PER_FILE); + testingClient.testing().setDir(targetDirPath); + testingClient.testing().setUsersPerFile(ExportImportConfig.DEFAULT_USERS_PER_FILE); testFullExportImport(); @@ -87,11 +87,11 @@ public class ExportImportTest extends AbstractExportImportTest { @Test public void testDirRealmExportImport() throws Throwable { - ExportImportConfig.setProvider(DirExportProviderFactory.PROVIDER_ID); - String targetDirPath = getExportImportTestDirectory() + File.separator + "dirRealmExport"; + testingClient.testing().setProvider(DirExportProviderFactory.PROVIDER_ID); + String targetDirPath = testingClient.testing().getExportImportTestDirectory() + File.separator + "dirRealmExport"; DirExportProvider.recursiveDeleteDir(new File(targetDirPath)); - ExportImportConfig.setDir(targetDirPath); - ExportImportConfig.setUsersPerFile(3); + testingClient.testing().setDir(targetDirPath); + testingClient.testing().setUsersPerFile(3); testRealmExportImport(); @@ -102,18 +102,18 @@ public class ExportImportTest extends AbstractExportImportTest { @Test public void testSingleFileFullExportImport() throws Throwable { - ExportImportConfig.setProvider(SingleFileExportProviderFactory.PROVIDER_ID); - String targetFilePath = getExportImportTestDirectory() + File.separator + "singleFile-full.json"; - ExportImportConfig.setFile(targetFilePath); + testingClient.testing().setProvider(SingleFileExportProviderFactory.PROVIDER_ID); + String targetFilePath = testingClient.testing().getExportImportTestDirectory() + File.separator + "singleFile-full.json"; + testingClient.testing().setFile(targetFilePath); testFullExportImport(); } @Test public void testSingleFileRealmExportImport() throws Throwable { - ExportImportConfig.setProvider(SingleFileExportProviderFactory.PROVIDER_ID); - String targetFilePath = getExportImportTestDirectory() + File.separator + "singleFile-realm.json"; - ExportImportConfig.setFile(targetFilePath); + testingClient.testing().setProvider(SingleFileExportProviderFactory.PROVIDER_ID); + String targetFilePath = testingClient.testing().getExportImportTestDirectory() + File.separator + "singleFile-realm.json"; + testingClient.testing().setFile(targetFilePath); testRealmExportImport(); } @@ -124,12 +124,12 @@ public class ExportImportTest extends AbstractExportImportTest { removeRealm("test-realm"); // Set the realm, which doesn't have builtin clients/roles inside JSON - ExportImportConfig.setProvider(SingleFileExportProviderFactory.PROVIDER_ID); + testingClient.testing().setProvider(SingleFileExportProviderFactory.PROVIDER_ID); URL url = ExportImportTest.class.getResource("/model/testrealm.json"); String targetFilePath = new File(url.getFile()).getAbsolutePath(); - ExportImportConfig.setFile(targetFilePath); + testingClient.testing().setFile(targetFilePath); - ExportImportConfig.setAction(ExportImportConfig.ACTION_IMPORT); + testingClient.testing().setAction(ExportImportConfig.ACTION_IMPORT); testingClient.testing().runImport(); @@ -144,8 +144,8 @@ public class ExportImportTest extends AbstractExportImportTest { } private void testFullExportImport() throws LifecycleException { - ExportImportConfig.setAction(ExportImportConfig.ACTION_EXPORT); - ExportImportConfig.setRealmName(null); + testingClient.testing().setAction(ExportImportConfig.ACTION_EXPORT); + testingClient.testing().setRealmName(""); testingClient.testing().runExport(); @@ -159,7 +159,7 @@ public class ExportImportTest extends AbstractExportImportTest { assertNotAuthenticated("test", "user3", "password"); // Configure import - ExportImportConfig.setAction(ExportImportConfig.ACTION_IMPORT); + testingClient.testing().setAction(ExportImportConfig.ACTION_IMPORT); testingClient.testing().runImport(); @@ -173,8 +173,8 @@ public class ExportImportTest extends AbstractExportImportTest { } private void testRealmExportImport() throws LifecycleException { - ExportImportConfig.setAction(ExportImportConfig.ACTION_EXPORT); - ExportImportConfig.setRealmName("test"); + testingClient.testing().setAction(ExportImportConfig.ACTION_EXPORT); + testingClient.testing().setRealmName("test"); testingClient.testing().runExport(); @@ -189,7 +189,7 @@ public class ExportImportTest extends AbstractExportImportTest { assertNotAuthenticated("test", "user3", "password"); // Configure import - ExportImportConfig.setAction(ExportImportConfig.ACTION_IMPORT); + testingClient.testing().setAction(ExportImportConfig.ACTION_IMPORT); testingClient.testing().runImport();