public void endElement(String uri, String localName, String qName) {
    // if end tag is one of below then set inXYZ to false
    if (qName.equals("ListenerDescriptions")) {
      inListenerDescriptions = false;
    } else if (qName.equals("AppCookieStickinessPolicies")) {
      inAppCookieStickinessPolicies = false;
    } else if (qName.equals("LBCookieStickinessPolicies")) {
      inLBCookieStickinessPolicies = false;
    } else if (qName.equals("LoadBalancerDescriptions")) {
      inLoadBalancerDescriptions = false;
    } else if (qName.equals("Instances")) {
      inInstances = false;
    } else if (qName.equals("AvailabilityZones")) {
      inAvailabilityZones = false;
    }

    if (qName.equals("DNSName")) {
      elb.setDnsName(currentText.toString().trim());
    } else if (qName.equals("LoadBalancerName")) {
      elb.setName(currentText.toString().trim());
    } else if (qName.equals("InstanceId")) {
      elb.getInstanceIds().add(currentText.toString().trim());
    } else if (qName.equals("member")) {

      if (inAvailabilityZones) {
        elb.getAvailabilityZones().add(currentText.toString().trim());
      } else if (!(inListenerDescriptions
          || inAppCookieStickinessPolicies
          || inInstances
          || inLBCookieStickinessPolicies
          || inAvailabilityZones)) {
        try {
          String region = AWSUtils.findRegionInArgsOrNull(getRequest());
          elb.setRegion(region);
          contents.add(elb);
        } catch (NullPointerException e) {
          logger.warn(e, "malformed load balancer: %s", localName);
        }

        this.elb = null;
      }
    }

    currentText = new StringBuilder();
  }
  @Test
  protected void testListInstanceStates() {
    for (LoadBalancer loadBalancer : api.getLoadBalancerApi().list().concat()) {
      Set<InstanceHealth> response =
          api().getHealthOfInstancesOfLoadBalancer(loadBalancer.getName());

      for (InstanceHealth instanceState : response) {
        checkInstanceState(instanceState);
      }

      if (response.size() > 0) {
        InstanceHealth instanceState = response.iterator().next();
        Assert.assertEquals(
            ImmutableSet.of(
                api()
                    .getHealthOfInstancesOfLoadBalancer(
                        ImmutableSet.of(instanceState.getInstanceId()), loadBalancer.getName())),
            instanceState);
      }
    }
  }
  public void testParse() {
    InputStream is = getClass().getResourceAsStream("/describe_loadbalancers.xml");

    Set<LoadBalancer> contents = Sets.newHashSet();
    LoadBalancer dummy =
        new LoadBalancer(
            null,
            "my-load-balancer",
            ImmutableSet.of("i-5b33e630", "i-8f26d7e4", "i-5933e632"),
            ImmutableSet.of("us-east-1a", "us-east-1c"),
            "my-load-balancer-1400212309.us-east-1.elb.amazonaws.com",
            dateService.iso8601DateParse("2011-05-25T23:47:23.590Z"));
    HealthCheck healthCheck = new HealthCheck(10, 30, "HTTP:80/index.html", 5, 2);
    dummy.setHealthCheck(healthCheck);

    ListenerDescription ld1 =
        new ListenerDescription(80, 80, "HTTP", null, ImmutableSet.of("AWSConsolePolicy-1"));
    dummy.getListeners().add(ld1);
    ListenerDescription ld2 =
        new ListenerDescription(8080, 8080, "HTTP", null, ImmutableSet.of("AWSConsolePolicy-2"));
    dummy.getListeners().add(ld2);

    AppCookieStickinessPolicy appPolicy =
        new AppCookieStickinessPolicy("AWSConsolePolicy-2", "JSESSIONID");
    dummy.getPolicies().add(appPolicy);
    LBCookieStickinessPolicy lbPolicy = new LBCookieStickinessPolicy("AWSConsolePolicy-1", 3600L);
    dummy.getPolicies().add(lbPolicy);

    contents.add(dummy);

    Set<LoadBalancer> result = parseLoadBalancers(is);

    assertEquals(result, contents);
  }