@Override public void run(String... args) throws Exception { repository.deleteAll(); // save a couple of customers repository.save(new Customer("Alice", "Smith")); repository.save(new Customer("Bob", "Smith")); // fetch all customers System.out.println("Customers found with findAll():"); System.out.println("-------------------------------"); for (Customer customer : repository.findAll()) { System.out.println(customer); } System.out.println(); // fetch an individual customer System.out.println("Customer found with findByFirstName('Alice'):"); System.out.println("--------------------------------"); System.out.println(repository.findByFirstName("Alice")); System.out.println("Customers found with findByLastName('Smith'):"); System.out.println("--------------------------------"); for (Customer customer : repository.findByLastName("Smith")) { System.out.println(customer); } }
@Before public void setUp() { repository.deleteAll(); dave = repository.save(new Customer("Dave", "Matthews")); oliver = repository.save(new Customer("Oliver August", "Matthews")); carter = repository.save(new Customer("Carter", "Beauford")); }
@Before public void setupMetaData() { apartment = apartmentRepository.save(Apartment.builder().capacity(3).name("name").build()); customer = customerRepository.save( Customer.builder().firstName("firstName").lastName("lastName").build()); }
/** * Test case to show the usage of the geo-spatial APIs to lookup people within a given distance of * a reference point. */ @Test public void exposesGeoSpatialFunctionality() { GeospatialIndex indexDefinition = new GeospatialIndex("address.location"); indexDefinition.getIndexOptions().put("min", -180); indexDefinition.getIndexOptions().put("max", 180); operations.indexOps(Customer.class).ensureIndex(indexDefinition); Customer ollie = new Customer("Oliver", "Gierke"); ollie.setAddress(new Address(new Point(52.52548, 13.41477))); ollie = repository.save(ollie); Point referenceLocation = new Point(52.51790, 13.41239); Distance oneKilometer = new Distance(1, Metrics.KILOMETERS); GeoResults<Customer> result = repository.findByAddressLocationNear(referenceLocation, oneKilometer); assertThat(result.getContent(), hasSize(1)); Distance distanceToFirstStore = result.getContent().get(0).getDistance(); assertThat(distanceToFirstStore.getMetric(), is(Metrics.KILOMETERS)); assertThat(distanceToFirstStore.getValue(), closeTo(0.862, 0.001)); }
/** Test case to show that automatically generated ids are assigned to the domain objects. */ @Test public void setsIdOnSave() { Customer dave = repository.save(new Customer("Dave", "Matthews")); assertThat(dave.getId(), is(notNullValue())); }