test_class.declarator: dataSourceStatusChecker
test_class.modifier: private
test_class.original_string: private DataSourceStatusChecker dataSourceStatusChecker;
test_class.type: DataSourceStatusChecker
test_class.var_name: dataSourceStatusChecker
test_class.declarator: applicationContext
test_class.modifier: @Mock
      private
test_class.original_string: @Mock
      private ApplicationContext applicationContext;
test_class.type: ApplicationContext
test_class.var_name: applicationContext
test_class.file: dubbo-config/dubbo-config-spring/src/test/java/com/alibaba/dubbo/config/spring/status/DataSourceStatusCheckerTest.java
test_class.identifier: DataSourceStatusCheckerTest
test_case.body: @Test
      public void testWithDatasourceHasNextResult() throws SQLException {
          Map<String, DataSource> map = new HashMap<String, DataSource>();
          DataSource dataSource = mock(DataSource.class);
          Connection connection = mock(Connection.class, Answers.RETURNS_DEEP_STUBS);
          given(dataSource.getConnection()).willReturn(connection);
          given(connection.getMetaData().getTypeInfo().next()).willReturn(true);
  
          map.put("mockDatabase", dataSource);
          given(applicationContext.getBeansOfType(eq(DataSource.class), anyBoolean(), anyBoolean())).willReturn(map);
          Status status = dataSourceStatusChecker.check();
  
          assertThat(status.getLevel(), is(Status.Level.OK));
      }
test_case.class_method_signature: DataSourceStatusCheckerTest.testWithDatasourceHasNextResult()
test_case.full_signature: @Test public void testWithDatasourceHasNextResult()
test_case.identifier: testWithDatasourceHasNextResult
test_case.invocations: mock mock willReturn given getConnection willReturn given next getTypeInfo getMetaData put willReturn given getBeansOfType eq anyBoolean anyBoolean check assertThat getLevel is
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testWithDatasourceHasNextResult()
focal_class.declarator: logger = LoggerFactory.getLogger(DataSourceStatusChecker.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger logger = LoggerFactory.getLogger(DataSourceStatusChecker.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.file: dubbo-config/dubbo-config-spring/src/main/java/com/alibaba/dubbo/config/spring/status/DataSourceStatusChecker.java
focal_class.identifier: DataSourceStatusChecker
focal_class.interfaces: implements StatusChecker
focal_class.class_method_signature: DataSourceStatusChecker.check()
focal_class.full_signature: @Override @SuppressWarnings("unchecked") public Status check()
focal_class.identifier: check
focal_class.modifiers: @Override @SuppressWarnings("unchecked") public
focal_class.parameters: ()
focal_class.return: Status
focal_class.signature: Status check()
focal_method.body: @Override
      @SuppressWarnings("unchecked")
      public Status check() {
          ApplicationContext context = null;
          for (ApplicationContext c : SpringExtensionFactory.getContexts()) {
              if (c != null) {
                  context = c;
                  break;
              }
          }
          if (context == null) {
              return new Status(Status.Level.UNKNOWN);
          }
          Map<String, DataSource> dataSources = context.getBeansOfType(DataSource.class, false, false);
          if (dataSources == null || dataSources.size() == 0) {
              return new Status(Status.Level.UNKNOWN);
          }
          Status.Level level = Status.Level.OK;
          StringBuilder buf = new StringBuilder();
          for (Map.Entry<String, DataSource> entry : dataSources.entrySet()) {
              DataSource dataSource = entry.getValue();
              if (buf.length() > 0) {
                  buf.append(", ");
              }
              buf.append(entry.getKey());
              try {
                  Connection connection = dataSource.getConnection();
                  try {
                      DatabaseMetaData metaData = connection.getMetaData();
                      ResultSet resultSet = metaData.getTypeInfo();
                      try {
                          if (!resultSet.next()) {
                              level = Status.Level.ERROR;
                          }
                      } finally {
                          resultSet.close();
                      }
                      buf.append(metaData.getURL());
                      buf.append("(");
                      buf.append(metaData.getDatabaseProductName());
                      buf.append("-");
                      buf.append(metaData.getDatabaseProductVersion());
                      buf.append(")");
                  } finally {
                      connection.close();
                  }
              } catch (Throwable e) {
                  logger.warn(e.getMessage(), e);
                  return new Status(level, e.getMessage());
              }
          }
          return new Status(level, buf.toString());
      }
focal_method.class_method_signature: DataSourceStatusChecker.check()
focal_method.full_signature: @Override @SuppressWarnings("unchecked") public Status check()
focal_method.identifier: check
focal_method.invocations: getContexts getBeansOfType size entrySet getValue length append append getKey getConnection getMetaData getTypeInfo next close append getURL append append getDatabaseProductName append append getDatabaseProductVersion append close warn getMessage getMessage toString
focal_method.modifiers: @Override @SuppressWarnings("unchecked") public
focal_method.parameters: ()
focal_method.return: Status
focal_method.signature: Status check()