diff options
Diffstat (limited to 'auth/auth-cass/src/test/java/org')
3 files changed, 106 insertions, 141 deletions
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 3377c7e9..2f64e099 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 @@ -22,11 +22,14 @@ package org.onap.aaf.auth.direct.test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.security.Principal; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.List; import javax.servlet.http.HttpServletRequest; @@ -34,39 +37,64 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; +import org.mockito.Mockito; import org.onap.aaf.auth.dao.cached.CachedCertDAO; +import org.onap.aaf.auth.dao.cass.CertDAO; import org.onap.aaf.auth.direct.DirectCertIdentity; +import org.onap.aaf.auth.env.AuthzTrans; +import org.onap.aaf.auth.layer.Result; import org.powermock.modules.junit4.PowerMockRunner; @RunWith(PowerMockRunner.class) public class JU_DirectCertIdentity { - - public DirectCertIdentity directCertIdentity; - - @Before - public void setUp(){ - directCertIdentity = new DirectCertIdentity(); - } + public DirectCertIdentity directCertIdentity; - @Mock - HttpServletRequest req; - X509Certificate cert; - byte[] _certBytes; - - @Test - public void testidentity(){ - - try { - Principal p = directCertIdentity.identity(req, cert, _certBytes); - assertEquals(( (p) == null),true); - - } catch (CertificateException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - //assertTrue(true); - - } + @Before + public void setUp() { + directCertIdentity = new DirectCertIdentity(); + } + + @Mock + HttpServletRequest req; + X509Certificate cert; + byte[] _certBytes; + + @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); + + } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectLocatorCreateor.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectLocatorCreateor.java deleted file mode 100644 index cd97faca..00000000 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectLocatorCreateor.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * ============LICENSE_START==================================================== - * org.onap.aaf - * =========================================================================== - * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. - * =========================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END==================================================== - * - */ -package org.onap.aaf.auth.direct.test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.MockitoAnnotations.initMocks; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; -import org.onap.aaf.auth.dao.cass.LocateDAO; -import org.onap.aaf.auth.direct.DirectLocatorCreator; -import org.onap.aaf.auth.env.AuthzEnv; -import org.onap.aaf.cadi.LocatorException; -import org.onap.aaf.cadi.PropAccess; -import org.onap.aaf.cadi.config.Config; - - -@RunWith(MockitoJUnitRunner.class) -public class JU_DirectLocatorCreateor { - - @Mock - LocateDAO ldao; - - @Mock - AuthzEnv env; - - @Before - public void setUp() throws Exception { - initMocks(this); - } - - // These tests should not Mock PropAccess - @Test - public void testCreate() { - assertTrue(true); - } -// PropAccess access = Mockito.mock(PropAccess.class); -// 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); -// DirectLocatorCreator aafLocatorObj=new DirectLocatorCreator(env, ldao); -// try { -// aafLocatorObj.setSelf("test", 9080); -// aafLocatorObj.create("test","30.20.30.30"); -// } catch (LocatorException e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } -// } -// -// @Test -// public void testCreateHostnameNull() { -// PropAccess access = Mockito.mock(PropAccess.class); -// 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); -// DirectLocatorCreator aafLocatorObj=new DirectLocatorCreator(env, ldao); -// try { -// aafLocatorObj.create("test","30.20.30.30"); -// } catch (LocatorException e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } -// } - - -}
\ No newline at end of file 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 1cc24107..f4bbd277 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 @@ -38,49 +38,76 @@ import org.onap.aaf.cadi.Access; import org.onap.aaf.cadi.CadiException; import org.onap.aaf.cadi.config.Config; - -@RunWith(MockitoJUnitRunner.class) +@RunWith(MockitoJUnitRunner.class) public class JU_DirectRegistrar { @Mock LocateDAO ldao; - -// @Mock -// Data locate; - + + // @Mock + // Data locate; + @Mock Access access; - + @Mock AuthzEnv env; - -// @Mock + + // @Mock AuthzTrans trans; - + @Before public void setUp() throws Exception { initMocks(this); } - + @Test public void testUpdate() { - DirectRegistrar registrarObj=null; + 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,""); - registrarObj = new DirectRegistrar( access, ldao, 9080); + 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(); } - org.onap.aaf.auth.layer.Result<Void> retVal1 = new Result<Void>(null,0,"test",new String[0]); - Mockito.doReturn(trans).when(env).newTransNoAvg(); -// Mockito.doReturn(retVal1).when(ldao).update(trans,locate); - registrarObj.update(env); -// System.out.println(retVal1); + // 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); + } + }
\ No newline at end of file |