Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testsuite of keycloak-admin-client in keycloak-client repository #16

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ quarkus/data/*.db

# Jakarta transformed sources #
###############################
/integration/admin-client/src/
/adapters/saml/jakarta-servlet-filter/src/
/adapters/oidc/jakarta-servlet-filter/src/
/testsuite/admin-client-tests/src/test/java/org/keycloak/client/testsuite/adminclient/
/.metadata/

# Git ephemeral files
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,26 @@

Keycloak-client java modules

## Building the project

```
mvn clean install -DskipTests=true
```

## Running the testsuite

```
cd testsuite
mvn clean install
```

By default testsuite starts Keycloak server inside docker image, which is based on testcontainers. So it uses white-box testing from the point of view of the Keycloak server.

When running with the argument `keycloak.lifecycle` like:

```
mvn clean install -Dkeycloak.lifecycle=remote
```

The testsuite won't start the Keycloak server, but instead tests will try to use Keycloak server, which is already started on this laptop where testsuite is running.

13 changes: 12 additions & 1 deletion admin-client-jee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
<artifactId>keycloak-client-parent</artifactId>
<groupId>org.keycloak</groupId>
<version>26.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>keycloak-admin-client-jee</artifactId>
<name>Keycloak Admin REST Client</name>
<name>Keycloak Admin JEE REST Client</name>
<description/>

<dependencies>
Expand Down Expand Up @@ -56,6 +57,16 @@
<artifactId>resteasy-client</artifactId>
<version>${resteasy-legacy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-core</artifactId>
<version>${resteasy-legacy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-core-spi</artifactId>
<version>${resteasy-legacy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-multipart-provider</artifactId>
Expand Down
1 change: 1 addition & 0 deletions admin-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<artifactId>keycloak-client-parent</artifactId>
<groupId>org.keycloak</groupId>
<version>26.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
<module>admin-client-jee</module>
<module>authz-client</module>
<module>policy-enforcer</module>
<module>testsuite</module>
</modules>

<dependencyManagement>
Expand Down Expand Up @@ -170,6 +171,11 @@
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${com.fasterxml.jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>${com.fasterxml.jackson.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>commons-logging-jboss-logging</artifactId>
Expand Down
46 changes: 46 additions & 0 deletions testsuite/admin-client-jee-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-client-testsuite-parent</artifactId>
<version>26.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>keycloak-admin-client-jee-testsuite</artifactId>

<properties>
<resteasy.version>${resteasy-legacy.version}</resteasy.version>
</properties>

<dependencies>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-client-testsuite-framework</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-admin-client</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-admin-client-jee</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.smallrye.config</groupId>
<artifactId>smallrye-config</artifactId>
<version>${smallrye.config.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.keycloak.client.testsuite;

import java.lang.reflect.Field;

import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.junit.jupiter.api.Test;
import org.keycloak.admin.client.Keycloak;
import org.testcontainers.shaded.org.hamcrest.MatcherAssert;

import static org.testcontainers.shaded.org.hamcrest.Matchers.equalTo;

/**
* @author <a href="mailto:[email protected]">Marek Posolda</a>
*/
public class ClasspathJEETest {

@Test
public void testCorrectResteasyClient() throws Exception {
Field clientField = Keycloak.class.getDeclaredField("client");
Class clientFieldClass = clientField.getType();
MatcherAssert.assertThat(getExpectedClientFieldClass(), equalTo(clientFieldClass.getName()));
}

@Test
public void testResteasyVersion() throws Exception {
Class resteasyClientSuperclass = ResteasyClient.class.getInterfaces()[0];
MatcherAssert.assertThat(getExpectedClientFieldClass(), equalTo(resteasyClientSuperclass.getName()));
}

protected String getExpectedClientFieldClass() {
return "javax.ws.rs.client.Client";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.keycloak.client.testsuite.adminclient;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.keycloak.admin.client.Keycloak;
import org.keycloak.client.testsuite.KeycloakContainersTestsuiteContext;
import org.keycloak.client.testsuite.RemoteTestsuiteContext;
import org.keycloak.client.testsuite.TestsuiteContext;

/**
* @author <a href="mailto:[email protected]">Marek Posolda</a>
*/
public abstract class AbstractAdminClientTest {

private static TestsuiteContext testsuiteContext;
protected static Keycloak adminClient;

@BeforeAll
public static void beforeAll() {
String keycloakLifecycle = System.getProperty("keycloak.lifecycle");
testsuiteContext = "remote".equalsIgnoreCase(keycloakLifecycle) ? new RemoteTestsuiteContext() : new KeycloakContainersTestsuiteContext();

testsuiteContext.startKeycloakServer();
adminClient = testsuiteContext.getKeycloakAdminClient();
}

@AfterAll
public static void afterAll() {
testsuiteContext.stopKeycloakServer();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.keycloak.client.testsuite.adminclient;

import java.util.List;

import org.junit.jupiter.api.Test;
import org.keycloak.client.testsuite.TestConstants;
import org.keycloak.representations.idm.RealmRepresentation;
import org.testcontainers.shaded.org.hamcrest.MatcherAssert;
import org.testcontainers.shaded.org.hamcrest.Matchers;

/**
* @author <a href="mailto:[email protected]">Marek Posolda</a>
*/
public class RealmsTest extends AbstractAdminClientTest {

@Test
public void realmsList() {
List<RealmRepresentation> realms = adminClient.realms().findAll();
MatcherAssert.assertThat(realms.stream()
.map(RealmRepresentation::getRealm)
.filter(realmName -> TestConstants.MASTER_REALM.equals(realmName))
.findFirst()
.isPresent(), Matchers.is(true));
}
}
89 changes: 89 additions & 0 deletions testsuite/admin-client-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-client-testsuite-parent</artifactId>
<version>26.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>keycloak-admin-client-testsuite</artifactId>

<properties>
<!-- Tests from this directory will be copied from "admin-client-jee-tests" -->
<admin-client-tests-root-dir>src/test/java/org/keycloak/client/testsuite/adminclient</admin-client-tests-root-dir>

<jakarta-transformer-sources>${project.basedir}/../admin-client-jee-tests/${admin-client-tests-root-dir}</jakarta-transformer-sources>
<jakarta-transformer-target>${project.basedir}/${admin-client-tests-root-dir}</jakarta-transformer-target>
</properties>

<dependencies>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-client-testsuite-framework</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<!-- delete the files created by the transformer -->
<directory>${admin-client-tests-root-dir}</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>transform</id>
<phase>initialize</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<property name="plugin_classpath" refid="maven.plugin.classpath"/>
<delete dir="${jakarta-transformer-target}"/>
<java classname="org.eclipse.transformer.cli.JakartaTransformerCLI" fork="true">
<arg value="${jakarta-transformer-sources}"/>
<arg value="${jakarta-transformer-target}"/>
<classpath>
<pathelement path="${plugin_classpath}"/>
</classpath>
</java>
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.eclipse.transformer</groupId>
<artifactId>org.eclipse.transformer.cli</artifactId>
<version>0.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.10.14</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.keycloak.client.testsuite;

import java.lang.reflect.Field;

import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.junit.jupiter.api.Test;
import org.keycloak.admin.client.Keycloak;
import org.testcontainers.shaded.org.hamcrest.MatcherAssert;

import static org.testcontainers.shaded.org.hamcrest.Matchers.equalTo;

/**
* Test that I have correct versions of admin-client (admin-client VS admin-client-jee) and corresponding libraries on classpath
*
* @author <a href="mailto:[email protected]">Marek Posolda</a>
*/
public class ClasspathJakartaTest {

@Test
public void testCorrectResteasyClient() throws Exception {
Field clientField = Keycloak.class.getDeclaredField("client");
Class clientFieldClass = clientField.getType();
MatcherAssert.assertThat(getExpectedClientFieldClass(), equalTo(clientFieldClass.getName()));
}

@Test
public void testResteasyVersion() throws Exception {
Class resteasyClientSuperclass = ResteasyClient.class.getInterfaces()[0];
MatcherAssert.assertThat(getExpectedClientFieldClass(), equalTo(resteasyClientSuperclass.getName()));
}

protected String getExpectedClientFieldClass() {
return "jakarta.ws.rs.client.Client";
}

}
Loading