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 16, 2024
1 parent 2c905cb commit 3b6f42e
Show file tree
Hide file tree
Showing 8 changed files with 382 additions and 1 deletion.
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
215 changes: 215 additions & 0 deletions it.tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
<?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.8-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>
<!-- OSGi -->
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
<version>7.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.cmpn</artifactId>
<version>7.0.0</version>
<scope>provided</scope>
</dependency>



<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
<scope>provided</scope>
</dependency>

<!-- 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>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>test</scope>
</dependency>


</dependencies>
</project>
92 changes: 92 additions & 0 deletions it.tests/src/main/features/groovy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"bundles": [
{
"id": "org.apache.groovy:groovy:${groovy.version}",
"start-order": "20"
},
{
"id": "org.apache.groovy:groovy-ant:${groovy.version}",
"start-order": "20"
},
{
"id": "org.apache.groovy:groovy-astbuilder:${groovy.version}",
"start-order": "20"
},
{
"id": "org.apache.groovy:groovy-cli-picocli:${groovy.version}",
"start-order": "20"
},
{
"id": "org.apache.groovy:groovy-console:${groovy.version}",
"start-order": "20"
},
{
"id": "org.apache.groovy:groovy-datetime:${groovy.version}",
"start-order": "20"
},
{
"id": "org.apache.groovy:groovy-docgenerator:${groovy.version}",
"start-order": "20"
},
{
"id": "org.apache.groovy:groovy-groovydoc:${groovy.version}",
"start-order": "20"
},
{
"id": "org.apache.groovy:groovy-groovysh:${groovy.version}",
"start-order": "20"
},
{
"id": "org.apache.groovy:groovy-jmx:${groovy.version}",
"start-order": "20"
},
{
"id": "org.apache.groovy:groovy-json:${groovy.version}",
"start-order": "20"
},
{
"id": "org.apache.groovy:groovy-jsr223:${groovy.version}",
"start-order": "20"
},
{
"id": "org.apache.groovy:groovy-macro:${groovy.version}",
"start-order": "20"
},
{
"id": "org.apache.groovy:groovy-nio:${groovy.version}",
"start-order": "20"
},
{
"id": "org.apache.groovy:groovy-servlet:${groovy.version}",
"start-order": "20"
},
{
"id": "org.apache.groovy:groovy-sql:${groovy.version}",
"start-order": "20"
},
{
"id": "org.apache.groovy:groovy-swing:${groovy.version}",
"start-order": "20"
},
{
"id": "org.apache.groovy:groovy-templates:${groovy.version}",
"start-order": "20"
},
{
"id": "org.apache.groovy:groovy-test:${groovy.version}",
"start-order": "20"
},
{
"id": "org.apache.groovy:groovy-test-junit5:${groovy.version}",
"start-order": "20"
},
{
"id": "org.apache.groovy:groovy-testng:${groovy.version}",
"start-order": "20"
},
{
"id": "org.apache.groovy:groovy-xml:${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,4 @@
package be.orbinson.aem.groovy.console.it;

public class Dummy {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package be.orbinson.aem.groovy.console.it;

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.HttpGet;
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.nio.charset.StandardCharsets;
import java.util.List;

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

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

@Test
public void testRunScript() throws Exception {
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", "println 'test'"));
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);
assertEquals("", body);
}
}
}
}
Loading

0 comments on commit 3b6f42e

Please sign in to comment.