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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations