Search in sources :

Example 1 with DefinitionDTO

use of org.talend.components.service.rest.dto.DefinitionDTO in project components by Talend.

the class DefinitionsControllerTest method shouldFilterComponentsByTypologyAndExecutionEngine.

public void shouldFilterComponentsByTypologyAndExecutionEngine(ConnectorTypology wantedTypology, ExecutionEngine executionEngine, int expectedResults) throws IOException {
    // given
    Map<String, ComponentDefinition> definitions = getComponentsDefinitions();
    // 
    BDDMockito.given(delegate.getDefinitionsMapByType(ComponentDefinition.class)).willReturn(definitions);
    // when
    final Response response = when().get(getVersionPrefix() + "/definitions/components?typology=" + wantedTypology + "&executionEngine=" + executionEngine.name()).andReturn();
    // then
    assertEquals(OK.value(), response.getStatusCode());
    List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() {
    });
    assertEquals(expectedResults, actual.size());
    assertEquals(expectedResults, actual.stream().filter(dto -> dto.getTypologies().contains(wantedTypology.name())).filter(dto -> dto.getExecutionEngines().contains(executionEngine.name())).count());
}
Also used : Response(com.jayway.restassured.response.Response) DefinitionsController(org.talend.components.service.rest.DefinitionsController) MockComponentDefinition(org.talend.components.service.rest.mock.MockComponentDefinition) Autowired(org.springframework.beans.factory.annotation.Autowired) DATA_STORE(org.talend.components.service.rest.DefinitionType.DATA_STORE) HashMap(java.util.HashMap) Definition(org.talend.daikon.definition.Definition) ComponentDefinition(org.talend.components.api.component.ComponentDefinition) NONE(org.talend.components.api.component.ConnectorTopology.NONE) Function(java.util.function.Function) ExecutionEngine(org.talend.components.api.component.runtime.ExecutionEngine) Response(com.jayway.restassured.response.Response) OUTGOING(org.talend.components.api.component.ConnectorTopology.OUTGOING) TRANSFORMER(org.talend.components.service.rest.dto.ConnectorTypology.TRANSFORMER) SOURCE(org.talend.components.service.rest.dto.ConnectorTypology.SOURCE) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Matchers.hasSize(org.hamcrest.Matchers.hasSize) INCOMING_AND_OUTGOING(org.talend.components.api.component.ConnectorTopology.INCOMING_AND_OUTGOING) TypeReference(com.fasterxml.jackson.core.type.TypeReference) JsonParseException(com.fasterxml.jackson.core.JsonParseException) RestAssured.when(com.jayway.restassured.RestAssured.when) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) DefinitionDTO(org.talend.components.service.rest.dto.DefinitionDTO) BDDMockito(org.mockito.BDDMockito) List(java.util.List) DatastoreDefinition(org.talend.components.common.datastore.DatastoreDefinition) MockDatastoreDefinition(org.talend.components.service.rest.mock.MockDatastoreDefinition) CONFIGURATION(org.talend.components.service.rest.dto.ConnectorTypology.CONFIGURATION) COMPONENT(org.talend.components.service.rest.DefinitionType.COMPONENT) ServiceConstants(org.talend.components.service.rest.ServiceConstants) AbstractSpringIntegrationTests(org.talend.components.service.rest.AbstractSpringIntegrationTests) INCOMING(org.talend.components.api.component.ConnectorTopology.INCOMING) SINK(org.talend.components.service.rest.dto.ConnectorTypology.SINK) ConnectorTypology(org.talend.components.service.rest.dto.ConnectorTypology) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) OK(org.springframework.http.HttpStatus.OK) DefinitionType(org.talend.components.service.rest.DefinitionType) Assert.assertEquals(org.junit.Assert.assertEquals) DefinitionDTO(org.talend.components.service.rest.dto.DefinitionDTO) Arrays.asList(java.util.Arrays.asList) List(java.util.List) MockComponentDefinition(org.talend.components.service.rest.mock.MockComponentDefinition) ComponentDefinition(org.talend.components.api.component.ComponentDefinition)

