use of ca.corefacility.bioinformatics.irida.web.controller.test.unit.support.IdentifiableTestEntity in project irida by phac-nml.
the class GenericControllerTest method testCreateGoodEntity.
@Test
public void testCreateGoodEntity() {
when(crudService.create(entity)).thenReturn(entity);
when(crudService.read(identifier)).thenReturn(entity);
ModelMap model = controller.create(entity, new MockHttpServletResponse());
assertTrue("Model should contain resource", model.containsKey("resource"));
IdentifiableTestEntity testResource = (IdentifiableTestEntity) model.get("resource");
assertNotNull("Resource should not be null", testResource);
assertTrue("Resource from model should be equivalent to resource added to model", testResource.equals(entity));
assertTrue("Model should contain a self-reference", testResource.getLink(Link.REL_SELF).getHref().endsWith(identifier.toString()));
}
use of ca.corefacility.bioinformatics.irida.web.controller.test.unit.support.IdentifiableTestEntity in project irida by phac-nml.
the class ControllerExceptionHandlerTest method testHandleConstraintViolations.
@Test
public void testHandleConstraintViolations() {
final String MESSAGES_BASENAME = "ValidationMessages";
Configuration<?> configuration = Validation.byDefaultProvider().configure();
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename(MESSAGES_BASENAME);
configuration.messageInterpolator(new ResourceBundleMessageInterpolator(new PlatformResourceBundleLocator(MESSAGES_BASENAME)));
ValidatorFactory factory = configuration.buildValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<?>> constraintViolations = new HashSet<>();
Set<ConstraintViolation<IdentifiableTestEntity>> violations = validator.validate(new IdentifiableTestEntity());
for (ConstraintViolation<IdentifiableTestEntity> v : violations) {
constraintViolations.add(v);
}
ResponseEntity<Map<String, List<String>>> response = controller.handleConstraintViolations(new ConstraintViolationException(constraintViolations));
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
// assertEquals("{\"label\":[\"You must provide a label.\"]}", response.getBody());
Map<String, List<String>> body = response.getBody();
assertTrue("The response must contain an error about a missing label.", body.containsKey("label"));
List<String> labels = body.get("label");
assertEquals("There must only be one error with the label.", 1, labels.size());
String error = labels.get(0);
assertEquals("The error must be 'You must provide a label.'", "You must provide a label.", error);
}
use of ca.corefacility.bioinformatics.irida.web.controller.test.unit.support.IdentifiableTestEntity in project irida by phac-nml.
the class GenericControllerTest method setUp.
@Before
@SuppressWarnings("unchecked")
public void setUp() {
crudService = mock(CRUDService.class);
entity = new IdentifiableTestEntity();
identifier = 1L;
entity.setId(identifier);
controller = new RESTGenericController<IdentifiableTestEntity>(crudService, IdentifiableTestEntity.class) {
};
updatedFields = new HashMap<>();
}
use of ca.corefacility.bioinformatics.irida.web.controller.test.unit.support.IdentifiableTestEntity in project irida by phac-nml.
the class GenericControllerTest method testGetResource.
@Test
public void testGetResource() {
when(crudService.read(identifier)).thenReturn(entity);
ModelMap model = null;
try {
model = controller.getResource(identifier);
} catch (GenericsException e) {
fail();
}
assertTrue(model.containsKey("resource"));
IdentifiableTestEntity resource = (IdentifiableTestEntity) model.get("resource");
assertTrue(resource.getLink(Link.REL_SELF).getHref().endsWith(identifier.toString()));
}
Aggregations