Search in sources :

Example 6 with AddTriggerModel

use of com.redhat.devtools.intellij.tektoncd.utils.model.actions.AddTriggerModel in project intellij-tekton by redhat-developer.

the class YAMLBuilderTest method checkPipelineRunCreatedHasParams.

@Test
public void checkPipelineRunCreatedHasParams() throws IOException {
    String content = load("pipeline3.yaml");
    AddTriggerModel model = new AddTriggerModel(content, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyMap());
    ObjectNode pipelineRunNode = YAMLBuilder.createPipelineRun(model);
    assertEquals(pipelineRunNode.get("apiVersion").asText(), "tekton.dev/v1beta1");
    assertEquals(pipelineRunNode.get("kind").asText(), "PipelineRun");
    assertEquals(pipelineRunNode.get("metadata").get("generateName").asText(), "foo-");
    assertEquals(pipelineRunNode.get("spec").get("pipelineRef").get("name").asText(), "foo");
    assertFalse(pipelineRunNode.get("spec").has("serviceAccountName"));
    assertFalse(pipelineRunNode.get("spec").has("serviceAccountNames"));
    assertTrue(pipelineRunNode.get("spec").has("params"));
    assertEquals(pipelineRunNode.get("spec").get("params").get(0).get("name").asText(), "param1");
    assertFalse(pipelineRunNode.get("spec").has("resources"));
    assertFalse(pipelineRunNode.get("spec").has("workspaces"));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AddTriggerModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.AddTriggerModel) Test(org.junit.Test) BaseTest(com.redhat.devtools.intellij.tektoncd.BaseTest)

Example 7 with AddTriggerModel

use of com.redhat.devtools.intellij.tektoncd.utils.model.actions.AddTriggerModel in project intellij-tekton by redhat-developer.

the class YAMLBuilderTest method checkTaskRunCreatedHasInputResource.

@Test
public void checkTaskRunCreatedHasInputResource() throws IOException {
    String content = load("task6.yaml");
    AddTriggerModel model = new AddTriggerModel(content, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyMap());
    ObjectNode taskRunNode = YAMLBuilder.createTaskRun(model);
    assertEquals(taskRunNode.get("apiVersion").asText(), "tekton.dev/v1beta1");
    assertEquals(taskRunNode.get("kind").asText(), "TaskRun");
    assertEquals(taskRunNode.get("metadata").get("generateName").asText(), "foo-");
    assertEquals(taskRunNode.get("spec").get("taskRef").get("name").asText(), "foo");
    assertFalse(taskRunNode.get("spec").has("serviceAccountName"));
    assertFalse(taskRunNode.get("spec").has("serviceAccountNames"));
    assertFalse(taskRunNode.get("spec").has("params"));
    assertTrue(taskRunNode.get("spec").has("resources"));
    assertEquals(taskRunNode.get("spec").get("resources").get("inputs").get(0).get("name").asText(), "resource1");
    assertFalse(taskRunNode.get("spec").get("resources").has("outputs"));
    assertFalse(taskRunNode.get("spec").has("workspaces"));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AddTriggerModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.AddTriggerModel) Test(org.junit.Test) BaseTest(com.redhat.devtools.intellij.tektoncd.BaseTest)

Example 8 with AddTriggerModel

use of com.redhat.devtools.intellij.tektoncd.utils.model.actions.AddTriggerModel in project intellij-tekton by redhat-developer.

the class YAMLBuilderTest method checkPipelineRunCreatedWithNoInputs.

// ///////////////////////////////////////////////////////
// /             CREATE PIPELINERUN
// ///////////////////////////////////////////////////////
@Test
public void checkPipelineRunCreatedWithNoInputs() throws IOException {
    String content = load("pipeline1.yaml");
    AddTriggerModel model = new AddTriggerModel(content, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyMap());
    ObjectNode pipelineRunNode = YAMLBuilder.createPipelineRun(model);
    assertEquals(pipelineRunNode.get("apiVersion").asText(), "tekton.dev/v1beta1");
    assertEquals(pipelineRunNode.get("kind").asText(), "PipelineRun");
    assertEquals(pipelineRunNode.get("metadata").get("generateName").asText(), "foo-");
    assertEquals(pipelineRunNode.get("spec").get("pipelineRef").get("name").asText(), "foo");
    assertFalse(pipelineRunNode.get("spec").has("serviceAccountName"));
    assertFalse(pipelineRunNode.get("spec").has("serviceAccountNames"));
    assertFalse(pipelineRunNode.get("spec").has("params"));
    assertFalse(pipelineRunNode.get("spec").has("resources"));
    assertFalse(pipelineRunNode.get("spec").has("workspaces"));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AddTriggerModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.AddTriggerModel) Test(org.junit.Test) BaseTest(com.redhat.devtools.intellij.tektoncd.BaseTest)

Example 9 with AddTriggerModel

use of com.redhat.devtools.intellij.tektoncd.utils.model.actions.AddTriggerModel in project intellij-tekton by redhat-developer.

the class ParametersStep method setContent.

public void setContent() {
    textFields = new LinkedHashMap<>();
    final int[] row = { 0 };
    // if we are inside the AddTriggerWizard we suggest users which are the params they can use (extracted by the bindings chosen in the previous step)
    if (model instanceof AddTriggerModel) {
        Set<String> variablesToSuggest = ((AddTriggerModel) model).extractVariablesFromSelectedBindings();
        if (!variablesToSuggest.isEmpty()) {
            String suggestVariablesText = "<html><body style=\"font-family: " + Font.DIALOG + ";font-size:10px;\">The following variables can be used as Parameter values in the form $variable:<br><br>";
            int cont = 0;
            for (String variable : variablesToSuggest) {
                suggestVariablesText += "<span style=\"font-size:10px;font-weight:bold;\">" + variable + "</span>   ";
                if (++cont % 4 == 0)
                    suggestVariablesText += "<br>";
            }
            suggestVariablesText += "<br><br>The variables are taken from the bindings chosen in the previous step and they will be<br>" + "filled by the EventListener when evaluating TriggerBindings for an event.</html>";
            JTextPane lblVariableText = new JTextPane();
            lblVariableText.setContentType("text/html");
            lblVariableText.setText(suggestVariablesText);
            lblVariableText.setEditable(false);
            lblVariableText.setBackground(null);
            lblVariableText.setBorder(null);
            addComponent(lblVariableText, null, BORDER_LABEL_NAME, null, 0, row[0], GridBagConstraints.NORTHWEST);
            row[0] += 1;
        }
    }
    model.getParams().stream().filter(input -> input.kind() == Input.Kind.PARAMETER).forEach(input -> {
        String label = "<html><span style=\\\"font-family:serif;font-size:10px;font-weight:bold;\\\">" + input.name() + "</span>  <span style=\\\"font-family:serif;font-size:10;font-weight:normal;font-style:italic;\\\">(" + input.type() + ")</span></html>";
        String tooltip = input.description().isPresent() ? input.description().get() + "\n" : "";
        if (input.type().equals("string")) {
            tooltip += "The parameter " + input.name() + " expects a string value.";
        } else {
            tooltip += "The parameter " + input.name() + " expects an array value (e.g. val1,val2,val3 ...). Leave it empty for an empty array.";
        }
        JLabel lblNameParam = new JLabel(label);
        addComponent(lblNameParam, null, BORDER_LABEL_NAME, ROW_DIMENSION, 0, row[0], GridBagConstraints.NORTHWEST);
        addTooltip(lblNameParam, tooltip);
        row[0] += 1;
        JTextField txtValueParam = new JTextField(input.defaultValue().orElse(""));
        textFields.put(input.name(), txtValueParam);
        txtValueParam = (JTextField) addComponent(txtValueParam, TIMES_PLAIN_14, null, ROW_DIMENSION, 0, row[0], GridBagConstraints.NORTHWEST);
        addListener(input.name(), txtValueParam, txtValueParam.getBorder(), row[0]);
        row[0] += 1;
    });
}
Also used : Color(java.awt.Color) ActionToRunModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.ActionToRunModel) DocumentListener(javax.swing.event.DocumentListener) TIMES_PLAIN_14(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.TIMES_PLAIN_14) JTextField(javax.swing.JTextField) Font(java.awt.Font) Set(java.util.Set) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ROW_DIMENSION_ERROR(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.ROW_DIMENSION_ERROR) GridBagConstraints(java.awt.GridBagConstraints) Border(javax.swing.border.Border) LinkedHashMap(java.util.LinkedHashMap) RED_BORDER_SHOW_ERROR(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.RED_BORDER_SHOW_ERROR) ROW_DIMENSION(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.ROW_DIMENSION) JLabel(javax.swing.JLabel) Map(java.util.Map) TIMES_PLAIN_10(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.TIMES_PLAIN_10) Input(com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input) JTextPane(javax.swing.JTextPane) AddTriggerModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.AddTriggerModel) DocumentEvent(javax.swing.event.DocumentEvent) MARGIN_TOP_35(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.MARGIN_TOP_35) BORDER_LABEL_NAME(com.redhat.devtools.intellij.tektoncd.ui.UIConstants.BORDER_LABEL_NAME) JTextPane(javax.swing.JTextPane) JLabel(javax.swing.JLabel) AddTriggerModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.AddTriggerModel) JTextField(javax.swing.JTextField)

