Search in sources :

Example 6 with CustomUserFieldReferenceType

use of io.gravitee.repository.management.model.CustomUserFieldReferenceType in project gravitee-management-rest-api by gravitee-io.

the class UserMetadataServiceTest method shouldDeleteUserMetadataUsingMetaDataID.

@Test
public void shouldDeleteUserMetadataUsingMetaDataID() throws Exception {
    final String FIELD_KEY = "field_key";
    final String REF_ID = "ORGAID";
    final CustomUserFieldReferenceType REF_TYPE = CustomUserFieldReferenceType.ORGANIZATION;
    final String USER_ID_WITH_META = "userid";
    final String USER_ID_WITHOUT_META = "userid2";
    User user = new User();
    user.setId(USER_ID_WITH_META);
    User user2 = new User();
    user2.setId(USER_ID_WITHOUT_META);
    Page<User> pageOfUser = new Page<>(Arrays.asList(user, user2), 1, 2, 2);
    Page<User> emptyPage = new Page<>(Collections.emptyList(), 2, 0, 2);
    when(userRepository.search(any(), any())).thenReturn(pageOfUser, emptyPage);
    Metadata md = new Metadata();
    md.setKey(FIELD_KEY);
    md.setName(FIELD_KEY);
    md.setReferenceId(REF_ID);
    md.setReferenceType(USER);
    md.setValue("test value");
    md.setFormat(STRING);
    when(metadataRepository.findById(FIELD_KEY, USER_ID_WITH_META, USER)).thenReturn(of(md));
    when(metadataRepository.findById(FIELD_KEY, USER_ID_WITHOUT_META, USER)).thenReturn(empty());
    userMetadataService.deleteAllByCustomFieldId(FIELD_KEY, REF_ID, REF_TYPE);
    verify(metadataRepository).delete(FIELD_KEY, USER_ID_WITH_META, USER);
    verify(metadataRepository, never()).delete(FIELD_KEY, USER_ID_WITHOUT_META, USER);
}
Also used : User(io.gravitee.repository.management.model.User) CustomUserFieldReferenceType(io.gravitee.repository.management.model.CustomUserFieldReferenceType) Metadata(io.gravitee.repository.management.model.Metadata) Page(io.gravitee.common.data.domain.Page) Test(org.junit.Test)

Aggregations

CustomUserFieldReferenceType (io.gravitee.repository.management.model.CustomUserFieldReferenceType)6 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)4 CustomUserField (io.gravitee.repository.management.model.CustomUserField)4 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)4 Date (java.util.Date)3 Page (io.gravitee.common.data.domain.Page)1 Metadata (io.gravitee.repository.management.model.Metadata)1 User (io.gravitee.repository.management.model.User)1 CustomUserFieldAlreadyExistException (io.gravitee.rest.api.service.exceptions.CustomUserFieldAlreadyExistException)1 CustomUserFieldNotFoundException (io.gravitee.rest.api.service.exceptions.CustomUserFieldNotFoundException)1 Test (org.junit.Test)1