Search in sources :

Example 11 with TestExecutorConfig

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

the class ProductExecutorConfigurationScenario7IntTest method an_admin_can_delete_former_created_product_executor_config.

@Test
public void an_admin_can_delete_former_created_product_executor_config() {
    /* prepare */
    TestExecutorConfig config = new TestExecutorConfig();
    config.productIdentifier = TestExecutorProductIdentifier.PDS_CODESCAN.name();
    config.name = "pds gosec-3";
    config.executorVersion = 1;
    config.setup.baseURL = "https://baseurl.product.example.com/start";
    UUID uuid = as(SUPER_ADMIN).createProductExecutorConfig(config);
    assertNotNull(uuid);
    /* execute */
    as(SUPER_ADMIN).deleteProductExecutorConfig(uuid);
    /* test */
    assertConfigDoesNotExist(uuid);
}
Also used : TestExecutorConfig(com.mercedesbenz.sechub.test.executorconfig.TestExecutorConfig) UUID(java.util.UUID) Test(org.junit.Test)

Example 12 with TestExecutorConfig

use of com.mercedesbenz.sechub.test.executorconfig.TestExecutorConfig 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)

Example 13 with TestExecutorConfig

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

the class AsUser method changeProductExecutorJobParameter.

/**
 * Change product executor job parameter by REST API - will fail when user has
 * not the permission to do this.
 *
 * @param executorConfigUUID
 * @param key
 * @param newValue
 * @throws IllegalArgumentException when executorConfigUUID is null
 * @throws IllegalStateException    when key was not found
 */
public AsUser changeProductExecutorJobParameter(TestExecutorConfig executorConfig, String key, String newValue) {
    ensureExecutorConfigUUIDs(executorConfig);
    UUID executorConfigUUID = executorConfig.uuid;
    if (executorConfigUUID == null) {
        throw new IllegalArgumentException("Invalid test case: executorConfigUUID may not be null! Name was:" + executorConfig.name);
    }
    TestExecutorConfig config = fetchProductExecutorConfig(executorConfigUUID);
    boolean changed = false;
    for (TestExecutorSetupJobParam param : config.setup.jobParameters) {
        if (param.key.equals(key)) {
            param.value = newValue;
            changed = true;
        }
    }
    if (changed) {
        updateProdcutExecutorConfig(executorConfigUUID, config);
    } else {
        throw new IllegalStateException("Invalid test case situation: key:" + key + " was not found!");
    }
    return this;
}
Also used : TestExecutorConfig(com.mercedesbenz.sechub.test.executorconfig.TestExecutorConfig) TestExecutorSetupJobParam(com.mercedesbenz.sechub.test.executorconfig.TestExecutorSetupJobParam) UUID(java.util.UUID)

Example 14 with TestExecutorConfig

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

the class AsUser method removeConfigurationFromProfile.

public AsUser removeConfigurationFromProfile(String profileId, UUID... uuids) {
    String url = getUrlBuilder().buildAdminFetchesProductExecutionProfile(profileId);
    String json = getRestHelper().getJSON(url);
    TestExecutionProfile profile = JSONConverter.get().fromJSON(TestExecutionProfile.class, json);
    for (UUID uuid : uuids) {
        TestExecutorConfig config = new TestExecutorConfig(uuid);
        // we do not need to load, because update service does only need uuids, other
        // parts are ignored*/
        // equals implemented with uuid, so works..
        profile.configurations.remove(config);
    }
    return updateProductExecutionProfile(profileId, profile);
}
Also used : TestExecutionProfile(com.mercedesbenz.sechub.test.executionprofile.TestExecutionProfile) TestExecutorConfig(com.mercedesbenz.sechub.test.executorconfig.TestExecutorConfig) UUID(java.util.UUID)

Example 15 with TestExecutorConfig

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

the class ExecutionProfileDialogUI method createMainPanel.

