diff options
author | Instrumental <jonathan.gathman@att.com> | 2019-08-07 13:40:39 -0500 |
---|---|---|
committer | Instrumental <jonathan.gathman@att.com> | 2019-08-07 13:40:42 -0500 |
commit | 3d1706fcbe7f95830ff6fd23cf679ee55c6d0595 (patch) | |
tree | ff97f10380a44d9f81d536c066782af10f728687 /auth/auth-service/src/test/java/org | |
parent | 321dce367d74092a0ba09930c3aa526abdbd5da8 (diff) |
Remove Tabs, per Jococo
Issue-ID: AAF-932
Change-Id: I3ab0ebcc082048d2d1424a58a90ea479fb005ee6
Signed-off-by: Instrumental <jonathan.gathman@att.com>
Diffstat (limited to 'auth/auth-service/src/test/java/org')
2 files changed, 132 insertions, 132 deletions
diff --git a/auth/auth-service/src/test/java/org/onap/aaf/auth/service/test/JU_BaseServiceImpl.java b/auth/auth-service/src/test/java/org/onap/aaf/auth/service/test/JU_BaseServiceImpl.java index 5e6cfb62..9a804c98 100644 --- a/auth/auth-service/src/test/java/org/onap/aaf/auth/service/test/JU_BaseServiceImpl.java +++ b/auth/auth-service/src/test/java/org/onap/aaf/auth/service/test/JU_BaseServiceImpl.java @@ -75,20 +75,20 @@ import aaf.v2_0.Users; @RunWith(MockitoJUnitRunner.class) public abstract class JU_BaseServiceImpl { - protected AuthzCassServiceImpl<Nss, Perms, Pkey, Roles, Users, UserRoles, Delgs, Certs, Keys, Request, History, Error, Approvals> - acsi; - protected Mapper_2_0 mapper; + protected AuthzCassServiceImpl<Nss, Perms, Pkey, Roles, Users, UserRoles, Delgs, Certs, Keys, Request, History, Error, Approvals> + acsi; + protected Mapper_2_0 mapper; - @Mock + @Mock protected DefaultOrg org; - @Mock + @Mock protected DefaultOrgIdentity orgIdentity; // // NOTE: Annotation format (@Mock and @Spy) do NOT seem to always work as a Base Class, // so we construct manually. // -// Mock Objects +// Mock Objects protected HistoryDAO historyDAO = mock(HistoryDAO.class); protected CacheInfoDAO cacheInfoDAO = mock(CacheInfoDAO.class); protected CachedNSDAO nsDAO = mock(CachedNSDAO.class); @@ -102,47 +102,47 @@ public abstract class JU_BaseServiceImpl { protected DelegateDAO delegateDAO = mock(DelegateDAO.class); protected ApprovalDAO approvalDAO = mock(ApprovalDAO.class); - // Spy Objects + // Spy Objects @Spy protected static PropAccess access = new PropAccess(); @Spy - protected static AuthzEnv env = new AuthzEnv(access); + protected static AuthzEnv env = new AuthzEnv(access); @Spy protected static AuthzTrans trans = env.newTransNoAvg(); // @Spy doesn't seem to work on Question. @Spy protected Question question = spy(new Question(trans, - historyDAO,cacheInfoDAO,nsDAO,permDAO, - roleDAO,userRoleDAO,credDAO,certDAO, - locateDAO,futureDAO,delegateDAO,approvalDAO)); + historyDAO,cacheInfoDAO,nsDAO,permDAO, + roleDAO,userRoleDAO,credDAO,certDAO, + locateDAO,futureDAO,delegateDAO,approvalDAO)); - public void setUp() throws Exception { - when(trans.org()).thenReturn(org); - when(org.getDomain()).thenReturn("org.onap"); - Define.set(access); - access.setProperty(Config.CADI_LATITUDE, "38.0"); - access.setProperty(Config.CADI_LONGITUDE, "-72.0"); - - mapper = new Mapper_2_0(question); - acsi = new AuthzCassServiceImpl<>(trans, mapper, question); - } - - ////////// - // Common Data Objects - ///////// + public void setUp() throws Exception { + when(trans.org()).thenReturn(org); + when(org.getDomain()).thenReturn("org.onap"); + Define.set(access); + access.setProperty(Config.CADI_LATITUDE, "38.0"); + access.setProperty(Config.CADI_LONGITUDE, "-72.0"); + + mapper = new Mapper_2_0(question); + acsi = new AuthzCassServiceImpl<>(trans, mapper, question); + } + + ////////// + // Common Data Objects + ///////// protected List<NsDAO.Data> nsData(String name) { - NsDAO.Data ndd = new NsDAO.Data(); - ndd.name=name; - int dot = name.lastIndexOf('.'); - if(dot<0) { - ndd.parent="."; - } else { - ndd.parent=name.substring(0,dot); - } - List<NsDAO.Data> rv = new ArrayList<NsDAO.Data>(); - rv.add(ndd); - return rv; + NsDAO.Data ndd = new NsDAO.Data(); + ndd.name=name; + int dot = name.lastIndexOf('.'); + if(dot<0) { + ndd.parent="."; + } else { + ndd.parent=name.substring(0,dot); + } + List<NsDAO.Data> rv = new ArrayList<NsDAO.Data>(); + rv.add(ndd); + return rv; } /** @@ -155,36 +155,36 @@ public abstract class JU_BaseServiceImpl { * @param days */ protected void whenRole(AuthzTrans trans, String user, String ns, String role, boolean exists, int days) { - Result<List<UserRoleDAO.Data>> result; - if(exists) { - result = Result.ok(listOf(urData(user,ns,role,days))); - } else { - result = Result.ok(emptyList(UserRoleDAO.Data.class)); - } - when(question.userRoleDAO().read(trans, user, ns+'.'+role)).thenReturn(result); + Result<List<UserRoleDAO.Data>> result; + if(exists) { + result = Result.ok(listOf(urData(user,ns,role,days))); + } else { + result = Result.ok(emptyList(UserRoleDAO.Data.class)); + } + when(question.userRoleDAO().read(trans, user, ns+'.'+role)).thenReturn(result); } protected UserRoleDAO.Data urData(String user, String ns, String rname, int days) { - UserRoleDAO.Data urdd = new UserRoleDAO.Data(); - urdd.user = user; - urdd.ns = ns; - urdd.rname = rname; - urdd.role = ns + '.' + rname; - GregorianCalendar gc = new GregorianCalendar(); - gc.add(GregorianCalendar.DAY_OF_YEAR, days); - urdd.expires = gc.getTime(); - return urdd; + UserRoleDAO.Data urdd = new UserRoleDAO.Data(); + urdd.user = user; + urdd.ns = ns; + urdd.rname = rname; + urdd.role = ns + '.' + rname; + GregorianCalendar gc = new GregorianCalendar(); + gc.add(GregorianCalendar.DAY_OF_YEAR, days); + urdd.expires = gc.getTime(); + return urdd; } protected <T> List<T> listOf(T t) { - List<T> list = new ArrayList<>(); - list.add(t); - return list; + List<T> list = new ArrayList<>(); + list.add(t); + return list; } protected <T> List<T> emptyList(Class<T> cls) { - return new ArrayList<>(); + return new ArrayList<>(); } } diff --git a/auth/auth-service/src/test/java/org/onap/aaf/auth/service/test/JU_ServiceImpl_createUserCred.java b/auth/auth-service/src/test/java/org/onap/aaf/auth/service/test/JU_ServiceImpl_createUserCred.java index 00da6b4c..2bb907ac 100644 --- a/auth/auth-service/src/test/java/org/onap/aaf/auth/service/test/JU_ServiceImpl_createUserCred.java +++ b/auth/auth-service/src/test/java/org/onap/aaf/auth/service/test/JU_ServiceImpl_createUserCred.java @@ -49,100 +49,100 @@ import junit.framework.Assert; @RunWith(MockitoJUnitRunner.class) public class JU_ServiceImpl_createUserCred extends JU_BaseServiceImpl { - @Mock - private Result<CredDAO.Data> rcdd; - - @Before - public void setUp() throws Exception { - super.setUp(); - } + @Mock + private Result<CredDAO.Data> rcdd; + + @Before + public void setUp() throws Exception { + super.setUp(); + } @Test public void validCreateNewIsOwner() throws OrganizationException { - CredRequest cr = credRequest1(); - final String fqi = "bob@people.onap.org"; - when(trans.user()).thenReturn(fqi); - when(org.isValidPassword(trans, cr.getId(),cr.getPassword())).thenReturn(""); - when(org.isValidCred(trans, cr.getId())).thenReturn(true); - when(org.canHaveMultipleCreds(cr.getId())).thenReturn(true); - when(org.getIdentity(trans, cr.getId())).thenReturn(orgIdentity); - when(orgIdentity.isFound()).thenReturn(true); - final String ns = "org.onap.sample"; - whenRole(trans, fqi, ns, "owner", false, 100); - when(question.nsDAO().read(trans, ns)).thenReturn(Result.ok(nsData(ns))); - when(question.credDAO().readID(trans, cr.getId())).thenReturn(Result.ok(emptyList(CredDAO.Data.class))); - when(question.credDAO().create(any(AuthzTrans.class), any(CredDAO.Data.class) )).thenReturn(Result.ok(credDataFound(cr,100))); - when(question.credDAO().readNS(trans, ns)).thenReturn(Result.ok(listOf(credDataFound(cr,100)))); - Result<?> result = acsi.createUserCred(trans,cr); - // Owner may do FIRST Creds - Assert.assertEquals(Result.OK,result.status); + CredRequest cr = credRequest1(); + final String fqi = "bob@people.onap.org"; + when(trans.user()).thenReturn(fqi); + when(org.isValidPassword(trans, cr.getId(),cr.getPassword())).thenReturn(""); + when(org.isValidCred(trans, cr.getId())).thenReturn(true); + when(org.canHaveMultipleCreds(cr.getId())).thenReturn(true); + when(org.getIdentity(trans, cr.getId())).thenReturn(orgIdentity); + when(orgIdentity.isFound()).thenReturn(true); + final String ns = "org.onap.sample"; + whenRole(trans, fqi, ns, "owner", false, 100); + when(question.nsDAO().read(trans, ns)).thenReturn(Result.ok(nsData(ns))); + when(question.credDAO().readID(trans, cr.getId())).thenReturn(Result.ok(emptyList(CredDAO.Data.class))); + when(question.credDAO().create(any(AuthzTrans.class), any(CredDAO.Data.class) )).thenReturn(Result.ok(credDataFound(cr,100))); + when(question.credDAO().readNS(trans, ns)).thenReturn(Result.ok(listOf(credDataFound(cr,100)))); + Result<?> result = acsi.createUserCred(trans,cr); + // Owner may do FIRST Creds + Assert.assertEquals(Result.OK,result.status); } @Test public void validCreateNewOnlyAdmin() throws OrganizationException { - CredRequest cr = credRequest1(); - final String fqi = "bob@people.onap.org"; - when(trans.user()).thenReturn(fqi); - when(org.isValidPassword(trans, cr.getId(),cr.getPassword())).thenReturn(""); - when(org.isValidCred(trans, cr.getId())).thenReturn(true); - when(org.canHaveMultipleCreds(cr.getId())).thenReturn(true); - when(org.getIdentity(trans, cr.getId())).thenReturn(orgIdentity); - when(orgIdentity.isFound()).thenReturn(true); - final String ns = "org.onap.sample"; - whenRole(trans,fqi,ns,"owner",false, 100); - whenRole(trans,fqi,ns,"admin",true, 100); - when(question.nsDAO().read(trans, ns)).thenReturn(Result.ok(nsData(ns))); - when(question.credDAO().readID(trans, cr.getId())).thenReturn(Result.ok(emptyList(CredDAO.Data.class))); - when(question.credDAO().create(any(AuthzTrans.class), any(CredDAO.Data.class) )).thenReturn(Result.ok(credDataFound(cr,100))); - when(question.credDAO().readNS(trans, ns)).thenReturn(Result.ok(listOf(credDataFound(cr,100)))); - Result<?> result = acsi.createUserCred(trans,cr); - // Admins may not do FIRST Creds - Assert.assertEquals(Result.ERR_Denied,result.status); + CredRequest cr = credRequest1(); + final String fqi = "bob@people.onap.org"; + when(trans.user()).thenReturn(fqi); + when(org.isValidPassword(trans, cr.getId(),cr.getPassword())).thenReturn(""); + when(org.isValidCred(trans, cr.getId())).thenReturn(true); + when(org.canHaveMultipleCreds(cr.getId())).thenReturn(true); + when(org.getIdentity(trans, cr.getId())).thenReturn(orgIdentity); + when(orgIdentity.isFound()).thenReturn(true); + final String ns = "org.onap.sample"; + whenRole(trans,fqi,ns,"owner",false, 100); + whenRole(trans,fqi,ns,"admin",true, 100); + when(question.nsDAO().read(trans, ns)).thenReturn(Result.ok(nsData(ns))); + when(question.credDAO().readID(trans, cr.getId())).thenReturn(Result.ok(emptyList(CredDAO.Data.class))); + when(question.credDAO().create(any(AuthzTrans.class), any(CredDAO.Data.class) )).thenReturn(Result.ok(credDataFound(cr,100))); + when(question.credDAO().readNS(trans, ns)).thenReturn(Result.ok(listOf(credDataFound(cr,100)))); + Result<?> result = acsi.createUserCred(trans,cr); + // Admins may not do FIRST Creds + Assert.assertEquals(Result.ERR_Denied,result.status); } @Test public void validCreateExisting() throws OrganizationException { - CredRequest cr = credRequest1(); - when(org.isValidPassword(trans, cr.getId(),cr.getPassword())).thenReturn(""); - when(org.isValidCred(trans, cr.getId())).thenReturn(true); - when(org.canHaveMultipleCreds(cr.getId())).thenReturn(true); - when(org.getIdentity(trans, cr.getId())).thenReturn(orgIdentity); - when(orgIdentity.isFound()).thenReturn(true); - String ns = "org.onap.sample"; - when(question.nsDAO().read(trans, ns)).thenReturn(Result.ok(nsData(ns))); - - CredDAO.Data cdd = credDataFound(cr,100); - when(question.credDAO().create(any(AuthzTrans.class), any(CredDAO.Data.class) )).thenReturn(Result.ok(cdd)); - when(question.credDAO().readID(trans, cr.getId())).thenReturn(Result.ok(listOf(cdd))); + CredRequest cr = credRequest1(); + when(org.isValidPassword(trans, cr.getId(),cr.getPassword())).thenReturn(""); + when(org.isValidCred(trans, cr.getId())).thenReturn(true); + when(org.canHaveMultipleCreds(cr.getId())).thenReturn(true); + when(org.getIdentity(trans, cr.getId())).thenReturn(orgIdentity); + when(orgIdentity.isFound()).thenReturn(true); + String ns = "org.onap.sample"; + when(question.nsDAO().read(trans, ns)).thenReturn(Result.ok(nsData(ns))); + + CredDAO.Data cdd = credDataFound(cr,100); + when(question.credDAO().create(any(AuthzTrans.class), any(CredDAO.Data.class) )).thenReturn(Result.ok(cdd)); + when(question.credDAO().readID(trans, cr.getId())).thenReturn(Result.ok(listOf(cdd))); - Result<?> result = acsi.createUserCred(trans,cr); - Assert.assertEquals(Result.OK,result.status); + Result<?> result = acsi.createUserCred(trans,cr); + Assert.assertEquals(Result.OK,result.status); } private CredRequest credRequest1() { - CredRequest cr = new CredRequest(); - cr.setId("m12345@sample.onap.org"); - cr.setPassword("BobAndWeave"); - cr.setType(CredDAO.RAW); - return cr; + CredRequest cr = new CredRequest(); + cr.setId("m12345@sample.onap.org"); + cr.setPassword("BobAndWeave"); + cr.setType(CredDAO.RAW); + return cr; } private CredDAO.Data credDataFound(CredRequest cr, int days) { - CredDAO.Data cdd = new CredDAO.Data(); - cdd.id = cr.getId(); - cdd.ns = FQI.reverseDomain(cr.getId()); - cdd.other = 12345; - cdd.tag = "1355434"; - cdd.type = CredDAO.BASIC_AUTH_SHA256; - try { - cdd.cred = ByteBuffer.wrap(Hash.hashSHA256(cr.getPassword().getBytes())); - } catch (NoSuchAlgorithmException e) { - Assert.fail(e.getMessage()); - } - GregorianCalendar gc = new GregorianCalendar(); - gc.add(GregorianCalendar.DAY_OF_YEAR, days); - cdd.expires = gc.getTime(); - return cdd; + CredDAO.Data cdd = new CredDAO.Data(); + cdd.id = cr.getId(); + cdd.ns = FQI.reverseDomain(cr.getId()); + cdd.other = 12345; + cdd.tag = "1355434"; + cdd.type = CredDAO.BASIC_AUTH_SHA256; + try { + cdd.cred = ByteBuffer.wrap(Hash.hashSHA256(cr.getPassword().getBytes())); + } catch (NoSuchAlgorithmException e) { + Assert.fail(e.getMessage()); + } + GregorianCalendar gc = new GregorianCalendar(); + gc.add(GregorianCalendar.DAY_OF_YEAR, days); + cdd.expires = gc.getTime(); + return cdd; } }
\ No newline at end of file |