Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
Continuous Integration Setup & Code Cleanup
Browse files Browse the repository at this point in the history
Tech debt release to get CI working, catch up on some unit tests, documentation, etc.

**Refactoring (Could Impact Existing Code)**
* Changed NebulaSettings.cls to use static variables and methods
* Changed Logger.cls to use static methods - everything now calls Logger directly
* Renamed QueryUtils.cls to QueryArgumentFormatter.cls (and refactored it)
* QueryBuilder.cls now uses QueryArgumentFormatter.cls
* Fixed the ordering of the filter scopes to be in descending order (for readability)

**Bugfixes**
* Fixed a problem with SObjectRecordTypes.cls when the object has no record types
* Logger now checks the custom setting to see if it is enabled

**Continuous Integration**
* Added .travis.yml for continuous integration. Passing unit tests with 75% code coverage is now required to approve a PR
* Added Travis CI build badges to README.md

**Unit Tests**
* Standardised the naming convention on a few test methods
* Added more unit tests & test classes
  • Loading branch information
jongpie authored May 10, 2017
2 parents b724297 + 2676c76 commit 8a97546
Show file tree
Hide file tree
Showing 23 changed files with 654 additions and 181 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js

script:
- npm install -g jsforce-metadata-tools
- jsforce-deploy --dry-run -u $DEPLOYMENT_USERNAME -p $DEPLOYMENT_PASSWORD$DEPLOYMENT_TOKEN -D $TRAVIS_BUILD_DIR/src -l $DEPLOYMENT_LOGIN_URL --rollbackOnError true --testLevel $DEPLOYMENT_TEST_LEVEL --pollTimeout $POLL_TIMEOUT
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Nebula Framework for Salesforce Apex
<a href="https://githubsfdeploy.herokuapp.com?owner=jongpie&repo=NebulaFramework">
<img alt="Deploy to Salesforce"
src="https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/src/main/webapp/resources/img/deploy.png">
</a>
<img alt="Deploy to Salesforce"src="https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/src/main/webapp/resources/img/deploy.png">
</a>

