Skip to content

Commit e6620ca

Browse files
author
vramik
committed
arquillian-testsuite added initial version of migration test
1 parent 480444f commit e6620ca

File tree

9 files changed

+1067
-155
lines changed

9 files changed

+1067
-155
lines changed

testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/ContainersTestEnricher.java

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
package org.keycloak.testsuite.arquillian;
22

3+
import java.io.File;
4+
import java.io.IOException;
35
import java.net.MalformedURLException;
46
import java.net.URL;
7+
import java.util.LinkedList;
8+
import org.apache.commons.io.FileUtils;
9+
import org.jboss.arquillian.container.spi.Container;
10+
import org.jboss.arquillian.container.spi.ContainerRegistry;
511
import org.jboss.arquillian.container.spi.event.StartSuiteContainers;
612
import org.jboss.arquillian.container.spi.event.StopSuiteContainers;
713
import org.jboss.arquillian.container.test.api.ContainerController;
@@ -33,13 +39,16 @@
3339
public class ContainersTestEnricher {
3440

3541
protected final Logger log = Logger.getLogger(this.getClass());
36-
42+
3743
@Inject
3844
private Instance<ContainerController> containerController;
3945

46+
@Inject
47+
private Instance<ContainerRegistry> containerRegistry;
48+
4049
@Inject
4150
private Event<StopSuiteContainers> stopSuiteContainers;
42-
51+
4352
private String appServerQualifier;
4453

4554
private static final String AUTH_SERVER_CONTAINER_PROPERTY = "auth.server.container";
@@ -62,24 +71,77 @@ public class ContainersTestEnricher {
6271
private InstanceProducer<OAuthClient> oauthClient;
6372

6473
private ContainerController controller;
74+
private LinkedList<Container> containers;
6575

6676
private final boolean migrationTests = System.getProperty("migration", "false").equals("true");
6777
private boolean alreadyStopped = false;
78+
private boolean init = false;
79+
80+
private void init() {
81+
if (!init) {
82+
containers = new LinkedList(containerRegistry.get().getContainers());
83+
}
84+
init = true;
85+
}
6886

87+
/*
88+
* non-javadoc
89+
*
90+
* Before starting suite containers. Initialization of containers is done
91+
* (only once during class life cycle)
92+
*/
6993
public void startSuiteContainers(@Observes(precedence = 1) StartSuiteContainers event) {
94+
init();
7095
if (migrationTests) {
71-
log.info("\n### Starting keycloak with previous version ###\n");
96+
log.info("\n\n### Starting keycloak with previous version ###\n");
7297
}
7398
}
7499

75-
public void stopMigrationContainer(@Observes AfterStart event) {
100+
/*
101+
* non-javadoc
102+
*
103+
* After start container. Server logs are checked (in case jboss based container).
104+
* In case of migration scenario: previous container is stopped.
105+
*/
106+
public void afterStart(@Observes AfterStart event) throws IOException {
107+
if (System.getProperty("check.server.log", "true").equals("true")) {
108+
checkServerLog();
109+
}
110+
76111
if (migrationTests && !alreadyStopped) {
77-
log.info("\n### Stopping keycloak with previous version ###\n");
112+
log.info("\n\n### Stopping keycloak with previous version ###\n");
78113
stopSuiteContainers.fire(new StopSuiteContainers());
114+
log.info("\n\n### Starting keycloak with current version ###\n");
79115
}
80116
alreadyStopped = true;
81117
}
82-
118+
119+
/*
120+
* non-javadoc
121+
*
122+
* check server logs (in case jboss based container) whether there are no ERRORs or SEVEREs
123+
*/
124+
private void checkServerLog() throws IOException {
125+
Container container = containers.removeFirst();
126+
if (!container.getName().equals("auth-server-undertow")) {
127+
String jbossHomePath = container.getContainerConfiguration().getContainerProperties().get("jbossHome");
128+
log.debug("jbossHome: " + jbossHomePath + "\n");
129+
130+
String serverLogContent = FileUtils.readFileToString(new File(jbossHomePath + "/standalone/log/server.log"));
131+
132+
boolean containsError
133+
= serverLogContent.contains("ERROR")
134+
|| serverLogContent.contains("SEVERE")
135+
|| serverLogContent.contains("Exception ");
136+
//There is expected string "Exception" in server log: Adding provider
137+
//singleton org.keycloak.services.resources.ModelExceptionMapper
138+
139+
if (containsError) {
140+
throw new RuntimeException(container.getName() + ": Server log contains ERROR.");
141+
}
142+
}
143+
}
144+
83145
public void beforeSuite(@Observes BeforeSuite event) {
84146
suiteContext.set(new SuiteContext());
85147
}

testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/KeycloakArquillianExtension.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.jboss.arquillian.test.spi.enricher.resource.ResourceProvider;
1111
import org.jboss.arquillian.test.spi.execution.TestExecutionDecider;
1212
import org.keycloak.testsuite.arquillian.jira.JiraTestExecutionDecider;
13+
import org.keycloak.testsuite.arquillian.migration.MigrationTestExecutionDecider;
1314
import org.keycloak.testsuite.arquillian.undertow.CustomUndertowContainer;
1415

1516
/**
@@ -36,7 +37,8 @@ public void register(ExtensionBuilder builder) {
3637
.service(DeployableContainer.class, CustomUndertowContainer.class);
3738

3839
builder
39-
.service(TestExecutionDecider.class, JiraTestExecutionDecider.class);
40+
.service(TestExecutionDecider.class, JiraTestExecutionDecider.class)
41+
.service(TestExecutionDecider.class, MigrationTestExecutionDecider.class);
4042

4143
builder
4244
.override(ResourceProvider.class, URLResourceProvider.class, URLProvider.class)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* JBoss, Home of Professional Open Source.
3+
* Copyright 2012, Red Hat, Inc., and individual contributors
4+
* as indicated by the @author tags. See the copyright.txt file in the
5+
* distribution for a full listing of individual contributors.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
*/
22+
package org.keycloak.testsuite.arquillian.migration;
23+
24+
import java.lang.annotation.Documented;
25+
import java.lang.annotation.ElementType;
26+
import java.lang.annotation.Retention;
27+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
28+
import java.lang.annotation.Target;
29+
30+
/**
31+
*
32+
* @author <a href="mailto:[email protected]">Vlastislav Ramik</a>
33+
*/
34+
@Documented
35+
@Retention(RUNTIME)
36+
@Target({ElementType.METHOD})
37+
public @interface Migration {
38+
String versionFrom();
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* JBoss, Home of Professional Open Source.
3+
* Copyright 2012, Red Hat, Inc., and individual contributors
4+
* as indicated by the @author tags. See the copyright.txt file in the
5+
* distribution for a full listing of individual contributors.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
*/
22+
package org.keycloak.testsuite.arquillian.migration;
23+
24+
import java.lang.reflect.Method;
25+
import org.jboss.arquillian.test.spi.execution.ExecutionDecision;
26+
import org.jboss.arquillian.test.spi.execution.TestExecutionDecider;
27+
28+
/**
29+
* @author <a href="mailto:[email protected]">Vlastislav Ramik</a>
30+
*/
31+
public class MigrationTestExecutionDecider implements TestExecutionDecider {
32+
33+
@Override
34+
public ExecutionDecision decide(Method method) {
35+
36+
boolean migrationTest = "true".equals(System.getProperty("migration", "false"));
37+
Migration migrationAnnotation = method.getAnnotation(Migration.class);
38+
39+
if (migrationTest && migrationAnnotation != null) {
40+
String versionFrom = migrationAnnotation.versionFrom();
41+
String version = System.getProperty("version");
42+
43+
44+
if (version.equals(versionFrom)) {
45+
return ExecutionDecision.execute();
46+
} else {
47+
return ExecutionDecision.dontExecute(method.getName() + "doesn't fit with migration version.");
48+
}
49+
}
50+
if ((migrationTest && migrationAnnotation == null) || (!migrationTest && migrationAnnotation != null)) {
51+
return ExecutionDecision.dontExecute("Migration test and no migration annotation or no migration test and migration annotation");
52+
}
53+
return ExecutionDecision.execute();
54+
}
55+
56+
@Override
57+
public int precedence() {
58+
return 1;
59+
}
60+
61+
}

testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/AbstractKeycloakTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public void beforeAbstractKeycloakTest() {
8686
driverSettings();
8787

8888
if (!suiteContext.isAdminPasswordUpdated()) {
89+
log.debug("updating admin password");
8990
updateMasterAdminPassword();
9091
suiteContext.setAdminPasswordUpdated(true);
9192
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* JBoss, Home of Professional Open Source.
3+
* Copyright 2012, Red Hat, Inc., and individual contributors
4+
* as indicated by the @author tags. See the copyright.txt file in the
5+
* distribution for a full listing of individual contributors.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
*/
22+
package org.keycloak.testsuite.migration;
23+
24+
import org.junit.Test;
25+
import org.keycloak.representations.idm.RealmRepresentation;
26+
import org.keycloak.testsuite.AbstractAuthTest;
27+
import org.keycloak.testsuite.arquillian.migration.Migration;
28+
29+
/**
30+
* @author <a href="mailto:[email protected]">Vlastislav Ramik</a>
31+
*/
32+
public class MigrationTest extends AbstractAuthTest {
33+
34+
@Test
35+
@Migration(versionFrom = "1.6.0.Final")
36+
public void migration16Test() {
37+
for (RealmRepresentation realm : adminClient.realms().findAll()) {
38+
System.out.println(realm.getRealm());
39+
}
40+
41+
throw new RuntimeException("TODO");
42+
}
43+
44+
}

testsuite/integration-arquillian/tests/base/src/test/resources/arquillian.xml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,16 @@
2525
<configuration>
2626
<property name="enabled">${migration.kc16}</property>
2727
<property name="adapterImplClass">org.jboss.as.arquillian.container.managed.ManagedDeployableContainer</property>
28-
<property name="jbossHome">${keycloak-1.6.0.Final.home}</property>
29-
<property name="javaVmArguments">-Djboss.socket.binding.port-offset=${auth.server.port.offset} -Xms64m -Xmx512m -XX:MaxPermSize=256m</property>
28+
<property name="jbossHome">${keycloak.migration.home}</property>
29+
<property name="javaVmArguments">
30+
-Dkeycloak.migration.action=import
31+
-Dkeycloak.migration.provider=singleFile
32+
-Dkeycloak.migration.file=${keycloak.migration.file}
33+
-Dkeycloak.migration.strategy=OVERWRITE_EXISTING
34+
-Dkeycloak.migration.realmName=Migration
35+
-Djboss.socket.binding.port-offset=${auth.server.port.offset}
36+
-Xms64m -Xmx512m -XX:MaxPermSize=256m
37+
</property>
3038
<property name="managementPort">${auth.server.management.port}</property>
3139
<property name="startupTimeoutInSeconds">${startup.timeout.sec}</property>
3240
</configuration>
@@ -36,7 +44,7 @@
3644
<configuration>
3745
<property name="enabled">${migration.kc15}</property>
3846
<property name="adapterImplClass">org.jboss.as.arquillian.container.managed.ManagedDeployableContainer</property>
39-
<property name="jbossHome">${keycloak-1.5.1.Final.home}</property>
47+
<property name="jbossHome">${keycloak.migration.homev}</property>
4048
<property name="javaVmArguments">-Djboss.socket.binding.port-offset=${auth.server.port.offset} -Xms64m -Xmx512m -XX:MaxPermSize=256m</property>
4149
<property name="managementPort">${auth.server.management.port}</property>
4250
<property name="startupTimeoutInSeconds">${startup.timeout.sec}</property>
@@ -47,7 +55,7 @@
4755
<configuration>
4856
<property name="enabled">${migration.kc14}</property>
4957
<property name="adapterImplClass">org.jboss.as.arquillian.container.managed.ManagedDeployableContainer</property>
50-
<property name="jbossHome">${keycloak-1.4.0.Final.home}</property>
58+
<property name="jbossHome">${keycloak.migration.home}</property>
5159
<property name="javaVmArguments">-Djboss.socket.binding.port-offset=${auth.server.port.offset} -Xms64m -Xmx512m -XX:MaxPermSize=256m</property>
5260
<property name="managementPort">${auth.server.management.port}</property>
5361
<property name="startupTimeoutInSeconds">${startup.timeout.sec}</property>
@@ -58,7 +66,7 @@
5866
<configuration>
5967
<property name="enabled">${migration.kc13}</property>
6068
<property name="adapterImplClass">org.jboss.as.arquillian.container.managed.ManagedDeployableContainer</property>
61-
<property name="jbossHome">${keycloak-1.3.1.Final.home}</property>
69+
<property name="jbossHome">${keycloak.migration.home}</property>
6270
<property name="javaVmArguments">-Djboss.socket.binding.port-offset=${auth.server.port.offset} -Xms64m -Xmx512m -XX:MaxPermSize=256m</property>
6371
<property name="managementPort">${auth.server.management.port}</property>
6472
<property name="startupTimeoutInSeconds">${startup.timeout.sec}</property>
@@ -69,7 +77,7 @@
6977
<configuration>
7078
<property name="enabled">${migration.kc12}</property>
7179
<property name="adapterImplClass">org.jboss.as.arquillian.container.managed.ManagedDeployableContainer</property>
72-
<property name="jbossHome">${keycloak-1.2.0.Final.home}</property>
80+
<property name="jbossHome">${keycloak.migration.homee}</property>
7381
<property name="javaVmArguments">-Djboss.socket.binding.port-offset=${auth.server.port.offset} -Xms64m -Xmx512m -XX:MaxPermSize=256m</property>
7482
<property name="managementPort">${auth.server.management.port}</property>
7583
<property name="startupTimeoutInSeconds">${startup.timeout.sec}</property>

0 commit comments

Comments
 (0)