Skip to content

Commit

Permalink
end to end implementation with junit5 tests and running demo
Browse files Browse the repository at this point in the history
  • Loading branch information
sourabhparsekar committed Jun 24, 2021
1 parent 6b15427 commit edacce3
Show file tree
Hide file tree
Showing 26 changed files with 393 additions and 80 deletions.
132 changes: 130 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Cook Veg Masala Noodles using Camunda Workflow
***

This standalone process application is an example using [Camunda Workflow](https://camunda.com/) & [Springboot](https://spring.io/projects/spring-boot). As for the use case, we will try to _cook veg masala instant noodles_ else order from our favorite restaurant if we fail.
## Introduction:
This standalone process application is an example using [Camunda Workflow](https://camunda.com/) & [Springboot](https://spring.io/projects/spring-boot) with JUnit5 Test cases. As for the use case, we will try to _cook veg masala instant noodles_ else order from our favorite restaurant if we fail.

_**Note:** You may see that some cooking steps may not be intuitive, but they are added to make use of features of camunda._

Expand All @@ -14,7 +16,7 @@ Out of the [BMPN 2.0 Implementations](https://docs.camunda.org/manual/7.15/refer
- `Timer Intermediate Catch Event`: Timer events are events which are triggered by a defined timer. They can be used as start event, intermediate event or boundary event.


### Veg Masala Noodles Cooking Flow:
### Use Case: Veg Masala Noodles Cooking Flow:
![Noodles Cooking Workflow Process](./src/main/resources/cook_noodles_process.png)

- We start by checking that we have minimum ingredients, where instant noodles, water, pan and spatula are mandatory. Vegetables, Cheese etc are optional to make instant noodles.
Expand All @@ -25,6 +27,7 @@ Out of the [BMPN 2.0 Implementations](https://docs.camunda.org/manual/7.15/refer

With that we reach end of our non-intuitive flow to cook my instant noodles. By the way, that's how I cook instant noodles, and they turn out good most of the times.


## Code Configuration

### Camunda Springboot Initializer
Expand All @@ -41,6 +44,8 @@ On systems running the `API`, it is recommended to use the below port for starti

> `10101` – default api listening port
http://localhost:10101/camunda-masala-noodles/swagger-ui.html

### API Build & deploy from GIT repo
Below section would cover high level tasks required to configure and deploy api jar using Apache Maven

Expand All @@ -52,6 +57,129 @@ Below section would cover high level tasks required to configure and deploy api
6. Start execution with `java -jar camunda-masala-noodles-<version>.jar`
7. Logs are generated in deployment-directory/logs folder with file name 'camunda-masala-noodles-logger.log' or as mentioned in logback-spring.xml

## Testing it out

### Run the Springboot application with maven

- You can follow above steps in order to compile, build, package and install jar using maven.

- Use command `mvnw clean install` to build and install the jar

- Use command `mvnw spring-boot:run` to run the springboot application.

- Alternatively you can navigate to file [MasalaNoodlesApplication](./src/main/java/com/noodles/MasalaNoodlesApplication.java) and start the application.

- If every thing works then you should see below log in your console
```
2021-06-25 00:27:50,315 INFO [main] org.springframework.boot.web.embedded.tomcat.TomcatWebServer: Tomcat started on port(s): 10101 (http) with context path '/camunda-masala-noodles'
2021-06-25 00:27:50,335 INFO [main] com.noodles.MasalaNoodlesApplication: Started MasalaNoodlesApplication in 22.716 seconds (JVM running for 25.565)
2021-06-25 00:27:50,340 INFO [main] org.camunda.bpm.engine.jobexecutor: ENGINE-14014 Starting up the JobExecutor[org.camunda.bpm.engine.spring.components.jobexecutor.SpringJobExecutor].
2021-06-25 00:27:50,344 INFO [JobExecutor[org.camunda.bpm.engine.spring.components.jobexecutor.SpringJobExecutor]] org.camunda.bpm.engine.jobexecutor: ENGINE-14018 JobExecutor[org.camunda.bpm.engine.spring.components.jobexecutor.SpringJobExecutor] starting to acquire jobs
```
- Refer to [running-your-application](https://docs.spring.io/spring-boot/docs/1.5.16.RELEASE/reference/html/using-boot-running-your-application.html) for more help with running boot application.

### Instantiate new process to make veg masala noodles

#### 1. Open & Login Camunda in Browser

- On your local machine, you can access Camunda using [Camunda Home Page](http://localhost:10101/camunda-masala-noodles) url
- Credentials are configured in [application.yaml](./src/main/resources/application.yaml) file in key `camunda.bpm.admin-user`. Default credentials are
> `username:` noodles
`password:` noodles

![camunda homepage](./documentation/images/camunda-homepage.png)

#### 2. Start 'Cook Masala Veggies Noodles' process

- Click on `TaskList` in welcome page

![camunda-welcome-screen.png](./documentation/images/camunda-welcome-screen.png)

- In top right corner, we have the menu. Click `Start process` to select the process to be started.

![camunda-tasklist-Start process.png](./documentation/images/camunda-tasklist-Start%20process.png)

- Click on `Cook Masala Veggies Noodles` which is the process we are about to test

#### 3. Input the details to start process instance

- We will now be presented with a `form` to select the ingredients we have. Based on our input, workflow will decide the course of action. _You can check console logs to see what happened with your process._

![camunda-start-process-instance.png](./documentation/images/camunda-start-process-instance.png)

#### 4. Navigate to Camunda Cockpit

- `Cockpit` helps us to visualise which step our process is. It would also give us the process instance id.

![camunda-cockpit.png](./documentation/images/camunda-cockpit.png)

- You can now click on `Cook Masala Veggies Noodles` Process Definition to view the process. Copy the process instance id.

![camunda-activity-instance.png](./documentation/images/camunda-activity-instance.png)

> Checking of ingredients process will end and cooking process will begin. In case you do not see your process in cockpit then, check logs on console. It would be mainly due to the fact that you do not have enough ingredients to cook instant noodles. In that case, you have to order online.
### Once cooked call the process using the instance id

#### 1. Open Swagger API Browser

- While you were busy with your mobile, suddenly you remember you have kept instant noodles to cook. If your process has not ended yet i:e noodles are not burnt and they are ready to eat then you can trigger an api to indicate to process that you cooked noodles.

- URL to access [Swagger API](http://localhost:10101/camunda-masala-noodles/swagger-ui.html)

#### 2. Indicate Noodles are cooked by passing the process instance id

- Click on `Try it out` to enable the API. The process instance id that was copied from cockpit, goes into the path parameter.

- Click `Execute` to send the request. You can check the response which will say `<process-instance-id> is ready to eat. `

![swagger-event.png](./documentation/images/swagger-event.png)

- If you want to read more about swagger, then you can go through [tutorial](https://sourabhparsekar.medium.com/open-api-specification-swagger3-fc9ad3bbacdd)

### Check Logs

- In the end, all the steps we did will be tracked via the logs in the console. If you filter the logs using keyword `workflow-service-info` then you would see below


Logs for **Process instantiation**
```
Timestamp:1624563683397:workflow-service-info:Check Ingredients:Check ingredients to make veg masala noodles
Timestamp:1624563683397:workflow-service-info:Check Ingredients:we can make veg masala noodles
Timestamp:1624563683400:workflow-service-info:Prepare Noodles:Follow below to make veg masala noodles
Timestamp:1624563683400:workflow-service-info:STEP 1:Take a deep-bottomed pan over medium flame and add water in it and bring it to a boil.
Timestamp:1624563683400:workflow-service-info:STEP 2:While the water starts to boil, check if you received IMs on your mobile.
Timestamp:1624563683400:workflow-service-info:STEP 3:Once the water boils, add chopped vegetables, add 1 packet of instant noodles and stir it.
Timestamp:1624563683401:workflow-service-info:STEP 4:Add the taste-maker to it and give it another stir
Timestamp:1624563683401:workflow-service-info:STEP 5:Close the lid
Timestamp:1624563683401:workflow-service-info:Cooking in Process:You can play with your mobile as it cooks for sometime...
```

Logs for **Process continuation success**
```
Timestamp:1624563718006:workflow-service-info:Noodles Cooked:Cooking done for process instance id: 28242b5c-d524-11eb-878f-dc7196c5d636
Timestamp:1624563718030:workflow-service-info:Eat Noodles:Veg masala noodles is ready. Let's eat... But first serve it..
Timestamp:1624563718030:workflow-service-info:Eat Noodles:Transfer to a serving bowl and sprinkle a pinch of chaat masala or oregano over the noodles to make it even more flavorful.
Timestamp:1624563718030:workflow-service-info:Eat Noodles:Serve it hot to enjoy!!
```

Logs for **Process continuation failure**
```
Timestamp:1624563560428:workflow-service-info:Order Online:Veg masala noodles was no success.. Let's order online...
Timestamp:1624563560429:workflow-service-info:Order Online:Ordering is not part of this flow yet... Try your local apps...
```

Logs for **insufficient ingredients**
```
Timestamp:1624562624142:workflow-service-info:Check Ingredients:Check ingredients to make veg masala noodles
Timestamp:1624562624142:workflow-service-error:Check Ingredients:we cannot make veg masala noodles as required ingredient is missing. Instant Noodles, Water, Pan and Spatula are required.
Timestamp:1624562624144:workflow-service-info:Order Online:Veg masala noodles was no success.. Let's order online...
Timestamp:1624562624145:workflow-service-info:Order Online:Ordering is not part of this flow yet... Try your local apps...
```

_Hope you enjoy the wonderful journey of cooking veg masala instant noodles using camunda workflow. Until next time, happy cooking !!_


## Appendix - Deployment as Docker container

To deploy API as Docker Container refer [Docker-Image-Deployment](./documentation/deployment/Readme.md)
45 changes: 37 additions & 8 deletions camunda-masala-noodles.iml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
<orderEntry type="library" name="Maven: commons-dbcp:commons-dbcp:1.4" level="project" />
<orderEntry type="library" name="Maven: commons-pool:commons-pool:1.6" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.3.4" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.3.4" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.3.4" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.3.4" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-jdbc:5.3.4" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-tx:5.3.4" level="project" />
Expand Down Expand Up @@ -72,13 +70,10 @@
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:9.0.43" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-validation:2.4.3" level="project" />
<orderEntry type="library" name="Maven: org.hibernate.validator:hibernate-validator:6.1.7.Final" level="project" />
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.4.1.Final" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.5.1" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-web:5.3.4" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.core:jersey-server:2.32" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.core:jersey-common:2.32" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2:osgi-resource-locator:1.0.3" level="project" />
<orderEntry type="library" name="Maven: com.sun.activation:jakarta.activation:1.2.2" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.core:jersey-client:2.32" level="project" />
<orderEntry type="library" name="Maven: jakarta.ws.rs:jakarta.ws.rs-api:2.1.6" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jersey.media:jersey-media-jaxb:2.32" level="project" />
Expand All @@ -91,7 +86,6 @@
<orderEntry type="library" name="Maven: org.glassfish.jersey.inject:jersey-hk2:2.32" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2:hk2-locator:2.6.1" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2.external:aopalliance-repackaged:2.6.1" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.25.0-GA" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2:hk2:2.6.1" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2:hk2-utils:2.6.1" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.hk2:hk2-api:2.6.1" level="project" />
Expand All @@ -110,7 +104,6 @@
<orderEntry type="library" name="Maven: org.camunda.bpm.springboot:camunda-bpm-spring-boot-starter-webapp-core:7.15.0" level="project" />
<orderEntry type="library" name="Maven: org.camunda.bpm.webapp:camunda-webapp:classes:7.15.0" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:2.4.3" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:5.3.4" level="project" />
<orderEntry type="library" name="Maven: org.camunda.bpm.webapp:camunda-webapp-webjar:7.15.0" level="project" />
<orderEntry type="library" name="Maven: org.camunda.bpm:camunda-engine-plugin-spin:7.15.0" level="project" />
<orderEntry type="library" name="Maven: org.camunda.spin:camunda-spin-core:1.10.1" level="project" />
Expand All @@ -134,7 +127,6 @@
<orderEntry type="library" name="Maven: org.junit.jupiter:junit-jupiter-params:5.7.1" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.7.1" level="project" />
<orderEntry type="library" name="Maven: org.mockito:mockito-core:3.6.28" level="project" />
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.10.20" level="project" />
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy-agent:1.10.20" level="project" />
<orderEntry type="library" name="Maven: org.objenesis:objenesis:3.1" level="project" />
<orderEntry type="library" name="Maven: org.mockito:mockito-junit-jupiter:3.6.28" level="project" />
Expand All @@ -150,7 +142,44 @@
<orderEntry type="library" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
<orderEntry type="library" name="Maven: org.junit.platform:junit-platform-commons:1.7.1" level="project" />
<orderEntry type="library" name="Maven: org.camunda.bpm.assert:camunda-bpm-assert-assertj3-11-1:4.0.0" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-data-jpa:2.4.3" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-aop:2.4.3" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.3.4" level="project" />
<orderEntry type="library" name="Maven: org.aspectj:aspectjweaver:1.9.6" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:2.4.3" level="project" />
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:3.4.5" level="project" />
<orderEntry type="library" name="Maven: jakarta.transaction:jakarta.transaction-api:1.3.3" level="project" />
<orderEntry type="library" name="Maven: jakarta.persistence:jakarta.persistence-api:2.2.3" level="project" />
<orderEntry type="library" name="Maven: org.hibernate:hibernate-core:5.4.28.Final" level="project" />
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.4.1.Final" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.27.0-GA" level="project" />
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.10.20" level="project" />
<orderEntry type="library" name="Maven: antlr:antlr:2.7.7" level="project" />
<orderEntry type="library" name="Maven: org.jboss:jandex:2.2.3.Final" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.5.1" level="project" />
<orderEntry type="library" name="Maven: org.dom4j:dom4j:2.1.3" level="project" />
<orderEntry type="library" name="Maven: org.hibernate.common:hibernate-commons-annotations:5.1.2.Final" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jaxb:jaxb-runtime:2.3.3" level="project" />
<orderEntry type="library" name="Maven: org.glassfish.jaxb:txw2:2.3.3" level="project" />
<orderEntry type="library" name="Maven: com.sun.istack:istack-commons-runtime:3.0.11" level="project" />
<orderEntry type="library" name="Maven: com.sun.activation:jakarta.activation:1.2.2" level="project" />
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-jpa:2.4.5" level="project" />
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-commons:2.4.5" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.3.4" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-aspects:5.3.4" level="project" />
<orderEntry type="library" name="Maven: com.h2database:h2:1.4.200" level="project" />
<orderEntry type="library" name="Maven: org.springdoc:springdoc-openapi-ui:1.4.8" level="project" />
<orderEntry type="library" name="Maven: org.springdoc:springdoc-openapi-webmvc-core:1.4.8" level="project" />
<orderEntry type="library" name="Maven: org.springdoc:springdoc-openapi-common:1.4.8" level="project" />
<orderEntry type="library" name="Maven: io.swagger.core.v3:swagger-models:2.1.4" level="project" />
<orderEntry type="library" name="Maven: io.swagger.core.v3:swagger-annotations:2.1.4" level="project" />
<orderEntry type="library" name="Maven: io.swagger.core.v3:swagger-integration:2.1.4" level="project" />
<orderEntry type="library" name="Maven: io.swagger.core.v3:swagger-core:2.1.4" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.11.4" level="project" />
<orderEntry type="library" name="Maven: io.github.classgraph:classgraph:4.8.69" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:5.3.4" level="project" />
<orderEntry type="library" name="Maven: org.webjars:swagger-ui:3.34.0" level="project" />
<orderEntry type="library" name="Maven: org.webjars:webjars-locator-core:0.46" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.camunda.bpm.extension.mockito:camunda-bpm-mockito:4.13.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.google.code.findbugs:jsr305:3.0.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.11" level="project" />
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/images/camunda-cockpit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/images/camunda-homepage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/images/camunda-welcome-screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/images/swagger-event.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
<scope>import</scope>
<type>pom</type>
</dependency>

</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -65,12 +64,24 @@
<version>7.15.0</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>

<!--Dependency for Swagger 3-->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.4.8</version>
</dependency>

<!-- Camunda Test Case Dependencies-->
<dependency>
<groupId>org.camunda.bpm.extension.mockito</groupId>
<artifactId>camunda-bpm-mockito</artifactId>
Expand Down
Loading

0 comments on commit edacce3

Please sign in to comment.