## Branches
| Name | Build Status |
| -------- | -------- |
| master | <img src="https://travis-ci.org/jongpie/NebulaFramework.svg?branch=master"> |
| dev | <img src="https://travis-ci.org/jongpie/NebulaFramework.svg?branch=dev"> |
10 changes: 5 additions & 5 deletions src/classes/Environment_Tests.cls
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@
private class Environment_Tests {

@isTest
static void getBaseUrl() {
static void it_should_return_base_url() {
System.assert(Environment.BaseUrl.endsWithIgnoreCase('.salesforce.com'));
}

@isTest
static void getInstanceName() {
static void it_should_return_instance_name() {
Organization org = [SELECT Id, InstanceName FROM Organization];
System.assertEquals(org.InstanceName, Environment.InstanceName);
}

@isTest
static void getIsSandbox() {
static void it_should_return_is_sandbox() {
Organization org = [SELECT Id, IsSandbox FROM Organization];
System.assertEquals(org.IsSandbox, Environment.IsSandbox);
}

@isTest
static void getName() {
static void it_should_return_name() {
Organization org = [SELECT Id, Name FROM Organization];
System.assertEquals(org.Name, Environment.Name);
}

@isTest
static void getType() {
static void it_should_return_type() {
Organization org = [SELECT Id, OrganizationType FROM Organization];
System.assertEquals(org.OrganizationType, Environment.Type);
}
Expand Down
11 changes: 0 additions & 11 deletions src/classes/ILogger.cls

This file was deleted.

34 changes: 20 additions & 14 deletions src/classes/Logger.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,38 @@
* 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 Logger implements ILogger {
public without sharing class Logger {

private static Id logId;
private static Attachment logAttachment;
private static List<Logger.Message> logMessages;

public Logger() {
static {
Logger.logMessages = Logger.logMessages == null ? new List<Logger.Message>() : Logger.logMessages;
Logger.logAttachment = Logger.logAttachment == null ? this.createLogAttachment() : Logger.logAttachment;
Logger.logAttachment = Logger.logAttachment == null ? createLogAttachment() : Logger.logAttachment;
}

public void addEntry(INebulaCore moduleClass, String message) {
this.addEntry(moduleClass, message, null);
public static void addEntry(INebulaCore moduleClass, String message) {
addEntry(moduleClass, message, null);
}

public void addEntry(INebulaCore moduleClass, String message, Exception ex) {
public static void addEntry(String message) {
addEntry(null, message, null);
}

public static void addEntry(INebulaCore moduleClass, String message, Exception ex) {
Logger.Message logMessage = new Logger.Message(moduleClass, message, ex);
Logger.logMessages.add(logMessage);
}

public void saveLogs() {
this.saveTransactionLog();
this.saveSingleLogFile();
public static void saveLogs() {
if(!NebulaSettings.loggerSettings.EnableLogging__c) return;

saveTransactionLog();
saveSingleLogFile();
}

private void saveTransactionLog() {
private static void saveTransactionLog() {
if(Logger.logId != null) return;

NebulaLog__c newLog = new NebulaLog__c(
Expand All @@ -39,7 +45,7 @@ public without sharing class Logger implements ILogger {
Logger.logId = newLog.Id;
}

private void saveSingleLogFile() {
private static void saveSingleLogFile() {
String parsedMessageString =
'NebulaCore.TRANSACTION_ID: ' + NebulaCore.TRANSACTION_ID
+ '\nInitial Class: ' + NebulaCore.INITIAL_CLASS;
Expand All @@ -65,7 +71,7 @@ public without sharing class Logger implements ILogger {
upsert Logger.logAttachment;
}

private Attachment createLogAttachment() {
private static Attachment createLogAttachment() {
Attachment attachment = new Attachment(
ContentType = 'text/plain',
IsPrivate = false,
Expand All @@ -83,8 +89,8 @@ public without sharing class Logger implements ILogger {
private Datetime timestamp;

public Message(INebulaCore moduleClass, String message, Exception ex) {
this.classModule = moduleClass.getClassModule();
this.className = moduleClass.getClassName();
this.classModule = moduleClass == null ? null : moduleClass.getClassModule();
this.className = moduleClass == null ? null : moduleClass.getClassName();
this.ex = ex;
this.message = message;
this.timestamp = System.now();
Expand Down
11 changes: 0 additions & 11 deletions src/classes/NebulaCore.cls
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ public abstract class NebulaCore implements INebulaCore {
public enum Module { RECORD_TYPES, REPOSITORY, SETTINGS, TRIGGER_HANDLER }

protected final Module currentModule;
private final ILogger logger;

protected NebulaCore() {
this.logger = new Logger();

if(NebulaCore.INITIAL_CLASS == null) NebulaCore.INITIAL_CLASS = this.getClassName();
if(NebulaCore.INITIAL_MODULE == null) NebulaCore.INITIAL_MODULE = this.getClassModule();
}
Expand All @@ -37,12 +34,4 @@ public abstract class NebulaCore implements INebulaCore {
return this.currentModule;
}

protected void addLogEntry(String message) {
this.logger.addEntry(this, message);
}

protected void saveLogs() {
this.logger.saveLogs();
}

}
65 changes: 39 additions & 26 deletions src/classes/NebulaSettings.cls
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,74 @@
*************************************************************************************************/
public without sharing class NebulaSettings {

public NebulaRecordTypesSettings__c recordTypesSettings;
public NebulaRepositorySettings__c repositorySettings;
public NebulaTriggerHandlerSettings__c triggerHandlerSettings;
public static NebulaLoggerSettings__c loggerSettings;
public static NebulaRecordTypesSettings__c recordTypesSettings;
public static NebulaRepositorySettings__c repositorySettings;
public static NebulaTriggerHandlerSettings__c triggerHandlerSettings;

public NebulaSettings() {
this.loadCustomSettings();
static {
loadCustomSettings();
}

public void resetAllSettingsToDefaults() {
this.deleteExistingCustomSettings();
this.createCustomSettings();
public static void resetAllSettingsToDefaults() {
deleteExistingCustomSettings();
createCustomSettings();
}

private void loadCustomSettings() {
this.loadRecordTypesSettings();
this.loadRepositorySettings();
this.loadTriggerHandlerSettings();
private static void loadCustomSettings() {
loadLoggerSettings();
loadRecordTypesSettings();
loadRepositorySettings();
loadTriggerHandlerSettings();
}

private void deleteExistingCustomSettings() {
private static void deleteExistingCustomSettings() {
delete [SELECT Id FROM NebulaLoggerSettings__c];
delete [SELECT Id FROM NebulaRecordTypesSettings__c];
delete [SELECT Id FROM NebulaRepositorySettings__c];
delete [SELECT Id FROM NebulaTriggerHandlerSettings__c];
}

private void createCustomSettings() {
private static void createCustomSettings() {
upsert NebulaLoggerSettings__c.getOrgDefaults();
upsert NebulaRecordTypesSettings__c.getOrgDefaults();
upsert NebulaRepositorySettings__c.getOrgDefaults();
upsert NebulaTriggerHandlerSettings__c.getOrgDefaults();
}

private void loadRecordTypesSettings() {
this.recordTypesSettings = NebulaRecordTypesSettings__c.getInstance();
private static void loadLoggerSettings() {
loggerSettings = NebulaLoggerSettings__c.getInstance();

if(this.recordTypesSettings.Id == null) {
if(loggerSettings.Id == null) {
upsert NebulaLoggerSettings__c.getOrgDefaults();
loggerSettings = NebulaLoggerSettings__c.getInstance();
}
}

private static void loadRecordTypesSettings() {
recordTypesSettings = NebulaRecordTypesSettings__c.getInstance();

if(recordTypesSettings.Id == null) {
upsert NebulaRecordTypesSettings__c.getOrgDefaults();
this.recordTypesSettings = NebulaRecordTypesSettings__c.getInstance();
recordTypesSettings = NebulaRecordTypesSettings__c.getInstance();
}
}

private void loadRepositorySettings() {
this.repositorySettings = NebulaRepositorySettings__c.getInstance();
private static void loadRepositorySettings() {
repositorySettings = NebulaRepositorySettings__c.getInstance();

if(this.repositorySettings.Id == null) {
if(repositorySettings.Id == null) {
upsert NebulaRepositorySettings__c.getOrgDefaults();
this.repositorySettings = NebulaRepositorySettings__c.getInstance();
repositorySettings = NebulaRepositorySettings__c.getInstance();
}
}

private void loadTriggerHandlerSettings() {
this.triggerHandlerSettings = NebulaTriggerHandlerSettings__c.getInstance();
private static void loadTriggerHandlerSettings() {
triggerHandlerSettings = NebulaTriggerHandlerSettings__c.getInstance();

if(this.triggerHandlerSettings.Id == null) {
if(triggerHandlerSettings.Id == null) {
upsert NebulaTriggerHandlerSettings__c.getOrgDefaults();
this.triggerHandlerSettings = NebulaTriggerHandlerSettings__c.getInstance();
triggerHandlerSettings = NebulaTriggerHandlerSettings__c.getInstance();
}
}

Expand Down
76 changes: 76 additions & 0 deletions src/classes/NebulaSettings_Tests.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*************************************************************************************************
* 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 NebulaSettings_Tests {

@isTest
static void it_should_return_recordTypesSettings() {
List<NebulaRecordTypesSettings__c> existingSettings = [SELECT Id FROM NebulaRecordTypesSettings__c];
System.assert(existingSettings.isEmpty());

Test.startTest();
System.assertNotEquals(null, NebulaSettings.recordTypesSettings);
Test.stopTest();
}

@isTest
static void it_should_return_loggerSettings() {
List<NebulaLoggerSettings__c> existingSettings = [SELECT Id FROM NebulaLoggerSettings__c];
System.assert(existingSettings.isEmpty());

Test.startTest();
System.assertNotEquals(null, NebulaSettings.loggerSettings);
Test.stopTest();
}

@isTest
static void it_should_return_repositorySettings() {
List<NebulaRepositorySettings__c> existingSettings = [SELECT Id FROM NebulaRepositorySettings__c];
System.assert(existingSettings.isEmpty());

Test.startTest();
System.assertNotEquals(null, NebulaSettings.repositorySettings);
Test.stopTest();
}

@isTest
static void it_should_return_triggerHandlerSettings() {
List<NebulaTriggerHandlerSettings__c> existingSettings = [SELECT Id FROM NebulaTriggerHandlerSettings__c];
System.assert(existingSettings.isEmpty());

Test.startTest();
System.assertNotEquals(null, NebulaSettings.triggerHandlerSettings);
Test.stopTest();
}

@isTest
static void it_should_reset_all_settings_to_defaults() {
NebulaLoggerSettings__c nebulaLoggerSettings = NebulaLoggerSettings__c.getInstance();
upsert nebulaLoggerSettings;
Id originalLoggerSettingsId = NebulaLoggerSettings__c.getInstance().Id;

NebulaRecordTypesSettings__c nebulaRecordTypesSettings = NebulaRecordTypesSettings__c.getInstance();
upsert nebulaRecordTypesSettings;
Id originalRecordTypesSettingsId = NebulaRecordTypesSettings__c.getInstance().Id;

NebulaRepositorySettings__c nebulaRepositorySettings = NebulaRepositorySettings__c.getInstance();
upsert nebulaRepositorySettings;
Id originalRepositorySettingsId = NebulaRepositorySettings__c.getInstance().Id;

NebulaTriggerHandlerSettings__c nebulaTriggerHandlerSettings = NebulaTriggerHandlerSettings__c.getInstance();
upsert nebulaTriggerHandlerSettings;
Id originalTriggerHandlerSettingsId = NebulaTriggerHandlerSettings__c.getInstance().Id;

Test.startTest();
NebulaSettings.resetAllSettingsToDefaults();
Test.stopTest();

System.assertNotEquals(originalLoggerSettingsId, NebulaLoggerSettings__c.getInstance().Id);
System.assertNotEquals(originalRecordTypesSettingsId, NebulaRecordTypesSettings__c.getInstance().Id);
System.assertNotEquals(originalRepositorySettingsId, NebulaRepositorySettings__c.getInstance().Id);
System.assertNotEquals(originalTriggerHandlerSettingsId, NebulaTriggerHandlerSettings__c.getInstance().Id);
}

}
Loading

0 comments on commit 8a97546

Please sign in to comment.