Search in sources :

Example 11 with CustomUserFieldEntity

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");
}
Also used : CustomUserField(io.gravitee.repository.management.model.CustomUserField) CustomUserFieldEntity(io.gravitee.rest.api.model.CustomUserFieldEntity) Test(org.junit.Test)

Example 12 with CustomUserFieldEntity

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());
}
Also used : CustomUserFieldEntity(io.gravitee.rest.api.model.CustomUserFieldEntity) Test(org.junit.Test)

Example 13 with CustomUserFieldEntity

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());
}
Also used : CustomUserFieldEntity(io.gravitee.rest.api.model.CustomUserFieldEntity) Test(org.junit.Test)

Aggregations

CustomUserFieldEntity (io.gravitee.rest.api.model.CustomUserFieldEntity)13 Test (org.junit.Test)11 Response (javax.ws.rs.core.Response)6 CustomUserField (io.gravitee.repository.management.model.CustomUserField)3 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)1 Date (java.util.Date)1 List (java.util.List)1