-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #559 from etendosoftware/feature/ETP-870
Feature ETP-870: Add tests for jobs defaults & ReportValuationStock
- Loading branch information
Showing
27 changed files
with
4,020 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src-test/src/com/etendoerp/reportvaluationstock/ETRVSComponentProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.etendoerp.reportvaluationstock; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.openbravo.client.kernel.BaseComponentProvider; | ||
|
||
import java.util.List; | ||
import java.util.HashMap; | ||
|
||
/** | ||
* Unit tests for the {@link ETRVSComponentProvider} class. | ||
* <p> | ||
* This class tests the behavior of the component provider methods, ensuring | ||
* correct handling of global component resources and specific components. | ||
* </p> | ||
*/ | ||
public class ETRVSComponentProviderTest { | ||
|
||
private ETRVSComponentProvider componentProvider; | ||
|
||
/** | ||
* Sets up the test environment by initializing the component provider instance. | ||
*/ | ||
@Before | ||
public void setUp() { | ||
componentProvider = new ETRVSComponentProvider(); | ||
} | ||
|
||
/** | ||
* Tests the {@link ETRVSComponentProvider(String, HashMap)} method. | ||
* <p> | ||
* Ensures that the method returns null when provided with an arbitrary ID and empty parameters. | ||
* </p> | ||
*/ | ||
@Test | ||
public void testGetComponent() { | ||
assertNull(componentProvider.getComponent("testId", new HashMap<>())); | ||
} | ||
|
||
/** | ||
* Tests the {@link ETRVSComponentProvider#getGlobalComponentResources()} method. | ||
* <p> | ||
* Verifies that the method returns a non-null list containing a single valid resource. | ||
* </p> | ||
*/ | ||
@Test | ||
public void testGetGlobalComponentResources() { | ||
List<BaseComponentProvider.ComponentResource> resources = componentProvider.getGlobalComponentResources(); | ||
|
||
assertNotNull(resources); | ||
|
||
assertEquals(1, resources.size()); | ||
|
||
BaseComponentProvider.ComponentResource resource = resources.get(0); | ||
assertNotNull(resource); | ||
|
||
assertEquals( | ||
"web/com.etendoerp.reportvaluationstock/js/etrvs-onchange.js", | ||
resource.getPath() | ||
); | ||
|
||
} | ||
|
||
/** | ||
* Tests that {@link ETRVSComponentProvider#getGlobalComponentResources()} returns a non-empty list. | ||
* <p> | ||
* Ensures the presence of global component resources. | ||
* </p> | ||
*/ | ||
@Test | ||
public void testGetGlobalComponentResourcesNotEmpty() { | ||
assertFalse(componentProvider.getGlobalComponentResources().isEmpty()); | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
src-test/src/com/etendoerp/reportvaluationstock/handler/CostingRuleUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package com.etendoerp.reportvaluationstock.handler; | ||
|
||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
|
||
import org.junit.Test; | ||
import org.junit.Before; | ||
import org.openbravo.dal.service.OBQuery; | ||
import org.openbravo.model.common.enterprise.Organization; | ||
import org.openbravo.dal.service.OBDal; | ||
import org.mockito.MockedStatic; | ||
import org.mockito.Mockito; | ||
import org.openbravo.model.materialmgmt.cost.CostingRule; | ||
|
||
/** | ||
* Test class for CostingRuleUtils, which verifies the logic related | ||
* to the calculation of costing rules based on organizations. | ||
*/ | ||
public class CostingRuleUtilsTest { | ||
|
||
private Organization mockOrganization; | ||
private OBDal mockOBDal; | ||
private ReportValuationStock reportValuationStock; | ||
|
||
/** | ||
* Sets up the initial state required for the tests. Prepare mocks and retrieves | ||
* the reflected method from ReportValuationStock for testing purposes. | ||
* | ||
* @throws Exception if an error occurs during the setup. | ||
*/ | ||
@Before | ||
public void setUp() throws Exception { | ||
reportValuationStock = new ReportValuationStock(); | ||
|
||
mockOrganization = Mockito.mock(Organization.class); | ||
mockOBDal = Mockito.mock(OBDal.class); | ||
} | ||
|
||
/** | ||
* Tests the getLEsCostingAlgortithm method with a valid organization. Verifies that | ||
* the method returns the expected costing rule when provided with correct data. | ||
* | ||
* @throws Exception if an error occurs during the test execution. | ||
*/ | ||
@Test | ||
public void testGetLEsCostingAlgortithmWithValidOrganization() throws Exception { | ||
String orgId = "TEST_ORG_ID"; | ||
CostingRule expectedRule = Mockito.mock(CostingRule.class); | ||
|
||
Mockito.when(mockOrganization.getId()).thenReturn(orgId); | ||
|
||
try (MockedStatic<OBDal> mockedStatic = Mockito.mockStatic(OBDal.class)) { | ||
mockedStatic.when(OBDal::getReadOnlyInstance).thenReturn(mockOBDal); | ||
|
||
@SuppressWarnings("unchecked") | ||
OBQuery<CostingRule> mockQuery = Mockito.mock(OBQuery.class); | ||
|
||
Mockito.when(mockOBDal.createQuery(Mockito.eq(CostingRule.class), Mockito.anyString())) | ||
.thenReturn(mockQuery); | ||
Mockito.when(mockQuery.setNamedParameter(Mockito.anyString(), Mockito.any())) | ||
.thenReturn(mockQuery); | ||
Mockito.when(mockQuery.setMaxResult(1)).thenReturn(mockQuery); | ||
Mockito.when(mockQuery.uniqueResult()).thenReturn(expectedRule); | ||
|
||
CostingRule result = reportValuationStock.getLEsCostingAlgortithm(mockOrganization); | ||
|
||
assertNotNull("The result should not be null", result); | ||
assertEquals("The result should be the expected CostingRule", expectedRule, result); | ||
} | ||
} | ||
|
||
/** | ||
* Tests the getLEsCostingAlgortithm method when no costing rules are found. | ||
* Verifies that the method returns null when no results are available. | ||
* | ||
* @throws Exception if an error occurs during the test execution. | ||
*/ | ||
@Test | ||
public void testGetLEsCostingAlgortithmNoRulesFound() throws Exception { | ||
String orgId = "TEST_ORG_ID"; | ||
|
||
Mockito.when(mockOrganization.getId()).thenReturn(orgId); | ||
|
||
try (MockedStatic<OBDal> mockedStatic = Mockito.mockStatic(OBDal.class)) { | ||
mockedStatic.when(OBDal::getReadOnlyInstance).thenReturn(mockOBDal); | ||
|
||
@SuppressWarnings("unchecked") | ||
OBQuery<CostingRule> mockQuery = Mockito.mock(OBQuery.class); | ||
|
||
Mockito.when(mockOBDal.createQuery(Mockito.eq(CostingRule.class), Mockito.anyString())) | ||
.thenReturn(mockQuery); | ||
Mockito.when(mockQuery.setNamedParameter(Mockito.anyString(), Mockito.any())) | ||
.thenReturn(mockQuery); | ||
Mockito.when(mockQuery.setMaxResult(1)).thenReturn(mockQuery); | ||
Mockito.when(mockQuery.uniqueResult()).thenReturn(null); | ||
|
||
CostingRule result = reportValuationStock.getLEsCostingAlgortithm(mockOrganization); | ||
|
||
assertNull("The result should be null when no rules are found", result); | ||
} | ||
} | ||
} |
Oops, something went wrong.