Search in sources :

Example 1 with TestExecutorSetupJobParam

use of com.mercedesbenz.sechub.test.executorconfig.TestExecutorSetupJobParam 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 2 with TestExecutorSetupJobParam

use of com.mercedesbenz.sechub.test.executorconfig.TestExecutorSetupJobParam 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 3 with TestExecutorSetupJobParam

use of com.mercedesbenz.sechub.test.executorconfig.TestExecutorSetupJobParam in project sechub by mercedes-benz.

the class ProductExecutorConfigRestControllerRestDocTest method restdoc_admin_updates_executor_config.

@Test
@UseCaseRestDoc(useCase = UseCaseAdminUpdatesExecutorConfig.class)
public void restdoc_admin_updates_executor_config() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildAdminUpdatesProductExecutorConfig(UUID_PARAMETER.pathElement());
    Class<? extends Annotation> useCase = UseCaseAdminUpdatesExecutorConfig.class;
    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://productNew.example.com";
    configFromUser.setup.credentials.user = "env:EXAMPLE_NEW_USENAME";
    configFromUser.setup.credentials.password = "env:EXAMPLE_NEW_PASSWORD";
    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);
    /* execute + test @formatter:off */
    this.mockMvc.perform(put(apiEndpoint, randomUUID).contentType(MediaType.APPLICATION_JSON_VALUE).content(JSONConverter.get().toJSON(configFromUser))).andExpect(status().isOk()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).requestSchema(OpenApiSchema.EXECUTOR_CONFIGURATION.getSchema()).and().document(requestFields(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, per default false").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 : TestExecutorConfig(com.mercedesbenz.sechub.test.executorconfig.TestExecutorConfig) TestExecutorSetupJobParam(com.mercedesbenz.sechub.test.executorconfig.TestExecutorSetupJobParam) UseCaseAdminUpdatesExecutorConfig(com.mercedesbenz.sechub.sharedkernel.usecases.admin.config.UseCaseAdminUpdatesExecutorConfig) 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 4 with TestExecutorSetupJobParam

use of com.mercedesbenz.sechub.test.executorconfig.TestExecutorSetupJobParam in project sechub by mercedes-benz.

the class IntegrationTestDefaultExecutorConfigurations method defineCheckmarxConfig.

private static TestExecutorConfig defineCheckmarxConfig() {
    TestExecutorConfig config = createTestExecutorConfig();
    config.enabled = true;
    config.executorVersion = 1;
    config.productIdentifier = TestExecutorProductIdentifier.CHECKMARX.name();
    config.name = INTTEST_NAME_PREFIX + "Checkmarx V1";
    config.setup.baseURL = "https://checkmarx.mock.example.org:6011";
    config.setup.credentials.user = "checkmarx-user";
    config.setup.credentials.password = "checkmarx-password";
    // not initialized - is done at creation time by scenario initializer!
    config.uuid = null;
    MappingData teamIdMappingData = new MappingData();
    teamIdMappingData.getEntries().add(CHECKMARX_TEAMID_MAPPING_DEFAULT_MAPPING);
    MappingData presetIdMappingData = new MappingData();
    presetIdMappingData.getEntries().add(CHECKMARX_PRESETID_MAPPING_DEFAULT_MAPPING);
    List<TestExecutorSetupJobParam> jobParameters = config.setup.jobParameters;
    jobParameters.add(new TestExecutorSetupJobParam("checkmarx.newproject.teamid.mapping", teamIdMappingData.toJSON()));
    jobParameters.add(new TestExecutorSetupJobParam("checkmarx.newproject.presetid.mapping", presetIdMappingData.toJSON()));
    return config;
}
Also used : TestExecutorConfig(com.mercedesbenz.sechub.test.executorconfig.TestExecutorConfig) TestExecutorSetupJobParam(com.mercedesbenz.sechub.test.executorconfig.TestExecutorSetupJobParam) MappingData(com.mercedesbenz.sechub.sharedkernel.mapping.MappingData)

Example 5 with TestExecutorSetupJobParam

use of com.mercedesbenz.sechub.test.executorconfig.TestExecutorSetupJobParam in project sechub by mercedes-benz.

the class ProductExecutorConfigRestControllerRestDocTest method restdoc_admin_creates_executor_config.

@Test
@UseCaseRestDoc(useCase = UseCaseAdminCreatesExecutorConfiguration.class)
public void restdoc_admin_creates_executor_config() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildAdminCreatesProductExecutorConfig();
    Class<? extends Annotation> useCase = UseCaseAdminCreatesExecutorConfiguration.class;
    UUID randomUUID = UUID.randomUUID();
    when(createService.createProductExecutorConfig(any())).thenReturn(randomUUID.toString());
    TestExecutorConfig configFromUser = new TestExecutorConfig();
    configFromUser.enabled = false;
    configFromUser.name = "PDS gosec config 1";
    configFromUser.productIdentifier = ProductIdentifier.PDS_CODESCAN.name();
    configFromUser.executorVersion = 1;
    configFromUser.setup.baseURL = "https://productXYZ.example.com";
    configFromUser.setup.credentials.user = "env:EXAMPLE_USENAME";
    configFromUser.setup.credentials.password = "env:EXAMPLE_PASSWORD";
    TestExecutorSetupJobParam param1 = new TestExecutorSetupJobParam("example.key1", "A value");
    TestExecutorSetupJobParam param2 = new TestExecutorSetupJobParam("example.key2", "Another value");
    configFromUser.setup.jobParameters.add(param1);
    configFromUser.setup.jobParameters.add(param2);
    /* execute + test @formatter:off */
    this.mockMvc.perform(post(apiEndpoint).contentType(MediaType.APPLICATION_JSON_VALUE).content(JSONConverter.get().toJSON(configFromUser))).andExpect(status().isCreated()).andExpect(content().string(randomUUID.toString())).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).responseSchema(OpenApiSchema.EXECUTOR_CONFIGURATION_ID.getSchema()).requestSchema(OpenApiSchema.EXECUTOR_CONFIGURATION.getSchema()).and().document(requestFields(fieldWithPath(PROPERTY_NAME).description("A name for this configuration"), fieldWithPath(PROPERTY_PRODUCTIDENTIFIER).description("Executor product identifier"), fieldWithPath(PROPERTY_EXECUTORVERSION).description("Executor version"), fieldWithPath(PROPERTY_ENABLED).description("Enabled state of executor, per default false").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())));
