Skip to content

Commit

Permalink
feat(java): ✨ boolean values handled as test data in excel s… (#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfaisalkhatri authored Oct 11, 2024
1 parent 3f3f55e commit 74aa390
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Objects;

import io.github.boykaframework.actions.interfaces.data.IDataRow;
import lombok.ToString;
import org.apache.logging.log4j.Logger;

/**
Expand All @@ -32,6 +33,7 @@
* @author Wasiq Bhamla
* @since 28-Nov-2023
*/
@ToString
class DataRow implements IDataRow {
private static final Logger LOGGER = getLogger ();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ public enum Message {
* Test Error.
*/
TEST_ERROR ("Test error..."),
/**
* Unsupported Excel value format.
*/
UNSUPPORTED_EXCEL_VALUE_FORMAT (
"The Excel value format of ({0}) is not supported. Please create a GitHub issue " + "with details to handle the same."),
/**
* User name required for cloud execution
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static io.github.boykaframework.enums.Message.ERROR_READING_FILE;
import static io.github.boykaframework.enums.Message.ERROR_SETTER_NOT_FOUND;
import static io.github.boykaframework.enums.Message.PATH_NOT_DIRECTORY;
import static io.github.boykaframework.enums.Message.UNSUPPORTED_EXCEL_VALUE_FORMAT;
import static io.github.boykaframework.manager.ParallelSession.getSession;
import static io.github.boykaframework.utils.ErrorHandler.handleAndThrow;
import static io.github.boykaframework.utils.ErrorHandler.throwError;
Expand All @@ -42,7 +43,6 @@
import java.util.List;
import java.util.Objects;

import io.github.boykaframework.utils.ErrorHandler;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
Expand Down Expand Up @@ -142,7 +142,7 @@ private <T> List<T> getDataFromFile (final List<Object[]> data, final Constructo
}
result.add (dataObject);
} catch (final InstantiationException | IllegalAccessException | InvocationTargetException e) {
ErrorHandler.handleAndThrow (ERROR_CALLING_SETTER, e, format ("set{0}", capitalize (header)), dataCtor.getClass ()
handleAndThrow (ERROR_CALLING_SETTER, e, format ("set{0}", capitalize (header)), dataCtor.getClass ()
.getSimpleName ());
}
}
Expand All @@ -162,11 +162,17 @@ private <T> void setFieldValue (final T dataObject, final Object value, final St
} else if (value instanceof Double) {
method = dataClass.getMethod (methodName, Double.class);
method.invoke (dataObject, Double.parseDouble (value.toString ()));
} else if (value instanceof Boolean) {
method = dataClass.getMethod (methodName, Boolean.class);
method.invoke (dataObject, Boolean.parseBoolean (value.toString ()));
} else {
throwError (UNSUPPORTED_EXCEL_VALUE_FORMAT, value.getClass ()
.getSimpleName ());
}
} catch (final IllegalAccessException | InvocationTargetException e) {
ErrorHandler.handleAndThrow (ERROR_CALLING_SETTER, e, methodName, dataClass.getSimpleName ());
handleAndThrow (ERROR_CALLING_SETTER, e, methodName, dataClass.getSimpleName ());
} catch (final NoSuchMethodException e) {
ErrorHandler.handleAndThrow (ERROR_SETTER_NOT_FOUND, e, methodName, dataClass.getSimpleName (), value.getClass ()
handleAndThrow (ERROR_SETTER_NOT_FOUND, e, methodName, dataClass.getSimpleName (), value.getClass ()
.getSimpleName ());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static Iterator<Object[]> getBookingData () {
public static Iterator<Object[]> getBookingDataObject () {
final var rows = DATA.get (BookingTestData.class);
return rows.stream ()
.filter (BookingTestData::getEnabled)
.map (d -> new Object[] { d })
.toList ()
.iterator ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
@ToString
@Data
public class BookingTestData {
private String additionalNeeds;
private String checkInDate;
private String checkOutDate;
private String depositPaid;
private String firstName;
private String lastName;
private Double srNo;
private Double totalPrice;
private String additionalNeeds;
private String checkInDate;
private String checkOutDate;
private String depositPaid;
private Boolean enabled;
private String firstName;
private String lastName;
private Double srNo;
private Double totalPrice;
}
Binary file modified core-java/src/test/resources/data/excel/BookingData.xlsx
Binary file not shown.

0 comments on commit 74aa390

Please sign in to comment.