Search in sources :

Example 6 with ProgramRegistry

use of net.morimekta.providence.reflect.util.ProgramRegistry in project providence by morimekta.

the class CProgramTest method testProgram.

@Test
public void testProgram() {
    ProgramRegistry registry = new ProgramRegistry();
    CStructDescriptor declaredDesc = new CStructDescriptor(null, "prog", "Struct", ImmutableList.of(), ImmutableMap.of());
    CService service = new CService("Documentation", "prog", "Service", null, ImmutableList.of(), ImmutableMap.of());
    CConst constant = new CConst(null, "kC", PPrimitive.STRING.provider(), new ConstProvider(registry.registryForPath("prog.thrift"), "string", "prog", "\"value\"", 2, 10), ImmutableMap.of());
    CProgram program = new CProgram("prog.thrift", "Documentation", "prog", ImmutableMap.of("java", "net.morimekta.providence", "cpp", "morimekta.providence"), ImmutableSet.of("first", "second"), ImmutableList.of("../something/first.thrift", "second.thrift"), ImmutableMap.of("S", "Struct"), ImmutableList.of(declaredDesc), ImmutableList.of(service), ImmutableList.of(constant));
    assertThat(program.getDocumentation(), is("Documentation"));
    assertThat(program.getProgramName(), is("prog"));
    assertThat(program.getTypedefs().entrySet(), hasSize(1));
    assertThat(program.getTypedefs().get("S"), is("Struct"));
    assertThat(program.getConstants(), hasSize(1));
    assertThat(program.getConstants(), hasItem(constant));
    assertThat(program.getServices(), hasSize(1));
    assertThat(program.getServices(), hasItem(service));
    assertThat(program.getDeclaredTypes(), hasSize(1));
    assertThat(program.getDeclaredTypes(), hasItem(declaredDesc));
    assertThat(program.getNamespaceForLanguage("java"), is("net.morimekta.providence"));
    assertThat(program.getNamespaceForLanguage("cpp"), is("morimekta.providence"));
}
Also used : ConstProvider(net.morimekta.providence.reflect.util.ConstProvider) ProgramRegistry(net.morimekta.providence.reflect.util.ProgramRegistry) Test(org.junit.Test)

Aggregations

ProgramRegistry (net.morimekta.providence.reflect.util.ProgramRegistry)6 File (java.io.File)4 ProgramType (net.morimekta.providence.model.ProgramType)3 ThriftProgramParser (net.morimekta.providence.reflect.parser.ThriftProgramParser)3 ProgramConverter (net.morimekta.providence.reflect.util.ProgramConverter)3 Before (org.junit.Before)3 FileInputStream (java.io.FileInputStream)2 ArgumentException (net.morimekta.console.args.ArgumentException)2 PService (net.morimekta.providence.descriptor.PService)2 CProgram (net.morimekta.providence.reflect.contained.CProgram)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 TreeSet (java.util.TreeSet)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ArgumentParser (net.morimekta.console.args.ArgumentParser)1 STTY (net.morimekta.console.util.STTY)1 PServiceCall (net.morimekta.providence.PServiceCall)1 PDeclaredDescriptor (net.morimekta.providence.descriptor.PDeclaredDescriptor)1 MessageReader (net.morimekta.providence.mio.MessageReader)1 MessageWriter (net.morimekta.providence.mio.MessageWriter)1