/* @formatter:on */
}
Also used : UseCaseAdminCreatesExecutorConfiguration(com.mercedesbenz.sechub.sharedkernel.usecases.admin.config.UseCaseAdminCreatesExecutorConfiguration) TestExecutorConfig(com.mercedesbenz.sechub.test.executorconfig.TestExecutorConfig) TestExecutorSetupJobParam(com.mercedesbenz.sechub.test.executorconfig.TestExecutorSetupJobParam) UUID(java.util.UUID) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Aggregations

TestExecutorSetupJobParam (com.mercedesbenz.sechub.test.executorconfig.TestExecutorSetupJobParam)15 TestExecutorConfig (com.mercedesbenz.sechub.test.executorconfig.TestExecutorConfig)13 UUID (java.util.UUID)8 Test (org.junit.Test)6 UseCaseRestDoc (com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc)4 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)4 ProductExecutionProfile (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutionProfile)1 ProductExecutorConfig (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig)1 MappingData (com.mercedesbenz.sechub.sharedkernel.mapping.MappingData)1 UseCaseAdminCreatesExecutorConfiguration (com.mercedesbenz.sechub.sharedkernel.usecases.admin.config.UseCaseAdminCreatesExecutorConfiguration)1 UseCaseAdminFetchesExecutionProfile (com.mercedesbenz.sechub.sharedkernel.usecases.admin.config.UseCaseAdminFetchesExecutionProfile)1 UseCaseAdminFetchesExecutorConfiguration (com.mercedesbenz.sechub.sharedkernel.usecases.admin.config.UseCaseAdminFetchesExecutorConfiguration)1 UseCaseAdminUpdatesExecutorConfig (com.mercedesbenz.sechub.sharedkernel.usecases.admin.config.UseCaseAdminUpdatesExecutorConfig)1 TestExecutionProfile (com.mercedesbenz.sechub.test.executionprofile.TestExecutionProfile)1