From d0da425912ac901c742702d59ba21c22e08d1752 Mon Sep 17 00:00:00 2001 From: Keyi Xing Date: Mon, 11 Mar 2024 10:57:32 -0400 Subject: [PATCH] Remove Optional as Kotlin is null-safe --- .../datamodel/UCloudEventAttributes.kt | 65 ++---- .../cloudevent/factory/CloudEventFactory.kt | 11 +- .../cloudevent/factory/UCloudEvent.kt | 135 ++++++------ .../validate/CloudEventValidator.kt | 99 ++++----- .../uri/serializer/LongUriSerializer.kt | 25 +-- .../uri/serializer/MicroUriSerializer.kt | 46 ++-- .../uprotocol/uri/serializer/UriSerializer.kt | 23 +- .../uprotocol/uuid/factory/UuidUtils.kt | 2 +- .../datamodel/UCloudEventAttributesTest.kt | 38 ++-- .../factory/CloudEventFactoryTest.kt | 2 +- .../cloudevent/factory/UCloudEventTest.kt | 139 +++++------- .../CloudEventToProtobufSerializerTest.kt | 2 +- .../validate/CloudEventValidatorTest.kt | 2 +- .../org/eclipse/uprotocol/rpc/RpcTest.kt | 2 +- .../validator/UAttributesValidatorTest.kt | 16 +- .../uri/serializer/LongUriSerializerTest.kt | 201 ++++++++---------- .../uri/serializer/MicroUriSerializerTest.kt | 55 ++--- .../uri/serializer/UriSerializerTest.kt | 44 ++-- .../uri/validator/UriValidatorTest.kt | 111 +++++----- 19 files changed, 436 insertions(+), 582 deletions(-) diff --git a/src/main/kotlin/org/eclipse/uprotocol/cloudevent/datamodel/UCloudEventAttributes.kt b/src/main/kotlin/org/eclipse/uprotocol/cloudevent/datamodel/UCloudEventAttributes.kt index c161036..8a78955 100644 --- a/src/main/kotlin/org/eclipse/uprotocol/cloudevent/datamodel/UCloudEventAttributes.kt +++ b/src/main/kotlin/org/eclipse/uprotocol/cloudevent/datamodel/UCloudEventAttributes.kt @@ -25,78 +25,45 @@ package org.eclipse.uprotocol.cloudevent.datamodel import org.eclipse.uprotocol.v1.UPriority -import java.util.* /** * Specifies the properties that can configure the UCloudEvent. - * @param hash an HMAC generated on the data portion of the CloudEvent message using the device key. + * @param hash An HMAC generated on the data portion of the CloudEvent message using the device key. * @param priority uProtocol Prioritization classifications. * @param ttl How long this event should live for after it was generated (in milliseconds). * 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. + * @param traceparent An identifier used to correlate observability across related events. */ data class UCloudEventAttributes internal constructor( - private val hash: String? = null, - private val priority: UPriority? = null, - private val ttl: Int? = null, - private val token: String? = null, - private val traceparent: String? = null + val hash: String? = null, + val priority: UPriority? = null, + val ttl: Int? = null, + val token: String? = null, + val traceparent: String? = null ) { private constructor(builder: UCloudEventAttributesBuilder) : this( - builder.hash, + if (builder.hash.isNullOrBlank()) null else builder.hash, builder.priority, builder.ttl, - builder.token, + if (builder.token.isNullOrBlank()) null else builder.token, builder.traceparent ) + /** + * An HMAC generated on the data portion of the CloudEvent message using the device key. + */ val isEmpty: Boolean /** * Indicates that there are no added additional attributes to configure when building a CloudEvent. * @return Returns true if this attributes container is an empty container and has no valuable information in building a CloudEvent. */ - get() = hash().isEmpty && priority().isEmpty && ttl().isEmpty && token().isEmpty && traceparent().isEmpty - - /** - * An HMAC generated on the data portion of the CloudEvent message using the device key. - * @return Returns an Optional hash attribute. - */ - fun hash(): Optional { - return if (hash.isNullOrBlank()) Optional.empty() else Optional.of(hash) - } + get() = hash == null && priority == null && ttl == null && token == null && traceparent == null - /** - * uProtocol Prioritization classifications. - * @return Returns an Optional priority attribute. - */ - fun priority(): Optional { - return if (priority == null) Optional.empty() else Optional.of(priority) - } - /** - * How long this event should live for after it was generated (in milliseconds). - * @return Returns an Optional time to live attribute. - */ - fun ttl(): Optional { - return if (ttl == null) Optional.empty() else Optional.of(ttl) - } - - /** - * Oauth2 access token to perform the access request defined in the request message. - * @return Returns an Optional OAuth token attribute. - */ - fun token(): Optional { - return if (token.isNullOrBlank()) Optional.empty() else Optional.of(token) - } - - - /** - * An identifier used to correlate observability across related events. - * @return Returns an Optional traceparent attribute. - */ - fun traceparent(): Optional { - return if (traceparent.isNullOrBlank()) Optional.empty() else Optional.of(traceparent) - } +// fun getSafeHash():String?{ +// return if (hash.isNullOrBlank()) null else hash +// } /** * Builder for constructing the UCloudEventAttributes. diff --git a/src/main/kotlin/org/eclipse/uprotocol/cloudevent/factory/CloudEventFactory.kt b/src/main/kotlin/org/eclipse/uprotocol/cloudevent/factory/CloudEventFactory.kt index 81ae850..5fe6a6c 100644 --- a/src/main/kotlin/org/eclipse/uprotocol/cloudevent/factory/CloudEventFactory.kt +++ b/src/main/kotlin/org/eclipse/uprotocol/cloudevent/factory/CloudEventFactory.kt @@ -208,12 +208,11 @@ object CloudEventFactory { .withDataSchema(URI.create(protoPayloadSchema)) */ .withData(protoPayloadBytes) - attributes.ttl().ifPresent { ttl -> cloudEventBuilder.withExtension("ttl", ttl) } - attributes.priority() - .ifPresent { priority -> cloudEventBuilder.withExtension("priority", priority.toString()) } - attributes.hash().ifPresent { hash -> cloudEventBuilder.withExtension("hash", hash) } - attributes.token().ifPresent { token -> cloudEventBuilder.withExtension("token", token) } - attributes.traceparent().ifPresent { traceparent: String -> + attributes.ttl?.let { ttl -> cloudEventBuilder.withExtension("ttl", ttl) } + attributes.priority?.let { priority -> cloudEventBuilder.withExtension("priority", priority.toString()) } + attributes.hash?.let { hash -> cloudEventBuilder.withExtension("hash", hash) } + attributes.token?.let { token -> cloudEventBuilder.withExtension("token", token) } + attributes.traceparent?.let { traceparent: String -> cloudEventBuilder.withExtension("traceparent", traceparent) } diff --git a/src/main/kotlin/org/eclipse/uprotocol/cloudevent/factory/UCloudEvent.kt b/src/main/kotlin/org/eclipse/uprotocol/cloudevent/factory/UCloudEvent.kt index a031a45..944a662 100644 --- a/src/main/kotlin/org/eclipse/uprotocol/cloudevent/factory/UCloudEvent.kt +++ b/src/main/kotlin/org/eclipse/uprotocol/cloudevent/factory/UCloudEvent.kt @@ -41,8 +41,6 @@ import org.eclipse.uprotocol.v1.UUID import java.net.URI import java.time.OffsetDateTime import java.time.temporal.ChronoUnit -import java.util.* - /** * Class to extract information from a CloudEvent. @@ -61,60 +59,60 @@ object UCloudEvent { /** * Extract the sink from a cloud event. The sink attribute is optional. * @param cloudEvent CloudEvent with sink to be extracted. - * @return Returns an Optional String value of a CloudEvent sink attribute if it exists, - * otherwise an Optional.empty() is returned. + * @return Returns a String value of a CloudEvent sink attribute if it exists, + * otherwise Null is returned. */ - fun getSink(cloudEvent: CloudEvent): Optional { + fun getSink(cloudEvent: CloudEvent): String? { return extractStringValueFromExtension("sink", cloudEvent) } /** * Extract the request id from a cloud event that is a response RPC CloudEvent. The attribute is optional. * @param cloudEvent the response RPC CloudEvent with request id to be extracted. - * @return Returns an Optional String value of a response RPC CloudEvent request id attribute if it exists, - * otherwise an Optional.empty() is returned. + * @return Returns a String value of a response RPC CloudEvent request id attribute if it exists, + * otherwise Null is returned. */ - fun getRequestId(cloudEvent: CloudEvent): Optional { + fun getRequestId(cloudEvent: CloudEvent): String? { return extractStringValueFromExtension("reqid", cloudEvent) } /** * Extract the hash attribute from a cloud event. The hash attribute is optional. * @param cloudEvent CloudEvent with hash to be extracted. - * @return Returns an Optional String value of a CloudEvent hash attribute if it exists, - * otherwise an Optional.empty() is returned. + * @return Returns a String value of a CloudEvent hash attribute if it exists, + * otherwise Null is returned. */ - fun getHash(cloudEvent: CloudEvent): Optional { + fun getHash(cloudEvent: CloudEvent): String? { return extractStringValueFromExtension("hash", cloudEvent) } /** * Extract the string value of the priority attribute from a cloud event. The priority attribute is optional. * @param cloudEvent CloudEvent with priority to be extracted. - * @return Returns an Optional String value of a CloudEvent priority attribute if it exists, - * otherwise an Optional.empty() is returned. + * @return Returns a String value of a CloudEvent priority attribute if it exists, + * otherwise Null is returned. */ - fun getPriority(cloudEvent: CloudEvent): Optional { + fun getPriority(cloudEvent: CloudEvent): String? { return extractStringValueFromExtension("priority", cloudEvent) } /** * Extract the integer value of the ttl attribute from a cloud event. The ttl attribute is optional. * @param cloudEvent CloudEvent with ttl to be extracted. - * @return Returns an Optional String value of a CloudEvent ttl attribute if it exists, - * otherwise an Optional.empty() is returned. + * @return Returns an Int value of a CloudEvent ttl attribute if it exists, + * otherwise Null is returned. */ - fun getTtl(cloudEvent: CloudEvent): Optional { - return extractStringValueFromExtension("ttl", cloudEvent).map(Integer::valueOf) + fun getTtl(cloudEvent: CloudEvent): Int? { + return extractStringValueFromExtension("ttl", cloudEvent)?.toInt() } /** * Extract the string value of the token attribute from a cloud event. The token attribute is optional. * @param cloudEvent CloudEvent with token to be extracted. - * @return Returns an Optional String value of a CloudEvent priority token if it exists, - * otherwise an Optional.empty() is returned. + * @return Returns a String value of a CloudEvent priority token if it exists, + * otherwise Null is returned. */ - fun getToken(cloudEvent: CloudEvent): Optional { + fun getToken(cloudEvent: CloudEvent): String? { return extractStringValueFromExtension("token", cloudEvent) } @@ -122,10 +120,10 @@ object UCloudEvent { /** * Extract the string value of the trafceparent attribute from a cloud event. The traceparent attribute is optional. * @param cloudEvent CloudEvent with traceparent to be extracted. - * @return Returns an Optional String value of a CloudEvent traceparent if it exists, - * otherwise an Optional.empty() is returned. + * @return Returns a String value of a CloudEvent traceparent if it exists, + * otherwise Null is returned. */ - fun getTraceparent(cloudEvent: CloudEvent): Optional { + fun getTraceparent(cloudEvent: CloudEvent): String? { return extractStringValueFromExtension("traceparent", cloudEvent) } @@ -138,7 +136,7 @@ object UCloudEvent { */ fun getCommunicationStatus(cloudEvent: CloudEvent): Int { return try { - extractIntegerValueFromExtension("commstatus", cloudEvent).orElse(UCode.OK_VALUE) + extractIntegerValueFromExtension("commstatus", cloudEvent)?:UCode.OK_VALUE } catch (e: Exception) { UCode.OK_VALUE } @@ -171,12 +169,12 @@ object UCloudEvent { /** * Extract the timestamp from the UUIDV8 CloudEvent ID, with Unix epoch as the * @param cloudEvent The CloudEvent with the timestamp to extract. - * @return Return the timestamp from the UUIDV8 CloudEvent ID or an empty Optional if timestamp can't be extracted. + * @return Return the timestamp from the UUIDV8 CloudEvent ID or a Null if timestamp can't be extracted. */ - fun getCreationTimestamp(cloudEvent: CloudEvent): Optional { + fun getCreationTimestamp(cloudEvent: CloudEvent): Long? { val cloudEventId = cloudEvent.id val uuid = LongUuidSerializer.INSTANCE.deserialize(cloudEventId) - return Optional.ofNullable(uuid.getTime()) + return uuid.getTime() } /** @@ -186,11 +184,7 @@ object UCloudEvent { * @return Returns true if the CloudEvent was configured with a ttl > 0 and a creation time to compare for expiration. */ fun isExpiredByCloudEventCreationDate(cloudEvent: CloudEvent): Boolean { - val maybeTtl: Optional = getTtl(cloudEvent) - if (maybeTtl.isEmpty) { - return false - } - val ttl: Int = maybeTtl.get() + val ttl = getTtl(cloudEvent) ?: return false if (ttl <= 0) { return false } @@ -207,11 +201,7 @@ object UCloudEvent { * @return Returns true if the CloudEvent was configured with a ttl > 0 and UUIDv8 id to compare for expiration. */ fun isExpired(cloudEvent: CloudEvent): Boolean { - val maybeTtl: Optional = getTtl(cloudEvent) - if (maybeTtl.isEmpty) { - return false - } - val ttl: Int = maybeTtl.get() + val ttl = getTtl(cloudEvent) ?: return false if (ttl <= 0) { return false } @@ -220,7 +210,7 @@ object UCloudEvent { if (uuid == UUID.getDefaultInstance()) { return false } - val delta: Long = System.currentTimeMillis() - (uuid.getTime()?:0L) + val delta: Long = System.currentTimeMillis() - (uuid.getTime() ?: 0L) return delta >= ttl } @@ -253,20 +243,20 @@ object UCloudEvent { /** * Extract the payload from the CloudEvent as a protobuf Message of the provided class. The protobuf of this message * class must be loaded on the client for this to work.

- * An all or nothing error handling strategy is implemented. If anything goes wrong, an empty optional will be returned.

+ * An all or nothing error handling strategy is implemented. If anything goes wrong, a Null will be returned.

* Example:

- *
Optional<SomeMessage> unpacked = UCloudEvent.unpack(cloudEvent, SomeMessage.class);
+ *
SomeMessage; unpacked = UCloudEvent.unpack(cloudEvent, SomeMessage::class.java);
* @param cloudEvent CloudEvent containing the payload to extract. * @param clazz The class that extends [Message] that the payload is extracted into. * @return Returns a [Message] payload of the class type that is provided. * @param The class type of the Message to be unpacked. */ - fun unpack(cloudEvent: CloudEvent, clazz: Class): Optional { + fun unpack(cloudEvent: CloudEvent, clazz: Class): T? { return try { - Optional.of(getPayload(cloudEvent).unpack(clazz)) + getPayload(cloudEvent).unpack(clazz) } catch (e: InvalidProtocolBufferException) { // All or nothing error handling strategy. If something goes wrong, you just get an empty. - Optional.empty() + null } } @@ -275,41 +265,38 @@ object UCloudEvent { * @param cloudEvent The CloudEvent we want to pretty print. * @return returns the String representation of the CloudEvent containing only the id, source, type and maybe a sink. */ - fun toString(cloudEvent: CloudEvent?): String { - return if (cloudEvent != null) { - "CloudEvent{id='" + cloudEvent.id + "', source='" + cloudEvent.source + "'" + getSink( - cloudEvent - ).map { sink -> String.format(", sink='%s'", sink) }.orElse("") + ", type='" + cloudEvent.type + "'}" - } else "null" + fun toString(cloudEvent: CloudEvent): String { + val sink = getSink(cloudEvent)?.let { ", sink='$it'" } ?: "" + return "CloudEvent{id='${cloudEvent.id}', source='${cloudEvent.source}'${sink}, type='${cloudEvent.type}'}" + } /** * Utility for extracting the String value of an extension. * @param extensionName The name of the CloudEvent extension. * @param cloudEvent The CloudEvent containing the data. - * @return returns the Optional String value of the extension matching the extension name, - * or an Optional.empty() is the value does not exist. + * @return returns the String value of the extension matching the extension name, + * or a Null is the value does not exist. */ - private fun extractStringValueFromExtension(extensionName: String, cloudEvent: CloudEvent): Optional { - val extensionNames: MutableSet? = cloudEvent.extensionNames - if (extensionNames != null) { - if (extensionNames.contains(extensionName)) { - val extension: kotlin.Any? = cloudEvent.getExtension(extensionName) - return if (extension == null) Optional.empty() else Optional.of(extension.toString()) + private fun extractStringValueFromExtension(extensionName: String, cloudEvent: CloudEvent): String? { + return cloudEvent.extensionNames?.let { + if (it.contains(extensionName)) { + cloudEvent.getExtension(extensionName)?.toString() + } else { + null } } - return Optional.empty() } /** * Utility for extracting the Integer value of an extension. * @param extensionName The name of the CloudEvent extension. * @param cloudEvent The CloudEvent containing the data. - * @return returns the Optional Integer value of the extension matching the extension name, - * or an Optional.empty() is the value does not exist. + * @return returns the Integer value of the extension matching the extension name, + * or a Null is the value does not exist. */ - private fun extractIntegerValueFromExtension(extensionName: String, cloudEvent: CloudEvent): Optional { - return extractStringValueFromExtension(extensionName, cloudEvent).map(Integer::valueOf) + private fun extractIntegerValueFromExtension(extensionName: String, cloudEvent: CloudEvent): Int? { + return extractStringValueFromExtension(extensionName, cloudEvent)?.toInt() } /** @@ -355,28 +342,28 @@ object UCloudEvent { val msgAttributes = uAttributes { id = LongUuidSerializer.INSTANCE.deserialize(event.id) type = getMessageType(event.type) - source = LongUriSerializer.instance().deserialize(event.source.toString()) + source = LongUriSerializer.INSTANCE.deserialize(event.source.toString()) if (hasCommunicationStatusProblem(event)) { commstatus = getCommunicationStatus(event) } - getPriority(event).ifPresent { + getPriority(event)?.let { val adjustedPriority = if (it.startsWith("UPRIORITY_")) it else "UPRIORITY_$it" priority = UPriority.valueOf(adjustedPriority) } - getSink(event).ifPresent { sink = LongUriSerializer.instance().deserialize(it) } + getSink(event)?.let { sink = LongUriSerializer.INSTANCE.deserialize(it) } - getRequestId(event).ifPresent { reqid = LongUuidSerializer.INSTANCE.deserialize(it) } + getRequestId(event)?.let { reqid = LongUuidSerializer.INSTANCE.deserialize(it) } - getTtl(event).ifPresent { ttl = it } + getTtl(event)?.let { ttl = it } - getToken(event).ifPresent { token = it } + getToken(event)?.let { token = it } - getTraceparent(event).ifPresent { traceparent = it } + getTraceparent(event)?.let { traceparent = it } - extractIntegerValueFromExtension("plevel", event).ifPresent { permissionLevel = it } + extractIntegerValueFromExtension("plevel", event)?.let { permissionLevel = it } } return uMessage { @@ -398,7 +385,7 @@ object UCloudEvent { val builder: CloudEventBuilder = CloudEventBuilder.v1().withId(LongUuidSerializer.INSTANCE.serialize(attributes.id)) builder.withType(getEventType(attributes.type)) - builder.withSource(URI.create(LongUriSerializer.instance().serialize(attributes.source))) + builder.withSource(URI.create(LongUriSerializer.INSTANCE.serialize(attributes.source))) val contentType = getContentTypeFromUPayloadFormat(payload.format) if (contentType.isNotEmpty()) { builder.withDataContentType(contentType) @@ -420,7 +407,7 @@ object UCloudEvent { } if (attributes.hasSink()) { - builder.withExtension("sink", URI.create(LongUriSerializer.instance().serialize(attributes.sink))) + builder.withExtension("sink", URI.create(LongUriSerializer.INSTANCE.serialize(attributes.sink))) } if (attributes.hasCommstatus()) { @@ -459,7 +446,7 @@ object UCloudEvent { .getExtension(UprotocolOptions.mimeType) == contentType }.map { v: EnumValueDescriptor -> UPayloadFormat.forNumber(v.number) - }.firstOrNull()?:UPayloadFormat.UPAYLOAD_FORMAT_PROTOBUF_WRAPPED_IN_ANY + }.firstOrNull() ?: UPayloadFormat.UPAYLOAD_FORMAT_PROTOBUF_WRAPPED_IN_ANY } /** diff --git a/src/main/kotlin/org/eclipse/uprotocol/cloudevent/validate/CloudEventValidator.kt b/src/main/kotlin/org/eclipse/uprotocol/cloudevent/validate/CloudEventValidator.kt index 46a3028..cd27da8 100644 --- a/src/main/kotlin/org/eclipse/uprotocol/cloudevent/validate/CloudEventValidator.kt +++ b/src/main/kotlin/org/eclipse/uprotocol/cloudevent/validate/CloudEventValidator.kt @@ -31,7 +31,6 @@ import org.eclipse.uprotocol.uri.serializer.LongUriSerializer import org.eclipse.uprotocol.uri.validator.isRpcMethod import org.eclipse.uprotocol.uri.validator.validate import org.eclipse.uprotocol.v1.* -import java.util.Optional /** * Validates a CloudEvent using google.grpc.Status

@@ -114,12 +113,11 @@ abstract class CloudEventValidator { } override fun validateSink(cloudEvent: CloudEvent): ValidationResult { - val maybeSink: Optional = UCloudEvent.getSink(cloudEvent) - if (maybeSink.isPresent) { - val sink: String = maybeSink.get() + var result: ValidationResult = ValidationResult.success() + UCloudEvent.getSink(cloudEvent)?.let { sink -> val checkSink: ValidationResult = validateUEntityUri(sink) if (checkSink.isFailure()) { - return ValidationResult.failure( + result = ValidationResult.failure( String.format( "Invalid CloudEvent sink [%s]. %s", sink, @@ -128,7 +126,7 @@ abstract class CloudEventValidator { ) } } - return ValidationResult.success() + return result } @@ -144,21 +142,17 @@ abstract class CloudEventValidator { private class Notification : Publish() { override fun validateSink(cloudEvent: CloudEvent): ValidationResult { - val maybeSink: Optional = UCloudEvent.getSink(cloudEvent) - if (maybeSink.isEmpty) { - return ValidationResult.failure("Invalid CloudEvent sink. Notification CloudEvent sink must be an uri.") - } else { - val sink: String = maybeSink.get() - val checkSink: ValidationResult = validateUEntityUri(sink) - if (checkSink.isFailure()) { - return ValidationResult.failure( - String.format( - "Invalid Notification type CloudEvent sink [%s]. %s", - sink, - checkSink.getMessage() - ) + val sink: String = UCloudEvent.getSink(cloudEvent) + ?: return ValidationResult.failure("Invalid CloudEvent sink. Notification CloudEvent sink must be an uri.") + val checkSink: ValidationResult = validateUEntityUri(sink) + if (checkSink.isFailure()) { + return ValidationResult.failure( + String.format( + "Invalid Notification type CloudEvent sink [%s]. %s", + sink, + checkSink.getMessage() ) - } + ) } return ValidationResult.success() } @@ -189,21 +183,17 @@ abstract class CloudEventValidator { override fun validateSink(cloudEvent: CloudEvent): ValidationResult { - val maybeSink: Optional = UCloudEvent.getSink(cloudEvent) - if (maybeSink.isEmpty) { - return ValidationResult.failure("Invalid RPC Request CloudEvent sink. Request CloudEvent sink must be uri for the method to be called.") - } else { - val sink: String = maybeSink.get() - val checkSink: ValidationResult = validateRpcMethod(sink) - if (checkSink.isFailure()) { - return ValidationResult.failure( - String.format( - "Invalid RPC Request CloudEvent sink [%s]. %s", - sink, - checkSink.getMessage() - ) + val sink: String = UCloudEvent.getSink(cloudEvent) + ?: return ValidationResult.failure("Invalid RPC Request CloudEvent sink. Request CloudEvent sink must be uri for the method to be called.") + val checkSink: ValidationResult = validateRpcMethod(sink) + if (checkSink.isFailure()) { + return ValidationResult.failure( + String.format( + "Invalid RPC Request CloudEvent sink [%s]. %s", + sink, + checkSink.getMessage() ) - } + ) } return ValidationResult.success() } @@ -241,21 +231,18 @@ abstract class CloudEventValidator { } override fun validateSink(cloudEvent: CloudEvent): ValidationResult { - val maybeSink: Optional = UCloudEvent.getSink(cloudEvent) - if (maybeSink.isEmpty) { - return ValidationResult.failure("Invalid CloudEvent sink. Response CloudEvent sink must be uri the destination of the response.") - } else { - val sink: String = maybeSink.get() - val checkSink: ValidationResult = validateRpcTopicUri(sink) - if (checkSink.isFailure()) { - return ValidationResult.failure( - String.format( - "Invalid RPC Response CloudEvent sink [%s]. %s", - sink, - checkSink.getMessage() - ) + val sink: String = UCloudEvent.getSink(cloudEvent) + ?: return ValidationResult.failure("Invalid CloudEvent sink. Response CloudEvent sink must be uri the destination of the response.") + val checkSink: ValidationResult = validateRpcTopicUri(sink) + if (checkSink.isFailure()) { + return ValidationResult.failure( + String.format( + "Invalid RPC Response CloudEvent sink [%s]. %s", + sink, + checkSink.getMessage() ) - } + ) + } return ValidationResult.success() } @@ -318,8 +305,8 @@ abstract class CloudEventValidator { * @param uuri uri string to validate. * @return Returns the ValidationResult containing a success or a failure with the error message. */ - fun validateUEntityUri(uuri: String?): ValidationResult { - val uri: UUri = LongUriSerializer.instance().deserialize(uuri) + fun validateUEntityUri(uuri: String): ValidationResult { + val uri: UUri = LongUriSerializer.INSTANCE.deserialize(uuri) return validateUEntityUri(uri) } @@ -332,8 +319,8 @@ abstract class CloudEventValidator { * @param uuri String UriPart to validate. * @return Returns the ValidationResult containing a success or a failure with the error message. */ - fun validateTopicUri(uuri: String?): ValidationResult { - val uri: UUri = LongUriSerializer.instance().deserialize(uuri) + fun validateTopicUri(uuri: String): ValidationResult { + val uri: UUri = LongUriSerializer.INSTANCE.deserialize(uuri) return validateTopicUri(uri) } @@ -362,8 +349,8 @@ abstract class CloudEventValidator { * @param uuri String UriPart to validate. * @return Returns the ValidationResult containing a success or a failure with the error message. */ - fun validateRpcTopicUri(uuri: String?): ValidationResult { - val uri: UUri = LongUriSerializer.instance().deserialize(uuri) + fun validateRpcTopicUri(uuri: String): ValidationResult { + val uri: UUri = LongUriSerializer.INSTANCE.deserialize(uuri) return validateRpcTopicUri(uri) } @@ -394,8 +381,8 @@ abstract class CloudEventValidator { * @param uuri String UriPart to validate. * @return Returns the ValidationResult containing a success or a failure with the error message. */ - fun validateRpcMethod(uuri: String?): ValidationResult { - val uri: UUri = LongUriSerializer.instance().deserialize(uuri) + fun validateRpcMethod(uuri: String): ValidationResult { + val uri: UUri = LongUriSerializer.INSTANCE.deserialize(uuri) val validationResult: ValidationResult = validateUEntityUri(uri) if (validationResult.isFailure()) { return ValidationResult.failure( diff --git a/src/main/kotlin/org/eclipse/uprotocol/uri/serializer/LongUriSerializer.kt b/src/main/kotlin/org/eclipse/uprotocol/uri/serializer/LongUriSerializer.kt index 6e7a4e4..be0be1b 100644 --- a/src/main/kotlin/org/eclipse/uprotocol/uri/serializer/LongUriSerializer.kt +++ b/src/main/kotlin/org/eclipse/uprotocol/uri/serializer/LongUriSerializer.kt @@ -26,7 +26,6 @@ package org.eclipse.uprotocol.uri.serializer import org.eclipse.uprotocol.uri.validator.isEmpty import org.eclipse.uprotocol.v1.* -import java.util.* /** * UUri Serializer that serializes a UUri to a long format string per @@ -38,8 +37,8 @@ class LongUriSerializer private constructor() : UriSerializer { * @param uri [UUri] object to be serialized to the String format. * @return Returns the String format of the supplied [UUri] that can be used as a sink or a source in a uProtocol publish communication. */ - override fun serialize(uri: UUri?): String { - if (uri == null || uri.isEmpty()) { + override fun serialize(uri: UUri): String { + if (uri.isEmpty()) { return "" } val sb = StringBuilder() @@ -58,8 +57,8 @@ class LongUriSerializer private constructor() : UriSerializer { * @return Returns an UUri data object. */ - override fun deserialize(uri: String?): UUri { - if (uri.isNullOrBlank()) { + override fun deserialize(uri: String): UUri { + if (uri.isBlank()) { return UUri.getDefaultInstance() } val uuri: String = if (uri.contains(":")) uri.substring(uri.indexOf(":") + 1) else uri.replace('\\', '/') @@ -124,10 +123,7 @@ class LongUriSerializer private constructor() : UriSerializer { } companion object { - private val INSTANCE = LongUriSerializer() - fun instance(): LongUriSerializer { - return INSTANCE - } + val INSTANCE = LongUriSerializer() private fun buildResourcePartOfUri(uri: UUri): String { if (!uri.hasResource()) { @@ -164,12 +160,10 @@ class LongUriSerializer private constructor() : UriSerializer { * @return Returns the String representation of the Authority in the uProtocol URI. */ private fun buildAuthorityPartOfUri(uAuthority: UAuthority): String { - val partialURI = StringBuilder("//") - val maybeName: Optional = Optional.ofNullable(uAuthority.name) - if (maybeName.isPresent) { - partialURI.append(maybeName.get()) - } - return partialURI.toString() + val partialURI = "//" + return uAuthority.name?.let { + "$partialURI$it" + } ?: partialURI } /** @@ -179,7 +173,6 @@ class LongUriSerializer private constructor() : UriSerializer { * @return Returns a UResource object. */ private fun parseFromString(resourceString: String): UResource { - Objects.requireNonNull(resourceString, " Resource must have a command name.") val parts: List = removeEmpty(resourceString.split("#")) val nameAndInstance = parts[0] val nameAndInstanceParts: List = removeEmpty(nameAndInstance.split(".")) diff --git a/src/main/kotlin/org/eclipse/uprotocol/uri/serializer/MicroUriSerializer.kt b/src/main/kotlin/org/eclipse/uprotocol/uri/serializer/MicroUriSerializer.kt index e63e7c6..33269fe 100644 --- a/src/main/kotlin/org/eclipse/uprotocol/uri/serializer/MicroUriSerializer.kt +++ b/src/main/kotlin/org/eclipse/uprotocol/uri/serializer/MicroUriSerializer.kt @@ -30,7 +30,6 @@ import org.eclipse.uprotocol.uri.validator.isMicroForm import org.eclipse.uprotocol.v1.* import java.io.ByteArrayOutputStream import java.io.IOException -import java.util.* /** * UUri Serializer that serializes a UUri to a byte[] (micro format) per @@ -48,8 +47,10 @@ class MicroUriSerializer private constructor() : UriSerializer { } companion object { - fun from(value: Int): Optional { - return Arrays.stream(entries.toTypedArray()).filter { p -> p.getValue().toInt() == value }.findAny() + fun from(value: Int): AddressType? { + return entries.toTypedArray().firstOrNull { + it.value == value + } } } } @@ -59,12 +60,12 @@ class MicroUriSerializer private constructor() : UriSerializer { * @param uri The [UUri] data object. * @return Returns a byte[] representing the serialized [UUri]. */ - override fun serialize(uri: UUri?): ByteArray { - if (uri == null || uri.isEmpty() || !uri.isMicroForm()) { + override fun serialize(uri: UUri): ByteArray { + if (uri.isEmpty() || !uri.isMicroForm()) { return ByteArray(0) } - val maybeUeId: Optional = Optional.ofNullable(uri.entity.id) - val maybeUResourceId: Optional = Optional.ofNullable(uri.resource.id) + val uEId = uri.entity.id + val uResourceId = uri.resource.id val os = ByteArrayOutputStream() // UP_VERSION os.write(UP_VERSION.toInt()) @@ -74,9 +75,11 @@ class MicroUriSerializer private constructor() : UriSerializer { 4 -> { AddressType.IPv4 } + 16 -> { AddressType.IPv6 } + else -> { return ByteArray(0) } @@ -90,12 +93,12 @@ class MicroUriSerializer private constructor() : UriSerializer { os.write(type.getValue().toInt()) // URESOURCE_ID - os.write(maybeUResourceId.get() shr 8) - os.write(maybeUResourceId.get()) + os.write(uResourceId shr 8) + os.write(uResourceId) // UENTITY_ID - os.write(maybeUeId.get() shr 8) - os.write(maybeUeId.get()) + os.write(uEId shr 8) + os.write(uEId) // UE_VERSION os.write((if (uri.entity.versionMajor == 0) 0.toByte() else uri.entity.versionMajor).toInt()) @@ -103,7 +106,6 @@ class MicroUriSerializer private constructor() : UriSerializer { // UNUSED os.write(0.toByte().toInt()) - // Populating the UAuthority if (type != AddressType.LOCAL) { @@ -130,8 +132,8 @@ class MicroUriSerializer private constructor() : UriSerializer { * @param uri A byte[] uProtocol micro URI. * @return Returns an [UUri] data object from the serialized format of a microUri. */ - override fun deserialize(uri: ByteArray?): UUri { - if (uri == null || uri.size < LOCAL_MICRO_URI_LENGTH) { + override fun deserialize(uri: ByteArray): UUri { + if (uri.size < LOCAL_MICRO_URI_LENGTH) { return UUri.getDefaultInstance() } @@ -140,17 +142,12 @@ class MicroUriSerializer private constructor() : UriSerializer { return UUri.getDefaultInstance() } val uResourceId = uri[2].toInt() and 0xFF shl 8 or (uri[3].toInt() and 0xFF) - val type: Optional = AddressType.from( - uri[1].toInt() - ) + val type: AddressType = AddressType.from(uri[1].toInt()) ?: return UUri.getDefaultInstance() // Validate Type is found - if (type.isEmpty) { - return UUri.getDefaultInstance() - } // Validate that the microUri is the correct length for the type - val addressType: AddressType = type.get() + val addressType: AddressType = type if (addressType == AddressType.LOCAL && uri.size != LOCAL_MICRO_URI_LENGTH) { return UUri.getDefaultInstance() } else if (addressType == AddressType.IPv4 && uri.size != IPV4_MICRO_URI_LENGTH) { @@ -193,7 +190,7 @@ class MicroUriSerializer private constructor() : UriSerializer { id = ueId versionMajor = uiVersion } - resource = uResource{ + resource = uResource { from(uResourceId) } uAuthority?.let { authority = it } @@ -205,9 +202,6 @@ class MicroUriSerializer private constructor() : UriSerializer { const val IPV4_MICRO_URI_LENGTH = 12 // IPv4 micro URI length const val IPV6_MICRO_URI_LENGTH = 24 // IPv6 micro UriPart length const val UP_VERSION: Byte = 0x1 // UP version - private val INSTANCE = MicroUriSerializer() - fun instance(): MicroUriSerializer { - return INSTANCE - } + val INSTANCE = MicroUriSerializer() } } diff --git a/src/main/kotlin/org/eclipse/uprotocol/uri/serializer/UriSerializer.kt b/src/main/kotlin/org/eclipse/uprotocol/uri/serializer/UriSerializer.kt index 9113789..535d315 100644 --- a/src/main/kotlin/org/eclipse/uprotocol/uri/serializer/UriSerializer.kt +++ b/src/main/kotlin/org/eclipse/uprotocol/uri/serializer/UriSerializer.kt @@ -28,7 +28,6 @@ import org.eclipse.uprotocol.uri.validator.isResolved import org.eclipse.uprotocol.v1.UUri import org.eclipse.uprotocol.v1.copy import org.eclipse.uprotocol.v1.uUri -import java.util.* /** * UUris are used in transport layers and hence need to be serialized. @@ -42,14 +41,14 @@ interface UriSerializer { * @param uri serialized UUri. * @return Returns a [UUri] object from the serialized format from the wire. */ - fun deserialize(uri: T?): UUri + fun deserialize(uri: T): UUri /** * Serialize from a [UUri] to a specific serialization format. * @param uri UUri object to be serialized to the format T. * @return Returns the [UUri] in the transport serialized format. */ - fun serialize(uri: UUri?): T + fun serialize(uri: UUri): T /** * Build a fully resolved [UUri] from the serialized long format and the serializes micro format. @@ -57,26 +56,30 @@ interface UriSerializer { * @param microUri [UUri] serialized as a byte[]. * @return Returns a [UUri] object serialized from one of the forms. */ - fun buildResolved(longUri: String?, microUri: ByteArray?): Optional { + fun buildResolved(longUri: String?, microUri: ByteArray?): UUri? { if (longUri.isNullOrEmpty() && (microUri == null || microUri.isEmpty())) { - return Optional.of(UUri.getDefaultInstance()) + return UUri.getDefaultInstance() } + val longUUri = longUri?.let { + LongUriSerializer.INSTANCE.deserialize(it) + } ?: UUri.getDefaultInstance() - val longUUri = LongUriSerializer.instance().deserialize(longUri) - val microUUri = MicroUriSerializer.instance().deserialize(microUri) + val microUUri = microUri?.let { + MicroUriSerializer.INSTANCE.deserialize(it) + } ?: UUri.getDefaultInstance() val uri = uUri { authority = microUUri.authority.copy { name = longUUri.authority.name } - entity=microUUri.entity.copy { + entity = microUUri.entity.copy { name = longUUri.entity.name } - resource=longUUri.resource.copy { + resource = longUUri.resource.copy { id = microUUri.resource.id } } - return if (uri.isResolved()) Optional.of(uri) else Optional.empty() + return if (uri.isResolved()) uri else null } } \ No newline at end of file diff --git a/src/main/kotlin/org/eclipse/uprotocol/uuid/factory/UuidUtils.kt b/src/main/kotlin/org/eclipse/uprotocol/uuid/factory/UuidUtils.kt index 1bca319..3422f8c 100644 --- a/src/main/kotlin/org/eclipse/uprotocol/uuid/factory/UuidUtils.kt +++ b/src/main/kotlin/org/eclipse/uprotocol/uuid/factory/UuidUtils.kt @@ -33,7 +33,7 @@ import org.eclipse.uprotocol.v1.UUID /** * Fetch the UUID version. * - * @return the UUID version from the UUID object or Optional.empty() if the uuid is null. + * @return the UUID version from the UUID object. */ fun UUID.getVersion(): UUIDVersion { // Version is bits masked by 0x000000000000F000 in MS long diff --git a/src/test/kotlin/org/eclipse/uprotocol/cloudevent/datamodel/UCloudEventAttributesTest.kt b/src/test/kotlin/org/eclipse/uprotocol/cloudevent/datamodel/UCloudEventAttributesTest.kt index 94b2701..44434a7 100644 --- a/src/test/kotlin/org/eclipse/uprotocol/cloudevent/datamodel/UCloudEventAttributesTest.kt +++ b/src/test/kotlin/org/eclipse/uprotocol/cloudevent/datamodel/UCloudEventAttributesTest.kt @@ -58,16 +58,16 @@ internal class UCloudEventAttributesTest { token = "someOAuthToken" traceparent = "someTraceparent" } - assertTrue(uCloudEventAttributes.hash().isPresent) - assertEquals("somehash", uCloudEventAttributes.hash().get()) - assertTrue(uCloudEventAttributes.priority().isPresent) - assertEquals(UPriority.UPRIORITY_CS6, uCloudEventAttributes.priority().get()) - assertTrue(uCloudEventAttributes.ttl().isPresent) - assertEquals(3, uCloudEventAttributes.ttl().get()) - assertTrue(uCloudEventAttributes.token().isPresent) - assertEquals("someOAuthToken", uCloudEventAttributes.token().get()) - assertTrue(uCloudEventAttributes.traceparent().isPresent) - assertEquals("someTraceparent", uCloudEventAttributes.traceparent().get()) + checkNotNull(uCloudEventAttributes.hash) + assertEquals("somehash", uCloudEventAttributes.hash) + checkNotNull(uCloudEventAttributes.priority) + assertEquals(UPriority.UPRIORITY_CS6, uCloudEventAttributes.priority) + checkNotNull(uCloudEventAttributes.ttl) + assertEquals(3, uCloudEventAttributes.ttl) + checkNotNull(uCloudEventAttributes.token) + assertEquals("someOAuthToken", uCloudEventAttributes.token) + checkNotNull(uCloudEventAttributes.traceparent) + assertEquals("someTraceparent", uCloudEventAttributes.traceparent) } @Test @@ -75,11 +75,11 @@ internal class UCloudEventAttributesTest { fun test_Isempty_function() { val uCloudEventAttributes: UCloudEventAttributes = UCloudEventAttributes.EMPTY assertTrue(uCloudEventAttributes.isEmpty) - assertTrue(uCloudEventAttributes.hash().isEmpty) - assertTrue(uCloudEventAttributes.priority().isEmpty) - assertTrue(uCloudEventAttributes.token().isEmpty) - assertTrue(uCloudEventAttributes.ttl().isEmpty) - assertTrue(uCloudEventAttributes.traceparent().isEmpty) + assertTrue(uCloudEventAttributes.hash.isNullOrBlank()) + assertNull(uCloudEventAttributes.priority) + assertNull(uCloudEventAttributes.token) + assertNull(uCloudEventAttributes.ttl) + assertNull(uCloudEventAttributes.traceparent) } @Test @@ -90,10 +90,10 @@ internal class UCloudEventAttributesTest { token = " " } assertTrue(uCloudEventAttributes.isEmpty) - assertTrue(uCloudEventAttributes.hash().isEmpty) - assertTrue(uCloudEventAttributes.priority().isEmpty) - assertTrue(uCloudEventAttributes.token().isEmpty) - assertTrue(uCloudEventAttributes.ttl().isEmpty) + assertNull(uCloudEventAttributes.hash) + assertNull(uCloudEventAttributes.priority) + assertNull(uCloudEventAttributes.token) + assertNull(uCloudEventAttributes.ttl) } @Test diff --git a/src/test/kotlin/org/eclipse/uprotocol/cloudevent/factory/CloudEventFactoryTest.kt b/src/test/kotlin/org/eclipse/uprotocol/cloudevent/factory/CloudEventFactoryTest.kt index 2d91136..ca2723c 100644 --- a/src/test/kotlin/org/eclipse/uprotocol/cloudevent/factory/CloudEventFactoryTest.kt +++ b/src/test/kotlin/org/eclipse/uprotocol/cloudevent/factory/CloudEventFactoryTest.kt @@ -355,7 +355,7 @@ internal class CloudEventFactoryTest { } } - return LongUriSerializer.instance().serialize(uri) + return LongUriSerializer.INSTANCE.serialize(uri) } private fun buildProtoPayloadForTest(): Any { diff --git a/src/test/kotlin/org/eclipse/uprotocol/cloudevent/factory/UCloudEventTest.kt b/src/test/kotlin/org/eclipse/uprotocol/cloudevent/factory/UCloudEventTest.kt index d601dfa..ce1eac1 100644 --- a/src/test/kotlin/org/eclipse/uprotocol/cloudevent/factory/UCloudEventTest.kt +++ b/src/test/kotlin/org/eclipse/uprotocol/cloudevent/factory/UCloudEventTest.kt @@ -59,9 +59,8 @@ internal class UCloudEventTest { val builder: CloudEventBuilder = buildBaseCloudEventBuilderForTest().withExtension("sink", URI.create(sinkForTest)) val cloudEvent: CloudEvent = builder.build() - val sink: Optional = UCloudEvent.getSink(cloudEvent) - assertTrue(sink.isPresent) - assertEquals(sinkForTest, sink.get()) + val sink = UCloudEvent.getSink(cloudEvent) + assertEquals(sinkForTest, sink) } @Test @@ -69,8 +68,8 @@ internal class UCloudEventTest { fun test_extract_sink_from_cloudevent_when_sink_does_not_exist() { val builder: CloudEventBuilder = buildBaseCloudEventBuilderForTest() val cloudEvent: CloudEvent = builder.build() - val sink: Optional = UCloudEvent.getSink(cloudEvent) - assertTrue(sink.isEmpty) + val sink = UCloudEvent.getSink(cloudEvent) + assertNull(sink) } @Test @@ -78,9 +77,8 @@ internal class UCloudEventTest { fun test_extract_requestId_from_cloudevent_when_requestId_exists() { val builder: CloudEventBuilder = buildBaseCloudEventBuilderForTest().withExtension("reqid", "someRequestId") val cloudEvent: CloudEvent = builder.build() - val requestId: Optional = UCloudEvent.getRequestId(cloudEvent) - assertTrue(requestId.isPresent) - assertEquals("someRequestId", requestId.get()) + val requestId = UCloudEvent.getRequestId(cloudEvent) + assertEquals("someRequestId", requestId) } @Test @@ -88,8 +86,8 @@ internal class UCloudEventTest { fun test_extract_requestId_from_cloudevent_when_requestId_does_not_exist() { val builder: CloudEventBuilder = buildBaseCloudEventBuilderForTest() val cloudEvent: CloudEvent = builder.build() - val requestId: Optional = UCloudEvent.getRequestId(cloudEvent) - assertTrue(requestId.isEmpty) + val requestId= UCloudEvent.getRequestId(cloudEvent) + assertNull(requestId) } @@ -98,9 +96,8 @@ internal class UCloudEventTest { fun test_extract_hash_from_cloudevent_when_hash_exists() { val builder: CloudEventBuilder = buildBaseCloudEventBuilderForTest() val cloudEvent: CloudEvent = builder.build() - val hash: Optional = UCloudEvent.getHash(cloudEvent) - assertTrue(hash.isPresent) - assertEquals("somehash", hash.get()) + val hash= UCloudEvent.getHash(cloudEvent) + assertEquals("somehash", hash) } @Test @@ -108,8 +105,8 @@ internal class UCloudEventTest { fun test_extract_hash_from_cloudevent_when_hash_does_not_exist() { val builder: CloudEventBuilder = buildBaseCloudEventBuilderForTest().withoutExtension("hash") val cloudEvent: CloudEvent = builder.build() - val hash: Optional = UCloudEvent.getHash(cloudEvent) - assertTrue(hash.isEmpty) + val hash: String? = UCloudEvent.getHash(cloudEvent) + assertNull(hash) } @Test @@ -117,9 +114,8 @@ internal class UCloudEventTest { fun test_extract_priority_from_cloudevent_when_priority_exists() { val builder: CloudEventBuilder = buildBaseCloudEventBuilderForTest() val cloudEvent: CloudEvent = builder.build() - val priority: Optional = UCloudEvent.getPriority(cloudEvent) - assertTrue(priority.isPresent) - assertEquals(UPriority.UPRIORITY_CS1.name, priority.get()) + val priority= UCloudEvent.getPriority(cloudEvent) + assertEquals(UPriority.UPRIORITY_CS1.name, priority) } @Test @@ -127,8 +123,8 @@ internal class UCloudEventTest { fun test_extract_priority_from_cloudevent_when_priority_does_not_exist() { val builder: CloudEventBuilder = buildBaseCloudEventBuilderForTest().withoutExtension("priority") val cloudEvent: CloudEvent = builder.build() - val priority: Optional = UCloudEvent.getPriority(cloudEvent) - assertTrue(priority.isEmpty) + val priority: String? = UCloudEvent.getPriority(cloudEvent) + assertNull(priority) } @Test @@ -136,9 +132,8 @@ internal class UCloudEventTest { fun test_extract_ttl_from_cloudevent_when_ttl_exists() { val builder: CloudEventBuilder = buildBaseCloudEventBuilderForTest() val cloudEvent: CloudEvent = builder.build() - val ttl: Optional = UCloudEvent.getTtl(cloudEvent) - assertTrue(ttl.isPresent) - assertEquals(3, ttl.get()) + val ttl = UCloudEvent.getTtl(cloudEvent) + assertEquals(3, ttl) } @Test @@ -146,8 +141,8 @@ internal class UCloudEventTest { fun test_extract_ttl_from_cloudevent_when_ttl_does_not_exist() { val builder: CloudEventBuilder = buildBaseCloudEventBuilderForTest().withoutExtension("ttl") val cloudEvent: CloudEvent = builder.build() - val ttl: Optional = UCloudEvent.getTtl(cloudEvent) - assertTrue(ttl.isEmpty) + val ttl: Int? = UCloudEvent.getTtl(cloudEvent) + assertNull(ttl) } @Test @@ -155,9 +150,8 @@ internal class UCloudEventTest { fun test_extract_token_from_cloudevent_when_token_exists() { val builder: CloudEventBuilder = buildBaseCloudEventBuilderForTest() val cloudEvent: CloudEvent = builder.build() - val token: Optional = UCloudEvent.getToken(cloudEvent) - assertTrue(token.isPresent) - assertEquals("someOAuthToken", token.get()) + val token: String? = UCloudEvent.getToken(cloudEvent) + assertEquals("someOAuthToken", token) } @Test @@ -165,8 +159,8 @@ internal class UCloudEventTest { fun test_extract_token_from_cloudevent_when_token_does_not_exist() { val builder: CloudEventBuilder = buildBaseCloudEventBuilderForTest().withoutExtension("token") val cloudEvent: CloudEvent = builder.build() - val token: Optional = UCloudEvent.getToken(cloudEvent) - assertTrue(token.isEmpty) + val token: String? = UCloudEvent.getToken(cloudEvent) + assertNull(token) } @Test @@ -174,9 +168,8 @@ internal class UCloudEventTest { fun test_extract_traceparent_from_cloudevent_when_traceparent_exists() { val builder: CloudEventBuilder = buildBaseCloudEventBuilderForTest() val cloudEvent: CloudEvent = builder.build() - val traceparent: Optional = UCloudEvent.getTraceparent(cloudEvent) - assertTrue(traceparent.isPresent) - assertEquals("someTraceparent", traceparent.get()) + val traceparent: String? = UCloudEvent.getTraceparent(cloudEvent) + assertEquals("someTraceparent", traceparent) } @Test @@ -184,8 +177,8 @@ internal class UCloudEventTest { fun test_extract_traceparent_from_cloudevent_when_traceparent_does_not_exist() { val builder: CloudEventBuilder = buildBaseCloudEventBuilderForTest().withoutExtension("traceparent") val cloudEvent: CloudEvent = builder.build() - val traceparent: Optional = UCloudEvent.getTraceparent(cloudEvent) - assertTrue(traceparent.isEmpty) + val traceparent: String? = UCloudEvent.getTraceparent(cloudEvent) + assertNull(traceparent) } @@ -272,8 +265,8 @@ internal class UCloudEventTest { fun test_extract_creation_timestamp_from_cloudevent_UUID_Id_when_not_a_UUIDV8_id() { val builder: CloudEventBuilder = buildBaseCloudEventBuilderForTest() val cloudEvent: CloudEvent = builder.build() - val creationTimestamp: Optional = UCloudEvent.getCreationTimestamp(cloudEvent) - assertTrue(creationTimestamp.isEmpty) + val creationTimestamp = UCloudEvent.getCreationTimestamp(cloudEvent) + assertNull(creationTimestamp) } @Test @@ -284,9 +277,7 @@ internal class UCloudEventTest { val builder: CloudEventBuilder = buildBaseCloudEventBuilderForTest().withId(strUuid) val cloudEvent: CloudEvent = builder.build() - val maybeCreationTimestamp: Optional = UCloudEvent.getCreationTimestamp(cloudEvent) - assertTrue(maybeCreationTimestamp.isPresent) - val creationTimestamp: Long = maybeCreationTimestamp.get() + val creationTimestamp = UCloudEvent.getCreationTimestamp(cloudEvent)?: fail() val now: OffsetDateTime = OffsetDateTime.now() val creationTimestampInstant: Instant = Instant.ofEpochMilli(creationTimestamp) val creationTimestampInstantEpochSecond: Long = creationTimestampInstant.epochSecond @@ -537,11 +528,9 @@ internal class UCloudEventTest { .withSource(URI.create("/body.access/1/door.front_left#Door")).withDataContentType(DATA_CONTENT_TYPE) .withDataSchema(URI.create(payloadForCloudEvent.typeUrl)).withData(cloudEventData) val cloudEvent: CloudEvent = cloudEventBuilder.build() - val extracted: Optional = UCloudEvent.unpack( + val unpackedCE: io.cloudevents.v1.proto.CloudEvent = UCloudEvent.unpack( cloudEvent, io.cloudevents.v1.proto.CloudEvent::class.java - ) - assertTrue(extracted.isPresent) - val unpackedCE: io.cloudevents.v1.proto.CloudEvent = extracted.get() + ) ?: fail() assertEquals("1.0", unpackedCE.specVersion) assertEquals("hello", unpackedCE.id) assertEquals("example.demo", unpackedCE.type) @@ -556,10 +545,10 @@ internal class UCloudEventTest { .withDataSchema(URI.create("type.googleapis.com/io.cloudevents.v1.CloudEvent")) .withData("

Hello

".toByteArray()) val cloudEvent: CloudEvent = cloudEventBuilder.build() - val extracted: Optional = UCloudEvent.unpack( + val extracted: io.cloudevents.v1.proto.CloudEvent? = UCloudEvent.unpack( cloudEvent, io.cloudevents.v1.proto.CloudEvent::class.java ) - assertTrue(extracted.isEmpty) + assertNull(extracted) } @Test @@ -575,14 +564,6 @@ internal class UCloudEventTest { assertEquals(expected, prettyPrint) } - @Test - @DisplayName("Test pretty printing a cloud event that is null") - fun test_pretty_printing_a_cloudevent_that_is_null() { - val prettyPrint: String = UCloudEvent.toString(null) - val expected = "null" - assertEquals(expected, prettyPrint) - } - @Test @DisplayName("Test pretty printing a cloud event without a sink") fun test_pretty_printing_a_cloudevent_without_a_sink() { @@ -677,25 +658,19 @@ internal class UCloudEventTest { ) val result = UCloudEvent.toMessage(cloudEvent) assertNotNull(result) - assertTrue(UCloudEvent.getTtl(cloudEvent).isPresent) - assertEquals(UCloudEvent.getTtl(cloudEvent).get(), result.attributes.ttl) - assertTrue(UCloudEvent.getToken(cloudEvent).isPresent) - assertEquals(UCloudEvent.getToken(cloudEvent).get(), result.attributes.getToken()) - assertTrue(UCloudEvent.getSink(cloudEvent).isPresent) + assertEquals(UCloudEvent.getTtl(cloudEvent), result.attributes.ttl) + assertEquals(UCloudEvent.getToken(cloudEvent), result.attributes.getToken()) assertEquals( - UCloudEvent.getSink(cloudEvent).get(), LongUriSerializer.instance().serialize(result.attributes.sink) + UCloudEvent.getSink(cloudEvent), LongUriSerializer.INSTANCE.serialize(result.attributes.sink) ) - assertTrue(UCloudEvent.getTraceparent(cloudEvent).isPresent) - assertEquals(UCloudEvent.getTraceparent(cloudEvent).get(), result.attributes.traceparent) + assertEquals(UCloudEvent.getTraceparent(cloudEvent), result.attributes.traceparent) assertEquals(UCloudEvent.getPayload(cloudEvent).toByteString(), result.payload.getValue()) assertEquals( UCloudEvent.getSource(cloudEvent), - LongUriSerializer.instance().serialize(result.attributes.source) + LongUriSerializer.INSTANCE.serialize(result.attributes.source) ) - assertTrue(UCloudEvent.getPriority(cloudEvent).isPresent) - assertEquals(UCloudEvent.getPriority(cloudEvent).get(), result.attributes.getPriority().name) - + assertEquals(UCloudEvent.getPriority(cloudEvent), result.attributes.getPriority().name) val cloudEvent1 = UCloudEvent.fromMessage(result) assertNotNull(cloudEvent1) assertEquals(cloudEvent, cloudEvent1) @@ -714,19 +689,16 @@ internal class UCloudEventTest { val result = UCloudEvent.toMessage(cloudEvent) assertNotNull(result) assertFalse(result.attributes.hasTtl()) - assertTrue(UCloudEvent.getSink(cloudEvent).isPresent) assertEquals( - UCloudEvent.getSink(cloudEvent).get(), LongUriSerializer.instance().serialize(result.attributes.sink) + UCloudEvent.getSink(cloudEvent), LongUriSerializer.INSTANCE.serialize(result.attributes.sink) ) assertEquals(UCloudEvent.getPayload(cloudEvent).toByteString(), result.payload.getValue()) assertEquals( UCloudEvent.getSource(cloudEvent), - LongUriSerializer.instance().serialize(result.attributes.source) + LongUriSerializer.INSTANCE.serialize(result.attributes.source) ) assertEquals(result.attributes.getPriority().getNumber(), 0) - - val cloudEvent1 = UCloudEvent.fromMessage(result) - assertEquals(cloudEvent, cloudEvent1) + assertEquals(cloudEvent, UCloudEvent.fromMessage(result)) } @@ -748,26 +720,20 @@ internal class UCloudEventTest { ) val result = UCloudEvent.toMessage(cloudEvent) assertNotNull(result) - assertTrue(UCloudEvent.getRequestId(cloudEvent).isPresent) assertEquals( - UCloudEvent.getRequestId(cloudEvent).get(), LongUuidSerializer.INSTANCE.serialize(result.attributes.reqid) + UCloudEvent.getRequestId(cloudEvent), LongUuidSerializer.INSTANCE.serialize(result.attributes.reqid) ) - assertTrue(UCloudEvent.getTtl(cloudEvent).isPresent) - assertEquals(UCloudEvent.getTtl(cloudEvent).get(), result.attributes.ttl) - assertTrue(UCloudEvent.getSink(cloudEvent).isPresent) + assertEquals(UCloudEvent.getTtl(cloudEvent), result.attributes.ttl) assertEquals( - UCloudEvent.getSink(cloudEvent).get(), LongUriSerializer.instance().serialize(result.attributes.sink) + UCloudEvent.getSink(cloudEvent), LongUriSerializer.INSTANCE.serialize(result.attributes.sink) ) assertEquals(UCloudEvent.getPayload(cloudEvent).toByteString(), result.payload.getValue()) assertEquals( UCloudEvent.getSource(cloudEvent), - LongUriSerializer.instance().serialize(result.attributes.source) + LongUriSerializer.INSTANCE.serialize(result.attributes.source) ) - assertTrue(UCloudEvent.getPriority(cloudEvent).isPresent) - assertEquals(UCloudEvent.getPriority(cloudEvent).get(), result.attributes.getPriority().name) - - val cloudEvent1 = UCloudEvent.fromMessage(result) - assertEquals(cloudEvent, cloudEvent1) + assertEquals(UCloudEvent.getPriority(cloudEvent), result.attributes.getPriority().name) + assertEquals(cloudEvent, UCloudEvent.fromMessage(result)) } @@ -890,8 +856,7 @@ internal class UCloudEventTest { assertNotNull(result) assertEquals(UPriority.UPRIORITY_CS4.name, result.attributes.getPriority().name) val cloudEvent1 = UCloudEvent.fromMessage(result) - assertTrue(UCloudEvent.getPriority(cloudEvent1).isPresent) - assertEquals(UPriority.UPRIORITY_CS4.name, UCloudEvent.getPriority(cloudEvent1).get()) + assertEquals(UPriority.UPRIORITY_CS4.name, UCloudEvent.getPriority(cloudEvent1)) } private fun buildSourceForTest(): String { @@ -905,7 +870,7 @@ internal class UCloudEventTest { } } - return LongUriSerializer.instance().serialize(uUri) + return LongUriSerializer.INSTANCE.serialize(uUri) } private fun buildBaseCloudEventBuilderForTest(): CloudEventBuilder { diff --git a/src/test/kotlin/org/eclipse/uprotocol/cloudevent/serialize/CloudEventToProtobufSerializerTest.kt b/src/test/kotlin/org/eclipse/uprotocol/cloudevent/serialize/CloudEventToProtobufSerializerTest.kt index de7edb3..b23ae9d 100644 --- a/src/test/kotlin/org/eclipse/uprotocol/cloudevent/serialize/CloudEventToProtobufSerializerTest.kt +++ b/src/test/kotlin/org/eclipse/uprotocol/cloudevent/serialize/CloudEventToProtobufSerializerTest.kt @@ -260,7 +260,7 @@ internal class CloudEventToProtobufSerializerTest { } - return LongUriSerializer.instance().serialize(uri) + return LongUriSerializer.INSTANCE.serialize(uri) } private fun buildProtoPayloadForTest(): Any { diff --git a/src/test/kotlin/org/eclipse/uprotocol/cloudevent/validate/CloudEventValidatorTest.kt b/src/test/kotlin/org/eclipse/uprotocol/cloudevent/validate/CloudEventValidatorTest.kt index 0b8d83f..5c8707e 100644 --- a/src/test/kotlin/org/eclipse/uprotocol/cloudevent/validate/CloudEventValidatorTest.kt +++ b/src/test/kotlin/org/eclipse/uprotocol/cloudevent/validate/CloudEventValidatorTest.kt @@ -600,7 +600,7 @@ internal class CloudEventValidatorTest { } private fun buildLongUriForTest(): String { - return LongUriSerializer.instance().serialize(buildUUriForTest()) + return LongUriSerializer.INSTANCE.serialize(buildUUriForTest()) } private fun buildUUriForTest(): UUri { diff --git a/src/test/kotlin/org/eclipse/uprotocol/rpc/RpcTest.kt b/src/test/kotlin/org/eclipse/uprotocol/rpc/RpcTest.kt index 87648df..4edf364 100644 --- a/src/test/kotlin/org/eclipse/uprotocol/rpc/RpcTest.kt +++ b/src/test/kotlin/org/eclipse/uprotocol/rpc/RpcTest.kt @@ -367,7 +367,7 @@ internal class RpcTest { } private fun buildTopic(): UUri { - return LongUriSerializer.instance().deserialize("//vcu.vin/hartley/1/rpc.Raise") + return LongUriSerializer.INSTANCE.deserialize("//vcu.vin/hartley/1/rpc.Raise") } private fun buildUCallOptions(): CallOptions { diff --git a/src/test/kotlin/org/eclipse/uprotocol/transport/validator/UAttributesValidatorTest.kt b/src/test/kotlin/org/eclipse/uprotocol/transport/validator/UAttributesValidatorTest.kt index fa4eb34..9d5cf56 100644 --- a/src/test/kotlin/org/eclipse/uprotocol/transport/validator/UAttributesValidatorTest.kt +++ b/src/test/kotlin/org/eclipse/uprotocol/transport/validator/UAttributesValidatorTest.kt @@ -538,7 +538,7 @@ internal class UAttributesValidatorTest { @Test @DisplayName("test validating invalid sink attribute") fun test_validating_invalid_sink_attribute() { - val uri: UUri = LongUriSerializer.instance().deserialize("//") + val uri: UUri = LongUriSerializer.INSTANCE.deserialize("//") val attributes: UAttributes = uAttributes { forPublication(testSource, UPriority.UPRIORITY_CS0) @@ -553,7 +553,7 @@ internal class UAttributesValidatorTest { @Test @DisplayName("test validating valid sink attribute") fun test_validating_valid_sink_attribute() { - val uri: UUri = LongUriSerializer.instance().deserialize("/haartley/1") + val uri: UUri = LongUriSerializer.INSTANCE.deserialize("/haartley/1") val attributes: UAttributes = uAttributes { forPublication(testSource, UPriority.UPRIORITY_CS0) @@ -695,7 +695,7 @@ internal class UAttributesValidatorTest { fun test_validating_request_validator_with_wrong_bad_ttl() { val attributes: UAttributes = uAttributes { forRequest( - testSource, LongUriSerializer.instance().deserialize("/hartley/1/rpc.response"), + testSource, LongUriSerializer.INSTANCE.deserialize("/hartley/1/rpc.response"), UPriority.UPRIORITY_CS6, -1 ) } @@ -713,7 +713,7 @@ internal class UAttributesValidatorTest { val attributes: UAttributes = uAttributes { forResponse( testSource, - LongUriSerializer.instance().deserialize("/hartley/1/rpc.response"), + LongUriSerializer.INSTANCE.deserialize("/hartley/1/rpc.response"), UPriority.UPRIORITY_CS6, UUIDV8() ) @@ -773,7 +773,7 @@ internal class UAttributesValidatorTest { @Test @DisplayName("test_valid_request_methoduri_in_sink") fun test_valid_request_methoduri_in_sink() { - val testSink = LongUriSerializer.instance().deserialize("/test.service/1/rpc.method") + val testSink = LongUriSerializer.INSTANCE.deserialize("/test.service/1/rpc.method") val attributes = uAttributes { forRequest(testSource, testSink, UPriority.UPRIORITY_CS0, 3000) } @@ -787,7 +787,7 @@ internal class UAttributesValidatorTest { @Test @DisplayName("test_invalid_request_methoduri_in_sink") fun test_invalid_request_methoduri_in_sink() { - val testSink = LongUriSerializer.instance().deserialize("/test.client/1/test.response") + val testSink = LongUriSerializer.INSTANCE.deserialize("/test.client/1/test.response") val attributes = uAttributes { forRequest(testSource, testSink, UPriority.UPRIORITY_CS0, 3000) } @@ -804,7 +804,7 @@ internal class UAttributesValidatorTest { @Test @DisplayName("test_valid_response_uri_in_sink") fun test_valid_response_uri_in_sink() { - val testSink = LongUriSerializer.instance().deserialize("/test.client/1/rpc.response") + val testSink = LongUriSerializer.INSTANCE.deserialize("/test.client/1/rpc.response") val attributes = uAttributes { forResponse( testSource, @@ -822,7 +822,7 @@ internal class UAttributesValidatorTest { @Test @DisplayName("test_invalid_response_uri_in_sink") fun test_invalid_response_uri_in_sink() { - val testSink = LongUriSerializer.instance().deserialize("/test.client/1/rpc.method") + val testSink = LongUriSerializer.INSTANCE.deserialize("/test.client/1/rpc.method") val attributes = uAttributes { forResponse( testSource, diff --git a/src/test/kotlin/org/eclipse/uprotocol/uri/serializer/LongUriSerializerTest.kt b/src/test/kotlin/org/eclipse/uprotocol/uri/serializer/LongUriSerializerTest.kt index eaa8b44..e33ddbe 100644 --- a/src/test/kotlin/org/eclipse/uprotocol/uri/serializer/LongUriSerializerTest.kt +++ b/src/test/kotlin/org/eclipse/uprotocol/uri/serializer/LongUriSerializerTest.kt @@ -21,14 +21,11 @@ package org.eclipse.uprotocol.uri.serializer import org.eclipse.uprotocol.uri.validator.isEmpty -import org.eclipse.uprotocol.uri.validator.isLongForm import org.eclipse.uprotocol.uri.validator.isRemote -import org.eclipse.uprotocol.uri.validator.isResolved import org.eclipse.uprotocol.v1.* import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test -import java.util.* class LongUriSerializerTest { @@ -40,41 +37,30 @@ class LongUriSerializerTest { resource = uResource { forRpcRequest("raise") } } - val strUri: String = LongUriSerializer.instance().serialize(uri) + val strUri: String = LongUriSerializer.INSTANCE.serialize(uri) assertEquals("/hartley//rpc.raise", strUri) - val uri2: UUri = LongUriSerializer.instance().deserialize(strUri) + val uri2: UUri = LongUriSerializer.INSTANCE.deserialize(strUri) assertEquals(uri, uri2) } - @Test - @DisplayName("Test parse uProtocol uri that is null") - fun test_parse_protocol_uri_when_is_null() { - val uri: UUri = LongUriSerializer.instance().deserialize(null) - assertTrue(uri.isEmpty()) - assertFalse(uri.isResolved()) - assertFalse(uri.isLongForm()) - } - @Test @DisplayName("Test parse uProtocol uri that is empty string") fun test_parse_protocol_uri_when_is_empty_string() { val uri = "" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertTrue(uuri.isEmpty()) - val uri2: String = LongUriSerializer.instance().serialize(null) - assertTrue(uri2.isEmpty()) } @Test @DisplayName("Test parse uProtocol uri with schema and slash") fun test_parse_protocol_uri_with_schema_and_slash() { val uri = "/" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertFalse(uuri.hasAuthority()) assertTrue(uuri.isEmpty()) assertFalse(uuri.hasResource()) assertFalse(uuri.hasEntity()) - val uri2: String = LongUriSerializer.instance().serialize(uUri { }) + val uri2: String = LongUriSerializer.INSTANCE.serialize(uUri { }) assertTrue(uri2.isEmpty()) } @@ -82,7 +68,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with schema and double slash") fun test_parse_protocol_uri_with_schema_and_double_slash() { val uri = "//" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertFalse(uuri.hasAuthority()) assertFalse(uuri.hasResource()) assertFalse(uuri.hasEntity()) @@ -93,7 +79,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with schema and 3 slash and something") fun test_parse_protocol_uri_with_schema_and_3_slash_and_something() { val uri = "///body.access" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertFalse(uuri.hasAuthority()) assertFalse(uuri.hasResource()) assertFalse(uuri.hasEntity()) @@ -106,7 +92,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with schema and 4 slash and something") fun test_parse_protocol_uri_with_schema_and_4_slash_and_something() { val uri = "////body.access" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertFalse(uuri.authority.isRemote()) assertFalse(uuri.hasResource()) assertFalse(uuri.hasEntity()) @@ -118,7 +104,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with schema and 5 slash and something") fun test_parse_protocol_uri_with_schema_and_5_slash_and_something() { val uri = "/////body.access" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertFalse(uuri.authority.isRemote()) assertFalse(uuri.hasResource()) assertFalse(uuri.hasEntity()) @@ -129,7 +115,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with schema and 6 slash and something") fun test_parse_protocol_uri_with_schema_and_6_slash_and_something() { val uri = "//////body.access" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertFalse(uuri.authority.isRemote()) assertTrue(uuri.isEmpty()) } @@ -138,7 +124,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with local service no version") fun test_parse_protocol_uri_with_local_service_no_version() { val uri = "/body.access" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertFalse(uuri.authority.isRemote()) assertEquals("body.access", uuri.entity.name) assertEquals(0, uuri.entity.versionMajor) @@ -150,7 +136,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with local service with version") fun test_parse_protocol_uri_with_local_service_with_version() { val uri = "/body.access/1" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertFalse(uuri.authority.isRemote()) assertEquals("body.access", uuri.entity.name) assertEquals(1, uuri.entity.versionMajor) @@ -161,7 +147,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with local service no version with resource name only") fun test_parse_protocol_uri_with_local_service_no_version_with_resource_name_only() { val uri = "/body.access//door" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertFalse(uuri.authority.isRemote()) assertEquals("body.access", uuri.entity.name) assertEquals(0, uuri.entity.versionMajor) @@ -175,7 +161,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with local service with version with resource name only") fun test_parse_protocol_uri_with_local_service_with_version_with_resource_name_only() { val uri = "/body.access/1/door" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertFalse(uuri.authority.isRemote()) assertEquals("body.access", uuri.entity.name) assertEquals(1, uuri.entity.versionMajor) @@ -188,7 +174,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with local service no version with resource and instance only") fun test_parse_protocol_uri_with_local_service_no_version_with_resource_with_instance() { val uri = "/body.access//door.front_left" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertFalse(uuri.authority.isRemote()) assertEquals("body.access", uuri.entity.name) assertEquals(0, uuri.entity.versionMajor) @@ -202,7 +188,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with local service with version with resource and instance only") fun test_parse_protocol_uri_with_local_service_with_version_with_resource_with_getMessage() { val uri = "/body.access/1/door.front_left" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertFalse(uuri.authority.isRemote()) assertEquals("body.access", uuri.entity.name) assertNotEquals(0, uuri.entity.versionMajor) @@ -217,7 +203,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with local service no version with resource with instance and message") fun test_parse_protocol_uri_with_local_service_no_version_with_resource_with_instance_and_getMessage() { val uri = "/body.access//door.front_left#Door" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertFalse(uuri.authority.isRemote()) assertEquals("body.access", uuri.entity.name) assertEquals(0, uuri.entity.versionMajor) @@ -232,7 +218,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with local service with version with resource with instance and message") fun test_parse_protocol_uri_with_local_service_with_version_with_resource_with_instance_and_getMessage() { val uri = "/body.access/1/door.front_left#Door" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertFalse(uuri.authority.isRemote()) assertEquals("body.access", uuri.entity.name) assertNotEquals(0, uuri.entity.versionMajor) @@ -248,7 +234,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol RPC uri with local service no version") fun test_parse_protocol_rpc_uri_with_local_service_no_version() { val uri = "/petapp//rpc.response" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertFalse(uuri.authority.isRemote()) assertEquals("petapp", uuri.entity.name) assertEquals(0, uuri.entity.versionMajor) @@ -262,7 +248,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol RPC uri with local service with version") fun test_parse_protocol_rpc_uri_with_local_service_with_version() { val uri = "/petapp/1/rpc.response" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertFalse(uuri.authority.isRemote()) assertEquals("petapp", uuri.entity.name) assertNotEquals(0, uuri.entity.versionMajor) @@ -277,7 +263,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with microRemote service , name with device and domain") fun test_parse_protocol_uri_with_remote_service_only_device_and_domain() { val uri = "//VCU.MY_CAR_VIN" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertTrue(uuri.authority.isRemote()) assertFalse(uuri.authority.name.isBlank()) assertEquals("VCU.MY_CAR_VIN", uuri.authority.name) @@ -287,7 +273,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with microRemote service only device and cloud domain") fun test_parse_protocol_uri_with_remote_service_only_device_and_cloud_domain() { val uri = "//cloud.uprotocol.example.com" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertTrue(uuri.authority.isRemote()) assertFalse(uuri.authority.name.isBlank()) assertEquals("cloud.uprotocol.example.com", uuri.authority.name) @@ -299,7 +285,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with microRemote service no version") fun test_parse_protocol_uri_with_remote_service_no_version() { val uri = "//VCU.MY_CAR_VIN/body.access" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertTrue(uuri.authority.isRemote()) assertFalse(uuri.authority.name.isBlank()) assertEquals("VCU.MY_CAR_VIN", uuri.authority.name) @@ -313,7 +299,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with microRemote cloud service no version") fun test_parse_protocol_uri_with_remote_cloud_service_no_version() { val uri = "//cloud.uprotocol.example.com/body.access" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertTrue(uuri.authority.isRemote()) assertFalse(uuri.authority.name.isBlank()) assertEquals("cloud.uprotocol.example.com", uuri.authority.name) @@ -327,7 +313,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with microRemote service with version") fun test_parse_protocol_uri_with_remote_service_with_version() { val uri = "//VCU.MY_CAR_VIN/body.access/1" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertTrue(uuri.authority.isRemote()) assertFalse(uuri.authority.name.isBlank()) assertEquals("VCU.MY_CAR_VIN", uuri.authority.name) @@ -342,7 +328,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with microRemote cloud service with version") fun test_parse_protocol_uri_with_remote_cloud_service_with_version() { val uri = "//cloud.uprotocol.example.com/body.access/1" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertTrue(uuri.authority.isRemote()) assertFalse(uuri.authority.name.isBlank()) assertEquals("cloud.uprotocol.example.com", uuri.authority.name) @@ -357,7 +343,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with microRemote service no version with resource name only") fun test_parse_protocol_uri_with_remote_service_no_version_with_resource_name_only() { val uri = "//VCU.MY_CAR_VIN/body.access//door" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertTrue(uuri.authority.isRemote()) assertFalse(uuri.authority.name.isBlank()) assertEquals("VCU.MY_CAR_VIN", uuri.authority.name) @@ -373,7 +359,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with microRemote cloud service no version with resource name only") fun test_parse_protocol_uri_with_remote_cloud_service_no_version_with_resource_name_only() { val uri = "//cloud.uprotocol.example.com/body.access//door" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertTrue(uuri.authority.isRemote()) assertFalse(uuri.authority.name.isBlank()) assertEquals("cloud.uprotocol.example.com", uuri.authority.name) @@ -389,7 +375,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with microRemote service with version with resource name only") fun test_parse_protocol_uri_with_remote_service_with_version_with_resource_name_only() { val uri = "//VCU.MY_CAR_VIN/body.access/1/door" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertTrue(uuri.authority.isRemote()) assertFalse(uuri.authority.name.isBlank()) assertEquals("VCU.MY_CAR_VIN", uuri.authority.name) @@ -406,7 +392,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with microRemote cloud service with version with resource name only") fun test_parse_protocol_uri_with_remote_service_cloud_with_version_with_resource_name_only() { val uri = "//cloud.uprotocol.example.com/body.access/1/door" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertTrue(uuri.authority.isRemote()) assertFalse(uuri.authority.name.isBlank()) assertEquals("cloud.uprotocol.example.com", uuri.authority.name) @@ -423,7 +409,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with microRemote service no version with resource and instance no message") fun test_parse_protocol_uri_with_remote_service_no_version_with_resource_and_instance_no_getMessage() { val uri = "//VCU.MY_CAR_VIN/body.access//door.front_left" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertTrue(uuri.authority.isRemote()) assertFalse(uuri.authority.name.isBlank()) assertEquals("VCU.MY_CAR_VIN", uuri.authority.name) @@ -440,7 +426,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with microRemote service with version with resource and instance no message") fun test_parse_protocol_uri_with_remote_service_with_version_with_resource_and_instance_no_getMessage() { val uri = "//VCU.MY_CAR_VIN/body.access/1/door.front_left" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertTrue(uuri.authority.isRemote()) assertFalse(uuri.authority.name.isBlank()) assertEquals("VCU.MY_CAR_VIN", uuri.authority.name) @@ -458,7 +444,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with microRemote service no version with resource and instance and message") fun test_parse_protocol_uri_with_remote_service_no_version_with_resource_and_instance_and_getMessage() { val uri = "//VCU.MY_CAR_VIN/body.access//door.front_left#Door" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertTrue(uuri.authority.isRemote()) assertFalse(uuri.authority.name.isBlank()) assertEquals("VCU.MY_CAR_VIN", uuri.authority.name) @@ -476,7 +462,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with microRemote cloud service no version with resource and instance and message") fun test_parse_protocol_uri_with_remote_cloud_service_no_version_with_resource_and_instance_and_getMessage() { val uri = "//cloud.uprotocol.example.com/body.access//door.front_left#Door" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertTrue(uuri.authority.isRemote()) assertFalse(uuri.authority.name.isBlank()) assertEquals("cloud.uprotocol.example.com", uuri.authority.name) @@ -494,7 +480,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with microRemote service with version with resource and instance and message") fun test_parse_protocol_uri_with_remote_service_with_version_with_resource_and_instance_and_getMessage() { val uri = "//VCU.MY_CAR_VIN/body.access/1/door.front_left#Door" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertTrue(uuri.authority.isRemote()) assertFalse(uuri.authority.name.isBlank()) assertEquals("VCU.MY_CAR_VIN", uuri.authority.name) @@ -513,7 +499,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with microRemote cloud service with version with resource and instance and message") fun test_parse_protocol_uri_with_remote_cloud_service_with_version_with_resource_and_instance_and_getMessage() { val uri = "//cloud.uprotocol.example.com/body.access/1/door.front_left#Door" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertTrue(uuri.authority.isRemote()) assertFalse(uuri.authority.name.isBlank()) assertEquals("cloud.uprotocol.example.com", uuri.authority.name) @@ -532,7 +518,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol uri with microRemote service with version with resource with message when there is only device, no domain") fun test_parse_protocol_uri_with_remote_service_with_version_with_resource_with_message_device_no_domain() { val uri = "//VCU/body.access/1/door.front_left" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertTrue(uuri.authority.isRemote()) assertFalse(uuri.authority.name.isBlank()) assertEquals("VCU", uuri.authority.name) @@ -550,7 +536,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol RPC uri with microRemote service no version") fun test_parse_protocol_rpc_uri_with_remote_service_no_version() { val uri = "//bo.cloud/petapp//rpc.response" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertTrue(uuri.authority.isRemote()) assertFalse(uuri.authority.name.isBlank()) assertEquals("bo.cloud", uuri.authority.name) @@ -567,7 +553,7 @@ class LongUriSerializerTest { @DisplayName("Test parse uProtocol RPC uri with microRemote service with version") fun test_parse_protocol_rpc_uri_with_remote_service_with_version() { val uri = "//bo.cloud/petapp/1/rpc.response" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertTrue(uuri.authority.isRemote()) assertFalse(uuri.authority.name.isBlank()) assertEquals("bo.cloud", uuri.authority.name) @@ -581,18 +567,11 @@ class LongUriSerializerTest { assertTrue(uuri.resource.message.isEmpty()) } - @Test - @DisplayName("Test Create a uProtocol URI from null") - fun test_build_protocol_uri_from__uri_when__uri_isnull() { - val uProtocolUri: String = LongUriSerializer.instance().serialize(null) - assertEquals("", uProtocolUri) - } - @Test @DisplayName("Test Create a uProtocol URI from an empty URI Object") fun test_build_protocol_uri_from__uri_when__uri_isEmpty() { val uuri: UUri = uUri { } - val uProtocolUri: String = LongUriSerializer.instance().serialize(uuri) + val uProtocolUri: String = LongUriSerializer.INSTANCE.serialize(uuri) assertEquals("", uProtocolUri) } @@ -605,7 +584,7 @@ class LongUriSerializerTest { entity = use resource = uResource { name = "door" } } - val uProtocolUri: String = LongUriSerializer.instance().serialize(uuri) + val uProtocolUri: String = LongUriSerializer.INSTANCE.serialize(uuri) assertEquals("/////door", uProtocolUri) } @@ -614,7 +593,7 @@ class LongUriSerializerTest { fun test_build_protocol_uri_from__uri_when__uri_has_local_authority_service_no_version() { val uuri: UUri = uUri { entity = uEntity { name = "body.access" } } - val uProtocolUri: String = LongUriSerializer.instance().serialize(uuri) + val uProtocolUri: String = LongUriSerializer.INSTANCE.serialize(uuri) assertEquals("/body.access", uProtocolUri) } @@ -629,7 +608,7 @@ class LongUriSerializerTest { entity = use resource = uResource { } } - val uProtocolUri: String = LongUriSerializer.instance().serialize(uuri) + val uProtocolUri: String = LongUriSerializer.INSTANCE.serialize(uuri) assertEquals("/body.access/1", uProtocolUri) } @@ -644,7 +623,7 @@ class LongUriSerializerTest { resource = uResource { name = "door" } } - val uProtocolUri: String = LongUriSerializer.instance().serialize(uuri) + val uProtocolUri: String = LongUriSerializer.INSTANCE.serialize(uuri) assertEquals("/body.access//door", uProtocolUri) } @@ -660,7 +639,7 @@ class LongUriSerializerTest { resource = uResource { name = "door" } } - val uProtocolUri: String = LongUriSerializer.instance().serialize(uuri) + val uProtocolUri: String = LongUriSerializer.INSTANCE.serialize(uuri) assertEquals("/body.access/1/door", uProtocolUri) } @@ -678,7 +657,7 @@ class LongUriSerializerTest { } } - val uProtocolUri: String = LongUriSerializer.instance().serialize(uuri) + val uProtocolUri: String = LongUriSerializer.INSTANCE.serialize(uuri) assertEquals("/body.access//door.front_left", uProtocolUri) } @@ -698,7 +677,7 @@ class LongUriSerializerTest { } - val uProtocolUri: String = LongUriSerializer.instance().serialize(uuri) + val uProtocolUri: String = LongUriSerializer.INSTANCE.serialize(uuri) assertEquals("/body.access/1/door.front_left", uProtocolUri) } @@ -718,7 +697,7 @@ class LongUriSerializerTest { } - val uProtocolUri: String = LongUriSerializer.instance().serialize(uuri) + val uProtocolUri: String = LongUriSerializer.INSTANCE.serialize(uuri) assertEquals("/body.access//door.front_left#Door", uProtocolUri) } @@ -737,7 +716,7 @@ class LongUriSerializerTest { message = "Door" } } - val uProtocolUri: String = LongUriSerializer.instance().serialize(uuri) + val uProtocolUri: String = LongUriSerializer.INSTANCE.serialize(uuri) assertEquals("/body.access/1/door.front_left#Door", uProtocolUri) } @@ -750,7 +729,7 @@ class LongUriSerializerTest { entity = use } - val uProtocolUri: String = LongUriSerializer.instance().serialize(uuri) + val uProtocolUri: String = LongUriSerializer.INSTANCE.serialize(uuri) assertEquals("//vcu.my_car_vin/body.access", uProtocolUri) } @@ -769,7 +748,7 @@ class LongUriSerializerTest { } } - val uProtocolUri: String = LongUriSerializer.instance().serialize(uuri) + val uProtocolUri: String = LongUriSerializer.INSTANCE.serialize(uuri) assertEquals("//vcu.my_car_vin/body.access/1", uProtocolUri) } @@ -785,7 +764,7 @@ class LongUriSerializerTest { entity = use } - val uProtocolUri: String = LongUriSerializer.instance().serialize(uuri) + val uProtocolUri: String = LongUriSerializer.INSTANCE.serialize(uuri) assertEquals("//cloud.uprotocol.example.com/body.access/1", uProtocolUri) } @@ -802,7 +781,7 @@ class LongUriSerializerTest { resource = uResource { name = "door" } } - val uProtocolUri: String = LongUriSerializer.instance().serialize(uuri) + val uProtocolUri: String = LongUriSerializer.INSTANCE.serialize(uuri) assertEquals("//vcu.my_car_vin/body.access/1/door", uProtocolUri) } @@ -819,7 +798,7 @@ class LongUriSerializerTest { resource = uResource { name = "door" } } - val uProtocolUri: String = LongUriSerializer.instance().serialize(uuri) + val uProtocolUri: String = LongUriSerializer.INSTANCE.serialize(uuri) assertEquals("//vcu.my_car_vin/body.access//door", uProtocolUri) } @@ -839,7 +818,7 @@ class LongUriSerializerTest { } } - val uProtocolUri: String = LongUriSerializer.instance().serialize(uuri) + val uProtocolUri: String = LongUriSerializer.INSTANCE.serialize(uuri) assertEquals("//vcu.my_car_vin/body.access/1/door.front_left", uProtocolUri) } @@ -859,7 +838,7 @@ class LongUriSerializerTest { } } - val uProtocolUri: String = LongUriSerializer.instance().serialize(uuri) + val uProtocolUri: String = LongUriSerializer.INSTANCE.serialize(uuri) assertEquals("//cloud.uprotocol.example.com/body.access/1/door.front_left", uProtocolUri) } @@ -878,7 +857,7 @@ class LongUriSerializerTest { } } - val uProtocolUri: String = LongUriSerializer.instance().serialize(uuri) + val uProtocolUri: String = LongUriSerializer.INSTANCE.serialize(uuri) assertEquals("//vcu.my_car_vin/body.access//door.front_left", uProtocolUri) } @@ -900,7 +879,7 @@ class LongUriSerializerTest { } - val uProtocolUri: String = LongUriSerializer.instance().serialize(uuri) + val uProtocolUri: String = LongUriSerializer.INSTANCE.serialize(uuri) assertEquals("//vcu.my_car_vin/body.access/1/door.front_left#Door", uProtocolUri) } @@ -920,7 +899,7 @@ class LongUriSerializerTest { } } - val uProtocolUri: String = LongUriSerializer.instance().serialize(uuri) + val uProtocolUri: String = LongUriSerializer.INSTANCE.serialize(uuri) assertEquals("//vcu.my_car_vin/body.access//door.front_left#Door", uProtocolUri) } @@ -935,7 +914,7 @@ class LongUriSerializerTest { name = "rpc" instance = "response" } - val uProtocolUri: String = LongUriSerializer.instance().serialize(uUri { + val uProtocolUri: String = LongUriSerializer.INSTANCE.serialize(uUri { entity = use resource = uResource }) @@ -953,7 +932,7 @@ class LongUriSerializerTest { name = "rpc" instance = "response" } - val uProtocolUri: String = LongUriSerializer.instance().serialize(uUri { + val uProtocolUri: String = LongUriSerializer.INSTANCE.serialize(uUri { authority = uAuthority entity = use resource = uResource @@ -970,7 +949,7 @@ class LongUriSerializerTest { versionMajor = 1 } val uResource: UResource = uResource { name = "door" } - val uProtocolUri: String = LongUriSerializer.instance().serialize(uUri { + val uProtocolUri: String = LongUriSerializer.INSTANCE.serialize(uUri { authority = uAuthority entity = use resource = uResource @@ -987,7 +966,7 @@ class LongUriSerializerTest { versionMajor = 1 } val uResource: UResource = uResource { name = "door" } - val ucustomUri: String = LongUriSerializer.instance().serialize(uUri { + val ucustomUri: String = LongUriSerializer.INSTANCE.serialize(uUri { authority = uAuthority entity = use resource = uResource @@ -1001,7 +980,7 @@ class LongUriSerializerTest { @DisplayName("Test parse local uProtocol uri with custom scheme") fun test_parse_local_protocol_uri_with_custom_scheme() { val uri = "custom:/body.access//door.front_left#Door" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertFalse(uuri.authority.isRemote()) assertEquals("body.access", uuri.entity.name) assertEquals(0, uuri.entity.versionMajor) @@ -1017,7 +996,7 @@ class LongUriSerializerTest { fun test_parse_remote_protocol_uri_with_custom_scheme() { val uri = "custom://vcu.vin/body.access//door.front_left#Door" val uri2 = "//vcu.vin/body.access//door.front_left#Door" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) assertTrue(uuri.authority.isRemote()) assertEquals("vcu.vin", uuri.authority.name) assertEquals("body.access", uuri.entity.name) @@ -1025,39 +1004,39 @@ class LongUriSerializerTest { assertEquals("door", uuri.resource.name) assertEquals("front_left", uuri.resource.instance) assertEquals("Door", uuri.resource.message) - assertEquals(uri2, LongUriSerializer.instance().serialize(uuri)) + assertEquals(uri2, LongUriSerializer.INSTANCE.serialize(uuri)) } @Test @DisplayName("Test build resolved uri passing null") fun test_deserialize_long_and_micro_passing_null() { - val uri: Optional = LongUriSerializer.instance().buildResolved(null, null) - assertTrue(uri.isPresent) - assertEquals("", LongUriSerializer.instance().serialize(uri.get())) + val uri: UUri? = LongUriSerializer.INSTANCE.buildResolved(null, null) + checkNotNull(uri) + assertEquals("", LongUriSerializer.INSTANCE.serialize(uri)) } @Test @DisplayName("Test build resolved uri passing null long uri empty byte array") fun test_deserialize_long_and_micro_passing_null_long_uri_empty_byte_array() { - val uri: Optional = LongUriSerializer.instance().buildResolved(null, ByteArray(0)) - assertTrue(uri.isPresent) - assertEquals("", LongUriSerializer.instance().serialize(uri.get())) + val uri: UUri? = LongUriSerializer.INSTANCE.buildResolved(null, ByteArray(0)) + checkNotNull(uri) + assertEquals("", LongUriSerializer.INSTANCE.serialize(uri)) } @Test @DisplayName("Test build resolved uri passing empty long uri null byte array") fun test_deserialize_long_and_micro_passing_nullempty_long_uri_null_byte_array() { - val uri: Optional = LongUriSerializer.instance().buildResolved("", null) - assertTrue(uri.isPresent) - assertEquals("", LongUriSerializer.instance().serialize(uri.get())) + val uri: UUri? = LongUriSerializer.INSTANCE.buildResolved("", null) + checkNotNull(uri) + assertEquals("", LongUriSerializer.INSTANCE.serialize(uri)) } @Test @DisplayName("Test build resolved uri passing empty long uri, empty byte[]") fun test_deserialize_long_and_micro_passing_empty_long_uri_empty_byte_array() { - val uri: Optional = LongUriSerializer.instance().buildResolved("", ByteArray(0)) - assertTrue(uri.isPresent) - assertEquals("", LongUriSerializer.instance().serialize(uri.get())) + val uri: UUri? = LongUriSerializer.INSTANCE.buildResolved("", ByteArray(0)) + checkNotNull(uri) + assertEquals("", LongUriSerializer.INSTANCE.serialize(uri)) } // @Test @@ -1065,12 +1044,12 @@ class LongUriSerializerTest { // void test_deserialize_long_and_micro_passing_UAuthority_that_doesnt_match() { // String longUUri = "//vcu.vin/body.access//door.front_left#Door"; // byte[] microUUri = new byte[] {0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; - // Optional uri = LongUriSerializer.instance().buildResolved(longUUri, microUUri); + // Optional uri = LongUriSerializer.INSTANCE.buildResolved(longUUri, microUUri); // assertTrue(uri.isEmpty()); // // String longUUri1 = "/body.access//door.front_left#Door"; // byte[] microUUri1 = new byte[] {0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; - // Optional uri1 = LongUriSerializer.instance().buildResolved(longUUri1, microUUri1); + // Optional uri1 = LongUriSerializer.INSTANCE.buildResolved(longUUri1, microUUri1); // assertTrue(uri1.isEmpty()); // } // @Test @@ -1080,27 +1059,27 @@ class LongUriSerializerTest { // byte[] goodMicroUUri = new byte[] {0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; // String badLongUUri = "///"; // byte[] badMicroUUri = new byte[] {0x0, 0x0, 0x0, 0x0, 0x0}; - // Optional uri = LongUriSerializer.instance().buildResolved(goodLongUUri, goodMicroUUri); + // Optional uri = LongUriSerializer.INSTANCE.buildResolved(goodLongUUri, goodMicroUUri); // assertFalse(uri.isEmpty()); - // Optional uri2 = LongUriSerializer.instance().buildResolved(goodLongUUri, badMicroUUri); + // Optional uri2 = LongUriSerializer.INSTANCE.buildResolved(goodLongUUri, badMicroUUri); // assertTrue(uri2.isEmpty()); - // Optional uri3 = LongUriSerializer.instance().buildResolved(badLongUUri, goodMicroUUri); + // Optional uri3 = LongUriSerializer.INSTANCE.buildResolved(badLongUUri, goodMicroUUri); // assertTrue(uri3.isEmpty()); - // Optional uri4 = LongUriSerializer.instance().buildResolved(badLongUUri, badMicroUUri); + // Optional uri4 = LongUriSerializer.INSTANCE.buildResolved(badLongUUri, badMicroUUri); // assertTrue(uri4.isEmpty()); - // Optional uri5 = LongUriSerializer.instance().buildResolved("", goodMicroUUri); + // Optional uri5 = LongUriSerializer.INSTANCE.buildResolved("", goodMicroUUri); // assertTrue(uri5.isEmpty()); - // Optional uri6 = LongUriSerializer.instance().buildResolved("", badMicroUUri); + // Optional uri6 = LongUriSerializer.INSTANCE.buildResolved("", badMicroUUri); // assertTrue(uri6.isEmpty()); - // Optional uri7 = LongUriSerializer.instance().buildResolved(null, goodMicroUUri); + // Optional uri7 = LongUriSerializer.INSTANCE.buildResolved(null, goodMicroUUri); // assertTrue(uri7.isEmpty()); - // Optional uri8 = LongUriSerializer.instance().buildResolved(null, badMicroUUri); + // Optional uri8 = LongUriSerializer.INSTANCE.buildResolved(null, badMicroUUri); // assertTrue(uri8.isEmpty()); // // - // Optional uri9 = LongUriSerializer.instance().buildResolved(goodLongUUri, null); + // Optional uri9 = LongUriSerializer.INSTANCE.buildResolved(goodLongUUri, null); // assertTrue(uri9.isEmpty()); - // Optional uri10 = LongUriSerializer.instance().buildResolved(goodLongUUri, new byte[0]); + // Optional uri10 = LongUriSerializer.INSTANCE.buildResolved(goodLongUUri, new byte[0]); // assertTrue(uri10.isEmpty()); // // } diff --git a/src/test/kotlin/org/eclipse/uprotocol/uri/serializer/MicroUriSerializerTest.kt b/src/test/kotlin/org/eclipse/uprotocol/uri/serializer/MicroUriSerializerTest.kt index 46c8278..fa3f960 100644 --- a/src/test/kotlin/org/eclipse/uprotocol/uri/serializer/MicroUriSerializerTest.kt +++ b/src/test/kotlin/org/eclipse/uprotocol/uri/serializer/MicroUriSerializerTest.kt @@ -35,18 +35,9 @@ class MicroUriSerializerTest { @Test @DisplayName("Test serialize and deserialize empty content") fun test_empty() { - val bytes: ByteArray = MicroUriSerializer.instance().serialize(UUri.getDefaultInstance()) + val bytes: ByteArray = MicroUriSerializer.INSTANCE.serialize(UUri.getDefaultInstance()) assertEquals(bytes.size, 0) - val uri2: UUri = MicroUriSerializer.instance().deserialize(bytes) - assertTrue(uri2.isEmpty()) - } - - @Test - @DisplayName("Test serialize and deserialize null content") - fun test_null() { - val bytes: ByteArray = MicroUriSerializer.instance().serialize(null) - assertEquals(bytes.size, 0) - val uri2: UUri = MicroUriSerializer.instance().deserialize(null) + val uri2: UUri = MicroUriSerializer.INSTANCE.deserialize(bytes) assertTrue(uri2.isEmpty()) } @@ -61,8 +52,8 @@ class MicroUriSerializerTest { resource = uResource { id = 19999 } } - val bytes: ByteArray = MicroUriSerializer.instance().serialize(uri) - val uri2: UUri = MicroUriSerializer.instance().deserialize(bytes) + val bytes: ByteArray = MicroUriSerializer.INSTANCE.serialize(uri) + val uri2: UUri = MicroUriSerializer.INSTANCE.deserialize(bytes) assertTrue(uri.isMicroForm()) assertTrue(bytes.isNotEmpty()) assertEquals(uri, uri2) @@ -80,7 +71,7 @@ class MicroUriSerializerTest { resource = uResource { id = 19999 } } - val bytes: ByteArray = MicroUriSerializer.instance().serialize(uri) + val bytes: ByteArray = MicroUriSerializer.INSTANCE.serialize(uri) assertTrue(bytes.isEmpty()) } @@ -93,7 +84,7 @@ class MicroUriSerializerTest { } - val bytes: ByteArray = MicroUriSerializer.instance().serialize(uri) + val bytes: ByteArray = MicroUriSerializer.INSTANCE.serialize(uri) assertTrue(bytes.isEmpty()) } @@ -102,7 +93,7 @@ class MicroUriSerializerTest { fun test_serialize_uri_missing_resource_id() { val uri: UUri = uUri { entity = uEntity { name = "hartley" } } - val bytes: ByteArray = MicroUriSerializer.instance().serialize(uri) + val bytes: ByteArray = MicroUriSerializer.INSTANCE.serialize(uri) assertTrue(bytes.isEmpty()) } @@ -110,10 +101,10 @@ class MicroUriSerializerTest { @DisplayName("Test deserialize bad micro uri - length") fun test_deserialize_bad_microuri_length() { var badMicroUUri = byteArrayOf(0x1, 0x0, 0x0, 0x0, 0x0) - var uuri: UUri = MicroUriSerializer.instance().deserialize(badMicroUUri) + var uuri: UUri = MicroUriSerializer.INSTANCE.deserialize(badMicroUUri) assertTrue(uuri.isEmpty()) badMicroUUri = byteArrayOf(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0) - uuri = MicroUriSerializer.instance().deserialize(badMicroUUri) + uuri = MicroUriSerializer.INSTANCE.deserialize(badMicroUUri) assertTrue(uuri.isEmpty()) } @@ -121,7 +112,7 @@ class MicroUriSerializerTest { @DisplayName("Test deserialize bad micro uri - not version 1") fun test_deserialize_bad_microuri_not_version_1() { val badMicroUUri = byteArrayOf(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0) - val uuri: UUri = MicroUriSerializer.instance().deserialize(badMicroUUri) + val uuri: UUri = MicroUriSerializer.INSTANCE.deserialize(badMicroUUri) assertTrue(uuri.isEmpty()) } @@ -129,7 +120,7 @@ class MicroUriSerializerTest { @DisplayName("Test deserialize bad micro uri - not valid address type") fun test_deserialize_bad_microuri_not_valid_address_type() { val badMicroUUri = byteArrayOf(0x1, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0) - val uuri: UUri = MicroUriSerializer.instance().deserialize(badMicroUUri) + val uuri: UUri = MicroUriSerializer.INSTANCE.deserialize(badMicroUUri) assertTrue(uuri.isEmpty()) } @@ -137,13 +128,13 @@ class MicroUriSerializerTest { @DisplayName("Test deserialize bad micro uri - valid address type and invalid length") fun test_deserialize_bad_microuri_valid_address_type_invalid_length() { var badMicroUUri = byteArrayOf(0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0) - var uuri: UUri = MicroUriSerializer.instance().deserialize(badMicroUUri) + var uuri: UUri = MicroUriSerializer.INSTANCE.deserialize(badMicroUUri) assertTrue(uuri.isEmpty()) badMicroUUri = byteArrayOf(0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0) - uuri = MicroUriSerializer.instance().deserialize(badMicroUUri) + uuri = MicroUriSerializer.INSTANCE.deserialize(badMicroUUri) assertTrue(uuri.isEmpty()) badMicroUUri = byteArrayOf(0x1, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0) - uuri = MicroUriSerializer.instance().deserialize(badMicroUUri) + uuri = MicroUriSerializer.INSTANCE.deserialize(badMicroUUri) assertTrue(uuri.isEmpty()) } @@ -161,8 +152,8 @@ class MicroUriSerializerTest { } - val bytes: ByteArray = MicroUriSerializer.instance().serialize(uri) - val uri2: UUri = MicroUriSerializer.instance().deserialize(bytes) + val bytes: ByteArray = MicroUriSerializer.INSTANCE.serialize(uri) + val uri2: UUri = MicroUriSerializer.INSTANCE.deserialize(bytes) assertTrue(bytes.isNotEmpty()) assertTrue(uri.isMicroForm()) assertTrue(uri2.isMicroForm()) @@ -188,8 +179,8 @@ class MicroUriSerializerTest { resource = uResource { id = 19999 } } - val bytes: ByteArray = MicroUriSerializer.instance().serialize(uri) - val uri2: UUri = MicroUriSerializer.instance().deserialize(bytes) + val bytes: ByteArray = MicroUriSerializer.INSTANCE.serialize(uri) + val uri2: UUri = MicroUriSerializer.INSTANCE.deserialize(bytes) assertTrue(uri.isMicroForm()) assertTrue(bytes.isNotEmpty()) assertTrue(uri == uri2) @@ -213,8 +204,8 @@ class MicroUriSerializerTest { resource = uResource { id = 19999 } } - val bytes: ByteArray = MicroUriSerializer.instance().serialize(uri) - val uri2: UUri = MicroUriSerializer.instance().deserialize(bytes) + val bytes: ByteArray = MicroUriSerializer.INSTANCE.serialize(uri) + val uri2: UUri = MicroUriSerializer.INSTANCE.deserialize(bytes) assertTrue(uri.isMicroForm()) assertTrue(bytes.isNotEmpty()) assertTrue(uri == uri2) @@ -236,7 +227,7 @@ class MicroUriSerializerTest { resource = uResource { id = 19999 } } - val bytes: ByteArray = MicroUriSerializer.instance().serialize(uri) + val bytes: ByteArray = MicroUriSerializer.INSTANCE.serialize(uri) assertTrue(bytes.isEmpty()) } @@ -258,9 +249,9 @@ class MicroUriSerializerTest { resource = uResource { id = 19999 } } - val bytes: ByteArray = MicroUriSerializer.instance().serialize(uri) + val bytes: ByteArray = MicroUriSerializer.INSTANCE.serialize(uri) assertEquals(bytes.size, 9 + size) - val uri2: UUri = MicroUriSerializer.instance().deserialize(bytes) + val uri2: UUri = MicroUriSerializer.INSTANCE.deserialize(bytes) assertTrue(uri.isMicroForm()) assertTrue(uri == uri2) } diff --git a/src/test/kotlin/org/eclipse/uprotocol/uri/serializer/UriSerializerTest.kt b/src/test/kotlin/org/eclipse/uprotocol/uri/serializer/UriSerializerTest.kt index 7aea902..7ff787b 100644 --- a/src/test/kotlin/org/eclipse/uprotocol/uri/serializer/UriSerializerTest.kt +++ b/src/test/kotlin/org/eclipse/uprotocol/uri/serializer/UriSerializerTest.kt @@ -28,8 +28,6 @@ import org.eclipse.uprotocol.v1.* import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test -import java.util.* - class UriSerializerTest { @Test @@ -54,19 +52,19 @@ class UriSerializerTest { } - val microuri: ByteArray = MicroUriSerializer.instance().serialize(microUUri) - val longuri: String = LongUriSerializer.instance().serialize(longUUri) + val microuri: ByteArray = MicroUriSerializer.INSTANCE.serialize(microUUri) + val longuri: String = LongUriSerializer.INSTANCE.serialize(longUUri) - val resolvedUUri: Optional = LongUriSerializer.instance().buildResolved(longuri, microuri) - assertTrue(resolvedUUri.isPresent) - assertFalse(resolvedUUri.get().isEmpty()) - assertEquals("testauth", resolvedUUri.get().authority.name) - assertEquals("neelam", resolvedUUri.get().entity.name) - assertEquals(29999, resolvedUUri.get().entity.id) - assertEquals(254, resolvedUUri.get().entity.versionMajor) - assertEquals("rpc", resolvedUUri.get().resource.name) - assertEquals("response", resolvedUUri.get().resource.instance) - assertEquals(39999, resolvedUUri.get().resource.id) + val resolvedUUri: UUri? = LongUriSerializer.INSTANCE.buildResolved(longuri, microuri) + checkNotNull(resolvedUUri) + assertFalse(resolvedUUri.isEmpty()) + assertEquals("testauth", resolvedUUri.authority.name) + assertEquals("neelam", resolvedUUri.entity?.name) + assertEquals(29999, resolvedUUri.entity?.id) + assertEquals(254, resolvedUUri.entity?.versionMajor) + assertEquals("rpc", resolvedUUri.resource?.name) + assertEquals("response", resolvedUUri.resource?.instance) + assertEquals(39999, resolvedUUri.resource?.id) } @Test @@ -74,10 +72,10 @@ class UriSerializerTest { fun test_build_resolved_null_long_null_micro_uri() { // Test the buildResolved method with invalid input - val result: Optional = MicroUriSerializer.instance().buildResolved(null, null) - assertTrue(result.isPresent) + val result: UUri? = MicroUriSerializer.INSTANCE.buildResolved(null, null) + checkNotNull(result) // Assert that the result is empty - assertTrue(result.get().isEmpty()) + assertTrue(result.isEmpty()) } @Test @@ -85,10 +83,10 @@ class UriSerializerTest { fun test_build_resolved_null_long_micro_uri() { // Test the buildResolved method with invalid input - val result: Optional = MicroUriSerializer.instance().buildResolved(null, ByteArray(0)) - assertTrue(result.isPresent) + val result: UUri? = MicroUriSerializer.INSTANCE.buildResolved(null, ByteArray(0)) + checkNotNull(result) // Assert that the result is empty - assertTrue(result.get().isEmpty()) + assertTrue(result.isEmpty()) } @Test @@ -96,10 +94,10 @@ class UriSerializerTest { fun test_build_resolved_valid_long_null_micro_uri() { // Test the buildResolved method with invalid input - val result: Optional = MicroUriSerializer.instance().buildResolved("", ByteArray(0)) - assertTrue(result.isPresent) + val result: UUri? = MicroUriSerializer.INSTANCE.buildResolved("", ByteArray(0)) + checkNotNull(result) // Assert that the result is not empty - assertTrue(result.get().isEmpty()) + assertTrue(result.isEmpty()) } @Test diff --git a/src/test/kotlin/org/eclipse/uprotocol/uri/validator/UriValidatorTest.kt b/src/test/kotlin/org/eclipse/uprotocol/uri/validator/UriValidatorTest.kt index 5a5b27b..3631575 100644 --- a/src/test/kotlin/org/eclipse/uprotocol/uri/validator/UriValidatorTest.kt +++ b/src/test/kotlin/org/eclipse/uprotocol/uri/validator/UriValidatorTest.kt @@ -34,19 +34,10 @@ import java.io.FileReader import java.io.IOException internal class UriValidatorTest { - @Test - @DisplayName("Test validate blank uri") - fun test_validate_blank_uri() { - val uri: UUri = LongUriSerializer.instance().deserialize(null) - val status: ValidationResult = uri.validate() - assertTrue(uri.isEmpty()) - assertEquals("Uri is empty.", status.getMessage()) - } - @Test @DisplayName("Test validate uri with no device name") fun test_validate_uri_with_no_entity_getName() { - val uri: UUri = LongUriSerializer.instance().deserialize("//") + val uri: UUri = LongUriSerializer.INSTANCE.deserialize("//") val status: ValidationResult = uri.validate() assertTrue(uri.isEmpty()) assertEquals("Uri is empty.", status.getMessage()) @@ -55,7 +46,7 @@ internal class UriValidatorTest { @Test @DisplayName("Test validate uri with uEntity") fun test_validate_uri_with_getEntity() { - val uri: UUri = LongUriSerializer.instance().deserialize("/hartley") + val uri: UUri = LongUriSerializer.INSTANCE.deserialize("/hartley") val status: ValidationResult = uri.validate() assertEquals(ValidationResult.success(), status) } @@ -63,7 +54,7 @@ internal class UriValidatorTest { @Test @DisplayName("Test validate with malformed URI") fun test_validate_with_malformed_uri() { - val uri: UUri = LongUriSerializer.instance().deserialize("hartley") + val uri: UUri = LongUriSerializer.INSTANCE.deserialize("hartley") val status: ValidationResult = uri.validate() assertTrue(uri.isEmpty()) assertEquals("Uri is empty.", status.getMessage()) @@ -80,7 +71,7 @@ internal class UriValidatorTest { @Test @DisplayName("Test validateRpcMethod with valid URI") fun test_validateRpcMethod_with_valid_uri() { - val uri: UUri = LongUriSerializer.instance().deserialize("/hartley//rpc.echo") + val uri: UUri = LongUriSerializer.INSTANCE.deserialize("/hartley//rpc.echo") val status: ValidationResult = uri.validateRpcMethod() assertEquals(ValidationResult.success(), status) } @@ -88,7 +79,7 @@ internal class UriValidatorTest { @Test @DisplayName("Test validateRpcMethod with invalid URI") fun test_validateRpcMethod_with_invalid_uri() { - val uri: UUri = LongUriSerializer.instance().deserialize("/hartley/echo") + val uri: UUri = LongUriSerializer.INSTANCE.deserialize("/hartley/echo") val status: ValidationResult = uri.validateRpcMethod() assertTrue(status.isFailure()) assertEquals("Uri is empty.", status.getMessage()) @@ -97,7 +88,7 @@ internal class UriValidatorTest { @Test @DisplayName("Test validateRpcMethod with malformed URI") fun test_validateRpcMethod_with_malformed_uri() { - val uri: UUri = LongUriSerializer.instance().deserialize("hartley") + val uri: UUri = LongUriSerializer.INSTANCE.deserialize("hartley") val status: ValidationResult = uri.validateRpcMethod() assertTrue(uri.isEmpty()) assertEquals("Uri is empty.", status.getMessage()) @@ -106,7 +97,7 @@ internal class UriValidatorTest { @Test @DisplayName("Test validateRpcResponse with valid URI") fun test_validateRpcResponse_with_valid_uri() { - val uri: UUri = LongUriSerializer.instance().deserialize("/hartley//rpc.response") + val uri: UUri = LongUriSerializer.INSTANCE.deserialize("/hartley//rpc.response") val status: ValidationResult = uri.validateRpcResponse() assertEquals(ValidationResult.success(), status) } @@ -114,7 +105,7 @@ internal class UriValidatorTest { @Test @DisplayName("Test validateRpcResponse with malformed URI") fun test_validateRpcResponse_with_malformed_uri() { - val uri: UUri = LongUriSerializer.instance().deserialize("hartley") + val uri: UUri = LongUriSerializer.INSTANCE.deserialize("hartley") val status: ValidationResult = uri.validateRpcResponse() assertTrue(uri.isEmpty()) assertEquals("Uri is empty.", status.getMessage()) @@ -123,7 +114,7 @@ internal class UriValidatorTest { @Test @DisplayName("Test validateRpcResponse with rpc type") fun test_validateRpcResponse_with_rpc_type() { - val uri: UUri = LongUriSerializer.instance().deserialize("/hartley//dummy.wrong") + val uri: UUri = LongUriSerializer.INSTANCE.deserialize("/hartley//dummy.wrong") val status: ValidationResult = uri.validateRpcResponse() assertTrue(status.isFailure()) assertEquals("Invalid RPC response type.", status.getMessage()) @@ -132,7 +123,7 @@ internal class UriValidatorTest { @Test @DisplayName("Test validateRpcResponse with invalid rpc response type") fun test_validateRpcResponse_with_invalid_rpc_response_type() { - val uri: UUri = LongUriSerializer.instance().deserialize("/hartley//rpc.wrong") + val uri: UUri = LongUriSerializer.INSTANCE.deserialize("/hartley//rpc.wrong") val status: ValidationResult = uri.validateRpcResponse() assertTrue(status.isFailure()) assertEquals("Invalid RPC response type.", status.getMessage()) @@ -142,7 +133,7 @@ internal class UriValidatorTest { @DisplayName("Test validate topic uri with version, when it is valid microRemote") fun test_topic_uri_with_version_when_it_is_valid_remote() { val uri = "//VCU.MY_CAR_VIN/body.access/1/door.front_left#Door" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validate() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validate() assertTrue(status.isSuccess()) } @@ -150,7 +141,7 @@ internal class UriValidatorTest { @DisplayName("Test validate topic uri no version, when it is valid microRemote") fun test_topic_uri_no_version_when_it_is_valid_remote() { val uri = "//VCU.MY_CAR_VIN/body.access//door.front_left#Door" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validate() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validate() assertTrue(status.isSuccess()) } @@ -158,7 +149,7 @@ internal class UriValidatorTest { @DisplayName("Test validate topic uri with version, when it is valid local") fun test_topic_uri_with_version_when_it_is_valid_local() { val uri = "/body.access/1/door.front_left#Door" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validate() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validate() assertTrue(status.isSuccess()) } @@ -166,7 +157,7 @@ internal class UriValidatorTest { @DisplayName("Test validate topic uri no version, when it is valid local") fun test_topic_uri_no_version_when_it_is_valid_local() { val uri = "/body.access//door.front_left#Door" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validate() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validate() assertTrue(status.isSuccess()) } @@ -174,7 +165,7 @@ internal class UriValidatorTest { @DisplayName("Test validate topic uri is invalid when uri contains nothing but schema") fun test_topic_uri_invalid_when_uri_has_schema_only() { val uri = ":" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validate() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validate() assertTrue(status.isFailure()) } @@ -182,7 +173,7 @@ internal class UriValidatorTest { @DisplayName("Test validate topic uri is invalid when uri contains empty use name local") fun test_topic_uri_invalid_when_uri_has_empty_use_name_local() { val uri = "/" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validate() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validate() assertTrue(status.isFailure()) } @@ -190,7 +181,7 @@ internal class UriValidatorTest { @DisplayName("Test validate topic uri is invalid when uri is microRemote but missing authority") fun test_topic_uri_invalid_when_uri_is_remote_no_authority() { val uri = "//" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validate() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validate() assertTrue(status.isFailure()) } @@ -198,7 +189,7 @@ internal class UriValidatorTest { @DisplayName("Test validate topic uri is invalid when uri is microRemote with use but missing authority") fun test_topic_uri_invalid_when_uri_is_remote_no_authority_with_use() { val uri = "///body.access/1/door.front_left#Door" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validate() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validate() assertTrue(status.isFailure()) } @@ -206,7 +197,7 @@ internal class UriValidatorTest { @DisplayName("Test validate topic uri is invalid when uri has no use information") fun test_topic_uri_invalid_when_uri_is_missing_use_remote() { val uri = "//VCU.myvin///door.front_left#Door" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validate() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validate() assertTrue(status.isFailure()) } @@ -214,7 +205,7 @@ internal class UriValidatorTest { @DisplayName("Test validate microRemote topic uri is invalid when uri is missing use name") fun test_topic_uri_invalid_when_uri_is_missing_use_name_remote() { val uri = "/1/door.front_left#Door" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validate() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validate() assertTrue(status.isFailure()) } @@ -222,7 +213,7 @@ internal class UriValidatorTest { @DisplayName("Test validate local topic uri is invalid when uri is missing use name") fun test_topic_uri_invalid_when_uri_is_missing_use_name_local() { val uri = "//VCU.myvin//1" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validate() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validate() assertTrue(status.isFailure()) } @@ -230,7 +221,7 @@ internal class UriValidatorTest { @DisplayName("Test validate rpc topic uri with version, when it is valid microRemote") fun test_rpc_topic_uri_with_version_when_it_is_valid_remote() { val uri = "//bo.cloud/petapp/1/rpc.response" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validateRpcMethod() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validateRpcMethod() assertTrue(status.isSuccess()) } @@ -238,7 +229,7 @@ internal class UriValidatorTest { @DisplayName("Test validate rpc topic uri no version, when it is valid microRemote") fun test_rpc_topic_uri_no_version_when_it_is_valid_remote() { val uri = "//bo.cloud/petapp//rpc.response" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validateRpcMethod() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validateRpcMethod() assertTrue(status.isSuccess()) } @@ -246,7 +237,7 @@ internal class UriValidatorTest { @DisplayName("Test validate rpc topic uri with version, when it is valid local") fun test_rpc_topic_uri_with_version_when_it_is_valid_local() { val uri = "/petapp/1/rpc.response" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validateRpcMethod() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validateRpcMethod() assertTrue(status.isSuccess()) } @@ -254,7 +245,7 @@ internal class UriValidatorTest { @DisplayName("Test validate rpc topic uri no version, when it is valid local") fun test_rpc_topic_uri_no_version_when_it_is_valid_local() { val uri = "/petapp//rpc.response" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validateRpcMethod() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validateRpcMethod() assertTrue(status.isSuccess()) } @@ -262,7 +253,7 @@ internal class UriValidatorTest { @DisplayName("Test validate rpc topic uri is invalid when uri contains nothing but schema") fun test_rpc_topic_uri_invalid_when_uri_has_schema_only() { val uri = ":" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validateRpcMethod() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validateRpcMethod() assertTrue(status.isFailure()) } @@ -270,7 +261,7 @@ internal class UriValidatorTest { @DisplayName("Test validate rpc topic uri with version, when it is local but missing rpc.respons") fun test_rpc_topic_uri_with_version_when_it_is_not_valid_missing_rpc_response_local() { val uri = "/petapp/1/dog" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validateRpcMethod() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validateRpcMethod() assertTrue(status.isFailure()) } @@ -278,7 +269,7 @@ internal class UriValidatorTest { @DisplayName("Test validate rpc topic uri with version, when it is microRemote but missing rpc.respons") fun test_rpc_topic_uri_with_version_when_it_is_not_valid_missing_rpc_response_remote() { val uri = "//petapp/1/dog" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validateRpcMethod() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validateRpcMethod() assertTrue(status.isFailure()) } @@ -286,7 +277,7 @@ internal class UriValidatorTest { @DisplayName("Test validate rpc topic uri is invalid when uri is microRemote but missing authority") fun test_rpc_topic_uri_invalid_when_uri_is_remote_no_authority() { val uri = "//" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validateRpcMethod() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validateRpcMethod() assertTrue(status.isFailure()) } @@ -294,7 +285,7 @@ internal class UriValidatorTest { @DisplayName("Test validate rpc topic uri is invalid when uri is microRemote with use but missing authority") fun test_rpc_topic_uri_invalid_when_uri_is_remote_no_authority_with_use() { val uri = "///body.access/1" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validateRpcMethod() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validateRpcMethod() assertTrue(status.isFailure()) } @@ -302,7 +293,7 @@ internal class UriValidatorTest { @DisplayName("Test validate rpc topic uri is invalid when uri has no use information") fun test_rpc_topic_uri_invalid_when_uri_is_missing_use() { val uri = "//VCU.myvin" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validateRpcMethod() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validateRpcMethod() assertTrue(status.isFailure()) } @@ -310,7 +301,7 @@ internal class UriValidatorTest { @DisplayName("Test validate microRemote rpc topic uri is invalid when uri is missing use name") fun test_rpc_topic_uri_invalid_when_uri_is_missing_use_name_remote() { val uri = "/1" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validateRpcMethod() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validateRpcMethod() assertTrue(status.isFailure()) } @@ -318,7 +309,7 @@ internal class UriValidatorTest { @DisplayName("Test validate local rpc topic uri is invalid when uri is missing use name") fun test_rpc_topic_uri_invalid_when_uri_is_missing_use_name_local() { val uri = "//VCU.myvin//1" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validateRpcMethod() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validateRpcMethod() assertTrue(status.isFailure()) } @@ -326,7 +317,7 @@ internal class UriValidatorTest { @DisplayName("Test validate rpc method uri with version, when it is valid microRemote") fun test_rpc_method_uri_with_version_when_it_is_valid_remote() { val uri = "//VCU.myvin/body.access/1/rpc.UpdateDoor" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validateRpcMethod() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validateRpcMethod() assertTrue(status.isSuccess()) } @@ -334,7 +325,7 @@ internal class UriValidatorTest { @DisplayName("Test validate rpc method uri no version, when it is valid microRemote") fun test_rpc_method_uri_no_version_when_it_is_valid_remote() { val uri = "//VCU.myvin/body.access//rpc.UpdateDoor" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validateRpcMethod() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validateRpcMethod() assertTrue(status.isSuccess()) } @@ -342,7 +333,7 @@ internal class UriValidatorTest { @DisplayName("Test validate rpc method uri with version, when it is valid local") fun test_rpc_method_uri_with_version_when_it_is_valid_local() { val uri = "/body.access/1/rpc.UpdateDoor" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validateRpcMethod() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validateRpcMethod() assertTrue(status.isSuccess()) } @@ -350,7 +341,7 @@ internal class UriValidatorTest { @DisplayName("Test validate rpc method uri no version, when it is valid local") fun test_rpc_method_uri_no_version_when_it_is_valid_local() { val uri = "/body.access//rpc.UpdateDoor" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validateRpcMethod() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validateRpcMethod() assertTrue(status.isSuccess()) } @@ -358,7 +349,7 @@ internal class UriValidatorTest { @DisplayName("Test validate rpc method uri is invalid when uri contains nothing but schema") fun test_rpc_method_uri_invalid_when_uri_has_schema_only() { val uri = ":" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validateRpcMethod() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validateRpcMethod() assertTrue(status.isFailure()) } @@ -366,7 +357,7 @@ internal class UriValidatorTest { @DisplayName("Test validate rpc method uri with version, when it is local but not an rpc method") fun test_rpc_method_uri_with_version_when_it_is_not_valid_not_rpc_method_local() { val uri = "/body.access//UpdateDoor" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validateRpcMethod() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validateRpcMethod() assertTrue(status.isFailure()) } @@ -374,7 +365,7 @@ internal class UriValidatorTest { @DisplayName("Test validate rpc method uri with version, when it is microRemote but not an rpc method") fun test_rpc_method_uri_with_version_when_it_is_not_valid_not_rpc_method_remote() { val uri = "//body.access/1/UpdateDoor" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validateRpcMethod() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validateRpcMethod() assertTrue(status.isFailure()) } @@ -382,7 +373,7 @@ internal class UriValidatorTest { @DisplayName("Test validate rpc method uri is invalid when uri is microRemote but missing authority") fun test_rpc_method_uri_invalid_when_uri_is_remote_no_authority() { val uri = "//" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validateRpcMethod() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validateRpcMethod() assertTrue(status.isFailure()) } @@ -390,7 +381,7 @@ internal class UriValidatorTest { @DisplayName("Test validate rpc method uri is invalid when uri is microRemote with use but missing authority") fun test_rpc_method_uri_invalid_when_uri_is_remote_no_authority_with_use() { val uri = "///body.access/1/rpc.UpdateDoor" - val uuri: UUri = LongUriSerializer.instance().deserialize(uri) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uri) val status: ValidationResult = uuri.validateRpcMethod() assertEquals("", uuri.toString()) assertTrue(status.isFailure()) @@ -418,7 +409,7 @@ internal class UriValidatorTest { @DisplayName("Test validate rpc method uri is invalid when uri has no use information") fun test_rpc_method_uri_invalid_when_uri_is_missing_use() { val uri = "//VCU.myvin" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validateRpcMethod() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validateRpcMethod() assertTrue(status.isFailure()) } @@ -426,7 +417,7 @@ internal class UriValidatorTest { @DisplayName("Test validate local rpc method uri is invalid when uri is missing use name") fun test_rpc_method_uri_invalid_when_uri_is_missing_use_name_local() { val uri = "/1/rpc.UpdateDoor" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validateRpcMethod() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validateRpcMethod() assertTrue(status.isFailure()) } @@ -434,7 +425,7 @@ internal class UriValidatorTest { @DisplayName("Test validate microRemote rpc method uri is invalid when uri is missing use name") fun test_rpc_method_uri_invalid_when_uri_is_missing_use_name_remote() { val uri = "//VCU.myvin//1/rpc.UpdateDoor" - val status: ValidationResult = LongUriSerializer.instance().deserialize(uri).validateRpcMethod() + val status: ValidationResult = LongUriSerializer.INSTANCE.deserialize(uri).validateRpcMethod() assertTrue(status.isFailure()) } @@ -445,7 +436,7 @@ internal class UriValidatorTest { // Access the "validUris" array val validUris: JSONArray = jsonObject.getJSONArray("validUris") for (i in 0 until validUris.length()) { - val uuri: UUri = LongUriSerializer.instance().deserialize(validUris.getString(i)) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(validUris.getString(i)) val status: ValidationResult = uuri.validate() assertTrue(status.isSuccess()) } @@ -459,7 +450,7 @@ internal class UriValidatorTest { val invalidUris: JSONArray = jsonObject.getJSONArray("invalidUris") for (i in 0 until invalidUris.length()) { val uriObject: JSONObject = invalidUris.getJSONObject(i) - val uuri: UUri = LongUriSerializer.instance().deserialize(uriObject.getString("uri")) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uriObject.getString("uri")) val status: ValidationResult = uuri.validate() assertTrue(status.isFailure()) assertEquals(status.getMessage(), uriObject.getString("status_message")) @@ -473,7 +464,7 @@ internal class UriValidatorTest { // Access the "validRpcUris" array val validRpcUris: JSONArray = jsonObject.getJSONArray("validRpcUris") for (i in 0 until validRpcUris.length()) { - val uuri: UUri = LongUriSerializer.instance().deserialize(validRpcUris.getString(i)) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(validRpcUris.getString(i)) val status: ValidationResult = uuri.validateRpcMethod() assertTrue(status.isSuccess()) } @@ -487,7 +478,7 @@ internal class UriValidatorTest { val invalidRpcUris: JSONArray = jsonObject.getJSONArray("invalidRpcUris") for (i in 0 until invalidRpcUris.length()) { val uriObject: JSONObject = invalidRpcUris.getJSONObject(i) - val uuri: UUri = LongUriSerializer.instance().deserialize(uriObject.getString("uri")) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(uriObject.getString("uri")) val status: ValidationResult = uuri.validateRpcMethod() assertTrue(status.isFailure()) assertEquals(status.getMessage(), uriObject.getString("status_message")) @@ -501,7 +492,7 @@ internal class UriValidatorTest { // Access the "validRpcResponseUris" array val validRpcResponseUris: JSONArray = jsonObject.getJSONArray("validRpcResponseUris") for (i in 0 until validRpcResponseUris.length()) { - val uuri: UUri = LongUriSerializer.instance().deserialize(validRpcResponseUris.getString(i)) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(validRpcResponseUris.getString(i)) val status: ValidationResult = uuri.validateRpcResponse() assertTrue(uuri.isRpcResponse()) assertTrue(status.isSuccess()) @@ -564,7 +555,7 @@ internal class UriValidatorTest { // Access the "invalidRpcResponseUris" array val invalidRpcResponseUris: JSONArray = jsonObject.getJSONArray("invalidRpcResponseUris") for (i in 0 until invalidRpcResponseUris.length()) { - val uuri: UUri = LongUriSerializer.instance().deserialize(invalidRpcResponseUris.getString(i)) + val uuri: UUri = LongUriSerializer.INSTANCE.deserialize(invalidRpcResponseUris.getString(i)) val status: ValidationResult = uuri.validateRpcResponse() assertTrue(status.isFailure()) }