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