-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for BrowserCallable annotation
Fixes #259
- Loading branch information
1 parent
4815aae
commit 0f2ed7d
Showing
9 changed files
with
294 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
...t/java/com/github/mcollovati/quarkus/hilla/deployment/AbstractEndpointControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/* | ||
* Copyright 2023 Marco Collovati, Dario Götze | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.github.mcollovati.quarkus.hilla.deployment; | ||
|
||
import dev.hilla.exception.EndpointValidationException; | ||
import io.restassured.RestAssured; | ||
import io.restassured.http.ContentType; | ||
import org.hamcrest.CoreMatchers; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import com.github.mcollovati.quarkus.hilla.deployment.endpoints.Pojo; | ||
|
||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
|
||
import static com.github.mcollovati.quarkus.hilla.deployment.TestUtils.givenEndpointRequest; | ||
|
||
abstract class AbstractEndpointControllerTest { | ||
protected abstract String getEndpointName(); | ||
|
||
@Test | ||
void invokeEndpoint_singleSimpleParameter() { | ||
String msg = "A text message"; | ||
givenEndpointRequest(getEndpointName(), "echo", TestUtils.Parameters.param("message", msg)) | ||
.then() | ||
.assertThat() | ||
.statusCode(200) | ||
.and() | ||
.body(equalTo("\"" + msg + "\"")); | ||
} | ||
|
||
@Test | ||
void invokeEndpoint_singleComplexParameter() { | ||
String msg = "A text message"; | ||
Pojo pojo = new Pojo(10, msg); | ||
givenEndpointRequest(getEndpointName(), "pojo", TestUtils.Parameters.param("pojo", pojo)) | ||
.then() | ||
.assertThat() | ||
.statusCode(200) | ||
.and() | ||
.body("number", equalTo(100)) | ||
.and() | ||
.body("text", equalTo(msg + msg)); | ||
} | ||
|
||
@Test | ||
void invokeEndpoint_multipleParameters() { | ||
givenEndpointRequest( | ||
getEndpointName(), | ||
"calculate", | ||
TestUtils.Parameters.param("operator", "+").add("a", 10).add("b", 20)) | ||
.then() | ||
.assertThat() | ||
.statusCode(200) | ||
.and() | ||
.body(equalTo("30")); | ||
} | ||
|
||
@Test | ||
void invokeEndpoint_wrongParametersOrder_badRequest() { | ||
givenEndpointRequest( | ||
getEndpointName(), | ||
"calculate", | ||
TestUtils.Parameters.param("a", 10).add("operator", "+").add("b", 20)) | ||
.then() | ||
.assertThat() | ||
.statusCode(400) | ||
.and() | ||
.body("type", equalTo(EndpointValidationException.class.getName())) | ||
.and() | ||
.body( | ||
"message", | ||
CoreMatchers.allOf( | ||
containsString("Validation error"), | ||
containsString("'" + getEndpointName() + "'"), | ||
containsString("'calculate'"))) | ||
.body("validationErrorData[0].parameterName", equalTo("operator")); | ||
} | ||
|
||
@Test | ||
void invokeEndpoint_wrongNumberOfParameters_badRequest() { | ||
givenEndpointRequest(getEndpointName(), "calculate", TestUtils.Parameters.param("operator", "+")) | ||
.then() | ||
.assertThat() | ||
.statusCode(400) | ||
.and() | ||
.body( | ||
"message", | ||
CoreMatchers.allOf( | ||
containsString("Incorrect number of parameters"), | ||
containsString("'" + getEndpointName() + "'"), | ||
containsString("'calculate'"), | ||
containsString("expected: 3, got: 1"))); | ||
} | ||
|
||
@Test | ||
void invokeEndpoint_wrongEndpointName_notFound() { | ||
givenEndpointRequest("NotExistingTestEndpoint", "calculate", TestUtils.Parameters.param("operator", "+")) | ||
.then() | ||
.assertThat() | ||
.statusCode(404); | ||
} | ||
|
||
@Test | ||
void invokeEndpoint_wrongMethodName_notFound() { | ||
givenEndpointRequest(getEndpointName(), "notExistingMethod", TestUtils.Parameters.param("operator", "+")) | ||
.then() | ||
.assertThat() | ||
.statusCode(404); | ||
} | ||
|
||
@Test | ||
void invokeEndpoint_emptyMethodName_notFound() { | ||
givenEndpointRequest(getEndpointName(), "", TestUtils.Parameters.param("operator", "+")) | ||
.then() | ||
.assertThat() | ||
.statusCode(404); | ||
} | ||
|
||
@Test | ||
void invokeEndpoint_missingMethodName_notFound() { | ||
RestAssured.given() | ||
.contentType(ContentType.JSON) | ||
.cookie("csrfToken", "CSRF_TOKEN") | ||
.header("X-CSRF-Token", "CSRF_TOKEN") | ||
.basePath("/connect") | ||
.when() | ||
.post(getEndpointName()) | ||
.then() | ||
.assertThat() | ||
.statusCode(404); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...st/java/com/github/mcollovati/quarkus/hilla/deployment/BrowserCallableControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2023 Marco Collovati, Dario Götze | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.github.mcollovati.quarkus.hilla.deployment; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.github.mcollovati.quarkus.hilla.deployment.endpoints.Pojo; | ||
import com.github.mcollovati.quarkus.hilla.deployment.endpoints.TestBrowserCallable; | ||
|
||
class BrowserCallableControllerTest extends AbstractEndpointControllerTest { | ||
|
||
private static final String ENDPOINT_NAME = TestBrowserCallable.class.getSimpleName(); | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(TestUtils.class, Pojo.class, TestBrowserCallable.class)); | ||
|
||
@Override | ||
protected String getEndpointName() { | ||
return ENDPOINT_NAME; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.