Search in sources :

Example 21 with Group

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

the class TestPatchGeneration method testRoundtripModifyEscapedField.

@Test(groups = { TestConstants.TESTNG_GROUP_KNOWN_ISSUE })
void testRoundtripModifyEscapedField() throws Exception {
    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);
    // "{$$foo={$set={bar=42}}}"
    final DataMap setMap = new DataMap();
    final DataMap barMap = new DataMap();
    barMap.put("bar", 42);
    setMap.put(PatchConstants.SET_COMMAND, barMap);
    final DataMap fooMap = new DataMap();
    fooMap.put("$$foo", setMap);
    assertEquals(update.getDataMap(), fooMap, "PatchTree DataMap must 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 22 with Group

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

the class TestPatchGeneration method testRoundtripAddEscapedField.

@Test
void testRoundtripAddEscapedField() throws Exception {
    Group g1 = new Group();
    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);
    // "{$set={$foo=value}}"
    final DataMap setMap = new DataMap();
    final DataMap fooMap = new DataMap();
    fooMap.put("$foo", "value");
    setMap.put(PatchConstants.SET_COMMAND, fooMap);
    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 23 with Group

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

the class TestPatchGeneration method testDiffRemove.

@Test
void testDiffRemove() throws Exception {
    Group g1 = new Group();
    g1.setId(17);
    g1.setDescription("Some description");
    Group g2 = new Group(g1.data().copy());
    g2.removeDescription();
    PatchTree update = PatchCreator.diff(g1, g2);
    // "{$delete=[description]}"
    final DataMap deleteMap = new DataMap();
    final DataList descriptionList = new DataList();
    descriptionList.add("description");
    deleteMap.put(PatchConstants.DELETE_COMMAND, descriptionList);
    assertEquals(update.getDataMap(), deleteMap, "PatchTree DataMap should be correct");
}
Also used : Group(com.linkedin.restli.examples.groups.api.Group) DataList(com.linkedin.data.DataList) PatchTree(com.linkedin.data.transform.patch.request.PatchTree) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 24 with Group

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

the class TestPatchGeneration method testDiffFromNull.

@Test
public void testDiffFromNull() throws Exception {
    Group g1 = new Group();
    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 internalSetMap = new DataMap();
    internalSetMap.put("id", 42);
    internalSetMap.put("name", "Some Group");
    final DataMap setMap = new DataMap();
    setMap.put(PatchConstants.SET_COMMAND, internalSetMap);
    assertEquals(update.getDataMap(), setMap, "PatchTree DataMap should be correct");
}
Also used : Group(com.linkedin.restli.examples.groups.api.Group) PatchTree(com.linkedin.data.transform.patch.request.PatchTree) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 25 with Group

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

the class TestPatchGeneration method testDiffFromNonNull.

@Test
void testDiffFromNonNull() 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 internalSetMap = new DataMap();
    internalSetMap.put("id", 42);
    internalSetMap.put("name", "Some Group");
    final DataMap setMap = new DataMap();
    setMap.put(PatchConstants.SET_COMMAND, internalSetMap);
    assertEquals(update.getDataMap(), setMap, "PatchTree DataMap should be correct");
}
Also used : Group(com.linkedin.restli.examples.groups.api.Group) PatchTree(com.linkedin.data.transform.patch.request.PatchTree) DataMap(com.linkedin.data.DataMap) 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