Skip to content

Commit

Permalink
assertions polish (#1586)
Browse files Browse the repository at this point in the history
* assertions polish

* adds more assertions
  • Loading branch information
rajadilipkolli authored Dec 19, 2024
1 parent 4e35643 commit 8d6ef23
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 56 deletions.
2 changes: 1 addition & 1 deletion boot-mongodb-elasticsearch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
<configuration>
<java>
<googleJavaFormat>
<version>1.25.0</version>
<version>1.25.2</version>
<style>AOSP</style>
</googleJavaFormat>
</java>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static com.example.mongoes.utils.AppConstants.PROFILE_TEST;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -16,5 +15,4 @@
public abstract class AbstractIntegrationTest {

@Autowired protected WebTestClient webTestClient;
@Autowired protected ObjectMapper objectMapper;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public class ContainersConfig {
@Bean
@RestartScope
ElasticsearchContainer elasticsearchContainer() {
return new ElasticsearchContainer("docker.elastic.co/elasticsearch/elasticsearch:8.16.1")
return new ElasticsearchContainer("docker.elastic.co/elasticsearch/elasticsearch:8.17.0")
.withEnv(Map.of("xpack.security.enabled", "false"));
}

@ServiceConnection
@Bean
@RestartScope
MongoDBContainer mongoDBContainer() {
return new MongoDBContainer(DockerImageName.parse("mongo").withTag("8.0.3")).withSharding();
return new MongoDBContainer(DockerImageName.parse("mongo").withTag("8.0.4")).withSharding();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,14 @@ class RestaurantESRepositoryIntegrationTest extends AbstractIntegrationTest {
public static final String RESTAURANT_NAME = "Lb Spumoni Gardens";
private static final String BOROUGH_NAME = "Brooklyn";
private static final String CUISINE_NAME = "Pizza/Italian";

@Autowired private RestaurantESRepository restaurantESRepository;

@BeforeAll
void setUpData() {
Restaurant restaurant = new Restaurant();
restaurant.setRestaurantId(2L);
restaurant.setName(RESTAURANT_NAME);
restaurant.setBorough(BOROUGH_NAME);
restaurant.setCuisine(CUISINE_NAME);
Address address = new Address();
address.setLocation(new Point(-73.9, 40.8));
restaurant.setAddress(address);
Grades grade = new Grades("A", LocalDateTime.of(2022, 1, 1, 1, 1, 1), 15);
Grades grade1 = new Grades("B", LocalDateTime.of(2022, 3, 31, 23, 59, 59), 15);
restaurant.setGrades(List.of(grade, grade1));
Restaurant restaurant1 = new Restaurant();
restaurant1.setRestaurantId(40363920L);
restaurant1.setBorough("Brooklyn");
restaurant1.setCuisine("Chinese");
restaurant1.setName("Yono gardens");
restaurant1.setGrades(List.of(grade, grade1));
Restaurant restaurant = createRestaurant(2L, RESTAURANT_NAME, BOROUGH_NAME, CUISINE_NAME);
Restaurant restaurant1 = createRestaurant(40363920L, "Yono gardens", "Brooklyn", "Chinese");

this.restaurantESRepository
.deleteAll()
.log()
Expand All @@ -68,6 +55,21 @@ void setUpData() {
() -> assertThat(this.restaurantESRepository.count().block()).isEqualTo(2));
}

private Restaurant createRestaurant(long id, String name, String borough, String cuisine) {
Restaurant restaurant = new Restaurant();
restaurant.setRestaurantId(id);
restaurant.setName(name);
restaurant.setBorough(borough);
restaurant.setCuisine(cuisine);
Address address = new Address();
address.setLocation(new Point(-73.9, 40.8));
restaurant.setAddress(address);
Grades grade = new Grades("A", LocalDateTime.of(2022, 1, 1, 1, 1, 1), 15);
Grades grade1 = new Grades("B", LocalDateTime.of(2022, 3, 31, 23, 59, 59), 15);
restaurant.setGrades(List.of(grade, grade1));
return restaurant;
}

@Test
void findByRestaurantId() {
var findByRestaurantId = this.restaurantESRepository.findByRestaurantId(1L);
Expand All @@ -77,31 +79,15 @@ void findByRestaurantId() {
var findByRestaurantIdMono = this.restaurantESRepository.findByRestaurantId(2L);

StepVerifier.create(findByRestaurantIdMono)
.consumeNextWith(
restaurant1 -> {
assertThat(restaurant1.getRestaurantId()).isEqualTo(2L);
assertThat(restaurant1.getName()).isEqualTo(RESTAURANT_NAME);
assertThat(restaurant1.getBorough()).isEqualTo(BOROUGH_NAME);
assertThat(restaurant1.getCuisine()).isEqualTo(CUISINE_NAME);
assertThat(restaurant1.getGrades()).isNotEmpty().hasSize(2);
})
.consumeNextWith(this::assertRestaurant)
.verifyComplete();
}

@Test
void findByName() {
var findNameMono = this.restaurantESRepository.findByName(RESTAURANT_NAME);

StepVerifier.create(findNameMono)
.consumeNextWith(
restaurant1 -> {
assertThat(restaurant1.getRestaurantId()).isEqualTo(2L);
assertThat(restaurant1.getName()).isEqualTo(RESTAURANT_NAME);
assertThat(restaurant1.getBorough()).isEqualTo(BOROUGH_NAME);
assertThat(restaurant1.getCuisine()).isEqualTo(CUISINE_NAME);
assertThat(restaurant1.getGrades()).isNotEmpty().hasSize(2);
})
.verifyComplete();
StepVerifier.create(findNameMono).consumeNextWith(this::assertRestaurant).verifyComplete();
}

@Test
Expand All @@ -112,14 +98,7 @@ void findByBorough() {
PageRequest.of(0, 10, Sort.by(Sort.Direction.ASC, "restaurant_id")));

StepVerifier.create(findByBoroughMono)
.consumeNextWith(
restaurant1 -> {
assertThat(restaurant1.getRestaurantId()).isEqualTo(2L);
assertThat(restaurant1.getName()).isEqualTo(RESTAURANT_NAME);
assertThat(restaurant1.getBorough()).isEqualTo(BOROUGH_NAME);
assertThat(restaurant1.getCuisine()).isEqualTo(CUISINE_NAME);
assertThat(restaurant1.getGrades()).isNotEmpty().hasSize(2);
})
.consumeNextWith(this::assertRestaurant)
.expectNextCount(1)
.verifyComplete();
}
Expand All @@ -131,14 +110,7 @@ void findByBoroughAndCuisineAndName() {
BOROUGH_NAME, CUISINE_NAME, RESTAURANT_NAME, PageRequest.of(0, 10));

StepVerifier.create(findByBoroughAndCuisineAndNameMono)
.consumeNextWith(
restaurant1 -> {
assertThat(restaurant1.getRestaurantId()).isEqualTo(2L);
assertThat(restaurant1.getName()).isEqualTo(RESTAURANT_NAME);
assertThat(restaurant1.getBorough()).isEqualTo(BOROUGH_NAME);
assertThat(restaurant1.getCuisine()).isEqualTo(CUISINE_NAME);
assertThat(restaurant1.getGrades()).isNotEmpty().hasSize(2);
})
.consumeNextWith(this::assertRestaurant)
.verifyComplete();
}

Expand Down Expand Up @@ -500,4 +472,17 @@ void aggregation() {
})
.verifyComplete();
}

private void assertRestaurant(Restaurant restaurant) {
assertThat(restaurant.getRestaurantId()).isEqualTo(2);
assertThat(restaurant.getName()).isEqualTo(RESTAURANT_NAME);
assertThat(restaurant.getBorough()).isEqualTo(BOROUGH_NAME);
assertThat(restaurant.getCuisine()).isEqualTo(CUISINE_NAME);
assertThat(restaurant.getGrades()).isNotEmpty().hasSize(2);
assertThat(restaurant.getAddress()).isNotNull();
assertThat(restaurant.getAddress().getLocation())
.isNotNull()
.extracting(Point::getX, Point::getY)
.containsExactly(-73.9, 40.8);
}
}

0 comments on commit 8d6ef23

Please sign in to comment.