Search in sources :

Example 1 with Contacts

use of com.microsoft.azure.keyvault.models.Contacts in project azure-sdk-for-java by Azure.

the class AsyncOperationsTest method certificateContactsAsync.

@Test
public void certificateContactsAsync() throws Exception {
    String vault = getVaultUri();
    Contacts contacts = keyVaultClient.setCertificateContactsAsync(vault, new Contacts(), null).get();
    Assert.assertNotNull(contacts);
    contacts = keyVaultClient.getCertificateContactsAsync(vault, null).get();
    Assert.assertNotNull(contacts);
    keyVaultClient.deleteCertificateContactsAsync(vault, null).get();
}
Also used : Contacts(com.microsoft.azure.keyvault.models.Contacts) Test(org.junit.Test)

Example 2 with Contacts

use of com.microsoft.azure.keyvault.models.Contacts in project azure-sdk-for-java by Azure.

the class CertificateOperationsTest method contactsCrudOperations.

/**
     * CRUD for Certificate contacts
     * @throws Exception 
     */
@Test
public void contactsCrudOperations() throws Exception {
    // Create
    Contact contact1 = new Contact();
    contact1.withName("James");
    contact1.withEmailAddress("james@contoso.com");
    contact1.withPhone("7777777777");
    Contact contact2 = new Contact();
    contact2.withName("Ethan");
    contact2.withEmailAddress("ethan@contoso.com");
    contact2.withPhone("8888888888");
    List<Contact> contacts = new ArrayList<Contact>();
    contacts.add(contact1);
    contacts.add(contact2);
    Contacts certificateContacts = new Contacts();
    certificateContacts.withContactList(contacts);
    Contacts createdCertificateContacts = keyVaultClient.setCertificateContacts(getVaultUri(), certificateContacts);
    Assert.assertNotNull(createdCertificateContacts);
    Assert.assertNotNull(createdCertificateContacts.contactList());
    Assert.assertTrue(createdCertificateContacts.contactList().size() == 2);
    Contact[] createContacts = createdCertificateContacts.contactList().toArray(new Contact[createdCertificateContacts.contactList().size()]);
    Assert.assertTrue(createContacts[0].name().equalsIgnoreCase("James"));
    Assert.assertTrue(createContacts[0].emailAddress().equalsIgnoreCase("james@contoso.com"));
    Assert.assertTrue(createContacts[0].phone().equalsIgnoreCase("7777777777"));
    Assert.assertTrue(createContacts[1].name().equalsIgnoreCase("Ethan"));
    Assert.assertTrue(createContacts[1].emailAddress().equalsIgnoreCase("ethan@contoso.com"));
    Assert.assertTrue(createContacts[1].phone().equalsIgnoreCase("8888888888"));
    // Get
    Contacts retrievedCertificateContacts = keyVaultClient.getCertificateContacts(getVaultUri());
    Assert.assertNotNull(retrievedCertificateContacts);
    Assert.assertNotNull(retrievedCertificateContacts.contactList());
    Assert.assertTrue(retrievedCertificateContacts.contactList().size() == 2);
    // Delete
    Contacts deletedCertificateContacts = keyVaultClient.deleteCertificateContacts(getVaultUri());
    Assert.assertNotNull(deletedCertificateContacts);
    Assert.assertNotNull(deletedCertificateContacts.contactList());
    Assert.assertTrue(deletedCertificateContacts.contactList().size() == 2);
    // Get after delete        
    try {
        keyVaultClient.getCertificateContacts(getVaultUri());
    } catch (KeyVaultErrorException e) {
        Assert.assertNotNull(e.body().error());
        Assert.assertEquals("ContactsNotFound", e.body().error().code());
    }
}
Also used : Contacts(com.microsoft.azure.keyvault.models.Contacts) KeyVaultErrorException(com.microsoft.azure.keyvault.models.KeyVaultErrorException) ArrayList(java.util.ArrayList) Contact(com.microsoft.azure.keyvault.models.Contact) Test(org.junit.Test)

Aggregations

Contacts (com.microsoft.azure.keyvault.models.Contacts)2 Test (org.junit.Test)2 Contact (com.microsoft.azure.keyvault.models.Contact)1 KeyVaultErrorException (com.microsoft.azure.keyvault.models.KeyVaultErrorException)1 ArrayList (java.util.ArrayList)1