From a47bd51641efcb84e19d68a6383f0947df826636 Mon Sep 17 00:00:00 2001 From: Sai Gandham Date: Fri, 24 May 2019 08:46:22 -0500 Subject: [PATCH] more junits to auth cass module Issue-ID: AAF-111 Change-Id: I7a1d2fd1568c9270174133e266d9590fe769dc7e Signed-off-by: Sai Gandham --- auth/auth-cass/JU_ConfigDAOTest.java | Bin 20 -> 0 bytes auth/auth-cass/JU_LocateDAOTest.java | Bin 56 -> 0 bytes auth/auth-cass/JU_NsDAOTest.java | Bin 28 -> 0 bytes auth/auth-cass/JU_OAuthTokenDAOTest.java | Bin 61 -> 0 bytes auth/auth-cass/JU_PermDAOTest.java | Bin 32 -> 0 bytes auth/auth-cass/JU_RoleDAOTest.java | Bin 24 -> 0 bytes auth/auth-cass/JU_UserRoleDAOTest.java | Bin 32 -> 0 bytes .../aaf/auth/direct/test/JU_DirectAAFLocator.java | 197 ++++++++++------- .../onap/aaf/auth/direct/test/JU_DirectAAFLur.java | 243 +++++++++++++++++++++ .../auth/direct/test/JU_DirectLocatorCreator.java | 88 ++++++++ 10 files changed, 447 insertions(+), 81 deletions(-) delete mode 100644 auth/auth-cass/JU_ConfigDAOTest.java delete mode 100644 auth/auth-cass/JU_LocateDAOTest.java delete mode 100644 auth/auth-cass/JU_NsDAOTest.java delete mode 100644 auth/auth-cass/JU_OAuthTokenDAOTest.java delete mode 100644 auth/auth-cass/JU_PermDAOTest.java delete mode 100644 auth/auth-cass/JU_RoleDAOTest.java delete mode 100644 auth/auth-cass/JU_UserRoleDAOTest.java create mode 100644 auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFLur.java create mode 100644 auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectLocatorCreator.java diff --git a/auth/auth-cass/JU_ConfigDAOTest.java b/auth/auth-cass/JU_ConfigDAOTest.java deleted file mode 100644 index c355c4df42525a08b9f96b6ad5835dddb67dc7cf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20 ScmZS3IJ1+1fr0Tq5&!^eYz?CT diff --git a/auth/auth-cass/JU_LocateDAOTest.java b/auth/auth-cass/JU_LocateDAOTest.java deleted file mode 100644 index ad7b3a2650137465f9254bbf3dd2e491e4d1f06e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 56 ZcmZP-ni$5wz`*z)3V>{!0Hg#a2>`-G4D|&F3`qR{U;(HYvK#<2RV1?j diff --git a/auth/auth-cass/JU_PermDAOTest.java b/auth/auth-cass/JU_PermDAOTest.java deleted file mode 100644 index 74b7a02c15db626333379e8d23c7b340b5ea4e3c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 32 WcmWf5GpUw=fr0Tq8UTthfP?@~4;A?U diff --git a/auth/auth-cass/JU_RoleDAOTest.java b/auth/auth-cass/JU_RoleDAOTest.java deleted file mode 100644 index 06a8e6c98de9288ab9232d49f9bea109ebbd106c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 24 WcmXr#S^b}Zfr0Tq6ad)_ASM8plnvtm diff --git a/auth/auth-cass/JU_UserRoleDAOTest.java b/auth/auth-cass/JU_UserRoleDAOTest.java deleted file mode 100644 index 56d5b8a4f141f04efcde54a3e888560c11615333..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 32 ScmdO4(coubU|{@@0{{Rwdl*pw 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 2801d433..01d4b9a2 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 @@ -61,95 +61,130 @@ public class JU_DirectAAFLocator { AuthzTrans trans; @Mock - Access access; + PropAccess access; @Before public void setUp() throws Exception { initMocks(this); } -// -// @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); -// try { -// DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao,"test","test"); -// } catch (LocatorException e) { -//// System.out.println(e.getMessage()); -// assertEquals("Invalid Version String: test", e.getMessage()); -// } -// } -// + + @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("20").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,""); + 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() { - Assert.assertTrue(true); + 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("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:")); + } } -// 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); -// try { -// DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao," test","3.2"); -// } catch (LocatorException e) { -//// System.out.println(e.getMessage()); -// assertTrue(e.getMessage().contains("Illegal character in path at index")); -// } -// } -// @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); -// try { -// aafLocatorObj = new DirectAAFLocator(env, ldao,"test","30.20.30.30"); -// } catch (LocatorException e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } -// Result> retVal1 = new Result>(null,0,"",new String[0]); -// -// Data data= new Data(); -// data.major=30; -// data.minor=30; -// data.patch=30; -// data.pkg=30; -// retVal1.value = new ArrayList(); -// 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); -// try { -// aafLocatorObj = new DirectAAFLocator(env, ldao,"test","30.20.30.30"); -// } catch (LocatorException e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } -// Result> retVal1 = new Result>(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("20").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,""); + 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> retVal1 = new Result>(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(); + 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("20").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER,""); + 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> retVal1 = new Result>(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 new file mode 100644 index 00000000..05077438 --- /dev/null +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFLur.java @@ -0,0 +1,243 @@ +/** + * ============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.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.MockitoAnnotations.initMocks; + +import java.security.Principal; +import java.util.ArrayList; +import java.util.List; + +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.NsSplit; +import org.onap.aaf.auth.dao.cass.PermDAO; +import org.onap.aaf.auth.dao.cass.PermDAO.Data; +import org.onap.aaf.auth.dao.hl.Question; +import org.onap.aaf.auth.direct.DirectAAFLur; +import org.onap.aaf.auth.direct.DirectAAFLur.PermPermission; +import org.onap.aaf.auth.env.AuthzEnv; +import org.onap.aaf.auth.env.AuthzTrans; +import org.onap.aaf.auth.env.AuthzTransImpl; +import org.onap.aaf.auth.env.NullTrans; +import org.onap.aaf.auth.layer.Result; +import org.onap.aaf.cadi.Permission; +import org.onap.aaf.cadi.aaf.AAFPermission; +import org.onap.aaf.cadi.lur.LocalPermission; +import org.onap.aaf.misc.env.LogTarget; +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 rsVal = new ArrayList(); + Result> rs = new Result>(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 rsVal = new ArrayList(); + 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> rs = new Result>(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>(rsVal,1,"test",new Object[0]); + Mockito.when(question.getPermsByUser(env.newTransNoAvg(), bait.getName(), false)).thenReturn(rs); + aafLurObj.fish(bait, pond); + rs = new Result>(rsVal,4,"test",new Object[0]); + Mockito.when(question.getPermsByUser(env.newTransNoAvg(), bait.getName(), false)).thenReturn(rs); + aafLurObj.fish(bait, pond); + rs = new Result>(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 rsVal = new ArrayList(); + 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 permissions = new ArrayList<>(); + permissions.add(pond); + + Result> rs = new Result>(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>(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 rs = new Result(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(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 rs = new Result(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("null.test", "name", "instance", "action"); + pp.match(pond); + } +} 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 new file mode 100644 index 00000000..c2b8597b --- /dev/null +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectLocatorCreator.java @@ -0,0 +1,88 @@ +/** + * ============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.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_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("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); + 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); + } +} -- 2.16.6