forked from mosip/admin-services
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'mosip:develop' into develop
- Loading branch information
Showing
134 changed files
with
7,605 additions
and
2,578 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
...n-service/src/test/java/io/mosip/admin/bulkdataupload/batch/CustomExcelRowMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package io.mosip.admin.bulkdataupload.batch; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.springframework.batch.extensions.excel.support.rowset.RowSet; | ||
import org.springframework.beans.NotWritablePropertyException; | ||
import org.springframework.boot.convert.ApplicationConversionService; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext; | ||
import org.springframework.format.support.DefaultFormattingConversionService; | ||
import org.springframework.validation.BindException; | ||
import org.springframework.validation.DataBinder; | ||
import org.springframework.validation.DefaultBindingErrorProcessor; | ||
import org.springframework.validation.beanvalidation.CustomValidatorBean; | ||
|
||
import javax.validation.ConstraintViolationException; | ||
import java.util.HashSet; | ||
import java.util.Properties; | ||
|
||
import static org.junit.Assert.*; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
@SpringBootTest | ||
@RunWith(MockitoJUnitRunner.class) | ||
public class CustomExcelRowMapperTest { | ||
|
||
@Test | ||
public void createBinder_withApplicationConversionService_returnSuccessResponse() { | ||
ApplicationConversionService conversionService = new ApplicationConversionService(); | ||
DataBinder actualCreateBinderResult = (new CustomExcelRowMapper<>(conversionService, new CustomValidatorBean())) | ||
.createBinder("Target"); | ||
|
||
assertNotNull(actualCreateBinderResult); | ||
assertFalse(actualCreateBinderResult.isIgnoreUnknownFields()); | ||
assertFalse(actualCreateBinderResult.isIgnoreInvalidFields()); | ||
assertTrue(actualCreateBinderResult.isAutoGrowNestedPaths()); | ||
assertNull(actualCreateBinderResult.getValidator()); | ||
assertEquals("Target", actualCreateBinderResult.getTarget()); | ||
assertEquals("target", actualCreateBinderResult.getObjectName()); | ||
assertTrue(actualCreateBinderResult.getBindingErrorProcessor() instanceof DefaultBindingErrorProcessor); | ||
assertEquals(256, actualCreateBinderResult.getAutoGrowCollectionLimit()); | ||
} | ||
|
||
@Test | ||
public void createBinder_withDefaultFormattingConversionService_returnSuccessResponse() { | ||
DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService(); | ||
|
||
DataBinder actualCreateBinderResult = (new CustomExcelRowMapper<>(conversionService, new CustomValidatorBean())) | ||
.createBinder("Target"); | ||
|
||
assertNotNull(actualCreateBinderResult); | ||
assertFalse(actualCreateBinderResult.isIgnoreUnknownFields()); | ||
assertFalse(actualCreateBinderResult.isIgnoreInvalidFields()); | ||
assertTrue(actualCreateBinderResult.isAutoGrowNestedPaths()); | ||
assertNull(actualCreateBinderResult.getValidator()); | ||
assertEquals("Target", actualCreateBinderResult.getTarget()); | ||
assertEquals("target", actualCreateBinderResult.getObjectName()); | ||
assertTrue(actualCreateBinderResult.getBindingErrorProcessor() instanceof DefaultBindingErrorProcessor); | ||
assertEquals(256, actualCreateBinderResult.getAutoGrowCollectionLimit()); | ||
} | ||
|
||
@Test | ||
public void customExcelRowMapper_withSetValues_returnSuccessResponse() { | ||
ApplicationConversionService conversionService = new ApplicationConversionService(); | ||
CustomExcelRowMapper<Object> actualCustomExcelRowMapper = new CustomExcelRowMapper<>(conversionService, | ||
new CustomValidatorBean()); | ||
actualCustomExcelRowMapper.setBeanFactory(new AnnotationConfigReactiveWebApplicationContext()); | ||
actualCustomExcelRowMapper.setDistanceLimit(1); | ||
actualCustomExcelRowMapper.setPrototypeBeanName("Name"); | ||
actualCustomExcelRowMapper.setStrict(true); | ||
actualCustomExcelRowMapper.setTargetType(Object.class); | ||
DataBinder dataBinder = new DataBinder("Target", "Object Name"); | ||
actualCustomExcelRowMapper.initBinder(dataBinder); | ||
assertNotNull(dataBinder); | ||
} | ||
|
||
@Test | ||
public void customExcelRowMapper_withInitBinder_returnSuccessResponse() { | ||
ApplicationConversionService conversionService = new ApplicationConversionService(); | ||
CustomExcelRowMapper<Object> actualCustomExcelRowMapper = new CustomExcelRowMapper<>(conversionService, | ||
new CustomValidatorBean()); | ||
DataBinder dataBinder = new DataBinder("Target", "Object Name"); | ||
actualCustomExcelRowMapper.initBinder(dataBinder); | ||
assertNotNull(dataBinder); | ||
} | ||
|
||
@Test(expected = Exception.class) | ||
public void mapRow_withEmptyRowSet_throwException() throws BindException { | ||
ApplicationConversionService conversionService = new ApplicationConversionService(); | ||
CustomExcelRowMapper<Object> customExcelRowMapper = new CustomExcelRowMapper<>(conversionService, | ||
new CustomValidatorBean()); | ||
customExcelRowMapper.setTargetType(Object.class); | ||
RowSet rowSet = mock(RowSet.class); | ||
when(rowSet.getProperties()).thenReturn(new Properties()); | ||
customExcelRowMapper.mapRow(rowSet); | ||
} | ||
|
||
@Test(expected = NotWritablePropertyException.class) | ||
public void mapRow_withProperties_throwNotWritablePropertyException() throws BindException { | ||
ApplicationConversionService conversionService = new ApplicationConversionService(); | ||
CustomExcelRowMapper<Object> customExcelRowMapper = new CustomExcelRowMapper<>(conversionService, | ||
new CustomValidatorBean()); | ||
customExcelRowMapper.setTargetType(Object.class); | ||
|
||
Properties properties = new Properties(); | ||
properties.setProperty("key", "value"); | ||
RowSet rowSet = mock(RowSet.class); | ||
when(rowSet.getProperties()).thenReturn(properties); | ||
customExcelRowMapper.mapRow(rowSet); | ||
} | ||
|
||
@Test(expected = ConstraintViolationException.class) | ||
public void mapRow_withConstraintViolation_throwConstraintViolationException() throws BindException { | ||
ApplicationConversionService conversionService = new ApplicationConversionService(); | ||
CustomExcelRowMapper<Object> customExcelRowMapper = new CustomExcelRowMapper<>(conversionService, | ||
new CustomValidatorBean()); | ||
customExcelRowMapper.setTargetType(Object.class); | ||
RowSet rowSet = mock(RowSet.class); | ||
when(rowSet.getProperties()).thenThrow(new ConstraintViolationException(new HashSet<>())); | ||
customExcelRowMapper.mapRow(rowSet); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.