Search in sources :

Example 31 with Procedure

use of org.teiid.metadata.Procedure in project teiid by teiid.

the class TestWSTranslator method testPre81Procedure.

@Test
public void testPre81Procedure() throws Exception {
    WSExecutionFactory ef = new WSExecutionFactory();
    WSConnection mockConnection = Mockito.mock(WSConnection.class);
    MetadataFactory mf = new MetadataFactory("vdb", 1, "x", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    ef.getMetadata(mf, mockConnection);
    Procedure p = mf.getSchema().getProcedure(WSExecutionFactory.INVOKE_HTTP);
    assertEquals(7, p.getParameters().size());
    p.getParameters().remove(4);
    p.getParameters().remove(5);
    // designer treated the result as an out parameter
    p.getParameters().get(0).setType(Type.Out);
    p.getParameters().add(3, p.getParameters().remove(0));
    for (int i = 0; i < p.getParameters().size(); i++) {
        p.getParameters().get(i).setPosition(i + 1);
    }
    p = mf.getSchema().getProcedure("invoke");
    assertEquals(6, p.getParameters().size());
    p.getParameters().remove(5);
    // designer treated the result as an out parameter
    p.getParameters().get(0).setType(Type.Out);
    p.getParameters().add(p.getParameters().remove(0));
    for (int i = 0; i < p.getParameters().size(); i++) {
        p.getParameters().get(i).setPosition(i + 1);
    }
    TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "vdb");
    RuntimeMetadataImpl rm = new RuntimeMetadataImpl(tm);
    Dispatch<Object> mockDispatch = mockDispatch();
    DataSource source = Mockito.mock(DataSource.class);
    Mockito.stub(mockDispatch.invoke(Mockito.any(DataSource.class))).toReturn(source);
    Mockito.stub(mockConnection.createDispatch(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(Class.class), Mockito.any(Service.Mode.class))).toReturn(mockDispatch);
    CommandBuilder cb = new CommandBuilder(tm);
    Call call = (Call) cb.getCommand("call invokeHttp('GET', null, null)");
    BinaryWSProcedureExecution pe = new BinaryWSProcedureExecution(call, rm, Mockito.mock(ExecutionContext.class), ef, mockConnection);
    pe.execute();
    pe.getOutputParameterValues();
    mockConnection = Mockito.mock(WSConnection.class);
    mockDispatch = Mockito.mock(Dispatch.class);
    StAXSource ssource = Mockito.mock(StAXSource.class);
    Mockito.stub(mockDispatch.invoke(Mockito.any(StAXSource.class))).toReturn(ssource);
    Mockito.stub(mockConnection.createDispatch(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(Class.class), Mockito.any(Service.Mode.class))).toReturn(mockDispatch);
    call = (Call) cb.getCommand("call invoke()");
    WSProcedureExecution wpe = new WSProcedureExecution(call, rm, Mockito.mock(ExecutionContext.class), ef, mockConnection);
    wpe.execute();
    wpe.getOutputParameterValues();
}
Also used : WSConnection(org.teiid.translator.WSConnection) Call(org.teiid.language.Call) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Dispatch(javax.xml.ws.Dispatch) StAXSource(javax.xml.transform.stax.StAXSource) Properties(java.util.Properties) DataSource(javax.activation.DataSource) ExecutionContext(org.teiid.translator.ExecutionContext) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) RuntimeMetadataImpl(org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl) Procedure(org.teiid.metadata.Procedure) CommandBuilder(org.teiid.cdk.CommandBuilder) Test(org.junit.Test)

Example 32 with Procedure

use of org.teiid.metadata.Procedure in project teiid by teiid.

the class TestSwaggerMetadataProcessor method testRefParameter.

@Test
public void testRefParameter() throws Exception {
    SwaggerExecutionFactory translator = new SwaggerExecutionFactory();
    translator.start();
    MetadataFactory mf = getMetadata(translator, UnitTestUtil.getTestDataPath() + "/redis-swagger.json");
    Procedure p = mf.getSchema().getProcedure("Operations_List");
    assertNotNull(p);
    assertEquals("GET", p.getProperty(RestMetadataExtension.METHOD, false).toUpperCase());
    assertEquals("https://management.azure.comnull/providers/Microsoft.Cache/operations", p.getProperty(RestMetadataExtension.URI, false));
    assertNotNull(p.getResultSet());
    assertNotNull(p.getParameterByName("api-version"));
}
Also used : RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Procedure(org.teiid.metadata.Procedure) Test(org.junit.Test)

Example 33 with Procedure

use of org.teiid.metadata.Procedure in project teiid by teiid.

the class TestSwaggerMetadataProcessor method testEndpointAsName.

@Test
public void testEndpointAsName() throws Exception {
    SwaggerExecutionFactory translator = new SwaggerExecutionFactory();
    translator.start();
    MetadataFactory mf = getMetadata(translator, UnitTestUtil.getTestDataPath() + "/fahrplan-swagger.json");
    Procedure p = mf.getSchema().getProcedure("arrivalBoard/id");
    assertNotNull(p);
    assertEquals("GET", p.getProperty(RestMetadataExtension.METHOD, false).toUpperCase());
    assertEquals("http://api.deutschebahn.com/freeplan/v1/arrivalBoard/{id}", p.getProperty(RestMetadataExtension.URI, false));
    assertNotNull(p.getResultSet());
}
Also used : RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Procedure(org.teiid.metadata.Procedure) Test(org.junit.Test)

