diff --git a/src/applications/Nebula.app b/src/applications/Nebula.app
new file mode 100644
index 0000000..ff89ffb
--- /dev/null
+++ b/src/applications/Nebula.app
@@ -0,0 +1,7 @@
+
+
+ NebulaLog__c
+ Large
+
+ NebulaLog__c
+
diff --git a/src/classes/DML.cls b/src/classes/DML.cls
new file mode 100644
index 0000000..3f88a83
--- /dev/null
+++ b/src/classes/DML.cls
@@ -0,0 +1,84 @@
+/*************************************************************************************************
+* This file is part of the Nebula Framework project, released under the MIT License. *
+* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. *
+*************************************************************************************************/
+public abstract class DML extends NebulaCore implements IDML {
+
+ private Schema.SObjectType sobjectType;
+
+ public DML(Schema.SObjectType sobjectType) {
+ this.sobjectType = sobjectType;
+ }
+
+ public virtual void insertRecords(SObject record) {
+ this.insertRecords(new List{record});
+ }
+
+ public virtual void insertRecords(List records) {
+ Database.insert(records);
+ }
+
+ public virtual void updateRecords(SObject record) {
+ this.updateRecords(new List{record});
+ }
+
+ public virtual void updateRecords(List records) {
+ Database.update(records);
+ }
+
+ public virtual void upsertRecords(SObject record) {
+ this.upsertRecords(this.castRecords(record));
+ }
+
+ public virtual void upsertRecords(List records) {
+ Database.upsert(records);
+ }
+
+ public virtual void undeleteRecords(SObject record) {
+ this.undeleteRecords(new List{record});
+ }
+
+ public virtual void undeleteRecords(List records) {
+ Database.undelete(records);
+ }
+
+ public virtual void deleteRecords(SObject record) {
+ this.deleteRecords(new List{record});
+ }
+
+ public virtual void deleteRecords(List records) {
+ Database.delete(records);
+ }
+
+ public virtual void hardDeleteRecords(SObject record) {
+ this.hardDeleteRecords(new List{record});
+ }
+
+ public virtual void hardDeleteRecords(List records) {
+ this.deleteRecords(records);
+ if(!records.isEmpty()) Database.emptyRecycleBin(records);
+ }
+
+ // Not all objects will have external ID fields, so these methods are protected (instead of public)
+ // Any object that needs an upsert by external ID can expose these methods in their repos
+ protected virtual void upsertRecords(SObject record, Schema.SObjectField externalIdField) {
+ this.upsertRecords(this.castRecords(record), externalIdField);
+ }
+
+ protected virtual void upsertRecords(List records, Schema.SObjectField externalIdField) {
+ Database.upsert(records, externalIdField);
+ }
+
+ private List castRecords(SObject record) {
+ // Salesforce will only allow upsert calls for SObjects if a declared-type list is passed in.
+ // This is fine for the bulk method, where we can assume the caller is passing in an explicit list, but for a single record,
+ // the only way to successfully perform the upsert is to dynamically spin up a list of the SObject's type
+
+ String listType = 'List<' + this.sobjectType + '>';
+ List castRecords = (List)Type.forName(listType).newInstance();
+ castRecords.add(record);
+
+ return castRecords;
+ }
+
+}
\ No newline at end of file
diff --git a/src/classes/DML.cls-meta.xml b/src/classes/DML.cls-meta.xml
new file mode 100644
index 0000000..8b061c8
--- /dev/null
+++ b/src/classes/DML.cls-meta.xml
@@ -0,0 +1,5 @@
+
+
+ 39.0
+ Active
+
diff --git a/src/classes/DMLMock.cls b/src/classes/DMLMock.cls
new file mode 100644
index 0000000..677a376
--- /dev/null
+++ b/src/classes/DMLMock.cls
@@ -0,0 +1,62 @@
+/*************************************************************************************************
+* This file is part of the Nebula Framework project, released under the MIT License. *
+* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. *
+*************************************************************************************************/
+@isTest
+public class DMLMock {
+
+ public virtual class Base implements IDML {
+
+ public void insertRecords(SObject record) {
+ this.insertRecords(new List{record});
+ }
+
+ public void insertRecords(List recordList) {
+ TestingUtils.generateIds(recordList);
+ TestingUtils.insertedRecords.addAll(recordList);
+ }
+
+ public void updateRecords(SObject record) {
+ this.updateRecords(new List{record});
+ }
+
+ public void updateRecords(List recordList) {
+ TestingUtils.updatedRecords.addAll(recordList);
+ }
+
+ public void upsertRecords(SObject record) {
+ this.upsertRecords(new List{record});
+ }
+
+ public void upsertRecords(List recordList) {
+ TestingUtils.generateIds(recordList);
+ TestingUtils.upsertedRecords.addAll(recordList);
+ }
+
+ public void undeleteRecords(SObject record) {
+ this.undeleteRecords(new List{record});
+ }
+
+ public void undeleteRecords(List recordList) {
+ TestingUtils.undeletedRecords.addAll(recordList);
+ }
+
+ public void deleteRecords(SObject record) {
+ this.deleteRecords(new List{record});
+ }
+
+ public void deleteRecords(List recordList) {
+ if(recordList != null) TestingUtils.deletedRecords.addAll(recordList);
+ }
+
+ public void hardDeleteRecords(SObject record) {
+ this.hardDeleteRecords(new List{record});
+ }
+
+ public void hardDeleteRecords(List recordList) {
+ this.deleteRecords(recordList);
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/src/classes/DMLMock.cls-meta.xml b/src/classes/DMLMock.cls-meta.xml
new file mode 100644
index 0000000..8b061c8
--- /dev/null
+++ b/src/classes/DMLMock.cls-meta.xml
@@ -0,0 +1,5 @@
+
+
+ 39.0
+ Active
+
diff --git a/src/classes/DMLMock_Tests.cls b/src/classes/DMLMock_Tests.cls
new file mode 100644
index 0000000..d6e0e71
--- /dev/null
+++ b/src/classes/DMLMock_Tests.cls
@@ -0,0 +1,89 @@
+/*************************************************************************************************
+* This file is part of the Nebula Framework project, released under the MIT License. *
+* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. *
+*************************************************************************************************/
+@isTest
+private class DMLMock_Tests {
+
+ static IDML dmlRepo = new DMLMock.Base();
+ static Schema.Contact con = createContact();
+
+ @isTest
+ static void it_should_fake_dml_insert() {
+ Test.startTest();
+ dmlRepo.insertRecords(con);
+ Test.stopTest();
+
+ System.assert(TestingUtils.insertedRecords.size() > 0);
+ }
+
+ @isTest
+ static void it_should_fake_dml_update() {
+ Test.startTest();
+ dmlRepo.updateRecords(con);
+ Test.stopTest();
+
+ System.assert(!TestingUtils.updatedRecords.isEmpty());
+ }
+
+ @isTest
+ static void it_should_fake_dml_upsert() {
+ Test.startTest();
+ dmlRepo.upsertRecords(con);
+ Test.stopTest();
+
+ System.assert(!TestingUtils.upsertedRecords.isEmpty());
+ }
+
+ @isTest
+ static void it_should_fake_dml_delete() {
+ Test.startTest();
+ dmlRepo.deleteRecords(con);
+ Test.stopTest();
+
+ System.assert(!TestingUtils.deletedRecords.isEmpty());
+ }
+
+ @isTest
+ static void it_should_fake_dml_hard_delete() {
+ Test.startTest();
+ dmlRepo.hardDeleteRecords(con);
+ Test.stopTest();
+
+ System.assert(!TestingUtils.deletedRecords.isEmpty());
+ }
+
+ @isTest
+ static void it_should_fake_dml_undelete() {
+ Test.startTest();
+ dmlRepo.undeleteRecords(con);
+ Test.stopTest();
+
+ System.assert(!TestingUtils.undeletedRecords.isEmpty());
+ }
+
+ @isTest
+ static void it_should_mock_updating_read_only_fields_when_updating_data() {
+ Schema.Lead l = new Schema.Lead();
+ l = (Lead)TestingUtils.setReadOnlyField(l, Schema.Lead.IsConverted, true);
+
+ Test.startTest();
+ dmlRepo.updateRecords(l);
+ Test.stoptest();
+
+ SObject record = TestingUtils.updatedRecords[0];
+ System.assert(record instanceof Schema.Lead);
+ System.assert(record.get('IsConverted') != null);
+ }
+
+ private static Contact createContact() {
+ con = new Contact();
+ con.Email = 'rightHandMan@hamilton.com';
+ con.FirstName = 'George';
+ con.LastName = 'Washington';
+ con.LeadSource = 'Web';
+
+ return con;
+ }
+
+}
\ No newline at end of file
diff --git a/src/classes/DMLMock_Tests.cls-meta.xml b/src/classes/DMLMock_Tests.cls-meta.xml
new file mode 100644
index 0000000..8b061c8
--- /dev/null
+++ b/src/classes/DMLMock_Tests.cls-meta.xml
@@ -0,0 +1,5 @@
+
+
+ 39.0
+ Active
+
diff --git a/src/classes/Environment.cls-meta.xml b/src/classes/Environment.cls-meta.xml
index cbddff8..8b061c8 100644
--- a/src/classes/Environment.cls-meta.xml
+++ b/src/classes/Environment.cls-meta.xml
@@ -1,5 +1,5 @@
- 38.0
+ 39.0
Active
diff --git a/src/classes/Environment_Tests.cls-meta.xml b/src/classes/Environment_Tests.cls-meta.xml
index cbddff8..8b061c8 100644
--- a/src/classes/Environment_Tests.cls-meta.xml
+++ b/src/classes/Environment_Tests.cls-meta.xml
@@ -1,5 +1,5 @@
- 38.0
+ 39.0
Active
diff --git a/src/classes/Exceptions.cls b/src/classes/Exceptions.cls
new file mode 100644
index 0000000..70b180e
--- /dev/null
+++ b/src/classes/Exceptions.cls
@@ -0,0 +1,11 @@
+/*************************************************************************************************
+* This file is part of the Nebula Framework project, released under the MIT License. *
+* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. *
+*************************************************************************************************/
+public without sharing class Exceptions {
+
+ public class InvalidOperationException extends Exception {}
+ public class RecordTypeException extends Exception {}
+ public class SObjectTriggerHandlerException extends Exception {}
+
+}
\ No newline at end of file
diff --git a/src/classes/Exceptions.cls-meta.xml b/src/classes/Exceptions.cls-meta.xml
new file mode 100644
index 0000000..8b061c8
--- /dev/null
+++ b/src/classes/Exceptions.cls-meta.xml
@@ -0,0 +1,5 @@
+
+
+ 39.0
+ Active
+
diff --git a/src/classes/IDML.cls b/src/classes/IDML.cls
new file mode 100644
index 0000000..4e53798
--- /dev/null
+++ b/src/classes/IDML.cls
@@ -0,0 +1,20 @@
+/*************************************************************************************************
+* This file is part of the Nebula Framework project, released under the MIT License. *
+* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. *
+*************************************************************************************************/
+public interface IDML {
+
+ void insertRecords(SObject record);
+ void insertRecords(List recordList);
+ void updateRecords(SObject record);
+ void updateRecords(List recordList);
+ void upsertRecords(SObject record);
+ void upsertRecords(List recordList);
+ void undeleteRecords(SObject record);
+ void undeleteRecords(List recordList);
+ void deleteRecords(SObject record);
+ void deleteRecords(List recordList);
+ void hardDeleteRecords(SObject record);
+ void hardDeleteRecords(List recordList);
+
+}
\ No newline at end of file
diff --git a/src/classes/IDML.cls-meta.xml b/src/classes/IDML.cls-meta.xml
new file mode 100644
index 0000000..8b061c8
--- /dev/null
+++ b/src/classes/IDML.cls-meta.xml
@@ -0,0 +1,5 @@
+
+
+ 39.0
+ Active
+
diff --git a/src/classes/INebulaCore.cls-meta.xml b/src/classes/INebulaCore.cls-meta.xml
index cbddff8..8b061c8 100644
--- a/src/classes/INebulaCore.cls-meta.xml
+++ b/src/classes/INebulaCore.cls-meta.xml
@@ -1,5 +1,5 @@
- 38.0
+ 39.0
Active
diff --git a/src/classes/IQueryArgumentFormatter.cls b/src/classes/IQueryArgumentFormatter.cls
new file mode 100644
index 0000000..bf321e2
--- /dev/null
+++ b/src/classes/IQueryArgumentFormatter.cls
@@ -0,0 +1,9 @@
+/*************************************************************************************************
+* This file is part of the Nebula Framework project, released under the MIT License. *
+* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. *
+*************************************************************************************************/
+public interface IQueryArgumentFormatter {
+
+ String getValue();
+
+}
\ No newline at end of file
diff --git a/src/classes/IQueryArgumentFormatter.cls-meta.xml b/src/classes/IQueryArgumentFormatter.cls-meta.xml
new file mode 100644
index 0000000..8b061c8
--- /dev/null
+++ b/src/classes/IQueryArgumentFormatter.cls-meta.xml
@@ -0,0 +1,5 @@
+
+
+ 39.0
+ Active
+
diff --git a/src/classes/IQueryBuilder.cls b/src/classes/IQueryBuilder.cls
index 2fb161c..5d5ec29 100644
--- a/src/classes/IQueryBuilder.cls
+++ b/src/classes/IQueryBuilder.cls
@@ -4,12 +4,16 @@
*************************************************************************************************/
public interface IQueryBuilder {
- // SOQL buildermethods
- IQueryBuilder whereField(Schema.SObjectField field, QueryOperator operator, Object value);
+ // Query builder methods
+ IQueryBuilder filterBy(IQueryFilter queryFilter);
+ IQueryBuilder filterBy(List queryFilters);
+
+ IQueryBuilder includeChildrenRecords(Schema.SObjectField childToParentRelationshipField, ISObjectRepository childSObjectRepository);
+ IQueryBuilder includeChildrenRecords(Map childFieldToChildSObjectRepositoryrMap);
IQueryBuilder orderBy(Schema.SObjectField orderByField);
IQueryBuilder orderBy(Schema.SObjectField orderByField, QuerySortOrder sortOrder);
- IQueryBuilder orderBy(Schema.SObjectField orderByField, QuerySortOrder sortOrder, QueryNullSortOrder nullSortOrder);
+ IQueryBuilder orderBy(Schema.SObjectField orderByField, QuerySortOrder sortOrder, QueryNullSortOrder nullsSortOrder);
IQueryBuilder limitCount(Integer limitCount);
IQueryBuilder setAsUpdate();
@@ -20,4 +24,8 @@ public interface IQueryBuilder {
List getQueryResults();
List getSearchResults(String searchTerm, QuerySearchGroup searchGroup);
+ // Get the dyanmic query strings
+ String getQuery();
+ String getQuery(Schema.SObjectField sobjectField);
+
}
\ No newline at end of file
diff --git a/src/classes/IQueryBuilder.cls-meta.xml b/src/classes/IQueryBuilder.cls-meta.xml
index cbddff8..8b061c8 100644
--- a/src/classes/IQueryBuilder.cls-meta.xml
+++ b/src/classes/IQueryBuilder.cls-meta.xml
@@ -1,5 +1,5 @@
- 38.0
+ 39.0
Active
diff --git a/src/classes/IQueryFilter.cls b/src/classes/IQueryFilter.cls
new file mode 100644
index 0000000..6fd64e1
--- /dev/null
+++ b/src/classes/IQueryFilter.cls
@@ -0,0 +1,11 @@
+/*************************************************************************************************
+* This file is part of the Nebula Framework project, released under the MIT License. *
+* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. *
+*************************************************************************************************/
+public interface IQueryFilter {
+
+ Object getProvidedValue();
+ Schema.SObjectField getSObjectField();
+ String getValue();
+
+}
\ No newline at end of file
diff --git a/src/classes/IQueryFilter.cls-meta.xml b/src/classes/IQueryFilter.cls-meta.xml
new file mode 100644
index 0000000..8b061c8
--- /dev/null
+++ b/src/classes/IQueryFilter.cls-meta.xml
@@ -0,0 +1,5 @@
+
+
+ 39.0
+ Active
+
diff --git a/src/classes/ISObjectRepository.cls b/src/classes/ISObjectRepository.cls
index 975f7c4..95caf88 100644
--- a/src/classes/ISObjectRepository.cls
+++ b/src/classes/ISObjectRepository.cls
@@ -7,23 +7,17 @@ public interface ISObjectRepository {
// SOQL
SObject getById(Id recordId);
List getById(List recordIdList);
+ List get(IQueryFilter queryFilter);
+ List get(List queryFilters);
+ List getByIdAndQueryFilters(Set idSet, List queryFilters);
+ List getByIdAndQueryFilters(List idList, List queryFilters);
// SOSL
- List searchInAllFields(String searchTerm);
- List searchInFieldsBySearchGroup(String searchTerm, QuerySearchGroup searchGroup);
+ List getSearchResults(String searchTerm);
+ List getSearchResults(String searchTerm, QuerySearchGroup searchGroup);
+ List getSearchResults(String searchTerm, QuerySearchGroup searchGroup, List queryFilters);
- // DML
- void doInsert(SObject record);
- void doInsert(List recordList);
- void doUpdate(SObject record);
- void doUpdate(List recordList);
- void doUpsert(SObject record);
- void doUpsert(List recordList);
- void doDelete(SObject record);
- void doDelete(List recordList);
- void doHardDelete(SObject record);
- void doHardDelete(List recordList);
- void doUndelete(SObject record);
- void doUndelete(List recordList);
+ // Additional methods
+ IQueryBuilder getQueryBuilder();
}
\ No newline at end of file
diff --git a/src/classes/ISObjectRepository.cls-meta.xml b/src/classes/ISObjectRepository.cls-meta.xml
index cbddff8..8b061c8 100644
--- a/src/classes/ISObjectRepository.cls-meta.xml
+++ b/src/classes/ISObjectRepository.cls-meta.xml
@@ -1,5 +1,5 @@
- 38.0
+ 39.0
Active
diff --git a/src/classes/ISObjectTriggerHandler.cls-meta.xml b/src/classes/ISObjectTriggerHandler.cls-meta.xml
index cbddff8..8b061c8 100644
--- a/src/classes/ISObjectTriggerHandler.cls-meta.xml
+++ b/src/classes/ISObjectTriggerHandler.cls-meta.xml
@@ -1,5 +1,5 @@
- 38.0
+ 39.0
Active
diff --git a/src/classes/Logger.cls b/src/classes/Logger.cls
index b973375..716b71f 100644
--- a/src/classes/Logger.cls
+++ b/src/classes/Logger.cls
@@ -6,23 +6,19 @@ public without sharing class Logger {
private static Id logId;
private static Attachment logAttachment;
- private static List logMessages;
+ @testVisible private static List logMessages;
static {
Logger.logMessages = Logger.logMessages == null ? new List() : Logger.logMessages;
Logger.logAttachment = Logger.logAttachment == null ? createLogAttachment() : Logger.logAttachment;
}
- public static void addEntry(INebulaCore moduleClass, String message) {
- addEntry(moduleClass, message, null);
- }
-
public static void addEntry(String message) {
- addEntry(null, message, null);
+ addEntry(null, message);
}
- public static void addEntry(INebulaCore moduleClass, String message, Exception ex) {
- Logger.Message logMessage = new Logger.Message(moduleClass, message, ex);
+ public static void addEntry(INebulaCore moduleClass, String message) {
+ Logger.Message logMessage = new Logger.Message(moduleClass, message);
Logger.logMessages.add(logMessage);
}
@@ -38,7 +34,6 @@ public without sharing class Logger {
NebulaLog__c newLog = new NebulaLog__c(
InitialClass__c = NebulaCore.INITIAL_CLASS,
- InitialModule__c = NebulaCore.INITIAL_MODULE == null ? null : NebulaCore.INITIAL_MODULE.name(),
TransactionId__c = NebulaCore.TRANSACTION_ID
);
insert newLog;
@@ -55,10 +50,10 @@ public without sharing class Logger {
parsedMessageString =
parsedMessageString
+ divider
- + '\nCurrent Module: ' + logMessage.classModule
- + '\nCurrent Class: ' + logMessage.className
- + '\nTimestamp: ' + logMessage.timestamp.format('yyyy-MM-dd_hh:mm:ss.SS')
- + '\n\n' + logMessage.message;
+ + '\nCurrent Module: ' + logMessage.ClassModule
+ + '\nCurrent Class: ' + logMessage.ClassName
+ + '\nTimestamp: ' + logMessage.Timestamp.format('yyyy-MM-dd_hh:mm:ss.SS')
+ + '\n\n' + logMessage.Message;
}
if(Logger.logAttachment.Id == null) {
@@ -82,18 +77,16 @@ public without sharing class Logger {
}
private class Message {
- private NebulaCore.Module classModule;
- private String className;
- private Exception ex; // TODO need to add exception info to log
- private String message;
- private Datetime timestamp;
-
- public Message(INebulaCore moduleClass, String message, Exception ex) {
- this.classModule = moduleClass == null ? null : moduleClass.getClassModule();
- this.className = moduleClass == null ? null : moduleClass.getClassName();
- this.ex = ex;
- this.message = message;
- this.timestamp = System.now();
+ public NebulaCore.Module ClassModule {get; private set;}
+ public String ClassName {get; private set;}
+ public String Message {get; private set;}
+ public Datetime Timestamp {get; private set;}
+
+ public Message(INebulaCore moduleClass, String message) {
+ this.ClassModule = moduleClass == null ? null : moduleClass.getClassModule();
+ this.ClassName = moduleClass == null ? null : moduleClass.getClassName();
+ this.Message = message;
+ this.Timestamp = System.now();
}
}
diff --git a/src/classes/Logger.cls-meta.xml b/src/classes/Logger.cls-meta.xml
index cbddff8..8b061c8 100644
--- a/src/classes/Logger.cls-meta.xml
+++ b/src/classes/Logger.cls-meta.xml
@@ -1,5 +1,5 @@
- 38.0
+ 39.0
Active
diff --git a/src/classes/Logger_Tests.cls b/src/classes/Logger_Tests.cls
new file mode 100644
index 0000000..36ae070
--- /dev/null
+++ b/src/classes/Logger_Tests.cls
@@ -0,0 +1,111 @@
+/*************************************************************************************************
+* This file is part of the Nebula Framework project, released under the MIT License. *
+* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. *
+*************************************************************************************************/
+@isTest
+private class Logger_Tests {
+
+ private class FakeNebulaClass extends NebulaCore {}
+
+ @isTest
+ static void it_should_add_entry_for_a_message_string() {
+ String message = 'my test message';
+ System.assert(Logger.logMessages.isEmpty());
+
+ Test.startTest();
+ Logger.addEntry(message);
+ Test.stopTest();
+
+ System.assertEquals(null, Logger.logMessages[0].ClassModule);
+ System.assertEquals(null, Logger.logMessages[0].ClassName);
+ System.assertEquals(message, Logger.logMessages[0].Message);
+ }
+
+ @isTest
+ static void it_should_add_entry_for_a_module_class_and_a_message_string() {
+ FakeNebulaClass moduleClass = new FakeNebulaClass();
+ String message = 'my test message';
+ System.assert(Logger.logMessages.isEmpty());
+
+ Test.startTest();
+ Logger.addEntry(moduleClass, message);
+ Test.stopTest();
+
+ System.assertEquals(moduleClass.getClassModule(), Logger.logMessages[0].ClassModule);
+ System.assertEquals(moduleClass.getClassName(), Logger.logMessages[0].ClassName);
+ System.assertEquals(message, Logger.logMessages[0].Message);
+ }
+
+ @isTest
+ static void it_should_add_entry_for_a_module_class_and_an_exception_and_a_message_string() {
+ FakeNebulaClass moduleClass = new FakeNebulaClass();
+ String message = 'my test message';
+ System.assert(Logger.logMessages.isEmpty());
+
+ Test.startTest();
+ Logger.addEntry(moduleClass, message);
+ Test.stopTest();
+
+ System.assertEquals(moduleClass.getClassModule(), Logger.logMessages[0].ClassModule);
+ System.assertEquals(moduleClass.getClassName(), Logger.logMessages[0].ClassName);
+ System.assertEquals(message, Logger.logMessages[0].Message);
+ }
+
+ @isTest
+ static void it_should_save_logs_when_logging_is_enabled() {
+ FakeNebulaClass moduleClass = new FakeNebulaClass();
+ String message = 'my test message';
+ System.assert(Logger.logMessages.isEmpty());
+ List existingLogs = [SELECT Id FROM NebulaLog__c];
+ System.assert(existingLogs.isEmpty());
+
+ // Enable logging
+ NebulaLoggerSettings__c nebulaLoggerSettings = NebulaLoggerSettings__c.getInstance();
+ nebulaLoggerSettings.EnableLogging__c = true;
+ upsert nebulaLoggerSettings;
+
+ Logger.addEntry(moduleClass, message);
+
+ Test.startTest();
+ String transactionId = NebulaCore.TRANSACTION_ID;
+ Logger.saveLogs();
+ Test.stopTest();
+
+ List logs = [SELECT Id, TransactionId__c FROM NebulaLog__c];
+ System.assertEquals(1, logs.size());
+ System.assertEquals(transactionId, logs[0].TransactionId__c);
+
+ List logAttachments = [SELECT Id, Name, ParentId, ContentType, IsPrivate, Body FROM Attachment WHERE ParentId = :logs[0].Id];
+ System.assertEquals(1, logAttachments.size());
+ System.assertEquals(transactionId, logAttachments[0].Name);
+ System.assertEquals('text/plain', logAttachments[0].ContentType);
+ System.assertEquals(false, logAttachments[0].IsPrivate);
+ String attachmentBody = logAttachments[0].Body.toString();
+ System.assert(attachmentBody.contains(message), attachmentBody);
+ }
+
+ @isTest
+ static void it_should_not_save_logs_when_logging_is_disabled() {
+ FakeNebulaClass moduleClass = new FakeNebulaClass();
+ String message = 'my test message';
+ System.assert(Logger.logMessages.isEmpty());
+ List existingLogs = [SELECT Id FROM NebulaLog__c];
+ System.assert(existingLogs.isEmpty());
+
+ // Disable logging
+ NebulaLoggerSettings__c nebulaLoggerSettings = NebulaLoggerSettings__c.getInstance();
+ nebulaLoggerSettings.EnableLogging__c = false;
+ upsert nebulaLoggerSettings;
+
+ Logger.addEntry(moduleClass, message);
+
+ Test.startTest();
+ String transactionId = NebulaCore.TRANSACTION_ID;
+ Logger.saveLogs();
+ Test.stopTest();
+
+ List logs = [SELECT Id, TransactionId__c FROM NebulaLog__c];
+ System.assertEquals(0, logs.size());
+ }
+
+}
\ No newline at end of file
diff --git a/src/classes/Logger_Tests.cls-meta.xml b/src/classes/Logger_Tests.cls-meta.xml
new file mode 100644
index 0000000..8b061c8
--- /dev/null
+++ b/src/classes/Logger_Tests.cls-meta.xml
@@ -0,0 +1,5 @@
+
+
+ 39.0
+ Active
+
diff --git a/src/classes/NebulaCore.cls b/src/classes/NebulaCore.cls
index 1113ebd..89591cf 100644
--- a/src/classes/NebulaCore.cls
+++ b/src/classes/NebulaCore.cls
@@ -5,8 +5,7 @@
public abstract class NebulaCore implements INebulaCore {
public static final String TRANSACTION_ID;
- public static String INITIAL_CLASS {public get; private set;}
- public static Module INITIAL_MODULE {public get; private set;}
+ public static String INITIAL_CLASS {get; private set;}
static {
NebulaCore.TRANSACTION_ID = new UUID().getValue();
@@ -19,7 +18,6 @@ public abstract class NebulaCore implements INebulaCore {
protected NebulaCore() {
if(NebulaCore.INITIAL_CLASS == null) NebulaCore.INITIAL_CLASS = this.getClassName();
- if(NebulaCore.INITIAL_MODULE == null) NebulaCore.INITIAL_MODULE = this.getClassModule();
}
public String getClassName() {
@@ -27,10 +25,6 @@ public abstract class NebulaCore implements INebulaCore {
}
public NebulaCore.Module getClassModule() {
- return this.getModule();
- }
-
- public NebulaCore.Module getModule() {
return this.currentModule;
}
diff --git a/src/classes/NebulaCore.cls-meta.xml b/src/classes/NebulaCore.cls-meta.xml
index cbddff8..8b061c8 100644
--- a/src/classes/NebulaCore.cls-meta.xml
+++ b/src/classes/NebulaCore.cls-meta.xml
@@ -1,5 +1,5 @@
- 38.0
+ 39.0
Active
diff --git a/src/classes/NebulaSettings.cls b/src/classes/NebulaSettings.cls
index a907772..6fc734a 100644
--- a/src/classes/NebulaSettings.cls
+++ b/src/classes/NebulaSettings.cls
@@ -4,10 +4,10 @@
*************************************************************************************************/
public without sharing class NebulaSettings {
- public static NebulaLoggerSettings__c loggerSettings;
- public static NebulaRecordTypesSettings__c recordTypesSettings;
- public static NebulaRepositorySettings__c repositorySettings;
- public static NebulaTriggerHandlerSettings__c triggerHandlerSettings;
+ public static NebulaLoggerSettings__c LoggerSettings {get; private set;}
+ public static NebulaRecordTypesSettings__c RecordTypesSettings {get; private set;}
+ public static NebulaRepositorySettings__c RepositorySettings {get; private set;}
+ public static NebulaTriggerHandlerSettings__c TriggerHandlerSettings {get; private set;}
static {
loadCustomSettings();
diff --git a/src/classes/NebulaSettings.cls-meta.xml b/src/classes/NebulaSettings.cls-meta.xml
index cbddff8..8b061c8 100644
--- a/src/classes/NebulaSettings.cls-meta.xml
+++ b/src/classes/NebulaSettings.cls-meta.xml
@@ -1,5 +1,5 @@
- 38.0
+ 39.0
Active
diff --git a/src/classes/NebulaSettings_Tests.cls b/src/classes/NebulaSettings_Tests.cls
index c7c4bc5..7fb6181 100644
--- a/src/classes/NebulaSettings_Tests.cls
+++ b/src/classes/NebulaSettings_Tests.cls
@@ -6,42 +6,42 @@
private class NebulaSettings_Tests {
@isTest
- static void it_should_return_recordTypesSettings() {
+ static void it_should_return_record_types_settings() {
List existingSettings = [SELECT Id FROM NebulaRecordTypesSettings__c];
System.assert(existingSettings.isEmpty());
Test.startTest();
- System.assertNotEquals(null, NebulaSettings.recordTypesSettings);
+ System.assertNotEquals(null, NebulaSettings.RecordTypesSettings);
Test.stopTest();
}
@isTest
- static void it_should_return_loggerSettings() {
+ static void it_should_return_logger_settings() {
List existingSettings = [SELECT Id FROM NebulaLoggerSettings__c];
System.assert(existingSettings.isEmpty());
Test.startTest();
- System.assertNotEquals(null, NebulaSettings.loggerSettings);
+ System.assertNotEquals(null, NebulaSettings.LoggerSettings);
Test.stopTest();
}
@isTest
- static void it_should_return_repositorySettings() {
+ static void it_should_return_repository_settings() {
List existingSettings = [SELECT Id FROM NebulaRepositorySettings__c];
System.assert(existingSettings.isEmpty());
Test.startTest();
- System.assertNotEquals(null, NebulaSettings.repositorySettings);
+ System.assertNotEquals(null, NebulaSettings.RepositorySettings);
Test.stopTest();
}
@isTest
- static void it_should_return_triggerHandlerSettings() {
+ static void it_should_return_trigger_handler_settings() {
List existingSettings = [SELECT Id FROM NebulaTriggerHandlerSettings__c];
System.assert(existingSettings.isEmpty());
Test.startTest();
- System.assertNotEquals(null, NebulaSettings.triggerHandlerSettings);
+ System.assertNotEquals(null, NebulaSettings.TriggerHandlerSettings);
Test.stopTest();
}
diff --git a/src/classes/NebulaSettings_Tests.cls-meta.xml b/src/classes/NebulaSettings_Tests.cls-meta.xml
index cbddff8..8b061c8 100644
--- a/src/classes/NebulaSettings_Tests.cls-meta.xml
+++ b/src/classes/NebulaSettings_Tests.cls-meta.xml
@@ -1,5 +1,5 @@
- 38.0
+ 39.0
Active
diff --git a/src/classes/QueryArgumentFormatter.cls b/src/classes/QueryArgumentFormatter.cls
index 6e96f84..0efce6a 100644
--- a/src/classes/QueryArgumentFormatter.cls
+++ b/src/classes/QueryArgumentFormatter.cls
@@ -2,19 +2,21 @@
* This file is part of the Nebula Framework project, released under the MIT License. *
* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. *
*************************************************************************************************/
-public without sharing class QueryArgumentFormatter {
+public virtual class QueryArgumentFormatter extends NebulaCore implements IQueryArgumentFormatter {
private Object argumentValue;
public QueryArgumentFormatter(Object argumentValue) {
+ this.currentModule = NebulaCore.Module.REPOSITORY;
+
this.argumentValue = argumentValue;
}
- public String getValue() {
+ public virtual String getValue() {
return this.objectToQueryString(this.argumentValue);
}
- private String objectToQueryString(Object valueToFormat) {
+ protected virtual String objectToQueryString(Object valueToFormat) {
if(valueToFormat == null) return null;
else if(valueToFormat instanceof List