Skip to content

Commit

Permalink
Added DmnTester documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
pme123 committed Dec 27, 2024
1 parent 7f32346 commit f948cbe
Show file tree
Hide file tree
Showing 11 changed files with 2,142 additions and 111 deletions.
2 changes: 1 addition & 1 deletion 00-docs/src/docs/company/03-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ lazy val apiConfig: ApiConfig =
.withJiraUrls("COM" -> "https://issue.mycompany.ch/browse")
```

## Default ApiConfig
### Default ApiConfig
This is the default Configuration:
```scala
// your company name like 'mycompany'
Expand Down
63 changes: 62 additions & 1 deletion 00-docs/src/docs/company/03-dmn.md
Original file line number Diff line number Diff line change
@@ -1 +1,62 @@
# 03-dmn
# 03-dmn
Use this to add Company specific DMNTester stuff like the configuration of the projects within the Company.

The following structure is generated by `./helperCompany.scala init`:

```bash
03-dmn/src
| main/resources
| main/scala/company/dmn
| | CompanyDmnTester.scala
| test/scala/company/dmn
```

## CompanyDmnTester
The Company's base class to generate the DmnTester Configurations and start the Docker image.

Example (generated by `./helperCompany.scala init`):

```scala
package mycompany.camundala.dmn

trait CompanyDmnTester extends DmnTesterConfigCreator:

override def starterConfig: DmnTesterStarterConfig =
DmnTesterStarterConfig(companyName = "mycompany")

end CompanyDmnTester
```

## DmnTesterStarterConfig
You can customize the DmnTester Configuration.

```scala
DmnTesterStarterConfig(
companyName = "valiant",
dmnPaths = Seq(localDmnPath)
)
```

### Default Config

Except for the `companyName` all other values are optional and preconfigured,
and **should not be adjusted**.

Especially the `dmnPaths` might change in the future.

