Search in sources :

Example 1 with Event

use of io.wring.model.Event in project wring by yegor256.

the class DyEventsITCase method deletesEvent.

/**
 * DyEvents can delete events.
 * @throws Exception If some problem inside
 */
@Test
public void deletesEvent() throws Exception {
    final User user = new DyUser(new Dynamo(), "boris");
    final Events events = user.events();
    events.post("subj", "body");
    final Event event = events.iterate().iterator().next();
    event.delete();
    MatcherAssert.assertThat(Iterables.size(events.iterate()), Matchers.equalTo(0));
}
Also used : User(io.wring.model.User) Events(io.wring.model.Events) Event(io.wring.model.Event) Test(org.junit.Test)

Example 2 with Event

use of io.wring.model.Event in project wring by yegor256.

the class BoostEventsTest method boostsEvents.

/**
 * BoostEvents can boost events.
 * @throws Exception If some problem inside
 */
@Test
public void boostsEvents() throws Exception {
    final Events events = Mockito.mock(Events.class);
    final Event event = Mockito.mock(Event.class);
    Mockito.doReturn(event).when(events).event(Mockito.anyString());
    new BoostEvents(events, "alpha.*").post("x", "an\nalpha one\nhere");
    Mockito.verify(event).vote(Tv.FIVE);
}
Also used : Events(io.wring.model.Events) Event(io.wring.model.Event) Test(org.junit.Test)

Example 3 with Event

use of io.wring.model.Event in project wring by yegor256.

the class TkEventDelete method act.

@Override
public Response act(final Request req) throws IOException {
    final User user = this.base.user(new RqUser(req).urn());
    final Href href = new RqHref.Base(req).href();
    final Event event = user.events().event(href.param("title").iterator().next());
    final String hash = new XePrint(event.asXembly()).text("{/event/md5/text()}");
    if (!hash.equals(href.param("hash").iterator().next())) {
        throw new RsForward(new RsFlash("Reload the page, the event has changed", Level.WARNING));
    }
    final String msg = new XePrint(event.asXembly()).text("Event \"{/event/title/text()}\" deleted");
    event.delete();
    return new RsForward(new RsFlash(msg));
}
Also used : RqHref(org.takes.rq.RqHref) User(io.wring.model.User) RsFlash(org.takes.facets.flash.RsFlash) RqHref(org.takes.rq.RqHref) Href(org.takes.misc.Href) Event(io.wring.model.Event) XePrint(io.wring.model.XePrint) RsForward(org.takes.facets.forward.RsForward)

Example 4 with Event

use of io.wring.model.Event in project wring by yegor256.

the class TkEventDown method act.

@Override
public Response act(final Request req) throws IOException {
    final User user = this.base.user(new RqUser(req).urn());
    final Event event = user.events().event(new RqHref.Base(req).href().param("title").iterator().next());
    event.vote(-Tv.TEN);
    return new RsForward(new RsFlash("Event down-voted"));
}
Also used : RqHref(org.takes.rq.RqHref) User(io.wring.model.User) RsFlash(org.takes.facets.flash.RsFlash) Event(io.wring.model.Event) RsForward(org.takes.facets.forward.RsForward)

Example 5 with Event

use of io.wring.model.Event in project wring by yegor256.

the class BoostEventsTest method passesEventsThroughByJsonConfig.

/**
 * IgnoreEvents can filter out events.
 * @throws Exception If some problem inside
 */
@Test
public void passesEventsThroughByJsonConfig() throws Exception {
    final Events events = Mockito.mock(Events.class);
    final Event event = Mockito.mock(Event.class);
    Mockito.doReturn(event).when(events).event(Mockito.anyString());
    new BoostEvents(events, Json.createReader(new InputStreamOf("{}")).readObject()).post("the title", "the body");
    Mockito.verify(event, Mockito.never()).vote(Mockito.anyInt());
}
Also used : Events(io.wring.model.Events) Event(io.wring.model.Event) InputStreamOf(org.cactoos.io.InputStreamOf) Test(org.junit.Test)

Aggregations

Event (io.wring.model.Event)7 Events (io.wring.model.Events)5 Test (org.junit.Test)5 User (io.wring.model.User)4 RsFlash (org.takes.facets.flash.RsFlash)2 RsForward (org.takes.facets.forward.RsForward)2 RqHref (org.takes.rq.RqHref)2 XePrint (io.wring.model.XePrint)1 InputStreamOf (org.cactoos.io.InputStreamOf)1 Href (org.takes.misc.Href)1 Xembler (org.xembly.Xembler)1