@Override protected Properties setupProperties() { Properties properties = super.setupProperties(); AzureLiveTestUtils.defaultProperties(properties); setIfTestSystemPropertyPresent(properties, "oauth.endpoint"); return properties; }
void assertProvider(Location provider) { assertEquals(provider.getScope(), LocationScope.PROVIDER); assertEquals(provider.getParent(), null); assertEquals(provider.getIso3166Codes(), getIso3166Codes()); }
@Test public void testTemplateBuilderWithLoginUserSpecified() throws IOException { tryOverrideUsingPropertyKey("jclouds"); tryOverrideUsingPropertyKey(provider); }
@Test public void testTemplateBuilderWithImageIdSpecified() throws IOException { Template defaultTemplate = view.getComputeService().templateBuilder().build(); ComputeServiceContext context = null; try { Properties overrides = setupProperties(); overrides.setProperty("jclouds.image-id", defaultTemplate.getImage().getId()); context = createView(overrides, setupModules()); assertEqualsTemplate(context.getComputeService().templateBuilder().build(), defaultTemplate); } finally { if (context != null) context.close(); } context = null; try { Properties overrides = setupProperties(); overrides.setProperty(provider + ".image-id", defaultTemplate.getImage().getId()); context = createView(overrides, setupModules()); assertEqualsTemplate(context.getComputeService().templateBuilder().build(), defaultTemplate); } finally { if (context != null) context.close(); } }
@Test public void testTemplateBuilderWithImageIdSpecified() throws IOException { Template defaultTemplate = view.getComputeService().templateBuilder().build(); ComputeServiceContext context = null; try { Properties overrides = setupProperties(); overrides.setProperty("jclouds.image-id", defaultTemplate.getImage().getId()); context = createView(overrides, setupModules()); assertEquals(context.getComputeService().templateBuilder().build().toString(), defaultTemplate.toString()); } finally { if (context != null) context.close(); } context = null; try { Properties overrides = setupProperties(); overrides.setProperty(provider + ".image-id", defaultTemplate.getImage().getId()); context = createView(overrides, setupModules()); assertEquals(context.getComputeService().templateBuilder().build().toString(), defaultTemplate.toString()); } finally { if (context != null) context.close(); } }
protected void tryOverrideUsingPropertyKey(String propertyKey) { // isolate tests from eachother, as default credentialStore is static Module credentialStoreModule = new CredentialStoreModule(new CopyInputStreamInputSupplierMap( new ConcurrentHashMap<String, InputSupplier<InputStream>>())); ComputeServiceContext context = null; try { Properties overrides = setupProperties(); String login = template != null && template.getLoginUser() != null ? template.getLoginUser() : "foo:bar"; overrides.setProperty(propertyKey + ".image.login-user", login); boolean auth = template != null && template.getAuthenticateSudo() != null ? template.getAuthenticateSudo() : true; overrides.setProperty(propertyKey + ".image.authenticate-sudo", auth + ""); context = createView(overrides, ImmutableSet.<Module>of(credentialStoreModule)); Iterable<String> userPass = Splitter.on(':').split(login); String user = Iterables.get(userPass, 0); String pass = Iterables.size(userPass) > 1 ? Iterables.get(userPass, 1) : null; assertEquals(context.getComputeService().templateBuilder().build().getImage().getDefaultCredentials(), LoginCredentials.builder().user(user).password(pass).authenticateSudo(auth).build()); } finally { if (context != null) { context.close(); } } }
@Test public void testTemplateBuilderCanUseImageId() throws Exception { Template defaultTemplate = view.getComputeService().templateBuilder().build(); view.close(); setupContext(); Template template = view.getComputeService().templateBuilder().imageId(defaultTemplate.getImage().getId()) .locationId(defaultTemplate.getLocation().getId()).build(); assertEquals(template.getImage(), defaultTemplate.getImage()); }
@Test(groups = { "integration", "live" }) public void testGetAssignableLocations() throws Exception { assertProvider(view.unwrap()); for (Location location : view.getComputeService().listAssignableLocations()) { System.err.printf("location %s%n", location); switch (location.getScope()) { case PROVIDER: assertProvider(location); break; case REGION: assertProvider(location.getParent()); assert location.getIso3166Codes().size() == 0 || location.getParent().getIso3166Codes().containsAll(location.getIso3166Codes()) : location + " ||" assertProvider(provider); assert location.getIso3166Codes().size() == 0 || location.getParent().getIso3166Codes().containsAll(location.getIso3166Codes()) : location + " ||" assertProvider(systemParent); break; case NETWORK: assertProvider(networkParent); break; case HOST: assertProvider(provider2); break;
protected void tryOverrideUsingPropertyKey(String propertyKey) { // isolate tests from eachother, as default credentialStore is static Module credentialStoreModule = new CredentialStoreModule( new ConcurrentHashMap<String, ByteSource>()); ComputeServiceContext context = null; try { Properties overrides = setupProperties(); String login = templateBuilderSpec != null && templateBuilderSpec.getLoginUser() != null ? templateBuilderSpec .getLoginUser() : "foo:bar"; overrides.setProperty(propertyKey + ".image.login-user", login); boolean auth = templateBuilderSpec != null && templateBuilderSpec.getAuthenticateSudo() != null ? templateBuilderSpec .getAuthenticateSudo() : true; overrides.setProperty(propertyKey + ".image.authenticate-sudo", auth + ""); context = createView(overrides, ImmutableSet.<Module>of(credentialStoreModule)); Iterable<String> userPass = Splitter.on(':').split(login); String user = Iterables.get(userPass, 0); String pass = Iterables.size(userPass) > 1 ? Iterables.get(userPass, 1) : null; assertEquals(context.getComputeService().templateBuilder().build().getImage().getDefaultCredentials(), LoginCredentials.builder().user(user).password(pass).authenticateSudo(auth).build()); } finally { if (context != null) { context.close(); } } }
@Test public void testTemplateBuilderCanUseImageId() throws Exception { Template defaultTemplate = view.getComputeService().templateBuilder().build(); view.close(); setupContext(); Template template = view.getComputeService().templateBuilder().imageId(defaultTemplate.getImage().getId()) .locationId(defaultTemplate.getLocation().getId()).build(); assertEquals(template.getImage(), defaultTemplate.getImage()); }
@Test(groups = { "integration", "live" }) public void testGetAssignableLocations() throws Exception { assertProvider(view.unwrap()); for (Location location : view.getComputeService().listAssignableLocations()) { assert location.getId() != null : location; switch (location.getScope()) { case PROVIDER: assertProvider(location); break; case REGION: assertProvider(location.getParent()); assert location.getIso3166Codes().size() == 0 || location.getParent().getIso3166Codes().containsAll(location.getIso3166Codes()) : location + " ||" assertProvider(provider); assert location.getIso3166Codes().size() == 0 || location.getParent().getIso3166Codes().containsAll(location.getIso3166Codes()) : location + " ||" assertProvider(systemParent); break; case NETWORK: assertProvider(networkParent); break; case HOST: assertProvider(provider2); break;
@Override protected Properties setupProperties() { TestProperties.setGoogleCredentialsFromJson(provider); return TestProperties.apply(provider, super.setupProperties()); }
void assertProvider(Location provider) { assertEquals(provider.getScope(), LocationScope.PROVIDER); assertEquals(provider.getParent(), null); assertEquals(provider.getIso3166Codes(), getIso3166Codes()); }
@Test public void testTemplateBuilderWithLoginUserSpecified() throws IOException { tryOverrideUsingPropertyKey("jclouds"); tryOverrideUsingPropertyKey(provider); }