Skip to content

Commit

Permalink
Rename UriParts to UriFormat
Browse files Browse the repository at this point in the history
Also make UUri implement this interface (cuz it should).
  • Loading branch information
czfdcn committed Sep 19, 2023
1 parent d19bc64 commit d9d8f2b
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* Devices will be grouped together into realms of Zone of Authority.<br>
* An Authority represents the deployment location of a specific Software Entity in the Ultiverse.
*/
public class UAuthority implements UriPart {
public class UAuthority implements UriFormat {
private final static UAuthority EMPTY = new UAuthority(null, null, null, false, true);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* A uE that publishes events is a <b>Service</b> role.<br>
* A uE that consumes events is an <b>Application</b> role.
*/
public class UEntity implements UriPart {
public class UEntity implements UriFormat {
private static final UEntity EMPTY = new UEntity("", null, null, false);

private final String name; // uE Name
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/eclipse/uprotocol/uri/datamodel/UResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* An UResource is something that can be manipulated/controlled/exposed by a service. Resources are unique when prepended with UAuthority that represents the device and
* UEntity that represents the service.
*/
public class UResource implements UriPart {
public class UResource implements UriFormat {

private static final UResource EMPTY = new UResource("", null,null, null, false);

Expand Down Expand Up @@ -71,24 +71,24 @@ private UResource(String name, String instance, String message, Short id, boolea
* @param message The Message type matches the protobuf service IDL message name that defines structured data types.
* A message is a data structure type used to define data that is passed in events and rpc methods.
* @param id The numeric representation of this uResource.
* @return Returns a UResource that has all the information that is needed to serialise into a long UUri or a micro UUri.
* @return Returns a UResource that has all the information that is needed to serialize into a long UUri or a micro UUri.
*/
public static UResource resolved(String name, String instance, String message, Short id) {
public static UResource resolvedFormat(String name, String instance, String message, Short id) {
boolean resolved = name != null && !name.isEmpty() && instance != null && !instance.isEmpty() && id != null;
return new UResource(name, instance, message, id, resolved);
}

/**
* Build a UResource that can be serialised into a long UUri. Mostly used for publishing messages.
* Build a UResource that can be serialized into a long UUri. Mostly used for publishing messages.
* @param name The name of the resource as a noun such as door or window, or in the case a method that manipulates the resource, a verb.
* @return Returns a UResource that can be serialised into a long UUri.
* @return Returns a UResource that can be serialized into a long UUri.
*/
public static UResource longFormat(String name) {
return new UResource(name, null, null, null, false);
}

/**
* Build a UResource that can be serialised into a long UUri. Mostly used for publishing messages.
* Build a UResource that can be serialized into a long UUri. Mostly used for publishing messages.
* @param name The name of the resource as a noun such as door or window, or in the case a method that manipulates the resource, a verb.
* @param instance An instance of a resource such as front_left.
* @param message The Message type matches the protobuf service IDL message name that defines structured data types.
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/eclipse/uprotocol/uri/datamodel/UUri.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* </pre>
*
*/
public class UUri {
public class UUri implements UriFormat {
private static final UUri EMPTY = new UUri(UAuthority.empty(), UEntity.empty(), UResource.empty());

private final UAuthority uAuthority;
Expand Down Expand Up @@ -89,6 +89,7 @@ public static UUri empty() {
* Indicates that this URI is an empty container and has no valuable information in building uProtocol sinks or sources.
* @return Returns true if this URI is an empty container and has no valuable information in building uProtocol sinks or sources.
*/
@Override
public boolean isEmpty() {
return uAuthority.isLocal() && uEntity().isEmpty()
&& uResource.isEmpty();
Expand All @@ -100,6 +101,7 @@ public boolean isEmpty() {
* @return Returns true if URI contains both names and numeric representations of the names inside its belly.
* Meaning that this UUri can be serialised to long or micro formats.
*/
@Override
public boolean isResolved() {
return uAuthority.isResolved() && uEntity.isResolved() && uResource.isResolved();
}
Expand All @@ -108,6 +110,7 @@ public boolean isResolved() {
* Determines if this UUri can be serialised into a long form UUri.
* @return Returns true if this UUri can be serialised into a long form UUri.
*/
@Override
public boolean isLongForm() {
return uAuthority.isLongForm() && uEntity.isLongForm() && uResource.isLongForm();
}
Expand All @@ -116,6 +119,7 @@ public boolean isLongForm() {
* Determines if this UUri can be serialised into a micro form UUri.
* @return Returns true if this UUri can be serialised into a micro form UUri.
*/
@Override
public boolean isMicroForm() {
return uAuthority.isMicroForm() && uEntity.isMicroForm() && uResource.isMicroForm();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.eclipse.uprotocol.uri.datamodel;

/**
* Basic building blocks for all data models that are part of a uProtocol URI.
* The interface defines APIs that MUST be implemented in all Uri uProtocol parts.
* Interface used to provide hints as to how the Uri part or Uri itself is formated meaning does it contain
* long format, micro format or both (resolved) information.
*/
public interface UriPart {
public interface UriFormat {

/**
* Supporting empty Uri parts enables avoiding null values in the data model, and can indicate the absence of a Uri Part.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void test_create_rpc_response_using_response_method() {
@Test
@DisplayName("Test creating an UResource with valid id")
public void test_create_UResource_with_valid_id() {
UResource uResource = UResource.resolved("door", "front_left", "Door", (short)5);
UResource uResource = UResource.resolvedFormat("door", "front_left", "Door", (short)5);
assertEquals("door", uResource.name());
assertTrue(uResource.instance().isPresent());
assertEquals("front_left", uResource.instance().get());
Expand All @@ -165,7 +165,7 @@ public void test_create_UResource_with_valid_id() {
@Test
@DisplayName("Test creating an UResource with invalid id")
public void test_create_UResource_with_invalid_id() {
UResource uResource = UResource.resolved("door", "front_left", "Door", null);
UResource uResource = UResource.resolvedFormat("door", "front_left", "Door", null);
assertEquals("door", uResource.name());
assertTrue(uResource.instance().isPresent());
assertEquals("front_left", uResource.instance().get());
Expand Down Expand Up @@ -203,7 +203,7 @@ public void test_create_response_UResource_by_calling_fromId() {
@Test
@DisplayName("Test creating a response UResource passing name, instance, and id")
public void test_create_response_UResource_passing_name_instance_and_id() {
UResource uResource = UResource.resolved("rpc", "response", null, (short)0);
UResource uResource = UResource.resolvedFormat("rpc", "response", null, (short)0);
assertEquals("rpc", uResource.name());
assertTrue(uResource.instance().isPresent());
assertEquals("response", uResource.instance().get());
Expand All @@ -216,7 +216,7 @@ public void test_create_response_UResource_passing_name_instance_and_id() {
@Test
@DisplayName("Test creating a request UResource passing name, instance, and id")
public void test_create_request_UResource_passing_name_instance_and_id() {
UResource uResource = UResource.resolved("rpc", null, null, (short)0);
UResource uResource = UResource.resolvedFormat("rpc", null, null, (short)0);
assertEquals("rpc", uResource.name());
assertTrue(uResource.instance().isEmpty());
assertTrue(uResource.message().isEmpty());
Expand All @@ -228,7 +228,7 @@ public void test_create_request_UResource_passing_name_instance_and_id() {
@Test
@DisplayName("Test isResolved with resolved UResources")
public void test_isResolved_with_resolved_UResources() {
UResource uResource = UResource.resolved("door", "front_left", "Door", (short)5);
UResource uResource = UResource.resolvedFormat("door", "front_left", "Door", (short)5);
assertTrue(uResource.isResolved());
UResource uResource2 = UResource.forRpcResponse();
assertTrue(uResource2.isResolved());
Expand All @@ -239,7 +239,7 @@ public void test_isResolved_with_resolved_UResources() {
@Test
@DisplayName("Test isResolved and isLongForm with unresolved UResources")
public void test_isResolved_with_unresolved_UResources() {
UResource uResource = UResource.resolved("door", "front_left", "Door", null);
UResource uResource = UResource.resolvedFormat("door", "front_left", "Door", null);
assertFalse(uResource.isResolved());
assertTrue(uResource.isLongForm());
UResource uResource2 = UResource.longFormat("door");
Expand All @@ -261,37 +261,37 @@ public void test_isResolved_with_unresolved_UResources() {
@Test
@DisplayName("Test resolved API with all possible combinations of the APIs passed valid and invalid")
public void test_resolved_API_with_all_possible_combinations_of_the_APIs_passed_valid_and_invalid() {
UResource uResource = UResource.resolved("door", "front_left", "Door", (short)5);
UResource uResource = UResource.resolvedFormat("door", "front_left", "Door", (short)5);
assertTrue(uResource.isResolved());
UResource uResource2 = UResource.resolved("door", "front_left", "Door", null);
UResource uResource2 = UResource.resolvedFormat("door", "front_left", "Door", null);
assertFalse(uResource2.isResolved());
UResource uResource3 = UResource.resolved("door", "front_left", null, (short)5);
UResource uResource3 = UResource.resolvedFormat("door", "front_left", null, (short)5);
assertTrue(uResource3.isResolved());
UResource uResource4 = UResource.resolved("door", "front_left", null, null);
UResource uResource4 = UResource.resolvedFormat("door", "front_left", null, null);
assertFalse(uResource4.isResolved());
UResource uResource5 = UResource.resolved("door", null, "Door", (short)5);
UResource uResource5 = UResource.resolvedFormat("door", null, "Door", (short)5);
assertFalse(uResource5.isResolved());
UResource uResource6 = UResource.resolved("door", null, "Door", null);
UResource uResource6 = UResource.resolvedFormat("door", null, "Door", null);
assertFalse(uResource6.isResolved());
UResource uResource7 = UResource.resolved("door", null, null, (short)5);
UResource uResource7 = UResource.resolvedFormat("door", null, null, (short)5);
assertFalse(uResource7.isResolved());
UResource uResource8 = UResource.resolved("door", null, null, null);
UResource uResource8 = UResource.resolvedFormat("door", null, null, null);
assertFalse(uResource8.isResolved());
UResource uResource9 = UResource.resolved(null, "front_left", "Door", (short)5);
UResource uResource9 = UResource.resolvedFormat(null, "front_left", "Door", (short)5);
assertFalse(uResource9.isResolved());
UResource uResource10 = UResource.resolved(null, "front_left", "Door", null);
UResource uResource10 = UResource.resolvedFormat(null, "front_left", "Door", null);
assertFalse(uResource10.isResolved());
UResource uResource11 = UResource.resolved(null, "front_left", null, (short)5);
UResource uResource11 = UResource.resolvedFormat(null, "front_left", null, (short)5);
assertFalse(uResource11.isResolved());
UResource uResource12 = UResource.resolved(null, "front_left", null, null);
UResource uResource12 = UResource.resolvedFormat(null, "front_left", null, null);
assertFalse(uResource12.isResolved());
UResource uResource13 = UResource.resolved(null, null, "Door", (short)5);
UResource uResource13 = UResource.resolvedFormat(null, null, "Door", (short)5);
assertFalse(uResource13.isResolved());
UResource uResource14 = UResource.resolved(null, null, "Door", null);
UResource uResource14 = UResource.resolvedFormat(null, null, "Door", null);
assertFalse(uResource14.isResolved());
UResource uResource15 = UResource.resolved(null, null, null, (short)5);
UResource uResource15 = UResource.resolvedFormat(null, null, null, (short)5);
assertFalse(uResource15.isResolved());
UResource uResource16 = UResource.resolved(null, null, null, null);
UResource uResource16 = UResource.resolvedFormat(null, null, null, null);
assertFalse(uResource16.isResolved());
}

Expand Down
12 changes: 6 additions & 6 deletions src/test/java/org/eclipse/uprotocol/uri/datamodel/UUriTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ public void test_isResolved_and_isLongForm() throws UnknownHostException {
assertFalse(uri2.isResolved());
assertTrue(uri2.isLongForm());

UUri uri3 = new UUri(UAuthority.local(), UEntity.longFormat("Hartley"), UResource.resolved("Raise", "Salary", "Bonus", (short)1));
UUri uri3 = new UUri(UAuthority.local(), UEntity.longFormat("Hartley"), UResource.resolvedFormat("Raise", "Salary", "Bonus", (short)1));
assertFalse(uri3.isResolved());
assertTrue(uri3.isLongForm());

UUri uri4 = new UUri(UAuthority.local(), UEntity.resolvedFormat("Hartley", null, (short)2), UResource.resolved("Raise", "Salary", "Bonus", (short)1));
UUri uri4 = new UUri(UAuthority.local(), UEntity.resolvedFormat("Hartley", null, (short)2), UResource.resolvedFormat("Raise", "Salary", "Bonus", (short)1));
assertTrue(uri4.isResolved());
assertTrue(uri4.isLongForm());

Expand All @@ -195,11 +195,11 @@ public void test_isResolved_and_isLongForm() throws UnknownHostException {
assertFalse(uri5.isResolved());
assertTrue(uri5.isLongForm());

UUri uri6 = new UUri(UAuthority.resolvedRemote("vcu", "vin", null), UEntity.longFormat("Hartley"), UResource.resolved("Raise", "Salary", "Bonus", (short)1));
UUri uri6 = new UUri(UAuthority.resolvedRemote("vcu", "vin", null), UEntity.longFormat("Hartley"), UResource.resolvedFormat("Raise", "Salary", "Bonus", (short)1));
assertFalse(uri6.isResolved());
assertTrue(uri6.isLongForm());

UUri uri7 = new UUri(UAuthority.resolvedRemote("vcu", "vin", null), UEntity.longFormat("Hartley"), UResource.resolved("Raise", "Salary", "Bonus", (short)1));
UUri uri7 = new UUri(UAuthority.resolvedRemote("vcu", "vin", null), UEntity.longFormat("Hartley"), UResource.resolvedFormat("Raise", "Salary", "Bonus", (short)1));
assertFalse(uri7.isResolved());
assertTrue(uri7.isLongForm());

Expand All @@ -208,11 +208,11 @@ public void test_isResolved_and_isLongForm() throws UnknownHostException {
assertFalse(uri8.isResolved());
assertTrue(uri8.isLongForm());

UUri uri9 = new UUri(UAuthority.resolvedRemote("vcu", "vin", InetAddress.getByName("192.168.1.100")), UEntity.longFormat("Hartley"), UResource.resolved("Raise", "Salary", "Bonus", (short)1));
UUri uri9 = new UUri(UAuthority.resolvedRemote("vcu", "vin", InetAddress.getByName("192.168.1.100")), UEntity.longFormat("Hartley"), UResource.resolvedFormat("Raise", "Salary", "Bonus", (short)1));
assertFalse(uri9.isResolved());
assertTrue(uri9.isLongForm());

UUri uri10 = new UUri(UAuthority.resolvedRemote("vcu", "vin", InetAddress.getByName("192.168.1.100")), UEntity.resolvedFormat("Hartley", null, (short)2), UResource.resolved("Raise", "Salary", "Bonus", (short)1));
UUri uri10 = new UUri(UAuthority.resolvedRemote("vcu", "vin", InetAddress.getByName("192.168.1.100")), UEntity.resolvedFormat("Hartley", null, (short)2), UResource.resolvedFormat("Raise", "Salary", "Bonus", (short)1));
assertTrue(uri10.isResolved());
assertTrue(uri10.isLongForm());

Expand Down

0 comments on commit d9d8f2b

Please sign in to comment.