@Test public void testTrimStartEndElements_missingMutateElements() { List<String> testData = Lists.newArrayList(); testData.add("<bar><foo></foo></bar>"); testData.add( "<ns1:operation xmlns:ns1=\"https: + "</ns1:operation>"); testData.add( "<operation xmlns=\"https: + "</operation>"); for (String requestXml : testData) { try { uploader.trimStartEndElements(requestXml, false, true); fail("Should have thrown an IllegalArgumentException for isLast and input: " + requestXml); } catch (IllegalArgumentException e) { assertTrue("Expected exception", true); } try { uploader.trimStartEndElements(requestXml, true, false); fail("Should have thrown an IllegalArgumentException for isFirst and input: " + requestXml); } catch (IllegalArgumentException e) { assertTrue("Expected exception", true); } } }
@VisibleForTesting String trimStartEndElements( String serializedRequest, boolean isFirstRequest, boolean isLastRequest) { int beginIndex = 0; int endIndex = serializedRequest.length(); if (!isFirstRequest) { beginIndex = serializedRequest.indexOf('>') + 1; Preconditions.checkArgument( serializedRequest.substring(0, beginIndex - 1).contains("mutate"), "Did not find an opening <mutate> element at the beginning of serialized request: %s", serializedRequest); } if (!isLastRequest) { endIndex = serializedRequest.lastIndexOf('<'); Preconditions.checkArgument(serializedRequest.substring(endIndex).contains("mutate"), "Did not find a closing </mutate> element at the end of serialized request: %s", serializedRequest); } return serializedRequest.substring(beginIndex, endIndex); }
BatchJobUploader { @VisibleForTesting String trimStartEndElements( String serializedRequest, boolean isFirstRequest, boolean isLastRequest) { int beginIndex = 0; int endIndex = serializedRequest.length(); if (!isFirstRequest) { beginIndex = serializedRequest.indexOf('>') + 1; Preconditions.checkArgument( serializedRequest.substring(0, beginIndex - 1).contains("mutate"), "Did not find an opening <mutate> element at the beginning of serialized request: %s", serializedRequest); } if (!isLastRequest) { endIndex = serializedRequest.lastIndexOf('<'); Preconditions.checkArgument(serializedRequest.substring(endIndex).contains("mutate"), "Did not find a closing </mutate> element at the end of serialized request: %s", serializedRequest); } return serializedRequest.substring(beginIndex, endIndex); } }
BatchJobUploader { @VisibleForTesting String trimStartEndElements( String serializedRequest, boolean isFirstRequest, boolean isLastRequest) { int beginIndex = 0; int endIndex = serializedRequest.length(); if (!isFirstRequest) { beginIndex = serializedRequest.indexOf('>') + 1; Preconditions.checkArgument( serializedRequest.substring(0, beginIndex - 1).contains("mutate"), "Did not find an opening <mutate> element at the beginning of serialized request: %s", serializedRequest); } if (!isLastRequest) { endIndex = serializedRequest.lastIndexOf('<'); Preconditions.checkArgument(serializedRequest.substring(endIndex).contains("mutate"), "Did not find a closing </mutate> element at the end of serialized request: %s", serializedRequest); } return serializedRequest.substring(beginIndex, endIndex); } @Inject  BatchJobUploader(
      AdWordsSession session, HttpTransport httpTransport, BatchJobLogger batchJobLogger); }
BatchJobUploader { @VisibleForTesting String trimStartEndElements( String serializedRequest, boolean isFirstRequest, boolean isLastRequest) { int beginIndex = 0; int endIndex = serializedRequest.length(); if (!isFirstRequest) { beginIndex = serializedRequest.indexOf('>') + 1; Preconditions.checkArgument( serializedRequest.substring(0, beginIndex - 1).contains("mutate"), "Did not find an opening <mutate> element at the beginning of serialized request: %s", serializedRequest); } if (!isLastRequest) { endIndex = serializedRequest.lastIndexOf('<'); Preconditions.checkArgument(serializedRequest.substring(endIndex).contains("mutate"), "Did not find a closing </mutate> element at the end of serialized request: %s", serializedRequest); } return serializedRequest.substring(beginIndex, endIndex); } @Inject  BatchJobUploader(
      AdWordsSession session, HttpTransport httpTransport, BatchJobLogger batchJobLogger); BatchJobUploadResponse uploadIncrementalBatchJobOperations(
      final BatchJobMutateRequestInterface request, final boolean isLastRequest,
      BatchJobUploadStatus batchJobUploadStatus); }
BatchJobUploader { @VisibleForTesting String trimStartEndElements( String serializedRequest, boolean isFirstRequest, boolean isLastRequest) { int beginIndex = 0; int endIndex = serializedRequest.length(); if (!isFirstRequest) { beginIndex = serializedRequest.indexOf('>') + 1; Preconditions.checkArgument( serializedRequest.substring(0, beginIndex - 1).contains("mutate"), "Did not find an opening <mutate> element at the beginning of serialized request: %s", serializedRequest); } if (!isLastRequest) { endIndex = serializedRequest.lastIndexOf('<'); Preconditions.checkArgument(serializedRequest.substring(endIndex).contains("mutate"), "Did not find a closing </mutate> element at the end of serialized request: %s", serializedRequest); } return serializedRequest.substring(beginIndex, endIndex); } @Inject  BatchJobUploader(
      AdWordsSession session, HttpTransport httpTransport, BatchJobLogger batchJobLogger); BatchJobUploadResponse uploadIncrementalBatchJobOperations(
      final BatchJobMutateRequestInterface request, final boolean isLastRequest,
      BatchJobUploadStatus batchJobUploadStatus);  }