<commit_before>package brooklyn.location.basic;

import java.util.Map;
import java.util.NoSuchElementException;

import org.testng.Assert;
import org.testng.annotations.Test;

import brooklyn.location.Location;
import brooklyn.location.basic.jclouds.JcloudsLocation;

public class LocationResolverTest {

    public static Location resolve(Map properties = [:], String id) {
        Location l = new LocationRegistry(properties).resolve(id);
        Assert.assertNotNull(l);
        return l;
    }
    
    @Test
    public void testLocalhostLoads() {
        Assert.assertTrue(resolve("localhost") instanceof LocalhostMachineProvisioningLocation);
    }

    @Test(expectedExceptions=[ NoSuchElementException.class, IllegalArgumentException.class ])
    public void testBogusFails() {
        /* the exception is thrown by credentialsfromenv, which is okay;
         * we could query jclouds ahead of time to see if the provider is supported, 
         * and add the following parameter to the @Test annotation:
         * expectedExceptionsMessageRegExp=".*[Nn]o resolver.*")
         */
        resolve("bogus:bogus");
    }

    public static final Map AWS_PROPS = [
        "brooklyn.jclouds.aws-ec2.identity":"x",
        "brooklyn.jclouds.aws-ec2.credential":"x",
        ]
    
    @Test
    public void testJcloudsLoads() {
        Assert.assertTrue(resolve(AWS_PROPS, "jclouds:aws-ec2") instanceof JcloudsLocation);
    }

    @Test
    public void testJcloudsImplicitLoads() {
        Assert.assertTrue(resolve(AWS_PROPS, "aws-ec2") instanceof JcloudsLocation);
    }

    @Test
    public void testJcloudsLocationLoads() {
        Assert.assertTrue(resolve(AWS_PROPS, "aws-ec2:eu-west-1") instanceof JcloudsLocation);
    }

    @Test
    public void testJcloudsRegionOnlyLoads() {
        Assert.assertTrue(resolve(AWS_PROPS, "eu-west-1") instanceof JcloudsLocation);
    }

    @Test(expectedExceptions=[ NoSuchElementException.class, IllegalArgumentException.class ],
        expectedExceptionsMessageRegExp=".*insufficient.*")
    public void testJcloudsOnlyFails() {
        resolve("jclouds");
    }
    
    @Test
    public void testAcceptsList() {
        new LocationRegistry().getLocationsById(["localhost"]);
    }

    @Test
    public void testRegistryCommaResolution() {
        List<Location> l;
        l = new LocationRegistry().getLocationsById(["byon:(hosts=\"192.168.1.{1,2}\")"]);
        Assert.assertEquals(1, l.size());
        l = new LocationRegistry().getLocationsById(["aws-ec2:us-west,byon:(hosts=\"192.168.1.{1,2}\"),aws-ec2:us-east"]);
        Assert.assertEquals(3, l.size());
        l = new LocationRegistry().getLocationsById(["aws-ec2:us-west,byon:(hosts=\"192.168.1.{1,2}\",user=bob),aws-ec2:us-east"]);
        Assert.assertEquals(3, l.size());
    }

    @Test
    public void testAcceptsListOLists() {
        //if inner list has a single item it automatically gets coerced correctly to string
        //preserve for compatibility with older CommandLineLocations (since 0.4.0) [but log warning]
        new LocationRegistry().getLocationsById([["localhost"]]);
    }

    @Test
    public void testLegacyCommandLineAcceptsList() {
        CommandLineLocations.getLocationsById(["localhost"]);
    }
    
    @Test
    public void testLegacyCommandLineAcceptsListOLists() {
        //if inner list has a single item it automatically gets coerced correctly to string
        //preserve for compatibility (since 0.4.0)
        CommandLineLocations.getLocationsById([["localhost"]]);
    }
    
}
<commit_msg>change test not to refer aws so it doesn't look for credentials<commit_after>package brooklyn.location.basic;

import java.util.Map;
import java.util.NoSuchElementException;

