Search in sources :

Example 1 with CommunicationUserIdentifierModel

use of com.azure.android.communication.chat.implementation.models.CommunicationUserIdentifierModel in project azure-sdk-for-android by Azure.

the class CommunicationIdentifierConverter method assertSingleType.

private static void assertSingleType(CommunicationIdentifierModel identifier) {
    CommunicationUserIdentifierModel communicationUser = identifier.getCommunicationUser();
    PhoneNumberIdentifierModel phoneNumber = identifier.getPhoneNumber();
    MicrosoftTeamsUserIdentifierModel microsoftTeamsUser = identifier.getMicrosoftTeamsUser();
    ArrayList<String> presentProperties = new ArrayList<String>();
    if (communicationUser != null) {
        presentProperties.add(communicationUser.getClass().getName());
    }
    if (phoneNumber != null) {
        presentProperties.add(phoneNumber.getClass().getName());
    }
    if (microsoftTeamsUser != null) {
        presentProperties.add(microsoftTeamsUser.getClass().getName());
    }
    if (presentProperties.size() > 1) {
        throw new IllegalArgumentException(String.format("Only one of the identifier models in %s should be present.", TextUtils.join(", ", presentProperties)));
    }
}
Also used : CommunicationUserIdentifierModel(com.azure.android.communication.chat.implementation.models.CommunicationUserIdentifierModel) PhoneNumberIdentifierModel(com.azure.android.communication.chat.implementation.models.PhoneNumberIdentifierModel) ArrayList(java.util.ArrayList) MicrosoftTeamsUserIdentifierModel(com.azure.android.communication.chat.implementation.models.MicrosoftTeamsUserIdentifierModel)

Example 2 with CommunicationUserIdentifierModel

use of com.azure.android.communication.chat.implementation.models.CommunicationUserIdentifierModel in project azure-sdk-for-android by Azure.

the class CommunicationIdentifierConverterTests method deserializeCommunicationUser.

@Test
public void deserializeCommunicationUser() {
    CommunicationIdentifier identifier = CommunicationIdentifierConverter.convert(new CommunicationIdentifierModel().setCommunicationUser(new CommunicationUserIdentifierModel().setId(someId)), logger);
    assertEquals(identifier.getClass(), CommunicationUserIdentifier.class);
    assertEquals(someId, ((CommunicationUserIdentifier) identifier).getId());
}
Also used : CommunicationUserIdentifierModel(com.azure.android.communication.chat.implementation.models.CommunicationUserIdentifierModel) CommunicationIdentifier(com.azure.android.communication.common.CommunicationIdentifier) CommunicationIdentifierModel(com.azure.android.communication.chat.implementation.models.CommunicationIdentifierModel) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with CommunicationUserIdentifierModel

use of com.azure.android.communication.chat.implementation.models.CommunicationUserIdentifierModel in project azure-sdk-for-android by Azure.

the class CommunicationIdentifierConverterTests method deserializerThrowsWhenMissingProperty.

@Test
public void deserializerThrowsWhenMissingProperty() {
    CommunicationIdentifierModel[] modelsWithMissingMandatoryProperty = new CommunicationIdentifierModel[] { // Missing RawId
    new CommunicationIdentifierModel(), // Missing Id
    new CommunicationIdentifierModel().setRawId(rawId).setCommunicationUser(new CommunicationUserIdentifierModel()), // Missing PhoneNumber
    new CommunicationIdentifierModel().setRawId(rawId).setPhoneNumber(new PhoneNumberIdentifierModel()), new CommunicationIdentifierModel().setRawId(rawId).setMicrosoftTeamsUser(// Missing userId
    new MicrosoftTeamsUserIdentifierModel().setCloud(CommunicationCloudEnvironmentModel.PUBLIC)), new CommunicationIdentifierModel().setRawId(rawId).setMicrosoftTeamsUser(// Missing UserId
    new MicrosoftTeamsUserIdentifierModel().setIsAnonymous(true).setCloud(CommunicationCloudEnvironmentModel.DOD)), new CommunicationIdentifierModel().setRawId(rawId).setMicrosoftTeamsUser(new MicrosoftTeamsUserIdentifierModel().setUserId(teamsUserId).setIsAnonymous(true)) };
    Arrays.stream(modelsWithMissingMandatoryProperty).forEach(identifierModel -> {
        assertThrows(NullPointerException.class, () -> {
            CommunicationIdentifierConverter.convert(identifierModel, logger);
        });
    });
}
Also used : CommunicationUserIdentifierModel(com.azure.android.communication.chat.implementation.models.CommunicationUserIdentifierModel) PhoneNumberIdentifierModel(com.azure.android.communication.chat.implementation.models.PhoneNumberIdentifierModel) MicrosoftTeamsUserIdentifierModel(com.azure.android.communication.chat.implementation.models.MicrosoftTeamsUserIdentifierModel) CommunicationIdentifierModel(com.azure.android.communication.chat.implementation.models.CommunicationIdentifierModel) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with CommunicationUserIdentifierModel

