use of io.gravitee.rest.api.model.CustomUserFieldEntity in project gravitee-management-rest-api by gravitee-io.
the class CustomUserFieldsServiceTest method shouldListAllEnvField.
@Test
public void shouldListAllEnvField() throws Exception {
final CustomUserField existingField1 = mock(CustomUserField.class);
when(existingField1.getKey()).thenReturn("key1");
when(existingField1.getFormat()).thenReturn(MetadataFormat.STRING);
final CustomUserField existingField2 = mock(CustomUserField.class);
when(existingField2.getKey()).thenReturn("key2");
when(existingField2.getFormat()).thenReturn(MetadataFormat.STRING);
when(customUserFieldsRepository.findByReferenceIdAndReferenceType(ORG_ID, REF_TYPE)).thenReturn(Arrays.asList(existingField1, existingField2));
List<CustomUserFieldEntity> entities = service.listAllFields();
verify(customUserFieldsRepository).findByReferenceIdAndReferenceType(ORG_ID, REF_TYPE);
assertNotNull("Fields", entities);
Assertions.assertThat(entities.stream().map(CustomUserFieldEntity::getKey).collect(Collectors.toList())).containsExactlyInAnyOrder("key1", "key2");
}
use of io.gravitee.rest.api.model.CustomUserFieldEntity in project gravitee-management-rest-api by gravitee-io.
the class CustomUserFieldsServiceTest method shouldNotCreateInvalidKey_spaces.
@Test(expected = CustomUserFieldException.class)
public void shouldNotCreateInvalidKey_spaces() throws Exception {
final CustomUserFieldEntity newFieldEntity = new CustomUserFieldEntity();
newFieldEntity.setKey("NEW KEY UPPERCASE");
newFieldEntity.setLabel("New Field Label");
newFieldEntity.setRequired(true);
newFieldEntity.setValues(Arrays.asList("test"));
service.create(newFieldEntity);
verify(customUserFieldsRepository, never()).create(any());
}
use of io.gravitee.rest.api.model.CustomUserFieldEntity in project gravitee-management-rest-api by gravitee-io.
the class CustomUserFieldsServiceTest method shouldNotCreateInvalidKey_tooLong.
@Test(expected = CustomUserFieldException.class)
public void shouldNotCreateInvalidKey_tooLong() throws Exception {
final CustomUserFieldEntity newFieldEntity = new CustomUserFieldEntity();
newFieldEntity.setKey("abcdefghijklmnopqrstuvwxz_-5648521389794abcdefghijklmnopqrstuvwxz_-5648521389794abcdefghijklmnopqrstuvwxz_-5648521389794abcdefghijklmnopqrstuvwxz_-5648521389794abcdefghijklmnopqrstuvwxz_-5648521389794");
newFieldEntity.setLabel("New Field Label");
newFieldEntity.setRequired(true);
newFieldEntity.setValues(Arrays.asList("test"));
service.create(newFieldEntity);
verify(customUserFieldsRepository, never()).create(any());
}
Aggregations