Commit 5f8d00e3 authored by Romain Bioteau's avatar Romain Bioteau Committed by GitHub

feat(deploy) deploy operation (#1825)

* remove deploy all
* split tenant resources and application resources
* improve deploy... wizard
* fix perf issues when opening the deploy... wizard

Closes BST-452
parent a90ffa0f
......@@ -246,3 +246,4 @@ deployOrganizationTitle=Deploy organization
deployOrganizationPageTitle=Select an organization to deploy
organizationValidationFailedMsg=Following issues have been found
deployingOrganization=Deploying organization '%s'...
organizationDeployed='%s' organization has been deployed
\ No newline at end of file
......@@ -68,7 +68,7 @@ public class OrganizationNameCellEditorValidatorTest {
@Test
public void testInvalidWhenorganiezationAlreadyExists() throws Exception {
final String OrgaToTest = "Myorga";
doReturn(orgaFileStore).when(orgaStore).getChild(OrgaToTest + "." + OrganizationRepositoryStore.ORGANIZATION_EXT);
doReturn(orgaFileStore).when(orgaStore).getChild(OrgaToTest + "." + OrganizationRepositoryStore.ORGANIZATION_EXT, true);
assertThat(validator.isValid(OrgaToTest)).isEqualTo(Messages.nameAlreadyExists);
}
......
......@@ -41,7 +41,7 @@ public class CustomUserInfoNameExpressionProviderTest {
@Before
public void setUp() throws Exception {
provider = new CustomUserInfoNameExpressionProvider(repoStore, ACME);
when(repoStore.getChild(ACME)).thenReturn(fileStore);
when(repoStore.getChild(ACME, true)).thenReturn(fileStore);
when(fileStore.getContent()).thenReturn(organization);
given(organization.getCustomUserInfoDefinitions()).willReturn(definitionsContainer);
}
......
......@@ -60,7 +60,7 @@ public class PublishActiveOrganizationAction implements IEngineAction {
final OrganizationRepositoryStore store = RepositoryManager.getInstance()
.getRepositoryStore(OrganizationRepositoryStore.class);
final OrganizationFileStore organizationFileStore = store
.getChild(artifactId + "." + OrganizationRepositoryStore.ORGANIZATION_EXT);
.getChild(artifactId + "." + OrganizationRepositoryStore.ORGANIZATION_EXT, true);
if (organizationFileStore == null) {
throw new FileNotFoundException(artifactId + "." + OrganizationRepositoryStore.ORGANIZATION_EXT);
}
......
......@@ -60,7 +60,7 @@ public class RefactorActorOperation extends AbstractRefactorOperation<Actor, Act
final String fileName = id + ".conf";
final ProcessConfigurationRepositoryStore processConfStore = RepositoryManager.getInstance().getCurrentRepository()
.getRepositoryStore(ProcessConfigurationRepositoryStore.class);
final ProcessConfigurationFileStore file = processConfStore.getChild(fileName);
final ProcessConfigurationFileStore file = processConfStore.getChild(fileName, true);
Configuration localeConfiguration = null;
Configuration localConfigurationCopy = null;
if (file != null) {
......
......@@ -94,7 +94,7 @@ public class ActorMappingConfigurationWizardPage extends WizardPage
adapterFactory.addAdapterFactory(new ActorMappingAdapterFactory());
deployedOrganization = Optional.ofNullable(RepositoryManager.getInstance()
.getRepositoryStore(OrganizationRepositoryStore.class)
.getChild(String.format("%s.organization", new ActiveOrganizationProvider().getActiveOrganization())))
.getChild(String.format("%s.organization", new ActiveOrganizationProvider().getActiveOrganization()), true))
.map(OrganizationFileStore::getContent);
}
......
......@@ -275,4 +275,5 @@ public class Messages extends NLS {
public static String deployOrganizationPageTitle;
public static String organizationValidationFailedMsg;
public static String deployingOrganization;
public static String organizationDeployed;
}
......@@ -62,6 +62,7 @@ public abstract class PublishOrganizationOperation implements IRunnableWithProgr
protected final Organization organization;
private APISession session;
private boolean flushSession;
private boolean shouldApplyAllProfileToUser = true;
public PublishOrganizationOperation(final Organization organization) {
this.organization = organization;
......@@ -70,11 +71,12 @@ public abstract class PublishOrganizationOperation implements IRunnableWithProgr
public void setSession(final APISession session) {
this.session = session;
}
public PublishOrganizationOperation doNotAllProfileToUsers() {
shouldApplyAllProfileToUser = false;
return this;
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
Assert.isNotNull(organization);
......@@ -111,7 +113,7 @@ public abstract class PublishOrganizationOperation implements IRunnableWithProgr
}
protected boolean shouldApplyAllProfileToUsers() {
return true;
return shouldApplyAllProfileToUser;
}
protected abstract void importOrganization(IdentityAPI identityAPI)
......
......@@ -26,7 +26,7 @@ public class UpdateOrganizationOperation extends PublishOrganizationOperation {
public UpdateOrganizationOperation(Organization organization) {
super(organization);
}
@Override
protected void importOrganization(IdentityAPI identityAPI) throws IOException, OrganizationImportException {
identityAPI.importOrganization(toString(organization), ImportPolicy.MERGE_DUPLICATES);
......
......@@ -92,9 +92,9 @@ public class ActorFilterImplFileStore extends EMFFileStore {
String className = implementation.getImplementationClassname();
ActorFilterSourceRepositoryStore sourceStore = getRepositoryAccessor()
.getRepositoryStore(ActorFilterSourceRepositoryStore.class);
IRepositoryFileStore sourceFile = sourceStore.getChild(className);
IRepositoryFileStore sourceFile = sourceStore.getChild(className, true);
String abstarctClassName = ClassGenerator.getAbstractClassName(className);
IRepositoryFileStore abstractFile = sourceStore.getChild(abstarctClassName);
IRepositoryFileStore abstractFile = sourceStore.getChild(abstarctClassName, true);
if (sourceFile != null && FileActionDialog.confirmDeletionQuestion(sourceFile.getName())) {
sourceFile.delete();
if (abstractFile != null) {
......
......@@ -92,8 +92,8 @@ public class ActorFilterImplRepositoryStore extends AbstractConnectorImplReposit
}
@Override
public ActorFilterImplFileStore getChild(String fileName) {
ActorFilterImplFileStore file = super.getChild(fileName);
public ActorFilterImplFileStore getChild(String fileName, boolean force) {
ActorFilterImplFileStore file = super.getChild(fileName, force);
if (file == null) {
URL url = ActorsPlugin.getDefault().getBundle().getResource(STORE_NAME + "/" + fileName);
if (url != null) {
......
......@@ -61,7 +61,7 @@ public class ActorFilterResourceProvider implements IBOSArchiveFileStoreProvider
final ConnectorDefinition def = filterDefSotre.getDefinition(defId, defVersion, existingDefinitions);
if (def != null) {
final IRepositoryFileStore definition = ((IRepositoryStore<? extends IRepositoryFileStore>) filterDefSotre).getChild(URI.decode(def
.eResource().getURI().lastSegment()));
.eResource().getURI().lastSegment()), true);
if (definition != null && definition.canBeShared()) {
files.add(definition);
......@@ -69,7 +69,7 @@ public class ActorFilterResourceProvider implements IBOSArchiveFileStoreProvider
try {
connectorDefinition = (ConnectorDefinition) definition.getContent();
for (final String jarName : connectorDefinition.getJarDependency()) {
final IRepositoryFileStore jarFile = depStore.getChild(jarName);
final IRepositoryFileStore jarFile = depStore.getChild(jarName, true);
if (jarFile != null) {
files.add(jarFile);
}
......@@ -82,7 +82,7 @@ public class ActorFilterResourceProvider implements IBOSArchiveFileStoreProvider
}
final String implId = mapping.getImplementationId();
final String implVersion = mapping.getImplementationVersion();
final IRepositoryFileStore implementation = filterImplStore.getChild(NamingUtils.toConnectorImplementationFilename(implId, implVersion, true));
final IRepositoryFileStore implementation = filterImplStore.getChild(NamingUtils.toConnectorImplementationFilename(implId, implVersion, true), true);
if (implementation != null && implementation.canBeShared()) {
files.add(implementation);
......@@ -91,13 +91,13 @@ public class ActorFilterResourceProvider implements IBOSArchiveFileStoreProvider
impl = (ConnectorImplementation) implementation.getContent();
final String className = impl.getImplementationClassname();
final String packageName = className.substring(0, className.lastIndexOf("."));
final IRepositoryFileStore packageFileStore = filterSourceStore.getChild(packageName);
final IRepositoryFileStore packageFileStore = filterSourceStore.getChild(packageName, true);
if (packageFileStore != null) {
files.add(packageFileStore);
}
for (final String jarName : impl.getJarDependencies().getJarDependency()) {
final IRepositoryFileStore jarFile = depStore.getChild(jarName);
final IRepositoryFileStore jarFile = depStore.getChild(jarName, true);
if (jarFile != null) {
files.add(jarFile);
}
......
......@@ -16,15 +16,21 @@ package org.bonitasoft.studio.actors.repository;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import org.bonitasoft.engine.session.APISession;
import org.bonitasoft.studio.actors.ActorsPlugin;
import org.bonitasoft.studio.actors.model.organization.DocumentRoot;
import org.bonitasoft.studio.actors.model.organization.Organization;
import org.bonitasoft.studio.actors.model.organization.OrganizationFactory;
import org.bonitasoft.studio.actors.model.organization.util.OrganizationXMLProcessor;
import org.bonitasoft.studio.actors.operation.CleanPublishOrganizationOperation;
import org.bonitasoft.studio.actors.operation.PublishOrganizationOperation;
import org.bonitasoft.studio.actors.operation.UpdateOrganizationOperation;
import org.bonitasoft.studio.actors.styler.ActiveOrganizationStyler;
import org.bonitasoft.studio.actors.ui.handler.DeployOrganizationHandler;
import org.bonitasoft.studio.actors.ui.wizard.ManageOrganizationWizard;
......@@ -36,18 +42,16 @@ import org.bonitasoft.studio.common.repository.core.ActiveOrganizationProvider;
import org.bonitasoft.studio.common.repository.filestore.EMFFileStore;
import org.bonitasoft.studio.common.repository.model.IDeployable;
import org.bonitasoft.studio.common.repository.model.IRenamable;
import org.bonitasoft.studio.common.repository.model.ITenantResource;
import org.bonitasoft.studio.ui.i18n.Messages;
import org.bonitasoft.studio.ui.validator.ExtensionSupported;
import org.bonitasoft.studio.ui.validator.FileNameValidator;
import org.bonitasoft.studio.ui.validator.InputValidatorWrapper;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
......@@ -70,7 +74,7 @@ import com.google.common.io.Files;
/**
* @author Romain Bioteau
*/
public class OrganizationFileStore extends EMFFileStore implements IDeployable, IRenamable {
public class OrganizationFileStore extends EMFFileStore implements IDeployable, IRenamable, ITenantResource {
private static final String DEPLOY_ORGA_CMD = "org.bonitasoft.studio.organization.publish";
private static final String ORGANIZATION_EXT = ".organization";
......@@ -215,7 +219,8 @@ public class OrganizationFileStore extends EMFFileStore implements IDeployable,
public Optional<String> retrieveNewName() {
String currentName = getDisplayName();
OrganizationRepositoryStore repositoryStore = (OrganizationRepositoryStore) store;
FileNameValidator validator = new FileNameValidator(repositoryStore, ExtensionSupported.ORGANIZATION, currentName);
FileNameValidator validator = new FileNameValidator(repositoryStore, ExtensionSupported.ORGANIZATION,
currentName);
InputDialog dialog = new InputDialog(Display.getDefault().getActiveShell(), Messages.rename,
Messages.renameFile, currentName, new InputValidatorWrapper(validator));
if (dialog.open() == Dialog.OK
......@@ -235,24 +240,29 @@ public class OrganizationFileStore extends EMFFileStore implements IDeployable,
return styledString;
}
/**
* build the current Organization if it is the active one, else does nothing.
*/
@Override
public void build(IPath buildPath, IProgressMonitor monitor) throws CoreException {
if (isActiveOrganization()) {
IPath orgaFolderPath = buildPath.append("organization");
IFolder orgaFolder = getRepository().getProject()
.getFolder(orgaFolderPath.makeRelativeTo(getRepository().getProject().getFullPath()));
if (!orgaFolder.exists()) {
orgaFolder.create(true, true, new NullProgressMonitor());
}
getResource().copy(orgaFolderPath.append(getName()), false, new NullProgressMonitor());
}
}
public boolean isActiveOrganization() {
return Objects.equals(activeOrganizationProvider.getActiveOrganization(), getContent().getName());
}
@Override
public IStatus deploy(APISession session, IProgressMonitor monitor) {
final String activeOrganization = activeOrganizationProvider.getActiveOrganization();
Organization organization = getContent();
PublishOrganizationOperation operation = Objects.equals(organization.getName(), activeOrganization)
? new UpdateOrganizationOperation(organization)
: new CleanPublishOrganizationOperation(organization);
if(!PlatformUtil.isACommunityBonitaProduct()) {
operation.doNotAllProfileToUsers();
}
operation.setSession(session);
try {
operation.run(monitor);
return ValidationStatus.info(String.format(org.bonitasoft.studio.actors.i18n.Messages.organizationDeployed,
organization.getName()));
} catch (InvocationTargetException | InterruptedException e) {
BonitaStudioLog.error(e);
return new Status(IStatus.ERROR, ActorsPlugin.PLUGIN_ID, "An error occured while depoying the Organization", e);
}
}
}
......@@ -41,7 +41,7 @@ class OrganizationNameCellEditorValidator implements ICellEditorValidator {
}
//Check unicity
final OrganizationRepositoryStore store = getOrganizationStore();
if (store.getChild(toValidate + "." + OrganizationRepositoryStore.ORGANIZATION_EXT) != null) {
if (store.getChild(toValidate + "." + OrganizationRepositoryStore.ORGANIZATION_EXT, true) != null) {
return Messages.nameAlreadyExists ;
}
return null;
......
......@@ -84,7 +84,7 @@ public class DeployOrganizationHandler {
private Optional<Organization> findOrganizationToDeploy(RepositoryAccessor repositoryAccessor, String organization) {
return Optional.ofNullable(organization)
.map(repositoryAccessor.getRepositoryStore(OrganizationRepositoryStore.class)::getChild)
.map(orga -> repositoryAccessor.getRepositoryStore(OrganizationRepositoryStore.class).getChild(orga, true))
.map(OrganizationFileStore::getContent);
}
......
......@@ -103,7 +103,7 @@ public class ImportOrganizationHandler extends AbstractHandler {
} catch (final Exception e) {
BonitaStudioLog.error(e);
final OrganizationFileStore file = organizationStore.getChild(new File(filePath).getName()
.replace(".xml", "." + OrganizationRepositoryStore.ORGANIZATION_EXT));
.replace(".xml", "." + OrganizationRepositoryStore.ORGANIZATION_EXT), true);
if (file != null) {
file.delete();
}
......
......@@ -52,7 +52,7 @@ public class InstallOrganizationHandler extends AbstractHandler {
final String id = event.getParameter("artifact");
final IRepositoryStore<?> organizationStore = RepositoryManager.getInstance()
.getRepositoryStore(OrganizationRepositoryStore.class);
IRepositoryFileStore file = organizationStore.getChild(id);
IRepositoryFileStore file = organizationStore.getChild(id, true);
if (file == null) {
BonitaStudioLog.warning("Organization : " + id + " not found !", ActorsPlugin.PLUGIN_ID);
final List<? extends IRepositoryFileStore> organizationFiles = organizationStore.getChildren();
......
......@@ -66,7 +66,7 @@ public class FilterImplementationWizard extends ConnectorImplementationWizard {
protected void initialize() {
implStore = RepositoryManager.getInstance().getRepositoryStore(ActorFilterImplRepositoryStore.class) ;
if(getOriginalImplementation() != null){
fileStore = implStore.getChild(NamingUtils.toConnectorImplementationFilename(getOriginalImplementation().getImplementationId(),getOriginalImplementation().getImplementationVersion(),true)) ;
fileStore = implStore.getChild(NamingUtils.toConnectorImplementationFilename(getOriginalImplementation().getImplementationId(),getOriginalImplementation().getImplementationVersion(),true), true) ;
}
defStore = RepositoryManager.getInstance().getRepositoryStore(ActorFilterDefRepositoryStore.class) ;
sourceStore = (ActorFilterSourceRepositoryStore) RepositoryManager.getInstance().getRepositoryStore(ActorFilterSourceRepositoryStore.class) ;
......
......@@ -195,7 +195,7 @@ public class ManageOrganizationWizard extends Wizard {
}
if (!exists) {
final IRepositoryFileStore f = store
.getChild(orga.getName() + "." + OrganizationRepositoryStore.ORGANIZATION_EXT);
.getChild(orga.getName() + "." + OrganizationRepositoryStore.ORGANIZATION_EXT, true);
if (f != null) {
f.delete();
}
......@@ -215,7 +215,7 @@ public class ManageOrganizationWizard extends Wizard {
}
final String fileName = organization.getName() + "."
+ OrganizationRepositoryStore.ORGANIZATION_EXT;
IRepositoryFileStore file = store.getChild(fileName);
IRepositoryFileStore file = store.getChild(fileName, true);
Organization oldOrga = null;
if (file == null) {
file = store.createRepositoryFileStore(fileName);
......
......@@ -45,7 +45,7 @@ public class CustomUserInfoNameExpressionProvider implements IExpressionNaturePr
@Override
public Expression[] getExpressions(final EObject context) {
final OrganizationFileStore organizationFileStore = store.getChild(activeOrgFileName);
final OrganizationFileStore organizationFileStore = store.getChild(activeOrgFileName, true);
final Organization organization = organizationFileStore.getContent();
final CustomUserInfoDefinitions infoDefContainer = organization.getCustomUserInfoDefinitions();
return getExpressions(infoDefContainer);
......
......@@ -86,7 +86,7 @@ public abstract class SelectOrganizationWizardPage extends WizardPage implements
organizationCombo.setInput(organizationStore.getChildren());
IRepositoryFileStore defaultOrganization = organizationStore
.getChild(activeOrganizationProvider.getActiveOrganization() + "." + OrganizationRepositoryStore.ORGANIZATION_EXT);
.getChild(activeOrganizationProvider.getActiveOrganization() + "." + OrganizationRepositoryStore.ORGANIZATION_EXT, true);
if (defaultOrganization == null) {
final List<OrganizationFileStore> orga = organizationStore.getChildren();
if (!orga.isEmpty()) {
......
......@@ -55,7 +55,7 @@ public class SelectUserFilterDefinitionWizardPage extends SelectFilterDefinition
if(selection != null){
ActorFilterDefRepositoryStore store = (ActorFilterDefRepositoryStore) RepositoryManager.getInstance().getRepositoryStore(ActorFilterDefRepositoryStore.class) ;
String fileName = selection.eResource().getURI().lastSegment() ;
IRepositoryFileStore file = store.getChild(fileName) ;
IRepositoryFileStore file = store.getChild(fileName, true) ;
if(FileActionDialog.confirmDeletionQuestion(fileName)){
file.delete() ;
}
......
......@@ -72,6 +72,7 @@ Import-Package: javax.annotation;version="1.2.0",
org.bonitasoft.engine.api,
org.bonitasoft.engine.bpm.bar,
org.bonitasoft.engine.exception,
org.bonitasoft.engine.session,
org.eclipse.e4.core.di.annotations,
org.eclipse.e4.ui.workbench.renderers.swt,
org.osgi.service.event;version="1.3.0"
......
<?xml version="1.0" encoding="ASCII"?>
<fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmi:id="_H5K40KiaEemxstQeqTvXDA">
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_KLgu4KiaEemxstQeqTvXDA" featurename="commands" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Command" xmi:id="_OmsgwKiaEemxstQeqTvXDA" elementId="org.bonitasoft.studio.application.command.deployProject" commandName="%deployProject"/>
<elements xsi:type="commands:Command" xmi:id="_yyuWEK0kEem8O8pWB8c8Fg" elementId="org.bonitasoft.studio.application.command.deployArtifacts" commandName="%deployArtifacts" description="Deploy a subpart of the project"/>
</fragments>
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_NR20wKiaEemxstQeqTvXDA" featurename="handlers" parentElementId="org.eclipse.e4.legacy.ide.application">
<elements xsi:type="commands:Handler" xmi:id="_R7mAAKiaEemxstQeqTvXDA" elementId="org.bonitasoft.studio.application.handler.deployProject" contributionURI="bundleclass://org.bonitasoft.studio.application/org.bonitasoft.studio.application.handler.DeployProjectHandler" command="_OmsgwKiaEemxstQeqTvXDA"/>
<elements xsi:type="commands:Handler" xmi:id="_6p_NQK0kEem8O8pWB8c8Fg" elementId="org.bonitasoft.studio.application.handler.deployArtifacts" contributionURI="bundleclass://org.bonitasoft.studio.application/org.bonitasoft.studio.application.handler.DeployArtifactsHandler" command="_yyuWEK0kEem8O8pWB8c8Fg"/>
</fragments>
</fragment:ModelFragments>
......@@ -74,4 +74,7 @@ selectNone=Select none
searchArtifact=Search artifacts
expandAll=Expand all
collapseAll=Collapse all
buildErrorTitle=Build error
\ No newline at end of file
buildErrorTitle=Build error
build=Build
deployStatus=Deploy status
deployStatusMessage=Deploy status below:
\ No newline at end of file
......@@ -58,5 +58,4 @@ export=Export...
rename=Rename...
newWithWizard=New...
showInSystemExplorer=Show in system explorer
deployProject=Deploy project
deployArtifacts=Deploy...
\ No newline at end of file
......@@ -514,31 +514,6 @@
checkEnabled="true">
</visibleWhen>
</command>
<command
commandId="org.bonitasoft.studio.application.command.deployProject"
style="push">
<visibleWhen
checkEnabled="false">
<with
variable="activeMenuSelection">
<and>
<count
value="1">
</count>
<or>
<iterate>
<instanceof
value="org.eclipse.core.resources.IProject">
</instanceof>
<test
property="org.bonitasoft.studio.application.isBonitaProject">
</test>
</iterate>
</or>
</and>
</with>
</visibleWhen>
</command>
<command
commandId="org.bonitasoft.studio.application.command.deployArtifacts"
style="push">
......
package org.bonitasoft.studio.application.handler;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.common.repository.model.IDeployable;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.common.repository.model.IRepositoryStore;
import org.eclipse.swt.widgets.Shell;
import org.junit.Before;
import org.junit.Test;
public class DeployProjectHandlerTest {
RepositoryAccessor repositoryAccessor;
@Before
public void init() {
repositoryAccessor = mock(RepositoryAccessor.class);
Repository repository = initRepository();
when(repositoryAccessor.getCurrentRepository()).thenReturn(repository);
}
private Repository initRepository() {
Repository repository = mock(Repository.class);
List<IRepositoryStore<? extends IRepositoryFileStore>> stores = initRepositoryStores();
when(repository.getAllStores()).thenReturn(stores);
return repository;
}
private List<IRepositoryStore<? extends IRepositoryFileStore>> initRepositoryStores() {
IRepositoryStore<DeployableFileStore> deployableRepositoryStore = mock(IRepositoryStore.class);
DeployableFileStore deployableFileStore1 = mock(DeployableFileStore.class);
when(deployableFileStore1.getName()).thenReturn("deployableFileStore1");
DeployableFileStore deployableFileStore2 = mock(DeployableFileStore.class);
when(deployableFileStore2.getName()).thenReturn("deployableFileStore2");
when(deployableRepositoryStore.getChildren()).thenReturn(Arrays.asList(deployableFileStore1, deployableFileStore2));
IRepositoryStore<NotDeployableFileStore> NotBuildableRepositoryStore = mock(IRepositoryStore.class);
NotDeployableFileStore notDeployableFileStore = mock(NotDeployableFileStore.class);
when(notDeployableFileStore.getName()).thenReturn("notDeployableeFileStore");
when(NotBuildableRepositoryStore.getChildren()).thenReturn(Arrays.asList(notDeployableFileStore));
return Arrays.asList(deployableRepositoryStore, NotBuildableRepositoryStore);
}
@Test
public void should_retrieve_deployable_artifacts() {
Collection<IRepositoryFileStore> fileStoresToBuild = new DeployProjectHandler()
.retrieveArtifactsToDeploy(mock(Shell.class), repositoryAccessor);
assertThat(fileStoresToBuild).hasSize(2);
assertThat(fileStoresToBuild).extracting(IRepositoryFileStore::getName)
.containsExactlyInAnyOrder("deployableFileStore1", "deployableFileStore2");
}
}
abstract class DeployableFileStore implements IDeployable, IRepositoryFileStore {
}
abstract class NotDeployableFileStore implements IRepositoryFileStore {
}