Example 10 with AddTriggerModel

use of com.redhat.devtools.intellij.tektoncd.utils.model.actions.AddTriggerModel in project intellij-tekton by redhat-developer.

the class YAMLBuilderTest method checkTaskRunCreatedHasParams.

@Test
public void checkTaskRunCreatedHasParams() throws IOException {
    String content = load("task3.yaml");
    AddTriggerModel model = new AddTriggerModel(content, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyMap());
    ObjectNode taskRunNode = YAMLBuilder.createTaskRun(model);
    assertEquals(taskRunNode.get("apiVersion").asText(), "tekton.dev/v1beta1");
    assertEquals(taskRunNode.get("kind").asText(), "TaskRun");
    assertEquals(taskRunNode.get("metadata").get("generateName").asText(), "foo-");
    assertEquals(taskRunNode.get("spec").get("taskRef").get("name").asText(), "foo");
    assertFalse(taskRunNode.get("spec").has("serviceAccountName"));
    assertFalse(taskRunNode.get("spec").has("serviceAccountNames"));
    assertTrue(taskRunNode.get("spec").has("params"));
    assertEquals(taskRunNode.get("spec").get("params").get(0).get("name").asText(), "parm1");
    assertFalse(taskRunNode.get("spec").has("resources"));
    assertFalse(taskRunNode.get("spec").has("workspaces"));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AddTriggerModel(com.redhat.devtools.intellij.tektoncd.utils.model.actions.AddTriggerModel) Test(org.junit.Test) BaseTest(com.redhat.devtools.intellij.tektoncd.BaseTest)

Aggregations

AddTriggerModel (com.redhat.devtools.intellij.tektoncd.utils.model.actions.AddTriggerModel)16 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)14 BaseTest (com.redhat.devtools.intellij.tektoncd.BaseTest)13 Test (org.junit.Test)13 Workspace (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Workspace)2 BORDER_LABEL_NAME (com.redhat.devtools.intellij.tektoncd.ui.UIConstants.BORDER_LABEL_NAME)2 Color (java.awt.Color)2 Font (java.awt.Font)2 GridBagConstraints (java.awt.GridBagConstraints)2 Map (java.util.Map)2 Ints (com.google.common.primitives.Ints)1 AllIcons (com.intellij.icons.AllIcons)1 Notification (com.intellij.notification.Notification)1 ComboBox (com.intellij.openapi.ui.ComboBox)1 IconLoader (com.intellij.openapi.util.IconLoader)1 JBList (com.intellij.ui.components.JBList)1 JBScrollPane (com.intellij.ui.components.JBScrollPane)1 Input (com.redhat.devtools.intellij.tektoncd.tkn.component.field.Input)1 ParentableNode (com.redhat.devtools.intellij.tektoncd.tree.ParentableNode)1 PipelineNode (com.redhat.devtools.intellij.tektoncd.tree.PipelineNode)1