Build a Test which checks that databinding service process between editors.

Main aim of this test is to check the good running of databinding service:


Create the Test class

Create java class MyFirstTest.java in package org.mycompany.myproject.testing.

package org.mycompany.myproject.testing;

import org.adichatz.engine.controller.collection.SectionController;
import org.adichatz.engine.controller.collection.TabularController;
import org.adichatz.engine.controller.nebula.PGroupController;
import org.adichatz.engine.e4.part.BoundedPart;
import org.adichatz.engine.e4.part.PartCore;
import org.adichatz.engine.e4.resource.E4SimulationTools;
import org.adichatz.engine.plugin.ParamMap;
import org.adichatz.engine.simulation.SimulationTools;
import org.adichatz.jpa.extra.JPAUtil;
import org.adichatz.testing.AdiAssert;
import org.adichatz.testing.TestingTools;
import org.eclipse.swt.widgets.Display;
import org.testng.Assert;
import org.testng.annotations.Test;

public class FilmActorBindingTest {
	@Test(priority = 1)
	public void relationshipDatabinding() {
		// Select Option queriesMenus/filmQuery in navigator "groupNavigator" and return a part.
		BoundedPart filmQueryPart = E4SimulationTools.handleNavigatorOpenPartItem("groupNavigator", "queriesMenu", "filmQUERY");
		// check that part is active.
		AdiAssert.isPartActive(filmQueryPart);
		TestingTools.testInfo("QueryForm with query 'filmQUERY' is active.");

		PartCore filmQueryCore = filmQueryPart.getGenCode();
		// Launch query in filmQuery part.
		SimulationTools.handleContextMenuAction(filmQueryCore, "tableCM:contextMenu", "launchQueryAction");

		// Select "Film 1" in tabular controller "tableInclude:table".
		SimulationTools.handleSelectBeanInTableViewer(filmQueryCore, "tableInclude:table", (short) 1);
		// check that one row in selected in tabular controller "tableInclude:table".
		AdiAssert.hasSelection(SimulationTools.getController(filmQueryCore, "tableInclude:table", TabularController.class));

		// Open editor for "Film 1"
		SimulationTools.handleContextMenuAction(filmQueryCore, "tableCM:contextMenu", "editEntityAction");

		// Check that an editor with following input parameters exists and is active.
		String[][] film1Params = new String[][] { { ParamMap.TITLE, "Film 1" },
				{ ParamMap.CONTRIBUTION_URI, JPAUtil.ENTITY_EDITOR_CONTRIBUTION_URI }, //
				{ ParamMap.ADI_RESOURCE_URI, "adi://myproject/model.film/FilmEDITOR" } //
		};
		BoundedPart film1Part = E4SimulationTools.handleEditorPart(film1Params);
		Assert.assertNotNull(film1Part, "Do not find Editor for 'Film 1'");
		AdiAssert.isPartActive(film1Part);
		TestingTools.testInfo("Editor for 'Film 1' is open and active.");

		// In Navigation item of outline page, select 'actorItem' item in 'DependenciesTabFolder' CTabFolder of 'Dependencies' page.
		E4SimulationTools.handleNavigationPart(film1Part.getGenCode(), "Dependencies, DependenciesTabFolder, actorsItem");

		// Select "Actor 1" in tabular controller "actorsTSI:table".
		SimulationTools.handleSelectBeanInTableViewer(film1Part.getGenCode(), "actorsTSI:table", (short) 1);
		// check that one row in selected in tabular controller "tableInclude:table".
		AdiAssert.hasSelection(SimulationTools.getController(film1Part.getGenCode(), "actorsTSI:table", TabularController.class));
		// double-click on row "Actor 1" (open or make active an editor for selected row).
		SimulationTools.handleDoubleClick(film1Part.getGenCode(), "actorsTSI:table");

		// Check that an editor with following input parameters exists and is active.
		String[][] actor1Params = new String[][] { { ParamMap.TITLE, "Actor 1" },
				{ ParamMap.CONTRIBUTION_URI, JPAUtil.ENTITY_EDITOR_CONTRIBUTION_URI }, //
				{ ParamMap.ADI_RESOURCE_URI, "adi://myproject/model.actor/ActorEDITOR" } //
		};
		BoundedPart actor1Part = E4SimulationTools.handleEditorPart(actor1Params);
		Assert.assertNotNull(actor1Part, "Do not find Editor for 'Actor 1'");
		AdiAssert.isPartActive(actor1Part);
		TestingTools.testInfo("Editor for 'Actor 1' is open and active.");

		// Select page "Dependencies" in current editor ("Actor 1").
		E4SimulationTools.handlePage(actor1Part, "Dependencies");

		// In 'Film 1' editor, check if value hosted by 'filmDetail:active' CheckController is 'false'.
		AdiAssert.assertTrue("'active' field in 'Film 1' editor is not 'true'",
				((boolean) SimulationTools.handleGetValueForFieldController(film1Part.getGenCode(), "filmDetail:active")));

		// In 'Film 1' editor, check if control of 'filmDetail:activeGroup' PGroupController is not disposed.
		AdiAssert.assertTrue("'activeGroup' PGroup is disposed in 'Film 1' editor",
				!SimulationTools.getController(film1Part.getGenCode(), "filmDetail:activeGroup", PGroupController.class)
						.getControl().isDisposed());

		// Select "Film 1" in tabular controller "filmsTSI:table".
		SimulationTools.handleSelectBeanInTableViewer(actor1Part.getGenCode(), "filmsTSI:table", (short) 1);

		// Change value for "filmsDIPart:active" FieldController (set active = false simulate a user action on check button)
		// This change must dispose 'filmDetail:activeGroup' Group controller.
		// Changes must be broadcasted in 'film1Part' editor.
		SimulationTools.handleSetValueForFieldController(actor1Part.getGenCode(), "filmsDIPart:active", false);

		// In 'Film 1' editor, check if value hosted by 'filmDetail:active' CheckController is 'false'.
		AdiAssert.assertTrue("'active' field in 'Film 1' editor is not false",
				!((boolean) SimulationTools.handleGetValueForFieldController(film1Part.getGenCode(), "filmDetail:active")));

		// In 'Film 1' editor, check if control of 'filmDetail:activeGroup' PGroupController is disposed.
		AdiAssert.assertTrue("'activeGroup' PGroup is not disposed in 'Film 1' editor",
				SimulationTools.getController(film1Part.getGenCode(), "filmDetail:activeGroup", PGroupController.class)
						.getControl().isDisposed());

		// Check if field controllers in <wrap adicode>filmDetail:detailContainer</wrap> SectionController are locks.
		AdiAssert.isLocked(SimulationTools.getController(film1Part.getGenCode(), "filmDetail:detailContainer",
				SectionController.class));

		// Process all deferred layouts before ending test
		// here, display actor editor after executing all layouts. Otherwise 'Actor 1' editor is closed without displaying controls.
		Display.getCurrent().readAndDispatch();
		// Wait 2 seconds
		SimulationTools.sleep(2000);
		// Refresh change on editor 'Actor 1'.
		E4SimulationTools.doRefresh(actor1Part.getGenCode(), false);
		// Close all editors
		E4SimulationTools.closeAll();
	}
}

