-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avniproject/avni-security#16 | Add basic tests for EnhancedValidation…
…Service
- Loading branch information
Showing
2 changed files
with
57 additions
and
1 deletion.
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
56 changes: 56 additions & 0 deletions
56
avni-server-api/src/test/java/org/avni/server/service/EnhancedValidationServiceTest.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,56 @@ | ||
package org.avni.server.service; | ||
|
||
import com.bugsnag.Bugsnag; | ||
import org.avni.server.common.ValidationResult; | ||
import org.avni.server.dao.AddressLevelTypeRepository; | ||
import org.avni.server.dao.ConceptRepository; | ||
import org.avni.server.dao.IndividualRepository; | ||
import org.avni.server.dao.SubjectTypeRepository; | ||
import org.avni.server.web.validation.ValidationException; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.when; | ||
import static org.mockito.MockitoAnnotations.initMocks; | ||
|
||
public class EnhancedValidationServiceTest { | ||
@Mock | ||
private FormMappingService formMappingService; | ||
@Mock | ||
private OrganisationConfigService organisationConfigService; | ||
@Mock | ||
private Bugsnag bugsnag; | ||
@Mock | ||
private ConceptRepository conceptRepository; | ||
@Mock | ||
private SubjectTypeRepository subjectTypeRepository; | ||
@Mock | ||
private IndividualRepository individualRepository; | ||
@Mock | ||
private AddressLevelTypeRepository addressLevelTypeRepository; | ||
|
||
private EnhancedValidationService enhancedValidationService; | ||
|
||
@Before | ||
public void setup() { | ||
initMocks(this); | ||
enhancedValidationService = new EnhancedValidationService(formMappingService, organisationConfigService, bugsnag, conceptRepository, subjectTypeRepository, individualRepository, addressLevelTypeRepository); | ||
} | ||
|
||
@Test(expected = ValidationException.class) | ||
public void shouldThrowValidationExceptionForInvalidDataIfFailOnValidationIsEnabled() { | ||
when(organisationConfigService.isFailOnValidationErrorEnabled()).thenReturn(true); | ||
String errorMessage = "Dummy Error Message"; | ||
enhancedValidationService.handleValidationFailure(errorMessage); | ||
} | ||
|
||
@Test | ||
public void shouldReturnValidationFailureForInvalidDataIfFailOnValidationIsDisabled() { | ||
when(organisationConfigService.isFailOnValidationErrorEnabled()).thenReturn(false); | ||
String errorMessage = "Dummy Error Message"; | ||
ValidationResult validationResult = enhancedValidationService.handleValidationFailure(errorMessage); | ||
assertTrue(validationResult.isFailure()); | ||
} | ||
} |