use of com.azure.android.communication.chat.implementation.models.CommunicationUserIdentifierModel in project azure-sdk-for-android by Azure.

the class CommunicationIdentifierConverterTests method deserializerThrowsWhenMoreThanOneNestedObjectsSet.

@Test
public void deserializerThrowsWhenMoreThanOneNestedObjectsSet() {
    CommunicationIdentifierModel[] modelsWithTooManyNestedObjects = new CommunicationIdentifierModel[] { new CommunicationIdentifierModel().setRawId(rawId).setCommunicationUser(new CommunicationUserIdentifierModel().setId(someId)).setPhoneNumber(new PhoneNumberIdentifierModel().setValue(testPhoneNumber)), new CommunicationIdentifierModel().setRawId(rawId).setCommunicationUser(new CommunicationUserIdentifierModel().setId(someId)).setMicrosoftTeamsUser(new MicrosoftTeamsUserIdentifierModel().setUserId(teamsUserId).setIsAnonymous(true).setCloud(CommunicationCloudEnvironmentModel.PUBLIC)), new CommunicationIdentifierModel().setRawId(rawId).setPhoneNumber(new PhoneNumberIdentifierModel().setValue(testPhoneNumber)).setMicrosoftTeamsUser(new MicrosoftTeamsUserIdentifierModel().setUserId(teamsUserId).setIsAnonymous(true).setCloud(CommunicationCloudEnvironmentModel.PUBLIC)) };
    Arrays.stream(modelsWithTooManyNestedObjects).forEach(identifierModel -> {
        assertThrows(IllegalArgumentException.class, () -> {
            CommunicationIdentifierConverter.convert(identifierModel, logger);
        });
    });
}
Also used : CommunicationUserIdentifierModel(com.azure.android.communication.chat.implementation.models.CommunicationUserIdentifierModel) PhoneNumberIdentifierModel(com.azure.android.communication.chat.implementation.models.PhoneNumberIdentifierModel) MicrosoftTeamsUserIdentifierModel(com.azure.android.communication.chat.implementation.models.MicrosoftTeamsUserIdentifierModel) CommunicationIdentifierModel(com.azure.android.communication.chat.implementation.models.CommunicationIdentifierModel) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with CommunicationUserIdentifierModel

use of com.azure.android.communication.chat.implementation.models.CommunicationUserIdentifierModel in project azure-sdk-for-android by Azure.

the class ChatImplClientTestBase method generateParticipant.

private static ChatParticipant generateParticipant(String id, String displayName) {
    ChatParticipant chatParticipant = new ChatParticipant();
    chatParticipant.setCommunicationIdentifier(new CommunicationIdentifierModel().setCommunicationUser(new CommunicationUserIdentifierModel().setId(id)));
    chatParticipant.setDisplayName(displayName);
    return chatParticipant;
}
Also used : CommunicationUserIdentifierModel(com.azure.android.communication.chat.implementation.models.CommunicationUserIdentifierModel) ChatParticipant(com.azure.android.communication.chat.implementation.models.ChatParticipant) CommunicationIdentifierModel(com.azure.android.communication.chat.implementation.models.CommunicationIdentifierModel)

Aggregations

CommunicationUserIdentifierModel (com.azure.android.communication.chat.implementation.models.CommunicationUserIdentifierModel)5 CommunicationIdentifierModel (com.azure.android.communication.chat.implementation.models.CommunicationIdentifierModel)4 MicrosoftTeamsUserIdentifierModel (com.azure.android.communication.chat.implementation.models.MicrosoftTeamsUserIdentifierModel)3 PhoneNumberIdentifierModel (com.azure.android.communication.chat.implementation.models.PhoneNumberIdentifierModel)3 Test (org.junit.jupiter.api.Test)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 ChatParticipant (com.azure.android.communication.chat.implementation.models.ChatParticipant)1 CommunicationIdentifier (com.azure.android.communication.common.CommunicationIdentifier)1 ArrayList (java.util.ArrayList)1