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);
}
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 */
}
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;
}
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);
}
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();
}
Aggregations