Package com.linkedin.data.transform.patch.request

Examples of com.linkedin.data.transform.patch.request.PatchTree


    g1.setId(17);
    g1.setDescription("Some description");

    Group g2 = new Group(g1.data().copy());
    g2.data().put("$foo", "value");
    PatchTree update = PatchCreator.diff(g1, g2);
    assertEquals(update.toString(), "{$set={$foo=value}}");
    assertFalse(g1.equals(g2));

    DataComplexProcessor processor = new DataComplexProcessor(new Patch(), update.getDataMap(), g1.data());
    processor.run(false);

    assertEquals(g1, g2);
  }
View Full Code Here


    Group g1 = new Group();
    g1.data().put("$foo", new DataMap());

    Group g2 = new Group(g1.data().copy());
    ((DataMap)g2.data().get("$foo")).put("bar", 42);
    PatchTree update = PatchCreator.diff(g1, g2);
    assertEquals(update.toString(), "{$$foo={$set={bar=42}}}");
    assertFalse(g1.equals(g2));

    DataComplexProcessor processor = new DataComplexProcessor(new Patch(), update.getDataMap(), g1.data());
    processor.run(false);

    assertEquals(g1, g2);
  }
View Full Code Here

                         buildPathKeys("statusID", 1L));

    // #2: Collection Partial Update
    methodDescriptor = statusResourceModel.findMethod(ResourceMethod.PARTIAL_UPDATE);
    statusResource = getMockResource(AsyncStatusCollectionResource.class);
    PatchTree p = new PatchTree();
    p.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(Integer.valueOf(42)));
    PatchRequest<Status> expected = PatchRequest.createFromPatchDocument(p.getDataMap());
    statusResource.update(eq(1L), eq(expected), EasyMock.<Callback<UpdateResponse>> anyObject());
    EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
      @Override
      public Object answer() throws Throwable {
        @SuppressWarnings("unchecked")
        Callback<UpdateResponse> callback = (Callback<UpdateResponse>) EasyMock.getCurrentArguments()[2];
        callback.onSuccess(null);
        return null;
      }
    });
    EasyMock.replay(statusResource);
    checkAsyncInvocation(statusResource,
                         callback,
                         methodDescriptor,
                         "POST",
                         version,
                         "/asyncstatuses/1",
                         "{\"patch\":{\"$set\":{\"foo\":42}}}",
                         buildPathKeys("statusID", 1L));

    // #3: Simple Resource Partial Update
    methodDescriptor = locationResourceModel.findMethod(ResourceMethod.PARTIAL_UPDATE);
    locationResource = getMockResource(AsyncLocationResource.class);
    p = new PatchTree();
    p.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(Integer.valueOf(51)));
    PatchRequest<Location> expectedLocation = PatchRequest.createFromPatchDocument(p.getDataMap());
    locationResource.update(eq(expectedLocation), EasyMock.<Callback<UpdateResponse>> anyObject());
    EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
      @Override
      public Object answer() throws Throwable {
        @SuppressWarnings("unchecked")
        Callback<UpdateResponse> callback = (Callback<UpdateResponse>) EasyMock.getCurrentArguments()[1];
        callback.onSuccess(null);
        return null;
      }
    });
    EasyMock.replay(locationResource);
    checkAsyncInvocation(locationResource,
                         callback,
                         methodDescriptor,
                         "POST",
                         version,
                         "/asyncstatuses/1/asynclocation",
                         "{\"patch\":{\"$set\":{\"foo\":51}}}",
                         buildPathKeys("statusID", 1L));

    // #4 Complex-key resource create
    methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.CREATE);
    discoveredItemsResource = getMockResource(AsyncDiscoveredItemsResource.class);
    discoveredItemsResource.create((DiscoveredItem)EasyMock.anyObject(),
                                   EasyMock.<Callback<CreateResponse>>anyObject());
    EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
      @Override
      public Object answer() throws Throwable {
        @SuppressWarnings("unchecked")
        Callback<CreateResponse> callback = (Callback<CreateResponse>) EasyMock.getCurrentArguments()[1];
        callback.onSuccess(null);
        return null;
      }
    });

    EasyMock.replay(discoveredItemsResource);
    checkAsyncInvocation(discoveredItemsResource,
                         callback,
                         methodDescriptor,
                         "POST",
                         version,
                         "/asyncdiscovereditems",
                         "{}",
                         null);

    // #5 Partial update on complex-key resource
    methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.PARTIAL_UPDATE);
    discoveredItemsResource = getMockResource(AsyncDiscoveredItemsResource.class);
    p = new PatchTree();
    p.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(Integer.valueOf(43)));
    PatchRequest<DiscoveredItem> expectedDiscoveredItem =
        PatchRequest.createFromPatchDocument(p.getDataMap());
    ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> key =
        getDiscoveredItemComplexKey(1L, 2, 3L);

    discoveredItemsResource.update(eq(key), eq(expectedDiscoveredItem), EasyMock.<Callback<UpdateResponse>>anyObject());
    EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
