Search in sources :

Example 1 with ValidatorReport

use of org.teiid.query.validator.ValidatorReport in project teiid by teiid.

the class TestAuthorizationValidationVisitor method helpTest.

private void helpTest(String sql, QueryMetadataInterface metadata, String[] expectedInaccesible, VDBMetaData vdb, DataPolicyMetadata... roles) throws QueryParserException, QueryResolverException, TeiidComponentException {
    QueryParser parser = QueryParser.getQueryParser();
    Command command = parser.parseCommand(sql);
    QueryResolver.resolveCommand(command, metadata);
    DataRolePolicyDecider dataRolePolicyDecider = createPolicyDecider(metadata, vdb, roles);
    // $NON-NLS-1$
    AuthorizationValidationVisitor visitor = new AuthorizationValidationVisitor(dataRolePolicyDecider, context);
    ValidatorReport report = Validator.validate(command, metadata, visitor);
    if (report.hasItems()) {
        ValidatorFailure firstFailure = report.getItems().iterator().next();
        // strings
        Set<String> expected = new HashSet<String>(Arrays.asList(expectedInaccesible));
        // elements
        Set<String> actual = new HashSet<String>();
        for (LanguageObject obj : firstFailure.getInvalidObjects()) {
            if (obj instanceof ElementSymbol) {
                actual.add(((ElementSymbol) obj).getName());
            } else {
                actual.add(obj.toString());
            }
        }
        assertEquals(expected, actual);
    } else if (expectedInaccesible.length > 0) {
        // $NON-NLS-1$
        fail("Expected inaccessible objects, but got none.");
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) QueryParser(org.teiid.query.parser.QueryParser) Command(org.teiid.query.sql.lang.Command) ValidatorFailure(org.teiid.query.validator.ValidatorFailure) ValidatorReport(org.teiid.query.validator.ValidatorReport) LanguageObject(org.teiid.query.sql.LanguageObject) HashSet(java.util.HashSet)

Example 2 with ValidatorReport

use of org.teiid.query.validator.ValidatorReport in project teiid by teiid.

the class TestMongoDBQueryExecution method setUp.

@Before
public void setUp() throws Exception {
    this.translator = new MongoDBExecutionFactory();
    this.translator.setDatabaseVersion("2.6");
    this.translator.start();
    MetadataFactory mf = TestDDLParser.helpParse(ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.ddl")), "northwind");
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "sakila", new FunctionTree("mongo", new UDFSource(translator.getPushDownFunctions())));
    ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
    if (report.hasItems()) {
        throw new RuntimeException(report.getFailureMessage());
    }
    this.utility = new TranslationUtility(metadata);
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) TranslationUtility(org.teiid.cdk.api.TranslationUtility) MetadataValidator(org.teiid.query.metadata.MetadataValidator) ValidatorReport(org.teiid.query.validator.ValidatorReport) Before(org.junit.Before)

Example 3 with ValidatorReport

use of org.teiid.query.validator.ValidatorReport in project teiid by teiid.

the class TestDataEntitySchemaBuilder method getNorthwindMetadataFromODataXML.

static TransformationMetadata getNorthwindMetadataFromODataXML() throws Exception {
    ModelMetaData model = new ModelMetaData();
    model.setName("nw");
    model.setModelType(Type.PHYSICAL);
    MetadataFactory mf = new MetadataFactory("northwind", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), model);
    EdmDataServices edm = new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new FileReader(UnitTestUtil.getTestDataFile("northwind.xml"))));
    ODataMetadataProcessor metadataProcessor = new ODataMetadataProcessor();
    // $NON-NLS-1$
    PropertiesUtils.setBeanProperties(metadataProcessor, mf.getModelProperties(), "importer");
    metadataProcessor.getMetadata(mf, edm);
    String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
    TransformationMetadata metadata = RealMetadataFactory.fromDDL(ddl, "northwind", "nw");
    ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
    if (report.hasItems()) {
        throw new RuntimeException(report.getFailureMessage());
    }
    return metadata;
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) EdmxFormatParser(org.odata4j.format.xml.EdmxFormatParser) FileReader(java.io.FileReader) MetadataValidator(org.teiid.query.metadata.MetadataValidator) ValidatorReport(org.teiid.query.validator.ValidatorReport) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 4 with ValidatorReport

