forked from camunda/camunda-bpm-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(run): add test coverage for cockpit plugins
Related to camunda#3411
- Loading branch information
Showing
8 changed files
with
253 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
39 changes: 39 additions & 0 deletions
39
...ro/run/qa/example-plugin/src/main/java/org/camunda/bpm/run/plugins/TestCockpitPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
.../run/qa/example-plugin/src/main/java/org/camunda/bpm/run/plugins/TestCockpitResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...gin/src/main/resources/META-INF/services/org.camunda.bpm.cockpit.plugin.spi.CockpitPlugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.camunda.bpm.run.plugins.TestCockpitPlugin |
115 changes: 115 additions & 0 deletions
115
...tion-tests/src/test/java/org/camunda/bpm/run/qa/plugin/CockpitPluginAutoDeploymentIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters