|
| 1 | +/* |
| 2 | + * Copyright 2019 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.cloud.dataflow.server.rest.documentation; |
| 18 | + |
| 19 | +import org.junit.FixMethodOrder; |
| 20 | +import org.junit.Test; |
| 21 | +import org.junit.runners.MethodSorters; |
| 22 | + |
| 23 | +import org.springframework.cloud.dataflow.core.ApplicationType; |
| 24 | +import org.springframework.cloud.dataflow.server.repository.TaskDeploymentRepository; |
| 25 | + |
| 26 | +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; |
| 27 | +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; |
| 28 | +import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; |
| 29 | +import static org.springframework.restdocs.request.RequestDocumentation.requestParameters; |
| 30 | +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; |
| 31 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
| 32 | + |
| 33 | +/** |
| 34 | + * Documentation for the {@code /tasks/logs} endpoint. |
| 35 | + * |
| 36 | + * @author Ilayaperumal Gopinathan |
| 37 | + */ |
| 38 | +@FixMethodOrder(MethodSorters.NAME_ASCENDING) |
| 39 | +public class TaskLogsDocumentation extends BaseDocumentation { |
| 40 | + |
| 41 | + @Test |
| 42 | + public void getLogsByTaskId() throws Exception { |
| 43 | + registerApp(ApplicationType.task, "timestamp", "1.2.0.RELEASE"); |
| 44 | + String taskName = "taskA"; |
| 45 | + documentation.dontDocument( () -> this.mockMvc.perform( |
| 46 | + post("/tasks/definitions") |
| 47 | + .param("name", taskName) |
| 48 | + .param("definition", "timestamp --format='yyyy MM dd'")) |
| 49 | + .andExpect(status().isOk())); |
| 50 | + this.mockMvc.perform( |
| 51 | + post("/tasks/executions") |
| 52 | + .param("name", taskName)) |
| 53 | + .andExpect(status().isCreated()); |
| 54 | + TaskDeploymentRepository taskDeploymentRepository = |
| 55 | + springDataflowServer.getWebApplicationContext().getBean(TaskDeploymentRepository.class); |
| 56 | + Thread.sleep(30000); |
| 57 | + this.mockMvc.perform( |
| 58 | + get("/tasks/logs/"+taskDeploymentRepository.findTopByTaskDefinitionNameOrderByCreatedOnAsc(taskName) |
| 59 | + .getTaskDeploymentId()).param("platformName", "default")) |
| 60 | + .andDo(print()) |
| 61 | + .andExpect(status().isOk()) |
| 62 | + .andDo(this.documentationHandler.document( |
| 63 | + requestParameters( |
| 64 | + parameterWithName("platformName").description("The name of the platform the task is launched.")) |
| 65 | + )); |
| 66 | + } |
| 67 | + |
| 68 | +} |
0 commit comments