Search in sources :

Example 6 with RuntimeMetadataImpl

use of org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl 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 7 with RuntimeMetadataImpl

use of org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl in project teiid by teiid.

the class TestWSTranslatorMetadata method testMetadata.

@Test
public void testMetadata() throws Exception {
    WSExecutionFactory ef = new WSExecutionFactory();
    Properties props = new Properties();
    WSConnection mockConnection = Mockito.mock(WSConnection.class);
    Mockito.stub(mockConnection.getWsdl()).toReturn(new File(UnitTestUtil.getTestDataPath() + "/xquotes.wsdl").toURI().toURL());
    Mockito.stub(mockConnection.getServiceQName()).toReturn(new QName("http://www.xignite.com/services/", "XigniteQuotes"));
    Mockito.stub(mockConnection.getPortQName()).toReturn(new QName("http://www.xignite.com/services/", "XigniteQuotesSoap"));
    MetadataFactory mf = new MetadataFactory("vdb", 1, "x", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
    ef.getMetadata(mf, mockConnection);
    assertEquals(36, mf.getSchema().getProcedures().size());
    TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "vdb");
    RuntimeMetadataImpl rm = new RuntimeMetadataImpl(tm);
    Dispatch<Object> mockDispatch = Mockito.mock(Dispatch.class);
    StAXSource source = Mockito.mock(StAXSource.class);
    Mockito.stub(mockDispatch.invoke(Mockito.any(DataSource.class))).toReturn(source);
    Mockito.stub(mockConnection.createDispatch(Mockito.any(Class.class), Mockito.any(Service.Mode.class))).toReturn(mockDispatch);
    CommandBuilder cb = new CommandBuilder(tm);
    Call call = (Call) cb.getCommand("call GetFundQuote('<foo/>')");
    WSWSDLProcedureExecution wpe = new WSWSDLProcedureExecution(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) QName(javax.xml.namespace.QName) 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) CommandBuilder(org.teiid.cdk.CommandBuilder) File(java.io.File) Test(org.junit.Test)

Example 8 with RuntimeMetadataImpl

use of org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl in project teiid by teiid.

the class TestWSTranslator method testHeaders.

@Test
public void testHeaders() 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);
    TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "vdb");
    RuntimeMetadataImpl rm = new RuntimeMetadataImpl(tm);
    Dispatch<Object> mockDispatch = mockDispatch();
    DataSource mock = Mockito.mock(DataSource.class);
    ByteArrayInputStream baos = new ByteArrayInputStream(new byte[100]);
    Mockito.stub(mock.getInputStream()).toReturn(baos);
    Mockito.stub(mockDispatch.invoke(Mockito.any(DataSource.class))).toReturn(mock);
    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, false, '{\"ContentType\":\"application/json\"}')");
    BinaryWSProcedureExecution pe = new BinaryWSProcedureExecution(call, rm, Mockito.mock(ExecutionContext.class), ef, mockConnection);
    pe.execute();
    Map<String, List<String>> headers = (Map<String, List<String>>) mockDispatch.getRequestContext().get(MessageContext.HTTP_REQUEST_HEADERS);
    assertEquals(Arrays.asList("application/json"), headers.get("ContentType"));
}
Also used : WSConnection(org.teiid.translator.WSConnection) Call(org.teiid.language.Call) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Properties(java.util.Properties) DataSource(javax.activation.DataSource) ExecutionContext(org.teiid.translator.ExecutionContext) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) RuntimeMetadataImpl(org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl) Procedure(org.teiid.metadata.Procedure) List(java.util.List) CommandBuilder(org.teiid.cdk.CommandBuilder) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test)

Example 9 with RuntimeMetadataImpl

use of org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl in project teiid by teiid.

the class TestWSTranslatorMetadata method testHttpMetadata.

@Ignore
@Test
public void testHttpMetadata() throws Exception {
    WSExecutionFactory ef = new WSExecutionFactory();
    Properties props = new Properties();
    props.setProperty("importer.servicename", "XigniteQuotes");
    props.setProperty("importer.portname", "XigniteQuotesHttpGet");
    WSConnection mockConnection = Mockito.mock(WSConnection.class);
    Mockito.stub(mockConnection.getWsdl()).toReturn(new File(UnitTestUtil.getTestDataPath() + "/xquotes.wsdl").toURI().toURL());
    MetadataFactory mf = new MetadataFactory("vdb", 1, "x", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
    ef.getMetadata(mf, mockConnection);
    assertEquals(34, mf.getSchema().getProcedures().size());
    TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "vdb");
    RuntimeMetadataImpl rm = new RuntimeMetadataImpl(tm);
    Dispatch<Object> mockDispatch = Mockito.mock(Dispatch.class);
    Mockito.stub(mockDispatch.invoke(Mockito.any(DataSource.class))).toReturn(Mockito.mock(StAXSource.class));
    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 GetFundQuote('<foo/>')");
    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) 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) CommandBuilder(org.teiid.cdk.CommandBuilder) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with RuntimeMetadataImpl

use of org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl in project teiid by teiid.

the class TestIckleConversionVisitor method helpUpdate.

private void helpUpdate(MetadataFactory mf, String query, String expected) throws Exception {
    InfinispanExecutionFactory ef = new InfinispanExecutionFactory();
    TransformationMetadata metadata = TestProtobufMetadataProcessor.getTransformationMetadata(mf, ef);
    TranslationUtility utility = new TranslationUtility(metadata);
    Command cmd = utility.parseCommand(query);
    InfinispanUpdateVisitor visitor = new InfinispanUpdateVisitor(new RuntimeMetadataImpl(metadata));
    visitor.append(cmd);
    String actual = null;
    if (cmd instanceof Update) {
        actual = visitor.getUpdateQuery();
    } else {
        actual = visitor.getDeleteQuery();
    }
    assertEquals(expected, actual);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Command(org.teiid.language.Command) RuntimeMetadataImpl(org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl) TranslationUtility(org.teiid.cdk.api.TranslationUtility) Update(org.teiid.language.Update)

Aggregations

RuntimeMetadataImpl (org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl)11 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)11 MetadataFactory (org.teiid.metadata.MetadataFactory)8 Test (org.junit.Test)7 ExecutionContext (org.teiid.translator.ExecutionContext)7 CommandBuilder (org.teiid.cdk.CommandBuilder)6 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)6 Properties (java.util.Properties)5 DataSource (javax.activation.DataSource)5 Call (org.teiid.language.Call)5 WSConnection (org.teiid.translator.WSConnection)5 TranslationUtility (org.teiid.cdk.api.TranslationUtility)4 StAXSource (javax.xml.transform.stax.StAXSource)3 Procedure (org.teiid.metadata.Procedure)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 Command (org.teiid.language.Command)2 Select (org.teiid.language.Select)2 Blob (java.sql.Blob)1 Connection (java.sql.Connection)1