Search in sources :

Example 36 with Ds3Element

use of com.spectralogic.ds3autogen.api.models.apispec.Ds3Element in project ds3_autogen by SpectraLogic.

the class BaseTypeGenerator_Test method toStructElementsList_FullList_Test.

@Test
public void toStructElementsList_FullList_Test() {
    final ImmutableList<StructElement> expectedElements = ImmutableList.of(new StructElement("ElementWithWrapper", "Type", "xml:\"OuterTag>InnerTag\""), new StructElement("ElementAsAttribute", "Type", "xml:\"ElementAsAttribute,attr\""), new StructElement("SimpleElement", "Type", "xml:\"SimpleElement\""));
    final ImmutableList<Ds3Element> elements = ImmutableList.of(elementWithWrapper, elementAsAttribute, simpleElement);
    final ImmutableList<StructElement> result = generator.toStructElementsList(elements);
    assertThat(result.size(), is(expectedElements.size()));
    expectedElements.forEach(expected -> assertThat(result, hasItem(expected)));
}
Also used : StructElement(com.spectralogic.ds3autogen.go.models.type.StructElement) Ds3Element(com.spectralogic.ds3autogen.api.models.apispec.Ds3Element) Test(org.junit.Test)

Example 37 with Ds3Element

use of com.spectralogic.ds3autogen.api.models.apispec.Ds3Element in project ds3_autogen by SpectraLogic.

the class CommonPrefixGenerator method toElementList.

/**
     * Converts a list of Ds3Elements into a list of Element models, while special casing the
     * CommonPrefixes element to refer to a list of CommonPrefixes objects (as opposed to a list
     * of strings specified within the contract).
     */