Example 2 with DefinitionDTO

use of org.talend.components.service.rest.dto.DefinitionDTO in project components by Talend.

the class DefinitionsControllerTest method shouldNotFilterTypology.

@Test
public void shouldNotFilterTypology() throws Exception {
    // given
    Map<String, ComponentDefinition> definitions = getComponentsDefinitions();
    // 
    BDDMockito.given(delegate.getDefinitionsMapByType(ComponentDefinition.class)).willReturn(definitions);
    // when
    final Response response = when().get(getVersionPrefix() + "/definitions/components").andReturn();
    // then
    assertEquals(OK.value(), response.getStatusCode());
    List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() {
    });
    assertEquals(14, actual.size());
}
Also used : Response(com.jayway.restassured.response.Response) DefinitionDTO(org.talend.components.service.rest.dto.DefinitionDTO) Arrays.asList(java.util.Arrays.asList) List(java.util.List) MockComponentDefinition(org.talend.components.service.rest.mock.MockComponentDefinition) ComponentDefinition(org.talend.components.api.component.ComponentDefinition) Test(org.junit.Test)

Example 3 with DefinitionDTO

use of org.talend.components.service.rest.dto.DefinitionDTO in project components by Talend.

the class DefinitionsControllerImpl method listDefinitions.

/**
 * Return all known definitions that match the given type.
 *
 * @param type the wanted definition type.
 * @return all known definitions that match the given type.
 * @returnWrapped java.lang.Iterable<org.talend.components.service.rest.dto.DefinitionDTO>
 */
@Override
public List<DefinitionDTO> listDefinitions(DefinitionType type, String tag) {
    logger.debug("listing definitions for {} ", type);
    // 
    Iterable<? extends Definition> definitionsByType = definitionServiceDelegate.getDefinitionsMapByType(type.getTargetClass()).values();
    Stream<? extends Definition> stream = stream(definitionsByType.spliterator(), false);
    if (tag != null) {
        stream = // 
        stream.filter(c -> HasTags.class.isAssignableFrom(c.getClass())).filter(c -> {
            for (Tag defTag : ((HasTags) c).getTags()) {
                if (TagUtils.hasTag(defTag, tag)) {
                    return true;
                }
            }
            return false;
        });
    }
    return stream.map(c -> {
        if (type == DefinitionType.COMPONENT) {
            return new DefinitionDTO((ComponentDefinition) c);
        } else {
            return new DefinitionDTO((DatastoreDefinition) c);
        }
    }).collect(Collectors.toList());
}
Also used : DefinitionRegistryService(org.talend.daikon.definition.service.DefinitionRegistryService) DefinitionsController(org.talend.components.service.rest.DefinitionsController) Logger(org.slf4j.Logger) HasTags(org.talend.daikon.i18n.tag.HasTags) Collection(java.util.Collection) Autowired(org.springframework.beans.factory.annotation.Autowired) Definition(org.talend.daikon.definition.Definition) ComponentDefinition(org.talend.components.api.component.ComponentDefinition) Collectors(java.util.stream.Collectors) ExecutionEngine(org.talend.components.api.component.runtime.ExecutionEngine) DefinitionDTO(org.talend.components.service.rest.dto.DefinitionDTO) List(java.util.List) Stream(java.util.stream.Stream) DatastoreDefinition(org.talend.components.common.datastore.DatastoreDefinition) StreamSupport.stream(java.util.stream.StreamSupport.stream) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ServiceImplementation(org.talend.daikon.annotation.ServiceImplementation) Tag(org.talend.daikon.i18n.tag.Tag) ConnectorTypology(org.talend.components.service.rest.dto.ConnectorTypology) TagUtils(org.talend.daikon.i18n.tag.TagUtils) DefinitionType(org.talend.components.service.rest.DefinitionType) HasTags(org.talend.daikon.i18n.tag.HasTags) DefinitionDTO(org.talend.components.service.rest.dto.DefinitionDTO) Tag(org.talend.daikon.i18n.tag.Tag) DatastoreDefinition(org.talend.components.common.datastore.DatastoreDefinition) ComponentDefinition(org.talend.components.api.component.ComponentDefinition)

