Skip to content

Commit

Permalink
added controller test
Browse files Browse the repository at this point in the history
  • Loading branch information
ikwattro committed Aug 28, 2024
1 parent 157be5c commit 7fe4fb4
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/test/java/com/graphaware/cypher/CypherControllerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.graphaware.cypher;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.graphaware.cypher.web.CypherRequest;
import com.graphaware.cypher.web.CypherResponse;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest
@AutoConfigureMockMvc
public class CypherControllerTest {

@Autowired
private MockMvc mockMvc;

@Autowired
private ObjectMapper objectMapper;


@Test
void testPostCypher() throws Exception {
var rels = List.of(
"(Person, LIVES_IN, City)",
"(Person, HAS_ACCOUNT, UserAccount)",
"(Vehicle, LICENCED_TO, LicensePlate)",
"(Vehicle, OWNED_BY, Person)",
"(AlprEvent, CAPTURED, LicensePlate)"
);

var cypher = """
MATCH path=(p:Person)-[:OWNED_BY]->(v:Vehicle)-[:LICENCED_TO]-(l:LicensePlate)
WHERE p.gender = 'M'
AND l.registrationNumber CONTAINS '88'
RETURN path
""";
var request = new CypherRequest(cypher, rels);
String jsonRequest = objectMapper.writeValueAsString(request);
var result = mockMvc.perform(MockMvcRequestBuilders.post("/enforceSchema")
.contentType("application/json")
.content(jsonRequest))
.andExpect(MockMvcResultMatchers.status().isOk()).andReturn();
CypherResponse cypherResponse = objectMapper.readValue(result.getResponse().getContentAsString(), CypherResponse.class);

assertThat(cypherResponse.cypher()).contains("(p:`Person`)<-[:`OWNED_BY`]-(v:`Vehicle`)");
}
}

0 comments on commit 7fe4fb4

Please sign in to comment.