-
Notifications
You must be signed in to change notification settings - Fork 7
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 #54 from mendix/dat/fix/large-decimal-logging
Allow avoiding scientific notation in big decimal logging
- Loading branch information
Showing
9 changed files
with
144 additions
and
46 deletions.
There are no files selected for viewing
Binary file not shown.
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 |
---|---|---|
@@ -1,7 +1,5 @@ | ||
## Building locally | ||
|
||
In order to prepare userlib folder to run the project locally, use `./gradlew prepareTest`. To keep only jars that are needed for the release, use `./gradlew prepareMpk`. | ||
|
||
`./gradlew mxBuild` builds the app locally. | ||
|
||
`./gradlew exportModule` creates an mpk to be released with only necessary jars included in userlib. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version=9.1.1 | ||
version=9.1.2 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
We added the "LogUseDecimalScientificNotation" constant to control how large decimal values are displayed. The default behaviour is to use scientific notation, which can be changed to show the full value instead. |
81 changes: 81 additions & 0 deletions
81
src/test/java/com/mendix/audittrail/tests/TestAuditConstants.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,81 @@ | ||
package com.mendix.audittrail.tests; | ||
|
||
import audittrail.proxies.TypeOfLog; | ||
import com.mendix.audittrail.tests.actual.ActualLog; | ||
import com.mendix.audittrail.tests.expected.ExpectedLog; | ||
import com.mendix.core.CoreException; | ||
import com.mendix.systemwideinterfaces.core.IContext; | ||
import org.junit.Test; | ||
import test_crm.proxies.Company; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.when; | ||
import static test_crm.proxies.Company.MemberNames.Dec; | ||
|
||
public class TestAuditConstants extends TestAuditWithData { | ||
@Test | ||
public void testLogUseDecimalScientificNotationIsTrue() throws CoreException { | ||
context = mockContextWithSetConstantValue(context, true); | ||
// Create new record | ||
final Company company = createBaseCompanyAndSetDecimalValue(); | ||
|
||
// Expect scientific decimal format in log | ||
final ExpectedLog expectedLog = createExpectedLog(TypeOfLog.Add, company).addAttribute(Dec, DEC_STRING_SCIENTIFIC); | ||
|
||
final ActualLog actualLog = ActualLog.getLastLog(context, company.getMendixObject().getId().toLong()); | ||
expectedLog.verify(actualLog); | ||
} | ||
|
||
@Test | ||
public void testLogUseDecimalScientificNotationIsFalse() throws CoreException { | ||
context = mockContextWithSetConstantValue(context, false); | ||
// Create new record | ||
final Company company = createBaseCompanyAndSetDecimalValue(); | ||
|
||
// Expect full decimal format in log | ||
final ExpectedLog expectedLog = createExpectedLog(TypeOfLog.Add, company).addAttribute(Dec, DEC_STRING_FULL); | ||
|
||
final ActualLog actualLog = ActualLog.getLastLog(context, company.getMendixObject().getId().toLong()); | ||
expectedLog.verify(actualLog); | ||
} | ||
|
||
@Test | ||
public void testLogUseDecimalScientificNotationIsNotSet() throws CoreException { | ||
// Create new record | ||
final Company company = createBaseCompanyAndSetDecimalValue(); | ||
|
||
// Expect scientific decimal format in log | ||
final ExpectedLog expectedLog = createExpectedLog(TypeOfLog.Add, company).addAttribute(Dec, DEC_STRING_SCIENTIFIC); | ||
|
||
final ActualLog actualLog = ActualLog.getLastLog(context, company.getMendixObject().getId().toLong()); | ||
expectedLog.verify(actualLog); | ||
} | ||
|
||
private IContext mockContextWithSetConstantValue(IContext context, Boolean decimalNotationConstantValue) { | ||
IContext spyContext = spy(context); | ||
com.mendix.core.conf.Configuration configSpy = spy(spyContext.getSystemConfiguration()); | ||
when(spyContext.getSystemConfiguration()).thenReturn(configSpy); | ||
when(spyContext.clone()).thenReturn(spyContext); | ||
when(configSpy.getConstantValue("AuditTrail.LogUseDecimalScientificNotation")) | ||
.thenReturn(decimalNotationConstantValue); | ||
return spyContext; | ||
} | ||
|
||
protected Company createBaseCompanyAndSetDecimalValue() throws CoreException { | ||
final Company company = new Company(context); | ||
|
||
company.setName(NAME); | ||
company.setCompanyNr(COMPANY_NR); | ||
company.setDec(DEC); | ||
|
||
company.commit(); | ||
return company; | ||
} | ||
|
||
private static final BigDecimal DEC = BigDecimal.valueOf(1000); | ||
private static final String DEC_STRING_SCIENTIFIC = "1E+3"; | ||
private static final String DEC_STRING_FULL = "1000"; | ||
|
||
} |
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
53 changes: 53 additions & 0 deletions
53
src/test/java/com/mendix/audittrail/tests/TestAuditWithData.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,53 @@ | ||
package com.mendix.audittrail.tests; | ||
|
||
import audittrail.proxies.MemberType; | ||
import audittrail.proxies.TypeOfLog; | ||
import com.mendix.audittrail.tests.expected.ExpectedLog; | ||
import com.mendix.core.CoreException; | ||
import com.mendix.systemwideinterfaces.core.IMendixObject; | ||
import test_crm.proxies.Company; | ||
import test_crm.proxies.Group; | ||
|
||
import java.util.Arrays; | ||
|
||
import static test_crm.proxies.Company.MemberNames.*; | ||
import static test_crm.proxies.Company.MemberNames.Company_Group; | ||
|
||
/** | ||
* Helper class for creating tests with a company objects | ||
*/ | ||
public abstract class TestAuditWithData extends TestAuditBase { | ||
protected Company createBaseCompany(final Group... groups) throws CoreException { | ||
final Company company = new Company(context); | ||
|
||
company.setName(NAME); | ||
company.setCompanyNr(COMPANY_NR); | ||
|
||
company.setCompany_Group(Arrays.asList(groups)); | ||
|
||
company.commit(); | ||
return company; | ||
} | ||
|
||
protected ExpectedLog createExpectedLog(final TypeOfLog typeOfLog, final Company company, | ||
final IMendixObject... groupObjects) { | ||
if (typeOfLog.equals(TypeOfLog.Add)) { | ||
return new ExpectedLog(typeOfLog, Company.entityName, admin, initialDate, Company.entityName) | ||
.addAttribute(Name, NAME).addAttribute(CompanyNr, COMPANY_NR) | ||
.addAttribute(InternNr, company.getInternNr()) | ||
.addAttribute(Dec, 0).addAttribute(Number, 0) | ||
.addAttribute(Founded, "") | ||
.addReferences(Company_Group, context, MemberType.ReferenceSet, groupObjects); | ||
} else { | ||
return new ExpectedLog(typeOfLog, Company.entityName, admin, initialDate, Company.entityName) | ||
.keepAttribute(Name, NAME).keepAttribute(CompanyNr, COMPANY_NR) | ||
.keepAttribute(InternNr, company.getInternNr()) | ||
.keepAttribute(Dec, 0).keepAttribute(Number, 0) | ||
.keepAttribute(Founded, "") | ||
.keepReferences(Company_Group, context, MemberType.ReferenceSet, groupObjects); | ||
} | ||
} | ||
|
||
protected static final String NAME = "Company"; | ||
protected static final String COMPANY_NR = "123"; | ||
} |