Announcement Announcement Module
Collapse
No announcement yet.
[neo4j] Validation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • [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
    I just tried it and it works, are you sure you use the correct @javax.validation.constraints.NotNull annotation? There are soo many around?

    Comment


    • #3
      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?

      Comment


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

        Thanks

        Michael

        Comment


        • #5
          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, 04:45 AM.

          Comment


          • #6
            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"/>

            Comment


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

              Cheers

              Michael

              Comment

              Working...
              X