use of com.mvp4g.rebind.config.element.ServiceElement in project mvp4g by mvp4g.
the class AbstractMvp4gAnnotationsWithServiceLoaderTest method testServices.
@Test
public void testServices() throws Mvp4gAnnotationException {
List<JClassType> annotedClasses = new ArrayList<JClassType>();
JClassType type = oracle.addClass(getService());
annotedClasses.add(type);
loader.load(annotedClasses, configuration);
Set<Mvp4gWithServicesElement> elements = getSet();
String serviceClass = SimpleService.class.getCanonicalName();
String serviceName = serviceClass.replace('.', '_');
List<InjectedElement> injectedServices = elements.iterator().next().getInjectedServices();
InjectedElement injectedService = injectedServices.get(0);
assertEquals(injectedServices.size(), 1);
assertEquals(injectedService.getSetterName(), "setSthg");
assertEquals(injectedService.getElementName(), serviceName + "Async");
Set<ServiceElement> services = configuration.getServices();
assertEquals(services.size(), 1);
ServiceElement service = services.iterator().next();
assertEquals(service.getName(), serviceName + "Async");
assertEquals(service.getClassName(), serviceClass);
annotedClasses.clear();
type = oracle.addClass(getSameService());
annotedClasses.add(type);
loader.load(annotedClasses, configuration);
assertEquals(services.size(), 1);
ServiceElement service2 = services.iterator().next();
assertSame(service, service2);
}
use of com.mvp4g.rebind.config.element.ServiceElement in project mvp4g by mvp4g.
the class Mvp4gConfigurationTest method testInjectedServiceRemove.
@Test
public void testInjectedServiceRemove() throws UnknownConfigurationElementException {
ServiceElement service1 = newService("service1");
ServiceElement service2 = newService("service2");
ServiceElement service3 = newService("service3");
ServiceElement service4 = newService("service4");
services.add(service1);
services.add(service2);
services.add(service3);
services.add(service4);
PresenterElement presenter = newPresenter(SimplePresenter01.class, "testPresenter");
presenter.getInjectedServices().add(new InjectedElement("service1", "setTestService"));
presenters.add(presenter);
HistoryConverterElement historyConverter = newHistoryConverter(SimpleHistoryConverter01.class, "testHistoryConverter");
historyConverter.getInjectedServices().add(new InjectedElement("service2", "setTestService"));
historyConverters.add(historyConverter);
EventHandlerElement eventHandlerElement = newEventHandler(SimpleEventHandler01.class, "testEventHandler");
eventHandlerElement.getInjectedServices().add(new InjectedElement("service3", "setTestService"));
eventHandlers.add(eventHandlerElement);
assertEquals(services.size(), 4);
assertTrue(services.contains(service1));
assertTrue(services.contains(service2));
assertTrue(services.contains(service3));
assertTrue(services.contains(service4));
configuration.validateServices();
assertEquals(services.size(), 3);
assertTrue(services.contains(service1));
assertTrue(services.contains(service2));
assertTrue(services.contains(service3));
assertFalse(services.contains(service4));
}
use of com.mvp4g.rebind.config.element.ServiceElement in project mvp4g by mvp4g.
the class Mvp4gAnnotationsWithServiceLoader method getServiceName.
/**
* Retrieve the name of service element with the given service class name. If no service with
* the given class name is found, create one.
*
* @param configuration
* configuration containing loaded elements of the application
* @param generatedClassName
* class name of the service element
*
* @return name of the service element (either found or create)
*/
private String getServiceName(Mvp4gConfiguration configuration, String generatedClassName) {
String serviceName = null;
for (ServiceElement service : configuration.getServices()) {
if (generatedClassName.equals(service.getGeneratedClassName())) {
serviceName = service.getName();
break;
}
}
if (serviceName == null) {
serviceName = generatedClassName.replace('.', '_');
ServiceElement service = new ServiceElement();
service.setClassName(generatedClassName.substring(0, generatedClassName.indexOf("Async")));
service.setName(serviceName);
configuration.getServices().add(service);
}
return serviceName;
}
use of com.mvp4g.rebind.config.element.ServiceElement in project mvp4g by mvp4g.
the class ServiceAnnotationsLoader method loadElement.
/*
* (non-Javadoc)
*
* @see com.mvp4g.rebind.config.loader.annotation.Mvp4gAnnotationsLoader#loadElement
* (com.google.gwt.core.ext.typeinfo.JClassType, java.lang.annotation.Annotation,
* com.mvp4g.rebind.config.Mvp4gConfiguration)
*/
@Override
protected void loadElement(JClassType c, Service annotation, Mvp4gConfiguration configuration) throws Mvp4gAnnotationException {
String className = c.getQualifiedSourceName();
String serviceName = buildElementNameIfNeeded(annotation.name(), className, "");
String path = annotation.path();
Class<?> generatedClass = annotation.generatedClass();
ServiceElement service = new ServiceElement();
service.setName(serviceName);
service.setClassName(className);
if ((path != null) && (path.length() > 0)) {
service.setPath(annotation.path());
}
if (!Void.class.equals(generatedClass)) {
service.setGeneratedClassName(generatedClass.getCanonicalName());
}
addElement(configuration.getServices(), service, c, null);
}
use of com.mvp4g.rebind.config.element.ServiceElement in project mvp4g by mvp4g.
the class Mvp4gConfigurationTest method newService.
private ServiceElement newService(String name) {
ServiceElement service = new ServiceElement();
service.setName(name);
return service;
}
Aggregations