]> git.codecow.com Git - flowpex.git/commitdiff
Add System.Blob.toString()
authorChris Duncan <chris@flowpex.dev>
Mon, 24 Jun 2024 06:38:14 +0000 (23:38 -0700)
committerChris Duncan <chris@flowpex.dev>
Mon, 24 Jun 2024 06:38:14 +0000 (23:38 -0700)
src/System/Blob/toString/System_Blob_toString.cls [new file with mode: 0644]
src/System/Blob/toString/System_Blob_toString.cls-meta.xml [new file with mode: 0644]
src/System/Blob/toString/System_Blob_toString_TEST.cls [new file with mode: 0644]
src/System/Blob/toString/System_Blob_toString_TEST.cls-meta.xml [new file with mode: 0644]

diff --git a/src/System/Blob/toString/System_Blob_toString.cls b/src/System/Blob/toString/System_Blob_toString.cls
new file mode 100644 (file)
index 0000000..3d03dd8
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Chris Duncan <chris@flowpex.dev>
+ * 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<Response> System_Blob_toString (List<Request> requests) {
+        List<Response> responses = new List<Response>();
+        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 (file)
index 0000000..ff0b65f
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+SPDX-FileCopyrightText: 2024 Chris Duncan <chris@flowpex.dev>
+SPDX-License-Identifier: GPL-3.0-or-later
+-->
+<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
+    <apiVersion>61.0</apiVersion>
+    <status>Active</status>
+</ApexClass>
\ 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 (file)
index 0000000..95e65c7
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Chris Duncan <chris@flowpex.dev>
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+@isTest
+private class System_Blob_toString_TEST {
+
+    @isTest
+    static void testNoArgs () {
+        List<System_Blob_toString.Request> requests = new List<System_Blob_toString.Request>();
+
+        Test.startTest();
+        List<System_Blob_toString.Response> responses = System_Blob_toString.System_Blob_toString(requests);
+        Test.stopTest();
+
+        Assert.areEqual(0, responses.size());
+    }
+
+    @isTest
+    static void testEmptyRequest () {
+        List<System_Blob_toString.Request> requests = new List<System_Blob_toString.Request>();
+        System_Blob_toString.Request req = new System_Blob_toString.Request();
+        requests.add(req);
+
+        Test.startTest();
+        List<System_Blob_toString.Response> 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<System_Blob_toString.Request> requests = new List<System_Blob_toString.Request>();
+        System_Blob_toString.Request req = new System_Blob_toString.Request(Blob.valueOf(''));
+        requests.add(req);
+
+        Test.startTest();
+        List<System_Blob_toString.Response> 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<Blob> blobList = new List<Blob>();
+        for (Integer i = 0; i < 10; i++) {
+            String s = i.toString();
+            blobList.add(Blob.valueOf(s));
+        }
+
+        Test.startTest();
+        List<System_Blob_toString.Request> requests = new List<System_Blob_toString.Request>();
+        for (Blob b : blobList) {
+            System_Blob_toString.Request req = new System_Blob_toString.Request(b);
+            requests.add(req);
+        }
+        List<System_Blob_toString.Response> 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 (file)
index 0000000..ff0b65f
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+SPDX-FileCopyrightText: 2024 Chris Duncan <chris@flowpex.dev>
+SPDX-License-Identifier: GPL-3.0-or-later
+-->
+<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
+    <apiVersion>61.0</apiVersion>
+    <status>Active</status>
+</ApexClass>
\ No newline at end of file