Java tutorial
/* Copyright 2013 Red Hat, Inc. and/or its affiliates. This file is part of lightblue. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.redhat.lightblue.eval; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.redhat.lightblue.metadata.EntityMetadata; import com.redhat.lightblue.metadata.PredefinedFields; import com.redhat.lightblue.metadata.TypeResolver; import com.redhat.lightblue.metadata.parser.Extensions; import com.redhat.lightblue.metadata.parser.JSONMetadataParser; import com.redhat.lightblue.metadata.types.DefaultTypes; import com.redhat.lightblue.query.Projection; import com.redhat.lightblue.query.QueryExpression; import com.redhat.lightblue.query.UpdateExpression; import com.redhat.lightblue.util.JsonDoc; import com.redhat.lightblue.util.JsonUtils; import com.redhat.lightblue.util.test.AbstractJsonNodeTest; import com.redhat.lightblue.TestDataStoreParser; public class EvalTestContext extends AbstractJsonNodeTest { EvalTestContext context; private static final JsonNodeFactory factory = JsonNodeFactory.withExactBigDecimals(true); public static JsonDoc getDoc(String fname) throws Exception { JsonNode node = loadJsonNode(fname); return new JsonDoc(node); } public static EntityMetadata getMd(String fname) throws Exception { JsonNode node = loadJsonNode(fname); Extensions<JsonNode> extensions = new Extensions<>(); extensions.addDefaultExtensions(); extensions.registerDataStoreParser("mongo", new TestDataStoreParser<JsonNode>()); TypeResolver resolver = new DefaultTypes(); JSONMetadataParser parser = new JSONMetadataParser(extensions, resolver, factory); EntityMetadata md = parser.parseEntityMetadata(node); PredefinedFields.ensurePredefinedFields(md); return md; } public static QueryExpression queryExpressionFromJson(String s) throws Exception { return QueryExpression.fromJson(JsonUtils.json(s.replace('\'', '\"'))); } public static UpdateExpression updateExpressionFromJson(String s) throws Exception { return UpdateExpression.fromJson(JsonUtils.json(s.replace('\'', '\"'))); } public static Projection projectionFromJson(String s) throws Exception { return Projection.fromJson(JsonUtils.json(s.replace('\'', '\"'))); } private EvalTestContext() { } }