KEYCLOAK-6146 Simplify test via RealmCreator
This commit is contained in:
parent
e3153295a9
commit
b3766576d7
2 changed files with 23 additions and 21 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2016 Red Hat, Inc. and/or its affiliates
|
||||
* Copyright 2018 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");
|
||||
|
@ -16,28 +16,35 @@
|
|||
*/
|
||||
package org.keycloak.testsuite.updaters;
|
||||
|
||||
import org.keycloak.admin.client.Keycloak;
|
||||
import java.io.Closeable;
|
||||
import javax.ws.rs.NotFoundException;
|
||||
import org.keycloak.admin.client.resource.RealmResource;
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:vramik@redhat.com">Vlastislav Ramik</a>
|
||||
* Creates a temporary realm and makes sure it is removed.
|
||||
*/
|
||||
public class RealmRemover {
|
||||
public class RealmCreator implements Closeable {
|
||||
|
||||
private final RealmResource realmResource;
|
||||
|
||||
public RealmRemover(RealmResource realmResource) {
|
||||
this.realmResource = realmResource;
|
||||
public RealmCreator(Keycloak adminClient, RealmRepresentation rep) {
|
||||
adminClient.realms().create(rep);
|
||||
this.realmResource = adminClient.realm(rep.getRealm());
|
||||
}
|
||||
|
||||
public Closeable remove() {
|
||||
return () -> {
|
||||
public RealmResource realm() {
|
||||
return this.realmResource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
try {
|
||||
realmResource.remove();
|
||||
} catch (NotFoundException e) {
|
||||
}
|
||||
};
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
|
@ -52,7 +52,7 @@ import org.keycloak.testsuite.auth.page.AuthRealm;
|
|||
import org.keycloak.testsuite.client.KeycloakTestingClient;
|
||||
import org.keycloak.testsuite.runonserver.RunOnServerDeployment;
|
||||
import org.keycloak.testsuite.runonserver.RunHelpers;
|
||||
import org.keycloak.testsuite.updaters.RealmRemover;
|
||||
import org.keycloak.testsuite.updaters.RealmCreator;
|
||||
import org.keycloak.testsuite.util.AdminEventPaths;
|
||||
import org.keycloak.testsuite.util.ClientBuilder;
|
||||
import org.keycloak.testsuite.util.CredentialBuilder;
|
||||
|
@ -224,14 +224,9 @@ public class RealmTest extends AbstractAdminTest {
|
|||
//KEYCLOAK-6146
|
||||
@Test
|
||||
public void createRealmWithPasswordPolicyFromJsonWithValidPasswords() throws IOException {
|
||||
//realm with password policies and users have passwords in correct state
|
||||
RealmRepresentation rep = loadJson(getClass().getResourceAsStream("/import/testrealm-keycloak-6146.json"), RealmRepresentation.class);
|
||||
adminClient.realms().create(rep);
|
||||
|
||||
RealmResource secureApp = adminClient.realms().realm("secure-app");
|
||||
RealmRepresentation created = secureApp.toRepresentation();
|
||||
|
||||
try (Closeable c = new RealmRemover(secureApp).remove()) {
|
||||
try (RealmCreator c = new RealmCreator(adminClient, rep)) {
|
||||
RealmRepresentation created = c.realm().toRepresentation();
|
||||
assertRealm(rep, created);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue