Skip to content

Commit

Permalink
Testsuite of keycloak-admin-client in keycloak-client repository
Browse files Browse the repository at this point in the history
closes keycloak/keycloak#31867

Signed-off-by: mposolda <[email protected]>
  • Loading branch information
mposolda committed Aug 5, 2024
1 parent 0eef6ff commit 1301b5e
Show file tree
Hide file tree
Showing 18 changed files with 508 additions and 1 deletion.
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
59 changes: 59 additions & 0 deletions testsuite/admin-client-jee-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?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-testsuite</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<type>test-jar</type>
<exclusions>
<exclusion>
<artifactId>*</artifactId>
<groupId>*</groupId>
</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,12 @@
package org.keycloak.client.testsuite.adminclientjee;

/**
* @author <a href="mailto:[email protected]">Marek Posolda</a>
*/
public class ClasspathJEETest extends org.keycloak.client.testsuite.adminclient.ClasspathTest {

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

/**
* @author <a href="mailto:[email protected]">Marek Posolda</a>
*/
public class RealmsJEETest extends org.keycloak.client.testsuite.adminclient.RealmsTest {
}
46 changes: 46 additions & 0 deletions testsuite/admin-client-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-testsuite</artifactId>

<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-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Multi-Release>true</Multi-Release>
</manifestEntries>
</archive>
</configuration>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
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,36 @@
package org.keycloak.client.testsuite.adminclient;

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 ClasspathTest {

@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";
}

}
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));
}
}
40 changes: 40 additions & 0 deletions testsuite/framework/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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-client-testsuite-framework</artifactId>

<!-- No dependencies on Keycloak artifacts here -->
<dependencies>
<dependency>
<groupId>com.github.dasniko</groupId>
<artifactId>testcontainers-keycloak</artifactId>
<version>${testcontainers.keycloak.version}</version>
<exclusions>
<exclusion>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-admin-client</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-admin-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<version>${quarkus.version}</version>
</dependency>
</dependencies>

</project>
Loading

0 comments on commit 1301b5e

Please sign in to comment.