diff --git a/.gitignore b/.gitignore index 0aaf4aa2..0a98f47d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ /Activities/Java/Invoke/out /Activities/Java/Invoke/.idea /Activities/Java/Invoke/.idea/artifacts +/Activities/Java/TestProgram/.idea +/Activities/Java/TestProgram/out/production/TestProgram/uipath/java/test diff --git a/Activities/Java/TestProgram/artifacts/TestProgram.jar b/Activities/Java/TestProgram/artifacts/TestProgram.jar index cc287097..dc149e98 100644 Binary files a/Activities/Java/TestProgram/artifacts/TestProgram.jar and b/Activities/Java/TestProgram/artifacts/TestProgram.jar differ diff --git a/Activities/Java/TestProgram/src/uipath/java/test/Cons.java b/Activities/Java/TestProgram/src/uipath/java/test/Cons.java new file mode 100644 index 00000000..8d771afc --- /dev/null +++ b/Activities/Java/TestProgram/src/uipath/java/test/Cons.java @@ -0,0 +1,17 @@ +package uipath.java.test; + +public class Cons { + String[] arr; + + public Cons(String[] cons) {} + + public Cons(String cons) {} + + public Cons(int[] cons) {} + + public Cons(float[] cons) {} + + public static void Write(String[] args) { + System.out.println(args.length); + } +} diff --git a/Activities/Java/TestProgram/src/uipath/java/test/GenericMethods.java b/Activities/Java/TestProgram/src/uipath/java/test/GenericMethods.java new file mode 100644 index 00000000..6d679ca5 --- /dev/null +++ b/Activities/Java/TestProgram/src/uipath/java/test/GenericMethods.java @@ -0,0 +1,96 @@ +package uipath.java.test; + +public class GenericMethods { + public String message; + String[] arr; + + public GenericMethods() { + System.out.println("Constructor without parameters"); + } + + public GenericMethods(String[] cons) { + System.out.println("Constructor with String[]"); + } + + public GenericMethods(String p1, String p2) { + System.out.println("Constructor with String and String"); + } + + public GenericMethods(String cons) { + System.out.println("Constructor with String"); + } + + public GenericMethods(int[] cons) { + System.out.println("Constructor with int[]"); + } + + public static void Write(String[] args) { + System.out.println("Static method with String[]"); + if (args!=null) { + System.out.println(args.length); + } + } + + public static void Write(String args) { + System.out.println("Static method with String"); + System.out.println(args); + } + + public static void Write(int args) { + System.out.println("Static method with int"); + System.out.println(args); + } + + public static void Write(boolean args) { + System.out.println("Static method with boolean"); + System.out.println(args); + } + + public static void Write(float args) { + System.out.println("Static method with float"); + System.out.println(args); + } + + public void WriteObj(String[] args) { + System.out.println("Instance method with String[]"); + System.out.println(args); + } + + public void WriteObj(String args) { + System.out.println("Instance method with String"); + System.out.println(args); + } + + public void WriteObj(float args) { + System.out.println("Instance method with float"); + System.out.println(args); + } + + public T GenericsExtObj(Object a) { + message = "Generic method with Object " + a; + return (T) ("Generic method with Object " + a); + } + + public Object GenericsExtString(T a) { + message = "Generic method " + a; + return "Generic method: " + a; + } + + public void GenericsS(String a) { + message = "Method that is named Generics " + a; + System.out.println("Method that is named Generics"); + } + + public T GenericsR(T a) { + message = "Generic method with return " + a; + System.out.println("Generic method with return"); + System.out.println(a); + return a; + } + + public void finalize() throws Throwable{ + System.out.println("Object is destroyed by the Garbage Collector"); + } + + public static void foo(){} +} diff --git a/Activities/Java/TestProgram/src/uipath/java/test/GenericsType.java b/Activities/Java/TestProgram/src/uipath/java/test/GenericsType.java new file mode 100644 index 00000000..47916158 --- /dev/null +++ b/Activities/Java/TestProgram/src/uipath/java/test/GenericsType.java @@ -0,0 +1,13 @@ +package uipath.java.test; + +public class GenericsType { + private T t; + + public T get() { + return this.t; + } + + public void set(T t1) { + this.t = t1; + } +} diff --git a/Activities/Java/UiPath.Java.Test/JavaTestsGenericMethods.cs b/Activities/Java/UiPath.Java.Test/JavaTestsGenericMethods.cs new file mode 100644 index 00000000..da1b3f31 --- /dev/null +++ b/Activities/Java/UiPath.Java.Test/JavaTestsGenericMethods.cs @@ -0,0 +1,410 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using System.IO; +using System.Threading; +using UiPath.Excel.Activities.Tests.Utils; +using UiPath.Java.Test.Fixtures; +using UiPath.TestUtils; +using Xunit; +using System.Diagnostics; + +namespace UiPath.Java.Test +{ + + [Trait(TestCategories.Category, JavaTestBaseFixture.Category)] + [TestCaseOrderer("UiPath.Java.Test.Utils.PriorityOrderer", "UiPath.Java.Test")] + + + public class JavaTestsGenericMethods : IClassFixture + { + private readonly JavaInvoker _invoker; + private readonly CancellationToken _ct; + + public JavaTestsGenericMethods(JavaTestDerivedFixture fixture) + { + _invoker = fixture.Invoker; + _ct = fixture.Ct; + } + + [Fact] + [TestPriority(0)] + public async Task GenericMethodsNoParams() + { + + await _invoker.LoadJar(Path.Combine(JavaTestBaseFixture.JavaFilesPath, "TestProgram.Jar"), _ct); + var javaObject = await _invoker.InvokeConstructor( + "uipath.java.test.GenericMethods", + null, + null, + _ct + ); + Assert.Contains("uipath.java.test.GenericMethods", javaObject.Convert()); + + } + + [Fact] + [TestPriority(0)] + public async Task GenericMethodsOneString() + { + await _invoker.LoadJar(Path.Combine(JavaTestBaseFixture.JavaFilesPath, "TestProgram.Jar"), _ct); + var javaObject = await _invoker.InvokeConstructor( + "uipath.java.test.GenericMethods", + new List { "String Test" }, + new List { typeof(string) }, + _ct + ); + Assert.Contains("uipath.java.test.GenericMethods", javaObject.Convert()); + } + + [Fact] + [TestPriority(0)] + public async Task GenericMethodsTwoStrings() + { + await _invoker.LoadJar(Path.Combine(JavaTestBaseFixture.JavaFilesPath, "TestProgram.Jar"), _ct); + var javaObject = await _invoker.InvokeConstructor( + "uipath.java.test.GenericMethods", + new List { "string1", "string2" }, + null, + _ct + ); + Assert.Contains("uipath.java.test.GenericMethods", javaObject.Convert()); + } + + [Fact] + [TestPriority(0)] + public async Task GenericMethodsIntArray() + { + int[] intArray = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + await _invoker.LoadJar(Path.Combine(JavaTestBaseFixture.JavaFilesPath, "TestProgram.Jar"), _ct); + var javaObject = await _invoker.InvokeConstructor( + "uipath.java.test.GenericMethods", + new List { intArray }, + null, + _ct + ); + Assert.Contains("uipath.java.test.GenericMethods", javaObject.Convert()); + } + + [Fact] + [TestPriority(0)] + public async Task GenericMethodsStringArray() + { + String[] Strings = { "S1", "S22", "3.3d", "4.4f", "5", "null" }; + await _invoker.LoadJar(Path.Combine(JavaTestBaseFixture.JavaFilesPath, "TestProgram.Jar"), _ct); + var javaObject = await _invoker.InvokeConstructor( + "uipath.java.test.GenericMethods", + new List { Strings }, + new List { typeof(string) }, + _ct + ); + Assert.Contains("uipath.java.test.GenericMethods", javaObject.Convert()); + } + + [Fact] + [TestPriority(1)] + public async Task WriteFloat() + { + await _invoker.LoadJar(Path.Combine(JavaTestBaseFixture.JavaFilesPath, "TestProgram.Jar"), _ct); + var JOWriteFloat = await _invoker.InvokeMethod( + "Write", + "uipath.java.test.GenericMethods", + null, + new List { 1.2f }, + null, + _ct + ); + } + + [Fact] + [TestPriority(1)] + public async Task WriteArrayString() + { + + String[] Strings = { "S1", "S22", "3.3d", "4.4f", "5", "null" }; + await _invoker.LoadJar(System.IO.Path.Combine(JavaTestBaseFixture.JavaFilesPath, "TestProgram.Jar"), _ct); + var javaObject = await _invoker.InvokeConstructor( + "uipath.java.test.GenericMethods", + null, + null, + _ct); + + await _invoker.LoadJar(Path.Combine(JavaTestBaseFixture.JavaFilesPath, "TestProgram.Jar"), _ct); + var JOWrite = await _invoker.InvokeMethod( + "Write", + null, + javaObject, + new List { Strings }, + null, + _ct + ); + } + + [Fact] + [TestPriority(1)] + public async Task WriteString() + { + + await _invoker.LoadJar(System.IO.Path.Combine(JavaTestBaseFixture.JavaFilesPath, "TestProgram.Jar"), _ct); + var javaObject = await _invoker.InvokeConstructor( + "uipath.java.test.GenericMethods", + null, + null, + _ct); + + await _invoker.LoadJar(Path.Combine(JavaTestBaseFixture.JavaFilesPath, "TestProgram.Jar"), _ct); + var JOWrite = await _invoker.InvokeMethod( + "Write", + null, + javaObject, + new List { "String one" }, + null, + _ct + ); + } + + [Fact] + [TestPriority(2)] + public async Task WriteObj_String() + { + var javaObject = await _invoker.InvokeConstructor( + "uipath.java.test.GenericMethods", + null, + null, + _ct + ); + Assert.Contains("uipath.java.test.GenericMethods", javaObject.Convert()); + + await _invoker.LoadJar(System.IO.Path.Combine(JavaTestBaseFixture.JavaFilesPath, "TestProgram.Jar"), _ct); + var javaObject2 = await _invoker.InvokeMethod( + "WriteObj", + null, + javaObject, + new List { "String name" }, + new List { typeof(string) }, + _ct + ); + + } + + [Fact] + [TestPriority(2)] + public async Task WriteObj_StringArray() + { + String[] Strings = { "S1", "S22", "3.3d", "4.4f", "5", "null" }; + var javaObject = await _invoker.InvokeConstructor( + "uipath.java.test.GenericMethods", + null, + null, + _ct + ); + Assert.Contains("uipath.java.test.GenericMethods", javaObject.Convert()); + + await _invoker.LoadJar(System.IO.Path.Combine(JavaTestBaseFixture.JavaFilesPath, "TestProgram.Jar"), _ct); + var javaObject2 = await _invoker.InvokeMethod( + "WriteObj", + null, + javaObject, + new List { Strings }, + null, + _ct + ); + } + + [Fact] + [TestPriority(2)] + public async Task WriteObj_Float() + { + + var javaObject = await _invoker.InvokeConstructor( + "uipath.java.test.GenericMethods", + null, + null, + _ct + ); + Assert.Contains("uipath.java.test.GenericMethods", javaObject.Convert()); + + await _invoker.LoadJar(Path.Combine(JavaTestBaseFixture.JavaFilesPath, "TestProgram.Jar"), _ct); + var floatObj = await _invoker.InvokeMethod( + "WriteObj", + null, + javaObject, + new List { 1.2f }, + null, + _ct + ); + } + + [Fact] + [TestPriority(2)] + public async Task GenericsExtendString() + { + await _invoker.LoadJar(Path.Combine(JavaTestBaseFixture.JavaFilesPath, "TestProgram.Jar"), _ct); + var javaObject = await _invoker.InvokeConstructor( + "uipath.java.test.GenericMethods", + null, + null, + _ct + ); + Assert.Contains("uipath.java.test.GenericMethods", javaObject.Convert()); + + String testString = "StringXY"; + await _invoker.LoadJar(Path.Combine(JavaTestBaseFixture.JavaFilesPath, "TestProgram.Jar"), _ct); + var stringObj = await _invoker.InvokeMethod( + "GenericsExtString", + null, + javaObject, + new List { testString }, + new List { typeof(string) }, + _ct + ); + Assert.Contains("Generic method: " + testString, stringObj.Convert()); + } + + [Fact] + [TestPriority(3)] + public async Task GenericsExtObj1() + { + var javaObject = await _invoker.InvokeConstructor( + "uipath.java.test.GenericMethods", + null, + null, + _ct + ); + Assert.Contains("uipath.java.test.GenericMethods", javaObject.Convert()); + + await _invoker.LoadJar(Path.Combine(JavaTestBaseFixture.JavaFilesPath, "TestProgram.Jar"), _ct); + var stringObj2 = await _invoker.InvokeMethod( + "GenericsExtObj", + null, + javaObject, + new List { "test string" }, + null, + _ct + ); + Assert.Contains("Generic method with Object ", stringObj2.Convert()); + } + + [Fact] + [TestPriority(3)] + public async Task GenericsExtObj2() + { + float floatobj = (2.3f); + await _invoker.LoadJar(Path.Combine(JavaTestBaseFixture.JavaFilesPath, "TestProgram.Jar"), _ct); + var javaObject = await _invoker.InvokeConstructor( + "uipath.java.test.GenericMethods", + null, + null, + _ct + ); + Assert.Contains("uipath.java.test.GenericMethods", javaObject.Convert()); + + + var stringObj2 = await _invoker.InvokeMethod( + "GenericsExtObj", + null, + javaObject, + new List { floatobj }, + null, + _ct + ); + Assert.Contains("Generic method with Object " + floatobj, stringObj2.Convert()); + } + + [Fact] + [TestPriority(4)] + public async Task GenericsR() + { + var javaObject = await _invoker.InvokeConstructor( + "uipath.java.test.GenericMethods", + null, + null, + _ct + ); + string objParam = "String Param"; + await _invoker.LoadJar(Path.Combine(JavaTestBaseFixture.JavaFilesPath, "TestProgram.Jar"), _ct); + var StringObject = await _invoker.InvokeMethod( + "GenericsR", + null, + javaObject, + new List { objParam }, + null, + _ct + ); + Assert.Contains(objParam , StringObject.Convert()); + + + await _invoker.LoadJar(Path.Combine(JavaTestBaseFixture.JavaFilesPath, "TestProgram.Jar"), _ct); + var IntObject = await _invoker.InvokeMethod( + "GenericsR", + null, + javaObject, + new List { 100 }, + new List { typeof(int) }, + _ct + ); + Assert.Equal(100, IntObject.Convert()); + + await _invoker.LoadJar(Path.Combine(JavaTestBaseFixture.JavaFilesPath, "TestProgram.Jar"), _ct); + var DoubleObject = await _invoker.InvokeMethod( + "GenericsR", + null, + javaObject, + new List { 2.3d }, + null, + _ct + ); + Assert.Equal(2.3 , DoubleObject.Convert()); + } + + [Fact] + [TestPriority(4)] + public async Task GenericsS() + { + var javaObject = await _invoker.InvokeConstructor( + "uipath.java.test.GenericMethods", + null, + null, + _ct + ); + + var TestString = "Test String"; + await _invoker.LoadJar(Path.Combine(JavaTestBaseFixture.JavaFilesPath, "TestProgram.Jar"), _ct); + var StringObj = await _invoker.InvokeMethod( + "GenericsS", + null, + javaObject, + new List { TestString }, + null, + _ct + ); + Assert.Contains("uipath.java.test.GenericMethods", javaObject.Convert()); + } + + [Fact] + [TestPriority(5)] + public async Task Finalize() + { + await _invoker.LoadJar(System.IO.Path.Combine(JavaTestBaseFixture.JavaFilesPath, "TestProgram.Jar"), _ct); + var javaObject = await _invoker.InvokeConstructor( + "uipath.java.test.GenericMethods", + null, + null, + _ct + ); + Assert.Contains("uipath.java.test.GenericMethods", javaObject.Convert()); + + await _invoker.LoadJar(Path.Combine(JavaTestBaseFixture.JavaFilesPath, "TestProgram.Jar"), _ct); + var JOFinalize = await _invoker.InvokeMethod( + "finalize", + null, + javaObject, + null, + null, + _ct + ); + + } + } +} + diff --git a/Activities/Java/UiPath.Java.Test/UiPath.Java.Test.csproj b/Activities/Java/UiPath.Java.Test/UiPath.Java.Test.csproj index 9a14df93..043bd2ca 100644 --- a/Activities/Java/UiPath.Java.Test/UiPath.Java.Test.csproj +++ b/Activities/Java/UiPath.Java.Test/UiPath.Java.Test.csproj @@ -72,6 +72,7 @@ +