diff options
Diffstat (limited to 'auth/auth-cass')
44 files changed, 8299 insertions, 8299 deletions
diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CacheInfoDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CacheInfoDAO.java index 9672199b..eea3c4c2 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CacheInfoDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CacheInfoDAO.java @@ -72,7 +72,7 @@ public class CacheInfoDAO extends CassDAOImpl<AuthzTrans,CacheInfoDAO.Data> impl // Hold current time stamps from Tables private final Date startTime; - private final boolean cacheNotify; + private final boolean cacheNotify; private PreparedStatement psCheck; ////////////////////////////////////////// @@ -87,22 +87,22 @@ public class CacheInfoDAO extends CassDAOImpl<AuthzTrans,CacheInfoDAO.Data> impl init(trans); } - public CacheInfoDAO(AuthzTrans trans, AbsCassDAO<AuthzTrans,?> aDao) throws APIException, IOException { + public CacheInfoDAO(AuthzTrans trans, AbsCassDAO<AuthzTrans,?> aDao) throws APIException, IOException { super(trans, CacheInfoDAO.class.getSimpleName(),aDao,Data.class,TABLE,readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); startTime = new Date(); init(trans); cacheNotify = noK8s(trans); } - /** - * Need a different point to point cache clear strategy for K8s... - * @param trans - * @return - */ + /** + * Need a different point to point cache clear strategy for K8s... + * @param trans + * @return + */ private boolean noK8s(AuthzTrans trans) { - String container = trans.getProperty(Config.AAF_LOCATOR_CONTAINER); - return ! ("helm".equals(container) || "oom".equals(container)); - } + String container = trans.getProperty(Config.AAF_LOCATOR_CONTAINER); + return ! ("helm".equals(container) || "oom".equals(container)); + } /** * @author Jonathan */ diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CredDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CredDAO.java index d64cff29..9a2511d2 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CredDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CredDAO.java @@ -85,8 +85,8 @@ public class CredDAO extends CassDAOImpl<AuthzTrans,CredDAO.Data> { public Date expires; public Integer other; public String ns; - public String tag; - public String notes; + public String tag; + public String notes; public ByteBuffer cred; // this is a blob in cassandra @@ -139,7 +139,7 @@ public class CredDAO extends CassDAOImpl<AuthzTrans,CredDAO.Data> { @Override protected void key(Data data, int _idx, Object[] obj) { - int idx = _idx; + int idx = _idx; obj[idx] = data.id; obj[++idx] = data.type; @@ -221,23 +221,23 @@ public class CredDAO extends CassDAOImpl<AuthzTrans,CredDAO.Data> { " WHERE id = ?", CredLoader.deflt,readConsistency); } - /* (non-Javadoc) - * @see org.onap.aaf.auth.dao.CassDAOImpl#create(org.onap.aaf.misc.env.TransStore, java.lang.Object) - */ - @Override - public Result<Data> create(AuthzTrans trans, Data data) { - if(data.tag == null) { - if(data.type==0) { - data.tag="PlaceHolder"; - } else { - long l = srand.nextLong(); - data.tag = Long.toHexString(l); - } - } - return super.create(trans, data); - } + /* (non-Javadoc) + * @see org.onap.aaf.auth.dao.CassDAOImpl#create(org.onap.aaf.misc.env.TransStore, java.lang.Object) + */ + @Override + public Result<Data> create(AuthzTrans trans, Data data) { + if(data.tag == null) { + if(data.type==0) { + data.tag="PlaceHolder"; + } else { + long l = srand.nextLong(); + data.tag = Long.toHexString(l); + } + } + return super.create(trans, data); + } - public Result<List<Data>> readNS(AuthzTrans trans, String ns) { + public Result<List<Data>> readNS(AuthzTrans trans, String ns) { return psNS.read(trans, R_TEXT, new Object[]{ns}); } @@ -267,12 +267,12 @@ public class CredDAO extends CassDAOImpl<AuthzTrans,CredDAO.Data> { : (modified.name() + "d credential for " + data.id); String spacer = ": "; if(data.notes!=null) { - hd.memo+=spacer + data.notes; - spacer = ", "; + hd.memo+=spacer + data.notes; + spacer = ", "; } if(data.tag!=null) { - hd.memo+=spacer + data.tag; + hd.memo+=spacer + data.tag; } // Detail? diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/FutureDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/FutureDAO.java index 72c0e98b..eafdb884 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/FutureDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/FutureDAO.java @@ -69,8 +69,8 @@ public class FutureDAO extends CassDAOImpl<AuthzTrans,FutureDAO.Data> { public String memo; public Date start; public Date expires; - public String target_key; - public Date target_date; + public String target_key; + public Date target_date; public ByteBuffer construct; // this is a blob in cassandra } diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/HistoryDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/HistoryDAO.java index 73ab343b..82874ce9 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/HistoryDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/HistoryDAO.java @@ -173,21 +173,21 @@ public class HistoryDAO extends CassDAOImpl<AuthzTrans, HistoryDAO.Data> { } public void createBatch(StringBuilder sb, Data data) { - sb.append("INSERT INTO history ("); - sb.append(helpers[FIELD_COMMAS]); - sb.append(") VALUES(now(),"); - sb.append(data.yr_mon); - sb.append(",'"); - sb.append(data.user); - sb.append("','"); - sb.append(data.action); - sb.append("','"); - sb.append(data.target); - sb.append("','"); - sb.append(data.subject); - sb.append("','"); - sb.append(data.memo); - sb.append("',null);\n"); + sb.append("INSERT INTO history ("); + sb.append(helpers[FIELD_COMMAS]); + sb.append(") VALUES(now(),"); + sb.append(data.yr_mon); + sb.append(",'"); + sb.append(data.user); + sb.append("','"); + sb.append(data.action); + sb.append("','"); + sb.append(data.target); + sb.append("','"); + sb.append(data.subject); + sb.append("','"); + sb.append(data.memo); + sb.append("',null);\n"); } public Result<List<Data>> readByYYYYMM(AuthzTrans trans, int yyyymm) { diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/LocateDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/LocateDAO.java index 085f4199..478cceb0 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/LocateDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/LocateDAO.java @@ -100,8 +100,8 @@ public class LocateDAO extends CassDAOImpl<AuthzTrans,LocateDAO.Data> { LocateLoader.deflt.unmarshal(this, toDIS(bb)); } - public Data copy() { - Data out = new Data(); + public Data copy() { + Data out = new Data(); out.name = name; out.hostname = hostname; out.port = port; @@ -115,8 +115,8 @@ public class LocateDAO extends CassDAOImpl<AuthzTrans,LocateDAO.Data> { out.subprotocol = new HashSet<>(); out.subprotocol.addAll(subprotocol); out.port_key = port_key; - return out; - } + return out; + } } private static class LocateLoader extends Loader<Data> implements Streamer<Data>{ diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/PermDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/PermDAO.java index 0033f8a1..699d6e28 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/PermDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/PermDAO.java @@ -93,31 +93,31 @@ public class PermDAO extends CassDAOImpl<AuthzTrans,PermDAO.Data> { } public String fullType() { - StringBuilder sb = new StringBuilder(); - if(ns==null) { - sb.append('.'); - } else { - sb.append(ns); - sb.append(ns.indexOf('@')<0?'.':':'); - } - sb.append(type); - return sb.toString(); + StringBuilder sb = new StringBuilder(); + if(ns==null) { + sb.append('.'); + } else { + sb.append(ns); + sb.append(ns.indexOf('@')<0?'.':':'); + } + sb.append(type); + return sb.toString(); } public String fullPerm() { - StringBuilder sb = new StringBuilder(); - if(ns==null) { - sb.append("null."); - } else { - sb.append(ns); - sb.append(ns.indexOf('@')<0?'.':':'); - } - sb.append(type); - sb.append('|'); - sb.append(instance); - sb.append('|'); - sb.append(action); - return sb.toString(); + StringBuilder sb = new StringBuilder(); + if(ns==null) { + sb.append("null."); + } else { + sb.append(ns); + sb.append(ns.indexOf('@')<0?'.':':'); + } + sb.append(type); + sb.append('|'); + sb.append(instance); + sb.append('|'); + sb.append(action); + return sb.toString(); } public String encode() { @@ -213,26 +213,26 @@ public class PermDAO extends CassDAOImpl<AuthzTrans,PermDAO.Data> { Data rv = new PermDAO.Data(); if (rdns.isOKhasData()) { switch(s.length) { - case 4: - rv.ns=s[0]; - rv.type=s[1]; - rv.instance=s[2]; - rv.action=s[3]; - break; + case 4: + rv.ns=s[0]; + rv.type=s[1]; + rv.instance=s[2]; + rv.action=s[3]; + break; case 3: - rv.ns=s[0]; + rv.ns=s[0]; rv.type=s[1]; rv.instance=s[2]; rv.action=s[3]; break; case 2: - rv.ns=s[0]; + rv.ns=s[0]; rv.type=s[1]; rv.instance=s[2]; rv.action=STAR; break; default: - rv.ns=s[0]; + rv.ns=s[0]; rv.type=s[1]; rv.instance = STAR; rv.action = STAR; diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/RoleDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/RoleDAO.java index a5fa7a77..e5c97559 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/RoleDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/RoleDAO.java @@ -106,15 +106,15 @@ public class RoleDAO extends CassDAOImpl<AuthzTrans,RoleDAO.Data> { } public String fullName() { - StringBuilder sb = new StringBuilder(); - if(ns==null) { - sb.append('.'); - } else { - sb.append(ns); - sb.append(ns.indexOf('@')<0?'.':':'); - } - sb.append(name); - return sb.toString(); + StringBuilder sb = new StringBuilder(); + if(ns==null) { + sb.append('.'); + } else { + sb.append(ns); + sb.append(ns.indexOf('@')<0?'.':':'); + } + sb.append(name); + return sb.toString(); } public String encode() { @@ -131,28 +131,28 @@ public class RoleDAO extends CassDAOImpl<AuthzTrans,RoleDAO.Data> { */ public static Result<Data> decode(AuthzTrans trans, Question q, String r) { Data data = new Data(); - if(r.indexOf('@')>=0) { - int colon = r.indexOf(':'); - if(colon<0) { - return Result.err(Result.ERR_BadData, "%s is not a valid Role",r); - } else { - data.ns=r.substring(0, colon); - data.name=r.substring(++colon); - } - } else { - String[] ss = Split.splitTrim('|', r,2); - if (ss[1]==null) { // older 1 part encoding must be evaluated for NS - Result<NsSplit> nss = q.deriveNsSplit(trans, ss[0]); - if (nss.notOK()) { - return Result.err(nss); - } - data.ns=nss.value.ns; - data.name=nss.value.name; - } else { // new 4 part encoding - data.ns=ss[0]; - data.name=ss[1]; - } - } + if(r.indexOf('@')>=0) { + int colon = r.indexOf(':'); + if(colon<0) { + return Result.err(Result.ERR_BadData, "%s is not a valid Role",r); + } else { + data.ns=r.substring(0, colon); + data.name=r.substring(++colon); + } + } else { + String[] ss = Split.splitTrim('|', r,2); + if (ss[1]==null) { // older 1 part encoding must be evaluated for NS + Result<NsSplit> nss = q.deriveNsSplit(trans, ss[0]); + if (nss.notOK()) { + return Result.err(nss); + } + data.ns=nss.value.ns; + data.name=nss.value.name; + } else { // new 4 part encoding + data.ns=ss[0]; + data.name=ss[1]; + } + } return Result.ok(data); } diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Function.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Function.java index 4ec70d4a..dd367c51 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Function.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Function.java @@ -245,13 +245,13 @@ public class Function { // 2.1) Does role exist with that name if(cname!=null && q.roleDAO().read(trans, parent, cname).isOKhasData()) { - return Result.err(Status.ERR_ConflictAlreadyExists, + return Result.err(Status.ERR_ConflictAlreadyExists, "Role exists with that name"); } // 2.2) Do perms exist with that name if(cname!=null && q.permDAO().readByType(trans, parent, cname).isOKhasData()) { - return Result.err(Status.ERR_ConflictAlreadyExists, + return Result.err(Status.ERR_ConflictAlreadyExists, "Perms exist with that name"); } diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/PermLookup.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/PermLookup.java index b0680621..3f0e92e7 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/PermLookup.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/PermLookup.java @@ -153,32 +153,32 @@ public class PermLookup { List<PermDAO.Data> lpdd = new ArrayList<>(); for (String perm : rss.value) { if (lookup) { - Map<String,PermDAO.Data> mspdd = new TreeMap<>(); + Map<String,PermDAO.Data> mspdd = new TreeMap<>(); Result<String[]> ap = PermDAO.Data.decodeToArray(trans, q, perm); if (ap.isOK()) { Result<List<PermDAO.Data>> rlpd = q.permDAO().read(perm,trans,ap.value); if (rlpd.isOKhasData()) { for (PermDAO.Data pData : rlpd.value) { - // ONLY add perms/roles which are related to this lookup - for(String pdr : pData.roles(false)) { - for(RoleDAO.Data r : roles.value) { - if(pdr.equals(r.encode())) { - PermDAO.Data pdd = mspdd.get(pData.fullPerm()); - if(pdd==null) { - pdd = new PermDAO.Data(); - pdd.ns = pData.ns; - pdd.type = pData.type; - pdd.instance = pData.instance; - pdd.action = pData.action; - pdd.description = pData.description; + // ONLY add perms/roles which are related to this lookup + for(String pdr : pData.roles(false)) { + for(RoleDAO.Data r : roles.value) { + if(pdr.equals(r.encode())) { + PermDAO.Data pdd = mspdd.get(pData.fullPerm()); + if(pdd==null) { + pdd = new PermDAO.Data(); + pdd.ns = pData.ns; + pdd.type = pData.type; + pdd.instance = pData.instance; + pdd.action = pData.action; + pdd.description = pData.description; lpdd.add(pdd); - } - pdd.roles(true).add(pdr); - break; - } - } - } + } + pdd.roles(true).add(pdr); + break; + } + } + } } } } else { diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Question.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Question.java index 6b6c23bf..b797ca05 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Question.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Question.java @@ -132,62 +132,62 @@ public class Question { private final HistoryDAO historyDAO; public HistoryDAO historyDAO() { - return historyDAO; + return historyDAO; } private final CachedNSDAO nsDAO; public CachedNSDAO nsDAO() { - return nsDAO; + return nsDAO; } private final CachedRoleDAO roleDAO; public CachedRoleDAO roleDAO() { - return roleDAO; + return roleDAO; } private final CachedPermDAO permDAO; public CachedPermDAO permDAO() { - return permDAO; + return permDAO; } private final CachedUserRoleDAO userRoleDAO; public CachedUserRoleDAO userRoleDAO() { - return userRoleDAO; + return userRoleDAO; } private final CachedCredDAO credDAO; public CachedCredDAO credDAO() { - return credDAO; + return credDAO; } private final CachedCertDAO certDAO; public CachedCertDAO certDAO() { - return certDAO; + return certDAO; } private final DelegateDAO delegateDAO; public DelegateDAO delegateDAO() { - return delegateDAO; + return delegateDAO; } private final FutureDAO futureDAO; public FutureDAO futureDAO() { - return futureDAO; + return futureDAO; } private final ApprovalDAO approvalDAO; public ApprovalDAO approvalDAO() { - return approvalDAO; + return approvalDAO; } public final LocateDAO locateDAO; public LocateDAO locateDAO() { - return locateDAO; + return locateDAO; } private final CacheInfoDAO cacheInfoDAO; - private final int cldays; - private final boolean alwaysSpecial; + private final int cldays; + private final boolean alwaysSpecial; public Question(AuthzTrans trans, Cluster cluster, String keyspace) throws APIException, IOException { PERMS = trans.slot("USER_PERMS"); @@ -229,18 +229,18 @@ public class Question { * Note: This Constructor created for JUNIT Purposes. Do not use otherwise. */ public Question(AuthzTrans trans, HistoryDAO historyDAO, CacheInfoDAO cacheInfoDAO, - CachedNSDAO nsDAO, CachedPermDAO permDAO, CachedRoleDAO roleDAO, - CachedUserRoleDAO userRoleDAO, CachedCredDAO credDAO, CachedCertDAO certDAO, - LocateDAO locateDAO,FutureDAO futureDAO, DelegateDAO delegateDAO, - ApprovalDAO approvalDAO ) { - this.historyDAO = historyDAO; - this.cacheInfoDAO = cacheInfoDAO; - this.nsDAO = nsDAO; - this.permDAO = permDAO; - this.roleDAO = roleDAO; - this.userRoleDAO = userRoleDAO; - this.credDAO = credDAO; - this.certDAO = certDAO; + CachedNSDAO nsDAO, CachedPermDAO permDAO, CachedRoleDAO roleDAO, + CachedUserRoleDAO userRoleDAO, CachedCredDAO credDAO, CachedCertDAO certDAO, + LocateDAO locateDAO,FutureDAO futureDAO, DelegateDAO delegateDAO, + ApprovalDAO approvalDAO ) { + this.historyDAO = historyDAO; + this.cacheInfoDAO = cacheInfoDAO; + this.nsDAO = nsDAO; + this.permDAO = permDAO; + this.roleDAO = roleDAO; + this.userRoleDAO = userRoleDAO; + this.credDAO = credDAO; + this.certDAO = certDAO; this.locateDAO = locateDAO; this.futureDAO = futureDAO; this.delegateDAO = delegateDAO; @@ -272,28 +272,28 @@ public class Question { } public Result<PermDAO.Data> permFrom(AuthzTrans trans, String type, String instance, String action) { - if(type.indexOf('@') >= 0) { - int colon = type.indexOf(':'); - if(colon>=0) { - PermDAO.Data pdd = new PermDAO.Data(); - pdd.ns = type.substring(0, colon); - pdd.type = type.substring(colon+1); - pdd.instance = instance; - pdd.action = action; - - return Result.ok(pdd); - } else { - return Result.err(Result.ERR_BadData,"Could not extract ns and type from " + type); - } - } else { - Result<NsDAO.Data> rnd = deriveNs(trans, type); - if (rnd.isOK()) { - return Result.ok(new PermDAO.Data(new NsSplit(rnd.value, type), - instance, action)); - } else { - return Result.err(rnd); - } - } + if(type.indexOf('@') >= 0) { + int colon = type.indexOf(':'); + if(colon>=0) { + PermDAO.Data pdd = new PermDAO.Data(); + pdd.ns = type.substring(0, colon); + pdd.type = type.substring(colon+1); + pdd.instance = instance; + pdd.action = action; + + return Result.ok(pdd); + } else { + return Result.err(Result.ERR_BadData,"Could not extract ns and type from " + type); + } + } else { + Result<NsDAO.Data> rnd = deriveNs(trans, type); + if (rnd.isOK()) { + return Result.ok(new PermDAO.Data(new NsSplit(rnd.value, type), + instance, action)); + } else { + return Result.err(rnd); + } + } } /** @@ -357,38 +357,38 @@ public class Question { } public Result<List<PermDAO.Data>> getPermsByType(AuthzTrans trans, String type) { - if(type.indexOf('@') >= 0) { - int colon = type.indexOf(':'); - if(colon>=0) { - return permDAO.readByType(trans, type.substring(0, colon),type.substring(colon+1)); - } else { - return Result.err(Result.ERR_BadData, "%s is malformed",type); - } - } else { - Result<NsSplit> nss = deriveNsSplit(trans, type); - if (nss.notOK()) { - return Result.err(nss); - } - return permDAO.readByType(trans, nss.value.ns, nss.value.name); - } + if(type.indexOf('@') >= 0) { + int colon = type.indexOf(':'); + if(colon>=0) { + return permDAO.readByType(trans, type.substring(0, colon),type.substring(colon+1)); + } else { + return Result.err(Result.ERR_BadData, "%s is malformed",type); + } + } else { + Result<NsSplit> nss = deriveNsSplit(trans, type); + if (nss.notOK()) { + return Result.err(nss); + } + return permDAO.readByType(trans, nss.value.ns, nss.value.name); + } } public Result<List<PermDAO.Data>> getPermsByName(AuthzTrans trans, String type, String instance, String action) { - if(type.indexOf('@') >= 0) { - int colon = type.indexOf(':'); - if(colon>=0) { - return permDAO.read(trans, type.substring(0, colon),type.substring(colon+1), instance,action); - } else { - return Result.err(Result.ERR_BadData, "%s is malformed",type); - } - } else { - Result<NsSplit> nss = deriveNsSplit(trans, type); - if (nss.notOK()) { - return Result.err(nss); - } - - return permDAO.read(trans, nss.value.ns, nss.value.name, instance,action); - } + if(type.indexOf('@') >= 0) { + int colon = type.indexOf(':'); + if(colon>=0) { + return permDAO.read(trans, type.substring(0, colon),type.substring(colon+1), instance,action); + } else { + return Result.err(Result.ERR_BadData, "%s is malformed",type); + } + } else { + Result<NsSplit> nss = deriveNsSplit(trans, type); + if (nss.notOK()) { + return Result.err(nss); + } + + return permDAO.read(trans, nss.value.ns, nss.value.name, instance,action); + } } public Result<List<PermDAO.Data>> getPermsByRole(AuthzTrans trans, String role, boolean lookup) { @@ -435,13 +435,13 @@ public class Question { } public Result<List<RoleDAO.Data>> getRolesByName(AuthzTrans trans, String role) { - if(role.startsWith(trans.user()) ) { - if(role.endsWith(":user")) { - return roleDAO.read(trans,trans.user(), "user"); - } else { - return Result.err(Result.ERR_BadData,"%s is a badly formatted role",role); - } - } + if(role.startsWith(trans.user()) ) { + if(role.endsWith(":user")) { + return roleDAO.read(trans,trans.user(), "user"); + } else { + return Result.err(Result.ERR_BadData,"%s is a badly formatted role",role); + } + } Result<NsSplit> nss = deriveNsSplit(trans, role); if (nss.notOK()) { return Result.err(nss); @@ -619,9 +619,9 @@ public class Question { } public Result<NsDAO.Data> mayUser(AuthzTrans trans, String user, RoleDAO.Data rdd, Access access) { - if(trans.user().equals(rdd.ns)) { - return Result.ok((NsDAO.Data)null); - } + if(trans.user().equals(rdd.ns)) { + return Result.ok((NsDAO.Data)null); + } Result<NsDAO.Data> rnsd = deriveNs(trans, rdd.ns); if (rnsd.isOK()) { return mayUser(trans, user, rnsd.value, rdd, access); @@ -676,17 +676,17 @@ public class Question { } public Result<NsDAO.Data> mayUser(AuthzTrans trans, String user,PermDAO.Data pdd, Access access) { - if(pdd.ns.indexOf('@')>-1) { - if(user.equals(pdd.ns) || isGranted(trans,user,Define.ROOT_NS(),"access",pdd.instance,READ)) { - NsDAO.Data ndd = new NsDAO.Data(); - ndd.name = user; - ndd.type = NsDAO.USER; - ndd.parent = ""; - return Result.ok(ndd); - } else { - return Result.err(Result.ERR_Security,"Only a User may modify User"); - } - } + if(pdd.ns.indexOf('@')>-1) { + if(user.equals(pdd.ns) || isGranted(trans,user,Define.ROOT_NS(),"access",pdd.instance,READ)) { + NsDAO.Data ndd = new NsDAO.Data(); + ndd.name = user; + ndd.type = NsDAO.USER; + ndd.parent = ""; + return Result.ok(ndd); + } else { + return Result.err(Result.ERR_Security,"Only a User may modify User"); + } + } Result<NsDAO.Data> rnsd = deriveNs(trans, pdd.ns); if (rnsd.isOK()) { return mayUser(trans, user, rnsd.value, pdd, access); @@ -885,7 +885,7 @@ public class Question { } } if (cddl.size()>1) { - Collections.sort(cddl, (a, b) -> b.expires.compareTo(a.expires)); + Collections.sort(cddl, (a, b) -> b.expires.compareTo(a.expires)); } } else { cddl = result.value; @@ -945,13 +945,13 @@ public class Question { rv = Result.err(Status.ERR_Security, "Credentials expired %s",Chrono.utcStamp(expired)); } else { - if (debug==null && alwaysSpecial) { - debug = new StringBuilder(); - } - if (debug!=null) { - debug.append(trans.env().encryptor().encrypt(new String(cred))); - rv = Result.err(Status.ERR_Security,String.format("invalid password - %s",debug.toString())); - } + if (debug==null && alwaysSpecial) { + debug = new StringBuilder(); + } + if (debug!=null) { + debug.append(trans.env().encryptor().encrypt(new String(cred))); + rv = Result.err(Status.ERR_Security,String.format("invalid password - %s",debug.toString())); + } } } } else { @@ -1005,14 +1005,14 @@ public class Question { } } else if (cred.type==CredDAO.FQI) { - cred.cred = null; - return Result.ok(cred); + cred.cred = null; + return Result.ok(cred); } return Result.err(Status.ERR_Security,"invalid/unreadable credential"); } public Result<Boolean> userCredCheck(AuthzTrans trans, CredDAO.Data orig, final byte[] raw) { - Result<Boolean> rv; + Result<Boolean> rv; TimeTaken tt = trans.start("CheckCred Cred", Env.SUB); try { switch(orig.type) { @@ -1231,11 +1231,11 @@ public class Question { Result<List<UserRoleDAO.Data>> rur = userRoleDAO.read(trans, user,ns+DOT_ADMIN); if (rur.isOKhasData()) { Date now = new Date(); - for (UserRoleDAO.Data urdd : rur.value){ - if (urdd.expires.after(now)) { - return true; - } - } + for (UserRoleDAO.Data urdd : rur.value){ + if (urdd.expires.after(now)) { + return true; + } + } }; return false; } diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectAAFLocator.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectAAFLocator.java index 27d5df74..bd297e7d 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectAAFLocator.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectAAFLocator.java @@ -73,15 +73,15 @@ public class DirectAAFLocator extends AbsAAFLocator<AuthzTrans> { } try { - String aaf_url; - if(name.indexOf('.')>=0) { - aaf_url = "https://"+Config.AAF_LOCATE_URL_TAG+'/'+name+':'+version; - } else { - aaf_url = "https://"+Config.AAF_LOCATE_URL_TAG+"/%CNS.%NS."+name+':'+version; - } - RegistrationPropHolder rph = new RegistrationPropHolder(access,0); - aaf_url = rph.replacements(getClass().getSimpleName(),aaf_url, null,null); - access.printf(Level.INIT,"Creating DirectAAFLocator to %s",aaf_url); + String aaf_url; + if(name.indexOf('.')>=0) { + aaf_url = "https://"+Config.AAF_LOCATE_URL_TAG+'/'+name+':'+version; + } else { + aaf_url = "https://"+Config.AAF_LOCATE_URL_TAG+"/%CNS.%NS."+name+':'+version; + } + RegistrationPropHolder rph = new RegistrationPropHolder(access,0); + aaf_url = rph.replacements(getClass().getSimpleName(),aaf_url, null,null); + access.printf(Level.INIT,"Creating DirectAAFLocator to %s",aaf_url); uri = new URI(aaf_url); } catch (URISyntaxException | UnknownHostException | CadiException e) { throw new LocatorException(e); diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectAAFUserPass.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectAAFUserPass.java index 3c7d873e..bdeb77f3 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectAAFUserPass.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectAAFUserPass.java @@ -52,10 +52,10 @@ public class DirectAAFUserPass implements CredVal { @Override public boolean validate(String user, Type type, byte[] pass, Object state) { - if(user==null || type==null || pass==null) { - return false; - } - + if(user==null || type==null || pass==null) { + return false; + } + try { AuthzTrans trans; boolean transfer = false; @@ -74,7 +74,7 @@ public class DirectAAFUserPass implements CredVal { } Result<Date> result = question.doesUserCredMatch(trans, user, pass); if(transfer) { - ((HttpServletRequest)state).setAttribute("CRED_TAG", trans.getTag()); + ((HttpServletRequest)state).setAttribute("CRED_TAG", trans.getTag()); } trans.logAuditTrail(env.debug()); switch(result.status) { diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectRegistrar.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectRegistrar.java index 99421097..ce9d5930 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectRegistrar.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectRegistrar.java @@ -41,54 +41,54 @@ public class DirectRegistrar implements Registrant<AuthzEnv> { private LocateDAO ldao; private List<LocateDAO.Data> ldd; public DirectRegistrar(Access access, LocateDAO ldao, int port) throws CadiException { - this.ldao = ldao; + this.ldao = ldao; ldd = new ArrayList<>(); RegistrationCreator rc = new RegistrationCreator(access); MgmtEndpoints mes = rc.create(port); for(MgmtEndpoint me : mes.getMgmtEndpoint()) { - ldd.add(convert(me)); + ldd.add(convert(me)); } } private LocateDAO.Data convert(MgmtEndpoint me) { - LocateDAO.Data out = new LocateDAO.Data(); - out.name=me.getName(); - out.hostname=me.getHostname(); - out.latitude=me.getLatitude(); - out.longitude=me.getLongitude(); - out.major=me.getMajor(); - out.minor=me.getMinor(); - out.pkg=me.getPkg(); - out.patch=me.getPatch(); - out.port=me.getPort(); - out.protocol=me.getProtocol(); - out.subprotocol(true).addAll(me.getSubprotocol()); -// out.port_key = UUID.randomUUID(); - return out; - } + LocateDAO.Data out = new LocateDAO.Data(); + out.name=me.getName(); + out.hostname=me.getHostname(); + out.latitude=me.getLatitude(); + out.longitude=me.getLongitude(); + out.major=me.getMajor(); + out.minor=me.getMinor(); + out.pkg=me.getPkg(); + out.patch=me.getPatch(); + out.port=me.getPort(); + out.protocol=me.getProtocol(); + out.subprotocol(true).addAll(me.getSubprotocol()); +// out.port_key = UUID.randomUUID(); + return out; + } - @Override + @Override public Result<Void> update(AuthzEnv env) { - AuthzTrans trans = env.newTransNoAvg(); - StringBuilder sb = null; - for(LocateDAO.Data ld : ldd) { - org.onap.aaf.auth.layer.Result<Void> dr = ldao.update(trans, ld); - if (dr.notOK()) { - if(sb == null) { - sb = new StringBuilder(dr.errorString()); - } else { - sb.append(';'); - sb.append(dr.errorString()); - } - } - } - - if(sb==null) { - return Result.ok(200, null); - } else { - return Result.err(503, sb.toString()); - } + AuthzTrans trans = env.newTransNoAvg(); + StringBuilder sb = null; + for(LocateDAO.Data ld : ldd) { + org.onap.aaf.auth.layer.Result<Void> dr = ldao.update(trans, ld); + if (dr.notOK()) { + if(sb == null) { + sb = new StringBuilder(dr.errorString()); + } else { + sb.append(';'); + sb.append(dr.errorString()); + } + } + } + + if(sb==null) { + return Result.ok(200, null); + } else { + return Result.err(503, sb.toString()); + } } /* (non-Javadoc) @@ -96,25 +96,25 @@ public class DirectRegistrar implements Registrant<AuthzEnv> { */ @Override public Result<Void> cancel(AuthzEnv env) { - AuthzTrans trans = env.newTransNoAvg(); - StringBuilder sb = null; - for(LocateDAO.Data ld : ldd) { + AuthzTrans trans = env.newTransNoAvg(); + StringBuilder sb = null; + for(LocateDAO.Data ld : ldd) { org.onap.aaf.auth.layer.Result<Void> dr = ldao.delete(trans, ld, false); - if (dr.notOK()) { - if(sb == null) { - sb = new StringBuilder(dr.errorString()); - } else { - sb.append(';'); - sb.append(dr.errorString()); - } - } - } - - if(sb==null) { - return Result.ok(200, null); - } else { - return Result.err(503, sb.toString()); - } + if (dr.notOK()) { + if(sb == null) { + sb = new StringBuilder(dr.errorString()); + } else { + sb.append(';'); + sb.append(dr.errorString()); + } + } + } + + if(sb==null) { + return Result.ok(200, null); + } else { + return Result.err(503, sb.toString()); + } } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_DAOException.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_DAOException.java index 0ee0ce8f..c1592bdb 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_DAOException.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_DAOException.java @@ -32,35 +32,35 @@ import org.powermock.api.mockito.PowerMockito; import org.powermock.modules.junit4.PowerMockRunner; public class JU_DAOException { - DAOException daoException; + DAOException daoException; String message = "message"; Throwable cause; @Before public void setUp(){ - daoException = new DAOException(); + daoException = new DAOException(); } @Test public void testNoArgConstructor(){ - assertNull(daoException.getMessage()); + assertNull(daoException.getMessage()); } @Test public void testOneArgConstructorMsg(){ - daoException = new DAOException("test message"); - assertTrue("test message".equalsIgnoreCase(daoException.getMessage())); + daoException = new DAOException("test message"); + assertTrue("test message".equalsIgnoreCase(daoException.getMessage())); } @Test public void testOneArgConstructorThrowable(){ - daoException = new DAOException(new Throwable()); - assertTrue("java.lang.Throwable".equalsIgnoreCase(daoException.getMessage())); + daoException = new DAOException(new Throwable()); + assertTrue("java.lang.Throwable".equalsIgnoreCase(daoException.getMessage())); } @Test public void testTwoArgConstructor(){ - daoException = new DAOException("test message", new Throwable()); - assertTrue("test message".equalsIgnoreCase(daoException.getMessage())); + daoException = new DAOException("test message", new Throwable()); + assertTrue("test message".equalsIgnoreCase(daoException.getMessage())); } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedCertDAOTest.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedCertDAOTest.java index 5be0f576..de004fd5 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedCertDAOTest.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedCertDAOTest.java @@ -32,26 +32,26 @@ import org.onap.aaf.auth.env.AuthzTrans; public class JU_CachedCertDAOTest { - private long expiresIn; - private CIDAO<AuthzTrans> info; - @Mock - private CertDAO dao; - private AuthzTrans trans; - - @Before - public void setUp() throws Exception { - initMocks(this); - } - - @Test - public void test() { - CachedCertDAO ccDao = new CachedCertDAO(dao, info, expiresIn); - - ccDao.readID(trans, "id"); - ccDao.readX500(trans, "x500"); - - verify(dao).readID(trans, "id"); - verify(dao).readX500(trans, "x500"); - } + private long expiresIn; + private CIDAO<AuthzTrans> info; + @Mock + private CertDAO dao; + private AuthzTrans trans; + + @Before + public void setUp() throws Exception { + initMocks(this); + } + + @Test + public void test() { + CachedCertDAO ccDao = new CachedCertDAO(dao, info, expiresIn); + + ccDao.readID(trans, "id"); + ccDao.readX500(trans, "x500"); + + verify(dao).readID(trans, "id"); + verify(dao).readX500(trans, "x500"); + } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedCredDAOTest.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedCredDAOTest.java index 06285357..7f5ed85c 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedCredDAOTest.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedCredDAOTest.java @@ -39,32 +39,32 @@ import org.onap.aaf.auth.layer.Result; public class JU_CachedCredDAOTest { - @Mock - private CIDAO<AuthzTrans> info; - @Mock - private CredDAO dao; - private AuthzTrans trans; - @Mock - private Result<List<Data>> value; + @Mock + private CIDAO<AuthzTrans> info; + @Mock + private CredDAO dao; + private AuthzTrans trans; + @Mock + private Result<List<Data>> value; - @Before - public void setUp() throws Exception { - initMocks(this); + @Before + public void setUp() throws Exception { + initMocks(this); - when(dao.readID(trans, "id")).thenReturn(value); - } + when(dao.readID(trans, "id")).thenReturn(value); + } - @Test - public void testOk() { - when(value.isOK()).thenReturn(false); - CachedCredDAO ccDao = new CachedCredDAO(dao, info, 100l); + @Test + public void testOk() { + when(value.isOK()).thenReturn(false); + CachedCredDAO ccDao = new CachedCredDAO(dao, info, 100l); - ccDao.readNS(trans, "ns"); - Result<List<Data>> result = ccDao.readID(trans, "id"); + ccDao.readNS(trans, "ns"); + Result<List<Data>> result = ccDao.readID(trans, "id"); - assertEquals(result.status, Status.OK); - verify(dao).readNS(trans, "ns"); - verify(dao).readID(trans, "id"); - } + assertEquals(result.status, Status.OK); + verify(dao).readNS(trans, "ns"); + verify(dao).readID(trans, "id"); + } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedNSDAOTest.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedNSDAOTest.java index b945b36e..064b985c 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedNSDAOTest.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedNSDAOTest.java @@ -32,23 +32,23 @@ import org.onap.aaf.auth.env.AuthzTrans; public class JU_CachedNSDAOTest { - private long expiresIn; - private CIDAO<AuthzTrans> info; - @Mock - private NsDAO dao; - private AuthzTrans trans; + private long expiresIn; + private CIDAO<AuthzTrans> info; + @Mock + private NsDAO dao; + private AuthzTrans trans; - @Before - public void setUp() throws Exception { - initMocks(this); - } + @Before + public void setUp() throws Exception { + initMocks(this); + } - @Test - public void test() { - CachedNSDAO ccDao = new CachedNSDAO(dao, info, expiresIn); + @Test + public void test() { + CachedNSDAO ccDao = new CachedNSDAO(dao, info, expiresIn); - assertNotNull(ccDao); + assertNotNull(ccDao); - } + } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedPermDAOTest.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedPermDAOTest.java index 66c32a7b..46bbc7e6 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedPermDAOTest.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedPermDAOTest.java @@ -43,28 +43,28 @@ import org.onap.aaf.misc.env.LogTarget; public class JU_CachedPermDAOTest { - @Mock - private CIDAO<AuthzTrans> info; - @Mock - private PermDAO dao; - - @Mock - RoleDAO.Data role; - - @Mock - private PermDAO.Data perm; - - @Mock - private AuthzTrans trans; - @Mock - private Result<List<PermDAO.Data>> value; - - @Before - public void setUp() throws Exception { - initMocks(this); - - when(dao.readNS(trans, "ns")).thenReturn(value); - when(trans.debug()).thenReturn(new LogTarget() { + @Mock + private CIDAO<AuthzTrans> info; + @Mock + private PermDAO dao; + + @Mock + RoleDAO.Data role; + + @Mock + private PermDAO.Data perm; + + @Mock + private AuthzTrans trans; + @Mock + private Result<List<PermDAO.Data>> value; + + @Before + public void setUp() throws Exception { + initMocks(this); + + when(dao.readNS(trans, "ns")).thenReturn(value); + when(trans.debug()).thenReturn(new LogTarget() { @Override public void printf(String fmt, Object... vars) {} @@ -87,80 +87,80 @@ public class JU_CachedPermDAOTest { return true; } }); - } - - @Test - public void testReadNS() { - when(value.isOKhasData()).thenReturn(true); - when(value.isOK()).thenReturn(false); - CachedPermDAO ccDao = new CachedPermDAO(dao, info, 100l); - - Result<List<Data>> result = ccDao.readNS(trans, "ns"); - - assertEquals(result, value); - - when(value.isOKhasData()).thenReturn(false); - - result = ccDao.readNS(trans, "ns"); - - assertEquals(result.status, Status.ERR_PermissionNotFound); - - ccDao.readChildren(trans, "ns", "type"); - - verify(dao).readChildren(trans, "ns", "type"); - } - - @Test - public void testReadByTypeSuccess() { - CachedPermDAO roleDaoObj =new CachedPermDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// - Result<List<Data>> retVal1 = new Result<List<Data>>(null,1,"test4",new String[0]); - Mockito.doReturn(retVal1).when(dao).readByType(trans, "test4",""); - Result<List<Data>> retVal = roleDaoObj.readByType(trans, "test4",""); -// System.out.println(retVal.status); - //retVal.status = 0; - assertEquals("1", Integer.toString(retVal.status)); - } - - @Test - public void testReadByTypeFailure() { - CachedPermDAO roleDaoObj =new CachedPermDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// - Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"test3123",new String[0]); - Mockito.doReturn(retVal1).when(dao).readByType(trans, "test3",""); - Result<List<Data>> retVal = roleDaoObj.readByType(trans, "test3",""); - //System.out.println(retVal.status); - assertEquals("23", Integer.toString(retVal.status)); - } - - @Test - public void testAddRole() { - CachedPermDAO roleDaoObj =new CachedPermDAO(dao,info, 10); - Result<Void> retVal1 = new Result<Void>(null,0,"testAddRole",new String[0]); - Mockito.doReturn(retVal1).when(info).touch(trans, null,null); - Mockito.doReturn(retVal1).when(dao).addRole(trans, perm,null); - Result<Void> retVal = roleDaoObj.addRole(trans, perm, role); -// System.out.println("ret value is::"+retVal); - assertEquals("testAddRole", retVal.toString()); - } - - @Test - public void testDelRole() { - CachedPermDAO roleDaoObj =new CachedPermDAO(dao,info, 10); - Result<Void> retVal1 = new Result<Void>(null,0,"testAddRole",new String[0]); - Mockito.doReturn(retVal1).when(info).touch(trans, null,null); - Mockito.doReturn(retVal1).when(dao).delRole(trans, perm,null); - Result<Void> retVal = roleDaoObj.delRole(trans, perm, role); -// System.out.println(retVal); - assertEquals("testAddRole", retVal.toString()); - } - - @Test - public void testAddDescription() { - CachedPermDAO roleDaoObj =new CachedPermDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// - Result<Void> retVal1 = new Result<Void>(null,0,"test1",new String[0]); - Mockito.doReturn(retVal1).when(dao).addDescription(trans, "","","","",""); - Result<Void> retVal = roleDaoObj.addDescription(trans, "", "","","",""); - //System.out.println(retVal.status); - assertEquals("0", Integer.toString(retVal.status)); - } + } + + @Test + public void testReadNS() { + when(value.isOKhasData()).thenReturn(true); + when(value.isOK()).thenReturn(false); + CachedPermDAO ccDao = new CachedPermDAO(dao, info, 100l); + + Result<List<Data>> result = ccDao.readNS(trans, "ns"); + + assertEquals(result, value); + + when(value.isOKhasData()).thenReturn(false); + + result = ccDao.readNS(trans, "ns"); + + assertEquals(result.status, Status.ERR_PermissionNotFound); + + ccDao.readChildren(trans, "ns", "type"); + + verify(dao).readChildren(trans, "ns", "type"); + } + + @Test + public void testReadByTypeSuccess() { + CachedPermDAO roleDaoObj =new CachedPermDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// + Result<List<Data>> retVal1 = new Result<List<Data>>(null,1,"test4",new String[0]); + Mockito.doReturn(retVal1).when(dao).readByType(trans, "test4",""); + Result<List<Data>> retVal = roleDaoObj.readByType(trans, "test4",""); +// System.out.println(retVal.status); + //retVal.status = 0; + assertEquals("1", Integer.toString(retVal.status)); + } + + @Test + public void testReadByTypeFailure() { + CachedPermDAO roleDaoObj =new CachedPermDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// + Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"test3123",new String[0]); + Mockito.doReturn(retVal1).when(dao).readByType(trans, "test3",""); + Result<List<Data>> retVal = roleDaoObj.readByType(trans, "test3",""); + //System.out.println(retVal.status); + assertEquals("23", Integer.toString(retVal.status)); + } + + @Test + public void testAddRole() { + CachedPermDAO roleDaoObj =new CachedPermDAO(dao,info, 10); + Result<Void> retVal1 = new Result<Void>(null,0,"testAddRole",new String[0]); + Mockito.doReturn(retVal1).when(info).touch(trans, null,null); + Mockito.doReturn(retVal1).when(dao).addRole(trans, perm,null); + Result<Void> retVal = roleDaoObj.addRole(trans, perm, role); +// System.out.println("ret value is::"+retVal); + assertEquals("testAddRole", retVal.toString()); + } + + @Test + public void testDelRole() { + CachedPermDAO roleDaoObj =new CachedPermDAO(dao,info, 10); + Result<Void> retVal1 = new Result<Void>(null,0,"testAddRole",new String[0]); + Mockito.doReturn(retVal1).when(info).touch(trans, null,null); + Mockito.doReturn(retVal1).when(dao).delRole(trans, perm,null); + Result<Void> retVal = roleDaoObj.delRole(trans, perm, role); +// System.out.println(retVal); + assertEquals("testAddRole", retVal.toString()); + } + + @Test + public void testAddDescription() { + CachedPermDAO roleDaoObj =new CachedPermDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// + Result<Void> retVal1 = new Result<Void>(null,0,"test1",new String[0]); + Mockito.doReturn(retVal1).when(dao).addDescription(trans, "","","","",""); + Result<Void> retVal = roleDaoObj.addDescription(trans, "", "","","",""); + //System.out.println(retVal.status); + assertEquals("0", Integer.toString(retVal.status)); + } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedRoleDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedRoleDAO.java index f2bdad2d..4d9527c5 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedRoleDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedRoleDAO.java @@ -45,25 +45,25 @@ import org.onap.aaf.misc.env.LogTarget; @RunWith(MockitoJUnitRunner.class) public class JU_CachedRoleDAO { - @Mock - RoleDAO dao; - - @Mock - CIDAO<AuthzTrans> info; - - @Mock - AuthzTransImpl trans; - - @Mock - RoleDAO.Data data; - - @Mock - PermDAO.Data permData; - - @Before - public void setUp() throws Exception { - initMocks(this); - when(trans.debug()).thenReturn(new LogTarget() { + @Mock + RoleDAO dao; + + @Mock + CIDAO<AuthzTrans> info; + + @Mock + AuthzTransImpl trans; + + @Mock + RoleDAO.Data data; + + @Mock + PermDAO.Data permData; + + @Before + public void setUp() throws Exception { + initMocks(this); + when(trans.debug()).thenReturn(new LogTarget() { @Override public void printf(String fmt, Object... vars) {} @@ -86,90 +86,90 @@ public class JU_CachedRoleDAO { return true; } }); - } - - @Test - public void testReadNameSuccess() { - CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// - Result<List<Data>> retVal1 = new Result<List<Data>>(null,1,"test4",new String[0]); - roleDaoObj.invalidate(""); - Mockito.doReturn(retVal1).when(dao).readName(trans, "test4"); -// Mockito.when(roleDaoObj.get(Mockito.any(), Mockito.any(String.class), Mockito.any())).thenReturn(retVal1); - Result<List<Data>> retVal = roleDaoObj.readName(trans, "test4"); -// System.out.println(retVal.status); - //retVal.status = 0; - assertEquals("1", Integer.toString(retVal.status)); - } - - @Test - public void testReadNameFailure() { - CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// - Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"test3123",new String[0]); - Mockito.doReturn(retVal1).when(dao).readName(trans, "test3"); -// Mockito.when(roleDaoObj.get(Mockito.any(), Mockito.any(String.class), Mockito.any())).thenReturn(retVal1); - Result<List<Data>> retVal = roleDaoObj.readName(trans, "test3"); -// System.out.println(retVal.status); - assertEquals("22", Integer.toString(retVal.status)); - } - @Test - public void testReadNSSuccess() { - CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// - Result<List<Data>> retVal1 = new Result<List<Data>>(null,1,"test",new String[0]); - Mockito.doReturn(retVal1).when(dao).readNS(trans, ""); -// Mockito.when(roleDaoObj.get(Mockito.any(), Mockito.any(String.class), Mockito.any())).thenReturn(retVal1); - Result<List<Data>> retVal = roleDaoObj.readNS(trans, ""); -// System.out.println(retVal.status); - assertEquals("1", Integer.toString(retVal.status)); - } - @Test - public void testReadNSFailure() { - CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// - Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"test1",new String[0]); - Mockito.doReturn(retVal1).when(dao).readNS(trans, ""); -// Mockito.when(roleDaoObj.get(Mockito.any(), Mockito.any(String.class), Mockito.any())).thenReturn(retVal1); - Result<List<Data>> retVal = roleDaoObj.readNS(trans, ""); -// System.out.println(retVal.status); - assertEquals("22", Integer.toString(retVal.status)); - } - - @Test - public void testReadChildren() { - CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// - Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"test1",new String[0]); - Mockito.doReturn(retVal1).when(dao).readChildren(trans, "",""); - Result<List<Data>> retVal = roleDaoObj.readChildren(trans, "", ""); - //System.out.println(retVal.status); - assertEquals("0", Integer.toString(retVal.status)); - } - - @Test - public void testAddPerm() { - CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10); - Result<Void> retVal1 = new Result<Void>(null,0,"testAddPerm",new String[0]); - Mockito.doReturn(retVal1).when(info).touch(trans, null,null); - Mockito.doReturn(retVal1).when(dao).addPerm(trans, data,permData); - Result<Void> retVal = roleDaoObj.addPerm(trans, data, permData); - assertEquals("testAddPerm", retVal.toString()); - } - - @Test - public void testDelPerm() { - CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10); - Result<Void> retVal1 = new Result<Void>(null,0,"testAddPerm",new String[0]); - Mockito.doReturn(retVal1).when(info).touch(trans, null,null); - Mockito.doReturn(retVal1).when(dao).delPerm(trans, data,permData); - Result<Void> retVal = roleDaoObj.delPerm(trans, data, permData); - System.out.println(retVal); - assertEquals("testAddPerm", retVal.toString()); - } + } + + @Test + public void testReadNameSuccess() { + CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// + Result<List<Data>> retVal1 = new Result<List<Data>>(null,1,"test4",new String[0]); + roleDaoObj.invalidate(""); + Mockito.doReturn(retVal1).when(dao).readName(trans, "test4"); +// Mockito.when(roleDaoObj.get(Mockito.any(), Mockito.any(String.class), Mockito.any())).thenReturn(retVal1); + Result<List<Data>> retVal = roleDaoObj.readName(trans, "test4"); +// System.out.println(retVal.status); + //retVal.status = 0; + assertEquals("1", Integer.toString(retVal.status)); + } + + @Test + public void testReadNameFailure() { + CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// + Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"test3123",new String[0]); + Mockito.doReturn(retVal1).when(dao).readName(trans, "test3"); +// Mockito.when(roleDaoObj.get(Mockito.any(), Mockito.any(String.class), Mockito.any())).thenReturn(retVal1); + Result<List<Data>> retVal = roleDaoObj.readName(trans, "test3"); +// System.out.println(retVal.status); + assertEquals("22", Integer.toString(retVal.status)); + } + @Test + public void testReadNSSuccess() { + CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// + Result<List<Data>> retVal1 = new Result<List<Data>>(null,1,"test",new String[0]); + Mockito.doReturn(retVal1).when(dao).readNS(trans, ""); +// Mockito.when(roleDaoObj.get(Mockito.any(), Mockito.any(String.class), Mockito.any())).thenReturn(retVal1); + Result<List<Data>> retVal = roleDaoObj.readNS(trans, ""); +// System.out.println(retVal.status); + assertEquals("1", Integer.toString(retVal.status)); + } + @Test + public void testReadNSFailure() { + CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// + Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"test1",new String[0]); + Mockito.doReturn(retVal1).when(dao).readNS(trans, ""); +// Mockito.when(roleDaoObj.get(Mockito.any(), Mockito.any(String.class), Mockito.any())).thenReturn(retVal1); + Result<List<Data>> retVal = roleDaoObj.readNS(trans, ""); +// System.out.println(retVal.status); + assertEquals("22", Integer.toString(retVal.status)); + } + + @Test + public void testReadChildren() { + CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// + Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"test1",new String[0]); + Mockito.doReturn(retVal1).when(dao).readChildren(trans, "",""); + Result<List<Data>> retVal = roleDaoObj.readChildren(trans, "", ""); + //System.out.println(retVal.status); + assertEquals("0", Integer.toString(retVal.status)); + } + + @Test + public void testAddPerm() { + CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10); + Result<Void> retVal1 = new Result<Void>(null,0,"testAddPerm",new String[0]); + Mockito.doReturn(retVal1).when(info).touch(trans, null,null); + Mockito.doReturn(retVal1).when(dao).addPerm(trans, data,permData); + Result<Void> retVal = roleDaoObj.addPerm(trans, data, permData); + assertEquals("testAddPerm", retVal.toString()); + } + + @Test + public void testDelPerm() { + CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10); + Result<Void> retVal1 = new Result<Void>(null,0,"testAddPerm",new String[0]); + Mockito.doReturn(retVal1).when(info).touch(trans, null,null); + Mockito.doReturn(retVal1).when(dao).delPerm(trans, data,permData); + Result<Void> retVal = roleDaoObj.delPerm(trans, data, permData); + System.out.println(retVal); + assertEquals("testAddPerm", retVal.toString()); + } - @Test - public void testAddDescription() { - CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// - Result<Void> retVal1 = new Result<Void>(null,0,"test1",new String[0]); - Mockito.doReturn(retVal1).when(dao).addDescription(trans, "","",""); - Result<Void> retVal = roleDaoObj.addDescription(trans, "", "",""); - //System.out.println(retVal.status); - assertEquals("0", Integer.toString(retVal.status)); - } + @Test + public void testAddDescription() { + CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// + Result<Void> retVal1 = new Result<Void>(null,0,"test1",new String[0]); + Mockito.doReturn(retVal1).when(dao).addDescription(trans, "","",""); + Result<Void> retVal = roleDaoObj.addDescription(trans, "", "",""); + //System.out.println(retVal.status); + assertEquals("0", Integer.toString(retVal.status)); + } }
\ No newline at end of file diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedUserRoleDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedUserRoleDAO.java index 8dcf8e44..053fc889 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedUserRoleDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedUserRoleDAO.java @@ -48,25 +48,25 @@ import org.powermock.modules.junit4.PowerMockRunner; @RunWith(PowerMockRunner.class) public class JU_CachedUserRoleDAO { - @Mock - UserRoleDAO dao; - - @Mock - CIDAO<AuthzTrans> info; - - @Mock - AuthzTransImpl trans; - - @Mock - RoleDAO.Data data; - - @Mock - PermDAO.Data permData; - - @Before - public void setUp() throws Exception { - initMocks(this); - when(trans.debug()).thenReturn(new LogTarget() { + @Mock + UserRoleDAO dao; + + @Mock + CIDAO<AuthzTrans> info; + + @Mock + AuthzTransImpl trans; + + @Mock + RoleDAO.Data data; + + @Mock + PermDAO.Data permData; + + @Before + public void setUp() throws Exception { + initMocks(this); + when(trans.debug()).thenReturn(new LogTarget() { @Override public void printf(String fmt, Object... vars) {} @@ -89,92 +89,92 @@ public class JU_CachedUserRoleDAO { return true; } }); - } - - private class TaggedPrincipalStub extends TaggedPrincipal { - String name="TaggedPrincipalStub"; + } + + private class TaggedPrincipalStub extends TaggedPrincipal { + String name="TaggedPrincipalStub"; public TaggedPrincipalStub() { super(); } public TaggedPrincipalStub(final TagLookup tl) { super(tl); } @Override public String getName() { return name; } @Override public String tag() { return null; } } - - @Test - public void testReadName() { - CachedUserRoleDAO roleDaoObj =new CachedUserRoleDAO(dao,info, 10L); - Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"test4",new String[0]); - Mockito.doReturn(retVal1).when(dao).readByUser(trans, "test4"); -// Mockito.when(roleDaoObj.get(Mockito.any(), Mockito.any(String.class), Mockito.any())).thenReturn(retVal1); - Result<List<Data>> retVal = roleDaoObj.readByUser(trans, "test4"); - //System.out.println(retVal.status); - //retVal.status = 0; - assertEquals("25", Integer.toString(retVal.status)); - } - - @Test - public void testReadNameUser() { - CachedUserRoleDAO roleDaoObj =new CachedUserRoleDAO(dao,info, 10L); - Result<List<Data>> retVal1 = new Result<List<Data>>(null,1,"TaggedPrincipalStub",new String[0]); - AuthzEnv env = Mockito.mock(AuthzEnv.class); - AuthzTransImpl transTemp = new AuthzTransImpl(env) { - @Override - public<T> T get(Slot slot, T deflt) { - Object o=null; - return (T)o; - } - - }; - transTemp.setUser(new TaggedPrincipalStub()); - Mockito.doReturn(retVal1).when(info).touch(trans, null,null); - Mockito.doReturn(retVal1).when(dao).readByUser(transTemp, "TaggedPrincipalStub"); - roleDaoObj.invalidate("TaggedPrincipalStub"); - Result<List<Data>> retVal = roleDaoObj.readByUser(transTemp, "TaggedPrincipalStub"); -// System.out.println(retVal.status); - assertEquals("1", Integer.toString(retVal.status)); - } - - @Test - public void testReadByRoleSuccess() { - CachedUserRoleDAO roleDaoObj =new CachedUserRoleDAO(dao,info, 0);//Mockito.mock(CachedRoleDAO.class);// - Result<List<Data>> retVal1 = new Result<List<Data>>(null,1,"test",new String[0]); - Mockito.doReturn(retVal1).when(dao).readByRole(trans, ""); - roleDaoObj.invalidate(""); - Result<List<Data>> retVal = roleDaoObj.readByRole(trans, ""); - //System.out.println(retVal.status); - assertEquals("1", Integer.toString(retVal.status)); - } - @Test - public void testReadByRoleFailure() { - CachedUserRoleDAO roleDaoObj =new CachedUserRoleDAO(dao,info, 0);//Mockito.mock(CachedRoleDAO.class);// - Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"test1",new String[0]); - Mockito.doReturn(retVal1).when(dao).readByRole(trans, ""); - roleDaoObj.invalidate(""); - Result<List<Data>> retVal = roleDaoObj.readByRole(trans, ""); - //System.out.println(retVal.status); - assertEquals("25", Integer.toString(retVal.status)); - } - - @Test - public void testReadUserInRole() { - CachedUserRoleDAO roleDaoObj =new CachedUserRoleDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// - Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"TaggedPrincipalStub",new String[0]); - AuthzEnv env = Mockito.mock(AuthzEnv.class); - AuthzTransImpl transTemp = new AuthzTransImpl(env) { - @Override - public<T> T get(Slot slot, T deflt) { - Object o=null; - return (T)o; - } - - }; - transTemp.setUser(new TaggedPrincipalStub()); - Mockito.doReturn(retVal1).when(info).touch(trans, null,null); - Mockito.doReturn(retVal1).when(dao).readByUserRole(transTemp, "",""); - Mockito.doReturn(retVal1).when(dao).readByUser(transTemp, "TaggedPrincipalStub"); - Result<List<Data>> retVal = roleDaoObj.readUserInRole(transTemp, "TaggedPrincipalStub",""); - //System.out.println(retVal.status); - assertEquals("25", Integer.toString(retVal.status)); - } - + + @Test + public void testReadName() { + CachedUserRoleDAO roleDaoObj =new CachedUserRoleDAO(dao,info, 10L); + Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"test4",new String[0]); + Mockito.doReturn(retVal1).when(dao).readByUser(trans, "test4"); +// Mockito.when(roleDaoObj.get(Mockito.any(), Mockito.any(String.class), Mockito.any())).thenReturn(retVal1); + Result<List<Data>> retVal = roleDaoObj.readByUser(trans, "test4"); + //System.out.println(retVal.status); + //retVal.status = 0; + assertEquals("25", Integer.toString(retVal.status)); + } + + @Test + public void testReadNameUser() { + CachedUserRoleDAO roleDaoObj =new CachedUserRoleDAO(dao,info, 10L); + Result<List<Data>> retVal1 = new Result<List<Data>>(null,1,"TaggedPrincipalStub",new String[0]); + AuthzEnv env = Mockito.mock(AuthzEnv.class); + AuthzTransImpl transTemp = new AuthzTransImpl(env) { + @Override + public<T> T get(Slot slot, T deflt) { + Object o=null; + return (T)o; + } + + }; + transTemp.setUser(new TaggedPrincipalStub()); + Mockito.doReturn(retVal1).when(info).touch(trans, null,null); + Mockito.doReturn(retVal1).when(dao).readByUser(transTemp, "TaggedPrincipalStub"); + roleDaoObj.invalidate("TaggedPrincipalStub"); + Result<List<Data>> retVal = roleDaoObj.readByUser(transTemp, "TaggedPrincipalStub"); +// System.out.println(retVal.status); + assertEquals("1", Integer.toString(retVal.status)); + } + + @Test + public void testReadByRoleSuccess() { + CachedUserRoleDAO roleDaoObj =new CachedUserRoleDAO(dao,info, 0);//Mockito.mock(CachedRoleDAO.class);// + Result<List<Data>> retVal1 = new Result<List<Data>>(null,1,"test",new String[0]); + Mockito.doReturn(retVal1).when(dao).readByRole(trans, ""); + roleDaoObj.invalidate(""); + Result<List<Data>> retVal = roleDaoObj.readByRole(trans, ""); + //System.out.println(retVal.status); + assertEquals("1", Integer.toString(retVal.status)); + } + @Test + public void testReadByRoleFailure() { + CachedUserRoleDAO roleDaoObj =new CachedUserRoleDAO(dao,info, 0);//Mockito.mock(CachedRoleDAO.class);// + Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"test1",new String[0]); + Mockito.doReturn(retVal1).when(dao).readByRole(trans, ""); + roleDaoObj.invalidate(""); + Result<List<Data>> retVal = roleDaoObj.readByRole(trans, ""); + //System.out.println(retVal.status); + assertEquals("25", Integer.toString(retVal.status)); + } + + @Test + public void testReadUserInRole() { + CachedUserRoleDAO roleDaoObj =new CachedUserRoleDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// + Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"TaggedPrincipalStub",new String[0]); + AuthzEnv env = Mockito.mock(AuthzEnv.class); + AuthzTransImpl transTemp = new AuthzTransImpl(env) { + @Override + public<T> T get(Slot slot, T deflt) { + Object o=null; + return (T)o; + } + + }; + transTemp.setUser(new TaggedPrincipalStub()); + Mockito.doReturn(retVal1).when(info).touch(trans, null,null); + Mockito.doReturn(retVal1).when(dao).readByUserRole(transTemp, "",""); + Mockito.doReturn(retVal1).when(dao).readByUser(transTemp, "TaggedPrincipalStub"); + Result<List<Data>> retVal = roleDaoObj.readUserInRole(transTemp, "TaggedPrincipalStub",""); + //System.out.println(retVal.status); + assertEquals("25", Integer.toString(retVal.status)); + } + }
\ No newline at end of file diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ApprovalDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ApprovalDAO.java index 79b4aeb5..2b303673 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ApprovalDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ApprovalDAO.java @@ -56,315 +56,315 @@ import com.google.common.util.concurrent.ListenableFuture; public class JU_ApprovalDAO { - @Mock + @Mock AuthzTrans trans; - @Mock - Cluster cluster; - - @Before - public void setUp() throws APIException, IOException { - initMocks(this); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); - } - - @Test - public void testInit() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("ApprovalDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on ApprovalDAO", Env.SUB); - Mockito.doNothing().when(tt).done(); - ApprovalDAO.Data data = new ApprovalDAO.Data(); - PSInfo createPS = Mockito.mock(PSInfo.class); - Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); - Mockito.doReturn(rs).when(createPS).exec(trans, "ApprovalDAOImpl CREATE", data); - - ApprovalDAOImpl daoObj = new ApprovalDAOImpl(trans, cluster, "test",data, createPS); -// data.id - Result<Data> retVal = daoObj.create(trans, data); - assertTrue(retVal.status == 0); - - rs = new Result<ResultSet>(null,1,"test",new String[0]); - Mockito.doReturn(rs).when(createPS).exec(trans, "ApprovalDAOImpl CREATE", data); - retVal = daoObj.create(trans, data); - assertTrue(retVal.status == 1); - - Result<List<ApprovalDAO.Data>> rs1 = new Result<List<ApprovalDAO.Data>>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(createPS).read(trans, "ApprovalDAOImpl CREATE", new Object[]{"testUser"}); - Result<List<ApprovalDAO.Data>> retVal1 = daoObj.readByUser(trans, "testUser"); - assertNull(retVal1); - - Mockito.doReturn(rs1).when(createPS).read(trans, "ApprovalDAOImpl CREATE", new Object[]{"testApprover"}); - retVal1 = daoObj.readByApprover(trans, "testApprover"); - assertNull(retVal1); - - Mockito.doReturn(rs1).when(createPS).read(trans, "ApprovalDAOImpl CREATE", new Object[]{new UUID(0, 0)}); - retVal1 = daoObj.readByTicket(trans, new UUID(0, 0)); - assertNull(retVal1); - - Mockito.doReturn(rs1).when(createPS).read(trans, "ApprovalDAOImpl CREATE", new Object[]{"testStatus"}); - retVal1 = daoObj.readByStatus(trans, "testStatus"); - assertNull(retVal1); - } - - @Test - public void testDelete() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("ApprovalDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on ApprovalDAO", Env.SUB); - Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); - Mockito.doNothing().when(tt).done(); - ApprovalDAO.Data data = new ApprovalDAO.Data(); + @Mock + Cluster cluster; + + @Before + public void setUp() throws APIException, IOException { + initMocks(this); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); + } + + @Test + public void testInit() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("ApprovalDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on ApprovalDAO", Env.SUB); + Mockito.doNothing().when(tt).done(); + ApprovalDAO.Data data = new ApprovalDAO.Data(); + PSInfo createPS = Mockito.mock(PSInfo.class); + Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); + Mockito.doReturn(rs).when(createPS).exec(trans, "ApprovalDAOImpl CREATE", data); + + ApprovalDAOImpl daoObj = new ApprovalDAOImpl(trans, cluster, "test",data, createPS); +// data.id + Result<Data> retVal = daoObj.create(trans, data); + assertTrue(retVal.status == 0); + + rs = new Result<ResultSet>(null,1,"test",new String[0]); + Mockito.doReturn(rs).when(createPS).exec(trans, "ApprovalDAOImpl CREATE", data); + retVal = daoObj.create(trans, data); + assertTrue(retVal.status == 1); + + Result<List<ApprovalDAO.Data>> rs1 = new Result<List<ApprovalDAO.Data>>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(createPS).read(trans, "ApprovalDAOImpl CREATE", new Object[]{"testUser"}); + Result<List<ApprovalDAO.Data>> retVal1 = daoObj.readByUser(trans, "testUser"); + assertNull(retVal1); + + Mockito.doReturn(rs1).when(createPS).read(trans, "ApprovalDAOImpl CREATE", new Object[]{"testApprover"}); + retVal1 = daoObj.readByApprover(trans, "testApprover"); + assertNull(retVal1); + + Mockito.doReturn(rs1).when(createPS).read(trans, "ApprovalDAOImpl CREATE", new Object[]{new UUID(0, 0)}); + retVal1 = daoObj.readByTicket(trans, new UUID(0, 0)); + assertNull(retVal1); + + Mockito.doReturn(rs1).when(createPS).read(trans, "ApprovalDAOImpl CREATE", new Object[]{"testStatus"}); + retVal1 = daoObj.readByStatus(trans, "testStatus"); + assertNull(retVal1); + } + + @Test + public void testDelete() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("ApprovalDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on ApprovalDAO", Env.SUB); + Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); + Mockito.doNothing().when(tt).done(); + ApprovalDAO.Data data = new ApprovalDAO.Data(); - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - - PSInfo createPS = Mockito.mock(PSInfo.class); - ResultSet rsObj = new ResultSetImpl(); - Result<ResultSet> rs = new Result<ResultSet>(rsObj,0,"test",new String[0]); - Mockito.doReturn(rs).when(createPS).exec(trans, "ApprovalDAOImpl READ", data); - Mockito.doReturn(rs).when(createPS).exec(trans, "ApprovalDAOImpl DELETE", data); - - ApprovalDAOImpl daoObj = new ApprovalDAOImpl(trans, cluster, "test", createPS, historyDAO); -// data.id - Result<Void> retVal = daoObj.delete(trans, data, true); - assertTrue(retVal.status == 0); - - rs = new Result<ResultSet>(rsObj,1,"test",new String[0]); - Mockito.doReturn(rs).when(createPS).exec(trans, "ApprovalDAOImpl READ", data); - retVal = daoObj.delete(trans, data, true); - assertTrue(retVal.status == 1); - - data.status="approved"; - data.memo="test"; - retVal = daoObj.delete(trans, data, false); - assertTrue(retVal.status == 0); - - daoObj.async(true); - data.status="denied"; - retVal = daoObj.delete(trans, data, false); - assertTrue(retVal.status == 0); + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + + PSInfo createPS = Mockito.mock(PSInfo.class); + ResultSet rsObj = new ResultSetImpl(); + Result<ResultSet> rs = new Result<ResultSet>(rsObj,0,"test",new String[0]); + Mockito.doReturn(rs).when(createPS).exec(trans, "ApprovalDAOImpl READ", data); + Mockito.doReturn(rs).when(createPS).exec(trans, "ApprovalDAOImpl DELETE", data); + + ApprovalDAOImpl daoObj = new ApprovalDAOImpl(trans, cluster, "test", createPS, historyDAO); +// data.id + Result<Void> retVal = daoObj.delete(trans, data, true); + assertTrue(retVal.status == 0); + + rs = new Result<ResultSet>(rsObj,1,"test",new String[0]); + Mockito.doReturn(rs).when(createPS).exec(trans, "ApprovalDAOImpl READ", data); + retVal = daoObj.delete(trans, data, true); + assertTrue(retVal.status == 1); + + data.status="approved"; + data.memo="test"; + retVal = daoObj.delete(trans, data, false); + assertTrue(retVal.status == 0); + + daoObj.async(true); + data.status="denied"; + retVal = daoObj.delete(trans, data, false); + assertTrue(retVal.status == 0); - data.status=null; - retVal = daoObj.delete(trans, data, false); - } - - @Test - public void testWasMOdified() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("ApprovalDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on ApprovalDAO", Env.SUB); - Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); - Mockito.doNothing().when(tt).done(); - ApprovalDAO.Data data = new ApprovalDAO.Data(); - PSInfo createPS = Mockito.mock(PSInfo.class); - - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - - ApprovalDAOImpl daoObj = new ApprovalDAOImpl(trans, cluster, "test", createPS, historyDAO); - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - - daoObj.wasModified(trans, CRUD.create, data, new String[] {}); - daoObj.wasModified(trans, CRUD.create, data, new String[] {null}); - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test",null}); - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); - - rs1 = new Result<ResultSet>(null,1,"test",new String[0]); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); - } - - @Test - public void testSecondConstructor() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("ApprovalDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on ApprovalDAO", Env.SUB); - Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); - Mockito.doNothing().when(tt).done(); - ApprovalDAO.Data data = new ApprovalDAO.Data(); - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - - ApprovalDAO daoObj = new ApprovalDAO(trans, historyDAO); - } + data.status=null; + retVal = daoObj.delete(trans, data, false); + } + + @Test + public void testWasMOdified() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("ApprovalDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on ApprovalDAO", Env.SUB); + Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); + Mockito.doNothing().when(tt).done(); + ApprovalDAO.Data data = new ApprovalDAO.Data(); + PSInfo createPS = Mockito.mock(PSInfo.class); + + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + + ApprovalDAOImpl daoObj = new ApprovalDAOImpl(trans, cluster, "test", createPS, historyDAO); + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); + + daoObj.wasModified(trans, CRUD.create, data, new String[] {}); + daoObj.wasModified(trans, CRUD.create, data, new String[] {null}); + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test",null}); + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); + + rs1 = new Result<ResultSet>(null,1,"test",new String[0]); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); + } + + @Test + public void testSecondConstructor() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("ApprovalDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on ApprovalDAO", Env.SUB); + Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); + Mockito.doNothing().when(tt).done(); + ApprovalDAO.Data data = new ApprovalDAO.Data(); + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + + ApprovalDAO daoObj = new ApprovalDAO(trans, historyDAO); + } } class ResultSetImpl implements ResultSet{ - @Override - public boolean isExhausted() { - // TODO Auto-generated method stub - return false; - } + @Override + public boolean isExhausted() { + // TODO Auto-generated method stub + return false; + } - @Override - public boolean isFullyFetched() { - // TODO Auto-generated method stub - return false; - } + @Override + public boolean isFullyFetched() { + // TODO Auto-generated method stub + return false; + } - @Override - public int getAvailableWithoutFetching() { - // TODO Auto-generated method stub - return 0; - } + @Override + public int getAvailableWithoutFetching() { + // TODO Auto-generated method stub + return 0; + } - @Override - public ListenableFuture<ResultSet> fetchMoreResults() { - // TODO Auto-generated method stub - return null; - } + @Override + public ListenableFuture<ResultSet> fetchMoreResults() { + // TODO Auto-generated method stub + return null; + } - @Override - public List<Row> all() { - // TODO Auto-generated method stub - return null; - } + @Override + public List<Row> all() { + // TODO Auto-generated method stub + return null; + } - @Override - public Iterator<Row> iterator() { - // TODO Auto-generated method stub - return null; - } + @Override + public Iterator<Row> iterator() { + // TODO Auto-generated method stub + return null; + } - @Override - public ExecutionInfo getExecutionInfo() { - // TODO Auto-generated method stub - return null; - } + @Override + public ExecutionInfo getExecutionInfo() { + // TODO Auto-generated method stub + return null; + } - @Override - public List<ExecutionInfo> getAllExecutionInfo() { - // TODO Auto-generated method stub - return null; - } + @Override + public List<ExecutionInfo> getAllExecutionInfo() { + // TODO Auto-generated method stub + return null; + } - @Override - public Row one() { - // TODO Auto-generated method stub - Row rowObj = Mockito.mock(Row.class); - Mockito.doReturn(Mockito.mock(ColumnDefinitions.class)).when(rowObj).getColumnDefinitions(); - return rowObj; - } + @Override + public Row one() { + // TODO Auto-generated method stub + Row rowObj = Mockito.mock(Row.class); + Mockito.doReturn(Mockito.mock(ColumnDefinitions.class)).when(rowObj).getColumnDefinitions(); + return rowObj; + } - @Override - public ColumnDefinitions getColumnDefinitions() { - // TODO Auto-generated method stub - return null; - } + @Override + public ColumnDefinitions getColumnDefinitions() { + // TODO Auto-generated method stub + return null; + } - @Override - public boolean wasApplied() { - // TODO Auto-generated method stub - return false; - } - + @Override + public boolean wasApplied() { + // TODO Auto-generated method stub + return false; + } + } class ApprovalDAOImpl extends ApprovalDAO{ - public ApprovalDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,ApprovalDAO.Data data,PSInfo createPS ) { - super(trans, cluster, keyspace); - this.createPS = createPS; - setPs(this, createPS, "psByUser"); - setPs(this, createPS, "psByApprover"); - setPs(this, createPS, "psByTicket"); - setPs(this, createPS, "psByStatus"); - } - - public ApprovalDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,PSInfo readPS ) { - super(trans, cluster, keyspace); - this.readPS = readPS; - } - - public ApprovalDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,PSInfo readPS, HistoryDAO historyDAO ) { - super(trans, cluster, keyspace); - this.deletePS = readPS; - this.readPS = readPS; - setHistoryDao(this, historyDAO); - setSession(this, Mockito.mock(Session.class)); - } - - public void setPs(ApprovalDAOImpl approvalDaoObj, PSInfo psInfoObj, String methodName) { - Field nsDaoField; - try { - nsDaoField = ApprovalDAO.class.getDeclaredField(methodName); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(approvalDaoObj, psInfoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + public ApprovalDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,ApprovalDAO.Data data,PSInfo createPS ) { + super(trans, cluster, keyspace); + this.createPS = createPS; + setPs(this, createPS, "psByUser"); + setPs(this, createPS, "psByApprover"); + setPs(this, createPS, "psByTicket"); + setPs(this, createPS, "psByStatus"); + } + + public ApprovalDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,PSInfo readPS ) { + super(trans, cluster, keyspace); + this.readPS = readPS; + } + + public ApprovalDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,PSInfo readPS, HistoryDAO historyDAO ) { + super(trans, cluster, keyspace); + this.deletePS = readPS; + this.readPS = readPS; + setHistoryDao(this, historyDAO); + setSession(this, Mockito.mock(Session.class)); + } + + public void setPs(ApprovalDAOImpl approvalDaoObj, PSInfo psInfoObj, String methodName) { + Field nsDaoField; + try { + nsDaoField = ApprovalDAO.class.getDeclaredField(methodName); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(approvalDaoObj, psInfoObj); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } - public void setHistoryDao(ApprovalDAOImpl approvalDaoObj, HistoryDAO historyDAO) { - Field nsDaoField; - try { - nsDaoField = ApprovalDAO.class.getDeclaredField("historyDAO"); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(approvalDaoObj, historyDAO); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - public void setSession(ApprovalDAOImpl approvalDaoObj, Session session) { - Field nsDaoField; - try { - nsDaoField = AbsCassDAO.class.getDeclaredField("session"); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(approvalDaoObj, session); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + public void setHistoryDao(ApprovalDAOImpl approvalDaoObj, HistoryDAO historyDAO) { + Field nsDaoField; + try { + nsDaoField = ApprovalDAO.class.getDeclaredField("historyDAO"); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(approvalDaoObj, historyDAO); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + public void setSession(ApprovalDAOImpl approvalDaoObj, Session session) { + Field nsDaoField; + try { + nsDaoField = AbsCassDAO.class.getDeclaredField("session"); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(approvalDaoObj, session); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ArtiDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ArtiDAO.java index e6318b99..d6e1fb55 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ArtiDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ArtiDAO.java @@ -55,247 +55,247 @@ import com.datastax.driver.core.Session; public class JU_ArtiDAO { - @Mock + @Mock AuthzTrans trans; - @Mock - Cluster cluster; - - @Before - public void setUp() throws APIException, IOException { - initMocks(this); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); - } - - @Test - public void testReadByMechID() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("ArtiDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on ArtiDAO", Env.SUB); - Mockito.doNothing().when(tt).done(); - - PSInfo psByMechIdObj = Mockito.mock(PSInfo.class); - Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); -// Mockito.doReturn(rs).when(createPS).exec(trans, "ArtiDAOImpl CREATE", data); - - ArtiDAOImpl daoObj = new ArtiDAOImpl(trans, cluster, "test", psByMechIdObj); - - Result<List<ArtiDAO.Data>> rs1 = new Result<List<ArtiDAO.Data>>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(psByMechIdObj).read(trans, "ArtiDAOImpl READ", new Object[]{"testMechId"}); - daoObj.readByMechID(trans, "testMechId"); - - rs1 = new Result<List<ArtiDAO.Data>>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(psByMechIdObj).read(trans, "ArtiDAOImpl READ", new Object[]{"testMachine"}); - daoObj.readByMachine(trans, "testMachine"); + @Mock + Cluster cluster; + + @Before + public void setUp() throws APIException, IOException { + initMocks(this); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); + } + + @Test + public void testReadByMechID() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("ArtiDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on ArtiDAO", Env.SUB); + Mockito.doNothing().when(tt).done(); + + PSInfo psByMechIdObj = Mockito.mock(PSInfo.class); + Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); +// Mockito.doReturn(rs).when(createPS).exec(trans, "ArtiDAOImpl CREATE", data); + + ArtiDAOImpl daoObj = new ArtiDAOImpl(trans, cluster, "test", psByMechIdObj); + + Result<List<ArtiDAO.Data>> rs1 = new Result<List<ArtiDAO.Data>>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(psByMechIdObj).read(trans, "ArtiDAOImpl READ", new Object[]{"testMechId"}); + daoObj.readByMechID(trans, "testMechId"); + + rs1 = new Result<List<ArtiDAO.Data>>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(psByMechIdObj).read(trans, "ArtiDAOImpl READ", new Object[]{"testMachine"}); + daoObj.readByMachine(trans, "testMachine"); - rs1 = new Result<List<ArtiDAO.Data>>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(psByMechIdObj).read(trans, "ArtiDAOImpl READ", new Object[]{"testNs"}); - daoObj.readByNs(trans, "testNs"); - } - - @Test - public void testWasMOdified() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("ArtiDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on ArtiDAO", Env.SUB); - Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); - Mockito.doNothing().when(tt).done(); - ArtiDAO.Data data = new ArtiDAO.Data(); - PSInfo createPS = Mockito.mock(PSInfo.class); - - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - - ArtiDAOImpl daoObj = new ArtiDAOImpl(trans, cluster, "test", createPS, historyDAO); - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - - daoObj.wasModified(trans, CRUD.create, data, new String[] {}); - daoObj.wasModified(trans, CRUD.create, data, new String[] {null}); - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test",null}); - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); - - rs1 = new Result<ResultSet>(null,1,"test",new String[0]); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); - - data.type(true); - daoObj.wasModified(trans, CRUD.delete, data, new String[] {"test","test"}); - - } - @Test - public void testData(){ - ArtiDAO.Data data = new ArtiDAO.Data(); - data.type(true); - data.type(false); - - data.sans(true); - data.sans(false); - data.sans = new TreeSet(); - data.sans(false); - data.sans(true); - - data.expires = new Date(); - data.toString(); - } - - @Test - public void testArtifactLoader(){ - ArtiDAO daoObj = new ArtiDAO(trans, cluster, "test"); - Class<?> innerClass = ArtiDAO.class.getDeclaredClasses()[0]; + rs1 = new Result<List<ArtiDAO.Data>>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(psByMechIdObj).read(trans, "ArtiDAOImpl READ", new Object[]{"testNs"}); + daoObj.readByNs(trans, "testNs"); + } + + @Test + public void testWasMOdified() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("ArtiDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on ArtiDAO", Env.SUB); + Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); + Mockito.doNothing().when(tt).done(); + ArtiDAO.Data data = new ArtiDAO.Data(); + PSInfo createPS = Mockito.mock(PSInfo.class); + + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + + ArtiDAOImpl daoObj = new ArtiDAOImpl(trans, cluster, "test", createPS, historyDAO); + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); + + daoObj.wasModified(trans, CRUD.create, data, new String[] {}); + daoObj.wasModified(trans, CRUD.create, data, new String[] {null}); + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test",null}); + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); + + rs1 = new Result<ResultSet>(null,1,"test",new String[0]); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); + + data.type(true); + daoObj.wasModified(trans, CRUD.delete, data, new String[] {"test","test"}); + + } + @Test + public void testData(){ + ArtiDAO.Data data = new ArtiDAO.Data(); + data.type(true); + data.type(false); + + data.sans(true); + data.sans(false); + data.sans = new TreeSet(); + data.sans(false); + data.sans(true); + + data.expires = new Date(); + data.toString(); + } + + @Test + public void testArtifactLoader(){ + ArtiDAO daoObj = new ArtiDAO(trans, cluster, "test"); + Class<?> innerClass = ArtiDAO.class.getDeclaredClasses()[0]; Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); try { - Object obj = constructor.newInstance(10); - Method innnerClassMtd; - - ArtiDAO.Data data = new ArtiDAO.Data(); - Row row = Mockito.mock(Row.class); - innnerClassMtd = innerClass.getMethod("load", new Class[] {ArtiDAO.Data.class, Row.class}); - innnerClassMtd.invoke(obj, new Object[] {data, row}); - - innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {ArtiDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); - - innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {ArtiDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); - -// DataInputStream in = Mockito.mock(DataInputStream.class); -//// Mockito.doReturn(100).when(in).read(); -//// Mockito.doReturn(100).when(in).readInt(); -// innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {ArtiDAO.Data.class, DataInputStream.class }); -// innnerClassMtd.invoke(obj, new Object[] {data, in}); - } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testSecondConstructor() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("ArtiDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on ArtiDAO", Env.SUB); - Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); - Mockito.doNothing().when(tt).done(); - ArtiDAO.Data data = new ArtiDAO.Data(); - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - - ArtiDAO daoObj = new ArtiDAO(trans, historyDAO, Mockito.mock(CacheInfoDAO.class)); - } - + Object obj = constructor.newInstance(10); + Method innnerClassMtd; + + ArtiDAO.Data data = new ArtiDAO.Data(); + Row row = Mockito.mock(Row.class); + innnerClassMtd = innerClass.getMethod("load", new Class[] {ArtiDAO.Data.class, Row.class}); + innnerClassMtd.invoke(obj, new Object[] {data, row}); + + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {ArtiDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); + + innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {ArtiDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); + +// DataInputStream in = Mockito.mock(DataInputStream.class); +//// Mockito.doReturn(100).when(in).read(); +//// Mockito.doReturn(100).when(in).readInt(); +// innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {ArtiDAO.Data.class, DataInputStream.class }); +// innnerClassMtd.invoke(obj, new Object[] {data, in}); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testSecondConstructor() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("ArtiDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on ArtiDAO", Env.SUB); + Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); + Mockito.doNothing().when(tt).done(); + ArtiDAO.Data data = new ArtiDAO.Data(); + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + + ArtiDAO daoObj = new ArtiDAO(trans, historyDAO, Mockito.mock(CacheInfoDAO.class)); + } + } class ArtiDAOImpl extends ArtiDAO{ - public ArtiDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace, PSInfo createPS ) { - super(trans, cluster, keyspace); - this.createPS = createPS; - setPs(this, createPS, "psByMechID"); - setPs(this, createPS, "psByMachine"); - setPs(this, createPS, "psByNs"); - } - - public ArtiDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,PSInfo readPS, HistoryDAO historyDAO ) { - super(trans, cluster, keyspace); - this.deletePS = readPS; - this.readPS = readPS; - setHistoryDao(this, historyDAO); - setSession(this, Mockito.mock(Session.class)); - } - - public void setPs(ArtiDAOImpl ArtiDAOObj, PSInfo psInfoObj, String methodName) { - Field nsDaoField; - try { - nsDaoField = ArtiDAO.class.getDeclaredField(methodName); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(ArtiDAOObj, psInfoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + public ArtiDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace, PSInfo createPS ) { + super(trans, cluster, keyspace); + this.createPS = createPS; + setPs(this, createPS, "psByMechID"); + setPs(this, createPS, "psByMachine"); + setPs(this, createPS, "psByNs"); + } + + public ArtiDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,PSInfo readPS, HistoryDAO historyDAO ) { + super(trans, cluster, keyspace); + this.deletePS = readPS; + this.readPS = readPS; + setHistoryDao(this, historyDAO); + setSession(this, Mockito.mock(Session.class)); + } + + public void setPs(ArtiDAOImpl ArtiDAOObj, PSInfo psInfoObj, String methodName) { + Field nsDaoField; + try { + nsDaoField = ArtiDAO.class.getDeclaredField(methodName); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(ArtiDAOObj, psInfoObj); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } - public void setHistoryDao(ArtiDAOImpl ArtiDAOObj, HistoryDAO historyDAO) { - Field nsDaoField; - try { - nsDaoField = ArtiDAO.class.getDeclaredField("historyDAO"); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(ArtiDAOObj, historyDAO); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - public void setSession(ArtiDAOImpl ArtiDAOObj, Session session) { - Field nsDaoField; - try { - nsDaoField = AbsCassDAO.class.getDeclaredField("session"); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(ArtiDAOObj, session); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + public void setHistoryDao(ArtiDAOImpl ArtiDAOObj, HistoryDAO historyDAO) { + Field nsDaoField; + try { + nsDaoField = ArtiDAO.class.getDeclaredField("historyDAO"); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(ArtiDAOObj, historyDAO); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + public void setSession(ArtiDAOImpl ArtiDAOObj, Session session) { + Field nsDaoField; + try { + nsDaoField = AbsCassDAO.class.getDeclaredField("session"); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(ArtiDAOObj, session); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_CacheInfoDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_CacheInfoDAO.java index 939cd27d..c23a3729 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_CacheInfoDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_CacheInfoDAO.java @@ -67,572 +67,572 @@ import com.datastax.driver.core.exceptions.DriverException; public class JU_CacheInfoDAO { - @Mock + @Mock AuthzTrans trans; - @Mock - Cluster cluster; - @Mock - Session session; - @Mock - AuthzEnv env; - @Mock - LogTarget logTarget; - - @Before - public void setUp() throws APIException, IOException { - initMocks(this); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).init(); - Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LATITUDE); - Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LONGITUDE); - Mockito.doReturn(session).when(cluster).connect("test"); - } - - @Test - public void testInit() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB); - Mockito.doNothing().when(tt).done(); - CacheInfoDAO.Data data = new CacheInfoDAO.Data(); - PSInfo createPS = Mockito.mock(PSInfo.class); - Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); - Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data); - - CacheInfoDAOImpl daoObj=null; - try { - daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } -// data.id - Result<Data> retVal = daoObj.create(trans, data); - assertTrue(retVal.status == 0); - } - - @Test - public void testTouch() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test: 1", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test: 1,2", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB); - Mockito.doNothing().when(tt).done(); + @Mock + Cluster cluster; + @Mock + Session session; + @Mock + AuthzEnv env; + @Mock + LogTarget logTarget; + + @Before + public void setUp() throws APIException, IOException { + initMocks(this); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).init(); + Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LATITUDE); + Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LONGITUDE); + Mockito.doReturn(session).when(cluster).connect("test"); + } + + @Test + public void testInit() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB); + Mockito.doNothing().when(tt).done(); + CacheInfoDAO.Data data = new CacheInfoDAO.Data(); + PSInfo createPS = Mockito.mock(PSInfo.class); + Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); + Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data); + + CacheInfoDAOImpl daoObj=null; + try { + daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } +// data.id + Result<Data> retVal = daoObj.create(trans, data); + assertTrue(retVal.status == 0); + } + + @Test + public void testTouch() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test: 1", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test: 1,2", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB); + Mockito.doNothing().when(tt).done(); - Mockito.doReturn(logTarget).when(env).debug(); - - CacheInfoDAO.Data data = new CacheInfoDAO.Data(); - PSInfo createPS = Mockito.mock(PSInfo.class); - Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); - Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data); - - CacheInfoDAOImpl daoObj=null; - try { - daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } -// data.id - Result<Void> retVal = daoObj.touch(trans, "test", 1, 2); - assertTrue(retVal.status == 0); - Mockito.doThrow(DriverException.class).when(session).executeAsync(Mockito.anyString()); - daoObj.startUpdate(env, Mockito.mock(HMangr.class), Mockito.mock(SecuritySetter.class), "12.0.0.1", 8080); - retVal = daoObj.touch(trans, "test", 1, 2); - - - try { - daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - assertTrue(retVal.status == Result.ERR_Backend); - Mockito.doThrow(APIException.class).when(session).executeAsync(Mockito.anyString()); - retVal = daoObj.touch(trans, "test", 1, 2); - try { - daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - assertTrue(retVal.status == Result.ERR_Backend); - Mockito.doThrow(IOException.class).when(session).executeAsync(Mockito.anyString()); - try { - daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - retVal = daoObj.touch(trans, "test", 1, 2); - assertTrue(retVal.status == Result.ERR_Backend); - } - - @Test - public void testCheck() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Check Table Timestamps", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB); - Mockito.doNothing().when(tt).done(); - CacheInfoDAO.Data data = new CacheInfoDAO.Data(); - PSInfo createPS = Mockito.mock(PSInfo.class); - Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); - Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data); - - CacheInfoDAOImpl daoObj=null; - PreparedStatement ps = Mockito.mock(PreparedStatement.class); - Mockito.doReturn(ps).when(session).prepare(Mockito.anyString()); - Mockito.doReturn(Mockito.mock(ColumnDefinitions.class)).when(ps).getVariables(); - Mockito.doReturn(Mockito.mock(PreparedId.class)).when(ps).getPreparedId(); - try { - daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } -// data.id - ResultSet resultSet = Mockito.mock(ResultSet.class); - List<Row> rowList = new ArrayList<>(); - Mockito.doReturn(rowList).when(resultSet).all(); - Mockito.doReturn(resultSet).when(session).execute(Mockito.any(Statement.class)); - Result<Void> retVal = daoObj.check(trans); - assertTrue(retVal.status == 0); - - Row row = Mockito.mock(Row.class); - Mockito.doReturn("test").when(row).getString(Mockito.anyInt()); - rowList.add(row); - row = Mockito.mock(Row.class); - Mockito.doReturn("test").when(row).getString(Mockito.anyInt()); - Mockito.doReturn(100).when(row).getInt(Mockito.anyInt()); - rowList.add(row); - retVal = daoObj.check(trans); - assertTrue(retVal.status == 0); + Mockito.doReturn(logTarget).when(env).debug(); + + CacheInfoDAO.Data data = new CacheInfoDAO.Data(); + PSInfo createPS = Mockito.mock(PSInfo.class); + Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); + Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data); + + CacheInfoDAOImpl daoObj=null; + try { + daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } +// data.id + Result<Void> retVal = daoObj.touch(trans, "test", 1, 2); + assertTrue(retVal.status == 0); + Mockito.doThrow(DriverException.class).when(session).executeAsync(Mockito.anyString()); + daoObj.startUpdate(env, Mockito.mock(HMangr.class), Mockito.mock(SecuritySetter.class), "12.0.0.1", 8080); + retVal = daoObj.touch(trans, "test", 1, 2); + + + try { + daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertTrue(retVal.status == Result.ERR_Backend); + Mockito.doThrow(APIException.class).when(session).executeAsync(Mockito.anyString()); + retVal = daoObj.touch(trans, "test", 1, 2); + try { + daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertTrue(retVal.status == Result.ERR_Backend); + Mockito.doThrow(IOException.class).when(session).executeAsync(Mockito.anyString()); + try { + daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + retVal = daoObj.touch(trans, "test", 1, 2); + assertTrue(retVal.status == Result.ERR_Backend); + } + + @Test + public void testCheck() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Check Table Timestamps", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB); + Mockito.doNothing().when(tt).done(); + CacheInfoDAO.Data data = new CacheInfoDAO.Data(); + PSInfo createPS = Mockito.mock(PSInfo.class); + Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); + Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data); + + CacheInfoDAOImpl daoObj=null; + PreparedStatement ps = Mockito.mock(PreparedStatement.class); + Mockito.doReturn(ps).when(session).prepare(Mockito.anyString()); + Mockito.doReturn(Mockito.mock(ColumnDefinitions.class)).when(ps).getVariables(); + Mockito.doReturn(Mockito.mock(PreparedId.class)).when(ps).getPreparedId(); + try { + daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } +// data.id + ResultSet resultSet = Mockito.mock(ResultSet.class); + List<Row> rowList = new ArrayList<>(); + Mockito.doReturn(rowList).when(resultSet).all(); + Mockito.doReturn(resultSet).when(session).execute(Mockito.any(Statement.class)); + Result<Void> retVal = daoObj.check(trans); + assertTrue(retVal.status == 0); + + Row row = Mockito.mock(Row.class); + Mockito.doReturn("test").when(row).getString(Mockito.anyInt()); + rowList.add(row); + row = Mockito.mock(Row.class); + Mockito.doReturn("test").when(row).getString(Mockito.anyInt()); + Mockito.doReturn(100).when(row).getInt(Mockito.anyInt()); + rowList.add(row); + retVal = daoObj.check(trans); + assertTrue(retVal.status == 0); - Mockito.doThrow(DriverException.class).when(session).execute(Mockito.any(Statement.class)); - retVal = daoObj.check(trans); - assertTrue(retVal.status == Result.ERR_Backend); - try { - daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Mockito.doThrow(APIException.class).when(session).execute(Mockito.any(Statement.class)); - retVal = daoObj.check(trans); - assertTrue(retVal.status == Result.ERR_Backend); - try { - daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Mockito.doThrow(IOException.class).when(session).execute(Mockito.any(Statement.class)); - retVal = daoObj.check(trans); - assertTrue(retVal.status == Result.ERR_Backend); - } - @Test - public void testStopUpdate() { - - CacheInfoDAO.stopUpdate(); - - } + Mockito.doThrow(DriverException.class).when(session).execute(Mockito.any(Statement.class)); + retVal = daoObj.check(trans); + assertTrue(retVal.status == Result.ERR_Backend); + try { + daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Mockito.doThrow(APIException.class).when(session).execute(Mockito.any(Statement.class)); + retVal = daoObj.check(trans); + assertTrue(retVal.status == Result.ERR_Backend); + try { + daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Mockito.doThrow(IOException.class).when(session).execute(Mockito.any(Statement.class)); + retVal = daoObj.check(trans); + assertTrue(retVal.status == Result.ERR_Backend); + } + @Test + public void testStopUpdate() { + + CacheInfoDAO.stopUpdate(); + + } /* - * This has intermittent Null Pointers, JUnit only - @Test - public void testGet() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test1: 1011", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB); - Mockito.doNothing().when(tt).done(); - CacheInfoDAO.Data data = new CacheInfoDAO.Data(); - PSInfo createPS = Mockito.mock(PSInfo.class); - Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); - Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data); - - CacheInfoDAOImpl daoObj=null; - try { - daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS); - Date retVal = daoObj.get(trans, "test", 1011); -// assertTrue(retVal.status == 0); - retVal = daoObj.get(trans, "test1", 1011); - } catch (APIException | IOException e) { - e.printStackTrace(); - } - } + * This has intermittent Null Pointers, JUnit only + @Test + public void testGet() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test1: 1011", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB); + Mockito.doNothing().when(tt).done(); + CacheInfoDAO.Data data = new CacheInfoDAO.Data(); + PSInfo createPS = Mockito.mock(PSInfo.class); + Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); + Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data); + + CacheInfoDAOImpl daoObj=null; + try { + daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS); + Date retVal = daoObj.get(trans, "test", 1011); +// assertTrue(retVal.status == 0); + retVal = daoObj.get(trans, "test1", 1011); + } catch (APIException | IOException e) { + e.printStackTrace(); + } + } */ - - @Test - public void testWasMOdified() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB); - Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); - Mockito.doNothing().when(tt).done(); - CacheInfoDAO.Data data = new CacheInfoDAO.Data("test",1); - PSInfo createPS = Mockito.mock(PSInfo.class); - - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - - CacheInfoDAOImpl daoObj=null; - try { - daoObj = new CacheInfoDAOImpl(trans, cluster, "test", createPS); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - - - } - - @Test - public void testInfoLoader(){ - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test1: 1011", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB); - Mockito.doNothing().when(tt).done(); - CacheInfoDAO.Data data1 = new CacheInfoDAO.Data(); - PSInfo createPS = Mockito.mock(PSInfo.class); - Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); - Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data1); + + @Test + public void testWasMOdified() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB); + Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); + Mockito.doNothing().when(tt).done(); + CacheInfoDAO.Data data = new CacheInfoDAO.Data("test",1); + PSInfo createPS = Mockito.mock(PSInfo.class); + + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + + CacheInfoDAOImpl daoObj=null; + try { + daoObj = new CacheInfoDAOImpl(trans, cluster, "test", createPS); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); + + + } + + @Test + public void testInfoLoader(){ + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test1: 1011", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB); + Mockito.doNothing().when(tt).done(); + CacheInfoDAO.Data data1 = new CacheInfoDAO.Data(); + PSInfo createPS = Mockito.mock(PSInfo.class); + Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); + Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data1); - CacheInfoDAOImpl daoObj=null; - try { - daoObj = new CacheInfoDAOImpl(trans, cluster, "test", createPS); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Class[] classList = CacheInfoDAO.class.getDeclaredClasses(); - Class<?> innerClass = null; - for(Class indCls:classList) { - if(indCls.getName().contains("InfoLoader")) { - innerClass = indCls; - } - } + CacheInfoDAOImpl daoObj=null; + try { + daoObj = new CacheInfoDAOImpl(trans, cluster, "test", createPS); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Class[] classList = CacheInfoDAO.class.getDeclaredClasses(); + Class<?> innerClass = null; + for(Class indCls:classList) { + if(indCls.getName().contains("InfoLoader")) { + innerClass = indCls; + } + } Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); try { - Object obj = constructor.newInstance(1); - Method innnerClassMtd; - - CacheInfoDAO.Data data = new CacheInfoDAO.Data(); - Row row = Mockito.mock(Row.class); - innnerClassMtd = innerClass.getMethod("load", new Class[] {CacheInfoDAO.Data.class, Row.class}); - innnerClassMtd.invoke(obj, new Object[] {data, row}); - - innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {CacheInfoDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"}}); + Object obj = constructor.newInstance(1); + Method innnerClassMtd; + + CacheInfoDAO.Data data = new CacheInfoDAO.Data(); + Row row = Mockito.mock(Row.class); + innnerClassMtd = innerClass.getMethod("load", new Class[] {CacheInfoDAO.Data.class, Row.class}); + innnerClassMtd.invoke(obj, new Object[] {data, row}); + + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {CacheInfoDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"}}); - innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {CacheInfoDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"}}); - } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testCacheUpdate(){ - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test1: 1011", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB); - Mockito.doNothing().when(tt).done(); - CacheInfoDAO.Data data1 = new CacheInfoDAO.Data(); - PSInfo createPS = Mockito.mock(PSInfo.class); - Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); - Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data1); + innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {CacheInfoDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"}}); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testCacheUpdate(){ + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test1: 1011", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB); + Mockito.doNothing().when(tt).done(); + CacheInfoDAO.Data data1 = new CacheInfoDAO.Data(); + PSInfo createPS = Mockito.mock(PSInfo.class); + Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); + Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data1); - CacheInfoDAOImpl daoObj=null; - try { - daoObj = new CacheInfoDAOImpl(trans, cluster, "test", createPS); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Class[] classList = CacheInfoDAO.class.getDeclaredClasses(); - Class<?> innerClass = null; - for(Class indCls:classList) { - if(indCls.getName().contains("CacheUpdate")) { - innerClass = indCls; - } - } + CacheInfoDAOImpl daoObj=null; + try { + daoObj = new CacheInfoDAOImpl(trans, cluster, "test", createPS); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Class[] classList = CacheInfoDAO.class.getDeclaredClasses(); + Class<?> innerClass = null; + for(Class indCls:classList) { + if(indCls.getName().contains("CacheUpdate")) { + innerClass = indCls; + } + } Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); try { - Object obj = constructor.newInstance(env,Mockito.mock(HMangr.class), Mockito.mock(SecuritySetter.class), "12.0.0.1", 8080); + Object obj = constructor.newInstance(env,Mockito.mock(HMangr.class), Mockito.mock(SecuritySetter.class), "12.0.0.1", 8080); - Class<?> innerInnerClass = Class.forName("org.onap.aaf.auth.dao.cass.CacheInfoDAO$CacheUpdate$CacheClear"); + Class<?> innerInnerClass = Class.forName("org.onap.aaf.auth.dao.cass.CacheInfoDAO$CacheUpdate$CacheClear"); Constructor<?> innerConstructor = innerInnerClass.getDeclaredConstructors()[0]; innerConstructor.setAccessible(true); Object innerClassObj = innerConstructor.newInstance(obj, trans); - - Method innnerClassMtd; - - CacheInfoDAO.Data data = new CacheInfoDAO.Data(); - Row row = Mockito.mock(Row.class); - Rcli rcli = Mockito.mock(Rcli.class); - URI uri = new URI("ftp","admin:admin@geeksforgeeks.org:1234","/path/data","tt","ttd"); - Mockito.doReturn(uri).when(rcli).getURI(); - Mockito.doReturn(Mockito.mock(org.onap.aaf.cadi.client.Future.class)).when(rcli).delete("/mgmt/cache/null/null", "application/Void+json;q=1.0;charset=utf-8;version=2.0,application/json;q=1.0;version=2.0,*/*;q=1.0"); - - innnerClassMtd = innerInnerClass.getMethod("code", new Class[] {Rcli.class}); - innnerClassMtd.invoke(innerClassObj, new Object[] {rcli}); - - org.onap.aaf.cadi.client.Future futureObj = Mockito.mock(org.onap.aaf.cadi.client.Future.class); - Mockito.doReturn(futureObj).when(rcli).delete("/mgmt/cache/null/null", "application/Void+json;q=1.0;charset=utf-8;version=2.0,application/json;q=1.0;version=2.0,*/*;q=1.0"); - Mockito.doReturn(true).when(futureObj).get(0); - innnerClassMtd.invoke(innerClassObj, new Object[] {rcli}); - - uri = new URI("ftp","12.0.0.1:8080","/path/data","tt","ttd"); - Mockito.doReturn(uri).when(rcli).getURI(); - innnerClassMtd.invoke(innerClassObj, new Object[] {rcli}); - } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (ClassNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (URISyntaxException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (APIException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testIntHolder(){ - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test1: 1011", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB); - Mockito.doNothing().when(tt).done(); - CacheInfoDAO.Data data1 = new CacheInfoDAO.Data(); - PSInfo createPS = Mockito.mock(PSInfo.class); - Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); - Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data1); + + Method innnerClassMtd; + + CacheInfoDAO.Data data = new CacheInfoDAO.Data(); + Row row = Mockito.mock(Row.class); + Rcli rcli = Mockito.mock(Rcli.class); + URI uri = new URI("ftp","admin:admin@geeksforgeeks.org:1234","/path/data","tt","ttd"); + Mockito.doReturn(uri).when(rcli).getURI(); + Mockito.doReturn(Mockito.mock(org.onap.aaf.cadi.client.Future.class)).when(rcli).delete("/mgmt/cache/null/null", "application/Void+json;q=1.0;charset=utf-8;version=2.0,application/json;q=1.0;version=2.0,*/*;q=1.0"); + + innnerClassMtd = innerInnerClass.getMethod("code", new Class[] {Rcli.class}); + innnerClassMtd.invoke(innerClassObj, new Object[] {rcli}); + + org.onap.aaf.cadi.client.Future futureObj = Mockito.mock(org.onap.aaf.cadi.client.Future.class); + Mockito.doReturn(futureObj).when(rcli).delete("/mgmt/cache/null/null", "application/Void+json;q=1.0;charset=utf-8;version=2.0,application/json;q=1.0;version=2.0,*/*;q=1.0"); + Mockito.doReturn(true).when(futureObj).get(0); + innnerClassMtd.invoke(innerClassObj, new Object[] {rcli}); + + uri = new URI("ftp","12.0.0.1:8080","/path/data","tt","ttd"); + Mockito.doReturn(uri).when(rcli).getURI(); + innnerClassMtd.invoke(innerClassObj, new Object[] {rcli}); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (URISyntaxException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testIntHolder(){ + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test1: 1011", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB); + Mockito.doNothing().when(tt).done(); + CacheInfoDAO.Data data1 = new CacheInfoDAO.Data(); + PSInfo createPS = Mockito.mock(PSInfo.class); + Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); + Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data1); - CacheInfoDAOImpl daoObj=null; - try { - daoObj = new CacheInfoDAOImpl(trans, cluster, "test", createPS); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Class[] classList = CacheInfoDAO.class.getDeclaredClasses(); - Class<?> innerClass = null; - for(Class indCls:classList) { - if(indCls.getName().contains("CacheUpdate")) { - innerClass = indCls; - } - } + CacheInfoDAOImpl daoObj=null; + try { + daoObj = new CacheInfoDAOImpl(trans, cluster, "test", createPS); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Class[] classList = CacheInfoDAO.class.getDeclaredClasses(); + Class<?> innerClass = null; + for(Class indCls:classList) { + if(indCls.getName().contains("CacheUpdate")) { + innerClass = indCls; + } + } Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); try { - Object obj = constructor.newInstance(env,Mockito.mock(HMangr.class), Mockito.mock(SecuritySetter.class), "12.0.0.1", 8080); + Object obj = constructor.newInstance(env,Mockito.mock(HMangr.class), Mockito.mock(SecuritySetter.class), "12.0.0.1", 8080); - Class<?> innerInnerClass = Class.forName("org.onap.aaf.auth.dao.cass.CacheInfoDAO$CacheUpdate$IntHolder"); + Class<?> innerInnerClass = Class.forName("org.onap.aaf.auth.dao.cass.CacheInfoDAO$CacheUpdate$IntHolder"); Constructor<?> innerConstructor = innerInnerClass.getDeclaredConstructors()[0]; innerConstructor.setAccessible(true); int[] a = new int[10]; Object innerClassObj = innerConstructor.newInstance(obj, a); - - Method innnerClassMtd=null; - - CacheInfoDAO.Data data = new CacheInfoDAO.Data(); - Row row = Mockito.mock(Row.class); - Rcli rcli = Mockito.mock(Rcli.class); - URI uri = new URI("ftp","admin:admin@geeksforgeeks.org:1234","/path/data","tt","ttd"); - Mockito.doReturn(uri).when(rcli).getURI(); - Mockito.doReturn(Mockito.mock(org.onap.aaf.cadi.client.Future.class)).when(rcli).delete("/mgmt/cache/null/null", "application/Void+json;q=1.0;charset=utf-8;version=2.0,application/json;q=1.0;version=2.0,*/*;q=1.0"); - - Method[] allMtds = innerInnerClass.getDeclaredMethods(); - for(Method indMtd:allMtds) { - if(indMtd.getName().contains("add")) { - innnerClassMtd = indMtd; - } - } - innnerClassMtd.invoke(innerClassObj, new Object[] {a}); - - - } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (ClassNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (URISyntaxException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (APIException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - //@Test - public void testSecondConstructor() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB); - Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); - Mockito.doNothing().when(tt).done(); - CacheInfoDAO.Data data = new CacheInfoDAO.Data(); - AbsCassDAO absCassDAO = Mockito.mock(AbsCassDAO.class); + + Method innnerClassMtd=null; + + CacheInfoDAO.Data data = new CacheInfoDAO.Data(); + Row row = Mockito.mock(Row.class); + Rcli rcli = Mockito.mock(Rcli.class); + URI uri = new URI("ftp","admin:admin@geeksforgeeks.org:1234","/path/data","tt","ttd"); + Mockito.doReturn(uri).when(rcli).getURI(); + Mockito.doReturn(Mockito.mock(org.onap.aaf.cadi.client.Future.class)).when(rcli).delete("/mgmt/cache/null/null", "application/Void+json;q=1.0;charset=utf-8;version=2.0,application/json;q=1.0;version=2.0,*/*;q=1.0"); + + Method[] allMtds = innerInnerClass.getDeclaredMethods(); + for(Method indMtd:allMtds) { + if(indMtd.getName().contains("add")) { + innnerClassMtd = indMtd; + } + } + innnerClassMtd.invoke(innerClassObj, new Object[] {a}); + + + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (URISyntaxException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (APIException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + //@Test + public void testSecondConstructor() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB); + Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); + Mockito.doNothing().when(tt).done(); + CacheInfoDAO.Data data = new CacheInfoDAO.Data(); + AbsCassDAO absCassDAO = Mockito.mock(AbsCassDAO.class); - try { - CacheInfoDAO daoObj = new CacheInfoDAO(trans, absCassDAO); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + try { + CacheInfoDAO daoObj = new CacheInfoDAO(trans, absCassDAO); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } class CacheInfoDAOImpl extends CacheInfoDAO{ - public CacheInfoDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,CacheInfoDAO.Data data,PSInfo createPS ) throws APIException, IOException { - super(trans, cluster, keyspace); - this.createPS = createPS; -// setPs(this, createPS, "psByUser"); -// setPs(this, createPS, "psByApprover"); -// setPs(this, createPS, "psByTicket"); -// setPs(this, createPS, "psByStatus"); -// setSession(this, Mockito.mock(Session.class)); - } - - public CacheInfoDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,PSInfo readPS ) throws APIException, IOException { - super(trans, cluster, keyspace); - this.readPS = readPS; - } - + public CacheInfoDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,CacheInfoDAO.Data data,PSInfo createPS ) throws APIException, IOException { + super(trans, cluster, keyspace); + this.createPS = createPS; +// setPs(this, createPS, "psByUser"); +// setPs(this, createPS, "psByApprover"); +// setPs(this, createPS, "psByTicket"); +// setPs(this, createPS, "psByStatus"); +// setSession(this, Mockito.mock(Session.class)); + } + + public CacheInfoDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,PSInfo readPS ) throws APIException, IOException { + super(trans, cluster, keyspace); + this.readPS = readPS; + } + - public void setPs(CacheInfoDAOImpl CacheInfoDAOObj, PSInfo psInfoObj, String methodName) { - Field nsDaoField; - try { - nsDaoField = CacheInfoDAO.class.getDeclaredField(methodName); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(CacheInfoDAOObj, psInfoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + public void setPs(CacheInfoDAOImpl CacheInfoDAOObj, PSInfo psInfoObj, String methodName) { + Field nsDaoField; + try { + nsDaoField = CacheInfoDAO.class.getDeclaredField(methodName); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(CacheInfoDAOObj, psInfoObj); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } - - public void setSession(CacheInfoDAOImpl CacheInfoDAOObj, Session session) { - Field nsDaoField; - try { - nsDaoField = AbsCassDAO.class.getDeclaredField("session"); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - nsDaoField.set(CacheInfoDAOObj, session); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - + + public void setSession(CacheInfoDAOImpl CacheInfoDAOObj, Session session) { + Field nsDaoField; + try { + nsDaoField = AbsCassDAO.class.getDeclaredField("session"); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + nsDaoField.set(CacheInfoDAOObj, session); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_CertDAOTest.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_CertDAOTest.java index 3b2352c0..782bd985 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_CertDAOTest.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_CertDAOTest.java @@ -56,331 +56,331 @@ import com.datastax.driver.core.Session; public class JU_CertDAOTest { - @Mock + @Mock AuthzTrans trans; - @Mock - Cluster cluster; - @Mock - Session session; - @Mock - AuthzEnv env; - @Mock - LogTarget logTarget; - - @Before - public void setUp() throws APIException, IOException { - initMocks(this); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).init(); - Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LATITUDE); - Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LONGITUDE); - Mockito.doReturn(session).when(cluster).connect("test"); - } - - @Test - public void testInit() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("CertDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CertDAO", Env.SUB); - Mockito.doNothing().when(tt).done(); - CertDAO.Data data = new CertDAO.Data(); - PSInfo createPS = Mockito.mock(PSInfo.class); - Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); - Mockito.doReturn(rs).when(createPS).exec(trans, "CertDAOImpl CREATE", data); - - CertDAOImpl daoObj=null; - try { - daoObj = new CertDAOImpl(trans, cluster, "test",data, createPS); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + @Mock + Cluster cluster; + @Mock + Session session; + @Mock + AuthzEnv env; + @Mock + LogTarget logTarget; + + @Before + public void setUp() throws APIException, IOException { + initMocks(this); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).init(); + Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LATITUDE); + Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LONGITUDE); + Mockito.doReturn(session).when(cluster).connect("test"); + } + + @Test + public void testInit() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("CertDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CertDAO", Env.SUB); + Mockito.doNothing().when(tt).done(); + CertDAO.Data data = new CertDAO.Data(); + PSInfo createPS = Mockito.mock(PSInfo.class); + Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); + Mockito.doReturn(rs).when(createPS).exec(trans, "CertDAOImpl CREATE", data); + + CertDAOImpl daoObj=null; + try { + daoObj = new CertDAOImpl(trans, cluster, "test",data, createPS); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } - } - - @Test - public void testCertLoader(){ - - Class<?> innerClass = CertDAO.class.getDeclaredClasses()[0]; + } + + @Test + public void testCertLoader(){ + + Class<?> innerClass = CertDAO.class.getDeclaredClasses()[0]; Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); try { - Object obj = constructor.newInstance(1); - Method innnerClassMtd; - - CertDAO.Data data = new CertDAO.Data(); - Row row = Mockito.mock(Row.class); - ByteBuffer bbObj = ByteBuffer.allocateDirect(10); - bbObj.limit(7); - bbObj.put(0, new Byte("0")); - bbObj.put(1, new Byte("1")); - bbObj.put(2, new Byte("2")); - Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); - - innnerClassMtd = innerClass.getMethod("load", new Class[] {CertDAO.Data.class, Row.class}); - innnerClassMtd.invoke(obj, new Object[] {data, row}); - - innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {CertDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); -// - innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {CertDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); - -// DataInputStream in = Mockito.mock(DataInputStream.class); -//// Mockito.doReturn(100).when(in).read(); -//// Mockito.doReturn(100).when(in).readInt(); -// innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {ArtiDAO.Data.class, DataInputStream.class }); -// innnerClassMtd.invoke(obj, new Object[] {data, in}); - } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testWasMOdified() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("CertDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CertDAO", Env.SUB); - Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); - Mockito.doNothing().when(tt).done(); - CertDAO.Data data = new CertDAO.Data(); - PSInfo createPS = Mockito.mock(PSInfo.class); - - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - Mockito.doReturn(rs1).when(cacheInfoDAO).touch(trans, CertDAO.TABLE, new int[1]); - - CertDAO daoObj = null; - try { - daoObj = new CertDAO(trans, historyDAO, cacheInfoDAO); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - - rs1 = new Result<ResultSet>(null,1,"test",new String[0]); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - - Mockito.doReturn(rs1).when(cacheInfoDAO).touch(trans, CertDAO.TABLE, new int[1]); - - try { - daoObj = new CertDAO(trans, historyDAO, cacheInfoDAO); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); + Object obj = constructor.newInstance(1); + Method innnerClassMtd; + + CertDAO.Data data = new CertDAO.Data(); + Row row = Mockito.mock(Row.class); + ByteBuffer bbObj = ByteBuffer.allocateDirect(10); + bbObj.limit(7); + bbObj.put(0, new Byte("0")); + bbObj.put(1, new Byte("1")); + bbObj.put(2, new Byte("2")); + Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); + + innnerClassMtd = innerClass.getMethod("load", new Class[] {CertDAO.Data.class, Row.class}); + innnerClassMtd.invoke(obj, new Object[] {data, row}); + + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {CertDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); +// + innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {CertDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); + +// DataInputStream in = Mockito.mock(DataInputStream.class); +//// Mockito.doReturn(100).when(in).read(); +//// Mockito.doReturn(100).when(in).readInt(); +// innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {ArtiDAO.Data.class, DataInputStream.class }); +// innnerClassMtd.invoke(obj, new Object[] {data, in}); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testWasMOdified() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("CertDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CertDAO", Env.SUB); + Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); + Mockito.doNothing().when(tt).done(); + CertDAO.Data data = new CertDAO.Data(); + PSInfo createPS = Mockito.mock(PSInfo.class); + + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + Mockito.doReturn(rs1).when(cacheInfoDAO).touch(trans, CertDAO.TABLE, new int[1]); + + CertDAO daoObj = null; + try { + daoObj = new CertDAO(trans, historyDAO, cacheInfoDAO); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); + + rs1 = new Result<ResultSet>(null,1,"test",new String[0]); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + + Mockito.doReturn(rs1).when(cacheInfoDAO).touch(trans, CertDAO.TABLE, new int[1]); + + try { + daoObj = new CertDAO(trans, historyDAO, cacheInfoDAO); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - daoObj.wasModified(trans, CRUD.delete, data, new String[] {"test"}); - daoObj.wasModified(trans, CRUD.delete, data, new String[] {"test", null}); - daoObj.wasModified(trans, CRUD.delete, data, new String[] {"test", "test"}); - daoObj.wasModified(trans, CRUD.delete, data, new String[] {null}); - daoObj.wasModified(trans, CRUD.delete, data, new String[] {}); - - try { - CertDAO.Data data1 = Mockito.mock(CertDAO.Data.class); - Mockito.doThrow(new IOException()).when(data1).bytify(); - Mockito.doReturn(new int[1]).when(data1).invalidate(Mockito.any()); - daoObj.wasModified(trans, CRUD.delete, data1, new String[] {}); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testRead() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("CertDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("CertDAO READ", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CertDAO", Env.SUB); - Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("CertDAOImpl READ",Env.REMOTE); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); - Mockito.doReturn(Mockito.mock(Decryptor.class)).when(trans).decryptor(); - Mockito.doNothing().when(tt).done(); - CertDAO.Data data = new CertDAO.Data(); - PSInfo createPS = Mockito.mock(PSInfo.class); - - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - Mockito.doReturn(rs1).when(cacheInfoDAO).touch(trans, CertDAO.TABLE, new int[1]); - - CertDAOImpl daoObj = null; - try { - daoObj = new CertDAOImpl(trans, historyDAO, cacheInfoDAO, createPS); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - daoObj.read(trans, new Object[] {"test", BigInteger.ONE}); - Field cbField; - try { - cbField = CassAccess.class.getDeclaredField("cb"); - - cbField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - cbField.set(null, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - daoObj.readX500(trans, "test"); - - try { - cbField = CassAccess.class.getDeclaredField("cb"); - - cbField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - cbField.set(null, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - daoObj.readID(trans, "test"); - } + daoObj.wasModified(trans, CRUD.delete, data, new String[] {"test"}); + daoObj.wasModified(trans, CRUD.delete, data, new String[] {"test", null}); + daoObj.wasModified(trans, CRUD.delete, data, new String[] {"test", "test"}); + daoObj.wasModified(trans, CRUD.delete, data, new String[] {null}); + daoObj.wasModified(trans, CRUD.delete, data, new String[] {}); + + try { + CertDAO.Data data1 = Mockito.mock(CertDAO.Data.class); + Mockito.doThrow(new IOException()).when(data1).bytify(); + Mockito.doReturn(new int[1]).when(data1).invalidate(Mockito.any()); + daoObj.wasModified(trans, CRUD.delete, data1, new String[] {}); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testRead() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("CertDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("CertDAO READ", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CertDAO", Env.SUB); + Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("CertDAOImpl READ",Env.REMOTE); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); + Mockito.doReturn(Mockito.mock(Decryptor.class)).when(trans).decryptor(); + Mockito.doNothing().when(tt).done(); + CertDAO.Data data = new CertDAO.Data(); + PSInfo createPS = Mockito.mock(PSInfo.class); + + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + Mockito.doReturn(rs1).when(cacheInfoDAO).touch(trans, CertDAO.TABLE, new int[1]); + + CertDAOImpl daoObj = null; + try { + daoObj = new CertDAOImpl(trans, historyDAO, cacheInfoDAO, createPS); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + daoObj.read(trans, new Object[] {"test", BigInteger.ONE}); + Field cbField; + try { + cbField = CassAccess.class.getDeclaredField("cb"); + + cbField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + cbField.set(null, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + daoObj.readX500(trans, "test"); + + try { + cbField = CassAccess.class.getDeclaredField("cb"); + + cbField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + cbField.set(null, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + daoObj.readID(trans, "test"); + } - - @Test - public void testSecondConstructor() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("CertDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CertDAO", Env.SUB); - Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); - Mockito.doNothing().when(tt).done(); - CertDAO.Data data = new CertDAO.Data(); - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + + @Test + public void testSecondConstructor() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("CertDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CertDAO", Env.SUB); + Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); + Mockito.doNothing().when(tt).done(); + CertDAO.Data data = new CertDAO.Data(); + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - try { - CertDAO daoObj = new CertDAO(trans, historyDAO, cacheInfoDAO); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + try { + CertDAO daoObj = new CertDAO(trans, historyDAO, cacheInfoDAO); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } class CertDAOImpl extends CertDAO{ - public CertDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,CertDAO.Data data,PSInfo createPS ) throws APIException, IOException { - super(trans, cluster, keyspace); - this.createPS = createPS; -// setPs(this, createPS, "psByUser"); -// setPs(this, createPS, "psByApprover"); -// setPs(this, createPS, "psByTicket"); -// setPs(this, createPS, "psByStatus"); -// setSession(this, Mockito.mock(Session.class)); - } - - public CertDAOImpl(AuthzTrans trans, HistoryDAO historyDAO, CacheInfoDAO cacheInfoDAO,PSInfo readPS ) throws APIException, IOException { - super(trans, historyDAO, cacheInfoDAO); - this.readPS = readPS; - } - + public CertDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,CertDAO.Data data,PSInfo createPS ) throws APIException, IOException { + super(trans, cluster, keyspace); + this.createPS = createPS; +// setPs(this, createPS, "psByUser"); +// setPs(this, createPS, "psByApprover"); +// setPs(this, createPS, "psByTicket"); +// setPs(this, createPS, "psByStatus"); +// setSession(this, Mockito.mock(Session.class)); + } + + public CertDAOImpl(AuthzTrans trans, HistoryDAO historyDAO, CacheInfoDAO cacheInfoDAO,PSInfo readPS ) throws APIException, IOException { + super(trans, historyDAO, cacheInfoDAO); + this.readPS = readPS; + } + - public void setPs(CertDAOImpl CertDAOObj, PSInfo psInfoObj, String methodName) { - Field nsDaoField; - try { - nsDaoField = CertDAO.class.getDeclaredField(methodName); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(CertDAOObj, psInfoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + public void setPs(CertDAOImpl CertDAOObj, PSInfo psInfoObj, String methodName) { + Field nsDaoField; + try { + nsDaoField = CertDAO.class.getDeclaredField(methodName); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(CertDAOObj, psInfoObj); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } - - public void setSession(CertDAOImpl CertDAOObj, Session session) { - Field nsDaoField; - try { - nsDaoField = AbsCassDAO.class.getDeclaredField("session"); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - nsDaoField.set(CertDAOObj, session); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - + + public void setSession(CertDAOImpl CertDAOObj, Session session) { + Field nsDaoField; + try { + nsDaoField = AbsCassDAO.class.getDeclaredField("session"); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + nsDaoField.set(CertDAOObj, session); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ConfigDAOTest.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ConfigDAOTest.java index 9eee56c4..91d16970 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ConfigDAOTest.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ConfigDAOTest.java @@ -63,248 +63,248 @@ import com.datastax.driver.core.Session; public class JU_ConfigDAOTest { - @Mock + @Mock AuthzTrans trans; - @Mock - Cluster cluster; - @Mock - Session session; - @Mock - AuthzEnv env; - @Mock - LogTarget logTarget; - - @Before - public void setUp() throws APIException, IOException { - initMocks(this); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).init(); - Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LATITUDE); - Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LONGITUDE); - Mockito.doReturn(session).when(cluster).connect("test"); - } - - @Test - public void testInit() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("ConfigDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on ConfigDAO", Env.SUB); - Mockito.doNothing().when(tt).done(); - ConfigDAO.Data data = new ConfigDAO.Data(); - PSInfo createPS = Mockito.mock(PSInfo.class); - Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); - Mockito.doReturn(rs).when(createPS).exec(trans, "ConfigDAOImpl CREATE", data); - - ConfigDAO daoObj=null; - try { - daoObj = new ConfigDAO(trans, cluster, "test"); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + @Mock + Cluster cluster; + @Mock + Session session; + @Mock + AuthzEnv env; + @Mock + LogTarget logTarget; + + @Before + public void setUp() throws APIException, IOException { + initMocks(this); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).init(); + Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LATITUDE); + Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LONGITUDE); + Mockito.doReturn(session).when(cluster).connect("test"); + } + + @Test + public void testInit() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("ConfigDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on ConfigDAO", Env.SUB); + Mockito.doNothing().when(tt).done(); + ConfigDAO.Data data = new ConfigDAO.Data(); + PSInfo createPS = Mockito.mock(PSInfo.class); + Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); + Mockito.doReturn(rs).when(createPS).exec(trans, "ConfigDAOImpl CREATE", data); + + ConfigDAO daoObj=null; + try { + daoObj = new ConfigDAO(trans, cluster, "test"); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } - } - - @Test - public void testConfigLoader(){ - - Class<?> innerClass = ConfigDAO.class.getDeclaredClasses()[0]; + } + + @Test + public void testConfigLoader(){ + + Class<?> innerClass = ConfigDAO.class.getDeclaredClasses()[0]; Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); try { - Object obj = constructor.newInstance(1); - Method innnerClassMtd; - - ConfigDAO.Data data = new ConfigDAO.Data(); - Row row = Mockito.mock(Row.class); - ByteBuffer bbObj = ByteBuffer.allocateDirect(10); - bbObj.limit(7); - bbObj.put(0, new Byte("0")); - bbObj.put(1, new Byte("1")); - bbObj.put(2, new Byte("2")); - Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); - - innnerClassMtd = innerClass.getMethod("load", new Class[] {ConfigDAO.Data.class, Row.class}); - innnerClassMtd.invoke(obj, new Object[] {data, row}); - - innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {ConfigDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); -// - innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {ConfigDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {ConfigDAO.Data.class, DataOutputStream.class }); - innnerClassMtd.invoke(obj, new Object[] {data, dos }); + Object obj = constructor.newInstance(1); + Method innnerClassMtd; + + ConfigDAO.Data data = new ConfigDAO.Data(); + Row row = Mockito.mock(Row.class); + ByteBuffer bbObj = ByteBuffer.allocateDirect(10); + bbObj.limit(7); + bbObj.put(0, new Byte("0")); + bbObj.put(1, new Byte("1")); + bbObj.put(2, new Byte("2")); + Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); + + innnerClassMtd = innerClass.getMethod("load", new Class[] {ConfigDAO.Data.class, Row.class}); + innnerClassMtd.invoke(obj, new Object[] {data, row}); + + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {ConfigDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); +// + innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {ConfigDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {ConfigDAO.Data.class, DataOutputStream.class }); + innnerClassMtd.invoke(obj, new Object[] {data, dos }); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - DataInputStream dis = new DataInputStream(bais); - innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {ConfigDAO.Data.class, DataInputStream.class }); - innnerClassMtd.invoke(obj, new Object[] {data, dis }); - - } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testWasMOdified() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("ConfigDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on ConfigDAO", Env.SUB); - Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); - Mockito.doNothing().when(tt).done(); - ConfigDAO.Data data = new ConfigDAO.Data(); - PSInfo createPS = Mockito.mock(PSInfo.class); - - ConfigDAO daoObj = null; - try { - daoObj = new ConfigDAO(trans, cluster, "test"); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - - - - } - - @Test - public void testRead() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("ConfigDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("ConfigDAO READ", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo READ on ConfigDAO", Env.SUB); - Mockito.doReturn(tt).when(trans).start(Mockito.anyString(),Mockito.anyInt()); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); - Mockito.doReturn(Mockito.mock(Decryptor.class)).when(trans).decryptor(); - Mockito.doNothing().when(tt).done(); - - Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new String[0]); - + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + DataInputStream dis = new DataInputStream(bais); + innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {ConfigDAO.Data.class, DataInputStream.class }); + innnerClassMtd.invoke(obj, new Object[] {data, dis }); + + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testWasMOdified() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("ConfigDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on ConfigDAO", Env.SUB); + Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); + Mockito.doNothing().when(tt).done(); + ConfigDAO.Data data = new ConfigDAO.Data(); + PSInfo createPS = Mockito.mock(PSInfo.class); + + ConfigDAO daoObj = null; + try { + daoObj = new ConfigDAO(trans, cluster, "test"); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); + + + + } + + @Test + public void testRead() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("ConfigDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("ConfigDAO READ", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo READ on ConfigDAO", Env.SUB); + Mockito.doReturn(tt).when(trans).start(Mockito.anyString(),Mockito.anyInt()); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); + Mockito.doReturn(Mockito.mock(Decryptor.class)).when(trans).decryptor(); + Mockito.doNothing().when(tt).done(); + + Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new String[0]); + - PSInfo psObj = Mockito.mock(PSInfo.class); - ConfigDAOImpl daoObj = null; - try { - daoObj = new ConfigDAOImpl(trans, cluster, "test",psObj); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Mockito.doReturn(rs1).when(psObj).read(trans, "ConfigDAO READ", new Object[]{"test"}); - daoObj.readName(trans, "test"); - - - } + PSInfo psObj = Mockito.mock(PSInfo.class); + ConfigDAOImpl daoObj = null; + try { + daoObj = new ConfigDAOImpl(trans, cluster, "test",psObj); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Mockito.doReturn(rs1).when(psObj).read(trans, "ConfigDAO READ", new Object[]{"test"}); + daoObj.readName(trans, "test"); + + + } - - - @Test - public void testSecondConstructor() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("ConfigDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on ConfigDAO", Env.SUB); - Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); - Mockito.doNothing().when(tt).done(); - AbsCassDAO absDAO = Mockito.mock(AbsCassDAO.class); + + + @Test + public void testSecondConstructor() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("ConfigDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on ConfigDAO", Env.SUB); + Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE); + Mockito.doNothing().when(tt).done(); + AbsCassDAO absDAO = Mockito.mock(AbsCassDAO.class); - try { - ConfigDAO daoObj = new ConfigDAO(trans, absDAO); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + try { + ConfigDAO daoObj = new ConfigDAO(trans, absDAO); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } class ConfigDAOImpl extends ConfigDAO{ - - public ConfigDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,PSInfo readPS ) throws APIException, IOException { - super(trans, cluster, keyspace); - setPs(this, readPS, "psName"); - } - + + public ConfigDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,PSInfo readPS ) throws APIException, IOException { + super(trans, cluster, keyspace); + setPs(this, readPS, "psName"); + } + - public void setPs(ConfigDAOImpl ConfigDAOObj, PSInfo psInfoObj, String methodName) { - Field nsDaoField; - try { - nsDaoField = ConfigDAO.class.getDeclaredField(methodName); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(ConfigDAOObj, psInfoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + public void setPs(ConfigDAOImpl ConfigDAOObj, PSInfo psInfoObj, String methodName) { + Field nsDaoField; + try { + nsDaoField = ConfigDAO.class.getDeclaredField(methodName); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(ConfigDAOObj, psInfoObj); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } - - public void setSession(ConfigDAOImpl ConfigDAOObj, Session session) { - Field nsDaoField; - try { - nsDaoField = AbsCassDAO.class.getDeclaredField("session"); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - nsDaoField.set(ConfigDAOObj, session); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - + + public void setSession(ConfigDAOImpl ConfigDAOObj, Session session) { + Field nsDaoField; + try { + nsDaoField = AbsCassDAO.class.getDeclaredField("session"); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + nsDaoField.set(ConfigDAOObj, session); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_DelegateDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_DelegateDAO.java index 88d71a99..39d7492a 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_DelegateDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_DelegateDAO.java @@ -47,142 +47,142 @@ import com.datastax.driver.core.Row; public class JU_DelegateDAO { - @Mock + @Mock AuthzTrans trans; - @Mock - Cluster cluster; - - @Before - public void setUp() throws APIException, IOException { - initMocks(this); - } + @Mock + Cluster cluster; + + @Before + public void setUp() throws APIException, IOException { + initMocks(this); + } - @Test - public void testInit() { - DelegateDAO daoObj = new DelegateDAO(trans, cluster, "test"); -// daoObj. - } - @Test - public void testReadByDelegate() { - DelegateDAO daoObj = new DelegateDAO(trans, cluster, "test"); - - PSInfo psObj = Mockito.mock(PSInfo.class); - setPsDelegate(daoObj, psObj, "psByDelegate"); - - Result<List<DelegateDAO.Data>> rs1 = new Result<List<DelegateDAO.Data>>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(psObj).read(trans, "DelegateDAO READ", new Object[]{"test"}); - - daoObj.readByDelegate(trans, "test"); - } - - public void setPsDelegate(DelegateDAO delegateDAOObj, PSInfo psInfoObj, String fieldName) { - Field nsDaoField; - try { - nsDaoField = DelegateDAO.class.getDeclaredField(fieldName); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(delegateDAOObj, psInfoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testSecondConstructor() { - AbsCassDAO absDAO = Mockito.mock(AbsCassDAO.class); + @Test + public void testInit() { + DelegateDAO daoObj = new DelegateDAO(trans, cluster, "test"); +// daoObj. + } + @Test + public void testReadByDelegate() { + DelegateDAO daoObj = new DelegateDAO(trans, cluster, "test"); + + PSInfo psObj = Mockito.mock(PSInfo.class); + setPsDelegate(daoObj, psObj, "psByDelegate"); + + Result<List<DelegateDAO.Data>> rs1 = new Result<List<DelegateDAO.Data>>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(psObj).read(trans, "DelegateDAO READ", new Object[]{"test"}); + + daoObj.readByDelegate(trans, "test"); + } + + public void setPsDelegate(DelegateDAO delegateDAOObj, PSInfo psInfoObj, String fieldName) { + Field nsDaoField; + try { + nsDaoField = DelegateDAO.class.getDeclaredField(fieldName); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(delegateDAOObj, psInfoObj); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testSecondConstructor() { + AbsCassDAO absDAO = Mockito.mock(AbsCassDAO.class); - DelegateDAO daoObj = new DelegateDAO(trans, absDAO); - - } + DelegateDAO daoObj = new DelegateDAO(trans, absDAO); + + } - @Test - public void testDelegateLoader(){ - Class<?> innerClass = null; - Class<?>[] innerClassArr = DelegateDAO.class.getDeclaredClasses(); - for(Class indCls:innerClassArr) { - if(indCls.getName().contains("DelegateLoader")) { - innerClass = indCls; - break; - } - } - + @Test + public void testDelegateLoader(){ + Class<?> innerClass = null; + Class<?>[] innerClassArr = DelegateDAO.class.getDeclaredClasses(); + for(Class indCls:innerClassArr) { + if(indCls.getName().contains("DelegateLoader")) { + innerClass = indCls; + break; + } + } + Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); try { - Object obj = constructor.newInstance(1); - Method innnerClassMtd; - - DelegateDAO.Data data = new DelegateDAO.Data(); - Row row = Mockito.mock(Row.class); - ByteBuffer bbObj = ByteBuffer.allocateDirect(10); - bbObj.limit(7); - bbObj.put(0, new Byte("0")); - bbObj.put(1, new Byte("1")); - bbObj.put(2, new Byte("2")); - Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); - - innnerClassMtd = innerClass.getMethod("load", new Class[] {DelegateDAO.Data.class, Row.class}); - innnerClassMtd.invoke(obj, new Object[] {data, row}); - - innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {DelegateDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); -// - innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {DelegateDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); - -// DataOutputStream dos = new DataOutputStream(new FileOutputStream("JU_DelegateDAOTest.java")); -// innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {DelegateDAO.Data.class, DataOutputStream.class }); -// innnerClassMtd.invoke(obj, new Object[] {data, dos }); + Object obj = constructor.newInstance(1); + Method innnerClassMtd; + + DelegateDAO.Data data = new DelegateDAO.Data(); + Row row = Mockito.mock(Row.class); + ByteBuffer bbObj = ByteBuffer.allocateDirect(10); + bbObj.limit(7); + bbObj.put(0, new Byte("0")); + bbObj.put(1, new Byte("1")); + bbObj.put(2, new Byte("2")); + Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); + + innnerClassMtd = innerClass.getMethod("load", new Class[] {DelegateDAO.Data.class, Row.class}); + innnerClassMtd.invoke(obj, new Object[] {data, row}); + + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {DelegateDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); +// + innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {DelegateDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); + +// DataOutputStream dos = new DataOutputStream(new FileOutputStream("JU_DelegateDAOTest.java")); +// innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {DelegateDAO.Data.class, DataOutputStream.class }); +// innnerClassMtd.invoke(obj, new Object[] {data, dos }); -// DataInputStream dis = new DataInputStream(new FileInputStream("JU_DelegateDAOTest.java")); -// innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {DelegateDAO.Data.class, DataInputStream.class }); -// innnerClassMtd.invoke(obj, new Object[] {data, dis }); - - } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testData(){ - DelegateDAO.Data data = new DelegateDAO.Data(); - data.user="user"; - data.delegate="delegate"; - data.expires = new Date(); - try { - data.bytify(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - +// DataInputStream dis = new DataInputStream(new FileInputStream("JU_DelegateDAOTest.java")); +// innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {DelegateDAO.Data.class, DataInputStream.class }); +// innnerClassMtd.invoke(obj, new Object[] {data, dis }); + + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testData(){ + DelegateDAO.Data data = new DelegateDAO.Data(); + data.user="user"; + data.delegate="delegate"; + data.expires = new Date(); + try { + data.bytify(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_FutureDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_FutureDAO.java index 68764a60..07946156 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_FutureDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_FutureDAO.java @@ -54,240 +54,240 @@ import com.datastax.driver.core.Row; public class JU_FutureDAO { - @Mock + @Mock AuthzTrans trans; - @Mock - Cluster cluster; - - @Before - public void setUp() throws APIException, IOException { - initMocks(this); - } + @Mock + Cluster cluster; + + @Before + public void setUp() throws APIException, IOException { + initMocks(this); + } - @Test - public void testInit() { - FutureDAO daoObj = new FutureDAO(trans, cluster, "test"); -// daoObj. - } - @Test - public void testReadByStartAndTarget() { - FutureDAO daoObj = new FutureDAO(trans, cluster, "test"); - - PSInfo psObj = Mockito.mock(PSInfo.class); - setPsByStartAndTarget(daoObj, psObj, "psByStartAndTarget"); - - Result<List<FutureDAO.Data>> rs1 = new Result<List<FutureDAO.Data>>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(psObj).read(trans, "FutureDAO READ", new Object[]{"test"}); - - daoObj.readByStartAndTarget(trans,new Date(), "test"); - } - @Test - public void testCreate() { - PSInfo psObj = Mockito.mock(PSInfo.class); + @Test + public void testInit() { + FutureDAO daoObj = new FutureDAO(trans, cluster, "test"); +// daoObj. + } + @Test + public void testReadByStartAndTarget() { + FutureDAO daoObj = new FutureDAO(trans, cluster, "test"); + + PSInfo psObj = Mockito.mock(PSInfo.class); + setPsByStartAndTarget(daoObj, psObj, "psByStartAndTarget"); + + Result<List<FutureDAO.Data>> rs1 = new Result<List<FutureDAO.Data>>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(psObj).read(trans, "FutureDAO READ", new Object[]{"test"}); + + daoObj.readByStartAndTarget(trans,new Date(), "test"); + } + @Test + public void testCreate() { + PSInfo psObj = Mockito.mock(PSInfo.class); - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - FutureDAO.Data data = new FutureDAO.Data(); + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + FutureDAO.Data data = new FutureDAO.Data(); - Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(psObj).exec(trans, "FutureDAOImpl CREATE", data); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - - FutureDAOImpl daoObj=null; - try { - daoObj = new FutureDAOImpl(trans, historyDAO, psObj); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Mockito.doReturn("test user").when(trans).user(); - - Result<FutureDAO.Data> retVal = daoObj.create(trans,data, "test"); - assertTrue(retVal.status == 0); - - StringBuilder sb = new StringBuilder(trans.user()); + Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(psObj).exec(trans, "FutureDAOImpl CREATE", data); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + + FutureDAOImpl daoObj=null; + try { + daoObj = new FutureDAOImpl(trans, historyDAO, psObj); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Mockito.doReturn("test user").when(trans).user(); + + Result<FutureDAO.Data> retVal = daoObj.create(trans,data, "test"); + assertTrue(retVal.status == 0); + + StringBuilder sb = new StringBuilder(trans.user()); sb.append(data.target); sb.append(System.currentTimeMillis()); - data.id = UUID.nameUUIDFromBytes(sb.toString().getBytes()); - - rs1 = new Result<ResultSet>(null,1,"test",new String[0]); - Mockito.doReturn(rs1).when(psObj).exec(trans, "FutureDAOImpl CREATE", data); - - retVal = daoObj.create(trans,data, "test"); - assertTrue(retVal.status != 0); - - - } - - public void setPsByStartAndTarget(FutureDAO FutureDAOObj, PSInfo psInfoObj, String fieldName) { - Field nsDaoField; - try { - nsDaoField = FutureDAO.class.getDeclaredField(fieldName); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(FutureDAOObj, psInfoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testWasMOdified() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("FutureDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on FutureDAO", Env.SUB); - Mockito.doReturn(tt).when(trans).start("DELETE Future",Env.REMOTE); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doNothing().when(tt).done(); - FutureDAO.Data data = new FutureDAO.Data(); - PSInfo createPS = Mockito.mock(PSInfo.class); - - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - - FutureDAOImpl daoObj = null; - try { - daoObj = new FutureDAOImpl(trans, historyDAO, createPS ); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - - daoObj.wasModified(trans, CRUD.create, data, new String[] {}); - daoObj.wasModified(trans, CRUD.create, data, new String[] {null}); - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test",null}); - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); - - rs1 = new Result<ResultSet>(null,1,"test",new String[0]); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); - } - - @Test - public void testSecondConstructor() { - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + data.id = UUID.nameUUIDFromBytes(sb.toString().getBytes()); + + rs1 = new Result<ResultSet>(null,1,"test",new String[0]); + Mockito.doReturn(rs1).when(psObj).exec(trans, "FutureDAOImpl CREATE", data); + + retVal = daoObj.create(trans,data, "test"); + assertTrue(retVal.status != 0); + + + } + + public void setPsByStartAndTarget(FutureDAO FutureDAOObj, PSInfo psInfoObj, String fieldName) { + Field nsDaoField; + try { + nsDaoField = FutureDAO.class.getDeclaredField(fieldName); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(FutureDAOObj, psInfoObj); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testWasMOdified() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("FutureDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on FutureDAO", Env.SUB); + Mockito.doReturn(tt).when(trans).start("DELETE Future",Env.REMOTE); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); + Mockito.doNothing().when(tt).done(); + FutureDAO.Data data = new FutureDAO.Data(); + PSInfo createPS = Mockito.mock(PSInfo.class); + + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + + FutureDAOImpl daoObj = null; + try { + daoObj = new FutureDAOImpl(trans, historyDAO, createPS ); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); + + daoObj.wasModified(trans, CRUD.create, data, new String[] {}); + daoObj.wasModified(trans, CRUD.create, data, new String[] {null}); + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test",null}); + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); + + rs1 = new Result<ResultSet>(null,1,"test",new String[0]); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); + } + + @Test + public void testSecondConstructor() { + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - FutureDAO daoObj = new FutureDAO(trans, historyDAO); - - } + FutureDAO daoObj = new FutureDAO(trans, historyDAO); + + } - @Test - public void testFutureLoader(){ - Class<?> innerClass = null; - Class<?>[] innerClassArr = FutureDAO.class.getDeclaredClasses(); - for(Class indCls:innerClassArr) { - if(indCls.getName().contains("FLoader")) { - innerClass = indCls; - break; - } - } - + @Test + public void testFutureLoader(){ + Class<?> innerClass = null; + Class<?>[] innerClassArr = FutureDAO.class.getDeclaredClasses(); + for(Class indCls:innerClassArr) { + if(indCls.getName().contains("FLoader")) { + innerClass = indCls; + break; + } + } + Constructor<?> constructor = innerClass.getDeclaredConstructors()[1]; constructor.setAccessible(true); Constructor<?> constructor1 = innerClass.getDeclaredConstructors()[0]; constructor1.setAccessible(true); try { - - Object obj = constructor.newInstance(1); - obj = constructor1.newInstance(); - Method innnerClassMtd; - - FutureDAO.Data data = new FutureDAO.Data(); - Row row = Mockito.mock(Row.class); - ByteBuffer bbObj = ByteBuffer.allocateDirect(10); - bbObj.limit(7); - bbObj.put(0, new Byte("0")); - bbObj.put(1, new Byte("1")); - bbObj.put(2, new Byte("2")); - Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); - - innnerClassMtd = innerClass.getMethod("load", new Class[] {FutureDAO.Data.class, Row.class}); - innnerClassMtd.invoke(obj, new Object[] {data, row}); - - innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {FutureDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); -// - innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {FutureDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); - -// DataOutputStream dos = new DataOutputStream(new FileOutputStream("JU_FutureDAOTest.java")); -// innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {FutureDAO.Data.class, DataOutputStream.class }); -// innnerClassMtd.invoke(obj, new Object[] {data, dos }); + + Object obj = constructor.newInstance(1); + obj = constructor1.newInstance(); + Method innnerClassMtd; + + FutureDAO.Data data = new FutureDAO.Data(); + Row row = Mockito.mock(Row.class); + ByteBuffer bbObj = ByteBuffer.allocateDirect(10); + bbObj.limit(7); + bbObj.put(0, new Byte("0")); + bbObj.put(1, new Byte("1")); + bbObj.put(2, new Byte("2")); + Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); + + innnerClassMtd = innerClass.getMethod("load", new Class[] {FutureDAO.Data.class, Row.class}); + innnerClassMtd.invoke(obj, new Object[] {data, row}); + + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {FutureDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); +// + innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {FutureDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); + +// DataOutputStream dos = new DataOutputStream(new FileOutputStream("JU_FutureDAOTest.java")); +// innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {FutureDAO.Data.class, DataOutputStream.class }); +// innnerClassMtd.invoke(obj, new Object[] {data, dos }); -// DataInputStream dis = new DataInputStream(new FileInputStream("JU_FutureDAOTest.java")); -// innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {FutureDAO.Data.class, DataInputStream.class }); -// innnerClassMtd.invoke(obj, new Object[] {data, dis }); - - } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - +// DataInputStream dis = new DataInputStream(new FileInputStream("JU_FutureDAOTest.java")); +// innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {FutureDAO.Data.class, DataInputStream.class }); +// innnerClassMtd.invoke(obj, new Object[] {data, dis }); + + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } class FutureDAOImpl extends FutureDAO{ - - public FutureDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,PSInfo readPS ) throws APIException, IOException { - super(trans, historyDAO); - setPs(this, readPS, "createPS"); - } - + + public FutureDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,PSInfo readPS ) throws APIException, IOException { + super(trans, historyDAO); + setPs(this, readPS, "createPS"); + } + - public void setPs(FutureDAOImpl FutureDAOObj, PSInfo psInfoObj, String methodName) { - Field nsDaoField; - try { - nsDaoField = CassDAOImpl.class.getDeclaredField(methodName); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(FutureDAOObj, psInfoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - + public void setPs(FutureDAOImpl FutureDAOObj, PSInfo psInfoObj, String methodName) { + Field nsDaoField; + try { + nsDaoField = CassDAOImpl.class.getDeclaredField(methodName); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(FutureDAOObj, psInfoObj); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_HistoryDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_HistoryDAO.java index 78eb92e8..f6d0a65b 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_HistoryDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_HistoryDAO.java @@ -57,275 +57,275 @@ import com.datastax.driver.core.Row; public class JU_HistoryDAO { - @Mock + @Mock AuthzTrans trans; - @Mock - Cluster cluster; - - @Before - public void setUp() throws APIException, IOException { - initMocks(this); - } + @Mock + Cluster cluster; + + @Before + public void setUp() throws APIException, IOException { + initMocks(this); + } - @Test - public void testInit() { - HistoryDAO daoObj = new HistoryDAO(trans, cluster, "test"); - } - @Test - public void testNewInitedData() { - HistoryDAO daoObj = new HistoryDAO(trans, cluster, "test"); - HistoryDAO.Data data = daoObj.newInitedData(); - assertTrue( Integer.toString(((new Date()).getYear())+1900).equalsIgnoreCase(Integer.toString(data.yr_mon).substring(0,4)) ); - } - - @Test - public void testCreateBatch() { - HistoryDAO daoObj = new HistoryDAO(trans, cluster, "test"); - StringBuilder sb = new StringBuilder(); - HistoryDAO.Data data = new HistoryDAO.Data(); - daoObj.createBatch(sb, data); - assertTrue(sb.toString().contains("INSERT INTO history")); - } - - @Test - public void testReadByYYYYMM() { - HistoryDAO daoObj = new HistoryDAO(trans, cluster, "test"); - AbsCassDAO<AuthzTrans, Data>.PSInfo psInfoObj = Mockito.mock(PSInfo.class); - setAbsCassDAO(daoObj, psInfoObj, "readByYRMN"); - - ResultSet rs = Mockito.mock(ResultSet.class); - Result<ResultSet> rs1 = new Result<ResultSet>(rs,0,"test",new String[0]); - Mockito.doReturn(rs1).when(psInfoObj).exec(trans, "yr_mon", 201905); - - Result<List<Data>> retVal = daoObj.readByYYYYMM(trans, 201905); - assertTrue(retVal.status !=1); - - rs1 = new Result<ResultSet>(rs,1,"test",new String[0]); - Mockito.doReturn(rs1).when(psInfoObj).exec(trans, "yr_mon", 201905); - retVal = daoObj.readByYYYYMM(trans, 201905); - assertTrue(retVal.status !=0); - } - - @Test - public void testReadByUser() { - HistoryDAO daoObj = new HistoryDAO(trans, cluster, "test"); - AbsCassDAO<AuthzTrans, Data>.PSInfo psInfoObj = Mockito.mock(PSInfo.class); - setAbsCassDAO(daoObj, psInfoObj, "readByUser"); - - ResultSet rs = Mockito.mock(ResultSet.class); - Result<ResultSet> rs1 = new Result<ResultSet>(rs,0,"test",new String[0]); - Mockito.doReturn(rs1).when(psInfoObj).exec(trans, "user", "test"); - - Result<List<Data>> retVal = daoObj.readByUser(trans, "test", 201905); - assertTrue(retVal.status !=1); - - rs1 = new Result<ResultSet>(rs,1,"test",new String[0]); - Mockito.doReturn(rs1).when(psInfoObj).exec(trans, "user", "test"); - retVal = daoObj.readByUser(trans,"test", 201905); - assertTrue(retVal.status !=0); - - retVal = daoObj.readByUser(trans,"test"); - assertTrue(retVal.status !=0); - } - - @Test - public void testReadBySubject() { - HistoryDAO daoObj = new HistoryDAO(trans, cluster, "test"); - AbsCassDAO<AuthzTrans, Data>.PSInfo psInfoObj = Mockito.mock(PSInfo.class); - setAbsCassDAO(daoObj, psInfoObj, "readBySubject"); - - ResultSet rs = Mockito.mock(ResultSet.class); - Result<ResultSet> rs1 = new Result<ResultSet>(rs,0,"test",new String[0]); - Mockito.doReturn(rs1).when(psInfoObj).exec(trans, "subject", "test", "test"); - - Result<List<Data>> retVal = daoObj.readBySubject(trans, "test", "test", 201905); - assertTrue(retVal.status !=1); - - rs1 = new Result<ResultSet>(rs,1,"test",new String[0]); - Mockito.doReturn(rs1).when(psInfoObj).exec(trans, "subject", "test", "test"); - retVal = daoObj.readBySubject(trans,"test", "test", 201905); - assertTrue(retVal.status !=0); - - retVal = daoObj.readBySubject(trans,"test", "test"); - assertTrue(retVal.status !=0); - } - - public void setAbsCassDAO(HistoryDAO HistoryDAOObj, PSInfo psInfoObj, String fieldName) { - Field nsDaoField; - try { - nsDaoField = HistoryDAO.class.getDeclaredField(fieldName); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(HistoryDAOObj, psInfoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - - @Test - public void testSecondConstructor() { - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + @Test + public void testInit() { + HistoryDAO daoObj = new HistoryDAO(trans, cluster, "test"); + } + @Test + public void testNewInitedData() { + HistoryDAO daoObj = new HistoryDAO(trans, cluster, "test"); + HistoryDAO.Data data = daoObj.newInitedData(); + assertTrue( Integer.toString(((new Date()).getYear())+1900).equalsIgnoreCase(Integer.toString(data.yr_mon).substring(0,4)) ); + } + + @Test + public void testCreateBatch() { + HistoryDAO daoObj = new HistoryDAO(trans, cluster, "test"); + StringBuilder sb = new StringBuilder(); + HistoryDAO.Data data = new HistoryDAO.Data(); + daoObj.createBatch(sb, data); + assertTrue(sb.toString().contains("INSERT INTO history")); + } + + @Test + public void testReadByYYYYMM() { + HistoryDAO daoObj = new HistoryDAO(trans, cluster, "test"); + AbsCassDAO<AuthzTrans, Data>.PSInfo psInfoObj = Mockito.mock(PSInfo.class); + setAbsCassDAO(daoObj, psInfoObj, "readByYRMN"); + + ResultSet rs = Mockito.mock(ResultSet.class); + Result<ResultSet> rs1 = new Result<ResultSet>(rs,0,"test",new String[0]); + Mockito.doReturn(rs1).when(psInfoObj).exec(trans, "yr_mon", 201905); + + Result<List<Data>> retVal = daoObj.readByYYYYMM(trans, 201905); + assertTrue(retVal.status !=1); + + rs1 = new Result<ResultSet>(rs,1,"test",new String[0]); + Mockito.doReturn(rs1).when(psInfoObj).exec(trans, "yr_mon", 201905); + retVal = daoObj.readByYYYYMM(trans, 201905); + assertTrue(retVal.status !=0); + } + + @Test + public void testReadByUser() { + HistoryDAO daoObj = new HistoryDAO(trans, cluster, "test"); + AbsCassDAO<AuthzTrans, Data>.PSInfo psInfoObj = Mockito.mock(PSInfo.class); + setAbsCassDAO(daoObj, psInfoObj, "readByUser"); + + ResultSet rs = Mockito.mock(ResultSet.class); + Result<ResultSet> rs1 = new Result<ResultSet>(rs,0,"test",new String[0]); + Mockito.doReturn(rs1).when(psInfoObj).exec(trans, "user", "test"); + + Result<List<Data>> retVal = daoObj.readByUser(trans, "test", 201905); + assertTrue(retVal.status !=1); + + rs1 = new Result<ResultSet>(rs,1,"test",new String[0]); + Mockito.doReturn(rs1).when(psInfoObj).exec(trans, "user", "test"); + retVal = daoObj.readByUser(trans,"test", 201905); + assertTrue(retVal.status !=0); + + retVal = daoObj.readByUser(trans,"test"); + assertTrue(retVal.status !=0); + } + + @Test + public void testReadBySubject() { + HistoryDAO daoObj = new HistoryDAO(trans, cluster, "test"); + AbsCassDAO<AuthzTrans, Data>.PSInfo psInfoObj = Mockito.mock(PSInfo.class); + setAbsCassDAO(daoObj, psInfoObj, "readBySubject"); + + ResultSet rs = Mockito.mock(ResultSet.class); + Result<ResultSet> rs1 = new Result<ResultSet>(rs,0,"test",new String[0]); + Mockito.doReturn(rs1).when(psInfoObj).exec(trans, "subject", "test", "test"); + + Result<List<Data>> retVal = daoObj.readBySubject(trans, "test", "test", 201905); + assertTrue(retVal.status !=1); + + rs1 = new Result<ResultSet>(rs,1,"test",new String[0]); + Mockito.doReturn(rs1).when(psInfoObj).exec(trans, "subject", "test", "test"); + retVal = daoObj.readBySubject(trans,"test", "test", 201905); + assertTrue(retVal.status !=0); + + retVal = daoObj.readBySubject(trans,"test", "test"); + assertTrue(retVal.status !=0); + } + + public void setAbsCassDAO(HistoryDAO HistoryDAOObj, PSInfo psInfoObj, String fieldName) { + Field nsDaoField; + try { + nsDaoField = HistoryDAO.class.getDeclaredField(fieldName); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(HistoryDAOObj, psInfoObj); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + + @Test + public void testSecondConstructor() { + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - HistoryDAO daoObj = new HistoryDAO(trans, historyDAO); - - } + HistoryDAO daoObj = new HistoryDAO(trans, historyDAO); + + } - @Test - public void testHistoryLoader(){ - Class<?> innerClass = null; - Class<?>[] innerClassArr = HistoryDAO.class.getDeclaredClasses(); - for(Class indCls:innerClassArr) { - if(indCls.getName().contains("HistLoader")) { - innerClass = indCls; - break; - } - } - + @Test + public void testHistoryLoader(){ + Class<?> innerClass = null; + Class<?>[] innerClassArr = HistoryDAO.class.getDeclaredClasses(); + for(Class indCls:innerClassArr) { + if(indCls.getName().contains("HistLoader")) { + innerClass = indCls; + break; + } + } + Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); try { - Object obj = constructor.newInstance(1); - Method innnerClassMtd; - - HistoryDAO.Data data = new HistoryDAO.Data(); - Row row = Mockito.mock(Row.class); - ByteBuffer bbObj = ByteBuffer.allocateDirect(10); - bbObj.limit(7); - bbObj.put(0, new Byte("0")); - bbObj.put(1, new Byte("1")); - bbObj.put(2, new Byte("2")); - Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); - - innnerClassMtd = innerClass.getMethod("load", new Class[] {HistoryDAO.Data.class, Row.class}); - innnerClassMtd.invoke(obj, new Object[] {data, row}); - - innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {HistoryDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); -// - innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {HistoryDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); - - } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testYYYYMM(){ - Class<?> innerClass = null; - Class<?>[] innerClassArr = HistoryDAO.class.getDeclaredClasses(); - for(Class indCls:innerClassArr) { - if(indCls.getName().contains("YYYYMM")) { - innerClass = indCls; - break; - } - } - + Object obj = constructor.newInstance(1); + Method innnerClassMtd; + + HistoryDAO.Data data = new HistoryDAO.Data(); + Row row = Mockito.mock(Row.class); + ByteBuffer bbObj = ByteBuffer.allocateDirect(10); + bbObj.limit(7); + bbObj.put(0, new Byte("0")); + bbObj.put(1, new Byte("1")); + bbObj.put(2, new Byte("2")); + Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); + + innnerClassMtd = innerClass.getMethod("load", new Class[] {HistoryDAO.Data.class, Row.class}); + innnerClassMtd.invoke(obj, new Object[] {data, row}); + + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {HistoryDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); +// + innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {HistoryDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); + + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testYYYYMM(){ + Class<?> innerClass = null; + Class<?>[] innerClassArr = HistoryDAO.class.getDeclaredClasses(); + for(Class indCls:innerClassArr) { + if(indCls.getName().contains("YYYYMM")) { + innerClass = indCls; + break; + } + } + Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); int yyyymm[] = new int[2]; try { - Object obj = constructor.newInstance(new HistoryDAO(trans, cluster, "test"), yyyymm); - Method innnerClassMtd; - - HistoryDAO.Data data = new HistoryDAO.Data(); - Row row = Mockito.mock(Row.class); - ByteBuffer bbObj = ByteBuffer.allocateDirect(10); - bbObj.limit(7); - bbObj.put(0, new Byte("0")); - bbObj.put(1, new Byte("1")); - bbObj.put(2, new Byte("2")); - Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); - - innnerClassMtd = innerClass.getMethod("ok", new Class[] {HistoryDAO.Data.class}); - innnerClassMtd.invoke(obj, new Object[] {data}); - - data.yr_mon=201904; - innnerClassMtd.invoke(obj, new Object[] {data}); - - } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - + Object obj = constructor.newInstance(new HistoryDAO(trans, cluster, "test"), yyyymm); + Method innnerClassMtd; + + HistoryDAO.Data data = new HistoryDAO.Data(); + Row row = Mockito.mock(Row.class); + ByteBuffer bbObj = ByteBuffer.allocateDirect(10); + bbObj.limit(7); + bbObj.put(0, new Byte("0")); + bbObj.put(1, new Byte("1")); + bbObj.put(2, new Byte("2")); + Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); + + innnerClassMtd = innerClass.getMethod("ok", new Class[] {HistoryDAO.Data.class}); + innnerClassMtd.invoke(obj, new Object[] {data}); + + data.yr_mon=201904; + innnerClassMtd.invoke(obj, new Object[] {data}); + + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } class HistoryDAOImpl extends HistoryDAO{ - - public HistoryDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,PSInfo readPS ) throws APIException, IOException { - super(trans, historyDAO); - setPs(this, readPS, "createPS"); - } - - public void setPs(HistoryDAOImpl HistoryDAOObj, PSInfo psInfoObj, String methodName) { - Field nsDaoField; - try { - nsDaoField = CassDAOImpl.class.getDeclaredField(methodName); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(HistoryDAOObj, psInfoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - + + public HistoryDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,PSInfo readPS ) throws APIException, IOException { + super(trans, historyDAO); + setPs(this, readPS, "createPS"); + } + + public void setPs(HistoryDAOImpl HistoryDAOObj, PSInfo psInfoObj, String methodName) { + Field nsDaoField; + try { + nsDaoField = CassDAOImpl.class.getDeclaredField(methodName); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(HistoryDAOObj, psInfoObj); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_LocateDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_LocateDAO.java index 3493b088..53bad44e 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_LocateDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_LocateDAO.java @@ -56,262 +56,262 @@ import com.datastax.driver.core.Row; public class JU_LocateDAO { - @Mock + @Mock AuthzTrans trans; - @Mock - Cluster cluster; - - @Before - public void setUp() throws APIException, IOException { - initMocks(this); - } + @Mock + Cluster cluster; + + @Before + public void setUp() throws APIException, IOException { + initMocks(this); + } - @Test - public void testInit() { - try { - LocateDAO daoObj = new LocateDAO(trans, cluster, "test"); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - @Test - public void testReadByStartAndTarget() { - LocateDAO daoObj = null; - try { - daoObj = new LocateDAO(trans, cluster, "test"); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - PSInfo psObj = Mockito.mock(PSInfo.class); - setPsByStartAndTarget(daoObj, psObj, "psName"); - - Result<List<LocateDAO.Data>> rs1 = new Result<List<LocateDAO.Data>>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(psObj).read(trans, "LocateDAO READ", new Object[]{"test"}); - - daoObj.readByName(trans, "test"); - } - - - public void setPsByStartAndTarget(LocateDAO LocateDAOObj, PSInfo psInfoObj, String fieldName) { - Field nsDaoField; - try { - nsDaoField = LocateDAO.class.getDeclaredField(fieldName); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(LocateDAOObj, psInfoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testWasMOdified() { - - LocateDAO.Data data = new LocateDAO.Data(); - - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - - LocateDAO daoObj = null; - try { - daoObj = new LocateDAO(trans, historyDAO ); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - - - } - - @Test - public void testSecondConstructor() { - AbsCassDAO historyDAO = Mockito.mock(AbsCassDAO.class); + @Test + public void testInit() { + try { + LocateDAO daoObj = new LocateDAO(trans, cluster, "test"); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + @Test + public void testReadByStartAndTarget() { + LocateDAO daoObj = null; + try { + daoObj = new LocateDAO(trans, cluster, "test"); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + PSInfo psObj = Mockito.mock(PSInfo.class); + setPsByStartAndTarget(daoObj, psObj, "psName"); + + Result<List<LocateDAO.Data>> rs1 = new Result<List<LocateDAO.Data>>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(psObj).read(trans, "LocateDAO READ", new Object[]{"test"}); + + daoObj.readByName(trans, "test"); + } + + + public void setPsByStartAndTarget(LocateDAO LocateDAOObj, PSInfo psInfoObj, String fieldName) { + Field nsDaoField; + try { + nsDaoField = LocateDAO.class.getDeclaredField(fieldName); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(LocateDAOObj, psInfoObj); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testWasMOdified() { + + LocateDAO.Data data = new LocateDAO.Data(); + + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + + LocateDAO daoObj = null; + try { + daoObj = new LocateDAO(trans, historyDAO ); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); + + + } + + @Test + public void testSecondConstructor() { + AbsCassDAO historyDAO = Mockito.mock(AbsCassDAO.class); - try { - LocateDAO daoObj = new LocateDAO(trans, historyDAO); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } + try { + LocateDAO daoObj = new LocateDAO(trans, historyDAO); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } - @Test - public void testLocateLoader(){ - Class<?> innerClass = null; - Class<?>[] innerClassArr = LocateDAO.class.getDeclaredClasses(); - for(Class indCls:innerClassArr) { - if(indCls.getName().contains("LocateLoader")) { - innerClass = indCls; - break; - } - } - + @Test + public void testLocateLoader(){ + Class<?> innerClass = null; + Class<?>[] innerClassArr = LocateDAO.class.getDeclaredClasses(); + for(Class indCls:innerClassArr) { + if(indCls.getName().contains("LocateLoader")) { + innerClass = indCls; + break; + } + } + Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); try { - - Object obj = constructor.newInstance(1); - Method innnerClassMtd; - - LocateDAO.Data data = new LocateDAO.Data(); - Row row = Mockito.mock(Row.class); - ByteBuffer bbObj = ByteBuffer.allocateDirect(10); - bbObj.limit(7); - bbObj.put(0, new Byte("0")); - bbObj.put(1, new Byte("1")); - bbObj.put(2, new Byte("2")); - Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); - - innnerClassMtd = innerClass.getMethod("load", new Class[] {LocateDAO.Data.class, Row.class}); - innnerClassMtd.invoke(obj, new Object[] {data, row}); - - innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {LocateDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 0, new Object[] {"test","test","test"} }); - - innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {LocateDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {LocateDAO.Data.class, DataOutputStream.class }); - innnerClassMtd.invoke(obj, new Object[] {data, dos }); + + Object obj = constructor.newInstance(1); + Method innnerClassMtd; + + LocateDAO.Data data = new LocateDAO.Data(); + Row row = Mockito.mock(Row.class); + ByteBuffer bbObj = ByteBuffer.allocateDirect(10); + bbObj.limit(7); + bbObj.put(0, new Byte("0")); + bbObj.put(1, new Byte("1")); + bbObj.put(2, new Byte("2")); + Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); + + innnerClassMtd = innerClass.getMethod("load", new Class[] {LocateDAO.Data.class, Row.class}); + innnerClassMtd.invoke(obj, new Object[] {data, row}); + + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {LocateDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 0, new Object[] {"test","test","test"} }); + + innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {LocateDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {LocateDAO.Data.class, DataOutputStream.class }); + innnerClassMtd.invoke(obj, new Object[] {data, dos }); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - DataInputStream dis = new DataInputStream(bais); - innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {LocateDAO.Data.class, DataInputStream.class }); - innnerClassMtd.invoke(obj, new Object[] {data, dis }); - - } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testData(){ - LocateDAO.Data data = new LocateDAO.Data(); - data.name="name"; - data.hostname="hostname"; - try { - data.bytify(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - data.subprotocol(true); - - Set<String> subProt = new HashSet<String>(); - Field protField; - try { - protField = LocateDAO.Data.class.getDeclaredField("subprotocol"); - - protField.setAccessible(true); - - protField.set(data, subProt); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - data.subprotocol(true); - subProt = new TreeSet<String>(); - subProt.add("test"); - try { - protField = LocateDAO.Data.class.getDeclaredField("subprotocol"); - - protField.setAccessible(true); - - protField.set(data, subProt); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - data.subprotocol(true); - data.subprotocol(false); - - LocateDAO.Data newDate = data.copy(); - assertTrue(data.name.equals(newDate.name)); - } - + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + DataInputStream dis = new DataInputStream(bais); + innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {LocateDAO.Data.class, DataInputStream.class }); + innnerClassMtd.invoke(obj, new Object[] {data, dis }); + + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testData(){ + LocateDAO.Data data = new LocateDAO.Data(); + data.name="name"; + data.hostname="hostname"; + try { + data.bytify(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + data.subprotocol(true); + + Set<String> subProt = new HashSet<String>(); + Field protField; + try { + protField = LocateDAO.Data.class.getDeclaredField("subprotocol"); + + protField.setAccessible(true); + + protField.set(data, subProt); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + data.subprotocol(true); + subProt = new TreeSet<String>(); + subProt.add("test"); + try { + protField = LocateDAO.Data.class.getDeclaredField("subprotocol"); + + protField.setAccessible(true); + + protField.set(data, subProt); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + data.subprotocol(true); + data.subprotocol(false); + + LocateDAO.Data newDate = data.copy(); + assertTrue(data.name.equals(newDate.name)); + } + } class LocateDAOImpl extends LocateDAO{ - - public LocateDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,PSInfo readPS ) throws APIException, IOException { - super(trans, historyDAO); - setPs(this, readPS, "createPS"); - } - + + public LocateDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,PSInfo readPS ) throws APIException, IOException { + super(trans, historyDAO); + setPs(this, readPS, "createPS"); + } + - public void setPs(LocateDAOImpl LocateDAOObj, PSInfo psInfoObj, String methodName) { - Field nsDaoField; - try { - nsDaoField = CassDAOImpl.class.getDeclaredField(methodName); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(LocateDAOObj, psInfoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - + public void setPs(LocateDAOImpl LocateDAOObj, PSInfo psInfoObj, String methodName) { + Field nsDaoField; + try { + nsDaoField = CassDAOImpl.class.getDeclaredField(methodName); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(LocateDAOObj, psInfoObj); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_Namespace.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_Namespace.java index 8de750c6..6bdb3d76 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_Namespace.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_Namespace.java @@ -37,69 +37,69 @@ import org.onap.aaf.misc.env.APIException; public class JU_Namespace { - Namespace namespace; - - @Before - public void setUp() throws APIException, IOException { - initMocks(this); - } + Namespace namespace; + + @Before + public void setUp() throws APIException, IOException { + initMocks(this); + } - @Test - public void testInit() { - new Namespace(); - NsDAO.Data data = new NsDAO.Data(); - data.name = "name"; - namespace = new Namespace(data); - assertTrue(namespace.name.equals("name")); - data.attrib = new HashMap<>(); - namespace = new Namespace(data); - data.attrib.put("test", "test"); - namespace = new Namespace(data); - } - - - - @Test - public void testSecondConstructor() { + @Test + public void testInit() { + new Namespace(); + NsDAO.Data data = new NsDAO.Data(); + data.name = "name"; + namespace = new Namespace(data); + assertTrue(namespace.name.equals("name")); + data.attrib = new HashMap<>(); + namespace = new Namespace(data); + data.attrib.put("test", "test"); + namespace = new Namespace(data); + } + + + + @Test + public void testSecondConstructor() { - NsDAO.Data data = new NsDAO.Data(); - data.name = "name"; - List<String> owner = new ArrayList<>(); - List<String> admin = new ArrayList<>();; - namespace = new Namespace(data,owner, admin); - assertTrue(namespace.name.equals("name")); - data.attrib = new HashMap<>(); - namespace = new Namespace(data,owner, admin); - data.attrib.put("test", "test"); - namespace = new Namespace(data ,owner, admin); - - NsDAO.Data retData = namespace.data(); - assertTrue(retData.name.equals("name")); - - } - @Test - public void testBytify() { - testSecondConstructor(); - try { - ByteBuffer retVal = namespace.bytify(); - namespace.reconstitute(retVal); - namespace.hashCode(); - namespace.toString(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - @Test - public void testEquals() { - testSecondConstructor(); - NsDAO.Data data = new NsDAO.Data(); - data.name = "name"; - Namespace nameObj = null; - assertFalse(namespace.equals(nameObj)); - assertFalse(namespace.equals(data)); - nameObj = new Namespace(data); - assertTrue(namespace.equals(nameObj)); - } - + NsDAO.Data data = new NsDAO.Data(); + data.name = "name"; + List<String> owner = new ArrayList<>(); + List<String> admin = new ArrayList<>();; + namespace = new Namespace(data,owner, admin); + assertTrue(namespace.name.equals("name")); + data.attrib = new HashMap<>(); + namespace = new Namespace(data,owner, admin); + data.attrib.put("test", "test"); + namespace = new Namespace(data ,owner, admin); + + NsDAO.Data retData = namespace.data(); + assertTrue(retData.name.equals("name")); + + } + @Test + public void testBytify() { + testSecondConstructor(); + try { + ByteBuffer retVal = namespace.bytify(); + namespace.reconstitute(retVal); + namespace.hashCode(); + namespace.toString(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + @Test + public void testEquals() { + testSecondConstructor(); + NsDAO.Data data = new NsDAO.Data(); + data.name = "name"; + Namespace nameObj = null; + assertFalse(namespace.equals(nameObj)); + assertFalse(namespace.equals(data)); + nameObj = new Namespace(data); + assertTrue(namespace.equals(nameObj)); + } + }
\ No newline at end of file diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_NsDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_NsDAO.java index d5af0a63..9be4f5a2 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_NsDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_NsDAO.java @@ -68,818 +68,818 @@ import com.datastax.driver.core.Session; public class JU_NsDAO { - @Mock + @Mock AuthzTrans trans; - @Mock - Cluster cluster; - @Mock - Session session; - @Mock - ResultSet rs; - - @Before - public void setUp() throws APIException, IOException { - initMocks(this); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).init(); - Mockito.doReturn(session).when(cluster).connect("test"); - Mockito.doReturn(Mockito.mock(TimeTaken.class)).when(trans).start(Mockito.anyString(), Mockito.anyInt()); - Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LATITUDE); - Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LONGITUDE); - - Iterator<Row> ite = Mockito.mock(Iterator.class); - Mockito.doReturn(ite).when(rs).iterator(); - Mockito.doReturn(rs).when(session).execute(Mockito.anyString()); - } - - @Test - public void testInit() { - try { - Session session = Mockito.mock(Session.class); - new NsDAOImpl(trans, cluster, "test", session); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public void setPsByStartAndTarget(NsDAO NsDAOObj, PSInfo psInfoObj, String fieldName) { - Field nsDaoField; - try { - nsDaoField = NsDAO.class.getDeclaredField(fieldName); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(NsDAOObj, psInfoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testWasMOdified() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("NsDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on NsDAO", Env.SUB); - Mockito.doReturn(tt).when(trans).start("DELETE Future",Env.REMOTE); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doNothing().when(tt).done(); - NsDAO.Data data = new NsDAO.Data(); - - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new Object[0]); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); - - NsDAO daoObj = null; - try { - daoObj = new NsDAO(trans, historyDAO, cacheInfoDAO); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - - daoObj.wasModified(trans, CRUD.create, data, new String[] {}); - daoObj.wasModified(trans, CRUD.create, data, new String[] {null}); - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test",null}); - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); - - rs1 = new Result<ResultSet>(null,1,"test",new Object[0]); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); - } - - @Test - public void testSecondConstructor() { - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - - try { - new NsDAO(trans, historyDAO, cacheInfoDAO); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - - @Test - public void testNSLoader(){ - Class<?> innerClass = null; - Class<?>[] innerClassArr = NsDAO.class.getDeclaredClasses(); - for(Class<?> indCls:innerClassArr) { - if(indCls.getName().contains("NSLoader")) { - innerClass = indCls; - break; - } - } - + @Mock + Cluster cluster; + @Mock + Session session; + @Mock + ResultSet rs; + + @Before + public void setUp() throws APIException, IOException { + initMocks(this); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).init(); + Mockito.doReturn(session).when(cluster).connect("test"); + Mockito.doReturn(Mockito.mock(TimeTaken.class)).when(trans).start(Mockito.anyString(), Mockito.anyInt()); + Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LATITUDE); + Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LONGITUDE); + + Iterator<Row> ite = Mockito.mock(Iterator.class); + Mockito.doReturn(ite).when(rs).iterator(); + Mockito.doReturn(rs).when(session).execute(Mockito.anyString()); + } + + @Test + public void testInit() { + try { + Session session = Mockito.mock(Session.class); + new NsDAOImpl(trans, cluster, "test", session); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public void setPsByStartAndTarget(NsDAO NsDAOObj, PSInfo psInfoObj, String fieldName) { + Field nsDaoField; + try { + nsDaoField = NsDAO.class.getDeclaredField(fieldName); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(NsDAOObj, psInfoObj); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testWasMOdified() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("NsDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on NsDAO", Env.SUB); + Mockito.doReturn(tt).when(trans).start("DELETE Future",Env.REMOTE); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); + Mockito.doNothing().when(tt).done(); + NsDAO.Data data = new NsDAO.Data(); + + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new Object[0]); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); + + NsDAO daoObj = null; + try { + daoObj = new NsDAO(trans, historyDAO, cacheInfoDAO); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); + + daoObj.wasModified(trans, CRUD.create, data, new String[] {}); + daoObj.wasModified(trans, CRUD.create, data, new String[] {null}); + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test",null}); + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); + + rs1 = new Result<ResultSet>(null,1,"test",new Object[0]); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); + } + + @Test + public void testSecondConstructor() { + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + + try { + new NsDAO(trans, historyDAO, cacheInfoDAO); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + @Test + public void testNSLoader(){ + Class<?> innerClass = null; + Class<?>[] innerClassArr = NsDAO.class.getDeclaredClasses(); + for(Class<?> indCls:innerClassArr) { + if(indCls.getName().contains("NSLoader")) { + innerClass = indCls; + break; + } + } + Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); try { - - Object obj = constructor.newInstance(1); - Method innnerClassMtd; - - NsDAO.Data data = new NsDAO.Data(); - Row row = Mockito.mock(Row.class); - ByteBuffer bbObj = ByteBuffer.allocateDirect(10); - bbObj.limit(7); - bbObj.put(0, new Byte("0")); - bbObj.put(1, new Byte("1")); - bbObj.put(2, new Byte("2")); - Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); - - innnerClassMtd = innerClass.getMethod("load", new Class[] {NsDAO.Data.class, Row.class}); - innnerClassMtd.invoke(obj, new Object[] {data, row}); - - innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {NsDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); -// - innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {NsDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {NsDAO.Data.class, DataOutputStream.class }); - innnerClassMtd.invoke(obj, new Object[] {data, dos }); - - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - DataInputStream dis = new DataInputStream(bais); - innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {NsDAO.Data.class, DataInputStream.class }); - innnerClassMtd.invoke(obj, new Object[] {data, dis }); - - } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - @Test - public void testCreate() { - PSInfo psObj = Mockito.mock(PSInfo.class); - - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - NsDAO.Data data = new NsDAO.Data(); - - Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new Object[0]); - Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl CREATE", data); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - NsDAOImpl daoObj=null; - try { - daoObj = new NsDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, session); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Mockito.doReturn("test user").when(trans).user(); - - Result<NsDAO.Data> retVal = daoObj.create(trans,data); - assertTrue(retVal.status == 4); - - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); - data.parent = "parent"; - data.attrib = new HashMap<>(); - data.attrib.put("test", "test"); - - Field cbField; - Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); - try { - cbField = CassAccess.class.getDeclaredField("cb"); - cbField.setAccessible(true); - cbField.set(daoObj, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - retVal = daoObj.create(trans,data); - assertTrue(retVal.status == 9); - - Field owningField; - Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); - try { - owningField = AbsCassDAO.class.getDeclaredField("owningDAO"); - owningField.setAccessible(true); - owningField.set(daoObj, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - retVal = daoObj.create(trans,data); - assertTrue(retVal.status == 0); - - } - - @Test - public void testUpdate() { - PSInfo psObj = Mockito.mock(PSInfo.class); - - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - NsDAO.Data data = new NsDAO.Data(); - - Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new Object[0]); - Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl CREATE", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl UPDATE", data); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - NsDAOImpl daoObj=null; - try { - daoObj = new NsDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, session); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Mockito.doReturn("test user").when(trans).user(); - - Result<Void> retVal = daoObj.update(trans,data); - assertTrue(retVal.status == 4); - - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); - data.parent = "parent"; - data.attrib = new HashMap<>(); - data.attrib.put("test", "test"); - Field cbField; - Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); - try { - cbField = AbsCassDAO.class.getDeclaredField("owningDAO"); - cbField.setAccessible(true); - cbField.set(daoObj, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - retVal = daoObj.update(trans,data); - assertTrue(retVal.status == 0); - - ResultSet rsMock = Mockito.mock(ResultSet.class); - Iterator<Row> iteMock = Mockito.mock(Iterator.class); - Mockito.doReturn(iteMock).when(rsMock).iterator(); - Row rowMock = Mockito.mock(Row.class); - Mockito.doReturn(rowMock).when(iteMock).next(); - Mockito.when(iteMock.hasNext()).thenReturn(true, false); - Mockito.doReturn("test").when(rowMock).getString(Mockito.anyInt()); - Mockito.doReturn(rsMock).when(session).execute(Mockito.anyString()); - retVal = daoObj.update(trans,data); - assertTrue(retVal.status == 0); - } - - @Test - public void testRead() { - PSInfo psObj = Mockito.mock(PSInfo.class); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); - - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - NsDAO.Data data = new NsDAO.Data(); - - Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new Object[0]); - Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl CREATE", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl UPDATE", data); - Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", data); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - NsDAOImpl daoObj=null; - try { - daoObj = new NsDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, session); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Mockito.doReturn("test user").when(trans).user(); - - Result<List<Data>> retVal = daoObj.read(trans,data); - assertTrue(retVal.status == 0); - - List<Data> dataAL= new ArrayList<>(); - dataAL.add(data); - rs1 = new Result<List<Data>>(dataAL,0,"test",new Object[0]); - Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", data); - Field cbField; - Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); - try { - cbField = AbsCassDAO.class.getDeclaredField("owningDAO"); - cbField.setAccessible(true); - cbField.set(daoObj, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - retVal = daoObj.read(trans,data); - assertTrue(retVal.status == 0); - - } - - @Test - public void testReadByObject() { - PSInfo psObj = Mockito.mock(PSInfo.class); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); - - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - NsDAO.Data data = new NsDAO.Data(); - - Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new Object[0]); - Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl CREATE", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl UPDATE", data); - Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", new Object[] {}); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - NsDAOImpl daoObj=null; - try { - daoObj = new NsDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, session); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Mockito.doReturn("test user").when(trans).user(); - - Result<List<Data>> retVal = daoObj.read(trans,new Object[] {}); - assertTrue(retVal.status == 0); - - List<Data> dataAL= new ArrayList<>(); - dataAL.add(data); - rs1 = new Result<List<Data>>(dataAL,0,"test",new Object[0]); - Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", new Object[] {}); - Field cbField; - Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); - try { - cbField = AbsCassDAO.class.getDeclaredField("owningDAO"); - cbField.setAccessible(true); - cbField.set(daoObj, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - retVal = daoObj.read(trans,new Object[] {}); - assertTrue(retVal.status == 0); - - } - - @Test - public void testDelete() { - PSInfo psObj = Mockito.mock(PSInfo.class); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); - - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - NsDAO.Data data = new NsDAO.Data(); - - Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new Object[0]); - Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl CREATE", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl UPDATE", data); - Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl DELETE", data); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - NsDAOImpl daoObj=null; - try { - daoObj = new NsDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, session); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Mockito.doReturn("test user").when(trans).user(); - Field cbField; - Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); - try { - cbField = AbsCassDAO.class.getDeclaredField("owningDAO"); - cbField.setAccessible(true); - cbField.set(daoObj, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Result<Void> retVal = daoObj.delete(trans,data, false); - assertTrue(retVal.status == 0); - - List<Data> dataAL= new ArrayList<>(); - dataAL.add(data); - rs1 = new Result<List<Data>>(dataAL,0,"test",new Object[0]); - Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", data); - - retVal = daoObj.delete(trans,data, false); - assertTrue(retVal.status == 0); - - } - - @Test - public void testReadNsByAttrib() { - PSInfo psObj = Mockito.mock(PSInfo.class); - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - NsDAO.Data data = new NsDAO.Data(); - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - NsDAOImpl daoObj=null; - try { - daoObj = new NsDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, session); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); - - Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new Object[0]); - Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl CREATE", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl UPDATE", data); - Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl DELETE", data); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - - Mockito.doReturn("test user").when(trans).user(); - Field cbField; - try { - cbField = AbsCassDAO.class.getDeclaredField("owningDAO"); - cbField.setAccessible(true); - cbField.set(daoObj, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Result<Set<String>> retVal = daoObj.readNsByAttrib(trans,"test"); - assertTrue(retVal.status == 0); - - ResultSet rsMock = Mockito.mock(ResultSet.class); - Iterator<Row> iteMock = Mockito.mock(Iterator.class); - Mockito.doReturn(iteMock).when(rsMock).iterator(); - Row rowMock = Mockito.mock(Row.class); - Mockito.doReturn(rowMock).when(iteMock).next(); - Mockito.when(iteMock.hasNext()).thenReturn(true, false); - Mockito.doReturn("test").when(rowMock).getString(Mockito.anyInt()); - Mockito.doReturn(rsMock).when(session).execute(Mockito.anyString()); - - retVal = daoObj.readNsByAttrib(trans,"test"); - assertTrue(retVal.status == 0); - - } - @Test - public void testAttribAdd() { - PSInfo psObj = Mockito.mock(PSInfo.class); - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - NsDAO.Data data = new NsDAO.Data(); - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - NsDAOImpl daoObj=null; - try { - daoObj = new NsDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, session); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); - - Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new Object[0]); - Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl CREATE", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl UPDATE", data); - Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl DELETE", data); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - - Mockito.doReturn("test user").when(trans).user(); - Field cbField; - try { - cbField = AbsCassDAO.class.getDeclaredField("owningDAO"); - cbField.setAccessible(true); - cbField.set(daoObj, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Result<Void> retVal = daoObj.attribAdd(trans, "test", "test", "test"); - assertTrue(retVal.status == 0); - } - - @Test - public void testAttribRemove() { - PSInfo psObj = Mockito.mock(PSInfo.class); - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - NsDAO.Data data = new NsDAO.Data(); - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - NsDAOImpl daoObj=null; - try { - daoObj = new NsDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, session); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); - - Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new Object[0]); - Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl CREATE", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl UPDATE", data); - Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl DELETE", data); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - - Mockito.doReturn("test user").when(trans).user(); - Field cbField; - try { - cbField = AbsCassDAO.class.getDeclaredField("owningDAO"); - cbField.setAccessible(true); - cbField.set(daoObj, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Result<Void> retVal = daoObj.attribRemove(trans, "test", "test"); - assertTrue(retVal.status == 0); - } - - @Test - public void testAddDescription() { - PSInfo psObj = Mockito.mock(PSInfo.class); - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - NsDAO.Data data = new NsDAO.Data(); - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - NsDAOImpl daoObj=null; - try { - daoObj = new NsDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, session); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); - - Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new Object[0]); - Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl CREATE", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl UPDATE", data); - Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl DELETE", data); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - - rs1 = new Result<List<Data>>(null,1,"test",new String[0]); - Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); - Mockito.doReturn("test user").when(trans).user(); - Field cbField; - try { - cbField = AbsCassDAO.class.getDeclaredField("owningDAO"); - cbField.setAccessible(true); - cbField.set(daoObj, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Result<Void> retVal = daoObj.addDescription(trans, "test", "test"); - assertTrue(retVal.status == 0); - } - - @Test - public void testGetChildren() { - PSInfo psObj = Mockito.mock(PSInfo.class); - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - NsDAOImpl daoObj=null; - try { - daoObj = new NsDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, session); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Result<List<Data>> retVal = daoObj.getChildren(trans, "test"); - assertNull(retVal); - } - - @Test - public void testData() { - NsDAO.Data data = new NsDAO.Data(); - data.attrib = null; - data.attrib(true); - - data.attrib = new HashMap<>(); - data.attrib(true); - - data.attrib(false); - data.attrib = new ConcurrentHashMap<>(); - data.attrib(true); - - data.name="123"; - data.split("test"); - - data.toString(); - } + + Object obj = constructor.newInstance(1); + Method innnerClassMtd; + + NsDAO.Data data = new NsDAO.Data(); + Row row = Mockito.mock(Row.class); + ByteBuffer bbObj = ByteBuffer.allocateDirect(10); + bbObj.limit(7); + bbObj.put(0, new Byte("0")); + bbObj.put(1, new Byte("1")); + bbObj.put(2, new Byte("2")); + Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); + + innnerClassMtd = innerClass.getMethod("load", new Class[] {NsDAO.Data.class, Row.class}); + innnerClassMtd.invoke(obj, new Object[] {data, row}); + + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {NsDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); +// + innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {NsDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {NsDAO.Data.class, DataOutputStream.class }); + innnerClassMtd.invoke(obj, new Object[] {data, dos }); + + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + DataInputStream dis = new DataInputStream(bais); + innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {NsDAO.Data.class, DataInputStream.class }); + innnerClassMtd.invoke(obj, new Object[] {data, dis }); + + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + @Test + public void testCreate() { + PSInfo psObj = Mockito.mock(PSInfo.class); + + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + NsDAO.Data data = new NsDAO.Data(); + + Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new Object[0]); + Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl CREATE", data); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + NsDAOImpl daoObj=null; + try { + daoObj = new NsDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, session); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Mockito.doReturn("test user").when(trans).user(); + + Result<NsDAO.Data> retVal = daoObj.create(trans,data); + assertTrue(retVal.status == 4); + + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); + data.parent = "parent"; + data.attrib = new HashMap<>(); + data.attrib.put("test", "test"); + + Field cbField; + Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); + try { + cbField = CassAccess.class.getDeclaredField("cb"); + cbField.setAccessible(true); + cbField.set(daoObj, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + retVal = daoObj.create(trans,data); + assertTrue(retVal.status == 9); + + Field owningField; + Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); + try { + owningField = AbsCassDAO.class.getDeclaredField("owningDAO"); + owningField.setAccessible(true); + owningField.set(daoObj, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + retVal = daoObj.create(trans,data); + assertTrue(retVal.status == 0); + + } + + @Test + public void testUpdate() { + PSInfo psObj = Mockito.mock(PSInfo.class); + + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + NsDAO.Data data = new NsDAO.Data(); + + Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new Object[0]); + Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl CREATE", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl UPDATE", data); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + NsDAOImpl daoObj=null; + try { + daoObj = new NsDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, session); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Mockito.doReturn("test user").when(trans).user(); + + Result<Void> retVal = daoObj.update(trans,data); + assertTrue(retVal.status == 4); + + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); + data.parent = "parent"; + data.attrib = new HashMap<>(); + data.attrib.put("test", "test"); + Field cbField; + Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); + try { + cbField = AbsCassDAO.class.getDeclaredField("owningDAO"); + cbField.setAccessible(true); + cbField.set(daoObj, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + retVal = daoObj.update(trans,data); + assertTrue(retVal.status == 0); + + ResultSet rsMock = Mockito.mock(ResultSet.class); + Iterator<Row> iteMock = Mockito.mock(Iterator.class); + Mockito.doReturn(iteMock).when(rsMock).iterator(); + Row rowMock = Mockito.mock(Row.class); + Mockito.doReturn(rowMock).when(iteMock).next(); + Mockito.when(iteMock.hasNext()).thenReturn(true, false); + Mockito.doReturn("test").when(rowMock).getString(Mockito.anyInt()); + Mockito.doReturn(rsMock).when(session).execute(Mockito.anyString()); + retVal = daoObj.update(trans,data); + assertTrue(retVal.status == 0); + } + + @Test + public void testRead() { + PSInfo psObj = Mockito.mock(PSInfo.class); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); + + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + NsDAO.Data data = new NsDAO.Data(); + + Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new Object[0]); + Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl CREATE", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl UPDATE", data); + Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", data); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + NsDAOImpl daoObj=null; + try { + daoObj = new NsDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, session); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Mockito.doReturn("test user").when(trans).user(); + + Result<List<Data>> retVal = daoObj.read(trans,data); + assertTrue(retVal.status == 0); + + List<Data> dataAL= new ArrayList<>(); + dataAL.add(data); + rs1 = new Result<List<Data>>(dataAL,0,"test",new Object[0]); + Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", data); + Field cbField; + Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); + try { + cbField = AbsCassDAO.class.getDeclaredField("owningDAO"); + cbField.setAccessible(true); + cbField.set(daoObj, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + retVal = daoObj.read(trans,data); + assertTrue(retVal.status == 0); + + } + + @Test + public void testReadByObject() { + PSInfo psObj = Mockito.mock(PSInfo.class); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); + + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + NsDAO.Data data = new NsDAO.Data(); + + Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new Object[0]); + Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl CREATE", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl UPDATE", data); + Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", new Object[] {}); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + NsDAOImpl daoObj=null; + try { + daoObj = new NsDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, session); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Mockito.doReturn("test user").when(trans).user(); + + Result<List<Data>> retVal = daoObj.read(trans,new Object[] {}); + assertTrue(retVal.status == 0); + + List<Data> dataAL= new ArrayList<>(); + dataAL.add(data); + rs1 = new Result<List<Data>>(dataAL,0,"test",new Object[0]); + Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", new Object[] {}); + Field cbField; + Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); + try { + cbField = AbsCassDAO.class.getDeclaredField("owningDAO"); + cbField.setAccessible(true); + cbField.set(daoObj, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + retVal = daoObj.read(trans,new Object[] {}); + assertTrue(retVal.status == 0); + + } + + @Test + public void testDelete() { + PSInfo psObj = Mockito.mock(PSInfo.class); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); + + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + NsDAO.Data data = new NsDAO.Data(); + + Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new Object[0]); + Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl CREATE", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl UPDATE", data); + Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl DELETE", data); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + NsDAOImpl daoObj=null; + try { + daoObj = new NsDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, session); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Mockito.doReturn("test user").when(trans).user(); + Field cbField; + Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); + try { + cbField = AbsCassDAO.class.getDeclaredField("owningDAO"); + cbField.setAccessible(true); + cbField.set(daoObj, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Result<Void> retVal = daoObj.delete(trans,data, false); + assertTrue(retVal.status == 0); + + List<Data> dataAL= new ArrayList<>(); + dataAL.add(data); + rs1 = new Result<List<Data>>(dataAL,0,"test",new Object[0]); + Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", data); + + retVal = daoObj.delete(trans,data, false); + assertTrue(retVal.status == 0); + + } + + @Test + public void testReadNsByAttrib() { + PSInfo psObj = Mockito.mock(PSInfo.class); + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + NsDAO.Data data = new NsDAO.Data(); + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + NsDAOImpl daoObj=null; + try { + daoObj = new NsDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, session); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); + + Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new Object[0]); + Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl CREATE", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl UPDATE", data); + Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl DELETE", data); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + + Mockito.doReturn("test user").when(trans).user(); + Field cbField; + try { + cbField = AbsCassDAO.class.getDeclaredField("owningDAO"); + cbField.setAccessible(true); + cbField.set(daoObj, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Result<Set<String>> retVal = daoObj.readNsByAttrib(trans,"test"); + assertTrue(retVal.status == 0); + + ResultSet rsMock = Mockito.mock(ResultSet.class); + Iterator<Row> iteMock = Mockito.mock(Iterator.class); + Mockito.doReturn(iteMock).when(rsMock).iterator(); + Row rowMock = Mockito.mock(Row.class); + Mockito.doReturn(rowMock).when(iteMock).next(); + Mockito.when(iteMock.hasNext()).thenReturn(true, false); + Mockito.doReturn("test").when(rowMock).getString(Mockito.anyInt()); + Mockito.doReturn(rsMock).when(session).execute(Mockito.anyString()); + + retVal = daoObj.readNsByAttrib(trans,"test"); + assertTrue(retVal.status == 0); + + } + @Test + public void testAttribAdd() { + PSInfo psObj = Mockito.mock(PSInfo.class); + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + NsDAO.Data data = new NsDAO.Data(); + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + NsDAOImpl daoObj=null; + try { + daoObj = new NsDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, session); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); + + Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new Object[0]); + Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl CREATE", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl UPDATE", data); + Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl DELETE", data); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + + Mockito.doReturn("test user").when(trans).user(); + Field cbField; + try { + cbField = AbsCassDAO.class.getDeclaredField("owningDAO"); + cbField.setAccessible(true); + cbField.set(daoObj, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Result<Void> retVal = daoObj.attribAdd(trans, "test", "test", "test"); + assertTrue(retVal.status == 0); + } + + @Test + public void testAttribRemove() { + PSInfo psObj = Mockito.mock(PSInfo.class); + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + NsDAO.Data data = new NsDAO.Data(); + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + NsDAOImpl daoObj=null; + try { + daoObj = new NsDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, session); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); + + Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new Object[0]); + Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl CREATE", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl UPDATE", data); + Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl DELETE", data); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + + Mockito.doReturn("test user").when(trans).user(); + Field cbField; + try { + cbField = AbsCassDAO.class.getDeclaredField("owningDAO"); + cbField.setAccessible(true); + cbField.set(daoObj, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Result<Void> retVal = daoObj.attribRemove(trans, "test", "test"); + assertTrue(retVal.status == 0); + } + + @Test + public void testAddDescription() { + PSInfo psObj = Mockito.mock(PSInfo.class); + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + NsDAO.Data data = new NsDAO.Data(); + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + NsDAOImpl daoObj=null; + try { + daoObj = new NsDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, session); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); + + Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new Object[0]); + Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl CREATE", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl UPDATE", data); + Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl DELETE", data); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + + rs1 = new Result<List<Data>>(null,1,"test",new String[0]); + Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); + Mockito.doReturn("test user").when(trans).user(); + Field cbField; + try { + cbField = AbsCassDAO.class.getDeclaredField("owningDAO"); + cbField.setAccessible(true); + cbField.set(daoObj, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Result<Void> retVal = daoObj.addDescription(trans, "test", "test"); + assertTrue(retVal.status == 0); + } + + @Test + public void testGetChildren() { + PSInfo psObj = Mockito.mock(PSInfo.class); + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + NsDAOImpl daoObj=null; + try { + daoObj = new NsDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, session); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Result<List<Data>> retVal = daoObj.getChildren(trans, "test"); + assertNull(retVal); + } + + @Test + public void testData() { + NsDAO.Data data = new NsDAO.Data(); + data.attrib = null; + data.attrib(true); + + data.attrib = new HashMap<>(); + data.attrib(true); + + data.attrib(false); + data.attrib = new ConcurrentHashMap<>(); + data.attrib(true); + + data.name="123"; + data.split("test"); + + data.toString(); + } } class NsDAOImpl extends NsDAO{ - -// public NsDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,PSInfo readPS ) throws APIException, IOException { -// super(trans, historyDAO); -// setSession(this, Mockito.mock(Session.class)); -// } - - - public NsDAOImpl(AuthzTrans trans, Cluster cluster, String keySpace, Session session)throws APIException, IOException { - super(trans, cluster, keySpace); - setSession(this, session); - } - - - public NsDAOImpl(AuthzTrans trans, HistoryDAO historyDAO, CacheInfoDAO cacheInfoDAO, - org.onap.aaf.auth.dao.AbsCassDAO.PSInfo psObj, Session session) throws APIException, IOException { - super(trans, historyDAO, cacheInfoDAO); - setPs(this, psObj, "createPS"); - setPs(this, psObj, "updatePS"); - setPs(this, psObj, "readPS"); - setPs(this, psObj, "deletePS"); - setPsNs(this, psObj, "psNS"); - setSession(this, session); - } - public void setPsNs(NsDAOImpl NsDAOObj, PSInfo psInfoObj, String methodName) { - Field nsDaoField; - try { - nsDaoField = NsDAO.class.getDeclaredField(methodName); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(NsDAOObj, psInfoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public void setPs(NsDAOImpl NsDAOObj, PSInfo psInfoObj, String methodName) { - Field nsDaoField; - try { - nsDaoField = CassDAOImpl.class.getDeclaredField(methodName); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(NsDAOObj, psInfoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - public void setSession(NsDAOImpl approvalDaoObj, Session session) { - Field nsDaoField; - try { - nsDaoField = AbsCassDAO.class.getDeclaredField("session"); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(approvalDaoObj, session); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + +// public NsDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,PSInfo readPS ) throws APIException, IOException { +// super(trans, historyDAO); +// setSession(this, Mockito.mock(Session.class)); +// } + + + public NsDAOImpl(AuthzTrans trans, Cluster cluster, String keySpace, Session session)throws APIException, IOException { + super(trans, cluster, keySpace); + setSession(this, session); + } + + + public NsDAOImpl(AuthzTrans trans, HistoryDAO historyDAO, CacheInfoDAO cacheInfoDAO, + org.onap.aaf.auth.dao.AbsCassDAO.PSInfo psObj, Session session) throws APIException, IOException { + super(trans, historyDAO, cacheInfoDAO); + setPs(this, psObj, "createPS"); + setPs(this, psObj, "updatePS"); + setPs(this, psObj, "readPS"); + setPs(this, psObj, "deletePS"); + setPsNs(this, psObj, "psNS"); + setSession(this, session); + } + public void setPsNs(NsDAOImpl NsDAOObj, PSInfo psInfoObj, String methodName) { + Field nsDaoField; + try { + nsDaoField = NsDAO.class.getDeclaredField(methodName); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(NsDAOObj, psInfoObj); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public void setPs(NsDAOImpl NsDAOObj, PSInfo psInfoObj, String methodName) { + Field nsDaoField; + try { + nsDaoField = CassDAOImpl.class.getDeclaredField(methodName); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(NsDAOObj, psInfoObj); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + public void setSession(NsDAOImpl approvalDaoObj, Session session) { + Field nsDaoField; + try { + nsDaoField = AbsCassDAO.class.getDeclaredField("session"); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(approvalDaoObj, session); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_OAuthTokenDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_OAuthTokenDAO.java index e8de65ad..5c158b6a 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_OAuthTokenDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_OAuthTokenDAO.java @@ -59,214 +59,214 @@ import com.datastax.driver.core.Row; public class JU_OAuthTokenDAO { - @Mock + @Mock AuthzTrans trans; - @Mock - Cluster cluster; - - @Before - public void setUp() throws APIException, IOException { - initMocks(this); - } + @Mock + Cluster cluster; + + @Before + public void setUp() throws APIException, IOException { + initMocks(this); + } - @Test - public void testInit() { - OAuthTokenDAO daoObj = new OAuthTokenDAO(trans, cluster, "test"); -// daoObj. - } - @Test - public void testReadByUser() { - OAuthTokenDAO daoObj = new OAuthTokenDAO(trans, cluster, "test"); - - PSInfo psObj = Mockito.mock(PSInfo.class); - setPsByStartAndTarget(daoObj, psObj, "psByUser"); - - Result<List<OAuthTokenDAO.Data>> rs1 = new Result<List<OAuthTokenDAO.Data>>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(psObj).read(trans, "OAuthTokenDAO READ", new Object[]{"test"}); - - daoObj.readByUser(trans, "test"); - } - - public void setPsByStartAndTarget(OAuthTokenDAO OAuthTokenDAOObj, PSInfo psInfoObj, String fieldName) { - Field nsDaoField; - try { - nsDaoField = OAuthTokenDAO.class.getDeclaredField(fieldName); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(OAuthTokenDAOObj, psInfoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testWasMOdified() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("OAuthTokenDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on OAuthTokenDAO", Env.SUB); - Mockito.doReturn(tt).when(trans).start("DELETE Future",Env.REMOTE); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doNothing().when(tt).done(); - OAuthTokenDAO.Data data = new OAuthTokenDAO.Data(); + @Test + public void testInit() { + OAuthTokenDAO daoObj = new OAuthTokenDAO(trans, cluster, "test"); +// daoObj. + } + @Test + public void testReadByUser() { + OAuthTokenDAO daoObj = new OAuthTokenDAO(trans, cluster, "test"); + + PSInfo psObj = Mockito.mock(PSInfo.class); + setPsByStartAndTarget(daoObj, psObj, "psByUser"); + + Result<List<OAuthTokenDAO.Data>> rs1 = new Result<List<OAuthTokenDAO.Data>>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(psObj).read(trans, "OAuthTokenDAO READ", new Object[]{"test"}); + + daoObj.readByUser(trans, "test"); + } + + public void setPsByStartAndTarget(OAuthTokenDAO OAuthTokenDAOObj, PSInfo psInfoObj, String fieldName) { + Field nsDaoField; + try { + nsDaoField = OAuthTokenDAO.class.getDeclaredField(fieldName); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(OAuthTokenDAOObj, psInfoObj); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testWasMOdified() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("OAuthTokenDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on OAuthTokenDAO", Env.SUB); + Mockito.doReturn(tt).when(trans).start("DELETE Future",Env.REMOTE); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); + Mockito.doNothing().when(tt).done(); + OAuthTokenDAO.Data data = new OAuthTokenDAO.Data(); - OAuthTokenDAO daoObj = null; - daoObj = new OAuthTokenDAO(trans, cluster, "test" ); - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - - } - - @Test - public void testSecondConstructor() { - AbsCassDAO absCassDAO = Mockito.mock(AbsCassDAO.class); + OAuthTokenDAO daoObj = null; + daoObj = new OAuthTokenDAO(trans, cluster, "test" ); + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); + + } + + @Test + public void testSecondConstructor() { + AbsCassDAO absCassDAO = Mockito.mock(AbsCassDAO.class); - OAuthTokenDAO daoObj = new OAuthTokenDAO(trans, absCassDAO); - - } + OAuthTokenDAO daoObj = new OAuthTokenDAO(trans, absCassDAO); + + } - @Test - public void testData(){ - OAuthTokenDAO.Data data = new OAuthTokenDAO.Data(); - data.scopes = null; - data.scopes(true); + @Test + public void testData(){ + OAuthTokenDAO.Data data = new OAuthTokenDAO.Data(); + data.scopes = null; + data.scopes(true); - data.scopes = new HashSet<>(); - data.scopes(true); + data.scopes = new HashSet<>(); + data.scopes(true); - data.scopes(false); - data.scopes = new ConcurrentHashSet<>(); - data.scopes(true); - - data.expires = new Date(); - data.user="test"; - data.id="id"; - data.toString(); - - data.active=true; - data.toString(); - - try { - ByteBuffer bb = data.bytify(); - data.reconstitute(bb); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - @Test - public void testOAuthLoader(){ - Class<?> innerClass = null; - Class<?>[] innerClassArr = OAuthTokenDAO.class.getDeclaredClasses(); - for(Class indCls:innerClassArr) { - if(indCls.getName().contains("OAuthLoader")) { - innerClass = indCls; - break; - } - } - + data.scopes(false); + data.scopes = new ConcurrentHashSet<>(); + data.scopes(true); + + data.expires = new Date(); + data.user="test"; + data.id="id"; + data.toString(); + + data.active=true; + data.toString(); + + try { + ByteBuffer bb = data.bytify(); + data.reconstitute(bb); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + @Test + public void testOAuthLoader(){ + Class<?> innerClass = null; + Class<?>[] innerClassArr = OAuthTokenDAO.class.getDeclaredClasses(); + for(Class indCls:innerClassArr) { + if(indCls.getName().contains("OAuthLoader")) { + innerClass = indCls; + break; + } + } + Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); try { - - Object obj = constructor.newInstance(1); - Method innnerClassMtd; - - OAuthTokenDAO.Data data = new OAuthTokenDAO.Data(); - Row row = Mockito.mock(Row.class); - ByteBuffer bbObj = ByteBuffer.allocateDirect(10); - bbObj.limit(7); - bbObj.put(0, new Byte("0")); - bbObj.put(1, new Byte("1")); - bbObj.put(2, new Byte("2")); - Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); - - innnerClassMtd = innerClass.getMethod("load", new Class[] {OAuthTokenDAO.Data.class, Row.class}); - innnerClassMtd.invoke(obj, new Object[] {data, row}); - - innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {OAuthTokenDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); -// - innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {OAuthTokenDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test","test"} }); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {OAuthTokenDAO.Data.class, DataOutputStream.class }); - innnerClassMtd.invoke(obj, new Object[] {data, dos }); + + Object obj = constructor.newInstance(1); + Method innnerClassMtd; + + OAuthTokenDAO.Data data = new OAuthTokenDAO.Data(); + Row row = Mockito.mock(Row.class); + ByteBuffer bbObj = ByteBuffer.allocateDirect(10); + bbObj.limit(7); + bbObj.put(0, new Byte("0")); + bbObj.put(1, new Byte("1")); + bbObj.put(2, new Byte("2")); + Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); + + innnerClassMtd = innerClass.getMethod("load", new Class[] {OAuthTokenDAO.Data.class, Row.class}); + innnerClassMtd.invoke(obj, new Object[] {data, row}); + + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {OAuthTokenDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); +// + innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {OAuthTokenDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test","test"} }); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {OAuthTokenDAO.Data.class, DataOutputStream.class }); + innnerClassMtd.invoke(obj, new Object[] {data, dos }); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - DataInputStream dis = new DataInputStream(bais); - innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {OAuthTokenDAO.Data.class, DataInputStream.class }); - innnerClassMtd.invoke(obj, new Object[] {data, dis }); - - } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + DataInputStream dis = new DataInputStream(bais); + innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {OAuthTokenDAO.Data.class, DataInputStream.class }); + innnerClassMtd.invoke(obj, new Object[] {data, dis }); + + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } class OAuthTokenDAOImpl extends OAuthTokenDAO{ - - public OAuthTokenDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,PSInfo readPS ) throws APIException, IOException { - super(trans, historyDAO); - setPs(this, readPS, "createPS"); - } - + + public OAuthTokenDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,PSInfo readPS ) throws APIException, IOException { + super(trans, historyDAO); + setPs(this, readPS, "createPS"); + } + - public void setPs(OAuthTokenDAOImpl OAuthTokenDAOObj, PSInfo psInfoObj, String methodName) { - Field nsDaoField; - try { - nsDaoField = CassDAOImpl.class.getDeclaredField(methodName); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(OAuthTokenDAOObj, psInfoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - + public void setPs(OAuthTokenDAOImpl OAuthTokenDAOObj, PSInfo psInfoObj, String methodName) { + Field nsDaoField; + try { + nsDaoField = CassDAOImpl.class.getDeclaredField(methodName); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(OAuthTokenDAOObj, psInfoObj); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_PermDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_PermDAO.java index c92420da..57f39922 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_PermDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_PermDAO.java @@ -63,591 +63,591 @@ import com.datastax.driver.core.Session; public class JU_PermDAO { - @Mock + @Mock AuthzTrans trans; - @Mock - Cluster cluster; - @Mock - Session session; - - @Before - public void setUp() throws APIException, IOException { - initMocks(this); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).init(); - Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LATITUDE); - Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LONGITUDE); - Mockito.doReturn(session).when(cluster).connect("test"); - } + @Mock + Cluster cluster; + @Mock + Session session; + + @Before + public void setUp() throws APIException, IOException { + initMocks(this); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).init(); + Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LATITUDE); + Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LONGITUDE); + Mockito.doReturn(session).when(cluster).connect("test"); + } - @Test - public void testInit() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("PermDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on PermDAO", Env.SUB); - try { - Session session = Mockito.mock(Session.class); - PermDAO daoObj = new PermDAO(trans, cluster, "test"); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } -// daoObj. - } - @Test - public void testReadByStartAndTarget() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("PermDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on PermDAO", Env.SUB); - PermDAO daoObj = null; - try { - Session session = Mockito.mock(Session.class); - daoObj = new PermDAO(trans, cluster, "test"); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - PSInfo psObj = Mockito.mock(PSInfo.class); - setPsByStartAndTarget(daoObj, psObj, "psByType"); - - Result<List<PermDAO.Data>> rs1 = new Result<List<PermDAO.Data>>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(psObj).read(trans, "PermDAO READ", new Object[]{"test"}); - - daoObj.readByType(trans, "test", "test"); - } - @Test - public void testReadChildren() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("PermDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on PermDAO", Env.SUB); - PermDAO daoObj = null; - try { - Session session = Mockito.mock(Session.class); - daoObj = new PermDAO(trans, cluster, "test"); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - PSInfo psObj = Mockito.mock(PSInfo.class); - setPsByStartAndTarget(daoObj, psObj, "psChildren"); - - Result<List<PermDAO.Data>> rs1 = new Result<List<PermDAO.Data>>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(psObj).read(trans, "PermDAO READ", new Object[]{"test"}); - - daoObj.readChildren(trans, "test", "test"); - } - @Test - public void testReadNs() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("PermDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on PermDAO", Env.SUB); - PermDAO daoObj = null; - try { - Session session = Mockito.mock(Session.class); - daoObj = new PermDAO(trans, cluster, "test"); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - PSInfo psObj = Mockito.mock(PSInfo.class); - setPsByStartAndTarget(daoObj, psObj, "psNS"); - - Result<List<PermDAO.Data>> rs1 = new Result<List<PermDAO.Data>>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(psObj).read(trans, "PermDAO READ", new Object[]{"test"}); - - daoObj.readNS(trans, "test"); - } - @Test - public void testAddRole() { - PSInfo psObj = Mockito.mock(PSInfo.class); - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - PermDAO.Data data = new PermDAO.Data(); - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - PermDAOImpl daoObj=null; - try { - daoObj = new PermDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, Mockito.mock(Session.class)); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + @Test + public void testInit() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("PermDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on PermDAO", Env.SUB); + try { + Session session = Mockito.mock(Session.class); + PermDAO daoObj = new PermDAO(trans, cluster, "test"); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } +// daoObj. + } + @Test + public void testReadByStartAndTarget() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("PermDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on PermDAO", Env.SUB); + PermDAO daoObj = null; + try { + Session session = Mockito.mock(Session.class); + daoObj = new PermDAO(trans, cluster, "test"); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + PSInfo psObj = Mockito.mock(PSInfo.class); + setPsByStartAndTarget(daoObj, psObj, "psByType"); + + Result<List<PermDAO.Data>> rs1 = new Result<List<PermDAO.Data>>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(psObj).read(trans, "PermDAO READ", new Object[]{"test"}); + + daoObj.readByType(trans, "test", "test"); + } + @Test + public void testReadChildren() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("PermDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on PermDAO", Env.SUB); + PermDAO daoObj = null; + try { + Session session = Mockito.mock(Session.class); + daoObj = new PermDAO(trans, cluster, "test"); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + PSInfo psObj = Mockito.mock(PSInfo.class); + setPsByStartAndTarget(daoObj, psObj, "psChildren"); + + Result<List<PermDAO.Data>> rs1 = new Result<List<PermDAO.Data>>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(psObj).read(trans, "PermDAO READ", new Object[]{"test"}); + + daoObj.readChildren(trans, "test", "test"); + } + @Test + public void testReadNs() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("PermDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on PermDAO", Env.SUB); + PermDAO daoObj = null; + try { + Session session = Mockito.mock(Session.class); + daoObj = new PermDAO(trans, cluster, "test"); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + PSInfo psObj = Mockito.mock(PSInfo.class); + setPsByStartAndTarget(daoObj, psObj, "psNS"); + + Result<List<PermDAO.Data>> rs1 = new Result<List<PermDAO.Data>>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(psObj).read(trans, "PermDAO READ", new Object[]{"test"}); + + daoObj.readNS(trans, "test"); + } + @Test + public void testAddRole() { + PSInfo psObj = Mockito.mock(PSInfo.class); + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + PermDAO.Data data = new PermDAO.Data(); + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + PermDAOImpl daoObj=null; + try { + daoObj = new PermDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, Mockito.mock(Session.class)); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("PermDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on PermDAO", Env.SUB); - - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("PermDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on PermDAO", Env.SUB); + + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); - Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(psObj).exec(trans, "PermDAOImpl CREATE", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "PermDAOImpl UPDATE", data); - Mockito.doReturn(rs1).when(psObj).read(trans, "PermDAOImpl READ", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "PermDAOImpl DELETE", data); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - - Result<Void> rs2 = new Result<Void>(null,0,"test",new String[0]); - Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); - - rs1 = new Result<List<Data>>(null,1,"test",new String[0]); - Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); - Mockito.doReturn("test user").when(trans).user(); - Field cbField; - try { - cbField = CassAccess.class.getDeclaredField("cb"); - cbField.setAccessible(true); - cbField.set(daoObj, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - PermDAO.Data perm = new PermDAO.Data(); - Result<Void> retVal = daoObj.addRole(trans, perm, "test"); - assertTrue(retVal.status == 9); - - Field owningField; - try { - owningField = AbsCassDAO.class.getDeclaredField("owningDAO"); - owningField.setAccessible(true); - owningField.set(daoObj, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - retVal = daoObj.addRole(trans, perm, "test"); - assertTrue(retVal.status == 0); - } - - @Test - public void testDelRole() { - PSInfo psObj = Mockito.mock(PSInfo.class); - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - PermDAO.Data data = new PermDAO.Data(); - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - PermDAOImpl daoObj=null; - try { - daoObj = new PermDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, Mockito.mock(Session.class)); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(psObj).exec(trans, "PermDAOImpl CREATE", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "PermDAOImpl UPDATE", data); + Mockito.doReturn(rs1).when(psObj).read(trans, "PermDAOImpl READ", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "PermDAOImpl DELETE", data); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + + Result<Void> rs2 = new Result<Void>(null,0,"test",new String[0]); + Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); + + rs1 = new Result<List<Data>>(null,1,"test",new String[0]); + Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); + Mockito.doReturn("test user").when(trans).user(); + Field cbField; + try { + cbField = CassAccess.class.getDeclaredField("cb"); + cbField.setAccessible(true); + cbField.set(daoObj, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + PermDAO.Data perm = new PermDAO.Data(); + Result<Void> retVal = daoObj.addRole(trans, perm, "test"); + assertTrue(retVal.status == 9); + + Field owningField; + try { + owningField = AbsCassDAO.class.getDeclaredField("owningDAO"); + owningField.setAccessible(true); + owningField.set(daoObj, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + retVal = daoObj.addRole(trans, perm, "test"); + assertTrue(retVal.status == 0); + } + + @Test + public void testDelRole() { + PSInfo psObj = Mockito.mock(PSInfo.class); + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + PermDAO.Data data = new PermDAO.Data(); + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + PermDAOImpl daoObj=null; + try { + daoObj = new PermDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, Mockito.mock(Session.class)); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("PermDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on PermDAO", Env.SUB); - - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("PermDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on PermDAO", Env.SUB); + + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); - Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(psObj).exec(trans, "PermDAOImpl CREATE", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "PermDAOImpl UPDATE", data); - Mockito.doReturn(rs1).when(psObj).read(trans, "PermDAOImpl READ", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "PermDAOImpl DELETE", data); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - - Result<Void> rs2 = new Result<Void>(null,0,"test",new String[0]); - Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); - - rs1 = new Result<List<Data>>(null,1,"test",new String[0]); - Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); - Mockito.doReturn("test user").when(trans).user(); - - PermDAO.Data perm = new PermDAO.Data(); - Field cbField; - try { - cbField = CassAccess.class.getDeclaredField("cb"); - cbField.setAccessible(true); - cbField.set(daoObj, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Result<Void> retVal = daoObj.delRole(trans, perm, "test"); - assertTrue(retVal.status == 9); - - Field owningDaoField; - try { - owningDaoField = AbsCassDAO.class.getDeclaredField("owningDAO"); - owningDaoField.setAccessible(true); - owningDaoField.set(daoObj, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - retVal = daoObj.delRole(trans, perm, "test"); - assertTrue(retVal.status == 0); - } - - @Test - public void testAddDescription() { - PSInfo psObj = Mockito.mock(PSInfo.class); - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - PermDAO.Data data = new PermDAO.Data(); - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - PermDAOImpl daoObj=null; - try { - daoObj = new PermDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, Mockito.mock(Session.class)); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(psObj).exec(trans, "PermDAOImpl CREATE", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "PermDAOImpl UPDATE", data); + Mockito.doReturn(rs1).when(psObj).read(trans, "PermDAOImpl READ", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "PermDAOImpl DELETE", data); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + + Result<Void> rs2 = new Result<Void>(null,0,"test",new String[0]); + Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); + + rs1 = new Result<List<Data>>(null,1,"test",new String[0]); + Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); + Mockito.doReturn("test user").when(trans).user(); + + PermDAO.Data perm = new PermDAO.Data(); + Field cbField; + try { + cbField = CassAccess.class.getDeclaredField("cb"); + cbField.setAccessible(true); + cbField.set(daoObj, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Result<Void> retVal = daoObj.delRole(trans, perm, "test"); + assertTrue(retVal.status == 9); + + Field owningDaoField; + try { + owningDaoField = AbsCassDAO.class.getDeclaredField("owningDAO"); + owningDaoField.setAccessible(true); + owningDaoField.set(daoObj, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + retVal = daoObj.delRole(trans, perm, "test"); + assertTrue(retVal.status == 0); + } + + @Test + public void testAddDescription() { + PSInfo psObj = Mockito.mock(PSInfo.class); + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + PermDAO.Data data = new PermDAO.Data(); + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + PermDAOImpl daoObj=null; + try { + daoObj = new PermDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, Mockito.mock(Session.class)); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("PermDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on PermDAO", Env.SUB); - - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("PermDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on PermDAO", Env.SUB); + + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); - Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(psObj).exec(trans, "PermDAOImpl CREATE", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "PermDAOImpl UPDATE", data); - Mockito.doReturn(rs1).when(psObj).read(trans, "PermDAOImpl READ", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "PermDAOImpl DELETE", data); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - - Result<Void> rs2 = new Result<Void>(null,1,"test",new String[0]); - Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); - - rs1 = new Result<List<Data>>(null,1,"test",new String[0]); - Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); - Mockito.doReturn("test user").when(trans).user(); - - PermDAO.Data perm = new PermDAO.Data(); - Field cbField; - try { - cbField = CassAccess.class.getDeclaredField("cb"); - cbField.setAccessible(true); - cbField.set(daoObj, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Result<Void> retVal = daoObj.addDescription(trans, "test", "test", "test", "test", "test"); - assertTrue(retVal.status == 9); - - Field owningDaoField; - try { - owningDaoField = AbsCassDAO.class.getDeclaredField("owningDAO"); - owningDaoField.setAccessible(true); - owningDaoField.set(daoObj, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - retVal = daoObj.addDescription(trans, "test", "test", "test", "test", "test"); - assertTrue(retVal.status == 0); - } - - public void setPsByStartAndTarget(PermDAO PermDAOObj, PSInfo psInfoObj, String fieldName) { - Field PermDAOField; - try { - PermDAOField = PermDAO.class.getDeclaredField(fieldName); - - PermDAOField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(PermDAOField, PermDAOField.getModifiers() & ~Modifier.FINAL); - - PermDAOField.set(PermDAOObj, psInfoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testWasMOdified() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("PermDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on PermDAO", Env.SUB); - Mockito.doReturn(tt).when(trans).start("DELETE Future",Env.REMOTE); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doNothing().when(tt).done(); - PermDAO.Data data = new PermDAO.Data(); - PSInfo createPS = Mockito.mock(PSInfo.class); - - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); - Result<Void> rs2 = new Result<Void>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); - - PermDAOImpl daoObj = null; - try { - daoObj = new PermDAOImpl(trans, historyDAO, cacheInfoDAO, createPS ); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - - daoObj.wasModified(trans, CRUD.create, data, new String[] {}); - daoObj.wasModified(trans, CRUD.create, data, new String[] {null}); - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test",null}); - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); - - rs1 = new Result<ResultSet>(null,1,"test",new String[0]); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - daoObj.wasModified(trans, CRUD.delete, data, new String[] {"test","test"}); - } - - @Test - public void testSecondConstructor() { - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(psObj).exec(trans, "PermDAOImpl CREATE", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "PermDAOImpl UPDATE", data); + Mockito.doReturn(rs1).when(psObj).read(trans, "PermDAOImpl READ", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "PermDAOImpl DELETE", data); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + + Result<Void> rs2 = new Result<Void>(null,1,"test",new String[0]); + Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); + + rs1 = new Result<List<Data>>(null,1,"test",new String[0]); + Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); + Mockito.doReturn("test user").when(trans).user(); + + PermDAO.Data perm = new PermDAO.Data(); + Field cbField; + try { + cbField = CassAccess.class.getDeclaredField("cb"); + cbField.setAccessible(true); + cbField.set(daoObj, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Result<Void> retVal = daoObj.addDescription(trans, "test", "test", "test", "test", "test"); + assertTrue(retVal.status == 9); + + Field owningDaoField; + try { + owningDaoField = AbsCassDAO.class.getDeclaredField("owningDAO"); + owningDaoField.setAccessible(true); + owningDaoField.set(daoObj, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + retVal = daoObj.addDescription(trans, "test", "test", "test", "test", "test"); + assertTrue(retVal.status == 0); + } + + public void setPsByStartAndTarget(PermDAO PermDAOObj, PSInfo psInfoObj, String fieldName) { + Field PermDAOField; + try { + PermDAOField = PermDAO.class.getDeclaredField(fieldName); + + PermDAOField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(PermDAOField, PermDAOField.getModifiers() & ~Modifier.FINAL); + + PermDAOField.set(PermDAOObj, psInfoObj); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testWasMOdified() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("PermDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on PermDAO", Env.SUB); + Mockito.doReturn(tt).when(trans).start("DELETE Future",Env.REMOTE); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); + Mockito.doNothing().when(tt).done(); + PermDAO.Data data = new PermDAO.Data(); + PSInfo createPS = Mockito.mock(PSInfo.class); + + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); + Result<Void> rs2 = new Result<Void>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); + + PermDAOImpl daoObj = null; + try { + daoObj = new PermDAOImpl(trans, historyDAO, cacheInfoDAO, createPS ); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); + + daoObj.wasModified(trans, CRUD.create, data, new String[] {}); + daoObj.wasModified(trans, CRUD.create, data, new String[] {null}); + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test",null}); + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); + + rs1 = new Result<ResultSet>(null,1,"test",new String[0]); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + daoObj.wasModified(trans, CRUD.delete, data, new String[] {"test","test"}); + } + + @Test + public void testSecondConstructor() { + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - PermDAO daoObj = new PermDAO(trans, historyDAO, cacheInfoDAO); - - } + PermDAO daoObj = new PermDAO(trans, historyDAO, cacheInfoDAO); + + } - @Test - public void testFutureLoader(){ - Class<?> innerClass = null; - Class<?>[] innerClassArr = PermDAO.class.getDeclaredClasses(); - for(Class indCls:innerClassArr) { - if(indCls.getName().contains("PermLoader")) { - innerClass = indCls; - break; - } - } - + @Test + public void testFutureLoader(){ + Class<?> innerClass = null; + Class<?>[] innerClassArr = PermDAO.class.getDeclaredClasses(); + for(Class indCls:innerClassArr) { + if(indCls.getName().contains("PermLoader")) { + innerClass = indCls; + break; + } + } + Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); try { - - Object obj = constructor.newInstance(1); - Method innnerClassMtd; - - PermDAO.Data data = new PermDAO.Data(); - Row row = Mockito.mock(Row.class); - ByteBuffer bbObj = ByteBuffer.allocateDirect(10); - bbObj.limit(7); - bbObj.put(0, new Byte("0")); - bbObj.put(1, new Byte("1")); - bbObj.put(2, new Byte("2")); - Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); - - innnerClassMtd = innerClass.getMethod("load", new Class[] {PermDAO.Data.class, Row.class}); - innnerClassMtd.invoke(obj, new Object[] {data, row}); - - innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {PermDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test"} }); -// - innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {PermDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {PermDAO.Data.class, DataOutputStream.class }); - innnerClassMtd.invoke(obj, new Object[] {data, dos }); + + Object obj = constructor.newInstance(1); + Method innnerClassMtd; + + PermDAO.Data data = new PermDAO.Data(); + Row row = Mockito.mock(Row.class); + ByteBuffer bbObj = ByteBuffer.allocateDirect(10); + bbObj.limit(7); + bbObj.put(0, new Byte("0")); + bbObj.put(1, new Byte("1")); + bbObj.put(2, new Byte("2")); + Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); + + innnerClassMtd = innerClass.getMethod("load", new Class[] {PermDAO.Data.class, Row.class}); + innnerClassMtd.invoke(obj, new Object[] {data, row}); + + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {PermDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test"} }); +// + innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {PermDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {PermDAO.Data.class, DataOutputStream.class }); + innnerClassMtd.invoke(obj, new Object[] {data, dos }); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - DataInputStream dis = new DataInputStream(bais); - innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {PermDAO.Data.class, DataInputStream.class }); - innnerClassMtd.invoke(obj, new Object[] {data, dis }); - - } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testData() { - PermDAO.Data data = new PermDAO.Data(); - NsSplit nss = new NsSplit("test", "test"); - data = new PermDAO.Data(nss, "test", "test"); - - data.toString(); - - assertTrue("test.test|test|test".equalsIgnoreCase(data.fullPerm())); - - Question q = Mockito.mock( Question.class); - - Result<NsSplit> rs = new Result<NsSplit>(nss,0,"test",new Object[0]); - Mockito.doReturn(rs).when(q).deriveNsSplit(trans, "test"); - Result<Data> retVal= PermDAO.Data.decode(trans, q, "test|||"); - assertTrue(retVal.status==0); - Result<String[]> retVal1= PermDAO.Data.decodeToArray(trans, q, "test|||"); - assertTrue(retVal.status==0); - retVal= PermDAO.Data.decode(trans, q, "test||"); - retVal1= PermDAO.Data.decodeToArray(trans, q, "test||"); - assertTrue(retVal.status==0); - - rs = new Result<NsSplit>(nss,1,"test",new Object[0]); - Mockito.doReturn(rs).when(q).deriveNsSplit(trans, "test"); - retVal= PermDAO.Data.decode(trans, q, "test||"); - retVal1= PermDAO.Data.decodeToArray(trans, q, "test||"); - assertTrue(retVal.status==1); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + DataInputStream dis = new DataInputStream(bais); + innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {PermDAO.Data.class, DataInputStream.class }); + innnerClassMtd.invoke(obj, new Object[] {data, dis }); + + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testData() { + PermDAO.Data data = new PermDAO.Data(); + NsSplit nss = new NsSplit("test", "test"); + data = new PermDAO.Data(nss, "test", "test"); + + data.toString(); + + assertTrue("test.test|test|test".equalsIgnoreCase(data.fullPerm())); + + Question q = Mockito.mock( Question.class); + + Result<NsSplit> rs = new Result<NsSplit>(nss,0,"test",new Object[0]); + Mockito.doReturn(rs).when(q).deriveNsSplit(trans, "test"); + Result<Data> retVal= PermDAO.Data.decode(trans, q, "test|||"); + assertTrue(retVal.status==0); + Result<String[]> retVal1= PermDAO.Data.decodeToArray(trans, q, "test|||"); + assertTrue(retVal.status==0); + retVal= PermDAO.Data.decode(trans, q, "test||"); + retVal1= PermDAO.Data.decodeToArray(trans, q, "test||"); + assertTrue(retVal.status==0); + + rs = new Result<NsSplit>(nss,1,"test",new Object[0]); + Mockito.doReturn(rs).when(q).deriveNsSplit(trans, "test"); + retVal= PermDAO.Data.decode(trans, q, "test||"); + retVal1= PermDAO.Data.decodeToArray(trans, q, "test||"); + assertTrue(retVal.status==1); - retVal= PermDAO.Data.decode(trans, q, "test|"); - retVal1= PermDAO.Data.decodeToArray(trans, q, "test|"); - assertTrue(retVal.status==4); - - NsDAO.Data ns = new NsDAO.Data(); - ns.name="test"; - PermDAO.Data.create(ns, "test"); + retVal= PermDAO.Data.decode(trans, q, "test|"); + retVal1= PermDAO.Data.decodeToArray(trans, q, "test|"); + assertTrue(retVal.status==4); + + NsDAO.Data ns = new NsDAO.Data(); + ns.name="test"; + PermDAO.Data.create(ns, "test"); - PermDAO.Data.create(trans,q, "test"); - rs = new Result<NsSplit>(nss,0,"test",new Object[0]); - Mockito.doReturn(rs).when(q).deriveNsSplit(trans, "test"); - PermDAO.Data.create(trans,q, "test|test|test|test"); - } - + PermDAO.Data.create(trans,q, "test"); + rs = new Result<NsSplit>(nss,0,"test",new Object[0]); + Mockito.doReturn(rs).when(q).deriveNsSplit(trans, "test"); + PermDAO.Data.create(trans,q, "test|test|test|test"); + } + } class PermDAOImpl extends PermDAO{ - public PermDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,CacheInfoDAO cacheDao, PSInfo readPS) throws APIException, IOException { - super(trans, historyDAO, cacheDao); - setPs(this, readPS, "createPS"); - } - - public PermDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,CacheInfoDAO cacheDao, PSInfo readPS, Session session ) throws APIException, IOException { - super(trans, historyDAO, cacheDao); - setPs(this, readPS, "createPS"); - setSession(this, session); - } - + public PermDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,CacheInfoDAO cacheDao, PSInfo readPS) throws APIException, IOException { + super(trans, historyDAO, cacheDao); + setPs(this, readPS, "createPS"); + } + + public PermDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,CacheInfoDAO cacheDao, PSInfo readPS, Session session ) throws APIException, IOException { + super(trans, historyDAO, cacheDao); + setPs(this, readPS, "createPS"); + setSession(this, session); + } + - public void setPs(PermDAOImpl PermDAOObj, PSInfo psInfoObj, String methodName) { - Field PermDAOField; - try { - PermDAOField = CassDAOImpl.class.getDeclaredField(methodName); - - PermDAOField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(PermDAOField, PermDAOField.getModifiers() & ~Modifier.FINAL); - - PermDAOField.set(PermDAOObj, psInfoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public void setSession(PermDAOImpl approvalDaoObj, Session session) { - Field nsDaoField; - try { - nsDaoField = AbsCassDAO.class.getDeclaredField("session"); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(approvalDaoObj, session); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + public void setPs(PermDAOImpl PermDAOObj, PSInfo psInfoObj, String methodName) { + Field PermDAOField; + try { + PermDAOField = CassDAOImpl.class.getDeclaredField(methodName); + + PermDAOField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(PermDAOField, PermDAOField.getModifiers() & ~Modifier.FINAL); + + PermDAOField.set(PermDAOObj, psInfoObj); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public void setSession(PermDAOImpl approvalDaoObj, Session session) { + Field nsDaoField; + try { + nsDaoField = AbsCassDAO.class.getDeclaredField("session"); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(approvalDaoObj, session); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_RoleDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_RoleDAO.java index fa023af3..4057a6ed 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_RoleDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_RoleDAO.java @@ -64,602 +64,602 @@ import com.datastax.driver.core.Session; public class JU_RoleDAO { - @Mock + @Mock AuthzTrans trans; - @Mock - Cluster cluster; - @Mock - Session session; - - @Before - public void setUp() throws APIException, IOException { - initMocks(this); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).init(); - Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LATITUDE); - Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LONGITUDE); - Mockito.doReturn(session).when(cluster).connect("test"); - } + @Mock + Cluster cluster; + @Mock + Session session; + + @Before + public void setUp() throws APIException, IOException { + initMocks(this); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).init(); + Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LATITUDE); + Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LONGITUDE); + Mockito.doReturn(session).when(cluster).connect("test"); + } - @Test - public void testInit() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("RoleDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on RoleDAO", Env.SUB); - try { - new RoleDAO(trans, cluster, "test"); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } -// daoObj. - } - @Test - public void testReadByStartAndTarget() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("RoleDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on RoleDAO", Env.SUB); - RoleDAO daoObj = null; - try { - daoObj = new RoleDAO(trans, cluster, "test"); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - PSInfo psObj = Mockito.mock(PSInfo.class); - setPsByStartAndTarget(daoObj, psObj, "psName"); - - Result<List<RoleDAO.Data>> rs1 = new Result<List<RoleDAO.Data>>(null,0,"test",new Object[0]); - Mockito.doReturn(rs1).when(psObj).read(trans, "RoleDAO READ", new Object[]{"test"}); - - daoObj.readName(trans, "test"); - } - @Test - public void testReadChildren() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("RoleDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on RoleDAO", Env.SUB); - RoleDAO daoObj = null; - try { - daoObj = new RoleDAO(trans, cluster, "test"); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - PSInfo psObj = Mockito.mock(PSInfo.class); - setPsByStartAndTarget(daoObj, psObj, "psChildren"); - - Result<List<RoleDAO.Data>> rs1 = new Result<List<RoleDAO.Data>>(null,0,"test",new Object[0]); - Mockito.doReturn(rs1).when(psObj).read(trans, "RoleDAO READ", new Object[]{"test"}); - - daoObj.readChildren(trans, "test", "test"); - - daoObj.readChildren(trans, "test", "*"); - daoObj.readChildren(trans, "test", ""); - } - @Test - public void testReadNs() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("RoleDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on RoleDAO", Env.SUB); - RoleDAO daoObj = null; - try { - daoObj = new RoleDAO(trans, cluster, "test"); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - PSInfo psObj = Mockito.mock(PSInfo.class); - setPsByStartAndTarget(daoObj, psObj, "psNS"); - - Result<List<RoleDAO.Data>> rs1 = new Result<List<RoleDAO.Data>>(null,0,"test",new Object[0]); - Mockito.doReturn(rs1).when(psObj).read(trans, "RoleDAO READ", new Object[]{"test"}); - - daoObj.readNS(trans, "test"); - } - @Test - public void testAddRole() { - PSInfo psObj = Mockito.mock(PSInfo.class); - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - RoleDAO.Data data = new RoleDAO.Data(); - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - RoleDAOImpl daoObj=null; - try { - daoObj = new RoleDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, Mockito.mock(Session.class)); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + @Test + public void testInit() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("RoleDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on RoleDAO", Env.SUB); + try { + new RoleDAO(trans, cluster, "test"); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } +// daoObj. + } + @Test + public void testReadByStartAndTarget() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("RoleDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on RoleDAO", Env.SUB); + RoleDAO daoObj = null; + try { + daoObj = new RoleDAO(trans, cluster, "test"); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + PSInfo psObj = Mockito.mock(PSInfo.class); + setPsByStartAndTarget(daoObj, psObj, "psName"); + + Result<List<RoleDAO.Data>> rs1 = new Result<List<RoleDAO.Data>>(null,0,"test",new Object[0]); + Mockito.doReturn(rs1).when(psObj).read(trans, "RoleDAO READ", new Object[]{"test"}); + + daoObj.readName(trans, "test"); + } + @Test + public void testReadChildren() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("RoleDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on RoleDAO", Env.SUB); + RoleDAO daoObj = null; + try { + daoObj = new RoleDAO(trans, cluster, "test"); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + PSInfo psObj = Mockito.mock(PSInfo.class); + setPsByStartAndTarget(daoObj, psObj, "psChildren"); + + Result<List<RoleDAO.Data>> rs1 = new Result<List<RoleDAO.Data>>(null,0,"test",new Object[0]); + Mockito.doReturn(rs1).when(psObj).read(trans, "RoleDAO READ", new Object[]{"test"}); + + daoObj.readChildren(trans, "test", "test"); + + daoObj.readChildren(trans, "test", "*"); + daoObj.readChildren(trans, "test", ""); + } + @Test + public void testReadNs() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("RoleDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on RoleDAO", Env.SUB); + RoleDAO daoObj = null; + try { + daoObj = new RoleDAO(trans, cluster, "test"); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + PSInfo psObj = Mockito.mock(PSInfo.class); + setPsByStartAndTarget(daoObj, psObj, "psNS"); + + Result<List<RoleDAO.Data>> rs1 = new Result<List<RoleDAO.Data>>(null,0,"test",new Object[0]); + Mockito.doReturn(rs1).when(psObj).read(trans, "RoleDAO READ", new Object[]{"test"}); + + daoObj.readNS(trans, "test"); + } + @Test + public void testAddRole() { + PSInfo psObj = Mockito.mock(PSInfo.class); + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + RoleDAO.Data data = new RoleDAO.Data(); + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + RoleDAOImpl daoObj=null; + try { + daoObj = new RoleDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, Mockito.mock(Session.class)); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("RoleDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on RoleDAO", Env.SUB); - - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("RoleDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on RoleDAO", Env.SUB); + + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); - Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new Object[0]); - Mockito.doReturn(rs1).when(psObj).exec(trans, "RoleDAOImpl CREATE", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "RoleDAOImpl UPDATE", data); - Mockito.doReturn(rs1).when(psObj).read(trans, "RoleDAOImpl READ", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "RoleDAOImpl DELETE", data); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - - Result<Void> rs2 = new Result<Void>(null,0,"test",new Object[0]); - Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); - - rs1 = new Result<List<Data>>(null,1,"test",new Object[0]); - Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); - Mockito.doReturn("test user").when(trans).user(); - Field cbField; - try { - cbField = CassAccess.class.getDeclaredField("cb"); - cbField.setAccessible(true); - cbField.set(daoObj, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - PermDAO.Data perm = new PermDAO.Data(); - RoleDAO.Data role = new RoleDAO.Data(); - Result<Void> retVal = daoObj.addPerm(trans, role, perm); - assertTrue(retVal.status == 9); - - Field owningField; - try { - owningField = AbsCassDAO.class.getDeclaredField("owningDAO"); - owningField.setAccessible(true); - owningField.set(daoObj, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - retVal = daoObj.addPerm(trans, role, perm); - assertTrue(retVal.status == 0); - } - - @Test - public void testDelRole() { - PSInfo psObj = Mockito.mock(PSInfo.class); - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - RoleDAO.Data data = new RoleDAO.Data(); - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - RoleDAOImpl daoObj=null; - try { - daoObj = new RoleDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, Mockito.mock(Session.class)); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new Object[0]); + Mockito.doReturn(rs1).when(psObj).exec(trans, "RoleDAOImpl CREATE", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "RoleDAOImpl UPDATE", data); + Mockito.doReturn(rs1).when(psObj).read(trans, "RoleDAOImpl READ", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "RoleDAOImpl DELETE", data); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + + Result<Void> rs2 = new Result<Void>(null,0,"test",new Object[0]); + Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); + + rs1 = new Result<List<Data>>(null,1,"test",new Object[0]); + Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); + Mockito.doReturn("test user").when(trans).user(); + Field cbField; + try { + cbField = CassAccess.class.getDeclaredField("cb"); + cbField.setAccessible(true); + cbField.set(daoObj, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + PermDAO.Data perm = new PermDAO.Data(); + RoleDAO.Data role = new RoleDAO.Data(); + Result<Void> retVal = daoObj.addPerm(trans, role, perm); + assertTrue(retVal.status == 9); + + Field owningField; + try { + owningField = AbsCassDAO.class.getDeclaredField("owningDAO"); + owningField.setAccessible(true); + owningField.set(daoObj, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + retVal = daoObj.addPerm(trans, role, perm); + assertTrue(retVal.status == 0); + } + + @Test + public void testDelRole() { + PSInfo psObj = Mockito.mock(PSInfo.class); + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + RoleDAO.Data data = new RoleDAO.Data(); + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + RoleDAOImpl daoObj=null; + try { + daoObj = new RoleDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, Mockito.mock(Session.class)); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("RoleDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on RoleDAO", Env.SUB); - - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("RoleDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on RoleDAO", Env.SUB); + + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); - Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new Object[0]); - Mockito.doReturn(rs1).when(psObj).exec(trans, "RoleDAOImpl CREATE", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "RoleDAOImpl UPDATE", data); - Mockito.doReturn(rs1).when(psObj).read(trans, "RoleDAOImpl READ", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "RoleDAOImpl DELETE", data); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - - Result<Void> rs2 = new Result<Void>(null,0,"test",new String[0]); - Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); - - rs1 = new Result<List<Data>>(null,1,"test",new String[0]); - Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); - Mockito.doReturn("test user").when(trans).user(); - - PermDAO.Data perm = new PermDAO.Data(); - Field cbField; - try { - cbField = CassAccess.class.getDeclaredField("cb"); - cbField.setAccessible(true); - cbField.set(daoObj, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - RoleDAO.Data role = new RoleDAO.Data(); - Result<Void> retVal = daoObj.delPerm(trans, role, perm); - assertTrue(retVal.status == 9); - - Field owningDaoField; - try { - owningDaoField = AbsCassDAO.class.getDeclaredField("owningDAO"); - owningDaoField.setAccessible(true); - owningDaoField.set(daoObj, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - retVal = daoObj.delPerm(trans,role, perm); - assertTrue(retVal.status == 0); - } - - @Test - public void testAddDescription() { - PSInfo psObj = Mockito.mock(PSInfo.class); - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - RoleDAO.Data data = new RoleDAO.Data(); - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - RoleDAOImpl daoObj=null; - try { - daoObj = new RoleDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, Mockito.mock(Session.class)); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new Object[0]); + Mockito.doReturn(rs1).when(psObj).exec(trans, "RoleDAOImpl CREATE", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "RoleDAOImpl UPDATE", data); + Mockito.doReturn(rs1).when(psObj).read(trans, "RoleDAOImpl READ", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "RoleDAOImpl DELETE", data); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + + Result<Void> rs2 = new Result<Void>(null,0,"test",new String[0]); + Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); + + rs1 = new Result<List<Data>>(null,1,"test",new String[0]); + Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); + Mockito.doReturn("test user").when(trans).user(); + + PermDAO.Data perm = new PermDAO.Data(); + Field cbField; + try { + cbField = CassAccess.class.getDeclaredField("cb"); + cbField.setAccessible(true); + cbField.set(daoObj, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + RoleDAO.Data role = new RoleDAO.Data(); + Result<Void> retVal = daoObj.delPerm(trans, role, perm); + assertTrue(retVal.status == 9); + + Field owningDaoField; + try { + owningDaoField = AbsCassDAO.class.getDeclaredField("owningDAO"); + owningDaoField.setAccessible(true); + owningDaoField.set(daoObj, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + retVal = daoObj.delPerm(trans,role, perm); + assertTrue(retVal.status == 0); + } + + @Test + public void testAddDescription() { + PSInfo psObj = Mockito.mock(PSInfo.class); + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + RoleDAO.Data data = new RoleDAO.Data(); + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + RoleDAOImpl daoObj=null; + try { + daoObj = new RoleDAOImpl(trans, historyDAO, cacheInfoDAO, psObj, Mockito.mock(Session.class)); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("RoleDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on RoleDAO", Env.SUB); - - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); - Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("RoleDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on RoleDAO", Env.SUB); + + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); - Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(psObj).exec(trans, "RoleDAOImpl CREATE", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "RoleDAOImpl UPDATE", data); - Mockito.doReturn(rs1).when(psObj).read(trans, "RoleDAOImpl READ", data); - Mockito.doReturn(rs1).when(psObj).exec(trans, "RoleDAOImpl DELETE", data); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - - Result<Void> rs2 = new Result<Void>(null,1,"test",new String[0]); - Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); - - rs1 = new Result<List<Data>>(null,1,"test",new String[0]); - Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); - Mockito.doReturn("test user").when(trans).user(); - - RoleDAO.Data perm = new RoleDAO.Data(); - Field cbField; - try { - cbField = CassAccess.class.getDeclaredField("cb"); - cbField.setAccessible(true); - cbField.set(daoObj, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Result<Void> retVal = daoObj.addDescription(trans, "test", "test", "test"); - assertTrue(retVal.status == 9); - - Field owningDaoField; - try { - owningDaoField = AbsCassDAO.class.getDeclaredField("owningDAO"); - owningDaoField.setAccessible(true); - owningDaoField.set(daoObj, null); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - retVal = daoObj.addDescription(trans, "test", "test", "test"); - assertTrue(retVal.status == 0); - } - - public void setPsByStartAndTarget(RoleDAO RoleDAOObj, PSInfo psInfoObj, String fieldName) { - Field RoleDAOField; - try { - RoleDAOField = RoleDAO.class.getDeclaredField(fieldName); - - RoleDAOField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(RoleDAOField, RoleDAOField.getModifiers() & ~Modifier.FINAL); - - RoleDAOField.set(RoleDAOObj, psInfoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testWasModified() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("RoleDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on RoleDAO", Env.SUB); - Mockito.doReturn(tt).when(trans).start("DELETE Future",Env.REMOTE); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doNothing().when(tt).done(); - RoleDAO.Data data = new RoleDAO.Data(); - PSInfo createPS = Mockito.mock(PSInfo.class); - - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); - Result<Void> rs2 = new Result<Void>(null,0,"test",new String[0]); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); - - RoleDAOImpl daoObj = null; - try { - daoObj = new RoleDAOImpl(trans, historyDAO, cacheInfoDAO, createPS ); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - - daoObj.wasModified(trans, CRUD.create, data, new String[] {}); - daoObj.wasModified(trans, CRUD.create, data, new String[] {null}); - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test",null}); - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); - - rs1 = new Result<ResultSet>(null,1,"test",new String[0]); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - daoObj.wasModified(trans, CRUD.delete, data, new String[] {"test","test"}); - } - - @Test - public void testSecondConstructor() { - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(psObj).exec(trans, "RoleDAOImpl CREATE", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "RoleDAOImpl UPDATE", data); + Mockito.doReturn(rs1).when(psObj).read(trans, "RoleDAOImpl READ", data); + Mockito.doReturn(rs1).when(psObj).exec(trans, "RoleDAOImpl DELETE", data); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + + Result<Void> rs2 = new Result<Void>(null,1,"test",new String[0]); + Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); + + rs1 = new Result<List<Data>>(null,1,"test",new String[0]); + Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); + Mockito.doReturn("test user").when(trans).user(); + + RoleDAO.Data perm = new RoleDAO.Data(); + Field cbField; + try { + cbField = CassAccess.class.getDeclaredField("cb"); + cbField.setAccessible(true); + cbField.set(daoObj, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Result<Void> retVal = daoObj.addDescription(trans, "test", "test", "test"); + assertTrue(retVal.status == 9); + + Field owningDaoField; + try { + owningDaoField = AbsCassDAO.class.getDeclaredField("owningDAO"); + owningDaoField.setAccessible(true); + owningDaoField.set(daoObj, null); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + retVal = daoObj.addDescription(trans, "test", "test", "test"); + assertTrue(retVal.status == 0); + } + + public void setPsByStartAndTarget(RoleDAO RoleDAOObj, PSInfo psInfoObj, String fieldName) { + Field RoleDAOField; + try { + RoleDAOField = RoleDAO.class.getDeclaredField(fieldName); + + RoleDAOField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(RoleDAOField, RoleDAOField.getModifiers() & ~Modifier.FINAL); + + RoleDAOField.set(RoleDAOObj, psInfoObj); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testWasModified() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("RoleDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on RoleDAO", Env.SUB); + Mockito.doReturn(tt).when(trans).start("DELETE Future",Env.REMOTE); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); + Mockito.doNothing().when(tt).done(); + RoleDAO.Data data = new RoleDAO.Data(); + PSInfo createPS = Mockito.mock(PSInfo.class); + + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); + Result<Void> rs2 = new Result<Void>(null,0,"test",new String[0]); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); + + RoleDAOImpl daoObj = null; + try { + daoObj = new RoleDAOImpl(trans, historyDAO, cacheInfoDAO, createPS ); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); + + daoObj.wasModified(trans, CRUD.create, data, new String[] {}); + daoObj.wasModified(trans, CRUD.create, data, new String[] {null}); + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test",null}); + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); + + rs1 = new Result<ResultSet>(null,1,"test",new String[0]); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + daoObj.wasModified(trans, CRUD.delete, data, new String[] {"test","test"}); + } + + @Test + public void testSecondConstructor() { + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - RoleDAO daoObj = new RoleDAO(trans, historyDAO, cacheInfoDAO); - - } + RoleDAO daoObj = new RoleDAO(trans, historyDAO, cacheInfoDAO); + + } - @Test - public void testFutureLoader(){ - Class<?> innerClass = null; - Class<?>[] innerClassArr = RoleDAO.class.getDeclaredClasses(); - for(Class indCls:innerClassArr) { - if(indCls.getName().contains("RoleLoader")) { - innerClass = indCls; - break; - } - } - + @Test + public void testFutureLoader(){ + Class<?> innerClass = null; + Class<?>[] innerClassArr = RoleDAO.class.getDeclaredClasses(); + for(Class indCls:innerClassArr) { + if(indCls.getName().contains("RoleLoader")) { + innerClass = indCls; + break; + } + } + Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); try { - - Object obj = constructor.newInstance(1); - Method innnerClassMtd; - - RoleDAO.Data data = new RoleDAO.Data(); - Row row = Mockito.mock(Row.class); - ByteBuffer bbObj = ByteBuffer.allocateDirect(10); - bbObj.limit(7); - bbObj.put(0, new Byte("0")); - bbObj.put(1, new Byte("1")); - bbObj.put(2, new Byte("2")); - Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); - - innnerClassMtd = innerClass.getMethod("load", new Class[] {RoleDAO.Data.class, Row.class}); - innnerClassMtd.invoke(obj, new Object[] {data, row}); - - innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {RoleDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test"} }); -// - innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {RoleDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {RoleDAO.Data.class, DataOutputStream.class }); - innnerClassMtd.invoke(obj, new Object[] {data, dos }); + + Object obj = constructor.newInstance(1); + Method innnerClassMtd; + + RoleDAO.Data data = new RoleDAO.Data(); + Row row = Mockito.mock(Row.class); + ByteBuffer bbObj = ByteBuffer.allocateDirect(10); + bbObj.limit(7); + bbObj.put(0, new Byte("0")); + bbObj.put(1, new Byte("1")); + bbObj.put(2, new Byte("2")); + Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); + + innnerClassMtd = innerClass.getMethod("load", new Class[] {RoleDAO.Data.class, Row.class}); + innnerClassMtd.invoke(obj, new Object[] {data, row}); + + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {RoleDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test"} }); +// + innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {RoleDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {RoleDAO.Data.class, DataOutputStream.class }); + innnerClassMtd.invoke(obj, new Object[] {data, dos }); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - DataInputStream dis = new DataInputStream(bais); - innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {RoleDAO.Data.class, DataInputStream.class }); - innnerClassMtd.invoke(obj, new Object[] {data, dis }); - - } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testData() { - RoleDAO.Data data = new RoleDAO.Data(); - NsSplit nss = new NsSplit("test", "test"); - data = new RoleDAO.Data(); - - data.toString(); - - - Question q = Mockito.mock( Question.class); - - Result<NsSplit> rs = new Result<NsSplit>(nss,0,"test",new Object[0]); - Mockito.doReturn(rs).when(q).deriveNsSplit(trans, "test"); - Result<Data> retVal= RoleDAO.Data.decode(trans, q, "test|||"); - assertTrue(retVal.status==0); - Result<String[]> retVal1= RoleDAO.Data.decodeToArray(trans, q, "test|||"); - assertTrue(retVal.status==0); - retVal= RoleDAO.Data.decode(trans, q, "test"); - retVal1= RoleDAO.Data.decodeToArray(trans, q, "test"); - assertTrue(retVal.status==0); - - rs = new Result<NsSplit>(nss,1,"test",new Object[0]); - Mockito.doReturn(rs).when(q).deriveNsSplit(trans, "test"); - retVal= RoleDAO.Data.decode(trans, q, "test"); - retVal1= RoleDAO.Data.decodeToArray(trans, q, "test"); - assertTrue(retVal.status==1); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + DataInputStream dis = new DataInputStream(bais); + innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {RoleDAO.Data.class, DataInputStream.class }); + innnerClassMtd.invoke(obj, new Object[] {data, dis }); + + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testData() { + RoleDAO.Data data = new RoleDAO.Data(); + NsSplit nss = new NsSplit("test", "test"); + data = new RoleDAO.Data(); + + data.toString(); + + + Question q = Mockito.mock( Question.class); + + Result<NsSplit> rs = new Result<NsSplit>(nss,0,"test",new Object[0]); + Mockito.doReturn(rs).when(q).deriveNsSplit(trans, "test"); + Result<Data> retVal= RoleDAO.Data.decode(trans, q, "test|||"); + assertTrue(retVal.status==0); + Result<String[]> retVal1= RoleDAO.Data.decodeToArray(trans, q, "test|||"); + assertTrue(retVal.status==0); + retVal= RoleDAO.Data.decode(trans, q, "test"); + retVal1= RoleDAO.Data.decodeToArray(trans, q, "test"); + assertTrue(retVal.status==0); + + rs = new Result<NsSplit>(nss,1,"test",new Object[0]); + Mockito.doReturn(rs).when(q).deriveNsSplit(trans, "test"); + retVal= RoleDAO.Data.decode(trans, q, "test"); + retVal1= RoleDAO.Data.decodeToArray(trans, q, "test"); + assertTrue(retVal.status==1); - retVal= RoleDAO.Data.decode(trans, q, "test"); - retVal1= RoleDAO.Data.decodeToArray(trans, q, "test"); - assertTrue(retVal.status==1); - - NsDAO.Data ns = new NsDAO.Data(); - ns.name="test"; - RoleDAO.Data.create(ns, "test"); + retVal= RoleDAO.Data.decode(trans, q, "test"); + retVal1= RoleDAO.Data.decodeToArray(trans, q, "test"); + assertTrue(retVal.status==1); + + NsDAO.Data ns = new NsDAO.Data(); + ns.name="test"; + RoleDAO.Data.create(ns, "test"); - UserRoleDAO.Data urdd = new UserRoleDAO.Data(); - urdd.ns="test"; - RoleDAO.Data dd=RoleDAO.Data.decode(urdd); - assertTrue("test".equals(dd.ns)); - - assertTrue(data.encode().contains("null")); - - data.perms = null; - data.perms(true); + UserRoleDAO.Data urdd = new UserRoleDAO.Data(); + urdd.ns="test"; + RoleDAO.Data dd=RoleDAO.Data.decode(urdd); + assertTrue("test".equals(dd.ns)); + + assertTrue(data.encode().contains("null")); + + data.perms = null; + data.perms(true); - data.perms = new HashSet<>(); - data.perms(true); + data.perms = new HashSet<>(); + data.perms(true); - data.perms(false); - data.perms = new TreeSet<>(); - data.perms(true); - } - + data.perms(false); + data.perms = new TreeSet<>(); + data.perms(true); + } + } class RoleDAOImpl extends RoleDAO{ - public RoleDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,CacheInfoDAO cacheDao, PSInfo readPS) throws APIException, IOException { - super(trans, historyDAO, cacheDao); - setPs(this, readPS, "createPS"); - } - - public RoleDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,CacheInfoDAO cacheDao, PSInfo readPS, Session session ) throws APIException, IOException { - super(trans, historyDAO, cacheDao); - setPs(this, readPS, "createPS"); - setSession(this, session); - } - + public RoleDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,CacheInfoDAO cacheDao, PSInfo readPS) throws APIException, IOException { + super(trans, historyDAO, cacheDao); + setPs(this, readPS, "createPS"); + } + + public RoleDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,CacheInfoDAO cacheDao, PSInfo readPS, Session session ) throws APIException, IOException { + super(trans, historyDAO, cacheDao); + setPs(this, readPS, "createPS"); + setSession(this, session); + } + - public void setPs(RoleDAOImpl RoleDAOObj, PSInfo psInfoObj, String methodName) { - Field RoleDAOField; - try { - RoleDAOField = CassDAOImpl.class.getDeclaredField(methodName); - - RoleDAOField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(RoleDAOField, RoleDAOField.getModifiers() & ~Modifier.FINAL); - - RoleDAOField.set(RoleDAOObj, psInfoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public void setSession(RoleDAOImpl approvalDaoObj, Session session) { - Field nsDaoField; - try { - nsDaoField = AbsCassDAO.class.getDeclaredField("session"); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(approvalDaoObj, session); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + public void setPs(RoleDAOImpl RoleDAOObj, PSInfo psInfoObj, String methodName) { + Field RoleDAOField; + try { + RoleDAOField = CassDAOImpl.class.getDeclaredField(methodName); + + RoleDAOField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(RoleDAOField, RoleDAOField.getModifiers() & ~Modifier.FINAL); + + RoleDAOField.set(RoleDAOObj, psInfoObj); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public void setSession(RoleDAOImpl approvalDaoObj, Session session) { + Field nsDaoField; + try { + nsDaoField = AbsCassDAO.class.getDeclaredField("session"); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(approvalDaoObj, session); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_UserRoleDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_UserRoleDAO.java index 8023fa9e..43496fd5 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_UserRoleDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_UserRoleDAO.java @@ -60,349 +60,349 @@ import com.datastax.driver.core.Session; public class JU_UserRoleDAO { - @Mock + @Mock AuthzTrans trans; - @Mock - Cluster cluster; - @Mock - Session session; - - @Before - public void setUp() throws APIException, IOException { - initMocks(this); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).init(); - Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LATITUDE); - Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LONGITUDE); - Mockito.doReturn(session).when(cluster).connect("test"); - } + @Mock + Cluster cluster; + @Mock + Session session; + + @Before + public void setUp() throws APIException, IOException { + initMocks(this); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).init(); + Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LATITUDE); + Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LONGITUDE); + Mockito.doReturn(session).when(cluster).connect("test"); + } - @Test - public void testInit() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("UserRoleDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on UserRoleDAO", Env.SUB); - try { - new UserRoleDAO(trans, cluster, "test"); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } -// daoObj. - } - @Test - public void testReadByUser() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("UserRoleDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on UserRoleDAO", Env.SUB); - UserRoleDAO daoObj = null; - try { - daoObj = new UserRoleDAO(trans, cluster, "test"); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - PSInfo psObj = Mockito.mock(PSInfo.class); - setPsByStartAndTarget(daoObj, psObj, "psByUser"); - - Result<List<UserRoleDAO.Data>> rs1 = new Result<List<UserRoleDAO.Data>>(null,0,"test",new Object[0]); - Mockito.doReturn(rs1).when(psObj).read(trans, "UserRoleDAO READ", new Object[]{"test"}); - - daoObj.readByUser(trans, "test"); - } - @Test - public void testReadByRole() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("UserRoleDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on UserRoleDAO", Env.SUB); - UserRoleDAO daoObj = null; - try { - daoObj = new UserRoleDAO(trans, cluster, "test"); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - PSInfo psObj = Mockito.mock(PSInfo.class); - setPsByStartAndTarget(daoObj, psObj, "psByRole"); - - Result<List<UserRoleDAO.Data>> rs1 = new Result<List<UserRoleDAO.Data>>(null,0,"test",new Object[0]); - Mockito.doReturn(rs1).when(psObj).read(trans, "UserRoleDAO READ", new Object[]{"test"}); - - daoObj.readByRole(trans, "test"); - } - @Test - public void testReadByUserRole() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("UserRoleDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on UserRoleDAO", Env.SUB); - UserRoleDAO daoObj = null; - try { - daoObj = new UserRoleDAO(trans, cluster, "test"); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - PSInfo psObj = Mockito.mock(PSInfo.class); - setPsByStartAndTarget(daoObj, psObj, "psUserInRole"); - - Result<List<UserRoleDAO.Data>> rs1 = new Result<List<UserRoleDAO.Data>>(null,0,"test",new Object[0]); - Mockito.doReturn(rs1).when(psObj).read(trans, "UserRoleDAO READ", new Object[]{"test"}); - - daoObj.readByUserRole(trans, "test","test"); - } - - - public void setPsByStartAndTarget(UserRoleDAO UserRoleDAOObj, PSInfo psInfoObj, String fieldName) { - Field UserRoleDAOField; - try { - UserRoleDAOField = UserRoleDAO.class.getDeclaredField(fieldName); - - UserRoleDAOField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(UserRoleDAOField, UserRoleDAOField.getModifiers() & ~Modifier.FINAL); - - UserRoleDAOField.set(UserRoleDAOObj, psInfoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testWasMOdified() { - TimeTaken tt = Mockito.mock(TimeTaken.class); - Mockito.doReturn(tt).when(trans).start("UserRoleDAO CREATE", Env.REMOTE); - Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); - Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); - Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on UserRoleDAO", Env.SUB); - Mockito.doReturn(tt).when(trans).start("DELETE Future",Env.REMOTE); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doNothing().when(tt).done(); - UserRoleDAO.Data data = new UserRoleDAO.Data(); - PSInfo createPS = Mockito.mock(PSInfo.class); - - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new Object[0]); - Result<Void> rs2 = new Result<Void>(null,0,"test",new Object[0]); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); - - UserRoleDAOImpl daoObj = null; - try { - daoObj = new UserRoleDAOImpl(trans, historyDAO, cacheInfoDAO, createPS ); - } catch (APIException | IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - - daoObj.wasModified(trans, CRUD.update, data, new String[] {}); - daoObj.wasModified(trans, CRUD.create, data, new String[] {null}); - daoObj.wasModified(trans, CRUD.create, data, new String[] {"test",null}); - daoObj.wasModified(trans, CRUD.update, data, new String[] {"test","test"}); + @Test + public void testInit() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("UserRoleDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on UserRoleDAO", Env.SUB); + try { + new UserRoleDAO(trans, cluster, "test"); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } +// daoObj. + } + @Test + public void testReadByUser() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("UserRoleDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on UserRoleDAO", Env.SUB); + UserRoleDAO daoObj = null; + try { + daoObj = new UserRoleDAO(trans, cluster, "test"); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + PSInfo psObj = Mockito.mock(PSInfo.class); + setPsByStartAndTarget(daoObj, psObj, "psByUser"); + + Result<List<UserRoleDAO.Data>> rs1 = new Result<List<UserRoleDAO.Data>>(null,0,"test",new Object[0]); + Mockito.doReturn(rs1).when(psObj).read(trans, "UserRoleDAO READ", new Object[]{"test"}); + + daoObj.readByUser(trans, "test"); + } + @Test + public void testReadByRole() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("UserRoleDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on UserRoleDAO", Env.SUB); + UserRoleDAO daoObj = null; + try { + daoObj = new UserRoleDAO(trans, cluster, "test"); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + PSInfo psObj = Mockito.mock(PSInfo.class); + setPsByStartAndTarget(daoObj, psObj, "psByRole"); + + Result<List<UserRoleDAO.Data>> rs1 = new Result<List<UserRoleDAO.Data>>(null,0,"test",new Object[0]); + Mockito.doReturn(rs1).when(psObj).read(trans, "UserRoleDAO READ", new Object[]{"test"}); + + daoObj.readByRole(trans, "test"); + } + @Test + public void testReadByUserRole() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("UserRoleDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on UserRoleDAO", Env.SUB); + UserRoleDAO daoObj = null; + try { + daoObj = new UserRoleDAO(trans, cluster, "test"); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + PSInfo psObj = Mockito.mock(PSInfo.class); + setPsByStartAndTarget(daoObj, psObj, "psUserInRole"); + + Result<List<UserRoleDAO.Data>> rs1 = new Result<List<UserRoleDAO.Data>>(null,0,"test",new Object[0]); + Mockito.doReturn(rs1).when(psObj).read(trans, "UserRoleDAO READ", new Object[]{"test"}); + + daoObj.readByUserRole(trans, "test","test"); + } + + + public void setPsByStartAndTarget(UserRoleDAO UserRoleDAOObj, PSInfo psInfoObj, String fieldName) { + Field UserRoleDAOField; + try { + UserRoleDAOField = UserRoleDAO.class.getDeclaredField(fieldName); + + UserRoleDAOField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(UserRoleDAOField, UserRoleDAOField.getModifiers() & ~Modifier.FINAL); + + UserRoleDAOField.set(UserRoleDAOObj, psInfoObj); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testWasMOdified() { + TimeTaken tt = Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(trans).start("UserRoleDAO CREATE", Env.REMOTE); + Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); + Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); + Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on UserRoleDAO", Env.SUB); + Mockito.doReturn(tt).when(trans).start("DELETE Future",Env.REMOTE); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); + Mockito.doNothing().when(tt).done(); + UserRoleDAO.Data data = new UserRoleDAO.Data(); + PSInfo createPS = Mockito.mock(PSInfo.class); + + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new Object[0]); + Result<Void> rs2 = new Result<Void>(null,0,"test",new Object[0]); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); + + UserRoleDAOImpl daoObj = null; + try { + daoObj = new UserRoleDAOImpl(trans, historyDAO, cacheInfoDAO, createPS ); + } catch (APIException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); + + daoObj.wasModified(trans, CRUD.update, data, new String[] {}); + daoObj.wasModified(trans, CRUD.create, data, new String[] {null}); + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test",null}); + daoObj.wasModified(trans, CRUD.update, data, new String[] {"test","test"}); - daoObj.wasModified(trans, CRUD.delete, data, new String[] {"test","test"}); - daoObj.wasModified(trans, CRUD.delete, data, new String[] {}); - - rs2 = new Result<Void>(null,1,"test",new Object[0]); - Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); - daoObj.wasModified(trans, CRUD.read, data, new String[] {"test","test"}); - daoObj.wasModified(trans, CRUD.read, data, new String[] {}); - - rs1 = new Result<ResultSet>(null,1,"test",new String[0]); - Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - daoObj.wasModified(trans, CRUD.delete, data, new String[] {"test","test"}); - } - - @Test - public void testSecondConstructor() { - HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); + daoObj.wasModified(trans, CRUD.delete, data, new String[] {"test","test"}); + daoObj.wasModified(trans, CRUD.delete, data, new String[] {}); + + rs2 = new Result<Void>(null,1,"test",new Object[0]); + Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); + daoObj.wasModified(trans, CRUD.read, data, new String[] {"test","test"}); + daoObj.wasModified(trans, CRUD.read, data, new String[] {}); + + rs1 = new Result<ResultSet>(null,1,"test",new String[0]); + Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); + daoObj.wasModified(trans, CRUD.delete, data, new String[] {"test","test"}); + } + + @Test + public void testSecondConstructor() { + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); - UserRoleDAO daoObj = new UserRoleDAO(trans, historyDAO, cacheInfoDAO); - - } + UserRoleDAO daoObj = new UserRoleDAO(trans, historyDAO, cacheInfoDAO); + + } - @Test - public void testFutureLoader(){ - Class<?> innerClass = null; - Class<?>[] innerClassArr = UserRoleDAO.class.getDeclaredClasses(); - for(Class indCls:innerClassArr) { - if(indCls.getName().contains("URLoader")) { - innerClass = indCls; - break; - } - } - + @Test + public void testFutureLoader(){ + Class<?> innerClass = null; + Class<?>[] innerClassArr = UserRoleDAO.class.getDeclaredClasses(); + for(Class indCls:innerClassArr) { + if(indCls.getName().contains("URLoader")) { + innerClass = indCls; + break; + } + } + Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); try { - - Object obj = constructor.newInstance(1); - Method innnerClassMtd; - - UserRoleDAO.Data data = new UserRoleDAO.Data(); - Row row = Mockito.mock(Row.class); - ByteBuffer bbObj = ByteBuffer.allocateDirect(10); - bbObj.limit(7); - bbObj.put(0, new Byte("0")); - bbObj.put(1, new Byte("1")); - bbObj.put(2, new Byte("2")); - Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); - - innnerClassMtd = innerClass.getMethod("load", new Class[] {UserRoleDAO.Data.class, Row.class}); - innnerClassMtd.invoke(obj, new Object[] {data, row}); - - innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {UserRoleDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test"} }); -// - innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {UserRoleDAO.Data.class, Integer.TYPE, Object[].class }); - innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {UserRoleDAO.Data.class, DataOutputStream.class }); - innnerClassMtd.invoke(obj, new Object[] {data, dos }); + + Object obj = constructor.newInstance(1); + Method innnerClassMtd; + + UserRoleDAO.Data data = new UserRoleDAO.Data(); + Row row = Mockito.mock(Row.class); + ByteBuffer bbObj = ByteBuffer.allocateDirect(10); + bbObj.limit(7); + bbObj.put(0, new Byte("0")); + bbObj.put(1, new Byte("1")); + bbObj.put(2, new Byte("2")); + Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); + + innnerClassMtd = innerClass.getMethod("load", new Class[] {UserRoleDAO.Data.class, Row.class}); + innnerClassMtd.invoke(obj, new Object[] {data, row}); + + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {UserRoleDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test"} }); +// + innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {UserRoleDAO.Data.class, Integer.TYPE, Object[].class }); + innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {UserRoleDAO.Data.class, DataOutputStream.class }); + innnerClassMtd.invoke(obj, new Object[] {data, dos }); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - DataInputStream dis = new DataInputStream(bais); - innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {UserRoleDAO.Data.class, DataInputStream.class }); - innnerClassMtd.invoke(obj, new Object[] {data, dis }); - - } catch (InstantiationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchMethodException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testData() { - UserRoleDAO.Data data = new UserRoleDAO.Data(); - NsSplit nss = new NsSplit("test", "test"); - data = new UserRoleDAO.Data(); - - data.toString(); - data.role("test", "test"); - assertTrue("test".equals(data.ns)); - - RoleDAO.Data rdd = new RoleDAO.Data(); - rdd.ns="test"; - data.role(rdd); - assertTrue("test".equals(data.ns)); - - Question q = Mockito.mock( Question.class); - Result<NsSplit> rs = new Result<NsSplit>(nss,0,"test",new Object[0]); - Mockito.doReturn(rs).when(q).deriveNsSplit(trans, "test"); - - data.role(trans, q, "test"); - - rs = new Result<NsSplit>(nss,1,"test",new Object[0]); - Mockito.doReturn(rs).when(q).deriveNsSplit(trans, "test"); - - data.role(trans, q, "test"); - } - + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + DataInputStream dis = new DataInputStream(bais); + innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {UserRoleDAO.Data.class, DataInputStream.class }); + innnerClassMtd.invoke(obj, new Object[] {data, dis }); + + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NoSuchMethodException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testData() { + UserRoleDAO.Data data = new UserRoleDAO.Data(); + NsSplit nss = new NsSplit("test", "test"); + data = new UserRoleDAO.Data(); + + data.toString(); + data.role("test", "test"); + assertTrue("test".equals(data.ns)); + + RoleDAO.Data rdd = new RoleDAO.Data(); + rdd.ns="test"; + data.role(rdd); + assertTrue("test".equals(data.ns)); + + Question q = Mockito.mock( Question.class); + Result<NsSplit> rs = new Result<NsSplit>(nss,0,"test",new Object[0]); + Mockito.doReturn(rs).when(q).deriveNsSplit(trans, "test"); + + data.role(trans, q, "test"); + + rs = new Result<NsSplit>(nss,1,"test",new Object[0]); + Mockito.doReturn(rs).when(q).deriveNsSplit(trans, "test"); + + data.role(trans, q, "test"); + } + } class UserRoleDAOImpl extends UserRoleDAO{ - public UserRoleDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,CacheInfoDAO cacheDao, PSInfo readPS) throws APIException, IOException { - super(trans, historyDAO, cacheDao); - setPs(this, readPS, "createPS"); - } - - public UserRoleDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,CacheInfoDAO cacheDao, PSInfo readPS, Session session ) throws APIException, IOException { - super(trans, historyDAO, cacheDao); - setPs(this, readPS, "createPS"); - setSession(this, session); - } - + public UserRoleDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,CacheInfoDAO cacheDao, PSInfo readPS) throws APIException, IOException { + super(trans, historyDAO, cacheDao); + setPs(this, readPS, "createPS"); + } + + public UserRoleDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,CacheInfoDAO cacheDao, PSInfo readPS, Session session ) throws APIException, IOException { + super(trans, historyDAO, cacheDao); + setPs(this, readPS, "createPS"); + setSession(this, session); + } + - public void setPs(UserRoleDAOImpl UserRoleDAOObj, PSInfo psInfoObj, String methodName) { - Field UserRoleDAOField; - try { - UserRoleDAOField = CassDAOImpl.class.getDeclaredField(methodName); - - UserRoleDAOField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(UserRoleDAOField, UserRoleDAOField.getModifiers() & ~Modifier.FINAL); - - UserRoleDAOField.set(UserRoleDAOObj, psInfoObj); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public void setSession(UserRoleDAOImpl approvalDaoObj, Session session) { - Field nsDaoField; - try { - nsDaoField = AbsCassDAO.class.getDeclaredField("session"); - - nsDaoField.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); -// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - - nsDaoField.set(approvalDaoObj, session); - } catch (NoSuchFieldException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + public void setPs(UserRoleDAOImpl UserRoleDAOObj, PSInfo psInfoObj, String methodName) { + Field UserRoleDAOField; + try { + UserRoleDAOField = CassDAOImpl.class.getDeclaredField(methodName); + + UserRoleDAOField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(UserRoleDAOField, UserRoleDAOField.getModifiers() & ~Modifier.FINAL); + + UserRoleDAOField.set(UserRoleDAOObj, psInfoObj); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public void setSession(UserRoleDAOImpl approvalDaoObj, Session session) { + Field nsDaoField; + try { + nsDaoField = AbsCassDAO.class.getDeclaredField("session"); + + nsDaoField.setAccessible(true); + // remove final modifier from field + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); +// modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); + + nsDaoField.set(approvalDaoObj, session); + } catch (NoSuchFieldException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_CassExecutor.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_CassExecutor.java index 56cc2b0e..6d029933 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_CassExecutor.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_CassExecutor.java @@ -46,111 +46,111 @@ import org.onap.aaf.cadi.CadiException; @RunWith(MockitoJUnitRunner.class) public class JU_CassExecutor { - - - private static final Object NO_PARAM = new Object[0]; + + + private static final Object NO_PARAM = new Object[0]; - @Mock - AuthzTransImpl trans; - - @Mock - Question q; - - @Mock - Access access; - - Function f; - - @Before - public void setUp() throws Exception { - initMocks(this); - try { - Mockito.doReturn("0.0").when(access).getProperty("aaf_root_ns","org.osaaf.aaf"); - Mockito.doReturn(new Properties()).when(access).getProperties(); - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - f =new Function(trans, q); - } - - @Test - public void testHasPermission() { - - CassExecutor cassExecutorObj =new CassExecutor(trans, f); - Mockito.doReturn(false).when(q).isGranted(trans, "","","","",""); - boolean retVal = cassExecutorObj.hasPermission("", "", "", "", ""); -// System.out.println(retVal); - assertFalse(retVal); - } - - @Test - public void testInRole() { - - CassExecutor cassExecutorObj =new CassExecutor(trans, f); - Result<NsSplit> retVal1 = new Result<NsSplit>(null,1,"",NO_PARAM); - Mockito.doReturn(retVal1).when(q).deriveNsSplit(trans, "test"); - - boolean retVal = cassExecutorObj.inRole("test"); -// System.out.println(retVal); - assertFalse(retVal); - } - - @Test - public void testNamespace() { - f =new Function(trans, q); - CassExecutor cassExecutorObj =new CassExecutor(trans, f); - Result<Data> retVal1 = new Result<Data>(null,1,"",NO_PARAM); - Mockito.doReturn(retVal1).when(q).validNSOfDomain(trans, null); - - String retVal=""; - try { - retVal = cassExecutorObj.namespace(); - } catch (Exception e) { - System.out.println(e.getMessage()); - assertEquals("33", e.getMessage()); - } - System.out.println(retVal); -// assertFalse(retVal); - } - - @Test - public void testId() { - Mockito.doReturn("").when(trans).user(); - CassExecutor cassExecutorObj =new CassExecutor(trans, f); - String retVal = cassExecutorObj.id(); - assertEquals("", retVal); - } - - @Test - public void testNamespaceSuccess() { - Mockito.doAnswer(new Answer<Object>() { - private int count = 0; + @Mock + AuthzTransImpl trans; + + @Mock + Question q; + + @Mock + Access access; + + Function f; + + @Before + public void setUp() throws Exception { + initMocks(this); + try { + Mockito.doReturn("0.0").when(access).getProperty("aaf_root_ns","org.osaaf.aaf"); + Mockito.doReturn(new Properties()).when(access).getProperties(); + Define.set(access); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + f =new Function(trans, q); + } + + @Test + public void testHasPermission() { + + CassExecutor cassExecutorObj =new CassExecutor(trans, f); + Mockito.doReturn(false).when(q).isGranted(trans, "","","","",""); + boolean retVal = cassExecutorObj.hasPermission("", "", "", "", ""); +// System.out.println(retVal); + assertFalse(retVal); + } + + @Test + public void testInRole() { + + CassExecutor cassExecutorObj =new CassExecutor(trans, f); + Result<NsSplit> retVal1 = new Result<NsSplit>(null,1,"",NO_PARAM); + Mockito.doReturn(retVal1).when(q).deriveNsSplit(trans, "test"); + + boolean retVal = cassExecutorObj.inRole("test"); +// System.out.println(retVal); + assertFalse(retVal); + } + + @Test + public void testNamespace() { + f =new Function(trans, q); + CassExecutor cassExecutorObj =new CassExecutor(trans, f); + Result<Data> retVal1 = new Result<Data>(null,1,"",NO_PARAM); + Mockito.doReturn(retVal1).when(q).validNSOfDomain(trans, null); + + String retVal=""; + try { + retVal = cassExecutorObj.namespace(); + } catch (Exception e) { + System.out.println(e.getMessage()); + assertEquals("33", e.getMessage()); + } + System.out.println(retVal); +// assertFalse(retVal); + } + + @Test + public void testId() { + Mockito.doReturn("").when(trans).user(); + CassExecutor cassExecutorObj =new CassExecutor(trans, f); + String retVal = cassExecutorObj.id(); + assertEquals("", retVal); + } + + @Test + public void testNamespaceSuccess() { + Mockito.doAnswer(new Answer<Object>() { + private int count = 0; - public Object answer(InvocationOnMock invocation) { - if (count++ == 1) - return "test@test.com"; + public Object answer(InvocationOnMock invocation) { + if (count++ == 1) + return "test@test.com"; - return null; - } - }).when(trans).user(); - f =new Function(trans, q); - CassExecutor cassExecutorObj =new CassExecutor(trans, f); - Result<Data> retVal1 = new Result<Data>(null,0,"",NO_PARAM); - Mockito.doReturn(retVal1).when(q).validNSOfDomain(trans, null); - - -// String retVal=""; - try { - /*retVal =*/ cassExecutorObj.namespace(); - } catch (Exception e) { - e.printStackTrace(); - System.out.println(e.getMessage()); -// assertNull( e.getMessage()); - } -// System.out.println(retVal); -// assertFalse(retVal); - } - + return null; + } + }).when(trans).user(); + f =new Function(trans, q); + CassExecutor cassExecutorObj =new CassExecutor(trans, f); + Result<Data> retVal1 = new Result<Data>(null,0,"",NO_PARAM); + Mockito.doReturn(retVal1).when(q).validNSOfDomain(trans, null); + + +// String retVal=""; + try { + /*retVal =*/ cassExecutorObj.namespace(); + } catch (Exception e) { + e.printStackTrace(); + System.out.println(e.getMessage()); +// assertNull( e.getMessage()); + } +// System.out.println(retVal); +// assertFalse(retVal); + } + }
\ No newline at end of file diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_Function.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_Function.java index ab7b2e59..bfa5838c 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_Function.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_Function.java @@ -80,1619 +80,1619 @@ import org.onap.aaf.misc.env.LogTarget; public class JU_Function { - private static final Object NO_PARAM = new Object[0]; - - @Mock + private static final Object NO_PARAM = new Object[0]; + + @Mock AuthzTrans trans; - @Mock - PropAccess access; - - @Mock - Question ques; - - @Mock - Organization org; - - @Mock - CachedNSDAO nsDAO; - - @Mock - CachedRoleDAO roleDAO; + @Mock + PropAccess access; + + @Mock + Question ques; + + @Mock + Organization org; + + @Mock + CachedNSDAO nsDAO; + + @Mock + CachedRoleDAO roleDAO; - @Mock - CachedPermDAO permDAO; + @Mock + CachedPermDAO permDAO; - @Mock - CachedCredDAO credDAO; + @Mock + CachedCredDAO credDAO; - @Mock - CachedUserRoleDAO userRoleDAO; + @Mock + CachedUserRoleDAO userRoleDAO; - @Mock - ApprovalDAO approvalDAO; + @Mock + ApprovalDAO approvalDAO; - @Mock - FutureDAO futureDAO; + @Mock + FutureDAO futureDAO; - @Before - public void setUp() throws APIException, IOException { - initMocks(this); - Mockito.doReturn(org).when(trans).org(); - Mockito.doReturn(nsDAO).when(ques).nsDAO(); - Mockito.doReturn(roleDAO).when(ques).roleDAO(); - Mockito.doReturn(permDAO).when(ques).permDAO(); - Mockito.doReturn(credDAO).when(ques).credDAO(); - Mockito.doReturn(userRoleDAO).when(ques).userRoleDAO(); - Mockito.doReturn(approvalDAO).when(ques).approvalDAO(); - Mockito.doReturn(futureDAO).when(ques).futureDAO(); + @Before + public void setUp() throws APIException, IOException { + initMocks(this); + Mockito.doReturn(org).when(trans).org(); + Mockito.doReturn(nsDAO).when(ques).nsDAO(); + Mockito.doReturn(roleDAO).when(ques).roleDAO(); + Mockito.doReturn(permDAO).when(ques).permDAO(); + Mockito.doReturn(credDAO).when(ques).credDAO(); + Mockito.doReturn(userRoleDAO).when(ques).userRoleDAO(); + Mockito.doReturn(approvalDAO).when(ques).approvalDAO(); + Mockito.doReturn(futureDAO).when(ques).futureDAO(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - - try { - Define.set(access); - } catch (CadiException e) { - } - } + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); + Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); + Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); + + try { + Define.set(access); + } catch (CadiException e) { + } + } - @Test - public void testCreateNs() { - Namespace namespace = Mockito.mock(Namespace.class); - namespace.name = "test.test"; - List<String> owner = new ArrayList<String>(); - namespace.owner = owner; + @Test + public void testCreateNs() { + Namespace namespace = Mockito.mock(Namespace.class); + namespace.name = "test.test"; + List<String> owner = new ArrayList<String>(); + namespace.owner = owner; - Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(roleDAO).read(trans, "test","test"); - Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(permDAO).readByType(trans, "test","test"); + Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(roleDAO).read(trans, "test","test"); + Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(permDAO).readByType(trans, "test","test"); - NsDAO.Data data = new NsDAO.Data(); - data.name="test"; - Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); - Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); + NsDAO.Data data = new NsDAO.Data(); + data.name="test"; + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); + Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - Result<Void> retVal = new Result<Void>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - //setQuestion(ques, cachedNS); - - Function funcObj = new Function(trans, ques); - Result<Void> result = funcObj.createNS(trans, namespace, true); - assertTrue(3 == result.status); - } - - @Test - public void testCreateNsReadSuccess() { - Namespace namespace = Mockito.mock(Namespace.class); - namespace.name = "test.test"; - List<String> owner = new ArrayList<String>(); - owner.add("test"); - namespace.owner = owner; - List<String> admin = new ArrayList<String>(); - admin.add("test"); - namespace.admin= admin; - - Organization org = Mockito.mock(Organization.class); - Mockito.doReturn(org).when(trans).org(); - - NsDAO.Data data = new NsDAO.Data(); - data.name="test"; - Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); - Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); + Result<Void> retVal = new Result<Void>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + //setQuestion(ques, cachedNS); + + Function funcObj = new Function(trans, ques); + Result<Void> result = funcObj.createNS(trans, namespace, true); + assertTrue(3 == result.status); + } + + @Test + public void testCreateNsReadSuccess() { + Namespace namespace = Mockito.mock(Namespace.class); + namespace.name = "test.test"; + List<String> owner = new ArrayList<String>(); + owner.add("test"); + namespace.owner = owner; + List<String> admin = new ArrayList<String>(); + admin.add("test"); + namespace.admin= admin; + + Organization org = Mockito.mock(Organization.class); + Mockito.doReturn(org).when(trans).org(); + + NsDAO.Data data = new NsDAO.Data(); + data.name="test"; + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); + Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - Result<Void> retVal = new Result<Void>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - - Function funcObj = new Function(trans, ques); - Result<Void> result = funcObj.createNS(trans, namespace, true); - assertTrue(3 == result.status); - } - - @Test - public void testCreateNsFromApprovaFalse() { - Namespace namespace = Mockito.mock(Namespace.class); - namespace.name = "test.test"; - List<String> owner = new ArrayList<String>(); - namespace.owner = owner; - - Organization org = Mockito.mock(Organization.class); - Mockito.doReturn(org).when(trans).org(); - - NsDAO.Data data = new NsDAO.Data(); - data.name="test"; - Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); - Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal1.value, Access.write); - - Function funcObj = new Function(trans, ques); - Result<Void> result = funcObj.createNS(trans, namespace, false); - assertTrue(1 == result.status); - - Mockito.doReturn(retVal2).when(ques).deriveNs(trans, "test"); - funcObj = new Function(trans, ques); - result = funcObj.createNS(trans, namespace, false); - assertTrue(1 == result.status); - } - - @Test - public void testCreateNsownerLoop() { - Namespace namespace = Mockito.mock(Namespace.class); - namespace.name = "test.test"; - List<String> owner = new ArrayList<String>(); - owner.add("test"); - namespace.owner = owner; - - Organization org = Mockito.mock(Organization.class); - Mockito.doReturn(org).when(trans).org(); - Mockito.doReturn(org).when(trans).org(); - - Function funcObj = new Function(trans, ques); - Result<Void> result = funcObj.createNS(trans, namespace, true); - assertTrue(result.status == Status.ERR_Policy); - assertTrue(result.details.contains("is not a valid user at")); - - Identity iden=Mockito.mock(Identity.class); - try { - Mockito.doReturn(iden).when(org).getIdentity(trans, "test"); - Mockito.doReturn("test").when(iden).mayOwn(); - } catch (OrganizationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - result = funcObj.createNS(trans, namespace, true); - assertTrue(result.status == Status.ERR_Policy); - assertTrue(result.details.contains("is an invalid Identity")); + Result<Void> retVal = new Result<Void>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + + Function funcObj = new Function(trans, ques); + Result<Void> result = funcObj.createNS(trans, namespace, true); + assertTrue(3 == result.status); + } + + @Test + public void testCreateNsFromApprovaFalse() { + Namespace namespace = Mockito.mock(Namespace.class); + namespace.name = "test.test"; + List<String> owner = new ArrayList<String>(); + namespace.owner = owner; + + Organization org = Mockito.mock(Organization.class); + Mockito.doReturn(org).when(trans).org(); + + NsDAO.Data data = new NsDAO.Data(); + data.name="test"; + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); + Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); + Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal1.value, Access.write); + + Function funcObj = new Function(trans, ques); + Result<Void> result = funcObj.createNS(trans, namespace, false); + assertTrue(1 == result.status); + + Mockito.doReturn(retVal2).when(ques).deriveNs(trans, "test"); + funcObj = new Function(trans, ques); + result = funcObj.createNS(trans, namespace, false); + assertTrue(1 == result.status); + } + + @Test + public void testCreateNsownerLoop() { + Namespace namespace = Mockito.mock(Namespace.class); + namespace.name = "test.test"; + List<String> owner = new ArrayList<String>(); + owner.add("test"); + namespace.owner = owner; + + Organization org = Mockito.mock(Organization.class); + Mockito.doReturn(org).when(trans).org(); + Mockito.doReturn(org).when(trans).org(); + + Function funcObj = new Function(trans, ques); + Result<Void> result = funcObj.createNS(trans, namespace, true); + assertTrue(result.status == Status.ERR_Policy); + assertTrue(result.details.contains("is not a valid user at")); + + Identity iden=Mockito.mock(Identity.class); + try { + Mockito.doReturn(iden).when(org).getIdentity(trans, "test"); + Mockito.doReturn("test").when(iden).mayOwn(); + } catch (OrganizationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + result = funcObj.createNS(trans, namespace, true); + assertTrue(result.status == Status.ERR_Policy); + assertTrue(result.details.contains("is an invalid Identity")); - Mockito.doReturn(true).when(iden).isFound(); - result = funcObj.createNS(trans, namespace, true); - assertTrue(result.status == Status.ERR_Policy); - assertTrue(result.details.contains("cannot be the owner of the namespace ")); - - Mockito.doReturn(true).when(org).isTestEnv(); - try { - Mockito.doReturn("test").when(org).validate(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); - result = funcObj.createNS(trans, namespace, true); - assertTrue(result.status == Status.ERR_Policy); - assertTrue(result.details.contains("cannot be the owner of the namespace ")); - } catch (OrganizationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testCreateNsownerLoopException() { - Namespace namespace = Mockito.mock(Namespace.class); - namespace.name = "test"; - List<String> owner = new ArrayList<String>(); - owner.add("test"); - namespace.owner = owner; - - Organization org = Mockito.mock(Organization.class); - Mockito.doReturn(org).when(trans).org(); - - Function funcObj = new Function(trans, ques); - - Identity iden=Mockito.mock(Identity.class); - try { - Mockito.doThrow(new OrganizationException()).when(org).getIdentity(trans, "test"); - Mockito.doReturn("test").when(iden).mayOwn(); - } catch (OrganizationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - NsDAO.Data data = new NsDAO.Data(); - data.name="test"; - Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); - Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - - Result<Void> result = funcObj.createNS(trans, namespace, true); - assertTrue(result.status == Status.ERR_Security); - assertTrue(result.details.contains("may not create Root Namespaces")); - - Mockito.doReturn(true).when(ques).isGranted(Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); - retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); - Mockito.doReturn(retVal1).when(ques).deriveNs(trans, null); - - Result<Void> retVal = new Result<Void>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - - result = funcObj.createNS(trans, namespace, true); - assertTrue(24 == result.status); - - } + Mockito.doReturn(true).when(iden).isFound(); + result = funcObj.createNS(trans, namespace, true); + assertTrue(result.status == Status.ERR_Policy); + assertTrue(result.details.contains("cannot be the owner of the namespace ")); + + Mockito.doReturn(true).when(org).isTestEnv(); + try { + Mockito.doReturn("test").when(org).validate(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); + result = funcObj.createNS(trans, namespace, true); + assertTrue(result.status == Status.ERR_Policy); + assertTrue(result.details.contains("cannot be the owner of the namespace ")); + } catch (OrganizationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testCreateNsownerLoopException() { + Namespace namespace = Mockito.mock(Namespace.class); + namespace.name = "test"; + List<String> owner = new ArrayList<String>(); + owner.add("test"); + namespace.owner = owner; + + Organization org = Mockito.mock(Organization.class); + Mockito.doReturn(org).when(trans).org(); + + Function funcObj = new Function(trans, ques); + + Identity iden=Mockito.mock(Identity.class); + try { + Mockito.doThrow(new OrganizationException()).when(org).getIdentity(trans, "test"); + Mockito.doReturn("test").when(iden).mayOwn(); + } catch (OrganizationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + NsDAO.Data data = new NsDAO.Data(); + data.name="test"; + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); + Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); + + Result<Void> result = funcObj.createNS(trans, namespace, true); + assertTrue(result.status == Status.ERR_Security); + assertTrue(result.details.contains("may not create Root Namespaces")); + + Mockito.doReturn(true).when(ques).isGranted(Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); + retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); + Mockito.doReturn(retVal1).when(ques).deriveNs(trans, null); + + Result<Void> retVal = new Result<Void>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + + result = funcObj.createNS(trans, namespace, true); + assertTrue(24 == result.status); + + } - @Test - public void testCreateNsAdminLoop() { - Namespace namespace = Mockito.mock(Namespace.class); - namespace.name = "test.test"; - List<String> owner = new ArrayList<String>(); - owner.add("test"); - namespace.owner = owner; - namespace.admin = owner; - - Organization org = Mockito.mock(Organization.class); - Mockito.doReturn(org).when(trans).org(); - - NsDAO.Data data = new NsDAO.Data(); - data.name="test"; - Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); - Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - - Result<Void> retVal = new Result<Void>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retVal).when(nsDAO).create(Mockito.any(), Mockito.any()); - List<CredDAO.Data> dataObj = new ArrayList<>(); - CredDAO.Data indData = new CredDAO.Data(); - indData.id = "test"; - indData.notes = "test"; - DateFormat sdf = new SimpleDateFormat("yyyy/mm/dd"); - try { - indData.expires = sdf.parse("2090/01/01"); - } catch (ParseException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - dataObj.add(indData); - Result<List<CredDAO.Data>> retVal2 = new Result<List<CredDAO.Data>>(dataObj,0,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(credDAO).readID(Mockito.any(), Mockito.anyString()); - - Identity iden=Mockito.mock(Identity.class); - try { - Mockito.doReturn(iden).when(org).getIdentity(trans, "test"); - Mockito.doReturn("test").when(iden).mayOwn(); - Mockito.doReturn(true).when(org).isTestEnv(); - } catch (OrganizationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(roleDAO).read(trans, "test","test"); - Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(permDAO).readByType(trans, "test","test"); + @Test + public void testCreateNsAdminLoop() { + Namespace namespace = Mockito.mock(Namespace.class); + namespace.name = "test.test"; + List<String> owner = new ArrayList<String>(); + owner.add("test"); + namespace.owner = owner; + namespace.admin = owner; + + Organization org = Mockito.mock(Organization.class); + Mockito.doReturn(org).when(trans).org(); + + NsDAO.Data data = new NsDAO.Data(); + data.name="test"; + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); + Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); + + Result<Void> retVal = new Result<Void>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal).when(nsDAO).create(Mockito.any(), Mockito.any()); + List<CredDAO.Data> dataObj = new ArrayList<>(); + CredDAO.Data indData = new CredDAO.Data(); + indData.id = "test"; + indData.notes = "test"; + DateFormat sdf = new SimpleDateFormat("yyyy/mm/dd"); + try { + indData.expires = sdf.parse("2090/01/01"); + } catch (ParseException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + dataObj.add(indData); + Result<List<CredDAO.Data>> retVal2 = new Result<List<CredDAO.Data>>(dataObj,0,"test",NO_PARAM); + Mockito.doReturn(retVal2).when(credDAO).readID(Mockito.any(), Mockito.anyString()); + + Identity iden=Mockito.mock(Identity.class); + try { + Mockito.doReturn(iden).when(org).getIdentity(trans, "test"); + Mockito.doReturn("test").when(iden).mayOwn(); + Mockito.doReturn(true).when(org).isTestEnv(); + } catch (OrganizationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(roleDAO).read(trans, "test","test"); + Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(permDAO).readByType(trans, "test","test"); - Function funcObj = new Function(trans, ques); - Result<Void> result = funcObj.createNS(trans, namespace, true); - assertTrue(result.status == 1); - - } - - @Test - public void testCreateNsAdminLoopCreateSucReadChildrenFailure() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); - Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); - Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Namespace namespace = Mockito.mock(Namespace.class); - namespace.name = "test.test"; - List<String> owner = new ArrayList<String>(); - owner.add("test"); - namespace.owner = owner; - namespace.admin = owner; - - Organization org = Mockito.mock(Organization.class); - Mockito.doReturn(org).when(trans).org(); - - NsDAO.Data data = new NsDAO.Data(); - data.name="test"; - Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); - Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - - Result<Void> retVal = new Result<Void>(null,0,"test",NO_PARAM); - Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retVal).when(nsDAO).create(Mockito.any(), Mockito.any()); - List<CredDAO.Data> dataObj = new ArrayList<>(); - CredDAO.Data indData = new CredDAO.Data(); - indData.id = "test"; - indData.notes = "test"; - DateFormat sdf = new SimpleDateFormat("yyyy/mm/dd"); - try { - indData.expires = sdf.parse("2090/01/01"); - } catch (ParseException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - dataObj.add(indData); - List<RoleDAO.Data> dataObj1 = new ArrayList<>(); - RoleDAO.Data indData1 = new RoleDAO.Data(); - indData1.ns = "test"; - indData1.name = "test"; - Set<String> permsSet = new HashSet<>(); - permsSet.add("test|test"); - indData1.perms = permsSet; - dataObj1.add(indData1); - - List<UserRoleDAO.Data> dataObj4 = new ArrayList<>(); - UserRoleDAO.Data indData4 = new UserRoleDAO.Data(); - indData4.ns = "test"; - indData4.rname = "test"; - dataObj4.add(indData4); - - List<PermDAO.Data> dataObj5 = new ArrayList<>(); - PermDAO.Data indData5 = new PermDAO.Data(); - indData5.ns = "test"; - indData5.type = "test"; - dataObj5.add(indData5); - - Result<List<CredDAO.Data>> retVal2 = new Result<List<CredDAO.Data>>(dataObj,0,"test",NO_PARAM); - Result<List<CredDAO.Data>> retVal6 = new Result<List<CredDAO.Data>>(dataObj,1,"test",NO_PARAM); - Result<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(dataObj1,0,"test",NO_PARAM); - Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(dataObj4,0,"test",NO_PARAM); - Result<List<PermDAO.Data>> retVal5 = new Result<List<PermDAO.Data>>(dataObj5,0,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(credDAO).readID(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retVal2).when(userRoleDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal6).when(roleDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal6).when(roleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); - Mockito.doReturn(retVal2).when(permDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal5).when(permDAO).readChildren(trans, "test", "test"); - Mockito.doReturn(retVal5).when(permDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); - Mockito.doReturn(retVal3).when(roleDAO).readChildren(trans, "test", "test"); - - Identity iden=Mockito.mock(Identity.class); - try { - Mockito.doReturn(iden).when(org).getIdentity(trans, "test"); - Mockito.doReturn("test").when(iden).mayOwn(); - Mockito.doReturn(true).when(org).isTestEnv(); - Mockito.doReturn(new GregorianCalendar(2010, 01, 01)).when(org).expiration(null, Expiration.UserInRole); - } catch (OrganizationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Function funcObj = new Function(trans, ques); - Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(roleDAO).read(trans, "test","test"); - Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(permDAO).readByType(trans, "test","test"); + Function funcObj = new Function(trans, ques); + Result<Void> result = funcObj.createNS(trans, namespace, true); + assertTrue(result.status == 1); + + } + + @Test + public void testCreateNsAdminLoopCreateSucReadChildrenFailure() { + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); + Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); + Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); + try { + Define.set(access); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Namespace namespace = Mockito.mock(Namespace.class); + namespace.name = "test.test"; + List<String> owner = new ArrayList<String>(); + owner.add("test"); + namespace.owner = owner; + namespace.admin = owner; + + Organization org = Mockito.mock(Organization.class); + Mockito.doReturn(org).when(trans).org(); + + NsDAO.Data data = new NsDAO.Data(); + data.name="test"; + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); + Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); + + Result<Void> retVal = new Result<Void>(null,0,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal).when(nsDAO).create(Mockito.any(), Mockito.any()); + List<CredDAO.Data> dataObj = new ArrayList<>(); + CredDAO.Data indData = new CredDAO.Data(); + indData.id = "test"; + indData.notes = "test"; + DateFormat sdf = new SimpleDateFormat("yyyy/mm/dd"); + try { + indData.expires = sdf.parse("2090/01/01"); + } catch (ParseException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + dataObj.add(indData); + List<RoleDAO.Data> dataObj1 = new ArrayList<>(); + RoleDAO.Data indData1 = new RoleDAO.Data(); + indData1.ns = "test"; + indData1.name = "test"; + Set<String> permsSet = new HashSet<>(); + permsSet.add("test|test"); + indData1.perms = permsSet; + dataObj1.add(indData1); + + List<UserRoleDAO.Data> dataObj4 = new ArrayList<>(); + UserRoleDAO.Data indData4 = new UserRoleDAO.Data(); + indData4.ns = "test"; + indData4.rname = "test"; + dataObj4.add(indData4); + + List<PermDAO.Data> dataObj5 = new ArrayList<>(); + PermDAO.Data indData5 = new PermDAO.Data(); + indData5.ns = "test"; + indData5.type = "test"; + dataObj5.add(indData5); + + Result<List<CredDAO.Data>> retVal2 = new Result<List<CredDAO.Data>>(dataObj,0,"test",NO_PARAM); + Result<List<CredDAO.Data>> retVal6 = new Result<List<CredDAO.Data>>(dataObj,1,"test",NO_PARAM); + Result<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(dataObj1,0,"test",NO_PARAM); + Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(dataObj4,0,"test",NO_PARAM); + Result<List<PermDAO.Data>> retVal5 = new Result<List<PermDAO.Data>>(dataObj5,0,"test",NO_PARAM); + Mockito.doReturn(retVal2).when(credDAO).readID(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal2).when(userRoleDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal6).when(roleDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal6).when(roleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + Mockito.doReturn(retVal2).when(permDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal5).when(permDAO).readChildren(trans, "test", "test"); + Mockito.doReturn(retVal5).when(permDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + Mockito.doReturn(retVal3).when(roleDAO).readChildren(trans, "test", "test"); + + Identity iden=Mockito.mock(Identity.class); + try { + Mockito.doReturn(iden).when(org).getIdentity(trans, "test"); + Mockito.doReturn("test").when(iden).mayOwn(); + Mockito.doReturn(true).when(org).isTestEnv(); + Mockito.doReturn(new GregorianCalendar(2010, 01, 01)).when(org).expiration(null, Expiration.UserInRole); + } catch (OrganizationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Function funcObj = new Function(trans, ques); + Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(roleDAO).read(trans, "test","test"); + Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(permDAO).readByType(trans, "test","test"); - Result<Void> result = funcObj.createNS(trans, namespace, true); - assertTrue(result.status == Status.ERR_ActionNotCompleted); - - } - - @Test - public void testCreateNsAdminLoopCreateSuc() { - Namespace namespace = Mockito.mock(Namespace.class); - namespace.name = "test.test"; - List<String> owner = new ArrayList<String>(); - owner.add("test"); - namespace.owner = owner; - namespace.admin = owner; - - Organization org = Mockito.mock(Organization.class); - Mockito.doReturn(org).when(trans).org(); - - NsDAO.Data data = new NsDAO.Data(); - data.name="test"; - Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); - Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - - Result<Void> retVal = new Result<Void>(null,0,"test",NO_PARAM); - Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retVal).when(nsDAO).create(Mockito.any(), Mockito.any()); - List<CredDAO.Data> dataObj = new ArrayList<>(); - CredDAO.Data indData = new CredDAO.Data(); - indData.id = "test"; - indData.notes = "test"; - DateFormat sdf = new SimpleDateFormat("yyyy/mm/dd"); - try { - indData.expires = sdf.parse("2090/01/01"); - } catch (ParseException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - dataObj.add(indData); - List<RoleDAO.Data> dataObj1 = new ArrayList<>(); - RoleDAO.Data indData1 = new RoleDAO.Data(); - indData1.ns = "test"; - indData1.name = "test"; - Set<String> permsSet = new HashSet<>(); - permsSet.add("test|test|test|test"); - indData1.perms = permsSet; - dataObj1.add(indData1); - - List<UserRoleDAO.Data> dataObj4 = new ArrayList<>(); - UserRoleDAO.Data indData4 = new UserRoleDAO.Data(); - indData4.ns = "test"; - indData4.rname = "test"; - dataObj4.add(indData4); - - List<PermDAO.Data> dataObj5 = new ArrayList<>(); - PermDAO.Data indData5 = new PermDAO.Data(); - indData5.ns = "test"; - indData5.type = "test"; - Set<String> rolesSet = new HashSet<>(); - rolesSet.add("test|test|test|test"); - indData5.roles = rolesSet; - dataObj5.add(indData5); - - Result<List<CredDAO.Data>> retVal2 = new Result<List<CredDAO.Data>>(dataObj,0,"test",NO_PARAM); - Result<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(dataObj1,0,"test",NO_PARAM); - Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(dataObj4,0,"test",NO_PARAM); - Result<List<PermDAO.Data>> retVal5 = new Result<List<PermDAO.Data>>(dataObj5,0,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(credDAO).readID(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retVal2).when(userRoleDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal2).when(roleDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal2).when(roleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); - Mockito.doReturn(retVal2).when(permDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal5).when(permDAO).readChildren(trans, "test", "test"); - Mockito.doReturn(retVal5).when(permDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); - Mockito.doReturn(retVal3).when(roleDAO).readChildren(trans, "test", "test"); - - Identity iden=Mockito.mock(Identity.class); - try { - Mockito.doReturn(iden).when(org).getIdentity(trans, "test"); - Mockito.doReturn("test").when(iden).mayOwn(); - Mockito.doReturn(true).when(org).isTestEnv(); - Mockito.doReturn(new GregorianCalendar(2010, 01, 01)).when(org).expiration(null, Expiration.UserInRole); - } catch (OrganizationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(roleDAO).read(trans, "test","test"); - Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(permDAO).readByType(trans, "test","test"); + Result<Void> result = funcObj.createNS(trans, namespace, true); + assertTrue(result.status == Status.ERR_ActionNotCompleted); + + } + + @Test + public void testCreateNsAdminLoopCreateSuc() { + Namespace namespace = Mockito.mock(Namespace.class); + namespace.name = "test.test"; + List<String> owner = new ArrayList<String>(); + owner.add("test"); + namespace.owner = owner; + namespace.admin = owner; + + Organization org = Mockito.mock(Organization.class); + Mockito.doReturn(org).when(trans).org(); + + NsDAO.Data data = new NsDAO.Data(); + data.name="test"; + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); + Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); + + Result<Void> retVal = new Result<Void>(null,0,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal).when(nsDAO).create(Mockito.any(), Mockito.any()); + List<CredDAO.Data> dataObj = new ArrayList<>(); + CredDAO.Data indData = new CredDAO.Data(); + indData.id = "test"; + indData.notes = "test"; + DateFormat sdf = new SimpleDateFormat("yyyy/mm/dd"); + try { + indData.expires = sdf.parse("2090/01/01"); + } catch (ParseException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + dataObj.add(indData); + List<RoleDAO.Data> dataObj1 = new ArrayList<>(); + RoleDAO.Data indData1 = new RoleDAO.Data(); + indData1.ns = "test"; + indData1.name = "test"; + Set<String> permsSet = new HashSet<>(); + permsSet.add("test|test|test|test"); + indData1.perms = permsSet; + dataObj1.add(indData1); + + List<UserRoleDAO.Data> dataObj4 = new ArrayList<>(); + UserRoleDAO.Data indData4 = new UserRoleDAO.Data(); + indData4.ns = "test"; + indData4.rname = "test"; + dataObj4.add(indData4); + + List<PermDAO.Data> dataObj5 = new ArrayList<>(); + PermDAO.Data indData5 = new PermDAO.Data(); + indData5.ns = "test"; + indData5.type = "test"; + Set<String> rolesSet = new HashSet<>(); + rolesSet.add("test|test|test|test"); + indData5.roles = rolesSet; + dataObj5.add(indData5); + + Result<List<CredDAO.Data>> retVal2 = new Result<List<CredDAO.Data>>(dataObj,0,"test",NO_PARAM); + Result<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(dataObj1,0,"test",NO_PARAM); + Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(dataObj4,0,"test",NO_PARAM); + Result<List<PermDAO.Data>> retVal5 = new Result<List<PermDAO.Data>>(dataObj5,0,"test",NO_PARAM); + Mockito.doReturn(retVal2).when(credDAO).readID(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal2).when(userRoleDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal2).when(roleDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal2).when(roleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + Mockito.doReturn(retVal2).when(permDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal5).when(permDAO).readChildren(trans, "test", "test"); + Mockito.doReturn(retVal5).when(permDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + Mockito.doReturn(retVal3).when(roleDAO).readChildren(trans, "test", "test"); + + Identity iden=Mockito.mock(Identity.class); + try { + Mockito.doReturn(iden).when(org).getIdentity(trans, "test"); + Mockito.doReturn("test").when(iden).mayOwn(); + Mockito.doReturn(true).when(org).isTestEnv(); + Mockito.doReturn(new GregorianCalendar(2010, 01, 01)).when(org).expiration(null, Expiration.UserInRole); + } catch (OrganizationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(roleDAO).read(trans, "test","test"); + Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(permDAO).readByType(trans, "test","test"); - Function funcObj = new Function(trans, ques); - Result<Void> result = funcObj.createNS(trans, namespace, true); - assertTrue(result.status == 0); - - } - - @Test - public void test4DeleteNs() { - Result<Void> retVal = new Result<Void>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - - Function funcObj = new Function(trans, ques); - Result<Void> result = funcObj.deleteNS(trans, "test"); - - assertTrue(result.status == Status.ERR_NsNotFound); - } - - @Test - public void test4DeleteCanMoveFail() { - List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); - NsDAO.Data dataObj = new NsDAO.Data(); - dataObj.type=1; - dataAl.add(dataObj); - Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",NO_PARAM); - Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - - Mockito.doReturn(false).when(ques).canMove(Mockito.any()); - Mockito.doReturn(retVal).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); - - Function funcObj = new Function(trans, ques); - Result<Void> result = funcObj.deleteNS(trans, "test"); - assertTrue(result.status == Status.ERR_Security); - - } - - @Test - public void test4DeleteNsReadSuc() { - List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); - NsDAO.Data dataObj = new NsDAO.Data(); - dataObj.type=1; - dataAl.add(dataObj); - Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",NO_PARAM); - Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - - Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); - - Function funcObj = new Function(trans, ques); - Result<Void> result = funcObj.deleteNS(trans, "test"); - assertTrue(result.status == 1); - - } - - @Test - public void test4DeleteNsMayUserSuc() { - List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); - NsDAO.Data dataObj = new NsDAO.Data(); - dataObj.type=1; - dataAl.add(dataObj); - Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",NO_PARAM); - Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - - Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); - - Function funcObj = new Function(trans, ques); - Result<Void> result = funcObj.deleteNS(trans, "test"); - assertTrue(result.status == 1); + Function funcObj = new Function(trans, ques); + Result<Void> result = funcObj.createNS(trans, namespace, true); + assertTrue(result.status == 0); + + } + + @Test + public void test4DeleteNs() { + Result<Void> retVal = new Result<Void>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + + Function funcObj = new Function(trans, ques); + Result<Void> result = funcObj.deleteNS(trans, "test"); + + assertTrue(result.status == Status.ERR_NsNotFound); + } + + @Test + public void test4DeleteCanMoveFail() { + List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); + NsDAO.Data dataObj = new NsDAO.Data(); + dataObj.type=1; + dataAl.add(dataObj); + Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + + Mockito.doReturn(false).when(ques).canMove(Mockito.any()); + Mockito.doReturn(retVal).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); + + Function funcObj = new Function(trans, ques); + Result<Void> result = funcObj.deleteNS(trans, "test"); + assertTrue(result.status == Status.ERR_Security); + + } + + @Test + public void test4DeleteNsReadSuc() { + List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); + NsDAO.Data dataObj = new NsDAO.Data(); + dataObj.type=1; + dataAl.add(dataObj); + Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); + + Function funcObj = new Function(trans, ques); + Result<Void> result = funcObj.deleteNS(trans, "test"); + assertTrue(result.status == 1); + + } + + @Test + public void test4DeleteNsMayUserSuc() { + List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); + NsDAO.Data dataObj = new NsDAO.Data(); + dataObj.type=1; + dataAl.add(dataObj); + Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); + Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); + + Function funcObj = new Function(trans, ques); + Result<Void> result = funcObj.deleteNS(trans, "test"); + assertTrue(result.status == 1); - Mockito.doReturn(true).when(ques).isGranted(Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); + Mockito.doReturn(true).when(ques).isGranted(Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); - Mockito.doReturn(retVal2).when(credDAO).readNS(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal2).when(credDAO).readNS(Mockito.any(), Mockito.anyString()); - Result<List<PermDAO.Data>> retVal5 = new Result<List<PermDAO.Data>>(null,0,"test",NO_PARAM); - Mockito.doReturn(retVal5).when(permDAO).readNS(trans, "test"); - - List<UserRoleDAO.Data> dataObj4 = new ArrayList<>(); - UserRoleDAO.Data indData4 = new UserRoleDAO.Data(); - indData4.ns = "test"; - indData4.rname = "test"; - dataObj4.add(indData4); - Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(dataObj4,0,"test",NO_PARAM); - Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(trans, "test"); - - List<RoleDAO.Data> dataObj1 = new ArrayList<>(); - RoleDAO.Data indData1 = new RoleDAO.Data(); - indData1.ns = "test"; - indData1.name = "test"; - Set<String> permsSet = new HashSet<>(); - permsSet.add("test|test"); - indData1.perms = permsSet; - dataObj1.add(indData1); - Result<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(dataObj1,0,"test",NO_PARAM); - Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test"); - Mockito.doReturn(retVal3).when(roleDAO).read(trans, indData1); - - funcObj = new Function(trans, ques); - result = funcObj.deleteNS(trans, "test"); - assertTrue(result.status == Status.ERR_DependencyExists); - - Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - - Mockito.doReturn(true).when(trans).requested(REQD_TYPE.force); - funcObj = new Function(trans, ques); - result = funcObj.deleteNS(trans, "test"); - assertNull(result); - } - @Test - public void test4DeleteNsDrivensFailure() { - List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); - NsDAO.Data dataObj = new NsDAO.Data(); - dataObj.type=1; - dataAl.add(dataObj); - Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",NO_PARAM); - Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - - Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); - - Function funcObj = new Function(trans, ques); - Result<Void> result = funcObj.deleteNS(trans, "test"); - assertTrue(result.status == 1); + Result<List<PermDAO.Data>> retVal5 = new Result<List<PermDAO.Data>>(null,0,"test",NO_PARAM); + Mockito.doReturn(retVal5).when(permDAO).readNS(trans, "test"); + + List<UserRoleDAO.Data> dataObj4 = new ArrayList<>(); + UserRoleDAO.Data indData4 = new UserRoleDAO.Data(); + indData4.ns = "test"; + indData4.rname = "test"; + dataObj4.add(indData4); + Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(dataObj4,0,"test",NO_PARAM); + Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(trans, "test"); + + List<RoleDAO.Data> dataObj1 = new ArrayList<>(); + RoleDAO.Data indData1 = new RoleDAO.Data(); + indData1.ns = "test"; + indData1.name = "test"; + Set<String> permsSet = new HashSet<>(); + permsSet.add("test|test"); + indData1.perms = permsSet; + dataObj1.add(indData1); + Result<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(dataObj1,0,"test",NO_PARAM); + Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test"); + Mockito.doReturn(retVal3).when(roleDAO).read(trans, indData1); + + funcObj = new Function(trans, ques); + result = funcObj.deleteNS(trans, "test"); + assertTrue(result.status == Status.ERR_DependencyExists); + + Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + + Mockito.doReturn(true).when(trans).requested(REQD_TYPE.force); + funcObj = new Function(trans, ques); + result = funcObj.deleteNS(trans, "test"); + assertNull(result); + } + @Test + public void test4DeleteNsDrivensFailure() { + List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); + NsDAO.Data dataObj = new NsDAO.Data(); + dataObj.type=1; + dataAl.add(dataObj); + Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); + Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); + + Function funcObj = new Function(trans, ques); + Result<Void> result = funcObj.deleteNS(trans, "test"); + assertTrue(result.status == 1); - Mockito.doReturn(true).when(ques).isGranted(Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); + Mockito.doReturn(true).when(ques).isGranted(Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); - Mockito.doReturn(retVal2).when(credDAO).readNS(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal2).when(credDAO).readNS(Mockito.any(), Mockito.anyString()); - List<PermDAO.Data> dataObj5 = new ArrayList<>(); - PermDAO.Data indData5 = new PermDAO.Data(); - indData5.ns = "test"; - indData5.type = "test"; - dataObj5.add(indData5); - Result<List<PermDAO.Data>> retVal5 = new Result<List<PermDAO.Data>>(dataObj5,0,"test",NO_PARAM); - Mockito.doReturn(retVal5).when(permDAO).readNS(trans, "test"); - Mockito.doReturn(retVal5).when(permDAO).readNS(trans, "test.test"); - Mockito.doReturn(retVal5).when(permDAO).read(trans, indData5); - - - List<RoleDAO.Data> dataObj1 = new ArrayList<>(); - RoleDAO.Data indData1 = new RoleDAO.Data(); - indData1.ns = "test"; - indData1.name = "test"; - Set<String> permsSet = new HashSet<>(); - permsSet.add("test|test"); - indData1.perms = permsSet; - dataObj1.add(indData1); - Result<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(dataObj1,0,"test",NO_PARAM); - Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test"); - Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test.test"); - Mockito.doReturn(retVal3).when(roleDAO).read(trans, indData1); - - funcObj = new Function(trans, ques); - result = funcObj.deleteNS(trans, "test"); - assertTrue(result.status == Status.ERR_DependencyExists); - - NsDAO.Data data = new NsDAO.Data(); - data.name="test"; - Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); - Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - - Mockito.doReturn(true).when(trans).requested(REQD_TYPE.force); - funcObj = new Function(trans, ques); - result = funcObj.deleteNS(trans, "test.test"); - assertTrue(result.status == 1); - } + List<PermDAO.Data> dataObj5 = new ArrayList<>(); + PermDAO.Data indData5 = new PermDAO.Data(); + indData5.ns = "test"; + indData5.type = "test"; + dataObj5.add(indData5); + Result<List<PermDAO.Data>> retVal5 = new Result<List<PermDAO.Data>>(dataObj5,0,"test",NO_PARAM); + Mockito.doReturn(retVal5).when(permDAO).readNS(trans, "test"); + Mockito.doReturn(retVal5).when(permDAO).readNS(trans, "test.test"); + Mockito.doReturn(retVal5).when(permDAO).read(trans, indData5); + + + List<RoleDAO.Data> dataObj1 = new ArrayList<>(); + RoleDAO.Data indData1 = new RoleDAO.Data(); + indData1.ns = "test"; + indData1.name = "test"; + Set<String> permsSet = new HashSet<>(); + permsSet.add("test|test"); + indData1.perms = permsSet; + dataObj1.add(indData1); + Result<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(dataObj1,0,"test",NO_PARAM); + Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test"); + Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test.test"); + Mockito.doReturn(retVal3).when(roleDAO).read(trans, indData1); + + funcObj = new Function(trans, ques); + result = funcObj.deleteNS(trans, "test"); + assertTrue(result.status == Status.ERR_DependencyExists); + + NsDAO.Data data = new NsDAO.Data(); + data.name="test"; + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); + Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); + + Mockito.doReturn(true).when(trans).requested(REQD_TYPE.force); + funcObj = new Function(trans, ques); + result = funcObj.deleteNS(trans, "test.test"); + assertTrue(result.status == 1); + } - @Test - public void test4DeleteNsWithDot() { - List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); - NsDAO.Data dataObj = new NsDAO.Data(); - dataObj.type=1; - dataAl.add(dataObj); - Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",NO_PARAM); - Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - - List<CredDAO.Data> nsDataList = new ArrayList<CredDAO.Data>(); - CredDAO.Data nsData = new CredDAO.Data(); - nsData.id="test"; - nsDataList.add(nsData); - Result<List<CredDAO.Data>> retVal21 = new Result<List<CredDAO.Data>>(nsDataList,0,"test",NO_PARAM); - Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); - - Function funcObj = new Function(trans, ques); - Result<Void> result = funcObj.deleteNS(trans, "test"); - assertTrue(result.status == 1); + @Test + public void test4DeleteNsWithDot() { + List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); + NsDAO.Data dataObj = new NsDAO.Data(); + dataObj.type=1; + dataAl.add(dataObj); + Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + + List<CredDAO.Data> nsDataList = new ArrayList<CredDAO.Data>(); + CredDAO.Data nsData = new CredDAO.Data(); + nsData.id="test"; + nsDataList.add(nsData); + Result<List<CredDAO.Data>> retVal21 = new Result<List<CredDAO.Data>>(nsDataList,0,"test",NO_PARAM); + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); + Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); + + Function funcObj = new Function(trans, ques); + Result<Void> result = funcObj.deleteNS(trans, "test"); + assertTrue(result.status == 1); - Mockito.doReturn(true).when(ques).isGranted(Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); + Mockito.doReturn(true).when(ques).isGranted(Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); - Mockito.doReturn(retVal21).when(credDAO).readNS(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retVal21).when(credDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + Mockito.doReturn(retVal21).when(credDAO).readNS(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal21).when(credDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); - List<PermDAO.Data> dataObj5 = new ArrayList<>(); - PermDAO.Data indData5 = new PermDAO.Data(); - indData5.ns = "test"; - indData5.type = "test"; - dataObj5.add(indData5); - Result<List<PermDAO.Data>> retVal5 = new Result<List<PermDAO.Data>>(dataObj5,0,"test",new Object[0]); - Mockito.doReturn(retVal5).when(permDAO).readNS(trans, "test"); - Mockito.doReturn(retVal5).when(permDAO).readNS(trans, "test.test"); - Mockito.doReturn(retVal5).when(permDAO).read(trans, indData5); - - List<UserRoleDAO.Data> dataObj4 = new ArrayList<>(); - UserRoleDAO.Data indData4 = new UserRoleDAO.Data(); - indData4.ns = "test"; - indData4.rname = "test"; - dataObj4.add(indData4); - Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(dataObj4,0,"test",NO_PARAM); - Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retVal4).when(userRoleDAO).readByUser(Mockito.any(), Mockito.anyString()); - - List<RoleDAO.Data> dataObj1 = new ArrayList<>(); - RoleDAO.Data indData1 = new RoleDAO.Data(); - indData1.ns = "test"; - indData1.name = "admin"; - Set<String> permsSet = new HashSet<>(); - permsSet.add("test|test"); - indData1.perms = permsSet; - dataObj1.add(indData1); - Result<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(dataObj1,0,"test",NO_PARAM); - Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test"); - Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test.test"); - Mockito.doReturn(retVal3).when(roleDAO).read(trans, indData1); - - funcObj = new Function(trans, ques); - result = funcObj.deleteNS(trans, "test"); - assertTrue(result.status == Status.ERR_DependencyExists); - - NsDAO.Data data = new NsDAO.Data(); - data.name="test"; - Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); - Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - - Mockito.doReturn(true).when(trans).requested(REQD_TYPE.force); - funcObj = new Function(trans, ques); - result = funcObj.deleteNS(trans, "test.test"); - assertNull(result); - } - - @Test - public void testGetOwners() { -// List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); -// NsDAO.Data dataObj = new NsDAO.Data(); -// dataObj.type=1; -// dataAl.add(dataObj); - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); -// -// Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); -// Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); -// - Function funcObj = new Function(trans, ques); - Result<List<String>> result = funcObj.getOwners(trans, "test", false); - assertTrue(result.status == 1); -// - } - - @Test - public void testDelOwner() { - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); + List<PermDAO.Data> dataObj5 = new ArrayList<>(); + PermDAO.Data indData5 = new PermDAO.Data(); + indData5.ns = "test"; + indData5.type = "test"; + dataObj5.add(indData5); + Result<List<PermDAO.Data>> retVal5 = new Result<List<PermDAO.Data>>(dataObj5,0,"test",new Object[0]); + Mockito.doReturn(retVal5).when(permDAO).readNS(trans, "test"); + Mockito.doReturn(retVal5).when(permDAO).readNS(trans, "test.test"); + Mockito.doReturn(retVal5).when(permDAO).read(trans, indData5); + + List<UserRoleDAO.Data> dataObj4 = new ArrayList<>(); + UserRoleDAO.Data indData4 = new UserRoleDAO.Data(); + indData4.ns = "test"; + indData4.rname = "test"; + dataObj4.add(indData4); + Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(dataObj4,0,"test",NO_PARAM); + Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal4).when(userRoleDAO).readByUser(Mockito.any(), Mockito.anyString()); + + List<RoleDAO.Data> dataObj1 = new ArrayList<>(); + RoleDAO.Data indData1 = new RoleDAO.Data(); + indData1.ns = "test"; + indData1.name = "admin"; + Set<String> permsSet = new HashSet<>(); + permsSet.add("test|test"); + indData1.perms = permsSet; + dataObj1.add(indData1); + Result<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(dataObj1,0,"test",NO_PARAM); + Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test"); + Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test.test"); + Mockito.doReturn(retVal3).when(roleDAO).read(trans, indData1); + + funcObj = new Function(trans, ques); + result = funcObj.deleteNS(trans, "test"); + assertTrue(result.status == Status.ERR_DependencyExists); + + NsDAO.Data data = new NsDAO.Data(); + data.name="test"; + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); + Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); + + Mockito.doReturn(true).when(trans).requested(REQD_TYPE.force); + funcObj = new Function(trans, ques); + result = funcObj.deleteNS(trans, "test.test"); + assertNull(result); + } + + @Test + public void testGetOwners() { +// List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); +// NsDAO.Data dataObj = new NsDAO.Data(); +// dataObj.type=1; +// dataAl.add(dataObj); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); +// +// Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); +// Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); +// + Function funcObj = new Function(trans, ques); + Result<List<String>> result = funcObj.getOwners(trans, "test", false); + assertTrue(result.status == 1); +// + } + + @Test + public void testDelOwner() { + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); - NsDAO.Data data = new NsDAO.Data(); - data.name="test"; - Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); - Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - - Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal1.value, Access.write); - - Function funcObj = new Function(trans, ques); - Result<Void> result = funcObj.delOwner(trans, "test", "test"); - assertTrue(result.status == 1); - - retVal1 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); - Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - result = funcObj.delOwner(trans, "test", "test"); - assertTrue(result.status == 1); - - retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); - Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - result = funcObj.delOwner(trans, "test", "test"); - retVal2 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal1.value, Access.write); - result = funcObj.delOwner(trans, "test", "test"); -// - } - - @Test - public void testGetAdmins() { -// List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); -// NsDAO.Data dataObj = new NsDAO.Data(); -// dataObj.type=1; -// dataAl.add(dataObj); - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); -// -// Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); -// Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); -// - Function funcObj = new Function(trans, ques); - Result<List<String>> result = funcObj.getAdmins(trans, "test", false); - assertTrue(result.status == 1); -// - } - - @Test - public void testDelAdmin() { - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readUserInRole(Mockito.any(), Mockito.anyString(), Mockito.anyString()); - Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); + NsDAO.Data data = new NsDAO.Data(); + data.name="test"; + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); + Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); + + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); + Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal1.value, Access.write); + + Function funcObj = new Function(trans, ques); + Result<Void> result = funcObj.delOwner(trans, "test", "test"); + assertTrue(result.status == 1); + + retVal1 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); + Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); + result = funcObj.delOwner(trans, "test", "test"); + assertTrue(result.status == 1); + + retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); + Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); + result = funcObj.delOwner(trans, "test", "test"); + retVal2 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); + Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal1.value, Access.write); + result = funcObj.delOwner(trans, "test", "test"); +// + } + + @Test + public void testGetAdmins() { +// List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); +// NsDAO.Data dataObj = new NsDAO.Data(); +// dataObj.type=1; +// dataAl.add(dataObj); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); +// +// Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); +// Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); +// + Function funcObj = new Function(trans, ques); + Result<List<String>> result = funcObj.getAdmins(trans, "test", false); + assertTrue(result.status == 1); +// + } + + @Test + public void testDelAdmin() { + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(userRoleDAO).readUserInRole(Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); - NsDAO.Data data = new NsDAO.Data(); - data.name="test"; - Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); - Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - - Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal1.value, Access.write); - - Function funcObj = new Function(trans, ques); - Result<Void> result = funcObj.delAdmin(trans, "test", "test"); - assertTrue(result.status == 1); - - retVal1 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); - Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - result = funcObj.delAdmin(trans, "test", "test"); - assertTrue(result.status == 1); - - retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); - Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - result = funcObj.delOwner(trans, "test", "test"); - retVal2 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal1.value, Access.write); - result = funcObj.delAdmin(trans, "test", "test"); -// - } - - @Test - public void testMovePerms() { -// List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); -// NsDAO.Data dataObj = new NsDAO.Data(); -// dataObj.type=1; -// dataAl.add(dataObj); - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - - Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); - - Mockito.doReturn(retVal).when(permDAO).create(Mockito.any(), Mockito.any()); - - NsDAO.Data nsDataObj = new NsDAO.Data(); - nsDataObj.name="test"; - StringBuilder sb = new StringBuilder(); - Result<List<PermDAO.Data>> retVal1 = new Result<List<PermDAO.Data>>(null,1,"test",NO_PARAM); - - invokeMovePerms(nsDataObj, sb, retVal1); - - List<PermDAO.Data> dataObj5 = new ArrayList<>(); - PermDAO.Data indData5 = new PermDAO.Data(); - indData5.ns = "test"; - indData5.type = "test"; - Set<String> rolesSet = new HashSet<>(); - rolesSet.add("testRole"); - indData5.roles = rolesSet; - dataObj5.add(indData5); - indData5 = new PermDAO.Data(); - indData5.ns = "test"; - indData5.type = "access"; - dataObj5.add(indData5); - retVal1 = new Result<List<PermDAO.Data>>(dataObj5,0,"test",NO_PARAM); + NsDAO.Data data = new NsDAO.Data(); + data.name="test"; + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); + Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); + + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); + Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal1.value, Access.write); + + Function funcObj = new Function(trans, ques); + Result<Void> result = funcObj.delAdmin(trans, "test", "test"); + assertTrue(result.status == 1); + + retVal1 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); + Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); + result = funcObj.delAdmin(trans, "test", "test"); + assertTrue(result.status == 1); + + retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); + Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); + result = funcObj.delOwner(trans, "test", "test"); + retVal2 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); + Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal1.value, Access.write); + result = funcObj.delAdmin(trans, "test", "test"); +// + } + + @Test + public void testMovePerms() { +// List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); +// NsDAO.Data dataObj = new NsDAO.Data(); +// dataObj.type=1; +// dataAl.add(dataObj); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + + Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); + + Mockito.doReturn(retVal).when(permDAO).create(Mockito.any(), Mockito.any()); + + NsDAO.Data nsDataObj = new NsDAO.Data(); + nsDataObj.name="test"; + StringBuilder sb = new StringBuilder(); + Result<List<PermDAO.Data>> retVal1 = new Result<List<PermDAO.Data>>(null,1,"test",NO_PARAM); + + invokeMovePerms(nsDataObj, sb, retVal1); + + List<PermDAO.Data> dataObj5 = new ArrayList<>(); + PermDAO.Data indData5 = new PermDAO.Data(); + indData5.ns = "test"; + indData5.type = "test"; + Set<String> rolesSet = new HashSet<>(); + rolesSet.add("testRole"); + indData5.roles = rolesSet; + dataObj5.add(indData5); + indData5 = new PermDAO.Data(); + indData5.ns = "test"; + indData5.type = "access"; + dataObj5.add(indData5); + retVal1 = new Result<List<PermDAO.Data>>(dataObj5,0,"test",NO_PARAM); - Result<List<UserRoleDAO.Data>> retVal3 = new Result<List<UserRoleDAO.Data>>(null,0,"test",NO_PARAM); - Mockito.doReturn(retVal3).when(permDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal3).when(permDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + Result<List<UserRoleDAO.Data>> retVal3 = new Result<List<UserRoleDAO.Data>>(null,0,"test",NO_PARAM); + Mockito.doReturn(retVal3).when(permDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal3).when(permDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); - NsSplit splitObj = new NsSplit("test", "test"); - Result<NsSplit> retVal2 = new Result<NsSplit>(splitObj,0,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); - - invokeMovePerms(nsDataObj, sb, retVal1); - - Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal4).when(permDAO).create(Mockito.any(), Mockito.any()); - invokeMovePerms(nsDataObj, sb, retVal1); - - Mockito.doReturn(retVal3).when(permDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal4).when(permDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); - invokeMovePerms(nsDataObj, sb, retVal1); - - } - - private void invokeMovePerms(NsDAO.Data nsDataObj, StringBuilder sb,Result<List<PermDAO.Data>> retVal1) { - Function funcObj = new Function(trans, ques); - Method met; - try { - met = Function.class.getDeclaredMethod("movePerms", AuthzTrans.class, NsDAO.Data.class, StringBuilder.class, Result.class); - met.setAccessible(true); - met.invoke(funcObj, trans, nsDataObj, sb, retVal1); - } catch (NoSuchMethodException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testMoveRoles() { -// List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); -// NsDAO.Data dataObj = new NsDAO.Data(); -// dataObj.type=1; -// dataAl.add(dataObj); - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - - Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); - - Mockito.doReturn(retVal).when(roleDAO).create(Mockito.any(), Mockito.any()); - - NsDAO.Data nsDataObj = new NsDAO.Data(); - nsDataObj.name="test"; - StringBuilder sb = new StringBuilder(); - Result<List<RoleDAO.Data>> retVal1 = new Result<List<RoleDAO.Data>>(null,1,"test",NO_PARAM); - - invokeMoveRoles(nsDataObj, sb, retVal1); - - List<RoleDAO.Data> dataObj5 = new ArrayList<>(); - RoleDAO.Data indData5 = new RoleDAO.Data(); - indData5.ns = "test"; - indData5.name = "test"; - Set<String> rolesSet = new HashSet<>(); - rolesSet.add("testRole"); - indData5.perms = rolesSet; - dataObj5.add(indData5); - indData5 = new RoleDAO.Data(); - indData5.ns = "test"; - indData5.name = "admin"; - dataObj5.add(indData5); - retVal1 = new Result<List<RoleDAO.Data>>(dataObj5,0,"test",NO_PARAM); - - Result<List<UserRoleDAO.Data>> retVal3 = new Result<List<UserRoleDAO.Data>>(null,0,"test",NO_PARAM); - Mockito.doReturn(retVal3).when(roleDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal3).when(roleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + NsSplit splitObj = new NsSplit("test", "test"); + Result<NsSplit> retVal2 = new Result<NsSplit>(splitObj,0,"test",NO_PARAM); + Mockito.doReturn(retVal2).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); + + invokeMovePerms(nsDataObj, sb, retVal1); + + Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal4).when(permDAO).create(Mockito.any(), Mockito.any()); + invokeMovePerms(nsDataObj, sb, retVal1); + + Mockito.doReturn(retVal3).when(permDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal4).when(permDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + invokeMovePerms(nsDataObj, sb, retVal1); + + } + + private void invokeMovePerms(NsDAO.Data nsDataObj, StringBuilder sb,Result<List<PermDAO.Data>> retVal1) { + Function funcObj = new Function(trans, ques); + Method met; + try { + met = Function.class.getDeclaredMethod("movePerms", AuthzTrans.class, NsDAO.Data.class, StringBuilder.class, Result.class); + met.setAccessible(true); + met.invoke(funcObj, trans, nsDataObj, sb, retVal1); + } catch (NoSuchMethodException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testMoveRoles() { +// List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); +// NsDAO.Data dataObj = new NsDAO.Data(); +// dataObj.type=1; +// dataAl.add(dataObj); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + + Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); + + Mockito.doReturn(retVal).when(roleDAO).create(Mockito.any(), Mockito.any()); + + NsDAO.Data nsDataObj = new NsDAO.Data(); + nsDataObj.name="test"; + StringBuilder sb = new StringBuilder(); + Result<List<RoleDAO.Data>> retVal1 = new Result<List<RoleDAO.Data>>(null,1,"test",NO_PARAM); + + invokeMoveRoles(nsDataObj, sb, retVal1); + + List<RoleDAO.Data> dataObj5 = new ArrayList<>(); + RoleDAO.Data indData5 = new RoleDAO.Data(); + indData5.ns = "test"; + indData5.name = "test"; + Set<String> rolesSet = new HashSet<>(); + rolesSet.add("testRole"); + indData5.perms = rolesSet; + dataObj5.add(indData5); + indData5 = new RoleDAO.Data(); + indData5.ns = "test"; + indData5.name = "admin"; + dataObj5.add(indData5); + retVal1 = new Result<List<RoleDAO.Data>>(dataObj5,0,"test",NO_PARAM); + + Result<List<UserRoleDAO.Data>> retVal3 = new Result<List<UserRoleDAO.Data>>(null,0,"test",NO_PARAM); + Mockito.doReturn(retVal3).when(roleDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal3).when(roleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); - NsSplit splitObj = new NsSplit("test", "test"); - Result<NsSplit> retVal2 = new Result<NsSplit>(splitObj,0,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); - - invokeMoveRoles(nsDataObj, sb, retVal1); - - Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal4).when(roleDAO).create(Mockito.any(), Mockito.any()); - invokeMoveRoles(nsDataObj, sb, retVal1); - - Mockito.doReturn(retVal3).when(roleDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal4).when(roleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); - invokeMoveRoles(nsDataObj, sb, retVal1); - - } - - private void invokeMoveRoles(NsDAO.Data nsDataObj, StringBuilder sb,Result<List<RoleDAO.Data>> retVal1) { - Function funcObj = new Function(trans, ques); - Method met; - try { - met = Function.class.getDeclaredMethod("moveRoles", AuthzTrans.class, NsDAO.Data.class, StringBuilder.class, Result.class); - met.setAccessible(true); - met.invoke(funcObj, trans, nsDataObj, sb, retVal1); - } catch (NoSuchMethodException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - @Test - public void testCreatePerm() { - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - List<PermDAO.Data> dataAl = new ArrayList<PermDAO.Data>(); - PermDAO.Data perm = new PermDAO.Data(); - Set<String> rolesSet = new HashSet<>(); - rolesSet.add("testRole"); - perm.roles = rolesSet; -// perm.type=1 - dataAl.add(perm); - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); - - Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); - Mockito.doReturn(retVal).when(userRoleDAO).create(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); - - Mockito.doReturn(retVal).when(permDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal).when(permDAO).read(trans, perm); - - Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,perm, Access.write); - - Function funcObj = new Function(trans, ques); - Result<Void> result = funcObj.createPerm(trans, perm, false); - assertTrue(result.status == 1); - - retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,perm, Access.write); - result = funcObj.createPerm(trans, perm, false); - assertTrue(result.status == 1); + NsSplit splitObj = new NsSplit("test", "test"); + Result<NsSplit> retVal2 = new Result<NsSplit>(splitObj,0,"test",NO_PARAM); + Mockito.doReturn(retVal2).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); + + invokeMoveRoles(nsDataObj, sb, retVal1); + + Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal4).when(roleDAO).create(Mockito.any(), Mockito.any()); + invokeMoveRoles(nsDataObj, sb, retVal1); + + Mockito.doReturn(retVal3).when(roleDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal4).when(roleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + invokeMoveRoles(nsDataObj, sb, retVal1); + + } + + private void invokeMoveRoles(NsDAO.Data nsDataObj, StringBuilder sb,Result<List<RoleDAO.Data>> retVal1) { + Function funcObj = new Function(trans, ques); + Method met; + try { + met = Function.class.getDeclaredMethod("moveRoles", AuthzTrans.class, NsDAO.Data.class, StringBuilder.class, Result.class); + met.setAccessible(true); + met.invoke(funcObj, trans, nsDataObj, sb, retVal1); + } catch (NoSuchMethodException | SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testCreatePerm() { + try { + Define.set(access); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + List<PermDAO.Data> dataAl = new ArrayList<PermDAO.Data>(); + PermDAO.Data perm = new PermDAO.Data(); + Set<String> rolesSet = new HashSet<>(); + rolesSet.add("testRole"); + perm.roles = rolesSet; +// perm.type=1 + dataAl.add(perm); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); + + Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); + Mockito.doReturn(retVal).when(userRoleDAO).create(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); + + Mockito.doReturn(retVal).when(permDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal).when(permDAO).read(trans, perm); + + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,perm, Access.write); + + Function funcObj = new Function(trans, ques); + Result<Void> result = funcObj.createPerm(trans, perm, false); + assertTrue(result.status == 1); + + retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); + Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,perm, Access.write); + result = funcObj.createPerm(trans, perm, false); + assertTrue(result.status == 1); - NsSplit nsObj = new NsSplit("test","test"); - Result<NsSplit> retValNs = new Result<NsSplit>(nsObj,0,"test",NO_PARAM); - Mockito.doReturn(retValNs).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retVal2).when(ques).mayUser(Mockito.any(), Mockito.anyString(),Mockito.any(RoleDAO.Data.class), Mockito.any()); - Result<List<RoleDAO.Data>> retVal3 = Result.ok(new ArrayList<>()); - Mockito.doReturn(retVal3).when(roleDAO).read(Mockito.any(),Mockito.any(RoleDAO.Data.class)); - Result<List<RoleDAO.Data>> retVal4 = Result.err(Result.ERR_NotFound,""); - Mockito.doReturn(retVal4).when(roleDAO).create(Mockito.any(),Mockito.any(RoleDAO.Data.class)); - result = funcObj.createPerm(trans, perm, false); - - Mockito.doReturn(retVal).when(permDAO).read(trans, perm); - result = funcObj.createPerm(trans, perm, true); - assertTrue(result.status == 1); + NsSplit nsObj = new NsSplit("test","test"); + Result<NsSplit> retValNs = new Result<NsSplit>(nsObj,0,"test",NO_PARAM); + Mockito.doReturn(retValNs).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal2).when(ques).mayUser(Mockito.any(), Mockito.anyString(),Mockito.any(RoleDAO.Data.class), Mockito.any()); + Result<List<RoleDAO.Data>> retVal3 = Result.ok(new ArrayList<>()); + Mockito.doReturn(retVal3).when(roleDAO).read(Mockito.any(),Mockito.any(RoleDAO.Data.class)); + Result<List<RoleDAO.Data>> retVal4 = Result.err(Result.ERR_NotFound,""); + Mockito.doReturn(retVal4).when(roleDAO).create(Mockito.any(),Mockito.any(RoleDAO.Data.class)); + result = funcObj.createPerm(trans, perm, false); + + Mockito.doReturn(retVal).when(permDAO).read(trans, perm); + result = funcObj.createPerm(trans, perm, true); + assertTrue(result.status == 1); - Mockito.doReturn(retVal2).when(permDAO).create(Mockito.any(), Mockito.any()); - result = funcObj.createPerm(trans, perm, true); - assertTrue(result.status == 0); - - Mockito.doReturn(false).when(trans).requested(REQD_TYPE.force); - Result<List<PermDAO.Data>> retVal1 = new Result<List<PermDAO.Data>>(dataAl,0,"test",NO_PARAM); - Mockito.doReturn(retVal1).when(permDAO).read(trans, perm); - result = funcObj.createPerm(trans, perm, true); - assertTrue(result.status == Status.ERR_ConflictAlreadyExists); - - } - @Test - public void testDeletePerm() { - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - List<PermDAO.Data> dataAl = new ArrayList<PermDAO.Data>(); - PermDAO.Data perm = new PermDAO.Data(); - Set<String> rolesSet = new HashSet<>(); - rolesSet.add("testRole"); - perm.roles = rolesSet; -// perm.type=1 - dataAl.add(perm); - - Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,perm, Access.write); - -// List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); -// NsDAO.Data dataObj = new NsDAO.Data(); -// dataObj.type=1; -// dataAl.add(dataObj); - Result<List<PermDAO.Data>> retVal = new Result<List<PermDAO.Data>>(dataAl,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - - Function funcObj = new Function(trans, ques); - Result<Void> result = funcObj.deletePerm(trans, perm, true,false); - assertTrue(result.status == 1); + Mockito.doReturn(retVal2).when(permDAO).create(Mockito.any(), Mockito.any()); + result = funcObj.createPerm(trans, perm, true); + assertTrue(result.status == 0); + + Mockito.doReturn(false).when(trans).requested(REQD_TYPE.force); + Result<List<PermDAO.Data>> retVal1 = new Result<List<PermDAO.Data>>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal1).when(permDAO).read(trans, perm); + result = funcObj.createPerm(trans, perm, true); + assertTrue(result.status == Status.ERR_ConflictAlreadyExists); + + } + @Test + public void testDeletePerm() { + try { + Define.set(access); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + List<PermDAO.Data> dataAl = new ArrayList<PermDAO.Data>(); + PermDAO.Data perm = new PermDAO.Data(); + Set<String> rolesSet = new HashSet<>(); + rolesSet.add("testRole"); + perm.roles = rolesSet; +// perm.type=1 + dataAl.add(perm); + + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,perm, Access.write); + +// List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); +// NsDAO.Data dataObj = new NsDAO.Data(); +// dataObj.type=1; +// dataAl.add(dataObj); + Result<List<PermDAO.Data>> retVal = new Result<List<PermDAO.Data>>(dataAl,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + + Function funcObj = new Function(trans, ques); + Result<Void> result = funcObj.deletePerm(trans, perm, true,false); + assertTrue(result.status == 1); -// Mockito.doReturn(retVal).when(cachedPermDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal).when(permDAO).read(trans, perm); - - result = funcObj.deletePerm(trans, perm, true,true); - assertTrue(result.status == Status.ERR_PermissionNotFound); +// Mockito.doReturn(retVal).when(cachedPermDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal).when(permDAO).read(trans, perm); + + result = funcObj.deletePerm(trans, perm, true,true); + assertTrue(result.status == Status.ERR_PermissionNotFound); - retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,perm, Access.write); - Result<List<PermDAO.Data>> retVal3 = new Result<List<PermDAO.Data>>(dataAl,0,"test",NO_PARAM); - Mockito.doReturn(retVal3).when(permDAO).read(trans, perm); - - NsSplit nsObj = new NsSplit("test","test"); - Result<NsSplit> retValNs = new Result<NsSplit>(nsObj,0,"test",NO_PARAM); - Mockito.doReturn(retValNs).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); - - Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); - - result = funcObj.deletePerm(trans, perm, true,false); - assertNull(result); - - Mockito.doReturn(retVal2).when(roleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); - result = funcObj.deletePerm(trans, perm, true,false); - assertNull(result); - - result = funcObj.deletePerm(trans, perm, false,false); -// assertTrue(result.status == 1); - } - - @Test - public void testDeleteRole() { - try { - Define.set(access); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); + Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,perm, Access.write); + Result<List<PermDAO.Data>> retVal3 = new Result<List<PermDAO.Data>>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal3).when(permDAO).read(trans, perm); + + NsSplit nsObj = new NsSplit("test","test"); + Result<NsSplit> retValNs = new Result<NsSplit>(nsObj,0,"test",NO_PARAM); + Mockito.doReturn(retValNs).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); + + Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); + + result = funcObj.deletePerm(trans, perm, true,false); + assertNull(result); + + Mockito.doReturn(retVal2).when(roleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); + result = funcObj.deletePerm(trans, perm, true,false); + assertNull(result); + + result = funcObj.deletePerm(trans, perm, false,false); +// assertTrue(result.status == 1); + } + + @Test + public void testDeleteRole() { + try { + Define.set(access); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } - List<UserRoleDAO.Data> dataAlUser = new ArrayList<UserRoleDAO.Data>(); - UserRoleDAO.Data roleUser = new UserRoleDAO.Data(); - Set<String> rolesSetUser = new HashSet<>(); - rolesSetUser.add("testRole|test|test"); -// perm.roles = rolesSet; -// perm.type=1 - dataAlUser.add(roleUser); - - List<RoleDAO.Data> dataAl = new ArrayList<RoleDAO.Data>(); - RoleDAO.Data role = new RoleDAO.Data(); - Set<String> rolesSet = new HashSet<>(); - rolesSet.add("testRole|test|test"); - role.perms = rolesSet; -// perm.roles = rolesSet; -// perm.type=1 - dataAl.add(role); - - Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,role, Access.write); - -// List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); -// NsDAO.Data dataObj = new NsDAO.Data(); -// dataObj.type=1; -// dataAl.add(dataObj); - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); -// -// Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); -// Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); -// - Function funcObj = new Function(trans, ques); - Result<Void> result = funcObj.deleteRole(trans, role, true, false); - assertTrue(result.status == 1); + List<UserRoleDAO.Data> dataAlUser = new ArrayList<UserRoleDAO.Data>(); + UserRoleDAO.Data roleUser = new UserRoleDAO.Data(); + Set<String> rolesSetUser = new HashSet<>(); + rolesSetUser.add("testRole|test|test"); +// perm.roles = rolesSet; +// perm.type=1 + dataAlUser.add(roleUser); + + List<RoleDAO.Data> dataAl = new ArrayList<RoleDAO.Data>(); + RoleDAO.Data role = new RoleDAO.Data(); + Set<String> rolesSet = new HashSet<>(); + rolesSet.add("testRole|test|test"); + role.perms = rolesSet; +// perm.roles = rolesSet; +// perm.type=1 + dataAl.add(role); + + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,role, Access.write); + +// List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); +// NsDAO.Data dataObj = new NsDAO.Data(); +// dataObj.type=1; +// dataAl.add(dataObj); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); +// +// Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); +// Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); +// + Function funcObj = new Function(trans, ques); + Result<Void> result = funcObj.deleteRole(trans, role, true, false); + assertTrue(result.status == 1); - Result<List<RoleDAO.Data>> retVal1 = new Result<List<RoleDAO.Data>>(dataAl,0,"test",NO_PARAM); - Mockito.doReturn(retVal1).when(roleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); - NsSplit splitObj = new NsSplit("test", "test"); - Result<NsSplit> retVal3 = new Result<NsSplit>(splitObj,0,"test",NO_PARAM); - Mockito.doReturn(retVal3).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); -// Mockito.doReturn(retVal).when(cachedPermDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal).when(permDAO).delRole(Mockito.any(), Mockito.any(),Mockito.any()); - result = funcObj.deleteRole(trans, role, true, true); - assertNull(result); - - Mockito.doReturn(retVal1).when(permDAO).delRole(Mockito.any(), Mockito.any(),Mockito.any()); - result = funcObj.deleteRole(trans, role, true, true); - assertNull(result); + Result<List<RoleDAO.Data>> retVal1 = new Result<List<RoleDAO.Data>>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal1).when(roleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); + NsSplit splitObj = new NsSplit("test", "test"); + Result<NsSplit> retVal3 = new Result<NsSplit>(splitObj,0,"test",NO_PARAM); + Mockito.doReturn(retVal3).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); +// Mockito.doReturn(retVal).when(cachedPermDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal).when(permDAO).delRole(Mockito.any(), Mockito.any(),Mockito.any()); + result = funcObj.deleteRole(trans, role, true, true); + assertNull(result); + + Mockito.doReturn(retVal1).when(permDAO).delRole(Mockito.any(), Mockito.any(),Mockito.any()); + result = funcObj.deleteRole(trans, role, true, true); + assertNull(result); - Mockito.doReturn(retVal).when(roleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); - result = funcObj.deleteRole(trans, role, true, true); - assertTrue(result.status == Status.ERR_RoleNotFound); - - retVal = new Result<List<UserRoleDAO.Data>>(dataAlUser,0,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - result = funcObj.deleteRole(trans, role, false, true); - assertTrue(result.status == Status.ERR_DependencyExists); - } - - @Test - public void testAddPermToRole() { - List<PermDAO.Data> dataAlPerm = new ArrayList<PermDAO.Data>(); - PermDAO.Data rolePerm = new PermDAO.Data(); - Set<String> rolesSetUser = new HashSet<>(); - rolesSetUser.add("testRole|test|test"); -// perm.roles = rolesSet; -// perm.type=1 - dataAlPerm.add(rolePerm); - - List<RoleDAO.Data> dataAl = new ArrayList<RoleDAO.Data>(); - RoleDAO.Data role = new RoleDAO.Data(); - Set<String> rolesSet = new HashSet<>(); - rolesSet.add("17623"); - role.perms = rolesSet; -// perm.roles = rolesSet; -// perm.type=1 - dataAl.add(role); - - NsDAO.Data nsObj = new NsDAO.Data(); - nsObj.name="test"; - NsDAO.Data nsObj1 = new NsDAO.Data(); - nsObj1.name="test12"; - -// List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); -// NsDAO.Data dataObj = new NsDAO.Data(); -// dataObj.type=1; -// dataAl.add(dataObj); - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal).when(roleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); + result = funcObj.deleteRole(trans, role, true, true); + assertTrue(result.status == Status.ERR_RoleNotFound); + + retVal = new Result<List<UserRoleDAO.Data>>(dataAlUser,0,"test",NO_PARAM); + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + result = funcObj.deleteRole(trans, role, false, true); + assertTrue(result.status == Status.ERR_DependencyExists); + } + + @Test + public void testAddPermToRole() { + List<PermDAO.Data> dataAlPerm = new ArrayList<PermDAO.Data>(); + PermDAO.Data rolePerm = new PermDAO.Data(); + Set<String> rolesSetUser = new HashSet<>(); + rolesSetUser.add("testRole|test|test"); +// perm.roles = rolesSet; +// perm.type=1 + dataAlPerm.add(rolePerm); + + List<RoleDAO.Data> dataAl = new ArrayList<RoleDAO.Data>(); + RoleDAO.Data role = new RoleDAO.Data(); + Set<String> rolesSet = new HashSet<>(); + rolesSet.add("17623"); + role.perms = rolesSet; +// perm.roles = rolesSet; +// perm.type=1 + dataAl.add(role); + + NsDAO.Data nsObj = new NsDAO.Data(); + nsObj.name="test"; + NsDAO.Data nsObj1 = new NsDAO.Data(); + nsObj1.name="test12"; + +// List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); +// NsDAO.Data dataObj = new NsDAO.Data(); +// dataObj.type=1; +// dataAl.add(dataObj); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(nsObj,0,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, role.ns, NsType.COMPANY); - Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, rolePerm.ns, NsType.COMPANY); - - Result<NsDAO.Data> retVal3 = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal3).when(ques).mayUser(trans, null,rolePerm, Access.write); - Mockito.doReturn(retVal3).when(ques).mayUser(trans, null,role, Access.write); - - Function funcObj = new Function(trans, ques); - Result<Void> result = funcObj.addPermToRole(trans, role, rolePerm, false); - assertTrue(result.status == 1); + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(nsObj,0,"test",NO_PARAM); + Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, role.ns, NsType.COMPANY); + Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, rolePerm.ns, NsType.COMPANY); + + Result<NsDAO.Data> retVal3 = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal3).when(ques).mayUser(trans, null,rolePerm, Access.write); + Mockito.doReturn(retVal3).when(ques).mayUser(trans, null,role, Access.write); + + Function funcObj = new Function(trans, ques); + Result<Void> result = funcObj.addPermToRole(trans, role, rolePerm, false); + assertTrue(result.status == 1); - retVal2 = new Result<NsDAO.Data>(nsObj,1,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, role.ns, NsType.COMPANY); - Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, rolePerm.ns, NsType.COMPANY); - result = funcObj.addPermToRole(trans, role, rolePerm, false); - assertTrue(result.status == 1); - - role.ns="test2"; - retVal2 = new Result<NsDAO.Data>(nsObj,0,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, role.ns, NsType.COMPANY); - result = funcObj.addPermToRole(trans, role, rolePerm, false); - assertTrue(result.status == 1); - - retVal2 = new Result<NsDAO.Data>(nsObj,0,"test1",NO_PARAM); - Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, role.ns, NsType.COMPANY); - Result<NsDAO.Data> retVal21 = new Result<NsDAO.Data>(nsObj1,0,"test1",NO_PARAM); - Mockito.doReturn(retVal21).when(ques).deriveFirstNsForType(trans, rolePerm.ns, NsType.COMPANY); - result = funcObj.addPermToRole(trans, role, rolePerm, false); - assertTrue(result.status == 1); - - retVal3 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); - Mockito.doReturn(retVal3).when(ques).mayUser(trans, null,rolePerm, Access.write); - retVal2 = new Result<NsDAO.Data>(nsObj,0,"test1",NO_PARAM); - Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, role.ns, NsType.COMPANY); - Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, rolePerm.ns, NsType.COMPANY); - -// Mockito.doReturn(retVal).when(cachedPermDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); - - result = funcObj.addPermToRole(trans, role, rolePerm, false); - assertTrue(result.status == Status.ERR_PermissionNotFound); - - Result<List<PermDAO.Data>> retValPerm= new Result<List<PermDAO.Data>>(dataAlPerm,0,"test1",NO_PARAM); - Mockito.doReturn(retValPerm).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); - - Mockito.doReturn(retVal3).when(roleDAO).read(trans, role); - - result = funcObj.addPermToRole(trans, role, rolePerm, true); - assertTrue(result.status == 22); + retVal2 = new Result<NsDAO.Data>(nsObj,1,"test",NO_PARAM); + Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, role.ns, NsType.COMPANY); + Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, rolePerm.ns, NsType.COMPANY); + result = funcObj.addPermToRole(trans, role, rolePerm, false); + assertTrue(result.status == 1); + + role.ns="test2"; + retVal2 = new Result<NsDAO.Data>(nsObj,0,"test",NO_PARAM); + Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, role.ns, NsType.COMPANY); + result = funcObj.addPermToRole(trans, role, rolePerm, false); + assertTrue(result.status == 1); + + retVal2 = new Result<NsDAO.Data>(nsObj,0,"test1",NO_PARAM); + Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, role.ns, NsType.COMPANY); + Result<NsDAO.Data> retVal21 = new Result<NsDAO.Data>(nsObj1,0,"test1",NO_PARAM); + Mockito.doReturn(retVal21).when(ques).deriveFirstNsForType(trans, rolePerm.ns, NsType.COMPANY); + result = funcObj.addPermToRole(trans, role, rolePerm, false); + assertTrue(result.status == 1); + + retVal3 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); + Mockito.doReturn(retVal3).when(ques).mayUser(trans, null,rolePerm, Access.write); + retVal2 = new Result<NsDAO.Data>(nsObj,0,"test1",NO_PARAM); + Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, role.ns, NsType.COMPANY); + Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, rolePerm.ns, NsType.COMPANY); + +// Mockito.doReturn(retVal).when(cachedPermDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); + + result = funcObj.addPermToRole(trans, role, rolePerm, false); + assertTrue(result.status == Status.ERR_PermissionNotFound); + + Result<List<PermDAO.Data>> retValPerm= new Result<List<PermDAO.Data>>(dataAlPerm,0,"test1",NO_PARAM); + Mockito.doReturn(retValPerm).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); + + Mockito.doReturn(retVal3).when(roleDAO).read(trans, role); + + result = funcObj.addPermToRole(trans, role, rolePerm, true); + assertTrue(result.status == 22); - Mockito.doReturn(true).when(trans).requested(REQD_TYPE.force); - result = funcObj.addPermToRole(trans, role, rolePerm, true); - assertTrue(result.status == 2); - - retVal3 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); - Mockito.doReturn(retVal3).when(ques).mayUser(trans, null,role, Access.write); - Mockito.doReturn(retVal3).when(roleDAO).create(trans, role); - result = funcObj.addPermToRole(trans, role, rolePerm, true); -// System.out.println(result.status); - assertNull(result); - - retVal3 = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal3).when(roleDAO).create(trans, role); - result = funcObj.addPermToRole(trans, role, rolePerm, true); - assertTrue(result.status == 1); - - Result<List<RoleDAO.Data>> retVal31 = new Result<List<RoleDAO.Data>>(dataAl,0,"test",NO_PARAM); - Mockito.doReturn(retVal31).when(roleDAO).read(trans, role); - result = funcObj.addPermToRole(trans, role, rolePerm, true); - assertTrue(result.status == 7); - } - - @Test - public void testDelPermFromRole() { - List<PermDAO.Data> dataAlPerm = new ArrayList<PermDAO.Data>(); - PermDAO.Data rolePerm = new PermDAO.Data(); - Set<String> rolesSetUser = new HashSet<>(); - rolesSetUser.add("testRole|test|test"); -// perm.roles = rolesSet; -// perm.type=1 - dataAlPerm.add(rolePerm); - - List<RoleDAO.Data> dataAl = new ArrayList<RoleDAO.Data>(); - RoleDAO.Data role = new RoleDAO.Data(); - Set<String> rolesSet = new HashSet<>(); - rolesSet.add("17623"); - role.perms = rolesSet; - dataAl.add(role); - -// List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); -// NsDAO.Data dataObj = new NsDAO.Data(); -// dataObj.type=1; -// dataAl.add(dataObj); - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(true).when(trans).requested(REQD_TYPE.force); + result = funcObj.addPermToRole(trans, role, rolePerm, true); + assertTrue(result.status == 2); + + retVal3 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); + Mockito.doReturn(retVal3).when(ques).mayUser(trans, null,role, Access.write); + Mockito.doReturn(retVal3).when(roleDAO).create(trans, role); + result = funcObj.addPermToRole(trans, role, rolePerm, true); +// System.out.println(result.status); + assertNull(result); + + retVal3 = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal3).when(roleDAO).create(trans, role); + result = funcObj.addPermToRole(trans, role, rolePerm, true); + assertTrue(result.status == 1); + + Result<List<RoleDAO.Data>> retVal31 = new Result<List<RoleDAO.Data>>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal31).when(roleDAO).read(trans, role); + result = funcObj.addPermToRole(trans, role, rolePerm, true); + assertTrue(result.status == 7); + } + + @Test + public void testDelPermFromRole() { + List<PermDAO.Data> dataAlPerm = new ArrayList<PermDAO.Data>(); + PermDAO.Data rolePerm = new PermDAO.Data(); + Set<String> rolesSetUser = new HashSet<>(); + rolesSetUser.add("testRole|test|test"); +// perm.roles = rolesSet; +// perm.type=1 + dataAlPerm.add(rolePerm); + + List<RoleDAO.Data> dataAl = new ArrayList<RoleDAO.Data>(); + RoleDAO.Data role = new RoleDAO.Data(); + Set<String> rolesSet = new HashSet<>(); + rolesSet.add("17623"); + role.perms = rolesSet; + dataAl.add(role); + +// List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); +// NsDAO.Data dataObj = new NsDAO.Data(); +// dataObj.type=1; +// dataAl.add(dataObj); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - Result<NsDAO.Data> retValFail = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); - Result<NsDAO.Data> retValSuc = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); - Mockito.doReturn(retValFail).when(ques).mayUser(trans, null,rolePerm, Access.write); - Mockito.doReturn(retValFail).when(ques).mayUser(trans, null,role, Access.write); - - Function funcObj = new Function(trans, ques); - Result<Void> result = funcObj.delPermFromRole(trans, role, rolePerm, false); - assertTrue(result.status == Status.ERR_Denied); - - Mockito.doReturn(retValFail).when(ques).mayUser(trans, null,rolePerm, Access.write); - Mockito.doReturn(retValSuc).when(ques).mayUser(trans, null,role, Access.write); - - Mockito.doReturn(retValFail).when(roleDAO).read(trans, role); - - Mockito.doReturn(retVal).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); - - result = funcObj.delPermFromRole(trans, role, rolePerm, false); - assertTrue(result.status == 1); - - Result<List<PermDAO.Data>> retValPermSuc = new Result<List<PermDAO.Data>>(dataAlPerm,0,"test",NO_PARAM); - Mockito.doReturn(retValPermSuc).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); - result = funcObj.delPermFromRole(trans, role, rolePerm, false); - assertTrue(result.status == 1); - - Result<List<RoleDAO.Data>> retValRoleSuc = new Result<List<RoleDAO.Data>>(dataAl,0,"test",NO_PARAM); - Mockito.doReturn(retValRoleSuc).when(roleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); - result = funcObj.delPermFromRole(trans, role, rolePerm, true); - assertTrue(result.status == Status.ERR_PermissionNotFound); - - role.perms = null; - dataAl.add(role); - rolesSet.add("null|null|null|null"); - role.perms = rolesSet; - dataAl.add(role); - Mockito.doReturn(retValRoleSuc).when(roleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); - Mockito.doReturn(retVal).when(permDAO).delRole(Mockito.any(), Mockito.any(),Mockito.any(RoleDAO.Data.class)); - result = funcObj.delPermFromRole(trans, role, rolePerm, true); - assertTrue(result.status == 1); - - Mockito.doReturn(true).when(trans).requested(REQD_TYPE.force); - result = funcObj.delPermFromRole(trans, role, rolePerm, true); - assertTrue(result.status == 1); - - Mockito.doReturn(retValRoleSuc).when(permDAO).delRole(Mockito.any(), Mockito.any(),Mockito.any(RoleDAO.Data.class)); - Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(),Mockito.any(PermDAO.Data.class)); - result = funcObj.delPermFromRole(trans, role, rolePerm, true); - assertTrue(result.status == 1); - - Mockito.doReturn(retValPermSuc).when(roleDAO).delPerm(Mockito.any(), Mockito.any(),Mockito.any(PermDAO.Data.class)); - result = funcObj.delPermFromRole(trans, role, rolePerm, true); - assertTrue(result.status == 0); - - Mockito.doReturn(retVal).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); - result = funcObj.delPermFromRole(trans, role, rolePerm, true); - assertTrue(result.status == 0); - - Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(),Mockito.any(PermDAO.Data.class)); - result = funcObj.delPermFromRole(trans, role, rolePerm, true); - assertTrue(result.status == 1); + Result<NsDAO.Data> retValFail = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); + Result<NsDAO.Data> retValSuc = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); + Mockito.doReturn(retValFail).when(ques).mayUser(trans, null,rolePerm, Access.write); + Mockito.doReturn(retValFail).when(ques).mayUser(trans, null,role, Access.write); + + Function funcObj = new Function(trans, ques); + Result<Void> result = funcObj.delPermFromRole(trans, role, rolePerm, false); + assertTrue(result.status == Status.ERR_Denied); + + Mockito.doReturn(retValFail).when(ques).mayUser(trans, null,rolePerm, Access.write); + Mockito.doReturn(retValSuc).when(ques).mayUser(trans, null,role, Access.write); + + Mockito.doReturn(retValFail).when(roleDAO).read(trans, role); + + Mockito.doReturn(retVal).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); + + result = funcObj.delPermFromRole(trans, role, rolePerm, false); + assertTrue(result.status == 1); + + Result<List<PermDAO.Data>> retValPermSuc = new Result<List<PermDAO.Data>>(dataAlPerm,0,"test",NO_PARAM); + Mockito.doReturn(retValPermSuc).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); + result = funcObj.delPermFromRole(trans, role, rolePerm, false); + assertTrue(result.status == 1); + + Result<List<RoleDAO.Data>> retValRoleSuc = new Result<List<RoleDAO.Data>>(dataAl,0,"test",NO_PARAM); + Mockito.doReturn(retValRoleSuc).when(roleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); + result = funcObj.delPermFromRole(trans, role, rolePerm, true); + assertTrue(result.status == Status.ERR_PermissionNotFound); + + role.perms = null; + dataAl.add(role); + rolesSet.add("null|null|null|null"); + role.perms = rolesSet; + dataAl.add(role); + Mockito.doReturn(retValRoleSuc).when(roleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); + Mockito.doReturn(retVal).when(permDAO).delRole(Mockito.any(), Mockito.any(),Mockito.any(RoleDAO.Data.class)); + result = funcObj.delPermFromRole(trans, role, rolePerm, true); + assertTrue(result.status == 1); + + Mockito.doReturn(true).when(trans).requested(REQD_TYPE.force); + result = funcObj.delPermFromRole(trans, role, rolePerm, true); + assertTrue(result.status == 1); + + Mockito.doReturn(retValRoleSuc).when(permDAO).delRole(Mockito.any(), Mockito.any(),Mockito.any(RoleDAO.Data.class)); + Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(),Mockito.any(PermDAO.Data.class)); + result = funcObj.delPermFromRole(trans, role, rolePerm, true); + assertTrue(result.status == 1); + + Mockito.doReturn(retValPermSuc).when(roleDAO).delPerm(Mockito.any(), Mockito.any(),Mockito.any(PermDAO.Data.class)); + result = funcObj.delPermFromRole(trans, role, rolePerm, true); + assertTrue(result.status == 0); + + Mockito.doReturn(retVal).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); + result = funcObj.delPermFromRole(trans, role, rolePerm, true); + assertTrue(result.status == 0); + + Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(),Mockito.any(PermDAO.Data.class)); + result = funcObj.delPermFromRole(trans, role, rolePerm, true); + assertTrue(result.status == 1); - NsSplit splitObj = new NsSplit("test", "test"); - Result<NsSplit> retVal3 = new Result<NsSplit>(splitObj,0,"test",NO_PARAM); - Mockito.doReturn(retVal3).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retValFail).when(ques).mayUser(Mockito.any(), Mockito.anyString(),Mockito.any(RoleDAO.Data.class), Mockito.any()); - Mockito.doReturn(retValFail).when(ques).mayUser(Mockito.any(), Mockito.anyString(),Mockito.any(PermDAO.Data.class), Mockito.any()); - result = funcObj.delPermFromRole(trans, "test", rolePerm); - assertTrue(result.status == 2); - - retVal3 = new Result<NsSplit>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal3).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); - result = funcObj.delPermFromRole(trans, "test", rolePerm); - assertTrue(result.status == 1); - } - @Test - public void testAddUserRole() { - List<UserRoleDAO.Data> urDataAl = new ArrayList<>(); - UserRoleDAO.Data urData = new UserRoleDAO.Data(); - urData.ns="test"; - urData.rname="test"; - urData.user="test"; - urDataAl.add(urData); - - Organization org = Mockito.mock(Organization.class); - Mockito.doReturn(org).when(trans).org(); - Mockito.doReturn(Mockito.mock(GregorianCalendar.class)).when(org).expiration(Mockito.any(), Mockito.any(), Mockito.anyString()); - - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Result<List<UserRoleDAO.Data>> retValSuc = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); - Mockito.doReturn(retVal).when(userRoleDAO).create(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); - Mockito.doReturn(retValSuc).when(roleDAO).read(Mockito.any(), Mockito.anyString(), Mockito.anyString()); + NsSplit splitObj = new NsSplit("test", "test"); + Result<NsSplit> retVal3 = new Result<NsSplit>(splitObj,0,"test",NO_PARAM); + Mockito.doReturn(retVal3).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retValFail).when(ques).mayUser(Mockito.any(), Mockito.anyString(),Mockito.any(RoleDAO.Data.class), Mockito.any()); + Mockito.doReturn(retValFail).when(ques).mayUser(Mockito.any(), Mockito.anyString(),Mockito.any(PermDAO.Data.class), Mockito.any()); + result = funcObj.delPermFromRole(trans, "test", rolePerm); + assertTrue(result.status == 2); + + retVal3 = new Result<NsSplit>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal3).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); + result = funcObj.delPermFromRole(trans, "test", rolePerm); + assertTrue(result.status == 1); + } + @Test + public void testAddUserRole() { + List<UserRoleDAO.Data> urDataAl = new ArrayList<>(); + UserRoleDAO.Data urData = new UserRoleDAO.Data(); + urData.ns="test"; + urData.rname="test"; + urData.user="test"; + urDataAl.add(urData); + + Organization org = Mockito.mock(Organization.class); + Mockito.doReturn(org).when(trans).org(); + Mockito.doReturn(Mockito.mock(GregorianCalendar.class)).when(org).expiration(Mockito.any(), Mockito.any(), Mockito.anyString()); + + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); + Result<List<UserRoleDAO.Data>> retValSuc = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); + Mockito.doReturn(retVal).when(userRoleDAO).create(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); + Mockito.doReturn(retValSuc).when(roleDAO).read(Mockito.any(), Mockito.anyString(), Mockito.anyString()); - Result<List<CredDAO.Data>> retVal2 = new Result<List<CredDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(credDAO).readID(Mockito.any(), Mockito.anyString()); - - Function funcObj = new Function(trans, ques); - Result<Void> result = funcObj.addUserRole(trans, urData); - assertTrue(result.status == 1); - - urData.rname=Question.ADMIN; - result = funcObj.addUserRole(trans, urData); - assertTrue(result.status == 1); - - NsDAO.Data data = new NsDAO.Data(); - data.name="test"; - Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); - Mockito.doReturn(retVal1).when(ques).mayUser(trans, null,retVal1.value, Access.write); - Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - try { - Mockito.doReturn(Mockito.mock(Identity.class)).when(org).getIdentity(trans, "test"); - } catch (OrganizationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - urData.rname=Question.OWNER; - result = funcObj.addUserRole(trans, urData); - assertTrue(result.status == 1); + Result<List<CredDAO.Data>> retVal2 = new Result<List<CredDAO.Data>>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal2).when(credDAO).readID(Mockito.any(), Mockito.anyString()); + + Function funcObj = new Function(trans, ques); + Result<Void> result = funcObj.addUserRole(trans, urData); + assertTrue(result.status == 1); + + urData.rname=Question.ADMIN; + result = funcObj.addUserRole(trans, urData); + assertTrue(result.status == 1); + + NsDAO.Data data = new NsDAO.Data(); + data.name="test"; + Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); + Mockito.doReturn(retVal1).when(ques).mayUser(trans, null,retVal1.value, Access.write); + Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); + try { + Mockito.doReturn(Mockito.mock(Identity.class)).when(org).getIdentity(trans, "test"); + } catch (OrganizationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + urData.rname=Question.OWNER; + result = funcObj.addUserRole(trans, urData); + assertTrue(result.status == 1); - Mockito.doReturn(retValSuc).when(userRoleDAO).create(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); - result = funcObj.addUserRole(trans, urData); - assertTrue(result.status == 0); + Mockito.doReturn(retValSuc).when(userRoleDAO).create(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); + result = funcObj.addUserRole(trans, urData); + assertTrue(result.status == 0); - Mockito.doReturn(retVal).when(roleDAO).read(Mockito.any(), Mockito.anyString(), Mockito.anyString()); - result = funcObj.addUserRole(trans, urData); - assertTrue(result.status == Status.ERR_RoleNotFound); - - Mockito.doReturn(retValSuc).when(userRoleDAO).read(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); - result = funcObj.addUserRole(trans, urData); - assertTrue(result.status == Status.ERR_ConflictAlreadyExists); - - result = funcObj.addUserRole(trans, "test", "test", "test"); - assertTrue(result.status == 1); - - try { - Mockito.doReturn(null).when(org).getIdentity(trans, "test"); - } catch (OrganizationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - result = funcObj.addUserRole(trans, "test", "test", "test"); - assertTrue(result.status == Result.ERR_BadData); - - try { - Mockito.doThrow(OrganizationException.class).when(org).getIdentity(trans, "test"); - } catch (OrganizationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - result = funcObj.addUserRole(trans, "test", "test", "test"); - assertTrue(result.status == 20); - } - - @Test - public void testExtendUserRole() { - List<UserRoleDAO.Data> urDataAl = new ArrayList<>(); - UserRoleDAO.Data urData = new UserRoleDAO.Data(); - urData.ns="test"; - urData.rname="test"; - urData.user="test"; - urData.expires=new Date(); - urDataAl.add(urData); - -// List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); -// NsDAO.Data dataObj = new NsDAO.Data(); -// dataObj.type=1; -// dataAl.add(dataObj); - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Result<List<UserRoleDAO.Data>> retValSuc = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retValSuc).when(roleDAO).read(Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.doReturn(retVal).when(roleDAO).read(Mockito.any(), Mockito.anyString(), Mockito.anyString()); + result = funcObj.addUserRole(trans, urData); + assertTrue(result.status == Status.ERR_RoleNotFound); + + Mockito.doReturn(retValSuc).when(userRoleDAO).read(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); + result = funcObj.addUserRole(trans, urData); + assertTrue(result.status == Status.ERR_ConflictAlreadyExists); + + result = funcObj.addUserRole(trans, "test", "test", "test"); + assertTrue(result.status == 1); + + try { + Mockito.doReturn(null).when(org).getIdentity(trans, "test"); + } catch (OrganizationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + result = funcObj.addUserRole(trans, "test", "test", "test"); + assertTrue(result.status == Result.ERR_BadData); + + try { + Mockito.doThrow(OrganizationException.class).when(org).getIdentity(trans, "test"); + } catch (OrganizationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + result = funcObj.addUserRole(trans, "test", "test", "test"); + assertTrue(result.status == 20); + } + + @Test + public void testExtendUserRole() { + List<UserRoleDAO.Data> urDataAl = new ArrayList<>(); + UserRoleDAO.Data urData = new UserRoleDAO.Data(); + urData.ns="test"; + urData.rname="test"; + urData.user="test"; + urData.expires=new Date(); + urDataAl.add(urData); + +// List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); +// NsDAO.Data dataObj = new NsDAO.Data(); +// dataObj.type=1; +// dataAl.add(dataObj); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); + Result<List<UserRoleDAO.Data>> retValSuc = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retValSuc).when(roleDAO).read(Mockito.any(), Mockito.anyString(), Mockito.anyString()); - Organization org = Mockito.mock(Organization.class); - Mockito.doReturn(org).when(trans).org(); - Mockito.doReturn(Mockito.mock(GregorianCalendar.class)).when(org).expiration(Mockito.any(), Mockito.any()); - - Function funcObj = new Function(trans, ques); - Result<Void> result = funcObj.extendUserRole(trans, urData, false); - assertNull(result); - - Mockito.doReturn(retVal).when(roleDAO).read(Mockito.any(), Mockito.anyString(), Mockito.anyString()); - Mockito.doReturn(retValSuc).when(userRoleDAO).read(trans, urData); - result = funcObj.extendUserRole(trans, urData, true); - assertTrue(result.status == Status.ERR_RoleNotFound); - - Mockito.doReturn(retVal).when(userRoleDAO).read(trans, urData); - result = funcObj.extendUserRole(trans, urData, true); - assertTrue(result.status == Status.ERR_UserRoleNotFound); - } - - @SuppressWarnings("deprecation") - @Test - public void testGetUsersByRole() { - List<UserRoleDAO.Data> urDataAl = new ArrayList<>(); - UserRoleDAO.Data urData = new UserRoleDAO.Data(); - urData.ns="test"; - urData.rname="test"; - urData.user="test"; - urData.expires=new Date(); - urDataAl.add(urData); - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + Organization org = Mockito.mock(Organization.class); + Mockito.doReturn(org).when(trans).org(); + Mockito.doReturn(Mockito.mock(GregorianCalendar.class)).when(org).expiration(Mockito.any(), Mockito.any()); + + Function funcObj = new Function(trans, ques); + Result<Void> result = funcObj.extendUserRole(trans, urData, false); + assertNull(result); + + Mockito.doReturn(retVal).when(roleDAO).read(Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.doReturn(retValSuc).when(userRoleDAO).read(trans, urData); + result = funcObj.extendUserRole(trans, urData, true); + assertTrue(result.status == Status.ERR_RoleNotFound); + + Mockito.doReturn(retVal).when(userRoleDAO).read(trans, urData); + result = funcObj.extendUserRole(trans, urData, true); + assertTrue(result.status == Status.ERR_UserRoleNotFound); + } + + @SuppressWarnings("deprecation") + @Test + public void testGetUsersByRole() { + List<UserRoleDAO.Data> urDataAl = new ArrayList<>(); + UserRoleDAO.Data urData = new UserRoleDAO.Data(); + urData.ns="test"; + urData.rname="test"; + urData.user="test"; + urData.expires=new Date(); + urDataAl.add(urData); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - Function funcObj = new Function(trans, ques); - Result<List<String>> result = funcObj.getUsersByRole(trans, "test", false); - assertTrue(result.status == 0); + Function funcObj = new Function(trans, ques); + Result<List<String>> result = funcObj.getUsersByRole(trans, "test", false); + assertTrue(result.status == 0); - result = funcObj.getUsersByRole(trans, "test", true); - assertTrue(result.status == 0); - - urData.expires=new Date(130,1,1); - result = funcObj.getUsersByRole(trans, "test", true); - assertTrue(result.status == 0); -// - } - @Test - public void testDelUserRole() { - List<UserRoleDAO.Data> urDataAl = new ArrayList<>(); - UserRoleDAO.Data urData = new UserRoleDAO.Data(); - urData.ns="test"; - urData.rname="test"; - urData.user="test"; - urData.expires=new Date(); - urDataAl.add(urData); - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); + result = funcObj.getUsersByRole(trans, "test", true); + assertTrue(result.status == 0); + + urData.expires=new Date(130,1,1); + result = funcObj.getUsersByRole(trans, "test", true); + assertTrue(result.status == 0); +// + } + @Test + public void testDelUserRole() { + List<UserRoleDAO.Data> urDataAl = new ArrayList<>(); + UserRoleDAO.Data urData = new UserRoleDAO.Data(); + urData.ns="test"; + urData.rname="test"; + urData.user="test"; + urData.expires=new Date(); + urDataAl.add(urData); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",NO_PARAM); + Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); - Function funcObj = new Function(trans, ques); - Result<Void> result = funcObj.delUserRole(trans, "test", "test", "test"); - assertNull(result); - - retVal = new Result<List<UserRoleDAO.Data>>(urDataAl,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); - result = funcObj.delUserRole(trans, "test", "test", "test"); -// assertTrue(result.status ==1); -// - } - - @Test - public void testCreateFuture() { - FutureDAO.Data data = new FutureDAO.Data(); - data.memo = "test"; - NsDAO.Data nsd = new NsDAO.Data(); - nsd.name = "test"; - - List<UserRoleDAO.Data> urDataAl = new ArrayList<>(); - UserRoleDAO.Data urData = new UserRoleDAO.Data(); - urData.ns="test"; - urData.rname="test"; - urData.user="test"; - urData.expires=new Date(); - urDataAl.add(urData); - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",NO_PARAM); - Result<List<UserRoleDAO.Data>> retValFail = new Result<List<UserRoleDAO.Data>>(urDataAl,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); + Function funcObj = new Function(trans, ques); + Result<Void> result = funcObj.delUserRole(trans, "test", "test", "test"); + assertNull(result); + + retVal = new Result<List<UserRoleDAO.Data>>(urDataAl,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); + result = funcObj.delUserRole(trans, "test", "test", "test"); +// assertTrue(result.status ==1); +// + } + + @Test + public void testCreateFuture() { + FutureDAO.Data data = new FutureDAO.Data(); + data.memo = "test"; + NsDAO.Data nsd = new NsDAO.Data(); + nsd.name = "test"; + + List<UserRoleDAO.Data> urDataAl = new ArrayList<>(); + UserRoleDAO.Data urData = new UserRoleDAO.Data(); + urData.ns="test"; + urData.rname="test"; + urData.user="test"; + urData.expires=new Date(); + urDataAl.add(urData); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",NO_PARAM); + Result<List<UserRoleDAO.Data>> retValFail = new Result<List<UserRoleDAO.Data>>(urDataAl,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); - Function funcObj = new Function(trans, ques); - Result<String> result = funcObj.createFuture(trans, data, "test", "test", nsd, FUTURE_OP.A); - assertTrue(result.status == 20); + Function funcObj = new Function(trans, ques); + Result<String> result = funcObj.createFuture(trans, data, "test", "test", nsd, FUTURE_OP.A); + assertTrue(result.status == 20); - Identity iden=Mockito.mock(Identity.class); - try { - Mockito.doReturn(iden).when(org).getIdentity(trans, "test"); - Mockito.doReturn("test").when(iden).mayOwn(); - } catch (OrganizationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - FutureDAO.Data futureData = new FutureDAO.Data(); - data.memo = "test"; - Result<FutureDAO.Data> retValFuture = new Result<FutureDAO.Data>(futureData,0,"test",NO_PARAM); - Mockito.doReturn(retValFuture).when(futureDAO).create(Mockito.any(), Mockito.any( FutureDAO.Data.class), Mockito.anyString()); - - ApprovalDAO.Data approvalData = new ApprovalDAO.Data(); - data.memo = "test"; - Result<ApprovalDAO.Data> retValApproval = new Result<ApprovalDAO.Data>(approvalData,0,"test",NO_PARAM); - Mockito.doReturn(retValApproval).when(approvalDAO).create(Mockito.any(), Mockito.any( ApprovalDAO.Data.class)); - - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - result = funcObj.createFuture(trans, data, "test", "test", nsd, FUTURE_OP.A); - assertTrue(result.status == 0); - - result = funcObj.createFuture(trans, data, "test", "test", null, FUTURE_OP.A); - assertTrue(result.status == 20); + Identity iden=Mockito.mock(Identity.class); + try { + Mockito.doReturn(iden).when(org).getIdentity(trans, "test"); + Mockito.doReturn("test").when(iden).mayOwn(); + } catch (OrganizationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + FutureDAO.Data futureData = new FutureDAO.Data(); + data.memo = "test"; + Result<FutureDAO.Data> retValFuture = new Result<FutureDAO.Data>(futureData,0,"test",NO_PARAM); + Mockito.doReturn(retValFuture).when(futureDAO).create(Mockito.any(), Mockito.any( FutureDAO.Data.class), Mockito.anyString()); + + ApprovalDAO.Data approvalData = new ApprovalDAO.Data(); + data.memo = "test"; + Result<ApprovalDAO.Data> retValApproval = new Result<ApprovalDAO.Data>(approvalData,0,"test",NO_PARAM); + Mockito.doReturn(retValApproval).when(approvalDAO).create(Mockito.any(), Mockito.any( ApprovalDAO.Data.class)); + + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + result = funcObj.createFuture(trans, data, "test", "test", nsd, FUTURE_OP.A); + assertTrue(result.status == 0); + + result = funcObj.createFuture(trans, data, "test", "test", null, FUTURE_OP.A); + assertTrue(result.status == 20); - Mockito.doReturn(retValFail).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - result = funcObj.createFuture(trans, data, "test", "test", nsd, FUTURE_OP.A); - assertTrue(result.status == Result.ERR_NotFound); - - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - try { - Mockito.doReturn(null).when(org).getIdentity(trans, "test"); - } catch (OrganizationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - result = funcObj.createFuture(trans, data, "test", "test", nsd, FUTURE_OP.A); - assertTrue(result.status == Result.ERR_NotFound); - - try { - Mockito.doReturn(iden).when(org).getIdentity(trans, "test"); - } catch (OrganizationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - result = funcObj.createFuture(trans, data, "test", "test", nsd, FUTURE_OP.C); - assertTrue(result.status == 0); - - retValApproval = new Result<ApprovalDAO.Data>(null,1,"test",NO_PARAM); - Mockito.doReturn(retValApproval).when(approvalDAO).create(Mockito.any(), Mockito.any( ApprovalDAO.Data.class)); - result = funcObj.createFuture(trans, data, "test", "test", nsd, FUTURE_OP.A); - assertTrue(result.status == 8); - } - @Test - public void testUbLookup() { - Object[] objArr = new Object[10]; - List<UserRoleDAO.Data> urDataAl = new ArrayList<>(); - UserRoleDAO.Data urData = new UserRoleDAO.Data(); - urData.ns="test"; - urData.rname="test"; - urData.user="test"; - urData.expires=new Date(); - urDataAl.add(urData); - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",NO_PARAM); - Result<List<UserRoleDAO.Data>> retValFail = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).read(trans, objArr); - - Function funcObj = new Function(trans, ques); - funcObj.urDBLookup.get(trans, objArr); - - Mockito.doReturn(retValFail).when(userRoleDAO).read(trans, objArr); - funcObj.urDBLookup.get(trans, objArr); - } - - @Test - public void testPerformFutureOp() { - FutureDAO.Data futureDataDaoObj = new FutureDAO.Data(); - futureDataDaoObj.memo="test"; - futureDataDaoObj.target = "test"; - futureDataDaoObj.id = new UUID(10L,10L); - - final List<ApprovalDAO.Data> apprs = new ArrayList<>(); - ApprovalDAO.Data approvalObj = new ApprovalDAO.Data(); - approvalObj.status = "approved"; - approvalObj.type = "owner"; - apprs.add(approvalObj); - Lookup<List<ApprovalDAO.Data>> lookupApprovalObj = new Lookup<List<ApprovalDAO.Data>>() { + Mockito.doReturn(retValFail).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + result = funcObj.createFuture(trans, data, "test", "test", nsd, FUTURE_OP.A); + assertTrue(result.status == Result.ERR_NotFound); + + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + try { + Mockito.doReturn(null).when(org).getIdentity(trans, "test"); + } catch (OrganizationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + result = funcObj.createFuture(trans, data, "test", "test", nsd, FUTURE_OP.A); + assertTrue(result.status == Result.ERR_NotFound); + + try { + Mockito.doReturn(iden).when(org).getIdentity(trans, "test"); + } catch (OrganizationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + result = funcObj.createFuture(trans, data, "test", "test", nsd, FUTURE_OP.C); + assertTrue(result.status == 0); + + retValApproval = new Result<ApprovalDAO.Data>(null,1,"test",NO_PARAM); + Mockito.doReturn(retValApproval).when(approvalDAO).create(Mockito.any(), Mockito.any( ApprovalDAO.Data.class)); + result = funcObj.createFuture(trans, data, "test", "test", nsd, FUTURE_OP.A); + assertTrue(result.status == 8); + } + @Test + public void testUbLookup() { + Object[] objArr = new Object[10]; + List<UserRoleDAO.Data> urDataAl = new ArrayList<>(); + UserRoleDAO.Data urData = new UserRoleDAO.Data(); + urData.ns="test"; + urData.rname="test"; + urData.user="test"; + urData.expires=new Date(); + urDataAl.add(urData); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",NO_PARAM); + Result<List<UserRoleDAO.Data>> retValFail = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(userRoleDAO).read(trans, objArr); + + Function funcObj = new Function(trans, ques); + funcObj.urDBLookup.get(trans, objArr); + + Mockito.doReturn(retValFail).when(userRoleDAO).read(trans, objArr); + funcObj.urDBLookup.get(trans, objArr); + } + + @Test + public void testPerformFutureOp() { + FutureDAO.Data futureDataDaoObj = new FutureDAO.Data(); + futureDataDaoObj.memo="test"; + futureDataDaoObj.target = "test"; + futureDataDaoObj.id = new UUID(10L,10L); + + final List<ApprovalDAO.Data> apprs = new ArrayList<>(); + ApprovalDAO.Data approvalObj = new ApprovalDAO.Data(); + approvalObj.status = "approved"; + approvalObj.type = "owner"; + apprs.add(approvalObj); + Lookup<List<ApprovalDAO.Data>> lookupApprovalObj = new Lookup<List<ApprovalDAO.Data>>() { @Override public List<ApprovalDAO.Data> get(AuthzTrans trans, Object ... keys) { return apprs; @@ -1706,61 +1706,61 @@ public class JU_Function { return userObj; } }; - + FutureDAO.Data futureData = new FutureDAO.Data(); -// data.memo = "test"; - Result<FutureDAO.Data> retValFuture = new Result<FutureDAO.Data>(futureData,0,"test",NO_PARAM); - Mockito.doReturn(retValFuture).when(futureDAO).delete(Mockito.any(), Mockito.any( FutureDAO.Data.class), Mockito.anyBoolean()); - -// List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); -// NsDAO.Data dataObj = new NsDAO.Data(); -// dataObj.type=1; -// dataAl.add(dataObj); - Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); -// -// Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); -// Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); -// - Function funcObj = new Function(trans, ques); - Result<Function.OP_STATUS> result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); - assertTrue(result.status == 0); - - approvalObj.status = "approved"; - approvalObj.type = "supervisor"; - result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); - assertTrue(result.status == 0); - - approvalObj.status = "approved"; - approvalObj.type = ""; - result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); - assertTrue(result.status == 0); - - approvalObj.status = "pending"; - approvalObj.type = "supervisor"; - result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); - assertTrue(result.status == 0); - - approvalObj.status = "pending"; - approvalObj.type = "owner"; - result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); - assertTrue(result.status == 0); - - approvalObj.status = "pending"; - approvalObj.type = ""; - result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); - assertTrue(result.status == 0); - - approvalObj.status = "denied"; - approvalObj.type = ""; - result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); - assertTrue(result.status == 0); - - retValFuture = new Result<FutureDAO.Data>(futureData,1,"test",NO_PARAM); - Mockito.doReturn(retValFuture).when(futureDAO).delete(Mockito.any(), Mockito.any( FutureDAO.Data.class), Mockito.anyBoolean()); - result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); - System.out.println(result); - assertTrue(result.status == 0); -// - } +// data.memo = "test"; + Result<FutureDAO.Data> retValFuture = new Result<FutureDAO.Data>(futureData,0,"test",NO_PARAM); + Mockito.doReturn(retValFuture).when(futureDAO).delete(Mockito.any(), Mockito.any( FutureDAO.Data.class), Mockito.anyBoolean()); + +// List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); +// NsDAO.Data dataObj = new NsDAO.Data(); +// dataObj.type=1; +// dataAl.add(dataObj); + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); +// +// Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); +// Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); +// + Function funcObj = new Function(trans, ques); + Result<Function.OP_STATUS> result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); + assertTrue(result.status == 0); + + approvalObj.status = "approved"; + approvalObj.type = "supervisor"; + result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); + assertTrue(result.status == 0); + + approvalObj.status = "approved"; + approvalObj.type = ""; + result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); + assertTrue(result.status == 0); + + approvalObj.status = "pending"; + approvalObj.type = "supervisor"; + result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); + assertTrue(result.status == 0); + + approvalObj.status = "pending"; + approvalObj.type = "owner"; + result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); + assertTrue(result.status == 0); + + approvalObj.status = "pending"; + approvalObj.type = ""; + result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); + assertTrue(result.status == 0); + + approvalObj.status = "denied"; + approvalObj.type = ""; + result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); + assertTrue(result.status == 0); + + retValFuture = new Result<FutureDAO.Data>(futureData,1,"test",NO_PARAM); + Mockito.doReturn(retValFuture).when(futureDAO).delete(Mockito.any(), Mockito.any( FutureDAO.Data.class), Mockito.anyBoolean()); + result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); + System.out.println(result); + assertTrue(result.status == 0); +// + } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_PermLookup.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_PermLookup.java index 9313af7a..7e1abeba 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_PermLookup.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_PermLookup.java @@ -54,335 +54,335 @@ import org.onap.aaf.misc.env.LogTarget; @RunWith(MockitoJUnitRunner.class) public class JU_PermLookup { - - - @Mock - AuthzTrans trans; - - @Mock - Question q; - - @Mock - Access access; + + + @Mock + AuthzTrans trans; + + @Mock + Question q; + + @Mock + Access access; - @Mock - CachedRoleDAO roleDAO; + @Mock + CachedRoleDAO roleDAO; - @Mock - CachedUserRoleDAO userRoleDAO; - - Function f; - - @Before - public void setUp() throws Exception { - initMocks(this); - Mockito.doReturn(userRoleDAO).when(q).userRoleDAO(); - Mockito.doReturn(roleDAO).when(q).roleDAO(); - - try { - Mockito.doReturn("0.0").when(access).getProperty("aaf_root_ns","org.osaaf.aaf"); - Mockito.doReturn(new Properties()).when(access).getProperties(); - Define.set(access); - - when(trans.error()).thenReturn(new LogTarget() { - - @Override - public void printf(String fmt, Object... vars) {} - - @Override - public void log(Throwable e, Object... msgs) { - e.getMessage(); - e.printStackTrace(); - msgs.toString(); - - } - - @Override - public void log(Object... msgs) { - } - - @Override - public boolean isLoggable() { - - return true; - } - }); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - f =new Function(trans, q); - } - - -// @Test -// public void testPerm() { -// -// PermLookup cassExecutorObj =PermLookup.get(trans, q,""); -// -//// System.out.println(cassExecutorObj); -//// assertFalse(retVal); -// } - - @Test - public void testGetUserRole() { - @SuppressWarnings("unchecked") - Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); - retVal1.value = new ArrayList<UserRoleDAO.Data>(); - UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); - - dataObj.expires = new Date(); - - retVal1.value.add(dataObj); - Mockito.doReturn(true).when(retVal1).isOKhasData(); - Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); - PermLookup cassExecutorObj =PermLookup.get(trans, q,""); - Result<List<UserRoleDAO.Data>> userRoles = cassExecutorObj.getUserRoles(); - - //System.out.println(""+userRoles.status); - assertEquals(24,userRoles.status); - } - - @Test - public void testGetUserRolesFirstIf() { - @SuppressWarnings("unchecked") - Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); - retVal1.value = new ArrayList<UserRoleDAO.Data>(); - - Mockito.doReturn(false).when(retVal1).isOKhasData(); - Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); - PermLookup cassExecutorObj =PermLookup.get(trans, q,""); - Result<List<UserRoleDAO.Data>> userRoles = cassExecutorObj.getUserRoles(); - -// System.out.println("output is"+userRoles.status); - assertEquals(0,userRoles.status); - } - - @Test - public void testGetUserRolesSecondIf() { - @SuppressWarnings("unchecked") - Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); - retVal1.value = new ArrayList<UserRoleDAO.Data>(); - UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); - - Date dt = new Date(); - Calendar c = Calendar.getInstance(); - c.setTime(dt); - c.add(Calendar.DATE, 1); - dataObj.expires = c.getTime(); - - retVal1.value.add(dataObj); - Mockito.doReturn(true).when(retVal1).isOKhasData(); - Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); - PermLookup cassExecutorObj =PermLookup.get(trans, q,""); - Result<List<UserRoleDAO.Data>> userRoles = cassExecutorObj.getUserRoles(); - - //System.out.println(userRoles.status); - assertEquals("Success",userRoles.details); - Result<List<UserRoleDAO.Data>> userRoles1 = cassExecutorObj.getUserRoles(); + @Mock + CachedUserRoleDAO userRoleDAO; + + Function f; + + @Before + public void setUp() throws Exception { + initMocks(this); + Mockito.doReturn(userRoleDAO).when(q).userRoleDAO(); + Mockito.doReturn(roleDAO).when(q).roleDAO(); + + try { + Mockito.doReturn("0.0").when(access).getProperty("aaf_root_ns","org.osaaf.aaf"); + Mockito.doReturn(new Properties()).when(access).getProperties(); + Define.set(access); + + when(trans.error()).thenReturn(new LogTarget() { + + @Override + public void printf(String fmt, Object... vars) {} + + @Override + public void log(Throwable e, Object... msgs) { + e.getMessage(); + e.printStackTrace(); + msgs.toString(); + + } + + @Override + public void log(Object... msgs) { + } + + @Override + public boolean isLoggable() { + + return true; + } + }); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + f =new Function(trans, q); + } + + +// @Test +// public void testPerm() { +// +// PermLookup cassExecutorObj =PermLookup.get(trans, q,""); +// +//// System.out.println(cassExecutorObj); +//// assertFalse(retVal); +// } + + @Test + public void testGetUserRole() { + @SuppressWarnings("unchecked") + Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); + retVal1.value = new ArrayList<UserRoleDAO.Data>(); + UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); + + dataObj.expires = new Date(); + + retVal1.value.add(dataObj); + Mockito.doReturn(true).when(retVal1).isOKhasData(); + Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); + PermLookup cassExecutorObj =PermLookup.get(trans, q,""); + Result<List<UserRoleDAO.Data>> userRoles = cassExecutorObj.getUserRoles(); + + //System.out.println(""+userRoles.status); + assertEquals(24,userRoles.status); + } + + @Test + public void testGetUserRolesFirstIf() { + @SuppressWarnings("unchecked") + Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); + retVal1.value = new ArrayList<UserRoleDAO.Data>(); + + Mockito.doReturn(false).when(retVal1).isOKhasData(); + Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); + PermLookup cassExecutorObj =PermLookup.get(trans, q,""); + Result<List<UserRoleDAO.Data>> userRoles = cassExecutorObj.getUserRoles(); + +// System.out.println("output is"+userRoles.status); + assertEquals(0,userRoles.status); + } + + @Test + public void testGetUserRolesSecondIf() { + @SuppressWarnings("unchecked") + Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); + retVal1.value = new ArrayList<UserRoleDAO.Data>(); + UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); + + Date dt = new Date(); + Calendar c = Calendar.getInstance(); + c.setTime(dt); + c.add(Calendar.DATE, 1); + dataObj.expires = c.getTime(); + + retVal1.value.add(dataObj); + Mockito.doReturn(true).when(retVal1).isOKhasData(); + Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); + PermLookup cassExecutorObj =PermLookup.get(trans, q,""); + Result<List<UserRoleDAO.Data>> userRoles = cassExecutorObj.getUserRoles(); + + //System.out.println(userRoles.status); + assertEquals("Success",userRoles.details); + Result<List<UserRoleDAO.Data>> userRoles1 = cassExecutorObj.getUserRoles(); - //System.out.println(userRoles1.status); - assertEquals(0, userRoles1.status); - } - - @Test - public void testGetRole() { - @SuppressWarnings("unchecked") - Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); - retVal1.value = new ArrayList<UserRoleDAO.Data>(); - UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); - - dataObj.expires = new Date(); - - retVal1.value.add(dataObj); - Mockito.doReturn(false).when(retVal1).isOKhasData(); - Mockito.doReturn(true).when(retVal1).isOK(); - Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); - PermLookup cassExecutorObj =PermLookup.get(trans, q,""); - Result<List<RoleDAO.Data>> userRoles = cassExecutorObj.getRoles(); - - //System.out.println(""+userRoles.status); - assertEquals(4,userRoles.status); - } - - @Test - public void testGetRoleFirstIf() { - @SuppressWarnings("unchecked") - Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); - retVal1.value = new ArrayList<UserRoleDAO.Data>(); - UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); - - dataObj.expires = new Date(); - dataObj.ns=""; - dataObj.rname=""; - - retVal1.value.add(dataObj); - Mockito.doReturn(false).when(retVal1).isOKhasData(); - Mockito.doReturn(false).when(retVal1).isOK(); - Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); - Mockito.doReturn(retVal1).when(roleDAO).read(trans,"",""); - PermLookup cassExecutorObj =PermLookup.get(trans, q,""); - Result<List<RoleDAO.Data>> userRoles = cassExecutorObj.getRoles(); - -// System.out.println(""+userRoles.status); - assertEquals(0,userRoles.status); - } - - @Test - public void testGetRoleSecondIf() { - @SuppressWarnings("unchecked") - Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); - retVal1.value = new ArrayList<UserRoleDAO.Data>(); - UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); - - dataObj.expires = new Date(); - dataObj.ns=""; - dataObj.rname=""; - - retVal1.value.add(dataObj); - Mockito.doReturn(false).when(retVal1).isOKhasData(); - Mockito.doReturn(true).when(retVal1).isOK(); - Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); - Mockito.doReturn(retVal1).when(roleDAO).read(trans,"",""); - PermLookup cassExecutorObj =PermLookup.get(trans, q,""); - Result<List<RoleDAO.Data>> userRoles = cassExecutorObj.getRoles(); - userRoles = cassExecutorObj.getRoles(); - -// System.out.println(""+userRoles.status); - assertEquals(0,userRoles.status); - } - @Test - public void testGetPerms() { - @SuppressWarnings("unchecked") - Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); - retVal1.value = new ArrayList<UserRoleDAO.Data>(); - Mockito.doReturn(false).when(retVal1).isOKhasData(); - Mockito.doReturn(true).when(retVal1).isOK(); - Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); - PermLookup cassExecutorObj =PermLookup.get(trans, q,""); - Result<Set<String>> userRoles = cassExecutorObj.getPermNames(); - userRoles = cassExecutorObj.getPermNames(); - - //System.out.println(""+userRoles.status); - assertEquals(0,userRoles.status); - } - @Test - public void testGetPermsRrldOk() { - @SuppressWarnings("unchecked") - Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); - retVal1.value = new ArrayList<UserRoleDAO.Data>(); - UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); - - dataObj.expires = new Date(); - - retVal1.value.add(dataObj); - Mockito.doReturn(false).when(retVal1).isOKhasData(); - Mockito.doReturn(true).when(retVal1).isOK(); - Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); - PermLookup cassExecutorObj =PermLookup.get(trans, q,""); - Result<Set<String>> userRoles = cassExecutorObj.getPermNames(); - - //System.out.println(""+userRoles.status); - assertEquals(4,userRoles.status); - } + //System.out.println(userRoles1.status); + assertEquals(0, userRoles1.status); + } + + @Test + public void testGetRole() { + @SuppressWarnings("unchecked") + Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); + retVal1.value = new ArrayList<UserRoleDAO.Data>(); + UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); + + dataObj.expires = new Date(); + + retVal1.value.add(dataObj); + Mockito.doReturn(false).when(retVal1).isOKhasData(); + Mockito.doReturn(true).when(retVal1).isOK(); + Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); + PermLookup cassExecutorObj =PermLookup.get(trans, q,""); + Result<List<RoleDAO.Data>> userRoles = cassExecutorObj.getRoles(); + + //System.out.println(""+userRoles.status); + assertEquals(4,userRoles.status); + } + + @Test + public void testGetRoleFirstIf() { + @SuppressWarnings("unchecked") + Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); + retVal1.value = new ArrayList<UserRoleDAO.Data>(); + UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); + + dataObj.expires = new Date(); + dataObj.ns=""; + dataObj.rname=""; + + retVal1.value.add(dataObj); + Mockito.doReturn(false).when(retVal1).isOKhasData(); + Mockito.doReturn(false).when(retVal1).isOK(); + Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); + Mockito.doReturn(retVal1).when(roleDAO).read(trans,"",""); + PermLookup cassExecutorObj =PermLookup.get(trans, q,""); + Result<List<RoleDAO.Data>> userRoles = cassExecutorObj.getRoles(); + +// System.out.println(""+userRoles.status); + assertEquals(0,userRoles.status); + } + + @Test + public void testGetRoleSecondIf() { + @SuppressWarnings("unchecked") + Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); + retVal1.value = new ArrayList<UserRoleDAO.Data>(); + UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); + + dataObj.expires = new Date(); + dataObj.ns=""; + dataObj.rname=""; + + retVal1.value.add(dataObj); + Mockito.doReturn(false).when(retVal1).isOKhasData(); + Mockito.doReturn(true).when(retVal1).isOK(); + Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); + Mockito.doReturn(retVal1).when(roleDAO).read(trans,"",""); + PermLookup cassExecutorObj =PermLookup.get(trans, q,""); + Result<List<RoleDAO.Data>> userRoles = cassExecutorObj.getRoles(); + userRoles = cassExecutorObj.getRoles(); + +// System.out.println(""+userRoles.status); + assertEquals(0,userRoles.status); + } + @Test + public void testGetPerms() { + @SuppressWarnings("unchecked") + Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); + retVal1.value = new ArrayList<UserRoleDAO.Data>(); + Mockito.doReturn(false).when(retVal1).isOKhasData(); + Mockito.doReturn(true).when(retVal1).isOK(); + Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); + PermLookup cassExecutorObj =PermLookup.get(trans, q,""); + Result<Set<String>> userRoles = cassExecutorObj.getPermNames(); + userRoles = cassExecutorObj.getPermNames(); + + //System.out.println(""+userRoles.status); + assertEquals(0,userRoles.status); + } + @Test + public void testGetPermsRrldOk() { + @SuppressWarnings("unchecked") + Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); + retVal1.value = new ArrayList<UserRoleDAO.Data>(); + UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); + + dataObj.expires = new Date(); + + retVal1.value.add(dataObj); + Mockito.doReturn(false).when(retVal1).isOKhasData(); + Mockito.doReturn(true).when(retVal1).isOK(); + Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); + PermLookup cassExecutorObj =PermLookup.get(trans, q,""); + Result<Set<String>> userRoles = cassExecutorObj.getPermNames(); + + //System.out.println(""+userRoles.status); + assertEquals(4,userRoles.status); + } - @SuppressWarnings("unchecked") - @Test - public void testGetPerm() { - Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); - Result<List<RoleDAO.Data>> retVal2 = Mockito.mock(Result.class); - - retVal1.value = new ArrayList<UserRoleDAO.Data>(); - retVal2.value = new ArrayList<RoleDAO.Data>(); - UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); - - Date dt = new Date(); - Calendar c = Calendar.getInstance(); - c.setTime(dt); - c.add(Calendar.DATE, 1); - dataObj.expires = c.getTime(); - dataObj.ns = ""; - dataObj.rname=""; - - RoleDAO.Data dataObj1 = Mockito.mock( RoleDAO.Data.class); - Set<String> permSet = new HashSet<String>(); - permSet.add("test"); - Mockito.doReturn(permSet).when(dataObj1).perms(false); - - dt = new Date(); - c = Calendar.getInstance(); - c.setTime(dt); - c.add(Calendar.DATE, 1); - dataObj1.ns = "test"; - dataObj1.perms = permSet; - - retVal1.value.add(dataObj); - retVal2.value.add(dataObj1); - Mockito.doReturn(true).when(retVal1).isOKhasData(); - Mockito.doReturn(true).when(retVal1).isOK(); - Mockito.doReturn(true).when(retVal2).isOK(); - Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); - Mockito.doReturn(retVal2).when(roleDAO).read(trans,"",""); + @SuppressWarnings("unchecked") + @Test + public void testGetPerm() { + Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); + Result<List<RoleDAO.Data>> retVal2 = Mockito.mock(Result.class); + + retVal1.value = new ArrayList<UserRoleDAO.Data>(); + retVal2.value = new ArrayList<RoleDAO.Data>(); + UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); + + Date dt = new Date(); + Calendar c = Calendar.getInstance(); + c.setTime(dt); + c.add(Calendar.DATE, 1); + dataObj.expires = c.getTime(); + dataObj.ns = ""; + dataObj.rname=""; + + RoleDAO.Data dataObj1 = Mockito.mock( RoleDAO.Data.class); + Set<String> permSet = new HashSet<String>(); + permSet.add("test"); + Mockito.doReturn(permSet).when(dataObj1).perms(false); + + dt = new Date(); + c = Calendar.getInstance(); + c.setTime(dt); + c.add(Calendar.DATE, 1); + dataObj1.ns = "test"; + dataObj1.perms = permSet; + + retVal1.value.add(dataObj); + retVal2.value.add(dataObj1); + Mockito.doReturn(true).when(retVal1).isOKhasData(); + Mockito.doReturn(true).when(retVal1).isOK(); + Mockito.doReturn(true).when(retVal2).isOK(); + Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); + Mockito.doReturn(retVal2).when(roleDAO).read(trans,"",""); - - PermLookup cassExecutorObj =PermLookup.get(trans, q,""); -// -// Mockito.doReturn(retVal2).when(cassExecutorObj).getPermNames(); - Result<List<Data>> userRoles = cassExecutorObj.getPerms(true); -// userRoles = cassExecutorObj.getPerms(false); - -// System.out.println(""+userRoles.status); - assertEquals(0,userRoles.status); - } - - @SuppressWarnings("unchecked") - @Test - public void testGetPermFalse() { - Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); - Result<List<RoleDAO.Data>> retVal2 = Mockito.mock(Result.class); - - retVal1.value = new ArrayList<UserRoleDAO.Data>(); - retVal2.value = new ArrayList<RoleDAO.Data>(); - UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); - - Date dt = new Date(); - Calendar c = Calendar.getInstance(); - c.setTime(dt); - c.add(Calendar.DATE, 1); - dataObj.expires = c.getTime(); - dataObj.ns = ""; - dataObj.rname=""; - - RoleDAO.Data dataObj1 = Mockito.mock( RoleDAO.Data.class); - Set<String> permSet = new HashSet<String>(); - permSet.add("test"); - Mockito.doReturn(permSet).when(dataObj1).perms(false); - - dt = new Date(); - c = Calendar.getInstance(); - c.setTime(dt); - c.add(Calendar.DATE, 1); - dataObj1.ns = "test"; - dataObj1.perms = permSet; - - retVal1.value.add(dataObj); - retVal2.value.add(dataObj1); - Mockito.doReturn(true).when(retVal1).isOKhasData(); - Mockito.doReturn(true).when(retVal1).isOK(); - Mockito.doReturn(true).when(retVal2).isOK(); - Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); - Mockito.doReturn(retVal2).when(roleDAO).read(trans,"",""); + + PermLookup cassExecutorObj =PermLookup.get(trans, q,""); +// +// Mockito.doReturn(retVal2).when(cassExecutorObj).getPermNames(); + Result<List<Data>> userRoles = cassExecutorObj.getPerms(true); +// userRoles = cassExecutorObj.getPerms(false); + +// System.out.println(""+userRoles.status); + assertEquals(0,userRoles.status); + } + + @SuppressWarnings("unchecked") + @Test + public void testGetPermFalse() { + Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); + Result<List<RoleDAO.Data>> retVal2 = Mockito.mock(Result.class); + + retVal1.value = new ArrayList<UserRoleDAO.Data>(); + retVal2.value = new ArrayList<RoleDAO.Data>(); + UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); + + Date dt = new Date(); + Calendar c = Calendar.getInstance(); + c.setTime(dt); + c.add(Calendar.DATE, 1); + dataObj.expires = c.getTime(); + dataObj.ns = ""; + dataObj.rname=""; + + RoleDAO.Data dataObj1 = Mockito.mock( RoleDAO.Data.class); + Set<String> permSet = new HashSet<String>(); + permSet.add("test"); + Mockito.doReturn(permSet).when(dataObj1).perms(false); + + dt = new Date(); + c = Calendar.getInstance(); + c.setTime(dt); + c.add(Calendar.DATE, 1); + dataObj1.ns = "test"; + dataObj1.perms = permSet; + + retVal1.value.add(dataObj); + retVal2.value.add(dataObj1); + Mockito.doReturn(true).when(retVal1).isOKhasData(); + Mockito.doReturn(true).when(retVal1).isOK(); + Mockito.doReturn(true).when(retVal2).isOK(); + Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); + Mockito.doReturn(retVal2).when(roleDAO).read(trans,"",""); - - PermLookup cassExecutorObj =PermLookup.get(trans, q,""); -// -// Mockito.doReturn(retVal2).when(cassExecutorObj).getPermNames(); - Result<List<Data>> userRoles = cassExecutorObj.getPerms(false); - userRoles = cassExecutorObj.getPerms(false); - -// System.out.println(""+userRoles.status); - assertEquals(0,userRoles.status); - } - + + PermLookup cassExecutorObj =PermLookup.get(trans, q,""); +// +// Mockito.doReturn(retVal2).when(cassExecutorObj).getPermNames(); + Result<List<Data>> userRoles = cassExecutorObj.getPerms(false); + userRoles = cassExecutorObj.getPerms(false); + +// System.out.println(""+userRoles.status); + assertEquals(0,userRoles.status); + } + }
\ No newline at end of file diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFLocator.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFLocator.java index f6d2a593..5a7d4959 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFLocator.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFLocator.java @@ -51,144 +51,144 @@ import junit.framework.Assert; @RunWith(MockitoJUnitRunner.class) public class JU_DirectAAFLocator { - @Mock - LocateDAO ldao; - - @Mock - AuthzEnv env; - - @Mock - AuthzTrans trans; - - @Mock - PropAccess access; - - @Before - public void setUp() throws Exception { - initMocks(this); - } - - @Test - public void testConstructorVersionExcpetion() { - Mockito.doReturn(access).when(env).access(); - Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null); - Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null); - Mockito.doReturn("20").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,""); - try { - DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao,"test","test"); - } catch (LocatorException e) { -// System.out.println(e.getMessage()); - assertEquals("Invalid Version String: test", e.getMessage()); - } - try { - DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao,"test","20.test"); - } catch (LocatorException e) { -// System.out.println(e.getMessage()); - assertEquals("Invalid Version String: 20.test", e.getMessage()); - }try { - DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao,"test","20.20.test"); - } catch (LocatorException e) { -// System.out.println(e.getMessage()); - assertEquals("Invalid Version String: 20.20.test", e.getMessage()); - }try { - DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao,"test","20.20.20.test"); - } catch (LocatorException e) { -// System.out.println(e.getMessage()); - assertEquals("Invalid Version String: 20.20.20.test", e.getMessage()); - } - } - - @Test - public void testConstructorExcpetion() { - Mockito.doReturn(access).when(env).access(); - Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null); - Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null); - Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,""); - Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER_NS,""); - Mockito.doReturn("20").when(access).getProperty(Config.AAF_LOCATOR_APP_NS,"AAF_NS"); - try { - DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao,"test",null); - } catch (LocatorException e) { -// System.out.println(e.getMessage()); - } - } - - // NOTE: These mocks to not well represent the DirectAAFLocator Class. - @Test - public void testConstructorUriExcpetion() { - Mockito.doReturn(access).when(env).access(); - Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null); - Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null); - Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,""); - Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER_NS,""); - Mockito.doReturn("20 30").when(access).getProperty(Config.AAF_URL,null); - try { - DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao,"test","192.0.0.1"); - } catch (LocatorException e) { -// System.out.println(e.getMessage()); - assertTrue(e.getMessage().contains("Illegal character in path at index 2:")); - } - } + @Mock + LocateDAO ldao; + + @Mock + AuthzEnv env; + + @Mock + AuthzTrans trans; + + @Mock + PropAccess access; + + @Before + public void setUp() throws Exception { + initMocks(this); + } + + @Test + public void testConstructorVersionExcpetion() { + Mockito.doReturn(access).when(env).access(); + Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null); + Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null); + Mockito.doReturn("20").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,""); + try { + DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao,"test","test"); + } catch (LocatorException e) { +// System.out.println(e.getMessage()); + assertEquals("Invalid Version String: test", e.getMessage()); + } + try { + DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao,"test","20.test"); + } catch (LocatorException e) { +// System.out.println(e.getMessage()); + assertEquals("Invalid Version String: 20.test", e.getMessage()); + }try { + DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao,"test","20.20.test"); + } catch (LocatorException e) { +// System.out.println(e.getMessage()); + assertEquals("Invalid Version String: 20.20.test", e.getMessage()); + }try { + DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao,"test","20.20.20.test"); + } catch (LocatorException e) { +// System.out.println(e.getMessage()); + assertEquals("Invalid Version String: 20.20.20.test", e.getMessage()); + } + } + + @Test + public void testConstructorExcpetion() { + Mockito.doReturn(access).when(env).access(); + Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null); + Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null); + Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,""); + Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER_NS,""); + Mockito.doReturn("20").when(access).getProperty(Config.AAF_LOCATOR_APP_NS,"AAF_NS"); + try { + DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao,"test",null); + } catch (LocatorException e) { +// System.out.println(e.getMessage()); + } + } + + // NOTE: These mocks to not well represent the DirectAAFLocator Class. + @Test + public void testConstructorUriExcpetion() { + Mockito.doReturn(access).when(env).access(); + Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null); + Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null); + Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,""); + Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER_NS,""); + Mockito.doReturn("20 30").when(access).getProperty(Config.AAF_URL,null); + try { + DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao,"test","192.0.0.1"); + } catch (LocatorException e) { +// System.out.println(e.getMessage()); + assertTrue(e.getMessage().contains("Illegal character in path at index 2:")); + } + } - @Test - public void testRefresh() { - - DirectAAFLocator aafLocatorObj=null; - PropAccess access = Mockito.mock(PropAccess.class); - Mockito.doReturn(access).when(env).access(); - Mockito.doReturn(trans).when(env).newTransNoAvg(); - Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null); - Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null); - Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,""); - Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER_NS,""); - Mockito.doReturn("http://aafurl.com").when(access).getProperty(Config.AAF_URL,null); - try { - aafLocatorObj = new DirectAAFLocator(env, ldao,"test","30.20.30.30"); - } catch (LocatorException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"",new Object[0]); - - Data data= new Data(); - data.major=30; - data.minor=30; - data.patch=30; - data.pkg=30; - retVal1.value = new ArrayList<Data>(); - retVal1.value.add(data); - - Mockito.doReturn(retVal1).when(ldao).readByName(trans,"test"); - boolean retVal = aafLocatorObj.refresh(); -// System.out.println(retVal); - assertTrue(retVal); - } - - @Test - public void testRefreshNOK() { - - DirectAAFLocator aafLocatorObj=null; - PropAccess access = Mockito.mock(PropAccess.class); - Mockito.doReturn(access).when(env).access(); - Mockito.doReturn(trans).when(env).newTransNoAvg(); - Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null); - Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null); - Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,""); - Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER_NS,""); - Mockito.doReturn("http://aafurl.com").when(access).getProperty(Config.AAF_URL,null); - try { - aafLocatorObj = new DirectAAFLocator(env, ldao,"test","30.20.30.30"); - } catch (LocatorException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Result<List<Data>> retVal1 = new Result<List<Data>>(null,1,"",new String[0]); - - Mockito.doReturn(retVal1).when(ldao).readByName(trans,"test"); - boolean retVal = aafLocatorObj.refresh(); -// System.out.println(retVal); - assertFalse(retVal); - } - + @Test + public void testRefresh() { + + DirectAAFLocator aafLocatorObj=null; + PropAccess access = Mockito.mock(PropAccess.class); + Mockito.doReturn(access).when(env).access(); + Mockito.doReturn(trans).when(env).newTransNoAvg(); + Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null); + Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null); + Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,""); + Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER_NS,""); + Mockito.doReturn("http://aafurl.com").when(access).getProperty(Config.AAF_URL,null); + try { + aafLocatorObj = new DirectAAFLocator(env, ldao,"test","30.20.30.30"); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"",new Object[0]); + + Data data= new Data(); + data.major=30; + data.minor=30; + data.patch=30; + data.pkg=30; + retVal1.value = new ArrayList<Data>(); + retVal1.value.add(data); + + Mockito.doReturn(retVal1).when(ldao).readByName(trans,"test"); + boolean retVal = aafLocatorObj.refresh(); +// System.out.println(retVal); + assertTrue(retVal); + } + + @Test + public void testRefreshNOK() { + + DirectAAFLocator aafLocatorObj=null; + PropAccess access = Mockito.mock(PropAccess.class); + Mockito.doReturn(access).when(env).access(); + Mockito.doReturn(trans).when(env).newTransNoAvg(); + Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null); + Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null); + Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,""); + Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER_NS,""); + Mockito.doReturn("http://aafurl.com").when(access).getProperty(Config.AAF_URL,null); + try { + aafLocatorObj = new DirectAAFLocator(env, ldao,"test","30.20.30.30"); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Result<List<Data>> retVal1 = new Result<List<Data>>(null,1,"",new String[0]); + + Mockito.doReturn(retVal1).when(ldao).readByName(trans,"test"); + boolean retVal = aafLocatorObj.refresh(); +// System.out.println(retVal); + assertFalse(retVal); + } + }
\ No newline at end of file diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFLur.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFLur.java index f0f3c5d0..0ed6e60c 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFLur.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFLur.java @@ -54,190 +54,190 @@ import org.onap.aaf.misc.env.Trans; @RunWith(MockitoJUnitRunner.class) public class JU_DirectAAFLur { - @Mock - AuthzEnv env; - - @Mock - Question question; - - @Mock - Principal bait; - - @Mock - Permission pond; - - @Mock - AuthzTrans trans; - - @Before - public void setUp() throws Exception { - initMocks(this); - Mockito.when(env.newTransNoAvg()).thenReturn(trans); - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); - } - - public void testFish() { - DirectAAFLur aafLurObj = new DirectAAFLur(env, question); - - List<PermDAO.Data> rsVal = new ArrayList<PermDAO.Data>(); - Result<List<Data>> rs = new Result<List<Data>>(rsVal,0,"test",new Object[0]); - Mockito.when(question.getPermsByUser(env.newTransNoAvg(), bait.getName(), false)).thenReturn(rs); - aafLurObj.fish(bait, pond); - } + @Mock + AuthzEnv env; + + @Mock + Question question; + + @Mock + Principal bait; + + @Mock + Permission pond; + + @Mock + AuthzTrans trans; + + @Before + public void setUp() throws Exception { + initMocks(this); + Mockito.when(env.newTransNoAvg()).thenReturn(trans); + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); + } + + public void testFish() { + DirectAAFLur aafLurObj = new DirectAAFLur(env, question); + + List<PermDAO.Data> rsVal = new ArrayList<PermDAO.Data>(); + Result<List<Data>> rs = new Result<List<Data>>(rsVal,0,"test",new Object[0]); + Mockito.when(question.getPermsByUser(env.newTransNoAvg(), bait.getName(), false)).thenReturn(rs); + aafLurObj.fish(bait, pond); + } - @Test - public void testFishSecondMtd() { - DirectAAFLur aafLurObj = new DirectAAFLur(env, question); - - List<PermDAO.Data> rsVal = new ArrayList<PermDAO.Data>(); - PermDAO.Data pd = new PermDAO.Data(); - pd.ns = "ns"; - pd.type = "name"; - pd.instance = null; - rsVal.add(pd); - pd = new PermDAO.Data(); - pd.ns = "ns"; - pd.type = "name"; - pd.instance = "instance"; - pd.action = null; - rsVal.add(pd); - - pd = new PermDAO.Data(); - pd.ns = "ns"; - pd.type = "name"; - pd.instance = "instance1"; - rsVal.add(pd); - pd = new PermDAO.Data(); - pd.ns = "ns1"; - pd.type = "name"; - rsVal.add(pd); - pd = new PermDAO.Data(); - pd.ns = "ns"; - pd.type = "name1"; - rsVal.add(pd); - - pd = new PermDAO.Data(); - pd.ns = "ns"; - pd.type = "name"; - pd.instance = "instance"; - pd.action = "action"; - rsVal.add(pd); - - pond = new DirectAAFLur.PermPermission("ns", "name", "instance", "action"); - - Result<List<Data>> rs = new Result<List<Data>>(rsVal,0,"test",new Object[0]); - Mockito.when(question.getPermsByUser(env.newTransNoAvg(), bait.getName(), false)).thenReturn(rs); - aafLurObj.fish(bait, pond); - - pond = new AAFPermission("ns", "name", "instance", "action"); - - Mockito.when(question.getPermsByUser(env.newTransNoAvg(), bait.getName(), false)).thenReturn(rs); - aafLurObj.fish(bait, pond); - - rs = new Result<List<Data>>(rsVal,1,"test",new Object[0]); - Mockito.when(question.getPermsByUser(env.newTransNoAvg(), bait.getName(), false)).thenReturn(rs); - aafLurObj.fish(bait, pond); - rs = new Result<List<Data>>(rsVal,4,"test",new Object[0]); - Mockito.when(question.getPermsByUser(env.newTransNoAvg(), bait.getName(), false)).thenReturn(rs); - aafLurObj.fish(bait, pond); - rs = new Result<List<Data>>(rsVal,25,"test",new Object[0]); - Mockito.when(question.getPermsByUser(env.newTransNoAvg(), bait.getName(), false)).thenReturn(rs); - aafLurObj.fish(bait, pond); - } - - @Test - public void testFishAll() { - Mockito.doReturn(Mockito.mock(LogTarget.class)).when(env).error(); - DirectAAFLur aafLurObj = new DirectAAFLur(env, question); - - List<PermDAO.Data> rsVal = new ArrayList<PermDAO.Data>(); - PermDAO.Data pd = new PermDAO.Data(); - pd.ns = "ns"; - pd.type = "name"; - pd.instance = null; - rsVal.add(pd); - - pond = new DirectAAFLur.PermPermission("ns", "name", "instance", "action"); - List<Permission> permissions = new ArrayList<>(); - permissions.add(pond); - - Result<List<Data>> rs = new Result<List<Data>>(rsVal,0,"test",new Object[0]); - Mockito.when(question.getPermsByUser(env.newTrans(), bait.getName(), false)).thenReturn(rs); - aafLurObj.fishAll(bait, permissions); - assertTrue(permissions.size() == 2); - - rs = new Result<List<Data>>(rsVal,1,"test",new Object[0]); - Mockito.when(question.getPermsByUser(env.newTrans(), bait.getName(), false)).thenReturn(rs); - aafLurObj.fishAll(bait, permissions); - } - - @Test - public void testDestroy() { - DirectAAFLur aafLurObj = new DirectAAFLur(env, question); - aafLurObj.destroy(); - } - - @Test - public void testHandlesExclusively() { - DirectAAFLur aafLurObj = new DirectAAFLur(env, question); - pond = new DirectAAFLur.PermPermission("ns", "name", "instance", "action"); - assertFalse(aafLurObj.handlesExclusively(pond)); - } - - @Test - public void testToString() { - DirectAAFLur aafLurObj = new DirectAAFLur(env, question); - assertTrue(aafLurObj.toString().contains("DirectAAFLur is enabled")); - } - - @Test - public void testHandles() { - DirectAAFLur aafLurObj = new DirectAAFLur(env, question); - assertTrue(aafLurObj.handles(null)); - } - - @Test - public void testCreatePerm() { - DirectAAFLur aafLurObj = new DirectAAFLur(env, question); - Permission retVal = aafLurObj.createPerm("test"); - assertTrue(retVal instanceof LocalPermission); - - NsSplit nss = new NsSplit("test", "test"); - Result<NsSplit> rs = new Result<NsSplit>(nss,0,"test",new Object[0]); - Mockito.when(question.deriveNsSplit(NullTrans.singleton() , "test")).thenReturn(rs); - retVal = aafLurObj.createPerm("test|1|2"); - assertTrue(retVal instanceof PermPermission); - - rs = new Result<NsSplit>(null,1,"test",new Object[0]); - Mockito.when(question.deriveNsSplit(NullTrans.singleton() , "test")).thenReturn(rs); - retVal = aafLurObj.createPerm("test|1|2"); - assertTrue(retVal instanceof LocalPermission); - } - - @Test - public void testClear() { - AuthzTransImpl trans = Mockito.mock(AuthzTransImpl.class); - Mockito.when(env.newTrans()).thenReturn(trans); - DirectAAFLur aafLurObj = new DirectAAFLur(env, question); - StringBuilder sb = new StringBuilder(); - Mockito.when(trans.auditTrail(0, sb)).thenReturn(Mockito.mock(Trans.Metric.class)); - aafLurObj.clear(bait, sb); - } - - @Test - public void testPermPermission() { - AuthzTransImpl trans = Mockito.mock(AuthzTransImpl.class); - NsSplit nss = new NsSplit("test", "test"); - Result<NsSplit> rs = new Result<NsSplit>(nss,0,"test",new Object[0]); - Mockito.when(question.deriveNsSplit(trans , "test")).thenReturn(rs); - PermPermission pp = new PermPermission(trans, question, "test|test|test|test"); - - assertTrue("test".equalsIgnoreCase(pp.getKey())); - assertTrue("AAFLUR".equalsIgnoreCase(pp.permType())); - - assertFalse(pp.match(null)); - - pond = new AAFPermission("test.test", "test", "test", "test"); - assertTrue(pp.match(pond)); - } + @Test + public void testFishSecondMtd() { + DirectAAFLur aafLurObj = new DirectAAFLur(env, question); + + List<PermDAO.Data> rsVal = new ArrayList<PermDAO.Data>(); + PermDAO.Data pd = new PermDAO.Data(); + pd.ns = "ns"; + pd.type = "name"; + pd.instance = null; + rsVal.add(pd); + pd = new PermDAO.Data(); + pd.ns = "ns"; + pd.type = "name"; + pd.instance = "instance"; + pd.action = null; + rsVal.add(pd); + + pd = new PermDAO.Data(); + pd.ns = "ns"; + pd.type = "name"; + pd.instance = "instance1"; + rsVal.add(pd); + pd = new PermDAO.Data(); + pd.ns = "ns1"; + pd.type = "name"; + rsVal.add(pd); + pd = new PermDAO.Data(); + pd.ns = "ns"; + pd.type = "name1"; + rsVal.add(pd); + + pd = new PermDAO.Data(); + pd.ns = "ns"; + pd.type = "name"; + pd.instance = "instance"; + pd.action = "action"; + rsVal.add(pd); + + pond = new DirectAAFLur.PermPermission("ns", "name", "instance", "action"); + + Result<List<Data>> rs = new Result<List<Data>>(rsVal,0,"test",new Object[0]); + Mockito.when(question.getPermsByUser(env.newTransNoAvg(), bait.getName(), false)).thenReturn(rs); + aafLurObj.fish(bait, pond); + + pond = new AAFPermission("ns", "name", "instance", "action"); + + Mockito.when(question.getPermsByUser(env.newTransNoAvg(), bait.getName(), false)).thenReturn(rs); + aafLurObj.fish(bait, pond); + + rs = new Result<List<Data>>(rsVal,1,"test",new Object[0]); + Mockito.when(question.getPermsByUser(env.newTransNoAvg(), bait.getName(), false)).thenReturn(rs); + aafLurObj.fish(bait, pond); + rs = new Result<List<Data>>(rsVal,4,"test",new Object[0]); + Mockito.when(question.getPermsByUser(env.newTransNoAvg(), bait.getName(), false)).thenReturn(rs); + aafLurObj.fish(bait, pond); + rs = new Result<List<Data>>(rsVal,25,"test",new Object[0]); + Mockito.when(question.getPermsByUser(env.newTransNoAvg(), bait.getName(), false)).thenReturn(rs); + aafLurObj.fish(bait, pond); + } + + @Test + public void testFishAll() { + Mockito.doReturn(Mockito.mock(LogTarget.class)).when(env).error(); + DirectAAFLur aafLurObj = new DirectAAFLur(env, question); + + List<PermDAO.Data> rsVal = new ArrayList<PermDAO.Data>(); + PermDAO.Data pd = new PermDAO.Data(); + pd.ns = "ns"; + pd.type = "name"; + pd.instance = null; + rsVal.add(pd); + + pond = new DirectAAFLur.PermPermission("ns", "name", "instance", "action"); + List<Permission> permissions = new ArrayList<>(); + permissions.add(pond); + + Result<List<Data>> rs = new Result<List<Data>>(rsVal,0,"test",new Object[0]); + Mockito.when(question.getPermsByUser(env.newTrans(), bait.getName(), false)).thenReturn(rs); + aafLurObj.fishAll(bait, permissions); + assertTrue(permissions.size() == 2); + + rs = new Result<List<Data>>(rsVal,1,"test",new Object[0]); + Mockito.when(question.getPermsByUser(env.newTrans(), bait.getName(), false)).thenReturn(rs); + aafLurObj.fishAll(bait, permissions); + } + + @Test + public void testDestroy() { + DirectAAFLur aafLurObj = new DirectAAFLur(env, question); + aafLurObj.destroy(); + } + + @Test + public void testHandlesExclusively() { + DirectAAFLur aafLurObj = new DirectAAFLur(env, question); + pond = new DirectAAFLur.PermPermission("ns", "name", "instance", "action"); + assertFalse(aafLurObj.handlesExclusively(pond)); + } + + @Test + public void testToString() { + DirectAAFLur aafLurObj = new DirectAAFLur(env, question); + assertTrue(aafLurObj.toString().contains("DirectAAFLur is enabled")); + } + + @Test + public void testHandles() { + DirectAAFLur aafLurObj = new DirectAAFLur(env, question); + assertTrue(aafLurObj.handles(null)); + } + + @Test + public void testCreatePerm() { + DirectAAFLur aafLurObj = new DirectAAFLur(env, question); + Permission retVal = aafLurObj.createPerm("test"); + assertTrue(retVal instanceof LocalPermission); + + NsSplit nss = new NsSplit("test", "test"); + Result<NsSplit> rs = new Result<NsSplit>(nss,0,"test",new Object[0]); + Mockito.when(question.deriveNsSplit(NullTrans.singleton() , "test")).thenReturn(rs); + retVal = aafLurObj.createPerm("test|1|2"); + assertTrue(retVal instanceof PermPermission); + + rs = new Result<NsSplit>(null,1,"test",new Object[0]); + Mockito.when(question.deriveNsSplit(NullTrans.singleton() , "test")).thenReturn(rs); + retVal = aafLurObj.createPerm("test|1|2"); + assertTrue(retVal instanceof LocalPermission); + } + + @Test + public void testClear() { + AuthzTransImpl trans = Mockito.mock(AuthzTransImpl.class); + Mockito.when(env.newTrans()).thenReturn(trans); + DirectAAFLur aafLurObj = new DirectAAFLur(env, question); + StringBuilder sb = new StringBuilder(); + Mockito.when(trans.auditTrail(0, sb)).thenReturn(Mockito.mock(Trans.Metric.class)); + aafLurObj.clear(bait, sb); + } + + @Test + public void testPermPermission() { + AuthzTransImpl trans = Mockito.mock(AuthzTransImpl.class); + NsSplit nss = new NsSplit("test", "test"); + Result<NsSplit> rs = new Result<NsSplit>(nss,0,"test",new Object[0]); + Mockito.when(question.deriveNsSplit(trans , "test")).thenReturn(rs); + PermPermission pp = new PermPermission(trans, question, "test|test|test|test"); + + assertTrue("test".equalsIgnoreCase(pp.getKey())); + assertTrue("AAFLUR".equalsIgnoreCase(pp.permType())); + + assertFalse(pp.match(null)); + + pond = new AAFPermission("test.test", "test", "test", "test"); + assertTrue(pp.match(pond)); + } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFUserPass.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFUserPass.java index c767aeb5..241d407b 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFUserPass.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFUserPass.java @@ -47,23 +47,23 @@ import org.onap.aaf.misc.env.LogTarget; @RunWith(MockitoJUnitRunner.class) public class JU_DirectAAFUserPass { - @Mock - Question question; - - @Mock - AuthzEnv env; - - @Mock - AuthzTrans trans; - - @Mock - HttpServletRequest request; - - - @Before - public void setUp() throws Exception { - initMocks(this); - when(env.warn()).thenReturn(new LogTarget() { + @Mock + Question question; + + @Mock + AuthzEnv env; + + @Mock + AuthzTrans trans; + + @Mock + HttpServletRequest request; + + + @Before + public void setUp() throws Exception { + initMocks(this); + when(env.warn()).thenReturn(new LogTarget() { @Override public void printf(String fmt, Object... vars) {} @@ -86,7 +86,7 @@ public class JU_DirectAAFUserPass { return true; } }); - when(env.error()).thenReturn(new LogTarget() { + when(env.error()).thenReturn(new LogTarget() { @Override public void printf(String fmt, Object... vars) {} @@ -109,115 +109,115 @@ public class JU_DirectAAFUserPass { return true; } }); - } - - @Test - public void testUserPass() { - - DirectAAFUserPass aafLocatorObj=null; - aafLocatorObj = new DirectAAFUserPass(env, question); - Result<Date> retVal1 = new Result<Date>(null,0,"",new String[0]); - Mockito.doReturn(trans).when(env).newTransNoAvg(); - try { - Mockito.doReturn(retVal1).when(question).doesUserCredMatch(trans, null, null); - } catch (DAOException e) { - e.printStackTrace(); - } - boolean retVal = aafLocatorObj.validate(null, null, null, null); - - assertFalse(retVal); - } - - @Test - public void testUserPassStateisRequest() { - - DirectAAFUserPass aafLocatorObj=null; - aafLocatorObj = new DirectAAFUserPass(env, question); - Result<Date> retVal1 = new Result<Date>(null,1,"",new String[0]); - Mockito.doReturn(trans).when(env).newTransNoAvg(); - try { - Mockito.doReturn(retVal1).when(question).doesUserCredMatch(trans, null, null); - } catch (DAOException e) { - e.printStackTrace(); - } - boolean retVal = aafLocatorObj.validate(null, null, null, request); - -// System.out.println(retVal); - assertFalse(retVal); - } - - @Test - public void testUserPassStateNotNull() { - - DirectAAFUserPass aafLocatorObj=null; - aafLocatorObj = new DirectAAFUserPass(env, question); - Result<Date> retVal1 = new Result<Date>(null,1,"",new String[0]); - Mockito.doReturn(trans).when(env).newTransNoAvg(); - try { - Mockito.doReturn(retVal1).when(question).doesUserCredMatch(trans, null, null); - } catch (DAOException e) { - e.printStackTrace(); - } - boolean retVal = aafLocatorObj.validate(null, null, null, "test"); - -// System.out.println(retVal); - assertFalse(retVal); - } - - @Test - public void testUserPassTransChk() { - - DirectAAFUserPass aafLocatorObj=null; - aafLocatorObj = new DirectAAFUserPass(env, question); - Result<Date> retVal1 = new Result<Date>(null,1,"",new String[0]); - Mockito.doReturn(trans).when(env).newTransNoAvg(); - try { - Mockito.doReturn(retVal1).when(question).doesUserCredMatch(trans, null, null); - } catch (DAOException e) { - e.printStackTrace(); - } - boolean retVal = aafLocatorObj.validate(null, null, null, trans); - -// System.out.println(retVal); - assertFalse(retVal); - } - - @Test - public void testUserPassTransIpNotNull() { - - DirectAAFUserPass aafLocatorObj=null; - aafLocatorObj = new DirectAAFUserPass(env, question); - Result<Date> retVal1 = new Result<Date>(null,1,"",new String[0]); - Mockito.doReturn("test").when(trans).ip(); - Mockito.doReturn(trans).when(env).newTransNoAvg(); - try { - Mockito.doReturn(retVal1).when(question).doesUserCredMatch(trans, null, null); - } catch (DAOException e) { - e.printStackTrace(); - } - boolean retVal = aafLocatorObj.validate(null, null, null, trans); - -// System.out.println(retVal); - assertFalse(retVal); - } - - @Test - public void testUserExceptionChk() { - - DirectAAFUserPass aafLocatorObj=null; - aafLocatorObj = new DirectAAFUserPass(env, question); - Result<Date> retVal1 = new Result<Date>(null,1,"",new String[0]); - Mockito.doReturn(trans).when(env).newTransNoAvg(); - try { - Mockito.doThrow(DAOException.class).when(question).doesUserCredMatch(trans, null, null); - } catch (DAOException e) { - // TODO Auto-generated catch block -// e.printStackTrace(); - } - boolean retVal = aafLocatorObj.validate(null, null, null, trans); - -// System.out.println(retVal); - assertFalse(retVal); - } - + } + + @Test + public void testUserPass() { + + DirectAAFUserPass aafLocatorObj=null; + aafLocatorObj = new DirectAAFUserPass(env, question); + Result<Date> retVal1 = new Result<Date>(null,0,"",new String[0]); + Mockito.doReturn(trans).when(env).newTransNoAvg(); + try { + Mockito.doReturn(retVal1).when(question).doesUserCredMatch(trans, null, null); + } catch (DAOException e) { + e.printStackTrace(); + } + boolean retVal = aafLocatorObj.validate(null, null, null, null); + + assertFalse(retVal); + } + + @Test + public void testUserPassStateisRequest() { + + DirectAAFUserPass aafLocatorObj=null; + aafLocatorObj = new DirectAAFUserPass(env, question); + Result<Date> retVal1 = new Result<Date>(null,1,"",new String[0]); + Mockito.doReturn(trans).when(env).newTransNoAvg(); + try { + Mockito.doReturn(retVal1).when(question).doesUserCredMatch(trans, null, null); + } catch (DAOException e) { + e.printStackTrace(); + } + boolean retVal = aafLocatorObj.validate(null, null, null, request); + +// System.out.println(retVal); + assertFalse(retVal); + } + + @Test + public void testUserPassStateNotNull() { + + DirectAAFUserPass aafLocatorObj=null; + aafLocatorObj = new DirectAAFUserPass(env, question); + Result<Date> retVal1 = new Result<Date>(null,1,"",new String[0]); + Mockito.doReturn(trans).when(env).newTransNoAvg(); + try { + Mockito.doReturn(retVal1).when(question).doesUserCredMatch(trans, null, null); + } catch (DAOException e) { + e.printStackTrace(); + } + boolean retVal = aafLocatorObj.validate(null, null, null, "test"); + +// System.out.println(retVal); + assertFalse(retVal); + } + + @Test + public void testUserPassTransChk() { + + DirectAAFUserPass aafLocatorObj=null; + aafLocatorObj = new DirectAAFUserPass(env, question); + Result<Date> retVal1 = new Result<Date>(null,1,"",new String[0]); + Mockito.doReturn(trans).when(env).newTransNoAvg(); + try { + Mockito.doReturn(retVal1).when(question).doesUserCredMatch(trans, null, null); + } catch (DAOException e) { + e.printStackTrace(); + } + boolean retVal = aafLocatorObj.validate(null, null, null, trans); + +// System.out.println(retVal); + assertFalse(retVal); + } + + @Test + public void testUserPassTransIpNotNull() { + + DirectAAFUserPass aafLocatorObj=null; + aafLocatorObj = new DirectAAFUserPass(env, question); + Result<Date> retVal1 = new Result<Date>(null,1,"",new String[0]); + Mockito.doReturn("test").when(trans).ip(); + Mockito.doReturn(trans).when(env).newTransNoAvg(); + try { + Mockito.doReturn(retVal1).when(question).doesUserCredMatch(trans, null, null); + } catch (DAOException e) { + e.printStackTrace(); + } + boolean retVal = aafLocatorObj.validate(null, null, null, trans); + +// System.out.println(retVal); + assertFalse(retVal); + } + + @Test + public void testUserExceptionChk() { + + DirectAAFUserPass aafLocatorObj=null; + aafLocatorObj = new DirectAAFUserPass(env, question); + Result<Date> retVal1 = new Result<Date>(null,1,"",new String[0]); + Mockito.doReturn(trans).when(env).newTransNoAvg(); + try { + Mockito.doThrow(DAOException.class).when(question).doesUserCredMatch(trans, null, null); + } catch (DAOException e) { + // TODO Auto-generated catch block +// e.printStackTrace(); + } + boolean retVal = aafLocatorObj.validate(null, null, null, trans); + +// System.out.println(retVal); + assertFalse(retVal); + } + }
\ No newline at end of file diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectCertIdentity.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectCertIdentity.java index 2f64e099..81195e5d 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectCertIdentity.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectCertIdentity.java @@ -48,53 +48,53 @@ import org.powermock.modules.junit4.PowerMockRunner; @RunWith(PowerMockRunner.class) public class JU_DirectCertIdentity { - public DirectCertIdentity directCertIdentity; + public DirectCertIdentity directCertIdentity; - @Before - public void setUp() { - directCertIdentity = new DirectCertIdentity(); - } + @Before + public void setUp() { + directCertIdentity = new DirectCertIdentity(); + } - @Mock - HttpServletRequest req; - X509Certificate cert; - byte[] _certBytes; + @Mock + HttpServletRequest req; + X509Certificate cert; + byte[] _certBytes; - @Test - public void testidentity() { + @Test + public void testidentity() { - try { - Principal p = directCertIdentity.identity(req, cert, _certBytes); - assertEquals(((p) == null), true); - - cert = Mockito.mock(X509Certificate.class); - Mockito.when(cert.getEncoded()).thenReturn(new byte[128]); - - Result<List<CertDAO.Data>> rs = new Result<List<CertDAO.Data>>(null, 1, "test", new Object[0]); - - CachedCertDAO cacheDao = Mockito.mock(CachedCertDAO.class); - Mockito.when(cacheDao.read(Mockito.any(AuthzTrans.class),Mockito.any(Object[].class))).thenReturn(rs); - DirectCertIdentity.set(cacheDao); - p = directCertIdentity.identity(req, cert, _certBytes); - - _certBytes = new byte[128]; - List<CertDAO.Data> dataAL = new ArrayList<>(); - CertDAO.Data data = new CertDAO.Data(); - dataAL.add(data); - rs = new Result<List<CertDAO.Data>>(dataAL, 0, "test", new Object[0]); - Mockito.when(cacheDao.read(Mockito.any(AuthzTrans.class),Mockito.any(Object[].class))).thenReturn(rs); - DirectCertIdentity.set(cacheDao); - p = directCertIdentity.identity(req, cert, _certBytes); - assertTrue(p.toString().contains("X509 Authentication for null")); - - cert = null; - directCertIdentity.identity(req, cert, _certBytes); - } catch (CertificateException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - // assertTrue(true); + try { + Principal p = directCertIdentity.identity(req, cert, _certBytes); + assertEquals(((p) == null), true); + + cert = Mockito.mock(X509Certificate.class); + Mockito.when(cert.getEncoded()).thenReturn(new byte[128]); + + Result<List<CertDAO.Data>> rs = new Result<List<CertDAO.Data>>(null, 1, "test", new Object[0]); + + CachedCertDAO cacheDao = Mockito.mock(CachedCertDAO.class); + Mockito.when(cacheDao.read(Mockito.any(AuthzTrans.class),Mockito.any(Object[].class))).thenReturn(rs); + DirectCertIdentity.set(cacheDao); + p = directCertIdentity.identity(req, cert, _certBytes); + + _certBytes = new byte[128]; + List<CertDAO.Data> dataAL = new ArrayList<>(); + CertDAO.Data data = new CertDAO.Data(); + dataAL.add(data); + rs = new Result<List<CertDAO.Data>>(dataAL, 0, "test", new Object[0]); + Mockito.when(cacheDao.read(Mockito.any(AuthzTrans.class),Mockito.any(Object[].class))).thenReturn(rs); + DirectCertIdentity.set(cacheDao); + p = directCertIdentity.identity(req, cert, _certBytes); + assertTrue(p.toString().contains("X509 Authentication for null")); + + cert = null; + directCertIdentity.identity(req, cert, _certBytes); + } catch (CertificateException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // assertTrue(true); - } + } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectLocatorCreator.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectLocatorCreator.java index 0eb75fcb..7ac4ed1b 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectLocatorCreator.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectLocatorCreator.java @@ -38,52 +38,52 @@ import org.onap.aaf.cadi.config.Config; @RunWith(MockitoJUnitRunner.class) public class JU_DirectLocatorCreator { - @Mock - AuthzEnv env; - - @Mock - LocateDAO locateDAO; - - @Mock - PropAccess access; - - @Before - public void setUp() throws Exception { - initMocks(this); - } - - @Test - public void testCreate() { - Mockito.doReturn(access).when(env).access(); - Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null); - Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null); - Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,""); - Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER_NS,""); - Mockito.doReturn("http://aafurl.com").when(access).getProperty(Config.AAF_URL,null); - DirectLocatorCreator directLocObj = new DirectLocatorCreator(env, locateDAO); - try { - directLocObj.create("test", "30.20.30.20"); - } catch (LocatorException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - directLocObj.setSelf("30.20.30.10", 8080); - try { - directLocObj.create("test", "30.20.30.20"); - } catch (LocatorException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + @Mock + AuthzEnv env; + + @Mock + LocateDAO locateDAO; + + @Mock + PropAccess access; + + @Before + public void setUp() throws Exception { + initMocks(this); + } + + @Test + public void testCreate() { + Mockito.doReturn(access).when(env).access(); + Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null); + Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null); + Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,""); + Mockito.doReturn("").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER_NS,""); + Mockito.doReturn("http://aafurl.com").when(access).getProperty(Config.AAF_URL,null); + DirectLocatorCreator directLocObj = new DirectLocatorCreator(env, locateDAO); + try { + directLocObj.create("test", "30.20.30.20"); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + directLocObj.setSelf("30.20.30.10", 8080); + try { + directLocObj.create("test", "30.20.30.20"); + } catch (LocatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } - @Test - public void testSetSelf() { - Mockito.doReturn(access).when(env).access(); - Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null); - Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null); - Mockito.doReturn("20").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,""); - Mockito.doReturn("http://aafurl.com").when(access).getProperty(Config.AAF_URL,null); - DirectLocatorCreator directLocObj = new DirectLocatorCreator(env, locateDAO); - directLocObj.setSelf("30.20.30.10", 8080); - } + @Test + public void testSetSelf() { + Mockito.doReturn(access).when(env).access(); + Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null); + Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null); + Mockito.doReturn("20").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,""); + Mockito.doReturn("http://aafurl.com").when(access).getProperty(Config.AAF_URL,null); + DirectLocatorCreator directLocObj = new DirectLocatorCreator(env, locateDAO); + directLocObj.setSelf("30.20.30.10", 8080); + } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectRegistrar.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectRegistrar.java index f4bbd277..cf1bd9d4 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectRegistrar.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectRegistrar.java @@ -41,73 +41,73 @@ import org.onap.aaf.cadi.config.Config; @RunWith(MockitoJUnitRunner.class) public class JU_DirectRegistrar { - @Mock - LocateDAO ldao; + @Mock + LocateDAO ldao; - // @Mock - // Data locate; + // @Mock + // Data locate; - @Mock - Access access; + @Mock + Access access; - @Mock - AuthzEnv env; + @Mock + AuthzEnv env; - // @Mock - AuthzTrans trans; + // @Mock + AuthzTrans trans; - @Before - public void setUp() throws Exception { - initMocks(this); - } + @Before + public void setUp() throws Exception { + initMocks(this); + } - @Test - public void testUpdate() { - DirectRegistrar registrarObj = null; - org.onap.aaf.auth.layer.Result<Void> rs = null; - try { - Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE, null); - Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE, null); - Mockito.doReturn("20").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER, ""); - Mockito.doReturn("20,test,test").when(access).getProperty(Config.AAF_LOCATOR_ENTRIES, ""); - rs = new org.onap.aaf.auth.layer.Result<Void>(null, 0, "test", new Object[0]); - Mockito.doReturn(rs).when(ldao).update(Mockito.any(), Mockito.any()); - registrarObj = new DirectRegistrar(access, ldao, 9080); + @Test + public void testUpdate() { + DirectRegistrar registrarObj = null; + org.onap.aaf.auth.layer.Result<Void> rs = null; + try { + Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE, null); + Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE, null); + Mockito.doReturn("20").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER, ""); + Mockito.doReturn("20,test,test").when(access).getProperty(Config.AAF_LOCATOR_ENTRIES, ""); + rs = new org.onap.aaf.auth.layer.Result<Void>(null, 0, "test", new Object[0]); + Mockito.doReturn(rs).when(ldao).update(Mockito.any(), Mockito.any()); + registrarObj = new DirectRegistrar(access, ldao, 9080); - - org.onap.aaf.auth.layer.Result<Void> retVal1 = new Result<Void>(null, 0, "test", new Object[0]); - Mockito.doReturn(trans).when(env).newTransNoAvg(); - // Mockito.doReturn(retVal1).when(ldao).update(trans,locate); - registrarObj.update(env); - - rs = new org.onap.aaf.auth.layer.Result<Void>(null, 1, "test", new Object[0]); - Mockito.doReturn(rs).when(ldao).update(Mockito.any(), Mockito.any()); - registrarObj = new DirectRegistrar(access, ldao, 9080); - registrarObj.update(env); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - // System.out.println(retVal1); - } + + org.onap.aaf.auth.layer.Result<Void> retVal1 = new Result<Void>(null, 0, "test", new Object[0]); + Mockito.doReturn(trans).when(env).newTransNoAvg(); + // Mockito.doReturn(retVal1).when(ldao).update(trans,locate); + registrarObj.update(env); + + rs = new org.onap.aaf.auth.layer.Result<Void>(null, 1, "test", new Object[0]); + Mockito.doReturn(rs).when(ldao).update(Mockito.any(), Mockito.any()); + registrarObj = new DirectRegistrar(access, ldao, 9080); + registrarObj.update(env); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // System.out.println(retVal1); + } - @Test - public void testCancel() { - DirectRegistrar registrarObj = null; - try { - Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE, null); - Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE, null); - Mockito.doReturn("20").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER, ""); - Mockito.doReturn("20,test,test").when(access).getProperty(Config.AAF_LOCATOR_ENTRIES, ""); - registrarObj = new DirectRegistrar(access, ldao, 9080); - - org.onap.aaf.auth.layer.Result<Void> rs = new org.onap.aaf.auth.layer.Result<Void>(null, 1, "test", new Object[0]); - Mockito.doReturn(rs).when(ldao).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); - } catch (CadiException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - registrarObj.cancel(env); - } + @Test + public void testCancel() { + DirectRegistrar registrarObj = null; + try { + Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE, null); + Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE, null); + Mockito.doReturn("20").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER, ""); + Mockito.doReturn("20,test,test").when(access).getProperty(Config.AAF_LOCATOR_ENTRIES, ""); + registrarObj = new DirectRegistrar(access, ldao, 9080); + + org.onap.aaf.auth.layer.Result<Void> rs = new org.onap.aaf.auth.layer.Result<Void>(null, 1, "test", new Object[0]); + Mockito.doReturn(rs).when(ldao).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + } catch (CadiException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + registrarObj.cancel(env); + } }
\ No newline at end of file |