diff --git a/.secrets.baseline b/.secrets.baseline index 48ca923..3ee8425 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -3,7 +3,7 @@ "files": "^.secrets.baseline$", "lines": null }, - "generated_at": "2025-10-28T04:20:32Z", + "generated_at": "2025-12-09T14:05:00Z", "plugins_used": [ { "name": "AWSKeyDetector" @@ -136,7 +136,7 @@ "hashed_secret": "9bf92274d58c3655b80055ad2ab17540f71d3058", "is_secret": false, "is_verified": false, - "line_number": 3295, + "line_number": 3373, "type": "Secret Keyword", "verified_result": null } diff --git a/README.md b/README.md index 5245136..f8a2ad8 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,7 @@ SDK Methods to consume - [Verify SMTP](#verify-smtp) - [Metrics](#Metrics) - [Get Metrics](#get-metrics) + - [Get Bounce Metrics](#get-bounce-metrics) - [Send Notifications](#send-notifications) ## Source @@ -1354,7 +1355,9 @@ GetMetricsOptions getMetricsOptionsModel = new GetMetricsOptions.Builder() .gte() .lte() .destinationId() + .subscriptionId() .emailTo() + .sourceId() .notificationId() .subject() .build(); @@ -1364,6 +1367,26 @@ Response response = eventNotificationsService.getMetrics(getMetricsOpti Metrics responseObj = response.getResult(); ``` +### Get Bounce Metrics + +```java +GetBounceMetricsOptions getBounceMetricsOptionsModel = new GetBounceMetricsOptions.Builder() + .instanceId(instanceId) + .destinationType("smtp_custom") + .gte() + .lte() + .destinationId() + .subscriptionId() + .emailTo() + .sourceId() + .notificationId() + .subject() + .build(); + +Response response = eventNotificationsService.getBounceMetrics(getBounceMetricsOptionsModel).execute(); +BounceMetrics responseObj = response.getResult(); +``` + ### Send Notifications ```java 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 8f36d98..870d52f 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 @@ -19,6 +19,7 @@ import com.google.gson.JsonObject; import com.ibm.cloud.event_notifications.common.SdkCommon; +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.BounceMetrics; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.CreateDestinationOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.CreateIntegrationOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.CreateSmtpConfigurationOptions; @@ -41,6 +42,7 @@ import com.ibm.cloud.eventnotifications.event_notifications.v1.model.DestinationResponse; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.DestinationTagsSubscriptionResponse; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.EnabledCountriesResponse; +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetBounceMetricsOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetDestinationOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetEnabledCountriesOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetIntegrationOptions; @@ -197,6 +199,9 @@ public ServiceCall getMetrics(GetMetricsOptions getMetricsOptions) { if (getMetricsOptions.destinationId() != null) { builder.query("destination_id", String.valueOf(getMetricsOptions.destinationId())); } + if (getMetricsOptions.subscriptionId() != null) { + builder.query("subscription_id", String.valueOf(getMetricsOptions.subscriptionId())); + } if (getMetricsOptions.sourceId() != null) { builder.query("source_id", String.valueOf(getMetricsOptions.sourceId())); } @@ -214,6 +219,57 @@ public ServiceCall getMetrics(GetMetricsOptions getMetricsOptions) { return createServiceCall(builder.build(), responseConverter); } + /** + * Get bounce metrics. + * + * Get bounce metrics. + * + * @param getBounceMetricsOptions the {@link GetBounceMetricsOptions} containing the options for the call + * @return a {@link ServiceCall} with a result of type {@link BounceMetrics} + */ + public ServiceCall getBounceMetrics(GetBounceMetricsOptions getBounceMetricsOptions) { + com.ibm.cloud.sdk.core.util.Validator.notNull(getBounceMetricsOptions, + "getBounceMetricsOptions cannot be null"); + Map pathParamsMap = new HashMap(); + pathParamsMap.put("instance_id", getBounceMetricsOptions.instanceId()); + RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/instances/{instance_id}/metrics/bounce", pathParamsMap)); + Map sdkHeaders = SdkCommon.getSdkHeaders("event_notifications", "v1", "getBounceMetrics"); + for (Entry header : sdkHeaders.entrySet()) { + builder.header(header.getKey(), header.getValue()); + } + builder.header("Accept", "application/json"); + builder.query("destination_type", String.valueOf(getBounceMetricsOptions.destinationType())); + builder.query("gte", String.valueOf(getBounceMetricsOptions.gte())); + builder.query("lte", String.valueOf(getBounceMetricsOptions.lte())); + if (getBounceMetricsOptions.destinationId() != null) { + builder.query("destination_id", String.valueOf(getBounceMetricsOptions.destinationId())); + } + if (getBounceMetricsOptions.subscriptionId() != null) { + builder.query("subscription_id", String.valueOf(getBounceMetricsOptions.subscriptionId())); + } + if (getBounceMetricsOptions.sourceId() != null) { + builder.query("source_id", String.valueOf(getBounceMetricsOptions.sourceId())); + } + if (getBounceMetricsOptions.emailTo() != null) { + builder.query("email_to", String.valueOf(getBounceMetricsOptions.emailTo())); + } + if (getBounceMetricsOptions.notificationId() != null) { + builder.query("notification_id", String.valueOf(getBounceMetricsOptions.notificationId())); + } + if (getBounceMetricsOptions.subject() != null) { + builder.query("subject", String.valueOf(getBounceMetricsOptions.subject())); + } + if (getBounceMetricsOptions.limit() != null) { + builder.query("limit", String.valueOf(getBounceMetricsOptions.limit())); + } + if (getBounceMetricsOptions.offset() != null) { + builder.query("offset", String.valueOf(getBounceMetricsOptions.offset())); + } + ResponseConverter responseConverter = + ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken() { }.getType()); + return createServiceCall(builder.build(), responseConverter); + } + /** * Send a notification. * diff --git a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/BounceMetricItem.java b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/BounceMetricItem.java new file mode 100644 index 0000000..4e0cc38 --- /dev/null +++ b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/BounceMetricItem.java @@ -0,0 +1,104 @@ +/* + * (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; + +/** + * Bounce metric object. + */ +public class BounceMetricItem extends GenericModel { + + @SerializedName("email_address") + protected String emailAddress; + protected String subject; + @SerializedName("error_message") + protected String errorMessage; + @SerializedName("ip_address") + protected String ipAddress; + @SerializedName("subscription_id") + protected String subscriptionId; + protected Date timestamp; + + protected BounceMetricItem() { } + + /** + * Gets the emailAddress. + * + * Email address. + * + * @return the emailAddress + */ + public String getEmailAddress() { + return emailAddress; + } + + /** + * Gets the subject. + * + * Subject. + * + * @return the subject + */ + public String getSubject() { + return subject; + } + + /** + * Gets the errorMessage. + * + * Error message. + * + * @return the errorMessage + */ + public String getErrorMessage() { + return errorMessage; + } + + /** + * Gets the ipAddress. + * + * IP address. + * + * @return the ipAddress + */ + public String getIpAddress() { + return ipAddress; + } + + /** + * Gets the subscriptionId. + * + * Subscription ID. + * + * @return the subscriptionId + */ + public String getSubscriptionId() { + return subscriptionId; + } + + /** + * Gets the timestamp. + * + * Bounced at. + * + * @return the timestamp + */ + public Date getTimestamp() { + return timestamp; + } +} + diff --git a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/BounceMetrics.java b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/BounceMetrics.java new file mode 100644 index 0000000..d9d90a3 --- /dev/null +++ b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/BounceMetrics.java @@ -0,0 +1,53 @@ +/* + * (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 bounce metrics. + */ +public class BounceMetrics extends GenericModel { + + protected List metrics; + @SerializedName("total_count") + protected Long totalCount; + + protected BounceMetrics() { } + + /** + * Gets the metrics. + * + * array of bounce metrics. + * + * @return the metrics + */ + public List getMetrics() { + return metrics; + } + + /** + * Gets the totalCount. + * + * total number of bounce metrics. + * + * @return the totalCount + */ + public Long getTotalCount() { + return totalCount; + } +} + diff --git a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetBounceMetricsOptions.java b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetBounceMetricsOptions.java new file mode 100644 index 0000000..d6102ee --- /dev/null +++ b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetBounceMetricsOptions.java @@ -0,0 +1,409 @@ +/* + * (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 getBounceMetrics options. + */ +public class GetBounceMetricsOptions extends GenericModel { + + /** + * Destination type. Allowed values are [smtp_custom]. + */ + public interface DestinationType { + /** smtp_custom. */ + String SMTP_CUSTOM = "smtp_custom"; + } + + protected String instanceId; + protected String destinationType; + protected String gte; + protected String lte; + protected String destinationId; + protected String subscriptionId; + protected String sourceId; + protected String emailTo; + protected String notificationId; + protected String subject; + protected Long limit; + protected Long offset; + + /** + * Builder. + */ + public static class Builder { + private String instanceId; + private String destinationType; + private String gte; + private String lte; + private String destinationId; + private String subscriptionId; + private String sourceId; + private String emailTo; + private String notificationId; + private String subject; + private Long limit; + private Long offset; + + /** + * Instantiates a new Builder from an existing GetBounceMetricsOptions instance. + * + * @param getBounceMetricsOptions the instance to initialize the Builder with + */ + private Builder(GetBounceMetricsOptions getBounceMetricsOptions) { + this.instanceId = getBounceMetricsOptions.instanceId; + this.destinationType = getBounceMetricsOptions.destinationType; + this.gte = getBounceMetricsOptions.gte; + this.lte = getBounceMetricsOptions.lte; + this.destinationId = getBounceMetricsOptions.destinationId; + this.subscriptionId = getBounceMetricsOptions.subscriptionId; + this.sourceId = getBounceMetricsOptions.sourceId; + this.emailTo = getBounceMetricsOptions.emailTo; + this.notificationId = getBounceMetricsOptions.notificationId; + this.subject = getBounceMetricsOptions.subject; + this.limit = getBounceMetricsOptions.limit; + this.offset = getBounceMetricsOptions.offset; + } + + /** + * Instantiates a new builder. + */ + public Builder() { + } + + /** + * Instantiates a new builder with required properties. + * + * @param instanceId the instanceId + * @param destinationType the destinationType + * @param gte the gte + * @param lte the lte + */ + public Builder(String instanceId, String destinationType, String gte, String lte) { + this.instanceId = instanceId; + this.destinationType = destinationType; + this.gte = gte; + this.lte = lte; + } + + /** + * Builds a GetBounceMetricsOptions. + * + * @return the new GetBounceMetricsOptions instance + */ + public GetBounceMetricsOptions build() { + return new GetBounceMetricsOptions(this); + } + + /** + * Set the instanceId. + * + * @param instanceId the instanceId + * @return the GetBounceMetricsOptions builder + */ + public Builder instanceId(String instanceId) { + this.instanceId = instanceId; + return this; + } + + /** + * Set the destinationType. + * + * @param destinationType the destinationType + * @return the GetBounceMetricsOptions builder + */ + public Builder destinationType(String destinationType) { + this.destinationType = destinationType; + return this; + } + + /** + * Set the gte. + * + * @param gte the gte + * @return the GetBounceMetricsOptions builder + */ + public Builder gte(String gte) { + this.gte = gte; + return this; + } + + /** + * Set the lte. + * + * @param lte the lte + * @return the GetBounceMetricsOptions builder + */ + public Builder lte(String lte) { + this.lte = lte; + return this; + } + + /** + * Set the destinationId. + * + * @param destinationId the destinationId + * @return the GetBounceMetricsOptions builder + */ + public Builder destinationId(String destinationId) { + this.destinationId = destinationId; + return this; + } + + /** + * Set the subscriptionId. + * + * @param subscriptionId the subscriptionId + * @return the GetBounceMetricsOptions builder + */ + public Builder subscriptionId(String subscriptionId) { + this.subscriptionId = subscriptionId; + return this; + } + + /** + * Set the sourceId. + * + * @param sourceId the sourceId + * @return the GetBounceMetricsOptions builder + */ + public Builder sourceId(String sourceId) { + this.sourceId = sourceId; + return this; + } + + /** + * Set the emailTo. + * + * @param emailTo the emailTo + * @return the GetBounceMetricsOptions builder + */ + public Builder emailTo(String emailTo) { + this.emailTo = emailTo; + return this; + } + + /** + * Set the notificationId. + * + * @param notificationId the notificationId + * @return the GetBounceMetricsOptions builder + */ + public Builder notificationId(String notificationId) { + this.notificationId = notificationId; + return this; + } + + /** + * Set the subject. + * + * @param subject the subject + * @return the GetBounceMetricsOptions builder + */ + public Builder subject(String subject) { + this.subject = subject; + return this; + } + + /** + * Set the limit. + * + * @param limit the limit + * @return the GetBounceMetricsOptions builder + */ + public Builder limit(long limit) { + this.limit = limit; + return this; + } + + /** + * Set the offset. + * + * @param offset the offset + * @return the GetBounceMetricsOptions builder + */ + public Builder offset(long offset) { + this.offset = offset; + return this; + } + } + + protected GetBounceMetricsOptions() { } + + protected GetBounceMetricsOptions(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.destinationType, + "destinationType cannot be null"); + com.ibm.cloud.sdk.core.util.Validator.notNull(builder.gte, + "gte cannot be null"); + com.ibm.cloud.sdk.core.util.Validator.notNull(builder.lte, + "lte cannot be null"); + instanceId = builder.instanceId; + destinationType = builder.destinationType; + gte = builder.gte; + lte = builder.lte; + destinationId = builder.destinationId; + subscriptionId = builder.subscriptionId; + sourceId = builder.sourceId; + emailTo = builder.emailTo; + notificationId = builder.notificationId; + subject = builder.subject; + limit = builder.limit; + offset = builder.offset; + } + + /** + * New builder. + * + * @return a GetBounceMetricsOptions 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 destinationType. + * + * Destination type. Allowed values are [smtp_custom]. + * + * @return the destinationType + */ + public String destinationType() { + return destinationType; + } + + /** + * Gets the gte. + * + * GTE (greater than equal), start timestamp in UTC. + * + * @return the gte + */ + public String gte() { + return gte; + } + + /** + * Gets the lte. + * + * LTE (less than equal), end timestamp in UTC. + * + * @return the lte + */ + public String lte() { + return lte; + } + + /** + * Gets the destinationId. + * + * Unique identifier for Destination. + * + * @return the destinationId + */ + public String destinationId() { + return destinationId; + } + + /** + * Gets the subscriptionId. + * + * Unique identifier for Subscription. + * + * @return the subscriptionId + */ + public String subscriptionId() { + return subscriptionId; + } + + /** + * Gets the sourceId. + * + * Unique identifier for Source. + * + * @return the sourceId + */ + public String sourceId() { + return sourceId; + } + + /** + * Gets the emailTo. + * + * Receiver email id. + * + * @return the emailTo + */ + public String emailTo() { + return emailTo; + } + + /** + * Gets the notificationId. + * + * Notification Id. + * + * @return the notificationId + */ + public String notificationId() { + return notificationId; + } + + /** + * Gets the subject. + * + * Email subject. + * + * @return the subject + */ + public String subject() { + return subject; + } + + /** + * 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; + } +} + diff --git a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetMetricsOptions.java b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetMetricsOptions.java index 5dbf38a..948b36d 100644 --- a/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetMetricsOptions.java +++ b/modules/event-notifications/src/main/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetMetricsOptions.java @@ -32,6 +32,7 @@ public interface DestinationType { protected String gte; protected String lte; protected String destinationId; + protected String subscriptionId; protected String sourceId; protected String emailTo; protected String notificationId; @@ -46,6 +47,7 @@ public static class Builder { private String gte; private String lte; private String destinationId; + private String subscriptionId; private String sourceId; private String emailTo; private String notificationId; @@ -62,6 +64,7 @@ private Builder(GetMetricsOptions getMetricsOptions) { this.gte = getMetricsOptions.gte; this.lte = getMetricsOptions.lte; this.destinationId = getMetricsOptions.destinationId; + this.subscriptionId = getMetricsOptions.subscriptionId; this.sourceId = getMetricsOptions.sourceId; this.emailTo = getMetricsOptions.emailTo; this.notificationId = getMetricsOptions.notificationId; @@ -153,6 +156,17 @@ public Builder destinationId(String destinationId) { return this; } + /** + * Set the subscriptionId. + * + * @param subscriptionId the subscriptionId + * @return the GetMetricsOptions builder + */ + public Builder subscriptionId(String subscriptionId) { + this.subscriptionId = subscriptionId; + return this; + } + /** * Set the sourceId. * @@ -214,6 +228,7 @@ protected GetMetricsOptions(Builder builder) { gte = builder.gte; lte = builder.lte; destinationId = builder.destinationId; + subscriptionId = builder.subscriptionId; sourceId = builder.sourceId; emailTo = builder.emailTo; notificationId = builder.notificationId; @@ -284,6 +299,17 @@ public String destinationId() { return destinationId; } + /** + * Gets the subscriptionId. + * + * Unique identifier for Subscription. + * + * @return the subscriptionId + */ + public String subscriptionId() { + return subscriptionId; + } + /** * Gets the sourceId. * 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 c72fae0..d3b4143 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 @@ -4295,7 +4295,9 @@ public void test2LTestMetrics(){ .gte(instant.minus(Duration.ofDays(1)).toString()) .lte(d1) .destinationId(destinationId16) + .subscriptionId(subscriptionId16) .emailTo("mobileb@us.ibm.com") + .sourceId(sourceId) .notificationId(notificationID) .subject("Metric Test") .build(); @@ -4315,7 +4317,39 @@ public void test2LTestMetrics(){ } @Test - public void test2MTestListPredefinedTemplates(){ + public void test2MTestBounceMetrics(){ + try{ + Instant instant = Instant.now(); + String d1 = instant.toString(); + + GetBounceMetricsOptions getBounceMetricsOptionsModel = new GetBounceMetricsOptions.Builder() + .instanceId(instanceId) + .destinationType("smtp_custom") + .gte(instant.minus(Duration.ofDays(1)).toString()) + .lte(d1) + .destinationId(destinationId16) + .subscriptionId(subscriptionId16) + .emailTo("mobileb@us.ibm.com") + .notificationId(notificationID) + .sourceId(sourceId) + .subject("Bounce Metrics") + .build(); + + // Invoke getBounceMetrics() with a valid options model and verify the result + Response response = service.getBounceMetrics(getBounceMetricsOptionsModel).execute(); + assertNotNull(response); + assertEquals(response.getStatusCode(), 200); + BounceMetrics 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 test2NTestListPredefinedTemplates(){ try{ ListPreDefinedTemplatesOptions listPreDefinedTemplatesOptionsModel = new ListPreDefinedTemplatesOptions.Builder() @@ -4339,7 +4373,7 @@ public void test2MTestListPredefinedTemplates(){ } @Test - public void test2NTestGetPredefinedTemplate(){ + public void test2OTestGetPredefinedTemplate(){ try{ GetPreDefinedTemplateOptions getPreDefinedTemplateOptionsModel = new GetPreDefinedTemplateOptions.Builder() @@ -4361,7 +4395,7 @@ public void test2NTestGetPredefinedTemplate(){ } @Test - public void test2ODeleteSubscription() throws Exception { + public void test2PDeleteSubscription() throws Exception { try { List subscriptions = new ArrayList<>(); @@ -4417,7 +4451,7 @@ public void test2ODeleteSubscription() throws Exception { } @Test - public void test2PDeleteTopic() throws Exception { + public void test2QDeleteTopic() throws Exception { try { List topics = new ArrayList<>(); @@ -4456,7 +4490,7 @@ public void test2PDeleteTopic() throws Exception { } @Test - public void test2QDeleteDestination() throws Exception { + public void test2RDeleteDestination() throws Exception { try { List destinations = new ArrayList<>(); destinations.add(destinationId); @@ -4509,7 +4543,7 @@ public void test2QDeleteDestination() throws Exception { } @Test - public void test2RDeleteSource() throws Exception { + public void test2SDeleteSource() throws Exception { try { DeleteSourceOptions deleteSourceOptions = new DeleteSourceOptions.Builder() .instanceId(instanceId) @@ -4539,7 +4573,7 @@ public void test2RDeleteSource() throws Exception { } @Test - public void test2SCreateIntegration() throws Exception { + public void test2TCreateIntegration() throws Exception { try { IntegrationCreateMetadata metadata = new IntegrationCreateMetadata.Builder() .endpoint(cosEndPoint) @@ -4567,7 +4601,7 @@ public void test2SCreateIntegration() throws Exception { } @Test - public void test2TListIntegrations() throws Exception { + public void test2UListIntegrations() throws Exception { try { int limit = 1; int offset = 0; @@ -4594,7 +4628,7 @@ public void test2TListIntegrations() throws Exception { } @Test - public void test2UGetIntegration() throws Exception { + public void test2VGetIntegration() throws Exception { try { GetIntegrationOptions integrationsOptions = new GetIntegrationOptions.Builder() .instanceId(instanceId) @@ -4614,7 +4648,7 @@ public void test2UGetIntegration() throws Exception { } @Test - public void test2VUpdateIntegration() throws Exception { + public void test2WUpdateIntegration() throws Exception { try { IntegrationMetadata metadata = new IntegrationMetadata.Builder() .endpoint(cosEndPoint) @@ -4642,7 +4676,7 @@ public void test2VUpdateIntegration() throws Exception { } @Test - public void test2WDeleteTemplate() throws Exception { + public void test2XDeleteTemplate() throws Exception { try { List templates = new ArrayList<>(); templates.add(templateInvitationID); @@ -4673,7 +4707,7 @@ public void test2WDeleteTemplate() throws Exception { } } @Test - public void test2XDeleteSMTPUser() throws Exception { + public void test2YDeleteSMTPUser() throws Exception { try { List users = new ArrayList<>(); users.add(smtpUserID); @@ -4696,7 +4730,7 @@ public void test2XDeleteSMTPUser() throws Exception { } } @Test - public void test2YDeleteSMTPConfiguration() throws Exception { + public void test2ZDeleteSMTPConfiguration() throws Exception { try { List smtpConfigIDs = new ArrayList<>(); smtpConfigIDs.add(smtpConfigID); 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 76f0bcb..74c72e1 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 @@ -13,6 +13,8 @@ package com.ibm.cloud.eventnotifications.event_notifications.v1; import com.ibm.cloud.eventnotifications.event_notifications.v1.EventNotifications; +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.BounceMetricItem; +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.BounceMetrics; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.Buckets; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ChannelCreateAttributes; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.ChannelUpdateAttributes; @@ -64,6 +66,7 @@ import com.ibm.cloud.eventnotifications.event_notifications.v1.model.EmailAttributesResponseSubscribedUnsubscribedItems; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.EnabledCountriesResponse; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.EventScheduleFilterAttributes; +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetBounceMetricsOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetDestinationOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetEnabledCountriesOptions; import com.ibm.cloud.eventnotifications.event_notifications.v1.model.GetIntegrationOptions; @@ -273,6 +276,7 @@ public void testGetMetricsWOptions() throws Throwable { .gte("testString") .lte("testString") .destinationId("testString") + .subscriptionId("testString") .sourceId("testString") .emailTo("testString") .notificationId("testString") @@ -299,6 +303,7 @@ public void testGetMetricsWOptions() throws Throwable { assertEquals(query.get("gte"), "testString"); assertEquals(query.get("lte"), "testString"); assertEquals(query.get("destination_id"), "testString"); + assertEquals(query.get("subscription_id"), "testString"); assertEquals(query.get("source_id"), "testString"); assertEquals(query.get("email_to"), "testString"); assertEquals(query.get("notification_id"), "testString"); @@ -322,6 +327,79 @@ public void testGetMetricsNoOptions() throws Throwable { eventNotificationsService.getMetrics(null).execute(); } + // Test the getBounceMetrics operation with a valid options model parameter + @Test + public void testGetBounceMetricsWOptions() throws Throwable { + // Register a mock response + String mockResponseBody = "{\"metrics\": [{\"email_address\": \"emailAddress\", \"subject\": \"subject\", \"error_message\": \"errorMessage\", \"ip_address\": \"ipAddress\", \"subscription_id\": \"subscriptionId\", \"timestamp\": \"2019-01-01T12:00:00.000Z\"}], \"total_count\": 0}"; + String getBounceMetricsPath = "/v1/instances/testString/metrics/bounce"; + server.enqueue(new MockResponse() + .setHeader("Content-type", "application/json") + .setResponseCode(200) + .setBody(mockResponseBody)); + + // Construct an instance of the GetBounceMetricsOptions model + GetBounceMetricsOptions getBounceMetricsOptionsModel = new GetBounceMetricsOptions.Builder() + .instanceId("testString") + .destinationType("smtp_custom") + .gte("testString") + .lte("testString") + .destinationId("testString") + .subscriptionId("testString") + .sourceId("testString") + .emailTo("testString") + .notificationId("testString") + .subject("testString") + .limit(Long.valueOf("1")) + .offset(Long.valueOf("0")) + .build(); + + // Invoke getBounceMetrics() with a valid options model and verify the result + Response response = eventNotificationsService.getBounceMetrics(getBounceMetricsOptionsModel).execute(); + assertNotNull(response); + BounceMetrics 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, getBounceMetricsPath); + // Verify query params + Map query = TestUtilities.parseQueryString(request); + assertNotNull(query); + assertEquals(query.get("destination_type"), "smtp_custom"); + assertEquals(query.get("gte"), "testString"); + assertEquals(query.get("lte"), "testString"); + assertEquals(query.get("destination_id"), "testString"); + assertEquals(query.get("subscription_id"), "testString"); + assertEquals(query.get("source_id"), "testString"); + assertEquals(query.get("email_to"), "testString"); + assertEquals(query.get("notification_id"), "testString"); + assertEquals(query.get("subject"), "testString"); + assertEquals(Long.valueOf(query.get("limit")), Long.valueOf("1")); + assertEquals(Long.valueOf(query.get("offset")), Long.valueOf("0")); + } + + // Test the getBounceMetrics operation with and without retries enabled + @Test + public void testGetBounceMetricsWRetries() throws Throwable { + eventNotificationsService.enableRetries(4, 30); + testGetBounceMetricsWOptions(); + + eventNotificationsService.disableRetries(); + testGetBounceMetricsWOptions(); + } + + // Test the getBounceMetrics operation with a null options model (negative test) + @Test(expectedExceptions = IllegalArgumentException.class) + public void testGetBounceMetricsNoOptions() throws Throwable { + server.enqueue(new MockResponse()); + eventNotificationsService.getBounceMetrics(null).execute(); + } + // Test the sendNotifications operation with a valid options model parameter @Test public void testSendNotificationsWOptions() throws Throwable { diff --git a/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/BounceMetricItemTest.java b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/BounceMetricItemTest.java new file mode 100644 index 0000000..8c249d3 --- /dev/null +++ b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/BounceMetricItemTest.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.BounceMetricItem; +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 BounceMetricItem model. + */ +public class BounceMetricItemTest { + final HashMap mockStreamMap = TestUtilities.createMockStreamMap(); + final List mockListFileWithMetadata = TestUtilities.creatMockListFileWithMetadata(); + + @Test + public void testBounceMetricItem() throws Throwable { + BounceMetricItem bounceMetricItemModel = new BounceMetricItem(); + assertNull(bounceMetricItemModel.getEmailAddress()); + assertNull(bounceMetricItemModel.getSubject()); + assertNull(bounceMetricItemModel.getErrorMessage()); + assertNull(bounceMetricItemModel.getIpAddress()); + assertNull(bounceMetricItemModel.getSubscriptionId()); + assertNull(bounceMetricItemModel.getTimestamp()); + } +} \ No newline at end of file diff --git a/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/BounceMetricsTest.java b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/BounceMetricsTest.java new file mode 100644 index 0000000..02dd0b2 --- /dev/null +++ b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/BounceMetricsTest.java @@ -0,0 +1,40 @@ +/* + * (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.BounceMetricItem; +import com.ibm.cloud.eventnotifications.event_notifications.v1.model.BounceMetrics; +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 BounceMetrics model. + */ +public class BounceMetricsTest { + final HashMap mockStreamMap = TestUtilities.createMockStreamMap(); + final List mockListFileWithMetadata = TestUtilities.creatMockListFileWithMetadata(); + + @Test + public void testBounceMetrics() throws Throwable { + BounceMetrics bounceMetricsModel = new BounceMetrics(); + assertNull(bounceMetricsModel.getMetrics()); + assertNull(bounceMetricsModel.getTotalCount()); + } +} \ No newline at end of file diff --git a/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetBounceMetricsOptionsTest.java b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetBounceMetricsOptionsTest.java new file mode 100644 index 0000000..9e975c2 --- /dev/null +++ b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetBounceMetricsOptionsTest.java @@ -0,0 +1,67 @@ +/* + * (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.GetBounceMetricsOptions; +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 GetBounceMetricsOptions model. + */ +public class GetBounceMetricsOptionsTest { + final HashMap mockStreamMap = TestUtilities.createMockStreamMap(); + final List mockListFileWithMetadata = TestUtilities.creatMockListFileWithMetadata(); + + @Test + public void testGetBounceMetricsOptions() throws Throwable { + GetBounceMetricsOptions getBounceMetricsOptionsModel = new GetBounceMetricsOptions.Builder() + .instanceId("testString") + .destinationType("smtp_custom") + .gte("testString") + .lte("testString") + .destinationId("testString") + .subscriptionId("testString") + .sourceId("testString") + .emailTo("testString") + .notificationId("testString") + .subject("testString") + .limit(Long.valueOf("1")) + .offset(Long.valueOf("0")) + .build(); + assertEquals(getBounceMetricsOptionsModel.instanceId(), "testString"); + assertEquals(getBounceMetricsOptionsModel.destinationType(), "smtp_custom"); + assertEquals(getBounceMetricsOptionsModel.gte(), "testString"); + assertEquals(getBounceMetricsOptionsModel.lte(), "testString"); + assertEquals(getBounceMetricsOptionsModel.destinationId(), "testString"); + assertEquals(getBounceMetricsOptionsModel.subscriptionId(), "testString"); + assertEquals(getBounceMetricsOptionsModel.sourceId(), "testString"); + assertEquals(getBounceMetricsOptionsModel.emailTo(), "testString"); + assertEquals(getBounceMetricsOptionsModel.notificationId(), "testString"); + assertEquals(getBounceMetricsOptionsModel.subject(), "testString"); + assertEquals(getBounceMetricsOptionsModel.limit(), Long.valueOf("1")); + assertEquals(getBounceMetricsOptionsModel.offset(), Long.valueOf("0")); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testGetBounceMetricsOptionsError() throws Throwable { + new GetBounceMetricsOptions.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/GetMetricsOptionsTest.java b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetMetricsOptionsTest.java index 89b8031..234f72f 100644 --- a/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetMetricsOptionsTest.java +++ b/modules/event-notifications/src/test/java/com/ibm/cloud/eventnotifications/event_notifications/v1/model/GetMetricsOptionsTest.java @@ -37,6 +37,7 @@ public void testGetMetricsOptions() throws Throwable { .gte("testString") .lte("testString") .destinationId("testString") + .subscriptionId("testString") .sourceId("testString") .emailTo("testString") .notificationId("testString") @@ -47,6 +48,7 @@ public void testGetMetricsOptions() throws Throwable { assertEquals(getMetricsOptionsModel.gte(), "testString"); assertEquals(getMetricsOptionsModel.lte(), "testString"); assertEquals(getMetricsOptionsModel.destinationId(), "testString"); + assertEquals(getMetricsOptionsModel.subscriptionId(), "testString"); assertEquals(getMetricsOptionsModel.sourceId(), "testString"); assertEquals(getMetricsOptionsModel.emailTo(), "testString"); assertEquals(getMetricsOptionsModel.notificationId(), "testString"); 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 6d44d70..a974605 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 @@ -2549,7 +2549,9 @@ public static void main(String[] args) throws Exception { .gte("2024-08-01T17:18:43Z") .lte("2024-08-02T11:55:22Z") .destinationId(destinationId16) + .subscriptionId(subscriptionId6) .emailTo("mobileb@us.ibm.com") + .sourceId(sourceId) .notificationId(notificationID) .subject("Metric Test") .build(); @@ -2565,6 +2567,32 @@ public static void main(String[] args) throws Exception { e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()), e); } + try { + // begin-bounce-metrics + GetBounceMetricsOptions getBounceMetricsOptionsModel = new GetBounceMetricsOptions.Builder() + .instanceId(instanceId) + .destinationType("smtp_custom") + .gte("2025-12-08T17:18:43Z") + .lte("2025-12-09T11:55:22Z") + .destinationId(destinationId16) + .subscriptionId(subscriptionId6) + .emailTo("mobileb@us.ibm.com") + .notificationId(notificationID) + .sourceId(sourceId) + .subject("Bounce Metrics") + .build(); + + // Invoke getMetrics() with a valid options model and verify the result + Response response = eventNotificationsService.getBounceMetrics(getBounceMetricsOptionsModel).execute(); + + BounceMetrics responseObj = response.getResult(); + System.out.println(responseObj); + // end-bounce-metrics + } 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-create_smtp_configuration String name = "SMTP Configuration";