Search in sources :

Example 21 with Properties

use of org.talend.daikon.properties.Properties 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)

Example 22 with Properties

use of org.talend.daikon.properties.Properties in project components by Talend.

the class ComponentPropertiesImpl method updateNestedProperties.

/**
 * this will look for all authorized nested properties that shall be compatible with the nestedValues and copy all
 * nestedValues properties into this.<br>
 * This default implementation will look for all nested properties that matches the type of nestedValues and copy
 * all nestedValues properties into it. This way of course be overriden if some component want to prevent the copy
 * of a given type into it.
 *
 * @param nestedValues values to be used update this current ComponentProperties nested Properties.
 * @return true if the copy was done and false if the targetProperties does not accept the nestedValues type.
 */
@Override
public boolean updateNestedProperties(final Properties nestedValues) {
    if (nestedValues == null) {
        return false;
    }
    // else not null so perfect
    final AtomicBoolean isCopied = new AtomicBoolean(false);
    accept(new PropertiesVisitor() {

        @Override
        public void visit(Properties properties, Properties parent) {
            if (properties.getClass().isAssignableFrom(nestedValues.getClass())) {
                properties.copyValuesFrom(nestedValues);
                isCopied.set(true);
            }
        // else not a compatible nestedValues so keep going
        }
    }, this);
    return isCopied.get();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Properties(org.talend.daikon.properties.Properties) PropertiesVisitor(org.talend.daikon.properties.PropertiesVisitor)

Example 23 with Properties

use of org.talend.daikon.properties.Properties in project components by Talend.

the class FullExamplePropertiesTest method testAllCallBacksAreCalled.

@Test
public void testAllCallBacksAreCalled() throws Throwable {
    interactWithAllWidgets();
    Properties validateProperty = getComponentService().validateProperty(cp.validateAllCallbackCalled.getName(), cp);
    assertEquals(validateProperty.getValidationResult().getMessage(), Result.OK, validateProperty.getValidationResult().getStatus());
}
Also used : Properties(org.talend.daikon.properties.Properties) Test(org.junit.Test) AbstractComponentTest(org.talend.components.api.test.AbstractComponentTest)

Example 24 with Properties

use of org.talend.daikon.properties.Properties in project components by Talend.

the class FullExamplePropertiesTest method testHiddingAField.

@Test
public void testHiddingAField() throws Throwable {
    assertFalse(cp.getForm(Form.MAIN).getWidget(cp.stringProp.getName()).isHidden());
    cp.hideStringPropProp.setValue(true);
    Properties resultCP = getComponentService().afterProperty(cp.hideStringPropProp.getName(), cp);
    assertTrue(resultCP.getForm(Form.MAIN).getWidget(cp.stringProp.getName()).isHidden());
}
Also used : Properties(org.talend.daikon.properties.Properties) Test(org.junit.Test) AbstractComponentTest(org.talend.components.api.test.AbstractComponentTest)

Aggregations

Properties (org.talend.daikon.properties.Properties)24 ComponentProperties (org.talend.components.api.properties.ComponentProperties)15 Test (org.junit.Test)7 NamedThing (org.talend.daikon.NamedThing)7 ComponentReferenceProperties (org.talend.components.api.properties.ComponentReferenceProperties)6 Property (org.talend.daikon.properties.property.Property)6 SimpleNamedThing (org.talend.daikon.SimpleNamedThing)5 SchemaProperty (org.talend.daikon.properties.property.SchemaProperty)4 ArrayList (java.util.ArrayList)3 DatasetProperties (org.talend.components.common.dataset.DatasetProperties)3 DatastoreProperties (org.talend.components.common.datastore.DatastoreProperties)3 INode (org.talend.core.model.process.INode)3 List (java.util.List)2 Schema (org.apache.avro.Schema)2 AbstractComponentTest (org.talend.components.api.test.AbstractComponentTest)2 SalesforceConnectionModuleProperties (org.talend.components.salesforce.SalesforceConnectionModuleProperties)2 SalesforceConnectionProperties (org.talend.components.salesforce.SalesforceConnectionProperties)2 SalesforceModuleProperties (org.talend.components.salesforce.SalesforceModuleProperties)2 TSalesforceInputProperties (org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties)2 TSalesforceOutputProperties (org.talend.components.salesforce.tsalesforceoutput.TSalesforceOutputProperties)2