Search in sources :

Example 6 with UseCaseRestDoc

use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc in project sechub by mercedes-benz.

the class ProductExecutionProfileRestControllerRestDocTest method restdoc_admin_updates_profile.

@Test
@UseCaseRestDoc(useCase = UseCaseAdminUpdatesExecutionProfile.class)
public void restdoc_admin_updates_profile() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildAdminUpdatesProductExecutionProfile(PROFILE_ID.pathElement());
    Class<? extends Annotation> useCase = UseCaseAdminUpdatesExecutionProfile.class;
    String profileId = "existing-profile-1";
    TestExecutionProfile profile = new TestExecutionProfile();
    profile.description = "changed description";
    profile.enabled = true;
    UUID randomUUID = UUID.randomUUID();
    TestExecutorConfig configFromUser = new TestExecutorConfig();
    configFromUser.uuid = randomUUID;
    profile.configurations.add(configFromUser);
    profile.projectIds = null;
    /* execute + test @formatter:off */
    this.mockMvc.perform(put(apiEndpoint, profileId).contentType(MediaType.APPLICATION_JSON_VALUE).content(JSONConverter.get().toJSON(profile))).andExpect(status().isOk()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).requestSchema(OpenApiSchema.EXECUTION_PROFILE_UPDATE.getSchema()).and().document(requestFields(fieldWithPath(PROPERTY_DESCRIPTION).description("A short description for the profile"), fieldWithPath(PROPERTY_ENABLED).description("Enabled state of profile, default is false").optional(), fieldWithPath(PROPERTY_CONFIGURATIONS + "[]." + ProductExecutorConfig.PROPERTY_UUID).description("Add uuid for configuration to use here"), /* ignore next parts - only inside test json, also ignored at update, because there only uuid is used */
    fieldWithPath(PROPERTY_CONFIGURATIONS + "[]." + ProductExecutorConfig.PROPERTY_ENABLED).ignored(), fieldWithPath(PROPERTY_CONFIGURATIONS + "[]." + ProductExecutorConfig.PROPERTY_EXECUTORVERSION).ignored(), fieldWithPath(PROPERTY_CONFIGURATIONS + "[]." + ProductExecutorConfig.PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_CREDENTIALS).ignored(), fieldWithPath(PROPERTY_CONFIGURATIONS + "[]." + ProductExecutorConfig.PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_JOBPARAMETERS).ignored()), pathParameters(parameterWithName(PROFILE_ID.paramName()).description("The profile id"))));
/* @formatter:on */
}
Also used : TestExecutionProfile(com.mercedesbenz.sechub.test.executionprofile.TestExecutionProfile) TestExecutorConfig(com.mercedesbenz.sechub.test.executorconfig.TestExecutorConfig) UUID(java.util.UUID) UseCaseAdminUpdatesExecutionProfile(com.mercedesbenz.sechub.sharedkernel.usecases.admin.config.UseCaseAdminUpdatesExecutionProfile) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Example 7 with UseCaseRestDoc

use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc in project sechub by mercedes-benz.

the class ProductExecutionProfileRestControllerRestDocTest method restdoc_admin_creates_profile.

@Test
@UseCaseRestDoc(useCase = UseCaseAdminCreatesExecutionProfile.class)
public void restdoc_admin_creates_profile() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildAdminCreatesProductExecutionProfile(PROFILE_ID.pathElement());
    Class<? extends Annotation> useCase = UseCaseAdminCreatesExecutionProfile.class;
    String profileId = "new-profile-1";
    TestExecutionProfile profile = new TestExecutionProfile();
    profile.description = "a short description for profile";
    profile.enabled = false;
    /* execute + test @formatter:off */
    this.mockMvc.perform(post(apiEndpoint, profileId).contentType(MediaType.APPLICATION_JSON_VALUE).content(JSONConverter.get().toJSON(profile))).andExpect(status().isCreated()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).requestSchema(OpenApiSchema.EXECUTION_PROFILE_CREATE.getSchema()).and().document(requestFields(fieldWithPath(PROPERTY_DESCRIPTION).description("A short description for the profile"), fieldWithPath(PROPERTY_ENABLED).description("Enabled state of profile, default is false").optional(), fieldWithPath(PROPERTY_CONFIGURATIONS + "[]").description("Configurations can be linked at creation time as well - see update description").optional(), fieldWithPath(PROPERTY_PROJECT_IDS + "[]").description("Projects can be linked by their ids at creation time as well - see update description").optional()), pathParameters(parameterWithName(PROFILE_ID.paramName()).description("The profile id"))));
/* @formatter:on */
}
Also used : TestExecutionProfile(com.mercedesbenz.sechub.test.executionprofile.TestExecutionProfile) UseCaseAdminCreatesExecutionProfile(com.mercedesbenz.sechub.sharedkernel.usecases.admin.config.UseCaseAdminCreatesExecutionProfile) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Example 8 with UseCaseRestDoc

use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc in project sechub by mercedes-benz.

the class ProductExecutionProfileRestControllerRestDocTest method restdoc_admin_fetches_profile.

@Test
@UseCaseRestDoc(useCase = UseCaseAdminFetchesExecutionProfile.class)
public void restdoc_admin_fetches_profile() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildAdminFetchesProductExecutionProfile(PROFILE_ID.pathElement());
    Class<? extends Annotation> useCase = UseCaseAdminFetchesExecutionProfile.class;
    String profileId = "existing-profile-1";
    TestExecutionProfile testprofile = new TestExecutionProfile();
    testprofile.description = "a description";
    testprofile.enabled = true;
    UUID randomUUID = UUID.randomUUID();
    TestExecutorConfig configFromUser = new TestExecutorConfig();
    configFromUser.enabled = false;
    configFromUser.name = "New name";
    configFromUser.productIdentifier = ProductIdentifier.PDS_CODESCAN.name();
    configFromUser.executorVersion = 1;
    configFromUser.setup.baseURL = "https://product.example.com";
    configFromUser.setup.credentials.user = "env:EXAMPLE_USENAME";
    configFromUser.setup.credentials.password = "env:EXAMPLE_PASSWORD";
    configFromUser.uuid = randomUUID;
    TestExecutorSetupJobParam param1 = new TestExecutorSetupJobParam("example.key1", "A value but changed. Remark: the other parameter (example.key2) has been removed by this call");
    configFromUser.setup.jobParameters.add(param1);
    testprofile.configurations.add(configFromUser);
    testprofile.projectIds.add("project-1");
    testprofile.projectIds.add("project-2");
    ProductExecutionProfile profile = JSONConverter.get().fromJSON(ProductExecutionProfile.class, JSONConverter.get().toJSON(testprofile));
    when(fetchService.fetchProductExecutorConfig(profileId)).thenReturn(profile);
    /* execute + test @formatter:off */
    this.mockMvc.perform(get(apiEndpoint, profileId).contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).responseSchema(OpenApiSchema.EXECUTION_PROFILE_FETCH.getSchema()).and().document(responseFields(fieldWithPath(PROPERTY_ID).optional().ignored(), fieldWithPath(PROPERTY_DESCRIPTION).description("A short description for the profile"), fieldWithPath(PROPERTY_ENABLED).description("Enabled state of profile, default is false").optional(), fieldWithPath(PROPERTY_CONFIGURATIONS + "[]." + ProductExecutorConfig.PROPERTY_UUID).description("uuid of configuration"), fieldWithPath(PROPERTY_CONFIGURATIONS + "[]." + ProductExecutorConfig.PROPERTY_NAME).description("name of configuration"), fieldWithPath(PROPERTY_CONFIGURATIONS + "[]." + ProductExecutorConfig.PROPERTY_ENABLED).description("enabled state of this config"), fieldWithPath(PROPERTY_CONFIGURATIONS + "[]." + ProductExecutorConfig.PROPERTY_PRODUCTIDENTIFIER).description("executed product"), fieldWithPath(PROPERTY_CONFIGURATIONS + "[]." + ProductExecutorConfig.PROPERTY_EXECUTORVERSION).description("executor version"), fieldWithPath(PROPERTY_CONFIGURATIONS + "[]." + ProductExecutorConfig.PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_BASEURL).ignored(), fieldWithPath(PROPERTY_CONFIGURATIONS + "[]." + ProductExecutorConfig.PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_CREDENTIALS + "." + ProductExecutorConfigSetupCredentials.PROPERTY_USER).ignored(), fieldWithPath(PROPERTY_CONFIGURATIONS + "[]." + ProductExecutorConfig.PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_CREDENTIALS + "." + ProductExecutorConfigSetupCredentials.PROPERTY_PASSWORD).ignored(), fieldWithPath(PROPERTY_CONFIGURATIONS + "[]." + ProductExecutorConfig.PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_JOBPARAMETERS + "[]." + ProductExecutorConfigSetupJobParameter.PROPERTY_KEY).ignored(), fieldWithPath(PROPERTY_CONFIGURATIONS + "[]." + ProductExecutorConfig.PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_JOBPARAMETERS + "[]." + ProductExecutorConfigSetupJobParameter.PROPERTY_VALUE).ignored(), fieldWithPath(PROPERTY_PROJECT_IDS + "[]").description("Projects can be linked by their ids here")), pathParameters(parameterWithName(PROFILE_ID.paramName()).description("The profile id"))));
