TestingExportImport in separate resource
This commit is contained in:
parent
258f7c8d60
commit
892d5fd1b7
5 changed files with 280 additions and 207 deletions
|
@ -76,6 +76,7 @@ import org.keycloak.models.UserProvider;
|
|||
import org.keycloak.representations.idm.AuthDetailsRepresentation;
|
||||
import org.keycloak.representations.idm.AuthenticationFlowRepresentation;
|
||||
import org.keycloak.representations.idm.UserRepresentation;
|
||||
import org.keycloak.testsuite.rest.resource.TestingExportImportResource;
|
||||
|
||||
import static org.keycloak.exportimport.ExportImportConfig.*;
|
||||
|
||||
|
@ -564,22 +565,6 @@ public class TestingResourceProvider implements RealmResourceProvider {
|
|||
return result;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/run-import")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response runImport() {
|
||||
new ExportImportManager(session).runImport();
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/run-export")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response runExport() {
|
||||
new ExportImportManager(session).runExport();
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/valid-credentials")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
|
@ -652,78 +637,9 @@ 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;
|
||||
@Path("/export-import")
|
||||
public TestingExportImportResource getExportImportResource() {
|
||||
return new TestingExportImportResource(session);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,142 @@
|
|||
/*
|
||||
* Copyright 2016 Red Hat, Inc. and/or its affiliates
|
||||
* and other contributors as indicated by the @author tags.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.keycloak.testsuite.rest.resource;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.keycloak.exportimport.ExportImportManager;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
|
||||
import static org.keycloak.exportimport.ExportImportConfig.ACTION;
|
||||
import static org.keycloak.exportimport.ExportImportConfig.DEFAULT_USERS_PER_FILE;
|
||||
import static org.keycloak.exportimport.ExportImportConfig.DIR;
|
||||
import static org.keycloak.exportimport.ExportImportConfig.FILE;
|
||||
import static org.keycloak.exportimport.ExportImportConfig.PROVIDER;
|
||||
import static org.keycloak.exportimport.ExportImportConfig.REALM_NAME;
|
||||
import static org.keycloak.exportimport.ExportImportConfig.USERS_PER_FILE;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
||||
*/
|
||||
public class TestingExportImportResource {
|
||||
|
||||
private final KeycloakSession session;
|
||||
|
||||
public TestingExportImportResource(KeycloakSession session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/run-import")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response runImport() {
|
||||
new ExportImportManager(session).runImport();
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/run-export")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response runExport() {
|
||||
new ExportImportManager(session).runExport();
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright 2016 Red Hat, Inc. and/or its affiliates
|
||||
* and other contributors as indicated by the @author tags.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.keycloak.testsuite.client.resources;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
||||
*/
|
||||
public interface TestingExportImportResource {
|
||||
|
||||
@GET
|
||||
@Path("/run-import")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response runImport();
|
||||
|
||||
@GET
|
||||
@Path("/run-export")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response runExport();
|
||||
|
||||
@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();
|
||||
|
||||
}
|
|
@ -17,8 +17,8 @@
|
|||
|
||||
package org.keycloak.testsuite.client.resources;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.keycloak.representations.idm.AdminEventRepresentation;
|
||||
import org.keycloak.representations.idm.AuthenticationFlowRepresentation;
|
||||
import org.keycloak.representations.idm.EventRepresentation;
|
||||
|
@ -37,7 +37,6 @@ import javax.ws.rs.core.MediaType;
|
|||
import javax.ws.rs.core.Response;
|
||||
import java.util.Map;
|
||||
import org.jboss.resteasy.annotations.cache.NoCache;
|
||||
import org.keycloak.exportimport.ExportImportManager;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
|
||||
|
@ -206,16 +205,6 @@ public interface TestingResource {
|
|||
@Produces(MediaType.APPLICATION_JSON)
|
||||
AuthenticatorState updateAuthenticator(AuthenticatorState state);
|
||||
|
||||
@GET
|
||||
@Path("/run-import")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response runImport();
|
||||
|
||||
@GET
|
||||
@Path("/run-export")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response runExport();
|
||||
|
||||
@GET
|
||||
@Path("/valid-credentials")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
|
@ -250,53 +239,7 @@ public interface TestingResource {
|
|||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public UserRepresentation getUserByServiceAccountClient(@QueryParam("realmName") String realmName, @QueryParam("clientId") String clientId);
|
||||
|
||||
@Path("export-import")
|
||||
TestingExportImportResource exportImport();
|
||||
|
||||
@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();
|
||||
}
|
||||
|
|
|
@ -75,11 +75,11 @@ public class ExportImportTest extends AbstractExportImportTest {
|
|||
|
||||
@Test
|
||||
public void testDirFullExportImport() throws Throwable {
|
||||
testingClient.testing().setProvider(DirExportProviderFactory.PROVIDER_ID);
|
||||
String targetDirPath = testingClient.testing().getExportImportTestDirectory()+ File.separator + "dirExport";
|
||||
testingClient.testing().exportImport().setProvider(DirExportProviderFactory.PROVIDER_ID);
|
||||
String targetDirPath = testingClient.testing().exportImport().getExportImportTestDirectory()+ File.separator + "dirExport";
|
||||
DirExportProvider.recursiveDeleteDir(new File(targetDirPath));
|
||||
testingClient.testing().setDir(targetDirPath);
|
||||
testingClient.testing().setUsersPerFile(ExportImportConfig.DEFAULT_USERS_PER_FILE);
|
||||
testingClient.testing().exportImport().setDir(targetDirPath);
|
||||
testingClient.testing().exportImport().setUsersPerFile(ExportImportConfig.DEFAULT_USERS_PER_FILE);
|
||||
|
||||
testFullExportImport();
|
||||
|
||||
|
@ -89,11 +89,13 @@ public class ExportImportTest extends AbstractExportImportTest {
|
|||
|
||||
@Test
|
||||
public void testDirRealmExportImport() throws Throwable {
|
||||
testingClient.testing().setProvider(DirExportProviderFactory.PROVIDER_ID);
|
||||
String targetDirPath = testingClient.testing().getExportImportTestDirectory() + File.separator + "dirRealmExport";
|
||||
testingClient.testing()
|
||||
.exportImport()
|
||||
.setProvider(DirExportProviderFactory.PROVIDER_ID);
|
||||
String targetDirPath = testingClient.testing().exportImport().getExportImportTestDirectory() + File.separator + "dirRealmExport";
|
||||
DirExportProvider.recursiveDeleteDir(new File(targetDirPath));
|
||||
testingClient.testing().setDir(targetDirPath);
|
||||
testingClient.testing().setUsersPerFile(3);
|
||||
testingClient.testing().exportImport().setDir(targetDirPath);
|
||||
testingClient.testing().exportImport().setUsersPerFile(3);
|
||||
|
||||
testRealmExportImport();
|
||||
|
||||
|
@ -104,18 +106,18 @@ public class ExportImportTest extends AbstractExportImportTest {
|
|||
|
||||
@Test
|
||||
public void testSingleFileFullExportImport() throws Throwable {
|
||||
testingClient.testing().setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
|
||||
String targetFilePath = testingClient.testing().getExportImportTestDirectory() + File.separator + "singleFile-full.json";
|
||||
testingClient.testing().setFile(targetFilePath);
|
||||
testingClient.testing().exportImport().setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
|
||||
String targetFilePath = testingClient.testing().exportImport().getExportImportTestDirectory() + File.separator + "singleFile-full.json";
|
||||
testingClient.testing().exportImport().setFile(targetFilePath);
|
||||
|
||||
testFullExportImport();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleFileRealmExportImport() throws Throwable {
|
||||
testingClient.testing().setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
|
||||
String targetFilePath = testingClient.testing().getExportImportTestDirectory() + File.separator + "singleFile-realm.json";
|
||||
testingClient.testing().setFile(targetFilePath);
|
||||
testingClient.testing().exportImport().setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
|
||||
String targetFilePath = testingClient.testing().exportImport().getExportImportTestDirectory() + File.separator + "singleFile-realm.json";
|
||||
testingClient.testing().exportImport().setFile(targetFilePath);
|
||||
|
||||
testRealmExportImport();
|
||||
}
|
||||
|
@ -126,14 +128,14 @@ public class ExportImportTest extends AbstractExportImportTest {
|
|||
removeRealm("test-realm");
|
||||
|
||||
// Set the realm, which doesn't have builtin clients/roles inside JSON
|
||||
testingClient.testing().setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
|
||||
testingClient.testing().exportImport().setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
|
||||
URL url = ExportImportTest.class.getResource("/model/testrealm.json");
|
||||
String targetFilePath = new File(url.getFile()).getAbsolutePath();
|
||||
testingClient.testing().setFile(targetFilePath);
|
||||
testingClient.testing().exportImport().setFile(targetFilePath);
|
||||
|
||||
testingClient.testing().setAction(ExportImportConfig.ACTION_IMPORT);
|
||||
testingClient.testing().exportImport().setAction(ExportImportConfig.ACTION_IMPORT);
|
||||
|
||||
testingClient.testing().runImport();
|
||||
testingClient.testing().exportImport().runImport();
|
||||
|
||||
RealmResource testRealmRealm = adminClient.realm("test-realm");
|
||||
|
||||
|
@ -158,14 +160,14 @@ public class ExportImportTest extends AbstractExportImportTest {
|
|||
realm.components().add(component);
|
||||
|
||||
|
||||
testingClient.testing().setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
|
||||
testingClient.testing().exportImport().setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
|
||||
|
||||
String targetFilePath = testingClient.testing().getExportImportTestDirectory() + File.separator + "singleFile-realm.json";
|
||||
testingClient.testing().setFile(targetFilePath);
|
||||
testingClient.testing().setAction(ExportImportConfig.ACTION_EXPORT);
|
||||
testingClient.testing().setRealmName("component-realm");
|
||||
String targetFilePath = testingClient.testing().exportImport().getExportImportTestDirectory() + File.separator + "singleFile-realm.json";
|
||||
testingClient.testing().exportImport().setFile(targetFilePath);
|
||||
testingClient.testing().exportImport().setAction(ExportImportConfig.ACTION_EXPORT);
|
||||
testingClient.testing().exportImport().setRealmName("component-realm");
|
||||
|
||||
testingClient.testing().runExport();
|
||||
testingClient.testing().exportImport().runExport();
|
||||
|
||||
// Delete some realm (and some data in admin realm)
|
||||
adminClient.realm("component-realm").remove();
|
||||
|
@ -173,9 +175,9 @@ public class ExportImportTest extends AbstractExportImportTest {
|
|||
Assert.assertEquals(3, adminClient.realms().findAll().size());
|
||||
|
||||
// Configure import
|
||||
testingClient.testing().setAction(ExportImportConfig.ACTION_IMPORT);
|
||||
testingClient.testing().exportImport().setAction(ExportImportConfig.ACTION_IMPORT);
|
||||
|
||||
testingClient.testing().runImport();
|
||||
testingClient.testing().exportImport().runImport();
|
||||
|
||||
realmRep = realm.toRepresentation();
|
||||
|
||||
|
@ -203,10 +205,10 @@ public class ExportImportTest extends AbstractExportImportTest {
|
|||
}
|
||||
|
||||
private void testFullExportImport() throws LifecycleException {
|
||||
testingClient.testing().setAction(ExportImportConfig.ACTION_EXPORT);
|
||||
testingClient.testing().setRealmName("");
|
||||
testingClient.testing().exportImport().setAction(ExportImportConfig.ACTION_EXPORT);
|
||||
testingClient.testing().exportImport().setRealmName("");
|
||||
|
||||
testingClient.testing().runExport();
|
||||
testingClient.testing().exportImport().runExport();
|
||||
|
||||
removeRealm("test");
|
||||
removeRealm("test-realm");
|
||||
|
@ -218,9 +220,9 @@ public class ExportImportTest extends AbstractExportImportTest {
|
|||
assertNotAuthenticated("test", "user3", "password");
|
||||
|
||||
// Configure import
|
||||
testingClient.testing().setAction(ExportImportConfig.ACTION_IMPORT);
|
||||
testingClient.testing().exportImport().setAction(ExportImportConfig.ACTION_IMPORT);
|
||||
|
||||
testingClient.testing().runImport();
|
||||
testingClient.testing().exportImport().runImport();
|
||||
|
||||
// Ensure data are imported back
|
||||
Assert.assertEquals(3, adminClient.realms().findAll().size());
|
||||
|
@ -232,10 +234,10 @@ public class ExportImportTest extends AbstractExportImportTest {
|
|||
}
|
||||
|
||||
private void testRealmExportImport() throws LifecycleException {
|
||||
testingClient.testing().setAction(ExportImportConfig.ACTION_EXPORT);
|
||||
testingClient.testing().setRealmName("test");
|
||||
testingClient.testing().exportImport().setAction(ExportImportConfig.ACTION_EXPORT);
|
||||
testingClient.testing().exportImport().setRealmName("test");
|
||||
|
||||
testingClient.testing().runExport();
|
||||
testingClient.testing().exportImport().runExport();
|
||||
|
||||
// Delete some realm (and some data in admin realm)
|
||||
adminClient.realm("test").remove();
|
||||
|
@ -248,9 +250,9 @@ public class ExportImportTest extends AbstractExportImportTest {
|
|||
assertNotAuthenticated("test", "user3", "password");
|
||||
|
||||
// Configure import
|
||||
testingClient.testing().setAction(ExportImportConfig.ACTION_IMPORT);
|
||||
testingClient.testing().exportImport().setAction(ExportImportConfig.ACTION_IMPORT);
|
||||
|
||||
testingClient.testing().runImport();
|
||||
testingClient.testing().exportImport().runImport();
|
||||
|
||||
// Ensure data are imported back, but just for "test" realm
|
||||
Assert.assertEquals(3, adminClient.realms().findAll().size());
|
||||
|
@ -273,27 +275,4 @@ public class ExportImportTest extends AbstractExportImportTest {
|
|||
Assert.assertEquals(expectedResult, testingClient.testing().validCredentials(realmName, username, password));
|
||||
}
|
||||
|
||||
private static String getExportImportTestDirectory() {
|
||||
String dirPath = null;
|
||||
String relativeDirExportImportPath = "testsuite" + File.separator +
|
||||
"integration-arquillian" + File.separator +
|
||||
"tests" + File.separator +
|
||||
"base" + File.separator +
|
||||
"target" + File.separator +
|
||||
"export-import";
|
||||
|
||||
if (System.getProperties().containsKey("maven.home")) {
|
||||
dirPath = System.getProperty("user.dir").replaceFirst("testsuite.integration.*", Matcher.quoteReplacement(relativeDirExportImportPath));
|
||||
} else {
|
||||
for (String c : System.getProperty("java.class.path").split(File.pathSeparator)) {
|
||||
if (c.contains(File.separator + "testsuite" + File.separator + "integration-arquillian" + File.separator)) {
|
||||
dirPath = c.replaceFirst("testsuite.integration-arquillian.*", Matcher.quoteReplacement(relativeDirExportImportPath));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String absolutePath = new File(dirPath).getAbsolutePath();
|
||||
return absolutePath;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue