test missing and invalid parameters
diff --git a/src/test/java/org/apache/sling/commons/crypto/it/tests/EncryptWebConsolePluginIT.java b/src/test/java/org/apache/sling/commons/crypto/it/tests/EncryptWebConsolePluginIT.java
index 8827162..ea4e13a 100644
--- a/src/test/java/org/apache/sling/commons/crypto/it/tests/EncryptWebConsolePluginIT.java
+++ b/src/test/java/org/apache/sling/commons/crypto/it/tests/EncryptWebConsolePluginIT.java
@@ -27,6 +27,8 @@
import javax.inject.Inject;
import org.apache.sling.commons.crypto.CryptoService;
+import org.jsoup.Connection.Method;
+import org.jsoup.Connection.Response;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.junit.Before;
@@ -131,4 +133,46 @@
assertThat(document.getElementById("ciphertext").text()).isEqualTo(text);
}
+ @Test
+ public void testEncryptMissingMessage() throws IOException {
+ final ServiceReference<CryptoService> reference = registration.getReference();
+ final String id = reference.getProperty(Constants.SERVICE_ID).toString();
+ final Response response = Jsoup.connect(url)
+ .header("Authorization", String.format("Basic %s", CREDENTIALS))
+ .data("service-id", id)
+ .method(Method.POST)
+ .ignoreHttpErrors(true)
+ .execute();
+ assertThat(response.statusCode()).isEqualTo(400);
+ assertThat(response.statusMessage()).isEqualTo("Parameter message is missing");
+ }
+
+ @Test
+ public void testEncryptMissingServiceId() throws IOException {
+ final String message = "Very secret message";
+ final Response response = Jsoup.connect(url)
+ .header("Authorization", String.format("Basic %s", CREDENTIALS))
+ .data("message", message)
+ .method(Method.POST)
+ .ignoreHttpErrors(true)
+ .execute();
+ assertThat(response.statusCode()).isEqualTo(400);
+ assertThat(response.statusMessage()).isEqualTo("Parameter service-id is missing");
+ }
+
+ @Test
+ public void testEncryptMissingInvalidServiceId() throws IOException {
+ final String id = "invalid";
+ final String message = "Very secret message";
+ final Response response = Jsoup.connect(url)
+ .header("Authorization", String.format("Basic %s", CREDENTIALS))
+ .data("service-id", id)
+ .data("message", message)
+ .method(Method.POST)
+ .ignoreHttpErrors(true)
+ .execute();
+ assertThat(response.statusCode()).isEqualTo(404);
+ assertThat(response.statusMessage()).isEqualTo("Crypto service with service id invalid not found");
+ }
+
}