|
| 1 | +/* |
| 2 | + * Licensed to Apache Software Foundation (ASF) under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Apache Software Foundation (ASF) licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.dolphinscheduler.e2e.cases; |
| 21 | + |
| 22 | +import org.apache.dolphinscheduler.e2e.core.DolphinScheduler; |
| 23 | +import org.apache.dolphinscheduler.e2e.pages.LoginPage; |
| 24 | +import org.apache.dolphinscheduler.e2e.pages.common.NavBarPage; |
| 25 | +import org.apache.dolphinscheduler.e2e.pages.project.ProjectDetailPage; |
| 26 | +import org.apache.dolphinscheduler.e2e.pages.project.ProjectPage; |
| 27 | +import org.apache.dolphinscheduler.e2e.pages.project.workflow.WorkflowDefinitionTab; |
| 28 | +import org.apache.dolphinscheduler.e2e.pages.project.workflow.WorkflowForm; |
| 29 | +import org.apache.dolphinscheduler.e2e.pages.project.workflow.WorkflowInstanceTab; |
| 30 | +import org.apache.dolphinscheduler.e2e.pages.project.workflow.task.JavaTaskForm; |
| 31 | +import org.apache.dolphinscheduler.e2e.pages.security.EnvironmentPage; |
| 32 | +import org.apache.dolphinscheduler.e2e.pages.security.SecurityPage; |
| 33 | +import org.apache.dolphinscheduler.e2e.pages.security.TenantPage; |
| 34 | +import org.apache.dolphinscheduler.e2e.pages.security.UserPage; |
| 35 | +import org.junit.jupiter.api.AfterAll; |
| 36 | +import org.junit.jupiter.api.BeforeAll; |
| 37 | +import org.junit.jupiter.api.Order; |
| 38 | +import org.junit.jupiter.api.Test; |
| 39 | +import org.openqa.selenium.By; |
| 40 | +import org.openqa.selenium.WebElement; |
| 41 | +import org.openqa.selenium.remote.RemoteWebDriver; |
| 42 | +import org.openqa.selenium.support.ui.ExpectedConditions; |
| 43 | +import org.openqa.selenium.support.ui.WebDriverWait; |
| 44 | +import org.testcontainers.shaded.org.awaitility.Awaitility; |
| 45 | + |
| 46 | +import java.time.Duration; |
| 47 | + |
| 48 | +import static org.assertj.core.api.Assertions.assertThat; |
| 49 | + |
| 50 | +@DolphinScheduler(composeFiles = "docker/basic/docker-compose.yaml") |
| 51 | +public class WorkflowJavaTaskE2ETest { |
| 52 | + private static final String project = "test-workflow-1"; |
| 53 | + |
| 54 | + private static final String workflow = "test-workflow-1"; |
| 55 | + |
| 56 | + private static final String user = "admin"; |
| 57 | + |
| 58 | + private static final String password = "dolphinscheduler123"; |
| 59 | + |
| 60 | + private static final String email = "[email protected]"; |
| 61 | + |
| 62 | + private static final String phone = "15800000000"; |
| 63 | + |
| 64 | + private static final String tenant = System.getProperty("user.name"); |
| 65 | + |
| 66 | + private static final String environmentName = "JAVA_HOME"; |
| 67 | + |
| 68 | + private static final String environmentConfig = "export JAVA_HOME=${JAVA_HOME:-/opt/java/openjdk}"; |
| 69 | + |
| 70 | + private static final String environmentDesc = "JAVA_HOME_DESC"; |
| 71 | + |
| 72 | + private static final String environmentWorkerGroup = "default"; |
| 73 | + |
| 74 | + private static final String javaContent = "public class Test {" + |
| 75 | + " public static void main(String[] args) {" + |
| 76 | + " System.out.println(\"hello world\");" + |
| 77 | + " }" + |
| 78 | + "}"; |
| 79 | + |
| 80 | + private static RemoteWebDriver browser; |
| 81 | + |
| 82 | + @BeforeAll |
| 83 | + public static void setup() { |
| 84 | + UserPage userPage = new LoginPage(browser) |
| 85 | + .login(user, password) |
| 86 | + .goToNav(SecurityPage.class) |
| 87 | + .goToTab(TenantPage.class) |
| 88 | + .create(tenant) |
| 89 | + .goToNav(SecurityPage.class) |
| 90 | + .goToTab(EnvironmentPage.class) |
| 91 | + .create(environmentName, environmentConfig, environmentDesc, environmentWorkerGroup) |
| 92 | + .goToNav(SecurityPage.class) |
| 93 | + .goToTab(UserPage.class); |
| 94 | + |
| 95 | + new WebDriverWait(userPage.driver(), Duration.ofSeconds(20)).until(ExpectedConditions.visibilityOfElementLocated( |
| 96 | + new By.ByClassName("name"))); |
| 97 | + |
| 98 | + userPage.update(user, user, email, phone, tenant) |
| 99 | + .goToNav(ProjectPage.class) |
| 100 | + .create(project) |
| 101 | + ; |
| 102 | + } |
| 103 | + |
| 104 | + @AfterAll |
| 105 | + public static void cleanup() { |
| 106 | + new NavBarPage(browser) |
| 107 | + .goToNav(ProjectPage.class) |
| 108 | + .goTo(project) |
| 109 | + .goToTab(WorkflowDefinitionTab.class) |
| 110 | + .delete(workflow); |
| 111 | + |
| 112 | + new NavBarPage(browser) |
| 113 | + .goToNav(ProjectPage.class) |
| 114 | + .delete(project); |
| 115 | + |
| 116 | + browser.navigate().refresh(); |
| 117 | + |
| 118 | + new NavBarPage(browser) |
| 119 | + .goToNav(SecurityPage.class) |
| 120 | + .goToTab(TenantPage.class) |
| 121 | + .delete(tenant); |
| 122 | + } |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | + @Test |
| 127 | + @Order(1) |
| 128 | + void testCreateWorkflow() { |
| 129 | + WorkflowDefinitionTab workflowDefinitionPage = |
| 130 | + new ProjectPage(browser) |
| 131 | + .goTo(project) |
| 132 | + .goToTab(WorkflowDefinitionTab.class); |
| 133 | + |
| 134 | + workflowDefinitionPage |
| 135 | + .createWorkflow() |
| 136 | + .<JavaTaskForm> addTask(WorkflowForm.TaskType.JAVA) |
| 137 | + .script(javaContent) |
| 138 | + .name("test-1") |
| 139 | + .addParam("today", "${system.datetime}") |
| 140 | + .selectEnv(environmentName) |
| 141 | + .submit() |
| 142 | + .submit() |
| 143 | + .name(workflow) |
| 144 | + .addGlobalParam("global_param", "hello world") |
| 145 | + .submit() |
| 146 | + ; |
| 147 | + |
| 148 | + Awaitility.await().untilAsserted(() -> assertThat(workflowDefinitionPage.workflowList()) |
| 149 | + .as("Workflow list should contain newly-created workflow") |
| 150 | + .anyMatch( |
| 151 | + it -> it.getText().contains(workflow) |
| 152 | + )); |
| 153 | + workflowDefinitionPage.publish(workflow); |
| 154 | + } |
| 155 | + |
| 156 | + |
| 157 | + @Test |
| 158 | + @Order(30) |
| 159 | + void testRunWorkflow() { |
| 160 | + final ProjectDetailPage projectPage = |
| 161 | + new ProjectPage(browser) |
| 162 | + .goToNav(ProjectPage.class) |
| 163 | + .goTo(project); |
| 164 | + |
| 165 | + projectPage |
| 166 | + .goToTab(WorkflowInstanceTab.class) |
| 167 | + .deleteAll(); |
| 168 | + projectPage |
| 169 | + .goToTab(WorkflowDefinitionTab.class) |
| 170 | + .run(workflow) |
| 171 | + .submit(); |
| 172 | + |
| 173 | + Awaitility.await().untilAsserted(() -> { |
| 174 | + browser.navigate().refresh(); |
| 175 | + |
| 176 | + final WorkflowInstanceTab.Row row = projectPage |
| 177 | + .goToTab(WorkflowInstanceTab.class) |
| 178 | + .instances() |
| 179 | + .iterator() |
| 180 | + .next(); |
| 181 | + |
| 182 | + assertThat(row.isSuccess()).isTrue(); |
| 183 | + assertThat(row.executionTime()).isEqualTo(1); |
| 184 | + }); |
| 185 | + } |
| 186 | +} |
0 commit comments