NewScoreCardXLSHandler extends DefaultNewResourceHandler { @Override public void create(final Package pkg, final String baseFileName, final NewResourcePresenter presenter) { busyIndicatorView.showBusyIndicator(ScoreCardXLSEditorConstants.INSTANCE.Uploading()); final Path path = pkg.getPackageMainResourcesPath(); final String fileName = buildFileName(baseFileName, resourceType); 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(path)); placeManager.goTo(newPath); } }, new Command() { @Override public void execute() { busyIndicatorView.hideBusyIndicator(); } } ); } NewScoreCardXLSHandler(); @Inject  NewScoreCardXLSHandler(final PlaceManager placeManager,
                                  final ScoreCardXLSResourceType resourceType,
                                  final BusyIndicatorView busyIndicatorView,
                                  final ClientMessageBus clientMessageBus,
                                  final AuthorizationManager authorizationManager,
                                  final SessionInfo sessionInfo); @Override List<Pair<String, ? extends IsWidget>> getExtensions(); @Override String getDescription(); @Override IsWidget getIcon(); @Override ResourceTypeDefinition getResourceType(); @Override boolean canCreate(); @Override void create(final Package pkg,
                       final String baseFileName,
                       final NewResourcePresenter presenter);  }
@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); handler.create(pkg, fileName, newResourcePresenter); verify(uploadWidget, times(1)).submit(eq(resourcesPath), eq(fileName + "." + resourceType.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 testSuccess() { final String fileName = "fileName"; final Package pkg = mock(Package.class); final Path resourcesPath = PathFactory.newPath("resources", "default: when(pkg.getPackageMainResourcesPath()).thenReturn(resourcesPath); handler.create(pkg, fileName, newResourcePresenter); verify(uploadWidget, times(1)).submit(eq(resourcesPath), eq(fileName + "." + resourceType.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()); }