diff --git a/sfdx-source/apex-extensions/main/application/classic/classes/fflib_ClassicDomainFactory.cls b/sfdx-source/apex-extensions/main/application/classic/classes/fflib_ClassicDomainFactory.cls index d53cec1..9c5845d 100644 --- a/sfdx-source/apex-extensions/main/application/classic/classes/fflib_ClassicDomainFactory.cls +++ b/sfdx-source/apex-extensions/main/application/classic/classes/fflib_ClassicDomainFactory.cls @@ -71,7 +71,7 @@ public virtual class fflib_ClassicDomainFactory public fflib_ClassicDomainFactory(fflib_ISelectorFactory selectorFactory, Map sObjectByDomainConstructorType) { - selectorFactory = selectorFactory; + this.selectorFactory = selectorFactory; this.constructorTypeByObject = getConstructorTypeByObject(sObjectByDomainConstructorType); this.mockDomainByObject = new Map(); } @@ -104,7 +104,7 @@ public virtual class fflib_ClassicDomainFactory **/ public virtual fflib_IDomain newInstance(Set recordIds, Schema.SObjectType sObjectType) { - return newInstance(selectorFactory.selectById(recordIds, sObjectType)); + return newInstance(selectorFactory.selectById(recordIds, sObjectType), sObjectType); } /** diff --git a/sfdx-source/apex-extensions/main/default/classes/domains/SObjects.cls b/sfdx-source/apex-extensions/main/default/classes/domains/SObjects.cls index cb8b79a..e638763 100644 --- a/sfdx-source/apex-extensions/main/default/classes/domains/SObjects.cls +++ b/sfdx-source/apex-extensions/main/default/classes/domains/SObjects.cls @@ -214,7 +214,7 @@ public virtual class SObjects @TestVisible protected virtual Dates getDateFieldValues(Schema.SObjectField sObjectField, fflib_Criteria criteria) { - return new SObjects(getRecords(criteria)) + return new SObjects(getRecords(criteria), getSObjectType()) .getDateFieldValues(sObjectField); } @@ -245,7 +245,7 @@ public virtual class SObjects @TestVisible protected virtual DateTimes getDateTimeFieldValues(Schema.SObjectField sObjectField, fflib_Criteria criteria) { - return new SObjects(getRecords(criteria)) + return new SObjects(getRecords(criteria), getSObjectType()) .getDateTimeFieldValues(sObjectField); } @@ -276,7 +276,7 @@ public virtual class SObjects @TestVisible protected virtual Decimals getDecimalFieldValues(Schema.SObjectField sObjectField, fflib_Criteria criteria) { - return new SObjects(getRecords(criteria)) + return new SObjects(getRecords(criteria), getSObjectType()) .getDecimalFieldValues(sObjectField); } @@ -307,7 +307,7 @@ public virtual class SObjects @TestVisible protected virtual Doubles getDoubleFieldValues(Schema.SObjectField sObjectField, fflib_Criteria criteria) { - return new SObjects(getRecords(criteria)) + return new SObjects(getRecords(criteria), getSObjectType()) .getDoubleFieldValues(sObjectField); } @@ -324,6 +324,7 @@ public virtual class SObjects * Accounts accounts = Accounts.newInstance(records); * Map accountNameById = accounts.getFieldByField(Account.Name, Account.Id); */ + @TestVisible protected virtual Map getFieldByField(Schema.SObjectField valueField, Schema.SObjectField keyField) { Map result = new Map(); @@ -352,6 +353,7 @@ public virtual class SObjects * Contacts contacts = Contacts.newInstance(records); * Map> contactIdByAccountId = contacts.getFieldsByField(Contact.Id, Contact.AccountId); */ + @TestVisible protected virtual Map> getFieldsByField(Schema.SObjectField valueField, Schema.SObjectField keyField) { Map> result = new Map>(); @@ -382,6 +384,7 @@ public virtual class SObjects * Contacts contacts = Contacts.newInstance(records); * Map accountIdByContactId = contacts.getIdFieldByIdField(Contact.AccountId, Contact.Id); */ + @TestVisible protected virtual Map getIdFieldByIdField(Schema.SObjectField valueField, Schema.SObjectField keyField) { Map result = new Map(); @@ -410,6 +413,7 @@ public virtual class SObjects * Contacts contacts = Contacts.newInstance(records); * Map> contactIdByAccountId = contacts.getIdFieldsByIdField(Contact.Id, Contact.AccountId); */ + @TestVisible protected virtual Map> getIdFieldsByIdField(Schema.SObjectField valueField, Schema.SObjectField keyField) { Map> result = new Map>(); @@ -459,7 +463,7 @@ public virtual class SObjects @TestVisible protected virtual Ids getIdFieldValues(Schema.SObjectField sObjectField, fflib_Criteria criteria) { - return new SObjects(getRecords(criteria)) + return new SObjects(getRecords(criteria), getSObjectType()) .getIdFieldValues(sObjectField); } @@ -491,7 +495,7 @@ public virtual class SObjects @TestVisible protected virtual Integers getIntegerFieldValues(Schema.SObjectField sObjectField, fflib_Criteria criteria) { - return new SObjects(getRecords(criteria)) + return new SObjects(getRecords(criteria), getSObjectType()) .getIntegerFieldValues(sObjectField); } @@ -522,7 +526,7 @@ public virtual class SObjects @TestVisible protected virtual Longs getLongFieldValues(Schema.SObjectField sObjectField, fflib_Criteria criteria) { - return new SObjects(getRecords(criteria)) + return new SObjects(getRecords(criteria), getSObjectType()) .getLongFieldValues(sObjectField); } @@ -538,6 +542,7 @@ public virtual class SObjects * Account account = Account.newInstance(records); * Map accountById = account.getSObjectByIdField(Account.Id); */ + @TestVisible protected virtual Map getSObjectByIdField(Schema.SObjectField sObjectField) { Map result = new Map(); @@ -562,13 +567,14 @@ public virtual class SObjects * Contacts contacts = Contacts.newInstance(records); * Map> contactsByAccountId = contacts.getSObjectsByIdField(Contact.AccountId); */ + @TestVisible protected virtual Map> getSObjectsByIdField(Schema.SObjectField sObjectField) { Map> result = new Map>(); for (SObject record : getRecords()) { Id fieldId = (Id) record.get(sObjectField); - if (record.get(fieldId) == null) continue; + if (fieldId == null) continue; if (!result.containsKey(fieldId)) { @@ -591,6 +597,7 @@ public virtual class SObjects * Account account = Account.newInstance(records); * Map accountByNumber = account.getSObjectByStringField(Account.AccountNumber); */ + @TestVisible protected virtual Map getSObjectByStringField(Schema.SObjectField sObjectField) { Map result = new Map(); @@ -616,6 +623,7 @@ public virtual class SObjects * Account account = Account.newInstance(records); * Map accountByName = account.getSObjectsByStringField(Account.AccountName); */ + @TestVisible protected virtual Map> getSObjectsByStringField(Schema.SObjectField sObjectField) { Map> result = new Map>(); @@ -646,6 +654,7 @@ public virtual class SObjects * Account account = Account.newInstance(records); * Map accountNameById = account.getStringFieldByIdField(Account.AccountName, Account.Id); */ + @TestVisible protected virtual Map getStringFieldByIdField(Schema.SObjectField valueField, Schema.SObjectField keyField) { Map result = new Map(); @@ -670,6 +679,7 @@ public virtual class SObjects * Account account = Account.newInstance(records); * Map accountNameById = account.getStringFieldByStringField(Account.AccountName, Account.Id); */ + @TestVisible protected virtual Map getStringFieldByStringField(Schema.SObjectField valueField, Schema.SObjectField keyField) { Map result = new Map(); @@ -708,7 +718,7 @@ public virtual class SObjects @TestVisible protected virtual Strings getStringFieldValues(Schema.SObjectField sObjectField, fflib_Criteria criteria) { - return new SObjects(getRecords(criteria)) + return new SObjects(getRecords(criteria), getSObjectType()) .getStringFieldValues(sObjectField); } @@ -722,7 +732,7 @@ public virtual class SObjects @TestVisible protected virtual void setFieldValue(Schema.SObjectField sObjectField, Object value, fflib_Criteria criteria) { - new SObjects(getRecords(criteria)) + new SObjects(getRecords(criteria), getSObjectType()) .setFieldValue(sObjectField, value); } } \ No newline at end of file diff --git a/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicDomainFactoryTest.cls b/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicDomainFactoryTest.cls new file mode 100644 index 0000000..79b3c75 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicDomainFactoryTest.cls @@ -0,0 +1,98 @@ +/** + * File Name: fflib_ClassicDomainFactoryTest + * + * @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. + */ +@IsTest +private class fflib_ClassicDomainFactoryTest +{ + @IsTest + static void testBehavior() + { + // todo - fix assertions + fflib_ClassicSelectorFactory selectorFactory = + new fflib_ClassicSelectorFactory( + new Map + { + Account.SObjectType => MySelector.class + }); + + fflib_ClassicDomainFactory domainFactory = new fflib_ClassicDomainFactory( + selectorFactory, + new Map + { + Account.SObjectType => MyDomainConstructor.class + }); + List records = new List(); + + domainFactory.newInstance(records); + domainFactory.newInstance( + new Set{fflib_IDGenerator.generate(Account.SObjectType)}, + Account.SObjectType); + domainFactory.newInstance(new Set{fflib_IDGenerator.generate(Account.SObjectType)}); + domainFactory.replaceWith(Account.SObjectType, MyDomain.class); + domainFactory.setMock(Account.SObjectType, new MyDomain(records)); + domainFactory.setMock(new MyDomain(records)); + } + + public class MySelector extends fflib_SObjectSelector + { + public List getSObjectFieldList() + { + return new List + { + Account.Id + }; + } + + public override List selectSObjectsById(Set idSet) + { + return new List{ new Account(Id = new List(idSet).get(0))}; + } + + public SObjectType getSObjectType() + { + return Account.SObjectType; + } + } + + public class MyDomain extends SObjects + { + public MyDomain(List records) + { + super(records, Account.SObjectType); + } + } + + public class MyDomainConstructor implements fflib_IDomainConstructor + { + public fflib_IDomain construct(List objects) + { + return new fflib_SObjects((List) objects); + } + } +} \ No newline at end of file diff --git a/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicDomainFactoryTest.cls-meta.xml b/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicDomainFactoryTest.cls-meta.xml new file mode 100644 index 0000000..d75b058 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/application/fflib_ClassicDomainFactoryTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 51.0 + Active + diff --git a/sfdx-source/apex-extensions/tests/classes/domains/SObjectsTest.cls b/sfdx-source/apex-extensions/tests/classes/domains/SObjectsTest.cls index b44d32b..1bc8d99 100644 --- a/sfdx-source/apex-extensions/tests/classes/domains/SObjectsTest.cls +++ b/sfdx-source/apex-extensions/tests/classes/domains/SObjectsTest.cls @@ -68,7 +68,7 @@ private class SObjectsTest } @IsTest - static void itShouldReturnTheDomainsType() + static void itShouldReturnTheCreatedData() { System.assertEquals( (Object) Schema.Account.SObjectType, @@ -84,6 +84,36 @@ private class SObjectsTest ); } + @IsTest + static void itShouldReturnTheDomainsType() + { + fflib_Criteria criteria = new fflib_Criteria().equalTo(Account.Name, 'A'); + + DomainAccounts domain = generateDomain(); + domain.getDateTimeFieldValues(Account.LastActivityDate); + domain.getDateTimeFieldValues(Account.CreatedDate); + domain.getFieldByField(Account.Name, Account.AccountNumber); + domain.getFieldsByField(Account.Id, Account.AccountNumber); + domain.getFieldByField(Account.Id, Account.Id); + domain.getIdFieldByIdField(Account.Id, Account.Id); + domain.getIdFieldsByIdField(Account.Id, Account.Id); + domain.getIdFieldValues(Account.Id); + domain.getIdFieldValues(Account.Id, criteria); + domain.getIntegerFieldValues(Account.NumberOfEmployees); + domain.getIntegerFieldValues(Account.NumberOfEmployees, criteria); + domain.getDoubleFieldValues(Account.BillingLatitude); + domain.getDoubleFieldValues(Account.BillingLatitude, criteria); + domain.getSObjectByIdField(Account.Id); + domain.getSObjectsByIdField(Account.Id); + domain.getSObjectByStringField(Account.Name); + domain.getSObjectsByStringField(Account.Name); + domain.getStringFieldByIdField(Account.Id, Account.Name); + domain.getStringFieldByStringField(Account.Name, Account.AccountNumber); + domain.getStringFieldValues(Account.Name, criteria); + + // todo - add assertions + } + @IsTest static void itShouldReturnRecordByIds() { diff --git a/sfdx-source/apex-extensions/tests/classes/utils/fflib_OperatorUtilsTest.cls b/sfdx-source/apex-extensions/tests/classes/utils/fflib_OperatorUtilsTest.cls new file mode 100644 index 0000000..ef91a00 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/utils/fflib_OperatorUtilsTest.cls @@ -0,0 +1,49 @@ +/** + * File Name: sflib_sflib_OperatorUtilsTest + * + * @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. + */ +@IsTest +private class fflib_OperatorUtilsTest +{ + @IsTest + static void testBehavior() + { + System.assertEquals('=', fflib_OperatorUtils.operatorToString(fflib_OperatorUtils.EQUALS)); + System.assertEquals('!=', fflib_OperatorUtils.operatorToString(fflib_OperatorUtils.NOT_EQUALS)); + System.assertEquals('<', fflib_OperatorUtils.operatorToString(fflib_OperatorUtils.LESS_THAN)); + System.assertEquals('<=', fflib_OperatorUtils.operatorToString(fflib_OperatorUtils.LESS_THAN_OR_EQUAL_TO)); + System.assertEquals('>', fflib_OperatorUtils.operatorToString(fflib_OperatorUtils.GREATER_THAN)); + System.assertEquals('>=', fflib_OperatorUtils.operatorToString(fflib_OperatorUtils.GREATER_THAN_OR_EQUAL_TO)); + System.assertEquals('like', fflib_OperatorUtils.operatorToString(fflib_OperatorUtils.LIKEx)); + System.assertEquals('IN', fflib_OperatorUtils.operatorToString(fflib_OperatorUtils.INx)); + System.assertEquals('NOT IN', fflib_OperatorUtils.operatorToString(fflib_OperatorUtils.NOT_IN)); + System.assertEquals('INCLUDES', fflib_OperatorUtils.operatorToString(fflib_OperatorUtils.INCLUDES)); + System.assertEquals('EXCLUDES', fflib_OperatorUtils.operatorToString(fflib_OperatorUtils.EXCLUDES)); + System.assertEquals(null, fflib_OperatorUtils.operatorToString(null)); + } +} \ No newline at end of file diff --git a/sfdx-source/apex-extensions/tests/classes/utils/fflib_OperatorUtilsTest.cls-meta.xml b/sfdx-source/apex-extensions/tests/classes/utils/fflib_OperatorUtilsTest.cls-meta.xml new file mode 100644 index 0000000..d75b058 --- /dev/null +++ b/sfdx-source/apex-extensions/tests/classes/utils/fflib_OperatorUtilsTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 51.0 + Active +