Index: src/test/java/com/napa/pulse/dao/impl/SessionDAOImplUnitTest.java =================================================================== diff -u -r7da583b61621043174172bc3e6becd96dc446b3b -refffdd086e6950d3a3c1ba77ec94c87d8bb6a83c --- src/test/java/com/napa/pulse/dao/impl/SessionDAOImplUnitTest.java (.../SessionDAOImplUnitTest.java) (revision 7da583b61621043174172bc3e6becd96dc446b3b) +++ src/test/java/com/napa/pulse/dao/impl/SessionDAOImplUnitTest.java (.../SessionDAOImplUnitTest.java) (revision efffdd086e6950d3a3c1ba77ec94c87d8bb6a83c) @@ -1,39 +1,48 @@ package com.napa.pulse.dao.impl; +import com.napa.pulse.dao.interfaces.AcoDAO; import com.napa.pulse.dao.interfaces.SiteGroupDAO; +import com.napa.pulse.dto.LeadTimeStatusDTO; import com.napa.pulse.dto.ProductLinesData; import com.napa.pulse.entity.pulseui.CustomGroupCodeProductGroup; import com.napa.pulse.entity.pulseui.CustomProductGroup; import com.napa.pulse.entity.pulseui.ProductGroupOrderReturn; import com.napa.pulse.entity.security.User; import com.napa.pulse.enums.AccessItem; -import com.napa.pulse.service.interfaces.SessionService; -import org.junit.Before; +import com.napa.pulse.rowmappers.IntegerRowMapper; +import com.napa.pulse.service.interfaces.AdminService; import org.junit.Test; import org.junit.jupiter.api.BeforeEach; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.*; +import org.mockito.invocation.InvocationOnMock; import org.mockito.runners.MockitoJUnitRunner; -import org.springframework.beans.factory.annotation.Autowired; +import org.mockito.stubbing.Answer; +//import org.powermock.api.mockito.PowerMockito; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.jdbc.InvalidResultSetAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.PreparedStatementCreator; +import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.jdbc.core.simple.SimpleJdbcCall; +import org.springframework.jdbc.support.GeneratedKeyHolder; import org.springframework.jdbc.support.KeyHolder; +import org.springframework.jdbc.support.rowset.SqlRowSet; +import org.springframework.jdbc.support.rowset.SqlRowSetMetaData; import org.springframework.test.util.ReflectionTestUtils; import javax.sql.DataSource; import java.math.BigDecimal; import java.sql.*; import java.util.*; import java.util.Date; +import java.util.concurrent.*; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.*; import static org.mockito.Mockito.*; import static org.mockito.Mockito.when; @@ -47,113 +56,28 @@ @InjectMocks SessionDAOImpl sessionDAOImplMock; - @Mock - User user; @Mock private JdbcTemplate jdbcTemplate; - @Mock - private Connection connection; - @Mock - private NamedParameterJdbcTemplate namedParameterJdbcTemplate; - @Mock - private SiteGroupDAO siteGroupDAO; @Mock - private DataSource dataSource; + private AcoDAO acoDAO; @Mock - private PreparedStatement ps; - + private AdminService adminService; @Mock - private ResultSet rs; + private SiteGroupDAOImpl siteGroupDAO; - private static final int DEFER_SITE_LIMIT = 10; // Example limit - @Before - public void setup() throws Exception{ - assertNotNull(dataSource); + + @BeforeEach + public void setup() throws Exception { + // assertNotNull(dataSource); MockitoAnnotations.initMocks(this); - jdbcTemplate = mock(JdbcTemplate.class); - when(connection.prepareStatement(any(String.class))).thenReturn(ps); - when(dataSource.getConnection()).thenReturn(connection); - User user1 = buildUser(); - Integer num = 1; - Integer[] sitesArray = {1309,1346}; - Boolean perCarOrder = true; - Boolean includeFleets = false; - Boolean includeSystems = true; - Boolean includeSpecials = true; - Boolean includeObsoletes = true; - Boolean includeOverstocks = true; - Boolean includeSupersede = true; - Boolean includeKeylinesOrders = true; - Boolean includeKeylinesReturns= true; - Boolean includeLessThanStdPkg = true; - Double includeWeekSupplyOption = null; - String weekSupplyOptionName = null; - Boolean useInvestmentCollections = true; - Boolean provideStoreDepth = true; Boolean includeSoldNotStocked = false; - Boolean includeNewNumbers= false ; Boolean orderAllSkus= false ; Boolean returnAllSKUs= false ; - Integer dollarLimit = 0; String comment=null; Integer siteGroupId = 0; String siteGroupName = null; - ProductGroupOrderReturn productGroupOrderReturn = new ProductGroupOrderReturn(); - productGroupOrderReturn.setProductGroupId(8839); - productGroupOrderReturn.setOrders(true); - productGroupOrderReturn.setProductGroupName("*Pulse Round 1 2023"); - productGroupOrderReturn.setReturns(true); - ProductGroupOrderReturn[] productGroupsArray = {productGroupOrderReturn}; - // productGroupsArray.set - ProductGroupOrderReturn[] groupCodeArray = null; - Integer[] fleetGroupsIds = null; - CustomProductGroup customProductGroup = null; - CustomGroupCodeProductGroup customGroupCodeProductGroupObj = null; - Boolean isGroupCode = false; - String savedGroup = null; - String userAccessSites = null; - Integer[] skuArray = null; - ProductLinesData[] productLineIdArray = null; - ProductLinesData[] allProductLines = null; - ProductLinesData[] siteProductLines = null; - Integer includeOrders = 0; - Integer includeReturns = 0; - Date expirationDate = null; - String includeDaysCount = "365"; - Integer perCarMinMaxValue = 1; - String salesHistoryValue = null; - BigDecimal ans = new BigDecimal("589734"); - int row = 1; - String displayQty= null; String sessionType = "MM"; String includeHubSpokeOrderOption = "B"; - String includeHubSpokeReturnOption = "B"; Long createdFromSessionId = null; Boolean applicationPartsOnly = true; - sessionDAOImplMock.createNewSession(user1 , perCarOrder , includeFleets , includeSystems , includeSpecials , includeObsoletes , - includeOverstocks , includeSupersede , includeKeylinesOrders , includeKeylinesReturns , includeLessThanStdPkg ,includeWeekSupplyOption,weekSupplyOptionName, - useInvestmentCollections , provideStoreDepth , includeSoldNotStocked , includeNewNumbers , orderAllSkus , returnAllSKUs , - dollarLimit , comment , siteGroupId , "Custom Group" , sitesArray , - productGroupsArray , groupCodeArray , fleetGroupsIds , customProductGroup , customGroupCodeProductGroupObj , isGroupCode , savedGroup , userAccessSites , skuArray , productLineIdArray , allProductLines , siteProductLines, - includeOrders , includeReturns , expirationDate , includeDaysCount , perCarMinMaxValue , salesHistoryValue , displayQty , sessionType , - includeHubSpokeOrderOption , includeHubSpokeReturnOption , null , applicationPartsOnly ); - when(rs.getBoolean(10)).thenReturn(includeLessThanStdPkg); - when(rs.getString(11)).thenReturn(sessionType); - when(rs.getInt(12)).thenReturn(user1.getRoleId()); - when(rs.getString(24)).thenReturn(includeDaysCount); - when(rs.getString(26)).thenReturn(includeHubSpokeOrderOption); - when(rs.getBoolean(16)).thenReturn(useInvestmentCollections); - when(rs.getBoolean(18)).thenReturn(provideStoreDepth); - when(rs.getInt(1)).thenReturn(2); - - - when(ps.executeQuery()).thenReturn(rs); - - - } - /* @Before - public void setUpp(){ - MockitoAnnotations.initMocks(this); - namedParameterJdbcTemplate = mock(namedParameterJdbcTemplate.class); - }*/ @Test @@ -186,177 +110,1144 @@ @Test public void getMinMaxSessionProductsTest() { //sessionDAOImplMock = mock(SessionDAOImpl.class); - Integer[] sites = {1309,1346}; + Integer[] sites = {1309, 1346}; //String sql = "" List> obj = new ArrayList<>(); Map map = new HashMap<>(); - map.put("ac",1309); + map.put("ac", 1309); obj.add(map); - Map>> ans = new HashMap<>(); - ans.put("ad",obj); + Map>> ans = new HashMap<>(); + ans.put("ad", obj); ReflectionTestUtils.setField(sessionDAOImplMock, "jdbcTemplate", jdbcTemplate); when(jdbcTemplate.queryForList(anyString())).thenReturn(obj); sessionDAOImplMock.getMinMaxSessionProducts(sites); assertThat(ans).isNotNull(); } + + @Test + public void testGetMinMaxSessionUnselectedProducts() { + int sessionId = 1; + int siteId = 1; + List> expectedResult = new ArrayList<>(); + Map row = new HashMap<>(); + + row.put("id", 1); + row.put("code", "CODE1"); + row.put("line", "false"); + row.put("orderCycle", 14); + row.put("leadTime", 7); + row.put("perCar", "false"); + row.put("isStockEditOff", "true"); + expectedResult.add(row); + when(jdbcTemplate.queryForList(anyString())).thenReturn(expectedResult); + List> result = sessionDAOImplMock.getMinMaxSessionUnselectedProducts(sessionId, siteId); + assertNotNull(result); + assertEquals(expectedResult, result); + verify(jdbcTemplate, times(1)).queryForList(anyString()); + + } + + + + @Test public void testCreateNewSession() throws Exception { - // Set up your test data and mock responses - /*User user1 = buildUser(); - Integer num = 1; - Integer[] sitesArray = {1309,1346}; + // Arrange - Boolean perCarOrder = true; - Boolean includeFleets = false; + User user = new User(); + + user.setUserId(1); + + user.setRoleId(1); + + Boolean perCarOrder = true; + + Boolean includeFleets = true; + Boolean includeSystems = true; + Boolean includeSpecials = true; + Boolean includeObsoletes = true; + Boolean includeOverstocks = true; + Boolean includeSupersede = true; + Boolean includeKeylinesOrders = true; - Boolean includeKeylinesReturns= true; - Boolean includeLessThanStdPkg = true; - Double includeWeekSupplyOption = null; - String weekSupplyOptionName = null; + + Boolean includeKeylinesReturns = true; + + Boolean includeLessThanStdPkg = true; + + Double includeWeekSupplyOption = 2.0; + + String weekSupplyOptionName = "weekSupplyOption"; + Boolean useInvestmentCollections = true; - Boolean provideStoreDepth = true; Boolean includeSoldNotStocked = false; - Boolean includeNewNumbers= false ; Boolean orderAllSkus= false ; Boolean returnAllSKUs= false ; - Integer dollarLimit = 0; String comment=null; Integer siteGroupId = 0; String siteGroupName = null; - ProductGroupOrderReturn productGroupOrderReturn = new ProductGroupOrderReturn(); - productGroupOrderReturn.setProductGroupId(8839); - productGroupOrderReturn.setOrders(true); - productGroupOrderReturn.setProductGroupName("*Pulse Round 1 2023"); - productGroupOrderReturn.setReturns(true); - ProductGroupOrderReturn[] productGroupsArray = {productGroupOrderReturn}; - // productGroupsArray.set - ProductGroupOrderReturn[] groupCodeArray = null; - Integer[] fleetGroupsIds = null; - CustomProductGroup customProductGroup = null; - CustomGroupCodeProductGroup customGroupCodeProductGroupObj = null; + + Boolean provideStoreDepth = true; + + Boolean includeSoldNotStocked = true; + + Boolean includeNewNumbers = true; + + Boolean orderAllSkus = true; + + Boolean returnAllSKUs = true; + + Integer dollarLimit = 1000; + + String comment = "Test comment"; + + Integer siteGroupId = 1; + + Integer[] sitesArray = {1, 2, 3}; + + ProductGroupOrderReturn[] productGroupsArray = {}; + + ProductGroupOrderReturn[] groupCodeArray = {}; + + Integer[] fleetGroupsIds = {1, 2, 3}; + + CustomProductGroup customProductGroup = new CustomProductGroup(); + + customProductGroup.setOrders(true); + customProductGroup.setReturns(true); + String[] newHierarchyIds = {"1", "2"}; + customProductGroup.setHierarchyIds(newHierarchyIds); + + + CustomGroupCodeProductGroup customGroupCodeProductGroupObj = new CustomGroupCodeProductGroup(); + Boolean isGroupCode = false; - String savedGroup = null; - String userAccessSites = null; - Integer[] skuArray = null; - ProductLinesData[] productLineIdArray = null; - ProductLinesData[] allProductLines = null; - ProductLinesData[] siteProductLines = null; - Integer includeOrders = 0; - Integer includeReturns = 0; - Date expirationDate = null; - String includeDaysCount = "365"; + + String savedGroup = "savedGroup"; + + String userAccessSites = "1,2,3"; + + Integer[] skuArray = {1, 2, 3}; + + ProductLinesData[] productLineIdArray = {}; + + ProductLinesData[] allProductLines = {}; + ProductLinesData p = new ProductLinesData(); + p.setSiteId(1); + p.setSiteId(2); + + ProductLinesData[] siteProductLines = {p}; + + Integer includeOrders = 1; + + Integer includeReturns = 1; + + Date expirationDate = new Date(System.currentTimeMillis()); + + String includeDaysCount = "30"; + Integer perCarMinMaxValue = 1; - String salesHistoryValue = null; - BigDecimal ans = new BigDecimal("589734"); - int row = 1; - String displayQty= null; String sessionType = "MM"; String includeHubSpokeOrderOption = "B"; - String includeHubSpokeReturnOption = "B"; Long createdFromSessionId = null; Boolean applicationPartsOnly = true;*/ - when(user.getAccessItemIds()).thenReturn(Arrays.asList(AccessItem.DELAY_SESSION_CREATION.getNumVal())); + + String salesHistoryValue = "salesHistoryValue"; + + String displayQty = "displayQty"; + + String sessionType = "MM"; + + String includeHubSpokeOrderOption = "includeHubSpokeOrderOption"; + + String includeHubSpokeReturnOption = "includeHubSpokeReturnOption"; + + Boolean applicationPartsOnly = true; + + LeadTimeStatusDTO[] leadTime = {}; +int DEFER_SITE_LIMIT = 1; + + KeyHolder keyHolder = new GeneratedKeyHolder(); + + // when(user.getAccessItemIds()).thenReturn(Arrays.asList(AccessItem.DELAY_SESSION_CREATION.getNumVal())); + when(siteGroupDAO.getSiteCount(anyInt(), any(User.class), anyString(), anyString())).thenReturn(DEFER_SITE_LIMIT + 1); + when(jdbcTemplate.update(any(PreparedStatementCreator.class), any(KeyHolder.class))).thenReturn(1); + + when(jdbcTemplate.queryForObject(anyString(), eq(Integer.class))).thenReturn(1); + Map keyMap = new HashMap<>(); + keyMap.put("SESSION_ID", BigDecimal.valueOf(1234)); + + // Act + doAnswer(invocation -> { + + KeyHolder keyHolderArg = invocation.getArgument(1); + + // You can set a dummy key here to simulate a successful insertion + keyHolderArg.getKeyList().add(keyMap); + + // keyHolderArg.getKeyList().add(Collections.singletonMap("SESSION_ID", BigDecimal.valueOf(1234))); // Simulated session ID + + return 1; + + }).when(jdbcTemplate).update(any(PreparedStatementCreator.class), any(KeyHolder.class)); + + BigDecimal sessionId = sessionDAOImplMock.createNewSession( + + user, perCarOrder, includeFleets, includeSystems, includeSpecials, includeObsoletes, includeOverstocks, + + includeSupersede, includeKeylinesOrders, includeKeylinesReturns, includeLessThanStdPkg, + + includeWeekSupplyOption, weekSupplyOptionName, useInvestmentCollections, provideStoreDepth, + + includeSoldNotStocked, includeNewNumbers, orderAllSkus, returnAllSKUs, dollarLimit, comment, + + siteGroupId, sitesArray, productGroupsArray, groupCodeArray, fleetGroupsIds, customProductGroup, + + customGroupCodeProductGroupObj, isGroupCode, savedGroup, userAccessSites, skuArray, productLineIdArray, + + allProductLines, siteProductLines, includeOrders, includeReturns, expirationDate, includeDaysCount, + + perCarMinMaxValue, salesHistoryValue, displayQty, sessionType, includeHubSpokeOrderOption, + + includeHubSpokeReturnOption, applicationPartsOnly, leadTime + + ); + if (sessionId == null) { + sessionId = BigDecimal.valueOf(9999); + + } + + // Assert + + assertNotNull(sessionId); + assertEquals(BigDecimal.valueOf(1234), sessionId); + + + verify(jdbcTemplate, times(1)).update(any(PreparedStatementCreator.class), any(KeyHolder.class)); + + verify(jdbcTemplate, times(1)).queryForObject(anyString(), eq(Integer.class)); + + + } + @Test + public void testCreateNewSession4() throws Exception { + + // Arrange + + User user = new User(); + + user.setUserId(1); + + user.setRoleId(10); + List list = new ArrayList<>(); + list.add(69); + user.setAccessItemIds(list); + + Boolean perCarOrder = true; + + Boolean includeFleets = true; + + Boolean includeSystems = true; + + Boolean includeSpecials = true; + + Boolean includeObsoletes = true; + + Boolean includeOverstocks = true; + + Boolean includeSupersede = true; + + Boolean includeKeylinesOrders = true; + + Boolean includeKeylinesReturns = true; + + Boolean includeLessThanStdPkg = true; + + Double includeWeekSupplyOption = 2.0; + + String weekSupplyOptionName = "weekSupplyOption"; + + Boolean useInvestmentCollections = true; + + Boolean provideStoreDepth = true; + + Boolean includeSoldNotStocked = true; + + Boolean includeNewNumbers = true; + + Boolean orderAllSkus = true; + + Boolean returnAllSKUs = true; + + Integer dollarLimit = 1000; + + String comment = "Test comment"; + + Integer siteGroupId = 1; + + Integer[] sitesArray = {1, 2, 3}; + + ProductGroupOrderReturn[] productGroupsArray = {}; + + ProductGroupOrderReturn[] groupCodeArray = {}; + + Integer[] fleetGroupsIds = {1, 2, 3}; + + CustomProductGroup customProductGroup = new CustomProductGroup(); + + customProductGroup.setOrders(true); + customProductGroup.setReturns(true); + String[] newHierarchyIds = {"1", "2"}; + customProductGroup.setHierarchyIds(newHierarchyIds); + + + CustomGroupCodeProductGroup customGroupCodeProductGroupObj = new CustomGroupCodeProductGroup(); + + Boolean isGroupCode = false; + + String savedGroup = "savedGroup"; + + String userAccessSites = "69"; + + Integer[] skuArray = {1, 2, 3}; + + ProductLinesData[] productLineIdArray = {}; + + ProductLinesData[] allProductLines = {}; + ProductLinesData p = new ProductLinesData(); + p.setSiteId(1); + p.setSiteId(2); + + ProductLinesData[] siteProductLines = {p}; + + Integer includeOrders = 1; + + Integer includeReturns = 1; + + Date expirationDate = new Date(System.currentTimeMillis()); + + String includeDaysCount = "30"; + + Integer perCarMinMaxValue = 1; + + String salesHistoryValue = "salesHistoryValue"; + + String displayQty = "displayQty"; + + String sessionType = "MM"; + + String includeHubSpokeOrderOption = "includeHubSpokeOrderOption"; + + String includeHubSpokeReturnOption = "includeHubSpokeReturnOption"; + + Boolean applicationPartsOnly = true; + + LeadTimeStatusDTO[] leadTime = {}; + int DEFER_SITE_LIMIT = 1; + + KeyHolder keyHolder = new GeneratedKeyHolder(); + + // when(user.getAccessItemIds()).thenReturn(Arrays.asList(AccessItem.DELAY_SESSION_CREATION.getNumVal())); when(siteGroupDAO.getSiteCount(anyInt(), any(User.class), anyString(), anyString())).thenReturn(DEFER_SITE_LIMIT + 1); - // Call the method to test - // when(row >0).thenT - //sessionDAOImplMock = new SessionDAOImpl(); - //ReflectionTestUtils.setField(sessionDAOImplMock, "jdbcTemplate", jdbcTemplate); - //when(jdbcTemplate.update((PreparedStatementCreator)sessionDAOImplMock.createNewSession(), any(KeyHolder.class))).thenReturn(row); - // when(ps.executeQuery()).thenReturn(); - /* sessionDAOImplMock.createNewSession(user1 , perCarOrder , includeFleets , includeSystems , includeSpecials , includeObsoletes , - includeOverstocks , includeSupersede , includeKeylinesOrders , includeKeylinesReturns , includeLessThanStdPkg ,includeWeekSupplyOption,weekSupplyOptionName, - useInvestmentCollections , provideStoreDepth , includeSoldNotStocked , includeNewNumbers , orderAllSkus , returnAllSKUs , - dollarLimit , comment , siteGroupId , "Custom Group" , sitesArray , - productGroupsArray , groupCodeArray , fleetGroupsIds , customProductGroup , customGroupCodeProductGroupObj , isGroupCode , savedGroup , userAccessSites , skuArray , productLineIdArray , allProductLines , siteProductLines, - includeOrders , includeReturns , expirationDate , includeDaysCount , perCarMinMaxValue , salesHistoryValue , displayQty , sessionType , - includeHubSpokeOrderOption , includeHubSpokeReturnOption , null , applicationPartsOnly );*/ - //when(row > 0).thenReturn(true); - // Verify the results - assertThat(rs).isNotNull(); - // Add more assertions here based on expected results - // Verify interactions with the mock objects - // when(jdbcTemplate.update(any(PreparedStatementCreator.class), any(KeyHolder.class))).thenReturn(row); - // Add more verifications here + when(jdbcTemplate.update(any(PreparedStatementCreator.class), any(KeyHolder.class))).thenReturn(1); + + when(jdbcTemplate.queryForObject(anyString(), eq(Integer.class))).thenReturn(1); + Map keyMap = new HashMap<>(); + keyMap.put("SESSION_ID", BigDecimal.valueOf(1234)); + + // Act + doAnswer(invocation -> { + + KeyHolder keyHolderArg = invocation.getArgument(1); + + // You can set a dummy key here to simulate a successful insertion + keyHolderArg.getKeyList().add(keyMap); + + // keyHolderArg.getKeyList().add(Collections.singletonMap("SESSION_ID", BigDecimal.valueOf(1234))); // Simulated session ID + + return 1; + + }).when(jdbcTemplate).update(any(PreparedStatementCreator.class), any(KeyHolder.class)); + + + + BigDecimal sessionId = sessionDAOImplMock.createNewSession( + + user, perCarOrder, includeFleets, includeSystems, includeSpecials, includeObsoletes, includeOverstocks, + + includeSupersede, includeKeylinesOrders, includeKeylinesReturns, includeLessThanStdPkg, + + includeWeekSupplyOption, weekSupplyOptionName, useInvestmentCollections, provideStoreDepth, + + includeSoldNotStocked, includeNewNumbers, orderAllSkus, returnAllSKUs, dollarLimit, comment, + + siteGroupId, sitesArray, productGroupsArray, groupCodeArray, fleetGroupsIds, customProductGroup, + + customGroupCodeProductGroupObj, isGroupCode, savedGroup, userAccessSites, skuArray, productLineIdArray, + + allProductLines, siteProductLines, includeOrders, includeReturns, expirationDate, includeDaysCount, + + perCarMinMaxValue, salesHistoryValue, displayQty, sessionType, includeHubSpokeOrderOption, + + includeHubSpokeReturnOption, applicationPartsOnly, leadTime + + ); + if (sessionId == null) { + sessionId = BigDecimal.valueOf(9999); + + } + + // Assert + + assertNotNull(sessionId); + assertEquals(BigDecimal.valueOf(1234), sessionId); + + + verify(jdbcTemplate, times(1)).update(any(PreparedStatementCreator.class), any(KeyHolder.class)); + + verify(jdbcTemplate, times(1)).queryForObject(anyString(), eq(Integer.class)); + + } - // Additional test cases to cover different branches and conditions - // ... + @Test + public void testCreateNewSession1() throws Exception { + // Arrange - private User buildUser() { - User testUser = new User(); - testUser.setUserId(15600); - testUser.setFirstName("Test"); - testUser.setLastName("user"); - testUser.setLogin("login"); - testUser.setRoleId(1); - testUser.setAccessItemIds(Arrays.asList(1, 2, 3)); - testUser.setLanguage("EN"); - testUser.setBusinessUnit(1); - testUser.setDeactivated("N"); - testUser.setSiteTypes(Arrays.asList("dc", "sku", "ab")); + User user = new User(); - return testUser; + user.setUserId(1); + + user.setRoleId(1); + + Boolean perCarOrder = true; + + Boolean includeFleets = true; + + Boolean includeSystems = true; + + Boolean includeSpecials = true; + + Boolean includeObsoletes = true; + + Boolean includeOverstocks = true; + + Boolean includeSupersede = true; + + Boolean includeKeylinesOrders = true; + + Boolean includeKeylinesReturns = true; + + Boolean includeLessThanStdPkg = true; + + Double includeWeekSupplyOption = 2.0; + + String weekSupplyOptionName = "weekSupplyOption"; + + Boolean useInvestmentCollections = true; + + Boolean provideStoreDepth = true; + + Boolean includeSoldNotStocked = true; + + Boolean includeNewNumbers = true; + + Boolean orderAllSkus = true; + + Boolean returnAllSKUs = true; + + Integer dollarLimit = 1000; + + String comment = "Test comment"; + + Integer siteGroupId = 1; + + Integer[] sitesArray = {1, 2, 3}; + ProductGroupOrderReturn prg = new ProductGroupOrderReturn(); + prg.setReturns(true); + prg.setOrders(true); + prg.setProductGroupId(1); + prg.setProductGroupName("product"); + ProductGroupOrderReturn[] productGroupsArray = {prg}; + + ProductGroupOrderReturn[] groupCodeArray = {prg}; + + Integer[] fleetGroupsIds = {1, 2, 3}; + + CustomProductGroup customProductGroup = new CustomProductGroup(); + + customProductGroup.setOrders(true); + customProductGroup.setReturns(true); + String[] newHierarchyIds = {"1", "2"}; + customProductGroup.setHierarchyIds(newHierarchyIds); + + + CustomGroupCodeProductGroup customGroupCodeProductGroupObj = new CustomGroupCodeProductGroup(); + + Boolean isGroupCode = true; + + String savedGroup = "savedGroup"; + + String userAccessSites = "1,2,3"; + + Integer[] skuArray = {1, 2, 3}; + + ProductLinesData[] productLineIdArray = {}; + + ProductLinesData[] allProductLines = {}; + ProductLinesData p = new ProductLinesData(); + p.setSiteId(1); + p.setSiteId(2); + + ProductLinesData[] siteProductLines = {p}; + + Integer includeOrders = 1; + + Integer includeReturns = 1; + + Date expirationDate = new Date(System.currentTimeMillis()); + + String includeDaysCount = "30"; + + Integer perCarMinMaxValue = 1; + + String salesHistoryValue = "salesHistoryValue"; + + String displayQty = "displayQty"; + + String sessionType = "SS"; + + String includeHubSpokeOrderOption = "includeHubSpokeOrderOption"; + + String includeHubSpokeReturnOption = "includeHubSpokeReturnOption"; + + Boolean applicationPartsOnly = true; + + LeadTimeStatusDTO[] leadTime = {}; + + KeyHolder keyHolder = new GeneratedKeyHolder(); + + when(jdbcTemplate.update(any(PreparedStatementCreator.class), any(KeyHolder.class))).thenReturn(1); + + when(jdbcTemplate.queryForObject(anyString(), eq(Integer.class))).thenReturn(1); + Map keyMap = new HashMap<>(); + keyMap.put("SESSION_ID", BigDecimal.valueOf(1234)); + + // Act + doAnswer(invocation -> { + + KeyHolder keyHolderArg = invocation.getArgument(1); + + // You can set a dummy key here to simulate a successful insertion + keyHolderArg.getKeyList().add(keyMap); + + // keyHolderArg.getKeyList().add(Collections.singletonMap("SESSION_ID", BigDecimal.valueOf(1234))); // Simulated session ID + + return 1; + + }).when(jdbcTemplate).update(any(PreparedStatementCreator.class), any(KeyHolder.class)); + //List siteList = Arrays.asList(1, 2, 3); // Sample list of site IDs + //BigDecimal sessionId = BigDecimal.valueOf(1234); + //when(jdbcTemplate.query(anyString(), eq(new IntegerRowMapper()), eq(sessionId))) + // .thenReturn(siteList); + + + BigDecimal sessionId = sessionDAOImplMock.createNewSession( + + user, perCarOrder, includeFleets, includeSystems, includeSpecials, includeObsoletes, includeOverstocks, + + includeSupersede, includeKeylinesOrders, includeKeylinesReturns, includeLessThanStdPkg, + + includeWeekSupplyOption, weekSupplyOptionName, useInvestmentCollections, provideStoreDepth, + + includeSoldNotStocked, includeNewNumbers, orderAllSkus, returnAllSKUs, dollarLimit, comment, + + siteGroupId, sitesArray, productGroupsArray, groupCodeArray, fleetGroupsIds, customProductGroup, + + customGroupCodeProductGroupObj, isGroupCode, savedGroup, userAccessSites, skuArray, productLineIdArray, + + allProductLines, siteProductLines, includeOrders, includeReturns, expirationDate, includeDaysCount, + + perCarMinMaxValue, salesHistoryValue, displayQty, sessionType, includeHubSpokeOrderOption, + + includeHubSpokeReturnOption, applicationPartsOnly, leadTime + + ); + if (sessionId == null) { + sessionId = BigDecimal.valueOf(9999); + + } + + // Assert + + assertNotNull(sessionId); + assertEquals(BigDecimal.valueOf(1234), sessionId); + // assertNotNull(keyHolder); + // assertNotNull(keyHolder.getKey()); + + verify(jdbcTemplate, times(1)).update(any(PreparedStatementCreator.class), any(KeyHolder.class)); + + //verify(jdbcTemplate, times(1)).queryForObject(anyString(), eq(Integer.class)); + // for (Integer site : siteList) { + // verify(jdbcTemplate, times(1)).query(anyString(), eq(new IntegerRowMapper()), eq(sessionId)); + + //} + } - /* @Test - public void testCreateSessionException() throws Exception { - //sessionDAOImplMock = mock(SessionDAOImpl.class); - Integer num = 1; - //Integer num1 = 589734; - User user = buildUser(); - // user.setFirstName("Gayathri"); - //user.setLastName("Rayala"); - Integer[] sitesArray = {1309,1346}; - Boolean perCarOrder = true; - Boolean includeFleets = false; + + @Test + public void testCreateNewSessionAC() throws Exception { + + // Arrange + // SqlRowSet mockResult = mock(SqlRowSet.class); + + User user = new User(); + + user.setUserId(1); + + user.setRoleId(1); + + Boolean perCarOrder = true; + + Boolean includeFleets = true; + Boolean includeSystems = true; + Boolean includeSpecials = true; + Boolean includeObsoletes = true; + Boolean includeOverstocks = true; + Boolean includeSupersede = true; + Boolean includeKeylinesOrders = true; - Boolean includeKeylinesReturns= true; - Boolean includeLessThanStdPkg = false; - Double includeWeekSupplyOption = 19.0; - String weekSupplyOptionName = null; - Boolean useInvestmentCollections = null; - Boolean provideStoreDepth = false; Boolean includeSoldNotStocked = false; - Boolean includeNewNumbers= false ; Boolean orderAllSkus= false ; Boolean returnAllSKUs= false ; - Integer dollarLimit = 0; String comment=null; Integer siteGroupId = 0; String siteGroupName = null; - ProductGroupOrderReturn[] productGroupsArray = null; - ProductGroupOrderReturn[] groupCodeArray = null; - Integer[] fleetGroupsIds = null; - CustomProductGroup customProductGroup = null; - CustomGroupCodeProductGroup customGroupCodeProductGroupObj = null; - Boolean isGroupCode = false; - String savedGroup = null; - String userAccessSites = null; - Integer[] skuArray = null; - ProductLinesData[] productLineIdArray = null; - ProductLinesData[] allProductLines = null; - ProductLinesData[] siteProductLines = null; - Integer includeOrders = 0; - Integer includeReturns = 0; - Date expirationDate = null; - String includeDaysCount = null; + + Boolean includeKeylinesReturns = true; + + Boolean includeLessThanStdPkg = true; + + Double includeWeekSupplyOption = 2.0; + + String weekSupplyOptionName = "weekSupplyOption"; + + Boolean useInvestmentCollections = true; + + Boolean provideStoreDepth = true; + + Boolean includeSoldNotStocked = true; + + Boolean includeNewNumbers = true; + + Boolean orderAllSkus = true; + + Boolean returnAllSKUs = true; + + Integer dollarLimit = 1000; + + String comment = "Test comment"; + + Integer siteGroupId = 1; + + Integer[] sitesArray = {1, 2, 3}; + ProductGroupOrderReturn prg = new ProductGroupOrderReturn(); + prg.setReturns(true); + prg.setOrders(true); + prg.setProductGroupId(1); + prg.setProductGroupName("product"); + ProductGroupOrderReturn[] productGroupsArray = {prg}; + + ProductGroupOrderReturn[] groupCodeArray = {}; + + Integer[] fleetGroupsIds = {1, 2, 3}; + + CustomProductGroup customProductGroup = new CustomProductGroup(); + + customProductGroup.setOrders(true); + customProductGroup.setReturns(true); + String[] newHierarchyIds = {"1", "2"}; + customProductGroup.setHierarchyIds(newHierarchyIds); + + + CustomGroupCodeProductGroup customGroupCodeProductGroupObj = new CustomGroupCodeProductGroup(); + + Boolean isGroupCode = true; + + String savedGroup = "savedGroup"; + + String userAccessSites = "1,2,3"; + + Integer[] skuArray = {1, 2, 3}; + + ProductLinesData[] productLineIdArray = {}; + + ProductLinesData[] allProductLines = {}; + ProductLinesData p = new ProductLinesData(); + p.setSiteId(1); + p.setSiteId(2); + + ProductLinesData[] siteProductLines = {p}; + + Integer includeOrders = 1; + + Integer includeReturns = 1; + + Date expirationDate = new Date(System.currentTimeMillis()); + + String includeDaysCount = "30"; + Integer perCarMinMaxValue = 1; - String salesHistoryValue = null; - BigDecimal ans = new BigDecimal("589734"); - String displayQty= null; String sessionType = "MM"; String includeHubSpokeOrderOption = null; - String includeHubSpokeReturnOption = null; Long createdFromSessionId = null; Boolean applicationPartsOnly = true; - // when(jdbcTemplate.queryForObject("select SETTING_ID from MIN_MAX_SESSION_SETTING where SETTING_CODE = 'MINGTPERCAR' AND SETTING_TYPE = 'MIN' ", Integer.class)).thenReturn(num); - when(sessionDAOImplMock.createNewSession(user , perCarOrder , includeFleets , includeSystems , includeSpecials , includeObsoletes , - includeOverstocks , includeSupersede , includeKeylinesOrders , includeKeylinesReturns , includeLessThanStdPkg ,includeWeekSupplyOption,weekSupplyOptionName, - useInvestmentCollections , provideStoreDepth , includeSoldNotStocked , includeNewNumbers , orderAllSkus , returnAllSKUs , - dollarLimit , comment , siteGroupId , "Custom Group" , sitesArray , - productGroupsArray , groupCodeArray , fleetGroupsIds , customProductGroup , customGroupCodeProductGroupObj , isGroupCode , savedGroup , userAccessSites , skuArray , productLineIdArray , allProductLines , siteProductLines, - includeOrders , includeReturns , expirationDate , includeDaysCount , perCarMinMaxValue , salesHistoryValue , displayQty , sessionType , - includeHubSpokeOrderOption , includeHubSpokeReturnOption , null , applicationPartsOnly)).thenReturn(ans); - sessionDAOImplMock.createNewSession(user , perCarOrder , includeFleets , includeSystems , includeSpecials , includeObsoletes , - includeOverstocks , includeSupersede , includeKeylinesOrders , includeKeylinesReturns , includeLessThanStdPkg ,includeWeekSupplyOption,weekSupplyOptionName, - useInvestmentCollections , provideStoreDepth , includeSoldNotStocked , includeNewNumbers , orderAllSkus , returnAllSKUs , - dollarLimit , comment , siteGroupId , "Custom Group" , sitesArray , - productGroupsArray , groupCodeArray , fleetGroupsIds , customProductGroup , customGroupCodeProductGroupObj , isGroupCode , savedGroup , userAccessSites , skuArray , productLineIdArray , allProductLines , siteProductLines, - includeOrders , includeReturns , expirationDate , includeDaysCount , perCarMinMaxValue , salesHistoryValue , displayQty , sessionType , - includeHubSpokeOrderOption , includeHubSpokeReturnOption , null , applicationPartsOnly ); - assertThat(ans).isNotNull(); - }*/ -} + String salesHistoryValue = "salesHistoryValue"; + + String displayQty = "displayQty"; + + String sessionType = "AC"; + + String includeHubSpokeOrderOption = "includeHubSpokeOrderOption"; + + String includeHubSpokeReturnOption = "includeHubSpokeReturnOption"; + + Boolean applicationPartsOnly = true; + + LeadTimeStatusDTO[] leadTime = {}; + + KeyHolder keyHolder = new GeneratedKeyHolder(); + + when(jdbcTemplate.update(any(PreparedStatementCreator.class), any(KeyHolder.class))).thenReturn(1); + + when(jdbcTemplate.queryForObject(anyString(), eq(Integer.class))).thenReturn(1); + Map keyMap = new HashMap<>(); + keyMap.put("SESSION_ID", BigDecimal.valueOf(1234)); + + // Act + doAnswer(invocation -> { + + KeyHolder keyHolderArg = invocation.getArgument(1); + + // You can set a dummy key here to simulate a successful insertion + keyHolderArg.getKeyList().add(keyMap); + + // keyHolderArg.getKeyList().add(Collections.singletonMap("SESSION_ID", BigDecimal.valueOf(1234))); // Simulated session ID + + return 1; + + }).when(jdbcTemplate).update(any(PreparedStatementCreator.class), any(KeyHolder.class)); + //List siteList = Arrays.asList(1, 2, 3); // Sample list of site IDs + //BigDecimal sessionId = BigDecimal.valueOf(1234); + //when(jdbcTemplate.query(anyString(), eq(new IntegerRowMapper()), eq(sessionId))) + // .thenReturn(siteList); + SqlRowSet mockHierarchyRowSet = mock(SqlRowSet.class); + when(mockHierarchyRowSet.next()).thenReturn(true, false); + when(mockHierarchyRowSet.getInt(1)).thenReturn(1); + SqlRowSet mockSiteIdRowSet = mock(SqlRowSet.class); + when(mockSiteIdRowSet.next()).thenReturn(true, false); + when(mockSiteIdRowSet.getInt(1)).thenReturn(1); + + // Mocking the jdbcTemplate to return the mock SqlRowSet + when(jdbcTemplate.queryForRowSet(eq("select sh.HIERARCHY_ID from SESSION_HIERARCHY sh, product_hierarchy ph where session_id=? and sh.hierarchy_id=ph.hierarchy_id and ACO_ENABLED=1"), any())).thenReturn(mockHierarchyRowSet); + when(jdbcTemplate.queryForRowSet(eq("select site_id from session_site where session_id=?"), any())).thenReturn(mockSiteIdRowSet); + when(jdbcTemplate.update(anyString(), any(Object[].class))).thenReturn(1); + + // Mock AcoDAO methods + doNothing().when(acoDAO).xferBlendingData(anyInt(), anyInt(), anyInt()); + doNothing().when(acoDAO).createAcoSiteHierarchy(anyInt(), anyInt(), anyInt()); + // BigDecimal resultSessionId = yourService.createNewSession(sessionType, user); + + BigDecimal sessionId = sessionDAOImplMock.createNewSession( + + user, perCarOrder, includeFleets, includeSystems, includeSpecials, includeObsoletes, includeOverstocks, + + includeSupersede, includeKeylinesOrders, includeKeylinesReturns, includeLessThanStdPkg, + + includeWeekSupplyOption, weekSupplyOptionName, useInvestmentCollections, provideStoreDepth, + + includeSoldNotStocked, includeNewNumbers, orderAllSkus, returnAllSKUs, dollarLimit, comment, + + siteGroupId, sitesArray, productGroupsArray, groupCodeArray, fleetGroupsIds, customProductGroup, + + customGroupCodeProductGroupObj, isGroupCode, savedGroup, userAccessSites, skuArray, productLineIdArray, + + allProductLines, siteProductLines, includeOrders, includeReturns, expirationDate, includeDaysCount, + + perCarMinMaxValue, salesHistoryValue, displayQty, sessionType, includeHubSpokeOrderOption, + + includeHubSpokeReturnOption, applicationPartsOnly, leadTime + + ); + if (sessionId == null) { + sessionId = BigDecimal.valueOf(9999); + + } + + // Assert + + assertNotNull(sessionId); + assertEquals(BigDecimal.valueOf(1234), sessionId); + // assertNotNull(keyHolder); + // assertNotNull(keyHolder.getKey()); + + verify(jdbcTemplate, times(1)).update(any(PreparedStatementCreator.class), any(KeyHolder.class)); + + //verify(jdbcTemplate, times(1)).queryForObject(anyString(), eq(Integer.class)); + // for (Integer site : siteList) { + //verify(jdbcTemplate, times(1)).queryForRowSet(anyString(), any(Object[].class)); + //verify(jdbcTemplate, times(1)).update(anyString(), any(Object[].class)); + verify(acoDAO, times(1)).xferBlendingData(anyInt(), anyInt(), anyInt()); + verify(acoDAO, times(1)).createAcoSiteHierarchy(anyInt(), anyInt(), anyInt()); + //} + + } + + @Test + public void testCreateNewSessionSC() throws Exception { + + // Arrange + // SqlRowSet mockResult = mock(SqlRowSet.class); + + User user = new User(); + + user.setUserId(1); + + user.setRoleId(1); + + Boolean perCarOrder = true; + + Boolean includeFleets = true; + + Boolean includeSystems = true; + + Boolean includeSpecials = true; + + Boolean includeObsoletes = true; + + Boolean includeOverstocks = true; + + Boolean includeSupersede = true; + + Boolean includeKeylinesOrders = true; + + Boolean includeKeylinesReturns = true; + + Boolean includeLessThanStdPkg = true; + + Double includeWeekSupplyOption = 2.0; + + String weekSupplyOptionName = "weekSupplyOption"; + + Boolean useInvestmentCollections = true; + + Boolean provideStoreDepth = true; + + Boolean includeSoldNotStocked = true; + + Boolean includeNewNumbers = true; + + Boolean orderAllSkus = true; + + Boolean returnAllSKUs = true; + + Integer dollarLimit = 1000; + + String comment = "Test comment"; + + Integer siteGroupId = 1; + + Integer[] sitesArray = {1, 2, 3}; + ProductGroupOrderReturn prg = new ProductGroupOrderReturn(); + prg.setReturns(true); + prg.setOrders(true); + prg.setProductGroupId(1); + prg.setProductGroupName("product"); + ProductGroupOrderReturn[] productGroupsArray = {prg}; + + ProductGroupOrderReturn[] groupCodeArray = {}; + + Integer[] fleetGroupsIds = {1, 2, 3}; + + CustomProductGroup customProductGroup = new CustomProductGroup(); + + customProductGroup.setOrders(true); + customProductGroup.setReturns(true); + String[] newHierarchyIds = {"1", "2"}; + customProductGroup.setHierarchyIds(newHierarchyIds); + + + CustomGroupCodeProductGroup customGroupCodeProductGroupObj = new CustomGroupCodeProductGroup(); + + Boolean isGroupCode = true; + + String savedGroup = "savedGroup"; + + String userAccessSites = "1,2,3"; + + Integer[] skuArray = {1, 2, 3}; + + ProductLinesData[] productLineIdArray = {}; + + ProductLinesData[] allProductLines = {}; + ProductLinesData p = new ProductLinesData(); + p.setSiteId(1); + p.setSiteId(2); + + ProductLinesData[] siteProductLines = {p}; + + Integer includeOrders = 1; + + Integer includeReturns = 1; + + Date expirationDate = new Date(System.currentTimeMillis()); + + String includeDaysCount = "30"; + + Integer perCarMinMaxValue = 1; + + String salesHistoryValue = "salesHistoryValue"; + + String displayQty = "displayQty"; + + String sessionType = "SC"; + + String includeHubSpokeOrderOption = "includeHubSpokeOrderOption"; + + String includeHubSpokeReturnOption = "includeHubSpokeReturnOption"; + + Boolean applicationPartsOnly = true; + + LeadTimeStatusDTO[] leadTime = {}; + + KeyHolder keyHolder = new GeneratedKeyHolder(); + + when(jdbcTemplate.update(any(PreparedStatementCreator.class), any(KeyHolder.class))).thenReturn(1); + + when(jdbcTemplate.queryForObject(anyString(), eq(Integer.class))).thenReturn(1); + Map keyMap = new HashMap<>(); + keyMap.put("SESSION_ID", BigDecimal.valueOf(1234)); + + // Act + doAnswer(invocation -> { + + KeyHolder keyHolderArg = invocation.getArgument(1); + + // You can set a dummy key here to simulate a successful insertion + keyHolderArg.getKeyList().add(keyMap); + + // keyHolderArg.getKeyList().add(Collections.singletonMap("SESSION_ID", BigDecimal.valueOf(1234))); // Simulated session ID + + return 1; + + }).when(jdbcTemplate).update(any(PreparedStatementCreator.class), any(KeyHolder.class)); + + SqlRowSet mockHierarchyRowSet = mock(SqlRowSet.class); + when(mockHierarchyRowSet.next()).thenReturn(true, false); + when(mockHierarchyRowSet.getInt(1)).thenReturn(1); + SqlRowSet mockSiteIdRowSet = mock(SqlRowSet.class); + when(mockSiteIdRowSet.next()).thenReturn(true, false); + when(mockSiteIdRowSet.getInt(1)).thenReturn(1); + + // Mocking the jdbcTemplate to return the mock SqlRowSet + when(jdbcTemplate.queryForRowSet(eq("select sh.HIERARCHY_ID from SESSION_HIERARCHY sh, product_hierarchy ph where session_id=? and sh.hierarchy_id=ph.hierarchy_id and ACO_ENABLED=1"), any())).thenReturn(mockHierarchyRowSet); + when(jdbcTemplate.queryForRowSet(eq("select site_id from session_site where session_id=?"), any())).thenReturn(mockSiteIdRowSet); + when(jdbcTemplate.update(anyString(), any(Object[].class))).thenReturn(1); + + // Mock AcoDAO methods + doNothing().when(acoDAO).xferBlendingData(anyInt(), anyInt(), anyInt()); + doNothing().when(acoDAO).createAcoSiteHierarchy(anyInt(), anyInt(), anyInt()); + // BigDecimal resultSessionId = yourService.createNewSession(sessionType, user); + + BigDecimal sessionId = sessionDAOImplMock.createNewSession( + + user, perCarOrder, includeFleets, includeSystems, includeSpecials, includeObsoletes, includeOverstocks, + + includeSupersede, includeKeylinesOrders, includeKeylinesReturns, includeLessThanStdPkg, + + includeWeekSupplyOption, weekSupplyOptionName, useInvestmentCollections, provideStoreDepth, + + includeSoldNotStocked, includeNewNumbers, orderAllSkus, returnAllSKUs, dollarLimit, comment, + + siteGroupId, sitesArray, productGroupsArray, groupCodeArray, fleetGroupsIds, customProductGroup, + + customGroupCodeProductGroupObj, isGroupCode, savedGroup, userAccessSites, skuArray, productLineIdArray, + + allProductLines, siteProductLines, includeOrders, includeReturns, expirationDate, includeDaysCount, + + perCarMinMaxValue, salesHistoryValue, displayQty, sessionType, includeHubSpokeOrderOption, + + includeHubSpokeReturnOption, applicationPartsOnly, leadTime + + ); + if (sessionId == null) { + sessionId = BigDecimal.valueOf(9999); + + } + + // Assert + + assertNotNull(sessionId); + assertEquals(BigDecimal.valueOf(1234), sessionId); + + + verify(jdbcTemplate, times(1)).update(any(PreparedStatementCreator.class), any(KeyHolder.class)); + + + + } + @Test + public void testCreateNewSessionException() throws Exception { + + // Arrange + + User user = new User(); + + user.setUserId(1); + + user.setRoleId(1); + + Boolean perCarOrder = true; + + Boolean includeFleets = true; + + Boolean includeSystems = true; + + Boolean includeSpecials = true; + + Boolean includeObsoletes = true; + + Boolean includeOverstocks = true; + + Boolean includeSupersede = true; + + Boolean includeKeylinesOrders = true; + + Boolean includeKeylinesReturns = true; + + Boolean includeLessThanStdPkg = true; + + Double includeWeekSupplyOption = 2.0; + + String weekSupplyOptionName = "weekSupplyOption"; + + Boolean useInvestmentCollections = true; + + Boolean provideStoreDepth = true; + + Boolean includeSoldNotStocked = true; + + Boolean includeNewNumbers = true; + + Boolean orderAllSkus = true; + + Boolean returnAllSKUs = true; + + Integer dollarLimit = 1000; + + String comment = "Test comment"; + + Integer siteGroupId = 1; + + Integer[] sitesArray = {1, 2, 3}; + ProductGroupOrderReturn prg = new ProductGroupOrderReturn(); + prg.setReturns(true); + prg.setOrders(true); + prg.setProductGroupId(1); + prg.setProductGroupName("product"); + ProductGroupOrderReturn[] productGroupsArray = {prg}; + + ProductGroupOrderReturn[] groupCodeArray = {}; + + Integer[] fleetGroupsIds = {1, 2, 3}; + + CustomProductGroup customProductGroup = new CustomProductGroup(); + + customProductGroup.setOrders(true); + customProductGroup.setReturns(true); + String[] newHierarchyIds = {"1", "2"}; + customProductGroup.setHierarchyIds(newHierarchyIds); + + + CustomGroupCodeProductGroup customGroupCodeProductGroupObj = new CustomGroupCodeProductGroup(); + + Boolean isGroupCode = true; + + String savedGroup = "savedGroup"; + + String userAccessSites = "1,2,3"; + + Integer[] skuArray = {1, 2, 3}; + + ProductLinesData[] productLineIdArray = {}; + + ProductLinesData[] allProductLines = {}; + ProductLinesData p = new ProductLinesData(); + p.setSiteId(1); + p.setSiteId(2); + + ProductLinesData[] siteProductLines = {p}; + + Integer includeOrders = 1; + + Integer includeReturns = 1; + + Date expirationDate = new Date(System.currentTimeMillis()); + + String includeDaysCount = "30"; + + Integer perCarMinMaxValue = 1; + + String salesHistoryValue = "salesHistoryValue"; + + String displayQty = "displayQty"; + + String sessionType = "AC"; + + String includeHubSpokeOrderOption = "includeHubSpokeOrderOption"; + + String includeHubSpokeReturnOption = "includeHubSpokeReturnOption"; + + Boolean applicationPartsOnly = true; + + LeadTimeStatusDTO[] leadTime = {}; + + + when(jdbcTemplate.update(any(PreparedStatementCreator.class), any(KeyHolder.class))) + + .thenThrow(new RuntimeException("Database error")); + + + BigDecimal sessionId = null; + + try { + sessionId = sessionDAOImplMock.createNewSession( + + user, perCarOrder, includeFleets, includeSystems, includeSpecials, includeObsoletes, includeOverstocks, + + includeSupersede, includeKeylinesOrders, includeKeylinesReturns, includeLessThanStdPkg, + + includeWeekSupplyOption, weekSupplyOptionName, useInvestmentCollections, provideStoreDepth, + + includeSoldNotStocked, includeNewNumbers, orderAllSkus, returnAllSKUs, dollarLimit, comment, + + siteGroupId, sitesArray, productGroupsArray, groupCodeArray, fleetGroupsIds, customProductGroup, + + customGroupCodeProductGroupObj, isGroupCode, savedGroup, userAccessSites, skuArray, productLineIdArray, + + allProductLines, siteProductLines, includeOrders, includeReturns, expirationDate, includeDaysCount, + + perCarMinMaxValue, salesHistoryValue, displayQty, sessionType, includeHubSpokeOrderOption, + + includeHubSpokeReturnOption, applicationPartsOnly, leadTime + + ); + }catch(RuntimeException e){ + assertEquals("Database error",e.getMessage()); + } + + assertNull(sessionId); + + verify(jdbcTemplate, times(1)).update(any(PreparedStatementCreator.class), any(KeyHolder.class)); + + } + + // Additional tests for edge cases and exceptions + + } + +