Skip to content

Commit

Permalink
Expose ID and destination type of LogDestinationName publicly (#796)
Browse files Browse the repository at this point in the history
  • Loading branch information
losalex committed Dec 11, 2021
1 parent 59d9996 commit e303a9b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Expand Up @@ -29,7 +29,7 @@
public final class LogDestinationName extends Option {
private static final long serialVersionUID = 7944256748441111191L;

enum DestinationType implements Option.OptionType {
public enum DestinationType implements Option.OptionType {
PROJECT,
FOLDER,
ORGANIZATION,
Expand Down Expand Up @@ -109,6 +109,16 @@ public LogName toLogName(String logId) {
return null;
}

/** Returns ID value associated with {@code LogDestinationName} object */
public String getId() {
return getValue().toString();
}

/** Returns destination type option value associated with {@code LogDestinationName} object */
public DestinationType getDestinationType() {
return getOptionType();
}

/** Creates a {@code LogDestinationName} object from given {@code LogName}. */
public static LogDestinationName fromLogName(LogName logName) {
if (logName == null) {
Expand Down
Expand Up @@ -116,25 +116,25 @@ public void testWriteOptionWithDestination() {
WriteOption writeOption = WriteOption.destination(LogDestinationName.project(PROJECT_NAME));
LogDestinationName resource = (LogDestinationName) writeOption.getValue();
assertEquals(WriteOption.OptionType.LOG_DESTINATION, writeOption.getOptionType());
assertEquals(LogDestinationName.DestinationType.PROJECT, resource.getOptionType());
assertEquals(PROJECT_NAME, resource.getValue());
assertEquals(LogDestinationName.DestinationType.PROJECT, resource.getDestinationType());
assertEquals(PROJECT_NAME, resource.getId());

writeOption = WriteOption.destination(LogDestinationName.billingAccount(BILLING_NAME));
resource = (LogDestinationName) writeOption.getValue();
assertEquals(WriteOption.OptionType.LOG_DESTINATION, writeOption.getOptionType());
assertEquals(LogDestinationName.DestinationType.BILLINGACCOUNT, resource.getOptionType());
assertEquals(BILLING_NAME, resource.getValue());
assertEquals(LogDestinationName.DestinationType.BILLINGACCOUNT, resource.getDestinationType());
assertEquals(BILLING_NAME, resource.getId());

writeOption = WriteOption.destination(LogDestinationName.folder(FOLDER_NAME));
resource = (LogDestinationName) writeOption.getValue();
assertEquals(WriteOption.OptionType.LOG_DESTINATION, writeOption.getOptionType());
assertEquals(LogDestinationName.DestinationType.FOLDER, resource.getOptionType());
assertEquals(FOLDER_NAME, resource.getValue());
assertEquals(LogDestinationName.DestinationType.FOLDER, resource.getDestinationType());
assertEquals(FOLDER_NAME, resource.getId());

writeOption = WriteOption.destination(LogDestinationName.organization(ORGANIZATION_NAME));
resource = (LogDestinationName) writeOption.getValue();
assertEquals(WriteOption.OptionType.LOG_DESTINATION, writeOption.getOptionType());
assertEquals(LogDestinationName.DestinationType.ORGANIZATION, resource.getOptionType());
assertEquals(ORGANIZATION_NAME, resource.getValue());
assertEquals(LogDestinationName.DestinationType.ORGANIZATION, resource.getDestinationType());
assertEquals(ORGANIZATION_NAME, resource.getId());
}
}

0 comments on commit e303a9b

Please sign in to comment.