Search in sources :

Example 6 with DefinitionDTO

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

the class DefinitionsControllerTest method shouldListDefinitions.

public // 
void shouldListDefinitions(// 
List<String> names, // 
Class clazz, // 
Function<List<String>, Map<String, ? extends Definition>> provider, // 
DefinitionType wantedType, String expectedType) throws IOException {
    // given
    // 
    BDDMockito.given(delegate.getDefinitionsMapByType(clazz)).willReturn(provider.apply(names));
    // when
    final Response response = when().get(getVersionPrefix() + "/definitions/" + wantedType).andReturn();
    // then
    assertEquals(OK.value(), response.getStatusCode());
    List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() {
    });
    assertEquals(names.size(), actual.size());
    actual.forEach(d -> {
        assertEquals(expectedType, d.getType());
        // it's expected
        assertTrue(names.contains(d.getName().substring("mock ".length())));
    });
}
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)

Example 7 with DefinitionDTO

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

the class DefinitionsControllerTest method shouldFilterComponentsByTypology.

public void shouldFilterComponentsByTypology(ConnectorTypology wantedTypology, 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.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, // it's
    actual.stream().filter(dto -> dto.getTypologies().contains(wantedTypology.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)

Example 8 with DefinitionDTO

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

the class JdbcComponentTestIT method getJdbcDefinition.

@Test
public void getJdbcDefinition() throws java.io.IOException {
    // when
    Response response = // 
    given().accept(APPLICATION_JSON_UTF8_VALUE).expect().statusCode(200).log().ifError().get(getVersionPrefix() + "/definitions/DATA_STORE");
    // then
    List<DefinitionDTO> definitions = mapper.readerFor(TypeFactory.defaultInstance().constructCollectionType(List.class, DefinitionDTO.class)).readValue(response.asInputStream());
    DefinitionDTO jdbcDef = null;
    for (DefinitionDTO definition : definitions) {
        if (DATA_STORE_DEFINITION_NAME.equals(definition.getName())) {
            jdbcDef = definition;
            break;
        }
    }
    assertNotNull(jdbcDef);
}
Also used : Response(com.jayway.restassured.response.Response) DefinitionDTO(org.talend.components.service.rest.dto.DefinitionDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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