Skip to content

Commit

Permalink
RHBRMS-75: Increase code coverage (apache#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jozef Marko authored and manstis committed Mar 14, 2017
1 parent ace2082 commit 013354c
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.HashMap;
import java.util.Map;

import org.drools.template.parser.DecisionTableParseException;
import org.drools.workbench.models.datamodel.oracle.ModelField;
import org.drools.workbench.models.datamodel.oracle.PackageDataModelOracle;
import org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult;
Expand Down Expand Up @@ -246,7 +247,8 @@ public void checkConversionOfXLSXFiles() {
when(ioService.newInputStream(any(org.uberfire.java.nio.file.Path.class))).thenReturn(is);
final ConversionResult result = converter.convert(path);
assertNotNull(result);
assertEquals(1, result.getMessages().size());
assertEquals(1,
result.getMessages().size());
assertTrue(result.getMessages().get(0).getMessage().startsWith("Created Guided Decision Table 'Weather"));

verify(guidedDecisionTableService,
Expand All @@ -255,4 +257,11 @@ public void checkConversionOfXLSXFiles() {
any(GuidedDecisionTable52.class),
any(String.class));
}

@Test(expected = DecisionTableParseException.class)
public void checkConversionOfXLSWithInvalidContent() {
final InputStream is = this.getClass().getResourceAsStream("wrong_file.xls");
when(ioService.newInputStream(any(org.uberfire.java.nio.file.Path.class))).thenReturn(is);
converter.convert(path);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
some text
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.drools.workbench.screens.dtablexls.client.resources.i18n.DecisionTableXLSEditorConstants;
import org.gwtbootstrap3.client.ui.Button;
import org.jboss.errai.bus.client.api.ClientMessageBus;
import org.jboss.errai.bus.client.framework.ClientMessageBusImpl;
import org.kie.workbench.common.widgets.client.resources.i18n.CommonConstants;
import org.kie.workbench.common.widgets.client.widget.AttachmentFileWidget;
import org.kie.workbench.common.widgets.metadata.client.KieEditorViewImpl;
Expand All @@ -50,7 +49,7 @@ interface ViewBinder

}

private static ViewBinder uiBinder = GWT.create( ViewBinder.class );
private static ViewBinder uiBinder = GWT.create(ViewBinder.class);

//This is not part of the UiBinder definition as it is created dependent upon the file-type being uploaded
AttachmentFileWidget uploadWidget;
Expand All @@ -70,80 +69,84 @@ interface ViewBinder
private DecisionTableXLSEditorView.Presenter presenter;

public DecisionTableXLSEditorViewImpl() {
initWidget( uiBinder.createAndBindUi( this ) );
initWidget(uiBinder.createAndBindUi(this));
}

@Override
public void init( final DecisionTableXLSEditorView.Presenter presenter ) {
public void init(final DecisionTableXLSEditorView.Presenter presenter) {
this.presenter = presenter;
}

@Override
public void setupUploadWidget( final ClientResourceType resourceTypeDefinition ) {
uploadWidget = new AttachmentFileWidget( new String[]{ resourceTypeDefinition.getSuffix() }, true );
public void setupUploadWidget(final ClientResourceType resourceTypeDefinition) {
uploadWidget = constructUploadWidget(resourceTypeDefinition);

uploadWidgetContainer.clear();
uploadWidgetContainer.setWidget( uploadWidget );
uploadWidgetContainer.setWidget(uploadWidget);

uploadWidget.addClickHandler( new ClickHandler() {
uploadWidget.addClickHandler(new ClickHandler() {
@Override
public void onClick( final ClickEvent event ) {
BusyPopup.showMessage( DecisionTableXLSEditorConstants.INSTANCE.Uploading() );
public void onClick(final ClickEvent event) {
BusyPopup.showMessage(DecisionTableXLSEditorConstants.INSTANCE.Uploading());
presenter.onUpload();
}
} );
});
}

public void setPath( final Path path ) {
downloadButton.addClickHandler( new ClickHandler() {
protected AttachmentFileWidget constructUploadWidget(final ClientResourceType resourceTypeDefinition) {
return new AttachmentFileWidget(new String[]{resourceTypeDefinition.getSuffix()},
true);
}

public void setPath(final Path path) {
downloadButton.addClickHandler(new ClickHandler() {
@Override
public void onClick( final ClickEvent event ) {
Window.open( getDownloadUrl( path ),
"downloading",
"resizable=no,scrollbars=yes,status=no" );
public void onClick(final ClickEvent event) {
Window.open(getDownloadUrl(path),
"downloading",
"resizable=no,scrollbars=yes,status=no");
}
} );
});
}

@Override
public void submit( final Path path ) {
uploadWidget.submit( path,
getServletUrl(),
new Command() {

@Override
public void execute() {
BusyPopup.close();
notifySuccess();
}

},
new Command() {

@Override
public void execute() {
BusyPopup.close();
}

}
);
public void submit(final Path path) {
uploadWidget.submit(path,
getServletUrl(),
new Command() {

@Override
public void execute() {
BusyPopup.close();
notifySuccess();
}
},
new Command() {

@Override
public void execute() {
BusyPopup.close();
}
}
);
}

@Override
public void setReadOnly( final boolean isReadOnly ) {
uploadWidget.setEnabled( !isReadOnly );
public void setReadOnly(final boolean isReadOnly) {
uploadWidget.setEnabled(!isReadOnly);
}

private void notifySuccess() {
notificationEvent.fire( new NotificationEvent( CommonConstants.INSTANCE.ItemCreatedSuccessfully() ) );
notificationEvent.fire(new NotificationEvent(CommonConstants.INSTANCE.ItemCreatedSuccessfully()));
}

String getDownloadUrl( final Path path ) {
return URLHelper.getDownloadUrl( path, getClientId() );
String getDownloadUrl(final Path path) {
return URLHelper.getDownloadUrl(path,
getClientId());
}

String getServletUrl() {
return URLHelper.getServletUrl( getClientId() );
return URLHelper.getServletUrl(getClientId());
}

String getClientId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,44 @@

package org.drools.workbench.screens.dtablexls.client.editor;

import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Command;
import com.google.gwtmockito.GwtMockitoTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.kie.workbench.common.widgets.client.widget.AttachmentFileWidget;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.uberfire.backend.vfs.Path;
import org.uberfire.client.workbench.type.ClientResourceType;

import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

@RunWith(GwtMockitoTestRunner.class)
public class DecisionTableXLSEditorViewImplTest {

private static final String SERVLET_URL = "dtablexls/file?clientId=123";
private DecisionTableXLSEditorViewImpl view;

@Mock
AttachmentFileWidget attachmentFileWidget;

@Mock
ClientResourceType type;

@Mock
DecisionTableXLSEditorPresenter presenter;

@Captor
ArgumentCaptor<ClickHandler> clickCaptor;

@Before
public void setup() {
view = new DecisionTableXLSEditorViewImpl() {
Expand All @@ -37,17 +62,46 @@ public void setup() {
String getClientId() {
return "123";
}

@Override
protected AttachmentFileWidget constructUploadWidget(ClientResourceType resourceTypeDefinition) {
return attachmentFileWidget;
}
};

view.init(presenter);
}

@Test
public void testGetDownloadUrl() throws Exception {
assertEquals( "dtablexls/file?clientId=123&attachmentPath=", view.getDownloadUrl( path() ) );
assertEquals(SERVLET_URL + "&attachmentPath=",
view.getDownloadUrl(path()));
}

@Test
public void getServletUrl() throws Exception {
assertEquals( "dtablexls/file?clientId=123", view.getServletUrl() );
assertEquals(SERVLET_URL,
view.getServletUrl());
}

@Test
public void testUploadWidgetClickHandler() throws Exception {
doCallRealMethod().when(presenter).onUpload();
view.setupUploadWidget(type);
verify(attachmentFileWidget).addClickHandler(clickCaptor.capture());
clickCaptor.getValue().onClick(null);
verify(presenter).submit();
}

@Test
public void testSubmit() throws Exception {
Path path = mock(Path.class);
view.setupUploadWidget(type);
view.submit(path);
verify(attachmentFileWidget).submit(eq(path),
eq(SERVLET_URL),
any(Command.class),
any(Command.class));
}

private Path path() {
Expand All @@ -63,7 +117,7 @@ public String toURI() {
}

@Override
public int compareTo( final Path o ) {
public int compareTo(final Path o) {
return 0;
}
};
Expand Down

0 comments on commit 013354c

Please sign in to comment.