Search in sources :

Example 6 with ViewElement

use of com.mvp4g.rebind.config.element.ViewElement in project mvp4g by mvp4g.

the class Mvp4gConfigurationTest method testEventHandlerWrongInterface.

@Test(expected = InvalidClassException.class)
public void testEventHandlerWrongInterface() throws InvalidMvp4gConfigurationException {
    ViewElement view = newView(SimpleView02.class, "view");
    views.add(view);
    PresenterElement presenter = new PresenterElement();
    presenter.setName("testHandler");
    presenter.setView("view");
    presenter.setClassName(Object.class.getName());
    presenters.add(presenter);
    EventElement event = newEvent("testEvent");
    event.setHandlers(new String[] { "testHandler" });
    events.add(event);
    setEventBus();
    configuration.validateEventHandlers();
}
Also used : EventElement(com.mvp4g.rebind.config.element.EventElement) OneObject(com.mvp4g.rebind.test_tools.OneObject) ViewElement(com.mvp4g.rebind.config.element.ViewElement) PresenterElement(com.mvp4g.rebind.config.element.PresenterElement) Test(org.junit.Test)

Example 7 with ViewElement

use of com.mvp4g.rebind.config.element.ViewElement in project mvp4g by mvp4g.

the class Mvp4gConfigurationTest method testGenerateNotMultiple.

@Test
public void testGenerateNotMultiple() throws InvalidMvp4gConfigurationException {
    EventBusElement eventBus = new EventBusElement(EventBusWithLookup.class.getName(), BaseEventBus.class.getName(), false);
    configuration.setEventBus(eventBus);
    EventElement event1 = newEvent("event1");
    event1.setHandlers(new String[] { "generate2" });
    event1.setGenerate(new String[] { "generate1", "generate2" });
    events.add(event1);
    ViewElement view = newView(SimpleView02.class, "view");
    view.setClassName(SimpleView02.class.getCanonicalName());
    views.add(view);
    PresenterElement generate1 = newPresenter(SimplePresenter01.class, "generate1");
    generate1.setView("view");
    EventHandlerElement generate2 = newEventHandler(SimpleEventHandler01.class, "generate2");
    presenters.add(generate1);
    try {
        configuration.validateEventHandlers();
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertTrue(e.getMessage().contains("Event event1: you can generate only multiple handlers. Did you forget to set the attribute multiple to true for generate1?"));
    }
    presenters.clear();
    eventHandlers.clear();
    eventHandlers.add(generate2);
    try {
        configuration.validateEventHandlers();
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertTrue(e.getMessage().contains("Event event1: you can generate only multiple handlers. Did you forget to set the attribute multiple to true for generate2?"));
    }
}
Also used : SimpleView02(com.mvp4g.rebind.test_tools.annotation.views.SimpleView02) EventElement(com.mvp4g.rebind.config.element.EventElement) InvalidMvp4gConfigurationException(com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException) EventBusElement(com.mvp4g.rebind.config.element.EventBusElement) EventBusWithLookup(com.mvp4g.client.event.EventBusWithLookup) BaseEventBus(com.mvp4g.client.event.BaseEventBus) EventHandlerElement(com.mvp4g.rebind.config.element.EventHandlerElement) ViewElement(com.mvp4g.rebind.config.element.ViewElement) PresenterElement(com.mvp4g.rebind.config.element.PresenterElement) Test(org.junit.Test)

Example 8 with ViewElement

use of com.mvp4g.rebind.config.element.ViewElement in project mvp4g by mvp4g.

the class Mvp4gConfigurationTest method testBroadcastHandlers.

