本文整理汇总了Java中com.redhat.lightblue.util.JsonUtils.json方法的典型用法代码示例。如果您正苦于以下问题:Java JsonUtils.json方法的具体用法?Java JsonUtils.json怎么用?Java JsonUtils.json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.redhat.lightblue.util.JsonUtils
的用法示例。
在下文中一共展示了JsonUtils.json方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConvert
import com.redhat.lightblue.util.JsonUtils; //导入方法依赖的package包/类
@Test
public void testConvert() throws IOException{
String databaseName = "fakeDatabase";
String datasourceName = "fakeDatasource";
MetadataParser<JsonNode> p = new JSONMetadataParser(
new Extensions<JsonNode>(),
new DefaultTypes(),
new JsonNodeFactory(true));
JsonNode emptyNode = JsonUtils.json("{}");
RDBMSDataStore ds = new RDBMSDataStore(databaseName, datasourceName);
new RDBMSDataStoreParser<JsonNode>().convert(p, emptyNode, ds);
assertEquals(databaseName, p.getStringProperty(emptyNode, "database"));
assertEquals(datasourceName, p.getStringProperty(emptyNode, "datasource"));
}
示例2: testFileURL
import com.redhat.lightblue.util.JsonUtils; //导入方法依赖的package包/类
@Test
public void testFileURL() throws Exception {
URL dirUrl = getClass().getResource(
"/externalResourcesConfiguration");
PluginConfiguration config = new PluginConfiguration(JsonUtils.json(
"[\"file:///" + dirUrl.getPath() + "\"]"));
Set<URL> urls = config.getPluginUrls();
assertNotNull(urls);
assertEquals(2, urls.size());
//Clunky, but guarantees the order.
List<URL> sortedUrls = new ArrayList<URL>(urls);
Collections.sort(sortedUrls, new Comparator<URL>() {
@Override
public int compare(URL o1, URL o2) {
return o1.getPath().compareTo(o2.getPath());
}
});
assertUrlEquals(sortedUrls.get(0), "not_really_a_jar.jar", "file");
assertUrlEquals(sortedUrls.get(1), "also_not_really_a_jar.jar", "file");
}
示例3: testConvert_WithNullValues
import com.redhat.lightblue.util.JsonUtils; //导入方法依赖的package包/类
@Test
public void testConvert_WithNullValues() throws IOException{
MetadataParser<JsonNode> p = new JSONMetadataParser(
new Extensions<JsonNode>(),
new DefaultTypes(),
new JsonNodeFactory(true));
JsonNode emptyNode = JsonUtils.json("{}");
RDBMSDataStore ds = new RDBMSDataStore(null, null);
new RDBMSDataStoreParser<JsonNode>().convert(p, emptyNode, ds);
assertNull(p.getStringProperty(emptyNode, "database"));
assertNull(p.getStringProperty(emptyNode, "datasource"));
}
示例4: testParse_EmptyDialect
import com.redhat.lightblue.util.JsonUtils; //导入方法依赖的package包/类
@Test
public void testParse_EmptyDialect() throws IOException{
expectedEx.expect(com.redhat.lightblue.util.Error.class);
expectedEx.expectMessage("{\"objectType\":\"error\",\"errorCode\":\""
+ RDBMSConstants.ERR_FIELD_REQUIRED
+ "\",\"msg\":\"No field informed\"}");
MetadataParser<JsonNode> p = new JSONMetadataParser(
new Extensions<JsonNode>(),
new DefaultTypes(),
new JsonNodeFactory(true));
JsonNode emptyNode = JsonUtils.json("{\"dialect\":\"\"}");
new RDBMSPropertyParserImpl<JsonNode>().parse(RDBMSPropertyParserImpl.NAME, p, emptyNode);
}
示例5: readPreference
import com.redhat.lightblue.util.JsonUtils; //导入方法依赖的package包/类
@Test
public void readPreference() throws IOException {
try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("parse-test-datasources.json")) {
JsonNode node = JsonUtils.json(is);
MongoConfiguration metadataConfig = new MongoConfiguration();
metadataConfig.initializeFromJson(node.get("metadata_readPreference"));
MongoConfiguration dataConfig = new MongoConfiguration();
dataConfig.initializeFromJson(node.get("mongodata_readPreference"));
assertEquals(ReadPreference.nearest(), metadataConfig.getMongoClientOptions().getReadPreference());
assertEquals(ReadPreference.secondary(), dataConfig.getMongoClientOptions().getReadPreference());
assertEquals(WriteConcern.SAFE, metadataConfig.getWriteConcern());
}
}
示例6: testParse
import com.redhat.lightblue.util.JsonUtils; //导入方法依赖的package包/类
@Test
public void testParse() throws IOException{
String databaseName = "fakeDatabase";
String datasourceName = "fakeDatasource";
MetadataParser<JsonNode> p = new JSONMetadataParser(
new Extensions<JsonNode>(),
new DefaultTypes(),
new JsonNodeFactory(true));
JsonNode node = JsonUtils.json("{\"database\":\"" + databaseName + "\",\"datasource\":\"" + datasourceName + "\"}");
RDBMSDataStore ds = new RDBMSDataStoreParser<JsonNode>().parse(RDBMSDataStoreParser.NAME, p, node);
assertNotNull(ds);
assertEquals(databaseName, ds.getDatabaseName());
assertEquals(datasourceName, ds.getDatasourceName());
}
示例7: readLdapConfiguration
import com.redhat.lightblue.util.JsonUtils; //导入方法依赖的package包/类
private static JsonNode readLdapConfiguration() throws IOException {
JsonNode root = null;
try (InputStream is = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(LdapConfiguration.FILENAME)) {
if (null == is) {
throw new FileNotFoundException(LdapConfiguration.FILENAME);
}
root = JsonUtils.json(is, true);
}
return root;
}
示例8: runSavedSearch
import com.redhat.lightblue.util.JsonUtils; //导入方法依赖的package包/类
@POST
@LZF
@Path("/search/{entity}/{version}/{searchName}")
public Response runSavedSearch(@PathParam("entity") String entity,
@PathParam("version") String version,
@PathParam("searchName") String searchName,
@QueryParam("P") String projection,
@QueryParam("S") String sort,
@QueryParam("from") Integer from,
@QueryParam("to") Integer to,
@QueryParam("maxResults") Integer maxResults,
String body) {
Map<String,String> map=new HashMap<>();
try {
JsonNode node=JsonUtils.json(body);
if(node instanceof ObjectNode) {
for(Iterator<Map.Entry<String,JsonNode>> itr=node.fields();itr.hasNext();) {
Map.Entry<String,JsonNode> entry=itr.next();
map.put(entry.getKey(),entry.getValue() instanceof NullNode?null:entry.getValue().asText());
}
}
} catch (Exception e) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
return runSavedSearch(entity,version,searchName,projection,sort,from,to,maxResults,map);
}
示例9: testConvert_NullObject
import com.redhat.lightblue.util.JsonUtils; //导入方法依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void testConvert_NullObject() throws IOException{
MetadataParser<JsonNode> p = new JSONMetadataParser(
new Extensions<JsonNode>(),
new DefaultTypes(),
new JsonNodeFactory(true));
JsonNode emptyNode = JsonUtils.json("{}");
new RDBMSPropertyParserImpl<JsonNode>().convert(p, emptyNode, null);
}
示例10: loadDefaultDatasources
import com.redhat.lightblue.util.JsonUtils; //导入方法依赖的package包/类
private static DataSourcesConfiguration loadDefaultDatasources() {
try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(DATASOURCE_FILENAME)) {
if (null == is) {
throw new FileNotFoundException(DATASOURCE_FILENAME);
}
return new DataSourcesConfiguration(JsonUtils.json(is, true));
} catch (Exception e) {
throw new RuntimeException("Cannot initialize datasources.", e);
}
}
示例11: testHttpURL
import com.redhat.lightblue.util.JsonUtils; //导入方法依赖的package包/类
@Test
public void testHttpURL() throws Exception {
PluginConfiguration config = new PluginConfiguration(JsonUtils.json(
"[\"http://www.somesite.com/my.jar\"]"));
Set<URL> urls = config.getPluginUrls();
assertNotNull(urls);
assertEquals(1, urls.size());
assertUrlEquals(urls.iterator().next(), "my.jar", "http");
}
示例12: toJson
import com.redhat.lightblue.util.JsonUtils; //导入方法依赖的package包/类
private static JsonNode toJson(String object) {
try {
return JsonUtils.json(object);
} catch (Exception e) {
throw Error.get(MetadataConstants.ERR_ILL_FORMED_METADATA, object);
}
}
示例13: testRDBMSDataSourceConfiguration
import com.redhat.lightblue.util.JsonUtils; //导入方法依赖的package包/类
@Test
public void testRDBMSDataSourceConfiguration() throws Exception {
// Create initial context
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory");
System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");
// already tried System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.as.naming.InitialContextFactory");
InitialContext ic = new InitialContext();
ic.createSubcontext("java:");
ic.createSubcontext("java:/comp");
ic.createSubcontext("java:/comp/env");
ic.createSubcontext("java:/comp/env/jdbc");
JdbcConnectionPool ds = JdbcConnectionPool.create("jdbc:h2:file:/tmp/test.db;FILE_LOCK=NO;MVCC=TRUE;DB_CLOSE_ON_EXIT=TRUE", "sa", "sasasa");
ic.bind("java:/mydatasource", ds);
JsonNode json = JsonUtils.json(FileUtil.readFile("rdbms-datasources.json"));
JsonNode rdbmsNode = json.get("rdbms");
cut.initializeFromJson(rdbmsNode);
assertEquals("org.h2.jdbcx.JdbcConnectionPool",cut.getDataSource("datasource").getClass().getCanonicalName());
assertEquals("datasource",cut.getDataSourceName().get(0));
assertEquals("rdbms",cut.getDatabaseName());
cut.setDatabaseName("db");
assertEquals("db", cut.getDatabaseName());
cut.setMetadataDataStoreParser(RDBMSDataStoreParser.class);
assertEquals("com.redhat.lightblue.metadata.rdbms.impl.RDBMSDataStoreParser",cut.getMetadataDataStoreParser().getCanonicalName());
}
示例14: testParse_DistinctTrue
import com.redhat.lightblue.util.JsonUtils; //导入方法依赖的package包/类
@Test
public void testParse_DistinctTrue() throws IOException{
MetadataParser<JsonNode> p = new JSONMetadataParser(
new Extensions<JsonNode>(),
new DefaultTypes(),
new JsonNodeFactory(true));
JsonNode node = JsonUtils.json("{\"tables\":[{\"name\":\"tname\"}],\"needDistinct\":true,\"projectionMappings\":[{\"column\":\"c\",\"field\":\"f\"}]}");
Join join = new Join();
join.parse(p, node);
assertTrue(join.isNeedDistinct());
}
示例15: writeConcern_deprecated
import com.redhat.lightblue.util.JsonUtils; //导入方法依赖的package包/类
@Test
public void writeConcern_deprecated() throws IOException {
try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("parse-test-datasources.json")) {
JsonNode node = JsonUtils.json(is);
MongoConfiguration dataConfig = new MongoConfiguration();
dataConfig.initializeFromJson(node.get("mongodata_writeConcern_deprecated"));
assertEquals(WriteConcern.SAFE, dataConfig.getWriteConcern());
}
}