diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/MockedOperationHandler.java |
Publish
Diffstat (limited to 'vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/MockedOperationHandler.java')
-rw-r--r-- | vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/MockedOperationHandler.java | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/MockedOperationHandler.java b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/MockedOperationHandler.java new file mode 100644 index 00000000000..ab5b36c74d1 --- /dev/null +++ b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/MockedOperationHandler.java @@ -0,0 +1,59 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.document.restapi.resource; + +import com.yahoo.document.restapi.OperationHandler; +import com.yahoo.document.restapi.Response; +import com.yahoo.document.restapi.RestApiException; +import com.yahoo.document.restapi.RestUri; +import com.yahoo.vespaxmlparser.VespaXMLFeedReader; + +import java.util.Optional; + +/** + * Mock that collects info about operation and returns them on second delete. + */ +public class MockedOperationHandler implements OperationHandler { + + StringBuilder log = new StringBuilder(); + int deleteCount = 0; + + @Override + public VisitResult visit(RestUri restUri, String documentSelection, Optional<String> cluster, Optional<String> continuation) throws RestApiException { + return new VisitResult(Optional.of("token"), "List of json docs, cont token " + continuation.map(a->a).orElse("not set") + ", doc selection: '" + + documentSelection + "'"); + } + + @Override + public void put(RestUri restUri, VespaXMLFeedReader.Operation data) throws RestApiException { + log.append("PUT: " + data.getDocument().getId()); + log.append(data.getDocument().getBody().toString()); + } + + @Override + public void update(RestUri restUri, VespaXMLFeedReader.Operation data) throws RestApiException { + log.append("UPDATE: " + data.getDocumentUpdate().getId()); + log.append(data.getDocumentUpdate().getFieldUpdates().toString()); + if (data.getDocumentUpdate().getCreateIfNonExistent()) { + log.append("[CREATE IF NON EXISTENT IS TRUE]"); + } + } + + @Override + public void delete(RestUri restUri, String condition) throws RestApiException { + deleteCount++; + if (deleteCount == 2) { + String theLog = log.toString(); + log = new StringBuilder(); + deleteCount = 0; + throw new RestApiException(Response.createErrorResponse(666, theLog)); + } + log.append("DELETE: " + restUri.generateFullId()); + } + + @Override + public Optional<String> get(RestUri restUri) throws RestApiException { + log.append("GET: " + restUri.generateFullId()); + return Optional.empty(); + } + +} |