Skip to content

Commit

Permalink
chore(run): add test coverage for cockpit plugins
Browse files Browse the repository at this point in the history
Related to camunda#3411
  • Loading branch information
mboskamp authored Jul 17, 2023
1 parent c056aa9 commit 335734d
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 3 deletions.
37 changes: 37 additions & 0 deletions distro/run/qa/example-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.camunda.bpm.run</groupId>
<artifactId>camunda-bpm-run-qa</artifactId>
<version>7.20.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

<artifactId>camunda-bpm-run-example-plugin</artifactId>
<name>Camunda Platform - Run - QA - Example Plugin</name>
<packaging>jar</packaging>

<dependencies>

<dependency>
<groupId>org.camunda.bpm.webapp</groupId>
<artifactId>camunda-webapp-jakarta</artifactId>
<classifier>classes</classifier>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
</dependency>

<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-web-api</artifactId>
<type>pom</type>
<scope>provided</scope>
<version>10.0.0</version>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.camunda.bpm.run.plugins;

import java.util.HashSet;
import java.util.Set;
import org.camunda.bpm.cockpit.plugin.spi.impl.AbstractCockpitPlugin;

public class TestCockpitPlugin extends AbstractCockpitPlugin {

public static final String ID = "test-cockpit-plugin";

public String getId() {
return ID;
}

@Override
public Set<Class<?>> getResourceClasses() {
Set<Class<?>> classes = new HashSet<>();

classes.add(TestCockpitResource.class);

return classes;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.camunda.bpm.run.plugins;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import org.camunda.bpm.cockpit.plugin.resource.AbstractCockpitPluginRootResource;

@Path("plugin/" + TestCockpitPlugin.ID)
public class TestCockpitResource extends AbstractCockpitPluginRootResource {

public TestCockpitResource() {
super(TestCockpitPlugin.ID);
}

@Path("test-string")
@GET
public String getTestString() {
return "test string";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.camunda.bpm.run.plugins.TestCockpitPlugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.camunda.bpm.run.qa.plugin;

import static io.restassured.RestAssured.when;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.fail;

import io.restassured.response.Response;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.Response.Status;
import org.camunda.bpm.run.qa.util.SpringBootManagedContainer;
import org.junit.After;
import org.junit.Test;

public class CockpitPluginAutoDeploymentIT {

static final String EXAMPLE_PLUGIN_HOME = "example.plugin.home";
static final String PLUGIN_ENDPOINT = "/camunda/api/cockpit/plugin/test-cockpit-plugin/test-string";

static SpringBootManagedContainer container;
static String baseDirectory = SpringBootManagedContainer.getRunHome();

protected List<String> deployedPlugins = new ArrayList<>();

@After
public void teardown() {
stopApp();
undeployPlugins();
}

public void stopApp() {
try {
if (container != null) {
container.stop();
}
} catch (Exception e) {
throw new RuntimeException("Cannot stop managed Spring Boot application!", e);
} finally {
container = null;
}
}

public void runStartScript() {
container = new SpringBootManagedContainer();
container.replaceConfigurationYml(SpringBootManagedContainer.APPLICATION_YML_PATH,
SpringBootManagedContainer.class.getClassLoader().getResourceAsStream("base-test-application.yml"));
try {
container.start();
} catch (Exception e) {
throw new RuntimeException("Cannot start managed Spring Boot application!", e);
}
}

@Test
public void shouldAutoDeployCockpitPlugin() throws IOException {
// given
deployPlugin("camunda-bpm-run-example-plugin.jar");
runStartScript();

// when
Response response = when().get(container.getBaseUrl() + PLUGIN_ENDPOINT);

// then
String responseBody = response.then()
.statusCode(Status.OK.getStatusCode())
.extract().body().asString();

assertThat(responseBody).isEqualTo("test string");
}

protected void deployPlugin(String jarName) throws IOException {
Path runUserlibDir = Paths.get(baseDirectory, SpringBootManagedContainer.USERLIB_PATH);
String pluginHome = System.getProperty(EXAMPLE_PLUGIN_HOME);

if (pluginHome == null || pluginHome.isEmpty()) {
throw new RuntimeException("System property " + EXAMPLE_PLUGIN_HOME + " not set. This property must point "
+ "to the root directory of the plugin to deploy.");
}

Path pluginPath = Paths.get(pluginHome, jarName).toAbsolutePath();
Path copy = Files.copy(pluginPath, runUserlibDir.resolve(pluginPath.getFileName()));

deployedPlugins.add(copy.toString());
}

protected void undeployPlugins() {
for (String pluginPath : deployedPlugins) {
try {
Files.delete(Paths.get(pluginPath));
} catch (IOException e) {
fail("unable to undeploy plugin " + pluginPath);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeoutException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -43,11 +42,12 @@ public class SpringBootManagedContainer {

public static final String APPLICATION_YML_PATH = "configuration/default.yml";
public static final String RESOURCES_PATH = "configuration/resources";
public static final String USERLIB_PATH = "configuration/userlib";

protected static final String BASE_TEST_APPLICATION_YML = "base-test-application.yml";
protected static final String RUN_HOME_VARIABLE = "camunda.run.home";

protected static final long RAMP_UP_SECONDS = 40;
protected static final long RAMP_UP_SECONDS = 60;
protected static final long RAMP_DOWN_SECONDS = 20;

protected static final Logger log = LoggerFactory.getLogger(SpringBootManagedContainer.class.getName());
Expand Down
2 changes: 2 additions & 0 deletions distro/run/qa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>example-plugin</module>
<module>integration-tests</module>
</modules>
</profile>
Expand All @@ -87,6 +88,7 @@
<profile>
<id>integration-test-camunda-run</id>
<modules>
<module>example-plugin</module>
<module>integration-tests</module>
<module>runtime</module>
</modules>
Expand Down
23 changes: 22 additions & 1 deletion distro/run/qa/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<properties>
<run-home>${project.build.directory}/run/camunda-bpm-run-distro</run-home>
<example-plugin-home>${project.build.directory}/run/example-plugin</example-plugin-home>
</properties>

<dependencies>
Expand Down Expand Up @@ -150,6 +151,7 @@
</dependenciesToScan>
<systemPropertyVariables>
<camunda.run.home>${run-home}</camunda.run.home>
<example.plugin.home>${example-plugin-home}</example.plugin.home>
<selenium.screenshot.directory>${project.build.directory}/selenium-screenshots</selenium.screenshot.directory>
</systemPropertyVariables>
</configuration>
Expand All @@ -167,7 +169,7 @@
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>default</id>
<id>copy-run-distro</id>
<goals>
<goal>unpack-dependencies</goal>
</goals>
Expand All @@ -182,6 +184,25 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-plugin</id>
<goals>
<goal>copy</goal>
</goals>
<phase>generate-test-resources</phase>
<configuration>
<artifact>org.camunda.bpm.run:camunda-bpm-run-example-plugin:${project.version}</artifact>
<overWriteSnapshots>true</overWriteSnapshots>
<stripVersion>true</stripVersion>
<outputDirectory>${example-plugin-home}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
Expand Down

0 comments on commit 335734d

Please sign in to comment.