Java Code Examples for com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription#setLoadBalancerName()

The following examples show how to use com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription#setLoadBalancerName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InventoryUtilTest.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * Fetch classic elb info test.
 *
 * @throws Exception the exception
 */
@SuppressWarnings("static-access")
@Test
public void fetchClassicElbInfoTest() throws Exception {
    
    mockStatic(AmazonElasticLoadBalancingClientBuilder.class);
    AmazonElasticLoadBalancing elbClient = PowerMockito.mock(AmazonElasticLoadBalancing.class);
    AmazonElasticLoadBalancingClientBuilder amazonElasticLoadBalancingClientBuilder = PowerMockito.mock(AmazonElasticLoadBalancingClientBuilder.class);
    AWSStaticCredentialsProvider awsStaticCredentialsProvider = PowerMockito.mock(AWSStaticCredentialsProvider.class);
    PowerMockito.whenNew(AWSStaticCredentialsProvider.class).withAnyArguments().thenReturn(awsStaticCredentialsProvider);
    when(amazonElasticLoadBalancingClientBuilder.standard()).thenReturn(amazonElasticLoadBalancingClientBuilder);
    when(amazonElasticLoadBalancingClientBuilder.withCredentials(anyObject())).thenReturn(amazonElasticLoadBalancingClientBuilder);
    when(amazonElasticLoadBalancingClientBuilder.withRegion(anyString())).thenReturn(amazonElasticLoadBalancingClientBuilder);
    when(amazonElasticLoadBalancingClientBuilder.build()).thenReturn(elbClient);
    
    com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult elbDescResult = new com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult();
    List<LoadBalancerDescription> elbList = new ArrayList<>();
    LoadBalancerDescription loadBalancerDescription = new LoadBalancerDescription();
    loadBalancerDescription.setLoadBalancerName("loadBalancerName");
    elbList.add(loadBalancerDescription);
    elbDescResult.setLoadBalancerDescriptions(elbList);
    when(elbClient.describeLoadBalancers(anyObject())).thenReturn(elbDescResult);
    
    com.amazonaws.services.elasticloadbalancing.model.DescribeTagsResult describeTagsResult = new com.amazonaws.services.elasticloadbalancing.model.DescribeTagsResult();
    List<TagDescription> tagsList = new ArrayList<TagDescription>();
    TagDescription tagDescription = new TagDescription();
    tagDescription.setLoadBalancerName("loadBalancerName");
    tagDescription.setTags(new ArrayList<com.amazonaws.services.elasticloadbalancing.model.Tag>());
    tagsList.add(tagDescription);
    describeTagsResult.setTagDescriptions(tagsList);
    when(elbClient.describeTags(anyObject())).thenReturn(describeTagsResult);
    assertThat(inventoryUtil.fetchClassicElbInfo(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), 
            "skipRegions", "account","accountName").size(), is(1));
    
}
 
Example 2
Source File: ZookeeperElbFilterTest.java    From chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void foundCloudformationZookeeper() {
    LoadBalancerDescription loadBalancer = new LoadBalancerDescription();
    List<ListenerDescription> listenerDescriptions = new ArrayList<>();
    listenerDescriptions.add(new ListenerDescription());
    loadBalancer.setListenerDescriptions(listenerDescriptions);
    loadBalancer.setLoadBalancerName(ENVIRONMENT + "-Zookeeper-whatever");
    Assert.assertTrue(filter.accept(loadBalancer));
}
 
Example 3
Source File: ZookeeperElbFilterTest.java    From chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void foundInternalExhibitor() {
    LoadBalancerDescription loadBalancer = new LoadBalancerDescription();
    List<ListenerDescription> listenerDescriptions = new ArrayList<>();
    listenerDescriptions.add(new ListenerDescription());
    loadBalancer.setListenerDescriptions(listenerDescriptions);
    loadBalancer.setLoadBalancerName("exhibitor-" + ENVIRONMENT + "-internal");
    Assert.assertTrue(filter.accept(loadBalancer));
}
 
Example 4
Source File: ZookeeperElbFilterTest.java    From chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void externalExhibitor() {
    LoadBalancerDescription loadBalancer = new LoadBalancerDescription();
    List<ListenerDescription> listenerDescriptions = new ArrayList<>();
    listenerDescriptions.add(new ListenerDescription());
    loadBalancer.setListenerDescriptions(listenerDescriptions);
    loadBalancer.setLoadBalancerName("exhibitor-" + ENVIRONMENT);
    Assert.assertFalse(filter.accept(loadBalancer));
}
 
Example 5
Source File: ZookeeperElbFilterTest.java    From chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void randomUnmatchedELB() {
    LoadBalancerDescription loadBalancer = new LoadBalancerDescription();
    List<ListenerDescription> listenerDescriptions = new ArrayList<>();
    listenerDescriptions.add(new ListenerDescription());
    loadBalancer.setListenerDescriptions(listenerDescriptions);
    loadBalancer.setLoadBalancerName(RandomStringUtils.random(5,"abcd"));
    Assert.assertFalse(filter.accept(loadBalancer));
}
 
