org.neo4j.ogm.exception.ResultProcessingException:无法解析响应

时间:2016-07-18 17:56:22

标签: junit neo4j spring-data-neo4j-4

我创建了一个新的Maven项目:

https://github.com/neosamples/neosamples

我逐渐复制内容:

https://github.com/luanne/flavorwocky

更好地了解它是如何工作的以及需要哪些依赖项。现在我想让单元测试将新项添加到GraphRepository中。目前我的项目有这样的布局:

enter image description here

其中:

Application.java

package com.samples.neo4j;

 ...(imports)

@Configuration
@ComponentScan("com.samples.neo4j")
@EnableAutoConfiguration
@EnableTransactionManagement
@EnableNeo4jRepositories("com.samples.neo4j.repository")
public class Application extends Neo4jConfiguration {

  final String grapheneUrl;

  public Application() {
    grapheneUrl = "http://neo4j:neopass@localhost:7474";
  }

  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }

  @Bean
  public org.neo4j.ogm.config.Configuration getConfiguration() {
    org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration();
    config.driverConfiguration().setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver").setURI(grapheneUrl);
    return config;
  }

  @Override
  @Bean
  public SessionFactory getSessionFactory() {
    return new SessionFactory(getConfiguration(), "com.samples.neo4j.domain");
  }

  @Override
  @Bean
  @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
  public Session getSession() throws Exception {
    return super.getSession();
  }
}

neo4j 是用户, neopass 是我在访问时使用的密码: http://localhost:7474/browser/

我正在尝试运行此单元测试:

@ContextConfiguration(classes = { PersistenceContext.class })
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)

public class ServiceTest {
  @Autowired
  MyNodeRepository nodeRepository;

  @Autowired
  Session session;

  @After
  public void tearDown() {
    session.purgeDatabase();
  }

  @Test
  public void test() {
    MyNode n = new MyNode("test");
    nodeRepository.save(n);
    MyNode node = IteratorUtil.firstOrNull(nodeRepository.findAll());
    assertNotNull(node);
  }
}

但是当我运行上面的单元测试时,我在控制台中得到以下错误:

2016-07-19 12:39:41,571  WARN o4j.ogm.drivers.http.request.HttpRequest: 235 - Caught response exception: Unauthorized
2016-07-19 12:39:41,596  WARN o4j.ogm.drivers.http.request.HttpRequest: 235 - Caught response exception: Auth scheme may not be null

和这个堆栈跟踪:

http://pastebin.com/tK42AqtW

我已经尝试过很长一段时间来自定义我的pom依赖项,但我觉得我在圈子里跑,下面是我目前的配置:

http://pastebin.com/5vt2EBdu

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

看起来您的身份验证凭据不太合适。如果您已经采用了flavorwocky配置,那么您不清楚GRAPHENEDB_URL代表什么。也许修改你的代码直接配置URI如下:

Application.java

config.driverConfiguration().setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver").setURI("http://neo4j:password@localhost:7474");

(用你正在使用的任何东西替换neo4j用户名/密码/主机/端口)

修改

问题是这种依赖性与SDN 4.1.2使用的驱动程序不兼容:

<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-ogm-drivers</artifactId>
    <version>2.0.0-M02</version>
    <scope>test</scope>         
</dependency>

您不需要在HTTP驱动程序中包含依赖项。但是如果您使用的是Embedded或Bolt,那么您需要包含这些(记录为here

如果删除此依赖项,则不再存在身份验证问题,但您的测试仍会失败,因为MyNode无法实例化 - 它需要一个no-args构造函数。

对于单元测试,我建议遵循flavorwocky并使用嵌入式驱动程序。您需要包含appropriate ogm.properties file.