Skip to content

Commit

Permalink
Merge pull request #163 from CAST-Extend/WEBITOOLS-192_Add_option_to_…
Browse files Browse the repository at this point in the history
…Preserve_preconfigured_module_generation_type

Webitools 192 add option to preserve preconfigured module generation type
  • Loading branch information
leon2Meudon92 committed Jul 24, 2023
2 parents 86f9e89 + 3d4ac45 commit 864872a
Show file tree
Hide file tree
Showing 16 changed files with 182 additions and 36 deletions.
14 changes: 10 additions & 4 deletions aip-console-jenkins/README.md
Expand Up @@ -263,8 +263,10 @@ The Add Version step provides the following parameters :
technologies JEE and DOTNET as well.<u>Has no effect if `Rescan` is checked</u>.
* *Enable Data Safety Investigation*: Enables the data safety investigation
objective for the version.
* *Module Generation Type*: How the module generation will be handled by AIP Console. Either "Full Content" (default), "
* *Module Generation Type*: How the module generation will be handled by AIP Console. Either "Preserve Configured" (
default), or '"Full Content", "
Analysis Unit module" or "Technology Module".
* **NOTE** Use Preserve Configured option to keep your existing module generation type unchanged.

Under `Advanced Settings` you will find the following parameters :

Expand Down Expand Up @@ -334,11 +336,15 @@ Under `Advanced Settings` you will find the following parameters :
The Analyze step provides the following parameters :

* *Application Name* (**required**): The name of the application for which the analysis will be run.
* *Version Name*: The name of the version to Analyze. <u>If left blank</u>, the analyzed version will <u>be the latest Delivered Version</u>. If no new Delivered Version Exists, <u>it will use the Current Version</u>.
* *Version Name*: The name of the version to Analyze. <u>If left blank</u>, the analyzed version will <u>be the latest
Delivered Version</u>. If no new Delivered Version Exists, <u>it will use the Current Version</u>.
* *Snapshot*: Whether Snapshots should be created after Analysis.
* *Publish to Imaging*: Publish to Imaging if Imaging is configured with AIP Console
* *Publish to the Health Dashboard* : When checked, consolidates snapshots and publishes data to the Health Dashboards. Checked by default.
* *Module Generation Type*: How the module generation will be handled by AIP Console. Either "Full Content" (default), "Analysis Unit module" or "Technology Module".
* *Publish to the Health Dashboard* : When checked, consolidates snapshots and publishes data to the Health Dashboards.
Checked by default.
* *Module Generation Type*: How the module generation will be handled by AIP Console. Either "Preserve Configured" (
default), or '"Full Content", "Analysis Unit module" or "Technology Module".
* **NOTE** Use Preserve Configured option to keep your existing module generation type unchanged..

Under `Advanced Settings` you will find the following parameters :

Expand Down
2 changes: 1 addition & 1 deletion aip-console-jenkins/pom.xml
Expand Up @@ -14,7 +14,7 @@
<packaging>hpi</packaging>
<properties>
<!-- Console Tools version -->
<revision>2.9.0-SNAPSHOT</revision>
<revision>2.9.1-RC</revision>
<!-- Baseline Jenkins version you use to build the plugin. Users must have this version or newer to run. -->
<jenkins.version>2.60.3</jenkins.version>
<java.level>8</java.level>
Expand Down
Expand Up @@ -118,7 +118,7 @@ public class AddVersionBuilder extends BaseActionBuilder implements SimpleBuildS
@Nullable
private String snapshotName = "";

private String moduleGenerationType = ModuleGenerationType.FULL_CONTENT.toString();
private String moduleGenerationType;

