/**
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See License.txt in the project root for
 * license information.
 */

package com.microsoft.azure.management.keyvault;

import com.microsoft.azure.management.resources.fluentcore.arm.Region;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.List;

public class VaultTests extends KeyVaultManagementTestBase {
    private static final String RG_NAME = "javacsmrg905";
    private static final String VAULT_NAME = "java-keyvault-905";

    @BeforeClass
    public static void setup() throws Exception {
        createClients();
    }

    @AfterClass
    public static void cleanup() throws Exception {
        //resourceManager.resourceGroups().delete(RG_NAME);
    }

    @Test
    public void canCRUDVault() throws Exception {
        // CREATE
        Vault vault = keyVaultManager.vaults().define(VAULT_NAME)
                .withRegion(Region.US_WEST)
                .withNewResourceGroup(RG_NAME)
                .defineAccessPolicy()
                    .forServicePrincipal("http://nativeapp")
                    .allowKeyPermissions(KeyPermissions.LIST)
                    .allowSecretAllPermissions()
                    .attach()
                .defineAccessPolicy()
                    .forUser("admin2@azuresdkteam.onmicrosoft.com")
                    .allowKeyAllPermissions()
                    .allowSecretAllPermissions()
                    .attach()
                .create();
        Assert.assertNotNull(vault);
        // GET
        vault = keyVaultManager.vaults().getByGroup(RG_NAME, VAULT_NAME);
        Assert.assertNotNull(vault);
        // LIST
        List<Vault> vaults = keyVaultManager.vaults().listByGroup(RG_NAME);
        for (Vault v : vaults) {
            if (VAULT_NAME.equals(v.name())) {
                vault = v;
                break;
            }
        }
        Assert.assertNotNull(vault);
        // UPDATE
        vault.update()
                .updateAccessPolicy(vault.accessPolicies().get(0).objectId().toString())
                    .allowKeyAllPermissions()
                    .disallowSecretAllPermissions()
                    .parent()
                .apply();
        vault.update()
                .defineAccessPolicy()
                    .forServicePrincipal("http://nativeapp")
                    .allowKeyAllPermissions()
                    .attach()
                .apply();
    }
}

@@ -1723,32 +1723,844 @@
 NotNull(vault);%0A
+        for (AccessPolicy policy : vault.accessPolicies()) %7B%0A            if (policy.objectId().toString().equals(%228188d1e8-3090-4e3c-aa76-38cf2b5c7b3a%22)) %7B%0A                Assert.assertArrayEquals(new KeyPermissions%5B%5D %7B KeyPermissions.LIST %7D, policy.permissions().keys().toArray());%0A                Assert.assertArrayEquals(new SecretPermissions%5B%5D %7B SecretPermissions.ALL %7D, policy.permissions().secrets().toArray());%0A            %7D%0A            if (policy.objectId().toString().equals(%225963f50c-7c43-405c-af7e-53294de76abd%22)) %7B%0A                Assert.assertArrayEquals(new KeyPermissions%5B%5D %7B KeyPermissions.ALL %7D, policy.permissions().keys().toArray());%0A                Assert.assertArrayEquals(new SecretPermissions%5B%5D %7B SecretPermissions.ALL %7D, policy.permissions().secrets().toArray());%0A            %7D%0A        %7D%0A
         // LIST%0A
@@ -2559,16 +2559,16 @@
 // LIST%0A
-
         
@@ -3106,24 +3106,464 @@
   .apply();%0A
+        for (AccessPolicy policy : vault.accessPolicies()) %7B%0A            if (policy.objectId().toString().equals(%228188d1e8-3090-4e3c-aa76-38cf2b5c7b3a%22)) %7B%0A                Assert.assertArrayEquals(new KeyPermissions%5B%5D %7B KeyPermissions.LIST, KeyPermissions.ALL %7D, policy.permissions().keys().toArray());%0A                Assert.assertArrayEquals(new SecretPermissions%5B%5D %7B %7D, policy.permissions().secrets().toArray());%0A            %7D%0A        %7D%0A
         vaul
@@ -3652,38 +3652,38 @@
 incipal(%22http://
-native
+client
 app%22)%0A          

Add asserts to keyvault tests