private void createMainPanel() {
    mainPanel = new JPanel(new GridBagLayout());
    int row = 0;
    /* id */
    idTextField = new JTextField(profile.id);
    mainPanel.add(new JLabel("Id"), createLabelConstraint(row));
    mainPanel.add(idTextField, createComponentConstraint(row++));
    if (idEditAllowed) {
        idTextField.setBorder(BorderFactory.createLineBorder(Color.ORANGE, 2));
        idTextField.setToolTipText("mandatory field");
    } else {
        idTextField.setEditable(false);
    }
    descriptionTextArea = new JTextArea(profile.description);
    mainPanel.add(new JLabel("Description"), createLabelConstraint(row));
    mainPanel.add(descriptionTextArea, createComponentConstraint(row++));
    /* enabled */
    enabledCheckBox = new JCheckBox("", profile.enabled);
    mainPanel.add(new JLabel("Enabled"), createLabelConstraint(row));
    mainPanel.add(enabledCheckBox, createComponentConstraint(row++));
    /* configurations */
    model = new DefaultTableModel() {

        private static final long serialVersionUID = 1L;

        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    model.addColumn("Executor config name");
    model.addColumn("enabled");
    model.addColumn("uuid");
    configurationTable = new JTable(model);
    configurationTable.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() > 1) {
                int row = configurationTable.getSelectedRow();
                Object selectedValue = model.getValueAt(row, 2);
                if (selectedValue instanceof UUID) {
                    UUID uuid = (UUID) selectedValue;
                    boolean changed = editConfigurationAction.executeDirectly(uuid);
                    if (!changed) {
                        return;
                    }
                    reloadChangedDataIntoLocalProfile(uuid);
                } else {
                    throw new IllegalStateException("not a uuid:" + selectedValue);
                }
            }
        }

        private void reloadChangedDataIntoLocalProfile(UUID uuid) {
            TestExecutorConfig found = null;
            for (TestExecutorConfig config : profile.configurations) {
                if (uuid.equals(config.uuid)) {
                    found = config;
                    break;
                }
            }
            if (found == null) {
                getContext().getOutputUI().error("Did not found config again with uuid:" + uuid);
                return;
            }
            profile.configurations.remove(found);
            TestExecutorConfig newConfig = getContext().getAdministration().fetchExecutorConfiguration(uuid);
            profile.configurations.add(newConfig);
            rebuildTableModelRows();
        }
    });
    rebuildTableModelRows();
    if (model.getRowCount() > 0) {
        configurationTable.setRowSelectionInterval(0, 0);
    }
    new TableRendersupport().addStandardTableCellRender(configurationTable);
    GridBagConstraints tableConstraint = createComponentConstraint(row++);
    tableConstraint.gridx = 0;
    tableConstraint.gridwidth++;
    tableConstraint.weighty = 0.5;
    JScrollPane tableScrollPane = new JScrollPane(configurationTable);
    tableScrollPane.setPreferredSize(new Dimension(600, 200));
    mainPanel.add(tableScrollPane, tableConstraint);
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout());
    buttonPanel.add(new JButton(new AddConfigAction()));
    buttonPanel.add(new JButton(new RemoveConfigAction()));
    mainPanel.add(buttonPanel, createComponentConstraint(row++));
    /* project ids - label */
    projectIdsLabel = new JLabel();
    GridBagConstraints projectIdLabelConstraint = createComponentConstraint(row++);
    projectIdLabelConstraint.ipady = 0;
    projectIdLabelConstraint.gridx = 0;
    projectIdLabelConstraint.gridwidth++;
    mainPanel.add(projectIdsLabel, projectIdLabelConstraint);
    /* text area for project ids */
    projectIdsTextArea = new JTextArea();
    projectIdsTextArea.setLineWrap(true);
    projectIdsTextArea.setEditable(false);
    projectIdsTextArea.setColumns(200);
    GridBagConstraints textAreaConstraint = createComponentConstraint(row++);
    textAreaConstraint.gridx = 0;
    textAreaConstraint.gridwidth++;
    textAreaConstraint.weighty = 0.5;
    JScrollPane textAreaScrollPane = new JScrollPane(projectIdsTextArea);
    textAreaScrollPane.setPreferredSize(new Dimension(600, 200));
    mainPanel.add(textAreaScrollPane, textAreaConstraint);
    updateProjectIdsAtUI();
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) JTextArea(javax.swing.JTextArea) FlowLayout(java.awt.FlowLayout) GridBagLayout(java.awt.GridBagLayout) DefaultTableModel(javax.swing.table.DefaultTableModel) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) UUID(java.util.UUID) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) TestExecutorConfig(com.mercedesbenz.sechub.test.executorconfig.TestExecutorConfig) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JCheckBox(javax.swing.JCheckBox) TableRendersupport(com.mercedesbenz.sechub.developertools.admin.ui.TableRendersupport) JTable(javax.swing.JTable)

Aggregations

TestExecutorConfig (com.mercedesbenz.sechub.test.executorconfig.TestExecutorConfig)37 UUID (java.util.UUID)26 Test (org.junit.Test)17 TestExecutionProfile (com.mercedesbenz.sechub.test.executionprofile.TestExecutionProfile)14 TestExecutorSetupJobParam (com.mercedesbenz.sechub.test.executorconfig.TestExecutorSetupJobParam)13 UseCaseRestDoc (com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc)5 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)5 DeveloperAdministration (com.mercedesbenz.sechub.developertools.admin.DeveloperAdministration)1 TableRendersupport (com.mercedesbenz.sechub.developertools.admin.ui.TableRendersupport)1 ExecutorConfigDialogUI (com.mercedesbenz.sechub.developertools.admin.ui.action.config.ExecutorConfigDialogUI)1 ProductExecutionProfile (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutionProfile)1 ProductExecutorConfig (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig)1 TestProject (com.mercedesbenz.sechub.integrationtest.api.TestProject)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 UseCaseAdminUpdatesExecutionProfile (com.mercedesbenz.sechub.sharedkernel.usecases.admin.config.UseCaseAdminUpdatesExecutionProfile)1 UseCaseAdminUpdatesExecutorConfig (com.mercedesbenz.sechub.sharedkernel.usecases.admin.config.UseCaseAdminUpdatesExecutorConfig)1 TestExecutionProfileList (com.mercedesbenz.sechub.test.executionprofile.TestExecutionProfileList)1