/* @formatter:on */
}
Also used : TestExecutionProfile(com.mercedesbenz.sechub.test.executionprofile.TestExecutionProfile) ProductExecutionProfile(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutionProfile) TestExecutorConfig(com.mercedesbenz.sechub.test.executorconfig.TestExecutorConfig) TestExecutorSetupJobParam(com.mercedesbenz.sechub.test.executorconfig.TestExecutorSetupJobParam) UUID(java.util.UUID) UseCaseAdminFetchesExecutionProfile(com.mercedesbenz.sechub.sharedkernel.usecases.admin.config.UseCaseAdminFetchesExecutionProfile) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Example 9 with UseCaseRestDoc

use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc in project sechub by mercedes-benz.

the class ProductExecutorConfigRestControllerRestDocTest method restdoc_admin_fetches_executor_config.

@Test
@UseCaseRestDoc(useCase = UseCaseAdminFetchesExecutorConfiguration.class)
public void restdoc_admin_fetches_executor_config() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildAdminFetchesProductExecutorConfig(UUID_PARAMETER.pathElement());
    Class<? extends Annotation> useCase = UseCaseAdminFetchesExecutorConfiguration.class;
    UUID uuid = UUID.randomUUID();
    TestExecutorConfig testConfig = new TestExecutorConfig();
    testConfig.uuid = uuid;
    testConfig.enabled = false;
    testConfig.name = "New name";
    testConfig.productIdentifier = ProductIdentifier.PDS_CODESCAN.name();
    testConfig.executorVersion = 1;
    testConfig.setup.baseURL = "https://product.example.com";
    testConfig.setup.credentials.user = "env:EXAMPLE_USENAME";
    testConfig.setup.credentials.password = "env:EXAMPLE_PASSWORD";
    TestExecutorSetupJobParam param1 = new TestExecutorSetupJobParam("example.key1", "A value");
    testConfig.setup.jobParameters.add(param1);
    ProductExecutorConfig config = JSONConverter.get().fromJSON(ProductExecutorConfig.class, JSONConverter.get().toJSON(testConfig));
    when(fetchService.fetchProductExecutorConfig(uuid)).thenReturn(config);
    /* execute + test @formatter:off */
    this.mockMvc.perform(get(apiEndpoint, uuid).contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).responseSchema(OpenApiSchema.EXECUTOR_CONFIGURATION_WITH_UUID.getSchema()).and().document(responseFields(fieldWithPath(PROPERTY_UUID).description("The uuid of this configuration"), fieldWithPath(PROPERTY_NAME).description("The name of this configuration"), fieldWithPath(PROPERTY_PRODUCTIDENTIFIER).description("Executor product identifier"), fieldWithPath(PROPERTY_EXECUTORVERSION).description("Executor version"), fieldWithPath(PROPERTY_ENABLED).description("Enabled state of executor").optional(), fieldWithPath(PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_BASEURL).description("Base URL to the product"), fieldWithPath(PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_CREDENTIALS + "." + ProductExecutorConfigSetupCredentials.PROPERTY_USER).description(CREDENTIALS_USER_DESCRIPTION), fieldWithPath(PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_CREDENTIALS + "." + ProductExecutorConfigSetupCredentials.PROPERTY_PASSWORD).description(CREDENTIALS_PWD_DESCRIPTION), fieldWithPath(PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_JOBPARAMETERS + "[]." + ProductExecutorConfigSetupJobParameter.PROPERTY_KEY).description(JOBPARAM_KEY_DESCRIPTION).optional(), fieldWithPath(PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_JOBPARAMETERS + "[]." + ProductExecutorConfigSetupJobParameter.PROPERTY_VALUE).description(JOBPARAM_VALUE_DESCRIPTION).optional()), pathParameters(parameterWithName(UUID_PARAMETER.paramName()).description("The configuration uuid"))));
