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 2021/11/22 16:13:50 UTC
[isis] branch master updated: ISIS-2877: adds a bunch more value-type test scenarios
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 18c690f ISIS-2877: adds a bunch more value-type test scenarios
18c690f is described below
commit 18c690f5f14002a4dd03d2e60074f6a82f29ee1d
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Nov 22 17:13:40 2021 +0100
ISIS-2877: adds a bunch more value-type test scenarios
---
.../isis/testdomain/value/ValueSemanticsTest.java | 29 ++-
.../testdomain/value/ValueSemanticsTester.java | 22 ++-
.../model/valuetypes/ValueTypeExample.java | 215 +++++++++++++++++++++
.../model/valuetypes/ValueTypeExampleString.java | 40 ----
.../model/valuetypes/ValueTypeExampleUuid.java | 42 ----
5 files changed, 256 insertions(+), 92 deletions(-)
diff --git a/regressiontests/stable-value/src/test/java/org/apache/isis/testdomain/value/ValueSemanticsTest.java b/regressiontests/stable-value/src/test/java/org/apache/isis/testdomain/value/ValueSemanticsTest.java
index 13a0c1d..58944b5 100644
--- a/regressiontests/stable-value/src/test/java/org/apache/isis/testdomain/value/ValueSemanticsTest.java
+++ b/regressiontests/stable-value/src/test/java/org/apache/isis/testdomain/value/ValueSemanticsTest.java
@@ -20,7 +20,6 @@ package org.apache.isis.testdomain.value;
import java.io.Serializable;
import java.util.Locale;
-import java.util.UUID;
import java.util.stream.Stream;
import javax.inject.Inject;
@@ -35,15 +34,18 @@ import org.springframework.test.context.TestPropertySource;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.isis.applib.services.iactnlayer.InteractionContext;
import org.apache.isis.applib.services.iactnlayer.InteractionService;
import org.apache.isis.applib.services.inject.ServiceInjector;
import org.apache.isis.applib.util.schema.CommonDtoUtils;
+import org.apache.isis.applib.value.Password;
import org.apache.isis.commons.internal.base._Refs;
import org.apache.isis.commons.internal.resources._Xml;
import org.apache.isis.commons.internal.resources._Xml.WriteOptions;
import org.apache.isis.core.config.presets.IsisPresets;
+import org.apache.isis.core.config.valuetypes.ValueSemanticsRegistry;
import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
import org.apache.isis.schema.cmd.v2.PropertyDto;
import org.apache.isis.schema.common.v2.ValueWithTypeDto;
@@ -85,6 +87,11 @@ class ValueSemanticsTest {
managedProp->example.getUpdateValue(),
(context, codec)->{
+ // TODO skip tests, because some value-types are not serializable
+ if(!(example.getValue() instanceof Serializable)) {
+ return;
+ }
+
// CoderDecoder round-trip test
val serialized = codec.toEncodedString(example.getValue());
assertEquals(example.getValue(), codec.fromEncodedString(serialized));
@@ -94,7 +101,16 @@ class ValueSemanticsTest {
// Parser round-trip test
val stringified = parser.parseableTextRepresentation(context, example.getValue());
- assertEquals(example.getValue(), parser.parseTextRepresentation(context, stringified));
+
+ if(valueType.equals(Password.class)) {
+
+ val recoveredValue = (Password)parser.parseTextRepresentation(context, stringified);
+ assertTrue(recoveredValue.checkPassword("*"));
+
+ } else {
+
+ assertEquals(example.getValue(), parser.parseTextRepresentation(context, stringified));
+ }
},
(context, renderer)->{
@@ -108,7 +124,7 @@ class ValueSemanticsTest {
val newValueRecorded = CommonDtoUtils.getValue(newValueRecordedDto);
// TODO skip tests, because some value-types are not represented by the schema yet
- if(valueType.equals(UUID.class)) {
+ if(newValueRecorded==null) {
return;
}
@@ -126,6 +142,12 @@ class ValueSemanticsTest {
}
+// @Test
+// void list() {
+// valueSemanticsRegistry.streamClassesWithValueSemantics()
+// .forEach(valueType->System.err.printf("%s%n", valueType.getSimpleName()));
+// }
+
// -- HELPER
// eg.. <ValueWithTypeDto type="string"><com:string>anotherString</com:string></ValueWithTypeDto>
@@ -151,6 +173,7 @@ class ValueSemanticsTest {
@Inject SpecificationLoader specLoader;
@Inject InteractionService interactionService;
@Inject ServiceInjector serviceInjector;
+ @Inject ValueSemanticsRegistry valueSemanticsRegistry;
Stream<Arguments> provideValueTypeExamples() {
return valueTypeExampleProvider.streamExamples()
diff --git a/regressiontests/stable-value/src/test/java/org/apache/isis/testdomain/value/ValueSemanticsTester.java b/regressiontests/stable-value/src/test/java/org/apache/isis/testdomain/value/ValueSemanticsTester.java
index 0f62028..e9510bf 100644
--- a/regressiontests/stable-value/src/test/java/org/apache/isis/testdomain/value/ValueSemanticsTester.java
+++ b/regressiontests/stable-value/src/test/java/org/apache/isis/testdomain/value/ValueSemanticsTester.java
@@ -19,6 +19,7 @@
package org.apache.isis.testdomain.value;
import java.io.Serializable;
+import java.util.Optional;
import java.util.function.Function;
import javax.inject.Inject;
@@ -82,8 +83,16 @@ public class ValueSemanticsTester<T extends Serializable> {
.createValueSemanticsContext(prop);
codecCallback.accept(context, codec(prop));
- parserCallback.accept(context, parser(prop));
- renderCallback.accept(context, renderer(prop));
+
+ val parserIfAny = parser(prop);
+ if(parserIfAny.isPresent()) {
+ parserCallback.accept(context, parserIfAny.get());
+ }
+
+ val rendererIfAny = renderer(prop);
+ if(rendererIfAny.isPresent()) {
+ renderCallback.accept(context, rendererIfAny.get());
+ }
interactionService.run(interactionContext, ()->{
@@ -127,17 +136,16 @@ public class ValueSemanticsTester<T extends Serializable> {
.orElseThrow(()->_Exceptions.noSuchElement());
}
- private Parser<T> parser(
+ private Optional<Parser<T>> parser(
final ObjectFeature feature) {
val valueFacet = valueFacet(feature);
- return valueFacet.selectParserForFeatureElseFallback(feature);
+ return valueFacet.selectParserForFeature(feature);
}
- private Renderer<T> renderer(
+ private Optional<Renderer<T>> renderer(
final ObjectFeature feature) {
val valueFacet = valueFacet(feature);
- return valueFacet.selectDefaultRenderer()
- .orElseThrow(()->_Exceptions.noSuchElement());
+ return valueFacet.selectDefaultRenderer();
}
}
diff --git a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/valuetypes/ValueTypeExample.java b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/valuetypes/ValueTypeExample.java
index eda768e..85b52df 100644
--- a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/valuetypes/ValueTypeExample.java
+++ b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/valuetypes/ValueTypeExample.java
@@ -18,12 +18,27 @@
*/
package org.apache.isis.testdomain.model.valuetypes;
+import java.awt.image.BufferedImage;
+import java.net.URL;
import java.util.List;
+import java.util.UUID;
import org.apache.isis.applib.annotation.Action;
import org.apache.isis.applib.annotation.Collection;
+import org.apache.isis.applib.annotation.DomainObject;
+import org.apache.isis.applib.annotation.Nature;
import org.apache.isis.applib.annotation.Programmatic;
import org.apache.isis.applib.annotation.Property;
+import org.apache.isis.applib.value.Blob;
+import org.apache.isis.applib.value.Clob;
+import org.apache.isis.applib.value.LocalResourcePath;
+import org.apache.isis.applib.value.Markup;
+import org.apache.isis.applib.value.NamedWithMimeType.CommonMimeType;
+import org.apache.isis.applib.value.Password;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.SneakyThrows;
public abstract class ValueTypeExample<T> {
@@ -50,4 +65,204 @@ public abstract class ValueTypeExample<T> {
return (Class<T>) getValue().getClass();
}
+ // -- EXAMPLES - BASIC
+
+ @DomainObject(
+ logicalTypeName = "isis.testdomain.valuetypes.ValueTypeExampleBoolean",
+ nature = Nature.BEAN)
+ public static class ValueTypeExampleBoolean
+ extends ValueTypeExample<Boolean> {
+
+ @Property @Getter @Setter
+ private Boolean value = Boolean.TRUE;
+
+ @Getter
+ private Boolean updateValue = Boolean.FALSE;
+
+ }
+
+ @DomainObject(
+ logicalTypeName = "isis.testdomain.valuetypes.ValueTypeExampleCharacter",
+ nature = Nature.BEAN)
+ public static class ValueTypeExampleCharacter
+ extends ValueTypeExample<Character> {
+
+ @Property @Getter @Setter
+ private Character value = 'a';
+
+ @Getter
+ private Character updateValue = 'b';
+
+ }
+
+ @DomainObject(
+ logicalTypeName = "isis.testdomain.valuetypes.ValueTypeExampleString",
+ nature = Nature.BEAN)
+ public static class ValueTypeExampleString
+ extends ValueTypeExample<String> {
+
+ @Property @Getter @Setter
+ private String value = "aString";
+
+ @Getter
+ private String updateValue = "anotherString";
+
+ }
+
+ @DomainObject(
+ logicalTypeName = "isis.testdomain.valuetypes.ValueTypeExamplePassword",
+ nature = Nature.BEAN)
+ public static class ValueTypeExamplePassword
+ extends ValueTypeExample<Password> {
+
+ @Property @Getter @Setter
+ private Password value = Password.of("aPassword");
+
+ @Getter
+ private Password updateValue = Password.of("anotherPassword");
+
+ }
+
+ @DomainObject(
+ logicalTypeName = "isis.testdomain.valuetypes.ValueTypeExampleBufferedImage",
+ nature = Nature.BEAN)
+ public static class ValueTypeExampleBufferedImage
+ extends ValueTypeExample<BufferedImage> {
+
+ @Property @Getter @Setter
+ private BufferedImage value = new BufferedImage(4, 4, BufferedImage.TYPE_INT_RGB);
+
+ @Getter
+ private BufferedImage updateValue = new BufferedImage(8, 8, BufferedImage.TYPE_INT_RGB);
+
+ }
+
+ @DomainObject(
+ logicalTypeName = "isis.testdomain.valuetypes.ValueTypeExampleBlob",
+ nature = Nature.BEAN)
+ public static class ValueTypeExampleBlob
+ extends ValueTypeExample<Blob> {
+
+ @Property @Getter @Setter
+ private Blob value = Blob.of("aBlob", CommonMimeType.BIN, new byte[] {1, 2, 3});
+
+ @Getter
+ private Blob updateValue = Blob.of("anotherBlob", CommonMimeType.BIN, new byte[] {3, 4});
+
+ }
+
+ @DomainObject(
+ logicalTypeName = "isis.testdomain.valuetypes.ValueTypeExampleClob",
+ nature = Nature.BEAN)
+ public static class ValueTypeExampleClob
+ extends ValueTypeExample<Clob> {
+
+ @Property @Getter @Setter
+ private Clob value = Clob.of("aClob", CommonMimeType.TXT, "abc");
+
+ @Getter
+ private Clob updateValue = Clob.of("anotherClob", CommonMimeType.TXT, "ef");
+
+ }
+
+ @DomainObject(
+ logicalTypeName = "isis.testdomain.valuetypes.ValueTypeExampleLocalResourcePath",
+ nature = Nature.BEAN)
+ public static class ValueTypeExampleLocalResourcePath
+ extends ValueTypeExample<LocalResourcePath> {
+
+ @Property @Getter @Setter
+ private LocalResourcePath value = new LocalResourcePath("img/a");
+
+ @Getter
+ private LocalResourcePath updateValue = new LocalResourcePath("img/b");
+
+ }
+
+ @DomainObject(
+ logicalTypeName = "isis.testdomain.valuetypes.ValueTypeExampleUrl",
+ nature = Nature.BEAN)
+ public static class ValueTypeExampleUrl
+ extends ValueTypeExample<URL> {
+
+ @Property @Getter @Setter
+ private URL value = url("https://a.b.c");
+
+ @Getter
+ private URL updateValue = url("https://b.c.d");
+
+ @SneakyThrows
+ private static URL url(final String url) {
+ return new URL(url);
+ }
+
+ }
+
+ @DomainObject(
+ logicalTypeName = "isis.testdomain.valuetypes.ValueTypeExampleMarkup",
+ nature = Nature.BEAN)
+ public static class ValueTypeExampleMarkup
+ extends ValueTypeExample<Markup> {
+
+ @Property @Getter @Setter
+ private Markup value = Markup.valueOf("aMarkup");
+
+ @Getter
+ private Markup updateValue = Markup.valueOf("anotherMarkup");
+
+ }
+
+ @DomainObject(
+ logicalTypeName = "isis.testdomain.valuetypes.ValueTypeExampleUuid",
+ nature = Nature.BEAN)
+ public static class ValueTypeExampleUuid
+ extends ValueTypeExample<UUID> {
+
+ @Property @Getter @Setter
+ private UUID value = UUID.randomUUID();
+
+ @Getter
+ private UUID updateValue = UUID.randomUUID();
+
+ }
+
+
+ // -- EXAMPLES - NUMBERS
+
+//TODO Byte
+//TODO Short
+//TODO Integer
+//TODO Long
+//TODO Float
+//TODO Double
+//TODO BigDecimal
+//TODO BigInteger
+
+
+ // -- EXAMPLES - TEMPORAL
+
+//TODO Date
+//TODO DateTime
+//TODO LocalDate
+//TODO LocalDateTime
+//TODO LocalTime
+//TODO Time
+//TODO Timestamp
+//TODO OffsetDateTime
+//TODO OffsetTime
+//TODO ZonedDateTime
+
+
+ // -- EXAMPLES - OTHER
+
+//TODO Bookmark
+//TODO OidDto
+
+//TODO ChangesDto
+//TODO CommandDto
+//TODO InteractionDto
+
+//TODO TreeNode
+
+
}
diff --git a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/valuetypes/ValueTypeExampleString.java b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/valuetypes/ValueTypeExampleString.java
deleted file mode 100644
index c537837..0000000
--- a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/valuetypes/ValueTypeExampleString.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.model.valuetypes;
-
-import org.apache.isis.applib.annotation.DomainObject;
-import org.apache.isis.applib.annotation.Nature;
-import org.apache.isis.applib.annotation.Property;
-
-import lombok.Getter;
-import lombok.Setter;
-
-@DomainObject(
- logicalTypeName = "isis.testdomain.valuetypes.ValueTypeExampleString",
- nature = Nature.BEAN)
-public class ValueTypeExampleString
-extends ValueTypeExample<String> {
-
- @Property @Getter @Setter
- private String value = "aString";
-
- @Getter
- private String updateValue = "anotherString";
-
-}
\ No newline at end of file
diff --git a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/valuetypes/ValueTypeExampleUuid.java b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/valuetypes/ValueTypeExampleUuid.java
deleted file mode 100644
index 8e760df..0000000
--- a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/model/valuetypes/ValueTypeExampleUuid.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.model.valuetypes;
-
-import java.util.UUID;
-
-import org.apache.isis.applib.annotation.DomainObject;
-import org.apache.isis.applib.annotation.Nature;
-import org.apache.isis.applib.annotation.Property;
-
-import lombok.Getter;
-import lombok.Setter;
-
-@DomainObject(
- logicalTypeName = "isis.testdomain.valuetypes.ValueTypeExampleUuid",
- nature = Nature.BEAN)
-public class ValueTypeExampleUuid
-extends ValueTypeExample<UUID> {
-
- @Property @Getter @Setter
- private UUID value = UUID.randomUUID();
-
- @Getter
- private UUID updateValue = UUID.randomUUID();
-
-}
\ No newline at end of file