NewGuidedDecisionTableWizardHelper { public void createNewGuidedDecisionTable(final Path contextPath, final String baseFileName, final GuidedDecisionTable52.TableFormat tableFormat, final GuidedDecisionTable52.HitPolicy hitPolicy, final HasBusyIndicator view, final RemoteCallback<Path> onSaveSuccessCallback) { PortablePreconditions.checkNotNull("contextPath", contextPath); PortablePreconditions.checkNotNull("baseFileName", baseFileName); PortablePreconditions.checkNotNull("tableFormat", tableFormat); PortablePreconditions.checkNotNull("hitPolicy", hitPolicy); PortablePreconditions.checkNotNull("view", view); PortablePreconditions.checkNotNull("onSaveSuccessCallback", onSaveSuccessCallback); dtService.call(new RemoteCallback<PackageDataModelOracleBaselinePayload>() { @Override public void callback(final PackageDataModelOracleBaselinePayload dataModel) { final AsyncPackageDataModelOracle oracle = oracleFactory.makeAsyncPackageDataModelOracle(contextPath, dataModel); wizard = beanManager.lookupBean(NewGuidedDecisionTableWizard.class).getInstance(); wizard.setContent(contextPath, baseFileName, tableFormat, hitPolicy, oracle, new NewGuidedDecisionTableWizard.GuidedDecisionTableWizardHandler() { @Override public void save(final Path contextPath, final String baseFileName, final GuidedDecisionTable52 model) { destroyWizard(); oracleFactory.destroy(oracle); view.showBusyIndicator(CommonConstants.INSTANCE.Saving()); dtService.call((Path path) -> { view.hideBusyIndicator(); onSaveSuccessCallback.callback(path); }, new HasBusyIndicatorDefaultErrorCallback(view)).create(contextPath, buildFileName(baseFileName), model, ""); } private String buildFileName(final String baseFileName) { final String suffix = dtResourceType.getSuffix(); final String prefix = dtResourceType.getPrefix(); final String extension = !(suffix == null || "".equals(suffix)) ? "." + dtResourceType.getSuffix() : ""; if (baseFileName.endsWith(extension)) { return prefix + baseFileName; } return prefix + baseFileName + extension; } @Override public void destroyWizard() { if (wizard != null) { beanManager.destroyBean(wizard); wizard = null; } } }); wizard.start(); } }).loadDataModel(contextPath); } @Inject  NewGuidedDecisionTableWizardHelper(final Caller<GuidedDecisionTableEditorService> dtService,
                                              final AsyncPackageDataModelOracleFactory oracleFactory,
                                              final SyncBeanManager beanManager); void createNewGuidedDecisionTable(final Path contextPath,
                                             final String baseFileName,
                                             final GuidedDecisionTable52.TableFormat tableFormat,
                                             final GuidedDecisionTable52.HitPolicy hitPolicy,
                                             final HasBusyIndicator view,
                                             final RemoteCallback<Path> onSaveSuccessCallback);  }
@Test public void checkNullContextPath() { rule.expect(IllegalArgumentException.class); helper.createNewGuidedDecisionTable(null, baseFileName, tableFormat, hitPolicy, view, onSaveSuccessCallback); }
@Test @SuppressWarnings("unchecked") public void checkNullBaseFilename() { rule.expect(IllegalArgumentException.class); helper.createNewGuidedDecisionTable(contextPath, null, tableFormat, hitPolicy, view, onSaveSuccessCallback); }
@Test @SuppressWarnings("unchecked") public void checkNullTableFormat() { rule.expect(IllegalArgumentException.class); helper.createNewGuidedDecisionTable(contextPath, baseFileName, null, hitPolicy, view, onSaveSuccessCallback); }
@Test @SuppressWarnings("unchecked") public void checkNullHitPolicy() { rule.expect(IllegalArgumentException.class); helper.createNewGuidedDecisionTable(contextPath, baseFileName, tableFormat, null, view, onSaveSuccessCallback); }
@Test @SuppressWarnings("unchecked") public void checkNullHasBusyIndicator() { rule.expect(IllegalArgumentException.class); helper.createNewGuidedDecisionTable(contextPath, baseFileName, tableFormat, hitPolicy, null, onSaveSuccessCallback); }
@Test public void checkNullSaveSuccessCallback() { rule.expect(IllegalArgumentException.class); helper.createNewGuidedDecisionTable(contextPath, baseFileName, tableFormat, hitPolicy, view, null); }
@Test @SuppressWarnings("unchecked") public void checkWizardContentIsSet() { helper.createNewGuidedDecisionTable(contextPath, baseFileName, tableFormat, hitPolicy, view, onSaveSuccessCallback); verify(wizardBean, times(1)).setContent(eq(contextPath), eq(baseFileName), eq(tableFormat), eq(hitPolicy), eq(oracle), any(GuidedDecisionTableWizardHandler.class)); }
@Test public void checkWizardHandlerSave() { helper.createNewGuidedDecisionTable(contextPath, baseFileName, tableFormat, hitPolicy, view, onSaveSuccessCallback); verify(wizardBean, times(1)).setContent(eq(contextPath), eq(baseFileName), eq(tableFormat), eq(hitPolicy), eq(oracle), wizardHandlerCaptor.capture()); final GuidedDecisionTableWizardHandler wizardHandler = wizardHandlerCaptor.getValue(); assertNotNull(wizardHandler); wizardHandler.save(contextPath, baseFileName, model); verify(beanManager, times(1)).destroyBean(wizardBean); verify(oracleFactory, times(1)).destroy(oracle); verify(view, times(1)).showBusyIndicator(any(String.class)); verify(dtService, times(1)).create(eq(contextPath), fileNameCaptor.capture(), eq(model), eq("")); verify(onSaveSuccessCallback, times(1)).callback(any(Path.class)); verify(view, times(1)).hideBusyIndicator(); final String fileName = fileNameCaptor.getValue(); assertNotNull(fileName); assertEquals(baseFileName + "." + dtResourceType.getSuffix(), fileName); }
@Test public void checkWizardHandlerDestroyWizard() { helper.createNewGuidedDecisionTable(contextPath, baseFileName, tableFormat, hitPolicy, view, onSaveSuccessCallback); verify(wizardBean, times(1)).setContent(eq(contextPath), eq(baseFileName), eq(tableFormat), eq(hitPolicy), eq(oracle), wizardHandlerCaptor.capture()); final GuidedDecisionTableWizardHandler wizardHandler = wizardHandlerCaptor.getValue(); assertNotNull(wizardHandler); wizardHandler.destroyWizard(); verify(beanManager, times(1)).destroyBean(wizardBean); }