@Test
  public void blobApiBean() throws IOException {
    final Ds3SpecParser parser = new Ds3SpecParserImpl();
    final Ds3ApiSpec spec =
        parser.getSpec(Ds3SpecParserImpl_Test.class.getResourceAsStream("/specs/blobApiBean.xml"));
    assertThat(spec.getTypes().size(), is(1));

    final Ds3Type blobApiBean =
        spec.getTypes().get("com.spectralogic.s3.common.platform.domain.BulkObject");
    assertThat(blobApiBean, is(notNullValue()));

    final ImmutableList<Ds3Element> elements = blobApiBean.getElements();
    assertThat(elements.size(), is(7));
    assertThat(elements.get(0).getName(), is("InCache"));
    assertThat(elements.get(0).getNullable(), is(true));
    assertThat(elements.get(1).getName(), is("Latest"));
    assertThat(elements.get(1).getNullable(), is(false));
    assertThat(elements.get(2).getName(), is("Length"));
    assertThat(elements.get(2).getNullable(), is(false));
    assertThat(elements.get(3).getName(), is("Name"));
    assertThat(elements.get(3).getNullable(), is(true));
    assertThat(elements.get(4).getName(), is("Offset"));
    assertThat(elements.get(4).getNullable(), is(false));
    assertThat(elements.get(5).getName(), is("PhysicalPlacement"));
    assertThat(elements.get(5).getNullable(), is(true));
    assertThat(elements.get(6).getName(), is("Version"));
    assertThat(elements.get(6).getNullable(), is(false));
  }
  public static ImmutableList<Struct> getAllStructs(
      final Ds3ApiSpec spec,
      final ImmutableSet<String> enumNames,
      final ImmutableSet<String> responseTypes,
      final ImmutableSet<String> embeddedTypes,
      final ImmutableSet<String> arrayMemberTypes,
      final ImmutableSet<String> paginatedTypes)
      throws ParseException {
    final ImmutableList.Builder<Struct> allStructsBuilder = ImmutableList.builder();
    if (ConverterUtil.hasContent(spec.getTypes())) {
      for (final Ds3Type ds3TypeEntry : spec.getTypes().values()) {
        if (ConverterUtil.hasContent(ds3TypeEntry.getEnumConstants())) continue;

        final Struct structEntry =
            StructConverter.toStruct(
                ds3TypeEntry,
                enumNames,
                responseTypes,
                embeddedTypes,
                arrayMemberTypes,
                paginatedTypes);
        allStructsBuilder.add(structEntry);
      }
    }
    return allStructsBuilder.build();
  }
 @Test
 public void fullXml_3_2() throws IOException {
   final Ds3SpecParser parser = new Ds3SpecParserImpl();
   final Ds3ApiSpec spec =
       parser.getSpec(Ds3SpecParserImpl_Test.class.getResourceAsStream("/specs/3_2_fullXml.xml"));
   assertThat(spec, is(notNullValue()));
   assertThat(spec.getRequests(), is(notNullValue()));
   assertThat(spec.getTypes(), is(notNullValue()));
 }
 public static ImmutableList<Request> getAllRequests(
     final Ds3ApiSpec spec, final Ds3DocSpec docSpec) throws ParseException {
   final ImmutableList.Builder<Request> allRequestsBuilder = ImmutableList.builder();
   if (ConverterUtil.hasContent(spec.getRequests())) {
     for (final Ds3Request ds3Request : spec.getRequests()) {
       allRequestsBuilder.add(RequestConverter.toRequest(ds3Request, docSpec));
     }
   }
   return allRequestsBuilder.build();
 }
  public static ImmutableList<Enum> getAllEnums(final Ds3ApiSpec spec) throws ParseException {
    final ImmutableList.Builder<Enum> allEnumsBuilder = ImmutableList.builder();
    if (ConverterUtil.hasContent(spec.getTypes())) {
      for (final Ds3Type ds3TypeEntry : spec.getTypes().values()) {
        if (ConverterUtil.isEmpty(ds3TypeEntry.getEnumConstants())) continue;

        allEnumsBuilder.add(EnumConverter.toEnum(ds3TypeEntry));
      }
    }
    return allEnumsBuilder.build();
  }
 @Test
 public void twoRequestHandlers() throws IOException {
   final Ds3SpecParser parser = new Ds3SpecParserImpl();
   final Ds3ApiSpec spec =
       parser.getSpec(
           Ds3SpecParserImpl_Test.class.getResourceAsStream("/specs/twoRequestHandlers.xml"));
   assertThat(spec, is(notNullValue()));
   assertThat(spec.getRequests(), is(notNullValue()));
   assertThat(spec.getRequests().size(), is(2));
   assertThat(
       spec.getRequests().get(0).getName(),
       is("com.spectralogic.s3.server.handler.reqhandler.amazons3.GetObjectRequest"));
   assertThat(
       spec.getRequests().get(1).getName(),
       is("com.spectralogic.s3.server.handler.reqhandler.amazons3.AbortMultiPartUploadRequest"));
 }
 /** Requests with optional paging require an extra "ds3_paging" member */
 public static ImmutableSet<String> getPaginatedTypes(final Ds3ApiSpec spec) {
   return spec.getRequests()
       .stream()
       .filter(Ds3RequestClassificationUtil::supportsPaginationRequest)
       .map(req -> RequestConverter.getResponseType(req.getDs3ResponseCodes()))
       .collect(GuavaCollectors.immutableSet());
 }
 /**
  * Find all types that are used as an array member, for generation of a parser for a list of a
  * type. Only applies to types that are wrapped in a common element.
  */
 public static ImmutableSet<String> getArrayMemberTypes(
     final Ds3ApiSpec spec, final ImmutableSet<String> enumTypes) {
   return spec.getTypes()
       .values()
       .stream()
       .flatMap(type -> type.getElements().stream())
       .filter(
           element ->
               element
                   .getType()
                   .equalsIgnoreCase("array")) // only want types that array member types
       .filter(element -> !element.getComponentType().contains("UUID")) // ignore UUID
       .filter(
           element ->
               element
                   .getDs3Annotations()
                   .stream()
                   .flatMap(anno -> anno.getDs3AnnotationElements().stream())
                   .anyMatch(
                       annoElem ->
                           annoElem
                               .getValue()
                               .equals(
                                   "SINGLE_BLOCK_FOR_ALL_ELEMENTS"))) // only want wrapped array
                                                                      // types
       .filter(
           element ->
               !enumTypes.contains(
                   EnumHelper.getDs3Type(element.getComponentType()))) // ignore enums
       .map(element -> StructHelper.getResponseTypeName(element.getComponentType()))
       .collect(GuavaCollectors.immutableSet());
 }
  /**
   * Find all types that are embedded members. Many 'top-level' types are not embedded and therefore
   * those parsers are useless.
   */
  public static ImmutableSet<String> getEmbeddedTypes(
      final Ds3ApiSpec spec, final ImmutableSet<String> enumTypes) {
    final ImmutableSet<String> embeddedTypes =
        spec.getTypes()
            .values()
            .stream()
            .flatMap(type -> type.getElements().stream())
            .filter(element -> !element.getType().equalsIgnoreCase("array"))
            .map(Ds3Element::getType)
            .collect(GuavaCollectors.immutableSet());
    final ImmutableSet<String> embeddedComponentTypes =
        spec.getTypes()
            .values()
            .stream()
            .flatMap(type -> type.getElements().stream())
            .filter(element -> element.getType().equalsIgnoreCase("array"))
            .map(Ds3Element::getComponentType)
            .collect(GuavaCollectors.immutableSet());

    final ImmutableSet<String> basicTypes =
        ImmutableSet.of(
            "boolean",
            "java.lang.Boolean",
            "int",
            "java.lang.Integer",
            "long",
            "java.lang.Long",
            "double",
            "java.lang.Double",
            "java.lang.String",
            "java.util.UUID",
            "java.util.Date",
            "java.lang.object",
            "com.spectralogic.util.db.lang.SqlOperation");

    return Stream.of(embeddedTypes, embeddedComponentTypes)
        .flatMap(Collection::stream)
        .filter(type -> !enumTypes.contains(StructHelper.getResponseTypeName(type)))
        .filter(type -> !basicTypes.contains(type))
        .map(StructHelper::getResponseTypeName)
        .sorted()
        .collect(GuavaCollectors.immutableSet());
  }
  @Test
  public void twoRequestHandlersAndOneType() throws IOException {
    final Ds3SpecParser parser = new Ds3SpecParserImpl();
    final Ds3ApiSpec spec =
        parser.getSpec(
            Ds3SpecParserImpl_Test.class.getResourceAsStream(
                "/specs/twoRequestHandlersAndOneType.xml"));
    assertThat(spec, is(notNullValue()));
    assertThat(spec.getTypes(), is(notNullValue()));
    assertThat(spec.getTypes().size(), is(1));
    assertThat(
        spec.getTypes().containsKey("com.spectralogic.s3.common.dao.domain.ds3.Priority"),
        is(true));

    final Ds3Type ds3Type =
        spec.getTypes().get("com.spectralogic.s3.common.dao.domain.ds3.Priority");
    assertThat(ds3Type, is(notNullValue()));
    assertThat(ds3Type.getName(), is("com.spectralogic.s3.common.dao.domain.ds3.Priority"));

    assertThat(ds3Type.getElements(), is(notNullValue()));
    assertThat(ds3Type.getElements().size(), is(1));
    assertThat(ds3Type.getElements().get(0).getName(), is("SpecifiableByUser"));
    assertThat(ds3Type.getElements().get(0).getType(), is("boolean"));
    assertThat(ds3Type.getElements().get(0).getComponentType(), is(nullValue()));
    assertThat(ds3Type.getElements().get(0).getDs3Annotations().size(), is(0));

    assertThat(ds3Type.getEnumConstants(), is(notNullValue()));
    assertThat(ds3Type.getEnumConstants().size(), is(6));
    assertThat(ds3Type.getEnumConstants().get(0).getName(), is("CRITICAL"));
    assertThat(ds3Type.getEnumConstants().get(0).getDs3Properties(), is(notNullValue()));
    assertThat(
        ds3Type.getEnumConstants().get(0).getDs3Properties().get(0).getName(),
        is("SpecifiableByUser"));
    assertThat(ds3Type.getEnumConstants().get(0).getDs3Properties().get(0).getValue(), is("false"));
    assertThat(
        ds3Type.getEnumConstants().get(0).getDs3Properties().get(0).getValueType(), is("boolean"));
  }
  @Test
  public void SingleRequestHandler() throws IOException {
    final Ds3SpecParser parser = new Ds3SpecParserImpl();
    final Ds3ApiSpec spec =
        parser.getSpec(
            Ds3SpecParserImpl_Test.class.getResourceAsStream("/specs/singleRequestHandler.xml"));
    assertThat(spec, is(notNullValue()));
    assertThat(spec.getRequests().size(), is(1));

    final Ds3Request ds3Request = spec.getRequests().get(0);
    assertThat(
        ds3Request.getName(),
        is("com.spectralogic.s3.server.handler.reqhandler.amazons3.GetObjectRequest"));
    assertThat(ds3Request.getHttpVerb(), is(HttpVerb.GET));
    assertThat(ds3Request.getClassification(), is(Classification.amazons3));
    assertThat(ds3Request.getBucketRequirement(), is(Requirement.REQUIRED));
    assertThat(ds3Request.getObjectRequirement(), is(Requirement.REQUIRED));
    assertThat(ds3Request.getAction(), is(nullValue()));
    assertThat(ds3Request.getResource(), is(nullValue()));
    assertThat(ds3Request.getResourceType(), is(nullValue()));
    assertThat(ds3Request.getOperation(), is(nullValue()));

    assertThat(ds3Request.getDs3ResponseCodes().size(), is(1));
    assertThat(ds3Request.getDs3ResponseCodes().get(0).getCode(), is(200));
    assertThat(ds3Request.getDs3ResponseCodes().get(0).getDs3ResponseTypes().size(), is(1));
    assertThat(
        ds3Request.getDs3ResponseCodes().get(0).getDs3ResponseTypes().get(0).getType(),
        is("java.lang.String"));
    assertThat(
        ds3Request.getDs3ResponseCodes().get(0).getDs3ResponseTypes().get(0).getComponentType(),
        is(nullValue()));

    assertThat(ds3Request.getOptionalQueryParams().size(), is(0));
    assertThat(ds3Request.getRequiredQueryParams().size(), is(1));
    assertThat(ds3Request.getRequiredQueryParams().get(0).getName(), is("Id"));
    assertThat(ds3Request.getRequiredQueryParams().get(0).getType(), is("java.util.UUID"));
  }
 @Test
 public void twoRequestHandlersAndTwoTypes() throws IOException {
   final Ds3SpecParser parser = new Ds3SpecParserImpl();
   final Ds3ApiSpec spec =
       parser.getSpec(
           Ds3SpecParserImpl_Test.class.getResourceAsStream(
               "/specs/twoRequestHandlersAndTwoTypes.xml"));
   assertThat(spec, is(notNullValue()));
   assertThat(spec.getTypes(), is(notNullValue()));
   assertThat(spec.getTypes().size(), is(2));
   assertThat(
       spec.getTypes().containsKey("com.spectralogic.s3.common.dao.domain.ds3.Priority"),
       is(true));
   assertThat(
       spec.getTypes()
           .containsKey("com.spectralogic.s3.common.dao.domain.tape.DetailedTapeFailure"),
       is(true));
   assertThat(
       spec.getTypes().get("com.spectralogic.s3.common.dao.domain.ds3.Priority"),
       is(notNullValue()));
   assertThat(
       spec.getTypes().get("com.spectralogic.s3.common.dao.domain.tape.DetailedTapeFailure"),
       is(notNullValue()));
 }