NewDecisionTableXLSHandler extends DefaultNewResourceHandler { @Override public void create( final Package pkg, final String baseFileName, final NewResourcePresenter presenter ) { busyIndicatorView.showBusyIndicator( DecisionTableXLSEditorConstants.INSTANCE.Uploading() ); final ResourceTypeDefinition type = uploadWidget.getFilenameSelectedToUpload().endsWith(decisionTableXLSResourceType.getSuffix()) ? decisionTableXLSResourceType : decisionTableXLSXResourceType; final Path path = pkg.getPackageMainResourcesPath(); final String fileName = buildFileName( baseFileName, type ); final Path newPath = PathFactory.newPathBasedOn( fileName, path.toURI() + "/" + encode( fileName ), path ); uploadWidget.submit( path, fileName, getServletUrl(), new Command() { @Override public void execute() { busyIndicatorView.hideBusyIndicator(); presenter.complete(); notifySuccess(); newResourceSuccessEvent.fire( new NewResourceSuccessEvent( newPath ) ); placeManager.goTo( newPath ); } }, new Command() { @Override public void execute() { busyIndicatorView.hideBusyIndicator(); } } ); } NewDecisionTableXLSHandler(); @Inject  NewDecisionTableXLSHandler( final PlaceManager placeManager,
                                       final DecisionTableXLSResourceType decisionTableXLSResourceType,
                                       final DecisionTableXLSXResourceType decisionTableXLSXResourceType,
                                       final BusyIndicatorView busyIndicatorView,
                                       final ClientMessageBus clientMessageBus ); @Override List<Pair<String, ? extends IsWidget>> getExtensions(); @Override String getDescription(); @Override IsWidget getIcon(); @Override ResourceTypeDefinition getResourceType(); @Override void validate(final String baseFileName, final ValidatorWithReasonCallback callback); @Override void create( final Package pkg,
                        final String baseFileName,
                        final NewResourcePresenter presenter );  }
@Test public void testSuccess() { final String fileName = "fileName"; final Package pkg = mock(Package.class); final Path resourcesPath = PathFactory.newPath("resources", "default: when(pkg.getPackageMainResourcesPath()).thenReturn(resourcesPath); when(uploadWidget.getFilenameSelectedToUpload()).thenReturn(fileName + ".xls"); handler.create(pkg, fileName, newResourcePresenter); verify(uploadWidget, times(1)).submit(eq(resourcesPath), eq(fileName + "." + decisionTableXLSResourceType.getSuffix()), any(String.class), successCmdCaptor.capture(), failureCmdCaptor.capture()); successCmdCaptor.getValue().execute(); verify(busyIndicatorView, times(1)).hideBusyIndicator(); verify(newResourcePresenter, times(1)).complete(); verify(mockNotificationEvent, times(1)).fire(any(NotificationEvent.class)); verify(newResourceSuccessEventMock, times(1)).fire(any(NewResourceSuccessEvent.class)); verify(placeManager, times(1)).goTo(newPathCaptor.capture()); assertEquals("default: newPathCaptor.getValue().toURI()); }
@Test public void testSuccessXLSX() { final String fileName = "fileName"; final Package pkg = mock(Package.class); final Path resourcesPath = PathFactory.newPath("resources", "default: when(pkg.getPackageMainResourcesPath()).thenReturn(resourcesPath); when(uploadWidget.getFilenameSelectedToUpload()).thenReturn(fileName + ".xlsx"); handler.create(pkg, fileName, newResourcePresenter); verify(uploadWidget, times(1)).submit(eq(resourcesPath), eq(fileName + "." + decisionTableXLSXResourceType.getSuffix()), any(String.class), successCmdCaptor.capture(), failureCmdCaptor.capture()); successCmdCaptor.getValue().execute(); verify(busyIndicatorView, times(1)).hideBusyIndicator(); verify(newResourcePresenter, times(1)).complete(); verify(mockNotificationEvent, times(1)).fire(any(NotificationEvent.class)); verify(newResourceSuccessEventMock, times(1)).fire(any(NewResourceSuccessEvent.class)); verify(placeManager, times(1)).goTo(newPathCaptor.capture()); assertEquals("default: newPathCaptor.getValue().toURI()); }
@Test public void testSuccessMultiByteProjectName() { final String fileName = "fileName"; final Package pkg = mock(Package.class); final Path resourcesPath = PathFactory.newPath("resources", "default: when(pkg.getPackageMainResourcesPath()).thenReturn(resourcesPath); when(uploadWidget.getFilenameSelectedToUpload()).thenReturn(fileName + ".xls"); handler.create(pkg, fileName, newResourcePresenter); verify(uploadWidget, times(1)).submit(eq(resourcesPath), eq(fileName + "." + decisionTableXLSResourceType.getSuffix()), any(String.class), successCmdCaptor.capture(), failureCmdCaptor.capture()); successCmdCaptor.getValue().execute(); verify(busyIndicatorView, times(1)).hideBusyIndicator(); verify(newResourcePresenter, times(1)).complete(); verify(mockNotificationEvent, times(1)).fire(any(NotificationEvent.class)); verify(placeManager, times(1)).goTo(newPathCaptor.capture()); assertEquals("default: newPathCaptor.getValue().toURI()); }
@Test public void testSuccessMultiByteFileName() { final String fileName = "あああ"; final Package pkg = mock(Package.class); final Path resourcesPath = PathFactory.newPath("resources", "default: when(pkg.getPackageMainResourcesPath()).thenReturn(resourcesPath); when(uploadWidget.getFilenameSelectedToUpload()).thenReturn(fileName + ".xls"); handler.create(pkg, fileName, newResourcePresenter); verify(uploadWidget, times(1)).submit(eq(resourcesPath), eq(fileName + "." + decisionTableXLSResourceType.getSuffix()), any(String.class), successCmdCaptor.capture(), failureCmdCaptor.capture()); successCmdCaptor.getValue().execute(); verify(busyIndicatorView, times(1)).hideBusyIndicator(); verify(newResourcePresenter, times(1)).complete(); verify(mockNotificationEvent, times(1)).fire(any(NotificationEvent.class)); verify(placeManager, times(1)).goTo(newPathCaptor.capture()); assertEquals("default: newPathCaptor.getValue().toURI()); }