From: Chris Duncan Date: Mon, 24 Jun 2024 06:38:14 +0000 (-0700) Subject: Add System.Blob.toString() X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=dd44216cb62b5e7003fd07a55859246163668450;p=flowpex.git Add System.Blob.toString() --- diff --git a/src/System/Blob/toString/System_Blob_toString.cls b/src/System/Blob/toString/System_Blob_toString.cls new file mode 100644 index 0000000..3d03dd8 --- /dev/null +++ b/src/System/Blob/toString/System_Blob_toString.cls @@ -0,0 +1,38 @@ +/* + * SPDX-FileCopyrightText: 2024 Chris Duncan + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +global class System_Blob_toString { + + @InvocableMethod(label='System.Blob.toString()' category='Flowpex System' iconName='slds:standard:text' description='Casts the Blob into a String.') + + public static List System_Blob_toString (List requests) { + List responses = new List(); + for (Request req : requests) { + Response res = new Response(); + try { + res.stringOfBlob = req.blobToString.toString(); + } catch (Exception e) { + System.debug(e); + } + responses.add(res); + } + return responses; + } + + public class Request { + @InvocableVariable(required='true' label='Blob' description='') + public Blob blobToString; + + public Request () {} + public Request (Blob b) { + this.blobToString = b; + } + } + + public class Response { + @InvocableVariable(label='String' description='') + public String stringOfBlob; + } +} \ No newline at end of file diff --git a/src/System/Blob/toString/System_Blob_toString.cls-meta.xml b/src/System/Blob/toString/System_Blob_toString.cls-meta.xml new file mode 100644 index 0000000..ff0b65f --- /dev/null +++ b/src/System/Blob/toString/System_Blob_toString.cls-meta.xml @@ -0,0 +1,9 @@ + + + + 61.0 + Active + \ No newline at end of file diff --git a/src/System/Blob/toString/System_Blob_toString_TEST.cls b/src/System/Blob/toString/System_Blob_toString_TEST.cls new file mode 100644 index 0000000..95e65c7 --- /dev/null +++ b/src/System/Blob/toString/System_Blob_toString_TEST.cls @@ -0,0 +1,73 @@ +/* + * SPDX-FileCopyrightText: 2024 Chris Duncan + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +@isTest +private class System_Blob_toString_TEST { + + @isTest + static void testNoArgs () { + List requests = new List(); + + Test.startTest(); + List responses = System_Blob_toString.System_Blob_toString(requests); + Test.stopTest(); + + Assert.areEqual(0, responses.size()); + } + + @isTest + static void testEmptyRequest () { + List requests = new List(); + System_Blob_toString.Request req = new System_Blob_toString.Request(); + requests.add(req); + + Test.startTest(); + List responses = System_Blob_toString.System_Blob_toString(requests); + Test.stopTest(); + + Assert.areEqual(1, responses.size()); + System_Blob_toString.Response res = responses[0]; + Assert.areEqual(null, res.stringOfBlob); + } + + @isTest + static void testBlankArg () { + List requests = new List(); + System_Blob_toString.Request req = new System_Blob_toString.Request(Blob.valueOf('')); + requests.add(req); + + Test.startTest(); + List responses = System_Blob_toString.System_Blob_toString(requests); + Test.stopTest(); + + Assert.areEqual(1, responses.size()); + System_Blob_toString.Response res = responses[0]; + Assert.areEqual('', res.stringOfBlob); + } + + @isTest + static void testManyArgs () { + List blobList = new List(); + for (Integer i = 0; i < 10; i++) { + String s = i.toString(); + blobList.add(Blob.valueOf(s)); + } + + Test.startTest(); + List requests = new List(); + for (Blob b : blobList) { + System_Blob_toString.Request req = new System_Blob_toString.Request(b); + requests.add(req); + } + List responses = System_Blob_toString.System_Blob_toString(requests); + Test.stopTest(); + + Assert.areEqual(10, responses.size()); + for (Integer i = 0; i < 10; i++) { + System_Blob_toString.Response res = responses[i]; + Assert.areEqual(i.toString(), res.stringOfBlob); + } + } +} \ No newline at end of file diff --git a/src/System/Blob/toString/System_Blob_toString_TEST.cls-meta.xml b/src/System/Blob/toString/System_Blob_toString_TEST.cls-meta.xml new file mode 100644 index 0000000..ff0b65f --- /dev/null +++ b/src/System/Blob/toString/System_Blob_toString_TEST.cls-meta.xml @@ -0,0 +1,9 @@ + + + + 61.0 + Active + \ No newline at end of file