Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
run: ./mvnw clean install -B -q -DskipITs=true
- name: Codecov
uses: codecov/[email protected]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why lower the version here?

with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload test report for sdk
uses: actions/upload-artifact@v5
with:
Expand Down
6 changes: 6 additions & 0 deletions spring-boot-examples/workflows/patterns/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
<artifactId>microcks-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-postgresql</artifactId>
<version>2.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

package io.dapr.springboot.examples.wfp;


import io.dapr.testcontainers.Component;
import io.dapr.testcontainers.DaprContainer;
import io.dapr.testcontainers.DaprLogLevel;
import io.dapr.testcontainers.WorkflowDashboardContainer;
import io.github.microcks.testcontainers.MicrocksContainersEnsemble;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
Expand All @@ -26,9 +27,12 @@
import org.springframework.test.context.DynamicPropertyRegistrar;
import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.Network;
import org.testcontainers.postgresql.PostgreSQLContainer;
import org.testcontainers.utility.DockerImageName;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static io.dapr.testcontainers.DaprContainerConstants.DAPR_RUNTIME_IMAGE_TAG;

Expand All @@ -45,19 +49,44 @@
@TestConfiguration(proxyBeanMethods = false)
public class DaprTestContainersConfig {

Map<String, String> postgreSQLDetails = new HashMap<>();

{{
postgreSQLDetails.put("host", "postgresql");
postgreSQLDetails.put("user", "postgres");
postgreSQLDetails.put("password", "postgres");
postgreSQLDetails.put("database", "dapr");
postgreSQLDetails.put("port", "5432");
postgreSQLDetails.put("actorStateStore", String.valueOf(true));

}}

private Component stateStoreComponent = new Component("kvstore",
"state.postgresql", "v2", postgreSQLDetails);

@Bean
@ServiceConnection
public DaprContainer daprContainer(Network network) {
public DaprContainer daprContainer(Network network, PostgreSQLContainer postgreSQLContainer) {

return new DaprContainer(DAPR_RUNTIME_IMAGE_TAG)
.withAppName("workflow-patterns-app")
.withComponent(new Component("kvstore", "state.in-memory", "v1", Collections.singletonMap("actorStateStore", String.valueOf(true))))
.withComponent(stateStoreComponent)
.withAppPort(8080)
.withNetwork(network)
.withAppHealthCheckPath("/actuator/health")
.withAppChannelAddress("host.testcontainers.internal");
.withAppChannelAddress("host.testcontainers.internal")
.dependsOn(postgreSQLContainer);
}

@Bean
public PostgreSQLContainer postgreSQLContainer(Network network) {
return new PostgreSQLContainer(DockerImageName.parse("postgres"))
.withNetworkAliases("postgresql")
.withDatabaseName("dapr")
.withUsername("postgres")
.withPassword("postgres")
.withNetwork(network);
}

@Bean
MicrocksContainersEnsemble microcksEnsemble(Network network) {
Expand All @@ -66,6 +95,14 @@ MicrocksContainersEnsemble microcksEnsemble(Network network) {
.withMainArtifacts("third-parties/remote-http-service.yaml");
}

@Bean
public WorkflowDashboardContainer workflowDashboard(Network network) {
return new WorkflowDashboardContainer(WorkflowDashboardContainer.getDefaultImageName())
.withNetwork(network)
.withStateStoreComponent(stateStoreComponent)
.withExposedPorts(8080);
}

@Bean
public DynamicPropertyRegistrar endpointsProperties(MicrocksContainersEnsemble ensemble) {
// We need to replace the default endpoints with those provided by Microcks.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright 2025 The Dapr Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* 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 io.dapr.testcontainers;

import io.dapr.testcontainers.converter.ComponentYamlConverter;
import io.dapr.testcontainers.converter.YamlConverter;
import io.dapr.testcontainers.converter.YamlMapperFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.images.builder.Transferable;
import org.testcontainers.utility.DockerImageName;
import org.yaml.snakeyaml.Yaml;

/**
* Test container for Dapr Workflow Dashboard.
*/
public class WorkflowDashboardContainer extends GenericContainer<WorkflowDashboardContainer> {
private static final Logger LOGGER = LoggerFactory.getLogger(WorkflowDashboardContainer.class);
private static final Yaml YAML_MAPPER = YamlMapperFactory.create();
private static final YamlConverter<Component> COMPONENT_CONVERTER = new ComponentYamlConverter(YAML_MAPPER);
public static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName
.parse("ghcr.io/diagridio/diagrid-dashboard:0.0.1");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be made a const to avoid a raw string here? That way when there is a version change its easier to find/update later on - like how we have the src/main/java/io/dapr/testcontainers/DaprContainerConstants.java file for the other container consts.

private int dashboardPort = 8080;
private Component stateStoreComponent;

/**
* Creates a new Dapr scheduler container.
* @param dockerImageName Docker image name.
*/
public WorkflowDashboardContainer(DockerImageName dockerImageName) {
super(dockerImageName);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
withExposedPorts(dashboardPort);
}

public WorkflowDashboardContainer withStateStoreComponent(Component stateStoreComponent) {
this.stateStoreComponent = stateStoreComponent;
return this;
}

/**
* Creates a new Dapr schedulers container.
* @param image Docker image name.
*/
public WorkflowDashboardContainer(String image) {
this(DockerImageName.parse(image));
}

@Override
protected void configure() {
super.configure();
if (stateStoreComponent != null) {
String componentYaml = COMPONENT_CONVERTER.convert(stateStoreComponent);
withCopyToContainer(Transferable.of(componentYaml), "/app/components/" + stateStoreComponent.getName() + ".yaml");
withEnv("COMPONENT_FILE", "/app/components/" + stateStoreComponent.getName() + ".yaml");
}

}

public static DockerImageName getDefaultImageName() {
return DEFAULT_IMAGE_NAME;
}

public WorkflowDashboardContainer withPort(Integer port) {
this.dashboardPort = port;
return this;
}

@Override
public void start() {
super.start();

LOGGER.info("Dapr Workflow Dashboard container started.");
LOGGER.info("Access the Dashboard at: http://localhost:{}", this.getMappedPort(dashboardPort));
}

public int getPort() {
return dashboardPort;
}

// Required by spotbugs plugin
@Override
public boolean equals(Object o) {
return super.equals(o);
}

@Override
public int hashCode() {
return super.hashCode();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2025 The Dapr Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* 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 io.dapr.testcontainers;

import org.junit.jupiter.api.Test;

import java.util.Collections;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class DaprWorkflowDashboardTest {

@Test
public void dashboardTest() {
Component stateStoreComponent = new Component("kvstore",
"state.in-memory", "v1", Collections.singletonMap("actorStateStore", "true"));
try (WorkflowDashboardContainer dashboard =
new WorkflowDashboardContainer(WorkflowDashboardContainer.DEFAULT_IMAGE_NAME)
.withStateStoreComponent(stateStoreComponent)) {
dashboard.configure();
assertNotNull(dashboard.getEnvMap().get("COMPONENT_FILE"));
assertFalse(dashboard.getEnvMap().get("COMPONENT_FILE").isEmpty());
assertEquals(8080, dashboard.getPort());

}
}
}
Loading