samedi 4 mars 2017

Join table not being populated in @Transactional test

I have following test:

@Test
public void createNewShopAndCheckUserShopsCollection()
{
    //given
    ShopEntity shop = new ShopEntity();
    String shopName = "test shop";

    MallEntity mall = new MallEntity();
    mall.setId(1L);

    UserEntity user = userService.findOne(1L);
    int shopsModeratedBefore = user.getModeratedShops().size();

    shop.setMall(mall);
    shop.setName(shopName);
    shop.setModerators(Collections.singletonList(user));


    ShopEntity savedShop = shopRepository.save(shop);
    user = userService.findOne(1L);

    assertThat(user.getModeratedShops()).hasSize(shopsModeratedBefore + 1);
}

in class annotated with @Transactional. I need to roll back after its execution, so other tests won't fail. However, it seems, that join table is not being populated before end of method (assertion is falling). How can I manually make sure it gets updated?

Aucun commentaire:

Enregistrer un commentaire