Differences
This shows you the differences between two versions of the page.
| — |
tutorial:testing_extensive [2020/04/16 10:56] (current) |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | <WRAP adihi><html><center></html>Build a Test which checks that <wrap adicode>databinding service</wrap> process between editors.<html></center></html> | ||
| + | \\ | ||
| + | Main aim of this test is to check the good running of <wrap adicode>databinding service</wrap>: | ||
| + | * Change on an entity in an editor is broadcasted on a second editor. | ||
| + | * Dynamic process on controllers is broadcasted between editors. | ||
| + | </WRAP> | ||
| + | \\ | ||
| + | === Create the Test class === | ||
| + | |||
| + | Create java class <wrap adicode>MyFirstTest.java</wrap> in package <wrap adicode>org.mycompany.myproject.testing</wrap>. | ||
| + | <sxh java; first-line: 1; highlight: [22, 29, 32, 37, 50, 53, 57, 70, 73, 74, 77, 78, 79, 82, 87, 90, 91, 94, 95, 96, 99, 100, 104, 106, 108, 110]; title: excerpt from 'MyFirstTest.java' class.> | ||
| + | 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(); | ||
| + | } | ||
| + | } | ||
| + | </sxh> | ||
| + | <WRAP indic> | ||
| + | **Explanations**: | ||
| + | * line <wrap adicode>22</wrap>: Open a <wrap adicode>Query Editor</wrap> for the <wrap adicode>FilmQUERY</wrap> query using naviator item. | ||
| + | * line <wrap adicode>29</wrap>: Launch the Query from context menu. | ||
| + | * line <wrap adicode>32</wrap>: Select row <wrap adicode>Film 1</wrap> in <wrap adicode>tableInclude:table</wrap>. | ||
| + | * line <wrap adicode>37</wrap>: Select <wrap adicode>editEntityAction</wrap> option in context menu on select row (opens an <wrap adicode>Entity editor</wrap>). | ||
| + | * line <wrap adicode>50</wrap>: <wrap adicode>Film 1</wrap> editor is active, in Navigation item of outline page, select <wrap adicode>actorItem</wrap> item. | ||
| + | * line <wrap adicode>53</wrap>: Select row <wrap adicode>Actor 1</wrap> in tabular controller <wrap adicode>actorsTSI:table</wrap>. | ||
| + | * line <wrap adicode>57</wrap>: Double-click on row <wrap adicode>Actor 1</wrap> (open or make active an editor for selected row). | ||
| + | * line <wrap adicode>70</wrap>: <wrap adicode>Actor 1</wrap> editor is active, Select <wrap adicode>Dependencies</wrap> page. | ||
| + | Tests before changing value for <wrap adicode>filmsDIPart:active</wrap> FieldController. | ||
| + | * line <wrap adicode>73</wrap>: In <wrap adicode>Film 1</wrap> editor, check if value hosted by <wrap adicode>filmDetail:active</wrap> CheckController is <wrap adicode>false</wrap>. | ||
| + | * line <wrap adicode>77</wrap>: In <wrap adicode>Film 1</wrap> editor, check if control of <wrap adicode>filmDetail:activeGroup</wrap> PGroupController is disposed. | ||
| + | Change. | ||
| + | * line <wrap adicode>82</wrap>: Select row <wrap adicode>Film 1</wrap> in <wrap adicode>filmsTSI:table</wrap>. | ||
| + | * line <wrap adicode>87</wrap>: Change value for <wrap adicode>filmsDIPart:active</wrap> FieldController (set <wrap adicode>active</wrap> = <wrap adicode>false</wrap> simulate a user action on check button) | ||
| + | Tests after changing value for <wrap adicode>filmsDIPart:active</wrap> FieldController. | ||
| + | * line <wrap adicode>90</wrap>: In <wrap adicode>Film 1</wrap> editor, check if value hosted by <wrap adicode>filmDetail:active</wrap> CheckController is <wrap adicode>false</wrap>. | ||
| + | * line <wrap adicode>94</wrap>: In <wrap adicode>Film 1</wrap> editor, check if control of <wrap adicode>filmDetail:activeGroup</wrap> PGroupController is disposed. | ||
| + | * line <wrap adicode>99</wrap>: Check if field controllers in <wrap adicode>filmDetail:detailContainer</wrap> SectionController are locks. | ||
| + | Display and close edtors | ||
| + | * line <wrap adicode>104</wrap>: Ends layouts process in <wrap adicode>Actor 1</wrap> editor (otherwise nothing is visible). | ||
| + | * line <wrap adicode>106</wrap>: Refresh (cancel) cupdated entities in <wrap adicode>Actor 1</wrap> editor. | ||
| + | * line <wrap adicode>110</wrap>: Close all editors. | ||
| + | </WRAP> | ||
| + | \\ \\ | ||
| + | === Create a intended bug === | ||
| + | Use example: [[extend_controller#example_2extend_a_specific_ccombocontroller_for_property_rating | extend a ccombo contorller for 'rating' property]].\\ | ||
| + | Add a bug in the new controller named <wrap adicode>org.mycompany.myProject.gencode.custom.RatingCComboController</wrap> as shown: | ||
| + | <sxh java first-line: 1; highlight: [43, 44, 45, 46]; title: excerpt from 'RatingCComboController.java' class.> | ||
| + | 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 | ||
| + | } | ||
| + | } | ||
| + | </sxh> | ||
| + | <WRAP indic> | ||
| + | Lines 43-46: This intended bug is just as example. | ||
| + | </WRAP> | ||
| + | \\ \\ | ||
| + | === Step 3: Add entry to 'AdichatzRcpCongif.xml' file === | ||
| + | <WRAP adihi>You need to add an simple entry in file <wrap adicode>$projectDirectory/resources/xml/AdichatzRcpConfig.xml</wrap> as shown below:</WRAP> | ||
| + | <sxh xml; first-line: 15; highlight: [19]; title: excerpt from 'AdichatzRcpConfig.xml' class.> | ||
| + | <?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> | ||
| + | </sxh> | ||
| + | <WRAP indic> | ||
| + | Lines 19: Add this line in <wrap adicode>AdichatzRcpConfig.xml</wrap>, relaunch application or <wrap adicode>Refresh testing menu</wrap> in application: The new item is available. | ||
| + | </WRAP> | ||
| + | \\ \\ | ||
| + | === Step 4: Execute and reexecute tests === | ||
| + | {{testing_film_actor.png |Execute the test}} | ||
| + | <WRAP indic>To execute the test: click on the corresponding item (<wrap adicode>Film Actor databinding test</wrap>). | ||
| + | * Test fails, at line <wrap adicode>98</wrap>. | ||
| + | * Close all editor and delete method <wrap adicode>lockEntity</wrap> of class <wrap adicode>RatingCComboController</wrap>. | ||
| + | * Rexecute test: Click on item <wrap adicode>Film Actor databinding test</wrap>. | ||
| + | * Test is sucessfull, All editors are closed. | ||
| + | </WRAP> | ||