Search in sources :

Example 1 with TestDataLocator

use of com.google.api.tools.framework.model.testing.TestDataLocator in project toolkit by googleapis.

the class ModelTypeNameConverterTestUtil method getTestType.

public static TypeRef getTestType(TemporaryFolder tempDir, String... path) {
    String fileName = "library.proto";
    TestDataLocator locator = TestDataLocator.create(CodegenTestUtil.class);
    locator.addTestDataSource(CodegenTestUtil.class, "testsrc");
    Model model = CodegenTestUtil.readModel(locator, tempDir, new String[] { fileName }, new String[] { "library.yaml" });
    ProtoContainerElement container = getElementWithName(model.getFiles(), fileName);
    if (container == null) {
        throw new IllegalStateException("file not found: " + fileName);
    }
    for (int i = 0; i < path.length; i++) {
        String pathElement = path[i];
        MessageType messageType = getElementWithName(container.getMessages(), pathElement);
        EnumType enumType = getElementWithName(container.getEnums(), pathElement);
        if (messageType != null) {
            container = messageType;
        } else if (enumType != null && i == path.length - 1) {
            return TypeRef.of(enumType);
        } else if (enumType != null) {
            throw new IllegalStateException("enum type cannot contain further elements: " + enumType);
        } else {
            throw new IllegalStateException("element not found: " + pathElement);
        }
    }
    if (container instanceof MessageType) {
        return TypeRef.of((MessageType) container);
    }
    throw new IllegalStateException("not a type: " + container);
}
Also used : EnumType(com.google.api.tools.framework.model.EnumType) Model(com.google.api.tools.framework.model.Model) ProtoContainerElement(com.google.api.tools.framework.model.ProtoContainerElement) TestDataLocator(com.google.api.tools.framework.model.testing.TestDataLocator) MessageType(com.google.api.tools.framework.model.MessageType)

Example 2 with TestDataLocator

use of com.google.api.tools.framework.model.testing.TestDataLocator in project toolkit by googleapis.

the class GoGapicSurfaceTransformerTest method setupClass.

@BeforeClass
public static void setupClass() {
    TestDataLocator locator = TestDataLocator.create(GoGapicSurfaceTransformerTest.class);
    model = CodegenTestUtil.readModel(locator, tempDir, new String[] { "myproto.proto", "singleservice.proto" }, new String[] { "myproto.yaml" });
    for (Interface apiInterface : model.getSymbolTable().getInterfaces()) {
        if (apiInterface.getSimpleName().equals("Gopher")) {
            GoGapicSurfaceTransformerTest.apiInterface = apiInterface;
            break;
        }
    }
    ConfigProto configProto = CodegenTestUtil.readConfig(model.getDiagCollector(), locator, new String[] { "myproto_gapic.yaml" });
    productConfig = GapicProductConfig.create(model, configProto);
    if (model.getDiagCollector().hasErrors()) {
        throw new IllegalStateException(model.getDiagCollector().getDiags().toString());
    }
}
Also used : ConfigProto(com.google.api.codegen.ConfigProto) TestDataLocator(com.google.api.tools.framework.model.testing.TestDataLocator) Interface(com.google.api.tools.framework.model.Interface) BeforeClass(org.junit.BeforeClass)

Example 3 with TestDataLocator

use of com.google.api.tools.framework.model.testing.TestDataLocator in project toolkit by googleapis.

the class GapicConfigProducerTest method missingConfigSchemaVersion.

@Test
public void missingConfigSchemaVersion() {
    TestDataLocator locator = TestDataLocator.create(GapicConfigProducerTest.class);
    locator.addTestDataSource(CodegenTestUtil.class, "testsrc");
    model = CodegenTestUtil.readModel(locator, tempDir, new String[] { "myproto.proto" }, new String[] { "myproto.yaml" });
    ConfigProto configProto = CodegenTestUtil.readConfig(model.getDiagCollector(), locator, new String[] { "missing_config_schema_version.yaml" });
    productConfig = GapicProductConfig.create(model, configProto);
    Diag expectedError = Diag.error(SimpleLocation.TOPLEVEL, "config_schema_version field is required in GAPIC yaml.");
    Truth.assertThat(model.getDiagCollector().hasErrors());
    Truth.assertThat(model.getDiagCollector().getDiags()).contains(expectedError);
}
Also used : ConfigProto(com.google.api.codegen.ConfigProto) Diag(com.google.api.tools.framework.model.Diag) TestDataLocator(com.google.api.tools.framework.model.testing.TestDataLocator) Test(org.junit.Test)

Aggregations

TestDataLocator (com.google.api.tools.framework.model.testing.TestDataLocator)3 ConfigProto (com.google.api.codegen.ConfigProto)2 Diag (com.google.api.tools.framework.model.Diag)1 EnumType (com.google.api.tools.framework.model.EnumType)1 Interface (com.google.api.tools.framework.model.Interface)1 MessageType (com.google.api.tools.framework.model.MessageType)1 Model (com.google.api.tools.framework.model.Model)1 ProtoContainerElement (com.google.api.tools.framework.model.ProtoContainerElement)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1