Add service negative tests

factory-mgt
Rushdi Mohamed 1 year ago
parent a19ea755cc
commit 7b5baccedc

@ -30,6 +30,7 @@ import io.entgra.device.mgt.core.factory.mgt.core.dao.common.FactoryMgtDAOFactor
import io.entgra.device.mgt.core.factory.mgt.common.dto.ProductionPlan;
import io.entgra.device.mgt.core.factory.mgt.common.exception.FactoryMgtDAOException;
import io.entgra.device.mgt.core.factory.mgt.core.exception.TransactionManagementException;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -93,6 +94,22 @@ public class ProductionPlanServiceImpl implements ProductionPlanService {
throw new BadRequestException(errorMsg);
}
try {
if (StringUtils.isBlank(productionPlan.getDate())) {
productionPlan.setDate(productionPlanOld.getDate());
}
if (StringUtils.isBlank(productionPlan.getTime())) {
productionPlan.setTime(productionPlanOld.getTime());
}
if (StringUtils.isBlank(productionPlan.getMachineId())) {
productionPlan.setMachineId(productionPlanOld.getMachineId());
}
if (StringUtils.isBlank(productionPlan.getProductId())) {
productionPlan.setProductId(productionPlanOld.getProductId());
}
if (productionPlan.getTarget() <= 0) {
productionPlan.setTarget(productionPlanOld.getTarget());
}
FactoryMgtDAOFactory.beginTransaction();
boolean result = factoryMgtDAO.updateProductionPlan(productionPlan);
if (result) {

@ -17,25 +17,61 @@
*/
package io.entgra.device.mgt.core.factory.mgt.core;
//
//import io.entgra.device.mgt.core.factory.mgt.common.spi.ProductionPlanService;
//import io.entgra.device.mgt.core.factory.mgt.core.impl.ProductionPlanServiceImpl;
//import io.entgra.device.mgt.core.factory.mgt.core.mock.BaseFactoryMgtPluginTest;
import io.entgra.device.mgt.core.factory.mgt.common.dto.ProductionPlan;
import io.entgra.device.mgt.core.factory.mgt.common.exception.BadRequestException;
import io.entgra.device.mgt.core.factory.mgt.common.exception.FactoryMgtException;
import io.entgra.device.mgt.core.factory.mgt.common.exception.FactoryMgtPluginException;
import io.entgra.device.mgt.core.factory.mgt.common.spi.ProductionPlanService;
import io.entgra.device.mgt.core.factory.mgt.core.service.impl.ProductionPlanServiceImpl;
import io.entgra.device.mgt.core.factory.mgt.core.mock.BaseFactoryMgtPluginTest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import io.entgra.device.mgt.core.factory.mgt.core.mock.BaseFactoryMgtPluginTest;
import org.testng.annotations.Test;
public class ServiceNegativeTest extends BaseFactoryMgtPluginTest {
private static final Log log = LogFactory.getLog(ServiceNegativeTest.class);
// private ProductionPlanService productionPlanService;
private ProductionPlanService productionPlanService;
@BeforeClass
public void init() {
// productionPlanService = new ProductionPlanServiceImpl();
log.info("Service test initialized");
productionPlanService = new ProductionPlanServiceImpl();
log.info("Service Negative test initialized");
}
@Test(description = "This method tests Add Production Plan method under negative circumstances with null data",
expectedExceptions = {FactoryMgtPluginException.class})
public void testAddProductionPlan() throws FactoryMgtPluginException {
ProductionPlan productionPlan = new ProductionPlan();
boolean result = productionPlanService.addProductionPlan(productionPlan);
Assert.assertTrue(result);
}
@Test(description = "This method tests Update Production Plan method under negative circumstances with null data",
expectedExceptions = {FactoryMgtPluginException.class})
public void testUpdateProductionPlanWithEmptyData() throws FactoryMgtPluginException, FactoryMgtException {
ProductionPlan productionPlan = new ProductionPlan();
boolean result = productionPlanService.updateProductionPlan(productionPlan);
Assert.assertTrue(result);
}
@Test(description = "This method tests Update Production Plan method under negative circumstances with null data",
expectedExceptions = {BadRequestException.class})
public void testUpdateProductionPlanWithInvalidId() throws FactoryMgtPluginException, FactoryMgtException {
ProductionPlan productionPlan = new ProductionPlan();
productionPlan.setId(0);
boolean result = productionPlanService.updateProductionPlan(productionPlan);
Assert.assertTrue(result);
}
@Test(description = "This method tests Delete Production Plan method under negative circumstances with null data",
expectedExceptions = {FactoryMgtPluginException.class})
public void testDeleteProductionPlanWithInvalidId() throws FactoryMgtPluginException {
boolean result = productionPlanService.deleteProductionPlan(0);
Assert.assertTrue(result);
}
}

@ -71,8 +71,8 @@ public class ServiceTest extends BaseFactoryMgtPluginTest {
@Test(dependsOnMethods = "testProductionPlans")
public void testAddProductionPlan() throws FactoryMgtPluginException {
ProductionPlan productionPlan = TestUtils.addProductionPlan();
boolean productionPlans = productionPlanService.addProductionPlan(productionPlan);
Assert.assertTrue(productionPlans);
boolean result = productionPlanService.addProductionPlan(productionPlan);
Assert.assertTrue(result);
}
@Test(dependsOnMethods = "testAddProductionPlan")
@ -84,8 +84,8 @@ public class ServiceTest extends BaseFactoryMgtPluginTest {
@Test(dependsOnMethods = "testAddProductionPlan")
public void testUpdateProductionPlanByProductionIdAfter() throws FactoryMgtPluginException, FactoryMgtException {
ProductionPlan productionPlan = TestUtils.updateProductionPlan();
boolean productionPlans = productionPlanService.updateProductionPlan(productionPlan);
Assert.assertTrue(productionPlans);
boolean result = productionPlanService.updateProductionPlan(productionPlan);
Assert.assertTrue(result);
}
@Test(dependsOnMethods = "testUpdateProductionPlanByProductionIdAfter")
@ -104,8 +104,8 @@ public class ServiceTest extends BaseFactoryMgtPluginTest {
@Test(dependsOnMethods = "testGetProductionPlanByProductionIdBeforeDelete")
public void testDeleteProductionPlanByProductionIdAfterUpdate() throws FactoryMgtPluginException {
boolean productionPlans = productionPlanService.deleteProductionPlan(28);
Assert.assertTrue(productionPlans);
boolean result = productionPlanService.deleteProductionPlan(28);
Assert.assertTrue(result);
}
@Test(dependsOnMethods = "testDeleteProductionPlanByProductionIdAfterUpdate")

Loading…
Cancel
Save