Search in sources :

Example 1 with DatastoreDefinition

use of org.talend.components.common.datastore.DatastoreDefinition in project components by Talend.

the class DataStoreServiceImplTest method getDatastoreDefinition.

@Test
@Ignore
public void getDatastoreDefinition() throws Exception {
    // Given
    ArrayList<DatastoreDefinition> definitions = new ArrayList<>();
    DatastoreDefinition dsd1 = mock(DatastoreDefinition.class);
    when(dsd1.getName()).thenReturn("toto");
    definitions.add(dsd1);
    DatastoreDefinition dsd2 = mock(DatastoreDefinition.class);
    String datastoreName = "datastore name";
    when(dsd2.getName()).thenReturn(datastoreName);
    definitions.add(dsd2);
    when(defRegistryDelegate.getDefinitionsMapByType(DatastoreDefinition.class).values()).thenReturn(definitions);
// When
// DatastoreDefinition datastoreDefinition = dataStoreController.getDataStoreProperties(datastoreName);
// 
// // Then
// assertEquals(dsd2, datastoreDefinition);
// verify(componentServiceDelegate, times(1)).getDefinitionsByType(DatastoreDefinition.class);
// verify(dsd1, times(1)).getName();
// verify(dsd2, times(1)).getName();
}
Also used : ArrayList(java.util.ArrayList) DatastoreDefinition(org.talend.components.common.datastore.DatastoreDefinition) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with DatastoreDefinition

use of org.talend.components.common.datastore.DatastoreDefinition 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 3 with DatastoreDefinition

use of org.talend.components.common.datastore.DatastoreDefinition in project components by Talend.

the class AbstractSpringIntegrationTests method setUp.

@Before
public void setUp() {
    // ensure any call from restassured goes to our server isntance
    RestAssured.port = localServerPort;
    // Init the mock delegate to return our data store mock on demand
    MockDatastoreDefinition datastoreDefinition = new MockDatastoreDefinition(DATA_STORE_DEFINITION_NAME);
    MockDatasetDefinition datasetDefinition = new MockDatasetDefinition(DATA_SET_DEFINITION_NAME);
    Map<String, DatastoreDefinition> datastoresMap = singletonMap(DATA_STORE_DEFINITION_NAME, datastoreDefinition);
    // 
    when(delegate.getDefinitionsMapByType(DatastoreDefinition.class)).thenReturn(datastoresMap);
    Map<String, DatasetDefinition> datasetMap = singletonMap(DATA_SET_DEFINITION_NAME, datasetDefinition);
    // 
    when(delegate.getDefinitionsMapByType(DatasetDefinition.class)).thenReturn(datasetMap);
    Map<String, Definition> runtimablesMap = new HashMap<>();
    runtimablesMap.putAll(datastoresMap);
    runtimablesMap.putAll(datasetMap);
    // 
    when(delegate.getDefinitionsMapByType(Definition.class)).thenReturn(runtimablesMap);
    // 
    when(delegate.getDefinitionsMapByType(Definition.class)).thenReturn(runtimablesMap);
    // TODO: map the dataset definition on the correct name
    when(delegate.getDefinitionForPropertiesType(MockDatasetProperties.class)).thenReturn(singletonList(datasetDefinition));
    when(delegate.getDefinitionForPropertiesType(MockDatastoreProperties.class)).thenReturn(singletonList(datastoreDefinition));
    when(delegate.createProperties(any(Definition.class), anyString())).thenAnswer(i -> {
        Properties properties = PropertiesImpl.createNewInstance(((Definition<Properties>) i.getArguments()[0]).getPropertiesClass(), (String) i.getArguments()[1]);
        properties.init();
        return properties;
    });
}
Also used : MockDatasetDefinition(org.talend.components.service.rest.mock.MockDatasetDefinition) HashMap(java.util.HashMap) Definition(org.talend.daikon.definition.Definition) MockDatasetDefinition(org.talend.components.service.rest.mock.MockDatasetDefinition) DatasetDefinition(org.talend.components.common.dataset.DatasetDefinition) DatastoreDefinition(org.talend.components.common.datastore.DatastoreDefinition) MockDatastoreDefinition(org.talend.components.service.rest.mock.MockDatastoreDefinition) MockDatastoreDefinition(org.talend.components.service.rest.mock.MockDatastoreDefinition) Matchers.anyString(org.mockito.Matchers.anyString) MockDatasetDefinition(org.talend.components.service.rest.mock.MockDatasetDefinition) DatasetDefinition(org.talend.components.common.dataset.DatasetDefinition) MockDatastoreProperties(org.talend.components.service.rest.mock.MockDatastoreProperties) Properties(org.talend.daikon.properties.Properties) MockDatasetProperties(org.talend.components.service.rest.mock.MockDatasetProperties) DatastoreDefinition(org.talend.components.common.datastore.DatastoreDefinition) MockDatastoreDefinition(org.talend.components.service.rest.mock.MockDatastoreDefinition) Before(org.junit.Before)

Aggregations

DatastoreDefinition (org.talend.components.common.datastore.DatastoreDefinition)3 Definition (org.talend.daikon.definition.Definition)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 StreamSupport.stream (java.util.stream.StreamSupport.stream)1 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Logger (org.slf4j.Logger)1 LoggerFactory.getLogger (org.slf4j.LoggerFactory.getLogger)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 ComponentDefinition (org.talend.components.api.component.ComponentDefinition)1 ExecutionEngine (org.talend.components.api.component.runtime.ExecutionEngine)1 DatasetDefinition (org.talend.components.common.dataset.DatasetDefinition)1 DefinitionType (org.talend.components.service.rest.DefinitionType)1