Search in sources :

Example 26 with Group

use of com.linkedin.restli.examples.groups.api.Group in project rest.li by linkedin.

the class TestPatchGeneration method testDiffFromOverwrittenNested.

@Test
public void testDiffFromOverwrittenNested() throws Exception {
    Group g1 = new Group();
    Location loc1 = new Location();
    loc1.setLatitude(0.0f);
    loc1.setLongitude(0.0f);
    g1.setLocation(loc1);
    Group g2 = new Group(g1.data().copy());
    Location loc2 = new Location();
    loc2.setLatitude(42.0f);
    loc2.setLongitude(17.0f);
    g2.setLocation(loc2);
    PatchTree update = PatchCreator.diff(g1, g2);
    // "{location={$set={longitude=17.0, latitude=42.0}}}"
    final DataMap setMap = new DataMap();
    final DataMap longLatMap = new DataMap();
    longLatMap.put("longitude", 17.0f);
    longLatMap.put("latitude", 42.0f);
    setMap.put(PatchConstants.SET_COMMAND, longLatMap);
    final DataMap locationMap = new DataMap();
    locationMap.put("location", setMap);
    Assert.assertEquals(update.getDataMap(), locationMap, "PatchTree DataMap should be correct");
}
Also used : Group(com.linkedin.restli.examples.groups.api.Group) PatchTree(com.linkedin.data.transform.patch.request.PatchTree) Location(com.linkedin.restli.examples.groups.api.Location) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 27 with Group

use of com.linkedin.restli.examples.groups.api.Group in project rest.li by linkedin.

the class TestPatchGeneration method testRoundtripAddFields.

@Test
void testRoundtripAddFields() throws Exception {
    Group g1 = new Group();
    g1.setId(17);
    g1.setDescription("Some description");
    Group g2 = new Group(g1.data().copy());
    g2.setId(42);
    g2.setName("Some Group");
    PatchTree update = PatchCreator.diff(g1, g2);
    // "{$set={id=42, name=Some Group}}"
    final DataMap setMap = new DataMap();
    final DataMap idNameMap = new DataMap();
    idNameMap.put("id", 42);
    idNameMap.put("name", "Some Group");
    setMap.put(PatchConstants.SET_COMMAND, idNameMap);
    assertEquals(update.getDataMap(), setMap, "PatchTree DataMap should be correct");
    assertFalse(g1.equals(g2));
    DataComplexProcessor processor = new DataComplexProcessor(new Patch(), update.getDataMap(), g1.data());
    processor.run(false);
    assertEquals(g1, g2);
}
Also used : Group(com.linkedin.restli.examples.groups.api.Group) DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor) Patch(com.linkedin.data.transform.patch.Patch) PatchTree(com.linkedin.data.transform.patch.request.PatchTree) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 28 with Group

use of com.linkedin.restli.examples.groups.api.Group in project rest.li by linkedin.

the class TestGroupsRequestBuilders method testEntityUpdate.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestGroupsBuilderDataProviderEntity")
public void testEntityUpdate(RootBuilderWrapper<Integer, Group> builders, URIDetails expectedURIDetails) throws IOException, RestException {
    Request<EmptyRecord> request = builders.partialUpdate().id(1).input(new PatchRequest<>()).build();
    checkRequestBuilder(request, ResourceMethod.PARTIAL_UPDATE, EmptyResponseDecoder.class, expectedURIDetails, new Group());
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) Group(com.linkedin.restli.examples.groups.api.Group) PatchRequest(com.linkedin.restli.common.PatchRequest) Test(org.testng.annotations.Test)

Aggregations

Group (com.linkedin.restli.examples.groups.api.Group)28 Test (org.testng.annotations.Test)14 GroupsRequestBuilders (com.linkedin.restli.examples.groups.client.GroupsRequestBuilders)13 GroupsBuilders (com.linkedin.restli.examples.groups.client.GroupsBuilders)11 URIDetails (com.linkedin.restli.internal.testutils.URIDetails)10 DataProvider (org.testng.annotations.DataProvider)10 DataMap (com.linkedin.data.DataMap)9 PatchTree (com.linkedin.data.transform.patch.request.PatchTree)9 HashMap (java.util.HashMap)7 DataComplexProcessor (com.linkedin.data.transform.DataComplexProcessor)4 Patch (com.linkedin.data.transform.patch.Patch)4 EmptyRecord (com.linkedin.restli.common.EmptyRecord)4 Location (com.linkedin.restli.examples.groups.api.Location)3 DataList (com.linkedin.data.DataList)2 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)2 IdResponse (com.linkedin.restli.common.IdResponse)2 GroupMembershipParam (com.linkedin.restli.examples.groups.api.GroupMembershipParam)2 GroupMembershipsRequestBuilders (com.linkedin.restli.examples.groups.client.GroupMembershipsRequestBuilders)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2