Commit a73ca61c authored by Jakub Balga's avatar Jakub Balga
Browse files

test and javadoc

parent 6bba8e9b
Pipeline #132078 passed with stages
in 2 minutes and 11 seconds
......@@ -5,15 +5,19 @@
package cz.muni.fi.pa165.winery.persistence.dao;
import cz.muni.fi.pa165.winery.persistence.PersistenceTestConfig;
import cz.muni.fi.pa165.winery.persistence.dao.review.ProductReviewDao;
import cz.muni.fi.pa165.winery.persistence.entities.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import java.math.BigDecimal;
import static org.assertj.core.api.Assertions.assertThat;
@ExtendWith(SpringExtension.class)
@SpringJUnitConfig(PersistenceTestConfig.class)
public class ProductReviewTests extends DaoTestBase<ProductReview> {
......@@ -79,6 +83,56 @@ public class ProductReviewTests extends DaoTestBase<ProductReview> {
return review;
}
@Test
public void testGetAll() {
var entity1 = getEntity1();
var entity2 = getEntity2();
executeTransaction(() ->
{
entityManager.persist(entity1);
entityManager.persist(entity2);
});
var entities = ((ProductReviewDao)daoBase).getAll((short)5);
Assertions.assertNotNull(entities);
Assertions.assertEquals(entities.size(), 1);
assertThat(entities).containsExactly(entity2);
}
@Test
public void testGetAllByUser() {
var entity1 = getEntity1();
var entity2 = getEntity2();
executeTransaction(() ->
{
entityManager.persist(entity1);
entityManager.persist(entity2);
});
var entities = ((ProductReviewDao)daoBase).getAllByUser(testUser.getId());
Assertions.assertNotNull(entities);
Assertions.assertEquals(entities.size(), 2);
assertThat(entities).containsExactly(entity1, entity2);
}
@Test
public void testGetAllByBottle() {
var entity1 = getEntity1();
var entity2 = getEntity2();
executeTransaction(() ->
{
entityManager.persist(entity1);
entityManager.persist(entity2);
});
var entities = ((ProductReviewDao)daoBase).getAllByBottle(testBottle.getId() + 1);
Assertions.assertNotNull(entities);
Assertions.assertEquals(entities.size(), 0);
}
@Override
protected void modifyEntityForUpdate(ProductReview productReview) {
productReview.setText("Updated text");
......
package cz.muni.fi.pa165.winery.persistence.dao;
import cz.muni.fi.pa165.winery.persistence.PersistenceTestConfig;
import cz.muni.fi.pa165.winery.persistence.dao.wine.WineBottleDao;
import cz.muni.fi.pa165.winery.persistence.entities.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import java.math.BigDecimal;
import static org.assertj.core.api.Assertions.assertThat;
/***
* @author Jakub Balga
*/
......@@ -47,7 +51,7 @@ public class WineBottleDaoTests extends DaoTestBase<WineBottle> {
testWineBottle.setGrape(testGrape);
testWineBottle.setVolume(new BigDecimal("0.70"));
testWineBottle.setPrice(new BigDecimal("800.00"));
testWineBottle.setStock(3);
testWineBottle.setStock(0);
return testWineBottle;
}
......@@ -63,6 +67,40 @@ public class WineBottleDaoTests extends DaoTestBase<WineBottle> {
return testWineBottle;
}
@Test
public void testGetAll() {
var entity1 = getEntity1();
var entity2 = getEntity2();
executeTransaction(() ->
{
entityManager.persist(entity1);
entityManager.persist(entity2);
});
var entities = ((WineBottleDao)daoBase).getAll(800, 899);
Assertions.assertNotNull(entities);
Assertions.assertEquals(entities.size(), 1);
assertThat(entities).containsExactly(entity1);
}
@Test
public void testGetAllOnStock() {
var entity1 = getEntity1();
var entity2 = getEntity2();
executeTransaction(() ->
{
entityManager.persist(entity1);
entityManager.persist(entity2);
});
var entities = ((WineBottleDao)daoBase).getAllOnStock();
Assertions.assertNotNull(entities);
Assertions.assertEquals(entities.size(), 1);
assertThat(entities).containsExactly(entity2);
}
@Override
protected void modifyEntityForUpdate(WineBottle wineBottle) {
wineBottle.setName("New champ");
......
package cz.muni.fi.pa165.winery.persistence.dao;
import cz.muni.fi.pa165.winery.persistence.PersistenceTestConfig;
import cz.muni.fi.pa165.winery.persistence.dao.wine.WineTypeDao;
import cz.muni.fi.pa165.winery.persistence.entities.Grape;
import cz.muni.fi.pa165.winery.persistence.entities.WineType;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Michaela Korenkova
*/
......@@ -49,6 +53,25 @@ public class WineTypeDaoTests extends DaoTestBase<WineType> {
return wineType;
}
@Test
public void testGetAllByGrape() {
var entity1 = getEntity1();
var entity2 = getEntity2();
executeTransaction(() ->
{
entityManager.persist(entity1);
entityManager.persist(entity2);
});
var entities = ((WineTypeDao)daoBase).getAllByGrape(testGrape.getId());
Assertions.assertNotNull(entities);
Assertions.assertEquals(entities.size(), 2);
assertThat(entities).containsExactly(entity1, entity2);
}
@Override
protected void modifyEntityForUpdate(WineType wineType) {
wineType.setName("wineType3");
......
......@@ -7,6 +7,9 @@ import org.modelmapper.ModelMapper;
import org.modelmapper.convention.MatchingStrategies;
import org.springframework.stereotype.Service;
/**
* @author Jakub Balga
*/
@Service
public class WineBottleEntityMapper extends EntityMapperImpl<WineBottleDto, WineBottle> {
public WineBottleEntityMapper() {
......
......@@ -12,6 +12,9 @@ import javax.transaction.Transactional;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author Jakub Balga
*/
@Service
public class ProductReviewServiceImpl extends PersistenceServiceImpl<ProductReviewDto, ProductReview> implements ProductReviewService {
......
package cz.muni.fi.pa165.winery.services.wine;
import cz.muni.fi.pa165.winery.dto.wine.WineBottleDto;
import cz.muni.fi.pa165.winery.persistence.dao.review.ProductReviewDao;
import cz.muni.fi.pa165.winery.persistence.dao.wine.WineBottleDao;
import cz.muni.fi.pa165.winery.persistence.entities.WineBottle;
import cz.muni.fi.pa165.winery.services.PersistenceServiceImpl;
......@@ -12,6 +11,9 @@ import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author Jakub Balga
*/
@Service
public class WineBottleServiceImpl extends PersistenceServiceImpl<WineBottleDto, WineBottle> implements WineBottleService {
......
......@@ -11,6 +11,9 @@ import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author Jakub Balga
*/
@Service
public class WineTypeServiceImpl extends PersistenceServiceImpl<WineTypeDto, WineType> implements WineTypeService {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment