I have created a new Maven Project:
https://github.com/neosamples/neosamples
where I gradually copy content from:
https://github.com/luanne/flavorwocky
to better understand how it works and which dependencies are needed. For now I would like to just make it possible to unit test adding new items to a GraphRepository. Currently my project has this layout:
Where:
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();
}
}
Where neo4j is the user and neopass is the password I am using when accessing: http://localhost:7474/browser/
And:
I am trying to run this unit test in:
@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);
}
}
But when I run the unit test above I get the below error in the console:
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
and this stack trace:
I have been tried to customize my pom dependencies for quite some time, but I get the feeling that I am running in circles, below is my current configuration:
Any suggestions?
Looks like your auth credentials aren't quite right. If you've taken the flavorwocky config, then it's not clear what your GRAPHENEDB_URL represents. Perhaps modify your code to configure the URI directly like this:
Application.java
config.driverConfiguration().setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver").setURI("http://neo4j:password@localhost:7474");
(Replace the neo4j username/password/host/port with whatever you're using)
Edit:
The problem is this dependency which is not compatible with the drivers used by SDN 4.1.2:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-drivers</artifactId>
<version>2.0.0-M02</version>
<scope>test</scope>
</dependency>
You don't need to include the dependency on the HTTP driver. But if you're using Embedded or Bolt, then you need to include these (documented here)
If you remove this dependency, then there is no longer an authentication problem, but your test will still fail because MyNode
cannot be instantiated- it requires a no-args constructor.
For the unit tests, I recommend following flavorwocky and using the embedded driver. You would need to include the appropriate ogm.properties file.