AbstractMuleDeployerMojo extends AbstractGenericMojo { protected Deployment getDeploymentConfiguration() throws DeploymentException { List<Deployment> deployments = getProjectInformation().getDeployments().stream().filter(Objects::nonNull) .collect(Collectors.toList()); if (deployments.isEmpty()) { throw new DeploymentException("No deployment configuration was defined. Aborting."); } Deployment deploymentConfiguration = deployments.get(0); deploymentConfiguration.setDefaultValues(mavenProject); return deploymentConfiguration; }  @Override void execute(); MavenResolverMetadata getMetadata(); void initializeAnypointDeploymentEnvironment();  }
@Test public void setDeploymentAllDeploymentNullTest() throws DeploymentException { expectedException.expect(DeploymentException.class); expectedException.expectMessage("No deployment configuration was defined. Aborting."); mojoSpy.setAgentDeployment(null); mojoSpy.setArmDeployment(null); mojoSpy.setCloudHubDeployment(null); mojoSpy.setStandaloneDeployment(null); mojoSpy.setClusterDeployment(null); mojoSpy.getDeploymentConfiguration(); }
@Test public void setDeploymentOneDeploymentNotNullTest() throws DeploymentException { mojoSpy.setAgentDeployment(null); mojoSpy.setArmDeployment(null); mojoSpy.setCloudHubDeployment(null); mojoSpy.setStandaloneDeployment(null); ClusterDeployment clusterDeploymentMock = mock(ClusterDeployment.class); doNothing().when(clusterDeploymentMock).setDefaultValues(projectMock); mojoSpy.setClusterDeployment(clusterDeploymentMock); assertThat("The resolved deployment is not the expected", mojoSpy.getDeploymentConfiguration(), equalTo(clusterDeploymentMock)); }
@Test public void setDeploymentOneDeploymentAndDistributionManagementTest() throws DeploymentException { mojoSpy.setAgentDeployment(null); mojoSpy.setArmDeployment(null); mojoSpy.setStandaloneDeployment(null); mojoSpy.setClusterDeployment(null); CloudHubDeployment cloudHubDeploymentMock = mock(CloudHubDeployment.class); doNothing().when(cloudHubDeploymentMock).setDefaultValues(projectMock); mojoSpy.setCloudHubDeployment(cloudHubDeploymentMock); DistributionManagement distributionManagementMock = mock(DistributionManagement.class); DeploymentRepository deploymentRepositoryMock = mock(DeploymentRepository.class); Settings settingsMock = mock(Settings.class); when(deploymentRepositoryMock.getUrl()) .thenReturn("https: when(distributionManagementMock.getRepository()).thenReturn(deploymentRepositoryMock); when(settingsMock.getServer(any())).thenReturn(mock(Server.class)); when(projectMock.getDistributionManagement()).thenReturn(distributionManagementMock); Properties systemProperties = new Properties(); MavenExecutionRequest mavenExecutionRequestMock = mock(MavenExecutionRequest.class); when(mavenExecutionRequestMock.getSystemProperties()).thenReturn(systemProperties); when(sessionMock.getRequest()).thenReturn(mavenExecutionRequestMock); when(sessionMock.getSettings()).thenReturn(settingsMock); assertThat("The resolved deployment is not the expected", mojoSpy.getDeploymentConfiguration(), equalTo(cloudHubDeploymentMock)); }