import org.testng.Assert;
import org.testng.annotations.Test;

import brooklyn.location.Location;
import brooklyn.location.basic.jclouds.JcloudsLocation;

public class LocationResolverTest {

    public static Location resolve(Map properties = [:], String id) {
        Location l = new LocationRegistry(properties).resolve(id);
        Assert.assertNotNull(l);
        return l;
    }
    
    @Test
    public void testLocalhostLoads() {
        Assert.assertTrue(resolve("localhost") instanceof LocalhostMachineProvisioningLocation);
    }

    @Test(expectedExceptions=[ NoSuchElementException.class, IllegalArgumentException.class ])
    public void testBogusFails() {
        /* the exception is thrown by credentialsfromenv, which is okay;
         * we could query jclouds ahead of time to see if the provider is supported, 
         * and add the following parameter to the @Test annotation:
         * expectedExceptionsMessageRegExp=".*[Nn]o resolver.*")
         */
        resolve("bogus:bogus");
    }

    public static final Map AWS_PROPS = [
        "brooklyn.jclouds.aws-ec2.identity":"x",
        "brooklyn.jclouds.aws-ec2.credential":"x",
        ]
    
    @Test
    public void testJcloudsLoads() {
        Assert.assertTrue(resolve(AWS_PROPS, "jclouds:aws-ec2") instanceof JcloudsLocation);
    }

    @Test
    public void testJcloudsImplicitLoads() {
        Assert.assertTrue(resolve(AWS_PROPS, "aws-ec2") instanceof JcloudsLocation);
    }

    @Test
    public void testJcloudsLocationLoads() {
        Assert.assertTrue(resolve(AWS_PROPS, "aws-ec2:eu-west-1") instanceof JcloudsLocation);
    }

    @Test
    public void testJcloudsRegionOnlyLoads() {
        Assert.assertTrue(resolve(AWS_PROPS, "eu-west-1") instanceof JcloudsLocation);
    }

    @Test(expectedExceptions=[ NoSuchElementException.class, IllegalArgumentException.class ],
        expectedExceptionsMessageRegExp=".*insufficient.*")
    public void testJcloudsOnlyFails() {
        resolve("jclouds");
    }
    
    @Test
    public void testAcceptsList() {
        new LocationRegistry().getLocationsById(["localhost"]);
    }

    @Test
    public void testRegistryCommaResolution() {
        List<Location> l;
        l = new LocationRegistry().getLocationsById(["byon:(hosts=\"192.168.1.{1,2}\")"]);
        Assert.assertEquals(1, l.size());
        l = new LocationRegistry().getLocationsById(["byon:(hosts=192.168.0.1),byon:(hosts=\"192.168.1.{1,2}\"),byon:(hosts=192.168.0.2)"]);
        Assert.assertEquals(3, l.size());
        l = new LocationRegistry().getLocationsById(["byon:(hosts=192.168.0.1),byon:(hosts=\"192.168.1.{1,2}\",user=bob),byon:(hosts=192.168.0.2)"]);
        Assert.assertEquals(3, l.size());
    }

    @Test
    public void testAcceptsListOLists() {
        //if inner list has a single item it automatically gets coerced correctly to string
        //preserve for compatibility with older CommandLineLocations (since 0.4.0) [but log warning]
        new LocationRegistry().getLocationsById([["localhost"]]);
    }

    @Test
    public void testLegacyCommandLineAcceptsList() {
        CommandLineLocations.getLocationsById(["localhost"]);
    }
    
    @Test
    public void testLegacyCommandLineAcceptsListOLists() {
        //if inner list has a single item it automatically gets coerced correctly to string
        //preserve for compatibility (since 0.4.0)
        CommandLineLocations.getLocationsById([["localhost"]]);
    }
    
}

{'fraction_non_alphanumeric': 0.11923931149361466, 'fraction_numerical': 0.01693503609106052, 'mean_word_length': 3.3195443645083933, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6441194', 'n_tokens_mistral': 2224, 'n_tokens_neox': 2131, 'n_words': 437}