View Full Code Here

    }

    // #2: Collection Partial Update
    methodDescriptor = statusResourceModel.findMethod(ResourceMethod.PARTIAL_UPDATE);
    statusResource = getMockResource(PromiseStatusCollectionResource.class);
    PatchTree p = new PatchTree();
    p.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(Integer.valueOf(42)));
    PatchRequest<Status> expected = PatchRequest.createFromPatchDocument(p.getDataMap());
    EasyMock.expect(statusResource.update(eq(1L), eq(expected))).andReturn(Promises.<UpdateResponse>value(null)).once();
    checkInvocation(statusResource,
                    methodDescriptor,
                    "POST",
                    version,
                    "/promisestatuses/1",
                    "{\"patch\":{\"$set\":{\"foo\":42}}}",
                    buildPathKeys("statusID", 1L));

    // #3: Simple Resource Partial Update

    methodDescriptor = locationResourceModel.findMethod(ResourceMethod.PARTIAL_UPDATE);
    locationResource = getMockResource(PromiseLocationResource.class);
    p = new PatchTree();
    p.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(Integer.valueOf(51)));
    PatchRequest<Location> expectedLocation = PatchRequest.createFromPatchDocument(p.getDataMap());
    EasyMock.expect(locationResource.update(eq(expectedLocation))).andReturn(Promises.<UpdateResponse>value(null)).once();
    checkInvocation(locationResource,
                    methodDescriptor,
                    "POST",
                    version,
                    "/promisestatuses/1/promiselocation",
                    "{\"patch\":{\"$set\":{\"foo\":51}}}",
                    buildPathKeys("statusID", 1L));

    // #4 Complex key resource create
    methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.CREATE);
    discoveredItemsResource = getMockResource(PromiseDiscoveredItemsResource.class);
    EasyMock.expect(
        discoveredItemsResource.create(
            (DiscoveredItem)EasyMock.anyObject())).andReturn(Promises.<CreateResponse>value(null)).once();
    checkInvocation(discoveredItemsResource,
                    methodDescriptor,
                    "POST",
                    version,
                    "/promisediscovereditems",
                    "{}");

    // #5 Complex key resource partial update
    methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.PARTIAL_UPDATE);
    discoveredItemsResource = getMockResource(PromiseDiscoveredItemsResource.class);
    p = new PatchTree();
    p.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(Integer.valueOf(43)));
    PatchRequest<DiscoveredItem> expectedDiscoveredItem =
        PatchRequest.createFromPatchDocument(p.getDataMap());
    ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> key =
        getDiscoveredItemComplexKey(1L, 2, 3L);
    EasyMock.expect(
        discoveredItemsResource.update(eq(key), eq(expectedDiscoveredItem))).andReturn(
          Promises.<UpdateResponse>value(null)).once();
View Full Code Here

    }

    // #2 Collection Partial Update
    methodDescriptor = statusResourceModel.findMethod(ResourceMethod.PARTIAL_UPDATE);
    statusResource = getMockResource(StatusCollectionResource.class);
    PatchTree p = new PatchTree();
    p.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(Integer.valueOf(42)));
    PatchRequest<Status> expected = PatchRequest.createFromPatchDocument(p.getDataMap());
    EasyMock.expect(statusResource.update(eq(1L), eq(expected))).andReturn(null).once();
    checkInvocation(statusResource,
                    methodDescriptor,
                    "POST",
                    version,
                    "/statuses/1",
                    "{\"patch\":{\"$set\":{\"foo\":42}}}",
                    buildPathKeys("statusID", 1L));

    // #3 Simple Resource Partial Update

    methodDescriptor = locationResourceModel.findMethod(ResourceMethod.PARTIAL_UPDATE);
    locationResource = getMockResource(LocationResource.class);
    p = new PatchTree();
    p.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(Integer.valueOf(51)));
    PatchRequest<Location> expectedLocation = PatchRequest.createFromPatchDocument(p.getDataMap());
    EasyMock.expect(locationResource.update(eq(expectedLocation))).andReturn(null).once();
    checkInvocation(locationResource,
                    methodDescriptor,
                    "POST",
                    version, "/statuses/1/location",
                    "{\"patch\":{\"$set\":{\"foo\":51}}}",
                    buildPathKeys("statusID", 1L));

    // #4 Complex-key resource create
    methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.CREATE);
    discoveredItemsResource = getMockResource(DiscoveredItemsResource.class);
    EasyMock.expect(
        discoveredItemsResource.create((DiscoveredItem)EasyMock.anyObject())).andReturn(null).once();
    checkInvocation(discoveredItemsResource,
                    methodDescriptor,
                    "POST",
                    version,
                    "/discovereditems",
                    "{}");

    // #5 Partial update on complex-key resource
    methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.PARTIAL_UPDATE);
    discoveredItemsResource = getMockResource(DiscoveredItemsResource.class);
    p = new PatchTree();
    p.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(Integer.valueOf(43)));
    PatchRequest<DiscoveredItem> expectedDiscoveredItem =
        PatchRequest.createFromPatchDocument(p.getDataMap());
    ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> key =
        getDiscoveredItemComplexKey(1L, 2, 3L);
    EasyMock.expect(
        discoveredItemsResource.update(eq(key), eq(expectedDiscoveredItem))).andReturn(null).once();
    checkInvocation(discoveredItemsResource,
View Full Code Here

  public void testCustomCrudParamsCollectionPartialUpdate(ProtocolVersion version, String uri, String body) throws Exception
  {
    ResourceModel model = buildResourceModel(CombinedResources.CollectionWithCustomCrudParams.class);
    ResourceMethodDescriptor methodDescriptor = model.findMethod(ResourceMethod.PARTIAL_UPDATE);
    CombinedResources.CollectionWithCustomCrudParams resource = getMockResource(CombinedResources.CollectionWithCustomCrudParams.class);
    PatchTree p = new PatchTree();
    p.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(Integer.valueOf(42)));
    PatchRequest<CombinedTestDataModels.Foo> expected = PatchRequest.createFromPatchDocument(p.getDataMap());
    EasyMock.expect(resource.myUpdate(eq("foo"), eq(expected), eq(1), eq("bar"))).andReturn(null).once();
    checkInvocation(resource, methodDescriptor, "POST", version, uri, body, buildPathKeys("testId", "foo"));
  }
