diff --git a/.gitignore b/.gitignore index 6731271b7d8..25751278147 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,8 @@ service-account.json # intellij .idea/ *.iml + +# Eclipse files +.project +.classpath +.settings diff --git a/appengine/search/.gitignore b/appengine/search/.gitignore deleted file mode 100644 index 471339729ae..00000000000 --- a/appengine/search/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -# Eclipse files -.project -.classpath -.settings - -# Target folders -target/ diff --git a/appengine/search/google-checks.xml b/appengine/search/google-checks.xml deleted file mode 100644 index 730c9148710..00000000000 --- a/appengine/search/google-checks.xml +++ /dev/null @@ -1,223 +0,0 @@ -<?xml version="1.0"?> -<!DOCTYPE module PUBLIC - "-//Puppy Crawl//DTD Check Configuration 1.3//EN" - "http://www.puppycrawl.com/dtds/configuration_1_3.dtd"> -<!-- - Copyright 2016 Google Inc. All Rights Reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> - -<!-- - Checkstyle configuration that checks the Google coding conventions from: - - - Google Java Style - https://google-styleguide.googlecode.com/svn-history/r130/trunk/javaguide.html - - Checkstyle is very configurable. Be sure to read the documentation at - http://checkstyle.sf.net (or in your downloaded distribution). - Most Checks are configurable, be sure to consult the documentation. - To completely disable a check, just comment it out or delete it from the file. - Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov. - --> -<module name = "Checker"> - <property name="charset" value="UTF-8"/> - - <property name="severity" value="error"/> - - <property name="fileExtensions" value="java, properties, xml"/> - <!-- Checks for whitespace --> - <!-- See http://checkstyle.sf.net/config_whitespace.html --> - <module name="FileTabCharacter"> - <property name="eachLine" value="true"/> - </module> - - <module name="TreeWalker"> - <!-- Make @SuppressWarnings available to checkstyle http://stackoverflow.com/a/22556386/101923 --> - <module name="SuppressWarningsHolder" /> - <module name="UnusedImports"/> - <module name="OuterTypeFilename"/> - <module name="IllegalTokenText"> - <property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/> - <property name="format" value="\\u00(08|09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/> - <property name="message" value="Avoid using corresponding octal or Unicode escape."/> - </module> - <module name="AvoidEscapedUnicodeCharacters"> - <property name="allowEscapesForControlCharacters" value="true"/> - <property name="allowByTailComment" value="true"/> - <property name="allowNonPrintableEscapes" value="true"/> - </module> - <module name="LineLength"> - <property name="max" value="100"/> - <property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/> - </module> - <module name="AvoidStarImport"/> - <module name="OneTopLevelClass"/> - <module name="NoLineWrap"/> - <module name="EmptyBlock"> - <property name="option" value="TEXT"/> - <property name="tokens" value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/> - </module> - <module name="NeedBraces"/> - <module name="LeftCurly"> - <property name="maxLineLength" value="100"/> - </module> - <module name="RightCurly"/> - <module name="RightCurly"> - <property name="option" value="alone"/> - <property name="tokens" value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO, STATIC_INIT, INSTANCE_INIT"/> - </module> - <module name="WhitespaceAround"> - <property name="allowEmptyConstructors" value="true"/> - <property name="allowEmptyMethods" value="true"/> - <property name="allowEmptyTypes" value="true"/> - <property name="allowEmptyLoops" value="true"/> - <message key="ws.notFollowed" - value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/> - <message key="ws.notPreceded" - value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/> - </module> - <module name="OneStatementPerLine"/> - <module name="MultipleVariableDeclarations"/> - <module name="ArrayTypeStyle"/> - <module name="MissingSwitchDefault"/> - <module name="FallThrough"/> - <module name="UpperEll"/> - <module name="ModifierOrder"/> - <module name="EmptyLineSeparator"> - <property name="allowNoEmptyLineBetweenFields" value="true"/> - <property name="tokens" value="CLASS_DEF, ENUM_DEF, INTERFACE_DEF, CTOR_DEF, METHOD_DEF, STATIC_INIT, INSTANCE_INIT, VARIABLE_DEF" /> - </module> - <module name="SeparatorWrap"> - <property name="tokens" value="DOT"/> - <property name="option" value="nl"/> - </module> - <module name="SeparatorWrap"> - <property name="tokens" value="COMMA"/> - <property name="option" value="EOL"/> - </module> - <module name="PackageName"> - <property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/> - <message key="name.invalidPattern" - value="Package name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="TypeName"> - <message key="name.invalidPattern" - value="Type name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="MemberName"> - <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/> - <message key="name.invalidPattern" - value="Member name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="ParameterName"> - <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/> - <message key="name.invalidPattern" - value="Parameter name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="LocalVariableName"> - <property name="tokens" value="VARIABLE_DEF"/> - <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/> - <property name="allowOneCharVarInForLoop" value="true"/> - <message key="name.invalidPattern" - value="Local variable name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="ClassTypeParameterName"> - <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/> - <message key="name.invalidPattern" - value="Class type name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="MethodTypeParameterName"> - <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/> - <message key="name.invalidPattern" - value="Method type name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="NoFinalizer"/> - <module name="GenericWhitespace"> - <message key="ws.followed" - value="GenericWhitespace ''{0}'' is followed by whitespace."/> - <message key="ws.preceded" - value="GenericWhitespace ''{0}'' is preceded with whitespace."/> - <message key="ws.illegalFollow" - value="GenericWhitespace ''{0}'' should followed by whitespace."/> - <message key="ws.notPreceded" - value="GenericWhitespace ''{0}'' is not preceded with whitespace."/> - </module> - <module name="Indentation"> - <property name="basicOffset" value="2"/> - <property name="braceAdjustment" value="0"/> - <property name="caseIndent" value="2"/> - <property name="throwsIndent" value="4"/> - <property name="lineWrappingIndentation" value="4"/> - <property name="arrayInitIndent" value="2"/> - </module> - <module name="AbbreviationAsWordInName"> - <property name="ignoreFinal" value="false"/> - <property name="allowedAbbreviationLength" value="1"/> - </module> - <module name="OverloadMethodsDeclarationOrder"/> - <module name="CustomImportOrder"> - <property name="specialImportsRegExp" value="^javax\."/> - <property name="sortImportsInGroupAlphabetically" value="true"/> - <property name="customImportOrderRules" value="STATIC###SAME_PACKAGE(2)###THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE###SPECIAL_IMPORTS"/> - </module> - <module name="MethodParamPad"/> - <module name="OperatorWrap"> - <property name="option" value="NL"/> - <property name="tokens" value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR, LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR "/> - </module> - <module name="AnnotationLocation"> - <property name="tokens" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF"/> - </module> - <module name="AnnotationLocation"> - <property name="tokens" value="VARIABLE_DEF"/> - <property name="allowSamelineMultipleAnnotations" value="true"/> - </module> - <module name="NonEmptyAtclauseDescription"/> - <module name="JavadocTagContinuationIndentation"/> - <module name="SummaryJavadocCheck"> - <property name="forbiddenSummaryFragments" value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/> - </module> - <module name="AtclauseOrder"> - <property name="tagOrder" value="@param, @return, @throws, @deprecated"/> - <property name="target" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/> - </module> - <module name="JavadocMethod"> - <property name="scope" value="public"/> - <property name="allowMissingJavadoc" value="true"/> - <property name="allowMissingParamTags" value="true"/> - <property name="allowMissingThrowsTags" value="true"/> - <property name="allowMissingReturnTag" value="true"/> - <property name="minLineCount" value="2"/> - <property name="allowedAnnotations" value="Override, Test"/> - <property name="allowThrowsTagsForSubclasses" value="true"/> - </module> - <module name="MethodName"> - <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/> - <message key="name.invalidPattern" - value="Method name ''{0}'' must match pattern ''{1}''."/> - </module> - <module name="SingleLineJavadoc"> - <property name="ignoreInlineTags" value="false"/> - </module> - <module name="EmptyCatchBlock"> - <property name="exceptionVariableName" value="expected"/> - </module> - <module name="FileContentsHolder"/> - </module> - - <!-- Allow silencing rules with annotations http://stackoverflow.com/a/22556386/101923 --> - <module name="SuppressWarningsFilter" /> - <!-- Allow silencing with comment http://stackoverflow.com/questions/4023185 --> - <module name="SuppressionCommentFilter" /> -</module> diff --git a/appengine/search/pom.xml b/appengine/search/pom.xml index 7d701bf5f67..9af359bb5f9 100644 --- a/appengine/search/pom.xml +++ b/appengine/search/pom.xml @@ -81,22 +81,6 @@ Copyright 2015 Google Inc. All Rights Reserved. <!-- for hot reload of the web application --> <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory> <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-checkstyle-plugin</artifactId> - <version>2.17</version> - <configuration> - <configLocation>google-checks.xml</configLocation> - <consoleOutput>true</consoleOutput> - <failOnViolation>true</failOnViolation> - <failsOnError>true</failsOnError> - <includeTestSourceDirectory>true</includeTestSourceDirectory> - <suppressionsLocation>suppressions.xml</suppressionsLocation> - </configuration> - <executions> - <execution><goals><goal>check</goal></goals></execution> - </executions> - </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <version>3.3</version> diff --git a/appengine/search/src/main/java/com/example/appengine/search/DeleteServlet.java b/appengine/search/src/main/java/com/example/appengine/search/DeleteServlet.java index 6b25a22638e..89ba596317a 100644 --- a/appengine/search/src/main/java/com/example/appengine/search/DeleteServlet.java +++ b/appengine/search/src/main/java/com/example/appengine/search/DeleteServlet.java @@ -23,13 +23,13 @@ import com.google.appengine.api.search.GetResponse; // [END delete_import] -//CHECKSTYLE:OFF +// CHECKSTYLE:OFF import com.google.appengine.api.search.Field; import com.google.appengine.api.search.Index; import com.google.appengine.api.search.IndexSpec; import com.google.appengine.api.search.SearchServiceFactory; // @formatter:on -//CHECKSTYLE:ON +// CHECKSTYLE:ON import java.io.IOException; import java.io.PrintWriter; diff --git a/appengine/search/src/main/java/com/example/appengine/search/IndexServlet.java b/appengine/search/src/main/java/com/example/appengine/search/IndexServlet.java index 85e53b5bfb4..c1394571c5f 100644 --- a/appengine/search/src/main/java/com/example/appengine/search/IndexServlet.java +++ b/appengine/search/src/main/java/com/example/appengine/search/IndexServlet.java @@ -23,13 +23,13 @@ import com.google.appengine.api.search.IndexSpec; import com.google.appengine.api.search.SearchServiceFactory; -//CHECKSTYLE:OFF +// CHECKSTYLE:OFF // [START get_document_import] import com.google.appengine.api.search.GetRequest; import com.google.appengine.api.search.GetResponse; // [END get_document_import] // @formatter:on -//CHECKSTYLE:ON +// CHECKSTYLE:ON import java.io.IOException; import java.io.PrintWriter; diff --git a/appengine/search/src/main/java/com/example/appengine/search/SchemaServlet.java b/appengine/search/src/main/java/com/example/appengine/search/SchemaServlet.java new file mode 100644 index 00000000000..6120dfc2661 --- /dev/null +++ b/appengine/search/src/main/java/com/example/appengine/search/SchemaServlet.java @@ -0,0 +1,81 @@ +/** + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.appengine.search; + +import com.google.appengine.api.search.Document; +import com.google.appengine.api.search.Field; +import com.google.appengine.api.search.SearchServiceFactory; + +// @formatter:off +// CHECKSTYLE:OFF +// [START schema_import] +import com.google.appengine.api.search.Field.FieldType; +import com.google.appengine.api.search.Index; +import com.google.appengine.api.search.GetIndexesRequest; +import com.google.appengine.api.search.GetResponse; +import com.google.appengine.api.search.Schema; +// [END schema_import] +// @formatter:on +// CHECKSTYLE:ON + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.List; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +@SuppressWarnings("serial") +public class SchemaServlet extends HttpServlet { + + private static final String SEARCH_INDEX = "schemaIndex"; + + @Override + public void doGet(HttpServletRequest req, HttpServletResponse resp) + throws IOException { + PrintWriter out = resp.getWriter(); + Document doc = Document.newBuilder() + .setId("theOnlyCar") + .addField(Field.newBuilder().setName("maker").setText("Toyota")) + .addField(Field.newBuilder().setName("price").setNumber(300000)) + .addField(Field.newBuilder().setName("color").setText("lightblue")) + .addField(Field.newBuilder().setName("model").setText("Prius")) + .build(); + try { + Utils.indexADocument(SEARCH_INDEX, doc); + } catch (InterruptedException e) { + // ignore + } + // [START list_schema] + GetResponse<Index> response = SearchServiceFactory.getSearchService().getIndexes( + GetIndexesRequest.newBuilder().setSchemaFetched(true).build()); + + // List out elements of each Schema + for (Index index : response) { + Schema schema = index.getSchema(); + for (String fieldName : schema.getFieldNames()) { + List<FieldType> typesForField = schema.getFieldTypes(fieldName); + // Just printing out the field names and types + for (FieldType type : typesForField) { + out.println(index.getName() + ":" + fieldName + ":" + type.name()); + } + } + } + // [START list_schema] + } +} diff --git a/appengine/search/src/main/java/com/example/appengine/search/SearchOptionServlet.java b/appengine/search/src/main/java/com/example/appengine/search/SearchOptionServlet.java new file mode 100644 index 00000000000..f3191a49847 --- /dev/null +++ b/appengine/search/src/main/java/com/example/appengine/search/SearchOptionServlet.java @@ -0,0 +1,126 @@ +/** + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.appengine.search; + +import com.google.appengine.api.search.Document; +import com.google.appengine.api.search.Index; + +// CHECKSTYLE:OFF +// @formatter:off +// [START search_option_import] +import com.google.appengine.api.search.Field; +import com.google.appengine.api.search.IndexSpec; +import com.google.appengine.api.search.SearchServiceFactory; +import com.google.appengine.api.search.Query; +import com.google.appengine.api.search.QueryOptions; +import com.google.appengine.api.search.Results; +import com.google.appengine.api.search.SearchException; +import com.google.appengine.api.search.SortExpression; +import com.google.appengine.api.search.SortOptions; +import com.google.appengine.api.search.ScoredDocument; +// [END search_option_import] +// @formatter:on +// CHECKSTYLE:ON + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.logging.Logger; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +/** + * Code snippet for searching with query options. + */ +@SuppressWarnings("serial") +public class SearchOptionServlet extends HttpServlet { + private static final Logger LOG = Logger.getLogger(SearchOptionServlet.class.getSimpleName()); + + private static final String SEARCH_INDEX = "searchOptionIndex"; + + private Index getIndex() { + IndexSpec indexSpec = IndexSpec.newBuilder().setName(SEARCH_INDEX).build(); + Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec); + return index; + } + + private Results<ScoredDocument> doSearch() { + String indexName = SEARCH_INDEX; + // [START search_with_options] + try { + // Build the SortOptions with 2 sort keys + SortOptions sortOptions = SortOptions.newBuilder() + .addSortExpression(SortExpression.newBuilder() + .setExpression("price") + .setDirection(SortExpression.SortDirection.DESCENDING) + .setDefaultValueNumeric(0)) + .addSortExpression(SortExpression.newBuilder() + .setExpression("brand") + .setDirection(SortExpression.SortDirection.DESCENDING) + .setDefaultValue("")) + .setLimit(1000) + .build(); + + // Build the QueryOptions + QueryOptions options = QueryOptions.newBuilder() + .setLimit(25) + .setFieldsToReturn("model", "price", "description") + .setSortOptions(sortOptions) + .build(); + + // A query string + String queryString = "product: coffee roaster AND price < 500"; + + // Build the Query and run the search + Query query = Query.newBuilder().setOptions(options).build(queryString); + IndexSpec indexSpec = IndexSpec.newBuilder().setName(indexName).build(); + Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec); + Results<ScoredDocument> result = index.search(query); + return result; + } catch (SearchException e) { + // handle exception... + } + return null; + // [END search_with_options] + } + + @Override + public void doGet(HttpServletRequest req, HttpServletResponse resp) + throws IOException { + // Put one document to avoid an error + Document document = Document.newBuilder() + .setId("theOnlyCoffeeRoaster") + .addField(Field.newBuilder().setName("price").setNumber(200)) + .addField(Field.newBuilder().setName("model").setText("TZ4000")) + .addField(Field.newBuilder().setName("brand").setText("MyBrand")) + .addField(Field.newBuilder().setName("product").setText("coffee roaster")) + .addField(Field.newBuilder() + .setName("description").setText("A coffee bean roaster at home")) + .build(); + try { + Utils.indexADocument(SEARCH_INDEX, document); + } catch (InterruptedException e) { + // ignore + } + PrintWriter out = resp.getWriter(); + Results<ScoredDocument> result = doSearch(); + for (ScoredDocument doc : result.getResults()) { + out.println(doc.toString()); + } + } +} diff --git a/appengine/search/src/main/java/com/example/appengine/search/SearchServlet.java b/appengine/search/src/main/java/com/example/appengine/search/SearchServlet.java index 8804ac48cec..efb32d6a242 100644 --- a/appengine/search/src/main/java/com/example/appengine/search/SearchServlet.java +++ b/appengine/search/src/main/java/com/example/appengine/search/SearchServlet.java @@ -26,12 +26,12 @@ import com.google.appengine.api.search.StatusCode; // [END search_document_import] -//CHECKSTYLE:OFF +// CHECKSTYLE:OFF import com.google.appengine.api.search.Index; import com.google.appengine.api.search.IndexSpec; import com.google.appengine.api.search.SearchServiceFactory; // @formatter:on -//CHECKSTYLE:ON +// CHECKSTYLE:ON import java.io.IOException; import java.io.PrintWriter; @@ -73,7 +73,7 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) int delay = 2; while (true) { try { - String queryString = "product: piano AND price < 5000"; + String queryString = "product = piano AND price < 5000"; Results<ScoredDocument> results = getIndex().search(queryString); // Iterate over the documents in the results @@ -99,7 +99,19 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) } break; } - // [START search_document] + // [END search_document] + // We don't test the search result below, but we're fine if it runs without errors. out.println("Search performed"); + Index index = getIndex(); + // [START simple_search_1] + index.search("rose water"); + // [END simple_search_1] + // [START simple_search_2] + index.search("1776-07-04"); + // [END simple_search_2] + // [START simple_search_3] + // search for documents with pianos that cost less than $5000 + index.search("product = piano AND price < 5000"); + // [END simple_search_3] } } diff --git a/appengine/search/src/main/webapp/WEB-INF/web.xml b/appengine/search/src/main/webapp/WEB-INF/web.xml index a3f744efa07..d3e1e6f8ec3 100644 --- a/appengine/search/src/main/webapp/WEB-INF/web.xml +++ b/appengine/search/src/main/webapp/WEB-INF/web.xml @@ -27,6 +27,14 @@ <servlet-name>search</servlet-name> <url-pattern>/search</url-pattern> </servlet-mapping> + <servlet> + <servlet-name>search_option</servlet-name> + <servlet-class>com.example.appengine.search.SearchOptionServlet</servlet-class> + </servlet> + <servlet-mapping> + <servlet-name>search_option</servlet-name> + <url-pattern>/search_option</url-pattern> + </servlet-mapping> <servlet> <servlet-name>delete</servlet-name> <servlet-class>com.example.appengine.search.DeleteServlet</servlet-class> @@ -35,4 +43,12 @@ <servlet-name>delete</servlet-name> <url-pattern>/delete</url-pattern> </servlet-mapping> + <servlet> + <servlet-name>schema</servlet-name> + <servlet-class>com.example.appengine.search.SchemaServlet</servlet-class> + </servlet> + <servlet-mapping> + <servlet-name>schema</servlet-name> + <url-pattern>/schema</url-pattern> + </servlet-mapping> </web-app> diff --git a/appengine/search/src/test/java/com/example/appengine/search/DeleteServletTest.java b/appengine/search/src/test/java/com/example/appengine/search/DeleteServletTest.java index 2ec6dde14c3..d520d56c1d3 100644 --- a/appengine/search/src/test/java/com/example/appengine/search/DeleteServletTest.java +++ b/appengine/search/src/test/java/com/example/appengine/search/DeleteServletTest.java @@ -1,3 +1,19 @@ +/** + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.example.appengine.search; import static com.google.common.truth.Truth.assertThat; diff --git a/appengine/search/src/test/java/com/example/appengine/search/DocumentServletTest.java b/appengine/search/src/test/java/com/example/appengine/search/DocumentServletTest.java index 789be7ea443..d5b32f2c62c 100644 --- a/appengine/search/src/test/java/com/example/appengine/search/DocumentServletTest.java +++ b/appengine/search/src/test/java/com/example/appengine/search/DocumentServletTest.java @@ -1,3 +1,19 @@ +/** + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.example.appengine.search; import static com.google.common.truth.Truth.assertThat; diff --git a/appengine/search/src/test/java/com/example/appengine/search/IndexServletTest.java b/appengine/search/src/test/java/com/example/appengine/search/IndexServletTest.java index 041ac35e33a..5a084b85d9a 100644 --- a/appengine/search/src/test/java/com/example/appengine/search/IndexServletTest.java +++ b/appengine/search/src/test/java/com/example/appengine/search/IndexServletTest.java @@ -1,3 +1,19 @@ +/** + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.example.appengine.search; import static com.google.common.truth.Truth.assertThat; diff --git a/appengine/search/src/test/java/com/example/appengine/search/SchemaServletTest.java b/appengine/search/src/test/java/com/example/appengine/search/SchemaServletTest.java new file mode 100644 index 00000000000..2a9fb122642 --- /dev/null +++ b/appengine/search/src/test/java/com/example/appengine/search/SchemaServletTest.java @@ -0,0 +1,76 @@ +/** + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.appengine.search; + +import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.when; + +import com.google.appengine.tools.development.testing.LocalServiceTestHelper; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.io.PrintWriter; +import java.io.StringWriter; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class SchemaServletTest { + private final LocalServiceTestHelper helper = new LocalServiceTestHelper(); + + @Mock private HttpServletRequest mockRequest; + @Mock private HttpServletResponse mockResponse; + private StringWriter responseWriter; + private SchemaServlet servletUnderTest; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + helper.setUp(); + + // Set up a fake HTTP response. + responseWriter = new StringWriter(); + when(mockResponse.getWriter()).thenReturn(new PrintWriter(responseWriter)); + + servletUnderTest = new SchemaServlet(); + } + + @After + public void tearDown() { + helper.tearDown(); + } + + @Test + public void doGet_successfulyInvoked() throws Exception { + servletUnderTest.doGet(mockRequest, mockResponse); + String content = responseWriter.toString(); + assertThat(content) + .named("SchemaServlet response") + .contains("schemaIndex:maker:TEXT"); + assertThat(content) + .named("SchemaServlet response") + .contains("schemaIndex:price:NUMBER"); + assertThat(content) + .named("SchemaServlet response") + .contains("schemaIndex:color:TEXT"); + assertThat(content) + .named("SchemaServlet response") + .contains("schemaIndex:model:TEXT"); + } +} \ No newline at end of file diff --git a/appengine/search/src/test/java/com/example/appengine/search/SearchOptionServletTest.java b/appengine/search/src/test/java/com/example/appengine/search/SearchOptionServletTest.java new file mode 100644 index 00000000000..2b759eaf1bf --- /dev/null +++ b/appengine/search/src/test/java/com/example/appengine/search/SearchOptionServletTest.java @@ -0,0 +1,66 @@ +/** + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.appengine.search; + +import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.when; + +import com.google.appengine.tools.development.testing.LocalServiceTestHelper; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.io.PrintWriter; +import java.io.StringWriter; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class SearchOptionServletTest { + private final LocalServiceTestHelper helper = new LocalServiceTestHelper(); + + @Mock private HttpServletRequest mockRequest; + @Mock private HttpServletResponse mockResponse; + private StringWriter responseWriter; + private SearchOptionServlet servletUnderTest; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + helper.setUp(); + + // Set up a fake HTTP response. + responseWriter = new StringWriter(); + when(mockResponse.getWriter()).thenReturn(new PrintWriter(responseWriter)); + + servletUnderTest = new SearchOptionServlet(); + } + + @After + public void tearDown() { + helper.tearDown(); + } + + @Test + public void doGet_successfulyInvoked() throws Exception { + servletUnderTest.doGet(mockRequest, mockResponse); + assertThat(responseWriter.toString()) + .named("SearchOptionServlet response") + .contains("documentId=theOnlyCoffeeRoaster"); + } +} diff --git a/appengine/search/src/test/java/com/example/appengine/search/SearchServletTest.java b/appengine/search/src/test/java/com/example/appengine/search/SearchServletTest.java index 719855cb472..f2fa060e48a 100644 --- a/appengine/search/src/test/java/com/example/appengine/search/SearchServletTest.java +++ b/appengine/search/src/test/java/com/example/appengine/search/SearchServletTest.java @@ -1,3 +1,19 @@ +/** + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.example.appengine.search; import static com.google.common.truth.Truth.assertThat; diff --git a/appengine/search/src/test/java/com/example/appengine/search/UtilsTest.java b/appengine/search/src/test/java/com/example/appengine/search/UtilsTest.java index 491cd377b23..ff8ee847c71 100644 --- a/appengine/search/src/test/java/com/example/appengine/search/UtilsTest.java +++ b/appengine/search/src/test/java/com/example/appengine/search/UtilsTest.java @@ -1,3 +1,19 @@ +/** + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.example.appengine.search; import static com.google.common.truth.Truth.assertThat; diff --git a/appengine/search/suppressions.xml b/appengine/search/suppressions.xml deleted file mode 100644 index 22a348c205e..00000000000 --- a/appengine/search/suppressions.xml +++ /dev/null @@ -1,27 +0,0 @@ -<?xml version="1.0"?> -<!DOCTYPE suppressions PUBLIC - "-//Puppy Crawl//DTD Suppressions 1.1//EN" - "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd"> -<!-- -Copyright 2016 Google Inc. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. ---> -<suppressions> - <!-- For our tests we do not demand API documentation. --> - <suppress files="[/\\]src[/\\]test[/\\]java[/\\].*\.java" checks="Javadoc.*"/> - - <!-- Suppress checks for generated code. --> - <suppress files="[/\\]target[/\\]" checks=".+"/> - <suppress files=".*AutoValue_.*\.java$" checks=".+"/> -</suppressions> diff --git a/java-repo-tools/google-checks.xml b/java-repo-tools/google-checks.xml index 5f1d75b1e7e..730c9148710 100644 --- a/java-repo-tools/google-checks.xml +++ b/java-repo-tools/google-checks.xml @@ -213,8 +213,11 @@ <module name="EmptyCatchBlock"> <property name="exceptionVariableName" value="expected"/> </module> + <module name="FileContentsHolder"/> </module> <!-- Allow silencing rules with annotations http://stackoverflow.com/a/22556386/101923 --> <module name="SuppressWarningsFilter" /> + <!-- Allow silencing with comment http://stackoverflow.com/questions/4023185 --> + <module name="SuppressionCommentFilter" /> </module>