Skip to content

Commit

Permalink
feat(core): add FlowService.findById
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-mulier-p committed Dec 15, 2023
1 parent 58467f6 commit b83caca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/src/main/java/io/kestra/core/services/FlowService.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public List<FlowWithSource> findByNamespaceWithSource(String tenantId, String na
return flowRepository.findByNamespaceWithSource(tenantId, namespace);
}

public Optional<Flow> findById(String tenantId, String namespace, String id) {
return flowRepository.findById(tenantId, namespace, id);
}

public Stream<Flow> keepLastVersion(Stream<Flow> stream) {
return keepLastVersionCollector(stream);
}
Expand Down
16 changes: 16 additions & 0 deletions core/src/test/java/io/kestra/core/services/FlowServiceTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.kestra.core.services;

import io.kestra.core.repositories.FlowRepositoryInterface;
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
import org.junit.jupiter.api.Test;
import io.kestra.core.models.flows.Flow;
Expand All @@ -16,13 +17,20 @@

@MicronautTest
class FlowServiceTest {
@Inject
private FlowRepositoryInterface flowRepository;
@Inject
private FlowService flowService;

private static Flow create(String flowId, String taskId, Integer revision) {
return create(null, flowId, taskId, revision);
}

private static Flow create(String tenantId, String flowId, String taskId, Integer revision) {
return Flow.builder()
.id(flowId)
.namespace("io.kestra.unittest")
.tenantId(tenantId)
.revision(revision)
.tasks(Collections.singletonList(Return.builder()
.id(taskId)
Expand Down Expand Up @@ -100,4 +108,12 @@ public void multipleFlow() {
assertThat(collect.stream().filter(flow -> flow.getId().equals("test2")).findFirst().orElseThrow().getRevision(), is(3));
assertThat(collect.stream().filter(flow -> flow.getId().equals("test3")).findFirst().orElseThrow().getRevision(), is(3));
}

@Test
public void findById() {
Flow flow = create("my-tenant", "test", "test", 1);
flowRepository.create(flow, flow.generateSource(), flow);
assertThat(flowService.findById("my-tenant", "io.kestra.unittest", "test").isPresent(), is(true));
assertThat(flowService.findById(null, "io.kestra.unittest", "test").isPresent(), is(false));
}
}

0 comments on commit b83caca

Please sign in to comment.