Skip to content

Commit

Permalink
Merge pull request #559 from etendosoftware/feature/ETP-870
Browse files Browse the repository at this point in the history
Feature ETP-870: Add tests for jobs defaults & ReportValuationStock
  • Loading branch information
Emi-Polliotti authored Dec 18, 2024
2 parents 47b92a9 + 76d808d commit 81936f5
Show file tree
Hide file tree
Showing 27 changed files with 4,020 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected JRDataSource getReportData(Map<String, Object> parameters) {
return (JRFieldProviderDataSource) jrParams.get(PARAM_SUB_REPORT);
}

private void buildData(VariablesSecureApp vars, String strDate,
protected void buildData(VariablesSecureApp vars, String strDate,
String strOrganization, String strWarehouse, String strCategoryProduct, String strCurrencyId,
boolean isWarehouseConsolidation, Map<String, Object> parameters) throws ServletException {
ReportValuationStockData[] data;
Expand Down
43 changes: 42 additions & 1 deletion pipelines/unittests/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ spec:
try {
echo "--------------- Running WebserviceTestSuite ---------------"
sh "./gradlew test --tests org.openbravo.test.WebserviceTestSuite --info"
sh "mv build/jacoco/test.exec build/jacoco/test1.exec"
sh "mv build/jacoco/test.exec build/jacoco/test0.exec"
echo "--------------- WebserviceTestSuite Successful ---------------"
currentBuild.result = SUCCESS
} catch (Exception e) {
Expand Down Expand Up @@ -282,6 +282,47 @@ spec:
}
}
// __________________________________________________________________________________________
// ------------------------------ com.smf.* TESTS ------------------------------------------
stage ('Core Test Suite') { // MARK: CoreTestSuite Test Suite
when {
expression {
env.STATUSBUILD == "1"
}
}
steps {
sh "./pipelines/unittests/build-update.sh ${REPO_NAME} ${COMMIT_INPROGRESS_STATUS} \"Running Test Suites\" ${ACCESS_TOKEN} ${GIT_COMMIT} ${BUILD_URL} \"${CONTEXT_BUILD}\""
container('compiler') {
script {
dir(REPO_NAME) {
try {
echo "--------------- Running CoreTestSuite ---------------"
sh "./gradlew test --tests com.smf.test.CoreTestSuite --info"
sh "mv build/jacoco/test.exec build/jacoco/test1.exec"
echo "--------------- CoreTestSuite Successful ---------------"
currentBuild.result = SUCCESS
} catch (Exception e) {
echo "--------------- CoreTestSuite Failed ---------------"
echo 'Exception occurred: ' + e.toString()
currentBuild.result = UNSTABLE
unstable('CoreTestSuite Failed')
env.STATUSTEST = "0"
} finally {
publishHTML([
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'build/reports/tests/test',
reportFiles: '*.html',
reportName: 'com.smf.* TESTS REPORT',
reportTitles: ''
])
}
}
}
}
}
}
// __________________________________________________________________________________________
// ------------------------------- STANDALONE TEST ------------------------------------------
stage ('Standalone Test Suite') { // MARK: Standalone Test Suite
when {
Expand Down
38 changes: 38 additions & 0 deletions pipelines/unittests/JenkinsfileOracle
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,44 @@ spec:
}
}
}
// __________________________________________________________________________________________
// ------------------------------ com.smf.* TESTS ------------------------------------------
stage ('Core Test Suite') { // MARK: com.smf.* Test Suite
when {
expression {
env.STATUSBUILD == "1"
}
}
steps {
container('compiler') {
script {
dir(REPO_NAME) {
try {
echo "--------------- Running CoreTestSuite ---------------"
sh "./gradlew test --tests com.smf.test.CoreTestSuite --info"
echo "--------------- CoreTestSuite Successful ---------------"
} catch (Exception e) {
echo "--------------- CoreTestSuite Failed ---------------"
echo 'Exception occurred: ' + e.toString()
currentBuild.result = UNSTABLE
unstable('CoreTestSuite Failed')
env.STATUSTEST = "0"
} finally {
publishHTML([
allowMissing: true,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'build/reports/tests/test',
reportFiles: '*.html',
reportName: 'com.smf.* TESTS REPORT',
reportTitles: ''
])
}
}
}
}
}
}
//___________________________________________________________________________________________
// ------------------------------- STANDALONE TEST ------------------------------------------
stage ('Standalone Test Suite'){
Expand Down
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());
}
}
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);
}
}
}
Loading

0 comments on commit 81936f5

Please sign in to comment.