Search in sources :

Example 11 with InvalidMvp4gConfigurationException

use of com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException in project mvp4g by mvp4g.

the class Mvp4gConfigurationTest method testRootModuleWithHistoryName.

@Test
public void testRootModuleWithHistoryName() {
    configuration.setModule(oracle.addClass(Modules.ModuleWithParent01.class));
    EventBusElement eventBus = new EventBusElement(EventBusOk.class.getName(), BaseEventBus.class.getName(), false);
    configuration.setEventBus(eventBus);
    assertTrue(configuration.isRootModule());
    try {
        configuration.loadParentModule();
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertEquals("Module " + Modules.ModuleWithParent01.class.getCanonicalName() + " can't have an history name since it's a root module.", e.getMessage());
    }
}
Also used : InvalidMvp4gConfigurationException(com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException) Modules(com.mvp4g.rebind.test_tools.Modules) EventBusOk(com.mvp4g.rebind.test_tools.annotation.events.EventBusOk) EventBusElement(com.mvp4g.rebind.config.element.EventBusElement) BaseEventBus(com.mvp4g.client.event.BaseEventBus) Test(org.junit.Test)

Example 12 with InvalidMvp4gConfigurationException

use of com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException 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 13 with InvalidMvp4gConfigurationException

use of com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException in project mvp4g by mvp4g.

the class Mvp4gConfigurationTest method testGinWithProperties.

@Test
public void testGinWithProperties() throws InvalidMvp4gConfigurationException {
    String[] propertiesValues;
    GinModuleElement gin = new GinModuleElement();
    oracle.addClass(DefaultMvp4gGinModule.class);
    gin.setModules(new String[] { DefaultMvp4gGinModule.class.getCanonicalName() });
    gin.setModuleProperties(new String[] { PropertyOracleStub.PROPERTY_OK });
    configuration.setGinModule(gin);
    propertiesValues = configuration.validateGinModule();
    assertEquals(gin.getModules().size(), 2);
    assertEquals(gin.getModules().get(0), DefaultMvp4gGinModule.class.getCanonicalName());
    assertEquals(gin.getModules().get(1), DefaultMvp4gGinModule.class.getCanonicalName());
    assertEquals(1, propertiesValues.length);
    assertEquals(DefaultMvp4gGinModule.class.getCanonicalName(), propertiesValues[0]);
    gin = new GinModuleElement();
    oracle.addClass(OneGinModule.class);
    gin.setModules(new String[] { DefaultMvp4gGinModule.class.getCanonicalName() });
    gin.setModuleProperties(new String[] { PropertyOracleStub.PROPERTY_OK, PropertyOracleStub.PROPERTY_OK2 });
    configuration.setGinModule(gin);
    propertiesValues = configuration.validateGinModule();
    assertEquals(gin.getModules().size(), 3);
    assertEquals(gin.getModules().get(0), DefaultMvp4gGinModule.class.getCanonicalName());
    assertEquals(gin.getModules().get(1), DefaultMvp4gGinModule.class.getCanonicalName());
    assertEquals(gin.getModules().get(2), OneGinModule.class.getCanonicalName());
    assertEquals(2, propertiesValues.length);
    assertEquals(DefaultMvp4gGinModule.class.getCanonicalName(), propertiesValues[0]);
    assertEquals(OneGinModule.class.getCanonicalName(), propertiesValues[1]);
    gin = new GinModuleElement();
    gin.setModuleProperties(new String[] { "unknown" });
    configuration.setGinModule(gin);
    try {
        configuration.validateGinModule();
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertTrue(e.getMessage().contains("couldn't find a value for the GIN module property unknown"));
    }
    gin = new GinModuleElement();
    oracle.addClass(String.class);
    gin.setModuleProperties(new String[] { PropertyOracleStub.PROPERTY_NOT_GIN_MODULE });
    configuration.setGinModule(gin);
    try {
        configuration.validateGinModule();
        fail();
    } catch (InvalidTypeException e) {
        assertTrue(e.getMessage().contains(GinModule.class.getCanonicalName()));
    }
}
Also used : GinModuleElement(com.mvp4g.rebind.config.element.GinModuleElement) InvalidMvp4gConfigurationException(com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException) OneGinModule(com.mvp4g.rebind.test_tools.annotation.gin.OneGinModule) DefaultMvp4gGinModule(com.mvp4g.client.DefaultMvp4gGinModule) OneGinModule(com.mvp4g.rebind.test_tools.annotation.gin.OneGinModule) DefaultMvp4gGinModule(com.mvp4g.client.DefaultMvp4gGinModule) GinModule(com.google.gwt.inject.client.GinModule) InvalidTypeException(com.mvp4g.rebind.exception.InvalidTypeException) Test(org.junit.Test)

Example 14 with InvalidMvp4gConfigurationException

