Skip to content

Commit

Permalink
refactor properties
Browse files Browse the repository at this point in the history
  • Loading branch information
aheber committed Jul 4, 2023
1 parent 51a19ae commit 98c14c8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 23 deletions.
30 changes: 17 additions & 13 deletions dlrs/main/classes/RollupController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
* Handles the Manage Trigger and Calculate Custom Buttons
**/
public with sharing class RollupController {
public static String DEF_API_VERSION = '58.0';
@TestVisible
private static String FALLBACK_COMPONENT_API_VERSION = '58.0';

public String ZipData { get; set; }

Expand Down Expand Up @@ -59,10 +60,12 @@ public with sharing class RollupController {
public ApexClass RollupParentTriggerTest { get; private set; }

public Integer deployCount;
public String apiVersion;

public Boolean MetadataConnectionError { get; set; }

@TestVisible
private String componentApiVersion;

public RollupController(ApexPages.StandardController standardController) {
// Query Lookup Rollup Summary record
this(
Expand Down Expand Up @@ -101,7 +104,7 @@ public with sharing class RollupController {
return '<?xml version="1.0" encoding="UTF-8"?>' +
'<Package xmlns="http://soap.sforce.com/2006/04/metadata">' +
'<version>' +
apiVersion +
componentApiVersion +
'</version>' +
'</Package>';
else
Expand Down Expand Up @@ -135,7 +138,7 @@ public with sharing class RollupController {
'</types>')
: '') +
'<version>' +
apiVersion +
componentApiVersion +
'</version>' +
'</Package>';
}
Expand Down Expand Up @@ -170,7 +173,7 @@ public with sharing class RollupController {
'</types>')
: '') +
'<version>' +
apiVersion +
componentApiVersion +
'</version>' +
'</Package>';
}
Expand All @@ -183,7 +186,7 @@ public with sharing class RollupController {
return '<?xml version="1.0" encoding="UTF-8"?>' +
'<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">' +
'<apiVersion>' +
apiVersion +
componentApiVersion +
'</apiVersion>' +
'<status>Active</status>' +
'</ApexClass>';
Expand Down Expand Up @@ -228,7 +231,7 @@ public with sharing class RollupController {
return '<?xml version="1.0" encoding="UTF-8"?>' +
'<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">' +
'<apiVersion>' +
apiVersion +
componentApiVersion +
'</apiVersion>' +
'<status>Active</status>' +
'</ApexTrigger>';
Expand Down Expand Up @@ -269,7 +272,7 @@ public with sharing class RollupController {
return '<?xml version="1.0" encoding="UTF-8"?>' +
'<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">' +
'<apiVersion>' +
apiVersion +
componentApiVersion +
'</apiVersion>' +
'<status>Active</status>' +
'</ApexClass>';
Expand Down Expand Up @@ -316,7 +319,7 @@ public with sharing class RollupController {
return '<?xml version="1.0" encoding="UTF-8"?>' +
'<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">' +
'<apiVersion>' +
apiVersion +
componentApiVersion +
'</apiVersion>' +
'<status>Active</status>' +
'</ApexTrigger>';
Expand Down Expand Up @@ -493,7 +496,7 @@ public with sharing class RollupController {
);
return;
}
apiVersion = getNewestApiVersion();
componentApiVersion = getNewestApiVersion();

// Already deployed?
Set<String> triggerNames = new Set<String>{ RollupTriggerName };
Expand Down Expand Up @@ -602,11 +605,11 @@ public with sharing class RollupController {
Http http = new Http();
HTTPResponse res = http.send(req);
if (res.getStatusCode() != 200) {
return DEF_API_VERSION;
return FALLBACK_COMPONENT_API_VERSION;
}
String body = res.getBody();
List<Object> data = (List<Object>) JSON.deserializeUntyped(body);
Decimal maxVersion = Decimal.valueOf(DEF_API_VERSION);
Decimal maxVersion = Decimal.valueOf(FALLBACK_COMPONENT_API_VERSION);
for (Object obj : data) {
Map<String, Object> apiV = (Map<String, Object>) obj;
Decimal newV = Decimal.valueOf((String) apiV.get('version'));
Expand All @@ -616,7 +619,8 @@ public with sharing class RollupController {
}
return String.valueOf(maxVersion);
} catch (Exception e) {
return DEF_API_VERSION;
System.debug(e);
return FALLBACK_COMPONENT_API_VERSION;
}
}

Expand Down
26 changes: 16 additions & 10 deletions dlrs/main/classes/RollupControllerTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private class RollupControllerTest {
'<?xml version="1.0" encoding="UTF-8"?>' +
'<Package xmlns="http://soap.sforce.com/2006/04/metadata">' +
'<version>' +
controller.apiVersion +
controller.componentApiVersion +
'</version>' +
'</Package>',
controller.getPackageXml()
Expand All @@ -116,7 +116,7 @@ private class RollupControllerTest {
'<name>ApexClass</name>' +
'</types>' +
'<version>' +
controller.apiVersion +
controller.componentApiVersion +
'</version>' +
'</Package>',
controller.getDestructiveChangesXml()
Expand All @@ -125,7 +125,7 @@ private class RollupControllerTest {
'<?xml version="1.0" encoding="UTF-8"?>' +
'<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">' +
'<apiVersion>' +
controller.apiVersion +
controller.componentApiVersion +
'</apiVersion>' +
'<status>Active</status>' +
'</ApexTrigger>',
Expand All @@ -135,7 +135,7 @@ private class RollupControllerTest {
'<?xml version="1.0" encoding="UTF-8"?>' +
'<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">' +
'<apiVersion>' +
controller.apiVersion +
controller.componentApiVersion +
'</apiVersion>' +
'<status>Active</status>' +
'</ApexClass>',
Expand Down Expand Up @@ -262,7 +262,7 @@ private class RollupControllerTest {
'<name>ApexClass</name>' +
'</types>' +
'<version>' +
controller.apiVersion +
controller.componentApiVersion +
'</version>' +
'</Package>',
controller.getPackageXml()
Expand All @@ -271,7 +271,7 @@ private class RollupControllerTest {
'<?xml version="1.0" encoding="UTF-8"?>' +
'<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">' +
'<apiVersion>' +
controller.apiVersion +
controller.componentApiVersion +
'</apiVersion>' +
'<status>Active</status>' +
'</ApexTrigger>',
Expand All @@ -281,7 +281,7 @@ private class RollupControllerTest {
'<?xml version="1.0" encoding="UTF-8"?>' +
'<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">' +
'<apiVersion>' +
controller.apiVersion +
controller.componentApiVersion +
'</apiVersion>' +
'<status>Active</status>' +
'</ApexClass>',
Expand Down Expand Up @@ -460,7 +460,7 @@ private class RollupControllerTest {
new RollupSummary(rollupSummary)
);
Test.stopTest();
Assert.areEqual('97.0', controller.apiVersion);
Assert.areEqual('97.0', controller.componentApiVersion);
}
}

Expand Down Expand Up @@ -492,7 +492,10 @@ private class RollupControllerTest {
new RollupSummary(rollupSummary)
);
Test.stopTest();
Assert.areEqual(RollupController.DEF_API_VERSION, controller.apiVersion);
Assert.areEqual(
RollupController.FALLBACK_COMPONENT_API_VERSION,
controller.componentApiVersion
);
}
}

Expand Down Expand Up @@ -524,7 +527,10 @@ private class RollupControllerTest {
new RollupSummary(rollupSummary)
);
Test.stopTest();
Assert.areEqual(RollupController.DEF_API_VERSION, controller.apiVersion);
Assert.areEqual(
RollupController.FALLBACK_COMPONENT_API_VERSION,
controller.componentApiVersion
);
}
}

Expand Down

0 comments on commit 98c14c8

Please sign in to comment.