use of org.teiid.query.validator.ValidatorReport in project teiid by teiid.

the class TestODataMetadataProcessor method testSchema.

@Test
public void testSchema() throws Exception {
    translator = new ODataExecutionFactory();
    translator.start();
    String csdl = ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.xml"));
    ODataMetadataProcessor processor = new ODataMetadataProcessor();
    Properties props = new Properties();
    props.setProperty("schemaNamespace", "ODataWeb.Northwind.Model");
    props.setProperty("entityContainer", "NorthwindEntities");
    MetadataFactory mf = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
    processor.getMetadata(mf, new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new InputStreamReader(new ByteArrayInputStream(csdl.getBytes())))));
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "northwind", new FunctionTree("foo", new UDFSource(translator.getPushDownFunctions())));
    ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
    if (report.hasItems()) {
        throw new RuntimeException(report.getFailureMessage());
    }
    String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
    // System.out.println(ddl);
    MetadataFactory mf2 = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    QueryParser.getQueryParser().parseDDL(mf2, ddl);
    Procedure p = mf.getSchema().getProcedure("executeVoid");
    assertNotNull(p);
    assertEquals(1, p.getParameters().size());
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) InputStreamReader(java.io.InputStreamReader) EdmxFormatParser(org.odata4j.format.xml.EdmxFormatParser) Properties(java.util.Properties) ValidatorReport(org.teiid.query.validator.ValidatorReport) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) Procedure(org.teiid.metadata.Procedure) MetadataValidator(org.teiid.query.metadata.MetadataValidator) Test(org.junit.Test)

Example 5 with ValidatorReport

use of org.teiid.query.validator.ValidatorReport in project teiid by teiid.

the class TestODataSQLVistor method setUp.

@Before
public void setUp() throws Exception {
    translator = new ODataExecutionFactory();
    translator.start();
    String csdl = ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.xml"));
    EdmDataServices eds = new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new InputStreamReader(new ByteArrayInputStream(csdl.getBytes()))));
    ODataMetadataProcessor processor = new ODataMetadataProcessor();
    Properties props = new Properties();
    props.setProperty("schemaNamespace", "ODataWeb.Northwind.Model");
    props.setProperty("entityContainer", "NorthwindEntities");
    MetadataFactory mf = new MetadataFactory("vdb", 1, "nw", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
    processor.getMetadata(mf, eds);
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "northwind", new FunctionTree("foo", new UDFSource(translator.getPushDownFunctions())));
    ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
    if (report.hasItems()) {
        throw new RuntimeException(report.getFailureMessage());
    }
    // TransformationMetadata metadata = RealMetadataFactory.fromDDL(ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("northwind.ddl")), "northwind", "nw");
    utility = new TranslationUtility(metadata);
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) InputStreamReader(java.io.InputStreamReader) TranslationUtility(org.teiid.cdk.api.TranslationUtility) EdmxFormatParser(org.odata4j.format.xml.EdmxFormatParser) Properties(java.util.Properties) ValidatorReport(org.teiid.query.validator.ValidatorReport) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) EdmDataServices(org.odata4j.edm.EdmDataServices) MetadataValidator(org.teiid.query.metadata.MetadataValidator) Before(org.junit.Before)

Aggregations

ValidatorReport (org.teiid.query.validator.ValidatorReport)70 Test (org.junit.Test)40 MetadataValidator (org.teiid.query.metadata.MetadataValidator)20 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)16 MetadataFactory (org.teiid.metadata.MetadataFactory)13 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)12 UDFSource (org.teiid.query.function.UDFSource)11 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)10 FunctionTree (org.teiid.query.function.FunctionTree)10 Command (org.teiid.query.sql.lang.Command)8 ValidatorFailure (org.teiid.query.validator.ValidatorFailure)6 QueryParser (org.teiid.query.parser.QueryParser)5 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)5 FileReader (java.io.FileReader)4 Properties (java.util.Properties)4 EdmxFormatParser (org.odata4j.format.xml.EdmxFormatParser)4 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)4 TranslationUtility (org.teiid.cdk.api.TranslationUtility)4 MetadataException (org.teiid.metadata.MetadataException)4 Table (org.teiid.metadata.Table)4