use of org.apache.kafka.common.config.ConfigDef in project kafka by apache.
the class StandaloneHerderTest method expectConfigValidation.
private void expectConfigValidation(Map<String, String>... configs) {
// config validation
ConnectorFactory connectorFactoryMock = PowerMock.createMock(ConnectorFactory.class);
EasyMock.expect(worker.getConnectorFactory()).andStubReturn(connectorFactoryMock);
Connector connectorMock = PowerMock.createMock(Connector.class);
EasyMock.expect(connectorFactoryMock.newConnector(EasyMock.anyString())).andReturn(connectorMock);
EasyMock.expect(connectorMock.config()).andStubReturn(new ConfigDef());
for (Map<String, String> config : configs) EasyMock.expect(connectorMock.validate(config)).andReturn(new Config(Collections.<ConfigValue>emptyList()));
}
use of org.apache.kafka.common.config.ConfigDef in project kafka by apache.
the class StandaloneHerderTest method testCreateConnectorFailedCustomValidation.
@Test
public void testCreateConnectorFailedCustomValidation() throws Exception {
connector = PowerMock.createMock(BogusSourceConnector.class);
Map<String, String> config = connectorConfig(SourceSink.SOURCE);
ConnectorFactory connectorFactoryMock = PowerMock.createMock(ConnectorFactory.class);
EasyMock.expect(worker.getConnectorFactory()).andStubReturn(connectorFactoryMock);
Connector connectorMock = PowerMock.createMock(Connector.class);
EasyMock.expect(connectorFactoryMock.newConnector(EasyMock.anyString())).andReturn(connectorMock);
ConfigDef configDef = new ConfigDef();
configDef.define("foo.bar", ConfigDef.Type.STRING, ConfigDef.Importance.HIGH, "foo.bar doc");
EasyMock.expect(connectorMock.config()).andReturn(configDef);
ConfigValue validatedValue = new ConfigValue("foo.bar");
validatedValue.addErrorMessage("Failed foo.bar validation");
EasyMock.expect(connectorMock.validate(config)).andReturn(new Config(singletonList(validatedValue)));
createCallback.onCompletion(EasyMock.<BadRequestException>anyObject(), EasyMock.<Herder.Created<ConnectorInfo>>isNull());
PowerMock.expectLastCall();
PowerMock.replayAll();
herder.putConnectorConfig(CONNECTOR_NAME, config, false, createCallback);
PowerMock.verifyAll();
}
use of org.apache.kafka.common.config.ConfigDef in project kafka by apache.
the class ConnectorPluginsResourceTest method testValidateConfig.
@Test
public void testValidateConfig() throws Throwable {
herder.validateConnectorConfig(EasyMock.eq(props));
PowerMock.expectLastCall().andAnswer(new IAnswer<ConfigInfos>() {
@Override
public ConfigInfos answer() {
ConfigDef connectorConfigDef = ConnectorConfig.configDef();
List<ConfigValue> connectorConfigValues = connectorConfigDef.validate(props);
Connector connector = new ConnectorPluginsResourceTestConnector();
Config config = connector.validate(props);
ConfigDef configDef = connector.config();
Map<String, ConfigDef.ConfigKey> configKeys = configDef.configKeys();
List<ConfigValue> configValues = config.configValues();
Map<String, ConfigDef.ConfigKey> resultConfigKeys = new HashMap<>(configKeys);
resultConfigKeys.putAll(connectorConfigDef.configKeys());
configValues.addAll(connectorConfigValues);
return AbstractHerder.generateResult(ConnectorPluginsResourceTestConnector.class.getName(), resultConfigKeys, configValues, Collections.singletonList("Test"));
}
});
PowerMock.replayAll();
ConfigInfos configInfos = connectorPluginsResource.validateConfigs(ConnectorPluginsResourceTestConnector.class.getName(), props);
assertEquals(CONFIG_INFOS.name(), configInfos.name());
assertEquals(CONFIG_INFOS.errorCount(), configInfos.errorCount());
assertEquals(CONFIG_INFOS.groups(), configInfos.groups());
assertEquals(new HashSet<>(CONFIG_INFOS.values()), new HashSet<>(configInfos.values()));
PowerMock.verifyAll();
}
use of org.apache.kafka.common.config.ConfigDef in project connect-utils by jcustenborder.
the class TemplateInput method fromConnector.
public static TemplateInput fromConnector(Class<? extends Connector> connectorClass) throws IllegalAccessException, InstantiationException {
final TemplateInput result = new TemplateInput();
Connector connector = connectorClass.newInstance();
ConfigDef config = connector.config();
assertNotNull(config, "config() cannot return a null.");
populateTemplate(connectorClass, result, config);
return result;
}
use of org.apache.kafka.common.config.ConfigDef in project connect-utils by jcustenborder.
the class TemplateInput method fromTransformation.
public static TemplateInput fromTransformation(Class<? extends Transformation> transform) throws IllegalAccessException, InstantiationException {
final TemplateInput result = new TemplateInput();
Transformation sourceConnector = transform.newInstance();
ConfigDef config = sourceConnector.config();
assertNotNull(config, "config() cannot return a null.");
populateTemplate(transform, result, config);
return result;
}
Aggregations