@Test public void shouldCountCarsWithFindCommand() throws Exception { String uniqueColorForTest = "color-shouldCountCarsWithFindCommand"; Car exampleCar = CarBuilder.aCar() .withManufacturer(UUID.randomUUID().toString()) .withColor(uniqueColorForTest) .build(); saveNewCopiesOfCarToRepository(exampleCar, 10); Car secondExampleCar = CarBuilder.aCar() .withManufacturer(UUID.randomUUID().toString()) .withColor(uniqueColorForTest) .build(); saveNewCopiesOfCarToRepository(secondExampleCar, 5); // Car searchByManufacturerExampleCar = new Car(null, 0, exampleCar.getManufacturer(), null); FindCommand<Car> findCommand = FindCommand.create(Car.class); findCommand.withSearchFilter("manufacturer", exampleCar.getManufacturer()); long foundCars = carRepository.findTotalItemCount(findCommand); assertThat(foundCars).isEqualTo(10); FindCommand<Car> findCommand2 = FindCommand.create(Car.class); findCommand2.withSearchFilter("color", uniqueColorForTest); long foundCarsByColor = carRepository.findTotalItemCount(findCommand2); assertThat(foundCarsByColor).isEqualTo(15); FindCommand<Car> findCommand3 = FindCommand.create(Car.class); findCommand3.withSearchFilter("manufacturer", exampleCar.getManufacturer()); findCommand3.withSearchFilter("color", uniqueColorForTest); long foundCarsByManufacturerAndColor = carRepository.findTotalItemCount(findCommand3); assertThat(foundCarsByManufacturerAndColor).isEqualTo(10); }
@Test public void shouldFindCarsAndRelatedTyresWithFindCommand() throws Exception { String uniqueColorForTest = "black-and-pink-with-ruby-and-related-tyres"; String tyreManufacturer = "tyre-manufacturer-1"; Car exampleCar = CarBuilder.aCar() .withManufacturer(UUID.randomUUID().toString()) .withColor(uniqueColorForTest) .withTyre(tyreManufacturer, 5) .withTyre(tyreManufacturer, 5) .withTyre(tyreManufacturer, 5) // .withTyre(tyreManufacturer, 5) // .withTyre(tyreManufacturer, 5) // .withTyre("tyre-manufacturer-2", 5) .build(); saveNewCopiesOfCarToRepository(exampleCar, 1); /*Car secondExampleCar = CarBuilder.aCar().withManufacturer(UUID.randomUUID().toString()) .withColor(uniqueColorForTest).build(); saveNewCopiesOfCarToRepository(secondExampleCar, 5);*/ // Car searchByManufacturerExampleCar = new Car(null, 0, exampleCar.getManufacturer(), null); FindCommand<Car> findCommand = FindCommand.create(Car.class); findCommand.withSearchFilter("manufacturer", exampleCar.getManufacturer()); findCommand.withSearchFilter("tyreList.manufacturer", tyreManufacturer); // List<Car> foundCars = carRepository.findItemsWith(findCommand); // int numberOfTries = 1; // for (int i = 0; i < numberOfTries; i++) { // log.info("testNumber=[{}]", i); // List<Car> foundCars = carRepository.tempfindItemsWithOneToMany(findCommand); int expectedSize = 1; List<Car> foundCars = carRepository.findItemsWith(findCommand); log.info("foundCars={}", foundCars); assertThat(foundCars).isNotNull().hasSize(expectedSize); long count = carRepository.findTotalItemCount(findCommand); assertThat(count).isNotNull().isEqualTo(expectedSize); } /*FindCommand<Car> findCommand2 = FindCommand.create(Car.class); findCommand2.withSearchFilter("color", uniqueColorForTest); List<Car> foundCarsByColor = carRepository.findItemsWith(findCommand2); assertThat(foundCarsByColor).isNotNull().hasSize(15); FindCommand<Car> findCommand3 = FindCommand.create(Car.class); findCommand3.withSearchFilter("manufacturer", exampleCar.getManufacturer()); findCommand3.withSearchFilter("color", uniqueColorForTest); List<Car> foundCarsByManufacturerAndColor = carRepository.findItemsWith(findCommand3); assertThat(foundCarsByManufacturerAndColor).isNotNull().hasSize(10);*/ }