Example 34 with Procedure

use of org.teiid.metadata.Procedure in project teiid by teiid.

the class TestSwaggerMetadataProcessor method testReftoResponse.

@Test
public void testReftoResponse() throws TranslatorException {
    SwaggerExecutionFactory translator = new SwaggerExecutionFactory();
    translator.start();
    MetadataFactory mf = petstoreMetadata(translator);
    Procedure p = mf.getSchema().getProcedure("findPetsByTags");
    assertNotNull(p);
    assertEquals("GET", p.getProperty(RestMetadataExtension.METHOD, false).toUpperCase());
    assertEquals("http://petstore.swagger.io/v2/pet/findByTags", p.getProperty(RestMetadataExtension.URI, false));
    assertNotNull(p.getResultSet());
    List<Column> columns = p.getResultSet().getColumns();
    assertEquals(8, columns.size());
    Column pa = p.getResultSet().getColumnByName("id");
    assertNull(pa.getNameInSource());
    pa = p.getResultSet().getColumnByName("category_id");
    assertEquals("category/id", pa.getNameInSource());
    pa = p.getResultSet().getColumnByName("tags_Tag_id");
    assertEquals("tags[]/Tag/id", pa.getNameInSource());
}
Also used : RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Column(org.teiid.metadata.Column) Procedure(org.teiid.metadata.Procedure) Test(org.junit.Test)

Example 35 with Procedure

use of org.teiid.metadata.Procedure in project teiid by teiid.

the class TestSwaggerMetadataProcessor method testSchema.

@Test
public void testSchema() throws Exception {
    SwaggerExecutionFactory translator = new SwaggerExecutionFactory();
    translator.start();
    MetadataFactory mf = swaggerMetadata(translator);
    // TransformationMetadata metadata = getTransformationMetadata(mf, translator);
    String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
    // System.out.println(ddl);
    MetadataFactory mf2 = new MetadataFactory("vdb", 1, "x", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    QueryParser.getQueryParser().parseDDL(mf2, ddl);
    Set<String> procSet = new HashSet<String>();
    for (Procedure p : mf.getSchema().getProcedures().values()) {
        procSet.add(p.getName());
    }
    assertEquals(29, procSet.size());
    assertTrue(procSet.contains("addCustomer"));
    assertTrue(procSet.contains("addOneCustomer"));
    assertTrue(procSet.contains("addCustomerList"));
    assertTrue(procSet.contains("getCustomers"));
    assertTrue(procSet.contains("getCustomerList"));
    assertTrue(procSet.contains("getCustomerByCity"));
    assertTrue(procSet.contains("getCustomerByCountry"));
    assertTrue(procSet.contains("getCustomerByName"));
    assertTrue(procSet.contains("getCustomerByNumber"));
    assertTrue(procSet.contains("getByNumCityCountry"));
    assertTrue(procSet.contains("size"));
    assertTrue(procSet.contains("removeCustomer"));
    assertTrue(procSet.contains("removeCustomerByCity"));
    assertTrue(procSet.contains("removeCustomerByCountry"));
    assertTrue(procSet.contains("removeCustomerByName"));
    assertTrue(procSet.contains("removeCustomerByNumber"));
    assertTrue(procSet.contains("removeCustomerByNumCityCountry"));
    assertTrue(procSet.contains("updateCustomer"));
    assertTrue(procSet.contains("updateCustomerByCity"));
    assertTrue(procSet.contains("updateCustomerByCountry"));
    assertTrue(procSet.contains("updateCustomerByName"));
    assertTrue(procSet.contains("updateCustomerByNumber"));
    assertTrue(procSet.contains("updateCustomerByNumCityCountry"));
    // test preferences
    Procedure p = mf.getSchema().getProcedures().get("updateCustomer");
    assertEquals("application/json", p.getProperty(RestMetadataExtension.PRODUCES, false));
}
Also used : RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) Procedure(org.teiid.metadata.Procedure) Properties(java.util.Properties) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Procedure (org.teiid.metadata.Procedure)82 ProcedureParameter (org.teiid.metadata.ProcedureParameter)36 Test (org.junit.Test)35 MetadataFactory (org.teiid.metadata.MetadataFactory)30 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)27 Schema (org.teiid.metadata.Schema)16 Column (org.teiid.metadata.Column)14 MetadataStore (org.teiid.metadata.MetadataStore)11 Properties (java.util.Properties)10 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)10 Table (org.teiid.metadata.Table)9 QueryNode (org.teiid.query.mapping.relational.QueryNode)8 List (java.util.List)6 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)6 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)5 TranslatorException (org.teiid.translator.TranslatorException)5 ODataType (org.teiid.translator.odata4.ODataMetadataProcessor.ODataType)5 ArrayList (java.util.ArrayList)4 Call (org.teiid.language.Call)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3