Search in sources :

Example 11 with Registry

use of com.microsoft.azure.management.containerregistry.Registry in project azure-tools-for-java by Microsoft.

the class ContainerRegistryMvpModelTest method testListContainerRegistries.

@Test
public void testListContainerRegistries() throws IOException {
    List<Subscription> subscriptions = new ArrayList<Subscription>();
    Subscription sub1 = mock(Subscription.class);
    when(sub1.getId()).thenReturn("1");
    Subscription sub2 = mock(Subscription.class);
    when(sub2.getId()).thenReturn("2");
    Subscription sub3 = mock(Subscription.class);
    when(sub3.getId()).thenReturn("3");
    when(mvpModel.getSelectedSubscriptions()).thenReturn(subscriptions);
    ContainerRegistryMvpModel mockModel = spy(containerRegistryMvpModel);
    when(authMethodManagerMock.getAzureClient(anyString())).thenReturn(azureMock);
    when(registriesMock.list()).thenReturn(new PagedList<Registry>() {

        @Override
        public Page<Registry> nextPage(String nextPageLink) throws RestException, IOException {
            return null;
        }
    });
    mockModel.listContainerRegistries(false);
    verify(mockModel, times(0)).listRegistryBySubscriptionId(anyString(), eq(false));
    subscriptions.add(sub1);
    subscriptions.add(sub2);
    subscriptions.add(sub3);
    mockModel.listContainerRegistries(false);
    verify(mockModel, times(3)).listRegistryBySubscriptionId(anyString(), eq(false));
    reset(mockModel);
    mockModel.listContainerRegistries(true);
    verify(mockModel, times(3)).listRegistryBySubscriptionId(anyString(), eq(true));
}
Also used : ArrayList(java.util.ArrayList) RestException(com.microsoft.rest.RestException) Page(com.microsoft.azure.Page) Registry(com.microsoft.azure.management.containerregistry.Registry) Mockito.anyString(org.mockito.Mockito.anyString) IOException(java.io.IOException) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with Registry

use of com.microsoft.azure.management.containerregistry.Registry in project azure-tools-for-java by Microsoft.

the class ContainerRegistryMvpModelTest method testSetAdminUserEnabled.

@Test
public void testSetAdminUserEnabled() throws Exception {
    Registry.Update update = mock(Registry.Update.class);
    Registry.Update with = mock(Registry.Update.class);
    Registry.Update without = mock(Registry.Update.class);
    RegistryInner innerMock = mock(RegistryInner.class);
    when(registryMock1.update()).thenReturn(update);
    when(registryMock1.inner()).thenReturn(innerMock);
    when(update.withRegistryNameAsAdminUser()).thenReturn(with);
    when(update.withoutRegistryNameAsAdminUser()).thenReturn(without);
    Registry registry;
    registry = containerRegistryMvpModel.setAdminUserEnabled(MOCK_SUBSCRIPTION_ID, MOCK_REGISTRY_ID, true);
    verify(with, times(1)).apply();
    assertEquals(registryMock1, registry);
    registry = containerRegistryMvpModel.setAdminUserEnabled(MOCK_SUBSCRIPTION_ID, MOCK_REGISTRY_ID, false);
    verify(without, times(1)).apply();
    assertEquals(registryMock1, registry);
    registry = containerRegistryMvpModel.setAdminUserEnabled(MOCK_SUBSCRIPTION_ID_WITHOUT_REGISTRIES, MOCK_REGISTRY_ID, true);
    assertEquals(null, registry);
}
Also used : RegistryInner(com.microsoft.azure.management.containerregistry.implementation.RegistryInner) Registry(com.microsoft.azure.management.containerregistry.Registry) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with Registry

use of com.microsoft.azure.management.containerregistry.Registry in project azure-tools-for-java by Microsoft.

the class ContainerRegistryMvpModel method listRegistryBySubscriptionId.

/**
 * Get Registry by subscription id.
 */
public List<ResourceEx<Registry>> listRegistryBySubscriptionId(@NotNull String sid, boolean force) {
    if (!force && subscriptionIdToRegistryMap.containsKey(sid)) {
        return subscriptionIdToRegistryMap.get(sid);
    }
    List<ResourceEx<Registry>> registryList = new ArrayList<>();
    Azure azure = AuthMethodManager.getInstance().getAzureClient(sid);
    for (Registry registry : azure.containerRegistries().list()) {
        registryList.add(new ResourceEx<>(registry, sid));
    }
    subscriptionIdToRegistryMap.put(sid, registryList);
    return registryList;
}
Also used : Azure(com.microsoft.azure.management.Azure) ArrayList(java.util.ArrayList) Registry(com.microsoft.azure.management.containerregistry.Registry) ResourceEx(com.microsoft.azuretools.core.mvp.model.ResourceEx)

Example 14 with Registry

use of com.microsoft.azure.management.containerregistry.Registry in project azure-tools-for-java by Microsoft.

the class ContainerRegistryMvpModel method getContainerRegistry.

/**
 * Get ACR by Id.
 */
@NotNull
public Registry getContainerRegistry(String sid, String id) throws Exception {
    Azure azure = AuthMethodManager.getInstance().getAzureClient(sid);
    Registries registries = azure.containerRegistries();
    if (registries == null) {
        throw new Exception(CANNOT_GET_REGISTRY + id);
    }
    Registry registry = registries.getById(id);
    if (registry == null) {
        throw new Exception(CANNOT_GET_REGISTRY + id);
    }
    return registry;
}
Also used : Azure(com.microsoft.azure.management.Azure) Registries(com.microsoft.azure.management.containerregistry.Registries) Registry(com.microsoft.azure.management.containerregistry.Registry) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Aggregations

Registry (com.microsoft.azure.management.containerregistry.Registry)14 PrivateRegistryImageSetting (com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting)5 Azure (com.microsoft.azure.management.Azure)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Gson (com.google.gson.Gson)2 Registries (com.microsoft.azure.management.containerregistry.Registries)2 DefaultDockerClient (com.spotify.docker.client.DefaultDockerClient)2 DockerClient (com.spotify.docker.client.DockerClient)2 ArrayList (java.util.ArrayList)2 RunManagerEx (com.intellij.execution.RunManagerEx)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 ConfigurationFactory (com.intellij.execution.configurations.ConfigurationFactory)1 Notification (com.intellij.notification.Notification)1 Page (com.microsoft.azure.Page)1 RegistryInner (com.microsoft.azure.management.containerregistry.implementation.RegistryInner)1 RegistryListCredentials (com.microsoft.azure.management.containerregistry.implementation.RegistryListCredentials)1 PushImageRunConfiguration (com.microsoft.azure.toolkit.intellij.webapp.docker.pushimage.PushImageRunConfiguration)1 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)1 Subscription (com.microsoft.azure.toolkit.lib.common.model.Subscription)1