View Full Code Here

  public void testCustomCrudParamsSimplePartialUpdate(ProtocolVersion version, String uri) throws Exception
  {
    ResourceModel model = buildResourceModel(CombinedResources.SimpleResourceWithCustomCrudParams.class);
    ResourceMethodDescriptor methodDescriptor = model.findMethod(ResourceMethod.PARTIAL_UPDATE);
    CombinedResources.SimpleResourceWithCustomCrudParams resource = getMockResource(CombinedResources.SimpleResourceWithCustomCrudParams.class);
    PatchTree p = new PatchTree();
    p.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(Integer.valueOf(51)));
    PatchRequest<CombinedTestDataModels.Foo> expected = PatchRequest.createFromPatchDocument(p.getDataMap());
    EasyMock.expect(resource.myPartialUpdate(eq(expected), eq(1), eq("bar"))).andReturn(null).once();
    checkInvocation(resource, methodDescriptor, "POST", version, uri,"{\"patch\":{\"$set\":{\"foo\":51}}}", buildBatchPathKeys());
  }
View Full Code Here

    PatchTreeTestModel testModel = pc.getRecordingProxy();

    testModel.setFooOptional(null, SetMode.REMOVE_IF_NULL);

    // Augment the patch request with the removes
    PatchTree ptExpect = new PatchTree();
    ptExpect.addOperation(PatchTreeTestModel.fields().fooOptional(), new RemoveFieldOp());

    Assert.assertEquals(pc.generatePatchTree().getDataMap(), ptExpect.getDataMap());
  }
View Full Code Here

    PatchTreeRecorder<PatchTreeTestModel> pc = makeOne();
    PatchTreeTestModel restCommonTestModel = pc.getRecordingProxy();

    restCommonTestModel.setFooOptional(null, SetMode.REMOVE_OPTIONAL_IF_NULL);
    // Augment the patch request with the removes
    PatchTree ptExpect = new PatchTree();
    ptExpect.addOperation(PatchTreeTestModel.fields().fooOptional(), new RemoveFieldOp());

    Assert.assertEquals(pc.generatePatchTree().getDataMap(),
                        ptExpect.getDataMap());
  }
View Full Code Here

    PatchTreeTestModel.FooUnion fooUnion = new PatchTreeTestModel.FooUnion();
    fooUnion.setInt(10);
    testModel.setFooRequired(100).setFooUnion(fooUnion).setFooRecordTemplate(null, SetMode.REMOVE_IF_NULL).removeFooOptional();

    PatchTree ptExpect = PatchCreator.diff(new DataMap(),
                                           new PatchTreeTestModel().setFooRequired(100).setFooUnion(fooUnion).data());
    // Augment the patch request with the removes
    ptExpect.addOperation(PatchTreeTestModel.fields().fooRecordTemplate(), new RemoveFieldOp());
    ptExpect.addOperation(PatchTreeTestModel.fields().fooOptional(), new RemoveFieldOp());

    Assert.assertEquals(pc.generatePatchTree().getDataMap(), ptExpect.getDataMap());
  }
View Full Code Here

TOP

Related Classes of com.linkedin.data.transform.patch.request.PatchTree

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.