diff --git a/.secrets.baseline b/.secrets.baseline index e5ac748..e989ee6 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -3,7 +3,7 @@ "files": "^.secrets.baseline$", "lines": null }, - "generated_at": "2025-06-24T09:19:25Z", + "generated_at": "2025-07-23T10:15:23Z", "plugins_used": [ { "name": "AWSKeyDetector" @@ -136,7 +136,7 @@ "hashed_secret": "9bf92274d58c3655b80055ad2ab17540f71d3058", "is_secret": false, "is_verified": false, - "line_number": 3090, + "line_number": 3280, "type": "Secret Keyword", "verified_result": null } diff --git a/README.md b/README.md index 3c40538..f82ac83 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,8 @@ SDK Methods to consume - [Get Template](#get-template) - [Update Template](#update-template) - [Delete Template](#delete-template) + - [List Predefined Templates](#list-predefined-templates) + - [Get Predefined Template](#get-predefined-template) - [Push Destination APIs](#push-destination-apis) - [Create Destination tag subscription](#create-destination-tag-subscription) - [List Destination tag subscription](#list-destination-tag-subscription) @@ -621,6 +623,31 @@ ListTemplatesOptions listTemplatesOptions = new ListTemplatesOptions.Builder() Response response = eventNotificationsService.listTemplates(listTemplatesOptions).execute(); ``` +### List predefined Templates + +```java +ListPreDefinedTemplatesOptions listPreDefinedTemplatesOptionsModel = new ListPreDefinedTemplatesOptions.Builder() + .instanceId() + .source() + .type() + .limit() + .offset() + .search() + .build(); + +// Invoke getMetrics() with a valid options model and verify the result +Response response = eventNotificationsService.listPreDefinedTemplates(listPreDefinedTemplatesOptionsModel).execute(); +``` +### Get predefined Template + +```java +GetPreDefinedTemplateOptions getPreDefinedTemplateOptionsModel = new GetPreDefinedTemplateOptions.Builder() + .instanceId(instanceId) + .id() + .build(); + +Response response = eventNotificationsService.getPreDefinedTemplate(getPreDefinedTemplateOptionsModel).execute(); +``` ### Get Template diff --git a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotifications.java b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotifications.java index d755d35..4f24e64 100644 --- a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotifications.java +++ b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotifications.java @@ -45,6 +45,8 @@ import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetEnabledCountriesOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetIntegrationOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetMetricsOptions; +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetPreDefinedTemplateOptions; +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetPredefinedTemplate; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetSmtpAllowedIpsOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetSmtpConfigurationOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetSmtpUserOptions; @@ -57,6 +59,7 @@ import com.ibm.cloud.eventnotifications.event_notifications.v1.model.IntegrationList; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListDestinationsOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListIntegrationsOptions; +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListPreDefinedTemplatesOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListSmtpConfigurationsOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListSmtpUsersOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListSourcesOptions; @@ -66,6 +69,7 @@ import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListTopicsOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.Metrics; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.NotificationResponse; +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.PredefinedTemplatesList; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ReplaceIntegrationOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ReplaceTemplateOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ReplaceTopicOptions; @@ -602,6 +606,41 @@ public ServiceCall listTemplates(ListTemplatesOptions listTemplate return createServiceCall(builder.build(), responseConverter); } + /** + * List all predefined templates. + * + * List all predefined templates. + * + * @param listPreDefinedTemplatesOptions the {@link ListPreDefinedTemplatesOptions} containing the options for the call + * @return a {@link ServiceCall} with a result of type {@link PredefinedTemplatesList} + */ + public ServiceCall listPreDefinedTemplates(ListPreDefinedTemplatesOptions listPreDefinedTemplatesOptions) { + com.ibm.cloud.sdk.core.util.Validator.notNull(listPreDefinedTemplatesOptions, + "listPreDefinedTemplatesOptions cannot be null"); + Map pathParamsMap = new HashMap(); + pathParamsMap.put("instance_id", listPreDefinedTemplatesOptions.instanceId()); + RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/pre_defined_templates", pathParamsMap)); + Map sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "listPreDefinedTemplates"); + for (Entry header : sdkHeaders.entrySet()) { + builder.header(header.getKey(), header.getValue()); + } + builder.header("Accept", "application/json"); + builder.query("source", String.valueOf(listPreDefinedTemplatesOptions.source())); + builder.query("type", String.valueOf(listPreDefinedTemplatesOptions.type())); + if (listPreDefinedTemplatesOptions.limit() != null) { + builder.query("limit", String.valueOf(listPreDefinedTemplatesOptions.limit())); + } + if (listPreDefinedTemplatesOptions.offset() != null) { + builder.query("offset", String.valueOf(listPreDefinedTemplatesOptions.offset())); + } + if (listPreDefinedTemplatesOptions.search() != null) { + builder.query("search", String.valueOf(listPreDefinedTemplatesOptions.search())); + } + ResponseConverter responseConverter = + ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken() { }.getType()); + return createServiceCall(builder.build(), responseConverter); + } + /** * Get details of a Template. * @@ -689,6 +728,31 @@ public ServiceCall deleteTemplate(DeleteTemplateOptions deleteTemplateOpti return createServiceCall(builder.build(), responseConverter); } + /** + * Get details of a Predefined Template. + * + * Get details of a Predefined Template. + * + * @param getPreDefinedTemplateOptions the {@link GetPreDefinedTemplateOptions} containing the options for the call + * @return a {@link ServiceCall} with a result of type {@link GetPredefinedTemplate} + */ + public ServiceCall getPreDefinedTemplate(GetPreDefinedTemplateOptions getPreDefinedTemplateOptions) { + com.ibm.cloud.sdk.core.util.Validator.notNull(getPreDefinedTemplateOptions, + "getPreDefinedTemplateOptions cannot be null"); + Map pathParamsMap = new HashMap(); + pathParamsMap.put("instance_id", getPreDefinedTemplateOptions.instanceId()); + pathParamsMap.put("id", getPreDefinedTemplateOptions.id()); + RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/pre_defined_templates/{id}", pathParamsMap)); + Map sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "getPreDefinedTemplate"); + for (Entry header : sdkHeaders.entrySet()) { + builder.header(header.getKey(), header.getValue()); + } + builder.header("Accept", "application/json"); + ResponseConverter responseConverter = + ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken() { }.getType()); + return createServiceCall(builder.build(), responseConverter); + } + /** * Create a new Destination. * diff --git a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/DestinationConfigOneOf.java b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/DestinationConfigOneOf.java index 284d1e6..9052470 100644 --- a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/DestinationConfigOneOf.java +++ b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/DestinationConfigOneOf.java @@ -49,6 +49,10 @@ public interface Verb { String GET = "get"; /** post. */ String POST = "post"; + /** put. */ + String PUT = "put"; + /** patch. */ + String PATCH = "patch"; } /** diff --git a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/DestinationConfigOneOfWebhookDestinationConfig.java b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/DestinationConfigOneOfWebhookDestinationConfig.java index 40b77a4..a505834 100644 --- a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/DestinationConfigOneOfWebhookDestinationConfig.java +++ b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/DestinationConfigOneOfWebhookDestinationConfig.java @@ -29,6 +29,10 @@ public interface Verb { String GET = "get"; /** post. */ String POST = "post"; + /** put. */ + String PUT = "put"; + /** patch. */ + String PATCH = "patch"; } diff --git a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetPreDefinedTemplateOptions.java b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetPreDefinedTemplateOptions.java new file mode 100644 index 0000000..d57d405 --- /dev/null +++ b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetPreDefinedTemplateOptions.java @@ -0,0 +1,133 @@ +/* + * (C) Copyright IBM Corp. 2025. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package com.ibm.cloud.eventnotifications.event_notifications.v1.model; + +import com.ibm.cloud.sdk.core.service.model.GenericModel; + +/** + * The getPreDefinedTemplate options. + */ +public class GetPreDefinedTemplateOptions extends GenericModel { + + protected String instanceId; + protected String id; + + /** + * Builder. + */ + public static class Builder { + private String instanceId; + private String id; + + /** + * Instantiates a new Builder from an existing GetPreDefinedTemplateOptions instance. + * + * @param getPreDefinedTemplateOptions the instance to initialize the Builder with + */ + private Builder(GetPreDefinedTemplateOptions getPreDefinedTemplateOptions) { + this.instanceId = getPreDefinedTemplateOptions.instanceId; + this.id = getPreDefinedTemplateOptions.id; + } + + /** + * Instantiates a new builder. + */ + public Builder() { + } + + /** + * Instantiates a new builder with required properties. + * + * @param instanceId the instanceId + * @param id the id + */ + public Builder(String instanceId, String id) { + this.instanceId = instanceId; + this.id = id; + } + + /** + * Builds a GetPreDefinedTemplateOptions. + * + * @return the new GetPreDefinedTemplateOptions instance + */ + public GetPreDefinedTemplateOptions build() { + return new GetPreDefinedTemplateOptions(this); + } + + /** + * Set the instanceId. + * + * @param instanceId the instanceId + * @return the GetPreDefinedTemplateOptions builder + */ + public Builder instanceId(String instanceId) { + this.instanceId = instanceId; + return this; + } + + /** + * Set the id. + * + * @param id the id + * @return the GetPreDefinedTemplateOptions builder + */ + public Builder id(String id) { + this.id = id; + return this; + } + } + + protected GetPreDefinedTemplateOptions() { } + + protected GetPreDefinedTemplateOptions(Builder builder) { + com.ibm.cloud.sdk.core.util.Validator.notEmpty(builder.instanceId, + "instanceId cannot be empty"); + com.ibm.cloud.sdk.core.util.Validator.notEmpty(builder.id, + "id cannot be empty"); + instanceId = builder.instanceId; + id = builder.id; + } + + /** + * New builder. + * + * @return a GetPreDefinedTemplateOptions builder + */ + public Builder newBuilder() { + return new Builder(this); + } + + /** + * Gets the instanceId. + * + * Unique identifier for IBM Cloud Event Notifications instance. + * + * @return the instanceId + */ + public String instanceId() { + return instanceId; + } + + /** + * Gets the id. + * + * Unique identifier for Template. + * + * @return the id + */ + public String id() { + return id; + } +} + diff --git a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetPredefinedTemplate.java b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetPredefinedTemplate.java new file mode 100644 index 0000000..b47df65 --- /dev/null +++ b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetPredefinedTemplate.java @@ -0,0 +1,113 @@ +/* + * (C) Copyright IBM Corp. 2025. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package com.ibm.cloud.eventnotifications.event_notifications.v1.model; + +import java.util.Date; + +import com.google.gson.annotations.SerializedName; +import com.ibm.cloud.sdk.core.service.model.GenericModel; + +/** + * Template object. + */ +public class GetPredefinedTemplate extends GenericModel { + + protected String id; + protected String name; + protected String description; + protected String type; + protected String source; + @SerializedName("updated_at") + protected Date updatedAt; + protected PredefinedTemplateConfig params; + + protected GetPredefinedTemplate() { } + + /** + * Gets the id. + * + * Template ID. + * + * @return the id + */ + public String getId() { + return id; + } + + /** + * Gets the name. + * + * Template name. + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * Gets the description. + * + * Template description. + * + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * Gets the type. + * + * The type of template. + * + * @return the type + */ + public String getType() { + return type; + } + + /** + * Gets the source. + * + * The type of source. + * + * @return the source + */ + public String getSource() { + return source; + } + + /** + * Gets the updatedAt. + * + * Updated at. + * + * @return the updatedAt + */ + public Date getUpdatedAt() { + return updatedAt; + } + + /** + * Gets the params. + * + * Payload describing a Predefined template configuration. + * + * @return the params + */ + public PredefinedTemplateConfig getParams() { + return params; + } +} + diff --git a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/ListPreDefinedTemplatesOptions.java b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/ListPreDefinedTemplatesOptions.java new file mode 100644 index 0000000..9f6a478 --- /dev/null +++ b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/ListPreDefinedTemplatesOptions.java @@ -0,0 +1,241 @@ +/* + * (C) Copyright IBM Corp. 2025. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package com.ibm.cloud.eventnotifications.event_notifications.v1.model; + +import com.ibm.cloud.sdk.core.service.model.GenericModel; + +/** + * The listPreDefinedTemplates options. + */ +public class ListPreDefinedTemplatesOptions extends GenericModel { + + protected String instanceId; + protected String source; + protected String type; + protected Long limit; + protected Long offset; + protected String search; + + /** + * Builder. + */ + public static class Builder { + private String instanceId; + private String source; + private String type; + private Long limit; + private Long offset; + private String search; + + /** + * Instantiates a new Builder from an existing ListPreDefinedTemplatesOptions instance. + * + * @param listPreDefinedTemplatesOptions the instance to initialize the Builder with + */ + private Builder(ListPreDefinedTemplatesOptions listPreDefinedTemplatesOptions) { + this.instanceId = listPreDefinedTemplatesOptions.instanceId; + this.source = listPreDefinedTemplatesOptions.source; + this.type = listPreDefinedTemplatesOptions.type; + this.limit = listPreDefinedTemplatesOptions.limit; + this.offset = listPreDefinedTemplatesOptions.offset; + this.search = listPreDefinedTemplatesOptions.search; + } + + /** + * Instantiates a new builder. + */ + public Builder() { + } + + /** + * Instantiates a new builder with required properties. + * + * @param instanceId the instanceId + * @param source the source + * @param type the type + */ + public Builder(String instanceId, String source, String type) { + this.instanceId = instanceId; + this.source = source; + this.type = type; + } + + /** + * Builds a ListPreDefinedTemplatesOptions. + * + * @return the new ListPreDefinedTemplatesOptions instance + */ + public ListPreDefinedTemplatesOptions build() { + return new ListPreDefinedTemplatesOptions(this); + } + + /** + * Set the instanceId. + * + * @param instanceId the instanceId + * @return the ListPreDefinedTemplatesOptions builder + */ + public Builder instanceId(String instanceId) { + this.instanceId = instanceId; + return this; + } + + /** + * Set the source. + * + * @param source the source + * @return the ListPreDefinedTemplatesOptions builder + */ + public Builder source(String source) { + this.source = source; + return this; + } + + /** + * Set the type. + * + * @param type the type + * @return the ListPreDefinedTemplatesOptions builder + */ + public Builder type(String type) { + this.type = type; + return this; + } + + /** + * Set the limit. + * + * @param limit the limit + * @return the ListPreDefinedTemplatesOptions builder + */ + public Builder limit(long limit) { + this.limit = limit; + return this; + } + + /** + * Set the offset. + * + * @param offset the offset + * @return the ListPreDefinedTemplatesOptions builder + */ + public Builder offset(long offset) { + this.offset = offset; + return this; + } + + /** + * Set the search. + * + * @param search the search + * @return the ListPreDefinedTemplatesOptions builder + */ + public Builder search(String search) { + this.search = search; + return this; + } + } + + protected ListPreDefinedTemplatesOptions() { } + + protected ListPreDefinedTemplatesOptions(Builder builder) { + com.ibm.cloud.sdk.core.util.Validator.notEmpty(builder.instanceId, + "instanceId cannot be empty"); + com.ibm.cloud.sdk.core.util.Validator.notNull(builder.source, + "source cannot be null"); + com.ibm.cloud.sdk.core.util.Validator.notNull(builder.type, + "type cannot be null"); + instanceId = builder.instanceId; + source = builder.source; + type = builder.type; + limit = builder.limit; + offset = builder.offset; + search = builder.search; + } + + /** + * New builder. + * + * @return a ListPreDefinedTemplatesOptions builder + */ + public Builder newBuilder() { + return new Builder(this); + } + + /** + * Gets the instanceId. + * + * Unique identifier for IBM Cloud Event Notifications instance. + * + * @return the instanceId + */ + public String instanceId() { + return instanceId; + } + + /** + * Gets the source. + * + * Source type. + * + * @return the source + */ + public String source() { + return source; + } + + /** + * Gets the type. + * + * Destination type. + * + * @return the type + */ + public String type() { + return type; + } + + /** + * Gets the limit. + * + * Page limit for paginated results. + * + * @return the limit + */ + public Long limit() { + return limit; + } + + /** + * Gets the offset. + * + * offset for paginated results. + * + * @return the offset + */ + public Long offset() { + return offset; + } + + /** + * Gets the search. + * + * Search string for filtering results. + * + * @return the search + */ + public String search() { + return search; + } +} + diff --git a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/PreDefinedTemplatesPager.java b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/PreDefinedTemplatesPager.java new file mode 100644 index 0000000..ae4bac2 --- /dev/null +++ b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/PreDefinedTemplatesPager.java @@ -0,0 +1,111 @@ +/* + * (C) Copyright IBM Corp. 2025. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package com.ibm.cloud.eventnotifications.event_notifications.v1.model; + +import com.ibm.cloud.eventnotifications.event_notifications.v1.EventNotifications; +import com.ibm.cloud.sdk.core.util.UrlHelper; +import java.util.ArrayList; +import java.util.List; +import java.util.NoSuchElementException; + +/** + * PreDefinedTemplatesPager can be used to simplify the use of the "listPreDefinedTemplates" method. + */ +public class PreDefinedTemplatesPager { + private static class PageContext { + private Long next; + public Long getNext() { + return next; + } + public void setNext(Long next) { + this.next = next; + } + } + + protected boolean hasNext; + protected ListPreDefinedTemplatesOptions options; + protected EventNotifications client; + protected PageContext pageContext; + + // Hide the default ctor. + protected PreDefinedTemplatesPager() { } + + /** + * Constructs a new PreDefinedTemplatesPager instance with the specified client and options model instance. + * @param client the EventNotifications instance to be used to invoke the "listPreDefinedTemplates" method + * @param options the ListPreDefinedTemplatesOptions instance to be used to invoke the "listPreDefinedTemplates" method + */ + public PreDefinedTemplatesPager(EventNotifications client, ListPreDefinedTemplatesOptions options) { + if (options.offset() != null && options.offset().longValue() != 0) { + throw new IllegalArgumentException("The options 'offset' field should not be set"); + } + + this.hasNext = true; + this.client = client; + this.options = options.newBuilder().build(); + this.pageContext = new PageContext(); + } + + /** + * Returns true if there are more results to be retrieved. + * @return boolean + */ + public boolean hasNext() { + return hasNext; + } + + /** + * Returns the next page of results. + * @return a List<PredefinedTemplate> that contains the next page of results + */ + public List getNext() { + if (!hasNext()) { + throw new NoSuchElementException("No more results available"); + } + + ListPreDefinedTemplatesOptions.Builder builder = this.options.newBuilder(); + if (this.pageContext.getNext() != null) { + builder.offset(this.pageContext.getNext()); + } + this.options = builder.build(); + + PredefinedTemplatesList result = client.listPreDefinedTemplates(options).execute().getResult(); + + Long next = null; + if (result.getNext() != null) { + String queryParam = UrlHelper.getQueryParam(result.getNext().getHref(), "offset"); + if (queryParam != null) { + next = Long.valueOf(queryParam); + } + } + this.pageContext.setNext(next); + if (next == null) { + this.hasNext = false; + } + + return result.getTemplates(); + } + + /** + * Returns all results by invoking getNext() repeatedly until all pages of results have been retrieved. + * @return a List<PredefinedTemplate> containing all results returned by the "listPreDefinedTemplates" method + */ + public List getAll() { + List results = new ArrayList<>(); + while (hasNext()) { + List nextPage = getNext(); + results.addAll(nextPage); + } + return results; + } +} diff --git a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/PredefinedTemplate.java b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/PredefinedTemplate.java new file mode 100644 index 0000000..b3d0cbd --- /dev/null +++ b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/PredefinedTemplate.java @@ -0,0 +1,101 @@ +/* + * (C) Copyright IBM Corp. 2025. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package com.ibm.cloud.eventnotifications.event_notifications.v1.model; + +import java.util.Date; + +import com.google.gson.annotations.SerializedName; +import com.ibm.cloud.sdk.core.service.model.GenericModel; + +/** + * Predefined Template object. + */ +public class PredefinedTemplate extends GenericModel { + + protected String id; + protected String name; + protected String description; + protected String source; + protected String type; + @SerializedName("updated_at") + protected Date updatedAt; + + protected PredefinedTemplate() { } + + /** + * Gets the id. + * + * Template ID. + * + * @return the id + */ + public String getId() { + return id; + } + + /** + * Gets the name. + * + * Template name. + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * Gets the description. + * + * Template description. + * + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * Gets the source. + * + * The type of source. + * + * @return the source + */ + public String getSource() { + return source; + } + + /** + * Gets the type. + * + * The type of template. + * + * @return the type + */ + public String getType() { + return type; + } + + /** + * Gets the updatedAt. + * + * Updated at. + * + * @return the updatedAt + */ + public Date getUpdatedAt() { + return updatedAt; + } +} + diff --git a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/PredefinedTemplateConfig.java b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/PredefinedTemplateConfig.java new file mode 100644 index 0000000..98cc1b0 --- /dev/null +++ b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/PredefinedTemplateConfig.java @@ -0,0 +1,37 @@ +/* + * (C) Copyright IBM Corp. 2025. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package com.ibm.cloud.eventnotifications.event_notifications.v1.model; + +import com.ibm.cloud.sdk.core.service.model.GenericModel; + +/** + * Payload describing a Predefined template configuration. + */ +public class PredefinedTemplateConfig extends GenericModel { + + protected String body; + + protected PredefinedTemplateConfig() { } + + /** + * Gets the body. + * + * Template body(Base64 encoded). + * + * @return the body + */ + public String getBody() { + return body; + } +} + diff --git a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/PredefinedTemplatesList.java b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/PredefinedTemplatesList.java new file mode 100644 index 0000000..4df3564 --- /dev/null +++ b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/PredefinedTemplatesList.java @@ -0,0 +1,113 @@ +/* + * (C) Copyright IBM Corp. 2025. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package com.ibm.cloud.eventnotifications.event_notifications.v1.model; + +import java.util.List; + +import com.google.gson.annotations.SerializedName; +import com.ibm.cloud.sdk.core.service.model.GenericModel; + +/** + * Payload describing a pre-defined templates list request. + */ +public class PredefinedTemplatesList extends GenericModel { + + @SerializedName("total_count") + protected Long totalCount; + protected Long offset; + protected Long limit; + protected List templates; + protected PageHrefResponse first; + protected PageHrefResponse previous; + protected PageHrefResponse next; + + protected PredefinedTemplatesList() { } + + /** + * Gets the totalCount. + * + * Total number of pre-defined templates. + * + * @return the totalCount + */ + public Long getTotalCount() { + return totalCount; + } + + /** + * Gets the offset. + * + * Current offset. + * + * @return the offset + */ + public Long getOffset() { + return offset; + } + + /** + * Gets the limit. + * + * limit to show templates. + * + * @return the limit + */ + public Long getLimit() { + return limit; + } + + /** + * Gets the templates. + * + * List of pre-defined templates. + * + * @return the templates + */ + public List getTemplates() { + return templates; + } + + /** + * Gets the first. + * + * Response having URL of the page. + * + * @return the first + */ + public PageHrefResponse getFirst() { + return first; + } + + /** + * Gets the previous. + * + * Response having URL of the page. + * + * @return the previous + */ + public PageHrefResponse getPrevious() { + return previous; + } + + /** + * Gets the next. + * + * Response having URL of the page. + * + * @return the next + */ + public PageHrefResponse getNext() { + return next; + } +} + diff --git a/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsIT.java b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsIT.java index a72aca8..b5c4502 100644 --- a/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsIT.java +++ b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsIT.java @@ -3983,6 +3983,52 @@ public void test2ITestMetrics(){ } + @Test + public void test2JTestListPredefinedTemplates(){ + + try{ + ListPreDefinedTemplatesOptions listPreDefinedTemplatesOptionsModel = new ListPreDefinedTemplatesOptions.Builder() + .instanceId(instanceId) + .source("logs") + .type("slack.notification") + .build(); + + // Invoke getMetrics() with a valid options model and verify the result + Response response = service.listPreDefinedTemplates(listPreDefinedTemplatesOptionsModel).execute(); + assertNotNull(response); + assertEquals(response.getStatusCode(), 200); + PredefinedTemplatesList responseObj = response.getResult(); + assertNotNull(responseObj); + } + catch(ServiceResponseException e){ + fail(String.format("Service returned status code %d: %s%nError details: %s", + e.getStatusCode(), e.getMessage(), e.getDebuggingInfo())); + } + + } + + @Test + public void test2KTestGetPredefinedTemplate(){ + + try{ + GetPreDefinedTemplateOptions getPreDefinedTemplateOptionsModel = new GetPreDefinedTemplateOptions.Builder() + .instanceId(instanceId) + .id("0cacb9a0-d43a-4042-920d-d4a3f7d4cbd5") //used from dev + .build(); + + Response response = service.getPreDefinedTemplate(getPreDefinedTemplateOptionsModel).execute(); + assertNotNull(response); + assertEquals(response.getStatusCode(), 200); + GetPredefinedTemplate responseObj = response.getResult(); + assertNotNull(responseObj); + } + catch(ServiceResponseException e){ + fail(String.format("Service returned status code %d: %s%nError details: %s", + e.getStatusCode(), e.getMessage(), e.getDebuggingInfo())); + } + + } + @Test public void test2JDeleteSubscription() throws Exception { try { diff --git a/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsTest.java b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsTest.java index 17a1397..65591df 100644 --- a/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsTest.java +++ b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsTest.java @@ -67,6 +67,8 @@ import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetEnabledCountriesOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetIntegrationOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetMetricsOptions; +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetPreDefinedTemplateOptions; +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetPredefinedTemplate; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetSmtpAllowedIpsOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetSmtpConfigurationOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetSmtpUserOptions; @@ -84,6 +86,7 @@ import com.ibm.cloud.eventnotifications.event_notifications.v1.model.IntegrationsPager; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListDestinationsOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListIntegrationsOptions; +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListPreDefinedTemplatesOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListSmtpConfigurationsOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListSmtpUsersOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListSourcesOptions; @@ -96,6 +99,10 @@ import com.ibm.cloud.eventnotifications.event_notifications.v1.model.NotificationCreate; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.NotificationResponse; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.PageHrefResponse; +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.PreDefinedTemplatesPager; +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.PredefinedTemplate; +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.PredefinedTemplateConfig; +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.PredefinedTemplatesList; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ReplaceIntegrationOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ReplaceTemplateOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ReplaceTopicOptions; @@ -1286,6 +1293,137 @@ public void testListTemplatesWithPagerGetAll() throws Throwable { assertEquals(allResults.size(), 2); } + // Test the listPreDefinedTemplates operation with a valid options model parameter + @Test + public void testListPreDefinedTemplatesWOptions() throws Throwable { + // Register a mock response + String mockResponseBody = "{\"total_count\": 10, \"offset\": 6, \"limit\": 5, \"templates\": [{\"id\": \"id\", \"name\": \"name\", \"description\": \"description\", \"source\": \"source\", \"type\": \"type\", \"updated_at\": \"2019-01-01T12:00:00.000Z\"}], \"first\": {\"href\": \"href\"}, \"previous\": {\"href\": \"href\"}, \"next\": {\"href\": \"href\"}}"; + String listPreDefinedTemplatesPath = "/v1/instances/testString/pre_defined_templates"; + server.enqueue(new MockResponse() + .setHeader("Content-type", "application/json") + .setResponseCode(200) + .setBody(mockResponseBody)); + + // Construct an instance of the ListPreDefinedTemplatesOptions model + ListPreDefinedTemplatesOptions listPreDefinedTemplatesOptionsModel = new ListPreDefinedTemplatesOptions.Builder() + .instanceId("testString") + .source("testString") + .type("testString") + .limit(Long.valueOf("10")) + .offset(Long.valueOf("0")) + .search("testString") + .build(); + + // Invoke listPreDefinedTemplates() with a valid options model and verify the result + Response response = eventNotificationsService.listPreDefinedTemplates(listPreDefinedTemplatesOptionsModel).execute(); + assertNotNull(response); + PredefinedTemplatesList responseObj = response.getResult(); + assertNotNull(responseObj); + + // Verify the contents of the request sent to the mock server + RecordedRequest request = server.takeRequest(); + assertNotNull(request); + assertEquals(request.getMethod(), "GET"); + // Verify request path + String parsedPath = TestUtilities.parseReqPath(request); + assertEquals(parsedPath, listPreDefinedTemplatesPath); + // Verify query params + Map query = TestUtilities.parseQueryString(request); + assertNotNull(query); + assertEquals(query.get("source"), "testString"); + assertEquals(query.get("type"), "testString"); + assertEquals(Long.valueOf(query.get("limit")), Long.valueOf("10")); + assertEquals(Long.valueOf(query.get("offset")), Long.valueOf("0")); + assertEquals(query.get("search"), "testString"); + } + + // Test the listPreDefinedTemplates operation with and without retries enabled + @Test + public void testListPreDefinedTemplatesWRetries() throws Throwable { + eventNotificationsService.enableRetries(4, 30); + testListPreDefinedTemplatesWOptions(); + + eventNotificationsService.disableRetries(); + testListPreDefinedTemplatesWOptions(); + } + + // Test the listPreDefinedTemplates operation with a null options model (negative test) + @Test(expectedExceptions = IllegalArgumentException.class) + public void testListPreDefinedTemplatesNoOptions() throws Throwable { + server.enqueue(new MockResponse()); + eventNotificationsService.listPreDefinedTemplates(null).execute(); + } + + // Test the listPreDefinedTemplates operation using the PreDefinedTemplatesPager.getNext() method + @Test + public void testListPreDefinedTemplatesWithPagerGetNext() throws Throwable { + // Set up the two-page mock response. + String mockResponsePage1 = "{\"next\":{\"href\":\"https://myhost.com/somePath?offset=1\"},\"total_count\":2,\"templates\":[{\"id\":\"id\",\"name\":\"name\",\"description\":\"description\",\"source\":\"source\",\"type\":\"type\",\"updated_at\":\"2019-01-01T12:00:00.000Z\"}],\"limit\":1}"; + String mockResponsePage2 = "{\"total_count\":2,\"templates\":[{\"id\":\"id\",\"name\":\"name\",\"description\":\"description\",\"source\":\"source\",\"type\":\"type\",\"updated_at\":\"2019-01-01T12:00:00.000Z\"}],\"limit\":1}"; + server.enqueue(new MockResponse() + .setHeader("Content-type", "application/json") + .setResponseCode(200) + .setBody(mockResponsePage1)); + server.enqueue(new MockResponse() + .setHeader("Content-type", "application/json") + .setResponseCode(200) + .setBody(mockResponsePage2)); + server.enqueue(new MockResponse() + .setHeader("Content-type", "application/json") + .setResponseCode(400) + .setBody("{\"message\": \"No more results available!\"}")); + + ListPreDefinedTemplatesOptions listPreDefinedTemplatesOptions = new ListPreDefinedTemplatesOptions.Builder() + .instanceId("testString") + .source("testString") + .type("testString") + .limit(Long.valueOf("10")) + .search("testString") + .build(); + + List allResults = new ArrayList<>(); + PreDefinedTemplatesPager pager = new PreDefinedTemplatesPager(eventNotificationsService, listPreDefinedTemplatesOptions); + while (pager.hasNext()) { + List nextPage = pager.getNext(); + assertNotNull(nextPage); + allResults.addAll(nextPage); + } + assertEquals(allResults.size(), 2); + } + + // Test the listPreDefinedTemplates operation using the PreDefinedTemplatesPager.getAll() method + @Test + public void testListPreDefinedTemplatesWithPagerGetAll() throws Throwable { + // Set up the two-page mock response. + String mockResponsePage1 = "{\"next\":{\"href\":\"https://myhost.com/somePath?offset=1\"},\"total_count\":2,\"templates\":[{\"id\":\"id\",\"name\":\"name\",\"description\":\"description\",\"source\":\"source\",\"type\":\"type\",\"updated_at\":\"2019-01-01T12:00:00.000Z\"}],\"limit\":1}"; + String mockResponsePage2 = "{\"total_count\":2,\"templates\":[{\"id\":\"id\",\"name\":\"name\",\"description\":\"description\",\"source\":\"source\",\"type\":\"type\",\"updated_at\":\"2019-01-01T12:00:00.000Z\"}],\"limit\":1}"; + server.enqueue(new MockResponse() + .setHeader("Content-type", "application/json") + .setResponseCode(200) + .setBody(mockResponsePage1)); + server.enqueue(new MockResponse() + .setHeader("Content-type", "application/json") + .setResponseCode(200) + .setBody(mockResponsePage2)); + server.enqueue(new MockResponse() + .setHeader("Content-type", "application/json") + .setResponseCode(400) + .setBody("{\"message\": \"No more results available!\"}")); + + ListPreDefinedTemplatesOptions listPreDefinedTemplatesOptions = new ListPreDefinedTemplatesOptions.Builder() + .instanceId("testString") + .source("testString") + .type("testString") + .limit(Long.valueOf("10")) + .search("testString") + .build(); + + PreDefinedTemplatesPager pager = new PreDefinedTemplatesPager(eventNotificationsService, listPreDefinedTemplatesOptions); + List allResults = pager.getAll(); + assertNotNull(allResults); + assertEquals(allResults.size(), 2); + } + // Test the getTemplate operation with a valid options model parameter @Test public void testGetTemplateWOptions() throws Throwable { @@ -1451,6 +1589,58 @@ public void testDeleteTemplateNoOptions() throws Throwable { eventNotificationsService.deleteTemplate(null).execute(); } + // Test the getPreDefinedTemplate operation with a valid options model parameter + @Test + public void testGetPreDefinedTemplateWOptions() throws Throwable { + // Register a mock response + String mockResponseBody = "{\"id\": \"id\", \"name\": \"name\", \"description\": \"description\", \"type\": \"type\", \"source\": \"source\", \"updated_at\": \"2019-01-01T12:00:00.000Z\", \"params\": {\"body\": \"body\"}}"; + String getPreDefinedTemplatePath = "/v1/instances/testString/pre_defined_templates/testString"; + server.enqueue(new MockResponse() + .setHeader("Content-type", "application/json") + .setResponseCode(200) + .setBody(mockResponseBody)); + + // Construct an instance of the GetPreDefinedTemplateOptions model + GetPreDefinedTemplateOptions getPreDefinedTemplateOptionsModel = new GetPreDefinedTemplateOptions.Builder() + .instanceId("testString") + .id("testString") + .build(); + + // Invoke getPreDefinedTemplate() with a valid options model and verify the result + Response response = eventNotificationsService.getPreDefinedTemplate(getPreDefinedTemplateOptionsModel).execute(); + assertNotNull(response); + GetPredefinedTemplate responseObj = response.getResult(); + assertNotNull(responseObj); + + // Verify the contents of the request sent to the mock server + RecordedRequest request = server.takeRequest(); + assertNotNull(request); + assertEquals(request.getMethod(), "GET"); + // Verify request path + String parsedPath = TestUtilities.parseReqPath(request); + assertEquals(parsedPath, getPreDefinedTemplatePath); + // Verify that there is no query string + Map query = TestUtilities.parseQueryString(request); + assertNull(query); + } + + // Test the getPreDefinedTemplate operation with and without retries enabled + @Test + public void testGetPreDefinedTemplateWRetries() throws Throwable { + eventNotificationsService.enableRetries(4, 30); + testGetPreDefinedTemplateWOptions(); + + eventNotificationsService.disableRetries(); + testGetPreDefinedTemplateWOptions(); + } + + // Test the getPreDefinedTemplate operation with a null options model (negative test) + @Test(expectedExceptions = IllegalArgumentException.class) + public void testGetPreDefinedTemplateNoOptions() throws Throwable { + server.enqueue(new MockResponse()); + eventNotificationsService.getPreDefinedTemplate(null).execute(); + } + // Test the createDestination operation with a valid options model parameter @Test public void testCreateDestinationWOptions() throws Throwable { diff --git a/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetPreDefinedTemplateOptionsTest.java b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetPreDefinedTemplateOptionsTest.java new file mode 100644 index 0000000..6790f75 --- /dev/null +++ b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetPreDefinedTemplateOptionsTest.java @@ -0,0 +1,47 @@ +/* + * (C) Copyright IBM Corp. 2025. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package com.ibm.cloud.eventnotifications.event_notifications.v1.model; + +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetPreDefinedTemplateOptions; +import com.ibm.cloud.eventnotifications.event_notifications.v1.utils.TestUtilities; +import com.ibm.cloud.sdk.core.service.model.FileWithMetadata; +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import org.testng.annotations.Test; +import static org.testng.Assert.*; + +/** + * Unit test class for the GetPreDefinedTemplateOptions model. + */ +public class GetPreDefinedTemplateOptionsTest { + final HashMap mockStreamMap = TestUtilities.createMockStreamMap(); + final List mockListFileWithMetadata = TestUtilities.creatMockListFileWithMetadata(); + + @Test + public void testGetPreDefinedTemplateOptions() throws Throwable { + GetPreDefinedTemplateOptions getPreDefinedTemplateOptionsModel = new GetPreDefinedTemplateOptions.Builder() + .instanceId("testString") + .id("testString") + .build(); + assertEquals(getPreDefinedTemplateOptionsModel.instanceId(), "testString"); + assertEquals(getPreDefinedTemplateOptionsModel.id(), "testString"); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testGetPreDefinedTemplateOptionsError() throws Throwable { + new GetPreDefinedTemplateOptions.Builder().build(); + } + +} \ No newline at end of file diff --git a/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetPredefinedTemplateTest.java b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetPredefinedTemplateTest.java new file mode 100644 index 0000000..02c7d27 --- /dev/null +++ b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetPredefinedTemplateTest.java @@ -0,0 +1,44 @@ +/* + * (C) Copyright IBM Corp. 2025. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package com.ibm.cloud.eventnotifications.event_notifications.v1.model; + +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetPredefinedTemplate; +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.PredefinedTemplateConfig; +import com.ibm.cloud.eventnotifications.event_notifications.v1.utils.TestUtilities; +import com.ibm.cloud.sdk.core.service.model.FileWithMetadata; +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import org.testng.annotations.Test; +import static org.testng.Assert.*; + +/** + * Unit test class for the GetPredefinedTemplate model. + */ +public class GetPredefinedTemplateTest { + final HashMap mockStreamMap = TestUtilities.createMockStreamMap(); + final List mockListFileWithMetadata = TestUtilities.creatMockListFileWithMetadata(); + + @Test + public void testGetPredefinedTemplate() throws Throwable { + GetPredefinedTemplate getPredefinedTemplateModel = new GetPredefinedTemplate(); + assertNull(getPredefinedTemplateModel.getId()); + assertNull(getPredefinedTemplateModel.getName()); + assertNull(getPredefinedTemplateModel.getDescription()); + assertNull(getPredefinedTemplateModel.getType()); + assertNull(getPredefinedTemplateModel.getSource()); + assertNull(getPredefinedTemplateModel.getUpdatedAt()); + assertNull(getPredefinedTemplateModel.getParams()); + } +} \ No newline at end of file diff --git a/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/ListPreDefinedTemplatesOptionsTest.java b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/ListPreDefinedTemplatesOptionsTest.java new file mode 100644 index 0000000..616b2db --- /dev/null +++ b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/ListPreDefinedTemplatesOptionsTest.java @@ -0,0 +1,55 @@ +/* + * (C) Copyright IBM Corp. 2025. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package com.ibm.cloud.eventnotifications.event_notifications.v1.model; + +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ListPreDefinedTemplatesOptions; +import com.ibm.cloud.eventnotifications.event_notifications.v1.utils.TestUtilities; +import com.ibm.cloud.sdk.core.service.model.FileWithMetadata; +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import org.testng.annotations.Test; +import static org.testng.Assert.*; + +/** + * Unit test class for the ListPreDefinedTemplatesOptions model. + */ +public class ListPreDefinedTemplatesOptionsTest { + final HashMap mockStreamMap = TestUtilities.createMockStreamMap(); + final List mockListFileWithMetadata = TestUtilities.creatMockListFileWithMetadata(); + + @Test + public void testListPreDefinedTemplatesOptions() throws Throwable { + ListPreDefinedTemplatesOptions listPreDefinedTemplatesOptionsModel = new ListPreDefinedTemplatesOptions.Builder() + .instanceId("testString") + .source("testString") + .type("testString") + .limit(Long.valueOf("1")) + .offset(Long.valueOf("0")) + .search("testString") + .build(); + assertEquals(listPreDefinedTemplatesOptionsModel.instanceId(), "testString"); + assertEquals(listPreDefinedTemplatesOptionsModel.source(), "testString"); + assertEquals(listPreDefinedTemplatesOptionsModel.type(), "testString"); + assertEquals(listPreDefinedTemplatesOptionsModel.limit(), Long.valueOf("1")); + assertEquals(listPreDefinedTemplatesOptionsModel.offset(), Long.valueOf("0")); + assertEquals(listPreDefinedTemplatesOptionsModel.search(), "testString"); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testListPreDefinedTemplatesOptionsError() throws Throwable { + new ListPreDefinedTemplatesOptions.Builder().build(); + } + +} \ No newline at end of file diff --git a/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/PredefinedTemplateConfigTest.java b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/PredefinedTemplateConfigTest.java new file mode 100644 index 0000000..efc382b --- /dev/null +++ b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/PredefinedTemplateConfigTest.java @@ -0,0 +1,37 @@ +/* + * (C) Copyright IBM Corp. 2025. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package com.ibm.cloud.eventnotifications.event_notifications.v1.model; + +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.PredefinedTemplateConfig; +import com.ibm.cloud.eventnotifications.event_notifications.v1.utils.TestUtilities; +import com.ibm.cloud.sdk.core.service.model.FileWithMetadata; +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import org.testng.annotations.Test; +import static org.testng.Assert.*; + +/** + * Unit test class for the PredefinedTemplateConfig model. + */ +public class PredefinedTemplateConfigTest { + final HashMap mockStreamMap = TestUtilities.createMockStreamMap(); + final List mockListFileWithMetadata = TestUtilities.creatMockListFileWithMetadata(); + + @Test + public void testPredefinedTemplateConfig() throws Throwable { + PredefinedTemplateConfig predefinedTemplateConfigModel = new PredefinedTemplateConfig(); + assertNull(predefinedTemplateConfigModel.getBody()); + } +} \ No newline at end of file diff --git a/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/PredefinedTemplateTest.java b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/PredefinedTemplateTest.java new file mode 100644 index 0000000..3bcb39e --- /dev/null +++ b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/PredefinedTemplateTest.java @@ -0,0 +1,42 @@ +/* + * (C) Copyright IBM Corp. 2025. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package com.ibm.cloud.eventnotifications.event_notifications.v1.model; + +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.PredefinedTemplate; +import com.ibm.cloud.eventnotifications.event_notifications.v1.utils.TestUtilities; +import com.ibm.cloud.sdk.core.service.model.FileWithMetadata; +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import org.testng.annotations.Test; +import static org.testng.Assert.*; + +/** + * Unit test class for the PredefinedTemplate model. + */ +public class PredefinedTemplateTest { + final HashMap mockStreamMap = TestUtilities.createMockStreamMap(); + final List mockListFileWithMetadata = TestUtilities.creatMockListFileWithMetadata(); + + @Test + public void testPredefinedTemplate() throws Throwable { + PredefinedTemplate predefinedTemplateModel = new PredefinedTemplate(); + assertNull(predefinedTemplateModel.getId()); + assertNull(predefinedTemplateModel.getName()); + assertNull(predefinedTemplateModel.getDescription()); + assertNull(predefinedTemplateModel.getSource()); + assertNull(predefinedTemplateModel.getType()); + assertNull(predefinedTemplateModel.getUpdatedAt()); + } +} \ No newline at end of file diff --git a/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/PredefinedTemplatesListTest.java b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/PredefinedTemplatesListTest.java new file mode 100644 index 0000000..384bf12 --- /dev/null +++ b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/PredefinedTemplatesListTest.java @@ -0,0 +1,46 @@ +/* + * (C) Copyright IBM Corp. 2025. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package com.ibm.cloud.eventnotifications.event_notifications.v1.model; + +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.PageHrefResponse; +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.PredefinedTemplate; +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.PredefinedTemplatesList; +import com.ibm.cloud.eventnotifications.event_notifications.v1.utils.TestUtilities; +import com.ibm.cloud.sdk.core.service.model.FileWithMetadata; +import com.ibm.cloud.sdk.core.util.DateUtils; +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import org.testng.annotations.Test; +import static org.testng.Assert.*; + +/** + * Unit test class for the PredefinedTemplatesList model. + */ +public class PredefinedTemplatesListTest { + final HashMap mockStreamMap = TestUtilities.createMockStreamMap(); + final List mockListFileWithMetadata = TestUtilities.creatMockListFileWithMetadata(); + + @Test + public void testPredefinedTemplatesList() throws Throwable { + PredefinedTemplatesList predefinedTemplatesListModel = new PredefinedTemplatesList(); + assertNull(predefinedTemplatesListModel.getTotalCount()); + assertNull(predefinedTemplatesListModel.getOffset()); + assertNull(predefinedTemplatesListModel.getLimit()); + assertNull(predefinedTemplatesListModel.getTemplates()); + assertNull(predefinedTemplatesListModel.getFirst()); + assertNull(predefinedTemplatesListModel.getPrevious()); + assertNull(predefinedTemplatesListModel.getNext()); + } +} \ No newline at end of file diff --git a/modules/examples/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsExamples.java b/modules/examples/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsExamples.java index d79b0ac..0b98379 100644 --- a/modules/examples/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsExamples.java +++ b/modules/examples/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/EventNotificationsExamples.java @@ -2578,6 +2578,40 @@ public static void main(String[] args) throws Exception { e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()), e); } + try { + // begin-list_predefined_templates + ListPreDefinedTemplatesOptions listPreDefinedTemplatesOptionsModel = new ListPreDefinedTemplatesOptions.Builder() + .instanceId(instanceId) + .source("logs") + .type("slack.notification") + .build(); + + // Invoke getMetrics() with a valid options model and verify the result + Response response = eventNotificationsService.listPreDefinedTemplates(listPreDefinedTemplatesOptionsModel).execute(); + PredefinedTemplatesList responseObj = response.getResult(); + System.out.println(responseObj); + // end-list_predefined_templates + } catch (ServiceResponseException e) { + logger.error(String.format("Service returned status code %s: %s%nError details: %s", + e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()), e); + } + + try { + // begin-get_predefined_templates + GetPreDefinedTemplateOptions getPreDefinedTemplateOptionsModel = new GetPreDefinedTemplateOptions.Builder() + .instanceId(instanceId) + .id("0cacb9a0-d43a-4042-920d-d4a3f7d4cbd5") + .build(); + + Response response = eventNotificationsService.getPreDefinedTemplate(getPreDefinedTemplateOptionsModel).execute(); + GetPredefinedTemplate responseObj = response.getResult(); + System.out.println(responseObj); + // end-get_predefined_templates + } catch (ServiceResponseException e) { + logger.error(String.format("Service returned status code %s: %s%nError details: %s", + e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()), e); + } + try { // begin-delete_smtp_user DeleteSmtpUserOptions deleteSmtpUserOptionsModel = new DeleteSmtpUserOptions.Builder()