Example 4 with DefinitionDTO

use of org.talend.components.service.rest.dto.DefinitionDTO in project components by Talend.

the class DefinitionsControllerTest method shouldFilterComponentsByTag.

public void shouldFilterComponentsByTag(String tag, int expectedResults) throws JsonParseException, JsonMappingException, IOException {
    Map<String, ComponentDefinition> definitions = getComponentsDefinitions();
    // 
    BDDMockito.given(delegate.getDefinitionsMapByType(ComponentDefinition.class)).willReturn(definitions);
    // when
    final Response response = when().get(getVersionPrefix() + "/definitions/" + COMPONENT + "?tag=" + tag).andReturn();
    // then
    assertEquals(OK.value(), response.getStatusCode());
    List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() {
    });
    assertEquals(expectedResults, actual.size());
}
Also used : Response(com.jayway.restassured.response.Response) DefinitionDTO(org.talend.components.service.rest.dto.DefinitionDTO) Arrays.asList(java.util.Arrays.asList) List(java.util.List) MockComponentDefinition(org.talend.components.service.rest.mock.MockComponentDefinition) ComponentDefinition(org.talend.components.api.component.ComponentDefinition)

Example 5 with DefinitionDTO

use of org.talend.components.service.rest.dto.DefinitionDTO in project components by Talend.

the class DefinitionsControllerTest method shouldFilterComponentsByExecutionEngine.

public void shouldFilterComponentsByExecutionEngine(ExecutionEngine executionEngine, int expectedResults) throws IOException {
    // given
    Map<String, ComponentDefinition> definitions = getComponentsDefinitions();
    // 
    BDDMockito.given(delegate.getDefinitionsMapByType(ComponentDefinition.class)).willReturn(definitions);
    // when
    final Response response = when().get(getVersionPrefix() + "/definitions/components?executionEngine=" + executionEngine.name()).andReturn();
    // then
    assertEquals(OK.value(), response.getStatusCode());
    List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() {
    });
    assertEquals(expectedResults, actual.size());
    assertEquals(expectedResults, actual.stream().filter(dto -> dto.getExecutionEngines().contains(executionEngine.name())).count());
}
Also used : Response(com.jayway.restassured.response.Response) DefinitionDTO(org.talend.components.service.rest.dto.DefinitionDTO) Arrays.asList(java.util.Arrays.asList) List(java.util.List) MockComponentDefinition(org.talend.components.service.rest.mock.MockComponentDefinition) ComponentDefinition(org.talend.components.api.component.ComponentDefinition)

Aggregations

DefinitionDTO (org.talend.components.service.rest.dto.DefinitionDTO)8 Response (com.jayway.restassured.response.Response)7 List (java.util.List)7 Arrays.asList (java.util.Arrays.asList)6 ComponentDefinition (org.talend.components.api.component.ComponentDefinition)6 MockComponentDefinition (org.talend.components.service.rest.mock.MockComponentDefinition)5 Test (org.junit.Test)3 Autowired (org.springframework.beans.factory.annotation.Autowired)2 ExecutionEngine (org.talend.components.api.component.runtime.ExecutionEngine)2 DatastoreDefinition (org.talend.components.common.datastore.DatastoreDefinition)2 DefinitionType (org.talend.components.service.rest.DefinitionType)2 DefinitionsController (org.talend.components.service.rest.DefinitionsController)2 ConnectorTypology (org.talend.components.service.rest.dto.ConnectorTypology)2 Definition (org.talend.daikon.definition.Definition)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 RestAssured.when (com.jayway.restassured.RestAssured.when)1 IOException (java.io.IOException)1