use of com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException in project mvp4g by mvp4g.

the class Mvp4gConfigurationTest method testChildViewLoadEvent.

@Test
public void testChildViewLoadEvent() throws InvalidMvp4gConfigurationException {
    ChildModuleElement childModule = newChildModule(Modules.ChildModule01.class, "child");
    childModule.setEventToDisplayView("testEvent");
    configuration.getOthersEventBusClassMap().put(Modules.ChildModule01.class.getCanonicalName(), oracle.addClass(EventBusOk.class));
    childModules.add(childModule);
    EventElement event = newEvent("testEvent");
    event.setForwardToModules(new String[] { "child" });
    event.setEventObjectClass(new String[] { String.class.getCanonicalName() });
    events.add(event);
    setEventBus();
    configuration.setModule(oracle.addClass(Modules.ModuleWithParent01.class));
    try {
        configuration.validateChildModules();
        fail();
    } catch (InvalidMvp4gConfigurationException e) {
        assertEquals(e.getMessage(), String.format("Child Module %s: event %s can not load child module's start view. Can not convert %s to %s.", childModule.getClassName(), "testEvent", SimpleView.class.getCanonicalName(), String.class.getCanonicalName()));
    }
    event = newEvent("testEvent");
    event.setForwardToModules(new String[] { "child" });
    event.setEventObjectClass(new String[] { Object.class.getCanonicalName() });
    events.clear();
    events.add(event);
    configuration.validateChildModules();
}
Also used : EventElement(com.mvp4g.rebind.config.element.EventElement) InvalidMvp4gConfigurationException(com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException) Modules(com.mvp4g.rebind.test_tools.Modules) EventBusOk(com.mvp4g.rebind.test_tools.annotation.events.EventBusOk) SimpleView(com.mvp4g.rebind.test_tools.annotation.views.SimpleView) OneObject(com.mvp4g.rebind.test_tools.OneObject) ChildModuleElement(com.mvp4g.rebind.config.element.ChildModuleElement) Test(org.junit.Test)

Example 15 with InvalidMvp4gConfigurationException

use of com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException in project mvp4g by mvp4g.

the class Mvp4gConfigurationTest method testStartEventWithParameter.

@Test
public void testStartEventWithParameter() throws InvalidMvp4gConfigurationException {
    EventElement e = newEvent("start");
    e.setEventObjectClass(new String[] { Object.class.getCanonicalName() });
    events.add(e);
    StartElement start = configuration.getStart();
    start.setPresenter("startPresenter");
    start.setEventType("start");
    try {
        configuration.validateStart();
        fail();
    } catch (InvalidMvp4gConfigurationException ex) {
        assertEquals("Start: Start event start can't have any object associated with it.", ex.getMessage());
    }
    events.clear();
    e = newEvent("start");
    events.add(e);
    configuration.validateStart();
}
Also used : StartElement(com.mvp4g.rebind.config.element.StartElement) EventElement(com.mvp4g.rebind.config.element.EventElement) InvalidMvp4gConfigurationException(com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException) OneObject(com.mvp4g.rebind.test_tools.OneObject) Test(org.junit.Test)

Aggregations

InvalidMvp4gConfigurationException (com.mvp4g.rebind.exception.InvalidMvp4gConfigurationException)27 Test (org.junit.Test)26 EventElement (com.mvp4g.rebind.config.element.EventElement)18 OneObject (com.mvp4g.rebind.test_tools.OneObject)11 Modules (com.mvp4g.rebind.test_tools.Modules)9 ChildModuleElement (com.mvp4g.rebind.config.element.ChildModuleElement)5 JClassType (com.google.gwt.core.ext.typeinfo.JClassType)3 GinModule (com.google.gwt.inject.client.GinModule)3 DefaultMvp4gGinModule (com.mvp4g.client.DefaultMvp4gGinModule)3 BaseEventBus (com.mvp4g.client.event.BaseEventBus)3 EventBusElement (com.mvp4g.rebind.config.element.EventBusElement)3 GinModuleElement (com.mvp4g.rebind.config.element.GinModuleElement)3 PresenterElement (com.mvp4g.rebind.config.element.PresenterElement)3 StartElement (com.mvp4g.rebind.config.element.StartElement)3 InvalidTypeException (com.mvp4g.rebind.exception.InvalidTypeException)3 EventBusOk (com.mvp4g.rebind.test_tools.annotation.events.EventBusOk)3 OneGinModule (com.mvp4g.rebind.test_tools.annotation.gin.OneGinModule)3 EventBusWithLookup (com.mvp4g.client.event.EventBusWithLookup)2 HistoryConverterElement (com.mvp4g.rebind.config.element.HistoryConverterElement)2 ViewElement (com.mvp4g.rebind.config.element.ViewElement)2