Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
GUVNOR-2813: Not possible to copy repository URL in Repository Editor (
Browse files Browse the repository at this point in the history
…#398)

(cherry picked from commit 5a16335)
  • Loading branch information
manstis authored and mbiarnes committed Dec 22, 2016
1 parent be654bb commit 920f118
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 28 deletions.
Expand Up @@ -18,9 +18,11 @@

import java.util.List;
import javax.enterprise.context.Dependent;
import javax.enterprise.event.Event;
import javax.enterprise.event.Observes;
import javax.inject.Inject;

import org.guvnor.structure.client.resources.i18n.CommonConstants;
import org.guvnor.structure.client.security.RepositoryController;
import org.guvnor.structure.repositories.PublicURI;
import org.guvnor.structure.repositories.RepositoryInfo;
Expand All @@ -39,6 +41,7 @@
import org.uberfire.java.nio.base.version.VersionRecord;
import org.uberfire.lifecycle.OnStartup;
import org.uberfire.mvp.PlaceRequest;
import org.uberfire.workbench.events.NotificationEvent;

@Dependent
@WorkbenchScreen(identifier = "RepositoryEditor")
Expand All @@ -47,6 +50,7 @@ public class RepositoryEditorPresenter {
private View view;
private Caller<RepositoryService> repositoryService;
private Caller<RepositoryServiceEditor> repositoryServiceEditor;
private Event<NotificationEvent> notification;
private PlaceManager placeManager;
private RepositoryController repositoryController;

Expand Down Expand Up @@ -76,11 +80,13 @@ public RepositoryEditorPresenter() {
public RepositoryEditorPresenter( final View view,
final Caller<RepositoryService> repositoryService,
final Caller<RepositoryServiceEditor> repositoryServiceEditor,
final Event<NotificationEvent> notification,
final PlaceManager placeManager,
final RepositoryController repositoryController ) {
this.view = view;
this.repositoryService = repositoryService;
this.repositoryServiceEditor = repositoryServiceEditor;
this.notification = notification;
this.placeManager = placeManager;
this.repositoryController = repositoryController;
}
Expand Down Expand Up @@ -142,6 +148,10 @@ public void callback( final List<VersionRecord> content ) {
record );
}

void onGitUrlCopied( final String uri ) {
notification.fire( new NotificationEvent( CommonConstants.INSTANCE.GitUriCopied( uri ) ) );
}

public void onRepositoryRemovedEvent( @Observes RepositoryRemovedEvent event ) {
if ( alias.equals( event.getRepository().getAlias() ) ) {
placeManager.closePlace( place );
Expand Down
Expand Up @@ -77,9 +77,11 @@ interface RepositoryEditorViewBinder
private RepositoryEditorPresenter presenter;
private boolean readOnly;

@PostConstruct
public void init() {
public RepositoryEditorView() {
initWidget( uiBinder.createAndBindUi( this ) );

myGitCopyButton.addDomHandler( ( e ) -> presenter.onGitUrlCopied( gitDaemonURI.getText() ),
ClickEvent.getType() );
}

@Override
Expand Down Expand Up @@ -132,19 +134,19 @@ public void onClick( ClickEvent event ) {
history.setVisible( false );
}

loadMore.addClickHandler(new ClickHandler() {
loadMore.addClickHandler( new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
presenter.onLoadMoreHistory(history.getWidgetCount());
public void onClick( ClickEvent event ) {
presenter.onLoadMoreHistory( history.getWidgetCount() );
}
});
} );

final String uriId = "uri-for-" + repositoryName;
gitDaemonURI.getElement().setId( uriId );

myGitCopyButton.init(false, uriId, gitDaemonURI.getText());
myGitCopyButton.init( false, uriId, gitDaemonURI.getText() );

glueCopy(myGitCopyButton.getElement());
glueCopy( myGitCopyButton.getElement() );
}

@Override
Expand Down
Expand Up @@ -18,36 +18,42 @@

import java.util.ArrayList;
import java.util.Collections;
import javax.enterprise.event.Event;
import javax.inject.Inject;

import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Widget;
import org.guvnor.structure.client.editors.context.GuvnorStructureContext;
import org.guvnor.structure.client.resources.i18n.CommonConstants;
import org.guvnor.structure.client.security.RepositoryController;
import org.guvnor.structure.repositories.PublicURI;
import org.guvnor.structure.repositories.Repository;
import org.uberfire.ext.widgets.core.client.resources.i18n.CoreConstants;
import org.uberfire.workbench.events.NotificationEvent;

public class RepositoryItemPresenter
implements IsWidget {

private Repository repository;

private RepositoryItemView view;
private RepositoryItemView view;
private GuvnorStructureContext guvnorStructureContext;
private HasRemoveRepositoryHandlers removeRepositoryHandler;
private RepositoryController repositoryController;
private Event<NotificationEvent> notification;

public RepositoryItemPresenter() {
}

@Inject
public RepositoryItemPresenter( final RepositoryItemView repositoryItemView,
final GuvnorStructureContext guvnorStructureContext,
final RepositoryController repositoryController ) {
final RepositoryController repositoryController,
final Event<NotificationEvent> notification ) {
this.view = repositoryItemView;
this.guvnorStructureContext = guvnorStructureContext;
this.repositoryController = repositoryController;
this.notification = notification;
}

public void setRepository( final Repository repository,
Expand All @@ -70,10 +76,10 @@ public void setRepository( final Repository repository,

populateBranches( branch );

boolean canUpdate = repositoryController.canUpdateRepository(repository);
boolean canDelete = repositoryController.canDeleteRepository(repository);
view.setUpdateEnabled(canUpdate);
view.setDeleteEnabled(canDelete);
boolean canUpdate = repositoryController.canUpdateRepository( repository );
boolean canDelete = repositoryController.canDeleteRepository( repository );
view.setUpdateEnabled( canUpdate );
view.setDeleteEnabled( canDelete );

view.refresh();
}
Expand Down Expand Up @@ -141,4 +147,8 @@ public void addRemoveRepositoryCommand( final HasRemoveRepositoryHandlers remove
this.removeRepositoryHandler = removeRepositoryHandlers;
}

void onGitUrlCopied( final String uri ) {
notification.fire( new NotificationEvent( CommonConstants.INSTANCE.GitUriCopied( uri ) ) );
}

}
Expand Up @@ -71,6 +71,10 @@ public class RepositoryItemViewImpl
@Inject
public RepositoryItemViewImpl() {
initWidget( uiBinder.createAndBindUi( this ) );

myGitCopyButton.addDomHandler( ( e ) -> presenter.onGitUrlCopied( gitDaemonURI.getText() ),
ClickEvent.getType() );

glueCopy( myGitCopyButton.getElement() );
}

Expand Down
Expand Up @@ -65,4 +65,6 @@ public interface CommonConstants

String Repositories();

String GitUriCopied(final String uri);

}
Expand Up @@ -17,4 +17,5 @@ OrganizationalUnitActionUpdate=Update
OrganizationalUnitActionDelete=Delete
OrganizationalUnitActionCreate=Create
Loading=Loading
Repositories=Repositories
Repositories=Repositories
GitUriCopied=Uri {0} has been successfully copied to the clipboard.
Expand Up @@ -37,8 +37,10 @@
import org.uberfire.ext.widgets.core.client.resources.i18n.CoreConstants;
import org.uberfire.java.nio.base.version.VersionRecord;
import org.uberfire.mocks.CallerMock;
import org.uberfire.mocks.EventSourceMock;
import org.uberfire.mvp.PlaceRequest;
import org.uberfire.mvp.impl.DefaultPlaceRequest;
import org.uberfire.workbench.events.NotificationEvent;

import static org.mockito.Mockito.*;

Expand All @@ -56,6 +58,9 @@ public class RepositoryEditorPresenterTest {
@Mock
private RepositoryServiceEditor repositoryServiceEditor;

@Mock
private EventSourceMock<NotificationEvent> notification;

@Mock
private PlaceManager placeManager;

Expand All @@ -79,8 +84,9 @@ public void before() {
presenter = new RepositoryEditorPresenter( view,
repositoryServiceCaller,
repositoryServiceEditorCaller,
notification,
placeManager,
repositoryController);
repositoryController );

repositoryInfo = new RepositoryInfo( "repository",
"repository",
Expand Down Expand Up @@ -174,4 +180,12 @@ public void testRepositoryRemovedEvent() {
times( 1 ) ).closePlace( eq( place ) );
}

@Test
public void testNotificationFiredWhenGitUriCopied() {
presenter.onGitUrlCopied( "uri" );

verify( notification,
times( 1 ) ).fire( any( NotificationEvent.class ) );
}

}
Expand Up @@ -35,6 +35,8 @@
import org.mockito.stubbing.Answer;
import org.uberfire.backend.vfs.Path;
import org.uberfire.mocks.CallerMock;
import org.uberfire.mocks.EventSourceMock;
import org.uberfire.workbench.events.NotificationEvent;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
Expand All @@ -53,6 +55,9 @@ public class RepositoriesPresenterTest {
@Mock
private RepositoryController repositoryController;

@Mock
private EventSourceMock<NotificationEvent> notification;

private GuvnorStructureContext guvnorStructureContext;

private Collection<Repository> repositories;
Expand Down Expand Up @@ -191,7 +196,7 @@ public void testNewBranchTest() {

//Emulates the context receiving the new branch event for a branch created in r1.
guvnorStructureContext.onNewBranch( new NewBranchEvent( "r1",
"theNewBranch", branchPath, System.currentTimeMillis() ) );
"theNewBranch", branchPath, System.currentTimeMillis() ) );

//Verify that the view was properly populated including the new branch.
//one time at initialization + one time when the new branch was loaded.
Expand All @@ -205,11 +210,14 @@ public void testNewBranchTest() {
}

private RepositoryItemPresenter createItemPresenter( RepositoryItemView itemView,
GuvnorStructureContext guvnorStructureContext,
Repository repository,
String branch ) {
GuvnorStructureContext guvnorStructureContext,
Repository repository,
String branch ) {
//reproduces the initialization of the RepositoryItems performed by the view.
RepositoryItemPresenter itemPresenter = new RepositoryItemPresenter( itemView, guvnorStructureContext, repositoryController );
RepositoryItemPresenter itemPresenter = new RepositoryItemPresenter( itemView,
guvnorStructureContext,
repositoryController,
notification );
itemPresenter.setRepository( repository, branch );
return itemPresenter;
}
Expand Down
Expand Up @@ -29,6 +29,8 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.uberfire.mocks.EventSourceMock;
import org.uberfire.workbench.events.NotificationEvent;

import static org.mockito.Mockito.*;

Expand All @@ -41,6 +43,9 @@ public class RepositoryItemPresenterTest {
@Mock
private RepositoryController repositoryController;

@Mock
private EventSourceMock<NotificationEvent> notification;

@Mock
private RepositoryItemView view;

Expand All @@ -49,9 +54,9 @@ public class RepositoryItemPresenterTest {
@Mock
private Repository repository;

List<PublicURI> publicURIs = new ArrayList<PublicURI>( );
List<PublicURI> publicURIs = new ArrayList<PublicURI>();

List<String> branches = new ArrayList<String>( );
List<String> branches = new ArrayList<String>();

@Mock
PublicURI uri1;
Expand All @@ -71,15 +76,18 @@ public void init() {
when( uri2.getProtocol() ).thenReturn( "test-protocol2" );
when( uri2.getURI() ).thenReturn( "uri2" );

presenter = new RepositoryItemPresenter( view, guvnorStructureContext, repositoryController );
presenter = new RepositoryItemPresenter( view,
guvnorStructureContext,
repositoryController,
notification );
when( repository.getAlias() ).thenReturn( "TestRepo" );

when( repositoryController.canUpdateRepository( repository ) ).thenReturn( false );
when( repositoryController.canDeleteRepository( repository ) ).thenReturn( false );
}

@Test
public void repositoryWithPublicUrisAndBranchesLoadTest( ) {
public void repositoryWithPublicUrisAndBranchesLoadTest() {
publicURIs.add( uri1 );
publicURIs.add( uri2 );
branches.add( "development" );
Expand All @@ -88,7 +96,7 @@ public void repositoryWithPublicUrisAndBranchesLoadTest( ) {
}

@Test
public void repositoryWithPublicUrisAndNoBranchesLoadTest( ) {
public void repositoryWithPublicUrisAndNoBranchesLoadTest() {
publicURIs.add( uri1 );
publicURIs.add( uri2 );
repositoryLoadTest( publicURIs, branches );
Expand All @@ -106,7 +114,8 @@ public void repositoryWithNoPublicUrisAndNoBranchesLoadTest() {
repositoryLoadTest( publicURIs, branches );
}

private void repositoryLoadTest( List<PublicURI> uris, List<String> branches ) {
private void repositoryLoadTest( List<PublicURI> uris,
List<String> branches ) {

when( repository.getAlias() ).thenReturn( "TestRepo" );
when( repository.getPublicURIs() ).thenReturn( publicURIs );
Expand Down Expand Up @@ -148,7 +157,7 @@ public void refreshBranchesTest() {
branches.add( "release" );

//emulates development branch was selected at the moment of the refresh
when( view.getSelectedBranch( ) ).thenReturn( "development" );
when( view.getSelectedBranch() ).thenReturn( "development" );

//check that the repository was loaded properly
repositoryLoadTest( publicURIs, branches );
Expand All @@ -169,4 +178,13 @@ public void refreshBranchesTest() {
//the previously selected branch should have been set again.
verify( view, times( 1 ) ).setSelectedBranch( "development" );
}

@Test
public void testNotificationFiredWhenGitUriCopied() {
presenter.onGitUrlCopied( "uri" );

verify( notification,
times( 1 ) ).fire( any( NotificationEvent.class ) );
}

}

0 comments on commit 920f118

Please sign in to comment.