You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/10/15 13:42:04 UTC
[isis] branch master updated: ISIS-2449: regressiontesting: adds
initial RO Spec tests
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new aaf4963 ISIS-2449: regressiontesting: adds initial RO Spec tests
aaf4963 is described below
commit aaf4963da1edb50bbfe3fe11e16c1d90a44f2e67
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu Oct 15 15:39:52 2020 +0200
ISIS-2449: regressiontesting: adds initial RO Spec tests
---
.../testdomain/rest/RestServiceRoSpecTest.java | 92 ++++++++++++++++++++++
.../rospec/Configuration_usingRoSpec.java | 31 ++++++++
.../isis/testdomain/rospec/RoSpecSampler.java | 55 +++++++++++++
.../testdomain/rospec/RoSpecTestApplication.java | 27 +++++++
.../testdomain/util/rest/RestEndpointService.java | 38 ++++-----
5 files changed, 220 insertions(+), 23 deletions(-)
diff --git a/regressiontests/incubating/src/test/java/org/apache/isis/testdomain/rest/RestServiceRoSpecTest.java b/regressiontests/incubating/src/test/java/org/apache/isis/testdomain/rest/RestServiceRoSpecTest.java
new file mode 100644
index 0000000..c8e6ccc
--- /dev/null
+++ b/regressiontests/incubating/src/test/java/org/apache/isis/testdomain/rest/RestServiceRoSpecTest.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.isis.testdomain.rest;
+
+import javax.inject.Inject;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.web.server.LocalServerPort;
+import org.springframework.context.annotation.Import;
+import org.springframework.test.context.TestPropertySource;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+import org.apache.isis.core.config.presets.IsisPresets;
+import org.apache.isis.extensions.restclient.ResponseDigest;
+import org.apache.isis.testdomain.conf.Configuration_headless;
+import org.apache.isis.testdomain.rospec.Configuration_usingRoSpec;
+import org.apache.isis.testdomain.util.rest.RestEndpointService;
+import org.apache.isis.viewer.restfulobjects.jaxrsresteasy4.IsisModuleViewerRestfulObjectsJaxrsResteasy4;
+
+import lombok.val;
+
+@SpringBootTest(
+ classes = {
+ RestEndpointService.class
+ },
+ webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@TestPropertySource(IsisPresets.UseLog4j2Test)
+@Import({
+ Configuration_headless.class,
+ Configuration_usingRoSpec.class,
+ IsisModuleViewerRestfulObjectsJaxrsResteasy4.class,
+})
+class RestServiceRoSpecTest {
+
+ @LocalServerPort int port; // just for reference (not used)
+ @Inject RestEndpointService restService;
+
+ @Test
+ void string() {
+ val digest = getDigest(String.class, "string");
+ val returnValue = digest.getEntities().getSingletonOrFail();
+ assertEquals("aString", returnValue);
+ }
+
+ // -- HELPER
+
+ public <T> ResponseDigest<T> getDigest(Class<T> entityType, String actionName) {
+
+ assertTrue(restService.getPort()>0);
+
+ val useRequestDebugLogging = true;
+ val client = restService.newClient(useRequestDebugLogging);
+
+ val request = restService.newInvocationBuilder(client,
+ String.format("services/testdomain.RoSpecSampler/actions/%s/invoke", actionName));
+
+ val args = client.arguments()
+ .build();
+
+ val response = request.post(args);
+ val digest = client.digest(response, entityType);
+
+ if(!digest.isSuccess()) {
+ fail(digest.getFailureCause());
+ }
+
+ return digest;
+
+ }
+
+
+}
diff --git a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/rospec/Configuration_usingRoSpec.java b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/rospec/Configuration_usingRoSpec.java
new file mode 100644
index 0000000..693dd09
--- /dev/null
+++ b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/rospec/Configuration_usingRoSpec.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.isis.testdomain.rospec;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+
+@Configuration
+@Import({
+ RoSpecSampler.class,
+ RoSpecTestApplication.class
+})
+public class Configuration_usingRoSpec {
+
+}
diff --git a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/rospec/RoSpecSampler.java b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/rospec/RoSpecSampler.java
new file mode 100644
index 0000000..a22a56f
--- /dev/null
+++ b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/rospec/RoSpecSampler.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.isis.testdomain.rospec;
+
+import org.apache.isis.applib.annotation.Action;
+import org.apache.isis.applib.annotation.DomainService;
+import org.apache.isis.applib.annotation.NatureOfService;
+
+@DomainService(
+ nature = NatureOfService.REST,
+ objectType = "testdomain.RoSpecSampler")
+public class RoSpecSampler {
+
+ @Action
+ public String string() {
+ return "aString";
+ }
+
+ @Action
+ public String stringNull() {
+ return null;
+ }
+
+ @Action
+ public int integerPrimitive() {
+ return 123;
+ }
+
+ @Action
+ public Integer integer() {
+ return 123;
+ }
+
+ @Action
+ public Integer integerNull() {
+ return null;
+ }
+
+}
diff --git a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/rospec/RoSpecTestApplication.java b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/rospec/RoSpecTestApplication.java
new file mode 100644
index 0000000..3ab2fe0
--- /dev/null
+++ b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/rospec/RoSpecTestApplication.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.isis.testdomain.rospec;
+
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/** seems required by RestServiceTest */
+@SpringBootApplication//(scanBasePackageClasses= {JdoTestDomainModule.class})
+public class RoSpecTestApplication {
+
+}
diff --git a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/util/rest/RestEndpointService.java b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/util/rest/RestEndpointService.java
index f85c64e..5bffb6d 100644
--- a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/util/rest/RestEndpointService.java
+++ b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/util/rest/RestEndpointService.java
@@ -94,13 +94,17 @@ public class RestEndpointService {
return client;
}
+ // -- NEW REQUEST BUILDER
+
+ public Invocation.Builder newInvocationBuilder(RestfulClient client, String actionPath) {
+ return client.request(actionPath, SuppressionType.ALL);
+ }
+
// -- ENDPOINTS
public ResponseDigest<JdoBook> getRecommendedBookOfTheWeek(RestfulClient client) {
- Invocation.Builder request = client.request(
- INVENTORY_RESOURCE + "/actions/recommendedBookOfTheWeek/invoke",
- SuppressionType.ALL);
-
+
+ val request = newInvocationBuilder(client, INVENTORY_RESOURCE + "/actions/recommendedBookOfTheWeek/invoke");
val args = client.arguments()
.build();
@@ -112,10 +116,7 @@ public class RestEndpointService {
public ResponseDigest<JdoBook> getMultipleBooks(RestfulClient client) throws JAXBException {
- Invocation.Builder request = client.request(
- INVENTORY_RESOURCE + "/actions/multipleBooks/invoke",
- SuppressionType.ALL);
-
+ val request = newInvocationBuilder(client, INVENTORY_RESOURCE + "/actions/multipleBooks/invoke");
val args = client.arguments()
.addActionParameter("nrOfBooks", 2)
.build();
@@ -128,10 +129,8 @@ public class RestEndpointService {
public ResponseDigest<JdoBook> storeBook(RestfulClient client, JdoBook newBook) throws JAXBException {
- val request = client.request(
- INVENTORY_RESOURCE + "/actions/storeBook/invoke",
- SuppressionType.ALL);
+ val request = newInvocationBuilder(client, INVENTORY_RESOURCE + "/actions/storeBook/invoke");
val args = client.arguments()
.addActionParameter("newBook", JdoBookDto.from(newBook).encode())
.build();
@@ -143,10 +142,8 @@ public class RestEndpointService {
}
public ResponseDigest<JdoBookDto> getRecommendedBookOfTheWeekAsDto(RestfulClient client) {
- Invocation.Builder request = client.request(
- INVENTORY_RESOURCE + "/actions/recommendedBookOfTheWeekAsDto/invoke",
- SuppressionType.ALL);
-
+
+ val request = newInvocationBuilder(client, INVENTORY_RESOURCE + "/actions/recommendedBookOfTheWeekAsDto/invoke");
val args = client.arguments()
.build();
@@ -158,10 +155,7 @@ public class RestEndpointService {
public ResponseDigest<JdoBookDto> getMultipleBooksAsDto(RestfulClient client) throws JAXBException {
- Invocation.Builder request = client.request(
- INVENTORY_RESOURCE + "/actions/multipleBooksAsDto/invoke",
- SuppressionType.ALL);
-
+ val request = newInvocationBuilder(client, INVENTORY_RESOURCE + "/actions/multipleBooksAsDto/invoke");
val args = client.arguments()
.addActionParameter("nrOfBooks", 2)
.build();
@@ -174,10 +168,8 @@ public class RestEndpointService {
public ResponseDigest<String> getHttpSessionInfo(RestfulClient client) {
- val request = client.request(
- INVENTORY_RESOURCE + "/actions/httpSessionInfo/invoke",
- SuppressionType.ALL);
-
+
+ val request = newInvocationBuilder(client, INVENTORY_RESOURCE + "/actions/httpSessionInfo/invoke");
val args = client.arguments()
.build();