From e71ad4704a4a16874be65f40713009e13ce4eabf Mon Sep 17 00:00:00 2001 From: Sandeep J Date: Tue, 11 Dec 2018 19:59:13 +0530 Subject: added files to convert project to spring boot also made changes to pom to add required dependencies. fix junit cases, upgrading to mockito 2.x Issue-ID: MUSIC-212 Change-Id: Ieeeaa6d62e03e962534182183aae8ae838d93eba Signed-off-by: Sandeep J --- .gitignore | 48 +- pom.xml | 947 +++++++++++---------- .../spring/data/cassandra/CassandraConfig.java | 67 ++ .../spring/data/cassandra/MusicApplication.java | 55 ++ .../java/org/onap/music/util/TestVotingApp.java | 145 ++++ src/main/resources/application.properties | 2 + .../onap/music/unittests/TestRestMusicData.java | 102 +-- .../onap/music/unittests/TestRestMusicQAPI.java | 47 +- .../org.mockito.plugins.MockMaker | 1 + .../org.mockito.plugins.StackTraceCleanerProvider | 1 + 10 files changed, 859 insertions(+), 556 deletions(-) create mode 100644 src/main/java/org/onap/music/spring/data/cassandra/CassandraConfig.java create mode 100644 src/main/java/org/onap/music/spring/data/cassandra/MusicApplication.java create mode 100644 src/main/java/org/onap/music/util/TestVotingApp.java create mode 100644 src/main/resources/application.properties create mode 100644 src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker create mode 100644 src/test/resources/mockito-extensions/org.mockito.plugins.StackTraceCleanerProvider diff --git a/.gitignore b/.gitignore index c795c9e7..570ed90e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,31 +1,27 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] +/target/ +!.mvn/wrapper/maven-wrapper.jar -# ignore all bin directories -# matches "bin" in any subfolder -bin/ - -# ignore all target directories -target/ -src/main/webapp -# ignore all files ending with ~ -*~ - -.DS_Store - -._* - -.metadata -# Eclipse stuff -.settings/ +### STS ### +.apt_generated .classpath +.factorypath .project -# Idea +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### .idea -debug-logs/ -.README.md.html +*.iws +*.iml +*.ipr -docs/Makefile -docs/_build -docs/conf.py +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +src/main/webapp/WEB-INF/classes/ +debug-logs/ diff --git a/pom.xml b/pom.xml index 7be084f9..2c90b00d 100755 --- a/pom.xml +++ b/pom.xml @@ -1,464 +1,509 @@ - + + - 4.0.0 - org.onap.music - dev-MUSIC-cassandra - jar - 3.2.1-SNAPSHOT - + 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.music + dev-MUSIC-cassandra + war + 3.2.1-SNAPSHOT + This is the MUSIC REST interface, packaged as a war file. - - UTF-8 - 1.19 - 2.25.1 - 2.0.1 - 3.4.0 - 3.4.11 + + org.springframework.boot + spring-boot-starter-parent + 2.1.0.RELEASE + + - UTF-8 - UTF-8 - - https://nexus.onap.org - /content/repositories/snapshots/ - /content/repositories/releases/ - /content/repositories/staging/ - /content/sites/site/org/onap/music/${project.version} - - ${maven.build.timestamp} - yyyy.MM.dd.HH.mm - - ${project.version}-${timestamp} - ${project.version}-latest - + + UTF-8 + 1.19 + 2.25.1 + 2.0.1 + 3.4.0 + 3.4.11 - - - ecomp-releases - ECOMP Release Repository - ${onap.nexus.url}/${releaseNexusPath} - - - ecomp-snapshots - Snapshot Repository - ${nexusproxy}/${snapshotNexusPath} - - - ecomp-staging - Staging Repository - ${nexusproxy}/${stagingNexusPath} - - + UTF-8 + UTF-8 + + https://nexus.onap.org + /content/repositories/snapshots/ + /content/repositories/releases/ + /content/repositories/staging/ + /content/sites/site/org/onap/music/${project.version} + + ${maven.build.timestamp} + yyyy.MM.dd.HH.mm + + ${project.version}-${timestamp} + ${project.version}-latest + - - dev-MUSIC-cassandra - src/main/java - src/main/webapp/WEB-INF/classes - src/test/java - target/test-classes - validate - - - src/main/resources - true - - - - - maven-eclipse-plugin - 2.9 - - - org.springframework.ide.eclipse.core.springnature - - - org.springframework.ide.eclipse.core.springbuilder - - true - true - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.5.1 - - 1.7 - 1.7 - - jar/** - - - - - maven-war-plugin - 2.4 - - WebContent - - - - org.apache.maven.plugins - maven-jar-plugin - 2.4 - - - make-a-jar - compile - - jar - - - - **/*.xml - **/*.properties - **/Sample* - - - - - - - org.apache.maven.plugins - maven-install-plugin - 2.4 - - - install - - install-file - - - jar - ${project.artifactId} - ${project.groupId} - ${project.version} - ${project.build.directory}/${project.artifactId}.jar - - - - - - + + + ecomp-releases + ECOMP Release Repository + ${onap.nexus.url}/${releaseNexusPath} + + + ecomp-snapshots + Snapshot Repository + ${nexusproxy}/${snapshotNexusPath} + + + ecomp-staging + Staging Repository + ${nexusproxy}/${stagingNexusPath} + + - - - - javax.servlet - servlet-api - 2.4 - provided - - - javax.servlet - javax.servlet-api - 3.0.1 - provided - - - - - - ch.qos.logback - logback-core - 1.2.3 - - - org.slf4j - slf4j-log4j12 - - - - - ch.qos.logback - logback-classic - 1.2.3 - - - org.slf4j - slf4j-log4j12 - - - - - com.att.eelf - eelf-core - 1.0.1-oss - - - - - - com.datastax.cassandra - cassandra-driver-core - ${cassandra.version} - - - - - - org.apache.zookeeper - zookeeper - ${zookeeper.version} - - - org.slf4j - slf4j-log4j12 - - - - - - - - com.sun.jersey - jersey-client - ${jersey1.version} - - - com.sun.jersey - jersey-server - ${jersey1.version} - - - com.sun.jersey - jersey-json - ${jersey1.version} - - - com.sun.jersey - jersey-servlet - ${jersey1.version} - - + + dev-MUSIC-cassandra + src/main/java + src/main/webapp/WEB-INF/classes + src/test/java + target/test-classes + validate + + + src/main/resources + true + + + + + maven-eclipse-plugin + 2.9 + + + org.springframework.ide.eclipse.core.springnature + + + org.springframework.ide.eclipse.core.springbuilder + + true + true + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + 1.7 + 1.7 + + jar/** + + + + + maven-war-plugin + 2.4 + + WebContent + false + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + make-a-jar + compile + + jar + + + + **/*.xml + **/*.properties + **/Sample* + + + + + + + org.apache.maven.plugins + maven-install-plugin + 2.4 + + + install + + install-file + + + jar + ${project.artifactId} + ${project.groupId} + ${project.version} + ${project.build.directory}/${project.artifactId}.jar + + + + + + - - org.apache.commons - commons-jcs-core - 2.2 - - - commons-codec - commons-codec - 1.11 - + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + javax.servlet + servlet-api + 2.4 + provided + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + + + + + io.springfox + springfox-swagger2 + 2.4.0 + + + io.springfox + springfox-swagger-ui + 2.4.0 + + + + + ch.qos.logback + logback-core + 1.2.3 + + + org.slf4j + slf4j-log4j12 + + + + + ch.qos.logback + logback-classic + 1.2.3 + + + org.slf4j + slf4j-log4j12 + + + + + com.att.eelf + eelf-core + 1.0.1-oss + + + + + com.datastax.cassandra + cassandra-driver-core + ${cassandra.version} + + + io.dropwizard.metrics + metrics-core + 3.1.0 + + + + org.springframework.boot + spring-boot-starter-data-cassandra + + + + org.apache.zookeeper + zookeeper + ${zookeeper.version} + + + org.slf4j + slf4j-log4j12 + + + + + + + com.sun.jersey + jersey-client + ${jersey1.version} + + + com.sun.jersey + jersey-server + ${jersey1.version} + + + com.sun.jersey + jersey-json + ${jersey1.version} + + + com.sun.jersey + jersey-servlet + ${jersey1.version} + + + + + org.apache.commons + commons-jcs-core + 2.2 + + + commons-codec + commons-codec + 1.11 + + + + + junit + junit + 4.12 + test + + + org.cassandraunit + cassandra-unit + 3.3.0.2 + test + + + org.apache.curator + curator-test + 2.3.0 + + + org.apache.zookeeper + zookeeper + + + org.slf4j + slf4j-log4j12 + + + test + + + + io.netty + netty-handler + 4.1.30.Final + + + com.fasterxml.jackson.core + jackson-databind + 2.9.4 + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + io.swagger + swagger-jersey-jaxrs + 1.5.18 + + + com.google.guava + guava + 18.0 + + + org.mindrot + jbcrypt + 0.4 + + + io.netty + netty-buffer + 4.1.30.Final + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.3 + + true + true + true + + https://docs.oracle.com/javase/7/docs/api/ + https://tomcat.apache.org/tomcat-7.0-doc/jspapi/ + http://docs.oracle.com/javaee/7/api/ + + + + + + + + docker + + + + io.fabric8 + docker-maven-plugin + 0.19.1 + + true + 1.23 + nexus3.onap.org:10003 + + + + onap/music/music + docker_music + + true + + ${docker.tag} + ${docker.latest.tag} + + ${project.basedir} + + artifact + + + + + + onap/music/cassandra_3_11 + docker_cassandra_sec + + true + + ${docker.tag} + ${docker.latest.tag} + + ${project.basedir}/distribution/cassandra + + + + + onap/music/cassandra_job + docker_cassandra_job + + true + + ${docker.tag} + ${docker.latest.tag} + + ${project.basedir}/distribution/cassandra_job + + + + + + + + + + + clean-images + pre-clean + + remove + + + true + music + + + + generate-images + package + + build + + + + push-images + deploy + + push + + + onap/music/music + + + + + + + + + + + ecomp-releases + Release Repository + ${nexusproxy}/${releaseNexusPath} + + + ecomp-snapshots + Snapshot Repository + ${nexusproxy}/${snapshotNexusPath} + + + + ecomp-site + dav:${nexusproxy}${sitePath} + + - - - junit - junit - 4.12 - test - - - org.cassandraunit - cassandra-unit - 3.3.0.2 - test - - - - org.apache.curator - curator-test - 2.3.0 - - - org.apache.zookeeper - zookeeper - - - org.slf4j - slf4j-log4j12 - - - test - - - org.mockito - mockito-all - 1.9.0 - test - - - - io.netty - netty-handler - 4.0.56.Final - - - com.fasterxml.jackson.core - jackson-databind - 2.9.4 - - - org.apache.httpcomponents - httpclient - 4.5.3 - - - io.swagger - swagger-jersey-jaxrs - 1.5.18 - - - com.google.guava - guava - 19.0 - - - org.mindrot - jbcrypt - 0.4 - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.10.3 - - true - true - true - - https://docs.oracle.com/javase/7/docs/api/ - https://tomcat.apache.org/tomcat-7.0-doc/jspapi/ - http://docs.oracle.com/javaee/7/api/ - - - - - - - - docker - - - - io.fabric8 - docker-maven-plugin - 0.19.1 - - true - 1.23 - nexus3.onap.org:10003 - - - - onap/music/music - docker_music - - true - - ${docker.tag} - ${docker.latest.tag} - - ${project.basedir} - - artifact - - - - - - onap/music/cassandra_music - docker_cassandra - - true - - 3.0-${timestamp} - 3.0-latest - - ${project.basedir}/distribution/cassandra - - - - - - - - - - - clean-images - pre-clean - - remove - - - true - music - - - - generate-images - package - - build - - - - push-images - deploy - - push - - - onap/music/music - - - - - - - - - - - ecomp-releases - Release Repository - ${nexusproxy}/${releaseNexusPath} - - - ecomp-snapshots - Snapshot Repository - ${nexusproxy}/${snapshotNexusPath} - - - - ecomp-site - dav:${nexusproxy}${sitePath} - - diff --git a/src/main/java/org/onap/music/spring/data/cassandra/CassandraConfig.java b/src/main/java/org/onap/music/spring/data/cassandra/CassandraConfig.java new file mode 100644 index 00000000..f35206db --- /dev/null +++ b/src/main/java/org/onap/music/spring/data/cassandra/CassandraConfig.java @@ -0,0 +1,67 @@ +/* + * ============LICENSE_START========================================== + * org.onap.music + * =================================================================== + * Copyright (c) 2018 IBM. + * =================================================================== + * 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.music.spring.data.cassandra; + +import java.util.Arrays; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; +import org.springframework.data.cassandra.config.AbstractCassandraConfiguration; +import org.springframework.data.cassandra.config.SchemaAction; +import org.springframework.data.cassandra.core.cql.keyspace.CreateKeyspaceSpecification; + +@Configuration +public class CassandraConfig extends AbstractCassandraConfiguration { + @Autowired + private Environment env; + + private static String KEYSPACE; + + @Override + public SchemaAction getSchemaAction() { + return SchemaAction.CREATE_IF_NOT_EXISTS; + } + + @Override + protected List getKeyspaceCreations() { + String keyspace = env.getProperty("keyspace.name") + System.currentTimeMillis(); + KEYSPACE=keyspace; + CreateKeyspaceSpecification specification = null; + specification = CreateKeyspaceSpecification.createKeyspace(KEYSPACE); + specification.ifNotExists(true); + + return Arrays.asList(specification); + } + + @Override + public String[] getEntityBasePackages() { + return new String[] { "org.onap.music" }; + } + + @Override + protected String getKeyspaceName() { + return KEYSPACE; + } +} diff --git a/src/main/java/org/onap/music/spring/data/cassandra/MusicApplication.java b/src/main/java/org/onap/music/spring/data/cassandra/MusicApplication.java new file mode 100644 index 00000000..dabae9a5 --- /dev/null +++ b/src/main/java/org/onap/music/spring/data/cassandra/MusicApplication.java @@ -0,0 +1,55 @@ +/* + * ============LICENSE_START========================================== + * org.onap.music + * =================================================================== + * Copyright (c) 2018 IBM. + * =================================================================== + * 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.music.spring.data.cassandra; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.context.annotation.ComponentScan; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@EnableSwagger2 +@SpringBootApplication +@ComponentScan(basePackages = {"org.onap.music" }) + +/** + * + */ +public class MusicApplication extends SpringBootServletInitializer { + + /** + * + */ + public static void main(String[] args) { + SpringApplication.run(MusicApplication.class, args); + } + + /** + * + */ + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(MusicApplication.class); + } +} diff --git a/src/main/java/org/onap/music/util/TestVotingApp.java b/src/main/java/org/onap/music/util/TestVotingApp.java new file mode 100644 index 00000000..e4a8272b --- /dev/null +++ b/src/main/java/org/onap/music/util/TestVotingApp.java @@ -0,0 +1,145 @@ +/* + * ============LICENSE_START========================================== + * org.onap.music + * =================================================================== + * Copyright (c) 2018 IBM. + * =================================================================== + * 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.music.util; + +import java.util.HashMap; +import java.util.Map; + +import org.onap.music.datastore.PreparedQueryObject; +import org.onap.music.exceptions.MusicLockingException; +import org.onap.music.exceptions.MusicQueryException; +import org.onap.music.exceptions.MusicServiceException; +import org.onap.music.main.MusicCore; + +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; + +/** + * + */ +public class TestVotingApp { + String keyspaceName; + String tableName; + + public TestVotingApp() throws MusicServiceException { + keyspaceName = "VotingAppForMusic" + System.currentTimeMillis(); + tableName = "votecount"; + } + + public void initialize() throws MusicServiceException { + createVotingKeyspace(); + System.out.println("Created keyspaces"); + createVotingTable(); + System.out.println("Created tables"); + + createEntryForCandidate("Popeye"); + createEntryForCandidate("Judy"); + createEntryForCandidate("Flash"); + createEntryForCandidate("Mickey"); + System.out.println("Created candidates"); + } + + private void createVotingTable() throws MusicServiceException { + PreparedQueryObject queryObject = new PreparedQueryObject(); + queryObject.appendQueryString( + "CREATE TABLE " + keyspaceName + "." + tableName + " (name text PRIMARY KEY, count int);"); + + try { + MusicCore.createTable(keyspaceName, tableName, queryObject, "eventual"); + } catch (MusicServiceException e) { + throw (e); + } + } + + private void createVotingKeyspace() throws MusicServiceException { + Map replicationInfo = new HashMap(); + replicationInfo.put("'class'", "'SimpleStrategy'"); + replicationInfo.put("'replication_factor'", 1); + + PreparedQueryObject queryObject = new PreparedQueryObject(); + queryObject.appendQueryString("CREATE KEYSPACE " + keyspaceName + " WITH REPLICATION = " + + replicationInfo.toString().replaceAll("=", ":")); + + try { + MusicCore.nonKeyRelatedPut(queryObject, "eventual"); + } catch (MusicServiceException e) { + throw (e); + } + } + + /* + * private void createVotingTable() throws MusicServiceException { + * PreparedQueryObject queryObject = new PreparedQueryObject(); + * queryObject.appendQueryString( "CREATE TABLE " + keyspaceName + "." + + * tableName + " (name text PRIMARY KEY, count int);"); + * + * try { MusicCore.createTable(keyspaceName, tableName, queryObject, + * "eventual"); } catch (MusicServiceException e) { throw (e); } } + */ + + private void createEntryForCandidate(String candidateName) throws MusicServiceException { + PreparedQueryObject queryObject = new PreparedQueryObject(); + queryObject.appendQueryString("INSERT INTO " + keyspaceName + "." + tableName + " (name, count) " + "VALUES ('" + + candidateName + "', 0);"); + + MusicCore.nonKeyRelatedPut(queryObject, "eventual"); + } + + public void updateVoteCount(String candidateName, int numVotes) + throws MusicLockingException, MusicQueryException, MusicServiceException { + PreparedQueryObject queryObject = new PreparedQueryObject(); + queryObject.appendQueryString("UPDATE " + keyspaceName + "." + tableName + " SET count=" + numVotes + + " where name='" + candidateName + "';"); + MusicCore.atomicPut(keyspaceName, tableName, candidateName, queryObject, null); + } + + public HashMap readAllVotes() throws MusicServiceException { + PreparedQueryObject queryObject = new PreparedQueryObject(); + queryObject.appendQueryString("SELECT * FROM " + keyspaceName + "." + tableName); + ResultSet rs = MusicCore.get(queryObject); + HashMap voteCount = new HashMap(); + for (Row candidate : rs.all()) { + voteCount.put(candidate.getString("name"), candidate.getInt("count")); + } + return voteCount; + } + + public static void main(String[] args) throws Exception { + TestVotingApp tva = new TestVotingApp(); + tva.initialize(); + + tva.updateVoteCount("Popeye", 5); + tva.updateVoteCount("Judy", 9); + tva.updateVoteCount("Mickey", 8); + tva.updateVoteCount("Flash", 1); + tva.updateVoteCount("Flash", 2); + + HashMap voteCount = tva.readAllVotes(); + System.out.println(voteCount); + assert (voteCount.get("Popeye") == 5); + assert (voteCount.get("Judy") == 9); + assert (voteCount.get("Mickey") == 8); + assert (voteCount.get("Flash") == 2); + } + +} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 00000000..cdeaa6e0 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,2 @@ +keyspace.name=VotingAppForMusic +server.port=1010 \ No newline at end of file diff --git a/src/test/java/org/onap/music/unittests/TestRestMusicData.java b/src/test/java/org/onap/music/unittests/TestRestMusicData.java index 493a6a4a..c8dd0830 100644 --- a/src/test/java/org/onap/music/unittests/TestRestMusicData.java +++ b/src/test/java/org/onap/music/unittests/TestRestMusicData.java @@ -39,11 +39,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; import org.mindrot.jbcrypt.BCrypt; -import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.music.datastore.MusicDataStoreHandle; import org.onap.music.datastore.PreparedQueryObject; import org.onap.music.datastore.jsonobjects.JsonDelete; @@ -82,14 +80,6 @@ public class TestRestMusicData { @Mock UriInfo info; - - //* cjc out - @Mock - CachingUtil cachUtilMock; - - @InjectMocks - private MusicCore mCore; - //*/ static String appName = "TestApp"; static String userId = "TestUser"; @@ -198,7 +188,7 @@ public class TestRestMusicData { jsonKeyspace.setDurabilityOfWrites("true"); jsonKeyspace.setKeyspaceName(keyspaceName); jsonKeyspace.setReplicationInfo(replicationInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.createKeySpace("1", "1", "1", null,authorization, appName, jsonKeyspace, keyspaceName); System.out.println("#######status is " + response.getStatus()); System.out.println("Entity" + response.getEntity()); @@ -210,7 +200,7 @@ public class TestRestMusicData { JsonKeySpace jsonKeyspace = new JsonKeySpace(); Map consistencyInfo = new HashMap<>(); Map replicationInfo = new HashMap<>(); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.createKeySpace("1", "1", "1", null, authorization,appName, jsonKeyspace, keyspaceName); System.out.println("#######status is " + response.getStatus()); System.out.println("Entity" + response.getEntity()); @@ -223,7 +213,7 @@ public class TestRestMusicData { Map consistencyInfo = new HashMap<>(); Map replicationInfo = new HashMap<>(); String appName1 = "test"; - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.createKeySpace("1", "1", "1", null,authorization, appName1, jsonKeyspace, keyspaceName); System.out.println("#######status is " + response.getStatus()); System.out.println("Entity" + response.getEntity()); @@ -242,7 +232,7 @@ public class TestRestMusicData { jsonKeyspace.setDurabilityOfWrites("true"); jsonKeyspace.setKeyspaceName("TestApp1"); jsonKeyspace.setReplicationInfo(replicationInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.createKeySpace("1", "1", "1", null,authorization, "TestApp1", jsonKeyspace, keyspaceName); System.out.println("#######status is " + response.getStatus()); @@ -252,8 +242,6 @@ public class TestRestMusicData { @Test public void Test2_createKeyspaceEmptyAuth() throws Exception { - - //MockitoAnnotations.initMocks(this); JsonKeySpace jsonKeyspace = new JsonKeySpace(); Map consistencyInfo = new HashMap<>(); Map replicationInfo = new HashMap<>(); @@ -267,7 +255,7 @@ public class TestRestMusicData { //Map m1= new HashMap<>() ; //Mockito.when(CachingUtil.verifyOnboarding("x","y","x")).thenReturn(m1); //Mockito.when(CachingUtil.verifyOnboarding(appNamex,userId,password).thenReturn(m1)); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); String authDatax = ":"+password; String authorizationx = new String(Base64.encode(authDatax.getBytes())); try { @@ -295,7 +283,7 @@ public class TestRestMusicData { jsonTable.setPrimaryKey("emp_name"); jsonTable.setTableName(tableName); jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization, jsonTable, keyspaceName, tableName); @@ -321,7 +309,7 @@ public class TestRestMusicData { jsonTable.setClusteringOrder("ASC"); jsonTable.setTableName(tableName); jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization, jsonTable, keyspaceName, tableName); @@ -350,7 +338,7 @@ public class TestRestMusicData { jsonTable.setFields(fields); jsonTable.setProperties(properties); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization, jsonTable, keyspaceName, tableName_prop); @@ -375,7 +363,7 @@ public class TestRestMusicData { String tableNameDup=tableName+"X"; jsonTable.setTableName(tableNameDup); jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonTable, keyspaceName, tableNameDup); @@ -411,7 +399,7 @@ public class TestRestMusicData { jsonTable.setPrimaryKey("emp_name"); jsonTable.setTableName(tableName); jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization, jsonTable, keyspaceName, tableName); @@ -436,7 +424,7 @@ public class TestRestMusicData { jsonTable.setPrimaryKey("emp_name"); jsonTable.setTableName(tableName); jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonTable, "wrong", tableName); @@ -464,7 +452,7 @@ public class TestRestMusicData { jsonTable.setTableName(tableNameC); jsonTable.setClusteringOrder("emp_id Desc"); jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonTable, keyspaceName, tableNameC); @@ -493,7 +481,7 @@ public class TestRestMusicData { jsonTable.setTableName(tableNameC); jsonTable.setClusteringOrder("emp_salary ASC"); jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonTable, keyspaceName, tableNameC); @@ -520,7 +508,7 @@ public class TestRestMusicData { jsonTable.setTableName(tableNameC); jsonTable.setClusteringOrder("emp_salary ASC"); jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonTable, keyspaceName, tableNameC); @@ -548,7 +536,7 @@ public class TestRestMusicData { jsonTable.setTableName(tableNameC); jsonTable.setClusteringOrder("emp_salary ASC"); jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonTable, keyspaceName, tableNameC); @@ -576,7 +564,7 @@ public class TestRestMusicData { jsonTable.setTableName(tableNameC); jsonTable.setClusteringOrder("emp_salary ASC"); jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonTable, keyspaceName, tableNameC); @@ -604,7 +592,7 @@ public class TestRestMusicData { jsonTable.setTableName(tableNameC); jsonTable.setClusteringOrder("emp_idx desc, emp_salary ASC"); jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonTable, keyspaceName, tableNameC); @@ -632,7 +620,7 @@ public class TestRestMusicData { jsonTable.setTableName(tableNameC); jsonTable.setClusteringOrder("emp_id desc, emp_salary ASC,uuid desc"); jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonTable, keyspaceName, tableNameC); @@ -660,7 +648,7 @@ public class TestRestMusicData { jsonTable.setTableName(tableNameC); jsonTable.setClusteringOrder("emp_salary ASC"); jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonTable, keyspaceName, tableNameC); @@ -695,7 +683,7 @@ public class TestRestMusicData { jsonInsert.setKeyspaceName(keyspaceName); jsonInsert.setTableName(tableName); jsonInsert.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonInsert, keyspaceName, tableName); assertEquals(200, response.getStatus()); @@ -714,7 +702,7 @@ public class TestRestMusicData { jsonInsert.setKeyspaceName(keyspaceName); jsonInsert.setTableName(tableName); jsonInsert.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonInsert, keyspaceName, tableName); @@ -735,7 +723,7 @@ public class TestRestMusicData { jsonInsert.setKeyspaceName(keyspaceName); jsonInsert.setTableName(tableName); jsonInsert.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization, jsonInsert, keyspaceName, tableName); @@ -756,7 +744,7 @@ public class TestRestMusicData { jsonInsert.setKeyspaceName(keyspaceName); jsonInsert.setTableName(tableName); jsonInsert.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonInsert, keyspaceName, "wrong"); @@ -777,7 +765,7 @@ public class TestRestMusicData { jsonUpdate.setKeyspaceName(keyspaceName); jsonUpdate.setTableName(tableName); jsonUpdate.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Mockito.when(info.getQueryParameters()).thenReturn(row); Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonUpdate, keyspaceName, tableName, info); @@ -787,7 +775,7 @@ public class TestRestMusicData { // need mock code to create error for MusicCore methods @Test public void Test5_updateTableAuthE() throws Exception { - MockitoAnnotations.initMocks(this); + //MockitoAnnotations.initMocks(this); JsonUpdate jsonUpdate = new JsonUpdate(); Map consistencyInfo = new HashMap<>(); MultivaluedMap row = new MultivaluedMapImpl(); @@ -800,7 +788,7 @@ public class TestRestMusicData { jsonUpdate.setTableName(tableName); jsonUpdate.setValues(values); //add ttl & timestamp - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Mockito.when(info.getQueryParameters()).thenReturn(row); //Map m1= new HashMap<>() ; //Mockito.when(MusicCore.autheticateUser(appName,userId,password,keyspaceName,"abc66ccc-d857-4e90-b1e5-df98a3d40ce6","updateTable")).thenReturn(m1); @@ -827,8 +815,8 @@ public class TestRestMusicData { jsonUpdate.setTableName(tableName); jsonUpdate.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.when(info.getQueryParameters()).thenReturn(row); String authDatax = ":";//+password; String authorizationx = new String(Base64.encode(authDatax.getBytes())); try { @@ -855,8 +843,8 @@ public class TestRestMusicData { jsonUpdate.setTableName(tableName); jsonUpdate.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.when(info.getQueryParameters()).thenReturn(row); String authDatax =":"+password; String authorizationx = new String(Base64.encode(authDatax.getBytes())); String appNamex="xx"; @@ -880,7 +868,7 @@ public class TestRestMusicData { row.add("emp_name", "testName"); consistencyInfo.put("type", "atomic"); jsonSelect.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Mockito.when(info.getQueryParameters()).thenReturn(row); Response response = data.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, keyspaceName, tableName, info); @@ -897,7 +885,7 @@ public class TestRestMusicData { row.add("emp_name", "testName"); consistencyInfo.put("type", "atomic"); jsonInsert.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Mockito.when(info.getQueryParameters()).thenReturn(row); Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonInsert, keyspaceName, tableName,info); @@ -914,7 +902,7 @@ public class TestRestMusicData { row.add("emp_name", "test1"); consistencyInfo.put("type", "atomic"); jsonDelete.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Mockito.when(info.getQueryParameters()).thenReturn(row); Response response = data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, @@ -931,7 +919,7 @@ public class TestRestMusicData { MultivaluedMap row = new MultivaluedMapImpl(); consistencyInfo.put("type", "atomic"); jsonDelete.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Mockito.when(info.getQueryParameters()).thenReturn(row); Response response = data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, @@ -948,8 +936,8 @@ public class TestRestMusicData { row.add("emp_name", "test1"); consistencyInfo.put("type", "atomic"); jsonDelete.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.when(info.getQueryParameters()).thenReturn(row); Response response = data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, null, keyspaceName, tableName, info); @@ -962,7 +950,7 @@ public class TestRestMusicData { Map consistencyInfo = new HashMap<>(); consistencyInfo.put("type", "atomic"); jsonTable.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.dropTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, keyspaceName, tableName); @@ -982,7 +970,7 @@ public class TestRestMusicData { jsonKeyspace.setDurabilityOfWrites("true"); jsonKeyspace.setKeyspaceName("TestApp1"); jsonKeyspace.setReplicationInfo(replicationInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", authorization,appName, keyspaceName); assertEquals(200, response.getStatus()); @@ -1000,7 +988,7 @@ public class TestRestMusicData { jsonKeyspace.setDurabilityOfWrites("true"); jsonKeyspace.setKeyspaceName("TestApp1"); jsonKeyspace.setReplicationInfo(replicationInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", wrongAuthorization, appName, keyspaceName); assertEquals(401, response.getStatus()); @@ -1011,7 +999,7 @@ public class TestRestMusicData { JsonKeySpace jsonKeyspace = new JsonKeySpace(); Map consistencyInfo = new HashMap<>(); Map replicationInfo = new HashMap<>(); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", authorization, appName, keyspaceName); assertEquals(400, response.getStatus()); @@ -1140,7 +1128,7 @@ public class TestRestMusicData { @Ignore @Test public void Test3_createLockReference() throws Exception { - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Map resultMap = (Map) lock.createLockReference(lockName,"1","1",authorization, null, appName).getEntity(); @SuppressWarnings("unchecked") Map resultMap1 = (Map) resultMap.get("lock"); @@ -1151,7 +1139,7 @@ public class TestRestMusicData { @Ignore @Test public void Test4_accquireLock() throws Exception { - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Map resultMap = (Map) lock.accquireLock(lockId,"1","1",authorization, null, appName).getEntity(); assertEquals(ResultType.SUCCESS, resultMap.get("status")); } @@ -1159,7 +1147,7 @@ public class TestRestMusicData { @Ignore @Test public void Test5_currentLockHolder() throws Exception { - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Map resultMap = (Map) lock.currentLockHolder(lockName,"1","1",authorization, null, appName).getEntity(); assertEquals(ResultType.SUCCESS, resultMap.get("status")); } @@ -1167,7 +1155,7 @@ public class TestRestMusicData { @Ignore @Test public void Test7_unLock() throws Exception { - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Map resultMap = (Map) lock.unLock(lockId,"1","1",authorization, null, appName).getEntity(); assertEquals(ResultType.SUCCESS, resultMap.get("status")); } diff --git a/src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java b/src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java index f611959c..c48f7b80 100644 --- a/src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java +++ b/src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java @@ -35,6 +35,7 @@ import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; import org.apache.curator.test.TestingServer; +import org.junit.After; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.FixMethodOrder; @@ -46,7 +47,7 @@ import org.mindrot.jbcrypt.BCrypt; //cjcimport org.mindrot.jbcrypt.BCrypt; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.music.datastore.MusicDataStoreHandle; import org.onap.music.datastore.PreparedQueryObject; import org.onap.music.datastore.jsonobjects.JsonDelete; @@ -264,7 +265,7 @@ public class TestRestMusicQAPI { jsonTable.setTableName(tableName); jsonTable.setFields(fields); //System.out.println("cjc before print version, xLatestVersion="+xLatestVersion); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = qData.createQ(majorV, minorV,patchV, aid, appName, authorization, jsonTable, keyspaceName, tableName); @@ -374,7 +375,7 @@ public class TestRestMusicQAPI { jsonTable.setClusteringOrder("emp_id DESC"); jsonTable.setFields(fields); //System.out.println("cjc before print version, xLatestVersion="+xLatestVersion); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = qData.createQ(majorV, minorV,patchV, aid, appName, authorization, jsonTable, keyspaceName, tableNameC); @@ -463,7 +464,7 @@ public class TestRestMusicQAPI { jsonTable.setClusteringOrder("emp_id DESCx"); jsonTable.setFields(fields); //System.out.println("cjc before print version, xLatestVersion="+xLatestVersion); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = qData.createQ(majorV, minorV,patchV, aid, appName, authorization, jsonTable, keyspaceName, tableNameC); @@ -491,7 +492,7 @@ public class TestRestMusicQAPI { String tableNameDup=tableName+"X"; jsonTable.setTableName(tableNameDup); jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = qData.createQ(majorV, minorV,patchV, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonTable, keyspaceName, tableNameDup); @@ -530,7 +531,7 @@ public class TestRestMusicQAPI { jsonTable.setTableName(tableName); jsonTable.setClusteringOrder("uuid DESC"); jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = qData.createQ(majorV, minorV,patchV, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization, jsonTable, keyspaceName, tableName); @@ -557,7 +558,7 @@ public class TestRestMusicQAPI { jsonTable.setClusteringKey("emp_salary"); jsonTable.setClusteringOrder("emp_salary DESC"); jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = qData.createQ(majorV, minorV,patchV, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonTable, "wrong", tableName); @@ -603,7 +604,7 @@ public class TestRestMusicQAPI { jsonInsert.setKeyspaceName(keyspaceName); jsonInsert.setTableName(tableName); jsonInsert.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = qData.insertIntoQ(majorV, minorV,patchV, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonInsert, keyspaceName, tableName); assertNotEquals(200, response.getStatus()); @@ -643,7 +644,7 @@ public class TestRestMusicQAPI { jsonInsert.setKeyspaceName(keyspaceName); jsonInsert.setTableName(tableName); jsonInsert.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = qData.insertIntoQ(majorV, minorV,patchV, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization, jsonInsert, keyspaceName, tableName); @@ -664,7 +665,7 @@ public class TestRestMusicQAPI { jsonInsert.setKeyspaceName(keyspaceName); jsonInsert.setTableName(tableName); jsonInsert.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = qData.insertIntoQ(majorV, minorV,patchV, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonInsert, keyspaceName, "wrong"); @@ -705,8 +706,8 @@ public class TestRestMusicQAPI { jsonUpdate.setKeyspaceName(keyspaceName); jsonUpdate.setTableName(tableName); jsonUpdate.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.when(info.getQueryParameters()).thenReturn(row); Response response = qData.updateQ(majorV, minorV,patchV, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonUpdate, keyspaceName, tableName, info); assertNotEquals(200, response.getStatus()); @@ -797,7 +798,7 @@ public class TestRestMusicQAPI { MultivaluedMap row = new MultivaluedMapImpl(); consistencyInfo.put("type", "atomic"); jsonDelete.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Mockito.when(info.getQueryParameters()).thenReturn(row); Response response = qData.deleteFromQ(majorV, minorV,patchV, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, @@ -814,8 +815,8 @@ public class TestRestMusicQAPI { row.add("emp_name", "test1"); consistencyInfo.put("type", "atomic"); jsonDelete.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.when(info.getQueryParameters()).thenReturn(row); Response response = qData.deleteFromQ(majorV, minorV,patchV, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, null, keyspaceName, tableName, info); @@ -857,7 +858,7 @@ public class TestRestMusicQAPI { jsonTable.setClusteringKey("emp_id"); jsonTable.setClusteringOrder("emp_id DESC"); jsonTable.setTableName(tableNameC); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = qData.createQ(majorV, minorV,patchV, aid, appName, authorization, jsonTable, keyspaceName, tableNameC); @@ -884,7 +885,7 @@ public class TestRestMusicQAPI { jsonTable.setClusteringOrder("emp_id DESC"); jsonTable.setTableName(tableNameC); jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = qData.createQ(majorV, minorV,patchV, aid, appName, authorization, jsonTable, keyspaceName, tableNameC); @@ -911,7 +912,7 @@ public class TestRestMusicQAPI { jsonTable.setClusteringOrder("emp_id DESC"); jsonTable.setTableName(tableNameC); jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = qData.createQ(majorV, minorV,patchV, aid, appName, authorization, jsonTable, keyspaceName, tableNameC); @@ -938,7 +939,7 @@ public class TestRestMusicQAPI { jsonTable.setClusteringKey("emp_id"); jsonTable.setTableName(tableNameC); jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = qData.createQ(majorV, minorV,patchV, aid, appName, authorization, jsonTable, keyspaceName, tableNameC); @@ -966,7 +967,7 @@ public class TestRestMusicQAPI { jsonTable.setClusteringOrder("emp_id ASC"); jsonTable.setTableName(tableNameC); jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = qData.createQ(majorV, minorV,patchV, aid, appName, authorization, jsonTable, keyspaceName, tableNameC); @@ -993,13 +994,14 @@ public class TestRestMusicQAPI { jsonTable.setTableName(tableNameC); jsonTable.setFields(fields); jsonTable.setClusteringOrder("emp_id ASC"); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = qData.createQ(majorV, minorV,patchV, aid, appName, authorization, jsonTable, keyspaceName, tableNameC); System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameC); System.out.println("Entity" + response.getEntity()); assertEquals(400, response.getStatus()); + } //Primary key with no partition key @@ -1020,7 +1022,8 @@ public class TestRestMusicQAPI { jsonTable.setTableName(tableNameC); jsonTable.setFields(fields); jsonTable.setClusteringOrder("emp_id ASC"); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + + //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Response response = qData.createQ(majorV, minorV,patchV, aid, appName, authorization, jsonTable, keyspaceName, tableNameC); diff --git a/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 00000000..1f0955d4 --- /dev/null +++ b/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1 @@ +mock-maker-inline diff --git a/src/test/resources/mockito-extensions/org.mockito.plugins.StackTraceCleanerProvider b/src/test/resources/mockito-extensions/org.mockito.plugins.StackTraceCleanerProvider new file mode 100644 index 00000000..049073ff --- /dev/null +++ b/src/test/resources/mockito-extensions/org.mockito.plugins.StackTraceCleanerProvider @@ -0,0 +1 @@ +org.mockito.internal.exceptions.stacktrace.DefaultStackTraceCleanerProvider \ No newline at end of file -- cgit 1.2.3-korg