From d4f4d573469aaa9b284313e4bd9535e6d8e3dd10 Mon Sep 17 00:00:00 2001 From: "Tschaen, Brendan" Date: Tue, 12 Nov 2019 14:28:26 -0500 Subject: Update junits Change-Id: Ic08113ccee0c11e541764059632dfb2692eba657 Issue-ID: MUSIC-521 Signed-off-by: Tschaen, Brendan --- .../org/onap/music/datastore/MusicDataStore.java | 17 +- .../music/datastore/jsonobjects/JsonInsert.java | 5 - .../music/datastore/jsonobjects/JsonTable.java | 29 -- .../music/datastore/jsonobjects/JsonUpdate.java | 88 ++++-- .../lockingservice/cassandra/CassaLockStore.java | 2 +- .../main/java/org/onap/music/main/MusicUtil.java | 1 + .../org/onap/music/cassandra/MusicUtilTest.java | 332 +++++++++++++++++++++ .../datastore/jsonobjects/JsonDeleteTest.java | 85 ++++++ .../datastore/jsonobjects/JsonInsertTest.java | 176 +++++++++++ .../datastore/jsonobjects/JsonKeySpaceTest.java | 72 +++++ .../datastore/jsonobjects/JsonSelectTest.java | 55 ++++ .../music/datastore/jsonobjects/JsonTableTest.java | 153 ++++++++++ .../datastore/jsonobjects/JsonUpdateTest.java | 166 +++++++++++ .../java/org/onap/music/main/ResultTypeTest.java | 42 +++ .../java/org/onap/music/main/ReturnTypeTest.java | 82 +++++ .../org/onap/music/unittests/CassandraCQL.java | 245 --------------- .../org/onap/music/unittests/MusicUtilTest.java | 332 --------------------- .../org/onap/music/unittests/ResultTypeTest.java | 43 --- .../org/onap/music/unittests/ReturnTypeTest.java | 84 ------ .../unittests/jsonobjects/JsonDeleteTest.java | 86 ------ .../unittests/jsonobjects/JsonInsertTest.java | 111 ------- .../unittests/jsonobjects/JsonKeySpaceTest.java | 73 ----- .../unittests/jsonobjects/JsonSelectTest.java | 56 ---- .../music/unittests/jsonobjects/JsonTableTest.java | 100 ------- .../unittests/jsonobjects/JsonUpdateTest.java | 111 ------- 25 files changed, 1228 insertions(+), 1318 deletions(-) create mode 100644 music-core/src/test/java/org/onap/music/cassandra/MusicUtilTest.java create mode 100644 music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonDeleteTest.java create mode 100644 music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonInsertTest.java create mode 100644 music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonKeySpaceTest.java create mode 100644 music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonSelectTest.java create mode 100644 music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonTableTest.java create mode 100644 music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonUpdateTest.java create mode 100644 music-core/src/test/java/org/onap/music/main/ResultTypeTest.java create mode 100644 music-core/src/test/java/org/onap/music/main/ReturnTypeTest.java delete mode 100644 music-core/src/test/java/org/onap/music/unittests/CassandraCQL.java delete mode 100644 music-core/src/test/java/org/onap/music/unittests/MusicUtilTest.java delete mode 100644 music-core/src/test/java/org/onap/music/unittests/ResultTypeTest.java delete mode 100644 music-core/src/test/java/org/onap/music/unittests/ReturnTypeTest.java delete mode 100644 music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java delete mode 100644 music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java delete mode 100644 music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java delete mode 100644 music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java delete mode 100644 music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java delete mode 100644 music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java (limited to 'music-core') diff --git a/music-core/src/main/java/org/onap/music/datastore/MusicDataStore.java b/music-core/src/main/java/org/onap/music/datastore/MusicDataStore.java index 9ccff828..2e17670f 100755 --- a/music-core/src/main/java/org/onap/music/datastore/MusicDataStore.java +++ b/music-core/src/main/java/org/onap/music/datastore/MusicDataStore.java @@ -61,10 +61,6 @@ import com.datastax.driver.extras.codecs.enums.EnumNameCodec; * */ public class MusicDataStore { - - public static final String CONSISTENCY_LEVEL_ONE = "ONE"; - public static final String CONSISTENCY_LEVEL_QUORUM = "QUORUM"; - public static final String CONSISTENCY_LEVEL_LOCAL_QUORUM = "LOCAL_QUORUM"; private Session session; private Cluster cluster; @@ -471,15 +467,16 @@ public class MusicDataStore { try { SimpleStatement statement = new SimpleStatement(queryObject.getQuery(), queryObject.getValues().toArray()); - if (consistencyLevel.equalsIgnoreCase(CONSISTENCY_LEVEL_ONE)) { + if (consistencyLevel.equalsIgnoreCase(MusicUtil.ONE)) { if(queryObject.getConsistency() == null) { statement.setConsistencyLevel(ConsistencyLevel.ONE); } else { statement.setConsistencyLevel(MusicUtil.getConsistencyLevel(queryObject.getConsistency())); } - } - else if (consistencyLevel.equalsIgnoreCase(CONSISTENCY_LEVEL_QUORUM)) { + } else if (consistencyLevel.equalsIgnoreCase(MusicUtil.QUORUM)) { statement.setConsistencyLevel(ConsistencyLevel.QUORUM); + } else if (consistencyLevel.equalsIgnoreCase(MusicUtil.LOCAL_QUORUM)) { + statement.setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM); } results = session.execute(statement); @@ -501,7 +498,7 @@ public class MusicDataStore { */ public ResultSet executeOneConsistencyGet(PreparedQueryObject queryObject) throws MusicServiceException, MusicQueryException { - return executeGet(queryObject, CONSISTENCY_LEVEL_ONE); + return executeGet(queryObject, MusicUtil.ONE); } /** @@ -512,7 +509,7 @@ public class MusicDataStore { */ public ResultSet executeLocalQuorumConsistencyGet(PreparedQueryObject queryObject) throws MusicServiceException, MusicQueryException { - return executeGet(queryObject, CONSISTENCY_LEVEL_LOCAL_QUORUM); + return executeGet(queryObject, MusicUtil.LOCAL_QUORUM); } /** @@ -523,7 +520,7 @@ public class MusicDataStore { */ public ResultSet executeQuorumConsistencyGet(PreparedQueryObject queryObject) throws MusicServiceException, MusicQueryException { - return executeGet(queryObject, CONSISTENCY_LEVEL_QUORUM); + return executeGet(queryObject, MusicUtil.QUORUM); } } diff --git a/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java b/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java index 57ff245a..2f685cfe 100644 --- a/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java +++ b/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java @@ -173,11 +173,6 @@ public class JsonInsert implements Serializable { * @throws MusicQueryException */ public PreparedQueryObject genInsertPreparedQueryObj() throws MusicQueryException { - if (logger.isDebugEnabled()) { - logger.debug("Coming inside genTableInsertQuery method " + this.getKeyspaceName()); - logger.debug("Coming inside genTableInsertQuery method " + this.getTableName()); - } - PreparedQueryObject queryObject = new PreparedQueryObject(); TableMetadata tableInfo = null; try { diff --git a/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java b/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java index ef560144..0a277e08 100644 --- a/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java +++ b/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java @@ -144,11 +144,6 @@ public class JsonTable { } public PreparedQueryObject genCreateTableQuery() throws MusicQueryException { - if (logger.isDebugEnabled()) { - logger.debug("Coming inside genCreateTableQuery method " + this.getKeyspaceName()); - logger.debug("Coming inside genCreateTableQuery method " + this.getTableName()); - } - String primaryKey = null; String partitionKey = this.getPartitionKey(); String clusterKey = this.getClusteringKey(); @@ -340,36 +335,12 @@ public class JsonTable { return queryObject; } - /** - * - * @return - */ - public PreparedQueryObject genCreateShadowLockingTableQuery() { - if (logger.isDebugEnabled()) { - logger.debug("Coming inside genCreateShadowLockingTableQuery method " + this.getKeyspaceName()); - logger.debug("Coming inside genCreateShadowLockingTableQuery method " + this.getTableName()); - } - - String tableName = "unsyncedKeys_" + this.getTableName(); - String tabQuery = "CREATE TABLE IF NOT EXISTS " + this.getKeyspaceName() + "." + tableName - + " ( key text,PRIMARY KEY (key) );"; - PreparedQueryObject queryObject = new PreparedQueryObject(); - queryObject.appendQueryString(tabQuery); - - return queryObject; - } - /** * genDropTableQuery * * @return PreparedQueryObject */ public PreparedQueryObject genDropTableQuery() { - if (logger.isDebugEnabled()) { - logger.debug("Coming inside genDropTableQuery method " + this.getKeyspaceName()); - logger.debug("Coming inside genDropTableQuery method " + this.getTableName()); - } - PreparedQueryObject query = new PreparedQueryObject(); query.appendQueryString("DROP TABLE " + this.getKeyspaceName() + "." + this.getTableName() + ";"); logger.info("Delete Query ::::: " + query.getQuery()); diff --git a/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java b/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java index 12508de0..cd767a44 100644 --- a/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java +++ b/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java @@ -65,7 +65,7 @@ public class JsonUpdate implements Serializable { private Map consistencyInfo; private transient Map conditions; private transient Map rowSpecification; - private StringBuilder rowIdString; + private String rowIdString; private String primarKeyValue; private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(JsonUpdate.class); @@ -142,11 +142,11 @@ public class JsonUpdate implements Serializable { this.values = values; } - public StringBuilder getRowIdString() { + public String getRowIdString() { return rowIdString; } - public void setRowIdString(StringBuilder rowIdString) { + public void setRowIdString(String rowIdString) { this.rowIdString = rowIdString; } @@ -176,11 +176,6 @@ public class JsonUpdate implements Serializable { * @throws MusicQueryException */ public PreparedQueryObject genUpdatePreparedQueryObj(MultivaluedMap rowParams) throws MusicQueryException { - if (logger.isDebugEnabled()) { - logger.debug("Coming inside genUpdatePreparedQueryObj method " + this.getKeyspaceName()); - logger.debug("Coming inside genUpdatePreparedQueryObj method " + this.getTableName()); - } - PreparedQueryObject queryObject = new PreparedQueryObject(); if((this.getKeyspaceName() == null || this.getKeyspaceName().isEmpty()) || @@ -205,20 +200,7 @@ public class JsonUpdate implements Serializable { Map valuesMap = this.getValues(); - TableMetadata tableInfo; - - try { - tableInfo = MusicDataStoreHandle.returnColumnMetadata(this.getKeyspaceName(), this.getTableName()); - } catch (MusicServiceException e) { - logger.error(EELFLoggerDelegate.errorLogger,e, AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes - .GENERALSERVICEERROR, e); - /*return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();*/ - throw new MusicQueryException(e.getMessage(), Status.BAD_REQUEST.getStatusCode()); - }catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, e, AppMessages.UNKNOWNERROR, ErrorSeverity.CRITICAL, - ErrorTypes.GENERALSERVICEERROR); - throw new MusicQueryException(e.getMessage(), Status.BAD_REQUEST.getStatusCode()); - } + TableMetadata tableInfo = getColumnMetadata(this.getKeyspaceName(), this.getTableName()); if (tableInfo == null) { logger.error(EELFLoggerDelegate.errorLogger,"Table information not found. Please check input for table name= "+this.getTableName(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR); @@ -289,7 +271,7 @@ public class JsonUpdate implements Serializable { rowId = getRowIdentifier(this.getKeyspaceName(), this.getTableName(), rowParams, queryObject); this.setRowIdString(rowId.rowIdString); this.setPrimarKeyValue(rowId.primarKeyValue); - if(rowId == null || rowId.primarKeyValue.isEmpty()) { + if(rowId == null || rowId.getPrimaryKeyValue().isEmpty()) { /*return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE) .setError("Mandatory WHERE clause is missing. Please check the input request.").toMap()).build();*/ @@ -312,7 +294,7 @@ public class JsonUpdate implements Serializable { queryObject.appendQueryString( - " SET " + fieldValueString + " WHERE " + rowId.rowIdString + ";"); + " SET " + fieldValueString + " WHERE " + rowId.getRowIdString() + ";"); @@ -324,7 +306,7 @@ public class JsonUpdate implements Serializable { // to avoid parsing repeatedly, just send the select query to obtain row PreparedQueryObject selectQuery = new PreparedQueryObject(); selectQuery.appendQueryString("SELECT * FROM " + this.getKeyspaceName() + "." + this.getTableName() + " WHERE " - + rowId.rowIdString + ";"); + + rowId.getRowIdString() + ";"); selectQuery.addValue(rowId.primarKeyValue); conditionInfo = new Condition(this.getConditions(), selectQuery); } @@ -348,20 +330,62 @@ public class JsonUpdate implements Serializable { return queryObject; } + + TableMetadata getColumnMetadata(String keyspaceName, String tableName) throws MusicQueryException { + TableMetadata tableInfo; + try { + tableInfo = returnColumnMetadata(keyspaceName, tableName); + } catch (MusicServiceException e) { + logger.error(EELFLoggerDelegate.errorLogger,e, AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes + .GENERALSERVICEERROR, e); + /*return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();*/ + throw new MusicQueryException(e.getMessage(), Status.BAD_REQUEST.getStatusCode()); + }catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, e, AppMessages.UNKNOWNERROR, ErrorSeverity.CRITICAL, + ErrorTypes.GENERALSERVICEERROR); + throw new MusicQueryException(e.getMessage(), Status.BAD_REQUEST.getStatusCode()); + } + return tableInfo; + } + + /** wrapper around static method for testing */ + TableMetadata returnColumnMetadata(String keyspace, String tableName) throws MusicServiceException { + return MusicDataStoreHandle.returnColumnMetadata(keyspace, tableName); + } - private class RowIdentifier { - public String primarKeyValue; - public StringBuilder rowIdString; + class RowIdentifier { + private String primarKeyValue; + private String rowIdString; @SuppressWarnings("unused") public PreparedQueryObject queryObject; // the string with all the row // identifiers separated by AND - public RowIdentifier(String primaryKeyValue, StringBuilder rowIdString, + public RowIdentifier(String primaryKeyValue, String rowIdString, PreparedQueryObject queryObject) { this.primarKeyValue = primaryKeyValue; this.rowIdString = rowIdString; this.queryObject = queryObject; } + + public String getPrimaryKeyValue() { + return this.primarKeyValue; + } + + public void setPrimaryKeyValue(String primaryKeyValue) { + this.primarKeyValue = primaryKeyValue; + } + + public String getRowIdString() { + return this.rowIdString.toString(); + } + + public void setRowIdString(String rowIdString) { + this.rowIdString = rowIdString; + } + + public PreparedQueryObject getQueryObject() { + return this.queryObject; + } } /** @@ -373,12 +397,12 @@ public class JsonUpdate implements Serializable { * @return * @throws MusicServiceException */ - private RowIdentifier getRowIdentifier(String keyspace, String tablename, + RowIdentifier getRowIdentifier(String keyspace, String tablename, MultivaluedMap rowParams, PreparedQueryObject queryObject) throws MusicServiceException { StringBuilder rowSpec = new StringBuilder(); int counter = 0; - TableMetadata tableInfo = MusicDataStoreHandle.returnColumnMetadata(keyspace, tablename); + TableMetadata tableInfo = returnColumnMetadata(keyspace, tablename); if (tableInfo == null) { logger.error(EELFLoggerDelegate.errorLogger, "Table information not found. Please check input for table name= " @@ -410,7 +434,7 @@ public class JsonUpdate implements Serializable { } counter = counter + 1; } - return new RowIdentifier(primaryKey.toString(), rowSpec, queryObject); + return new RowIdentifier(primaryKey.toString(), rowSpec.toString(), queryObject); } } diff --git a/music-core/src/main/java/org/onap/music/lockingservice/cassandra/CassaLockStore.java b/music-core/src/main/java/org/onap/music/lockingservice/cassandra/CassaLockStore.java index edce3fff..cb6816e0 100644 --- a/music-core/src/main/java/org/onap/music/lockingservice/cassandra/CassaLockStore.java +++ b/music-core/src/main/java/org/onap/music/lockingservice/cassandra/CassaLockStore.java @@ -129,7 +129,7 @@ public class CassaLockStore { table = table_prepend_name+table; String tabQuery = "CREATE TABLE IF NOT EXISTS "+keyspace+"."+table + " ( key text, lockReference bigint, createTime text, acquireTime text, guard bigint static, " - + "lockType text, owner text, PRIMARY KEY ((key), lockReference) ) " + + "lockType text, leasePeriodTime bigint, owner text, PRIMARY KEY ((key), lockReference) ) " + "WITH CLUSTERING ORDER BY (lockReference ASC);"; PreparedQueryObject queryObject = new PreparedQueryObject(); diff --git a/music-core/src/main/java/org/onap/music/main/MusicUtil.java b/music-core/src/main/java/org/onap/music/main/MusicUtil.java index d46e770e..db51322d 100644 --- a/music-core/src/main/java/org/onap/music/main/MusicUtil.java +++ b/music-core/src/main/java/org/onap/music/main/MusicUtil.java @@ -73,6 +73,7 @@ public class MusicUtil { public static final String EVENTUAL_NB = "eventual_nb"; public static final String ALL = "all"; public static final String QUORUM = "quorum"; + public static final String LOCAL_QUORUM = "local_quorum"; public static final String ONE = "one"; public static final String ATOMICDELETELOCK = "atomic_delete_lock"; diff --git a/music-core/src/test/java/org/onap/music/cassandra/MusicUtilTest.java b/music-core/src/test/java/org/onap/music/cassandra/MusicUtilTest.java new file mode 100644 index 00000000..90cd68e2 --- /dev/null +++ b/music-core/src/test/java/org/onap/music/cassandra/MusicUtilTest.java @@ -0,0 +1,332 @@ +/* + * ============LICENSE_START========================================== + * org.onap.music + * =================================================================== + * Copyright (c) 2017 AT&T Intellectual Property + * Modifications Copyright (C) 2019 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.cassandra; + +import static org.junit.Assert.*; +import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.junit.Test; +import org.onap.music.datastore.PreparedQueryObject; +import org.onap.music.main.MusicUtil; +//import org.onap.music.main.CorePropertiesLoader; +import org.onap.music.service.MusicCoreService; + +import com.datastax.driver.core.ConsistencyLevel; +import com.datastax.driver.core.DataType; + +public class MusicUtilTest { + + private static final String XLATESTVERSION = "X-latestVersion"; + private static final String XMINORVERSION = "X-minorVersion"; + private static final String XPATCHVERSION = "X-patchVersion"; + + @Test + public void testGetCassName() { + MusicUtil.setCassName("Cassandra"); + assertTrue(MusicUtil.getCassName().equals("Cassandra")); + } + + @Test + public void testGetCassPwd() { + MusicUtil.setCassPwd("Cassandra"); + assertTrue(MusicUtil.getCassPwd().equals("Cassandra")); + } + + @Test + public void testMusicAafNs() { + MusicUtil.setMusicAafNs("ns"); + assertTrue("ns".equals(MusicUtil.getMusicAafNs())); + } + + @Test + public void testMusicCoreService() { + MusicUtil.setLockUsing(MusicUtil.CASSANDRA); + MusicCoreService mc = null; + mc = MusicUtil.getMusicCoreService(); + assertTrue(mc != null); + MusicUtil.setLockUsing("nothing"); + mc = null; + mc = MusicUtil.getMusicCoreService(); + assertTrue(mc != null); + + } + + @Test + public void testCipherEncKey() { + MusicUtil.setCipherEncKey("cipherEncKey"); + assertTrue("cipherEncKey".equals(MusicUtil.getCipherEncKey())); + } + + @Test + public void testGetMusicPropertiesFilePath() { + MusicUtil.setMusicPropertiesFilePath("filepath"); + assertEquals(MusicUtil.getMusicPropertiesFilePath(),"filepath"); + } + + @Test + public void testGetDefaultLockLeasePeriod() { + MusicUtil.setDefaultLockLeasePeriod(5000); + assertEquals(MusicUtil.getDefaultLockLeasePeriod(),5000); + } + + @Test + public void testIsDebug() { + MusicUtil.setDebug(true); + assertTrue(MusicUtil.isDebug()); + } + + @Test + public void testGetVersion() { + MusicUtil.setVersion("1.0.0"); + assertEquals(MusicUtil.getVersion(),"1.0.0"); + } + + @Test + public void testBuildVersionA() { + assertEquals(MusicUtil.buildVersion("1","2","3"),"1.2.3"); + } + + @Test + public void testBuildVersionB() { + assertEquals(MusicUtil.buildVersion("1",null,"3"),"1"); + } + + @Test + public void testBuildVersionC() { + assertEquals(MusicUtil.buildVersion("1","2",null),"1.2"); + } + +/* + @Test + public void testBuileVersionResponse() { + assertTrue(MusicUtil.buildVersionResponse("1","2","3").getClass().getSimpleName().equals("Builder")); + assertTrue(MusicUtil.buildVersionResponse("1",null,"3").getClass().getSimpleName().equals("Builder")); + assertTrue(MusicUtil.buildVersionResponse("1","2",null).getClass().getSimpleName().equals("Builder")); + assertTrue(MusicUtil.buildVersionResponse(null,null,null).getClass().getSimpleName().equals("Builder")); + } +*/ + @Test + public void testGetConsistency() { + assertTrue(ConsistencyLevel.ONE.equals(MusicUtil.getConsistencyLevel("one"))); + } + + @Test + public void testRetryCount() { + MusicUtil.setRetryCount(1); + assertEquals(MusicUtil.getRetryCount(),1); + } + + @Test + public void testIsCadi() { + MusicUtil.setIsCadi(true); + assertEquals(MusicUtil.getIsCadi(),true); + } + + + @Test + public void testGetMyCassaHost() { + MusicUtil.setMyCassaHost("10.0.0.2"); + assertEquals(MusicUtil.getMyCassaHost(),"10.0.0.2"); + } + + @Test + public void testIsValidQueryObject() { + PreparedQueryObject myQueryObject = new PreparedQueryObject(); + myQueryObject.appendQueryString("select * from apple where type = ?"); + myQueryObject.addValue("macintosh"); + assertTrue(MusicUtil.isValidQueryObject(true,myQueryObject)); + + myQueryObject.appendQueryString("select * from apple"); + assertTrue(MusicUtil.isValidQueryObject(false,myQueryObject)); + + myQueryObject.appendQueryString("select * from apple where type = ?"); + assertFalse(MusicUtil.isValidQueryObject(true,myQueryObject)); + + myQueryObject = new PreparedQueryObject(); + myQueryObject.appendQueryString(""); + System.out.println("#######" + myQueryObject.getQuery().isEmpty()); + assertFalse(MusicUtil.isValidQueryObject(false,myQueryObject)); + + + } + + + + + @Test(expected = IllegalStateException.class) + public void testMusicUtil() { + System.out.println("MusicUtil Constructor Test"); + MusicUtil mu = new MusicUtil(); + System.out.println(mu.toString()); + } + + @Test + public void testConvertToCQLDataType() throws Exception { + Map myMap = new HashMap(); + myMap.put("name","tom"); + assertEquals(MusicUtil.convertToCQLDataType(DataType.varchar(),"Happy People"),"'Happy People'"); + assertEquals(MusicUtil.convertToCQLDataType(DataType.uuid(),UUID.fromString("29dc2afa-c2c0-47ae-afae-e72a645308ab")),"29dc2afa-c2c0-47ae-afae-e72a645308ab"); + assertEquals(MusicUtil.convertToCQLDataType(DataType.blob(),"Hi"),"Hi"); + assertEquals(MusicUtil.convertToCQLDataType(DataType.map(DataType.varchar(),DataType.varchar()),myMap),"{'name':'tom'}"); + } + + @Test + public void testConvertToActualDataType() throws Exception { + assertEquals(MusicUtil.convertToActualDataType(DataType.varchar(),"Happy People"),"Happy People"); + assertEquals(MusicUtil.convertToActualDataType(DataType.uuid(),"29dc2afa-c2c0-47ae-afae-e72a645308ab"),UUID.fromString("29dc2afa-c2c0-47ae-afae-e72a645308ab")); + assertEquals(MusicUtil.convertToActualDataType(DataType.varint(),"1234"),BigInteger.valueOf(Long.parseLong("1234"))); + assertEquals(MusicUtil.convertToActualDataType(DataType.bigint(),"123"),Long.parseLong("123")); + assertEquals(MusicUtil.convertToActualDataType(DataType.cint(),"123"),Integer.parseInt("123")); + assertEquals(MusicUtil.convertToActualDataType(DataType.cfloat(),"123.01"),Float.parseFloat("123.01")); + assertEquals(MusicUtil.convertToActualDataType(DataType.cdouble(),"123.02"),Double.parseDouble("123.02")); + assertEquals(MusicUtil.convertToActualDataType(DataType.cboolean(),"true"),Boolean.parseBoolean("true")); + List myList = new ArrayList(); + List newList = myList; + myList.add("TOM"); + assertEquals(MusicUtil.convertToActualDataType(DataType.list(DataType.varchar()),myList),newList); + Map myMap = new HashMap(); + myMap.put("name","tom"); + Map newMap = myMap; + assertEquals(MusicUtil.convertToActualDataType(DataType.map(DataType.varchar(),DataType.varchar()),myMap),newMap); + } + + @Test + public void testConvertToActualDataTypeByte() throws Exception { + byte[] testByte = "TOM".getBytes(); + assertEquals(MusicUtil.convertToActualDataType(DataType.blob(),testByte),ByteBuffer.wrap(testByte)); + + } + + @Test + public void testJsonMaptoSqlString() throws Exception { + Map myMap = new HashMap<>(); + myMap.put("name","tom"); + myMap.put("value",5); + String result = MusicUtil.jsonMaptoSqlString(myMap,","); + assertTrue(result.contains("name")); + assertTrue(result.contains("value")); + } + + @Test + public void test_generateUUID() { + //this function shouldn't be in cachingUtil + System.out.println("Testing getUUID"); + String uuid1 = MusicUtil.generateUUID(); + String uuid2 = MusicUtil.generateUUID(); + assertFalse(uuid1==uuid2); + } + + + @Test + public void testIsValidConsistency(){ + assertTrue(MusicUtil.isValidConsistency("ALL")); + assertFalse(MusicUtil.isValidConsistency("TEST")); + } + + @Test + public void testLockUsing() { + MusicUtil.setLockUsing("testlock"); + assertEquals("testlock", MusicUtil.getLockUsing()); + } + + @Test + public void testCassaPort() { + MusicUtil.setCassandraPort(1234); + assertEquals(1234, MusicUtil.getCassandraPort()); + } + + @Test + public void testBuild() { + MusicUtil.setBuild("testbuild"); + assertEquals("testbuild", MusicUtil.getBuild()); + } + + @Test + public void testTransId() { + MusicUtil.setTransIdPrefix("prefix"); + assertEquals("prefix-", MusicUtil.getTransIdPrefix()); + } + + + @Test + public void testConversationIdPrefix() { + MusicUtil.setConversationIdPrefix("prefix-"); + assertEquals("prefix-", MusicUtil.getConversationIdPrefix()); + } + + @Test + public void testClientIdPrefix() { + MusicUtil.setClientIdPrefix("clientIdPrefix"); + assertEquals("clientIdPrefix-", MusicUtil.getClientIdPrefix()); + } + + @Test + public void testMessageIdPrefix() { + MusicUtil.setMessageIdPrefix("clientIdPrefix"); + assertEquals("clientIdPrefix-", MusicUtil.getMessageIdPrefix()); + } + + @Test + public void testTransIdPrefix() { + MusicUtil.setTransIdPrefix("transIdPrefix"); + assertEquals("transIdPrefix-", MusicUtil.getTransIdPrefix()); + } + + @Test + public void testConvIdReq() { + MusicUtil.setConversationIdRequired(true); + assertEquals(true, MusicUtil.getConversationIdRequired()); + } + + @Test + public void testClientIdRequired() { + MusicUtil.setClientIdRequired(true); + assertEquals(true, MusicUtil.getClientIdRequired()); + } + + @Test + public void testMessageIdRequired() { + MusicUtil.setMessageIdRequired(true); + assertEquals(true, MusicUtil.getMessageIdRequired()); + } + + @Test + public void testTransIdRequired() { + MusicUtil.setTransIdRequired(true); + assertEquals(true,MusicUtil.getTransIdRequired()); + } +/* + @Test + public void testLoadProperties() { + PropertiesLoader pl = new PropertiesLoader(); + pl.loadProperties(); + } +*/ +} diff --git a/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonDeleteTest.java b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonDeleteTest.java new file mode 100644 index 00000000..0014f823 --- /dev/null +++ b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonDeleteTest.java @@ -0,0 +1,85 @@ +/* + * ============LICENSE_START========================================== + * org.onap.music + * =================================================================== + * Copyright (c) 2017 AT&T Intellectual Property + * =================================================================== + * Modifications Copyright (c) 2019 Samsung + * =================================================================== + * 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.datastore.jsonobjects; + +import static org.junit.Assert.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.Before; +import org.junit.Test; + +public class JsonDeleteTest { + + JsonDelete jd = null; + + @Before + public void init() { + jd = new JsonDelete(); + } + + @Test + public void testGetConditions() { + Map mapSo = new HashMap<>(); + mapSo.put("key1","one"); + mapSo.put("key2","two"); + jd.setConditions(mapSo); + assertEquals("one",jd.getConditions().get("key1")); + } + + @Test + public void testGetConsistencyInfo() { + Map mapSs = new HashMap<>(); + mapSs.put("key3","three"); + mapSs.put("key4","four"); + jd.setConsistencyInfo(mapSs); + assertEquals("three",jd.getConsistencyInfo().get("key3")); + } + + @Test + public void testGetColumns() { + List ary = new ArrayList<>(); + ary.add("e1"); + ary.add("e2"); + ary.add("e3"); + jd.setColumns(ary); + assertEquals("e1",jd.getColumns().get(0)); + } + + @Test + public void testGetTtl() { + jd.setTtl("2000"); + assertEquals("2000",jd.getTtl()); + } + + @Test + public void testGetTimestamp() { + jd.setTimestamp("20:00"); + assertEquals("20:00",jd.getTimestamp()); + + } + +} diff --git a/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonInsertTest.java b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonInsertTest.java new file mode 100644 index 00000000..ad71c9ea --- /dev/null +++ b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonInsertTest.java @@ -0,0 +1,176 @@ +/* + * ============LICENSE_START========================================== + * org.onap.music + * =================================================================== + * Copyright (c) 2017 AT&T Intellectual Property + * =================================================================== + * Modifications Copyright (c) 2019 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.datastore.jsonobjects; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.SerializationUtils; +import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.internal.util.reflection.FieldSetter; +import org.onap.music.datastore.MusicDataStore; +import org.onap.music.datastore.MusicDataStoreHandle; +import org.onap.music.datastore.PreparedQueryObject; +import org.onap.music.exceptions.MusicQueryException; +import org.onap.music.exceptions.MusicServiceException; +import com.datastax.driver.core.ColumnMetadata; +import com.datastax.driver.core.DataType; +import com.datastax.driver.core.Session; +//import org.mockito.internal.util.reflection.Whitebox; +import com.datastax.driver.core.TableMetadata; + + +public class JsonInsertTest { + + JsonInsert ji = new JsonInsert(); + + @Test + public void testGetKeyspaceName() { + ji.setKeyspaceName("keyspace"); + assertEquals("keyspace",ji.getKeyspaceName()); + } + + @Test + public void testGetTableName() { + ji.setTableName("table"); + assertEquals("table",ji.getTableName()); + } + + @Test + public void testGetConsistencyInfo() { + Map cons = new HashMap<>(); + cons.put("test","true"); + ji.setConsistencyInfo(cons); + assertEquals("true",ji.getConsistencyInfo().get("test")); + } + + @Test + public void testGetTtl() { + ji.setTtl("ttl"); + assertEquals("ttl",ji.getTtl()); + } + + @Test + public void testGetTimestamp() { + ji.setTimestamp("10:30"); + assertEquals("10:30",ji.getTimestamp()); + } + + @Test + public void testGetValues() { + Map cons = new HashMap<>(); + cons.put("val1","one"); + cons.put("val2","two"); + ji.setValues(cons); + assertEquals("one",ji.getValues().get("val1")); + } + + @Test + public void testGetRowSpecification() { + Map cons = new HashMap<>(); + cons.put("val1","one"); + cons.put("val2","two"); + ji.setRowSpecification(cons); + assertEquals("two",ji.getRowSpecification().get("val2")); + } + + @Test + public void testSerialize() { + Map cons = new HashMap<>(); + cons.put("val1","one"); + cons.put("val2","two"); + ji.setTimestamp("10:30"); + ji.setRowSpecification(cons); + byte[] test1 = ji.serialize(); + byte[] ji1 = SerializationUtils.serialize(ji); + assertArrayEquals(ji1,test1); + } + + @Test + public void testObjectMap() + { + Map map = new HashMap<>(); + ji.setObjectMap(map); + assertEquals(map, ji.getObjectMap()); + } + + @Test + public void testPrimaryKey() { + ji.setPrimaryKeyVal("primKey"); + assertEquals("primKey", ji.getPrimaryKeyVal()); + } + + @Test + public void testGenInsertPreparedQueryObj() throws Exception { + ji.setKeyspaceName("keyspace"); + ji.setTableName("table"); + ji.setPrimaryKeyVal("value"); + Map rowSpec = new HashMap<>(); + rowSpec.put("val1","one"); + rowSpec.put("val2","two"); + ji.setRowSpecification(rowSpec); + Map vals = new HashMap<>(); + vals.put("val1","one"); + vals.put("val2","two"); + ji.setValues(vals); + + Map cons = new HashMap<>(); + cons.put("type","quorum"); + ji.setConsistencyInfo(cons); + + MusicDataStore mds = Mockito.mock(MusicDataStore.class); + Session session = Mockito.mock(Session.class); + Mockito.when(mds.getSession()).thenReturn(session); + MusicDataStoreHandle mdsh = Mockito.mock(MusicDataStoreHandle.class); + FieldSetter.setField(mdsh, mdsh.getClass().getDeclaredField("mDstoreHandle"), mds); + TableMetadata tableMeta = Mockito.mock(TableMetadata.class); + Mockito.when(mds.returnColumnMetadata(Mockito.anyString(), Mockito.anyString())) + .thenReturn(tableMeta); + + ColumnMetadata cmd = Mockito.mock(ColumnMetadata.class); + List listcmd = new ArrayList<>(); + listcmd.add(cmd); + Mockito.when(tableMeta.getPrimaryKey()).thenReturn(listcmd); + Mockito.when(cmd.getName()).thenReturn("val1"); + Mockito.when(tableMeta.getColumn("val1")).thenReturn(cmd); + Mockito.when(tableMeta.getColumn("val2")).thenReturn(cmd); + Mockito.when(cmd.getType()).thenReturn(DataType.text()); + + PreparedQueryObject query = ji.genInsertPreparedQueryObj(); + System.out.println(query.getQuery()); + System.out.println(query.getValues()); + + + assertEquals("INSERT INTO keyspace.table (vector_ts,val2,val1) VALUES (?,?,?);", query.getQuery()); + assertTrue(query.getValues().containsAll(vals.values())); + } + +} diff --git a/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonKeySpaceTest.java b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonKeySpaceTest.java new file mode 100644 index 00000000..a3fa58e4 --- /dev/null +++ b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonKeySpaceTest.java @@ -0,0 +1,72 @@ +/* + * ============LICENSE_START========================================== + * org.onap.music + * =================================================================== + * Copyright (c) 2017 AT&T Intellectual Property + * =================================================================== + * 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.datastore.jsonobjects; + +import static org.junit.Assert.*; +import java.util.HashMap; +import java.util.Map; +import org.junit.Before; +import org.junit.Test; + +public class JsonKeySpaceTest { + + JsonKeySpace jk = null; + + + @Before + public void init() { + jk = new JsonKeySpace(); + } + + + + @Test + public void testGetConsistencyInfo() { + Map mapSs = new HashMap<>(); + mapSs.put("k1", "one"); + jk.setConsistencyInfo(mapSs); + assertEquals("one",jk.getConsistencyInfo().get("k1")); + } + + @Test + public void testGetReplicationInfo() { + Map mapSo = new HashMap<>(); + mapSo.put("k1", "one"); + jk.setReplicationInfo(mapSo); + assertEquals("one",jk.getReplicationInfo().get("k1")); + + } + + @Test + public void testGetDurabilityOfWrites() { + jk.setDurabilityOfWrites("1"); + assertEquals("1",jk.getDurabilityOfWrites()); + } + + @Test + public void testGetKeyspaceName() { + jk.setKeyspaceName("Keyspace"); + assertEquals("Keyspace",jk.getKeyspaceName()); + } + +} diff --git a/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonSelectTest.java b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonSelectTest.java new file mode 100644 index 00000000..21c022ab --- /dev/null +++ b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonSelectTest.java @@ -0,0 +1,55 @@ +/* + * ============LICENSE_START========================================== + * org.onap.music + * =================================================================== + * Copyright (c) 2017 AT&T Intellectual Property + * =================================================================== + * Modifications Copyright (c) 2018-2019 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.datastore.jsonobjects; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; + +public class JsonSelectTest { + + @Test + public void testGetConsistencyInfo() { + JsonSelect js = new JsonSelect(); + Map mapSs = new HashMap<>(); + mapSs.put("k1", "one"); + js.setConsistencyInfo(mapSs); + assertEquals("one", js.getConsistencyInfo().get("k1")); + } + + @Test + public void testSerialize() throws IOException { + JsonSelect js = new JsonSelect(); + Map mapSs = new HashMap<>(); + mapSs.put("Key", "Value"); + js.setConsistencyInfo(mapSs); + js.serialize(); + } + +} diff --git a/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonTableTest.java b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonTableTest.java new file mode 100644 index 00000000..3ab32d40 --- /dev/null +++ b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonTableTest.java @@ -0,0 +1,153 @@ +/* + * ============LICENSE_START========================================== + * org.onap.music + * =================================================================== + * Copyright (c) 2017 AT&T Intellectual Property + * =================================================================== + * Modifications Copyright (c) 2019 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.datastore.jsonobjects; + +import static org.junit.Assert.*; +import java.util.HashMap; +import java.util.Map; +import org.junit.Before; +import org.junit.Test; +import org.onap.music.exceptions.MusicQueryException; + +public class JsonTableTest { + + JsonTable jt = null; + + @Before + public void init() { + jt = new JsonTable(); + } + + @Test + public void testGetConsistencyInfo() { + Map mapSs = new HashMap<>(); + mapSs.put("k1", "one"); + jt.setConsistencyInfo(mapSs); + assertEquals("one",jt.getConsistencyInfo().get("k1")); + } + + @Test + public void testGetProperties() { + Map properties = new HashMap<>(); + properties.put("k1", "one"); + jt.setProperties(properties); + assertEquals(properties.size(), jt.getProperties().size()); + } + + @Test + public void testGetFields() { + Map fields = new HashMap<>(); + fields.put("k1", "one"); + jt.setFields(fields); + assertEquals("one",jt.getFields().get("k1")); + } + + @Test + public void testGetKeyspaceName() { + String keyspace = "keyspace"; + jt.setKeyspaceName(keyspace); + assertEquals(keyspace,jt.getKeyspaceName()); + } + + @Test + public void testGetTableName() { + String table = "table"; + jt.setTableName(table); + assertEquals(table,jt.getTableName()); + } + + @Test + public void testGetClusteringOrder() { + String clusteringOrder = "clusteringOrder"; + jt.setClusteringOrder(clusteringOrder); + assertEquals(clusteringOrder,jt.getClusteringOrder()); + } + + @Test + public void testGetClusterKey() { + String clusterKey = "clusterKey"; + jt.setClusteringKey(clusterKey); + assertEquals(clusterKey, jt.getClusteringKey()); + } + + @Test + public void testGetPrimaryKey() { + String primaryKey = "primaryKey"; + jt.setPrimaryKey(primaryKey); + assertEquals(primaryKey,jt.getPrimaryKey()); + } + + @Test + public void testFilteringKey() { + jt.setFilteringKey("FilteringKey"); + assertEquals("FilteringKey",jt.getFilteringKey()); + } + + @Test + public void testPartitionKey() { + jt.setPartitionKey("ParitionKey"); + assertEquals("ParitionKey",jt.getPartitionKey()); + } + + @Test + public void genCreateTableQuery() throws MusicQueryException { + JsonTable jt2 = new JsonTable(); + jt2.setKeyspaceName("keyspace"); + jt2.setTableName("table"); + Map fields = new HashMap<>(); + fields.put("k1", "one"); + jt2.setFields(fields); + jt2.setPrimaryKey("k1"); + Map mapSs = new HashMap<>(); + mapSs.put("k1", "one"); + jt2.setConsistencyInfo(mapSs); + String clusteringOrder = "clusteringOrder"; + jt.setClusteringOrder(clusteringOrder); + String clusterKey = "clusterKey"; + jt.setClusteringKey(clusterKey); + + System.out.println(jt2.genCreateTableQuery().getQuery()); + assertEquals("CREATE TABLE keyspace.table (vector_ts text,k1 one, PRIMARY KEY ( (k1) ));", + jt2.genCreateTableQuery().getQuery()); + } + + @Test + public void genDropTableQuery() throws MusicQueryException { + JsonTable jt2 = new JsonTable(); + jt2.setKeyspaceName("keyspace"); + jt2.setTableName("table"); + Map fields = new HashMap<>(); + fields.put("k1", "one"); + jt2.setFields(fields); + jt2.setPrimaryKey("k1"); + Map mapSs = new HashMap<>(); + mapSs.put("k1", "one"); + jt.setConsistencyInfo(mapSs); + + System.out.println(jt2.genDropTableQuery().getQuery()); + assertEquals("DROP TABLE keyspace.table;", + jt2.genDropTableQuery().getQuery()); + } +} diff --git a/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonUpdateTest.java b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonUpdateTest.java new file mode 100644 index 00000000..37c729f4 --- /dev/null +++ b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonUpdateTest.java @@ -0,0 +1,166 @@ +/******************************************************************************* + * ============LICENSE_START========================================== + * org.onap.music + * =================================================================== + * Copyright (c) 2018 AT&T Intellectual Property + * =================================================================== + * Modifications Copyright (c) 2019 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.datastore.jsonobjects; + +import static org.junit.Assert.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.ws.rs.core.MultivaluedMap; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.music.datastore.jsonobjects.JsonUpdate.RowIdentifier; +import com.datastax.driver.core.ColumnMetadata; +import com.datastax.driver.core.DataType; +import com.datastax.driver.core.TableMetadata; + +public class JsonUpdateTest { + + JsonUpdate ju = null; + + @Before + public void init() { + ju = new JsonUpdate(); + } + + + @Test + public void testGetConditions() { + Map mapSo = new HashMap<>(); + mapSo.put("key1","one"); + mapSo.put("key2","two"); + ju.setConditions(mapSo); + assertEquals("one",ju.getConditions().get("key1")); + } + + @Test + public void testGetRow_specification() { + Map mapSo = new HashMap<>(); + mapSo.put("key1","one"); + mapSo.put("key2","two"); + ju.setRow_specification(mapSo); + assertEquals("one",ju.getRow_specification().get("key1")); + } + + @Test + public void testGetKeyspaceName() { + String keyspace = "keyspace"; + ju.setKeyspaceName(keyspace); + assertEquals(keyspace,ju.getKeyspaceName()); + } + + @Test + public void testGetTableName() { + String table = "table"; + ju.setTableName(table); + assertEquals(table,ju.getTableName()); + } + + @Test + public void testGetConsistencyInfo() { + Map mapSs = new HashMap<>(); + mapSs.put("k1", "one"); + ju.setConsistencyInfo(mapSs); + assertEquals("one",ju.getConsistencyInfo().get("k1")); + } + + @Test + public void testGetTtl() { + ju.setTtl("2000"); + assertEquals("2000",ju.getTtl()); + } + + @Test + public void testGetTimestamp() { + ju.setTimestamp("20:00"); + assertEquals("20:00",ju.getTimestamp()); + + } + + @Test + public void testGetValues() { + Map cons = new HashMap<>(); + cons.put("val1","one"); + cons.put("val2","two"); + ju.setValues(cons); + assertEquals("one",ju.getValues().get("val1")); + } + + @Test + public void testSerialize() { + assertTrue(ju.serialize() instanceof byte[]); + } + + @Test + public void testRowIdString() { + ju.setRowIdString("testing"); + assertEquals("testing", ju.getRowIdString()); + } + + @Test + public void testPrimaryKeyValue() { + ju.setPrimarKeyValue("primeKey"); + assertEquals("primeKey", ju.getPrimarKeyValue()); + } + + @Test + public void testGenUpdatePreparedQueryObj() throws Exception { + JsonUpdate ju = Mockito.spy(JsonUpdate.class); + MultivaluedMap rowParams = Mockito.mock(MultivaluedMap.class); + + ju.setKeyspaceName("keyspace"); + ju.setTableName("table"); + ju.setPrimarKeyValue("primaryKeyValue"); + Map consistencyInfo = new HashMap<>(); + consistencyInfo.put("type", "critical"); + ju.setConsistencyInfo(consistencyInfo); + Map values = new HashMap<>(); + values.put("col1", "val1"); + ju.setValues(values); + + TableMetadata tmd = Mockito.mock(TableMetadata.class); + Mockito.doReturn(tmd).when(ju).returnColumnMetadata(Mockito.anyString(), Mockito.anyString()); + ColumnMetadata cmd = Mockito.mock(ColumnMetadata.class); + Mockito.when(tmd.getColumn("col1")).thenReturn(cmd); + List colList = new ArrayList<>(); + colList.add(cmd); + Mockito.when(tmd.getPrimaryKey()).thenReturn(colList); + Mockito.when(cmd.getType()).thenReturn(DataType.varchar()); + + RowIdentifier rowId = Mockito.mock(RowIdentifier.class); + Mockito.doReturn(rowId).when(ju).getRowIdentifier(Mockito.anyString(), Mockito.anyString(), Mockito.any(), + Mockito.any()); + + Mockito.when(rowId.getRowIdString()).thenReturn("col1"); + Mockito.when(rowId.getPrimaryKeyValue()).thenReturn("val1"); + + + assertEquals("UPDATE keyspace.table SET vector_ts=?,col1= ? WHERE col1;", + ju.genUpdatePreparedQueryObj(rowParams).getQuery()); + } +} diff --git a/music-core/src/test/java/org/onap/music/main/ResultTypeTest.java b/music-core/src/test/java/org/onap/music/main/ResultTypeTest.java new file mode 100644 index 00000000..d6ccc1f1 --- /dev/null +++ b/music-core/src/test/java/org/onap/music/main/ResultTypeTest.java @@ -0,0 +1,42 @@ +/* + * ============LICENSE_START========================================== + * org.onap.music + * =================================================================== + * Copyright (c) 2017 AT&T Intellectual Property + * =================================================================== + * 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.main; + +import static org.junit.Assert.*; +import org.junit.Test; + +public class ResultTypeTest { + + @Test + public void testResultType() { + assertEquals("SUCCESS",ResultType.SUCCESS.name()); + assertEquals("FAILURE",ResultType.FAILURE.name()); + } + + @Test + public void testGetResult() { + assertEquals("Success",ResultType.SUCCESS.getResult()); + assertEquals("Failure",ResultType.FAILURE.getResult()); + } + +} diff --git a/music-core/src/test/java/org/onap/music/main/ReturnTypeTest.java b/music-core/src/test/java/org/onap/music/main/ReturnTypeTest.java new file mode 100644 index 00000000..fbb5f84d --- /dev/null +++ b/music-core/src/test/java/org/onap/music/main/ReturnTypeTest.java @@ -0,0 +1,82 @@ +/* + * ============LICENSE_START========================================== + * org.onap.music + * =================================================================== + * Copyright (c) 2017 AT&T Intellectual Property + * =================================================================== + * 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.main; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.Map; + +import org.junit.Test; + +public class ReturnTypeTest { + + @Test + public void testReturnType() { + ReturnType result = new ReturnType(ResultType.SUCCESS,"message"); + assertEquals(result.getMessage(),"message"); + assertEquals(result.getResult(),ResultType.SUCCESS); + } + + @Test + public void testTimingInfo() { + ReturnType result = new ReturnType(ResultType.SUCCESS,"message"); + result.setTimingInfo("123"); + assertEquals(result.getTimingInfo(),"123"); + } + + @Test + public void testGetResult() { + ReturnType result = new ReturnType(ResultType.FAILURE,"message"); + assertEquals(result.getResult(),ResultType.FAILURE); + } + + @Test + public void testGetMessage() { + ReturnType result = new ReturnType(ResultType.SUCCESS,"message"); + result.setMessage("NewMessage"); + assertEquals(result.getMessage(),"NewMessage"); + } + + @Test + public void testToJson() { + ReturnType result = new ReturnType(ResultType.SUCCESS,"message"); + String myJson = result.toJson(); + assertTrue(myJson.contains("message")); + } + + @Test + public void testToString() { + ReturnType result = new ReturnType(ResultType.SUCCESS,"message"); + String test = result.toString(); + assertTrue(test.contains("message")); + } + + @Test + public void testToMap() { + ReturnType result = new ReturnType(ResultType.SUCCESS,"message"); + Map myMap = result.toMap(); + assertTrue(myMap.containsKey("message")); + } + +} diff --git a/music-core/src/test/java/org/onap/music/unittests/CassandraCQL.java b/music-core/src/test/java/org/onap/music/unittests/CassandraCQL.java deleted file mode 100644 index 582744fb..00000000 --- a/music-core/src/test/java/org/onap/music/unittests/CassandraCQL.java +++ /dev/null @@ -1,245 +0,0 @@ -/* - * ============LICENSE_START========================================== - * org.onap.music - * =================================================================== - * Copyright (c) 2017 AT&T Intellectual Property - * =================================================================== - * 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.unittests; - -/** - * @author srupane - * - */ - -import java.math.BigInteger; -import java.net.InetAddress; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -//import org.apache.thrift.transport.TTransportException; -import org.cassandraunit.utils.EmbeddedCassandraServerHelper; -import org.onap.music.datastore.MusicDataStore; -import org.onap.music.datastore.PreparedQueryObject; -import org.onap.music.lockingservice.cassandra.LockType; -import com.datastax.driver.core.Cluster; -import com.datastax.driver.core.Session; -import com.datastax.driver.extras.codecs.enums.EnumNameCodec; - -public class CassandraCQL { - public static final String createAdminKeyspace = "CREATE KEYSPACE admin WITH REPLICATION = " - + "{'class' : 'SimpleStrategy' , 'replication_factor': 1} AND DURABLE_WRITES = true"; - - public static final String createAdminTable = "CREATE TABLE admin.keyspace_master (" + " uuid uuid, keyspace_name text," - + " application_name text, is_api boolean," - + " password text, username text," - + " is_aaf boolean, PRIMARY KEY (uuid)\n" + ");"; - - public static final String createKeySpace = - "CREATE KEYSPACE IF NOT EXISTS testcassa WITH replication = " - +"{'class':'SimpleStrategy','replication_factor':1} AND durable_writes = true;"; - - public static final String dropKeyspace = "DROP KEYSPACE IF EXISTS testcassa"; - - public static final String createTableEmployees = - "CREATE TABLE IF NOT EXISTS testcassa.employees " - + "(vector_ts text,empid uuid,empname text,empsalary varint,address Map,PRIMARY KEY (empname)) " - + "WITH comment='Financial Info of employees' " - + "AND compression={'sstable_compression':'DeflateCompressor','chunk_length_kb':64} " - + "AND compaction={'class':'SizeTieredCompactionStrategy','min_threshold':6};"; - - public static final String insertIntoTablePrepared1 = - "INSERT INTO testcassa.employees (vector_ts,empid,empname,empsalary) VALUES (?,?,?,?); "; - - public static final String insertIntoTablePrepared2 = - "INSERT INTO testcassa.employees (vector_ts,empid,empname,empsalary,address) VALUES (?,?,?,?,?);"; - - public static final String selectALL = "SELECT * FROM testcassa.employees;"; - - public static final String selectSpecific = - "SELECT * FROM testcassa.employees WHERE empname= ?;"; - - public static final String updatePreparedQuery = - "UPDATE testcassa.employees SET vector_ts=?,address= ? WHERE empname= ?;"; - - public static final String deleteFromTable = " "; - - public static final String deleteFromTablePrepared = " "; - - // Set Values for Prepared Query - - public static List setPreparedInsertValues1() { - - List preppreparedInsertValues1 = new ArrayList<>(); - String vectorTs = - String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis()); - UUID empId = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40cd6"); - BigInteger empSalary = BigInteger.valueOf(23443); - String empName = "Mr Test one"; - preppreparedInsertValues1.add(vectorTs); - preppreparedInsertValues1.add(empId); - preppreparedInsertValues1.add(empName); - preppreparedInsertValues1.add(empSalary); - return preppreparedInsertValues1; - } - - public static List setPreparedInsertValues2() { - - List preparedInsertValues2 = new ArrayList<>(); - String vectorTs = - String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis()); - UUID empId = UUID.fromString("abc434cc-d657-4e90-b4e5-df4223d40cd6"); - BigInteger empSalary = BigInteger.valueOf(45655); - String empName = "Mr Test two"; - Map address = new HashMap<>(); - preparedInsertValues2.add(vectorTs); - preparedInsertValues2.add(empId); - preparedInsertValues2.add(empName); - preparedInsertValues2.add(empSalary); - address.put("Street", "1 some way"); - address.put("City", "Some town"); - preparedInsertValues2.add(address); - return preparedInsertValues2; - } - - public static List setPreparedUpdateValues() { - - List preparedUpdateValues = new ArrayList<>(); - String vectorTs = - String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis()); - Map address = new HashMap<>(); - preparedUpdateValues.add(vectorTs); - String empName = "Mr Test one"; - address.put("Street", "101 Some Way"); - address.put("City", "New York"); - preparedUpdateValues.add(address); - preparedUpdateValues.add(empName); - return preparedUpdateValues; - } - - // Generate Different Prepared Query Objects - /** - * Query Object for Get. - * - * @return - */ - public static PreparedQueryObject setPreparedGetQuery() { - - PreparedQueryObject queryObject = new PreparedQueryObject(); - String empName1 = "Mr Test one"; - queryObject.appendQueryString(selectSpecific); - queryObject.addValue(empName1); - return queryObject; - } - - /** - * Query Object 1 for Insert. - * - * @return {@link PreparedQueryObject} - */ - public static PreparedQueryObject setPreparedInsertQueryObject1() { - - PreparedQueryObject queryobject = new PreparedQueryObject(); - queryobject.appendQueryString(insertIntoTablePrepared1); - List values = setPreparedInsertValues1(); - if (!values.isEmpty() || values != null) { - for (Object o : values) { - queryobject.addValue(o); - } - } - return queryobject; - - } - - /** - * Query Object 2 for Insert. - * - * @return {@link PreparedQueryObject} - */ - public static PreparedQueryObject setPreparedInsertQueryObject2() { - - PreparedQueryObject queryobject = new PreparedQueryObject(); - queryobject.appendQueryString(insertIntoTablePrepared2); - List values = setPreparedInsertValues2(); - if (!values.isEmpty() || values != null) { - for (Object o : values) { - queryobject.addValue(o); - } - } - return queryobject; - - } - - /** - * Query Object for Update. - * - * @return {@link PreparedQueryObject} - */ - public static PreparedQueryObject setPreparedUpdateQueryObject() { - - PreparedQueryObject queryobject = new PreparedQueryObject(); - queryobject.appendQueryString(updatePreparedQuery); - List values = setPreparedUpdateValues(); - if (!values.isEmpty() || values != null) { - for (Object o : values) { - queryobject.addValue(o); - } - } - return queryobject; - - } - - private static ArrayList getAllPossibleLocalIps() { - ArrayList allPossibleIps = new ArrayList(); - try { - Enumeration en = NetworkInterface.getNetworkInterfaces(); - while (en.hasMoreElements()) { - NetworkInterface ni = (NetworkInterface) en.nextElement(); - Enumeration ee = ni.getInetAddresses(); - while (ee.hasMoreElements()) { - InetAddress ia = (InetAddress) ee.nextElement(); - allPossibleIps.add(ia.getHostAddress()); - } - } - } catch (SocketException e) { - System.out.println(e.getMessage()); - } - return allPossibleIps; - } - - public static MusicDataStore connectToEmbeddedCassandra() throws Exception { - System.setProperty("log4j.configuration", "log4j.properties"); - - String address = "localhost"; - - EmbeddedCassandraServerHelper.startEmbeddedCassandra(); - Cluster cluster = new Cluster.Builder().withoutJMXReporting().withoutMetrics().addContactPoint(address).withPort(9142).build(); - cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(5000); - - Session session = cluster.connect(); - - return new MusicDataStore(cluster, session); - } - -} diff --git a/music-core/src/test/java/org/onap/music/unittests/MusicUtilTest.java b/music-core/src/test/java/org/onap/music/unittests/MusicUtilTest.java deleted file mode 100644 index 39432d07..00000000 --- a/music-core/src/test/java/org/onap/music/unittests/MusicUtilTest.java +++ /dev/null @@ -1,332 +0,0 @@ -/* - * ============LICENSE_START========================================== - * org.onap.music - * =================================================================== - * Copyright (c) 2017 AT&T Intellectual Property - * Modifications Copyright (C) 2019 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.unittests; - -import static org.junit.Assert.*; -import java.math.BigInteger; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.junit.Test; -import org.onap.music.datastore.PreparedQueryObject; -import org.onap.music.main.MusicUtil; -//import org.onap.music.main.CorePropertiesLoader; -import org.onap.music.service.MusicCoreService; - -import com.datastax.driver.core.ConsistencyLevel; -import com.datastax.driver.core.DataType; - -public class MusicUtilTest { - - private static final String XLATESTVERSION = "X-latestVersion"; - private static final String XMINORVERSION = "X-minorVersion"; - private static final String XPATCHVERSION = "X-patchVersion"; - - @Test - public void testGetCassName() { - MusicUtil.setCassName("Cassandra"); - assertTrue(MusicUtil.getCassName().equals("Cassandra")); - } - - @Test - public void testGetCassPwd() { - MusicUtil.setCassPwd("Cassandra"); - assertTrue(MusicUtil.getCassPwd().equals("Cassandra")); - } - - @Test - public void testMusicAafNs() { - MusicUtil.setMusicAafNs("ns"); - assertTrue("ns".equals(MusicUtil.getMusicAafNs())); - } - - @Test - public void testMusicCoreService() { - MusicUtil.setLockUsing(MusicUtil.CASSANDRA); - MusicCoreService mc = null; - mc = MusicUtil.getMusicCoreService(); - assertTrue(mc != null); - MusicUtil.setLockUsing("nothing"); - mc = null; - mc = MusicUtil.getMusicCoreService(); - assertTrue(mc != null); - - } - - @Test - public void testCipherEncKey() { - MusicUtil.setCipherEncKey("cipherEncKey"); - assertTrue("cipherEncKey".equals(MusicUtil.getCipherEncKey())); - } - - @Test - public void testGetMusicPropertiesFilePath() { - MusicUtil.setMusicPropertiesFilePath("filepath"); - assertEquals(MusicUtil.getMusicPropertiesFilePath(),"filepath"); - } - - @Test - public void testGetDefaultLockLeasePeriod() { - MusicUtil.setDefaultLockLeasePeriod(5000); - assertEquals(MusicUtil.getDefaultLockLeasePeriod(),5000); - } - - @Test - public void testIsDebug() { - MusicUtil.setDebug(true); - assertTrue(MusicUtil.isDebug()); - } - - @Test - public void testGetVersion() { - MusicUtil.setVersion("1.0.0"); - assertEquals(MusicUtil.getVersion(),"1.0.0"); - } - - @Test - public void testBuildVersionA() { - assertEquals(MusicUtil.buildVersion("1","2","3"),"1.2.3"); - } - - @Test - public void testBuildVersionB() { - assertEquals(MusicUtil.buildVersion("1",null,"3"),"1"); - } - - @Test - public void testBuildVersionC() { - assertEquals(MusicUtil.buildVersion("1","2",null),"1.2"); - } - -/* - @Test - public void testBuileVersionResponse() { - assertTrue(MusicUtil.buildVersionResponse("1","2","3").getClass().getSimpleName().equals("Builder")); - assertTrue(MusicUtil.buildVersionResponse("1",null,"3").getClass().getSimpleName().equals("Builder")); - assertTrue(MusicUtil.buildVersionResponse("1","2",null).getClass().getSimpleName().equals("Builder")); - assertTrue(MusicUtil.buildVersionResponse(null,null,null).getClass().getSimpleName().equals("Builder")); - } -*/ - @Test - public void testGetConsistency() { - assertTrue(ConsistencyLevel.ONE.equals(MusicUtil.getConsistencyLevel("one"))); - } - - @Test - public void testRetryCount() { - MusicUtil.setRetryCount(1); - assertEquals(MusicUtil.getRetryCount(),1); - } - - @Test - public void testIsCadi() { - MusicUtil.setIsCadi(true); - assertEquals(MusicUtil.getIsCadi(),true); - } - - - @Test - public void testGetMyCassaHost() { - MusicUtil.setMyCassaHost("10.0.0.2"); - assertEquals(MusicUtil.getMyCassaHost(),"10.0.0.2"); - } - - @Test - public void testIsValidQueryObject() { - PreparedQueryObject myQueryObject = new PreparedQueryObject(); - myQueryObject.appendQueryString("select * from apple where type = ?"); - myQueryObject.addValue("macintosh"); - assertTrue(MusicUtil.isValidQueryObject(true,myQueryObject)); - - myQueryObject.appendQueryString("select * from apple"); - assertTrue(MusicUtil.isValidQueryObject(false,myQueryObject)); - - myQueryObject.appendQueryString("select * from apple where type = ?"); - assertFalse(MusicUtil.isValidQueryObject(true,myQueryObject)); - - myQueryObject = new PreparedQueryObject(); - myQueryObject.appendQueryString(""); - System.out.println("#######" + myQueryObject.getQuery().isEmpty()); - assertFalse(MusicUtil.isValidQueryObject(false,myQueryObject)); - - - } - - - - - @Test(expected = IllegalStateException.class) - public void testMusicUtil() { - System.out.println("MusicUtil Constructor Test"); - MusicUtil mu = new MusicUtil(); - System.out.println(mu.toString()); - } - - @Test - public void testConvertToCQLDataType() throws Exception { - Map myMap = new HashMap(); - myMap.put("name","tom"); - assertEquals(MusicUtil.convertToCQLDataType(DataType.varchar(),"Happy People"),"'Happy People'"); - assertEquals(MusicUtil.convertToCQLDataType(DataType.uuid(),UUID.fromString("29dc2afa-c2c0-47ae-afae-e72a645308ab")),"29dc2afa-c2c0-47ae-afae-e72a645308ab"); - assertEquals(MusicUtil.convertToCQLDataType(DataType.blob(),"Hi"),"Hi"); - assertEquals(MusicUtil.convertToCQLDataType(DataType.map(DataType.varchar(),DataType.varchar()),myMap),"{'name':'tom'}"); - } - - @Test - public void testConvertToActualDataType() throws Exception { - assertEquals(MusicUtil.convertToActualDataType(DataType.varchar(),"Happy People"),"Happy People"); - assertEquals(MusicUtil.convertToActualDataType(DataType.uuid(),"29dc2afa-c2c0-47ae-afae-e72a645308ab"),UUID.fromString("29dc2afa-c2c0-47ae-afae-e72a645308ab")); - assertEquals(MusicUtil.convertToActualDataType(DataType.varint(),"1234"),BigInteger.valueOf(Long.parseLong("1234"))); - assertEquals(MusicUtil.convertToActualDataType(DataType.bigint(),"123"),Long.parseLong("123")); - assertEquals(MusicUtil.convertToActualDataType(DataType.cint(),"123"),Integer.parseInt("123")); - assertEquals(MusicUtil.convertToActualDataType(DataType.cfloat(),"123.01"),Float.parseFloat("123.01")); - assertEquals(MusicUtil.convertToActualDataType(DataType.cdouble(),"123.02"),Double.parseDouble("123.02")); - assertEquals(MusicUtil.convertToActualDataType(DataType.cboolean(),"true"),Boolean.parseBoolean("true")); - List myList = new ArrayList(); - List newList = myList; - myList.add("TOM"); - assertEquals(MusicUtil.convertToActualDataType(DataType.list(DataType.varchar()),myList),newList); - Map myMap = new HashMap(); - myMap.put("name","tom"); - Map newMap = myMap; - assertEquals(MusicUtil.convertToActualDataType(DataType.map(DataType.varchar(),DataType.varchar()),myMap),newMap); - } - - @Test - public void testConvertToActualDataTypeByte() throws Exception { - byte[] testByte = "TOM".getBytes(); - assertEquals(MusicUtil.convertToActualDataType(DataType.blob(),testByte),ByteBuffer.wrap(testByte)); - - } - - @Test - public void testJsonMaptoSqlString() throws Exception { - Map myMap = new HashMap<>(); - myMap.put("name","tom"); - myMap.put("value",5); - String result = MusicUtil.jsonMaptoSqlString(myMap,","); - assertTrue(result.contains("name")); - assertTrue(result.contains("value")); - } - - @Test - public void test_generateUUID() { - //this function shouldn't be in cachingUtil - System.out.println("Testing getUUID"); - String uuid1 = MusicUtil.generateUUID(); - String uuid2 = MusicUtil.generateUUID(); - assertFalse(uuid1==uuid2); - } - - - @Test - public void testIsValidConsistency(){ - assertTrue(MusicUtil.isValidConsistency("ALL")); - assertFalse(MusicUtil.isValidConsistency("TEST")); - } - - @Test - public void testLockUsing() { - MusicUtil.setLockUsing("testlock"); - assertEquals("testlock", MusicUtil.getLockUsing()); - } - - @Test - public void testCassaPort() { - MusicUtil.setCassandraPort(1234); - assertEquals(1234, MusicUtil.getCassandraPort()); - } - - @Test - public void testBuild() { - MusicUtil.setBuild("testbuild"); - assertEquals("testbuild", MusicUtil.getBuild()); - } - - @Test - public void testTransId() { - MusicUtil.setTransIdPrefix("prefix"); - assertEquals("prefix-", MusicUtil.getTransIdPrefix()); - } - - - @Test - public void testConversationIdPrefix() { - MusicUtil.setConversationIdPrefix("prefix-"); - assertEquals("prefix-", MusicUtil.getConversationIdPrefix()); - } - - @Test - public void testClientIdPrefix() { - MusicUtil.setClientIdPrefix("clientIdPrefix"); - assertEquals("clientIdPrefix-", MusicUtil.getClientIdPrefix()); - } - - @Test - public void testMessageIdPrefix() { - MusicUtil.setMessageIdPrefix("clientIdPrefix"); - assertEquals("clientIdPrefix-", MusicUtil.getMessageIdPrefix()); - } - - @Test - public void testTransIdPrefix() { - MusicUtil.setTransIdPrefix("transIdPrefix"); - assertEquals("transIdPrefix-", MusicUtil.getTransIdPrefix()); - } - - @Test - public void testConvIdReq() { - MusicUtil.setConversationIdRequired(true); - assertEquals(true, MusicUtil.getConversationIdRequired()); - } - - @Test - public void testClientIdRequired() { - MusicUtil.setClientIdRequired(true); - assertEquals(true, MusicUtil.getClientIdRequired()); - } - - @Test - public void testMessageIdRequired() { - MusicUtil.setMessageIdRequired(true); - assertEquals(true, MusicUtil.getMessageIdRequired()); - } - - @Test - public void testTransIdRequired() { - MusicUtil.setTransIdRequired(true); - assertEquals(true,MusicUtil.getTransIdRequired()); - } -/* - @Test - public void testLoadProperties() { - PropertiesLoader pl = new PropertiesLoader(); - pl.loadProperties(); - } -*/ -} diff --git a/music-core/src/test/java/org/onap/music/unittests/ResultTypeTest.java b/music-core/src/test/java/org/onap/music/unittests/ResultTypeTest.java deleted file mode 100644 index 012629e0..00000000 --- a/music-core/src/test/java/org/onap/music/unittests/ResultTypeTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * ============LICENSE_START========================================== - * org.onap.music - * =================================================================== - * Copyright (c) 2017 AT&T Intellectual Property - * =================================================================== - * 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.unittests; - -import static org.junit.Assert.*; -import org.junit.Test; -import org.onap.music.main.ResultType; - -public class ResultTypeTest { - - @Test - public void testResultType() { - assertEquals("SUCCESS",ResultType.SUCCESS.name()); - assertEquals("FAILURE",ResultType.FAILURE.name()); - } - - @Test - public void testGetResult() { - assertEquals("Success",ResultType.SUCCESS.getResult()); - assertEquals("Failure",ResultType.FAILURE.getResult()); - } - -} diff --git a/music-core/src/test/java/org/onap/music/unittests/ReturnTypeTest.java b/music-core/src/test/java/org/onap/music/unittests/ReturnTypeTest.java deleted file mode 100644 index 490020ac..00000000 --- a/music-core/src/test/java/org/onap/music/unittests/ReturnTypeTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * ============LICENSE_START========================================== - * org.onap.music - * =================================================================== - * Copyright (c) 2017 AT&T Intellectual Property - * =================================================================== - * 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.unittests; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.Map; - -import org.junit.Test; -import org.onap.music.main.ResultType; -import org.onap.music.main.ReturnType; - -public class ReturnTypeTest { - - @Test - public void testReturnType() { - ReturnType result = new ReturnType(ResultType.SUCCESS,"message"); - assertEquals(result.getMessage(),"message"); - assertEquals(result.getResult(),ResultType.SUCCESS); - } - - @Test - public void testTimingInfo() { - ReturnType result = new ReturnType(ResultType.SUCCESS,"message"); - result.setTimingInfo("123"); - assertEquals(result.getTimingInfo(),"123"); - } - - @Test - public void testGetResult() { - ReturnType result = new ReturnType(ResultType.FAILURE,"message"); - assertEquals(result.getResult(),ResultType.FAILURE); - } - - @Test - public void testGetMessage() { - ReturnType result = new ReturnType(ResultType.SUCCESS,"message"); - result.setMessage("NewMessage"); - assertEquals(result.getMessage(),"NewMessage"); - } - - @Test - public void testToJson() { - ReturnType result = new ReturnType(ResultType.SUCCESS,"message"); - String myJson = result.toJson(); - assertTrue(myJson.contains("message")); - } - - @Test - public void testToString() { - ReturnType result = new ReturnType(ResultType.SUCCESS,"message"); - String test = result.toString(); - assertTrue(test.contains("message")); - } - - @Test - public void testToMap() { - ReturnType result = new ReturnType(ResultType.SUCCESS,"message"); - Map myMap = result.toMap(); - assertTrue(myMap.containsKey("message")); - } - -} diff --git a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java b/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java deleted file mode 100644 index a069b81d..00000000 --- a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * ============LICENSE_START========================================== - * org.onap.music - * =================================================================== - * Copyright (c) 2017 AT&T Intellectual Property - * =================================================================== - * Modifications Copyright (c) 2019 Samsung - * =================================================================== - * 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.unittests.jsonobjects; - -import static org.junit.Assert.*; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.junit.Before; -import org.junit.Test; -import org.onap.music.datastore.jsonobjects.JsonDelete; - -public class JsonDeleteTest { - - JsonDelete jd = null; - - @Before - public void init() { - jd = new JsonDelete(); - } - - @Test - public void testGetConditions() { - Map mapSo = new HashMap<>(); - mapSo.put("key1","one"); - mapSo.put("key2","two"); - jd.setConditions(mapSo); - assertEquals("one",jd.getConditions().get("key1")); - } - - @Test - public void testGetConsistencyInfo() { - Map mapSs = new HashMap<>(); - mapSs.put("key3","three"); - mapSs.put("key4","four"); - jd.setConsistencyInfo(mapSs); - assertEquals("three",jd.getConsistencyInfo().get("key3")); - } - - @Test - public void testGetColumns() { - List ary = new ArrayList<>(); - ary.add("e1"); - ary.add("e2"); - ary.add("e3"); - jd.setColumns(ary); - assertEquals("e1",jd.getColumns().get(0)); - } - - @Test - public void testGetTtl() { - jd.setTtl("2000"); - assertEquals("2000",jd.getTtl()); - } - - @Test - public void testGetTimestamp() { - jd.setTimestamp("20:00"); - assertEquals("20:00",jd.getTimestamp()); - - } - -} diff --git a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java b/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java deleted file mode 100644 index 4992af7b..00000000 --- a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * ============LICENSE_START========================================== - * org.onap.music - * =================================================================== - * Copyright (c) 2017 AT&T Intellectual Property - * =================================================================== - * Modifications Copyright (c) 2019 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.unittests.jsonobjects; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.lang3.SerializationUtils; -import org.junit.Test; -import org.onap.music.datastore.jsonobjects.JsonInsert; - -public class JsonInsertTest { - - JsonInsert ji = new JsonInsert(); - - @Test - public void testGetKeyspaceName() { - ji.setKeyspaceName("keyspace"); - assertEquals("keyspace",ji.getKeyspaceName()); - } - - @Test - public void testGetTableName() { - ji.setTableName("table"); - assertEquals("table",ji.getTableName()); - } - - @Test - public void testGetConsistencyInfo() { - Map cons = new HashMap<>(); - cons.put("test","true"); - ji.setConsistencyInfo(cons); - assertEquals("true",ji.getConsistencyInfo().get("test")); - } - - @Test - public void testGetTtl() { - ji.setTtl("ttl"); - assertEquals("ttl",ji.getTtl()); - } - - @Test - public void testGetTimestamp() { - ji.setTimestamp("10:30"); - assertEquals("10:30",ji.getTimestamp()); - } - - @Test - public void testGetValues() { - Map cons = new HashMap<>(); - cons.put("val1","one"); - cons.put("val2","two"); - ji.setValues(cons); - assertEquals("one",ji.getValues().get("val1")); - } - - @Test - public void testGetRowSpecification() { - Map cons = new HashMap<>(); - cons.put("val1","one"); - cons.put("val2","two"); - ji.setRowSpecification(cons); - assertEquals("two",ji.getRowSpecification().get("val2")); - } - - @Test - public void testSerialize() { - Map cons = new HashMap<>(); - cons.put("val1","one"); - cons.put("val2","two"); - ji.setTimestamp("10:30"); - ji.setRowSpecification(cons); - byte[] test1 = ji.serialize(); - byte[] ji1 = SerializationUtils.serialize(ji); - assertArrayEquals(ji1,test1); - } - - @Test - public void testObjectMap() - { - Map map = new HashMap<>(); - ji.setObjectMap(map); - assertEquals(map, ji.getObjectMap()); - } - -} diff --git a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java b/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java deleted file mode 100644 index 0f4abd7c..00000000 --- a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * ============LICENSE_START========================================== - * org.onap.music - * =================================================================== - * Copyright (c) 2017 AT&T Intellectual Property - * =================================================================== - * 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.unittests.jsonobjects; - -import static org.junit.Assert.*; -import java.util.HashMap; -import java.util.Map; -import org.junit.Before; -import org.junit.Test; -import org.onap.music.datastore.jsonobjects.JsonKeySpace; - -public class JsonKeySpaceTest { - - JsonKeySpace jk = null; - - - @Before - public void init() { - jk = new JsonKeySpace(); - } - - - - @Test - public void testGetConsistencyInfo() { - Map mapSs = new HashMap<>(); - mapSs.put("k1", "one"); - jk.setConsistencyInfo(mapSs); - assertEquals("one",jk.getConsistencyInfo().get("k1")); - } - - @Test - public void testGetReplicationInfo() { - Map mapSo = new HashMap<>(); - mapSo.put("k1", "one"); - jk.setReplicationInfo(mapSo); - assertEquals("one",jk.getReplicationInfo().get("k1")); - - } - - @Test - public void testGetDurabilityOfWrites() { - jk.setDurabilityOfWrites("1"); - assertEquals("1",jk.getDurabilityOfWrites()); - } - - @Test - public void testGetKeyspaceName() { - jk.setKeyspaceName("Keyspace"); - assertEquals("Keyspace",jk.getKeyspaceName()); - } - -} diff --git a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java b/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java deleted file mode 100644 index 37d1787a..00000000 --- a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * ============LICENSE_START========================================== - * org.onap.music - * =================================================================== - * Copyright (c) 2017 AT&T Intellectual Property - * =================================================================== - * Modifications Copyright (c) 2018-2019 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.unittests.jsonobjects; - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; -import org.onap.music.datastore.jsonobjects.JsonSelect; - -public class JsonSelectTest { - - @Test - public void testGetConsistencyInfo() { - JsonSelect js = new JsonSelect(); - Map mapSs = new HashMap<>(); - mapSs.put("k1", "one"); - js.setConsistencyInfo(mapSs); - assertEquals("one", js.getConsistencyInfo().get("k1")); - } - - @Test - public void testSerialize() throws IOException { - JsonSelect js = new JsonSelect(); - Map mapSs = new HashMap<>(); - mapSs.put("Key", "Value"); - js.setConsistencyInfo(mapSs); - js.serialize(); - } - -} diff --git a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java b/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java deleted file mode 100644 index 4e3b4629..00000000 --- a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * ============LICENSE_START========================================== - * org.onap.music - * =================================================================== - * Copyright (c) 2017 AT&T Intellectual Property - * =================================================================== - * Modifications Copyright (c) 2019 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.unittests.jsonobjects; - -import static org.junit.Assert.*; -import java.util.HashMap; -import java.util.Map; -import org.junit.Before; -import org.junit.Test; -import org.onap.music.datastore.jsonobjects.JsonTable; - -public class JsonTableTest { - - JsonTable jt = null; - - @Before - public void init() { - jt = new JsonTable(); - } - - @Test - public void testGetConsistencyInfo() { - Map mapSs = new HashMap<>(); - mapSs.put("k1", "one"); - jt.setConsistencyInfo(mapSs); - assertEquals("one",jt.getConsistencyInfo().get("k1")); - } - - @Test - public void testGetProperties() { - Map properties = new HashMap<>(); - properties.put("k1", "one"); - jt.setProperties(properties); - } - - @Test - public void testGetFields() { - Map fields = new HashMap<>(); - fields.put("k1", "one"); - jt.setFields(fields); - assertEquals("one",jt.getFields().get("k1")); - } - - @Test - public void testGetKeyspaceName() { - String keyspace = "keyspace"; - jt.setKeyspaceName(keyspace); - assertEquals(keyspace,jt.getKeyspaceName()); - } - - @Test - public void testGetTableName() { - String table = "table"; - jt.setTableName(table); - assertEquals(table,jt.getTableName()); - } - - @Test - public void testGetClusteringOrder() { - String clusteringOrder = "clusteringOrder"; - jt.setClusteringOrder(clusteringOrder); - assertEquals(clusteringOrder,jt.getClusteringOrder()); - } - - @Test - public void testGetPrimaryKey() { - String primaryKey = "primaryKey"; - jt.setPrimaryKey(primaryKey); - assertEquals(primaryKey,jt.getPrimaryKey()); - } - - @Test - public void testFilteringKey() { - jt.setFilteringKey("FilteringKey"); - assertEquals("FilteringKey",jt.getFilteringKey()); - } - -} diff --git a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java b/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java deleted file mode 100644 index e00cb463..00000000 --- a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * ============LICENSE_START========================================== - * org.onap.music - * =================================================================== - * Copyright (c) 2018 AT&T Intellectual Property - * =================================================================== - * Modifications Copyright (c) 2019 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.unittests.jsonobjects; - -import static org.junit.Assert.*; -import java.util.HashMap; -import java.util.Map; -import org.junit.Before; -import org.junit.Test; -import org.onap.music.datastore.jsonobjects.JsonUpdate; - -public class JsonUpdateTest { - - JsonUpdate ju = null; - - @Before - public void init() { - ju = new JsonUpdate(); - } - - - @Test - public void testGetConditions() { - Map mapSo = new HashMap<>(); - mapSo.put("key1","one"); - mapSo.put("key2","two"); - ju.setConditions(mapSo); - assertEquals("one",ju.getConditions().get("key1")); - } - - @Test - public void testGetRow_specification() { - Map mapSo = new HashMap<>(); - mapSo.put("key1","one"); - mapSo.put("key2","two"); - ju.setRow_specification(mapSo); - assertEquals("one",ju.getRow_specification().get("key1")); - } - - @Test - public void testGetKeyspaceName() { - String keyspace = "keyspace"; - ju.setKeyspaceName(keyspace); - assertEquals(keyspace,ju.getKeyspaceName()); - } - - @Test - public void testGetTableName() { - String table = "table"; - ju.setTableName(table); - assertEquals(table,ju.getTableName()); - } - - @Test - public void testGetConsistencyInfo() { - Map mapSs = new HashMap<>(); - mapSs.put("k1", "one"); - ju.setConsistencyInfo(mapSs); - assertEquals("one",ju.getConsistencyInfo().get("k1")); - } - - @Test - public void testGetTtl() { - ju.setTtl("2000"); - assertEquals("2000",ju.getTtl()); - } - - @Test - public void testGetTimestamp() { - ju.setTimestamp("20:00"); - assertEquals("20:00",ju.getTimestamp()); - - } - - @Test - public void testGetValues() { - Map cons = new HashMap<>(); - cons.put("val1","one"); - cons.put("val2","two"); - ju.setValues(cons); - assertEquals("one",ju.getValues().get("val1")); - } - - @Test - public void testSerialize() { - assertTrue(ju.serialize() instanceof byte[]); - } - -} -- cgit 1.2.3-korg