Skip to content

Commit

Permalink
Start adding integration tests, still an issue with resolving certain…
Browse files Browse the repository at this point in the history
… groovy classes
  • Loading branch information
royteeuwen committed Sep 19, 2024
1 parent 6a9e99d commit 8f444f2
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ jobs:
- name: Build
run: mvn --batch-mode --update-snapshots install

- name: Integration tests
run: mvn clean install -pl it.tests -Pit
2 changes: 1 addition & 1 deletion bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</goals>
<configuration>
<bnd><![CDATA[
Import-Package: com.day.cq.*;resolution:=optional,org.apache.commons.mail;resolution:=optional,*
Import-Package: com.day.cq.*;resolution:=optional,org.apache.commons.mail;resolution:=optional,org.apache.sling.distribution;resolution:=optional
DynamicImport-Package: *
]]></bnd>
</configuration>
Expand Down
189 changes: 189 additions & 0 deletions it.tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
<?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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>be.orbinson.aem</groupId>
<artifactId>aem-groovy-console</artifactId>
<version>19.0.9-SNAPSHOT</version>
</parent>

<artifactId>aem-groovy-console-it-tests</artifactId>
<name>AEM Groovy Console - IT Tests</name>

<repositories>
<!-- Be able to depend on the latest Sling feature releases -->
<repository>
<id>apache-snapshot</id>
<url>https://repository.apache.org/content/groups/snapshots</url>
</repository>
</repositories>

<build>
<plugins>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<executions>
<execution>
<id>bnd-process</id>
<goals>
<goal>bnd-process</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>it</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>reserve-network-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<portNames>
<portName>http.port</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.sling</groupId>
<artifactId>slingfeature-maven-plugin</artifactId>
<version>1.8.4</version>
<extensions>true</extensions>
<executions>
<execution>
<id>aggregate-features</id>
<goals>
<goal>aggregate-features</goal>
</goals>
<configuration>
<aggregates>
<aggregate>
<includeArtifact>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.starter</artifactId>
<classifier>oak_tar</classifier>
<type>slingosgifeature</type>
<version>13-SNAPSHOT</version>
</includeArtifact>
<filesInclude>*.json</filesInclude>
</aggregate>
</aggregates>
<replacePropertyVariables>groovy.version</replacePropertyVariables>
</configuration>
</execution>
<execution>
<goals>
<goal>attach-features</goal>
</goals>
<id>attach-features</id>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.sling</groupId>
<artifactId>feature-launcher-maven-plugin</artifactId>
<version>0.1.6</version>
<configuration>
<launches>
<launch>
<id>model</id>
<skip>${skipTests}</skip>
<feature>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<type>slingosgifeature</type>
</feature>

<launcherArguments>
<frameworkProperties>
<org.osgi.service.http.port>${http.port}</org.osgi.service.http.port>
</frameworkProperties>
<!-- Uncomment to enable debugging of IT tests -->
<!--<vmOptions>-->
<!-- <value>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5000</value>-->
<!--</vmOptions>-->
</launcherArguments>
<startTimeoutSeconds>180</startTimeoutSeconds>
</launch>
</launches>
</configuration>
<executions>
<execution>
<goals>
<goal>start</goal>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<systemPropertyVariables>
<HTTP_PORT>${http.port}</HTTP_PORT>
<build.log.file>${project.build.directory}/../build.log</build.log.file>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<dependencies>
<!-- Testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.14</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.11.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
8 changes: 8 additions & 0 deletions it.tests/src/main/features/groovy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"bundles": [
{
"id": "org.apache.groovy:groovy-dateutil:${groovy.version}",
"start-order": "20"
}
]
}
8 changes: 8 additions & 0 deletions it.tests/src/main/features/groovyconsole-repoinit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
create path /conf/groovyconsole/replication(sling:Folder)
create path /var/groovyconsole/audit(sling:Folder)

create service user aem-groovy-console-service with path system/aem-groovy-console
set ACL for aem-groovy-console-service
allow jcr:all on /
allow jcr:all on /var/groovyconsole/audit
end
25 changes: 25 additions & 0 deletions it.tests/src/main/features/groovyconsole.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

{
"bundles":[
{
"id": "be.orbinson.aem:groovy-osgi:${project.version}",
"start-order": "19"
},
{
"id":"be.orbinson.aem:aem-groovy-console-api:${project.version}",
"start-order":"20"
},
{
"id":"be.orbinson.aem:aem-groovy-console-bundle:${project.version}",
"start-order":"20"
}
],
"configurations": {
"org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended~groovyconsole":{
"user.mapping":[
"aem-groovy-console-bundle=[aem-groovy-console-service]"
]
}
},
"repoinit:TEXT|true":"@file"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package be.orbinson.aem.groovy.console.it;

import com.google.gson.Gson;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class GroovyConsoleServiceIT {
private static final int SLING_PORT = Integer.getInteger("HTTP_PORT", 8080);

@Test
void testScriptReturnsResult() throws Exception {
String script = "print 'test'";
Map response = executeScript(script);
assertEquals("test", response.get("output"));
}

private static Map executeScript(String script) throws IOException {
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
HttpPost executeScript = new HttpPost("http://localhost:" + SLING_PORT + "/bin/groovyconsole/post");
List<BasicNameValuePair> basicNameValuePairs = new java.util.ArrayList<>();
basicNameValuePairs.add(new BasicNameValuePair("script", script));
executeScript.setEntity(new UrlEncodedFormEntity(basicNameValuePairs, StandardCharsets.UTF_8));
executeScript.addHeader("Authorization", "Basic " + Base64.encodeBase64String("admin:admin".getBytes(StandardCharsets.UTF_8)));
try (CloseableHttpResponse response = httpclient.execute(executeScript)) {
String body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
return new Gson().fromJson(body, Map.class);
}
}
}
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<module>ui.apps.aem</module>
<module>ui.config</module>
<module>ui.content</module>
<module>it.tests</module>
</modules>

<url>https://github.com/orbinson/aem-groovy-console</url>
Expand Down

0 comments on commit 8f444f2

Please sign in to comment.