@Test
public void testBroadcastHandlers() throws InvalidMvp4gConfigurationException {
    oracle.addClass(TestBroadcast.class);
    ViewElement view = newView(SimpleView01.class, "view");
    views.add(view);
    PresenterElement presenter = new PresenterElement();
    presenter.setName("presenter");
    Class<?> c = Presenters.BroadcastPresenter.class;
    presenter.setClassName(c.getCanonicalName());
    oracle.addClass(c);
    presenter.setView("view");
    presenters.add(presenter);
    PresenterElement presenter2 = new PresenterElement();
    presenter2.setName("presenter2");
    c = Presenters.BroadcastPresenter2.class;
    presenter2.setClassName(c.getCanonicalName());
    oracle.addClass(c);
    presenter2.setView("view");
    presenters.add(presenter2);
    PresenterElement presenter3 = new PresenterElement();
    presenter3.setName("presenter3");
    c = Presenters.BroadcastPresenter2.class;
    presenter3.setClassName(c.getCanonicalName());
    presenter3.setView("view");
    presenters.add(presenter3);
    EventElement event = newEvent("event");
    event.setBroadcastTo(TestBroadcast.class.getCanonicalName());
    event.setHandlers(new String[0]);
    events.add(event);
    EventElement event2 = newEvent("event2");
    event2.setBroadcastTo(TestBroadcast2.class.getCanonicalName());
    event2.setHandlers(new String[] { "presenter3" });
    events.add(event2);
    setEventBus();
    configuration.validateEventHandlers();
    List<String> handlers = event.getHandlers();
    assertEquals(3, handlers.size());
    assertEquals("presenter3", handlers.get(0));
    assertEquals("presenter2", handlers.get(1));
    assertEquals("presenter", handlers.get(2));
    handlers = event2.getHandlers();
    assertEquals(2, handlers.size());
    assertEquals("presenter3", handlers.get(0));
    assertEquals("presenter2", handlers.get(1));
}
Also used : TestBroadcast2(com.mvp4g.rebind.test_tools.annotation.TestBroadcast2) EventElement(com.mvp4g.rebind.config.element.EventElement) TestBroadcast(com.mvp4g.rebind.test_tools.annotation.TestBroadcast) Presenters(com.mvp4g.rebind.test_tools.annotation.Presenters) ViewElement(com.mvp4g.rebind.config.element.ViewElement) PresenterElement(com.mvp4g.rebind.config.element.PresenterElement) Test(org.junit.Test)

Example 9 with ViewElement

use of com.mvp4g.rebind.config.element.ViewElement in project mvp4g by mvp4g.

the class Mvp4gConfigurationTest method testEventBindsAnnotationRestriction.

@Test
public void testEventBindsAnnotationRestriction() throws InvalidMvp4gConfigurationException {
    // checking situation when handlers has the same attributes as binds
    EventElement event = newEvent("testEvent1");
    event.setHandlers(new String[] { "handler1", "handler2" });
    event.setBinds(new String[] { "hander3", "handler1" });
    events.add(event);
    setEventBus();
    try {
        configuration.validateEventHandlers();
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertTrue(e.getMessage().contains("Event testEvent1: the same handler handler1 is used in the bind and handlers attributes. If you need handler1 to handle this event, you should remove it from the bind attribute."));
    } finally {
        events.remove(event);
    }
    // checking situation when passive event has some binds
    EventElement event2 = newEvent("testEvent2");
    event2.setBinds(new String[] { "someHandler" });
    event2.setPassive("true");
    events.add(event2);
    try {
        configuration.validateEventHandlers();
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertTrue(e.getMessage().contains("Passive event can't bind any elements. Remove bind attribute from the testEvent2 event in order to keep it passive."));
    } finally {
        events.remove(event2);
    }
    // checking that combination with broadcastTo and passive event don't lead to exception
    PresenterElement presenter = newPresenter(SimplePresenter01.class, "testPresenter");
    presenter.setMultiple("true");
    presenter.setView("view");
    presenters.add(presenter);
    ViewElement view = newView(SimpleView01.class, "view");
    views.add(view);
    oracle.addClass(TestBroadcast.class);
    EventElement event3 = newEvent("testEvent3");
    event3.setPassive("true");
    event3.setBroadcastTo(TestBroadcast.class.getCanonicalName());
    event3.setGenerate(new String[] { "testPresenter" });
    events.add(event3);
    try {
        assertTrue(event3.isPassive());
        configuration.validateEventHandlers();
    } catch (InvalidMvp4gConfigurationException e) {
        assertTrue(e.getMessage().contains("Passive event can't have any binds elements. Remove bind annotation from the testEvent3 event in order to keep it passive"));
        fail();
    } finally {
        events.remove(event3);
        presenters.remove(presenter);
    }
}
Also used : EventElement(com.mvp4g.rebind.config.element.EventElement) TestBroadcast(com.mvp4g.rebind.test_tools.annotation.TestBroadcast) InvalidMvp4gConfigurationException(com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException) ViewElement(com.mvp4g.rebind.config.element.ViewElement) PresenterElement(com.mvp4g.rebind.config.element.PresenterElement) Test(org.junit.Test)

Example 10 with ViewElement

use of com.mvp4g.rebind.config.element.ViewElement in project mvp4g by mvp4g.

the class Mvp4gConfigurationTest method testEventHandlerRemove.

