@Test public void testTrimStartEndElements_notFirst_isLast() { List<List<String>> testData = Lists.newArrayList(); testData.add(Lists.newArrayList("<mutate><foo></foo></mutate>", "<foo></foo></mutate>")); testData.add(Lists.newArrayList( "<ns1:mutate xmlns:ns1=\"https: + "</ns1:mutate>", "<foo></foo></ns1:mutate>")); testData.add(Lists.newArrayList("<mutate></mutate>", "</mutate>")); for (List<String> testPair : testData) { String requestXml = testPair.get(0); String postProcessed = uploader.trimStartEndElements(requestXml, false, true); assertEquals("Trimmed result should exclude starting mutate if !isFirst and isLast", testPair.get(1), postProcessed); } }
@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);  }