DMN decision check using java

Hi,
We are trying to incorporate below java to check DMN decision statically. But I don’t know why errors showing like “The import org.assertj cannot be resolved” and “The import org.junit cannot be resolved”.

package com.example.demo;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;

import java.io.InputStream;

import org.camunda.bpm.dmn.engine.DmnDecision;
import org.camunda.bpm.dmn.engine.DmnDecisionRuleResult;
import org.camunda.bpm.dmn.engine.DmnDecisionTableResult;
import org.camunda.bpm.dmn.engine.DmnEngine;
import org.camunda.bpm.dmn.engine.test.DmnEngineRule;
import org.camunda.bpm.engine.variable.VariableMap;
import org.camunda.bpm.engine.variable.Variables;
import org.junit.Rule;
import org.junit.Test;

public class CreditApplicationTestCase {

  @Rule
  public DmnEngineRule rule = new DmnEngineRule();

  @Test
  public void shouldEvaluateDecision() {
    // Get DMN engine
    DmnEngine dmnEngine = rule.getDmnEngine();

    // Parse decision
    InputStream inputStream = getClass().getResourceAsStream("Grocery.dmn");
    DmnDecision decision = dmnEngine.parseDecision("Decision_3frgt", inputStream);

    // Set input variables
    VariableMap variables = Variables.createVariables()
      .putValue("Fruit", "Apple")
      .putValue("Price", 123);

    // Evaluate decision with id 'Decision_3frgt' from file 'Grocery.dmn'
    DmnDecisionTableResult results = dmnEngine.evaluateDecisionTable(decision, variables);

    // Check that one rule has matched
    assertThat(results).hasSize(1);

    DmnDecisionRuleResult result = results.getSingleResult();
    assertThat(result)
      .containsOnly(entry("result", "1")
      );
  }

}

Pom.xml as below

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.7.1</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.abeam.workflow.delegates</groupId>
	<artifactId>DmnFileTestCreate</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>DmnFileTestCreate</name>
	<description>Demo project for Spring Boot</description>
	<properties>
		<java.version>11</java.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>

		<!-- https://mvnrepository.com/artifact/org.camunda.bpm/camunda-engine-spring -->
		<dependency>
		    <groupId>org.camunda.bpm</groupId>
		    <artifactId>camunda-engine-spring</artifactId>
		    <version>7.17.0-alpha4</version>
		</dependency>

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-jdk14 -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-jdk14</artifactId>
    <version>2.0.0-alpha7</version>
    <scope>test</scope>
</dependency>

	
	    <!-- https://mvnrepository.com/artifact/org.powermock/powermock-module-junit4 -->
<dependency>
    <groupId>org.powermock</groupId>
    <artifactId>powermock-module-junit4</artifactId>
    <version>2.0.9</version>
    <scope>test</scope>
</dependency>
	    
	
<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
<dependency>
    <groupId>org.assertj</groupId>
    <artifactId>assertj-core</artifactId>
    <version>3.6.2</version>
    <scope>test</scope>
</dependency>


	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>

Could you please help to resole this error.

@Junaka

DmnEngineRule will work only with the Junit context.

You need to access DecisionService to evaluate the decisions.

DecisionService decisionService = BpmPlatform.getDefaultProcessEngine().getDecisionService();

DmnDecisionTableResult decisionTableResult = decisionService
	.evaluateDecisionTableByKey(decisionDefinitionKey, decisionVariablesMap);

Hi @aravindhrs thanks,

I tried, but got some error as same. Can you please guide me.
Sorry am new to java and Camunda as well.

@Junaka Junit classes or functions are won’t be available at runtime scope. Could you share the minimal project in GitHub? I can look into it.