diff --git a/dev-tools/update-dependencies b/dev-tools/update-dependencies index 3eeec3b..9bc0a96 100755 --- a/dev-tools/update-dependencies +++ b/dev-tools/update-dependencies @@ -1,6 +1,6 @@ #!/bin/bash -mkdir ./temp +mkdir ./temp || true cd ./temp rm -Rf fflib-apex-mocks/ rm -Rf fflib-apex-common/ diff --git a/sfdx-source/apex-extensions/main/application/classic/classes/fflib_ClassicSelectorFactory.cls b/sfdx-source/apex-extensions/main/application/classic/classes/fflib_ClassicSelectorFactory.cls index 0f6cd20..45ec345 100644 --- a/sfdx-source/apex-extensions/main/application/classic/classes/fflib_ClassicSelectorFactory.cls +++ b/sfdx-source/apex-extensions/main/application/classic/classes/fflib_ClassicSelectorFactory.cls @@ -32,11 +32,6 @@ public virtual class fflib_ClassicSelectorFactory extends fflib_Application.SelectorFactory implements fflib_ISelectorFactory { - /** - * Constructs a simple Selector Factory - **/ - public fflib_ClassicSelectorFactory() {} - /** * Constructs a Selector Factory linking SObjectType's with Apex Classes implement the fflib_ISObjectSelector interface * Note that the factory does not check the given Apex Classes implement the interface diff --git a/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_AppBindingMetaDataModule.cls b/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_AppBindingMetaDataModule.cls index 601accb..ef569fb 100644 --- a/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_AppBindingMetaDataModule.cls +++ b/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_AppBindingMetaDataModule.cls @@ -49,6 +49,7 @@ public with sharing class fflib_AppBindingMetaDataModule } } + @TestVisible private Object getBindingObject(fflib_AppBinding__mdt binding) { if (String.isBlank(binding.BindingObject__c) && String.isBlank(binding.BindingObjectAlternate__c)) return null; @@ -58,12 +59,12 @@ public with sharing class fflib_AppBindingMetaDataModule : binding.BindingObjectAlternate__c.toLowerCase().trim(); // Assume its an SObjectType - List schemaDescribes = Schema.describeSObjects(new List {bindingObjectApiName}); - if (schemaDescribes.size() == 1) + try { + List schemaDescribes = Schema.describeSObjects(new List {bindingObjectApiName}); return schemaDescribes.get(0).getSObjectType(); } - else + catch (InvalidParameterValueException e) { // check if its an Object (class) Type objectType = System.Type.forName(bindingObjectApiName); @@ -93,6 +94,7 @@ public with sharing class fflib_AppBindingMetaDataModule return bindingTypeByStrings.get(binding.Type__c.toUpperCase()); } + @TestVisible private Type getSystemType(fflib_AppBinding__mdt binding, Schema.SObjectField sObjectField) { String systemTypeName = String.valueOf(binding.get(sObjectField)); diff --git a/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_AppBindingResolver.cls b/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_AppBindingResolver.cls index 7f65040..0991c2f 100644 --- a/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_AppBindingResolver.cls +++ b/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_AppBindingResolver.cls @@ -96,42 +96,6 @@ public virtual class fflib_AppBindingResolver return this; } - public fflib_IAppBindingResolver byObject(Object bindingObject) - { - this.bindingToResolve.setBindingObject(bindingObject); - return this; - } - - public fflib_IAppBindingResolver bySequence(Integer sequence) - { - this.bindingToResolve.setSequence(sequence); - return this; - } - - public fflib_IAppBindingResolver byType(fflib_AppBindingType bindingType) - { - this.bindingToResolve.setBindingType(bindingType); - return this; - } - - public fflib_IAppBindingResolver byInterfaceType(Type interfaceType) - { - this.bindingToResolve.setInterfaceType(interfaceType); - return this; - } - - public fflib_IAppBindingResolver byNamespacePrefix(String namespacePrefix) - { - this.bindingToResolve.setNamespacePrefix(namespacePrefix); - return this; - } - - public fflib_IAppBindingResolver byPackageName(String packageName) - { - this.bindingToResolve.setPackageName(packageName); - return this; - } - /** * Handles lazy loading of modules, if no custom module is configured (via addModule) the default module is returned * diff --git a/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_DynamicAppFactory.cls b/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_DynamicAppFactory.cls index 7f7f742..b350c12 100644 --- a/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_DynamicAppFactory.cls +++ b/sfdx-source/apex-extensions/main/application/dynamic/classes/fflib_DynamicAppFactory.cls @@ -33,25 +33,4 @@ public abstract class fflib_DynamicAppFactory protected String packageName; protected fflib_IAppBindingResolver resolver; - protected Map routes; - - protected Map mockImplByObjectType = new Map(); - - protected void setMock(Object objectType, Object mock) - { - this.mockImplByObjectType.put( - objectType, - mock - ); - } - - protected Object getMock(Object objectType) - { - return this.mockImplByObjectType.get(objectType); - } - - protected Boolean hasMock(Object objectType) - { - return this.mockImplByObjectType.containsKey(objectType); - } } \ No newline at end of file diff --git a/sfdx-source/apex-extensions/main/application/dynamic/classes/interfaces/fflib_IAppBindingResolver.cls b/sfdx-source/apex-extensions/main/application/dynamic/classes/interfaces/fflib_IAppBindingResolver.cls index 3748dcc..21377f7 100644 --- a/sfdx-source/apex-extensions/main/application/dynamic/classes/interfaces/fflib_IAppBindingResolver.cls +++ b/sfdx-source/apex-extensions/main/application/dynamic/classes/interfaces/fflib_IAppBindingResolver.cls @@ -31,11 +31,5 @@ public interface fflib_IAppBindingResolver { fflib_IAppBindingResolver addModule(fflib_IAppBindingModule bindingModule); - fflib_IAppBindingResolver byObject(Object bindingObject); - fflib_IAppBindingResolver bySequence(Integer sequence); - fflib_IAppBindingResolver byType(fflib_AppBindingType bindingType); - fflib_IAppBindingResolver byInterfaceType(System.Type interfaceType); - fflib_IAppBindingResolver byNamespacePrefix(String namespacePrefix); - fflib_IAppBindingResolver byPackageName(String packageName); List resolve(); } \ No newline at end of file diff --git a/sfdx-source/apex-extensions/main/default/classes/selectors/fflib_SObjectShareSelector.cls b/sfdx-source/apex-extensions/main/default/classes/selectors/fflib_SObjectShareSelector.cls deleted file mode 100644 index 38d6d56..0000000 --- a/sfdx-source/apex-extensions/main/default/classes/selectors/fflib_SObjectShareSelector.cls +++ /dev/null @@ -1,121 +0,0 @@ -/** - * File Name: fflib_SObjectShareSelector - * - * @description Abstract selector for SObject Shares - * - * @author architect ir. Wilhelmus G.J. Velzeboer - * - * Copyright (c), W.G.J. Velzeboer, - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * - Redistributions of source code must retain the above author notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of the author nor the names of its contributors - * may be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -public abstract inherited sharing class fflib_SObjectShareSelector - extends fflib_SObjectSelector -{ - private String accessLevelFieldName - { - get - { - if (accessLevelFieldName == null) - { - accessLevelFieldName = fflib_SObjectShare.getAccessLevelFieldName(getSObjectType2()); - } - return accessLevelFieldName; - } - private set; - } - private String parentIdFieldName - { - get - { - if (parentIdFieldName == null) - { - parentIdFieldName = fflib_SObjectShare.getParentIdFieldName(getSObjectType2()); - } - return parentIdFieldName; - } - private set; - } - private String rowCauseFieldName = 'RowCause'; - private String userOrGroupIdName = 'UserOrGroupId'; - private List sObjectFieldList - { - get - { - if (sObjectFieldList == null) - { - SObjectType sObjectType = getSObjectType2(); - fflib_SObjectDescribe sObjectDescribe = fflib_SObjectDescribe.getDescribe(sObjectType); - sObjectFieldList = new List - { - fflib_SObjectShare.getIdField(sObjectType), - fflib_SObjectShare.getAccessLevelField(sObjectType), - fflib_SObjectShare.getParentIdField(sObjectType), - fflib_SObjectShare.getRowCauseField(sObjectType), - fflib_SObjectShare.getUserOrGroupIdField(sObjectType) - }; - } - return sObjectFieldList; - } - private set; - } - - public List getSObjectFieldList() - { - return sObjectFieldList; - } - - protected List selectShareByParentId(Set parentIds) - { - return Database.query( - newQueryFactory() - .setCondition(parentIdFieldName + ' IN :parentIds') - .toSOQL()); - } - - protected List selectShareByParentId(Set parentIds, Set userOrGroupIds) - { - return Database.query( - newQueryFactory() - .setCondition(parentIdFieldName + ' IN :parentIds AND ' + userOrGroupIdName + ' IN :userOrGroupIds') - .toSOQL()); - } - - protected List selectShareByParentId(Set parentIds, Set userOrGroupIds, Set accessLevels) - { - return Database.query( - newQueryFactory() - .setCondition(parentIdFieldName + ' IN :parentIds AND ' - + userOrGroupIdName + ' IN :userOrGroupIds AND ' - + accessLevelFieldName + ' IN :accessLevels') - .toSOQL()); - } - - protected List selectShareByParentId(Set parentIds, Set rowCauses) - { - return Database.query( - newQueryFactory() - .setCondition(parentIdFieldName + ' IN :parentIds AND ' + rowCauseFieldName + ' IN :rowCauses') - .toSOQL()); - } -} \ No newline at end of file diff --git a/sfdx-source/apex-extensions/main/default/classes/triggerHanders/fflib_SObjectTriggerHandler.cls b/sfdx-source/apex-extensions/main/default/classes/triggerHanders/fflib_SObjectTriggerHandler.cls index 1df6f98..7a60379 100644 --- a/sfdx-source/apex-extensions/main/default/classes/triggerHanders/fflib_SObjectTriggerHandler.cls +++ b/sfdx-source/apex-extensions/main/default/classes/triggerHanders/fflib_SObjectTriggerHandler.cls @@ -42,9 +42,9 @@ public virtual with sharing class fflib_SObjectTriggerHandler super(records, sObjectType); } - public List getChangedRecords(String fileName) + public List getChangedRecords(String fieldName) { - return getChangedRecords(new Set{ fileName }); + return getChangedRecords(new Set{ fieldName }); } public List getChangedRecords(Schema.SObjectField fieldToken) diff --git a/sfdx-source/apex-extensions/main/default/classes/utils/fflib_SObjectShare.cls b/sfdx-source/apex-extensions/main/default/classes/utils/fflib_SObjectShare.cls index 0838479..c548b43 100644 --- a/sfdx-source/apex-extensions/main/default/classes/utils/fflib_SObjectShare.cls +++ b/sfdx-source/apex-extensions/main/default/classes/utils/fflib_SObjectShare.cls @@ -46,7 +46,7 @@ public with sharing class fflib_SObjectShare Id parentId, Id userOrGroupId) { - return createShares(sObjectType, new Set{ parentId }, new Set{ userOrGroupId }, ACCESS_LEVEL_EDIT) + return createEditShares(sObjectType, parentId, new Set{ userOrGroupId }) .get(0); } @@ -64,7 +64,7 @@ public with sharing class fflib_SObjectShare Id parentId, Set userOrGroupIds) { - return createShares(sObjectType, new Set{ parentId }, userOrGroupIds, ACCESS_LEVEL_EDIT); + return createEditShares(sObjectType, new Set{ parentId }, userOrGroupIds); } /** @@ -98,7 +98,7 @@ public with sharing class fflib_SObjectShare Id parentId, Id userOrGroupId) { - return createShares(sObjectType, new Set{ parentId }, new Set{ userOrGroupId }, ACCESS_LEVEL_READ) + return createReadShares(sObjectType, parentId, new Set{ userOrGroupId }) .get(0); } @@ -116,7 +116,7 @@ public with sharing class fflib_SObjectShare Id parentId, Set userOrGroupIds) { - return createShares(sObjectType, new Set{ parentId }, userOrGroupIds, ACCESS_LEVEL_READ); + return createReadShares(sObjectType, new Set{ parentId }, userOrGroupIds); } /** @@ -172,17 +172,6 @@ public with sharing class fflib_SObjectShare return results; } - /** - * Gets the SObjectField for the Id field of the given SObjectType - * - * @param sObjectType The SObjectType to get its Id field - * - * @return Returns the Id.SObjectField - */ - public static SObjectField getIdField(SObjectType sObjectType) - { - return getsObjectField(fflib_SObjectDescribe.getDescribe(sObjectType).getFields(), 'Id'); - } /** * Gets the name of the AccessLevel field of the given SObjectType diff --git a/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingMetaDataModuleTest.cls b/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingMetaDataModuleTest.cls new file mode 100644 index 0000000..ea4b070 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingMetaDataModuleTest.cls @@ -0,0 +1,45 @@ +@IsTest(IsParallel=true) +private class fflib_AppBindingMetaDataModuleTest +{ + @IsTest + static void itShouldCheckForAnException(){ + fflib_AppBindingMetaDataModule module = new fflib_AppBindingMetaDataModule(); + fflib_AppBinding__mdt binding = new fflib_AppBinding__mdt( + BindingObjectAlternate__c = 'SomeNonExistingClass', + DeveloperName = 'SomeNonExistingClass' + ); + try + { + module.getBindingObject(binding); + System.Assert.fail('Expected an exception'); + } + catch (fflib_AppBindingMetaDataModule.DeveloperException e) + { + System.Assert.areEqual( + e.getMessage(), + 'Failed to find (S)Object somenonexistingclass referenced by binding SomeNonExistingClass' + ); + } + } + + @IsTest + static void getSystemType_failing(){ + fflib_AppBindingMetaDataModule module = new fflib_AppBindingMetaDataModule(); + fflib_AppBinding__mdt binding = new fflib_AppBinding__mdt( + ImplementationType__c = 'SomeNonExistingClass', + DeveloperName = 'SomeNonExistingClass' + ); + try + { + module.getSystemType(binding, fflib_AppBinding__mdt.ImplementationType__c); + System.Assert.fail('Expected an exception'); + } + catch (fflib_AppBindingMetaDataModule.DeveloperException e) + { + System.Assert.areEqual( + e.getMessage(), + 'Unable to find SomeNonExistingClass referenced by binding SomeNonExistingClass for ImplementationType__c' + ); + } + } +} \ No newline at end of file diff --git a/sfdx-source/apex-extensions/main/default/classes/selectors/fflib_SObjectShareSelector.cls-meta.xml b/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingMetaDataModuleTest.cls-meta.xml similarity index 100% rename from sfdx-source/apex-extensions/main/default/classes/selectors/fflib_SObjectShareSelector.cls-meta.xml rename to sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingMetaDataModuleTest.cls-meta.xml diff --git a/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingResolverTest.cls b/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingResolverTest.cls new file mode 100644 index 0000000..84a6af8 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingResolverTest.cls @@ -0,0 +1,25 @@ +@IsTest(IsParallel=true) +private class fflib_AppBindingResolverTest +{ + @IsTest + static void testWithEmptyRouter() + { + fflib_IAppBindingResolver resolver = fflib_AppBindingResolver.newInstance(); + System.Assert.areEqual(0, resolver.resolve().size()); + } + + + @IsTest + static void testWithCustomRouter(){ + fflib_IAppBindingResolver resolver = new fflib_AppBindingResolver(new CustomRouter()); + System.Assert.areEqual(0, resolver.resolve().size()); + } + + private class CustomRouter implements fflib_IAppBindingRouter + { + public Map getRoutes() + { + return new Map{ fflib_AppBindingResolverTest.class => fflib_AppBindingResolverTest.class }; + } + } +} \ No newline at end of file diff --git a/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingResolverTest.cls-meta.xml b/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingResolverTest.cls-meta.xml new file mode 100644 index 0000000..754ecb1 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingResolverTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 57.0 + Active + diff --git a/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingsTest.cls b/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingsTest.cls new file mode 100644 index 0000000..33536ea --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingsTest.cls @@ -0,0 +1,23 @@ +@IsTest +private class fflib_AppBindingsTest +{ + @IsTest + static void testBehavior() + { + fflib_AppBinding binding = new fflib_AppBinding(); + binding.setImplementationType(fflib_AppBindingsTest.class); + binding.setInterfaceType(fflib_AppBindingsTest.class); + binding.setBindingObject(fflib_AppBindingsTest.class); + binding.setNamespacePrefix('test'); + binding.setSequence(1); + + fflib_AppBindings appBindings = new fflib_AppBindings(new List()); + appBindings.addBinding(binding); + System.Assert.areEqual(fflib_AppBindingsTest.class, appBindings.getImplementations().get(0), 'Incorrect returned implementation'); + System.Assert.areEqual(1, appBindings.selectByInterfaceType(fflib_AppBindingsTest.class).getObjects().size(), 'Incorrect returned interface type'); + System.Assert.areEqual(1, appBindings.selectByNamespacePrefix('test').getObjects().size(), 'Incorrect returned namespace prefix'); + System.Assert.areEqual(1, appBindings.selectByObject(fflib_AppBindingsTest.class).getObjects().size(), 'Incorrect returned object'); + System.Assert.areEqual(fflib_IAppBinding.class, appBindings.getType(), 'Incorrect returned type'); + appBindings.selectBySequence(1); + } +} \ No newline at end of file diff --git a/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingsTest.cls-meta.xml b/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingsTest.cls-meta.xml new file mode 100644 index 0000000..754ecb1 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/application/fflib_AppBindingsTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 57.0 + Active + diff --git a/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicSelectorFactoryTest.cls b/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicSelectorFactoryTest.cls new file mode 100644 index 0000000..70f6506 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicSelectorFactoryTest.cls @@ -0,0 +1,29 @@ + +@IsTest(IsParallel=true) +private class fflib_ClassicSelectorFactoryTest +{ + @IsTest + static void testSelectById() + { + fflib_ClassicSelectorFactory classicSelectorFactory = + new fflib_ClassicSelectorFactory( + new Map {Schema.Account.SObjectType => TestAccountSelector.class}); + List sObjects = classicSelectorFactory.selectById( + new Set {fflib_IDGenerator.generate(Schema.Account.SObjectType)}, + Schema.Account.SObjectType); + System.Assert.isTrue(sObjects.isEmpty()); + } + + private class TestAccountSelector implements fflib_ISObjectSelector + { + public List selectSObjectsById(Set idSet) + { + return new List(); + } + + public SObjectType sObjectType() + { + return Schema.Account.SObjectType; + } + } +} \ No newline at end of file diff --git a/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicSelectorFactoryTest.cls-meta.xml b/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicSelectorFactoryTest.cls-meta.xml new file mode 100644 index 0000000..754ecb1 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicSelectorFactoryTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 57.0 + Active + diff --git a/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicUnitOfWorkFactoryTest.cls b/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicUnitOfWorkFactoryTest.cls new file mode 100644 index 0000000..0fa6b03 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicUnitOfWorkFactoryTest.cls @@ -0,0 +1,19 @@ +@IsTest(IsParallel=true) +private class fflib_ClassicUnitOfWorkFactoryTest +{ + @IsTest + static void testUnitOfWork() + { + new fflib_ClassicUnitOfWorkFactory(new List{ Schema.Account.SObjectType }); + } + + @IsTest + static void testUnitOfWorkMock() + { + fflib_ApexMocks mocks = new fflib_ApexMocks(); + fflib_ISObjectUnitOfWork unitOfWorkMock = new fflib_SObjectMocks.SObjectUnitOfWork(mocks); + + new fflib_ClassicUnitOfWorkFactory() + .setMock(unitOfWorkMock); + } +} \ No newline at end of file diff --git a/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicUnitOfWorkFactoryTest.cls-meta.xml b/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicUnitOfWorkFactoryTest.cls-meta.xml new file mode 100644 index 0000000..754ecb1 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicUnitOfWorkFactoryTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 57.0 + Active + diff --git a/sfdx-source/apex-extensions/tests/classes/application/fflib_DynamicDomainFactoryTest.cls b/sfdx-source/apex-extensions/tests/classes/application/fflib_DynamicDomainFactoryTest.cls index 1f1e055..5a4f23d 100644 --- a/sfdx-source/apex-extensions/tests/classes/application/fflib_DynamicDomainFactoryTest.cls +++ b/sfdx-source/apex-extensions/tests/classes/application/fflib_DynamicDomainFactoryTest.cls @@ -44,6 +44,11 @@ public class fflib_DynamicDomainFactoryTest fflib_DynamicSelectorFactoryTest.Selector, PACKAGE_FORCE_APP); + private static final fflib_DynamicDomainFactory NonDomain = + new fflib_DynamicDomainFactory( + bindingResolver, + fflib_DynamicSelectorFactoryTest.Selector); + private static final fflib_DynamicDomainFactory OtherDomain = new fflib_DynamicDomainFactory( bindingResolver, diff --git a/sfdx-source/apex-extensions/tests/classes/logger/fflib_LogEventStoreListenerTest.cls b/sfdx-source/apex-extensions/tests/classes/logger/fflib_LogEventStoreListenerTest.cls index d96903e..5a26e3f 100644 --- a/sfdx-source/apex-extensions/tests/classes/logger/fflib_LogEventStoreListenerTest.cls +++ b/sfdx-source/apex-extensions/tests/classes/logger/fflib_LogEventStoreListenerTest.cls @@ -88,7 +88,7 @@ private class fflib_LogEventStoreListenerTest { Profile profile = [SELECT Id FROM Profile WHERE Name = :TEST_USER_PROFILE]; return new User( - Alias = 'Testfflib', + Alias = 'TestUser', Email = 'TestUser@example.com', EmailEncodingKey = 'UTF-8', FirstName = 'Test', diff --git a/sfdx-source/apex-extensions/tests/classes/triggerHandler/fflib_SObjectTriggerHandlerTest.cls b/sfdx-source/apex-extensions/tests/classes/triggerHandler/fflib_SObjectTriggerHandlerTest.cls new file mode 100644 index 0000000..23d18cb --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/triggerHandler/fflib_SObjectTriggerHandlerTest.cls @@ -0,0 +1,28 @@ +@IsTest(IsParallel=true) +private class fflib_SObjectTriggerHandlerTest +{ + @IsTest + static void testNewRecords() + { + Account record = new Account(Name = 'Account'); + List records = new List {record}; + fflib_SObjectTriggerHandler handler = new fflib_SObjectTriggerHandler(records); + System.Assert.areEqual(0, handler.getChangedRecords('Name').size()); + } + + @IsTest + static void testUpdateRecords() + { + Account record = new Account( + Id = fflib_IDGenerator.generate(Schema.Account.SObjectType), + Name = 'Account'); + Account existingRecord = new Account( + Id = record.Id, + Name = ''); + + List records = new List {record}; + fflib_SObjectTriggerHandler handler = new fflib_SObjectTriggerHandler(records, Schema.Account.SObjectType); + handler.ExistingRecords = new Map{ record.Id => existingRecord}; + System.Assert.areEqual(1, handler.getChangedRecords(Schema.Account.Name).size()); + } +} \ No newline at end of file diff --git a/sfdx-source/apex-extensions/tests/classes/triggerHandler/fflib_SObjectTriggerHandlerTest.cls-meta.xml b/sfdx-source/apex-extensions/tests/classes/triggerHandler/fflib_SObjectTriggerHandlerTest.cls-meta.xml new file mode 100644 index 0000000..754ecb1 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/triggerHandler/fflib_SObjectTriggerHandlerTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 57.0 + Active + diff --git a/sfdx-source/apex-extensions/tests/classes/unitOfWork/fflib_SObjectUnitOfWork2Test.cls b/sfdx-source/apex-extensions/tests/classes/unitOfWork/fflib_SObjectUnitOfWork2Test.cls new file mode 100644 index 0000000..ec560e0 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/unitOfWork/fflib_SObjectUnitOfWork2Test.cls @@ -0,0 +1,141 @@ +@IsTest(IsParallel=true) +private class fflib_SObjectUnitOfWork2Test +{ + private static List SOBJECT_LIST = new List {Schema.Account.SObjectType}; + + @IsTest + static void testRegisterNewOfDomain() + { + Account parentRecord = new Account( + Id = fflib_IDGenerator.generate(Schema.Account.SObjectType), + Name = 'Parent'); + Account record = new Account(Name = 'Child'); + List records = new List {record}; + TestDomain domain = new TestDomain(records); + + TestDML testDML = new TestDML(); + fflib_SObjectUnitOfWork2 unitOfWork = new fflib_SObjectUnitOfWork2(SOBJECT_LIST, testDML); + unitOfWork.registerNew(domain, Schema.Account.ParentId, parentRecord); + unitOfWork.commitWork(); + + System.Assert.areEqual(1, testDML.toInsert.size(), 'Expected one record to be inserted'); + System.Assert.areEqual(parentRecord.Id, ((Account) testDML.toInsert.get(0)).ParentId, 'Expected the record to be linked to the parent'); + } + + @IsTest + static void testRegisterDirtyOfDomain() + { + Account parentRecord = new Account( + Id = fflib_IDGenerator.generate(Schema.Account.SObjectType), + Name = 'Parent'); + Account record = new Account( + Id = fflib_IDGenerator.generate(Schema.Account.SObjectType), + Name = 'Child'); + List records = new List {record}; + TestDomain domain = new TestDomain(records); + + TestDML testDML = new TestDML(); + fflib_SObjectUnitOfWork2 unitOfWork = new fflib_SObjectUnitOfWork2(SOBJECT_LIST, testDML); + unitOfWork.registerDirty(domain, Schema.Account.ParentId, parentRecord); + unitOfWork.commitWork(); + + System.Assert.areEqual(1, testDML.toUpdate.size(), 'Expected one record to be inserted'); + System.Assert.areEqual(parentRecord.Id, ((Account) testDML.toUpdate.get(0)).ParentId, 'Expected the record to be linked to the parent'); + } + + @IsTest + static void testRegisterNewOfDomain_failing_NotTheSameType() + { + Account parentRecord = new Account( + Id = fflib_IDGenerator.generate(Schema.Account.SObjectType), + Name = 'Parent'); + Account accountRecord = new Account(Name = 'Account'); + Contact contactRecord = new Contact(LastName = 'Contact'); + List records = new List {accountRecord, contactRecord}; + + TestDML testDML = new TestDML(); + try + { + fflib_SObjectUnitOfWork2 unitOfWork = new fflib_SObjectUnitOfWork2(SOBJECT_LIST, testDML); + unitOfWork.registerNew(records, Schema.Account.ParentId, parentRecord); + System.Assert.fail('The UnitOfWork should have thrown an exception'); + } + catch (fflib_SObjectUnitOfWork.UnitOfWorkException e) + { + System.Assert.areEqual(e.getMessage(), 'All records should be of the same SObjectType'); + } + } + + @IsTest + static void testRegisterNewOfDomain_failing_NotSupportedType() + { + Account parentRecord = new Account( + Id = fflib_IDGenerator.generate(Schema.Account.SObjectType), + Name = 'Parent'); + Contact contactRecord = new Contact(LastName = 'Contact'); + List records = new List {contactRecord}; + + TestDML testDML = new TestDML(); + try + { + fflib_SObjectUnitOfWork2 unitOfWork = new fflib_SObjectUnitOfWork2(SOBJECT_LIST, testDML); + unitOfWork.registerNew(records, Schema.Account.ParentId, parentRecord); + System.Assert.fail('The UnitOfWork should have thrown an exception'); + } + catch (fflib_SObjectUnitOfWork.UnitOfWorkException e) + { + System.Assert.areEqual(e.getMessage(), 'SObject type Contact is not supported by this unit of work'); + } + } + + private class TestDomain extends fflib_SObjects + { + private TestDomain(List records) + { + super(records); + } + + private TestDomain(List records, SObjectType sObjectType) + { + super(records, sObjectType); + } + + public override SObjectType getSObjectType() + { + return Schema.Account.SObjectType; + } + } + + private class TestDML implements fflib_SObjectUnitOfWork.IDML + { + public List toDelete = new List(); + public List toInsert = new List(); + public List toUpdate = new List(); + public List toEmptyRecycleBin = new List(); + public List toPublish = new List(); + public void dmlDelete(List objList) + { + this.toDelete.addAll(objList); + } + + public void dmlInsert(List objList) + { + this.toInsert.addAll(objList); + } + + public void dmlUpdate(List objList) + { + this.toUpdate.addAll(objList); + } + + public void emptyRecycleBin(List objList) + { + this.toEmptyRecycleBin.addAll(objList); + } + + public void eventPublish(List objList) + { + this.toPublish.addAll(objList); + } + } +} \ No newline at end of file diff --git a/sfdx-source/apex-extensions/tests/classes/unitOfWork/fflib_SObjectUnitOfWork2Test.cls-meta.xml b/sfdx-source/apex-extensions/tests/classes/unitOfWork/fflib_SObjectUnitOfWork2Test.cls-meta.xml new file mode 100644 index 0000000..754ecb1 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/unitOfWork/fflib_SObjectUnitOfWork2Test.cls-meta.xml @@ -0,0 +1,5 @@ + + + 57.0 + Active + diff --git a/sfdx-source/apex-extensions/tests/classes/utils/fflib_SObjectShareTest.cls b/sfdx-source/apex-extensions/tests/classes/utils/fflib_SObjectShareTest.cls new file mode 100644 index 0000000..6315d15 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/utils/fflib_SObjectShareTest.cls @@ -0,0 +1,58 @@ +@IsTest(IsParallel=true) +private class fflib_SObjectShareTest +{ + @IsTest + static void testEditShareCreation_single() + { + Id accountId = fflib_IDGenerator.generate(Schema.Account.SObjectType); + Id groupId = fflib_IDGenerator.generate(Schema.Group.SObjectType); + SObject editShare = fflib_SObjectShare.createEditShare(Schema.Account.SObjectType, accountId, groupId); + System.Assert.areEqual(accountId, editShare.get('AccountId')); + System.Assert.areEqual(groupId, editShare.get('UserOrGroupId')); + System.Assert.areEqual('Edit', editShare.get('AccountAccessLevel')); + System.Assert.areEqual('Manual', editShare.get('RowCause')); + } + + @IsTest + static void testReadShareCreation_single() + { + Id accountId = fflib_IDGenerator.generate(Schema.Account.SObjectType); + Id groupId = fflib_IDGenerator.generate(Schema.Group.SObjectType); + SObject editShare = fflib_SObjectShare.createReadShare(Schema.Account.SObjectType, accountId, groupId); + System.Assert.areEqual(accountId, editShare.get('AccountId')); + System.Assert.areEqual(groupId, editShare.get('UserOrGroupId')); + System.Assert.areEqual('Read', editShare.get('AccountAccessLevel')); + System.Assert.areEqual('Manual', editShare.get('RowCause')); + } + + @IsTest + static void testAccessLevelField() + { + System.Assert.areEqual( + Schema.AccountShare.AccountAccessLevel, + fflib_SObjectShare.getAccessLevelField(Schema.AccountShare.SObjectType)); + } + + @IsTest + static void testParentIdField() + { + System.Assert.areEqual( + Schema.AccountShare.AccountId, + fflib_SObjectShare.getParentIdField(Schema.AccountShare.SObjectType)); + } + + @IsTest + static void testRowClauseField() + { + System.Assert.areEqual( + Schema.AccountShare.RowCause, + fflib_SObjectShare.getRowCauseField(Schema.AccountShare.SObjectType)); + } + @IsTest + static void testUserOrGroupField() + { + System.Assert.areEqual( + Schema.AccountShare.UserOrGroupId, + fflib_SObjectShare.getUserOrGroupIdField(Schema.AccountShare.SObjectType)); + } +} \ No newline at end of file diff --git a/sfdx-source/apex-extensions/tests/classes/utils/fflib_SObjectShareTest.cls-meta.xml b/sfdx-source/apex-extensions/tests/classes/utils/fflib_SObjectShareTest.cls-meta.xml new file mode 100644 index 0000000..754ecb1 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/utils/fflib_SObjectShareTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 57.0 + Active +