Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Version in ordering filters #1198

Merged
merged 11 commits into from
Nov 18, 2019
Merged
7 changes: 5 additions & 2 deletions client/src/main/java/io/spine/client/Filters.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.spine.base.Field;
import io.spine.base.FieldPath;
import io.spine.client.CompositeFilter.CompositeOperator;
import io.spine.core.Version;

import java.util.Collection;

Expand Down Expand Up @@ -63,6 +64,7 @@
* {@link #le <=}) supports only the following types:
* <ul>
* <li>{@link Timestamp com.google.protobuf.Timestamp};
* <li>{@link Version io.spine.core.Version};
* <li>Java primitive number types;
* <li>{@code String}.
* </ul>
Expand Down Expand Up @@ -217,7 +219,7 @@ public static CompositeFilter either(Filter first, Filter... rest) {
static CompositeFilter all(Collection<Filter> filters) {
checkNotNull(filters);
checkArgument(!filters.isEmpty(),
"Composite filter must contain at least one simple filter in it");
"Composite filter must contain at least one simple filter in it.");
return composeFilters(filters, ALL);
}

Expand Down Expand Up @@ -247,9 +249,10 @@ private static void checkSupportedOrderingComparisonType(Class<?> cls) {
Class<?> dataType = Primitives.wrap(cls);
boolean supported = isSupportedNumber(dataType)
|| Timestamp.class.isAssignableFrom(dataType)
|| Version.class.isAssignableFrom(dataType)
|| String.class.isAssignableFrom(dataType);
checkArgument(supported,
"The type %s is not supported for the ordering comparison.",
"The type `%s` is not supported for the ordering comparison.",
dataType.getCanonicalName());
}

Expand Down
43 changes: 34 additions & 9 deletions client/src/test/java/io/spine/client/FiltersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.google.protobuf.StringValue;
import com.google.protobuf.Timestamp;
import io.spine.client.Filter.Operator;
import io.spine.core.Version;
import io.spine.core.Versions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -56,7 +58,6 @@
import static io.spine.testing.Tests.assertHasPrivateParameterlessCtor;
import static java.lang.String.join;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

@DisplayName("Filters utility should")
Expand Down Expand Up @@ -176,22 +177,46 @@ class CreateOrderingFilter {
@DisplayName("for numbers")
void forNumbers() {
double number = 3.14;
Filter filter = le("doubleField", number);
assertNotNull(filter);
assertEquals(LESS_OR_EQUAL, filter.getOperator());
Filter filter = le("double_field", number);
assertThat(filter).isNotNull();
assertThat(filter.getOperator()).isEqualTo(LESS_OR_EQUAL);

DoubleValue value = unpack(filter.getValue(), DoubleValue.class);
assertEquals(number, value.getValue());
assertThat(value.getValue()).isWithin(0.01).of(number);
}

@Test
@DisplayName("for strings")
void forStrings() {
String theString = "abc";
Filter filter = gt("stringField", theString);
assertNotNull(filter);
assertEquals(GREATER_THAN, filter.getOperator());
Filter filter = gt("string_field", theString);
assertThat(filter).isNotNull();
assertThat(filter.getOperator()).isEqualTo(GREATER_THAN);

StringValue value = unpack(filter.getValue(), StringValue.class);
assertEquals(theString, value.getValue());
assertThat(value.getValue()).isEqualTo(theString);
}

@Test
@DisplayName("for timestamps")
void forTimestamps() {
Timestamp timestamp = currentTime();
Filter filter = gt("timestamp_field", timestamp);
assertThat(filter).isNotNull();
assertThat(filter.getOperator()).isEqualTo(GREATER_THAN);
Timestamp value = unpack(filter.getValue(), Timestamp.class);
assertThat(value).isEqualTo(timestamp);
}

@Test
@DisplayName("for versions")
void forVersions() {
Version version = Versions.zero();
Filter filter = ge("version_field", version);
assertThat(filter).isNotNull();
assertThat(filter.getOperator()).isEqualTo(GREATER_OR_EQUAL);
Version value = unpack(filter.getValue(), Version.class);
assertThat(value).isEqualTo(version);
}
}

Expand Down
2 changes: 1 addition & 1 deletion config
6 changes: 3 additions & 3 deletions core/src/main/java/io/spine/core/Signal.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ default C context() {
/**
* Obtains the type URL of the enclosed message.
*/
default TypeUrl typeUrl() {
default TypeUrl enclosedTypeUrl() {
return TypeUrl.ofEnclosed(getMessage());
}

Expand Down Expand Up @@ -181,7 +181,7 @@ default MessageId messageId() {
return MessageId
.newBuilder()
.setId(pack(id()))
.setTypeUrl(typeUrl().value())
.setTypeUrl(enclosedTypeUrl().value())
.vBuild();
}

Expand All @@ -194,7 +194,7 @@ default Origin asMessageOrigin() {
MessageId commandQualifier = MessageId
.newBuilder()
.setId(pack(id()))
.setTypeUrl(typeUrl().value())
.setTypeUrl(enclosedTypeUrl().value())
.buildPartial();
Origin origin = Origin
.newBuilder()
Expand Down
16 changes: 8 additions & 8 deletions license-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Nov 15 17:55:18 EET 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Nov 18 16:07:43 EET 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -743,7 +743,7 @@ This report was generated on **Fri Nov 15 17:55:18 EET 2019** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Nov 15 17:55:18 EET 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Nov 18 16:07:46 EET 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -1144,7 +1144,7 @@ This report was generated on **Fri Nov 15 17:55:18 EET 2019** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Nov 15 17:55:19 EET 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Nov 18 16:07:49 EET 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -1699,7 +1699,7 @@ This report was generated on **Fri Nov 15 17:55:19 EET 2019** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Nov 15 17:55:20 EET 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Nov 18 16:07:53 EET 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -2117,7 +2117,7 @@ This report was generated on **Fri Nov 15 17:55:20 EET 2019** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Nov 15 17:55:20 EET 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Nov 18 16:07:56 EET 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -2536,7 +2536,7 @@ This report was generated on **Fri Nov 15 17:55:20 EET 2019** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Nov 15 17:55:21 EET 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Nov 18 16:07:59 EET 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -2963,7 +2963,7 @@ This report was generated on **Fri Nov 15 17:55:21 EET 2019** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Nov 15 17:55:21 EET 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Nov 18 16:08:02 EET 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).



Expand Down Expand Up @@ -3466,4 +3466,4 @@ This report was generated on **Fri Nov 15 17:55:21 EET 2019** using [Gradle-Lice
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Nov 15 17:55:22 EET 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Mon Nov 18 16:08:05 EET 2019** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
16 changes: 8 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ all modules and does not describe the project structure per-subproject.
<dependency>
<groupId>io.spine</groupId>
<artifactId>spine-base</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -82,13 +82,13 @@ all modules and does not describe the project structure per-subproject.
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-model-compiler</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-plugin-base</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -130,7 +130,7 @@ all modules and does not describe the project structure per-subproject.
<dependency>
<groupId>io.spine</groupId>
<artifactId>spine-testlib</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -142,13 +142,13 @@ all modules and does not describe the project structure per-subproject.
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-mute-logging</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-plugin-testlib</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -210,12 +210,12 @@ all modules and does not describe the project structure per-subproject.
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-javadoc-filter</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-protoc-plugin</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void safePost(Command command) {
} catch (Throwable t) {
_error().withCause(t)
.log("Error posting command `%s` with ID `%s`: `%s`.",
command.typeUrl(),
command.enclosedTypeUrl(),
command.getId()
.getUuid(),
t.getLocalizedMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
*
* <p>Since entity columns are proto-based and have a limited amount of possible types, this class
* allows descendants to override concrete type mapping rules in a convenient way.
*
* <p>Some of the types are expected to be mapped in a way so they support the ordering comparison
* operators ("greater than", "less than or equals", etc.). For details, see
* {@link io.spine.client.Filters}.
*/
public abstract class AbstractColumnMapping<R> implements ColumnMapping<R> {

Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/io/spine/server/type/EventClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static EventClass from(TypeUrl typeUrl) {
* <p>Named {@code from} to avoid collision with {@link #of(Message)}.
*/
public static EventClass from(Event event) {
return from(event.typeUrl());
return from(event.enclosedTypeUrl());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private void trace(SignalDispatchedMixin<?> event) {
tracer.processedBy(event.getReceiver(), event.getEntityType());
} catch (Exception e) {
_error().withCause(e)
.log("Error during trace construction on event `%s`.", payload.typeUrl());
.log("Error during trace construction on event `%s`.", payload.enclosedTypeUrl());
}
}
}
2 changes: 1 addition & 1 deletion server/src/test/java/io/spine/server/stand/StandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ void uponEvent() {
.messageId();
assertThat(origin.asCommandId()).isEqualTo(cmd.id());
assertThat(origin.getTypeUrl()).isEqualTo(cmd.command()
.typeUrl()
.enclosedTypeUrl()
.value());
Any packedMessage = event.getMessage();
CustomerCreated eventMessage = unpack(packedMessage, CustomerCreated.class);
Expand Down
46 changes: 38 additions & 8 deletions server/src/test/java/io/spine/server/type/EventClassTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,22 @@
package io.spine.server.type;

import com.google.common.testing.NullPointerTester;
import com.google.protobuf.Any;
import io.spine.core.Event;
import io.spine.protobuf.AnyPacker;
import io.spine.test.core.ProjectCreated;
import io.spine.test.core.ProjectId;
import io.spine.type.TypeUrl;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

import static com.google.common.truth.Truth.assertThat;
import static io.spine.base.Identifier.newUuid;
import static io.spine.testing.DisplayNames.NOT_ACCEPT_NULLS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

@DisplayName("EventClass should")
@DisplayName("`EventClass` should")
class EventClassTest {

@Test
Expand All @@ -41,12 +46,37 @@ void passNullToleranceCheck() {
.testAllPublicStaticMethods(EventClass.class);
}

@Test
@DisplayName("be constructed from TypeUrl instance")
void constructFromTypeUrl() {
TypeUrl typeUrl = TypeUrl.from(ProjectCreated.getDescriptor());
EventClass eventClass = EventClass.from(typeUrl);
assertEquals(ProjectCreated.class, eventClass.value());
@Nested
@DisplayName("be constructed")
class BeConstructed {

@Test
@DisplayName("from `TypeUrl` instance")
void fromTypeUrl() {
TypeUrl typeUrl = TypeUrl.from(ProjectCreated.getDescriptor());
EventClass eventClass = EventClass.from(typeUrl);
assertThat(eventClass.value()).isEqualTo(ProjectCreated.class);
}

@Test
@DisplayName("from `Event` instance")
void fromEvent() {
ProjectId id = ProjectId
.newBuilder()
.setId(newUuid())
.build();
ProjectCreated projectCreated = ProjectCreated
.newBuilder()
.setProjectId(id)
.build();
Any any = AnyPacker.pack(projectCreated);
Event event = Event
.newBuilder()
.setMessage(any)
.build();
EventClass eventClass = EventClass.from(event);
assertThat(eventClass.value()).isEqualTo(ProjectCreated.class);
}
}

@SuppressWarnings({"CheckReturnValue", "ResultOfMethodCallIgnored"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ private void checkRejected(CommandId commandId,
CommandRejected rejected = eventAccumulator.assertReceivedEvent(CommandRejected.class);
assertEquals(commandId, rejected.getId());
Event rejectionEvent = rejected.getRejectionEvent();
TypeUrl rejectionType = rejectionEvent.typeUrl();
TypeUrl rejectionType = rejectionEvent.enclosedTypeUrl();
TypeUrl expectedType = TypeUrl.of(expectedRejectionClass);
assertEquals(expectedType, rejectionType);
}
Expand Down
Loading