ParseRESTCommand extends ParseRequest<JSONObject> { public void resolveLocalIds() { try { ArrayList<JSONObject> localPointers = new ArrayList<>(); getLocalPointersIn(jsonParameters, localPointers); for (JSONObject pointer : localPointers) { String localId = (String) pointer.get("localId"); String objectId = getLocalIdManager().getObjectId(localId); if (objectId == null) { throw new IllegalStateException( "Tried to serialize a command referencing a new, unsaved object."); } pointer.put("objectId", objectId); pointer.remove("localId"); } maybeChangeServerOperation(); } catch (JSONException e) { } } ParseRESTCommand(
            String httpPath,
            ParseHttpRequest.Method httpMethod,
            Map<String, ?> parameters,
            String sessionToken);  ParseRESTCommand(
            String httpPath,
            ParseHttpRequest.Method httpMethod,
            JSONObject jsonParameters,
            String sessionToken); private  ParseRESTCommand(
            String httpPath,
            ParseHttpRequest.Method httpMethod,
            JSONObject jsonParameters,
            String localId, String sessionToken);   ParseRESTCommand(Init<?> builder); static ParseRESTCommand fromJSONObject(JSONObject jsonObject); @Override Task<JSONObject> executeAsync(
            final ParseHttpClient client,
            final ProgressCallback uploadProgressCallback,
            final ProgressCallback downloadProgressCallback,
            final Task<Void> cancellationToken); String getCacheKey(); JSONObject toJSONObject(); String getSessionToken(); String getOperationSetUUID(); String getLocalId(); void setLocalId(String localId); void resolveLocalIds(); void retainLocalIds(); void releaseLocalIds(); public String masterKey; }
@Test public void testResolveLocalIdsWithNoObjectId() { LocalIdManager localIdManager = mock(LocalIdManager.class); when(localIdManager.createLocalId()).thenReturn("localIdAgain"); ParseCorePlugins.getInstance().registerLocalIdManager(localIdManager); ParseObject object = new ParseObject("Test"); object.put("key", "value"); String httpPath = "www.parse.com"; JSONObject jsonParameters = PointerOrLocalIdEncoder.get().encodeRelatedObject(object); String sessionToken = "sessionToken"; String localId = "localId"; ParseRESTCommand command = new ParseRESTCommand.Builder() .httpPath(httpPath) .jsonParameters(jsonParameters) .method(ParseHttpRequest.Method.POST) .sessionToken(sessionToken) .localId(localId) .build(); thrown.expect(IllegalStateException.class); thrown.expectMessage("Tried to serialize a command referencing a new, unsaved object."); command.resolveLocalIds(); verify(localIdManager, times(1)).getObjectId("localIdAgain"); }
@Test public void testResolveLocalIds() throws Exception { LocalIdManager localIdManager = mock(LocalIdManager.class); when(localIdManager.createLocalId()).thenReturn("localIdAgain"); when(localIdManager.getObjectId("localIdAgain")).thenReturn("objectIdAgain"); when(localIdManager.getObjectId("localId")).thenReturn("objectId"); ParseCorePlugins.getInstance().registerLocalIdManager(localIdManager); ParseObject object = new ParseObject("Test"); object.put("key", "value"); String httpPath = "classes"; JSONObject jsonParameters = PointerOrLocalIdEncoder.get().encodeRelatedObject(object); String sessionToken = "sessionToken"; String localId = "localId"; ParseRESTCommand command = new ParseRESTCommand.Builder() .httpPath(httpPath) .jsonParameters(jsonParameters) .method(ParseHttpRequest.Method.POST) .sessionToken(sessionToken) .localId(localId) .build(); command.resolveLocalIds(); verify(localIdManager, times(1)).getObjectId("localIdAgain"); verify(localIdManager, times(1)).getObjectId("localId"); assertFalse(jsonParameters.has("localId")); assertEquals("objectIdAgain", jsonParameters.getString("objectId")); assertNull(command.getLocalId()); assertEquals(ParseHttpRequest.Method.PUT, command.method); assertTrue(command.httpPath.contains("objectId")); }