Results 1 to 7 of 7

Thread: [neo4j] Validation

  1. #1
    Join Date
    Aug 2011
    Posts
    22

    Default [neo4j] Validation

    Need some help making bean validation work with SDN:

    Code:
    @NodeEntity 
    public class Dummy {
    	@GraphId 
    	Long id;
    	
    	@Indexed 
    	@NotNull 
    	String x; // want this to never be null
    	
    	public Dummy() {}
    	public Dummy(String x) {
    		this.x = x;
    	}
    }
    Code:
    public interface DummyRepository extends GraphRepository<Dummy> {}
    Code:
    @ContextConfiguration(locations = "classpath:/context.xml")
    @RunWith(SpringJUnit4ClassRunner.class)
    public class DummyTest {	
    	@Autowired private DummyRepository dummyRepository;
    	@Autowired private Neo4jTemplate neo4jTemplate; 
    	
    	@Before public void dropDb() {
    		Neo4jHelper.cleanDb(neo4jTemplate);
    	}
    	
    	@Test(expected = ValidationException.class) 
    	public void testNullX() {
    		Dummy dummy = new Dummy(null);
    		dummyRepository.save(dummy);
    	}
    }
    context.xml is:
    Code:
        <context:spring-configured/>
        <context:annotation-config/>
        
        <bean id="validator" class="org.hibernate.validator.HibernateValidator"/>	
        <neo4j:config storeDirectory="target/neo4j-db"/>
        <neo4j:repositories base-package="com.XXXXXXXXXX.repositories" />
            
        <tx:annotation-driven mode="proxy" />
    I have hibernate-validator 4.2.0 dependency in my pom.xml. The test fails since there's no ValidationException. Anything I'm missing?

  2. #2
    Join Date
    Jan 2011
    Location
    Dresden, Germany
    Posts
    525

    Default

    I just tried it and it works, are you sure you use the correct @javax.validation.constraints.NotNull annotation? There are soo many around?

  3. #3
    Join Date
    Aug 2011
    Posts
    22

    Default

    Quote Originally Posted by MichaelHunger View Post
    are you sure
    Well, now that you ask, I'm not :-)

    I have this dependency:
    Code:
    		<dependency>
    			<groupId>javax.validation</groupId>
    			<artifactId>validation-api</artifactId>
    			<version>1.0.0.GA</version>
    		</dependency>
    I've also tried using @NotEmpty and @NotBlank annotations from hibernate-validator package - still no success, it just doesn't throw. Anything else you think I should check?

  4. #4
    Join Date
    Jan 2011
    Location
    Dresden, Germany
    Posts
    525

    Default

    Could you try to reproduce the test that is contained in SDN ?

    Thanks

    Michael

  5. #5
    Join Date
    Aug 2011
    Posts
    22

    Default

    Downloaded recent commit from github:
    Code:
    Results :
    
    Failed tests:
      injectionForCodeConfiguredExistingGraphDatabaseService(org.springframework.data.neo4j.config.DataGraphNamespaceHandlerTest)
      injectionForExistingGraphDatabaseService(org.springframework.data.neo4j.config.DataGraphNamespaceHandlerTest)
      injectionForConversionService(org.springframework.data.neo4j.config.DataGraphNamespaceHandlerTest)
      injectionForJustStoreDir(org.springframework.data.neo4j.config.DataGraphNamespaceHandlerTest)
    
    Tests run: 256, Failures: 4, Errors: 0, Skipped: 4
    
    [INFO] ------------------------------------------------------------------------
    [INFO] Reactor Summary:
    [INFO]
    [INFO] Spring Data Neo4j Parent .......................... SUCCESS [0.461s]
    [INFO] Spring Data Neo4j ................................. FAILURE [1:09.906s]
    [INFO] Spring Data Neo4J Aspects ......................... SKIPPED
    [INFO] Spring Data Neo4j REST Wrapper .................... SKIPPED
    [INFO] Spring Data Neo4J Cross-Store Handling ............ SKIPPED
    [INFO] Spring Data Neo4j Distribution .................... SKIPPED
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 1:10.892s
    [INFO] Finished at: Tue Apr 24 13:39:09 MSD 2012
    [INFO] Final Memory: 33M/327M
    [INFO] ------------------------------------------------------------------------
    Last edited by loki2302; Apr 24th, 2012 at 04:45 AM.

  6. #6
    Join Date
    Aug 2011
    Posts
    22

    Default

    Fixed my code by replacing:
    Code:
    <bean id="validator" class="org.hibernate.validator.HibernateValidator"/>
    with:
    Code:
    <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>

  7. #7
    Join Date
    Jan 2011
    Location
    Dresden, Germany
    Posts
    525

    Default

    Thanks for pointing it out, that's the way the SDN tests are set up too, I added it to the docs.

    Cheers

    Michael

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •