From afda4af6e0667f19ad9d99f4be0807cb752dd2a1 Mon Sep 17 00:00:00 2001 From: Puneet Khanduri Date: Wed, 2 Nov 2022 17:43:28 +0530 Subject: [PATCH] --wip-- [skip ci] --- .../features/overrides/editor/CodeEditor.tsx | 2 +- .../functional/algebra/BijectionTest.java | 15 +++++++++++++++ .../interpreter/SimpleTransformerTest.java | 19 +++++++++++++++++++ .../{TxTest.java => TransformerTest.java} | 4 ++-- .../proxy/ReactorHttpDifferenceProxyTest.java | 14 ++++++++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 src/test/scala/ai/diffy/functional/algebra/BijectionTest.java create mode 100644 src/test/scala/ai/diffy/interpreter/SimpleTransformerTest.java rename src/test/scala/ai/diffy/interpreter/{TxTest.java => TransformerTest.java} (94%) create mode 100644 src/test/scala/ai/diffy/proxy/ReactorHttpDifferenceProxyTest.java diff --git a/frontend/src/features/overrides/editor/CodeEditor.tsx b/frontend/src/features/overrides/editor/CodeEditor.tsx index e9ac054..e2db479 100644 --- a/frontend/src/features/overrides/editor/CodeEditor.tsx +++ b/frontend/src/features/overrides/editor/CodeEditor.tsx @@ -29,7 +29,7 @@ export default function CodeEditor() { color="inherit" aria-label="save" onClick={ - ()=>selectedEdge && updateOverride({injectionPoint: selectedEdge, transformationJs: currentTxJs}) + ()=>selectedEdge && updateOverride({injectionPoint: selectedEdge, transformationJs: currentTxJs || '(request)=>(request)'}) .then(() => { dispatch(setTransformationJs(undefined)); dispatch(openAlert(`Save success. Transformation will be applied to ${selectedEdge}.`)); diff --git a/src/test/scala/ai/diffy/functional/algebra/BijectionTest.java b/src/test/scala/ai/diffy/functional/algebra/BijectionTest.java new file mode 100644 index 0000000..e8275ba --- /dev/null +++ b/src/test/scala/ai/diffy/functional/algebra/BijectionTest.java @@ -0,0 +1,15 @@ +package ai.diffy.functional.algebra; + +public class BijectionTest { + public static void main(String[] args) { + Bijection identity = Bijection.of(String::toUpperCase, String::toLowerCase); + try { + identity.apply("s"); + identity.unapply("s"); + String x = identity.wrap(str -> str+str).apply("lower"); + System.out.println(x); + } catch (Throwable e) { + throw new RuntimeException(e); + } + } +} \ No newline at end of file diff --git a/src/test/scala/ai/diffy/interpreter/SimpleTransformerTest.java b/src/test/scala/ai/diffy/interpreter/SimpleTransformerTest.java new file mode 100644 index 0000000..7914d93 --- /dev/null +++ b/src/test/scala/ai/diffy/interpreter/SimpleTransformerTest.java @@ -0,0 +1,19 @@ +package ai.diffy.interpreter; + +public class SimpleTransformerTest { + public static class Name{ + public String first; + public String last; + } + public static void main(String[] args) { + try { + Name name = new Name(); + name.first = "Puneet"; + name.last = "Khanduri"; + Transformer transformer = new Transformer<>(Name.class, "(name)=>{console.log(JSON.stringify(name,null,4)); return name;}"); + transformer.apply(name); + } catch (Throwable e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/test/scala/ai/diffy/interpreter/TxTest.java b/src/test/scala/ai/diffy/interpreter/TransformerTest.java similarity index 94% rename from src/test/scala/ai/diffy/interpreter/TxTest.java rename to src/test/scala/ai/diffy/interpreter/TransformerTest.java index e48095e..8d0321c 100644 --- a/src/test/scala/ai/diffy/interpreter/TxTest.java +++ b/src/test/scala/ai/diffy/interpreter/TransformerTest.java @@ -9,7 +9,7 @@ import java.util.HashMap; import java.util.Map; -public class TxTest { +public class TransformerTest { public static void main(String [] args) { try { Source tx = Source.newBuilder("js", new File("src/test/scala/ai/diffy/interpreter/transform.js")).build(); @@ -22,7 +22,7 @@ public static void main(String [] args) { System.out.println("All done!"); System.out.println("\n\nHere's the original:\n"+request); System.out.println("\n\nHere's the transformed:\n"+transformed); - } catch (Exception e) { + } catch (Throwable e) { throw new RuntimeException(e); } } diff --git a/src/test/scala/ai/diffy/proxy/ReactorHttpDifferenceProxyTest.java b/src/test/scala/ai/diffy/proxy/ReactorHttpDifferenceProxyTest.java new file mode 100644 index 0000000..8ba5548 --- /dev/null +++ b/src/test/scala/ai/diffy/proxy/ReactorHttpDifferenceProxyTest.java @@ -0,0 +1,14 @@ +package ai.diffy.proxy; + +import reactor.core.publisher.Mono; + +import java.util.concurrent.CompletableFuture; + +public class ReactorHttpDifferenceProxyTest { + public static void main(String[] args) { + Mono.fromFuture(CompletableFuture.failedFuture(new RuntimeException())) + .doOnError(t -> System.out.println("error")) + .block() + ; + } +}