Skip to content

Commit

Permalink
Feature ETP-870: Refactored constants into a utility class
Browse files Browse the repository at this point in the history
  • Loading branch information
Emi-Polliotti committed Dec 18, 2024
1 parent e1d87ea commit 2ebb18d
Show file tree
Hide file tree
Showing 19 changed files with 290 additions and 250 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ public void testGetLEsCostingAlgortithmWithValidOrganization() throws Exception
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)))
Mockito.when(mockQuery.setNamedParameter(Mockito.eq(TestUtils.ORG_IDS), 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);
assertEquals("El resultado debería ser el CostingRule esperado", expectedRule, result);
assertNotNull("The result should not be null", result);
assertEquals("The result should be the expected CostingRule", expectedRule, result);
}
}

Expand All @@ -89,14 +89,14 @@ public void testGetLEsCostingAlgortithmNoRulesFound() throws Exception {
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)))
Mockito.when(mockQuery.setNamedParameter(Mockito.eq(TestUtils.ORG_IDS), 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);
assertNull("The result should be null when no rules are found" , result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,7 @@ public class ReportValuationStockAddParametersTest {

private ReportValuationStock reportValuationStock;

private static final String TEST_ORG_ID = "testOrgId";
private static final String TEST_WAREHOUSE_ID = "testWarehouseId";
private static final String TEST_CATEGORY_ID = "testCategoryId";
private static final String TEST_CURRENCY_ID = "testCurrencyId";
private static final String TEST_DATE = "2024-01-01";


/**
* Set up the test environment, including mocks and static contexts.
Expand Down Expand Up @@ -146,12 +142,12 @@ public void testAddAdditionalParametersValidInput() throws Exception {
JSONObject jsonContent = new JSONObject();
JSONObject params = new JSONObject();

params.put("AD_Org_ID", TEST_ORG_ID);
params.put("M_Warehouse_ID", TEST_WAREHOUSE_ID);
params.put("AD_Org_ID", TestUtils.TEST_ORG_ID);
params.put("M_Warehouse_ID", TestUtils.TEST_WAREHOUSE_ID);
params.put("WarehouseConsolidation", true);
params.put("M_Product_Category_ID", TEST_CATEGORY_ID);
params.put("C_Currency_ID", TEST_CURRENCY_ID);
params.put("Date", TEST_DATE);
params.put("M_Product_Category_ID", TestUtils.TEST_CATEGORY_ID);
params.put("C_Currency_ID", TestUtils.TEST_CURRENCY_ID);
params.put("Date", TestUtils.TEST_DATE);

jsonContent.put("_params", params);
jsonContent.put(ApplicationConstants.BUTTON_VALUE, "PDF");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,7 @@ public class ReportValuationStockBuildDataTest {
private OrganizationStructureProvider mockOsp;

private Method buildDataMethod;
private static final String TEST_DATE = "2024-01-01";
private static final String TEST_ORG_ID = "testOrgId";
private static final String TEST_WAREHOUSE_ID = "testWarehouseId";
private static final String TEST_CATEGORY_ID = "testCategoryId";
private static final String TEST_CURRENCY_ID = "testCurrencyId";
private static final String TEST_CLIENT_ID = "testClientId";
private static final String WAREHOUSE_NOT_IN_LE = "WarehouseNotInLE";



/**
Expand All @@ -95,10 +89,10 @@ public void setUp() throws Exception {
);
buildDataMethod.setAccessible(true);

when(mockClient.getId()).thenReturn(TEST_CLIENT_ID);
when(mockClient.getId()).thenReturn(TestUtils.TEST_CLIENT_ID);

Set<String> orgTree = new HashSet<>();
orgTree.add(TEST_ORG_ID);
orgTree.add(TestUtils.TEST_ORG_ID);
}

/**
Expand Down Expand Up @@ -130,28 +124,28 @@ public void testBuildDataWithNullLegalEntity() {
when(mockOsp.getLegalEntity(any(Organization.class))).thenReturn(null);

OBError mockError = mock(OBError.class);
when(mockError.getMessage()).thenReturn(WAREHOUSE_NOT_IN_LE);
when(mockError.getMessage()).thenReturn(TestUtils.WAREHOUSE_NOT_IN_LE);
obMessageUtilsMock.when(() -> OBMessageUtils.messageBD(anyString()))
.thenReturn(WAREHOUSE_NOT_IN_LE);
.thenReturn(TestUtils.WAREHOUSE_NOT_IN_LE);
obMessageUtilsMock.when(() -> OBMessageUtils.translateError(anyString()))
.thenReturn(mockError);

try {
buildDataMethod.invoke(
reportValuationStock,
vars,
TEST_DATE,
TEST_ORG_ID,
TEST_WAREHOUSE_ID,
TEST_CATEGORY_ID,
TEST_CURRENCY_ID,
TestUtils.TEST_DATE,
TestUtils.TEST_ORG_ID,
TestUtils.TEST_WAREHOUSE_ID,
TestUtils.TEST_CATEGORY_ID,
TestUtils.TEST_CURRENCY_ID,
false,
parameters
);
} catch (Exception e) {
assertTrue("Expected ServletException", e.getCause() instanceof ServletException);
assertTrue("Expected correct error message",
StringUtils.contains(e.getCause().getMessage(), WAREHOUSE_NOT_IN_LE));
StringUtils.contains(e.getCause().getMessage(), TestUtils.WAREHOUSE_NOT_IN_LE));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
@RunWith(MockitoJUnitRunner.class)
public class ReportValuationStockGetReportTest {

private static final String PROCESS_TIME = "processTime";

@Mock
private VariablesSecureApp vars;

Expand All @@ -56,21 +54,7 @@ public class ReportValuationStockGetReportTest {
private ReportValuationStock reportValuationStock;
private Method getReportValuationStockDataMethod;

private static final String TEST_DATE = "2024-01-01";
private static final String TEST_CATEGORY = "TEST_CATEGORY";
private static final String TEST_CURRENCY = "102";
private static final String TEST_WAREHOUSE = "TEST_WAREHOUSE";
private static final String TEST_ORG = "TEST_ORG";
private static final String TEST_CLIENT = "TEST_CLIENT";
private static final String TEST_LANGUAGE = "en_US";

private static final String DATE_NEXT = "dateNext";
private static final String MAX_AGG_DATE = "maxAggDate";
private static final String DATE_FORMAT = "dateFormat";
private static final String ORG_IDS = "orgIds";
private static final String ERROR_RESULT_NULL = "Result should not be null";
private static final String ERROR_DATA_LENGTH = "Should return expected data length";
private static final String ERROR_EXPECTED_DATA = "Should return expected data";


/**
Expand All @@ -92,7 +76,7 @@ public void setUp() throws Exception {
);
getReportValuationStockDataMethod.setAccessible(true);

when(vars.getLanguage()).thenReturn(TEST_LANGUAGE);
when(vars.getLanguage()).thenReturn(TestUtils.TEST_LANGUAGE);
}

/**
Expand All @@ -115,14 +99,14 @@ public void testGetReportDataWithCostTypeAndNoWarehouseConsolidation() throws Ex

ReportValuationStockData[] result = (ReportValuationStockData[]) getReportValuationStockDataMethod.invoke(
reportValuationStock,
vars, TEST_DATE, TEST_CATEGORY, TEST_CURRENCY, false, PROCESS_TIME,
"N", "STA", TEST_WAREHOUSE, readOnlyCP, filterOrg, TEST_ORG,
ORG_IDS, TEST_ORG, TEST_CLIENT, DATE_NEXT, MAX_AGG_DATE, DATE_FORMAT
vars, TestUtils.TEST_DATE, TestUtils.TEST_CATEGORY, TestUtils.TEST_CURRENCY, false, TestUtils.PROCESS_TIME,
"N", "STA", TestUtils.TEST_WAREHOUSE, readOnlyCP, filterOrg, TestUtils.TEST_ORG,
TestUtils.ORG_IDS, TestUtils.TEST_ORG, TestUtils.TEST_CLIENT, TestUtils.DATE_NEXT, TestUtils.MAX_AGG_DATE, TestUtils.DATE_FORMAT
);

assertNotNull(ERROR_RESULT_NULL, result);
assertEquals(ERROR_DATA_LENGTH, expectedData.length, result.length);
assertEquals(ERROR_EXPECTED_DATA, expectedData[0], result[0]);
assertNotNull(TestUtils.ERROR_RESULT_NULL, result);
assertEquals(TestUtils.ERROR_DATA_LENGTH, expectedData.length, result.length);
assertEquals(TestUtils.ERROR_EXPECTED_DATA, expectedData[0], result[0]);
}
}

Expand All @@ -145,14 +129,14 @@ public void testGetReportDataWithoutCostTypeAndWithWarehouseConsolidation() thro

ReportValuationStockData[] result = (ReportValuationStockData[]) getReportValuationStockDataMethod.invoke(
reportValuationStock,
vars, TEST_DATE, TEST_CATEGORY, TEST_CURRENCY, true, PROCESS_TIME,
"N", null, TEST_WAREHOUSE, readOnlyCP, filterOrg, TEST_ORG,
ORG_IDS, TEST_ORG, TEST_CLIENT, DATE_NEXT, MAX_AGG_DATE, DATE_FORMAT
vars, TestUtils.TEST_DATE, TestUtils.TEST_CATEGORY, TestUtils.TEST_CURRENCY, true, TestUtils.PROCESS_TIME,
"N", null, TestUtils.TEST_WAREHOUSE, readOnlyCP, filterOrg, TestUtils.TEST_ORG,
TestUtils.ORG_IDS, TestUtils.TEST_ORG, TestUtils.TEST_CLIENT, TestUtils.DATE_NEXT, TestUtils.MAX_AGG_DATE, TestUtils.DATE_FORMAT
);

assertNotNull(ERROR_RESULT_NULL, result);
assertEquals(ERROR_DATA_LENGTH, expectedData.length, result.length);
assertEquals(ERROR_EXPECTED_DATA, expectedData[0], result[0]);
assertNotNull(TestUtils.ERROR_RESULT_NULL, result);
assertEquals(TestUtils.ERROR_DATA_LENGTH, expectedData.length, result.length);
assertEquals(TestUtils.ERROR_EXPECTED_DATA, expectedData[0], result[0]);
}
}

Expand All @@ -175,14 +159,14 @@ public void testGetReportDataWithoutCostTypeAndNoWarehouseConsolidation() throws

ReportValuationStockData[] result = (ReportValuationStockData[]) getReportValuationStockDataMethod.invoke(
reportValuationStock,
vars, TEST_DATE, TEST_CATEGORY, TEST_CURRENCY, false, PROCESS_TIME,
"N", null, TEST_WAREHOUSE, readOnlyCP, filterOrg, TEST_ORG,
ORG_IDS, TEST_ORG, TEST_CLIENT, DATE_NEXT, MAX_AGG_DATE, DATE_FORMAT
vars, TestUtils.TEST_DATE, TestUtils.TEST_CATEGORY, TestUtils.TEST_CURRENCY, false, TestUtils.PROCESS_TIME,
"N", null, TestUtils.TEST_WAREHOUSE, readOnlyCP, filterOrg, TestUtils.TEST_ORG,
TestUtils.ORG_IDS, TestUtils.TEST_ORG, TestUtils.TEST_CLIENT, TestUtils.DATE_NEXT, TestUtils.MAX_AGG_DATE, TestUtils.DATE_FORMAT
);

assertNotNull(ERROR_RESULT_NULL, result);
assertEquals(ERROR_DATA_LENGTH, expectedData.length, result.length);
assertEquals(ERROR_EXPECTED_DATA, expectedData[0], result[0]);
assertNotNull(TestUtils.ERROR_RESULT_NULL, result);
assertEquals(TestUtils.ERROR_DATA_LENGTH, expectedData.length, result.length);
assertEquals(TestUtils.ERROR_EXPECTED_DATA, expectedData[0], result[0]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
@RunWith(MockitoJUnitRunner.class)
public class ReportValuationStockParametersTest {

private static final String TEST_ORG_ID = "testOrgId";


@Mock
private ReportDefinition mockProcess;
Expand Down Expand Up @@ -109,7 +107,7 @@ public void testAddAdditionalParametersInvalidDate() throws Exception {
JSONObject jsonContent = new JSONObject();
JSONObject params = new JSONObject();

params.put("AD_Org_ID", TEST_ORG_ID);
params.put("AD_Org_ID", TestUtils.TEST_ORG_ID);
params.put("Date", "invalid-date");
jsonContent.put("_params", params);

Expand Down
Loading

0 comments on commit 2ebb18d

Please sign in to comment.