@Test public void testInit() throws Exception { model.setTableFormat(GuidedDecisionTable52.TableFormat.LIMITED_ENTRY); doReturn(model).when(presenter).getModel(); doReturn(presenter).when(wizard).getPresenter(); plugin.init(wizard); verify(plugin).setupDefaultValues(); }
@Test public void testGetPagesWhenTableFormatIsNotLimitedEntry() throws Exception { model.setTableFormat(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY); doReturn(model).when(presenter).getModel(); final List<WizardPage> pages = plugin.getPages(); final boolean hasPatternToDeletePage = pages.stream().anyMatch(a -> a instanceof PatternToDeletePage); assertFalse(hasPatternToDeletePage); assertEquals(1, pages.size()); }
@Test public void testGetPagesWhenTableFormatIsLimitedEntry() throws Exception { model.setTableFormat(GuidedDecisionTable52.TableFormat.LIMITED_ENTRY); doReturn(model).when(presenter).getModel(); final List<WizardPage> pages = plugin.getPages(); final boolean hasPatternToDeletePage = pages.stream().anyMatch(a -> a instanceof PatternToDeletePage); assertTrue(hasPatternToDeletePage); assertEquals(2, pages.size()); }
public LimitedGuidedDecisionTableBuilder(final String packageName, final Collection<Import> imports, final String tableName) { table.setPackageName(packageName); table.setTableFormat(GuidedDecisionTable52.TableFormat.LIMITED_ENTRY); table.getImports().getImports().addAll(imports); table.setTableName(tableName); }
public ExtendedGuidedDecisionTableBuilder(final String packageName, final Collection<Import> imports, final String tableName) { table.setPackageName(packageName); table.setTableFormat(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY); table.getImports().getImports().addAll(imports); table.setTableName(tableName); }
public LimitedGuidedDecisionTableBuilder(final String packageName, final Collection<Import> imports, final String tableName) { table.setPackageName(packageName); table.setTableFormat(GuidedDecisionTable52.TableFormat.LIMITED_ENTRY); table.getImports().getImports().addAll(imports); table.setTableName(tableName); }
public ExtendedGuidedDecisionTableBuilder(final String packageName, final Collection<Import> imports, final String tableName) { table.setPackageName(packageName); table.setTableFormat(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY); table.getImports().getImports().addAll(imports); table.setTableName(tableName); }
@Before public void setup() { dtServiceCaller = new CallerMock<>(dtService); model = new GuidedDecisionTable52(); model.setTableFormat(tableFormat); model.setHitPolicy(hitPolicy); helper = new NewGuidedDecisionTableWizardHelper(dtServiceCaller, oracleFactory, beanManager); when(beanManager.lookupBean(eq(NewGuidedDecisionTableWizard.class))).thenReturn(wizardBeanDef); when(wizardBeanDef.getInstance()).thenReturn(wizardBean); when(dtService.loadDataModel(eq(contextPath))).thenReturn(oracleBasePayload); when(dtService.create(any(Path.class), any(String.class), any(GuidedDecisionTable52.class), any(String.class))).<Path>thenAnswer((invocation) -> { final Path path = ((Path) invocation.getArguments()[0]); final String fileName = ((String) invocation.getArguments()[1]); final Path newPath = PathFactory.newPath(fileName, path.toURI() + "/" + fileName); return newPath; }); when(oracleFactory.makeAsyncPackageDataModelOracle(contextPath, oracleBasePayload)).thenReturn(oracle); }
this._dtable.setTableFormat(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY); this._dtable.setTableName(RuleSheetParserUtil.getRuleName(value)); this._dtable.setPackageName(_dmo.getPackageName());
public void setContent(final Path contextPath, final String baseFileName, final GuidedDecisionTable52.TableFormat tableFormat, final GuidedDecisionTable52.HitPolicy hitPolicy, final AsyncPackageDataModelOracle oracle, final GuidedDecisionTableWizardHandler handler) { this.model = new GuidedDecisionTable52(); this.model.setTableFormat(tableFormat); this.model.setHitPolicy(hitPolicy); if (GuidedDecisionTable52.HitPolicy.RESOLVED_HIT.equals(hitPolicy)) { final MetadataCol52 metadataCol52 = new MetadataCol52(); metadataCol52.setMetadata(GuidedDecisionTable52.HitPolicy.RESOLVED_HIT_METADATA_NAME); this.model.getMetadataCols().add(metadataCol52); } this.contextPath = contextPath; this.oracle = oracle; this.handler = handler; final Validator validator = new Validator(model.getConditions()); for (WizardPage page : pages) { final AbstractGuidedDecisionTableWizardPage dtp = (AbstractGuidedDecisionTableWizardPage) page; dtp.setContent(contextPath, baseFileName, tableFormat, hitPolicy, oracle, model, validator); dtp.initialise(); } }
public void setContent(final Path contextPath, final String baseFileName, final GuidedDecisionTable52.TableFormat tableFormat, final GuidedDecisionTable52.HitPolicy hitPolicy, final AsyncPackageDataModelOracle oracle, final GuidedDecisionTableWizardHandler handler) { this.model = new GuidedDecisionTable52(); this.model.setTableFormat(tableFormat); this.model.setHitPolicy(hitPolicy); if (GuidedDecisionTable52.HitPolicy.RESOLVED_HIT.equals(hitPolicy)) { final MetadataCol52 metadataCol52 = new MetadataCol52(); metadataCol52.setMetadata(GuidedDecisionTable52.HitPolicy.RESOLVED_HIT_METADATA_NAME); this.model.getMetadataCols().add(metadataCol52); } this.contextPath = contextPath; this.oracle = oracle; this.handler = handler; final Validator validator = new Validator(model.getConditions()); for (WizardPage page : pages) { final AbstractGuidedDecisionTableWizardPage dtp = (AbstractGuidedDecisionTableWizardPage) page; dtp.setContent(contextPath, baseFileName, tableFormat, hitPolicy, oracle, model, validator); dtp.initialise(); } }
@Test public void testLimitedEntryAttributes() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.setTableFormat(GuidedDecisionTable52.TableFormat.LIMITED_ENTRY); dt.setTableName("limited-entry"); AttributeCol52 attr = new AttributeCol52(); attr.setAttribute("salience"); dt.getAttributeCols().add(attr); dt.setData(DataUtilities.makeDataLists(new String[][]{ new String[]{"1", "desc", "100"}, new String[]{"2", "desc", "200"} })); GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance(); String drl = p.marshal(dt); assertTrue(drl.indexOf("salience 100") > -1); assertTrue(drl.indexOf("salience 200") > -1); }
@Test public void testLimitedEntryMetadata() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.setTableFormat(GuidedDecisionTable52.TableFormat.LIMITED_ENTRY); dt.setTableName("limited-entry"); MetadataCol52 md = new MetadataCol52(); md.setMetadata("metadata"); dt.getMetadataCols().add(md); dt.setData(DataUtilities.makeDataLists(new String[][]{ new String[]{"1", "desc", "md1"}, new String[]{"2", "desc", "md2"} })); GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance(); String drl = p.marshal(dt); assertTrue(drl.indexOf("@metadata(md1)") > -1); assertTrue(drl.indexOf("@metadata(md2)") > -1); }
private void createEmptyDecisionTable(final Path contextPath, final String baseFileName) { final GuidedDecisionTable52 model = new GuidedDecisionTable52(); model.setTableFormat(options.getTableFormat()); model.setHitPolicy(options.getHitPolicy()); if (GuidedDecisionTable52.HitPolicy.RESOLVED_HIT.equals(options.getHitPolicy())) { final MetadataCol52 metadataCol52 = new MetadataCol52(); metadataCol52.setMetadata(GuidedDecisionTable52.HitPolicy.RESOLVED_HIT_METADATA_NAME); model.getMetadataCols().add(metadataCol52); } model.setTableName(baseFileName); final RemoteCallback<Path> onSaveSuccessCallback = getSuccessCallback(newResourcePresenter); busyIndicatorView.showBusyIndicator(CommonConstants.INSTANCE.Saving()); service.call((Path path) -> { busyIndicatorView.hideBusyIndicator(); onSaveSuccessCallback.callback(path); }, new HasBusyIndicatorDefaultErrorCallback(busyIndicatorView)).create(contextPath, buildFileName(baseFileName, resourceType), model, ""); }
private void createEmptyDecisionTable(final Path contextPath, final String baseFileName) { final GuidedDecisionTable52 model = new GuidedDecisionTable52(); model.setTableFormat(options.getTableFormat()); model.setHitPolicy(options.getHitPolicy()); if (GuidedDecisionTable52.HitPolicy.RESOLVED_HIT.equals(options.getHitPolicy())) { final MetadataCol52 metadataCol52 = new MetadataCol52(); metadataCol52.setMetadata(GuidedDecisionTable52.HitPolicy.RESOLVED_HIT_METADATA_NAME); model.getMetadataCols().add(metadataCol52); } model.setTableName(baseFileName); final RemoteCallback<Path> onSaveSuccessCallback = getSuccessCallback(newResourcePresenter); busyIndicatorView.showBusyIndicator(CommonConstants.INSTANCE.Saving()); service.call((Path path) -> { busyIndicatorView.hideBusyIndicator(); onSaveSuccessCallback.callback(path); }, new HasBusyIndicatorDefaultErrorCallback(busyIndicatorView)).create(contextPath, buildFileName(baseFileName, resourceType), model, ""); }
@Test public void testLimitedEntryConditionsNoConstraints() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.setTableFormat(GuidedDecisionTable52.TableFormat.LIMITED_ENTRY); dt.setTableName("limited-entry"); Pattern52 p1 = new Pattern52(); p1.setBoundName("p1"); p1.setFactType("Smurf"); dt.getConditions().add(p1); // This is a hack consistent with how the Expanded Form decision table // works. I wouldn't be too surprised if this changes at some time, but // GuidedDTDRLPersistence.marshal does not support empty patterns at // present. LimitedEntryConditionCol52 cc1 = new LimitedEntryConditionCol52(); cc1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL); cc1.setValue(new DTCellValue52("y")); p1.getChildColumns().add(cc1); dt.setData(DataUtilities.makeDataLists(new Object[][]{ new Object[]{1l, "desc", true}, new Object[]{2l, "desc", false} })); GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance(); String drl = p.marshal(dt); int index = -1; index = drl.indexOf("Smurf( )"); assertTrue(index > -1); index = drl.indexOf("Smurf( )", index + 1); assertFalse(index > -1); }
@Test public void testLimitedEntryConditionsConstraints1() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.setTableFormat(GuidedDecisionTable52.TableFormat.LIMITED_ENTRY); dt.setTableName("limited-entry"); Pattern52 p1 = new Pattern52(); p1.setBoundName("p1"); p1.setFactType("Smurf"); dt.getConditions().add(p1); LimitedEntryConditionCol52 cc1 = new LimitedEntryConditionCol52(); cc1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL); cc1.setFieldType(DataType.TYPE_STRING); cc1.setFactField("name"); cc1.setOperator("=="); cc1.setValue(new DTCellValue52("Pupa")); p1.getChildColumns().add(cc1); dt.setData(DataUtilities.makeDataLists(new Object[][]{ new Object[]{1l, "desc", true}, new Object[]{2l, "desc", false} })); GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance(); String drl = p.marshal(dt); int index = -1; index = drl.indexOf("Smurf( name == \"Pupa\" )"); assertTrue(index > -1); index = drl.indexOf("Smurf( name == \"Pupa\" )", index + 1); assertFalse(index > -1); }
@Test public void testLHSInOperator() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.setTableFormat(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY); dt.setTableName("extended-entry");
@Test public void testLHSIsNullOperatorWithNullValues() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.setTableFormat(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY); dt.setTableName("extended-entry");
@Test public void testLimitedEntryLHSIsNullOperator() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.setTableFormat(GuidedDecisionTable52.TableFormat.LIMITED_ENTRY); dt.setTableName("limited-entry");