https://bz.apache.org/bugzilla/show_bug.cgi?id=51781

--- Comment #7 from Anupriya <[email protected]> ---
I have attached the xlsx file, in attachment section. 

Following is my test case : 

@Test(expectedExceptions = TransformationException.class)
    public void ExcelRowValidationTest() throws IOException,
TransformationException {
        Sheet sheet = new XSSFWorkbook(new
FileInputStream(getFile(TransformationConstants.TEST_MAPPING_FILE_ROWS_INVALID))).getSheetAt(0);
       
Mockito.doReturn(sheet).when(utilSpy).getExcelSheetAt(Mockito.anyString(),
Mockito.anyInt());
       
Assert.assertNull(utilSpy.convertExcelColumnsToMap(TransformationConstants.TEST_MAPPING_FILE_ROWS_INVALID,
TransformationConstants.COLUMN_3, TransformationConstants.COLUMN_4,
TransformationConstants.CALLER_ID_MAPPING));
    }


API being called up :

public Map<String, String> convertExcelColumnsToMap(String excelFileName, int
keyColIndex, int valueColIndex, String callerId) throws TransformationException
{

        try {
            logger.info("Entering convert from Excel to Map API");
            Map<String, String> map = new HashMap<>();
            Sheet sheet = getExcelSheetAt(excelFileName, 0);
            int rowCounter = 1; //because rowCounter in excel starts from 0

            System.out.println("last : " + sheet.getLastRowNum());
            System.out.println("physical rows : " +
sheet.getPhysicalNumberOfRows());


            if
(StringUtils.equalsIgnoreCase(TransformationConstants.CALLER_ID_MAPPING,
callerId) && sheet.getPhysicalNumberOfRows() !=
TransformationConstants.FIXED_ROWS_COUNT) {
                logger.error("Number of rows in mapping definition are not as
per fixed value." + TransformationConstants.FIXED_ROWS_COUNT);
                throw new
TransformationException(ValidationMessages.MAPPING_FILE_INVALID_ROW_COUNT +
TransformationConstants.FIXED_ROWS_COUNT);
            }
            for (int rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) {
                logger.info("Processing row : " + (rowNum + 1));
                Row currentRow = sheet.getRow(rowNum);

                if (currentRow != null) {
                    logger.info("This api is called up from : " + callerId);
                   
//System.out.println(StringUtils.isBlank(currentRow.getCell(keyColIndex).getStringCellValue()));
                   
//System.out.println(StringUtils.equals("BLANK",currentRow.getCell(keyColIndex).getCellType().toString()));
                    if
(StringUtils.equalsIgnoreCase(TransformationConstants.CALLER_ID_MAPPING,
callerId) && currentRow.getCell(keyColIndex) != null &&
!StringUtils.equals("BLANK",currentRow.getCell(keyColIndex).getCellType().toString())
&& currentRow.getCell(valueColIndex) != null) {
                        logger.info("Validating the content in mapping
definition");
                        if
(TransformationConstants.baseElementList.contains(currentRow.getCell(keyColIndex).getStringCellValue())
&&
TransformationConstants.standardElementList.contains(currentRow.getCell(valueColIndex).getStringCellValue()))
{
                           
map.put(currentRow.getCell(keyColIndex).getStringCellValue(),
currentRow.getCell(valueColIndex).getStringCellValue());
                        } else {
                            logger.error("Either Base Form element or Standard
Form element is invalid");
                            throw new
TransformationException(ValidationMessages.MAPPING_FILE_INVALID_ELEMENT +
(rowNum + 1) + ", refer input file : " + excelFileName);
                        }
                    } else if
(StringUtils.equalsIgnoreCase(TransformationConstants.CALLER_ID_FORM, callerId)
&& currentRow.getCell(keyColIndex) != null) {
                        logger.info("Setting the Form and mapping file name in
a map");
                        String value = null;
                        if (currentRow.getCell(valueColIndex) != null) {
                            value =
currentRow.getCell(valueColIndex).getStringCellValue();
                        }
                       
map.put(currentRow.getCell(keyColIndex).getStringCellValue(), value);
                    } else {
                        logger.error(ValidationMessages.EMPTY_CELL + (rowNum +
1) + " refer input file : " + excelFileName);
                        throw new
TransformationException(ValidationMessages.EMPTY_CELL + (rowNum + 1) + ", refer
input file : " + excelFileName);
                    }
                }

                rowCounter++;
            }

            // Double check as getPhysicalNumberofRows() API is considering
rows with BLANK Cell Type as well.
            if(rowCounter != TransformationConstants.FIXED_ROWS_COUNT){
                logger.error("Number of rows in mapping definition are not as
per fixed value." + TransformationConstants.FIXED_ROWS_COUNT);
                throw new
TransformationException(ValidationMessages.MAPPING_FILE_INVALID_ROW_COUNT +
TransformationConstants.FIXED_ROWS_COUNT);
            }

            return map;
        } catch (TransformationException transformationException) {
            logger.error(transformationException.getMessage());
            throw new
TransformationException(transformationException.getMessage());
        } catch (FileNotFoundException fileNotFoundException) {
            logger.error("An error occurred, file {} doesn't exist in
directory", excelFileName, fileNotFoundException);
            throw new TransformationException(ValidationMessages.FILE_NOT_FOUND
+ excelFileName);
        } catch (IOException ioException) {
            logger.error("Some IOException occurred : " +
ioException.getMessage());
            throw new
TransformationException(ValidationMessages.GENERAL_EXCEPTION + excelFileName);
        } catch (Exception exception) {
            logger.error(ValidationMessages.GENERAL_CONVERSION_EXCEPTION +
excelFileName);
            throw new
TransformationException(ValidationMessages.GENERAL_CONVERSION_EXCEPTION +
excelFileName);
        }
    }


RESULTS :

D:\openJDK\bin\java.exe
-agentlib:jdwp=transport=dt_socket,address=127.0.0.1:60822,suspend=y,server=n
-ea -Didea.test.cyclic.buffer.size=1048576
-javaagent:C:\Users\c-anupriya.garg\AppData\Local\JetBrains\IdeaIC2021.3\groovyHotSwap\gragent.jar
-javaagent:C:\Users\c-anupriya.garg\AppData\Local\JetBrains\IdeaIC2021.3\captureAgent\debugger-agent.jar
-Dfile.encoding=UTF-8
@C:\Users\c-anupriya.garg\AppData\Local\Temp\idea_arg_file180201787
com.intellij.rt.testng.RemoteTestNGStarter -usedefaultlisteners false
-socket60821
@w@C:\Users\c-anupriya.garg\AppData\Local\Temp\idea_working_dirs_testng1.tmp
-temp C:\Users\c-anupriya.garg\AppData\Local\Temp\idea_testng1.tmp
Connected to the target VM, address: '127.0.0.1:60822', transport: 'socket'
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in
[jar:file:/C:/Users/c-anupriya.garg/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-log4j12/1.7.30/c21f55139d8141d2231214fb1feaf50a1edca95e/slf4j-log4j12-1.7.30.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in
[jar:file:/C:/Users/c-anupriya.garg/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-simple/1.7.30/e606eac955f55ecf1d8edcccba04eb8ac98088dd/slf4j-simple-1.7.30.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in
[jar:file:/C:/Users/c-anupriya.garg/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.2.3/7c4f3c474fb2c041d8028740440937705ebb473a/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in
[jar:file:/C:/Users/c-anupriya.garg/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.2.8/22d21c4dfc77adf6f2f24bf3991846792de50b48/logback-classic-1.2.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an
explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
[TestNG] Running:
 
C:\Users\c-anupriya.garg\AppData\Local\JetBrains\IdeaIC2021.3\temp-testng-customsuite.xml

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.mockito.cglib.core.ReflectUtils$2
(file:/C:/Users/c-anupriya.garg/.gradle/caches/modules-2/files-2.1/org.mockito/mockito-all/1.10.19/539df70269cc254a58cccc5d8e43286b4a73bf30/mockito-all-1.10.19.jar)
to method
java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of
org.mockito.cglib.core.ReflectUtils$2
WARNING: Use --illegal-access=warn to enable warnings of further illegal
reflective access operations
WARNING: All illegal access operations will be denied in a future release
log4j:WARN No appenders could be found for logger
(com.metricstream.appstudio.transformation.utils.FileUtils).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more
info.


last : 10
physical rows : 11

===============================================
Default Suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================

Disconnected from the target VM, address: '127.0.0.1:60822', transport:
'socket'

Process finished with exit code 0

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to