-
Notifications
You must be signed in to change notification settings - Fork 877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make ARN Resource builder more expressive. Implement proper toString() #3683
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ | |
import java.util.Optional; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import software.amazon.awssdk.arns.ArnResource.ArnResourceFormat; | ||
|
||
public class ArnResourceTest { | ||
|
||
@Test | ||
|
@@ -64,4 +66,72 @@ public void hashCodeEquals_minimalProperties() { | |
assertThat(arnResource.equals(anotherResource)).isTrue(); | ||
assertThat(arnResource.hashCode()).isEqualTo(anotherResource.hashCode()); | ||
} | ||
|
||
@Test | ||
public void toString_resourceIdOnly() { | ||
ArnResource arnResource = ArnResource.builder().resourceId("resource").build(); | ||
assertThat("null:resource:null").isEqualTo(arnResource.toString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add unit test to demonstrate the unexpected 'null' behavior here of the |
||
} | ||
|
||
@Test | ||
public void toString_resourceType_resourceId() { | ||
ArnResource arnResource = ArnResource.builder() | ||
.resourceType("type") | ||
.resourceId("resource") | ||
.build(); | ||
assertThat("type:resource:null").isEqualTo(arnResource.toString()); | ||
} | ||
|
||
@Test | ||
public void toFormattedString_resourceType_resourceId_qualfiier() { | ||
ArnResource arnResource = ArnResource.builder() | ||
.resourceType("type") | ||
.resourceId("resource") | ||
.qualifier("qualifier") | ||
.build(); | ||
assertThat("type:resource:qualifier").isEqualTo(arnResource.toStringFormatted()); | ||
} | ||
|
||
@Test | ||
public void toFormattedString_slash__resourceType_resourceId_qualfiier() { | ||
ArnResource arnResource = ArnResource.builder() | ||
.resourceType("type") | ||
.resourceId("resource") | ||
.qualifier("qualifier") | ||
.resourceFormat(ArnResourceFormat.RESOURCE_WITH_SLASH) | ||
.build(); | ||
assertThat("type/resource:qualifier").isEqualTo(arnResource.toStringFormatted()); | ||
} | ||
|
||
@Test | ||
public void toStringFormatted_resourceType_resourceId_parse_slash_seperator() { | ||
ArnResource arnResource = ArnResource.builder() | ||
.resourceType("vpc") | ||
.resourceFormat(ArnResourceFormat.RESOURCE_WITH_SLASH) | ||
.resourceId("vpc-0e9801d129EXAMPLE") | ||
.build(); | ||
assertThat("vpc/vpc-0e9801d129EXAMPLE").isEqualTo(arnResource.toStringFormatted()); | ||
} | ||
|
||
@Test | ||
public void toStringFormatted_resourceType_resourceId_slash_seperator() { | ||
ArnResource arnResource = ArnResource.fromString("vpc/vpc-0e9801d129EXAMPLE"); | ||
assertThat("vpc/vpc-0e9801d129EXAMPLE").isEqualTo(arnResource.toStringFormatted()); | ||
assertThat(arnResource.resourceType()).isEqualTo(Optional.of("vpc")); | ||
assertThat(arnResource.resourceId()).isEqualTo("vpc-0e9801d129EXAMPLE"); | ||
assertThat(arnResource.qualifier()).isEqualTo(Optional.empty()); | ||
} | ||
|
||
@Test | ||
public void toStringFormatted_arn_resource() { | ||
ArnResource arnResource = ArnResource.fromString("vpc/vpc-0e9801d129EXAMPLE:qualifier"); | ||
ArnResource arnResourceCpy = ArnResource.builder() | ||
.arnResource(arnResource) | ||
.build(); | ||
assertThat("vpc/vpc-0e9801d129EXAMPLE:qualifier").isEqualTo(arnResourceCpy.toStringFormatted()); | ||
assertThat(arnResourceCpy.resourceType()).isEqualTo(Optional.of("vpc")); | ||
assertThat(arnResourceCpy.resourceId()).isEqualTo("vpc-0e9801d129EXAMPLE"); | ||
assertThat(arnResourceCpy.qualifier()).isEqualTo(Optional.of("qualifier")); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ | |
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import java.util.Optional; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class ArnTest { | ||
|
@@ -31,7 +33,6 @@ public void arnWithBasicResource_ParsesCorrectly() { | |
assertThat(arn.region()).hasValue("us-east-1"); | ||
assertThat(arn.accountId()).hasValue("12345678910"); | ||
assertThat(arn.resourceAsString()).isEqualTo("myresource"); | ||
System.out.println(arn.resource()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. General cleanup |
||
} | ||
|
||
@Test | ||
|
@@ -110,8 +111,7 @@ public void arnWithResourceTypeAndResourceAndQualifier_SlashSplitter_ParsesCorre | |
assertThat(arn.service()).isEqualTo("s3"); | ||
assertThat(arn.region()).hasValue("us-east-1"); | ||
assertThat(arn.resourceAsString()).isEqualTo("bucket/foobar/1"); | ||
verifyArnResource(arn.resource()); | ||
assertThat(arn.resource().qualifier().get()).isEqualTo("1"); | ||
assertThat(arn.resource().qualifier()).isEqualTo(Optional.empty()); | ||
Comment on lines
-113
to
+114
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As seen here, this is a valid S3 path, yet it is being treated as a qualifier. |
||
} | ||
|
||
@Test | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may potentially break customers who rely on existing behavior. Can we introduce a new method,
toStringPretty
ortoStringFormatted
?