```scala
// the name of the container that will be started
containerName: String = "camunda-dmn-tester",
// path to where the configs should be created in
dmnConfigPaths: Seq[os.Path] = Seq(
projectBasePath / "03-dmn" / "src" / "main" / "resources" / "dmnConfigs"
),
// paths where the DMNs are (could be in different places)
dmnPaths: Seq[os.Path] = Seq(
projectBasePath / "src" / "main" / "resources"
),
// the port the DMN Tester is started - e.g. http://localhost:8883
exposedPort: Int = 8883,
// the image version of the DMN Tester
imageVersion: String = "latest"
```
7 changes: 4 additions & 3 deletions 00-docs/src/docs/company/04-helper.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ case class CompanyDevHelper(projectName: String, subProjects: Seq[String] = Seq.

lazy val apiConfig: ApiConfig = ApiConfig("mycompany")//.withTenantId("mycompany")...

def deployConfig: Option[DeployConfig] = ???
def devConfig: DevConfig = ???
def dockerConfig: DockerConfig = ???
lazy val deployConfig: Option[DeployConfig] = ???
lazy val devConfig: DevConfig = ???
lazy val dockerConfig: DockerConfig = ???
lazy val publishConfig: Option[PublishConfig] = ???

```
95 changes: 11 additions & 84 deletions 00-docs/src/docs/functionalityDsls/dmnTester.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ Let's start with a basic example:
package camundala.examples.invoice.dmn
// import the projects bpmns (DMNs)
import camundala.examples.invoice.bpmn.*
// import Camundala dmn DSL / the DMN Tester starter
import camundala.dmn.{DmnTesterConfigCreator, DmnTesterStarter}
// define an object that extends ..

object ProjectDmnTester
extends DmnTesterConfigCreator, // .. from a Config Creator DSL
DmnTesterStarter, // .. from a starter - that runs the DMN Tester automatically
App: // .. to run the Application
extends CompanyDmnTester:

startDmnTester()

Expand All @@ -50,11 +46,9 @@ end ProjectDmnTester
### Run the DMN Tester
In your _sbt-console_:

`runMain camundala.examples.invoice.dmn.ProjectDmnTester`
`dmn/run`

## startDmnTester
Starts the Docker container.
This makes the whole process pretty nice and fast.
This starts the Docker container and makes the whole process pretty nice and fast.
The following steps are done:

- Check if the Container is already running.
Expand All @@ -69,10 +63,8 @@ You start from the DMN, that you defined, here an example:

```scala
lazy val InvoiceAssignApproverDMN = collectEntries(
decisionDefinitionKey = "example-invoice-c7-assignApprover",
in = SelectApproverGroup(),
out = Seq(ApproverGroup.management),
descr = "Decision Table on who must approve the Invoice.",
)
```

Expand Down Expand Up @@ -120,11 +112,11 @@ So if you have complex set of dependent DMN Tables you can test them separately,
### .dmnPath
To support different naming schemes, you can adjust the DMN file name the following way:

- Nothing to do, if the file name is `dmnBasePath / s"${decisionId}.dmn"`. (see configuration)
- Nothing to do, if the file name is `dmnBasePath / s"${decisionId.replace("mycompany-", "")}.dmn"`. (see configuration)
- The creation of the default path can be overridden:
```scala
protected def defaultDmnPath(dmnName: String): os.Path =
dmnBasePath / s"${dmnName.replace("myPrefix-", "")}.dmn"
dmnBasePath / s"$decisionId.dmn"
```
- A different name, but with the same _defaultDmnPath_:
```scala
Expand Down Expand Up @@ -176,77 +168,12 @@ So it is a corner case if this is rather a test input.

The output variable can be whatever you want.

## Configuration
The following is the default configuration:
```scala
case class DmnTesterStarterConfig(
// the name of the container that will be started
containerName: String = "camunda-dmn-tester",
// path to where the configs should be created in
dmnConfigPaths: Seq[os.Path] = Seq(
projectBasePath / "src" / "it" / "resources" / "dmnConfigs"
),
// paths where the DMNs are (could be different places)
dmnPaths: Seq[os.Path] = Seq(
projectBasePath / "src" / "main" / "resources"
),
// the port the DMN Tester is started - e.g. http://localhost:8883
exposedPort: Int = 8883,
// the image version of the DMN Tester
imageVersion: String = "latest"
)
```

You can override it via the following variables (you see the defaults):

```scala
protected def starterConfig: DmnTesterStarterConfig = DmnTesterStarterConfig()
// this is the project where you start the DmnCreator
protected def projectBasePath: os.Path = os.pwd

// the path where the DMNs are
protected def dmnBasePath: os.Path = starterConfig.dmnPaths.head
// the path where the DMN Configs are
protected def dmnConfigPath: os.Path = starterConfig.dmnConfigPaths.head
// creating the Path to the DMN - by default the _dmnName_ is `decisionDmn.decisionDefinitionKey`.
protected def defaultDmnPath(dmnName: String): os.Path = dmnBasePath / s"$dmnName.dmn"

```

Example of a general Tester you can use for all project, that also starts the DMN Tester:

```scala
trait MyCompanyDmnTester extends DmnTesterConfigCreator, DmnTesterStarter:

private def localDmnPath = os.pwd / diagramPath

override protected def starterConfig: DmnTesterStarterConfig =
DmnTesterStarterConfig(
dmnPaths = Seq(localDmnPath)
)
override protected def defaultDmnPath(dmnName: String): os.Path =
val dmnPath = dmnBasePath / s"${dmnName.replace("mycompany-", "")}.dmn"
if(!dmnPath.toIO.exists())
throw FileNotFoundException(s"There is no DMN in $dmnPath")
dmnPath

startDmnTester()

end MyCompanyDmnTester
```

So in the project you can focus on the creation of DMN Configurations, like:

```scala
// runMain mycompany.nnk.dmn.ProjectDmnTester
object ProjectDmnTester extends MyCompanyDmnTester, App:

createDmnConfigs(
...
)
@:callout(info)
Be aware that you must run the DMN Tester again, whenever you made changes (`sbt dmn/run`).
@:@

end ProjectDmnTester
```
## Configuration
See [03-dmn].

## Problem Handling

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import java.time.LocalDateTime
import scala.language.reflectiveCalls
import scala.reflect.ClassTag

trait DmnTesterConfigCreator extends DmnConfigWriter:
trait DmnTesterConfigCreator extends DmnConfigWriter, DmnTesterStarter:

// the path where the DMNs are
protected def dmnBasePath: os.Path = starterConfig.dmnPaths.head
Expand All @@ -24,6 +24,7 @@ trait DmnTesterConfigCreator extends DmnConfigWriter:
dmnPath

protected def createDmnConfigs(dmnTesterObjects: DmnTesterObject[?]*): Unit =
startDmnTester
dmnConfigs(dmnTesterObjects)
.foreach(updateConfig(_, dmnConfigPath))
println("Check it on http://localhost:8883")
Expand Down
2 changes: 1 addition & 1 deletion 03-dmn/src/main/scala/camundala/dmn/DmnTesterStarter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import scala.util.{Failure, Success, Try}

trait DmnTesterStarter extends DmnTesterHelpers, App:

def startDmnTester(): Unit =
lazy val startDmnTester: Unit =
println("Check logs in Docker Console!")
println(s"Open the browser: http://localhost:${starterConfig.exposedPort}")
if checkIsRunning() then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,12 @@ case class CompanyWrapperGenerator()(using config: DevConfig):
private lazy val dmnWrapper =
s"""package $companyName.camundala.dmn
|
|import camundala.dmn.*
|trait CompanyDmnTester extends DmnTesterConfigCreator:
|
|/**
| * Add here company specific stuff, to run the DMN Tester.
| */
|trait CompanyDmnTester extends DmnTesterConfigCreator, DmnTesterStarter:
| override def starterConfig: DmnTesterStarterConfig =
| DmnTesterStarterConfig(companyName = "$companyName")
|
| def starterConfig: DmnTesterStarterConfig =
| DmnTesterStarterConfig( // adjust paths if needed
| companyName = "$companyName",
| )
|end CompanyDmnTester
|""".stripMargin

private lazy val simulationWrapper =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import bpmn.*
import java.time.LocalDateTime

object ProjectDmnTester
extends DmnTesterConfigCreator,
DmnTesterStarter,
App:
extends DmnTesterConfigCreator:

private lazy val localDmnConfigPath: os.Path =
os.pwd / "05-examples" / "demos" / "03-dmn" / "src" / "main" / "resources" / "dmnConfigs"
Expand All @@ -24,9 +22,7 @@ object ProjectDmnTester
dmnPaths = Seq(localDmnPath),
dmnConfigPaths = Seq(localDmnConfigPath)
)

startDmnTester()


createDmnConfigs(
DecisionResultTypes.singleEntryDMN.testUnit
.dmnPath("DecisionResultTypes")
Expand Down
Loading

0 comments on commit f948cbe

Please sign in to comment.