From 9e150fd57cc4bf43c05efc60003b8e42a6807c36 Mon Sep 17 00:00:00 2001 From: Wojciech Debski Date: Sun, 29 Oct 2023 21:05:41 +0100 Subject: [PATCH 1/2] added helloworld example of upload files using POST --- .../HelloWorldFileUploadTest.java | 17 ++++++++++++ .../hello_world_file_upload_test.json | 26 +++++++++++++++++++ .../helloworld_file_upload/textfile.txt | 1 + .../resources/postman_echo_host.properties | 6 +++++ 4 files changed, 50 insertions(+) create mode 100644 http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldfileupload/HelloWorldFileUploadTest.java create mode 100644 http-testing/src/test/resources/helloworld_file_upload/hello_world_file_upload_test.json create mode 100644 http-testing/src/test/resources/helloworld_file_upload/textfile.txt create mode 100644 http-testing/src/test/resources/postman_echo_host.properties diff --git a/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldfileupload/HelloWorldFileUploadTest.java b/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldfileupload/HelloWorldFileUploadTest.java new file mode 100644 index 000000000..208abaf19 --- /dev/null +++ b/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldfileupload/HelloWorldFileUploadTest.java @@ -0,0 +1,17 @@ +package org.jsmart.zerocode.testhelp.tests.helloworldfileupload; + +import org.jsmart.zerocode.core.domain.Scenario; +import org.jsmart.zerocode.core.domain.TargetEnv; +import org.jsmart.zerocode.core.runner.ZeroCodeUnitRunner; +import org.junit.Test; +import org.junit.runner.RunWith; + +@TargetEnv("postman_echo_host.properties") +@RunWith(ZeroCodeUnitRunner.class) +public class HelloWorldFileUploadTest { + + @Test + @Scenario("helloworld_file_upload/hello_world_file_upload_test.json") + public void fileUploadTest() throws Exception { + } +} diff --git a/http-testing/src/test/resources/helloworld_file_upload/hello_world_file_upload_test.json b/http-testing/src/test/resources/helloworld_file_upload/hello_world_file_upload_test.json new file mode 100644 index 000000000..5657926f8 --- /dev/null +++ b/http-testing/src/test/resources/helloworld_file_upload/hello_world_file_upload_test.json @@ -0,0 +1,26 @@ +{ + "scenarioName": "Assert that file has been uploaded successfully", + "steps": [ + { + "name": "post_file", + "url": "/post", + "method": "POST", + "request": { + "headers": { + "Content-Type": "multipart/form-data" + }, + "body": { + "files": ["file:helloworld_file_upload/textfile.txt"] + } + }, + "verify": { + "status": 200, + "body": { + "files": { + "['textfile.txt']": "data:application/octet-stream;base64,SGVsbG9Xb3JsZA==" + } + } + } + } + ] +} \ No newline at end of file diff --git a/http-testing/src/test/resources/helloworld_file_upload/textfile.txt b/http-testing/src/test/resources/helloworld_file_upload/textfile.txt new file mode 100644 index 000000000..8970971f1 --- /dev/null +++ b/http-testing/src/test/resources/helloworld_file_upload/textfile.txt @@ -0,0 +1 @@ +HelloWorld \ No newline at end of file diff --git a/http-testing/src/test/resources/postman_echo_host.properties b/http-testing/src/test/resources/postman_echo_host.properties new file mode 100644 index 000000000..a65941cbc --- /dev/null +++ b/http-testing/src/test/resources/postman_echo_host.properties @@ -0,0 +1,6 @@ +# Web Server host and port +web.application.endpoint.host=https://postman-echo.com +# Web Service Port; Leave it blank in case it is default port i.e. 80 or 443 etc +web.application.endpoint.port= +# Web Service context; Leave it blank in case you do not have a common context +web.application.endpoint.context= From 8b6b5183a77d9f8770f34a4c57fff72346fbb911 Mon Sep 17 00:00:00 2001 From: nirmalchandra Date: Wed, 1 Nov 2023 13:08:11 +0000 Subject: [PATCH 2/2] Build and run the test --- http-testing/pom.xml | 1 + .../helloworldfileupload/HelloWorldFileUploadTest.java | 2 +- .../helloworldjavaexec/SecurityHeaderTokenDynamicTest.java | 4 ++-- .../HelloWorldPropertiesReadingTest.java | 6 +++--- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/http-testing/pom.xml b/http-testing/pom.xml index dd9aa31e0..7e2b18472 100644 --- a/http-testing/pom.xml +++ b/http-testing/pom.xml @@ -67,6 +67,7 @@ org.jsmart.zerocode.testhelp.tests.helloworldjavaexec.HelloWorldJavaApiAsProtocolTest org.jsmart.zerocode.testhelp.tests.helloworldarrayelementmatching.HelloWorldArrayElementPickerTest org.jsmart.zerocode.testhelp.tests.helloworldimplicitdelay.JustHelloImplicitDelayTimeOutTest + org.jsmart.zerocode.testhelp.tests.helloworldfileupload.HelloWorldFileUploadTest diff --git a/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldfileupload/HelloWorldFileUploadTest.java b/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldfileupload/HelloWorldFileUploadTest.java index 208abaf19..ea805ce84 100644 --- a/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldfileupload/HelloWorldFileUploadTest.java +++ b/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldfileupload/HelloWorldFileUploadTest.java @@ -12,6 +12,6 @@ public class HelloWorldFileUploadTest { @Test @Scenario("helloworld_file_upload/hello_world_file_upload_test.json") - public void fileUploadTest() throws Exception { + public void testFileUpload() throws Exception { } } diff --git a/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldjavaexec/SecurityHeaderTokenDynamicTest.java b/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldjavaexec/SecurityHeaderTokenDynamicTest.java index 05ba28a0c..08f17d54c 100644 --- a/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldjavaexec/SecurityHeaderTokenDynamicTest.java +++ b/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldjavaexec/SecurityHeaderTokenDynamicTest.java @@ -1,6 +1,6 @@ package org.jsmart.zerocode.testhelp.tests.helloworldjavaexec; -import org.jsmart.zerocode.core.domain.JsonTestCase; +import org.jsmart.zerocode.core.domain.Scenario; import org.jsmart.zerocode.core.domain.TargetEnv; import org.jsmart.zerocode.core.runner.ZeroCodeUnitRunner; import org.junit.Test; @@ -11,7 +11,7 @@ public class SecurityHeaderTokenDynamicTest { @Test - @JsonTestCase("helloworldjavaexec/hello_world_security_token_for_header_test.json") + @Scenario("helloworldjavaexec/hello_world_security_token_for_header_test.json") public void testNewHeaderToken() throws Exception { } diff --git a/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldproperties/HelloWorldPropertiesReadingTest.java b/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldproperties/HelloWorldPropertiesReadingTest.java index 3635227f6..a92d0d753 100644 --- a/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldproperties/HelloWorldPropertiesReadingTest.java +++ b/http-testing/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworldproperties/HelloWorldPropertiesReadingTest.java @@ -1,6 +1,6 @@ package org.jsmart.zerocode.testhelp.tests.helloworldproperties; -import org.jsmart.zerocode.core.domain.JsonTestCase; +import org.jsmart.zerocode.core.domain.Scenario; import org.jsmart.zerocode.core.domain.TargetEnv; import org.jsmart.zerocode.core.runner.ZeroCodeUnitRunner; import org.junit.Test; @@ -11,12 +11,12 @@ public class HelloWorldPropertiesReadingTest { @Test - @JsonTestCase("helloworld_properties_reading/read_properties_into_test_steps.json") + @Scenario("helloworld_properties_reading/read_properties_into_test_steps.json") public void test_aPropertyKeyValue() throws Exception { } @Test - @JsonTestCase("helloworld_properties_reading/use_common_SAML_token_as_headers.json") + @Scenario("helloworld_properties_reading/use_common_SAML_token_as_headers.json") public void test_useCommonSAMLToken() throws Exception { }