From cec57b169e9be657f0bd18ce73e19437d3a7efb8 Mon Sep 17 00:00:00 2001 From: mposolda Date: Mon, 17 Feb 2014 18:11:41 +0100 Subject: [PATCH] Fix all tests with MySQL. Removing nested transactions --- docbook/reference/en/en-US/modules/Overview.xml | 2 +- .../java/org/keycloak/models/jpa/JpaModelProvider.java | 3 --- .../java/org/keycloak/model/test/AbstractModelTest.java | 8 ++++++++ .../test/java/org/keycloak/model/test/AdapterTest.java | 6 +----- .../test/java/org/keycloak/model/test/UserModelTest.java | 8 -------- .../org/keycloak/server/KeycloakServerApplication.java | 1 - .../main/java/org/keycloak/testutils/KeycloakServer.java | 2 +- .../testsuite/composites/CompositeImportRoleTest.java | 9 +++++---- 8 files changed, 16 insertions(+), 23 deletions(-) diff --git a/docbook/reference/en/en-US/modules/Overview.xml b/docbook/reference/en/en-US/modules/Overview.xml index dda24860c3..6dbf2a5eb8 100755 --- a/docbook/reference/en/en-US/modules/Overview.xml +++ b/docbook/reference/en/en-US/modules/Overview.xml @@ -78,7 +78,7 @@ Once a user is logged in, they can visit any other application managed by the realm and not have to re-enter credentials. This also hold true for logging out. Roles can also be defined at the application level and assigned to specific users. Depending on the application type, you may also be able to view and manage - user sessions from the adminstration console. + user sessions from the administration console. An oauth client is similar to an application in that it can request something like a login diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/JpaModelProvider.java b/model/jpa/src/main/java/org/keycloak/models/jpa/JpaModelProvider.java index 56b0a90b81..03473e5d41 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/JpaModelProvider.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/JpaModelProvider.java @@ -16,8 +16,6 @@ import javax.persistence.Persistence; */ public class JpaModelProvider implements ModelProvider { - private static final Logger logger = Logger.getLogger(JpaModelProvider.class); - @Override public String getId() { return "jpa"; @@ -26,7 +24,6 @@ public class JpaModelProvider implements ModelProvider { @Override public KeycloakSessionFactory createFactory() { EntityManagerFactory emf = Persistence.createEntityManagerFactory("jpa-keycloak-identity-store", getHibernateProperties()); - logger.info("RDBMS connection url: " + emf.getProperties().get("hibernate.connection.url")); return new JpaKeycloakSessionFactory(emf); } diff --git a/model/tests/src/test/java/org/keycloak/model/test/AbstractModelTest.java b/model/tests/src/test/java/org/keycloak/model/test/AbstractModelTest.java index 1f2fda1be3..f334236650 100644 --- a/model/tests/src/test/java/org/keycloak/model/test/AbstractModelTest.java +++ b/model/tests/src/test/java/org/keycloak/model/test/AbstractModelTest.java @@ -40,6 +40,14 @@ public class AbstractModelTest { factory.close(); } + protected void commit() { + identitySession.getTransaction().commit(); + identitySession.close(); + identitySession = factory.createSession(); + identitySession.getTransaction().begin(); + realmManager = new RealmManager(identitySession); + } + public static RealmRepresentation loadJson(String path) throws IOException { InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(path); ByteArrayOutputStream os = new ByteArrayOutputStream(); diff --git a/model/tests/src/test/java/org/keycloak/model/test/AdapterTest.java b/model/tests/src/test/java/org/keycloak/model/test/AdapterTest.java index 6bd1f07bd1..cd18852239 100755 --- a/model/tests/src/test/java/org/keycloak/model/test/AdapterTest.java +++ b/model/tests/src/test/java/org/keycloak/model/test/AdapterTest.java @@ -96,11 +96,7 @@ public class AdapterTest extends AbstractModelTest { String id = realmModel.getId(); System.out.println("id: " + id); - identitySession.getTransaction().commit(); - identitySession.close(); - identitySession = factory.createSession(); - identitySession.getTransaction().begin(); - realmManager = new RealmManager(identitySession); + commit(); List realms = identitySession.getRealms(null); System.out.println("num realms: " + realms.size()); Assert.assertEquals(realms.size(), 1); diff --git a/model/tests/src/test/java/org/keycloak/model/test/UserModelTest.java b/model/tests/src/test/java/org/keycloak/model/test/UserModelTest.java index 6567e19971..89bc061cd5 100755 --- a/model/tests/src/test/java/org/keycloak/model/test/UserModelTest.java +++ b/model/tests/src/test/java/org/keycloak/model/test/UserModelTest.java @@ -99,14 +99,6 @@ public class UserModelTest extends AbstractModelTest { Assert.assertTrue(user.getRequiredActions().isEmpty()); } - protected void commit() { - identitySession.getTransaction().commit(); - identitySession.close(); - identitySession = factory.createSession(); - identitySession.getTransaction().begin(); - realmManager = new RealmManager(identitySession); - } - public static void assertEquals(UserModel expected, UserModel actual) { Assert.assertEquals(expected.getLoginName(), actual.getLoginName()); Assert.assertEquals(expected.getFirstName(), actual.getFirstName()); diff --git a/server/src/main/java/org/keycloak/server/KeycloakServerApplication.java b/server/src/main/java/org/keycloak/server/KeycloakServerApplication.java index fdcdaa4e57..fc9331a1de 100755 --- a/server/src/main/java/org/keycloak/server/KeycloakServerApplication.java +++ b/server/src/main/java/org/keycloak/server/KeycloakServerApplication.java @@ -29,7 +29,6 @@ public class KeycloakServerApplication extends KeycloakApplication { session.getTransaction().begin(); RealmRepresentation rep = loadJson(new FileInputStream(importRealm), RealmRepresentation.class); importRealm(session, rep); - session.getTransaction().commit(); } String themeDir = System.getProperty("keycloak.theme.dir"); diff --git a/testsuite/integration/src/main/java/org/keycloak/testutils/KeycloakServer.java b/testsuite/integration/src/main/java/org/keycloak/testutils/KeycloakServer.java index ebd181b93e..6fbb6fde19 100755 --- a/testsuite/integration/src/main/java/org/keycloak/testutils/KeycloakServer.java +++ b/testsuite/integration/src/main/java/org/keycloak/testutils/KeycloakServer.java @@ -96,7 +96,7 @@ public class KeycloakServer { } } - private static T loadJson(InputStream is, Class type) { + public static T loadJson(InputStream is, Class type) { try { return JsonSerialization.readValue(is, type); } catch (IOException e) { diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/composites/CompositeImportRoleTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/composites/CompositeImportRoleTest.java index ddd15ed166..dfb2fc9253 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/composites/CompositeImportRoleTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/composites/CompositeImportRoleTest.java @@ -41,6 +41,7 @@ import org.keycloak.testsuite.pages.LoginPage; import org.keycloak.testsuite.rule.AbstractKeycloakRule; import org.keycloak.testsuite.rule.WebResource; import org.keycloak.testsuite.rule.WebRule; +import org.keycloak.testutils.KeycloakServer; import org.openqa.selenium.WebDriver; import java.security.PublicKey; @@ -55,12 +56,12 @@ public class CompositeImportRoleTest { public static AbstractKeycloakRule keycloakRule = new AbstractKeycloakRule(){ @Override protected void configure(RealmManager manager, RealmModel adminRealm) { - server.importRealm(getClass().getResourceAsStream("/testcomposite.json")); - RealmModel realm = manager.getRealmByName("Test"); + RealmModel realm = manager.createRealm("Test"); + RealmRepresentation representation = KeycloakServer.loadJson(getClass().getResourceAsStream("/testcomposite.json"), RealmRepresentation.class); + manager.importRealm(representation, realm); + realmPublicKey = realm.getPublicKey(); - - deployServlet("app", "/app", ApplicationServlet.class); }