Search in sources :

Example 1 with Template

use of io.kestra.core.models.templates.Template in project kestra by kestra-io.

the class MemoryTemplateRepository method findDistinctNamespace.

@Override
public List<String> findDistinctNamespace() {
    HashSet<String> namespaces = new HashSet<>();
    for (Template t : this.findAll()) {
        namespaces.add(t.getNamespace());
    }
    ArrayList<String> namespacesList = new ArrayList<>(namespaces);
    Collections.sort(namespacesList);
    return new ArrayList<>(namespacesList);
}
Also used : Template(io.kestra.core.models.templates.Template)

Example 2 with Template

use of io.kestra.core.models.templates.Template in project kestra by kestra-io.

the class TemplateControllerTest method updateTemplate.

@Test
void updateTemplate() {
    Template template = createTemplate();
    client.toBlocking().retrieve(POST("/api/v1/templates", template), Template.class);
    Template createdTemplate = client.toBlocking().retrieve(HttpRequest.GET("/api/v1/templates/" + template.getNamespace() + "/" + template.getId()), Template.class);
    assertThat(template.getTasks().size(), is(2));
    Task t3 = Return.builder().id("task-3").type(Return.class.getName()).format("test").build();
    Template updateTemplate = Template.builder().id(template.getId()).namespace(template.getNamespace()).tasks(Arrays.asList(t3)).build();
    client.toBlocking().retrieve(PUT("/api/v1/templates/" + template.getNamespace() + "/" + template.getId(), updateTemplate), Template.class);
    Template updatedTemplate = client.toBlocking().retrieve(HttpRequest.GET("/api/v1/templates/" + template.getNamespace() + "/" + template.getId()), Template.class);
    assertThat(updatedTemplate.getTasks().size(), is(1));
    assertThat(updatedTemplate.getTasks().get(0).getId(), is("task-3"));
}
Also used : Task(io.kestra.core.models.tasks.Task) Return(io.kestra.core.tasks.debugs.Return) Template(io.kestra.core.models.templates.Template) Test(org.junit.jupiter.api.Test) AbstractMemoryRunnerTest(io.kestra.core.runners.AbstractMemoryRunnerTest)

Example 3 with Template

use of io.kestra.core.models.templates.Template in project kestra by kestra-io.

the class TemplateControllerTest method deleteTemplate.

@Test
void deleteTemplate() {
    Template template = createTemplate();
    client.toBlocking().retrieve(POST("/api/v1/templates", template), Template.class);
    Template createdTemplate = client.toBlocking().retrieve(HttpRequest.GET("/api/v1/templates/" + template.getNamespace() + "/" + template.getId()), Template.class);
    assertThat(createdTemplate.getId(), is(template.getId()));
    HttpResponse<Void> deleteResult = client.toBlocking().exchange(DELETE("/api/v1/templates/" + template.getNamespace() + "/" + template.getId()));
    assertThat(deleteResult.getStatus(), is(NO_CONTENT));
    HttpClientResponseException e = assertThrows(HttpClientResponseException.class, () -> {
        client.toBlocking().retrieve(HttpRequest.GET("/api/v1/templates/" + template.getNamespace() + "/" + template.getId()));
    });
    assertThat(e.getStatus(), is(HttpStatus.NOT_FOUND));
}
Also used : HttpClientResponseException(io.micronaut.http.client.exceptions.HttpClientResponseException) Template(io.kestra.core.models.templates.Template) Test(org.junit.jupiter.api.Test) AbstractMemoryRunnerTest(io.kestra.core.runners.AbstractMemoryRunnerTest)

Example 4 with Template

use of io.kestra.core.models.templates.Template in project kestra by kestra-io.

the class TemplateControllerTest method create.

@Test
void create() {
    Template template = createTemplate();
    HttpClientResponseException e = assertThrows(HttpClientResponseException.class, () -> {
        client.toBlocking().retrieve(HttpRequest.GET("/api/v1/templates/" + template.getId()));
    });
    assertThat(e.getStatus(), is(HttpStatus.NOT_FOUND));
    Template result = client.toBlocking().retrieve(POST("/api/v1/templates", template), Template.class);
    Template createdTemplate = client.toBlocking().retrieve(HttpRequest.GET("/api/v1/templates/" + template.getNamespace() + "/" + template.getId()), Template.class);
    assertThat(createdTemplate.getId(), is(template.getId()));
}
Also used : HttpClientResponseException(io.micronaut.http.client.exceptions.HttpClientResponseException) Template(io.kestra.core.models.templates.Template) Test(org.junit.jupiter.api.Test) AbstractMemoryRunnerTest(io.kestra.core.runners.AbstractMemoryRunnerTest)

Example 5 with Template

use of io.kestra.core.models.templates.Template in project kestra by kestra-io.

the class AbstractTemplateRepositoryTest method findAll.

@Test
void findAll() {
    long saveCount = templateRepository.findAll().size();
    Template template = builder().build();
    templateRepository.create(template);
    long size = templateRepository.findAll().size();
    assertThat(size, greaterThan(saveCount));
    templateRepository.delete(template);
    assertThat((long) templateRepository.findAll().size(), is(saveCount));
}
Also used : Template(io.kestra.core.models.templates.Template) Test(org.junit.jupiter.api.Test) MicronautTest(io.micronaut.test.extensions.junit5.annotation.MicronautTest)

Aggregations

Template (io.kestra.core.models.templates.Template)12 Test (org.junit.jupiter.api.Test)9 MicronautTest (io.micronaut.test.extensions.junit5.annotation.MicronautTest)5 AbstractMemoryRunnerTest (io.kestra.core.runners.AbstractMemoryRunnerTest)4 HttpClientResponseException (io.micronaut.http.client.exceptions.HttpClientResponseException)2 Task (io.kestra.core.models.tasks.Task)1 TemplateRepositoryInterface (io.kestra.core.repositories.TemplateRepositoryInterface)1 Return (io.kestra.core.tasks.debugs.Return)1 ArrayList (java.util.ArrayList)1 BoolQueryBuilder (org.opensearch.index.query.BoolQueryBuilder)1 SearchSourceBuilder (org.opensearch.search.builder.SearchSourceBuilder)1