Example 6
Source File: FetchElasticLoadBalancersJobTest.java    From fullstop with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
    this.violationSinkMock = mock(ViolationSink.class);
    this.clientProviderMock = mock(ClientProvider.class);
    this.accountIdSupplierMock = mock(AccountIdSupplier.class);
    this.jobsPropertiesMock = mock(JobsProperties.class);
    this.portsChecker = mock(PortsChecker.class);
    this.securityGroupsChecker = mock(SecurityGroupsChecker.class);
    this.mockAwsELBClient = mock(AmazonElasticLoadBalancingClient.class);
    this.mockAwsApplications = mock(AwsApplications.class);
    this.mockViolationService = mock(ViolationService.class);
    this.fetchTaupageYamlMock = mock(FetchTaupageYaml.class);
    this.mockAmiDetailsProvider = mock(AmiDetailsProvider.class);
    this.mockEC2InstanceProvider = mock(EC2InstanceProvider.class);

    final Listener listener = new Listener("HTTPS", 80, 80);

    final ListenerDescription listenerDescription = new ListenerDescription();
    listenerDescription.setListener(listener);

    final ArrayList<LoadBalancerDescription> elbs = newArrayList();
    final ArrayList<TagDescription> tagDescriptions = newArrayList();

    final LoadBalancerDescription publicELB = new LoadBalancerDescription();
    publicELB.setScheme("internet-facing");
    publicELB.setListenerDescriptions(newArrayList(listenerDescription));
    publicELB.setCanonicalHostedZoneName("test.com");
    publicELB.setInstances(asList(new Instance("i1"), new Instance("i2")));
    publicELB.setLoadBalancerName("publicELB");
    elbs.add(publicELB);
    tagDescriptions.add(
            new TagDescription()
                    .withLoadBalancerName("publicELB")
                    .withTags(newArrayList(
                            new Tag().withKey("someTag").withValue("someValue"))));

    final LoadBalancerDescription privateELB = new LoadBalancerDescription();
    privateELB.setScheme("internal");
    privateELB.setCanonicalHostedZoneName("internal.org");
    privateELB.setLoadBalancerName("privateELB");
    elbs.add(privateELB);

    for (int i = 1; i <= 20; i++) {
        final String loadBalancerName = "kubeELB" + i;
        final LoadBalancerDescription kubeELB = new LoadBalancerDescription();
        kubeELB.setScheme("internet-facing");
        kubeELB.setCanonicalHostedZoneName("test" + i + ".com");
        kubeELB.setLoadBalancerName(loadBalancerName);
        elbs.add(kubeELB);

        tagDescriptions.add(
                new TagDescription()
                        .withLoadBalancerName(loadBalancerName)
                        .withTags(newArrayList(
                                new Tag().withKey("someTag").withValue("someValue"),
                                new Tag().withKey("kubernetes.io/cluster/").withValue("owned"))));
    }

    mockDescribeELBResult = new DescribeLoadBalancersResult();
    mockDescribeELBResult.setLoadBalancerDescriptions(elbs);

    mockDescribeTagsResult = new DescribeTagsResult();
    mockDescribeTagsResult.setTagDescriptions(tagDescriptions);

    regions.add(REGION1);

    when(clientProviderMock.getClient(any(), any(String.class), any(Region.class))).thenReturn(mockAwsELBClient);

    when(mockEC2InstanceProvider.getById(anyString(), any(Region.class), anyString()))
            .thenReturn(Optional.of(new com.amazonaws.services.ec2.model.Instance().withInstanceId("foo").withImageId("bar")));
    when(mockAmiDetailsProvider.getAmiDetails(anyString(), any(Region.class), anyString()))
            .thenReturn(ImmutableMap.of("ami_id", "bar"));
}
 
Example 7
Source File: ZookeeperElbFilterTest.java    From chassis with Apache License 2.0 4 votes vote down vote up
@Test
public void noMatchingEnvironment() {
    LoadBalancerDescription loadBalancer = new LoadBalancerDescription();
    loadBalancer.setLoadBalancerName("foo-Zookeeper-whatever");
    Assert.assertFalse(filter.accept(loadBalancer));
}
 
Example 8
Source File: ZookeeperElbFilterTest.java    From chassis with Apache License 2.0 4 votes vote down vote up
@Test
public void matchingEnvironmentNoMatchingName() {
    LoadBalancerDescription loadBalancer = new LoadBalancerDescription();
    loadBalancer.setLoadBalancerName(ENVIRONMENT + "-Asgard-whatever");
    Assert.assertFalse(filter.accept(loadBalancer));
}