Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature ETP-870: Add tests for jobs defaults & ReportValuationStock #559

Merged
merged 6 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
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
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
valeg-etendo marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
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
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
valeg-etendo marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
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
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
valeg-etendo marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
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());
}
}
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
valeg-etendo marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
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;

import java.lang.reflect.Method;

/**
* 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 Method getLEsCostingAlgortithmMethod;

/**
* 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 {
getLEsCostingAlgortithmMethod = ReportValuationStock.class.getDeclaredMethod("getLEsCostingAlgortithm", Organization.class);
getLEsCostingAlgortithmMethod.setAccessible(true);

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);

OBQuery<CostingRule> mockQuery = Mockito.mock(OBQuery.class);
Mockito.when(mockOBDal.createQuery(Mockito.eq(CostingRule.class), Mockito.anyString()))
.thenReturn(mockQuery);
Mockito.when(mockQuery.setNamedParameter(Mockito.eq("orgId"), Mockito.eq(orgId)))
.thenReturn(mockQuery);
Mockito.when(mockQuery.setMaxResult(1)).thenReturn(mockQuery);
Mockito.when(mockQuery.uniqueResult()).thenReturn(expectedRule);

CostingRule result = (CostingRule) getLEsCostingAlgortithmMethod.invoke(null, mockOrganization);

assertNotNull("El resultado no debería ser null", result);
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
assertEquals("El resultado debería ser el CostingRule esperado", expectedRule, result);
Emi-Polliotti marked this conversation as resolved.
Show resolved Hide resolved
}
}

/**
* 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);

OBQuery mockQuery = Mockito.mock(OBQuery.class);
Mockito.when(mockOBDal.createQuery(Mockito.eq(CostingRule.class), Mockito.anyString()))
.thenReturn(mockQuery);
Mockito.when(mockQuery.setNamedParameter(Mockito.eq("orgId"), Mockito.eq(orgId)))
.thenReturn(mockQuery);
Mockito.when(mockQuery.setMaxResult(1)).thenReturn(mockQuery);
Mockito.when(mockQuery.uniqueResult()).thenReturn(null);

CostingRule result = (CostingRule) getLEsCostingAlgortithmMethod.invoke(null, mockOrganization);

assertNull("El resultado debería ser null cuando no se encuentran reglas", result);
}
}
}
Loading
Loading