JdbcConnectionLoader implements BundleEntityLoader { @Override public void load(final Bundle bundle, final Element element) { final Element jdbcConnectionElement = getSingleChildElement(getSingleChildElement(element, RESOURCE), JDBC_CONNECTION); final String name = getSingleChildElementTextContent(jdbcConnectionElement, NAME); final Map<String, Object> properties = mapPropertiesElements(getSingleChildElement(jdbcConnectionElement, PROPERTIES, true), PROPERTIES); final Integer minPoolSize = (Integer) properties.remove(PROPERTY_MIN_POOL_SIZE); final Integer maxPoolSize = (Integer) properties.remove(PROPERTY_MAX_POOL_SIZE); final Element extension = getSingleChildElement(jdbcConnectionElement, EXTENSION); final String driverClass = getSingleChildElementTextContent(extension, DRIVER_CLASS); final String jdbcUrl = getSingleChildElementTextContent(extension, JDBC_URL); final Map<String, Object> connectionProperties = mapPropertiesElements(getSingleChildElement(extension, CONNECTION_PROPERTIES, true), CONNECTION_PROPERTIES); final String user = (String) connectionProperties.remove(PROPERTY_USER); final String password = (String) connectionProperties.remove(PROPERTY_PASSWORD); JdbcConnection jdbcConnection = new JdbcConnection(); jdbcConnection.setName(name); jdbcConnection.setId(jdbcConnectionElement.getAttribute(ATTRIBUTE_ID)); jdbcConnection.setJdbcUrl(jdbcUrl); jdbcConnection.setDriverClass(driverClass); jdbcConnection.setUser(user); jdbcConnection.setPassword(password); jdbcConnection.setMinimumPoolSize(minPoolSize); jdbcConnection.setMaximumPoolSize(maxPoolSize); jdbcConnection.setProperties(connectionProperties); Set<Annotation> annotations = new HashSet<>(); Annotation bundleEntity = new Annotation(AnnotationType.BUNDLE_HINTS); bundleEntity.setId(jdbcConnectionElement.getAttribute(ATTRIBUTE_ID)); annotations.add(bundleEntity); jdbcConnection.setAnnotations(annotations); bundle.getJdbcConnections().put(name, jdbcConnection); } @VisibleForTesting  JdbcConnectionLoader(); @Override void load(final Bundle bundle, final Element element); @Override String getEntityType();  }
@Test void load() { Bundle bundle = new Bundle(); loader.load(bundle, createJdbcXml(DocumentTools.INSTANCE.getDocumentBuilder().newDocument())); assertFalse(bundle.getJdbcConnections().isEmpty()); assertEquals(1, bundle.getJdbcConnections().size()); assertNotNull(bundle.getJdbcConnections().get("Test")); JdbcConnection entity = bundle.getJdbcConnections().get("Test"); assertNotNull(entity); assertEquals(1, entity.getMinimumPoolSize().intValue()); assertEquals(2, entity.getMaximumPoolSize().intValue()); }