Skip to content

Commit

Permalink
added search 1 tests #1069
Browse files Browse the repository at this point in the history
  • Loading branch information
MartxelAran committed Oct 19, 2024
1 parent 95a67a9 commit f12a6e2
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,21 @@ public void seedDatabase() {
BasketBallEntity[] basketballs = {
new BasketBallEntity(1, "Nike", new BigDecimal("50.0"), matches[0]),
new BasketBallEntity(2, "Adidas", new BigDecimal("60.0"), matches[1]),
new BasketBallEntity(3, "Spalding", new BigDecimal("70.0"), matches[2])
new BasketBallEntity(3, "Spalding", new BigDecimal("70.0"), matches[2]),
new BasketBallEntity(4, "Puma", new BigDecimal("22.75"), matches[3]),
new BasketBallEntity(5, "Wilson", new BigDecimal("27.30"), matches[0]),
new BasketBallEntity(6, "Molten", new BigDecimal("31.90"), matches[1]),
new BasketBallEntity(7, "Under Armour", new BigDecimal("34.25"), matches[3]),
new BasketBallEntity(8, "Li-Ning", new BigDecimal("28.45"), matches[1]),
new BasketBallEntity(9, "Peak", new BigDecimal("24.99"), matches[5]),
new BasketBallEntity(10, "New Balance", new BigDecimal("30.50"), matches[2])
};
this.basketBallRepository.saveAll(Arrays.asList(basketballs));

BasketSeasonEntity[] seasons = {
new BasketSeasonEntity(1, 2022, 2023, "NBA", List.of(matches[0], matches[1])),
new BasketSeasonEntity(2, 2023, 2024, "Euroleague", List.of(matches[2])),
new BasketSeasonEntity(3, 2021, 2022, "ACB", List.of(matches[0], matches[1], matches[2]))
new BasketSeasonEntity(3, 2021, 2022, "ACB", List.of(matches[0], matches[1], matches[2], matches[5])),
};
this.basketSeasonRepository.saveAll(Arrays.asList(seasons));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package es.upm.miw.apaw_practice.adapters.mongodb.basketball.daos;

import es.upm.miw.apaw_practice.TestConfig;
import es.upm.miw.apaw_practice.adapters.mongodb.basketball.entities.BasketSeasonEntity;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import static org.junit.jupiter.api.Assertions.*;

@TestConfig
public class BasketSeasonRepositoryIT {

@Autowired
private BasketSeasonRepository basketSeasonRepository;

@Test
void testFindByLeague(){
assertTrue(this.basketSeasonRepository.findByLeague("NBA").isPresent());
BasketSeasonEntity basketSeasonEntity = this.basketSeasonRepository.findByLeague("NBA").get();
assertEquals("NBA", basketSeasonEntity.getLeague());
assertEquals(2022, basketSeasonEntity.getStartYear());
assertEquals(2023, basketSeasonEntity.getEndYear());
assertNotNull(basketSeasonEntity.getBasketMatchEntities());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,14 @@ void testUpdate() {
assertEquals(1,updatedBasketBall.getId());
assertEquals(new BigDecimal("50.0"), updatedBasketBall.getPrice());
}

@Test
void testGetDistinctBrands(){
List<String> brands = this.basketBallPersistenceMongodb.getDistinctBrands("ACB", "Lebron");
assertTrue(brands.contains("Nike"));
assertTrue(brands.contains("Spalding"));
assertTrue(brands.contains("Wilson"));
assertTrue(brands.contains("Peak"));
assertTrue(brands.contains("New Balance"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import java.time.LocalDateTime;
import java.util.List;

import static es.upm.miw.apaw_practice.adapters.rest.basketball.BasketBallResource.BALLS;
import static es.upm.miw.apaw_practice.adapters.rest.basketball.BasketBallResource.ID_ID;
import static es.upm.miw.apaw_practice.adapters.rest.basketball.BasketBallResource.*;
import static org.junit.jupiter.api.Assertions.assertTrue;

@RestTestConfig
public class BasketBallResourceIT {
Expand Down Expand Up @@ -52,4 +52,18 @@ void testUpdate() {
.expectBody(BasketBall.class)
.value(Assertions::assertNotNull);
}

@Test
void testGetDistinctBrands(){
this.webTestClient
.get()
.uri(uriBuilder ->
uriBuilder.path(BALLS + SEARCH + DISTINCT_BRANDS)
.queryParam("q", "league:NBA;playerName:Lebron")
.build())
.exchange()
.expectStatus().isOk()
.expectBody(List.class)
.value(value -> assertTrue(value.contains("Nike")));
}
}

0 comments on commit f12a6e2

Please sign in to comment.