Skip to content

Commit

Permalink
Add fields max_connections, allowed_updates in WebhookInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
pengrad committed Jun 6, 2017
1 parent bd09a52 commit 4e2e360
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pengrad.telegrambot.model;

import java.io.Serializable;
import java.util.Arrays;

/**
* Stas Parshin
Expand All @@ -14,6 +15,8 @@ public class WebhookInfo implements Serializable {
private Integer pending_update_count;
private Integer last_error_date;
private String last_error_message;
private Integer max_connections;
private String[] allowed_updates;

public String url() {
return url;
Expand All @@ -35,6 +38,14 @@ public String lastErrorMessage() {
return last_error_message;
}

public Integer maxConnections() {
return max_connections;
}

public String[] allowedUpdates() {
return allowed_updates;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -49,7 +60,12 @@ public boolean equals(Object o) {
return false;
if (last_error_date != null ? !last_error_date.equals(that.last_error_date) : that.last_error_date != null)
return false;
return last_error_message != null ? last_error_message.equals(that.last_error_message) : that.last_error_message == null;
if (last_error_message != null ? !last_error_message.equals(that.last_error_message) : that.last_error_message != null)
return false;
if (max_connections != null ? !max_connections.equals(that.max_connections) : that.max_connections != null)
return false;
// Probably incorrect - comparing Object[] arrays with Arrays.equals
return Arrays.equals(allowed_updates, that.allowed_updates);
}

@Override
Expand All @@ -59,6 +75,8 @@ public int hashCode() {
result = 31 * result + (pending_update_count != null ? pending_update_count.hashCode() : 0);
result = 31 * result + (last_error_date != null ? last_error_date.hashCode() : 0);
result = 31 * result + (last_error_message != null ? last_error_message.hashCode() : 0);
result = 31 * result + (max_connections != null ? max_connections.hashCode() : 0);
result = 31 * result + Arrays.hashCode(allowed_updates);
return result;
}

Expand All @@ -70,6 +88,8 @@ public String toString() {
", pending_update_count=" + pending_update_count +
", last_error_date=" + last_error_date +
", last_error_message='" + last_error_message + '\'' +
", max_connections=" + max_connections +
", allowed_updates=" + Arrays.toString(allowed_updates) +
'}';
}
}
17 changes: 14 additions & 3 deletions library/src/test/java/com/pengrad/telegrambot/TelegramBotTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -515,19 +515,30 @@ public void getWebhookInfo() {

@Test
public void setWebhook() throws IOException, InterruptedException {
BaseResponse response = bot.execute(new SetWebhook().url("https://google.com").certificate(new File(certificateFile))
.maxConnections(100).allowedUpdates("message", "callback_query"));
String url = "https://google.com";
Integer maxConnections = 100;
String[] allowedUpdates = {"message", "callback_query"};
BaseResponse response = bot.execute(new SetWebhook().url(url).certificate(new File(certificateFile))
.maxConnections(100).allowedUpdates(allowedUpdates));
assertTrue(response.isOk());

Thread.sleep(1000);

WebhookInfo webhookInfo = bot.execute(new GetWebhookInfo()).webhookInfo();
assertEquals(url, webhookInfo.url());
assertTrue(webhookInfo.hasCustomCertificate());
assertEquals(maxConnections, webhookInfo.maxConnections());
assertEquals(allowedUpdates, webhookInfo.allowedUpdates());
assertNotNull(webhookInfo.lastErrorDate());
assertNotNull(webhookInfo.lastErrorMessage());

response = bot.execute(new SetWebhook().url("https://google.com")
.certificate(Files.readAllBytes(new File(certificateFile).toPath())).allowedUpdates(""));
assertTrue(response.isOk());

Thread.sleep(1000);

response = bot.execute(new SetWebhook().allowedUpdates(new String[0]));
response = bot.execute(new SetWebhook());
assertTrue(response.isOk());
}

Expand Down

0 comments on commit 4e2e360

Please sign in to comment.