org.tentackle.fx.rdc.junit.GuiProviderTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tentackle-test-fx-rdc Show documentation
Show all versions of tentackle-test-fx-rdc Show documentation
Test depdendency to support writing FX-RDC-based tests.
This artifact must be included in test-scope only!
The newest version!
/*
* Tentackle - https://tentackle.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.tentackle.fx.rdc.junit;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.platform.commons.logging.Logger;
import org.junit.platform.commons.logging.LoggerFactory;
import org.tentackle.common.Version;
import org.tentackle.fx.rdc.GuiProvider;
import org.tentackle.fx.rdc.GuiProviderFactory;
import org.tentackle.fx.rdc.GuiProviderService;
import org.tentackle.pdo.PdoFactory;
import org.tentackle.pdo.PdoRuntimeException;
import org.tentackle.pdo.PersistentDomainObject;
import org.tentackle.reflect.ClassMapper;
/**
* Junit5 test to verify that all GUI-providers can be loaded and bound.
* Opens a session in case some providers need it.
* Simply extend this class and put that in a test source folder.
*
* Example:
*
public class TestGuiProviders extends GuiProviderTest {
TestGuiProviders() {
super("my.package.name");
}
}
*
* @author harald
*/
public abstract class GuiProviderTest extends FxRdcTestApplication {
private static final Logger LOGGER = LoggerFactory.getLogger(GuiProviderTest.class);
private final String packagePrefix;
private final ClassMapper classMapper;
/**
* Creates the GUI provider test.
*
* @param packagePrefix optional package prefix, null or empty if all
*/
public GuiProviderTest(String packagePrefix) {
super("fx-rdc-provider-test", Version.RELEASE);
this.packagePrefix = packagePrefix;
classMapper = ClassMapper.create(getName(), GuiProvider.class);
}
public GuiProviderTest() {
this(null);
}
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testGuiProviders() {
for (String pdoClassName : classMapper.getMap().keySet()) {
PersistentDomainObject pdo = PdoFactory.getInstance().create(pdoClassName, getDomainContext());
try {
GuiProvider provider = GuiProviderFactory.getInstance().createGuiProvider(pdo);
if (packagePrefix == null || provider.getClass().getName().startsWith(packagePrefix)) {
GuiProviderService anno = provider.getClass().getAnnotation(GuiProviderService.class);
if (anno == null || anno.test()) {
LOGGER.info(() -> "testing gui provider " + provider.getClass().getName());
if (provider.isEditorAvailable()) {
provider.createEditor();
}
if (provider.isFinderAvailable()) {
provider.createFinder();
}
provider.createGraphic();
provider.createTableView();
provider.createTreeItem();
}
else {
LOGGER.info(() -> "gui provider " + provider.getClass().getName() + " not tested!");
}
}
}
catch (PdoRuntimeException nx) {
if (!(nx.getCause() instanceof ClassNotFoundException)) {
Assertions.fail("creating GuiProvider for " + pdo.getClassBaseName() + " failed", nx);
}
else {
LOGGER.info(() -> "no GuiProvider for " + pdo.getClassBaseName());
}
}
catch (RuntimeException ex) {
Assertions.fail("testing GuiProvider for " + pdo.getClassBaseName() + " failed", ex);
}
}
}
}