Skip to content

Commit 9557a07

Browse files
Shared code tutorial
1 parent 6de0b0e commit 9557a07

File tree

14 files changed

+189
-26
lines changed

14 files changed

+189
-26
lines changed

docs/make/project/module.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ To create a Module, follow the steps below :
4242
| Compare with remote repository | Compare local configuration with a remote repository |
4343
| ALTER DB history | Retain relevant configuration items' old values during export |
4444

45-
### Module filtering & default module
45+
### Module filtering & default module {#module-filtering}
4646

4747
The **Visible Modules* button in the platform's header: ![](img/module/header-button.png)
4848
- Filters the platform's configuration objects by module (eye icon next to the module name).

docs/make/settings/shared-code.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ Shared Code can be used in various scenarios, including Java class creation, bus
5454

5555
- [PlatformHooks](/docs/core/platform-hooks)
5656
- [Unit testing](/docs/core/unit-testing)
57-
57+
- [Unit test shared code tutorial](/tutorial/enhancing/shared-code)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.simplicite.tests.Training;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.fail;
5+
6+
import org.json.JSONObject;
7+
import org.junit.Test;
8+
9+
import com.simplicite.bpm.*;
10+
import com.simplicite.util.*;
11+
import com.simplicite.util.exceptions.*;
12+
import com.simplicite.util.tools.*;
13+
14+
/**
15+
* Unit tests for the TrnProduct business object
16+
* Tests the product stock management functionality
17+
*/
18+
public class TrnProductTest {
19+
20+
/**
21+
* Helper method to get system admin grant for testing
22+
* @return Grant with system admin privileges
23+
*/
24+
public Grant getGrant() {
25+
// Using the system admin grant for testing
26+
return Grant.getSystemAdmin();
27+
}
28+
29+
/**
30+
* Test the increaseStock action
31+
* Verifies that calling increaseStock increases the product stock by 10 units
32+
*/
33+
@Test
34+
public void testIncreaseStock() {
35+
try {
36+
// Create a test product with initial stock of 5
37+
ObjectDB product = getGrant().getTmpObject("TrnProduct");
38+
// Set test product data using JSON
39+
product.setValuesFromJSONObject(new JSONObject()
40+
.put("trnPrdCode", "TEST001")
41+
.put("trnPrdName", "Test Product")
42+
.put("trnPrdStock", 5), true, false, false);
43+
// Save the test product to database
44+
product.save();
45+
46+
// Get reference to stock field and store initial value
47+
ObjectField stockField = product.getField("trnPrdStock");
48+
int initialStock = stockField.getInt(0);
49+
50+
// Execute the increaseStock action on the product
51+
product.invokeAction("IncreaseStock", null);
52+
53+
// Assert that stock increased by exactly 10 units
54+
assertEquals("Stock should be increased by 10", initialStock + 10, stockField.getInt(0));
55+
56+
// Cleanup by removing test product from database
57+
product.delete();
58+
}
59+
catch (Exception e) {
60+
// Fail test and show error if any exception occurs
61+
fail("Test failed: " + e.getMessage());
62+
}
63+
}
64+
}

docs/tutorial/enhancing/_external-shared-code.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

docs/tutorial/enhancing/_mapping.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
2-
sidebar_class_name: hidden
32
sidebar_position: 15
4-
title: Mapping
3+
title: 3.4. Mapping
54
---
65

76
Mapping
82.7 KB
Loading
284 KB
Loading
3.17 KB
Loading
294 KB
Loading
291 KB
Loading

0 commit comments

Comments
 (0)