0

i'm making a test of a Client, specifically i'm getting all clients, and i have this piece of code:

ClientMockMvc.perform(get("/clients?sort=id,desc"))
        .andExpect(status().isOk())
        .andExpect(jsonPath("$.[*].location").value(DEFAULT_LOCATION))

But i got this error:

Expected: Location{id=974351, street='AAAAA', number='AAAA', province={id= 974251, desc="AAAA"}}

Actual: {id=974351, street='AAAAA', number='AAAA', province={id= 974251, desc="AAAA"}}

I can't find a workaround for this, anyone has an idea? Am i doing something wrong? Thanks in advance!

Rohr Facu
  • 607
  • 1
  • 12
  • 29
  • where is DEFAULT_LOCATION defined? – pvpkiran Feb 15 '18 at 00:23
  • In the test, i gave it default values, asigned it to the client and persisted it in the database. – Rohr Facu Feb 15 '18 at 00:26
  • show how it is declared? As a String? or Object? – pvpkiran Feb 15 '18 at 00:27
  • DEFAULT_LOCATION = new Location() .street(DEFAULT_STREET) .number(DEFAULT_NUMBER) .province(DEFAULT_PROVINCE); DEFAULT_LOCATION = locationRepository.save(DEFAULT_LOCATION); – Rohr Facu Feb 15 '18 at 00:31
  • see DEFAULT_LOCATION you are creating a new object hence the error is it is expecting `Location{id=974351, street='AAAAA', number='AAAA', province={id= 974251, desc="AAAA"}}`. But `jsonPath("$.[*].location"` is a string which is `{id=974351, street='AAAAA', number='AAAA', province={id= 974251, desc="AAAA"}}` without Location prefix – pvpkiran Feb 15 '18 at 00:33
  • How could i fix it? I guess DEFAULT_LOCATION.toString() Wont help right? – Rohr Facu Feb 15 '18 at 00:38
  • what does this endpoint return `/clients?sort=id,desc` – pvpkiran Feb 15 '18 at 00:38
  • It returns the list of all clients – Rohr Facu Feb 15 '18 at 00:41

0 Answers0