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+ }
0 commit comments