Skip to content

Commit

Permalink
#94 mockito up
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Aug 5, 2020
1 parent bc3a0a7 commit 7ded4bd
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 164 deletions.
161 changes: 0 additions & 161 deletions nginx.conf.sigil

This file was deleted.

7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
<parent>
<groupId>com.jcabi</groupId>
<artifactId>parent</artifactId>
<version>0.50.6</version>
<version>0.50.7</version>
</parent>
<groupId>io.wring</groupId>
<artifactId>wring</artifactId>
Expand Down Expand Up @@ -100,6 +100,11 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
<artifactId>sentry</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>com.github.pengrad</groupId>
<artifactId>java-telegram-bot-api</artifactId>
<version>4.9.0</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
Expand Down
24 changes: 23 additions & 1 deletion src/main/java/io/wring/agents/Cycle.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/
package io.wring.agents;

import com.pengrad.telegrambot.TelegramBot;
import io.wring.model.Base;
import io.wring.model.Events;
import io.wring.model.Pipe;
Expand Down Expand Up @@ -58,12 +59,26 @@ final class Cycle implements Proc<Pipe> {
*/
private final transient Base base;

/**
* Telegram.
*/
private final transient TelegramBot telegram;

/**
* Ctor.
* @param bse Base
*/
Cycle(final Base bse) {
this(bse, new TelegramBot(""));
}

/**
* Ctor.
* @param bse Base
*/
Cycle(final Base bse, final TelegramBot bot) {
this.base = bse;
this.telegram = bot;
}

@Override
Expand Down Expand Up @@ -91,7 +106,14 @@ json, new TextOf(new BytesOf(error)).asString()
if (obj != null) {
new Exec(
new JsonAgent(this.base, obj),
new IgnoreEvents(new BoostEvents(events, obj), obj),
new IgnoreEvents(
new TelegramEvents(
new BoostEvents(events, obj),
this.telegram,
obj
),
obj
),
pipe
).run();
}
Expand Down
24 changes: 23 additions & 1 deletion src/main/java/io/wring/agents/Routine.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
import com.jcabi.log.VerboseRunnable;
import com.jcabi.log.VerboseThreads;
import com.jcabi.manifests.Manifests;
import com.pengrad.telegrambot.TelegramBot;
import com.pengrad.telegrambot.UpdatesListener;
import com.pengrad.telegrambot.model.Update;
import com.pengrad.telegrambot.request.SendMessage;
import io.sentry.Sentry;
import io.wring.model.Base;
import io.wring.model.Pipe;
Expand Down Expand Up @@ -86,6 +90,11 @@ public final class Routine implements Callable<Integer>, AutoCloseable {
*/
private final transient ExecutorService executor;

/**
* Telegram.
*/
private final transient TelegramBot telegram;

/**
* Ctor.
* @param bse Base
Expand Down Expand Up @@ -115,12 +124,25 @@ public Routine(final Base bse, final int total) {
)
)
);
this.telegram = new TelegramBot(Manifests.read("Wring-TelegramToken"));
}

/**
* Start it.
*/
public void start() {
this.telegram.setUpdatesListener(updates -> {
for (final Update update : updates) {
final long chat = update.message().chat().id();
this.telegram.execute(
new SendMessage(
chat,
String.format("Your chat ID is %d", chat)
)
);
}
return UpdatesListener.CONFIRMED_UPDATES_ALL;
});
Sentry.init(Manifests.read("Wring-SentryDsn"));
this.ticker.scheduleWithFixedDelay(
new VerboseRunnable(
Expand Down Expand Up @@ -237,7 +259,7 @@ private static void close(final ExecutorService svc)
private Runnable job(final Pipe pipe) {
return new RunnableOf<>(
new FuncWithFallback<Pipe, Boolean>(
new FuncOf<>(new Cycle(this.base)),
new FuncOf<>(new Cycle(this.base, this.telegram)),
new FuncOf<>(
error -> {
Sentry.capture(error);
Expand Down
Loading

0 comments on commit 7ded4bd

Please sign in to comment.