diff --git a/config/enterprise-project-scratch-def.json b/config/enterprise-project-scratch-def.json index b464990..66c6888 100644 --- a/config/enterprise-project-scratch-def.json +++ b/config/enterprise-project-scratch-def.json @@ -1,9 +1,21 @@ { - "orgName": "Acme DF18 Enterprise Company", + "orgName": "force-di-scratch-ent", "edition": "Enterprise", + "features": ["MultiCurrency","AuthorApex"], "settings": { + "communitiesSettings": { + "enableNetworksEnabled": false + }, + "mobileSettings": { + "enableS1EncryptedStoragePref2": false + }, "lightningExperienceSettings": { - "enableS1DesktopEnabled": true + "enableS1DesktopEnabled": true + }, + "securitySettings": { + "sessionSettings":{ + "sessionTimeout": "TwelveHours" + } } } } diff --git a/config/project-scratch-def.json b/config/project-scratch-def.json index f8408d3..8096eea 100644 --- a/config/project-scratch-def.json +++ b/config/project-scratch-def.json @@ -1,9 +1,21 @@ { - "orgName": "force-di", + "orgName": "force-di-scratch-dev", "edition": "Developer", + "features": ["MultiCurrency","AuthorApex"], "settings": { + "communitiesSettings": { + "enableNetworksEnabled": false + }, + "mobileSettings": { + "enableS1EncryptedStoragePref2": false + }, "lightningExperienceSettings": { - "enableS1DesktopEnabled": true + "enableS1DesktopEnabled": true + }, + "securitySettings": { + "sessionSettings":{ + "sessionTimeout": "TwelveHours" + } } } } diff --git a/force-di/main/aura/di_injector/di_injector.cmp b/force-di/main/aura/di_injector/di_injector.cmp index 7b7aad7..7f40a2a 100644 --- a/force-di/main/aura/di_injector/di_injector.cmp +++ b/force-di/main/aura/di_injector/di_injector.cmp @@ -28,6 +28,11 @@ + + + + + {!v.body} diff --git a/force-di/main/aura/di_injector/di_injectorController.js b/force-di/main/aura/di_injector/di_injectorController.js index 96018c1..beea9b6 100644 --- a/force-di/main/aura/di_injector/di_injectorController.js +++ b/force-di/main/aura/di_injector/di_injectorController.js @@ -30,19 +30,29 @@ // Resolve the given binding var action = cmp.get("c.getBinding"); action.setParams({ bindingName : cmp.get("v.bindingName") }); + action.setCallback(this, function(response) { var state = response.getState(); if (state === "SUCCESS") { var bindingInfo = response.getReturnValue(); var injectAttrs = cmp.get("v.body"); + // Construct attributes to pass on to injected component var componentName = null; var componentAttrs = {}; + + if(bindingInfo.BindingTypeAsString == 'Flow') { componentName = 'c:di_injectorFlowProxy'; componentAttrs['flowName'] = bindingInfo.To; componentAttrs['injectorAttributes'] = injectAttrs; } else if(bindingInfo.BindingTypeAsString == 'LightningComponent') { + // Added by Leon Kempers: set aura:id + let bindingId = cmp.get('v.bindingId'); + if (typeof bindingId === 'undefined') { + cmp.set('v.bindingId', 'di_component'); + } + componentAttrs['aura:id'] = cmp.get('v.bindingId'); componentName = bindingInfo.To; for (var attrIdx in injectAttrs) { var injectAttr = injectAttrs[attrIdx]; @@ -52,6 +62,7 @@ console.log("Binding type " + bindingInfo.BindingTypeAsString + ' not supported'); return; } + // Inject the component bound to the given binding $A.createComponent( componentName, @@ -88,5 +99,32 @@ } }); $A.enqueueAction(action); + }, + + // Added by Leon Kempers: Listen to attribute value change + // + // added a handler to capture the di_injectorAttributeChangeEvent. When it comes in, + // the handleChangeEvent() function looks at the bindingId variable stored in the component, + // finds the component based on this ID, and changes the specified attribute to the 'newValue'. + // + // The only not-so-pretty thing here is that sometimes (e.g. in case of the spinner) the value + // changed while $A.createComponent was still running (i.e. the Lightning Component hadn't + // been put on the DOM yet). So in that case, we just wait 100ms and try again. + handleChangeEvent : function(component, event, helper) { + + let bindingId = component.get('v.bindingId'); + let auraCmp = component.find(bindingId); + + // Sometimes value will change while the Aura Component hasn't + // been added to the DOM yet; wait 100ms and try again + if (typeof(auraCmp) === undefined) { + setTimeout(function() { + this.handleChangeEvent(component, event, helper); + }, 100); + } else { + let name = event.getParam('name'); + let newValue = event.getParam('newValue'); + auraCmp.set('v.' + name, newValue); + } } }) diff --git a/force-di/main/aura/di_injectorAttribute/di_injectorAttribute.cmp b/force-di/main/aura/di_injectorAttribute/di_injectorAttribute.cmp index b197e78..9fca1a0 100644 --- a/force-di/main/aura/di_injectorAttribute/di_injectorAttribute.cmp +++ b/force-di/main/aura/di_injectorAttribute/di_injectorAttribute.cmp @@ -16,4 +16,18 @@ description="Specific data type the value represents. Helps when mapping values to things like input variables of flows." required="false"/> + + + + + diff --git a/force-di/main/aura/di_injectorAttribute/di_injectorAttributeController.js b/force-di/main/aura/di_injectorAttribute/di_injectorAttributeController.js new file mode 100644 index 0000000..69d2801 --- /dev/null +++ b/force-di/main/aura/di_injectorAttribute/di_injectorAttributeController.js @@ -0,0 +1,11 @@ +({ + // Leon Kempers - handle dynamic value change via event + handleValueChange : function(component, event, helper) { + let name = component.get('v.name'); + let newValue = event.getParam('value'); + + let changeEvent = component.getEvent('attributeChangeEvent'); + changeEvent.setParams({ 'name' : name, 'newValue' : newValue }); + changeEvent.fire(); + } +}) \ No newline at end of file diff --git a/force-di/main/aura/di_injectorAttributeChangeEvent/di_injectorAttributeChangeEvent.evt b/force-di/main/aura/di_injectorAttributeChangeEvent/di_injectorAttributeChangeEvent.evt new file mode 100644 index 0000000..2147c90 --- /dev/null +++ b/force-di/main/aura/di_injectorAttributeChangeEvent/di_injectorAttributeChangeEvent.evt @@ -0,0 +1,8 @@ + + + + + diff --git a/force-di/main/aura/di_injectorAttributeChangeEvent/di_injectorAttributeChangeEvent.evt-meta.xml b/force-di/main/aura/di_injectorAttributeChangeEvent/di_injectorAttributeChangeEvent.evt-meta.xml new file mode 100644 index 0000000..bc90b9b --- /dev/null +++ b/force-di/main/aura/di_injectorAttributeChangeEvent/di_injectorAttributeChangeEvent.evt-meta.xml @@ -0,0 +1,5 @@ + + + 48.0 + A Lightning Event Bundle + \ No newline at end of file diff --git a/force-di/main/classes/di_Binding.cls b/force-di/main/classes/di_Binding.cls index 931613a..6a659f7 100644 --- a/force-di/main/classes/di_Binding.cls +++ b/force-di/main/classes/di_Binding.cls @@ -275,7 +275,6 @@ public abstract class di_Binding implements Comparable { { if ( this.bindings == null ) { - System.debug('// di_Binding.Resolver :: Loading Bindings //'); // Ask each module to configure and aggregate the resulting bindings this.bindings = new List(); for (di_Module module : modules) diff --git a/force-di/main/classes/di_Injector.cls b/force-di/main/classes/di_Injector.cls index d76aa22..b9f3d25 100644 --- a/force-di/main/classes/di_Injector.cls +++ b/force-di/main/classes/di_Injector.cls @@ -33,11 +33,13 @@ public class di_Injector { public static final di_Injector Org = new di_Injector( new List { - new CustomMetadataModule()}); + new CustomMetadataModule() + }); /** * Bindings visible to this Injector **/ + @TestVisible public di_Binding.Resolver Bindings {get; private set;} /** @@ -84,7 +86,6 @@ public class di_Injector { if ( String.isBlank(developerName) ) { throw new InjectorException('Request for Binding cannot take "developerName" parameter of null'); } - List bindingsFound = this.Bindings.byName( developerName.toLowerCase().trim() ).get(); if ( bindingsFound == null || bindingsFound.isEmpty() ) { throw new InjectorException('Binding for "' + developerName + '" not found'); @@ -121,8 +122,8 @@ public class di_Injector { } List bindingsFound = this.Bindings.bySObject( bindingSObjectType ) - .byName( developerName.toLowerCase().trim() ) - .get(); + .byName( developerName.toLowerCase().trim() ) + .get(); if ( bindingsFound == null || bindingsFound.isEmpty() || bindingsFound[0] == null) { throw new InjectorException('Binding for "' + developerName + '" and SObjectType "' + bindingSObjectType + '" not found'); @@ -152,23 +153,23 @@ public class di_Injector { , BindingObject__r.QualifiedApiName , BindingObjectAlternate__c , BindingSequence__c - FROM di_Binding__mdt]; - for(di_Binding__mdt records :bindingMDTRec){ + FROM di_Binding__mdt]; + for(di_Binding__mdt records :bindingMDTRec) { recordList.add(new di_BindingConfigWrapper(records)); } // When we want to mock data from metadata for injecting dependencies. - if(di_Injector.mock_BindingConfigurationWrappersOuter != null){ + if(di_Injector.mock_BindingConfigurationWrappersOuter != null) { recordList = di_Injector.mock_BindingConfigurationWrappersOuter; } return recordList; } public override void configure() { // TODO: Support Namespace - for(di_BindingConfigWrapper bindingConfig :getDIBinding()){ + for(di_BindingConfigWrapper bindingConfig :getDIBinding()) { bind(bindingConfig.DeveloperName); type(bindingConfig.Type); if( String.isNotBlank(bindingConfig.BindingObject) - || String.isNotBlank(bindingConfig.BindingObjectAlternate)){ + || String.isNotBlank(bindingConfig.BindingObjectAlternate)) { bindingObjectApiName = String.isNotBlank(bindingConfig.BindingObject) ? bindingConfig.bindingObjectQualifiedApiName.toLowerCase().trim() : bindingConfig.BindingObjectAlternate.toLowerCase().trim(); @@ -178,7 +179,7 @@ public class di_Injector { } bind(results[0].getSObjectType()); // if it is getting here, then it is finding a SObject to add to the binding } - if(bindingConfig.BindingSequence != null){ + if(bindingConfig.BindingSequence != null) { sequence(Integer.valueOf(bindingConfig.BindingSequence)); } data(bindingConfig); diff --git a/force-di/main/classes/di_InjectorComponentController.cls b/force-di/main/classes/di_InjectorComponentController.cls index 92e46bd..75da4e7 100644 --- a/force-di/main/classes/di_InjectorComponentController.cls +++ b/force-di/main/classes/di_InjectorComponentController.cls @@ -22,13 +22,14 @@ * 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 with sharing class di_InjectorComponentController { - public String BindingNameValue {set;get;} - - public Object ParametersValue {set;get;} + public String BindingNameValue {set; get;} + // BJA - container id for lightning-- allows consumers to reference into (optional) + public String BindingIdValue {set; get;} + public Object ParametersValue {set; get;} public ApexPages.Component getInject() { ApexPages.Component cmp = null; @@ -56,7 +57,7 @@ public with sharing class di_InjectorComponentController { return new Component.di_injectorFlowProxy( flowName = flowName, inputVariables = params - ); + ); } } \ No newline at end of file diff --git a/force-di/main/classes/di_PlatformCache.cls b/force-di/main/classes/di_PlatformCache.cls index 9e4dcf8..044934d 100644 --- a/force-di/main/classes/di_PlatformCache.cls +++ b/force-di/main/classes/di_PlatformCache.cls @@ -1,9 +1,40 @@ -public with sharing class di_PlatformCache +/* + * Modifications: + * B Anderson -- + * + Checked for Cache not enabled ( getPartition) + * + Re-aligned the code for readability + * + Add Tests + */ +public with sharing class di_PlatformCache { - private di_PlatformCache() { } - + ////////////////////////////////////////////////////////////////////////////////////////////// + // Data Members + ////////////////////////////////////////////////////////////////////////////////////////////// + // number of seconds for a 24 hour period + public static final Integer NUM_OF_SECS_IN24HR = 86400; + + @TestVisible + private static final String BINDING_KEY = 'bindingKeyIndex'; + @TestVisible private static di_PlatformCache instance; + @TestVisible + private Map > > cacheKeyIndexMap = new Map > >(); + @TestVisible + private static Map generatedKeyNames = new Map(); + // Used for turning on logging (if needed) + @TestVisible + private static Boolean DEBUGGING = false; + + ////////////////////////////////////////////////////////////////////////////////////////////// + // Ctors + ////////////////////////////////////////////////////////////////////////////////////////////// + // singleton + private di_PlatformCache() { + } + ////////////////////////////////////////////////////////////////////////////////////////////// + // Public Methods + ////////////////////////////////////////////////////////////////////////////////////////////// public static di_PlatformCache getInstance() { if ( instance == null ) @@ -14,48 +45,21 @@ public with sharing class di_PlatformCache return instance; } - private static di_Configurations__c getConfig() - { - di_Configurations__c config = di_Configurations__c.getInstance(); - - if ( config == null ) - { - config = new di_Configurations__c(); - config.SetupOwnerId = ConnectApi.Organization.getSettings().orgId; - insert config; - } - - return config; - } public static Boolean isStoringBindingInPlatformCache() { return getConfig().UsePlatformCacheToStoreBindings__c == null ? false : getConfig().UsePlatformCacheToStoreBindings__c; } - - private static String getPartitionName() - { - return getConfig().OrgCachePartitionName__c; - } - - private Integer getPartitionTTL() - { - return 86400; // number of seconds for a 24 hour period - } - - private static Cache.OrgPartition getPartition() - { - return Cache.Org.getPartition(getPartitionName()); - } - - private Map>> cacheKeyIndexMap = new Map>>(); - - public Map>> getCacheKeyIndexMap() + public Map > > getCacheKeyIndexMap() { if ( cacheKeyIndexMap.isEmpty() ) { try { - cacheKeyIndexMap = (Map>>) getPartition().get( getKeyIndexName() ); + // if there IS NO Partition created; let's not FAIL + Cache.OrgPartition orgPartition = getPartition(); + if ( orgPartition != null ) { + cacheKeyIndexMap = (Map > >) orgPartition.get( getKeyIndexName() ); + } } catch (Cache.Org.OrgCacheException ex) { // this indicates a potentially corrupt cache, so clear the map and let it rebuild @@ -64,40 +68,176 @@ public with sharing class di_PlatformCache if ( cacheKeyIndexMap == null ) { - cacheKeyIndexMap = new Map>>(); + cacheKeyIndexMap = new Map > >(); } - + /* - for(String key : cacheKeyIndexMap.keySet()) { - System.debug('Cache Key => ' + key); + for(String key : cacheKeyIndexMap.keySet()) { + log('Cache Key => ' + key); for (SObjectType subkey : cacheKeyIndexMap.get(key).keySet()) { - System.debug('Cache Key Index => ' + subkey); + log('Cache Key Index => ' + subkey); for(String item : cacheKeyIndexMap.get(key).get(subkey)) { - System.debug('Cache Key Index Item => ' + item); + log('Cache Key Index Item => ' + item); } } - } - */ + } + */ } return cacheKeyIndexMap; } - private void pushCacheKeyIndexMapToCache() + public Boolean addBindingToPlatformCache( di_Binding binding ) { - getPartition().put( getKeyIndexName(), this.cacheKeyIndexMap, getPartitionTTL(), Cache.Visibility.ALL, false); + Boolean result=false; + if ( isStoringBindingInPlatformCache() ) + { + // if there IS NO Partition created; let's not FAIL + Cache.OrgPartition orgPartition = getPartition(); + if ( orgPartition != null ) { + String theKeyName = getKeyName(binding); + // add the binding to the platform cache directly + orgPartition.put(theKeyName, binding, getPartitionTTL(), Cache.Visibility.ALL, false); + // add the binding's cache key name to the bindingKeyIndex + addBindingToKeyIndex(binding); + log('Adding binding for hash => ' + theKeyName + ' && developerName => ' + binding.developerName + ' && object => ' + binding.bindingObject); + result = true; + } + } + return result; + } + + public list retrieveBindings(String developerName, Schema.SObjectType bindingSObjectType) + { + list bindings = new list(); + + if ( isStoringBindingInPlatformCache() + && string.isNotBlank(developerName) + && bindingSObjectType != null) + { + log('Retrieving from Cache Key => ' + developerName + ' && Cache Key Index => ' + bindingSObjectType); + // if there IS NO Partition created; let's not FAIL + Cache.OrgPartition orgPartition = getPartition(); + Map > keyIndexBySObjectTypeMap = getCacheKeyIndexMap().get(developerName.toLowerCase().trim()); + if ( keyIndexBySObjectTypeMap != null && orgPartition != null ) + { + Set cacheKeys = keyIndexBySObjectTypeMap.get(bindingSObjectType); + if ( cacheKeys != null ) + { + Object cachedObject = null; + for ( String cacheKey : cacheKeys ) + { + cachedObject = orgPartition.get( cacheKey ); + if ( cachedObject != null ) + { + bindings.add( (di_Binding) cachedObject); + } + } + } + } + } + + return bindings; } + public static void clearCachedBindings() { + + Set keys =getPartitionKeys(); + + if ( keys != null ) { + String partitionKey = getPartitionName(); + Cache.OrgPartition partition = getPartition(); + // clear current bindings + for (String key : partition.getKeys() ) { + try { + partition.remove(key); + } catch (Exception ex) { + log('XX]> Unable to remove Platform Cache partition [' + partitionKey + '] key [' + key + ']'); + } + } + } + } + + /** + * getPartitionKeys get partition keys + * @return return Set partition keys + */ + public static Set getPartitionKeys() { + Set keys = null; + Cache.OrgPartition partition = getPartition(); + if ( partition != null ) { + // get partition keys + keys= partition.getKeys(); + } + return keys; + }// end of getPartitionKeys + ////////////////////////////////////////////////////////////////////////////////////////////// + // Private Methods + ////////////////////////////////////////////////////////////////////////////////////////////// + + @TestVisible + private static di_Configurations__c getConfig() + { + di_Configurations__c config = di_Configurations__c.getInstance(); + + if ( config == null ) + { + config = new di_Configurations__c(); + config.SetupOwnerId = ConnectApi.Organization.getSettings().orgId; + // make CheckMarx happy + if (di_Configurations__c.SObjectType.getDescribe().isCreateable() ) + { + insert config; + } + } + + return config; + } + + @TestVisible + private static String getPartitionName() + { + return getConfig().OrgCachePartitionName__c; + } + @TestVisible + private Integer getPartitionTTL() + { + return NUM_OF_SECS_IN24HR; // number of seconds for a 24 hour period + } + @TestVisible + private static Cache.OrgPartition getPartition() + { + Cache.OrgPartition result=null; + try { + result=Cache.Org.getPartition(getPartitionName()); + } catch (Exception excp) { + log('ERROR: Is there Cache? Is the Cache Partition enabled : Exception:' + excp); + } + return result; + } + + @TestVisible + private boolean pushCacheKeyIndexMapToCache() + { + // if there IS NO Partition created; let's not FAIL + Cache.OrgPartition orgPartition = getPartition(); + if ( orgPartition != null ) { + orgPartition.put( getKeyIndexName(), this.cacheKeyIndexMap, getPartitionTTL(), Cache.Visibility.ALL, false); + + } + return orgPartition != null; + } + @TestVisible private void addBindingToKeyIndex(di_Binding binding) { String workingDeveloperName = binding.developerName.toLowerCase().trim(); - if ( ! getCacheKeyIndexMap().containsKey( workingDeveloperName ) ) + if ( !getCacheKeyIndexMap().containsKey( workingDeveloperName ) ) { - getCacheKeyIndexMap().put(workingDeveloperName, new Map>() ); + getCacheKeyIndexMap().put(workingDeveloperName, new Map >() ); } - if ( ! getCacheKeyIndexMap().get(workingDeveloperName).containsKey( binding.bindingObject) ) + if ( !getCacheKeyIndexMap().get(workingDeveloperName).containsKey( binding.bindingObject) ) { getCacheKeyIndexMap().get(workingDeveloperName).put( binding.bindingObject, new Set() ); } @@ -107,91 +247,62 @@ public with sharing class di_PlatformCache pushCacheKeyIndexMapToCache(); } - private static Map generatedKeyNames = new Map(); - + @TestVisible private String constructKeyName( Schema.SObjectType bindingSObjectType, String developerName ) { - String key = ( ( bindingSObjectType != null ) ? bindingSObjectType.getDescribe().getName().toLowerCase().replaceAll('__','') : '' ) - + ( String.isBlank(developerName) ? '' : developerName.toLowerCase().trim() ); + String key = ( ( bindingSObjectType != null ) ? bindingSObjectType.getDescribe().getName().toLowerCase().replaceAll('__','') : '' ) + + ( String.isBlank(developerName) ? '' : developerName.toLowerCase().trim() ); // put generated hash into a map on first pass, so that we do not perform hashcode() operation more than once per "key" // hashcode() is a more expensive operation than map.get() if (generatedKeyNames.containsKey(key)) { return generatedKeyNames.get(key); } String hash = String.valueOf( Math.abs( ( key ).hashcode() ) ); - //System.debug('Creating Hash For => ' + developerName + ' && ' + bindingSObjectType + ' := ' + hash); + log('Creating Hash For => ' + developerName + ' && ' + bindingSObjectType + ' := ' + hash); generatedKeyNames.put(key, hash); return hash; } - + @TestVisible private String getKeyName( String developerName, Schema.SObjectType bindingSObjectType) { return constructKeyName( bindingSObjectType, developerName); } - + @TestVisible private String getKeyName( di_Binding binding ) { return constructKeyName( binding.bindingObject, binding.developerName); } - + @TestVisible private String getKeyIndexName() { - return 'bindingKeyIndex'; + return di_PlatformCache.BINDING_KEY; } - public void addBindingToPlatformCache( di_Binding binding ) - { - if ( isStoringBindingInPlatformCache() ) - { - String theKeyName = getKeyName(binding); - // add the binding to the platform cache directly - getPartition().put(theKeyName, binding, getPartitionTTL(), Cache.Visibility.ALL, false); - // add the binding's cache key name to the bindingKeyIndex - addBindingToKeyIndex(binding); - //System.debug('Adding binding for hash => ' + theKeyName + ' && developerName => ' + binding.developerName + ' && object => ' + binding.bindingObject); - } - } - - public list retrieveBindings(String developerName, Schema.SObjectType bindingSObjectType) - { - list bindings = new list(); - - if ( isStoringBindingInPlatformCache() ) - { - //System.debug('Retrieving from Cache Key => ' + developerName + ' && Cache Key Index => ' + bindingSObjectType); - - Map> keyIndexBySObjectTypeMap = getCacheKeyIndexMap().get(developerName.toLowerCase().trim()); - if ( keyIndexBySObjectTypeMap != null ) - { - Set cacheKeys = keyIndexBySObjectTypeMap.get(bindingSObjectType); - if ( cacheKeys != null ) - { - Object cachedObject = null; - for ( String cacheKey : cacheKeys ) - { - cachedObject = getPartition().get( cacheKey ); - if ( cachedObject != null ) - { - bindings.add( (di_Binding) getPartition().get( cacheKey ) ); - } - } - } - } + /** + * log centralize to encapsulate and refactor later + * @param excp to display in sink + */ + @TestVisible + private static Boolean log(Exception excp){ + Boolean before=DEBUGGING,result; + // always show exceptions + DEBUGGING=true; + result=log(excp.getMessage()); + DEBUGGING=before; + return result; + + }// end of log + /** + * log centralize to encapsulate and refactor later + * @param message message to display in sink + */ + @TestVisible + private static Boolean log(String message){ + Boolean doLog = DEBUGGING && string.isNotBlank(message); + if ( doLog ) { + system.debug('+++ di_PlatformCache.message: ' + message); } - - return bindings; - } + return doLog; + }// end of log - public static void clearCachedBindings() { - String partitionKey = getPartitionName(); - Cache.OrgPartition partition = getPartition(); - // clear current bindings - for (String key : partition.getKeys() ) { - try { - partition.remove(key); - } catch (Exception ex) { - System.debug('XX]> Unable to remove Platform Cache partition [' + partitionKey + '] key [' + key + ']'); - } - } - } } \ No newline at end of file diff --git a/force-di/test/classes/di_BindingConfigWrapperTest.cls b/force-di/test/classes/di_BindingConfigWrapperTest.cls new file mode 100644 index 0000000..47589d1 --- /dev/null +++ b/force-di/test/classes/di_BindingConfigWrapperTest.cls @@ -0,0 +1,81 @@ +/** + * + * 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 copyright 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 Andrew Fawcett, 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. + **/ +/** + * Modifications: + * ============= + * B Anderson : Gettting the overall code-coverage > 75% + */ +@isTest +private with sharing class di_BindingConfigWrapperTest { + + @isTest + static void givenBindingWrapperThenExtractAndValidate(){ + // Given + di_BindingConfigWrapper wrapper = new di_BindingConfigWrapper( + 'QualifiedAPIName' + , 'DeveloperName' + , 'NamespacePrefix' + , 'Type' + , 'To' + , 'BindingObject' + , 'BindingObjectQualifiedApiName' + , 'BindingObjectAlternate' + , 10.10 + ); + // Then + system.assertEquals('QualifiedAPIName', wrapper.QualifiedAPIName); + system.assertEquals('DeveloperName', wrapper.DeveloperName); + system.assertEquals('NamespacePrefix', wrapper.NamespacePrefix); + system.assertEquals('Type', wrapper.Type); + system.assertEquals('To', wrapper.To); + system.assertEquals('BindingObject', wrapper.BindingObject); + system.assertEquals('BindingObjectQualifiedApiName', wrapper.BindingObjectQualifiedApiName); + system.assertEquals('BindingObjectAlternate', wrapper.BindingObjectAlternate); + system.assertEquals(10.10, wrapper.BindingSequence); + } + + @isTest + static void givenBindingWrapperWithMDTThenExtractAndValidate(){ + // Given + di_Binding__mdt bindingConfig = new di_Binding__mdt(); + bindingConfig.QualifiedApiName='QualifiedAPIName'; + bindingConfig.DeveloperName='DeveloperName'; + bindingConfig.NamespacePrefix='NamespacePrefix'; + bindingConfig.Type__c='Type'; + bindingConfig.To__c='To'; + bindingConfig.BindingObject__c='BindingObject'; + bindingConfig.BindingObjectAlternate__c='BindingObjectAlternate'; + bindingConfig.BindingSequence__c=10.10; + di_BindingConfigWrapper wrapper = new di_BindingConfigWrapper(bindingConfig); + // Then + system.assertEquals('QualifiedAPIName', wrapper.QualifiedAPIName); + system.assertEquals('DeveloperName', wrapper.DeveloperName); + system.assertEquals('NamespacePrefix', wrapper.NamespacePrefix); + system.assertEquals('Type', wrapper.Type); + system.assertEquals('To', wrapper.To); + system.assertEquals('BindingObject', wrapper.BindingObject); + system.assertEquals('BindingObjectAlternate', wrapper.BindingObjectAlternate); + system.assertEquals(10.10, wrapper.BindingSequence); + } +} diff --git a/force-di/test/classes/di_BindingConfigWrapperTest.cls-meta.xml b/force-di/test/classes/di_BindingConfigWrapperTest.cls-meta.xml new file mode 100644 index 0000000..db9bf8c --- /dev/null +++ b/force-di/test/classes/di_BindingConfigWrapperTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 48.0 + Active + diff --git a/force-di/test/classes/di_BindingTest.cls b/force-di/test/classes/di_BindingTest.cls index 5585c28..12ab11e 100644 --- a/force-di/test/classes/di_BindingTest.cls +++ b/force-di/test/classes/di_BindingTest.cls @@ -25,6 +25,7 @@ **/ @IsTest +@TestVisible private class di_BindingTest { @IsTest diff --git a/force-di/test/classes/di_InjectorCMPFlowProxyControllerTest.cls b/force-di/test/classes/di_InjectorCMPFlowProxyControllerTest.cls index ee6d282..767e908 100644 --- a/force-di/test/classes/di_InjectorCMPFlowProxyControllerTest.cls +++ b/force-di/test/classes/di_InjectorCMPFlowProxyControllerTest.cls @@ -1,14 +1,17 @@ - @isTest +@isTest private with sharing class di_InjectorCMPFlowProxyControllerTest { @isTest private static void givenValueWhenGetInjectThenThrowException(){ - String FlowNameValue = 'AccountRecordFlow'; - Object InputVariablesValue = 'Account'; + di_InjectorComponentFlowProxyController newObj = new di_InjectorComponentFlowProxyController(); + newObj.FlowNameValue = 'AccountRecordFlow'; + newObj.InputVariablesValue = new Map { + 'Account'=>null + }; try { - newObj.getInject(); - } catch(Exception e){ + newObj.getInject(); + } catch(Exception e) { System.assertEquals(e.getMessage().contains('Invalid value for property name'), true, 'correct Exception is thrown'); } } diff --git a/force-di/test/classes/di_InjectorComponentControllerTest.cls b/force-di/test/classes/di_InjectorComponentControllerTest.cls index 2911ccd..c8ceade 100644 --- a/force-di/test/classes/di_InjectorComponentControllerTest.cls +++ b/force-di/test/classes/di_InjectorComponentControllerTest.cls @@ -22,8 +22,11 @@ * 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. -**/ - + **/ +/** + * Modifications: + * B Anderson - Updated Unit Tests ( needing >75% overall) + */ @IsTest private class di_InjectorComponentControllerTest { @@ -31,12 +34,11 @@ private class di_InjectorComponentControllerTest { static void givenWrongBindingNameValueWhenGetInjectThenThrowException(){ //given di_InjectorComponentController newObj = new di_InjectorComponentController(); - String BindingNameValue = 'flow_AccountRecord_VF'; - Object ParametersValue = 'Account'; + try { - //When - newObj.getInject(); - } catch(Exception e){ + //When + newObj.getInject(); + } catch(Exception e) { //Then System.assertEquals(e.getMessage().contains('List index out of bounds'), true, 'Correct exception is not thrown'); } @@ -45,7 +47,47 @@ private class di_InjectorComponentControllerTest { @isTest static void givenFlowNameWhenGetInjectorFlowProxyInstanceThenMethodCall(){ di_InjectorComponentController newObj = new di_InjectorComponentController(); - newObj.getInjectorFlowProxyInstance('HelloWorld', 'Account'); + Object result= newObj.getInjectorFlowProxyInstance('HelloWorld', 'Account'); + //Then + System.assertEquals(true, result instanceOf Component.di_injectorFlowProxy ); + + } + + @isTest + static void givenApexPageComponentGetInjectorIsValid() { + // Given + final String BINDING_NAME = 'myapexpage_cmp'; + di_InjectorComponentController newObj = new di_InjectorComponentController(); + newObj.BindingNameValue=BINDING_NAME; + + Component.Apex.PageBlock pageBlk = new Component.Apex.PageBlock(); + di_Injector.Org.Bindings.set(new di_Module() + .visualforceComponent() + .bind(BINDING_NAME) + .toObject(pageBlk)); + //When + + Object result= newObj.getInject(); + //Then + System.assertNotEquals(null, result ); + System.assertEquals(true,result instanceOf Component.apex.pageblock); + + } + + @isTest + static void givenLightningComponentGetBindingId() { + // Given + final String BINDING_NAME = 'myapexpage_cmp'; + final String BINDING_ID = 'myapexpage_id'; + // When + di_InjectorComponentController newObj = new di_InjectorComponentController(); + newObj.BindingNameValue=BINDING_NAME; + newObj.BindingIdValue=BINDING_ID; + + //Then + System.assertEquals( BINDING_ID,newObj.BindingIdValue); + System.assertEquals( BINDING_NAME,newObj.BindingNameValue); + } } diff --git a/force-di/test/classes/di_InjectorTest.cls b/force-di/test/classes/di_InjectorTest.cls index 35111ca..4f7f39d 100644 --- a/force-di/test/classes/di_InjectorTest.cls +++ b/force-di/test/classes/di_InjectorTest.cls @@ -22,20 +22,124 @@ * 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. -**/ - + **/ +/** + * Modifications: + * ============= + * B Anderson : Gettting the overall code-coverage > 75% + */ @IsTest private class di_InjectorTest { - + //TODO @IsTest private static void test(){ di_module module = new di_module(); di_Injector injector = new di_Injector(module); - + di_Injector.Org.Bindings.byName( Contact.class.getName() ) - .bySObject( Account.sObjectType ) - .replaceBindingWith( null ); - + .bySObject( Account.sObjectType ) + .replaceBindingWith( null ); + + } + @IsTest + private static void givenListOfModulesBindThenGetCount(){ + // Given + List modules = new List { + }; + final Integer expected = 0; + // When + di_Injector injector = new di_Injector(modules); + // Then + system.assertEquals(expected, injector.Bindings.get().size()); + + } + + @isTest + static void givenInstanceThenGetThatInstance(){ + // Given + di_module module=new di_module(); + di_Binding bobBinding = di_Binding.newInstance( + di_Binding.BindingType.Apex, + di_BindingTest.Bob.class.getName(), null, null, + di_BindingTest.Bob.class.getName(), null); + + module.getBindings().add(bobBinding); + + di_Injector injector = new di_Injector(module); + // When + Object result=injector.getInstance(di_BindingTest.Bob.class); + Object resultNoParams=injector.getInstance(di_BindingTest.Bob.class,(Object)null); + Object resultByName=injector.getInstance(di_BindingTest.Bob.class.getName()); + // Then + system.assertEquals(true, result instanceof di_BindingTest.Bob); + system.assertEquals(true, resultByName instanceof di_BindingTest.Bob); + system.assertEquals(true, resultNoParams instanceof di_BindingTest.Bob); } + + @isTest + static void givenInstanceNameThenGetException(){ + // Given + di_module module=new di_module(); + di_Injector injector = new di_Injector(module); + Boolean hasException = false; + // When + try { + injector.getInstance((String)null); + } catch (di_Injector.InjectorException excp) { + hasException=true; + } + // Then + system.assertEquals(true, hasException); + // When + hasException=false; + try { + injector.getInstance(''); + } catch (di_Injector.InjectorException excp) { + hasException=true; + } + // Then + system.assertEquals(true, hasException); + + } + + @isTest + static void givenNullSTypeParamterInGetInstanceThenThrowException() + { + // + // Given + di_Module module= new di_Module(); + di_Injector injector = new di_Injector(module); + Schema.SObjectType sType = null; + Boolean hasException=false; + // Then + + try { + injector.getInstance(di_Module.class,sType); + } catch (di_Injector.InjectorException excp) { + hasException=true; + } + // Then + system.assertEquals(true, hasException); + } + @isTest + static void givenNullParamterInGetInstanceThenThrowException() + { + // + // Given + di_Module module= new di_Module(); + di_Injector injector = new di_Injector(module); + Schema.SObjectType sType = Account.getSObjectType(); + Boolean hasException=false; + // Then + + try { + injector.getInstance(Account.class,sType,null); + } catch (di_Injector.InjectorException excp) { + hasException=true; + } + // Then + system.assertEquals(true, hasException); + } + } \ No newline at end of file diff --git a/force-di/test/classes/di_ModuleTest.cls b/force-di/test/classes/di_ModuleTest.cls index 7b10c29..0ee322a 100644 --- a/force-di/test/classes/di_ModuleTest.cls +++ b/force-di/test/classes/di_ModuleTest.cls @@ -22,8 +22,68 @@ * 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. -**/ + **/ + /** + * Modifications: + * -------------- + * B Anderson : Gettting the overall code-coverage > 75% + */ @IsTest private class di_ModuleTest { + + @isTest + static void givenBindingInModuleWhenSetTypeThenGetModule(){ + + // Given + di_Module module=new di_Module(); + di_Binding bobBinding = di_Binding.newInstance( + di_Binding.BindingType.Apex, + di_BindingTest.Bob.class.getName(), null, null, + di_BindingTest.Bob.class.getName(), null); + List bindings = new List { + bobBinding + }; + module.getBindings().add(bobBinding); + // Then + system.assertEquals(module, module.type(di_Binding.BindingType.Apex.name())); + // gt bindings + system.assertEquals(bindings, module.getBindings()); + } + + @isTest + static void givenBadBindingTypeThenGetModuleException(){ + + // Given + di_Module module=new di_Module(); + // Then + Boolean moduleExceptionThrown=false; + try { + module.type('not-valid'); + } catch(di_Module.ModuleException excp) { + moduleExceptionThrown=true; + + } + system.assertEquals(true,moduleExceptionThrown); + } + + @isTest + static void givenModuleWhenSettingValuesThenGet(){ + + // Given + di_Module module=new di_Module(); + // When + module.type(di_Binding.BindingType.Apex) + .data('test') + .sequence(1) + .bind(di_BindingTest.Bob.class); + di_Module mod= module.to(di_BindingTest.Bob.class); + + List bindings = module.getBindings(); + + // Then + system.assertEquals('test',(String)bindings[0].Data); + system.assertEquals('apex',(String)bindings[0].BindingTypeAsString.toLowerCase()); + system.assertEquals(1,bindings[0].bindingSequence); + } } diff --git a/force-di/test/classes/di_PlatformCacheTest.cls b/force-di/test/classes/di_PlatformCacheTest.cls new file mode 100644 index 0000000..1cce713 --- /dev/null +++ b/force-di/test/classes/di_PlatformCacheTest.cls @@ -0,0 +1,317 @@ +/** + * + * 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 copyright 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 Andrew Fawcett, 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 with sharing class di_PlatformCacheTest { + + static final String EXPECTED_PARTITION_NAME = 'diPartition'; + + @isTest + static void givenNoPlatformCacheInstanceThenCreate(){ + // Given/ When + di_PlatformCache cache = di_PlatformCache.getInstance(); + + //Then + System.assertEquals(true, cache == di_PlatformCache.instance); + + } + + @isTest + static void givenPlatformCacheConfigThenCreate(){ + // Given/ When + di_Configurations__c config = di_PlatformCache.getConfig(); + //Then + System.assertEquals(true, config!=null); + + } + + @isTest + static void givenStoringBindingIsTrueThenGet(){ + // Given/ When configuraiton is true + makeData(); + //Then + System.assertEquals(true,di_PlatformCache.isStoringBindingInPlatformCache()); + + } + + + @isTest + static void givenPartitionNameSetThenGetNonNull(){ + // Given/ When partition name is set + makeData(); + //Then + System.assertEquals(EXPECTED_PARTITION_NAME,di_PlatformCache.getPartitionName()); + + } + + @isTest + static void givenPartitionTTLSetThenGetSeconds(){ + // Given/ When partition name is set + di_PlatformCache cache = di_PlatformCache.getInstance(); + //Then + System.assertEquals(di_PlatformCache.NUM_OF_SECS_IN24HR,cache.getPartitionTTL()); + + } + + @isTest + static void givenNoDataInCachePartitionThenGetEmptyKeys(){ + // Given/ When partition name is set + makeData(); + di_PlatformCache cache = di_PlatformCache.getInstance(); + //Then + System.assertEquals(0,cache.getCacheKeyIndexMap().size()); + + } + @isTest + static void givenDataInCachePartitionIsNotEnabledThenGetEmptyKeys(){ + // Given when not storing ( ) + makeData(false); + di_PlatformCache cache = di_PlatformCache.getInstance(); + // create binding + di_Binding binding = di_Binding.newInstance( + di_Binding.BindingType.Apex, + di_BindingTest.Bob.class.getName(), null, null, di_BindingTest.Bob.class.getName(), null); + // When + cache.addBindingToPlatformCache(binding); + //Then + System.assertEquals(0,cache.getCacheKeyIndexMap().size()); + + } + + @isTest + static void givenDataInCachePartitionIsEnabledThenGetEmptyKeys(){ + // Given when storing ( ) + Integer expected=0; + makeData(true); + di_PlatformCache cache = di_PlatformCache.getInstance(); + // if there IS NO Partition created; let's not FAIL + Cache.OrgPartition orgPartition = di_PlatformCache.getPartition(); + // if we have cache informaiton, then we expect 1 + if ( orgPartition != null ) { + expected=1; + } + // create binding + di_Binding binding = di_Binding.newInstance( + di_Binding.BindingType.Apex, + di_BindingTest.Bob.class.getName(), null, null, di_BindingTest.Bob.class.getName(), null); + // When + cache.addBindingToPlatformCache(binding); + //Then + System.assertEquals(expected,cache.getCacheKeyIndexMap().size()); + + } + + @isTest + static void givenCachedBindingsClearThenGetEmpty(){ + // Given + makeData(true); + + // When + di_PlatformCache.clearCachedBindings(); + Set keys = di_PlatformCache.getPartitionKeys(); + //Then + System.assertEquals(true,keys == null || keys.size()==0); + + } + + @isTest + static void givenInvalidDeveloperNameThenGetEmptyKeys(){ + // Given + makeData(true); + di_PlatformCache cache = di_PlatformCache.getInstance(); + // when + list binding = cache.retrieveBindings(null,Account.sObjectType); + //Then + System.assertEquals(0,binding.size()); + } + @isTest + static void givenInvalidSObjectTypeThenGetEmptyKeys(){ + // Given + makeData(true); + di_PlatformCache cache = di_PlatformCache.getInstance(); + // when + list binding = cache.retrieveBindings('value',null); + //Then + System.assertEquals(0,binding.size()); + } + // + @isTest + static void givenCacheMapAddedThenGetKeys(){ + // Given + di_PlatformCache cache = di_PlatformCache.getInstance(); + // When + Cache.OrgPartition orgPartition = di_PlatformCache.getPartition(); + //Then + System.assertEquals(orgPartition != null,cache.pushCacheKeyIndexMapToCache()); + } + @isTest + static void givenLogMethodThenGetKeys(){ + // Given + di_PlatformCache.DEBUGGING = true; + // When + //Then + System.assertEquals(true,di_PlatformCache.log('test')); + System.assertEquals(true,di_PlatformCache.log(new NullPointerException())); + } + + @IsTest + static void givenValidBindingThenAddBinding(){ + // Given + di_PlatformCache cache = di_PlatformCache.getInstance(); + // create binding + di_Binding binding = di_Binding.newInstance( + di_Binding.BindingType.Apex, + di_BindingTest.Bob.class.getName(), null, null, di_BindingTest.Bob.class.getName(), null); + String workingDeveloperName = binding.developerName.toLowerCase().trim(); + + // When + cache.addBindingToKeyIndex(binding); + // Then + system.assertEquals(1, cache.getCacheKeyIndexMap().size()); + system.assertNotEquals(null,cache.getCacheKeyIndexMap().get(workingDeveloperName)); + } + + // + @IsTest + static void givenValidTSTypeAndNameThenHash(){ + // + // Given + di_PlatformCache cache = di_PlatformCache.getInstance(); + // When + String hash= cache.constructKeyName(Account.sObjectType,'test'); + // Then + system.assertEquals(true, hash != null); + + } + // + @IsTest + static void givenKeyIndexNameThenGetKey(){ + // + // Given + di_PlatformCache cache = di_PlatformCache.getInstance(); + // When + // Then + system.assertEquals(di_PlatformCache.BINDING_KEY, cache.getKeyIndexName()); + + } + // + @IsTest + static void givenValidSTypeAndNameThenHash(){ + // + // Given + di_PlatformCache cache = di_PlatformCache.getInstance(); + // When + String hash= cache.constructKeyName(Account.sObjectType,'test'); + // Then + system.assertEquals(true, hash != null); + + } + + // + @IsTest + static void givenDevNameAndSTypeThenGetHashAndKey(){ + // + // Given + di_PlatformCache cache = di_PlatformCache.getInstance(); + // When + String key= cache.getKeyName('test',Account.sObjectType), + hash= cache.constructKeyName(Account.sObjectType,'test'); + // Then + system.assertEquals(hash, key); + + } + + @isTest + static void givenReadOnlyAccessThenGetInstance(){ + // Given + User ruser = di_PlatformCacheTest.setROTestUser(false,false,false,false); + System.runAs(ruser) { + // Then + di_Configurations__c config = di_PlatformCache.getConfig(); + system.assertEquals(true, config!=null); + system.assertEquals(false, config.UsePlatformCacheToStoreBindings__c); + system.assertEquals(null, config.OrgCachePartitionName__c); + } + } + + @isTest + static void givenANewConfigSettingThenGetThatInstance(){ + // Given + User ruser = di_PlatformCacheTest.setROTestUser(false,false,false,false); + final String PARTITION = 'test'; + di_Configurations__c usrConfig = new di_Configurations__c(); + usrConfig.SetupOwnerId = ruser.Id; + usrConfig.UsePlatformCacheToStoreBindings__c = true; + usrConfig.OrgCachePartitionName__c = PARTITION; + insert usrConfig; + + System.runAs(ruser) { + // Then + di_Configurations__c config = di_PlatformCache.getConfig(); + system.assertEquals(true, config!=null); + system.assertEquals(true, config.UsePlatformCacheToStoreBindings__c); + system.assertEquals(PARTITION, config.OrgCachePartitionName__c); + } + } + // + /////////////////////////////////////////////////////////////////////////////// + // Private Helper + /////////////////////////////////////////////////////////////////////////////// + + + static void makeData(){ + makeData(true); + } + + static void makeData(Boolean isStoring){ + di_Configurations__c setting = new di_Configurations__c(SetupOwnerId=Userinfo.getUserId()); + + setting.OrgCachePartitionName__c = EXPECTED_PARTITION_NAME; + setting.UsePlatformCacheToStoreBindings__c = isStoring; + insert setting; + } + + /** + * readonly user + */ + @TestVisible + private static User setROTestUser(Boolean read, Boolean create, Boolean edit, Boolean remove){ + Profile prof = [SELECT Id FROM Profile WHERE Name='Read Only']; + + User newUser = new User(Alias = 'readonly', + Email='standarduser@mytest.com', + EmailEncodingKey='UTF-8', + LastName='TestingReadOnly', + LanguageLocaleKey='en_US', + LocaleSidKey='en_US', + ProfileId = prof.Id, + TimeZoneSidKey='America/Los_Angeles', + UserName='readonly@mytest.com'); + + insert newUser; + + return newUser; + }// end of setTestUser + + +} diff --git a/force-di/test/classes/di_PlatformCacheTest.cls-meta.xml b/force-di/test/classes/di_PlatformCacheTest.cls-meta.xml new file mode 100644 index 0000000..db9bf8c --- /dev/null +++ b/force-di/test/classes/di_PlatformCacheTest.cls-meta.xml @@ -0,0 +1,5 @@ + + + 48.0 + Active + diff --git a/force-di/test/testSuites/force_di_teststuite.testSuite-meta.xml b/force-di/test/testSuites/force_di_teststuite.testSuite-meta.xml new file mode 100644 index 0000000..ff24bb8 --- /dev/null +++ b/force-di/test/testSuites/force_di_teststuite.testSuite-meta.xml @@ -0,0 +1,12 @@ + + + di_BindingParamTest + di_BindingTest + di_FlowTest + di_InjectorCMPFlowProxyControllerTest + di_InjectorComponentControllerTest + di_InjectorControllerTest + di_InjectorTest + di_ModuleTest + di_PlatformCacheTest +