use of com.mysql.cj.conf.PropertySet in project JavaSegundasQuintas by ecteruel.
the class ZeroDateTimeToNullValueFactoryTest method testBasics.
@Test
public void testBasics() {
PropertySet pset = new DefaultPropertySet();
pset.<PropertyDefinitions.ZeroDatetimeBehavior>getEnumProperty(PropertyKey.zeroDateTimeBehavior).setValue(ZeroDatetimeBehavior.CONVERT_TO_NULL);
LocalDateTimeValueFactory vf = new LocalDateTimeValueFactory(pset);
assertNull(vf.createFromDate(new InternalDate()));
assertEquals(LocalDateTime.of(2018, 1, 1, 0, 0, 0, 0), vf.createFromDate(new InternalDate(2018, 1, 1)));
assertNotNull(vf.createFromTime(new InternalTime()));
assertEquals(LocalDateTime.ofEpochSecond(0, 0, ZoneOffset.UTC), vf.createFromTime(new InternalTime()));
assertThrows(DataReadException.class, "The value '-1:00:00' is an invalid TIME value. JDBC Time objects represent a wall-clock time and not a duration as MySQL treats them. If you are treating this type as a duration, consider retrieving this value as a string and dealing with it according to your requirements.", new Callable<Void>() {
@Override
public Void call() throws Exception {
vf.createFromTime(new InternalTime(-1, 0, 0, 0, 0));
return null;
}
});
assertThrows(DataReadException.class, "The value '44:00:00' is an invalid TIME value. JDBC Time objects represent a wall-clock time and not a duration as MySQL treats them. If you are treating this type as a duration, consider retrieving this value as a string and dealing with it according to your requirements.", new Callable<Void>() {
@Override
public Void call() throws Exception {
vf.createFromTime(new InternalTime(44, 0, 0, 0, 0));
return null;
}
});
assertEquals(LocalDateTime.of(1970, 1, 1, 1, 1, 1, 1), vf.createFromTime(new InternalTime(1, 1, 1, 1, 9)));
assertNull(vf.createFromTimestamp(new InternalTimestamp(0, 0, 0, 0, 0, 0, 0, 0)));
assertThrows(DataReadException.class, "Zero date value prohibited", new Callable<Void>() {
@Override
public Void call() throws Exception {
vf.createFromTimestamp(new InternalTimestamp(0, 0, 0, 1, 1, 1, 1, 9));
return null;
}
});
assertThrows(DateTimeException.class, "Invalid value for MonthOfYear \\(valid values 1 - 12\\): 0", new Callable<Void>() {
@Override
public Void call() throws Exception {
assertEquals(LocalDateTime.of(0, 0, 1, 1, 1, 1, 1), vf.createFromTimestamp(new InternalTimestamp(0, 0, 1, 1, 1, 1, 1, 9)));
return null;
}
});
assertThrows(DateTimeException.class, "Invalid value for DayOfMonth \\(valid values 1 - 28/31\\): 0", new Callable<Void>() {
@Override
public Void call() throws Exception {
assertEquals(LocalDateTime.of(0, 1, 0, 1, 1, 1, 1), vf.createFromTimestamp(new InternalTimestamp(0, 1, 0, 1, 1, 1, 1, 9)));
return null;
}
});
assertEquals(LocalDateTime.of(0, 1, 1, 1, 1, 1, 1), vf.createFromTimestamp(new InternalTimestamp(0, 1, 1, 1, 1, 1, 1, 9)));
assertThrows(DateTimeException.class, "Invalid value for MonthOfYear \\(valid values 1 - 12\\): 0", new Callable<Void>() {
@Override
public Void call() throws Exception {
assertEquals(LocalDateTime.of(2018, 0, 0, 1, 1, 1, 1), vf.createFromTimestamp(new InternalTimestamp(2018, 0, 0, 1, 1, 1, 1, 9)));
return null;
}
});
assertThrows(DateTimeException.class, "Invalid value for MonthOfYear \\(valid values 1 - 12\\): 0", new Callable<Void>() {
@Override
public Void call() throws Exception {
assertEquals(LocalDateTime.of(2018, 0, 1, 1, 1, 1, 1), vf.createFromTimestamp(new InternalTimestamp(2018, 0, 1, 1, 1, 1, 1, 9)));
return null;
}
});
assertThrows(DateTimeException.class, "Invalid value for DayOfMonth \\(valid values 1 - 28/31\\): 0", new Callable<Void>() {
@Override
public Void call() throws Exception {
assertEquals(LocalDateTime.of(2018, 1, 0, 1, 1, 1, 1), vf.createFromTimestamp(new InternalTimestamp(2018, 1, 0, 1, 1, 1, 1, 9)));
return null;
}
});
assertEquals(LocalDateTime.of(2018, 1, 1, 1, 1, 1, 1), vf.createFromTimestamp(new InternalTimestamp(2018, 1, 1, 1, 1, 1, 1, 9)));
assertEquals("java.time.LocalDateTime", vf.getTargetTypeName());
}
use of com.mysql.cj.conf.PropertySet in project ABC by RuiPinto96274.
the class InternalXBaseTestCase method createTestSession.
public MysqlxSession createTestSession() {
PropertySet pset = new DefaultPropertySet();
pset.initializeProperties(this.testProperties);
MysqlxSession session = new MysqlxSession(this.testHostInfo, pset);
return session;
}
use of com.mysql.cj.conf.PropertySet in project ABC by RuiPinto96274.
the class ClientImpl method newPooledXProtocol.
private PooledXProtocol newPooledXProtocol(HostInfo hi) {
PooledXProtocol tryProt;
PropertySet pset = new DefaultPropertySet();
pset.initializeProperties(hi.exposeAsProperties());
tryProt = new PooledXProtocol(hi, pset);
tryProt.addListener(this);
tryProt.connect(hi.getUser(), hi.getPassword(), hi.getDatabase());
return tryProt;
}
use of com.mysql.cj.conf.PropertySet in project JavaSegundasQuintas by ecteruel.
the class SessionImpl method getUri.
public String getUri() {
PropertySet pset = this.session.getPropertySet();
StringBuilder sb = new StringBuilder(ConnectionUrl.Type.XDEVAPI_SESSION.getScheme());
sb.append("//").append(this.session.getProcessHost()).append(":").append(this.session.getPort()).append("/").append(this.defaultSchemaName).append("?");
boolean isFirstParam = true;
for (PropertyKey propKey : PropertyDefinitions.PROPERTY_KEY_TO_PROPERTY_DEFINITION.keySet()) {
RuntimeProperty<?> propToGet = pset.getProperty(propKey);
if (propToGet.isExplicitlySet()) {
String propValue = propToGet.getStringValue();
Object defaultValue = propToGet.getPropertyDefinition().getDefaultValue();
if (defaultValue == null && !StringUtils.isNullOrEmpty(propValue) || defaultValue != null && propValue == null || defaultValue != null && propValue != null && !propValue.equals(defaultValue.toString())) {
if (isFirstParam) {
isFirstParam = false;
} else {
sb.append("&");
}
sb.append(propKey.getKeyName());
sb.append("=");
sb.append(propValue);
}
// TODO custom properties?
}
}
return sb.toString();
}
use of com.mysql.cj.conf.PropertySet in project JavaSegundasQuintas by ecteruel.
the class SecureSessionTest method testXdevapiSslConnectionOptions.
/**
* Tests that given SSL/TLS related session properties values are processed as expected.
*
* @throws Exception
*/
@Test
public void testXdevapiSslConnectionOptions() throws Exception {
assumeTrue(supportsTestCertificates(this.session), "This test requires the server configured with SSL certificates from ConnectorJ/src/test/config/ssl-test-certs");
Session testSess;
PropertySet propSet;
/*
* Check defaults.
*/
testSess = this.fact.getSession(this.sslFreeBaseUrl);
propSet = ((SessionImpl) testSess).getSession().getPropertySet();
// X DevAPI options.
assertEquals(XdevapiSslMode.REQUIRED, propSet.getProperty(PropertyKey.xdevapiSslMode).getValue());
assertNull(propSet.getProperty(PropertyKey.xdevapiSslTrustStoreUrl).getValue());
assertEquals("JKS", propSet.getProperty(PropertyKey.xdevapiSslTrustStoreType).getValue());
assertNull(propSet.getProperty(PropertyKey.xdevapiSslTrustStorePassword).getValue());
assertTrue(propSet.getBooleanProperty(PropertyKey.xdevapiFallbackToSystemTrustStore).getValue());
assertNull(propSet.getProperty(PropertyKey.xdevapiSslKeyStoreUrl).getValue());
assertEquals("JKS", propSet.getProperty(PropertyKey.xdevapiSslKeyStoreType).getValue());
assertNull(propSet.getProperty(PropertyKey.xdevapiSslKeyStorePassword).getValue());
assertTrue(propSet.getBooleanProperty(PropertyKey.xdevapiFallbackToSystemKeyStore).getValue());
// Global (JDBC) options.
assertEquals(SslMode.REQUIRED, propSet.getProperty(PropertyKey.sslMode).getValue());
assertNull(propSet.getProperty(PropertyKey.trustCertificateKeyStoreUrl).getValue());
assertEquals("JKS", propSet.getProperty(PropertyKey.trustCertificateKeyStoreType).getValue());
assertNull(propSet.getProperty(PropertyKey.trustCertificateKeyStorePassword).getValue());
assertTrue(propSet.getBooleanProperty(PropertyKey.fallbackToSystemTrustStore).getValue());
assertNull(propSet.getProperty(PropertyKey.clientCertificateKeyStoreUrl).getValue());
assertEquals("JKS", propSet.getProperty(PropertyKey.clientCertificateKeyStoreType).getValue());
assertNull(propSet.getProperty(PropertyKey.clientCertificateKeyStorePassword).getValue());
assertTrue(propSet.getBooleanProperty(PropertyKey.fallbackToSystemKeyStore).getValue());
testSess.close();
/*
* Check SSL properties set globally (JDBC)
*/
Properties props = new Properties(this.sslFreeTestProperties);
// Set global SSL connection properties.
props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.VERIFY_CA.toString());
props.setProperty(PropertyKey.trustCertificateKeyStoreUrl.getKeyName(), "file:src/test/config/ssl-test-certs/ca-truststore");
props.setProperty(PropertyKey.trustCertificateKeyStoreType.getKeyName(), "JKS");
props.setProperty(PropertyKey.trustCertificateKeyStorePassword.getKeyName(), "password");
props.setProperty(PropertyKey.fallbackToSystemTrustStore.getKeyName(), "false");
props.setProperty(PropertyKey.clientCertificateKeyStoreUrl.getKeyName(), "file:src/test/config/ssl-test-certs/client-keystore");
props.setProperty(PropertyKey.clientCertificateKeyStoreType.getKeyName(), "JKS");
props.setProperty(PropertyKey.clientCertificateKeyStorePassword.getKeyName(), "password");
props.setProperty(PropertyKey.fallbackToSystemKeyStore.getKeyName(), "false");
testSess = this.fact.getSession(props);
propSet = ((SessionImpl) testSess).getSession().getPropertySet();
// X DevAPI options keep defaults.
assertEquals(XdevapiSslMode.REQUIRED, propSet.getProperty(PropertyKey.xdevapiSslMode).getValue());
assertNull(propSet.getProperty(PropertyKey.xdevapiSslTrustStoreUrl).getValue());
assertEquals("JKS", propSet.getProperty(PropertyKey.xdevapiSslTrustStoreType).getValue());
assertNull(propSet.getProperty(PropertyKey.xdevapiSslTrustStorePassword).getValue());
assertTrue(propSet.getBooleanProperty(PropertyKey.xdevapiFallbackToSystemTrustStore).getValue());
assertNull(propSet.getProperty(PropertyKey.xdevapiSslKeyStoreUrl).getValue());
assertEquals("JKS", propSet.getProperty(PropertyKey.xdevapiSslKeyStoreType).getValue());
assertNull(propSet.getProperty(PropertyKey.xdevapiSslKeyStorePassword).getValue());
assertTrue(propSet.getBooleanProperty(PropertyKey.xdevapiFallbackToSystemKeyStore).getValue());
// Global (JDBC) were set.
assertEquals(SslMode.VERIFY_CA, propSet.getProperty(PropertyKey.sslMode).getValue());
assertEquals("file:src/test/config/ssl-test-certs/ca-truststore", propSet.getProperty(PropertyKey.trustCertificateKeyStoreUrl).getValue());
assertEquals("JKS", propSet.getProperty(PropertyKey.trustCertificateKeyStoreType).getValue());
assertEquals("password", propSet.getProperty(PropertyKey.trustCertificateKeyStorePassword).getValue());
assertFalse(propSet.getBooleanProperty(PropertyKey.fallbackToSystemTrustStore).getValue());
assertEquals("file:src/test/config/ssl-test-certs/client-keystore", propSet.getProperty(PropertyKey.clientCertificateKeyStoreUrl).getValue());
assertEquals("JKS", propSet.getProperty(PropertyKey.clientCertificateKeyStoreType).getValue());
assertEquals("password", propSet.getProperty(PropertyKey.clientCertificateKeyStorePassword).getValue());
assertFalse(propSet.getBooleanProperty(PropertyKey.fallbackToSystemKeyStore).getValue());
testSess.close();
props.setProperty(PropertyKey.fallbackToSystemTrustStore.getKeyName(), "true");
props.setProperty(PropertyKey.fallbackToSystemKeyStore.getKeyName(), "true");
testSess = this.fact.getSession(props);
propSet = ((SessionImpl) testSess).getSession().getPropertySet();
// X DevAPI options keep defaults.
assertEquals(XdevapiSslMode.REQUIRED, propSet.getProperty(PropertyKey.xdevapiSslMode).getValue());
assertNull(propSet.getProperty(PropertyKey.xdevapiSslTrustStoreUrl).getValue());
assertEquals("JKS", propSet.getProperty(PropertyKey.xdevapiSslTrustStoreType).getValue());
assertNull(propSet.getProperty(PropertyKey.xdevapiSslTrustStorePassword).getValue());
assertTrue(propSet.getBooleanProperty(PropertyKey.xdevapiFallbackToSystemTrustStore).getValue());
assertNull(propSet.getProperty(PropertyKey.xdevapiSslKeyStoreUrl).getValue());
assertEquals("JKS", propSet.getProperty(PropertyKey.xdevapiSslKeyStoreType).getValue());
assertNull(propSet.getProperty(PropertyKey.xdevapiSslKeyStorePassword).getValue());
assertTrue(propSet.getBooleanProperty(PropertyKey.xdevapiFallbackToSystemKeyStore).getValue());
// Global (JDBC) options were set.
assertEquals(SslMode.VERIFY_CA, propSet.getProperty(PropertyKey.sslMode).getValue());
assertEquals("file:src/test/config/ssl-test-certs/ca-truststore", propSet.getProperty(PropertyKey.trustCertificateKeyStoreUrl).getValue());
assertEquals("JKS", propSet.getProperty(PropertyKey.trustCertificateKeyStoreType).getValue());
assertEquals("password", propSet.getProperty(PropertyKey.trustCertificateKeyStorePassword).getValue());
assertTrue(propSet.getBooleanProperty(PropertyKey.fallbackToSystemTrustStore).getValue());
assertEquals("file:src/test/config/ssl-test-certs/client-keystore", propSet.getProperty(PropertyKey.clientCertificateKeyStoreUrl).getValue());
assertEquals("JKS", propSet.getProperty(PropertyKey.clientCertificateKeyStoreType).getValue());
assertEquals("password", propSet.getProperty(PropertyKey.clientCertificateKeyStorePassword).getValue());
assertTrue(propSet.getBooleanProperty(PropertyKey.fallbackToSystemKeyStore).getValue());
testSess.close();
/*
* Check SSL properties set locally on the X DevAPI.
*/
props = new Properties(this.sslFreeTestProperties);
// Set global SSL connection properties.
props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.toString());
props.setProperty(PropertyKey.trustCertificateKeyStoreUrl.getKeyName(), "trust-cert-keystore-url");
props.setProperty(PropertyKey.trustCertificateKeyStoreType.getKeyName(), "trust-cert-keystore-type");
props.setProperty(PropertyKey.trustCertificateKeyStorePassword.getKeyName(), "trust-cert-keystore-pwd");
props.setProperty(PropertyKey.fallbackToSystemTrustStore.getKeyName(), "false");
props.setProperty(PropertyKey.clientCertificateKeyStoreUrl.getKeyName(), "client-cert-keystore-url");
props.setProperty(PropertyKey.clientCertificateKeyStoreType.getKeyName(), "client-cert-keystore-type");
props.setProperty(PropertyKey.clientCertificateKeyStorePassword.getKeyName(), "client-cert-keystore-pwd");
props.setProperty(PropertyKey.fallbackToSystemKeyStore.getKeyName(), "false");
// Set X DevAPI local connection properties.
props.setProperty(PropertyKey.xdevapiSslMode.getKeyName(), XdevapiSslMode.VERIFY_CA.toString());
props.setProperty(PropertyKey.xdevapiSslTrustStoreUrl.getKeyName(), "file:src/test/config/ssl-test-certs/ca-truststore");
props.setProperty(PropertyKey.xdevapiSslTrustStoreType.getKeyName(), "JKS");
props.setProperty(PropertyKey.xdevapiSslTrustStorePassword.getKeyName(), "password");
props.setProperty(PropertyKey.xdevapiFallbackToSystemTrustStore.getKeyName(), "false");
props.setProperty(PropertyKey.xdevapiSslKeyStoreUrl.getKeyName(), "file:src/test/config/ssl-test-certs/client-keystore");
props.setProperty(PropertyKey.xdevapiSslKeyStoreType.getKeyName(), "JKS");
props.setProperty(PropertyKey.xdevapiSslKeyStorePassword.getKeyName(), "password");
props.setProperty(PropertyKey.xdevapiFallbackToSystemKeyStore.getKeyName(), "false");
testSess = this.fact.getSession(props);
propSet = ((SessionImpl) testSess).getSession().getPropertySet();
// X DevAPI options were set.
assertEquals(XdevapiSslMode.VERIFY_CA, propSet.getProperty(PropertyKey.xdevapiSslMode).getValue());
assertEquals("file:src/test/config/ssl-test-certs/ca-truststore", propSet.getProperty(PropertyKey.xdevapiSslTrustStoreUrl).getValue());
assertEquals("JKS", propSet.getProperty(PropertyKey.xdevapiSslTrustStoreType).getValue());
assertEquals("password", propSet.getProperty(PropertyKey.xdevapiSslTrustStorePassword).getValue());
assertFalse(propSet.getBooleanProperty(PropertyKey.xdevapiFallbackToSystemTrustStore).getValue());
assertEquals("file:src/test/config/ssl-test-certs/client-keystore", propSet.getProperty(PropertyKey.xdevapiSslKeyStoreUrl).getValue());
assertEquals("JKS", propSet.getProperty(PropertyKey.xdevapiSslKeyStoreType).getValue());
assertEquals("password", propSet.getProperty(PropertyKey.xdevapiSslKeyStorePassword).getValue());
assertFalse(propSet.getBooleanProperty(PropertyKey.xdevapiFallbackToSystemKeyStore).getValue());
// Global (JDBC) options were overridden.
assertEquals(SslMode.VERIFY_CA, propSet.getProperty(PropertyKey.sslMode).getValue());
assertEquals("file:src/test/config/ssl-test-certs/ca-truststore", propSet.getProperty(PropertyKey.trustCertificateKeyStoreUrl).getValue());
assertEquals("JKS", propSet.getProperty(PropertyKey.trustCertificateKeyStoreType).getValue());
assertEquals("password", propSet.getProperty(PropertyKey.trustCertificateKeyStorePassword).getValue());
assertFalse(propSet.getBooleanProperty(PropertyKey.fallbackToSystemTrustStore).getValue());
assertEquals("file:src/test/config/ssl-test-certs/client-keystore", propSet.getProperty(PropertyKey.clientCertificateKeyStoreUrl).getValue());
assertEquals("JKS", propSet.getProperty(PropertyKey.clientCertificateKeyStoreType).getValue());
assertEquals("password", propSet.getProperty(PropertyKey.clientCertificateKeyStorePassword).getValue());
assertFalse(propSet.getBooleanProperty(PropertyKey.fallbackToSystemKeyStore).getValue());
testSess.close();
props.setProperty(PropertyKey.xdevapiFallbackToSystemTrustStore.getKeyName(), "true");
props.setProperty(PropertyKey.xdevapiFallbackToSystemKeyStore.getKeyName(), "true");
testSess = this.fact.getSession(props);
propSet = ((SessionImpl) testSess).getSession().getPropertySet();
// X DevAPI options were set.
assertEquals(XdevapiSslMode.VERIFY_CA, propSet.getProperty(PropertyKey.xdevapiSslMode).getValue());
assertEquals("file:src/test/config/ssl-test-certs/ca-truststore", propSet.getProperty(PropertyKey.xdevapiSslTrustStoreUrl).getValue());
assertEquals("JKS", propSet.getProperty(PropertyKey.xdevapiSslTrustStoreType).getValue());
assertEquals("password", propSet.getProperty(PropertyKey.xdevapiSslTrustStorePassword).getValue());
assertTrue(propSet.getBooleanProperty(PropertyKey.xdevapiFallbackToSystemTrustStore).getValue());
assertEquals("file:src/test/config/ssl-test-certs/client-keystore", propSet.getProperty(PropertyKey.xdevapiSslKeyStoreUrl).getValue());
assertEquals("JKS", propSet.getProperty(PropertyKey.xdevapiSslKeyStoreType).getValue());
assertEquals("password", propSet.getProperty(PropertyKey.xdevapiSslKeyStorePassword).getValue());
assertTrue(propSet.getBooleanProperty(PropertyKey.xdevapiFallbackToSystemKeyStore).getValue());
// Global (JDBC) options were overridden.
assertEquals(SslMode.VERIFY_CA, propSet.getProperty(PropertyKey.sslMode).getValue());
assertEquals("file:src/test/config/ssl-test-certs/ca-truststore", propSet.getProperty(PropertyKey.trustCertificateKeyStoreUrl).getValue());
assertEquals("JKS", propSet.getProperty(PropertyKey.trustCertificateKeyStoreType).getValue());
assertEquals("password", propSet.getProperty(PropertyKey.trustCertificateKeyStorePassword).getValue());
assertTrue(propSet.getBooleanProperty(PropertyKey.fallbackToSystemTrustStore).getValue());
assertEquals("file:src/test/config/ssl-test-certs/client-keystore", propSet.getProperty(PropertyKey.clientCertificateKeyStoreUrl).getValue());
assertEquals("JKS", propSet.getProperty(PropertyKey.clientCertificateKeyStoreType).getValue());
assertEquals("password", propSet.getProperty(PropertyKey.clientCertificateKeyStorePassword).getValue());
assertTrue(propSet.getBooleanProperty(PropertyKey.fallbackToSystemKeyStore).getValue());
testSess.close();
}
Aggregations