Fix all tests with MySQL. Removing nested transactions

This commit is contained in:
mposolda committed 2014-02-18 11:22:19 +01:00
1 parent 1375e72cf7
commit cec57b169e
8 files changed
+16 -23

No files matched your search

@@ -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 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 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 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.
</para> </para>
<para> <para>
An <emphasis>oauth client</emphasis> is similar to an application in that it can request something like a login An <emphasis>oauth client</emphasis> is similar to an application in that it can request something like a login
@@ -16,8 +16,6 @@ import javax.persistence.Persistence;
*/ */
public class JpaModelProvider implements ModelProvider { public class JpaModelProvider implements ModelProvider {
private static final Logger logger = Logger.getLogger(JpaModelProvider.class);
@Override @Override
public String getId() { public String getId() {
return "jpa"; return "jpa";
@@ -26,7 +24,6 @@ public class JpaModelProvider implements ModelProvider {
@Override @Override
public KeycloakSessionFactory createFactory() { public KeycloakSessionFactory createFactory() {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("jpa-keycloak-identity-store", getHibernateProperties()); EntityManagerFactory emf = Persistence.createEntityManagerFactory("jpa-keycloak-identity-store", getHibernateProperties());
logger.info("RDBMS connection url: " + emf.getProperties().get("hibernate.connection.url"));
return new JpaKeycloakSessionFactory(emf); return new JpaKeycloakSessionFactory(emf);
} }
@@ -40,6 +40,14 @@ public class AbstractModelTest {
factory.close(); 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 { public static RealmRepresentation loadJson(String path) throws IOException {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(path); InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
ByteArrayOutputStream os = new ByteArrayOutputStream(); ByteArrayOutputStream os = new ByteArrayOutputStream();
@@ -96,11 +96,7 @@ public class AdapterTest extends AbstractModelTest {
String id = realmModel.getId(); String id = realmModel.getId();
System.out.println("id: " + id); System.out.println("id: " + id);
identitySession.getTransaction().commit(); commit();
identitySession.close();
identitySession = factory.createSession();
identitySession.getTransaction().begin();
realmManager = new RealmManager(identitySession);
List<RealmModel> realms = identitySession.getRealms(null); List<RealmModel> realms = identitySession.getRealms(null);
System.out.println("num realms: " + realms.size()); System.out.println("num realms: " + realms.size());
Assert.assertEquals(realms.size(), 1); Assert.assertEquals(realms.size(), 1);
@@ -99,14 +99,6 @@ public class UserModelTest extends AbstractModelTest {
Assert.assertTrue(user.getRequiredActions().isEmpty()); 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) { public static void assertEquals(UserModel expected, UserModel actual) {
Assert.assertEquals(expected.getLoginName(), actual.getLoginName()); Assert.assertEquals(expected.getLoginName(), actual.getLoginName());
Assert.assertEquals(expected.getFirstName(), actual.getFirstName()); Assert.assertEquals(expected.getFirstName(), actual.getFirstName());
@@ -29,7 +29,6 @@ public class KeycloakServerApplication extends KeycloakApplication {
session.getTransaction().begin(); session.getTransaction().begin();
RealmRepresentation rep = loadJson(new FileInputStream(importRealm), RealmRepresentation.class); RealmRepresentation rep = loadJson(new FileInputStream(importRealm), RealmRepresentation.class);
importRealm(session, rep); importRealm(session, rep);
session.getTransaction().commit();
} }
String themeDir = System.getProperty("keycloak.theme.dir"); String themeDir = System.getProperty("keycloak.theme.dir");
@@ -96,7 +96,7 @@ public class KeycloakServer {
} }
} }
private static <T> T loadJson(InputStream is, Class<T> type) { public static <T> T loadJson(InputStream is, Class<T> type) {
try { try {
return JsonSerialization.readValue(is, type); return JsonSerialization.readValue(is, type);
} catch (IOException e) { } catch (IOException e) {
@@ -41,6 +41,7 @@ import org.keycloak.testsuite.pages.LoginPage;
import org.keycloak.testsuite.rule.AbstractKeycloakRule; import org.keycloak.testsuite.rule.AbstractKeycloakRule;
import org.keycloak.testsuite.rule.WebResource; import org.keycloak.testsuite.rule.WebResource;
import org.keycloak.testsuite.rule.WebRule; import org.keycloak.testsuite.rule.WebRule;
import org.keycloak.testutils.KeycloakServer;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
import java.security.PublicKey; import java.security.PublicKey;
@@ -55,12 +56,12 @@ public class CompositeImportRoleTest {
public static AbstractKeycloakRule keycloakRule = new AbstractKeycloakRule(){ public static AbstractKeycloakRule keycloakRule = new AbstractKeycloakRule(){
@Override @Override
protected void configure(RealmManager manager, RealmModel adminRealm) { protected void configure(RealmManager manager, RealmModel adminRealm) {
server.importRealm(getClass().getResourceAsStream("/testcomposite.json")); RealmModel realm = manager.createRealm("Test");
RealmModel realm = manager.getRealmByName("Test"); RealmRepresentation representation = KeycloakServer.loadJson(getClass().getResourceAsStream("/testcomposite.json"), RealmRepresentation.class);
manager.importRealm(representation, realm);
realmPublicKey = realm.getPublicKey(); realmPublicKey = realm.getPublicKey();
deployServlet("app", "/app", ApplicationServlet.class); deployServlet("app", "/app", ApplicationServlet.class);
} }