use of io.gravitee.rest.api.model.CustomUserFieldEntity in project gravitee-management-rest-api by gravitee-io.
the class CustomUserFieldsResourceNotAdminTest method shouldNotUpdateField.
@Test
public void shouldNotUpdateField() {
reset(customUserFieldService);
final CustomUserFieldEntity field = new CustomUserFieldEntity();
field.setKey("test-update");
field.setLabel("Test");
final Response response = orgTarget("/" + field.getKey()).request().put(Entity.json(field));
assertEquals(FORBIDDEN_403, response.getStatus());
verify(customUserFieldService, never()).update(any());
}
use of io.gravitee.rest.api.model.CustomUserFieldEntity in project gravitee-management-rest-api by gravitee-io.
the class CustomUserFieldsResourceAdminTest method shouldUpdate.
@Test
public void shouldUpdate() {
reset(customUserFieldService);
final CustomUserFieldEntity field = new CustomUserFieldEntity();
field.setKey("test-update");
field.setLabel("Test");
ArgumentCaptor<CustomUserFieldEntity> argument = ArgumentCaptor.forClass(CustomUserFieldEntity.class);
when(customUserFieldService.update(any())).thenReturn(field);
final Response response = orgTarget("/" + field.getKey()).request().put(Entity.json(field));
assertEquals(OK_200, response.getStatus());
verify(customUserFieldService, times(1)).update(any());
verify(customUserFieldService).update(argument.capture());
assertNotNull("Field provided can't be null", argument.getValue());
assertEquals(field.getKey(), argument.getValue().getKey());
}
use of io.gravitee.rest.api.model.CustomUserFieldEntity in project gravitee-management-rest-api by gravitee-io.
the class CustomUserFieldsResourceAdminTest method shouldCreateField.
@Test
public void shouldCreateField() {
reset(customUserFieldService);
final CustomUserFieldEntity field = new CustomUserFieldEntity();
field.setKey("TestResCreate");
field.setLabel("TestResCreate");
ArgumentCaptor<CustomUserFieldEntity> argument = ArgumentCaptor.forClass(CustomUserFieldEntity.class);
when(customUserFieldService.create(any())).thenReturn(field);
final Response response = orgTarget().request().post(Entity.json(field));
assertEquals(CREATED_201, response.getStatus());
verify(customUserFieldService, times(1)).create(any());
verify(customUserFieldService).create(argument.capture());
assertNotNull("Field provided can't be null", argument.getValue());
assertEquals(field.getKey(), argument.getValue().getKey());
assertTrue("LocationHeader value", response.getHeaderString("Location").endsWith(this.contextPath() + "/" + field.getKey()));
}
use of io.gravitee.rest.api.model.CustomUserFieldEntity in project gravitee-management-rest-api by gravitee-io.
the class ConfigurationCustomFieldsResourceTest method shouldListCustomFields.
@Test
public void shouldListCustomFields() {
final CustomUserFieldEntity customUserFieldEntity = new CustomUserFieldEntity();
customUserFieldEntity.setKey("key1");
customUserFieldEntity.setLabel("label 1");
customUserFieldEntity.setRequired(true);
customUserFieldEntity.setValues(Arrays.asList("a", "b"));
doReturn(Arrays.asList(customUserFieldEntity)).when(customUserFieldService).listAllFields();
final Response response = target().request().get();
assertEquals(HttpStatusCode.OK_200, response.getStatus());
final List<CustomUserFieldEntity> listOfCustomUserFields = response.readEntity(new GenericType<List<CustomUserFieldEntity>>() {
});
assertEquals(1, listOfCustomUserFields.size());
assertEquals(customUserFieldEntity.getKey(), listOfCustomUserFields.get(0).getKey());
assertEquals(customUserFieldEntity.getLabel(), listOfCustomUserFields.get(0).getLabel());
assertEquals(customUserFieldEntity.isRequired(), listOfCustomUserFields.get(0).isRequired());
assertTrue(listOfCustomUserFields.get(0).getValues().containsAll(customUserFieldEntity.getValues()));
}
use of io.gravitee.rest.api.model.CustomUserFieldEntity in project gravitee-management-rest-api by gravitee-io.
the class CustomUserFieldsServiceTest method shouldNotCreateExistingField.
@Test(expected = CustomUserFieldAlreadyExistException.class)
public void shouldNotCreateExistingField() throws Exception {
final CustomUserFieldEntity newFieldEntity = new CustomUserFieldEntity();
newFieldEntity.setKey("NEWKEYUPPERCASE");
newFieldEntity.setLabel("New Field Label");
newFieldEntity.setRequired(true);
newFieldEntity.setValues(Arrays.asList("test"));
when(customUserFieldsRepository.findById(anyString(), anyString(), any())).thenReturn(Optional.of(mock(CustomUserField.class)));
service.create(newFieldEntity);
verify(customUserFieldsRepository, never()).create(any());
}
Aggregations