本文整理汇总了Java中com.redhat.lightblue.util.JsonDoc.modify方法的典型用法代码示例。如果您正苦于以下问题:Java JsonDoc.modify方法的具体用法?Java JsonDoc.modify怎么用?Java JsonDoc.modify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.redhat.lightblue.util.JsonDoc
的用法示例。
在下文中一共展示了JsonDoc.modify方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldNotCreateNotificationsIfSomethingNotWatchedChanged
import com.redhat.lightblue.util.JsonDoc; //导入方法依赖的package包/类
@Test
public void shouldNotCreateNotificationsIfSomethingNotWatchedChanged() throws Exception {
EntityMetadata md = getMd("usermd.json");
JsonNode pre = loadJsonNode("userdata.json");
HookConfiguration cfg = new NotificationHookConfiguration(
projection("{'field':'personalInfo','recursive':1}"),
null,
false);
JsonNode post = loadJsonNode("userdata.json");
JsonDoc.modify(post, new Path("login"), JsonNodeFactory.instance.textNode("blah"), true);
List<HookDoc> docs= new ArrayList<>();
HookDoc doc = new HookDoc(md, new JsonDoc(pre), new JsonDoc(post), CRUDOperation.UPDATE, "me");
docs.add(doc);
hook.processHook(md,cfg,docs);
Assert.assertNull(insertCapturingMediator.capturedInsert);
}
示例2: shouldCaptureWatchedNonContainerNodeChangesInEntityData
import com.redhat.lightblue.util.JsonDoc; //导入方法依赖的package包/类
@Test
public void shouldCaptureWatchedNonContainerNodeChangesInEntityData() throws Exception {
EntityMetadata md = getMd("usermd.json");
JsonNode pre = loadJsonNode("userdata.json");
JsonNode post = loadJsonNode("userdata.json");
JsonDoc.modify(post, new Path("sites.0.streetAddress.city"), JsonNodeFactory.instance.textNode("blah"), true);
List<HookDoc> docs= new ArrayList<>();
HookDoc doc = new HookDoc(md, new JsonDoc(pre), new JsonDoc(post), CRUDOperation.UPDATE, "me");
docs.add(doc);
HookConfiguration cfg = new NotificationHookConfiguration(
projection("{'field':'sites','recursive':1}"),
projection("{'field':'sites','recursive':1}"),
false);
hook.processHook(md, cfg, docs);
Assert.assertNotNull(insertCapturingMediator.capturedInsert);
JsonNode data=insertCapturingMediator.capturedInsert.getEntityData();
Assert.assertEquals("sites.0.streetAddress.city",data.get("updatedPaths").get(0).asText());
Assert.assertEquals(1,data.get("updatedPaths").size());
}
示例3: shouldOnlyIncludeWhatChangedOfArrayElementIfElementIdentityNotWatched
import com.redhat.lightblue.util.JsonDoc; //导入方法依赖的package包/类
@Test
public void shouldOnlyIncludeWhatChangedOfArrayElementIfElementIdentityNotWatched()
throws Exception {
EntityMetadata md = getMd("usermd.json");
JsonNode pre = loadJsonNode("userdata.json");
JsonNode post = loadJsonNode("userdata.json");
JsonDoc.modify(post, new Path("sites.0.streetAddress.city"), JsonNodeFactory.instance.textNode("blah"), true);
List<HookDoc> docs= new ArrayList<>();
HookDoc doc = new HookDoc(md, new JsonDoc(pre), new JsonDoc(post), CRUDOperation.UPDATE, "me");
docs.add(doc);
HookConfiguration cfg = new NotificationHookConfiguration(
projection("{'field':'sites.*.streetAddress.city','recursive':1}"),
null,
false);
hook.processHook(md, cfg, docs);
Assert.assertNotNull(insertCapturingMediator.capturedInsert);
JsonNode data=insertCapturingMediator.capturedInsert.getEntityData();
Truth.assertThat(
Iterables.transform(data.get("updatedPaths"), toTextValue()))
.containsExactly("sites.0.streetAddress.city");
}
示例4: shouldCaptureWatchedArrayElementRemovalInRemovedEntityDataAndRemovedElements
import com.redhat.lightblue.util.JsonDoc; //导入方法依赖的package包/类
@Test
public void shouldCaptureWatchedArrayElementRemovalInRemovedEntityDataAndRemovedElements() throws Exception {
EntityMetadata md = getMd("usermd.json");
JsonNode pre = loadJsonNode("userdata.json");
JsonNode post = loadJsonNode("userdata.json");
JsonDoc.modify(post,new Path("sites.1"),null,true);
List<HookDoc> docs= new ArrayList<>();
HookDoc doc = new HookDoc(md, new JsonDoc(pre), new JsonDoc(post), CRUDOperation.UPDATE, "me");
docs.add(doc);
HookConfiguration cfg = new NotificationHookConfiguration(
projection("{'field':'sites','recursive':1}"),
projection("{'field':'sites','recursive':1}"),
false);
hook.processHook(md, cfg, docs);
JsonNode data=insertCapturingMediator.capturedInsert.getEntityData();
Assert.assertEquals(1,data.get("removedPaths").size());
Assert.assertEquals("sites.1",data.get("removedPaths").get(0).asText());
// Check we also have sites.1 contents
assertEntityDataValueEquals( (ArrayNode)data.get("removedEntityData"),"sites.1.siteId","2");
assertEntityDataValueEquals( (ArrayNode)data.get("removedEntityData"),"sites.1.siteType","billing");
}
示例5: shouldIncludeRemovedEntityDataForModifications
import com.redhat.lightblue.util.JsonDoc; //导入方法依赖的package包/类
@Test
public void shouldIncludeRemovedEntityDataForModifications() throws Exception {
EntityMetadata md = getMd("usermd.json");
JsonNode pre = loadJsonNode("userdata.json");
JsonNode post = loadJsonNode("userdata.json");
JsonDoc.modify(post, new Path("sites.0.streetAddress.city"),
JsonNodeFactory.instance.textNode("new city"), true);
List<HookDoc> docs= new ArrayList<>();
HookDoc doc = new HookDoc(md, new JsonDoc(pre), new JsonDoc(post), CRUDOperation.UPDATE, "me");
docs.add(doc);
HookConfiguration cfg = new NotificationHookConfiguration(
projection("{'field':'sites','recursive':1}"),
projection("{'field':'sites','recursive':1}"),
false);
hook.processHook(md, cfg, docs);
JsonNode data=insertCapturingMediator.capturedInsert.getEntityData();
Assert.assertEquals(0,data.get("removedPaths").size());
// Check we also have sites.1 contents
assertEntityDataValueEquals((ArrayNode) data.get("removedEntityData"),
"sites.0.streetAddress.city", "Denver");
}
示例6: shouldCaptureNullsAsNull
import com.redhat.lightblue.util.JsonDoc; //导入方法依赖的package包/类
@Test
public void shouldCaptureNullsAsNull() throws Exception {
EntityMetadata md = getMd("usermd.json");
JsonNode post = loadJsonNode("userdata.json");
JsonDoc.modify(post, new Path("personalInfo.company"),
JsonNodeFactory.instance.nullNode(), true);
List<HookDoc> docs= new ArrayList<>();
HookDoc doc = new HookDoc(md, null, new JsonDoc(post), CRUDOperation.INSERT, "me");
docs.add(doc);
HookConfiguration cfg = new NotificationHookConfiguration(
projection("{'field':'personalInfo','recursive':1}"),
projection("{'field':'personalInfo','recursive':1}"),
false);
hook.processHook(md, cfg, docs);
JsonNode data=insertCapturingMediator.capturedInsert.getEntityData();
// Check we also have sites.1 contents
assertEntityDataValueEquals((ArrayNode) data.get("entityData"), "personalInfo.company", null);
}
示例7: fieldfieldComparisonTest
import com.redhat.lightblue.util.JsonDoc; //导入方法依赖的package包/类
@Test
public void fieldfieldComparisonTest() throws Exception {
EntityMetadata md = getMd("./testMetadata5.json");
TestCRUDOperationContext ctx = new TestCRUDOperationContext(CRUDOperation.INSERT);
ctx.add(md);
JsonDoc doc = new JsonDoc(loadJsonNode("./testdata5.json"));
// This makes field1=field2
doc.modify(new Path("field2"),JsonNodeFactory.instance.textNode("f1"),false);
Projection projection = projection("{'field':'_id'}");
addDocument(ctx,doc);
CRUDInsertionResponse response = controller.insert(ctx, projection);
ctx = new TestCRUDOperationContext(CRUDOperation.FIND);
ctx.add(md);
controller.find(ctx, query("{'field':'field1','op':'=','rfield':'field2'}"),
projection("{'field':'*','recursive':1}"), null, null, null);
List<DocCtx> documents=streamToList(ctx);
Assert.assertEquals(1, documents.size());
}
示例8: insertTest_nullReqField
import com.redhat.lightblue.util.JsonDoc; //导入方法依赖的package包/类
@Test
public void insertTest_nullReqField() throws Exception {
EntityMetadata md = getMd("./testMetadata-requiredFields2.json");
TestCRUDOperationContext ctx = new TestCRUDOperationContext(CRUDOperation.INSERT);
ctx.add(md);
JsonDoc doc = new JsonDoc(loadJsonNode("./testdata1.json"));
doc.modify(new Path("field1"), null, false);
Projection projection = projection("{'field':'_id'}");
addDocument(ctx,doc);
CRUDInsertionResponse response = controller.insert(ctx, projection);
List<DocCtx> documents=streamToList(ctx);
System.out.println(getDataErrors(ctx));
Assert.assertEquals(1, documents.size());
Assert.assertTrue(ctx.getErrors() == null || ctx.getErrors().isEmpty());
Assert.assertTrue( getDataErrors(ctx).isEmpty());
Assert.assertEquals(ctx.getInputDocumentsWithoutErrors().size(), response.getNumInserted());
String id = documents.get(0).getOutputDocument().get(new Path("_id")).asText();
try (DBCursor c = coll.find(new BasicDBObject("_id", DocTranslator.createIdFrom(id)))) {
Assert.assertEquals(1, c.count());
}
}
示例9: objectTypeIsAlwaysProjected
import com.redhat.lightblue.util.JsonDoc; //导入方法依赖的package包/类
@Test
public void objectTypeIsAlwaysProjected() throws Exception {
EntityMetadata md = getMd("./testMetadata.json");
TestCRUDOperationContext ctx = new TestCRUDOperationContext(CRUDOperation.INSERT);
ctx.add(md);
// Generate some docs
List<JsonDoc> docs = new ArrayList<>();
int numDocs = 20;
for (int i = 0; i < numDocs; i++) {
JsonDoc doc = new JsonDoc(loadJsonNode("./testdata1.json"));
doc.modify(new Path("field1"), nodeFactory.textNode("doc" + i), false);
doc.modify(new Path("field3"), nodeFactory.numberNode(i), false);
docs.add(doc);
}
addDocuments(ctx,docs);
controller.insert(ctx, projection("{'field':'*','recursive':true}"));
ctx = new TestCRUDOperationContext(CRUDOperation.FIND);
ctx.add(md);
controller.find(ctx, query("{'field':'field3','op':'>=','rvalue':0}"),
projection("{'field':'field3'}"), null, null, null);
// The fact that there is no exceptions means objectType was included
}
示例10: findInqId
import com.redhat.lightblue.util.JsonDoc; //导入方法依赖的package包/类
@Test
public void findInqId() throws Exception {
EntityMetadata md = getMd("./testMetadata_idInt.json");
TestCRUDOperationContext ctx = new TestCRUDOperationContext(CRUDOperation.INSERT);
ctx.add(md);
// Generate some docs
List<JsonDoc> docs = new ArrayList<>();
int numDocs = 20;
for (int i = 0; i < numDocs; i++) {
JsonDoc doc = new JsonDoc(loadJsonNode("./testdata1.json"));
doc.modify(new Path("_id"), nodeFactory.textNode("" + i), false);
docs.add(doc);
}
addDocuments(ctx,docs);
controller.insert(ctx, projection("{'field':'_id'}"));
ctx = new TestCRUDOperationContext(CRUDOperation.FIND);
ctx.add(md);
controller.find(ctx, query("{'field':'_id','op':'$in','values':[1]}"),
projection("{'field':'*','recursive':1}"), null, null, null);
List<DocCtx> documents=streamToList(ctx);
Assert.assertEquals(1, documents.size());
}
示例11: updateTest_nullReqField
import com.redhat.lightblue.util.JsonDoc; //导入方法依赖的package包/类
@Test
public void updateTest_nullReqField() throws Exception {
EntityMetadata md = getMd("./testMetadata-requiredFields2.json");
TestCRUDOperationContext ctx = new TestCRUDOperationContext(CRUDOperation.INSERT);
ctx.add(md);
JsonDoc doc = new JsonDoc(loadJsonNode("./testdata1.json"));
doc.modify(new Path("field1"), JsonNodeFactory.instance.nullNode(), false);
Projection projection = projection("{'field':'_id'}");
addDocument(ctx,doc);
CRUDInsertionResponse response = controller.insert(ctx, projection);
ctx = new TestCRUDOperationContext(CRUDOperation.UPDATE);
ctx.add(md);
CRUDUpdateResponse upd = controller.update(ctx, query("{'field':'field2','op':'=','rvalue':'f2'}"),
update(" {'$set' : {'field3':3 }}"),
projection("{'field':'*','recursive':1}"));
Assert.assertEquals(0, upd.getNumUpdated());
Assert.assertEquals(1, upd.getNumFailed());
Assert.assertEquals(1, getDataErrors(ctx).size());
Assert.assertEquals(1, getDataErrors(ctx).get(0).getErrors().size());
Error error = getDataErrors(ctx).get(0).getErrors().get(0);
Assert.assertEquals("crud:Required", error.getErrorCode());
Assert.assertEquals("field1", error.getMsg());
}
示例12: shouldCreateNotificationWithIdsAndChangedWatchedFieldWhenNoIncludeProjectionProvided
import com.redhat.lightblue.util.JsonDoc; //导入方法依赖的package包/类
@Test
public void shouldCreateNotificationWithIdsAndChangedWatchedFieldWhenNoIncludeProjectionProvided() throws Exception {
EntityMetadata md=getMd("usermd.json");
JsonNode pre=loadJsonNode("userdata.json");
// Watch anything under "personalInfo"
// Only store id in notification
HookConfiguration cfg=new NotificationHookConfiguration(
projection("{'field':'personalInfo','recursive':1}"),
null,
false);
JsonNode post=loadJsonNode("userdata.json");
List<HookDoc> docs = new ArrayList<>();
JsonDoc.modify(post,new Path("personalInfo.company"),JsonNodeFactory.instance.textNode("blah"),true);
HookDoc doc=new HookDoc(md,new JsonDoc(pre),new JsonDoc(post),CRUDOperation.UPDATE,"me");
docs.add(doc);
hook.processHook(md,cfg,docs);
Assert.assertNotNull("Hook did not insert any notification", insertCapturingMediator.capturedInsert);
JsonNode notification= insertCapturingMediator.capturedInsert.getEntityData();
Assert.assertNotNull("Hook tried to insert a null notification", notification);
System.out.println(notification);
Assert.assertEquals("user",notification.get("entityName").asText());
Assert.assertEquals("5.0.0",notification.get("entityVersion").asText());
Assert.assertEquals("update", notification.get("operation").asText());
// The id fields must be there, and nothing else
ArrayNode ed=(ArrayNode)notification.get("entityData");
Assert.assertEquals(3,ed.size());
assertEntityDataValueEquals(ed,"_id","123");
assertEntityDataValueEquals(ed,"iduid","345");
assertEntityDataValueEquals(ed, "personalInfo.company", "blah");
}
示例13: shouldCaptureIncludeProjectionInEntityDataInAdditionToIds
import com.redhat.lightblue.util.JsonDoc; //导入方法依赖的package包/类
@Test
public void shouldCaptureIncludeProjectionInEntityDataInAdditionToIds() throws Exception {
EntityMetadata md=getMd("usermd.json");
JsonNode pre=loadJsonNode("userdata.json");
HookConfiguration cfg=new NotificationHookConfiguration(
projection("{'field':'personalInfo','recursive':1}"),
projection("[{'field':'login'},{'field':'sites.*.siteType'}]"),
false);
JsonNode post=loadJsonNode("userdata.json");
JsonDoc.modify(post,new Path("personalInfo.company"),JsonNodeFactory.instance.textNode("blah"),true);
List<HookDoc> docs=new ArrayList<>();
HookDoc doc=new HookDoc(md,new JsonDoc(pre),new JsonDoc(post),CRUDOperation.UPDATE,"me");
docs.add(doc);
hook.processHook(md,cfg,docs);
Assert.assertNotNull(insertCapturingMediator.capturedInsert);
// Doc is in the insertion req
JsonNode notification= insertCapturingMediator.capturedInsert.getEntityData();
Assert.assertNotNull(notification);
System.out.println(notification);
ArrayNode ed=(ArrayNode)notification.get("entityData");
Assert.assertEquals(6,ed.size());
assertEntityDataValueEquals(ed,"_id","123");
assertEntityDataValueEquals(ed,"iduid","345");
assertEntityDataValueEquals(ed,"login","bserdar");
assertEntityDataValueEquals(ed,"sites.0.siteType","shipping");
assertEntityDataValueEquals(ed,"sites.1.siteType","billing");
}
示例14: shouldFallBackToWatchingEverythingAndIncludingNothingIfNoConfigurationProvided
import com.redhat.lightblue.util.JsonDoc; //导入方法依赖的package包/类
@Test
public void shouldFallBackToWatchingEverythingAndIncludingNothingIfNoConfigurationProvided() throws Exception {
EntityMetadata md = getMd("usermd.json");
JsonNode pre = loadJsonNode("userdata.json");
JsonNode post = loadJsonNode("userdata.json");
JsonDoc.modify(post, new Path("login"), JsonNodeFactory.instance.textNode("blah"), true);
List<HookDoc> docs= new ArrayList<>();
HookDoc doc = new HookDoc(md, new JsonDoc(pre), new JsonDoc(post), CRUDOperation.UPDATE, "me");
docs.add(doc);
hook.processHook(md, /* config */ null, docs);
Assert.assertNotNull(insertCapturingMediator.capturedInsert);
}
示例15: updatePredefinedFields
import com.redhat.lightblue.util.JsonDoc; //导入方法依赖的package包/类
@Override
public void updatePredefinedFields(CRUDOperationContext ctx, JsonDoc doc) {
// If it is a save operation, we rely on _id being passed by client, so we don't auto-generate that
// If not, it needs to be auto-generated
if (ctx.getCRUDOperation() != CRUDOperation.SAVE) {
JsonNode idNode = doc.get(DocTranslator.ID_PATH);
if (idNode == null || idNode instanceof NullNode) {
doc.modify(DocTranslator.ID_PATH,
ctx.getFactory().getNodeFactory().textNode(ObjectId.get().toString()),
false);
}
}
}