From: Lee, Tian (tl5884) Date: Fri, 1 Mar 2019 16:03:03 +0000 (+0000) Subject: Add elasticsearch with searchguard Dockerfile X-Git-Tag: 1.4.2~16 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=aai%2Fsearch-data-service.git;a=commitdiff_plain;h=e07d5b8dc0801583518b4f27ce6b8f3b56bcf206 Add elasticsearch with searchguard Dockerfile Add Dockerfile that produces an image of ElasticSearch with SearchGuard plugin pre-installed, and restructure the Maven project to build both the old search-data-service Dockerfile and the new elasticsearch-sg Dockerfile. Change-Id: Iff7cb79e3c09da78b6233422f40cb03eeef5bfdb Issue-ID: AAI-2203 Signed-off-by: Lee, Tian (tl5884) --- diff --git a/elasticsearch-sg/pom.xml b/elasticsearch-sg/pom.xml new file mode 100644 index 0000000..cd24333 --- /dev/null +++ b/elasticsearch-sg/pom.xml @@ -0,0 +1,81 @@ + + + 4.0.0 + + org.onap.aai.search-data-service + elasticsearch-sg + elasticsearch with searchguard + 1.4.0-SNAPSHOT + pom + + + + + org.apache.maven.plugins + maven-resources-plugin + 2.7 + + + copy-docker-file + process-resources + + copy-resources + + + target + true + + + ${basedir}/src/main/docker + + **/* + + + + + + + + + + com.spotify + docker-maven-plugin + 0.4.11 + + true + docker-hub + ${docker.push.registry}/onap/${project.artifactId} + ${basedir}/target + + latest + + true + + + + + + + \ No newline at end of file diff --git a/elasticsearch-sg/src/main/docker/Dockerfile b/elasticsearch-sg/src/main/docker/Dockerfile new file mode 100644 index 0000000..0ccb31d --- /dev/null +++ b/elasticsearch-sg/src/main/docker/Dockerfile @@ -0,0 +1,10 @@ +# https://github.com/elastic/elasticsearch-docker +FROM docker.elastic.co/elasticsearch/elasticsearch:6.1.2 + +USER elasticsearch + +# Search Guard plugin +RUN elasticsearch-plugin install --batch com.floragunn:search-guard-6:6.1.2-22.3 \ + && chmod +x plugins/search-guard-6/tools/*.sh + +ENTRYPOINT ["/usr/share/elasticsearch/bin/run.sh"] \ No newline at end of file diff --git a/pom.xml b/pom.xml index 65c8d40..3eb4543 100644 --- a/pom.xml +++ b/pom.xml @@ -21,450 +21,31 @@ --> - 4.0.0 - - - spring-boot-starter-parent - org.springframework.boot - 1.5.18.RELEASE - - org.onap.aai - search-data-service - 1.4.0-SNAPSHOT - aai-search-data-service - - - ${basedir}/target - https://nexus.onap.org - 1.8 - ${basedir}/src/main/java-gen - google_checks.xml - - java - jacoco - ${project.build.directory}/surefire-reports - - ${project.build.directory}/coverage-reports/jacoco.exec - - false - ${project.version} - - - - - - com.google.code.gson - gson - 2.8.2 - - - - org.hamcrest - hamcrest-library - 1.3 - test - - - - com.jayway.jsonpath - json-path - 2.2.0 - - - - com.googlecode.json-simple - json-simple - 1.1.1 - - - - org.dom4j - dom4j - 2.1.1 - provided - - - - commons-io - commons-io - 2.4 - - - - org.mockito - mockito-all - 1.10.19 - test - - - - - org.onap.aai.logging-service - common-logging - 1.2.2 - - - - org.onap.aai.logging-service - logging-api - 1.2.2 - - - - org.onap.aai.logging-service - eelf-logging - 1.2.2 - - - - - com.fasterxml.jackson.core - jackson-databind - 2.7.8 - - - - org.apache.directory.studio - org.apache.commons.lang - 2.6 - - - - radeox - radeox - 0.9 - - - - com.github.fge - json-schema-validator - 2.0.0 - - - - org.json - json - 20180130 - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-tomcat - - - - - - org.springframework.boot - spring-boot-starter-jetty - - - - org.springframework.boot - spring-boot-starter - - - ch.qos.logback - logback-classic - - - - - - org.springframework.boot - spring-boot-starter-jersey - - - org.springframework.boot - spring-boot-starter-tomcat - - - - - - org.springframework.boot - spring-boot-starter-actuator - - - - org.springframework.boot - spring-boot-starter-test - test - - - - org.springframework.boot - spring-boot-starter-security - - - - - ch.qos.logback - logback-classic - 1.2.1 - - - - ch.qos.logback - logback-core - 1.2.1 - - - - - - - central - Maven 2 repository 2 - http://repo2.maven.org/maven2/ - - - ecomp-releases - ECOMP Release Repository - ${nexusproxy}/content/repositories/releases/ - - - ecomp-snapshots - ECOMP Snapshot Repository - ${nexusproxy}/content/repositories/snapshots/ - - - ecomp-staging - ECOMP Staging Repository - ${nexusproxy}/content/repositories/staging/ - - - - - search-data-service-package - - - org.springframework.boot - spring-boot-maven-plugin - - - - - org.apache.maven.plugins - maven-site-plugin - - - - org.apache.maven.plugins - maven-checkstyle-plugin - 2.17 - - - - checkstyle - - - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - groovy-eclipse-compiler - true - 1.8 - 1.8 - - - - org.codehaus.groovy - groovy-eclipse-compiler - 2.9.0-01 - - - org.codehaus.groovy - groovy-eclipse-batch - 2.3.4-01 - - - - - com.spotify - docker-maven-plugin - 0.4.11 - - true - docker-hub - ${docker.push.registry}/onap/${project.artifactId} - ${docker.location} - - latest - - true - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.7 - true - - ${nexusproxy} - 176c31dfe190a - ecomp-staging - - - - - - org.jsonschema2pojo - jsonschema2pojo-maven-plugin - 0.4.26 - - true - ${basedir}/src/main/resources/json/schema - ${generatedSourceDir} - org.onap.aai.sa.rest - - - - - generate - - - - - - - org.apache.maven.plugins - maven-resources-plugin - 2.7 - - - copy-docker-file - package - - copy-resources - - - target - true - - - ${basedir}/src/main/docker - true - - **/* - - - - ${basedir} - true - - bundleconfig-local/** - - - - ${basedir}/src/main/bin/ - - - - - - - - - com.mycila - license-maven-plugin - 3.0 - -
License.txt
- - src/main/java/** - src/test/java/** - pom.xml - - true -
- - - - check - - validate - - -
- - - org.apache.maven.plugins - maven-deploy-plugin - - true - - - - org.codehaus.mojo - sonar-maven-plugin - 3.2 - - - org.jacoco - jacoco-maven-plugin - 0.7.7.201606060606 - - true - - - - jacoco-initialize-unit-tests - - prepare-agent - - - ${project.build.directory}/coverage-reports/jacoco.exec - - - - - - - - - - maven-clean-plugin - 3.0.0 - - - - ${generatedSourceDir} - - - - -
-
- - - ecomp-releases - ECOMP Release Repository - ${nexusproxy}/content/repositories/releases/ - - - ecomp-snapshots - ECOMP Snapshot Repository - ${nexusproxy}/content/repositories/snapshots/ - - - ecomp-javadoc - dav:https://ecomp-nexus:8443/repository/aai/search-data-service-javadoc/${project.version} - - -
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + org.onap.aai + search-data-service-agg + aai-search-data-service aggregate pom + 1.4.0-SNAPSHOT + pom + + + search-data-service + elasticsearch-sg + + + + + + com.spotify + docker-maven-plugin + 0.4.11 + + true + + + + + + \ No newline at end of file diff --git a/License.txt b/search-data-service/License.txt similarity index 100% rename from License.txt rename to search-data-service/License.txt diff --git a/bundleconfig-local/etc/logback.xml b/search-data-service/bundleconfig-local/etc/logback.xml similarity index 100% rename from bundleconfig-local/etc/logback.xml rename to search-data-service/bundleconfig-local/etc/logback.xml diff --git a/search-data-service/pom.xml b/search-data-service/pom.xml new file mode 100644 index 0000000..a270914 --- /dev/null +++ b/search-data-service/pom.xml @@ -0,0 +1,461 @@ + + + 4.0.0 + + + spring-boot-starter-parent + org.springframework.boot + 1.5.18.RELEASE + + + org.onap.aai + search-data-service + 1.4.0-SNAPSHOT + aai-search-data-service + + + ${basedir}/target + https://nexus.onap.org + 1.8 + ${basedir}/src/main/java-gen + google_checks.xml + + java + jacoco + ${project.build.directory}/surefire-reports + + ${project.build.directory}/coverage-reports/jacoco.exec + + false + ${project.version} + + + + + + com.google.code.gson + gson + + + + org.hamcrest + hamcrest-library + test + + + + com.jayway.jsonpath + json-path + + + + com.googlecode.json-simple + json-simple + + + + org.dom4j + dom4j + 2.1.1 + provided + + + + commons-io + commons-io + 2.4 + + + + org.mockito + mockito-all + 1.10.19 + test + + + + + org.onap.aai.logging-service + common-logging + 1.2.2 + + + + org.onap.aai.logging-service + logging-api + 1.2.2 + + + + org.onap.aai.logging-service + eelf-logging + 1.2.2 + + + + + com.fasterxml.jackson.core + jackson-databind + + + + org.apache.directory.studio + org.apache.commons.lang + 2.6 + + + + radeox + radeox + 0.9 + + + + com.github.fge + json-schema-validator + 2.0.0 + + + + org.json + json + 20180130 + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + + org.springframework.boot + spring-boot-starter-jetty + + + + org.springframework.boot + spring-boot-starter + + + ch.qos.logback + logback-classic + + + + + + org.springframework.boot + spring-boot-starter-jersey + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.springframework.boot + spring-boot-starter-security + + + + + ch.qos.logback + logback-classic + + + + ch.qos.logback + logback-core + + + + + + + central + Maven 2 repository 2 + http://repo2.maven.org/maven2/ + + + ecomp-releases + ECOMP Release Repository + ${nexusproxy}/content/repositories/releases/ + + + ecomp-snapshots + ECOMP Snapshot Repository + ${nexusproxy}/content/repositories/snapshots/ + + + ecomp-staging + ECOMP Staging Repository + ${nexusproxy}/content/repositories/staging/ + + + + + search-data-service-package + + + org.springframework.boot + spring-boot-maven-plugin + + + + + org.apache.maven.plugins + maven-site-plugin + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.17 + + + + checkstyle + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + groovy-eclipse-compiler + true + 1.8 + 1.8 + + + + org.codehaus.groovy + groovy-eclipse-compiler + 2.9.0-01 + + + org.codehaus.groovy + groovy-eclipse-batch + 2.3.4-01 + + + + + com.spotify + docker-maven-plugin + 0.4.11 + + true + docker-hub + ${docker.push.registry}/onap/${project.artifactId} + ${docker.location} + + latest + + true + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ${nexusproxy} + 176c31dfe190a + ecomp-staging + + + + + + org.jsonschema2pojo + jsonschema2pojo-maven-plugin + 0.4.26 + + true + ${basedir}/src/main/resources/json/schema + ${generatedSourceDir} + org.onap.aai.sa.rest + + + + + generate + + + + + + + org.apache.maven.plugins + maven-resources-plugin + + + copy-docker-file + package + + copy-resources + + + target + true + + + ${basedir}/src/main/docker + true + + **/* + + + + ${basedir} + true + + bundleconfig-local/** + + + + ${basedir}/src/main/bin/ + + + + + + + + + com.mycila + license-maven-plugin + 3.0 + +
License.txt
+ + src/main/java/** + src/test/java/** + pom.xml + + true +
+ + + + check + + validate + + +
+ + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + org.codehaus.mojo + sonar-maven-plugin + 3.2 + + + org.jacoco + jacoco-maven-plugin + 0.7.7.201606060606 + + true + + + + jacoco-initialize-unit-tests + + prepare-agent + + + ${project.build.directory}/coverage-reports/jacoco.exec + + + + + + + + + + maven-clean-plugin + + + + ${generatedSourceDir} + + + + +
+
+ + + ecomp-releases + ECOMP Release Repository + ${nexusproxy}/content/repositories/releases/ + + + ecomp-snapshots + ECOMP Snapshot Repository + ${nexusproxy}/content/repositories/snapshots/ + + + ecomp-javadoc + dav:https://ecomp-nexus:8443/repository/aai/search-data-service-javadoc/${project.version} + + +
diff --git a/src/main/bin/start.sh b/search-data-service/src/main/bin/start.sh similarity index 100% rename from src/main/bin/start.sh rename to search-data-service/src/main/bin/start.sh diff --git a/src/main/docker/Dockerfile b/search-data-service/src/main/docker/Dockerfile similarity index 96% rename from src/main/docker/Dockerfile rename to search-data-service/src/main/docker/Dockerfile index ad402b2..1a70fd7 100644 --- a/src/main/docker/Dockerfile +++ b/search-data-service/src/main/docker/Dockerfile @@ -14,7 +14,7 @@ RUN export JAVA_HOME # Build up the deployment folder structure RUN mkdir -p $MICRO_HOME RUN mkdir -p $MICRO_HOME/bundleconfig/etc -ADD search-data-service* $MICRO_HOME/ +ADD *.jar $MICRO_HOME/ RUN mkdir -p $BIN_HOME COPY *.sh $BIN_HOME COPY bundleconfig-local $MICRO_HOME/bundleconfig diff --git a/src/main/java/org/onap/aai/sa/Application.java b/search-data-service/src/main/java/org/onap/aai/sa/Application.java similarity index 98% rename from src/main/java/org/onap/aai/sa/Application.java rename to search-data-service/src/main/java/org/onap/aai/sa/Application.java index 059ca22..ad52dfd 100644 --- a/src/main/java/org/onap/aai/sa/Application.java +++ b/search-data-service/src/main/java/org/onap/aai/sa/Application.java @@ -1,58 +1,58 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ -package org.onap.aai.sa; - -import java.util.HashMap; -import org.eclipse.jetty.util.security.Password; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.support.SpringBootServletInitializer; - -@SpringBootApplication -public class Application extends SpringBootServletInitializer { - - public static void main(String[] args) { - String keyStorePassword = System.getProperty("KEY_STORE_PASSWORD"); - if (keyStorePassword == null || keyStorePassword.isEmpty()) { - throw new RuntimeException("Env property KEY_STORE_PASSWORD not set"); - } - HashMap props = new HashMap<>(); - String deobfuscatedKeyStorePassword = keyStorePassword.startsWith("OBF:") ? Password.deobfuscate(keyStorePassword) : keyStorePassword; - props.put("server.ssl.key-store-password", deobfuscatedKeyStorePassword); - - String trustStoreLocation = System.getProperty("TRUST_STORE_LOCATION"); - String trustStorePassword = System.getProperty("TRUST_STORE_PASSWORD"); - if (trustStoreLocation != null && trustStorePassword != null) { - trustStorePassword = trustStorePassword.startsWith("OBF:") ? Password.deobfuscate(trustStorePassword) : trustStorePassword; - props.put("server.ssl.trust-store", trustStoreLocation); - props.put("server.ssl.trust-store-password", trustStorePassword); - } - - String requireClientAuth = System.getenv("REQUIRE_CLIENT_AUTH"); - if (requireClientAuth == null || requireClientAuth.isEmpty()) { - props.put("server.ssl.client-auth", "need"); - }else { - props.put("server.ssl.client-auth", Boolean.valueOf(requireClientAuth)? "need" : "want"); - } - - new Application().configure(new SpringApplicationBuilder(Application.class).properties(props)).run(args); - } -} +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.aai.sa; + +import java.util.HashMap; +import org.eclipse.jetty.util.security.Password; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.support.SpringBootServletInitializer; + +@SpringBootApplication +public class Application extends SpringBootServletInitializer { + + public static void main(String[] args) { + String keyStorePassword = System.getProperty("KEY_STORE_PASSWORD"); + if (keyStorePassword == null || keyStorePassword.isEmpty()) { + throw new RuntimeException("Env property KEY_STORE_PASSWORD not set"); + } + HashMap props = new HashMap<>(); + String deobfuscatedKeyStorePassword = keyStorePassword.startsWith("OBF:") ? Password.deobfuscate(keyStorePassword) : keyStorePassword; + props.put("server.ssl.key-store-password", deobfuscatedKeyStorePassword); + + String trustStoreLocation = System.getProperty("TRUST_STORE_LOCATION"); + String trustStorePassword = System.getProperty("TRUST_STORE_PASSWORD"); + if (trustStoreLocation != null && trustStorePassword != null) { + trustStorePassword = trustStorePassword.startsWith("OBF:") ? Password.deobfuscate(trustStorePassword) : trustStorePassword; + props.put("server.ssl.trust-store", trustStoreLocation); + props.put("server.ssl.trust-store-password", trustStorePassword); + } + + String requireClientAuth = System.getenv("REQUIRE_CLIENT_AUTH"); + if (requireClientAuth == null || requireClientAuth.isEmpty()) { + props.put("server.ssl.client-auth", "need"); + }else { + props.put("server.ssl.client-auth", Boolean.valueOf(requireClientAuth)? "need" : "want"); + } + + new Application().configure(new SpringApplicationBuilder(Application.class).properties(props)).run(args); + } +} diff --git a/src/main/java/org/onap/aai/sa/auth/SearchDbServiceAuth.java b/search-data-service/src/main/java/org/onap/aai/sa/auth/SearchDbServiceAuth.java similarity index 100% rename from src/main/java/org/onap/aai/sa/auth/SearchDbServiceAuth.java rename to search-data-service/src/main/java/org/onap/aai/sa/auth/SearchDbServiceAuth.java diff --git a/src/main/java/org/onap/aai/sa/auth/SearchDbServiceAuthCore.java b/search-data-service/src/main/java/org/onap/aai/sa/auth/SearchDbServiceAuthCore.java similarity index 100% rename from src/main/java/org/onap/aai/sa/auth/SearchDbServiceAuthCore.java rename to search-data-service/src/main/java/org/onap/aai/sa/auth/SearchDbServiceAuthCore.java diff --git a/src/main/java/org/onap/aai/sa/rest/AnalysisConfiguration.java b/search-data-service/src/main/java/org/onap/aai/sa/rest/AnalysisConfiguration.java similarity index 100% rename from src/main/java/org/onap/aai/sa/rest/AnalysisConfiguration.java rename to search-data-service/src/main/java/org/onap/aai/sa/rest/AnalysisConfiguration.java diff --git a/src/main/java/org/onap/aai/sa/rest/AnalyzerApi.java b/search-data-service/src/main/java/org/onap/aai/sa/rest/AnalyzerApi.java similarity index 100% rename from src/main/java/org/onap/aai/sa/rest/AnalyzerApi.java rename to search-data-service/src/main/java/org/onap/aai/sa/rest/AnalyzerApi.java diff --git a/src/main/java/org/onap/aai/sa/rest/ApiUtils.java b/search-data-service/src/main/java/org/onap/aai/sa/rest/ApiUtils.java similarity index 100% rename from src/main/java/org/onap/aai/sa/rest/ApiUtils.java rename to search-data-service/src/main/java/org/onap/aai/sa/rest/ApiUtils.java diff --git a/src/main/java/org/onap/aai/sa/rest/BulkApi.java b/search-data-service/src/main/java/org/onap/aai/sa/rest/BulkApi.java similarity index 100% rename from src/main/java/org/onap/aai/sa/rest/BulkApi.java rename to search-data-service/src/main/java/org/onap/aai/sa/rest/BulkApi.java diff --git a/src/main/java/org/onap/aai/sa/rest/BulkMetaData.java b/search-data-service/src/main/java/org/onap/aai/sa/rest/BulkMetaData.java similarity index 100% rename from src/main/java/org/onap/aai/sa/rest/BulkMetaData.java rename to search-data-service/src/main/java/org/onap/aai/sa/rest/BulkMetaData.java diff --git a/src/main/java/org/onap/aai/sa/rest/BulkOperation.java b/search-data-service/src/main/java/org/onap/aai/sa/rest/BulkOperation.java similarity index 100% rename from src/main/java/org/onap/aai/sa/rest/BulkOperation.java rename to search-data-service/src/main/java/org/onap/aai/sa/rest/BulkOperation.java diff --git a/src/main/java/org/onap/aai/sa/rest/BulkRequest.java b/search-data-service/src/main/java/org/onap/aai/sa/rest/BulkRequest.java similarity index 100% rename from src/main/java/org/onap/aai/sa/rest/BulkRequest.java rename to search-data-service/src/main/java/org/onap/aai/sa/rest/BulkRequest.java diff --git a/src/main/java/org/onap/aai/sa/rest/Document.java b/search-data-service/src/main/java/org/onap/aai/sa/rest/Document.java similarity index 100% rename from src/main/java/org/onap/aai/sa/rest/Document.java rename to search-data-service/src/main/java/org/onap/aai/sa/rest/Document.java diff --git a/src/main/java/org/onap/aai/sa/rest/DocumentApi.java b/search-data-service/src/main/java/org/onap/aai/sa/rest/DocumentApi.java similarity index 100% rename from src/main/java/org/onap/aai/sa/rest/DocumentApi.java rename to search-data-service/src/main/java/org/onap/aai/sa/rest/DocumentApi.java diff --git a/src/main/java/org/onap/aai/sa/rest/IndexApi.java b/search-data-service/src/main/java/org/onap/aai/sa/rest/IndexApi.java similarity index 100% rename from src/main/java/org/onap/aai/sa/rest/IndexApi.java rename to search-data-service/src/main/java/org/onap/aai/sa/rest/IndexApi.java diff --git a/src/main/java/org/onap/aai/sa/rest/SearchServiceApi.java b/search-data-service/src/main/java/org/onap/aai/sa/rest/SearchServiceApi.java similarity index 100% rename from src/main/java/org/onap/aai/sa/rest/SearchServiceApi.java rename to search-data-service/src/main/java/org/onap/aai/sa/rest/SearchServiceApi.java diff --git a/src/main/java/org/onap/aai/sa/rest/SettingConfiguration.java b/search-data-service/src/main/java/org/onap/aai/sa/rest/SettingConfiguration.java similarity index 100% rename from src/main/java/org/onap/aai/sa/rest/SettingConfiguration.java rename to search-data-service/src/main/java/org/onap/aai/sa/rest/SettingConfiguration.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/RestEchoService.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/RestEchoService.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/RestEchoService.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/RestEchoService.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/config/ElasticSearchConfig.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/config/ElasticSearchConfig.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/config/ElasticSearchConfig.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/config/ElasticSearchConfig.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/DocumentStoreDataEntity.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/DocumentStoreDataEntity.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/DocumentStoreDataEntity.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/DocumentStoreDataEntity.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/DocumentStoreDataEntityImpl.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/DocumentStoreDataEntityImpl.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/DocumentStoreDataEntityImpl.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/DocumentStoreDataEntityImpl.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/DocumentStoreInterface.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/DocumentStoreInterface.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/DocumentStoreInterface.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/DocumentStoreInterface.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchBulkOperationResult.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchBulkOperationResult.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchBulkOperationResult.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchBulkOperationResult.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchCause.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchCause.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchCause.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchCause.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchError.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchError.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchError.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchError.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpController.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpController.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpController.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpController.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpsController.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpsController.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpsController.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpsController.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchOperationStatus.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchOperationStatus.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchOperationStatus.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchOperationStatus.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchResultItem.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchResultItem.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchResultItem.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchResultItem.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchShardStatus.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchShardStatus.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchShardStatus.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchShardStatus.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/exception/DocumentStoreOperationException.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/exception/DocumentStoreOperationException.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/exception/DocumentStoreOperationException.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/exception/DocumentStoreOperationException.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/AggregationBucket.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/AggregationBucket.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/entity/AggregationBucket.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/AggregationBucket.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/AggregationResult.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/AggregationResult.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/entity/AggregationResult.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/AggregationResult.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/AggregationResults.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/AggregationResults.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/entity/AggregationResults.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/AggregationResults.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/Document.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/Document.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/entity/Document.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/Document.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/DocumentOperationResult.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/DocumentOperationResult.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/entity/DocumentOperationResult.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/DocumentOperationResult.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/ErrorResult.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/ErrorResult.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/entity/ErrorResult.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/ErrorResult.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/OperationResult.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/OperationResult.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/entity/OperationResult.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/OperationResult.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/OperationResultBuilder.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/OperationResultBuilder.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/entity/OperationResultBuilder.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/OperationResultBuilder.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/SearchHit.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/SearchHit.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/entity/SearchHit.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/SearchHit.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/SearchHits.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/SearchHits.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/entity/SearchHits.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/SearchHits.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/SearchOperationResult.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/SearchOperationResult.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/entity/SearchOperationResult.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/SearchOperationResult.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/SuggestHit.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/SuggestHit.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/entity/SuggestHit.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/SuggestHit.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/SuggestHits.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/SuggestHits.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/entity/SuggestHits.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/entity/SuggestHits.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/logging/SearchDbMsgs.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/logging/SearchDbMsgs.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/logging/SearchDbMsgs.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/logging/SearchDbMsgs.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/AbstractAggregation.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/AbstractAggregation.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/AbstractAggregation.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/AbstractAggregation.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/Aggregation.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/Aggregation.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/Aggregation.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/Aggregation.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/AggregationStatement.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/AggregationStatement.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/AggregationStatement.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/AggregationStatement.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateHistogramAggregation.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateHistogramAggregation.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateHistogramAggregation.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateHistogramAggregation.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateRange.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateRange.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateRange.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateRange.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateRangeAggregation.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateRangeAggregation.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateRangeAggregation.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateRangeAggregation.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/Filter.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/Filter.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/Filter.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/Filter.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/GroupByAggregation.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/GroupByAggregation.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/GroupByAggregation.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/GroupByAggregation.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/ParsedQuery.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/ParsedQuery.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/ParsedQuery.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/ParsedQuery.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/Query.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/Query.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/Query.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/Query.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/QueryStatement.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/QueryStatement.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/QueryStatement.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/QueryStatement.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/RangeQuery.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/RangeQuery.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/RangeQuery.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/RangeQuery.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/SearchStatement.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/SearchStatement.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/SearchStatement.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/SearchStatement.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/Sort.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/Sort.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/Sort.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/Sort.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/SuggestionStatement.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/SuggestionStatement.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/SuggestionStatement.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/SuggestionStatement.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/TermQuery.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/TermQuery.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/TermQuery.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/searchapi/TermQuery.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/service/SearchService.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/service/SearchService.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/service/SearchService.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/service/SearchService.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/util/AggregationParsingUtil.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/util/AggregationParsingUtil.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/util/AggregationParsingUtil.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/util/AggregationParsingUtil.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/util/DocumentSchemaUtil.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/util/DocumentSchemaUtil.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/util/DocumentSchemaUtil.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/util/DocumentSchemaUtil.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/util/ElasticSearchPayloadTranslator.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/util/ElasticSearchPayloadTranslator.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/util/ElasticSearchPayloadTranslator.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/util/ElasticSearchPayloadTranslator.java diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/util/SearchDbConstants.java b/search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/util/SearchDbConstants.java similarity index 100% rename from src/main/java/org/onap/aai/sa/searchdbabstraction/util/SearchDbConstants.java rename to search-data-service/src/main/java/org/onap/aai/sa/searchdbabstraction/util/SearchDbConstants.java diff --git a/src/main/resources/application.properties b/search-data-service/src/main/resources/application.properties similarity index 97% rename from src/main/resources/application.properties rename to search-data-service/src/main/resources/application.properties index 7d169a7..ae8f9c3 100644 --- a/src/main/resources/application.properties +++ b/search-data-service/src/main/resources/application.properties @@ -1,4 +1,4 @@ -server.ssl.key-store=/opt/app/search-data-service/config/auth/tomcat_keystore -server.ssl.enabled=true -server.port=9509 -server.ssl.enabled-protocols=TLSv1.1,TLSv1.2 +server.ssl.key-store=/opt/app/search-data-service/config/auth/tomcat_keystore +server.ssl.enabled=true +server.port=9509 +server.ssl.enabled-protocols=TLSv1.1,TLSv1.2 diff --git a/src/main/resources/banner.txt b/search-data-service/src/main/resources/banner.txt similarity index 100% rename from src/main/resources/banner.txt rename to search-data-service/src/main/resources/banner.txt diff --git a/src/main/resources/json/schema/analyzer.schema.json b/search-data-service/src/main/resources/json/schema/analyzer.schema.json similarity index 100% rename from src/main/resources/json/schema/analyzer.schema.json rename to search-data-service/src/main/resources/json/schema/analyzer.schema.json diff --git a/src/main/resources/json/schema/document-field.schema.json b/search-data-service/src/main/resources/json/schema/document-field.schema.json similarity index 100% rename from src/main/resources/json/schema/document-field.schema.json rename to search-data-service/src/main/resources/json/schema/document-field.schema.json diff --git a/src/main/resources/json/schema/document.schema.json b/search-data-service/src/main/resources/json/schema/document.schema.json similarity index 100% rename from src/main/resources/json/schema/document.schema.json rename to search-data-service/src/main/resources/json/schema/document.schema.json diff --git a/src/main/resources/json/schema/filter.schema.json b/search-data-service/src/main/resources/json/schema/filter.schema.json similarity index 100% rename from src/main/resources/json/schema/filter.schema.json rename to search-data-service/src/main/resources/json/schema/filter.schema.json diff --git a/src/main/resources/logging/SearchDbMsgs.properties b/search-data-service/src/main/resources/logging/SearchDbMsgs.properties similarity index 100% rename from src/main/resources/logging/SearchDbMsgs.properties rename to search-data-service/src/main/resources/logging/SearchDbMsgs.properties diff --git a/src/test/java/org/onap/aai/sa/auth/SearchDbServiceAuthTest.java b/search-data-service/src/test/java/org/onap/aai/sa/auth/SearchDbServiceAuthTest.java similarity index 97% rename from src/test/java/org/onap/aai/sa/auth/SearchDbServiceAuthTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/auth/SearchDbServiceAuthTest.java index a4b5395..97e928e 100644 --- a/src/test/java/org/onap/aai/sa/auth/SearchDbServiceAuthTest.java +++ b/search-data-service/src/test/java/org/onap/aai/sa/auth/SearchDbServiceAuthTest.java @@ -1,86 +1,86 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ -package org.onap.aai.sa.auth; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.onap.aai.sa.searchdbabstraction.util.SearchDbConstants; -import org.springframework.http.HttpHeaders; - -// import javax.servlet.http.Cookie; - -public class SearchDbServiceAuthTest { - - @Mock - HttpHeaders headers; - - // @Mock - // Cookie mockedCookie; - - @Before - public void setUp() throws NoSuchFieldException, IllegalAccessException, IOException { - MockitoAnnotations.initMocks(this); - System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); - setFinalStatic(System.getProperty("AJSC_HOME") + "/src/test/resources/json/search_policy.json"); - } - - @Test - public void testAuthUser() { - SearchDbServiceAuth aaiAuth = new SearchDbServiceAuth(); - String auth = aaiAuth.authUser(headers, "user-1", "function-1"); - Assert.assertEquals(auth, "AAI_9101"); - } - - // @Test - // public void testAuthCookie_NullCookie(){ - // SearchDbServiceAuth aaiAuth = new SearchDbServiceAuth(); - // Cookie cookie = null; - // Assert.assertFalse(aaiAuth.authCookie(cookie, "function-1", new StringBuilder("user-1"))); - // } - - // @Test - // public void testAuthCookie_NotNullCookie(){ - // SearchDbServiceAuth aaiAuth = new SearchDbServiceAuth(); - // Cookie cookie = new Cookie ( "TestCookie", "TestValue"); - // // Cookie cookie = new Cookie ( "TestCookie", "TestValue" ); - // boolean retValue = aaiAuth.authCookie(cookie, "GET:testFunction", new StringBuilder("testuser")); - // Assert.assertTrue(retValue); - // } - - static void setFinalStatic(String fieldValue) - throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - Field configField = SearchDbConstants.class.getDeclaredField("SDB_AUTH_CONFIG_FILENAME"); - configField.setAccessible(true); - - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - modifiersField.setInt(configField, configField.getModifiers() & ~Modifier.FINAL); - - configField.set(null, fieldValue); - } -} +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.aai.sa.auth; + +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.onap.aai.sa.searchdbabstraction.util.SearchDbConstants; +import org.springframework.http.HttpHeaders; + +// import javax.servlet.http.Cookie; + +public class SearchDbServiceAuthTest { + + @Mock + HttpHeaders headers; + + // @Mock + // Cookie mockedCookie; + + @Before + public void setUp() throws NoSuchFieldException, IllegalAccessException, IOException { + MockitoAnnotations.initMocks(this); + System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/')); + setFinalStatic(System.getProperty("AJSC_HOME") + "/src/test/resources/json/search_policy.json"); + } + + @Test + public void testAuthUser() { + SearchDbServiceAuth aaiAuth = new SearchDbServiceAuth(); + String auth = aaiAuth.authUser(headers, "user-1", "function-1"); + Assert.assertEquals(auth, "AAI_9101"); + } + + // @Test + // public void testAuthCookie_NullCookie(){ + // SearchDbServiceAuth aaiAuth = new SearchDbServiceAuth(); + // Cookie cookie = null; + // Assert.assertFalse(aaiAuth.authCookie(cookie, "function-1", new StringBuilder("user-1"))); + // } + + // @Test + // public void testAuthCookie_NotNullCookie(){ + // SearchDbServiceAuth aaiAuth = new SearchDbServiceAuth(); + // Cookie cookie = new Cookie ( "TestCookie", "TestValue"); + // // Cookie cookie = new Cookie ( "TestCookie", "TestValue" ); + // boolean retValue = aaiAuth.authCookie(cookie, "GET:testFunction", new StringBuilder("testuser")); + // Assert.assertTrue(retValue); + // } + + static void setFinalStatic(String fieldValue) + throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { + Field configField = SearchDbConstants.class.getDeclaredField("SDB_AUTH_CONFIG_FILENAME"); + configField.setAccessible(true); + + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(configField, configField.getModifiers() & ~Modifier.FINAL); + + configField.set(null, fieldValue); + } +} diff --git a/src/test/java/org/onap/aai/sa/rest/ApiUtilsTest.java b/search-data-service/src/test/java/org/onap/aai/sa/rest/ApiUtilsTest.java similarity index 100% rename from src/test/java/org/onap/aai/sa/rest/ApiUtilsTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/rest/ApiUtilsTest.java diff --git a/src/test/java/org/onap/aai/sa/rest/BulkApiTest.java b/search-data-service/src/test/java/org/onap/aai/sa/rest/BulkApiTest.java similarity index 100% rename from src/test/java/org/onap/aai/sa/rest/BulkApiTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/rest/BulkApiTest.java diff --git a/src/test/java/org/onap/aai/sa/rest/BulkRequestTest.java b/search-data-service/src/test/java/org/onap/aai/sa/rest/BulkRequestTest.java similarity index 97% rename from src/test/java/org/onap/aai/sa/rest/BulkRequestTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/rest/BulkRequestTest.java index d5999b8..7d784d1 100644 --- a/src/test/java/org/onap/aai/sa/rest/BulkRequestTest.java +++ b/search-data-service/src/test/java/org/onap/aai/sa/rest/BulkRequestTest.java @@ -1,149 +1,149 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ -package org.onap.aai.sa.rest; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -@AutoConfigureMockMvc -public class BulkRequestTest { - - @Test - public void testBulkRequest_Delete() { - BulkRequest request = new BulkRequest(); - BulkOperation operation = new BulkOperation(); - Document document = new Document(); - BulkMetaData metaData = getMetaData(); - operation.setMetaData(metaData); - operation.setDocument(document); - Assert.assertNotNull(operation.getDocument()); - Assert.assertNotNull(operation.getMetaData()); - Assert.assertNotNull(operation.toString()); - - request.setDelete(operation); - Assert.assertNotNull(request.getDelete()); - Assert.assertEquals(operation, request.getOperation()); - Assert.assertEquals(BulkRequest.OperationType.DELETE, request.getOperationType()); - Assert.assertTrue(request.toString().contains("delete:")); - - - } - - @Test - public void testBulkRequest_Update() { - BulkRequest request = new BulkRequest(); - BulkOperation operation = new BulkOperation(); - Document document = new Document(); - BulkMetaData metaData = getMetaData(); - operation.setMetaData(metaData); - operation.setDocument(document); - Assert.assertNotNull(operation.getDocument()); - Assert.assertNotNull(operation.getMetaData()); - Assert.assertNotNull(operation.toString()); - - request.setUpdate(operation); - Assert.assertNotNull(request.getUpdate()); - Assert.assertEquals(operation, request.getOperation()); - Assert.assertEquals(BulkRequest.OperationType.UPDATE, request.getOperationType()); - Assert.assertTrue(request.toString().contains("update:")); - - } - - @Test - public void testBulkRequest_Create() { - BulkRequest request = new BulkRequest(); - BulkOperation operation = new BulkOperation(); - Document document = new Document(); - BulkMetaData metaData = getMetaData(); - operation.setMetaData(metaData); - operation.setDocument(document); - Assert.assertNotNull(operation.getDocument()); - Assert.assertNotNull(operation.getMetaData()); - Assert.assertNotNull(operation.toString()); - - request.setCreate(operation); - Assert.assertNotNull(request.getCreate()); - Assert.assertEquals(operation, request.getOperation()); - Assert.assertEquals(BulkRequest.OperationType.CREATE, request.getOperationType()); - Assert.assertTrue(request.toString().contains("create:")); - - } - - @Test - public void testBulkRequest_Undefined() { - BulkRequest request = new BulkRequest(); - Assert.assertNull(request.getOperation()); - Assert.assertNull(request.getOperationType()); - Assert.assertEquals("UNDEFINED", request.toString()); - } - - @Test - public void testGetIndex() { - BulkRequest request = new BulkRequest(); - BulkOperation operation = new BulkOperation(); - BulkMetaData metaData = new BulkMetaData(); - metaData.setUrl("/test/indexes/index1"); - operation.setMetaData(metaData); - request.setCreate(operation); - String index = request.getIndex(); - Assert.assertEquals(index, "index1"); - } - - @Test - public void testGetId() { - BulkRequest request = new BulkRequest(); - BulkOperation operation = new BulkOperation(); - BulkMetaData metaData = new BulkMetaData(); - metaData.setUrl("/test/documents/document1"); - operation.setMetaData(metaData); - request.setCreate(operation); - String index = request.getId(); - Assert.assertEquals(index, "document1"); - } - - @Test - public void testApiUtils() { - Assert.assertEquals("services/search-data-service/v1/search/indexes/index1", ApiUtils.buildIndexUri("index1")); - Assert.assertEquals("services/search-data-service/v1/search/indexes/index1/documents/document1", - ApiUtils.buildDocumentUri("index1", "document1")); - Assert.assertTrue(ApiUtils.validateIndexUri("services/search-data-service/v1/search/indexes/index1")); - Assert.assertTrue(ApiUtils.validateDocumentUri( - "services/search-data-service/v1/search/indexes/index1/documents/document1", true)); - Assert.assertTrue(ApiUtils.validateDocumentUri( - "services/search-data-service/v1/search/indexes/index1/documents/document1", false)); - } - - private BulkMetaData getMetaData() { - BulkMetaData metaData = new BulkMetaData(); - metaData.setUrl("http://127.0.0.1"); - metaData.setEtag("etag-1"); - Assert.assertEquals(metaData.getUrl(), "http://127.0.0.1"); - Assert.assertEquals(metaData.getEtag(), "etag-1"); - Assert.assertNotNull(metaData.toString()); - return metaData; - } -} +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.aai.sa.rest; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +@AutoConfigureMockMvc +public class BulkRequestTest { + + @Test + public void testBulkRequest_Delete() { + BulkRequest request = new BulkRequest(); + BulkOperation operation = new BulkOperation(); + Document document = new Document(); + BulkMetaData metaData = getMetaData(); + operation.setMetaData(metaData); + operation.setDocument(document); + Assert.assertNotNull(operation.getDocument()); + Assert.assertNotNull(operation.getMetaData()); + Assert.assertNotNull(operation.toString()); + + request.setDelete(operation); + Assert.assertNotNull(request.getDelete()); + Assert.assertEquals(operation, request.getOperation()); + Assert.assertEquals(BulkRequest.OperationType.DELETE, request.getOperationType()); + Assert.assertTrue(request.toString().contains("delete:")); + + + } + + @Test + public void testBulkRequest_Update() { + BulkRequest request = new BulkRequest(); + BulkOperation operation = new BulkOperation(); + Document document = new Document(); + BulkMetaData metaData = getMetaData(); + operation.setMetaData(metaData); + operation.setDocument(document); + Assert.assertNotNull(operation.getDocument()); + Assert.assertNotNull(operation.getMetaData()); + Assert.assertNotNull(operation.toString()); + + request.setUpdate(operation); + Assert.assertNotNull(request.getUpdate()); + Assert.assertEquals(operation, request.getOperation()); + Assert.assertEquals(BulkRequest.OperationType.UPDATE, request.getOperationType()); + Assert.assertTrue(request.toString().contains("update:")); + + } + + @Test + public void testBulkRequest_Create() { + BulkRequest request = new BulkRequest(); + BulkOperation operation = new BulkOperation(); + Document document = new Document(); + BulkMetaData metaData = getMetaData(); + operation.setMetaData(metaData); + operation.setDocument(document); + Assert.assertNotNull(operation.getDocument()); + Assert.assertNotNull(operation.getMetaData()); + Assert.assertNotNull(operation.toString()); + + request.setCreate(operation); + Assert.assertNotNull(request.getCreate()); + Assert.assertEquals(operation, request.getOperation()); + Assert.assertEquals(BulkRequest.OperationType.CREATE, request.getOperationType()); + Assert.assertTrue(request.toString().contains("create:")); + + } + + @Test + public void testBulkRequest_Undefined() { + BulkRequest request = new BulkRequest(); + Assert.assertNull(request.getOperation()); + Assert.assertNull(request.getOperationType()); + Assert.assertEquals("UNDEFINED", request.toString()); + } + + @Test + public void testGetIndex() { + BulkRequest request = new BulkRequest(); + BulkOperation operation = new BulkOperation(); + BulkMetaData metaData = new BulkMetaData(); + metaData.setUrl("/test/indexes/index1"); + operation.setMetaData(metaData); + request.setCreate(operation); + String index = request.getIndex(); + Assert.assertEquals(index, "index1"); + } + + @Test + public void testGetId() { + BulkRequest request = new BulkRequest(); + BulkOperation operation = new BulkOperation(); + BulkMetaData metaData = new BulkMetaData(); + metaData.setUrl("/test/documents/document1"); + operation.setMetaData(metaData); + request.setCreate(operation); + String index = request.getId(); + Assert.assertEquals(index, "document1"); + } + + @Test + public void testApiUtils() { + Assert.assertEquals("services/search-data-service/v1/search/indexes/index1", ApiUtils.buildIndexUri("index1")); + Assert.assertEquals("services/search-data-service/v1/search/indexes/index1/documents/document1", + ApiUtils.buildDocumentUri("index1", "document1")); + Assert.assertTrue(ApiUtils.validateIndexUri("services/search-data-service/v1/search/indexes/index1")); + Assert.assertTrue(ApiUtils.validateDocumentUri( + "services/search-data-service/v1/search/indexes/index1/documents/document1", true)); + Assert.assertTrue(ApiUtils.validateDocumentUri( + "services/search-data-service/v1/search/indexes/index1/documents/document1", false)); + } + + private BulkMetaData getMetaData() { + BulkMetaData metaData = new BulkMetaData(); + metaData.setUrl("http://127.0.0.1"); + metaData.setEtag("etag-1"); + Assert.assertEquals(metaData.getUrl(), "http://127.0.0.1"); + Assert.assertEquals(metaData.getEtag(), "etag-1"); + Assert.assertNotNull(metaData.toString()); + return metaData; + } +} diff --git a/src/test/java/org/onap/aai/sa/rest/DocumentApiTest.java b/search-data-service/src/test/java/org/onap/aai/sa/rest/DocumentApiTest.java similarity index 100% rename from src/test/java/org/onap/aai/sa/rest/DocumentApiTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/rest/DocumentApiTest.java diff --git a/src/test/java/org/onap/aai/sa/rest/DocumentSchemaTest.java b/search-data-service/src/test/java/org/onap/aai/sa/rest/DocumentSchemaTest.java similarity index 100% rename from src/test/java/org/onap/aai/sa/rest/DocumentSchemaTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/rest/DocumentSchemaTest.java diff --git a/src/test/java/org/onap/aai/sa/rest/DocumentTest.java b/search-data-service/src/test/java/org/onap/aai/sa/rest/DocumentTest.java similarity index 98% rename from src/test/java/org/onap/aai/sa/rest/DocumentTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/rest/DocumentTest.java index e780e3b..e4cf335 100644 --- a/src/test/java/org/onap/aai/sa/rest/DocumentTest.java +++ b/search-data-service/src/test/java/org/onap/aai/sa/rest/DocumentTest.java @@ -1,727 +1,727 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ -package org.onap.aai.sa.rest; - -import com.fasterxml.jackson.core.JsonProcessingException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -// import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MultivaluedMap; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.onap.aai.sa.searchdbabstraction.elasticsearch.config.ElasticSearchConfig; -import org.onap.aai.sa.searchdbabstraction.elasticsearch.dao.DocumentStoreDataEntity; -import org.onap.aai.sa.searchdbabstraction.elasticsearch.dao.DocumentStoreInterface; -import org.onap.aai.sa.searchdbabstraction.elasticsearch.dao.ElasticSearchHttpController; -import org.onap.aai.sa.searchdbabstraction.elasticsearch.exception.DocumentStoreOperationException; -import org.onap.aai.sa.searchdbabstraction.entity.DocumentOperationResult; -import org.onap.aai.sa.searchdbabstraction.entity.ErrorResult; -import org.onap.aai.sa.searchdbabstraction.entity.SearchHits; -import org.onap.aai.sa.searchdbabstraction.entity.SearchOperationResult; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import java.util.Properties; - - -public class DocumentTest { - - @Mock - SearchServiceApi searchServiceApi; - - @Mock - HttpServletRequest request; - - @Mock - HttpHeaders headers; - - @Mock - HttpServletResponse httpResponse; - - @Mock - DocumentStoreInterface documentStore; - - @Mock - MultivaluedMap multivaluedMap; - - @InjectMocks - IndexApi indexApi; - - DocumentApi documentApi; - - @Mock - ElasticSearchHttpController httpController; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - documentApi = new DocumentApi(searchServiceApi); - } - - @Test - public void testDocumentClass_AllMethods() throws JsonProcessingException { - Document doc = new Document(); - doc.setField("name-1", "value-1"); - Assert.assertTrue(doc.getFields().size() == 1); - Assert.assertTrue(doc.toJson().contains("value-1")); - Assert.assertNotNull(doc.toString()); - Assert.assertTrue(doc.toString().contains("name-1")); - } - - @Test - public void testProcessPost_NullContent() { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - String content = null; - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap); - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - ResponseEntity response = - documentApi.processPost(content, request, headers, httpResponse, "index", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.BAD_REQUEST.value() == response.getStatusCodeValue()); - } - - @SuppressWarnings("unchecked") - @Test - public void testProcessPost_NotNullContent() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - String content = "content"; - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap); - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenThrow(IllegalArgumentException.class); - ResponseEntity response = - documentApi.processPost(content, request, headers, httpResponse, "index", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); - } - - // - @Test - public void testProcessPost_ValidRequest() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - String content = "content"; - DocumentOperationResult result = new DocumentOperationResult(); - result.setResultCode(150); - result.setError(new ErrorResult("type-1", "reason-1")); - result.setFailureCause("test-failure"); - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap); - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenReturn(true); - Mockito.when(documentStore.createDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class), - Mockito.anyBoolean())).thenReturn(result); - Mockito.doNothing().when(httpResponse).setHeader(Mockito.anyString(), Mockito.anyString()); - ResponseEntity response = - documentApi.processPost(content, request, headers, httpResponse, "index", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.INTERNAL_SERVER_ERROR.value() == response.getStatusCodeValue()); - } - - // - @Test - public void testProcessSearchWithGet_Created() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - String content = "content"; - SearchOperationResult result = new SearchOperationResult(); - result.setResultCode(201); - SearchHits hits = new SearchHits(); - hits.setTotalHits("2"); - result.setSearchResult(hits); - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap); - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenReturn(true); - Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result); - ResponseEntity response = - documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.CREATED.value() == response.getStatusCodeValue()); - - } - - @SuppressWarnings("unchecked") - @Test - public void testProcessSearchWithGet_ValidateThrowsException() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - String content = "content"; - SearchOperationResult result = new SearchOperationResult(); - result.setResultCode(201); - SearchHits hits = new SearchHits(); - hits.setTotalHits("2"); - result.setSearchResult(hits); - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap); - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenThrow(IllegalArgumentException.class); - Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result); - ResponseEntity response = - documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); - - } - - @Test - public void testProcessSearchWithGet_ValidateIsFalse() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - String content = "content"; - SearchOperationResult result = new SearchOperationResult(); - result.setResultCode(201); - SearchHits hits = new SearchHits(); - hits.setTotalHits("2"); - result.setSearchResult(hits); - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap); - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenReturn(false); - Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result); - ResponseEntity response = - documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); - - } - - @Test - public void testProcessSearchWithGet_InvalidResult() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - String content = "content"; - SearchOperationResult result = new SearchOperationResult(); - result.setResultCode(302); - SearchHits hits = new SearchHits(); - hits.setTotalHits("2"); - result.setSearchResult(hits); - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenReturn(true); - Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result); - ResponseEntity response = - documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue()); - - } - - @Test - public void testProcessPut_NullContent() { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - String content = null; - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - ResponseEntity response = - documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.BAD_REQUEST.value() == response.getStatusCodeValue()); - } - - @SuppressWarnings("unchecked") - @Test - public void testProcessPut_RequestThrowsException() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - String content = "content"; - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenThrow(IllegalArgumentException.class); - ResponseEntity response = - documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); - } - - @Test - public void testProcessPut_RequestInvalid() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - String content = "content"; - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenReturn(false); - ResponseEntity response = - documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); - } - - @Test - public void testProcessPut_ResultInvalid() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - String content = "content"; - DocumentOperationResult result = new DocumentOperationResult(); - result.setResultCode(302); - result.setError(new ErrorResult("type-1", "reason-1")); - result.setFailureCause("test-failure"); - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenReturn(true); - Mockito.when(documentStore.createDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class), - Mockito.anyBoolean())).thenReturn(result); - ResponseEntity response = - documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue()); - } - - @SuppressWarnings("unchecked") - @Test - public void testProcessDelete_RequestThrowsException() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - String content = "content"; - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenThrow(IllegalArgumentException.class); - ResponseEntity response = - documentApi.processDelete(content, request, headers, httpResponse, "index", "id-1", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); - } - - @Test - public void testProcessDelete_RequestInvalid() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - String content = "content"; - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenReturn(false); - ResponseEntity response = - documentApi.processDelete(content, request, headers, httpResponse, "index", "id-1", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); - } - - @Ignore - @Test - public void testProcessDelete_ResultInvalid() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - String content = "content"; - DocumentOperationResult result = new DocumentOperationResult(); - result.setResultCode(302); - result.setError(new ErrorResult("type-1", "reason-1")); - result.setFailureCause("test-failure"); - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenReturn(true); - Mockito.when(documentStore.deleteDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class))) - .thenReturn(result); - ResponseEntity response = - documentApi.processDelete(content, request, headers, httpResponse, "index", "id-1", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue()); - } - - @SuppressWarnings("unchecked") - @Test - public void testProcessGet_RequestThrowsException() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - String content = "content"; - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenThrow(IllegalArgumentException.class); - ResponseEntity response = - documentApi.processGet(content, request, headers, httpResponse, "index", "id-1", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); - } - - @Test - public void testProcessGet_RequestInvalid() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - String content = "content"; - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenReturn(false); - ResponseEntity response = - documentApi.processGet(content, request, headers, httpResponse, "index", "id-1", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); - } - - @Test - public void testProcessGet_ResultInvalid() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - String content = "content"; - DocumentOperationResult result = new DocumentOperationResult(); - result.setResultCode(302); - result.setError(new ErrorResult("type-1", "reason-1")); - result.setFailureCause("test-failure"); - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenReturn(true); - Mockito.when(documentStore.getDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class))) - .thenReturn(result); - ResponseEntity response = - documentApi.processGet(content, request, headers, httpResponse, "index", "id-1", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue()); - } - - @Test - public void testQueryWithGetWithPayload_NullContent() { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - String content = null; - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - ResponseEntity response = - documentApi.queryWithGetWithPayload(content, request, headers, "index-1", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.BAD_REQUEST.value() == response.getStatusCodeValue()); - } - - @SuppressWarnings("unchecked") - @Test - public void testQueryWithGetWithPayload_RequestThrowsException() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - String content = "content"; - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenThrow(IllegalArgumentException.class); - ResponseEntity response = - documentApi.queryWithGetWithPayload(content, request, headers, "index-1", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); - } - - @Test - public void testQueryWithGetWithPayload_RequestInvalid() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - String content = "content"; - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenReturn(false); - ResponseEntity response = - documentApi.queryWithGetWithPayload(content, request, headers, "index-1", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); - } - - @Test - public void testCreateProcessIndex_IndexApi_RequestInvalid() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenReturn(false); - ResponseEntity response = - indexApi.processCreateIndex("document-1", request, headers, "index-1", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); - } - - @SuppressWarnings("unchecked") - @Test - public void testCreateProcessIndex_IndexApi_RequestThrowsException() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenThrow(IllegalArgumentException.class); - ResponseEntity response = - indexApi.processCreateIndex("document-1", request, headers, "index-1", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); - } - - @Test - public void testCreateProcessIndex_IndexApi_NullDocument() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - String documentSchema = null; - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenReturn(true); - ResponseEntity response = - indexApi.processCreateIndex(documentSchema, request, headers, "index-1", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.INTERNAL_SERVER_ERROR.value() == response.getStatusCodeValue()); - } - - @Test - public void testProcessDelete_IndexApi_RequestInvalid() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenReturn(false); - ResponseEntity response = indexApi.processDelete("document-1", request, headers, documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); - } - - @SuppressWarnings("unchecked") - @Test - public void testProcessDelete_IndexApi_RequestThrowsException() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenThrow(IllegalArgumentException.class); - ResponseEntity response = indexApi.processDelete("document-1", request, headers, documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); - } - - @SuppressWarnings("unchecked") - @Test - public void testProcessDelete_IndexApi_DeleteIndexException() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenReturn(true); - Mockito.when(documentStore.deleteIndex(Mockito.anyString())).thenThrow(DocumentStoreOperationException.class); - ResponseEntity response = indexApi.processDelete("document-1", request, headers, documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.INTERNAL_SERVER_ERROR.value() == response.getStatusCodeValue()); - } - - @Test - public void testUserAuthorization() throws Exception { - String transactionId = "transactionId-1"; - String remoteAddr = "http://127.0.0.1"; - String content = "content"; - // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; - Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); - Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); - Mockito.when(request.getMethod()).thenReturn("testMethod"); - Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); - Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), - Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) - .thenCallRealMethod(); - - Mockito.doAnswer(new Answer() { - public ElasticSearchConfig answer(InvocationOnMock invocation) { - Properties properties = new Properties(); - return new ElasticSearchConfig(properties); - } - }).when(httpController).getElasticSearchConfig(); - - searchServiceApi.documentStore = httpController; - - ResponseEntity response = - documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); - - Mockito.doAnswer(new Answer() { - public ElasticSearchConfig answer(InvocationOnMock invocation) { - Properties properties = new Properties(); - properties.put(ElasticSearchConfig.ES_AUTH_ENABLED, "true"); - return new ElasticSearchConfig(properties); - } - }).when(httpController).getElasticSearchConfig(); - - - response = documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); - - Mockito.doAnswer(new Answer() { - public ElasticSearchConfig answer(InvocationOnMock invocation) { - Properties properties = new Properties(); - properties.put(ElasticSearchConfig.ES_AUTH_ENABLED, "false"); - return new ElasticSearchConfig(properties); - } - }).when(httpController).getElasticSearchConfig(); - - DocumentOperationResult result = new DocumentOperationResult(); - result.setResultCode(302); - result.setError(new ErrorResult("type-1", "reason-1")); - result.setFailureCause("test-failure"); - Mockito.when(documentStore.createDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class), - Mockito.anyBoolean())).thenReturn(result); - response = documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore); - Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue()); - - } +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.aai.sa.rest; + +import com.fasterxml.jackson.core.JsonProcessingException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +// import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MultivaluedMap; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import org.onap.aai.sa.searchdbabstraction.elasticsearch.config.ElasticSearchConfig; +import org.onap.aai.sa.searchdbabstraction.elasticsearch.dao.DocumentStoreDataEntity; +import org.onap.aai.sa.searchdbabstraction.elasticsearch.dao.DocumentStoreInterface; +import org.onap.aai.sa.searchdbabstraction.elasticsearch.dao.ElasticSearchHttpController; +import org.onap.aai.sa.searchdbabstraction.elasticsearch.exception.DocumentStoreOperationException; +import org.onap.aai.sa.searchdbabstraction.entity.DocumentOperationResult; +import org.onap.aai.sa.searchdbabstraction.entity.ErrorResult; +import org.onap.aai.sa.searchdbabstraction.entity.SearchHits; +import org.onap.aai.sa.searchdbabstraction.entity.SearchOperationResult; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import java.util.Properties; + + +public class DocumentTest { + + @Mock + SearchServiceApi searchServiceApi; + + @Mock + HttpServletRequest request; + + @Mock + HttpHeaders headers; + + @Mock + HttpServletResponse httpResponse; + + @Mock + DocumentStoreInterface documentStore; + + @Mock + MultivaluedMap multivaluedMap; + + @InjectMocks + IndexApi indexApi; + + DocumentApi documentApi; + + @Mock + ElasticSearchHttpController httpController; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + documentApi = new DocumentApi(searchServiceApi); + } + + @Test + public void testDocumentClass_AllMethods() throws JsonProcessingException { + Document doc = new Document(); + doc.setField("name-1", "value-1"); + Assert.assertTrue(doc.getFields().size() == 1); + Assert.assertTrue(doc.toJson().contains("value-1")); + Assert.assertNotNull(doc.toString()); + Assert.assertTrue(doc.toString().contains("name-1")); + } + + @Test + public void testProcessPost_NullContent() { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + String content = null; + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap); + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + ResponseEntity response = + documentApi.processPost(content, request, headers, httpResponse, "index", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.BAD_REQUEST.value() == response.getStatusCodeValue()); + } + + @SuppressWarnings("unchecked") + @Test + public void testProcessPost_NotNullContent() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + String content = "content"; + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap); + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenThrow(IllegalArgumentException.class); + ResponseEntity response = + documentApi.processPost(content, request, headers, httpResponse, "index", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); + } + + // + @Test + public void testProcessPost_ValidRequest() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + String content = "content"; + DocumentOperationResult result = new DocumentOperationResult(); + result.setResultCode(150); + result.setError(new ErrorResult("type-1", "reason-1")); + result.setFailureCause("test-failure"); + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap); + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenReturn(true); + Mockito.when(documentStore.createDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class), + Mockito.anyBoolean())).thenReturn(result); + Mockito.doNothing().when(httpResponse).setHeader(Mockito.anyString(), Mockito.anyString()); + ResponseEntity response = + documentApi.processPost(content, request, headers, httpResponse, "index", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.INTERNAL_SERVER_ERROR.value() == response.getStatusCodeValue()); + } + + // + @Test + public void testProcessSearchWithGet_Created() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + String content = "content"; + SearchOperationResult result = new SearchOperationResult(); + result.setResultCode(201); + SearchHits hits = new SearchHits(); + hits.setTotalHits("2"); + result.setSearchResult(hits); + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap); + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenReturn(true); + Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result); + ResponseEntity response = + documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.CREATED.value() == response.getStatusCodeValue()); + + } + + @SuppressWarnings("unchecked") + @Test + public void testProcessSearchWithGet_ValidateThrowsException() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + String content = "content"; + SearchOperationResult result = new SearchOperationResult(); + result.setResultCode(201); + SearchHits hits = new SearchHits(); + hits.setTotalHits("2"); + result.setSearchResult(hits); + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap); + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenThrow(IllegalArgumentException.class); + Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result); + ResponseEntity response = + documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); + + } + + @Test + public void testProcessSearchWithGet_ValidateIsFalse() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + String content = "content"; + SearchOperationResult result = new SearchOperationResult(); + result.setResultCode(201); + SearchHits hits = new SearchHits(); + hits.setTotalHits("2"); + result.setSearchResult(hits); + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap); + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenReturn(false); + Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result); + ResponseEntity response = + documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); + + } + + @Test + public void testProcessSearchWithGet_InvalidResult() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + String content = "content"; + SearchOperationResult result = new SearchOperationResult(); + result.setResultCode(302); + SearchHits hits = new SearchHits(); + hits.setTotalHits("2"); + result.setSearchResult(hits); + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenReturn(true); + Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result); + ResponseEntity response = + documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue()); + + } + + @Test + public void testProcessPut_NullContent() { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + String content = null; + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + ResponseEntity response = + documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.BAD_REQUEST.value() == response.getStatusCodeValue()); + } + + @SuppressWarnings("unchecked") + @Test + public void testProcessPut_RequestThrowsException() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + String content = "content"; + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenThrow(IllegalArgumentException.class); + ResponseEntity response = + documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); + } + + @Test + public void testProcessPut_RequestInvalid() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + String content = "content"; + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenReturn(false); + ResponseEntity response = + documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); + } + + @Test + public void testProcessPut_ResultInvalid() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + String content = "content"; + DocumentOperationResult result = new DocumentOperationResult(); + result.setResultCode(302); + result.setError(new ErrorResult("type-1", "reason-1")); + result.setFailureCause("test-failure"); + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenReturn(true); + Mockito.when(documentStore.createDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class), + Mockito.anyBoolean())).thenReturn(result); + ResponseEntity response = + documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue()); + } + + @SuppressWarnings("unchecked") + @Test + public void testProcessDelete_RequestThrowsException() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + String content = "content"; + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenThrow(IllegalArgumentException.class); + ResponseEntity response = + documentApi.processDelete(content, request, headers, httpResponse, "index", "id-1", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); + } + + @Test + public void testProcessDelete_RequestInvalid() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + String content = "content"; + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenReturn(false); + ResponseEntity response = + documentApi.processDelete(content, request, headers, httpResponse, "index", "id-1", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); + } + + @Ignore + @Test + public void testProcessDelete_ResultInvalid() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + String content = "content"; + DocumentOperationResult result = new DocumentOperationResult(); + result.setResultCode(302); + result.setError(new ErrorResult("type-1", "reason-1")); + result.setFailureCause("test-failure"); + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenReturn(true); + Mockito.when(documentStore.deleteDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class))) + .thenReturn(result); + ResponseEntity response = + documentApi.processDelete(content, request, headers, httpResponse, "index", "id-1", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue()); + } + + @SuppressWarnings("unchecked") + @Test + public void testProcessGet_RequestThrowsException() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + String content = "content"; + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenThrow(IllegalArgumentException.class); + ResponseEntity response = + documentApi.processGet(content, request, headers, httpResponse, "index", "id-1", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); + } + + @Test + public void testProcessGet_RequestInvalid() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + String content = "content"; + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenReturn(false); + ResponseEntity response = + documentApi.processGet(content, request, headers, httpResponse, "index", "id-1", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); + } + + @Test + public void testProcessGet_ResultInvalid() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + String content = "content"; + DocumentOperationResult result = new DocumentOperationResult(); + result.setResultCode(302); + result.setError(new ErrorResult("type-1", "reason-1")); + result.setFailureCause("test-failure"); + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenReturn(true); + Mockito.when(documentStore.getDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class))) + .thenReturn(result); + ResponseEntity response = + documentApi.processGet(content, request, headers, httpResponse, "index", "id-1", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue()); + } + + @Test + public void testQueryWithGetWithPayload_NullContent() { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + String content = null; + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + ResponseEntity response = + documentApi.queryWithGetWithPayload(content, request, headers, "index-1", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.BAD_REQUEST.value() == response.getStatusCodeValue()); + } + + @SuppressWarnings("unchecked") + @Test + public void testQueryWithGetWithPayload_RequestThrowsException() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + String content = "content"; + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenThrow(IllegalArgumentException.class); + ResponseEntity response = + documentApi.queryWithGetWithPayload(content, request, headers, "index-1", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); + } + + @Test + public void testQueryWithGetWithPayload_RequestInvalid() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + String content = "content"; + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenReturn(false); + ResponseEntity response = + documentApi.queryWithGetWithPayload(content, request, headers, "index-1", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); + } + + @Test + public void testCreateProcessIndex_IndexApi_RequestInvalid() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenReturn(false); + ResponseEntity response = + indexApi.processCreateIndex("document-1", request, headers, "index-1", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); + } + + @SuppressWarnings("unchecked") + @Test + public void testCreateProcessIndex_IndexApi_RequestThrowsException() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenThrow(IllegalArgumentException.class); + ResponseEntity response = + indexApi.processCreateIndex("document-1", request, headers, "index-1", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); + } + + @Test + public void testCreateProcessIndex_IndexApi_NullDocument() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + String documentSchema = null; + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenReturn(true); + ResponseEntity response = + indexApi.processCreateIndex(documentSchema, request, headers, "index-1", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.INTERNAL_SERVER_ERROR.value() == response.getStatusCodeValue()); + } + + @Test + public void testProcessDelete_IndexApi_RequestInvalid() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenReturn(false); + ResponseEntity response = indexApi.processDelete("document-1", request, headers, documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); + } + + @SuppressWarnings("unchecked") + @Test + public void testProcessDelete_IndexApi_RequestThrowsException() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenThrow(IllegalArgumentException.class); + ResponseEntity response = indexApi.processDelete("document-1", request, headers, documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); + } + + @SuppressWarnings("unchecked") + @Test + public void testProcessDelete_IndexApi_DeleteIndexException() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenReturn(true); + Mockito.when(documentStore.deleteIndex(Mockito.anyString())).thenThrow(DocumentStoreOperationException.class); + ResponseEntity response = indexApi.processDelete("document-1", request, headers, documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.INTERNAL_SERVER_ERROR.value() == response.getStatusCodeValue()); + } + + @Test + public void testUserAuthorization() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + String content = "content"; + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenCallRealMethod(); + + Mockito.doAnswer(new Answer() { + public ElasticSearchConfig answer(InvocationOnMock invocation) { + Properties properties = new Properties(); + return new ElasticSearchConfig(properties); + } + }).when(httpController).getElasticSearchConfig(); + + searchServiceApi.documentStore = httpController; + + ResponseEntity response = + documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); + + Mockito.doAnswer(new Answer() { + public ElasticSearchConfig answer(InvocationOnMock invocation) { + Properties properties = new Properties(); + properties.put(ElasticSearchConfig.ES_AUTH_ENABLED, "true"); + return new ElasticSearchConfig(properties); + } + }).when(httpController).getElasticSearchConfig(); + + + response = documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); + + Mockito.doAnswer(new Answer() { + public ElasticSearchConfig answer(InvocationOnMock invocation) { + Properties properties = new Properties(); + properties.put(ElasticSearchConfig.ES_AUTH_ENABLED, "false"); + return new ElasticSearchConfig(properties); + } + }).when(httpController).getElasticSearchConfig(); + + DocumentOperationResult result = new DocumentOperationResult(); + result.setResultCode(302); + result.setError(new ErrorResult("type-1", "reason-1")); + result.setFailureCause("test-failure"); + Mockito.when(documentStore.createDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class), + Mockito.anyBoolean())).thenReturn(result); + response = documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue()); + + } } \ No newline at end of file diff --git a/src/test/java/org/onap/aai/sa/rest/IndexApiTest.java b/search-data-service/src/test/java/org/onap/aai/sa/rest/IndexApiTest.java similarity index 100% rename from src/test/java/org/onap/aai/sa/rest/IndexApiTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/rest/IndexApiTest.java diff --git a/src/test/java/org/onap/aai/sa/rest/SearchServiceApiHarness.java b/search-data-service/src/test/java/org/onap/aai/sa/rest/SearchServiceApiHarness.java similarity index 100% rename from src/test/java/org/onap/aai/sa/rest/SearchServiceApiHarness.java rename to search-data-service/src/test/java/org/onap/aai/sa/rest/SearchServiceApiHarness.java diff --git a/src/test/java/org/onap/aai/sa/rest/SettingConfigurationTest.java b/search-data-service/src/test/java/org/onap/aai/sa/rest/SettingConfigurationTest.java similarity index 100% rename from src/test/java/org/onap/aai/sa/rest/SettingConfigurationTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/rest/SettingConfigurationTest.java diff --git a/src/test/java/org/onap/aai/sa/rest/StubEsController.java b/search-data-service/src/test/java/org/onap/aai/sa/rest/StubEsController.java similarity index 100% rename from src/test/java/org/onap/aai/sa/rest/StubEsController.java rename to search-data-service/src/test/java/org/onap/aai/sa/rest/StubEsController.java diff --git a/src/test/java/org/onap/aai/sa/rest/TestUtils.java b/search-data-service/src/test/java/org/onap/aai/sa/rest/TestUtils.java similarity index 100% rename from src/test/java/org/onap/aai/sa/rest/TestUtils.java rename to search-data-service/src/test/java/org/onap/aai/sa/rest/TestUtils.java diff --git a/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/config/ElasticSearchConfigTest.java b/search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/config/ElasticSearchConfigTest.java similarity index 97% rename from src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/config/ElasticSearchConfigTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/config/ElasticSearchConfigTest.java index b976f17..e840e2c 100644 --- a/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/config/ElasticSearchConfigTest.java +++ b/search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/config/ElasticSearchConfigTest.java @@ -1,53 +1,53 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ -package org.onap.aai.sa.searchdbabstraction.elasticsearch.config; - -import java.util.Properties; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; - -public class ElasticSearchConfigTest { - - @Autowired - ElasticSearchConfig elasticSearchConfig; - - @Before - public void setUp() { - Properties prop = new Properties(); - prop.put("es.cluster-name", "cluster-1"); - prop.put("es.ip-address", "127.0.0.1"); - prop.put("es.http-port", "9001"); - // elasticSearchConfig = new ElasticSearchConfig(prop); - } - - @Ignore - @Test - public void testAllGetMethods() { - Assert.assertEquals(elasticSearchConfig.getClusterName(), "cluster-1"); - Assert.assertEquals(elasticSearchConfig.getIpAddress(), "127.0.0.1"); - Assert.assertEquals(elasticSearchConfig.getHttpPort(), "9001"); - Assert.assertEquals(elasticSearchConfig.getJavaApiPort(), "9300"); - Assert.assertNotNull(elasticSearchConfig.toString()); - } -} +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.aai.sa.searchdbabstraction.elasticsearch.config; + +import java.util.Properties; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +public class ElasticSearchConfigTest { + + @Autowired + ElasticSearchConfig elasticSearchConfig; + + @Before + public void setUp() { + Properties prop = new Properties(); + prop.put("es.cluster-name", "cluster-1"); + prop.put("es.ip-address", "127.0.0.1"); + prop.put("es.http-port", "9001"); + // elasticSearchConfig = new ElasticSearchConfig(prop); + } + + @Ignore + @Test + public void testAllGetMethods() { + Assert.assertEquals(elasticSearchConfig.getClusterName(), "cluster-1"); + Assert.assertEquals(elasticSearchConfig.getIpAddress(), "127.0.0.1"); + Assert.assertEquals(elasticSearchConfig.getHttpPort(), "9001"); + Assert.assertEquals(elasticSearchConfig.getJavaApiPort(), "9300"); + Assert.assertNotNull(elasticSearchConfig.toString()); + } +} diff --git a/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/AggregationResponseParsingTest.java b/search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/AggregationResponseParsingTest.java similarity index 100% rename from src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/AggregationResponseParsingTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/AggregationResponseParsingTest.java diff --git a/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpControllerTest.java b/search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpControllerTest.java similarity index 100% rename from src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpControllerTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpControllerTest.java diff --git a/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchResultItemTest.java b/search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchResultItemTest.java similarity index 97% rename from src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchResultItemTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchResultItemTest.java index 43203c9..eef7742 100644 --- a/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchResultItemTest.java +++ b/search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchResultItemTest.java @@ -1,119 +1,119 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ -package org.onap.aai.sa.searchdbabstraction.elasticsearch.dao; - -import org.junit.Assert; -import org.junit.Test; - -public class ElasticSearchResultItemTest { - - @Test - public void testAllMethods() { - ElasticSearchShardStatus shardStatus = new ElasticSearchShardStatus(); - shardStatus.setTotal(10); - shardStatus.setSuccessful(0); - shardStatus.setFailed(1); - Assert.assertEquals(shardStatus.getTotal(), 10); - Assert.assertEquals(shardStatus.getSuccessful(), 0); - Assert.assertEquals(shardStatus.getFailed(), 1); - - ElasticSearchCause cause = new ElasticSearchCause(); - cause.setType("type-1"); - cause.setReason("reason-1"); - Assert.assertEquals(cause.getType(), "type-1"); - Assert.assertEquals(cause.getReason(), "reason-1"); - - ElasticSearchError error = new ElasticSearchError(); - error.setType("type-1"); - error.setReason("reason-1"); - error.setCausedBy(cause); - Assert.assertEquals(error.getType(), "type-1"); - Assert.assertEquals(error.getReason(), "reason-1"); - Assert.assertNotNull(error.getCausedBy()); - error.setAdditionalProperties("name-1", "value-1"); - Assert.assertNotNull(error.getAdditionalProperties()); - - // Create Status - ElasticSearchResultItem resultItem1 = new ElasticSearchResultItem(); - resultItem1.setCreate(getStatus(shardStatus, error)); - Assert.assertNotNull(resultItem1.getCreate()); - Assert.assertEquals(resultItem1.operationType(), "create"); - Assert.assertEquals(resultItem1.operationStatus(), resultItem1.getCreate()); - Assert.assertTrue(resultItem1.toString().contains("create")); - Assert.assertNotNull(resultItem1.toJson()); - - // Index Status - ElasticSearchResultItem resultItem2 = new ElasticSearchResultItem(); - resultItem2.setIndex(getStatus(shardStatus, error)); - Assert.assertNotNull(resultItem2.getIndex()); - Assert.assertEquals(resultItem2.operationType(), "update"); - Assert.assertEquals(resultItem2.operationStatus(), resultItem2.getIndex()); - Assert.assertTrue(resultItem2.toString().contains("index")); - Assert.assertNotNull(resultItem2.toJson()); - - // Delete Status - ElasticSearchResultItem resultItem3 = new ElasticSearchResultItem(); - resultItem3.setDelete(getStatus(shardStatus, error)); - Assert.assertNotNull(resultItem3.getDelete()); - Assert.assertEquals(resultItem3.operationType(), "delete"); - Assert.assertEquals(resultItem3.operationStatus(), resultItem3.getDelete()); - Assert.assertTrue(resultItem3.toString().contains("delete")); - Assert.assertNotNull(resultItem3.toJson()); - - // Unknown Status - ElasticSearchResultItem resultItem4 = new ElasticSearchResultItem(); - Assert.assertEquals(resultItem4.operationType(), "unknown"); - Assert.assertNull(resultItem4.operationStatus()); - - // ElasticSearchBulkOperationResult - ElasticSearchResultItem[] resultItems = {resultItem1, resultItem2, resultItem3}; - ElasticSearchBulkOperationResult result = new ElasticSearchBulkOperationResult(); - result.setErrors(true); - result.setTook(new Integer(10)); - result.setItems(resultItems); - Assert.assertTrue(result.getErrors()); - Assert.assertEquals(result.getTook(), new Integer(10)); - Assert.assertNotNull(result.getItems()); - Assert.assertNotNull(result.toString()); - } - - private ElasticSearchOperationStatus getStatus(ElasticSearchShardStatus shardStatus, ElasticSearchError error) { - ElasticSearchOperationStatus status = new ElasticSearchOperationStatus(); - status.setIndex("index-1"); - status.setType("type-1"); - status.setId("id-1"); - status.setVersion("1.0"); - status.setShards(shardStatus); - status.setStatus(new Integer(1)); - status.setError(error); - status.setAdditionalProperties("REQUEST_URL", "http://127.0.0.1"); - Assert.assertEquals(status.getIndex(), "index-1"); - Assert.assertEquals(status.getType(), "type-1"); - Assert.assertEquals(status.getId(), "id-1"); - Assert.assertEquals(status.getVersion(), "1.0"); - Assert.assertEquals(status.getStatus(), new Integer(1)); - Assert.assertNotNull(status.getShards()); - Assert.assertNotNull(status.getError()); - Assert.assertNotNull(status.getAdditionalProperties()); - return status; - } - -} +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.aai.sa.searchdbabstraction.elasticsearch.dao; + +import org.junit.Assert; +import org.junit.Test; + +public class ElasticSearchResultItemTest { + + @Test + public void testAllMethods() { + ElasticSearchShardStatus shardStatus = new ElasticSearchShardStatus(); + shardStatus.setTotal(10); + shardStatus.setSuccessful(0); + shardStatus.setFailed(1); + Assert.assertEquals(shardStatus.getTotal(), 10); + Assert.assertEquals(shardStatus.getSuccessful(), 0); + Assert.assertEquals(shardStatus.getFailed(), 1); + + ElasticSearchCause cause = new ElasticSearchCause(); + cause.setType("type-1"); + cause.setReason("reason-1"); + Assert.assertEquals(cause.getType(), "type-1"); + Assert.assertEquals(cause.getReason(), "reason-1"); + + ElasticSearchError error = new ElasticSearchError(); + error.setType("type-1"); + error.setReason("reason-1"); + error.setCausedBy(cause); + Assert.assertEquals(error.getType(), "type-1"); + Assert.assertEquals(error.getReason(), "reason-1"); + Assert.assertNotNull(error.getCausedBy()); + error.setAdditionalProperties("name-1", "value-1"); + Assert.assertNotNull(error.getAdditionalProperties()); + + // Create Status + ElasticSearchResultItem resultItem1 = new ElasticSearchResultItem(); + resultItem1.setCreate(getStatus(shardStatus, error)); + Assert.assertNotNull(resultItem1.getCreate()); + Assert.assertEquals(resultItem1.operationType(), "create"); + Assert.assertEquals(resultItem1.operationStatus(), resultItem1.getCreate()); + Assert.assertTrue(resultItem1.toString().contains("create")); + Assert.assertNotNull(resultItem1.toJson()); + + // Index Status + ElasticSearchResultItem resultItem2 = new ElasticSearchResultItem(); + resultItem2.setIndex(getStatus(shardStatus, error)); + Assert.assertNotNull(resultItem2.getIndex()); + Assert.assertEquals(resultItem2.operationType(), "update"); + Assert.assertEquals(resultItem2.operationStatus(), resultItem2.getIndex()); + Assert.assertTrue(resultItem2.toString().contains("index")); + Assert.assertNotNull(resultItem2.toJson()); + + // Delete Status + ElasticSearchResultItem resultItem3 = new ElasticSearchResultItem(); + resultItem3.setDelete(getStatus(shardStatus, error)); + Assert.assertNotNull(resultItem3.getDelete()); + Assert.assertEquals(resultItem3.operationType(), "delete"); + Assert.assertEquals(resultItem3.operationStatus(), resultItem3.getDelete()); + Assert.assertTrue(resultItem3.toString().contains("delete")); + Assert.assertNotNull(resultItem3.toJson()); + + // Unknown Status + ElasticSearchResultItem resultItem4 = new ElasticSearchResultItem(); + Assert.assertEquals(resultItem4.operationType(), "unknown"); + Assert.assertNull(resultItem4.operationStatus()); + + // ElasticSearchBulkOperationResult + ElasticSearchResultItem[] resultItems = {resultItem1, resultItem2, resultItem3}; + ElasticSearchBulkOperationResult result = new ElasticSearchBulkOperationResult(); + result.setErrors(true); + result.setTook(new Integer(10)); + result.setItems(resultItems); + Assert.assertTrue(result.getErrors()); + Assert.assertEquals(result.getTook(), new Integer(10)); + Assert.assertNotNull(result.getItems()); + Assert.assertNotNull(result.toString()); + } + + private ElasticSearchOperationStatus getStatus(ElasticSearchShardStatus shardStatus, ElasticSearchError error) { + ElasticSearchOperationStatus status = new ElasticSearchOperationStatus(); + status.setIndex("index-1"); + status.setType("type-1"); + status.setId("id-1"); + status.setVersion("1.0"); + status.setShards(shardStatus); + status.setStatus(new Integer(1)); + status.setError(error); + status.setAdditionalProperties("REQUEST_URL", "http://127.0.0.1"); + Assert.assertEquals(status.getIndex(), "index-1"); + Assert.assertEquals(status.getType(), "type-1"); + Assert.assertEquals(status.getId(), "id-1"); + Assert.assertEquals(status.getVersion(), "1.0"); + Assert.assertEquals(status.getStatus(), new Integer(1)); + Assert.assertNotNull(status.getShards()); + Assert.assertNotNull(status.getError()); + Assert.assertNotNull(status.getAdditionalProperties()); + return status; + } + +} diff --git a/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/AggregationStatementTest.java b/search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/AggregationStatementTest.java similarity index 100% rename from src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/AggregationStatementTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/AggregationStatementTest.java diff --git a/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/AggregationTest.java b/search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/AggregationTest.java similarity index 100% rename from src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/AggregationTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/AggregationTest.java diff --git a/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateHistogramAggregationTest.java b/search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateHistogramAggregationTest.java similarity index 100% rename from src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateHistogramAggregationTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateHistogramAggregationTest.java diff --git a/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateRangeAggregationTest.java b/search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateRangeAggregationTest.java similarity index 100% rename from src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateRangeAggregationTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateRangeAggregationTest.java diff --git a/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateRangeTest.java b/search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateRangeTest.java similarity index 100% rename from src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateRangeTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/DateRangeTest.java diff --git a/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/FilterTest.java b/search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/FilterTest.java similarity index 100% rename from src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/FilterTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/FilterTest.java diff --git a/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/GroupByAggregationTest.java b/search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/GroupByAggregationTest.java similarity index 100% rename from src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/GroupByAggregationTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/GroupByAggregationTest.java diff --git a/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/QueryTest.java b/search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/QueryTest.java similarity index 100% rename from src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/QueryTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/QueryTest.java diff --git a/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/RangeQueryTest.java b/search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/RangeQueryTest.java similarity index 100% rename from src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/RangeQueryTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/RangeQueryTest.java diff --git a/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/SearchStatementTest.java b/search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/SearchStatementTest.java similarity index 100% rename from src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/SearchStatementTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/SearchStatementTest.java diff --git a/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/SortTest.java b/search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/SortTest.java similarity index 100% rename from src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/SortTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/SortTest.java diff --git a/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/TermQueryTest.java b/search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/TermQueryTest.java similarity index 98% rename from src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/TermQueryTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/TermQueryTest.java index 5a15913..9eab5f4 100644 --- a/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/TermQueryTest.java +++ b/search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/searchapi/TermQueryTest.java @@ -1,63 +1,63 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ -package org.onap.aai.sa.searchdbabstraction.searchapi; - -import com.fasterxml.jackson.databind.ObjectMapper; -import java.io.IOException; -import org.junit.Assert; -import org.junit.Test; - -public class TermQueryTest { - - @Test - public void testAllMethods() throws IOException { - String field = "searchTags.nested"; - String stringValue = "theValue.nested"; - String termQueryWithStringValueJson = "{\"field\": \"" + field + "\", \"value\": \"" + stringValue + "\"}"; - - ObjectMapper mapper = new ObjectMapper(); - TermQuery stringTermQuery = mapper.readValue(termQueryWithStringValueJson, TermQuery.class); - Assert.assertEquals(stringValue, stringTermQuery.getValue()); - Assert.assertEquals("searchTags.nested", stringTermQuery.getField()); - stringTermQuery.setOperator("operator-1"); - Assert.assertEquals("operator-1", stringTermQuery.getOperator()); - stringTermQuery.setSearchAnalyzer("search-1"); - Assert.assertEquals("search-1", stringTermQuery.getSearchAnalyzer()); - - String field1 = "searchTags-1 searchTags.second"; - String stringValue1 = "theValue-1 theValue.second"; - String multiFieldTermQueryJSon = "{\"field\": \"" + field1 + "\", \"value\": \"" + stringValue1 + "\"}"; - TermQuery multiFieldTermQuery = mapper.readValue(multiFieldTermQueryJSon, TermQuery.class); - multiFieldTermQuery.setOperator("and"); - multiFieldTermQuery.setSearchAnalyzer("search-1"); - Assert.assertNotNull(multiFieldTermQuery.toElasticSearch()); - Assert.assertNotNull(multiFieldTermQuery.pathForNestedField(field1)); - - String field2 = "search11 search2"; - String stringValue2 = "theValue1 theValue2"; - String multiFieldTermJSon = "{\"field\": \"" + field2 + "\", \"value\": \"" + stringValue2 + "\"}"; - TermQuery multiFieldTerm = mapper.readValue(multiFieldTermJSon, TermQuery.class); - multiFieldTerm.setOperator("or"); - multiFieldTerm.setSearchAnalyzer("search-1"); - Assert.assertNotNull(multiFieldTerm.toElasticSearch()); - } - -} +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.aai.sa.searchdbabstraction.searchapi; + +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; +import org.junit.Assert; +import org.junit.Test; + +public class TermQueryTest { + + @Test + public void testAllMethods() throws IOException { + String field = "searchTags.nested"; + String stringValue = "theValue.nested"; + String termQueryWithStringValueJson = "{\"field\": \"" + field + "\", \"value\": \"" + stringValue + "\"}"; + + ObjectMapper mapper = new ObjectMapper(); + TermQuery stringTermQuery = mapper.readValue(termQueryWithStringValueJson, TermQuery.class); + Assert.assertEquals(stringValue, stringTermQuery.getValue()); + Assert.assertEquals("searchTags.nested", stringTermQuery.getField()); + stringTermQuery.setOperator("operator-1"); + Assert.assertEquals("operator-1", stringTermQuery.getOperator()); + stringTermQuery.setSearchAnalyzer("search-1"); + Assert.assertEquals("search-1", stringTermQuery.getSearchAnalyzer()); + + String field1 = "searchTags-1 searchTags.second"; + String stringValue1 = "theValue-1 theValue.second"; + String multiFieldTermQueryJSon = "{\"field\": \"" + field1 + "\", \"value\": \"" + stringValue1 + "\"}"; + TermQuery multiFieldTermQuery = mapper.readValue(multiFieldTermQueryJSon, TermQuery.class); + multiFieldTermQuery.setOperator("and"); + multiFieldTermQuery.setSearchAnalyzer("search-1"); + Assert.assertNotNull(multiFieldTermQuery.toElasticSearch()); + Assert.assertNotNull(multiFieldTermQuery.pathForNestedField(field1)); + + String field2 = "search11 search2"; + String stringValue2 = "theValue1 theValue2"; + String multiFieldTermJSon = "{\"field\": \"" + field2 + "\", \"value\": \"" + stringValue2 + "\"}"; + TermQuery multiFieldTerm = mapper.readValue(multiFieldTermJSon, TermQuery.class); + multiFieldTerm.setOperator("or"); + multiFieldTerm.setSearchAnalyzer("search-1"); + Assert.assertNotNull(multiFieldTerm.toElasticSearch()); + } + +} diff --git a/src/test/java/org/onap/aai/sa/searchdbabstraction/util/ElasticSearchPayloadTranslatorTest.java b/search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/util/ElasticSearchPayloadTranslatorTest.java similarity index 100% rename from src/test/java/org/onap/aai/sa/searchdbabstraction/util/ElasticSearchPayloadTranslatorTest.java rename to search-data-service/src/test/java/org/onap/aai/sa/searchdbabstraction/util/ElasticSearchPayloadTranslatorTest.java diff --git a/src/test/resources/json/analysis-config.json b/search-data-service/src/test/resources/json/analysis-config.json similarity index 100% rename from src/test/resources/json/analysis-config.json rename to search-data-service/src/test/resources/json/analysis-config.json diff --git a/src/test/resources/json/bulk-ops-invalid.json b/search-data-service/src/test/resources/json/bulk-ops-invalid.json similarity index 100% rename from src/test/resources/json/bulk-ops-invalid.json rename to search-data-service/src/test/resources/json/bulk-ops-invalid.json diff --git a/src/test/resources/json/bulk-ops-valid.json b/search-data-service/src/test/resources/json/bulk-ops-valid.json similarity index 100% rename from src/test/resources/json/bulk-ops-valid.json rename to search-data-service/src/test/resources/json/bulk-ops-valid.json diff --git a/src/test/resources/json/dynamic-custom-template.json b/search-data-service/src/test/resources/json/dynamic-custom-template.json similarity index 100% rename from src/test/resources/json/dynamic-custom-template.json rename to search-data-service/src/test/resources/json/dynamic-custom-template.json diff --git a/src/test/resources/json/dynamicIndex.json b/search-data-service/src/test/resources/json/dynamicIndex.json similarity index 100% rename from src/test/resources/json/dynamicIndex.json rename to search-data-service/src/test/resources/json/dynamicIndex.json diff --git a/src/test/resources/json/es-payload-translation.json b/search-data-service/src/test/resources/json/es-payload-translation.json similarity index 100% rename from src/test/resources/json/es-payload-translation.json rename to search-data-service/src/test/resources/json/es-payload-translation.json diff --git a/src/test/resources/json/filter-config.json b/search-data-service/src/test/resources/json/filter-config.json similarity index 100% rename from src/test/resources/json/filter-config.json rename to search-data-service/src/test/resources/json/filter-config.json diff --git a/src/test/resources/json/index-mapping.json b/search-data-service/src/test/resources/json/index-mapping.json similarity index 100% rename from src/test/resources/json/index-mapping.json rename to search-data-service/src/test/resources/json/index-mapping.json diff --git a/src/test/resources/json/nested-document.json b/search-data-service/src/test/resources/json/nested-document.json similarity index 100% rename from src/test/resources/json/nested-document.json rename to search-data-service/src/test/resources/json/nested-document.json diff --git a/src/test/resources/json/queries/query-with-subrange.json b/search-data-service/src/test/resources/json/queries/query-with-subrange.json similarity index 100% rename from src/test/resources/json/queries/query-with-subrange.json rename to search-data-service/src/test/resources/json/queries/query-with-subrange.json diff --git a/src/test/resources/json/queries/simple-parsed-query.json b/search-data-service/src/test/resources/json/queries/simple-parsed-query.json similarity index 100% rename from src/test/resources/json/queries/simple-parsed-query.json rename to search-data-service/src/test/resources/json/queries/simple-parsed-query.json diff --git a/src/test/resources/json/search_policy.json b/search-data-service/src/test/resources/json/search_policy.json similarity index 94% rename from src/test/resources/json/search_policy.json rename to search-data-service/src/test/resources/json/search_policy.json index 63c6785..b1abe3c 100644 --- a/src/test/resources/json/search_policy.json +++ b/search-data-service/src/test/resources/json/search_policy.json @@ -1,63 +1,63 @@ -{ - "roles": [ - { - "name": "testRole", - "functions": [{ - "name": "testFunction", - "methods": [{ - "name": "GET" - }, { - "name": "DELETE" - }, { - "name": "PUT" - } - ] - } - ], - "users": [{ - "username": "testUser" - } - - ] - }, - - { - "name": "devRole", - "functions": [{ - "name": "search", - "methods": [{ - "name": "GET" - }, { - "name": "DELETE" - }, { - "name": "PUT" - } - ] - } - ], - "users": [ - { - "username": "cn=onap, ou=onap, o=onap, l=ottawa, st=ontario, c=ca" - } - - ] - }, - - { - "name": "testBasicAuth", - "functions": [{ - "name": "testBasicAuthFuncyion", - "methods": [{ - "name": "GET" - } - ] - } - ], - "users": [{ - "user": "testBasicAuthUser", - "pass": "OBF:1ytc1vu91v2p1rxf1mqh1v8s1z0d1msn1san1mqf1z0h1v9u1msl1rvf1v1p1vv11yta" - } - ] - } - ] +{ + "roles": [ + { + "name": "testRole", + "functions": [{ + "name": "testFunction", + "methods": [{ + "name": "GET" + }, { + "name": "DELETE" + }, { + "name": "PUT" + } + ] + } + ], + "users": [{ + "username": "testUser" + } + + ] + }, + + { + "name": "devRole", + "functions": [{ + "name": "search", + "methods": [{ + "name": "GET" + }, { + "name": "DELETE" + }, { + "name": "PUT" + } + ] + } + ], + "users": [ + { + "username": "cn=onap, ou=onap, o=onap, l=ottawa, st=ontario, c=ca" + } + + ] + }, + + { + "name": "testBasicAuth", + "functions": [{ + "name": "testBasicAuthFuncyion", + "methods": [{ + "name": "GET" + } + ] + } + ], + "users": [{ + "user": "testBasicAuthUser", + "pass": "OBF:1ytc1vu91v2p1rxf1mqh1v8s1z0d1msn1san1mqf1z0h1v9u1msl1rvf1v1p1vv11yta" + } + ] + } + ] } \ No newline at end of file diff --git a/src/test/resources/json/settings-config.json b/search-data-service/src/test/resources/json/settings-config.json similarity index 100% rename from src/test/resources/json/settings-config.json rename to search-data-service/src/test/resources/json/settings-config.json diff --git a/src/test/resources/json/simpleDocument.json b/search-data-service/src/test/resources/json/simpleDocument.json similarity index 100% rename from src/test/resources/json/simpleDocument.json rename to search-data-service/src/test/resources/json/simpleDocument.json diff --git a/src/test/resources/json/tier-support-document.json b/search-data-service/src/test/resources/json/tier-support-document.json similarity index 100% rename from src/test/resources/json/tier-support-document.json rename to search-data-service/src/test/resources/json/tier-support-document.json