@Override
public ImmutableList<Element> toElementList(final ImmutableList<Ds3Element> ds3Elements) {
    if (isEmpty(ds3Elements)) {
        LOG.error("There are no elements when the CommonPrefixes element was expected");
        return ImmutableList.of();
    }
    final ImmutableList.Builder<Element> builder = ImmutableList.builder();
    for (final Ds3Element ds3Element : ds3Elements) {
        if (ds3Element.getName().equals(COMMON_PREFIX_ELEMENT)) {
            final Ds3Element commonPrefixes = new Ds3Element("CommonPrefixes", "array", "CommonPrefixes", false);
            builder.add(toElement(commonPrefixes));
        } else {
            builder.add(toElement(ds3Element));
        }
    }
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Ds3Element(com.spectralogic.ds3autogen.api.models.apispec.Ds3Element) Element(com.spectralogic.ds3autogen.java.models.Element) Ds3Element(com.spectralogic.ds3autogen.api.models.apispec.Ds3Element)

Example 38 with Ds3Element

use of com.spectralogic.ds3autogen.api.models.apispec.Ds3Element in project ds3_autogen by SpectraLogic.

the class BaseTypeGenerator method getImportsFromDs3Elements.

/**
     * Gets all the required imports that the elements will need in order to properly
     * generate the java model
     */
protected static ImmutableList<String> getImportsFromDs3Elements(final ImmutableList<Ds3Element> elements) {
    if (isEmpty(elements)) {
        return ImmutableList.of();
    }
    final ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    for (final Ds3Element element : elements) {
        if (element.getType().contains(".") && !ConvertType.isModelName(element.getType())) {
            builder.add(ConvertType.toModelName(element.getType()));
        }
        if (hasContent(element.getComponentType()) && element.getComponentType().contains(".")) {
            if (!ConvertType.isModelName(element.getComponentType())) {
                builder.add(ConvertType.toModelName(element.getComponentType()));
            }
            builder.add("java.util.List");
            builder.add("java.util.ArrayList");
            builder.add("com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper");
        }
        if (isAttribute(element.getDs3Annotations())) {
            builder.add("com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty");
        }
    }
    return builder.build().asList();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Ds3Element(com.spectralogic.ds3autogen.api.models.apispec.Ds3Element)

Example 39 with Ds3Element

use of com.spectralogic.ds3autogen.api.models.apispec.Ds3Element in project ds3_autogen by SpectraLogic.

the class Ds3TypeClassificationUtil_Test method getTestTypeMap.

/**
     * Creates a type map with testing values
     */
private static ImmutableMap<String, Ds3Type> getTestTypeMap() {
    final Ds3Type enumType = new Ds3Type("TestEnumType", "", ImmutableList.of(), ImmutableList.of(new Ds3EnumConstant("ONE", null)));
    final Ds3Type elementType = new Ds3Type("TestElementType", ImmutableList.of(new Ds3Element("Element", "int", null, false)));
    return ImmutableMap.of(enumType.getName(), enumType, elementType.getName(), elementType);
}
Also used : Ds3ModelPartialDataFixture.createEmptyDs3Type(com.spectralogic.ds3autogen.testutil.Ds3ModelPartialDataFixture.createEmptyDs3Type) Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type) Ds3EnumConstant(com.spectralogic.ds3autogen.api.models.apispec.Ds3EnumConstant) Ds3Element(com.spectralogic.ds3autogen.api.models.apispec.Ds3Element)

Example 40 with Ds3Element

use of com.spectralogic.ds3autogen.api.models.apispec.Ds3Element in project ds3_autogen by SpectraLogic.

the class Ds3TypeClassificationUtil_Test method getElementNames_Test.

@Test
public void getElementNames_Test() {
    final ImmutableList<Ds3Element> elements = ImmutableList.of(new Ds3Element("Code", "java.lang.String", null, true), new Ds3Element("HttpErrorCode", "int", null, false));
    final Ds3Type type = createDs3TypeTestData("TestType", elements);
    final ImmutableList<String> result = getElementNames(type);
    assertThat(result.size(), is(2));
    assertTrue(result.contains("Code"));
    assertTrue(result.contains("HttpErrorCode"));
}
Also used : Ds3ModelPartialDataFixture.createEmptyDs3Type(com.spectralogic.ds3autogen.testutil.Ds3ModelPartialDataFixture.createEmptyDs3Type) Ds3Type(com.spectralogic.ds3autogen.api.models.apispec.Ds3Type) Ds3Element(com.spectralogic.ds3autogen.api.models.apispec.Ds3Element) Test(org.junit.Test)

Aggregations

Ds3Element (com.spectralogic.ds3autogen.api.models.apispec.Ds3Element)54 Test (org.junit.Test)48 Ds3Type (com.spectralogic.ds3autogen.api.models.apispec.Ds3Type)22 C_Type (com.spectralogic.ds3autogen.c.models.C_Type)10 Ds3Annotation (com.spectralogic.ds3autogen.api.models.apispec.Ds3Annotation)9 Element (com.spectralogic.ds3autogen.java.models.Element)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 Ds3AnnotationElement (com.spectralogic.ds3autogen.api.models.apispec.Ds3AnnotationElement)5 ImmutableList (com.google.common.collect.ImmutableList)4 Ds3ApiSpec (com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec)4 Struct (com.spectralogic.ds3autogen.c.models.Struct)4 NetNullableVariable (com.spectralogic.ds3autogen.net.model.common.NetNullableVariable)4 Ds3ModelPartialDataFixture.createEmptyDs3Type (com.spectralogic.ds3autogen.testutil.Ds3ModelPartialDataFixture.createEmptyDs3Type)4 Ds3SpecParser (com.spectralogic.ds3autogen.api.Ds3SpecParser)3 Ds3EnumConstant (com.spectralogic.ds3autogen.api.models.apispec.Ds3EnumConstant)3 TestFileUtilsImpl (com.spectralogic.ds3autogen.utils.TestFileUtilsImpl)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Ds3SpecParserImpl (com.spectralogic.ds3autogen.Ds3SpecParserImpl)2 NameMapper (com.spectralogic.ds3autogen.NameMapper)2 Ds3DocSpecParser (com.spectralogic.ds3autogen.api.Ds3DocSpecParser)2