@DataBoundConstructor
public AddVersionBuilder(String applicationName, String filePath) {
Expand Down
Expand Up @@ -30,6 +30,7 @@
</f:entry>
<f:entry title="${%moduleGenerationType}" description="${%moduleGenerationType.descr}">
<select name="moduleGenerationType" field="moduleGenerationType">
<option value="preserve_configured">Preserve configured</option>
<option value="full_content">Full content</option>
<option value="one_per_au">Analysis unit module</option>
<option value="one_per_techno">Technology module</option>
Expand Down
Expand Up @@ -17,6 +17,7 @@
</f:entry>
<f:entry title="${%moduleGenerationType}" description="${%moduleGenerationType.descr}">
<select name="moduleGenerationType" field="moduleGenerationType">
<option value="preserve_configured">Preserve configured</option>
<option value="full_content">Full content</option>
<option value="one_per_au">Analysis unit module</option>
<option value="one_per_techno">Technology module</option>
Expand Down
Expand Up @@ -64,6 +64,7 @@ public void setUp() throws Exception {
doReturn(ApiInfoDto.builder().apiVersion("1.12.0-DEV").build())
.when(restApiService).getAipConsoleApiInfo();
doReturn(BaseBuilderTest.TEST_APP).when(applicationService).getApplicationFromGuid(BaseBuilderTest.TEST_APP_NAME);
doReturn(BaseBuilderTest.TEST_APP).when(applicationService).getApplicationFromGuid(BaseBuilderTest.TEST_APP_GUID);
}

@Test
Expand All @@ -73,7 +74,7 @@ public void testAddVersionStepToJob() throws Exception {
AddVersionBuilder job = new AddVersionBuilder(BaseBuilderTest.TEST_APP_NAME, BaseBuilderTest.TEST_ARCHIVE_NAME);
job.setDomainName("");
job.setCssServerName("");
job.setModuleGenerationType(ModuleGenerationType.FULL_CONTENT.toString());
job.setModuleGenerationType(ModuleGenerationType.PRESERVE_CONFIGURED.toString());
jenkins.assertEqualDataBoundBeans(job, project.getBuildersList().get(0));
}

Expand All @@ -100,7 +101,7 @@ public void testBuildFreestyleDefaultOk() throws Exception {
doReturn(BaseBuilderTest.TEST_APP)
.when(applicationService).getApplicationFromName(BaseBuilderTest.TEST_APP_NAME);
doReturn(true)
.when(uploadService).uploadInputStream(eq(BaseBuilderTest.TEST_APP_NAME), anyString(), anyLong(), isA(InputStream.class));
.when(uploadService).uploadInputStream(eq(BaseBuilderTest.TEST_APP_GUID), anyString(), anyLong(), isA(InputStream.class));
doReturn(BaseBuilderTest.TEST_JOB_GUID)
.when(jobsService).startAddVersionJob(any(JobRequestBuilder.class));
doReturn(JobState.COMPLETED)
Expand Down Expand Up @@ -211,7 +212,7 @@ public void testBuildErrorCreatingAnalyzeJob() throws Exception {
doReturn(BaseBuilderTest.TEST_APP)
.when(applicationService).getApplicationFromName(BaseBuilderTest.TEST_APP_NAME);
doReturn(true)
.when(uploadService).uploadInputStream(eq(BaseBuilderTest.TEST_APP_NAME), anyString(), anyLong(), isA(InputStream.class));
.when(uploadService).uploadInputStream(eq(BaseBuilderTest.TEST_APP_GUID), anyString(), anyLong(), isA(InputStream.class));
doThrow(new JobServiceException("fake exception"))
.when(jobsService).startAddVersionJob(any(JobRequestBuilder.class));

Expand All @@ -230,7 +231,7 @@ public void testBuildAnalyseResultCancelled() throws Exception {
doReturn(BaseBuilderTest.TEST_APP)
.when(applicationService).getApplicationFromName(BaseBuilderTest.TEST_APP_NAME);
doReturn(true)
.when(uploadService).uploadInputStream(eq(BaseBuilderTest.TEST_APP_NAME), anyString(), anyLong(), isA(InputStream.class));
.when(uploadService).uploadInputStream(eq(BaseBuilderTest.TEST_APP_GUID), anyString(), anyLong(), isA(InputStream.class));
doReturn(BaseBuilderTest.TEST_JOB_GUID)
.when(jobsService).startAddVersionJob(any(JobRequestBuilder.class));
doReturn(JobState.CANCELED)
Expand Down
@@ -0,0 +1,65 @@
package io.jenkins.plugins.aipconsole;

import com.castsoftware.aip.console.tools.core.dto.ModuleGenerationType;
import com.castsoftware.aip.console.tools.core.dto.VersionDto;
import com.castsoftware.aip.console.tools.core.dto.VersionStatus;
import com.castsoftware.aip.console.tools.core.dto.jobs.JobRequestBuilder;
import com.castsoftware.aip.console.tools.core.dto.jobs.JobState;
import com.google.common.collect.Sets;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.Set;
import java.util.concurrent.Future;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class AnalyzeBuilderTest extends BaseBuilderTest {
@InjectMocks
private AnalyzeBuilder analyzeBuilder;

@Before
public void setUp() throws Exception {
super.startUp();
analyzeBuilder = new AnalyzeBuilder(BaseBuilderTest.TEST_APP_NAME);
MockitoAnnotations.initMocks(this);
doReturn(BaseBuilderTest.TEST_APP).when(applicationService).getApplicationFromGuid(BaseBuilderTest.TEST_APP_NAME);
when(applicationService.getApplicationFromGuid(TEST_APP_GUID)).thenReturn(BaseBuilderTest.TEST_APP);
}

@Test
public void testAnalyze_WithModulePreserveConfigured() throws Exception {
analyzeBuilder.setVersionName(TEST_VERSION_NAME);
analyzeBuilder.setModuleGenerationType(ModuleGenerationType.PRESERVE_CONFIGURED.toString());
FreeStyleProject project = getProjectWithBuilder(analyzeBuilder);

VersionDto versionDto = Mockito.mock(VersionDto.class);
when(versionDto.getName()).thenReturn(TEST_VERSION_NAME);
when(versionDto.getStatus()).thenReturn(VersionStatus.DELIVERED);
Set<VersionDto> versions = Sets.newHashSet(versionDto);
when(applicationService.getApplicationVersion(TEST_APP_GUID)).thenReturn(versions);

doReturn(BaseBuilderTest.TEST_APP_NAME).when(applicationService).getApplicationGuidFromName(BaseBuilderTest.TEST_APP_NAME);
doReturn(BaseBuilderTest.TEST_APP).when(applicationService).getApplicationFromName(BaseBuilderTest.TEST_APP_NAME);
when(jobsService.startJob(any(JobRequestBuilder.class))).thenReturn(BaseBuilderTest.TEST_JOB_GUID);

doReturn(JobState.COMPLETED).when(jobsService).pollAndWaitForJobFinished(eq(BaseBuilderTest.TEST_JOB_GUID), any(), any(), any(), eq(null));

Future<FreeStyleBuild> futureBuild = project.scheduleBuild2(0);
FreeStyleBuild build = jenkins.assertBuildStatus(Result.SUCCESS, futureBuild.get());

//jenkins.assertLogContains(OnbordingApplicationBuilder_DescriptorImpl_FastScanForbidden(), build);
}
}
Expand Up @@ -27,6 +27,7 @@ public class BaseBuilderTest {
protected static final String TEST_KEY = "key";
protected static final String TEST_CONTENT = "test";
protected static final String TEST_APP_NAME = "appName";
protected static final String TEST_VERSION_NAME = "versionName";
protected static final String TEST_APP_GUID = "app-GUID";
protected static final String TEST_ARCHIVE_NAME = "archive.zip";
protected static final String TEST_FOLDER_NAME = "testFolder";
Expand All @@ -36,7 +37,7 @@ public class BaseBuilderTest {

protected static final String TEST_UPLOAD_FILE_PATH = "C:\\Report\\model.CASTArchitect";
protected static final String TEST_REPORT_PATH = "C:\\Report";
protected static final ApplicationDto TEST_APP = ApplicationDto.builder().name(TEST_APP_NAME).guid(TEST_APP_NAME).inPlaceMode(false).build();
protected static final ApplicationDto TEST_APP = ApplicationDto.builder().name(TEST_APP_NAME).guid(TEST_APP_GUID).inPlaceMode(false).build();
@Rule
public JenkinsRule jenkins = new JenkinsRule();

Expand Down
6 changes: 4 additions & 2 deletions aip-console-tools-cli/README.md
Expand Up @@ -263,7 +263,8 @@ The available options are :
snapshot or from publishing application to the Health dashboard. *default* : false
* `--module-option` (optional) Generates a user defined module option forr either technology module or analysis unit
module.
Possible value is one of: full_content, one_per_au, one_per_techno
Possible value is one of: preserve_configured, full_content, one_per_au, one_per_techno.
* **NOTE** Use Preserve Configured option to keep your existing module generation type unchanged.
*NOTE*: When creating a version, if a previous version exists, it's configuration will be cloned to the new version,
but the new source will be used for analysis.
Expand Down Expand Up @@ -338,7 +339,8 @@ The available options are :
* `--consolidation` or `--upload-application` (optional) : When sets to false, this prevents from consolidating
* `--module-option` (optional) Generates a user defined module option forr either technology module or analysis unit
module.
Possible value is one of: full_content, one_per_au, one_per_techno
Possible value is one of: preserve_configured, full_content, one_per_au, one_per_techno
* **NOTE** Use Preserve Configured option to keep your existing module generation type unchanged.
* snapshot or from publishing application to the Health dashboard. *default* : false
Expand Down
Expand Up @@ -92,7 +92,7 @@ public class AnalyzeCommand extends BasicCollable {
defaultValue = "true", fallbackValue = "true")
private boolean consolidation = true;

@CommandLine.Option(names = "--module-option", description = "Generates a user defined module option forr either technology module or analysis unit module. Possible value is one of: full_content, one_per_au, one_per_techno")
@CommandLine.Option(names = "--module-option", description = "Generates a user defined module option for either technology module or analysis unit module. Possible value is one of: full_content, one_per_au, one_per_techno")
private ModuleGenerationType moduleGenerationType;

public AnalyzeCommand(RestApiService restApiService, JobsService jobsService, ApplicationService applicationService) {
Expand Down Expand Up @@ -177,6 +177,7 @@ public Integer processCallCommand() throws Exception {
} else {
builder.endStep(Constants.ANALYZE);
}

applicationService.updateModuleGenerationType(applicationGuid, builder, moduleGenerationType, false);

builder.versionName(versionToAnalyze.getName())
Expand Down
Expand Up @@ -11,6 +11,7 @@
import com.castsoftware.aip.console.tools.core.utils.Constants;
import com.castsoftware.aip.console.tools.factories.SpringAwareCommandFactory;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -151,6 +152,18 @@ protected ApplicationDto getTestApplicationMock() {
return applicationDto;
}

protected CommandLine.Model.OptionSpec getCommandLineOption(CommandLine.Model.CommandSpec spec, String optionName) {
//Checks that the initial value set for the module type is full content
List<CommandLine.Model.ArgSpec> argsSpec = spec.args();
for (CommandLine.Model.ArgSpec cmdArg : argsSpec) {
CommandLine.Model.OptionSpec optionSpec = (CommandLine.Model.OptionSpec) cmdArg;
if (StringUtils.equalsAny(optionName, optionSpec.names())) {
return optionSpec;
}
}
return null;
}

protected void runStringArgs(Callable<Integer> command, String[] args) {
try {
cliToTest = new CommandLine(command, springAwareCommandFactory);
Expand Down
Expand Up @@ -2,6 +2,7 @@

import com.castsoftware.aip.console.tools.commands.AnalyzeCommand;
import com.castsoftware.aip.console.tools.core.dto.DebugOptionsDto;
import com.castsoftware.aip.console.tools.core.dto.ModuleGenerationType;
import com.castsoftware.aip.console.tools.core.dto.VersionDto;
import com.castsoftware.aip.console.tools.core.dto.VersionStatus;
import com.castsoftware.aip.console.tools.core.dto.jobs.JobExecutionDto;
Expand All @@ -28,8 +29,10 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
Expand Down Expand Up @@ -220,4 +223,51 @@ public void testAnalyzeCommand_JobCanceled() throws ApplicationServiceException,
assertThat(spec, is(notNullValue()));
assertThat(exitCode, is(Constants.RETURN_JOB_CANCELED));
}

@Test
public void testAnalyzeCommand_WithModulePreserveConfigured() throws ApplicationServiceException, UploadException, JobServiceException, PackagePathInvalidException {
boolean verbose = true;
String[] args = new String[]{"--apikey", TestConstants.TEST_API_KEY,
"--app-name=" + TestConstants.TEST_CREATRE_APP,
"--version-name", TestConstants.TEST_VERSION_NAME,
"-S", "--process-imaging",
"--module-option", ModuleGenerationType.PRESERVE_CONFIGURED.toString()};

when(applicationService.getApplicationFromName(TestConstants.TEST_CREATRE_APP)).thenReturn(TestConstants.TEST_APP);
//Set<VersionDto> versions =
VersionDto versionDto = new VersionDto();
versionDto.setName(TestConstants.TEST_VERSION_NAME);
versionDto.setStatus(VersionStatus.DELIVERED);
when(applicationService.getApplicationVersion(TestConstants.TEST_APP_GUID)).thenReturn(Sets.newSet(versionDto));
when(jobsService.startJob(any(JobRequestBuilder.class))).thenReturn(TestConstants.TEST_JOB_GUID);
DebugOptionsDto debugOptions = Mockito.mock(DebugOptionsDto.class);
when(debugOptions.isActivateAmtMemoryProfile()).thenReturn(false);
when(applicationService.getDebugOptions(TestConstants.TEST_APP_GUID)).thenReturn(debugOptions);

JobExecutionDto jobStatus = new JobExecutionDto();
jobStatus.setAppGuid(TestConstants.TEST_APP_GUID);
jobStatus.setState(JobState.COMPLETED);
jobStatus.setCreatedDate(new Date());
jobStatus.setAppName(TestConstants.TEST_CREATRE_APP);
when(jobsService.pollAndWaitForJobFinished(anyString(), any(Function.class), anyBoolean())).thenReturn(jobStatus);

runStringArgs(analyzeCommand, args);

CommandLine.Model.CommandSpec spec = cliToTest.getCommandSpec();
assertThat(spec, is(notNullValue()));

//Checks that the initial value set for the module type is full content
CommandLine.Model.OptionSpec optionSpec = getCommandLineOption(spec, "--module-option");
assertThat(optionSpec.hasInitialValue(), is(true));
assertThat(optionSpec.mapFallbackValue(), is("__unspecified__"));
assertThat(optionSpec.initialValue(), is(nullValue())); //not initialized in the command
assertThat(optionSpec.typedValues(), hasSize(1));
ModuleGenerationType typeInfo = (ModuleGenerationType) optionSpec.typedValues().get(0);
assertThat(typeInfo, is(ModuleGenerationType.PRESERVE_CONFIGURED));

// What you set is what you get
assertThat(analyzeCommand.getModuleGenerationType(), is(ModuleGenerationType.PRESERVE_CONFIGURED));
assertThat(exitCode, is(Constants.RETURN_OK));
}

}
Expand Up @@ -4,6 +4,7 @@
import java.util.stream.Collectors;

public enum ModuleGenerationType {
PRESERVE_CONFIGURED,
ONE_PER_TECHNO,
ONE_PER_AU,
FULL_CONTENT;
Expand Down

0 comments on commit 864872a

Please sign in to comment.