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/org/apache/dubbo/config/spring/status/DataSourceStatusCheckerTest.java
test_class.identifier: DataSourceStatusCheckerTest
test_case.body: @Test
      public void testWithDatasourceNotHasNextResult() 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(false);
  
          map.put("mockDatabase", dataSource);
          given(applicationContext.getBeansOfType(eq(DataSource.class), anyBoolean(), anyBoolean())).willReturn(map);
          Status status = dataSourceStatusChecker.check();
  
          assertThat(status.getLevel(), is(Status.Level.ERROR));
      }
test_case.class_method_signature: DataSourceStatusCheckerTest.testWithDatasourceNotHasNextResult()
test_case.full_signature: @Test public void testWithDatasourceNotHasNextResult()
test_case.identifier: testWithDatasourceNotHasNextResult
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 testWithDatasourceNotHasNextResult()
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/org/apache/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 public Status check()
focal_class.identifier: check
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: Status
focal_class.signature: Status check()
focal_method.body: @Override
      public Status check() {
          Optional<ApplicationContext> context =
                  SpringExtensionFactory.getContexts().stream().filter(Objects::nonNull).findFirst();
  
          if (!context.isPresent()) {
              return new Status(Status.Level.UNKNOWN);
          }
  
          Map<String, DataSource> dataSources =
                  context.get().getBeansOfType(DataSource.class, false, false);
          if (CollectionUtils.isEmptyMap(dataSources)) {
              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()) {
                  DatabaseMetaData metaData = connection.getMetaData();
                  try (ResultSet resultSet = metaData.getTypeInfo()) {
                      if (!resultSet.next()) {
                          level = Status.Level.ERROR;
                      }
                  }
                  buf.append(metaData.getURL());
                  buf.append("(");
                  buf.append(metaData.getDatabaseProductName());
                  buf.append("-");
                  buf.append(metaData.getDatabaseProductVersion());
                  buf.append(")");
              } 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 public Status check()
focal_method.identifier: check
focal_method.invocations: findFirst filter stream getContexts isPresent getBeansOfType get isEmptyMap entrySet getValue length append append getKey getConnection getMetaData getTypeInfo next append getURL append append getDatabaseProductName append append getDatabaseProductVersion append warn getMessage getMessage toString
focal_method.modifiers: @Override public
focal_method.parameters: ()
focal_method.return: Status
focal_method.signature: Status check()