Explanations:

  • line 22: Open a Query Editor for the FilmQUERY query using naviator item.
  • line 29: Launch the Query from context menu.
  • line 32: Select row Film 1 in tableInclude:table.
  • line 37: Select editEntityAction option in context menu on select row (opens an Entity editor).
  • line 50: Film 1 editor is active, in Navigation item of outline page, select actorItem item.
  • line 53: Select row Actor 1 in tabular controller actorsTSI:table.
  • line 57: Double-click on row Actor 1 (open or make active an editor for selected row).
  • line 70: Actor 1 editor is active, Select Dependencies page.

Tests before changing value for filmsDIPart:active FieldController.

  • line 73: In Film 1 editor, check if value hosted by filmDetail:active CheckController is false.
  • line 77: In Film 1 editor, check if control of filmDetail:activeGroup PGroupController is disposed.

Change.

  • line 82: Select row Film 1 in filmsTSI:table.
  • line 87: Change value for filmsDIPart:active FieldController (set active = false simulate a user action on check button)

Tests after changing value for filmsDIPart:active FieldController.

  • line 90: In Film 1 editor, check if value hosted by filmDetail:active CheckController is false.
  • line 94: In Film 1 editor, check if control of filmDetail:activeGroup PGroupController is disposed.
  • line 99: Check if field controllers in filmDetail:detailContainer SectionController are locks.

Display and close edtors

  • line 104: Ends layouts process in Actor 1 editor (otherwise nothing is visible).
  • line 106: Refresh (cancel) cupdated entities in Actor 1 editor.
  • line 110: Close all editors.



Create a intended bug

Use example: extend a ccombo contorller for 'rating' property.
Add a bug in the new controller named org.mycompany.myProject.gencode.custom.RatingCComboController as shown:

package org.mycompany.myproject.gencode.custom;

import org.adichatz.engine.controller.IContainerController;
import org.adichatz.engine.controller.field.CComboController;
import org.adichatz.engine.core.ControllerCore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Display;

public class RatingCComboController extends CComboController {

	public RatingCComboController(String id, IContainerController parentController, ControllerCore genCode) {
		super(id, parentController, genCode);
	}

	@Override
	public void createControl() {
		super.createControl();
		getCCombo().addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				setRatingBackGroundColor();
			}
		});
	}

	@Override
	public void setValue(Object value) {
		super.setValue(value);
		setRatingBackGroundColor();
	}

	private void setRatingBackGroundColor() {
		if ("NC-17".equals(getValue()))
			getCCombo().setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
		else if ("R".equals(getValue()))
			getCCombo().setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW));
		else
			getCCombo().setBackground(null);
	}

	@Override
	public void lockEntity(boolean locked) {
		// BUG : this method must be deleted
	}
}

Lines 43-46: This intended bug is just as example.



Step 3: Add entry to 'AdichatzRcpCongif.xml' file

You need to add an simple entry in file $projectDirectory/resources/xml/AdichatzRcpConfig.xml as shown below:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <testing expanded="true">
        <suite id="myFirstSuite" label="Suite example" launchOnStartup="false" expanded="true">
            <test id="myFirstTest" label="my first test" testURI="bundleclass://myproject/org.mycompany.myproject.testing.MyFirstTest"/>
            <test id="filmActorTest" label="Film/Actor databinding test" testURI="bundleclass://myproject/org.mycompany.myproject.testing.FilmActorBindingTest" expanded="true"/>
        </suite>
    </testing>

Lines 19: Add this line in AdichatzRcpConfig.xml, relaunch application or Refresh testing menu in application: The new item is available.



Step 4: Execute and reexecute tests

Execute the test

To execute the test: click on the corresponding item (Film Actor databinding test).

  • Test fails, at line 98.
  • Close all editor and delete method lockEntity of class RatingCComboController.
  • Rexecute test: Click on item Film Actor databinding test.
  • Test is sucessfull, All editors are closed.