@Test
public void testEventHandlerRemove() throws InvalidMvp4gConfigurationException {
    ViewElement view = newView(SimpleView01.class, "view");
    views.add(view);
    PresenterElement presenter1 = newPresenter(SimplePresenter01.class, "presenter1");
    presenter1.setView("view");
    presenters.add(presenter1);
    PresenterElement presenter2 = newPresenter(SimplePresenter02.class, "presenter2");
    presenter2.setView("view");
    presenters.add(presenter2);
    PresenterElement presenter3 = newPresenter(SimplePresenter03.class, "presenter3");
    presenter3.setView("view");
    presenter3.setMultiple("true");
    presenters.add(presenter3);
    PresenterElement presenter4 = newPresenter(SimplePresenter04.class, "presenter4");
    presenter4.setView("view");
    presenters.add(presenter4);
    EventHandlerElement handler1 = newEventHandler(SimpleEventHandler01.class, "handler1");
    eventHandlers.add(handler1);
    EventHandlerElement handler2 = newEventHandler(SimpleEventHandler02.class, "handler2");
    eventHandlers.add(handler2);
    EventHandlerElement handler3 = newEventHandler(SimpleEventHandler03.class, "handler3");
    handler3.setMultiple("true");
    eventHandlers.add(handler3);
    EventHandlerElement handler4 = newEventHandler(SimpleEventHandler04.class, "handler4");
    eventHandlers.add(handler4);
    EventElement event = newEvent("testEvent");
    event.setHandlers(new String[] { "presenter1", "handler1" });
    event.setGenerate(new String[] { "presenter3", "handler3" });
    event.setBinds(new String[] { "presenter4", "handler4" });
    events.add(event);
    setEventBus();
    assertEquals(4, presenters.size());
    assertTrue(presenters.contains(presenter1));
    assertTrue(presenters.contains(presenter2));
    assertEquals(4, eventHandlers.size());
    assertTrue(eventHandlers.contains(handler1));
    assertTrue(eventHandlers.contains(handler2));
    configuration.validateEventHandlers();
    assertEquals(3, presenters.size());
    assertTrue(presenters.contains(presenter1));
    assertFalse(presenters.contains(presenter2));
    assertEquals(3, eventHandlers.size());
    assertTrue(eventHandlers.contains(handler1));
    assertFalse(eventHandlers.contains(handler2));
    presenter2.setMultiple(Boolean.TRUE.toString());
    presenters.add(presenter2);
    handler2.setMultiple(Boolean.TRUE.toString());
    eventHandlers.add(handler2);
    assertEquals(4, presenters.size());
    assertTrue(presenters.contains(presenter1));
    assertTrue(presenters.contains(presenter2));
    assertEquals(4, eventHandlers.size());
    assertTrue(eventHandlers.contains(handler1));
    assertTrue(eventHandlers.contains(handler2));
    configuration.validateEventHandlers();
    assertEquals(4, presenters.size());
    assertTrue(presenters.contains(presenter1));
    assertTrue(presenters.contains(presenter2));
    assertEquals(4, eventHandlers.size());
    assertTrue(eventHandlers.contains(handler1));
    assertTrue(eventHandlers.contains(handler2));
}
Also used : EventElement(com.mvp4g.rebind.config.element.EventElement) EventHandlerElement(com.mvp4g.rebind.config.element.EventHandlerElement) ViewElement(com.mvp4g.rebind.config.element.ViewElement) PresenterElement(com.mvp4g.rebind.config.element.PresenterElement) Test(org.junit.Test)

Aggregations

ViewElement (com.mvp4g.rebind.config.element.ViewElement)17 Test (org.junit.Test)15 PresenterElement (com.mvp4g.rebind.config.element.PresenterElement)14 EventElement (com.mvp4g.rebind.config.element.EventElement)12 EventHandlerElement (com.mvp4g.rebind.config.element.EventHandlerElement)4 Presenters (com.mvp4g.rebind.test_tools.annotation.Presenters)4 BaseEventBus (com.mvp4g.client.event.BaseEventBus)3 EventBusElement (com.mvp4g.rebind.config.element.EventBusElement)3 InvalidTypeException (com.mvp4g.rebind.exception.InvalidTypeException)3 JClassType (com.google.gwt.core.ext.typeinfo.JClassType)2 EventBusWithLookup (com.mvp4g.client.event.EventBusWithLookup)2 InvalidMvp4gConfigurationException (com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException)2 TestBroadcast (com.mvp4g.rebind.test_tools.annotation.TestBroadcast)2 SimpleView02 (com.mvp4g.rebind.test_tools.annotation.views.SimpleView02)2 ArrayList (java.util.ArrayList)2 EventBus (com.mvp4g.client.event.EventBus)1 OneObject (com.mvp4g.rebind.test_tools.OneObject)1 TestBroadcast2 (com.mvp4g.rebind.test_tools.annotation.TestBroadcast2)1 SimplePresenter01 (com.mvp4g.rebind.test_tools.annotation.presenters.SimplePresenter01)1 SimpleView03 (com.mvp4g.rebind.test_tools.annotation.views.SimpleView03)1