Ejemplo n.º 1
0
  @Test
  public void testCreateLocation() throws Exception {
    Time time = Time.of(2015, 12, 24, 9, 1, 0);
    UserLocation mc =
        TestUtility.createUserLocation(
            "+94770780210", "CDC47124648058A", 98.0f, "Home", 79.857488, 6.8781381, time);

    HTTP.Response response =
        HTTP.POST(server.httpURI().resolve("/contra/location/create").toString(), mc);

    // Check the status.
    assertEquals("Error in request.", HttpURLConnection.HTTP_OK, response.status());

    // Do not use the exact location for withinDistance
    Result result =
        server
            .graph()
            .execute(
                "START n = node:location_layer('withinDistance:[6.8781381, 79.857487, 0.1]') RETURN n.name as name");

    Map<String, Object> map = result.next();

    assertEquals("Location is not created.", "Home", map.get("name"));
  }
Ejemplo n.º 2
0
  @Test
  public void testFindWithin() throws Exception {
    Nearby param = new Nearby();
    param.setLongitude(79.8547);
    param.setLatitude(6.8939);
    param.setDistance(1);
    HTTP.Response response =
        HTTP.POST(server.httpURI().resolve("/contra/location/findwithin").toString(), param);

    // Check the status.
    assertEquals("Error in request.", HttpURLConnection.HTTP_OK, response.status());

    Gson gson = new Gson();
    Message<List<Location>> message =
        gson.fromJson(response.rawContent(), new TypeToken<Message<List<Location>>>() {}.getType());
    List<Location> locations = message.getEntity();
    // Check the status.
    assertEquals("Exact locations are not found.", 3, locations.size());

    String[] expected = {"Majestic City", "Unity Plaza"};
    String[] actual = {locations.get(0).getName(), locations.get(1).getName()};
    assertArrayEquals("Expected locations are not found.", expected, actual);
  }
Ejemplo n.º 3
0
 /**
  * Close the Neo4j testing server.
  *
  * @throws Exception
  */
 @AfterClass
 public static void tearDown() throws Exception {
   databaseService.shutdown();
   server.close();
 }
Ejemplo n.º 4
0
 /**
  * Setup the No4j server for testing purposes.
  *
  * @throws Exception
  */
 @BeforeClass
 public static void setUp() throws Exception {
   server = TestUtility.createServer(LocationResource.class);
   databaseService = server.graph();
   TestUtility.createCommonEntities(databaseService);
 }