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

Remove 'Priority' enum from UCloudAttributes class #38

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

package org.eclipse.uprotocol.cloudevent.datamodel;

import org.eclipse.uprotocol.v1.UPriority;

import java.util.Objects;
import java.util.Optional;

Expand All @@ -35,7 +37,7 @@ public class UCloudEventAttributes {
private static final UCloudEventAttributes EMPTY = new UCloudEventAttributes(null, null, null, null);

private final String hash;
private final Priority priority;
private final UPriority priority;
private final Integer ttl;
private final String token;

Expand All @@ -48,7 +50,7 @@ public class UCloudEventAttributes {
* Events without this attribute (or value is 0) MUST NOT timeout.
* @param token Oauth2 access token to perform the access request defined in the request message.
*/
private UCloudEventAttributes(String hash, Priority priority, Integer ttl, String token) {
private UCloudEventAttributes(String hash, UPriority priority, Integer ttl, String token) {
this.hash = hash;
this.priority = priority;
this.ttl = ttl;
Expand Down Expand Up @@ -91,7 +93,7 @@ public Optional<String> hash() {
* uProtocol Prioritization classifications.
* @return Returns an Optional priority attribute.
*/
public Optional<Priority> priority() {
public Optional<UPriority> priority() {
return priority == null ? Optional.empty() : Optional.of(priority);
}

Expand All @@ -116,7 +118,7 @@ public Optional<String> token() {
*/
public static class UCloudEventAttributesBuilder {
private String hash;
private Priority priority;
private UPriority priority;
private Integer ttl;
private String token;

Expand All @@ -137,7 +139,7 @@ public UCloudEventAttributesBuilder withHash(String hash) {
* @param priority uProtocol Prioritization classifications.
* @return Returns the UCloudEventAttributesBuilder with the configured priority.
*/
public UCloudEventAttributesBuilder withPriority(Priority priority) {
public UCloudEventAttributesBuilder withPriority(UPriority priority) {
this.priority = priority;
return this;
}
Expand Down Expand Up @@ -174,35 +176,6 @@ public UCloudEventAttributes build() {
}
}

/**
* Priority according to SDV 202 Quality of Service (QoS) and Prioritization.
*/
public enum Priority {
// Low Priority. No bandwidth assurance such as File Transfer.
LOW ("CS0"),
// Standard, undifferentiated application such as General (unclassified).
STANDARD ("CS1"),
// Operations, Administration, and Management such as Streamer messages (sub, connect, etc…)
OPERATIONS ("CS2"),
// Multimedia streaming such as Video Streaming
MULTIMEDIA_STREAMING ("CS3"),
// Real-time interactive such as High priority (rpc events)
REALTIME_INTERACTIVE ("CS4"),
// Signaling such as Important
SIGNALING("CS5"),
// Network control such as Safety Critical
NETWORK_CONTROL ("CS6");

private final String qosString;
public String qosString() {
return qosString;
}

Priority(String qosString) {
this.qosString = qosString;
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ static CloudEventBuilder buildBaseCloudEvent(String id, String source,
.withData(protoPayloadBytes);

attributes.ttl().ifPresent(ttl -> cloudEventBuilder.withExtension("ttl", ttl));
attributes.priority().ifPresent(priority -> cloudEventBuilder.withExtension("priority", priority.qosString()));
attributes.priority().ifPresent(priority -> cloudEventBuilder.withExtension("priority",
String.valueOf(priority)));
attributes.hash().ifPresent(hash -> cloudEventBuilder.withExtension("hash", hash));
attributes.token().ifPresent(token -> cloudEventBuilder.withExtension("token", token));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package org.eclipse.uprotocol.cloudevent.datamodel;

import nl.jqno.equalsverifier.EqualsVerifier;
import org.eclipse.uprotocol.v1.UPriority;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

Expand All @@ -43,11 +44,11 @@ public void testHashCodeEquals() {
public void testToString() {
final UCloudEventAttributes uCloudEventAttributes = new UCloudEventAttributes.UCloudEventAttributesBuilder()
.withHash("somehash")
.withPriority(UCloudEventAttributes.Priority.STANDARD)
.withPriority(UPriority.UPRIORITY_CS1)
.withTtl(3)
.withToken("someOAuthToken")
.build();
String expected = "UCloudEventAttributes{hash='somehash', priority=STANDARD, ttl=3, token='someOAuthToken'}";
String expected = "UCloudEventAttributes{hash='somehash', priority=UPRIORITY_CS1, ttl=3, token='someOAuthToken'}";
assertEquals(expected, uCloudEventAttributes.toString());

}
Expand All @@ -57,14 +58,14 @@ public void testToString() {
public void test_create_valid() {
final UCloudEventAttributes uCloudEventAttributes = new UCloudEventAttributes.UCloudEventAttributesBuilder()
.withHash("somehash")
.withPriority(UCloudEventAttributes.Priority.NETWORK_CONTROL)
.withPriority(UPriority.UPRIORITY_CS6)
.withTtl(3)
.withToken("someOAuthToken")
.build();
assertTrue(uCloudEventAttributes.hash().isPresent());
assertEquals("somehash", uCloudEventAttributes.hash().get());
assertTrue(uCloudEventAttributes.priority().isPresent());
assertEquals(UCloudEventAttributes.Priority.NETWORK_CONTROL, uCloudEventAttributes.priority().get());
assertEquals(UPriority.UPRIORITY_CS6, uCloudEventAttributes.priority().get());
assertTrue(uCloudEventAttributes.ttl().isPresent());
assertEquals(3, uCloudEventAttributes.ttl().get());
assertTrue(uCloudEventAttributes.token().isPresent());
Expand Down Expand Up @@ -118,7 +119,7 @@ public void test_Isempty_function_permutations() {
assertFalse(uCloudEventAttributes3.isEmpty());

final UCloudEventAttributes uCloudEventAttributes4 = new UCloudEventAttributes.UCloudEventAttributesBuilder()
.withPriority(UCloudEventAttributes.Priority.LOW)
.withPriority(UPriority.UPRIORITY_CS0)
.build();
assertFalse(uCloudEventAttributes4.isEmpty());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.eclipse.uprotocol.cloudevent.datamodel.UCloudEventType;
import org.eclipse.uprotocol.uri.serializer.LongUriSerializer;
import org.eclipse.uprotocol.v1.UEntity;
import org.eclipse.uprotocol.v1.UPriority;
import org.eclipse.uprotocol.v1.UResource;
import org.eclipse.uprotocol.v1.UUri;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -58,7 +59,7 @@ public void test_create_base_cloud_event() {
// additional attributes
final UCloudEventAttributes uCloudEventAttributes = new UCloudEventAttributes.UCloudEventAttributesBuilder()
.withHash("somehash")
.withPriority(UCloudEventAttributes.Priority.STANDARD)
.withPriority(UPriority.UPRIORITY_CS1)
.withTtl(3)
.withToken("someOAuthToken")
.build();
Expand All @@ -77,7 +78,7 @@ public void test_create_base_cloud_event() {
assertEquals(UCloudEventType.PUBLISH.type(), cloudEvent.getType());
assertFalse(cloudEvent.getExtensionNames().contains("sink"));
assertEquals("somehash", cloudEvent.getExtension("hash"));
assertEquals(UCloudEventAttributes.Priority.STANDARD.qosString(), cloudEvent.getExtension("priority"));
assertEquals(UPriority.UPRIORITY_CS1.name(), cloudEvent.getExtension("priority"));
assertEquals(3, cloudEvent.getExtension("ttl"));
assertEquals("someOAuthToken", cloudEvent.getExtension("token"));

Expand All @@ -96,7 +97,7 @@ public void test_create_base_cloud_event_with_datacontenttype_and_schema() {
// additional attributes
final UCloudEventAttributes uCloudEventAttributes = new UCloudEventAttributes.UCloudEventAttributesBuilder()
.withHash("somehash")
.withPriority(UCloudEventAttributes.Priority.STANDARD)
.withPriority(UPriority.UPRIORITY_CS1)
.withTtl(3)
.withToken("someOAuthToken")
.build();
Expand All @@ -121,7 +122,7 @@ public void test_create_base_cloud_event_with_datacontenttype_and_schema() {
Objects.requireNonNull(cloudEvent.getDataSchema()).toString());
assertFalse(cloudEvent.getExtensionNames().contains("sink"));
assertEquals("somehash", cloudEvent.getExtension("hash"));
assertEquals(UCloudEventAttributes.Priority.STANDARD.qosString(), cloudEvent.getExtension("priority"));
assertEquals(UPriority.UPRIORITY_CS1.name(), cloudEvent.getExtension("priority"));
assertEquals(3, cloudEvent.getExtension("ttl"));
assertEquals("someOAuthToken", cloudEvent.getExtension("token"));

Expand Down Expand Up @@ -174,7 +175,7 @@ public void test_create_publish_cloud_event() {
// additional attributes
final UCloudEventAttributes uCloudEventAttributes = new UCloudEventAttributes.UCloudEventAttributesBuilder()
.withHash("somehash")
.withPriority(UCloudEventAttributes.Priority.STANDARD)
.withPriority(UPriority.UPRIORITY_CS1)
.withTtl(3)
.build();

Expand All @@ -186,7 +187,7 @@ public void test_create_publish_cloud_event() {
assertEquals(UCloudEventType.PUBLISH.type(), cloudEvent.getType());
assertFalse(cloudEvent.getExtensionNames().contains("sink"));
assertEquals("somehash", cloudEvent.getExtension("hash"));
assertEquals(UCloudEventAttributes.Priority.STANDARD.qosString(), cloudEvent.getExtension("priority"));
assertEquals(UPriority.UPRIORITY_CS1.name(), cloudEvent.getExtension("priority"));
assertEquals(3, cloudEvent.getExtension("ttl"));

assertArrayEquals(protoPayload.toByteArray(), Objects.requireNonNull(cloudEvent.getData()).toBytes());
Expand All @@ -208,7 +209,7 @@ public void test_create_notification_cloud_event() {
// additional attributes
final UCloudEventAttributes uCloudEventAttributes = new UCloudEventAttributes.UCloudEventAttributesBuilder()
.withHash("somehash")
.withPriority(UCloudEventAttributes.Priority.OPERATIONS)
.withPriority(UPriority.UPRIORITY_CS2)
.withTtl(3)
.build();

Expand All @@ -224,7 +225,7 @@ public void test_create_notification_cloud_event() {

assertEquals(UCloudEventType.PUBLISH.type(), cloudEvent.getType());
assertEquals("somehash", cloudEvent.getExtension("hash"));
assertEquals(UCloudEventAttributes.Priority.OPERATIONS.qosString(), cloudEvent.getExtension("priority"));
assertEquals(UPriority.UPRIORITY_CS2.name(), cloudEvent.getExtension("priority"));
assertEquals(3, cloudEvent.getExtension("ttl"));

assertArrayEquals(protoPayload.toByteArray(), Objects.requireNonNull(cloudEvent.getData()).toBytes());
Expand All @@ -247,7 +248,7 @@ public void test_create_request_cloud_event_from_local_use() {
// additional attributes
final UCloudEventAttributes uCloudEventAttributes = new UCloudEventAttributes.UCloudEventAttributesBuilder()
.withHash("somehash")
.withPriority(UCloudEventAttributes.Priority.OPERATIONS)
.withPriority(UPriority.UPRIORITY_CS2)
.withTtl(3)
.withToken("someOAuthToken")
.build();
Expand All @@ -264,7 +265,7 @@ public void test_create_request_cloud_event_from_local_use() {

assertEquals("req.v1", cloudEvent.getType());
assertEquals("somehash", cloudEvent.getExtension("hash"));
assertEquals(UCloudEventAttributes.Priority.OPERATIONS.qosString(), cloudEvent.getExtension("priority"));
assertEquals(UPriority.UPRIORITY_CS2.name(), cloudEvent.getExtension("priority"));
assertEquals(3, cloudEvent.getExtension("ttl"));
assertEquals("someOAuthToken", cloudEvent.getExtension("token"));

Expand All @@ -289,7 +290,7 @@ public void test_create_response_cloud_event_originating_from_local_use() {
// additional attributes
final UCloudEventAttributes uCloudEventAttributes = new UCloudEventAttributes.UCloudEventAttributesBuilder()
.withHash("somehash")
.withPriority(UCloudEventAttributes.Priority.OPERATIONS)
.withPriority(UPriority.UPRIORITY_CS2)
.withTtl(3)
.build();

Expand All @@ -305,7 +306,7 @@ public void test_create_response_cloud_event_originating_from_local_use() {

assertEquals("res.v1", cloudEvent.getType());
assertEquals("somehash", cloudEvent.getExtension("hash"));
assertEquals(UCloudEventAttributes.Priority.OPERATIONS.qosString(), cloudEvent.getExtension("priority"));
assertEquals(UPriority.UPRIORITY_CS2.name(), cloudEvent.getExtension("priority"));
assertEquals(3, cloudEvent.getExtension("ttl"));

assertEquals("requestIdFromRequestCloudEvent", cloudEvent.getExtension("reqid"));
Expand All @@ -328,7 +329,7 @@ public void test_create_a_failed_response_cloud_event_originating_from_local_use
// additional attributes
final UCloudEventAttributes uCloudEventAttributes = new UCloudEventAttributes.UCloudEventAttributesBuilder()
.withHash("somehash")
.withPriority(UCloudEventAttributes.Priority.OPERATIONS)
.withPriority(UPriority.UPRIORITY_CS2)
.withTtl(3)
.build();

Expand All @@ -346,7 +347,7 @@ public void test_create_a_failed_response_cloud_event_originating_from_local_use

assertEquals("res.v1", cloudEvent.getType());
assertEquals("somehash", cloudEvent.getExtension("hash"));
assertEquals(UCloudEventAttributes.Priority.OPERATIONS.qosString(), cloudEvent.getExtension("priority"));
assertEquals(UPriority.UPRIORITY_CS2.name(), cloudEvent.getExtension("priority"));
assertEquals(3, cloudEvent.getExtension("ttl"));
assertEquals(Code.INVALID_ARGUMENT_VALUE, cloudEvent.getExtension("commstatus"));

Expand All @@ -368,7 +369,7 @@ public void test_create_a_failed_response_cloud_event_originating_from_remote_us
// additional attributes
final UCloudEventAttributes uCloudEventAttributes = new UCloudEventAttributes.UCloudEventAttributesBuilder()
.withHash("somehash")
.withPriority(UCloudEventAttributes.Priority.OPERATIONS)
.withPriority(UPriority.UPRIORITY_CS2)
.withTtl(3)
.build();

Expand All @@ -386,7 +387,7 @@ public void test_create_a_failed_response_cloud_event_originating_from_remote_us

assertEquals("res.v1", cloudEvent.getType());
assertEquals("somehash", cloudEvent.getExtension("hash"));
assertEquals(UCloudEventAttributes.Priority.OPERATIONS.qosString(), cloudEvent.getExtension("priority"));
assertEquals(UPriority.UPRIORITY_CS2.name(), cloudEvent.getExtension("priority"));
assertEquals(3, cloudEvent.getExtension("ttl"));
assertEquals(Code.INVALID_ARGUMENT_VALUE, cloudEvent.getExtension("commstatus"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@
import org.eclipse.uprotocol.uuid.factory.UuidFactory;
import org.eclipse.uprotocol.uuid.factory.UuidUtils;
import org.eclipse.uprotocol.uuid.serializer.LongUuidSerializer;
import org.eclipse.uprotocol.v1.UEntity;
import org.eclipse.uprotocol.v1.UResource;
import org.eclipse.uprotocol.v1.UUID;
import org.eclipse.uprotocol.v1.UUri;
import org.eclipse.uprotocol.v1.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -154,7 +151,7 @@ public void test_extract_priority_from_cloudevent_when_priority_exists() {

final Optional<String> priority = UCloudEvent.getPriority(cloudEvent);
assertTrue(priority.isPresent());
Assertions.assertEquals(UCloudEventAttributes.Priority.STANDARD.qosString(), priority.get());
Assertions.assertEquals(UPriority.UPRIORITY_CS1.name(), priority.get());
}

@Test
Expand Down Expand Up @@ -667,7 +664,7 @@ private CloudEventBuilder buildBaseCloudEventBuilderForTest() {
// additional attributes
final UCloudEventAttributes uCloudEventAttributes =
new UCloudEventAttributes.UCloudEventAttributesBuilder().withHash(
"somehash").withPriority(UCloudEventAttributes.Priority.STANDARD).withTtl(3).withToken(
"somehash").withPriority(UPriority.UPRIORITY_CS1).withTtl(3).withToken(
"someOAuthToken")
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.eclipse.uprotocol.cloudevent.factory.CloudEventFactory;
import org.eclipse.uprotocol.cloudevent.factory.UCloudEvent;

import org.eclipse.uprotocol.v1.UPriority;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -170,7 +171,7 @@ public void test_double_serialization_protobuf_when_creating_cloud_event_with_fa
// additional attributes
final UCloudEventAttributes uCloudEventAttributes = new UCloudEventAttributes.UCloudEventAttributesBuilder()
.withHash("somehash")
.withPriority(UCloudEventAttributes.Priority.STANDARD)
.withPriority(UPriority.UPRIORITY_CS1)
.withTtl(3)
.withToken("someOAuthToken")
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.eclipse.uprotocol.cloudevent.factory.UCloudEvent;
import org.eclipse.uprotocol.uri.serializer.LongUriSerializer;
import org.eclipse.uprotocol.v1.UEntity;
import org.eclipse.uprotocol.v1.UPriority;
import org.eclipse.uprotocol.v1.UResource;
import org.eclipse.uprotocol.v1.UUri;
import org.junit.jupiter.api.DisplayName;
Expand Down Expand Up @@ -65,7 +66,7 @@ public void test_serialize_and_desirialize_cloud_event_to_protobuf() {
// configure cloud event
final UCloudEventAttributes uCloudEventAttributes = new UCloudEventAttributes.UCloudEventAttributesBuilder()
.withHash("somehash")
.withPriority(UCloudEventAttributes.Priority.LOW)
.withPriority(UPriority.UPRIORITY_CS0)
.withTtl(3)
.build();

Expand Down Expand Up @@ -152,7 +153,7 @@ public void test_double_serialization_protobuf_when_creating_cloud_event_with_fa
// additional attributes
final UCloudEventAttributes uCloudEventAttributes = new UCloudEventAttributes.UCloudEventAttributesBuilder()
.withHash("somehash")
.withPriority(UCloudEventAttributes.Priority.STANDARD)
.withPriority(UPriority.UPRIORITY_CS1)
.withTtl(3)
.withToken("someOAuthToken")
.build();
Expand Down
Loading