/* @formatter:on */
}
Also used : UseCaseAdminFetchesExecutorConfiguration(com.mercedesbenz.sechub.sharedkernel.usecases.admin.config.UseCaseAdminFetchesExecutorConfiguration) TestExecutorConfig(com.mercedesbenz.sechub.test.executorconfig.TestExecutorConfig) TestExecutorSetupJobParam(com.mercedesbenz.sechub.test.executorconfig.TestExecutorSetupJobParam) ProductExecutorConfig(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig) UUID(java.util.UUID) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Example 10 with UseCaseRestDoc

use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc in project sechub by mercedes-benz.

the class ProductExecutorConfigRestControllerRestDocTest method restDoc_admin_fetches_executor_config_list.

@Test
@UseCaseRestDoc(useCase = UseCaseAdminFetchesExecutorConfigurationList.class)
public void restDoc_admin_fetches_executor_config_list() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildAdminFetchesListOfProductExecutionConfigurations();
    Class<? extends Annotation> useCase = UseCaseAdminFetchesExecutorConfigurationList.class;
    UUID uuid = UUID.randomUUID();
    ProductExecutorConfigList list = new ProductExecutorConfigList();
    ProductExecutorConfigListEntry entry = new ProductExecutorConfigListEntry(uuid, "example configuration", true);
    list.getExecutorConfigurations().add(entry);
    when(fetchListService.fetchProductExecutorConfigList()).thenReturn(list);
    /* execute + test @formatter:off */
    this.mockMvc.perform(get(apiEndpoint).contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).responseSchema(OpenApiSchema.EXECUTOR_CONFIGURATION_LIST.getSchema()).and().document(responseFields(fieldWithPath("type").description("Always `executorConfigurationList` as an identifier for the list"), fieldWithPath("executorConfigurations[]." + PROPERTY_UUID).description("The uuid of the configuration"), fieldWithPath("executorConfigurations[]." + PROPERTY_NAME).description("The configuration name"), fieldWithPath("executorConfigurations[]." + PROPERTY_ENABLED).description("Enabled state of configuration"))));
/* @formatter:on */
}
Also used : ProductExecutorConfigList(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigList) UseCaseAdminFetchesExecutorConfigurationList(com.mercedesbenz.sechub.sharedkernel.usecases.admin.config.UseCaseAdminFetchesExecutorConfigurationList) UUID(java.util.UUID) ProductExecutorConfigListEntry(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigListEntry) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Aggregations

UseCaseRestDoc (com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc)37 Test (org.junit.Test)35 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)35 UUID (java.util.UUID)17 WithMockUser (org.springframework.security.test.context.support.WithMockUser)7 SchedulerResult (com.mercedesbenz.sechub.domain.schedule.SchedulerResult)5 SecHubConfiguration (com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration)5 UseCaseUserCreatesNewJob (com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserCreatesNewJob)5 TestExecutorConfig (com.mercedesbenz.sechub.test.executorconfig.TestExecutorConfig)5 ScheduleJobStatus (com.mercedesbenz.sechub.domain.schedule.ScheduleJobStatus)4 ScheduleSecHubJob (com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob)4 TestExecutorSetupJobParam (com.mercedesbenz.sechub.test.executorconfig.TestExecutorSetupJobParam)4 Project (com.mercedesbenz.sechub.domain.administration.project.Project)3 User (com.mercedesbenz.sechub.domain.administration.user.User)3 TestExecutionProfile (com.mercedesbenz.sechub.test.executionprofile.TestExecutionProfile)3 AdministrationAutoCleanupConfig (com.mercedesbenz.sechub.domain.administration.autocleanup.AdministrationAutoCleanupConfig)2 ProjectDetailInformation (com.mercedesbenz.sechub.domain.administration.project.ProjectDetailInformation)2 ProjectMetaDataEntity (com.mercedesbenz.sechub.domain.administration.project.ProjectMetaDataEntity)2 FalsePositiveJobData (com.mercedesbenz.sechub.domain.scan.project.FalsePositiveJobData)2 ScanMockData (com.mercedesbenz.sechub.domain.scan.project.ScanMockData)2