Search in sources :

Example 16 with Mvp4gAnnotationException

use of com.mvp4g.rebind.exception.loader.Mvp4gAnnotationException in project mvp4g by mvp4g.

the class AbstractMvp4gAnnotationLoaderTest method testSameElementTwice.

@Test(expected = Mvp4gAnnotationException.class)
public void testSameElementTwice() throws Mvp4gAnnotationException {
    try {
        List<JClassType> annotedClasses = new ArrayList<JClassType>();
        JClassType type = oracle.addClass(getSimpleClass());
        annotedClasses.add(type);
        annotedClasses.add(type);
        loader.load(annotedClasses, configuration);
    } catch (Mvp4gAnnotationException e) {
        assertTrue(e.getMessage().contains("Duplicate"));
        throw e;
    }
}
Also used : JClassType(com.google.gwt.core.ext.typeinfo.JClassType) ArrayList(java.util.ArrayList) Mvp4gAnnotationException(com.mvp4g.rebind.exception.loader.Mvp4gAnnotationException) Test(org.junit.Test)

Example 17 with Mvp4gAnnotationException

use of com.mvp4g.rebind.exception.loader.Mvp4gAnnotationException in project mvp4g by mvp4g.

the class EventsAnnotationsLoader method loadHistory.

/**
 * Build history converter of an event. If the converter class name is given, first it tries to
 * find an instance of this class, and if none is found, create one.
 *
 * @param c             annoted class
 * @param method        method that defines the event
 * @param annotation    Event annotation
 * @param element       Event element
 * @param configuration configuration containing loaded elements of the application
 * @throws Mvp4gAnnotationException
 */
private void loadHistory(JClassType c, JMethod method, Event annotation, EventElement element, Mvp4gConfiguration configuration) throws Mvp4gAnnotationException {
    String hcName = annotation.historyConverterName();
    Class<?> hcClass = annotation.historyConverter();
    if ((hcName != null) && (hcName.length() > 0)) {
        element.setHistory(hcName);
    } else if (!Event.NoHistoryConverter.class.equals(hcClass)) {
        String hcClassName = hcClass.getCanonicalName();
        Set<HistoryConverterElement> historyConverters = configuration.getHistoryConverters();
        hcName = getElementName(historyConverters, hcClassName);
        if (hcName == null) {
            String err = "No instance of " + hcClassName + " is defined. Have you forgotten to annotate your history converter with @History?";
            throw new Mvp4gAnnotationException(c.getQualifiedSourceName(), method.getName(), err);
        }
        element.setHistory(hcName);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Mvp4gAnnotationException(com.mvp4g.rebind.exception.loader.Mvp4gAnnotationException)

Example 18 with Mvp4gAnnotationException

use of com.mvp4g.rebind.exception.loader.Mvp4gAnnotationException in project mvp4g by mvp4g.

the class AbstractMvp4gAnnotationsWithServiceLoaderTest method testWithNoParameter.

@Test(expected = Mvp4gAnnotationException.class)
public void testWithNoParameter() throws Mvp4gAnnotationException {
    try {
        List<JClassType> annotedClasses = new ArrayList<JClassType>();
        JClassType type = oracle.addClass(getClassWithNoParameter());
        annotedClasses.add(type);
        loader.load(annotedClasses, configuration);
    } catch (Mvp4gAnnotationException e) {
        assertTrue(e.getMessage().contains("Only setter method with one parameter can be used to inject a service"));
        throw e;
    }
}
Also used : JClassType(com.google.gwt.core.ext.typeinfo.JClassType) ArrayList(java.util.ArrayList) Mvp4gAnnotationException(com.mvp4g.rebind.exception.loader.Mvp4gAnnotationException) Test(org.junit.Test)

Example 19 with Mvp4gAnnotationException

use of com.mvp4g.rebind.exception.loader.Mvp4gAnnotationException in project mvp4g by mvp4g.

the class AbstractMvp4gAnnotationsWithServiceLoaderTest method testWithMoreThanOneParameter.

@Test(expected = Mvp4gAnnotationException.class)
public void testWithMoreThanOneParameter() throws Mvp4gAnnotationException {
    try {
        List<JClassType> annotedClasses = new ArrayList<JClassType>();
        JClassType type = oracle.addClass(getClassWithMoreThanOne());
        annotedClasses.add(type);
        loader.load(annotedClasses, configuration);
    } catch (Mvp4gAnnotationException e) {
        assertTrue(e.getMessage().contains("Only setter method with one parameter can be used to inject a service"));
        throw e;
    }
}
Also used : JClassType(com.google.gwt.core.ext.typeinfo.JClassType) ArrayList(java.util.ArrayList) Mvp4gAnnotationException(com.mvp4g.rebind.exception.loader.Mvp4gAnnotationException) Test(org.junit.Test)

Example 20 with Mvp4gAnnotationException

use of com.mvp4g.rebind.exception.loader.Mvp4gAnnotationException in project mvp4g by mvp4g.

the class EventsAnnotationsLoaderTest method testSameModuleForLoadModuleViewEvent.

@Test(expected = Mvp4gAnnotationException.class)
public void testSameModuleForLoadModuleViewEvent() throws Mvp4gAnnotationException {
    try {
        List<JClassType> annotedClasses = new ArrayList<JClassType>();
        annotedClasses.add(oracle.addClass(PresenterWithName.class));
        new PresenterAnnotationsLoader().load(annotedClasses, configuration);
        annotedClasses.clear();
        JClassType type = oracle.addClass(Events.EventBusSameModuleForLoadModuleViewEvent.class);
        annotedClasses.add(type);
        loader.load(annotedClasses, configuration);
    } catch (Mvp4gAnnotationException e) {
        assertTrue(e.getMessage().contains("Module " + Modules.Module01.class.getCanonicalName() + ": you can't have two events to load this module view."));
        throw e;
    }
}
Also used : JClassType(com.google.gwt.core.ext.typeinfo.JClassType) PresenterWithName(com.mvp4g.rebind.test_tools.annotation.presenters.PresenterWithName) Events(com.mvp4g.rebind.test_tools.annotation.Events) Mvp4gAnnotationException(com.mvp4g.rebind.exception.loader.Mvp4gAnnotationException) Test(org.junit.Test)

Aggregations

Mvp4gAnnotationException (com.mvp4g.rebind.exception.loader.Mvp4gAnnotationException)29 JClassType (com.google.gwt.core.ext.typeinfo.JClassType)26 Test (org.junit.Test)25 Events (com.mvp4g.rebind.test_tools.annotation.Events)17 PresenterWithName (com.mvp4g.rebind.test_tools.annotation.presenters.PresenterWithName)12 ArrayList (java.util.ArrayList)5 JMethod (com.google.gwt.core.ext.typeinfo.JMethod)2 JParameter (com.google.gwt.core.ext.typeinfo.JParameter)2 SimplePresenter01 (com.mvp4g.rebind.test_tools.annotation.presenters.SimplePresenter01)2 TypeOracle (com.google.gwt.core.ext.typeinfo.TypeOracle)1 InjectService (com.mvp4g.client.annotation.InjectService)1 ChildModules (com.mvp4g.client.annotation.module.ChildModules)1 NoStartPresenter (com.mvp4g.client.presenter.NoStartPresenter)1 InjectedElement (com.mvp4g.rebind.config.element.InjectedElement)1 Mvp4gWithServicesElement (com.mvp4g.rebind.config.element.Mvp4gWithServicesElement)1 Modules (com.mvp4g.rebind.test_tools.Modules)1 EventHandlers (com.mvp4g.rebind.test_tools.annotation.EventHandlers)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1