Skip to content

Commit

Permalink
Update the unit test for more coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
dddj698 committed Jun 20, 2024
1 parent 615de33 commit 2683c57
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -545,4 +545,15 @@ internal class UAttributesValidatorTest {
assertEquals(validator.toString(), "UAttributesValidator.Response")
assertEquals(result.getMessage(), "Invalid correlation UUID")
}

@Test
@DisplayName("Test getValidator for other type of messages")
fun testUAttributeValidatorGetValidatorForOtherTypes() {
val attributes1 = uAttributes {
type = UMessageType.UMESSAGE_TYPE_UNSPECIFIED
}
val validator1: UAttributesValidator = attributes1.getValidator()

assertTrue(validator1 is Publish)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package org.eclipse.uprotocol.uri.serializer

import org.eclipse.uprotocol.uri.validator.isEmpty
import org.eclipse.uprotocol.v1.UUri
import org.eclipse.uprotocol.v1.uUri
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.DisplayName
Expand Down Expand Up @@ -236,67 +237,95 @@ class UriSerializerTest {
@Test
@DisplayName("Test serializing an Empty UUri")
fun test_serializing_an_empty_UUri() {
val uri = UUri.getDefaultInstance()
val uri = uUri { }
val serializedUri: String = uri.serialize()
assertTrue(serializedUri.isBlank())
}

@Test
@DisplayName("Test serializing a full UUri")
fun test_serializing_a_full_UUri() {
val uri = UUri.newBuilder()
.setAuthorityName("myAuthority")
.setUeId(1)
.setUeVersionMajor(2)
.setResourceId(3)
.build()
val uri = uUri {
authorityName = "myAuthority"
ueId = 1
ueVersionMajor = 2
resourceId = 3
}
val serializedUri: String = uri.serialize()
assertEquals("//myAuthority/1/2/3", serializedUri)
}

@Test
@DisplayName("Test serializing a UUri with only authority")
fun test_serializing_a_UUri_with_only_authority() {
val uri = UUri.newBuilder()
.setAuthorityName("myAuthority")
.build()
val uri = uUri {
authorityName = "myAuthority"

}
val serializedUri: String = uri.serialize()
assertEquals("//myAuthority/0/0/0", serializedUri)
}

@Test
@DisplayName("Test serializing a UUri with only authority and ueId")
@DisplayName("Test serializing a UUri with authority and ueId")
fun test_serializing_a_UUri_with_only_authority_and_ueId() {
val uri = UUri.newBuilder()
.setAuthorityName("myAuthority")
.setUeId(1)
.build()
val uri = uUri {
authorityName = "myAuthority"
ueId = 1
}
val serializedUri: String = uri.serialize()
assertEquals("//myAuthority/1/0/0", serializedUri)
}

@Test
@DisplayName("Test serializing a UUri with only authority, ueId and ueVersionMajor")
@DisplayName("Test serializing a UUri with authority, ueId and ueVersionMajor")
fun test_serializing_a_UUri_with_only_authority_ueId_and_ueVersionMajor() {
val uri = UUri.newBuilder()
.setAuthorityName("myAuthority")
.setUeId(1)
.setUeVersionMajor(2)
.build()
val uri = uUri {
authorityName = "myAuthority"
ueId = 1
ueVersionMajor = 2

}
val serializedUri: String = uri.serialize()
assertEquals("//myAuthority/1/2/0", serializedUri)
}

@Test
@DisplayName("Test serializing a UUri with only authority, ueId, ueVersionMajor and resourceId")
@DisplayName("Test serializing a UUri with authority, ueId, ueVersionMajor and resourceId")
fun test_serializing_a_UUri_with_only_authority_ueId_ueVersionMajor_and_resourceId() {
val uri = UUri.newBuilder()
.setAuthorityName("myAuthority")
.setUeId(1)
.setUeVersionMajor(2)
.setResourceId(3)
.build()
val uri = uUri {
authorityName = "myAuthority"
ueId = 1
ueVersionMajor = 2
resourceId = 3

}
val serializedUri: String = uri.serialize()
assertEquals("//myAuthority/1/2/3", serializedUri)
}
@Test
@DisplayName("Test serializing a UUri with empty authority, ueId, ueVersionMajor and resourceId")
fun test_serializing_a_UUri_with_empty_authority_ueId_ueVersionMajor_and_resourceId() {
val uri = uUri {
authorityName = ""
ueId = 1
ueVersionMajor = 2
resourceId = 3
}
val serializedUri: String = uri.serialize()
assertEquals("/1/2/3", serializedUri)
}

@Test
@DisplayName("Test serializing a UUri with blank authority, ueId, ueVersionMajor and resourceId")
fun test_serializing_a_UUri_with_blank_authority_ueId_ueVersionMajor_and_resourceId() {
val uri = uUri {
authorityName = " "
ueId = 1
ueVersionMajor = 2
resourceId = 3
}
val serializedUri: String = uri.serialize()
assertEquals("/1/2/3", serializedUri)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class UriValidatorTest {
fun test_isEmpty_UUri_for_empty_built_UUri() {
val uri = UUri.newBuilder().build()
assertTrue(uri.isEmpty())
assertFalse(uri.isNotEmpty())
}

@Test
Expand Down

0 comments on commit 2683c57

Please sign in to comment.