lundi 30 novembre 2015

sdn 4.0 wired behaviour in unit test

This is bit strange for me. I have a company repository

@Repository
public interface CompanyRepository extends GraphRepository<Company> {

    Company findByName(String name);

    @Query("MATCH (n:Company) WHERE lower(n.name) CONTAINS lower({0}) RETURN n")
    List<Company> findByPartialName(String name);

then I have a unit test class to test those two methods

public class CompanyRepositoryTest extends Neo4JTestConfig {

@Autowired
private CompanyRepository companyRepository;

@Before
public void setUp() throws Exception {

    Company company = new Company();
    company.setName("Westpac");
    company.setUrl("www.westpac.com.au");

    companyRepository.save(company);

    Company company2 = new Company();
    company2.setName("test Hl");
    company2.setUrl("www.test.com.au");

    companyRepository.save(company2);
}

@After
public void tearDown() throws Exception {
    companyRepository.deleteAll();
}

@Test
public void testFindByName() throws Exception {

    Company company = companyRepository.findByName("Westpac");
    assertEquals(company.getUrl(), "www.westpac.com.au");
}

@Test
public void testFindByPartialName() throws Exception {

    List<Company> companies = companyRepository.findByPartialName("St");
    assertEquals(2, companies.size());

    List<Company> companies2 = companyRepository.findByPartialName("west");
    assertEquals(1, companies2.size());
}
}

those are looks all good? yep, I think so. I can run each @Test method with out any problems.

However, when I run the on the class level, whatever the 2nd test method always failed.

I looked into the database, the 1st time run @Before, it is all good, two Company are saved into neo4j with the name and url properties. But for the 2nd time run of @Before, all the Company node in neo4j does not have any properties. This is causing the 2nd @Test failed.

I am using

<spring.data.neo4j.version>4.0.0.RELEASE</spring.data.neo4j.version>

and

<neo4j.ogm.version>1.1.2</neo4j.ogm.version>

any idea why?

Aucun commentaire:

Enregistrer un commentaire