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);
}
Aggregations