Skip to content

Commit

Permalink
[WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
jongpie committed Oct 15, 2024
1 parent ede47f1 commit 5d33c4f
Show file tree
Hide file tree
Showing 35 changed files with 189 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
// TODO Add Apex docs
@SuppressWarnings('PMD.ApexDoc, PMD.ApexCRUDViolation')
public without sharing virtual class LoggerConfigurationDataSelector {
public without sharing class LoggerConfigurationDataSelector {
private static final LoggerConfigurationDataSelector INSTANCE = new LoggerConfigurationDataSelector();

@TestVisible
Expand Down Expand Up @@ -43,7 +43,7 @@ public without sharing virtual class LoggerConfigurationDataSelector {
}

// TODO decide if LoggerSettings__c should be here (I don't think so)
public virtual List<LogEntryDataMaskRule__mdt> getLogEntryDataMaskRules() {
public List<LogEntryDataMaskRule__mdt> getLogEntryDataMaskRules() {
return mockLogEntryDataMaskRules ?? LogEntryDataMaskRule__mdt.getAll().values().deepClone();
}

Expand All @@ -52,7 +52,7 @@ public without sharing virtual class LoggerConfigurationDataSelector {
* including the field `SObjectField__r.QualifiedApiName` that cannot be accessed via `LogEntryTagRule__mdt.getAll()`
* @return The cached `List<LogEntryTagRule__mdt>` records
*/
public virtual List<LogEntryTagRule__mdt> getLogEntryTagRules() {
public List<LogEntryTagRule__mdt> getLogEntryTagRules() {
List<LogEntryTagRule__mdt> rules = [
SELECT Id, SObjectField__r.QualifiedApiName, ComparisonType__c, ComparisonValue__c, Tags__c
FROM LogEntryTagRule__mdt
Expand All @@ -64,39 +64,54 @@ public without sharing virtual class LoggerConfigurationDataSelector {
}

for (LogEntryTagRule__mdt rule : rules) {
rule.SObjectField__c = rule.SObjectField__r.QualifiedApiName;
rule.SObjectField__c = rule.SObjectField__r.QualifiedApiName ?? rule.SObjectField__c;
}
return rules;
}

public virtual List<LoggerFieldMapping__mdt> getLoggerFieldMappings() {
return mockLoggerFieldMappings ??
[
SELECT
DeveloperName,
IsEnabled__c,
SourceSObjectType__r.QualifiedApiName,
SourceField__r.QualifiedApiName,
TargetSObjectType__r.QualifiedApiName,
TargetField__r.QualifiedApiName
FROM LoggerFieldMapping__mdt
WHERE IsEnabled__c = TRUE
];
public List<LoggerFieldMapping__mdt> getLoggerFieldMappings() {
List<LoggerFieldMapping__mdt> fieldMappings = [
SELECT
DeveloperName,
IsEnabled__c,
SourceSObjectType__r.QualifiedApiName,
SourceField__r.QualifiedApiName,
TargetSObjectType__r.QualifiedApiName,
TargetField__r.QualifiedApiName
FROM LoggerFieldMapping__mdt
WHERE IsEnabled__c = TRUE
];

if (mockLoggerFieldMappings != null) {
fieldMappings = mockLoggerFieldMappings;
}

for (LoggerFieldMapping__mdt fieldMapping : fieldMappings) {
fieldMapping.SourceSObjectType__c = fieldMapping.SourceSObjectType__r.QualifiedApiName ?? fieldMapping.SourceSObjectType__c;
fieldMapping.SourceField__c = fieldMapping.SourceField__r.QualifiedApiName ?? fieldMapping.SourceField__c;
fieldMapping.TargetSObjectType__c = fieldMapping.TargetSObjectType__r.QualifiedApiName ?? fieldMapping.TargetSObjectType__c;
fieldMapping.TargetField__c = fieldMapping.TargetField__r.QualifiedApiName ?? fieldMapping.TargetField__c;
}

return fieldMappings;
}

public virtual Map<String, LoggerParameter__mdt> getLoggerParameters() {
public Map<String, LoggerParameter__mdt> getLoggerParameters() {
return mockLoggerParameters ?? LoggerParameter__mdt.getAll().deepClone();
}

public virtual List<LoggerPlugin__mdt> getLoggerPlugins() {
public List<LoggerPlugin__mdt> getLoggerPlugins() {
return mockLoggerPlugins ?? LoggerPlugin__mdt.getAll().values().deepClone();
}

public virtual List<LoggerScenarioRule__mdt> getLoggerScenarioRules() {
public List<LoggerScenarioRule__mdt> getLoggerScenarioRules() {
return mockLoggerScenarioRules ?? LoggerScenarioRule__mdt.getAll().values().deepClone();
}

public virtual List<LoggerSObjectHandler__mdt> getLoggerSObjectHandlers() {
public List<LoggerSObjectHandler__mdt> getLoggerSObjectHandlers() {
// TODO eventually update this method to handle mapping relationship fields to lookup fields,
// Example: handler.SObjectType__c = handler.SObjectType__r.QualifiedApiName;
// Right now, this is handled in LoggerSObjectHandler
return mockLoggerSObjectHandlers ??
[
SELECT IsEnabled__c, SObjectHandlerApexClass__c, SObjectType__r.QualifiedApiName, SObjectTypeOverride__c
Expand All @@ -105,7 +120,7 @@ public without sharing virtual class LoggerConfigurationDataSelector {
];
}

public virtual List<LogStatus__mdt> getLogStatuses() {
public List<LogStatus__mdt> getLogStatuses() {
return mockLogStatuses ?? LogStatus__mdt.getAll().values().deepClone();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ public without sharing class LoggerFieldMapper {
private static Map<Schema.SObjectType, Map<Schema.SObjectType, List<LoggerFieldMapping__mdt>>> loadRecords() {
Map<Schema.SObjectType, Map<Schema.SObjectType, List<LoggerFieldMapping__mdt>>> sourceSObjectTypeToTargetFieldMappings = new Map<Schema.SObjectType, Map<Schema.SObjectType, List<LoggerFieldMapping__mdt>>>();
for (LoggerFieldMapping__mdt fieldMapping : LoggerConfigurationDataSelector.getInstance().getLoggerFieldMappings()) {
fieldMapping.SourceSObjectType__c = fieldMapping.SourceSObjectType__c ?? fieldMapping.SourceSObjectType__r.QualifiedApiName;
fieldMapping.SourceField__c = fieldMapping.SourceField__c ?? fieldMapping.SourceField__r.QualifiedApiName;
fieldMapping.TargetSObjectType__c = fieldMapping.TargetSObjectType__c ?? fieldMapping.TargetSObjectType__r.QualifiedApiName;
fieldMapping.TargetField__c = fieldMapping.TargetField__c ?? fieldMapping.TargetField__r.QualifiedApiName;
addFieldMapping(fieldMapping, sourceSObjectTypeToTargetFieldMappings);
}

Expand Down
1 change: 1 addition & 0 deletions nebula-logger/core/main/logger-engine/classes/Logger.cls
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ global with sharing class Logger {
// The rest of the codebase should use a method in Logger.cls
System.debug(System.LoggingLevel.INFO, 'Nebula Logger - Version Number: ' + getVersionNumber());
System.debug(System.LoggingLevel.INFO, 'Nebula Logger - Transaction ID: ' + getTransactionId());
System.debug(System.LoggingLevel.INFO, 'Nebula Logger - Request ID: ' + REQUEST_ID);
System.debug(System.LoggingLevel.INFO, 'Nebula Logger - Organization API Version: ' + getOrganizationApiVersion());
setScenario(getUserSettings().DefaultScenario__c);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ private class LoggerConfigurationDataSelector_Tests {
FROM LoggerFieldMapping__mdt
WHERE IsEnabled__c = TRUE
];
for (LoggerFieldMapping__mdt fieldMapping : expectedValues) {
fieldMapping.SourceSObjectType__c = fieldMapping.SourceSObjectType__r.QualifiedApiName ?? fieldMapping.SourceSObjectType__c;
fieldMapping.SourceField__c = fieldMapping.SourceField__r.QualifiedApiName ?? fieldMapping.SourceField__c;
fieldMapping.TargetSObjectType__c = fieldMapping.TargetSObjectType__r.QualifiedApiName ?? fieldMapping.TargetSObjectType__c;
fieldMapping.TargetField__c = fieldMapping.TargetField__r.QualifiedApiName ?? fieldMapping.TargetField__c;
}

List<LoggerFieldMapping__mdt> returnedValues = LoggerConfigurationDataSelector.getInstance().getLoggerFieldMappings();

Expand Down Expand Up @@ -201,7 +207,4 @@ private class LoggerConfigurationDataSelector_Tests {

System.Assert.areEqual(LoggerConfigurationDataSelector.mockLogStatuses, returnedValues);
}

private class MockLoggerConfigurationDataSelector extends LoggerConfigurationDataSelector {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ private class LogBatchPurgeController_Tests {
private static final String CAN_EXECUTE_LOG_BATCH_PURGER_PERMISSION = 'CanExecuteLogBatchPurger';
private static final Schema.Profile STANDARD_USER_PROFILE = [SELECT Id FROM Profile WHERE Name IN ('Standard User', 'Usuario estándar', '標準ユーザー')];

static {
// Don't use the org's actual custom metadata records when running tests
LoggerConfigurationDataSelector.useMocks();
}

@IsTest
static void it_should_return_logPurgeAction_options() {
List<String> fakeLogPurgeActions = new List<String>{ 'A_FAKE_PURGE_ACTION', 'ANOTHER_ONE', 'SOME_OTHER_PURGE_ACTION' };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
@SuppressWarnings('PMD.ApexDoc, PMD.CyclomaticComplexity, PMD.ExcessiveParameterList, PMD.MethodNamingConventions, PMD.NcssMethodCount')
@IsTest(IsParallel=true)
private class LogBatchPurgeScheduler_Tests {
static {
// Don't use the org's actual custom metadata records when running tests
LoggerConfigurationDataSelector.useMocks();
}

@IsTest
static void it_implements_system_schedulable_interface() {
Object scheduler = new LogBatchPurgeScheduler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ private class LogBatchPurger_Tests {
private static LoggerBatchableContext batchInput;
private static List<SObject> pluginRecords;

static {
// Don't use the org's actual custom metadata records when running tests
LoggerConfigurationDataSelector.useMocks();
}

@TestSetup
static void setupData() {
LoggerSObjectHandler.shouldExecute(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
@SuppressWarnings('PMD.ApexDoc, PMD.CyclomaticComplexity, PMD.ExcessiveParameterList, PMD.MethodNamingConventions, PMD.NcssMethodCount')
@IsTest
private class LogEntryEventStreamController_Tests {
static {
// Don't use the org's actual custom metadata records when running tests
LoggerConfigurationDataSelector.useMocks();
}

@IsTest
static void it_should_return_is_enabled_parameter() {
Boolean mockValue = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
@SuppressWarnings('PMD.ApexDoc, PMD.MethodNamingConventions')
@IsTest(IsParallel=true)
private class LogEntryFieldSetPicklist_Tests {
static {
// Don't use the org's actual custom metadata records when running tests
LoggerConfigurationDataSelector.useMocks();
}

@IsTest
static void it_should_return_null_for_default_value_when_empty_value_is_configured() {
String emptyFieldSetName = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
private class LogEntryHandler_Tests {
private static final Boolean IS_OMNISTUDIO_ENABLED = System.Type.forName('Schema.OmniProcess') != null;

static {
// Don't use the org's actual custom metadata records when running tests
LoggerConfigurationDataSelector.useMocks();
}

@TestSetup
static void setupData() {
LoggerSObjectHandler.shouldExecute(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ private class LogEntryMetadataViewerController_Tests {
private static final String SOURCE_METADATA_ORIGIN = 'Origin';

static {
// Don't use the org's actual custom metadata records when running tests
LoggerConfigurationDataSelector.useMocks();
LogManagementDataSelector.setMock(MOCK_SELECTOR);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
@SuppressWarnings('PMD.ApexDoc, PMD.CyclomaticComplexity, PMD.ExcessiveParameterList, PMD.MethodNamingConventions, PMD.NcssMethodCount')
@IsTest(IsParallel=true)
private class LogEntryTagHandler_Tests {
static {
// Don't use the org's actual custom metadata records when running tests
LoggerConfigurationDataSelector.useMocks();
}

@TestSetup
static void setupData() {
LoggerSObjectHandler.shouldExecute(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ private class LogHandler_Tests {
private static final String FIRST_STATUS = Schema.Log__c.Status__c.getDescribe().getPicklistValues().get(0).getValue();
private static final String SECOND_STATUS = Schema.Log__c.Status__c.getDescribe().getPicklistValues().get(1).getValue();

static {
// Don't use the org's actual custom metadata records when running tests
LoggerConfigurationDataSelector.useMocks();
}

@IsTest
static void it_should_return_the_log_sobjectType() {
System.Assert.areEqual(Schema.Log__c.SObjectType, new LogHandler().getSObjectType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ private class LogManagementDataSelector_Tests {
@TestVisible
private static final Boolean IS_OMNISTUDIO_ENABLED = System.Type.forName('Schema.OmniProcess') != null;

static {
// Don't use the org's actual custom metadata records when running tests
LoggerConfigurationDataSelector.useMocks();
}

@IsTest
static void it_dynamically_queries_all_records_for_specified_sobject_type_and_fields() {
Schema.SObjectType targetSObjectType = Schema.Organization.SObjectType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
@SuppressWarnings('PMD.ApexDoc, PMD.CyclomaticComplexity, PMD.ExcessiveParameterList, PMD.MethodNamingConventions, PMD.NcssMethodCount')
@IsTest(IsParallel=false)
private class LogMassDeleteExtension_Tests {
static {
// Don't use the org's actual custom metadata records when running tests
LoggerConfigurationDataSelector.useMocks();
}

@TestSetup
static void setupData() {
LoggerSObjectHandler.shouldExecute(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
@SuppressWarnings('PMD.ApexDoc, PMD.MethodNamingConventions')
@IsTest(IsParallel=true)
private class LogViewerController_Tests {
static {
// Don't use the org's actual custom metadata records when running tests
LoggerConfigurationDataSelector.useMocks();
}

@TestSetup
static void setupData() {
LoggerSObjectHandler.shouldExecute(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
@SuppressWarnings('PMD.MethodNamingConventions')
@IsTest(IsParallel=true)
private class LoggerBatchableContext_Tests {
static {
// Don't use the org's actual custom metadata records when running tests
LoggerConfigurationDataSelector.useMocks();
}

@IsTest
static void it_constructs_instance_when_both_parameters_provided() {
Database.BatchableContext mockBatchableContext = new LoggerMockDataCreator.MockBatchableContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ private class LoggerEmailSender_Tests {
set;
}

static {
// Don't use the org's actual custom metadata records when running tests
LoggerConfigurationDataSelector.useMocks();
}

@IsTest
static void it_should_indicate_email_deliverability_is_based_on_email_deliverability_when_org_limits_not_exceeded() {
System.OrgLimit singleEmailOrgLimit = OrgLimits.getMap().get('SingleEmail');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
@SuppressWarnings('PMD.MethodNamingConventions')
@IsTest(IsParallel=true)
private class LoggerHomeHeaderController_Tests {
static {
// Don't use the org's actual custom metadata records when running tests
LoggerConfigurationDataSelector.useMocks();
}

@IsTest
public static void it_returns_environment_details_when_status_api_callout_is_enabled() {
LoggerParameter.setMock(new LoggerParameter__mdt(DeveloperName = 'CallStatusApi', Value__c = System.JSON.serialize(true)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
@SuppressWarnings('PMD.ApexDoc, PMD.ApexUnitTestClassShouldHaveAsserts, PMD.MethodNamingConventions')
@IsTest(IsParallel=true)
private class LoggerSObjectMetadata_Tests {
static {
// Don't use the org's actual custom metadata records when running tests
LoggerConfigurationDataSelector.useMocks();
}

@IsTest
static void it_should_return_schema_for_specified_sobject_api_name() {
Schema.SObjectType userSObjectType = Schema.User.SObjectType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
@SuppressWarnings('PMD.ApexDoc, PMD.CyclomaticComplexity, PMD.ExcessiveParameterList, PMD.MethodNamingConventions, PMD.NcssMethodCount')
@IsTest(IsParallel=true)
private class LoggerScenarioHandler_Tests {
static {
// Don't use the org's actual custom metadata records when running tests
LoggerConfigurationDataSelector.useMocks();
}

@IsTest
static void it_should_return_the_loggerScenario_sobjectType() {
System.Assert.areEqual(Schema.LoggerScenario__c.SObjectType, new LoggerScenarioHandler().getSObjectType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
@SuppressWarnings('PMD.ApexDoc, PMD.CyclomaticComplexity, PMD.ExcessiveParameterList, PMD.MethodNamingConventions')
@IsTest(IsParallel=false)
private class LoggerSettingsController_Tests {
static {
// Don't use the org's actual custom metadata records when running tests
LoggerConfigurationDataSelector.useMocks();
}

@IsTest
static void it_should_return_loggingLevel_picklist_options() {
Integer expectedLoggingLevelSize = System.LoggingLevel.values().size() - 1; // LoggingLEVEL.NONE and System.LoggingLevel.INTERNAL are ignored, '--NONE--' is automatically included
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
@SuppressWarnings('PMD.ApexDoc, PMD.CyclomaticComplexity, PMD.ExcessiveParameterList, PMD.MethodNamingConventions, PMD.NcssMethodCount')
@IsTest(IsParallel=true)
private class LoggerTagHandler_Tests {
static {
// Don't use the org's actual custom metadata records when running tests
LoggerConfigurationDataSelector.useMocks();
}

@IsTest
static void it_should_return_the_loggerTag_sobjectType() {
System.Assert.areEqual(Schema.LoggerTag__c.SObjectType, new LoggerTagHandler().getSObjectType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ private class RelatedLogEntriesController_Tests {
private static final Integer TOTAL_LOG_ENTRIES = 10;
private static final Integer TOTAL_RELATED_LOG_ENTRIES = 7;

static {
// Don't use the org's actual custom metadata records when running tests
LoggerConfigurationDataSelector.useMocks();
}

static String getFieldSetName() {
Schema.FieldSet fieldSet = Schema.SObjectType.LogEntry__c.fieldSets.getMap().values().get(0);
String fieldSetNamespacePrefix = String.isBlank(fieldSet.getNameSpace()) ? '' : fieldSet.getNameSpace() + '__';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ private class CallableLogger_Tests {
private static final String TEST_OMNI_PROCESS_ID = '0jNDL000000Cbac2AC';

static {
// Don't use the org's actual custom metadata records when running tests
LoggerConfigurationDataSelector.useMocks();
CallableLogger.returnLogEntryEventBuilderInOutput = true;
}

Expand Down
Loading

0 comments on commit 5d33c4f

Please sign in to comment.