diff options
author | Sai Gandham <sg481n@att.com> | 2018-12-30 23:17:59 -0600 |
---|---|---|
committer | Sai Gandham <sg481n@att.com> | 2018-12-30 23:18:15 -0600 |
commit | 850788c053064409ad07b2b313396c674b57ac4b (patch) | |
tree | 98fab74319b35d8b661ee2171de01924f61e81f7 | |
parent | 52c89c9940544c1b2db1dd1e0ce9b22e2fcdca42 (diff) |
Add more junits in auth cass & misc env
Issue-ID: AAF-111
Change-Id: Iac8ff0043b89b00f2f6f9f45ccfa6253552d445d
Signed-off-by: Sai Gandham <sg481n@att.com>
20 files changed, 2711 insertions, 272 deletions
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 4a307693..a513da0a 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,9 +132,9 @@ public class Question { public final HistoryDAO historyDAO; public final CachedNSDAO nsDAO; - public final CachedRoleDAO roleDAO; + public CachedRoleDAO roleDAO; public final CachedPermDAO permDAO; - public final CachedUserRoleDAO userRoleDAO; + public CachedUserRoleDAO userRoleDAO; public final CachedCredDAO credDAO; public final CachedCertDAO certDAO; public final DelegateDAO delegateDAO; @@ -145,6 +145,7 @@ public class Question { public Question(AuthzTrans trans, Cluster cluster, String keyspace, boolean startClean) throws APIException, IOException { PERMS = trans.slot("USER_PERMS"); + System.out.println(trans.init()); trans.init().log("Instantiating DAOs"); long expiresIn = Long.parseLong(trans.getProperty(Config.AAF_USER_EXPIRES, Config.AAF_USER_EXPIRES_DEF)); historyDAO = new HistoryDAO(trans, cluster, keyspace); diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedPermDAOTest.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedPermDAOTest.java new file mode 100644 index 00000000..66c32a7b --- /dev/null +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedPermDAOTest.java @@ -0,0 +1,166 @@ +/** + * ============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.dao.cached; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.aaf.auth.dao.CIDAO; +import org.onap.aaf.auth.dao.cass.PermDAO; +import org.onap.aaf.auth.dao.cass.PermDAO.Data; +import org.onap.aaf.auth.dao.cass.RoleDAO; +import org.onap.aaf.auth.dao.cass.Status; +import org.onap.aaf.auth.env.AuthzTrans; +import org.onap.aaf.auth.env.AuthzTransImpl; +import org.onap.aaf.auth.layer.Result; +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() { + + @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; + } + }); + } + + @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/JU_CachedRoleDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedRoleDAO.java deleted file mode 100644 index 2e27bfd9..00000000 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedRoleDAO.java +++ /dev/null @@ -1,174 +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.dao.cached; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -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.CIDAO; -import org.onap.aaf.auth.dao.cass.PermDAO; -import org.onap.aaf.auth.dao.cass.RoleDAO; -import org.onap.aaf.auth.dao.cass.RoleDAO.Data; -import org.onap.aaf.auth.env.AuthzTrans; -import org.onap.aaf.auth.env.AuthzTransImpl; -import org.onap.aaf.auth.layer.Result; -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() { - - @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; - } - }); - } - - @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]); - 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)); - } -}
\ No newline at end of file diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedUserRoleDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedUserRoleDAO.java new file mode 100644 index 00000000..8dcf8e44 --- /dev/null +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedUserRoleDAO.java @@ -0,0 +1,180 @@ +/** + * ============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.dao.cached; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +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.onap.aaf.auth.dao.CIDAO; +import org.onap.aaf.auth.dao.cass.PermDAO; +import org.onap.aaf.auth.dao.cass.RoleDAO; +import org.onap.aaf.auth.dao.cass.UserRoleDAO; +import org.onap.aaf.auth.dao.cass.UserRoleDAO.Data; +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.layer.Result; +import org.onap.aaf.cadi.principal.TaggedPrincipal; +import org.onap.aaf.misc.env.LogTarget; +import org.onap.aaf.misc.env.Slot; +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() { + + @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; + } + }); + } + + 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)); + } + + +}
\ No newline at end of file diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CassExecutor.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CassExecutor.java new file mode 100644 index 00000000..5dd33c7e --- /dev/null +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CassExecutor.java @@ -0,0 +1,154 @@ +/** + * ============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.dao.hl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.mockito.MockitoAnnotations.initMocks; + +import java.util.Properties; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; +import org.onap.aaf.auth.common.Define; +import org.onap.aaf.auth.dao.cass.NsSplit; +import org.onap.aaf.auth.dao.cass.UserRoleDAO.Data; +import org.onap.aaf.auth.env.AuthzTransImpl; +import org.onap.aaf.auth.layer.Result; +import org.onap.aaf.cadi.Access; +import org.onap.aaf.cadi.CadiException; + + +@RunWith(MockitoJUnitRunner.class) +public class JU_CassExecutor { + + + + @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,"",new String[0]); + 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,"",new String[0]); + 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() { + private int count = 0; + + 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,"",new String[0]); + 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/JU_PermLookup.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_PermLookup.java new file mode 100644 index 00000000..e63d4b52 --- /dev/null +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_PermLookup.java @@ -0,0 +1,383 @@ +/** + * ============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.dao.hl; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Properties; +import java.util.Set; + +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.common.Define; +import org.onap.aaf.auth.dao.cached.CachedRoleDAO; +import org.onap.aaf.auth.dao.cached.CachedUserRoleDAO; +import org.onap.aaf.auth.dao.cass.PermDAO.Data; +import org.onap.aaf.auth.dao.cass.RoleDAO; +import org.onap.aaf.auth.dao.cass.UserRoleDAO; +import org.onap.aaf.auth.env.AuthzTrans; +import org.onap.aaf.auth.layer.Result; +import org.onap.aaf.cadi.Access; +import org.onap.aaf.cadi.CadiException; +import org.onap.aaf.misc.env.LogTarget; + + +@RunWith(MockitoJUnitRunner.class) +public class JU_PermLookup { + + + + @Mock + AuthzTrans 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); + + 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() { + q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); + 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(q.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() { + q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); + 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(q.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() { + q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); + 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(q.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() { + q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); + 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(q.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() { + q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); + q.roleDAO = Mockito.mock(CachedRoleDAO.class); + 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(q.userRoleDAO).readByUser(trans,""); + Mockito.doReturn(retVal1).when(q.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() { + q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); + q.roleDAO = Mockito.mock(CachedRoleDAO.class); + 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(q.userRoleDAO).readByUser(trans,""); + Mockito.doReturn(retVal1).when(q.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() { + q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); + 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(q.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() { + q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); + 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(q.userRoleDAO).readByUser(trans,""); + PermLookup cassExecutorObj =PermLookup.get(trans, q,""); + Result<Set<String>> userRoles = cassExecutorObj.getPermNames(); + + //System.out.println(""+userRoles.status); + assertEquals(4,userRoles.status); + } + + + @Test + public void testGetPerm() { + q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); + q.roleDAO = Mockito.mock(CachedRoleDAO.class); + 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(q.userRoleDAO).readByUser(trans,""); + Mockito.doReturn(retVal2).when(q.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); + } + + @Test + public void testGetPermFalse() { + q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class); + q.roleDAO = Mockito.mock(CachedRoleDAO.class); + 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(q.userRoleDAO).readByUser(trans,""); + Mockito.doReturn(retVal2).when(q.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); + } + +}
\ No newline at end of file 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 deleted file mode 100644 index 972e366c..00000000 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedPermDAOTest.java +++ /dev/null @@ -1,78 +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.dao.cached; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -import java.util.List; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.onap.aaf.auth.dao.CIDAO; -import org.onap.aaf.auth.dao.cass.PermDAO; -import org.onap.aaf.auth.dao.cass.PermDAO.Data; -import org.onap.aaf.auth.dao.cass.Status; -import org.onap.aaf.auth.env.AuthzTrans; -import org.onap.aaf.auth.layer.Result; - -public class JU_CachedPermDAOTest { - - @Mock - private CIDAO<AuthzTrans> info; - @Mock - private PermDAO dao; - 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); - } - - @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"); - } - -} 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 new file mode 100644 index 00000000..cf850587 --- /dev/null +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFLocator.java @@ -0,0 +1,152 @@ +/** + * ============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.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.MockitoAnnotations.initMocks; + +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.LocateDAO; +import org.onap.aaf.auth.dao.cass.LocateDAO.Data; +import org.onap.aaf.auth.direct.DirectAAFLocator; +import org.onap.aaf.auth.env.AuthzEnv; +import org.onap.aaf.auth.env.AuthzTrans; +import org.onap.aaf.auth.layer.Result; +import org.onap.aaf.cadi.Access; +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_DirectAAFLocator { + + @Mock + LocateDAO ldao; + + @Mock + AuthzEnv env; + + @Mock + AuthzTrans trans; + + @Mock + Access access; + + @Before + public void setUp() throws Exception { + initMocks(this); + } + + @Test + public void testConstructorExcpetion() { + + 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","test"); + } catch (LocatorException e) { +// System.out.println(e.getMessage()); + assertEquals("Invalid Version String: test", e.getMessage()); + } + } + + @Test + public void testConstructorUriExcpetion() { + + 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<List<Data>> retVal1 = new Result<List<Data>>(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<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); + 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_DirectAAFUserPass.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFUserPass.java new file mode 100644 index 00000000..ca0a8917 --- /dev/null +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFUserPass.java @@ -0,0 +1,223 @@ +/** + * ============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.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import java.util.Date; + +import javax.servlet.http.HttpServletRequest; + +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.DAOException; +import org.onap.aaf.auth.dao.hl.Question; +import org.onap.aaf.auth.direct.DirectAAFUserPass; +import org.onap.aaf.auth.env.AuthzEnv; +import org.onap.aaf.auth.env.AuthzTrans; +import org.onap.aaf.auth.layer.Result; +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() { + + @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; + } + }); + when(env.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; + } + }); + } + + @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); + + assertTrue(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_DirectLocatorCreateor.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectLocatorCreateor.java new file mode 100644 index 00000000..d026500c --- /dev/null +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectLocatorCreateor.java @@ -0,0 +1,86 @@ +/** + * ============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.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); + } + + @Test + public void testCreate() { + 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-core/src/main/java/org/onap/aaf/auth/layer/Result.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/layer/Result.java index a3abb2bb..3e68e3ab 100644 --- a/auth/auth-core/src/main/java/org/onap/aaf/auth/layer/Result.java +++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/layer/Result.java @@ -48,7 +48,7 @@ public class Result<RV> { ERR_Backend = 9, ERR_General = 20; - public final RV value; + public RV value; public final int status; public final String details; public final String[] variables; @@ -275,6 +275,8 @@ public class Result<RV> { * @return */ public boolean isOKhasData() { + System.out.println("specialCondition:"+specialCondition); + System.out.println("specialCondition:"+(specialCondition & EMPTY_LIST)); return status == OK && (specialCondition & EMPTY_LIST) != EMPTY_LIST; } diff --git a/cadi/core/src/test/resources/keystore.p12 b/cadi/core/src/test/resources/keystore.p12 Binary files differnew file mode 100644 index 00000000..51273d5d --- /dev/null +++ b/cadi/core/src/test/resources/keystore.p12 diff --git a/cadi/core/src/test/resources/output_key b/cadi/core/src/test/resources/output_key new file mode 100644 index 00000000..9d94dcbd --- /dev/null +++ b/cadi/core/src/test/resources/output_key @@ -0,0 +1 @@ +QRSTUVWXYZabcdef
\ No newline at end of file diff --git a/cadi/core/src/test/resources/truststore.jks b/cadi/core/src/test/resources/truststore.jks Binary files differnew file mode 100644 index 00000000..9ee3dcf6 --- /dev/null +++ b/cadi/core/src/test/resources/truststore.jks diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/Api.java b/misc/env/src/test/java/org/onap/aaf/misc/env/Api.java new file mode 100644 index 00000000..688e11b8 --- /dev/null +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/Api.java @@ -0,0 +1,373 @@ +/** + * ============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==================================================== + * + */ +// +// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.5-2 +// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> +// Any modifications to this file will be lost upon recompilation of the source schema. +// Generated on: 2018.12.09 at 10:14:23 PM IST +// + + +package org.onap.aaf.misc.env; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + + +/** + * <p>Java class for anonymous complex type. + * + * <p>The following schema fragment specifies the expected content contained within this class. + * + * <pre> + * <complexType> + * <complexContent> + * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> + * <sequence> + * <element name="route" maxOccurs="unbounded" minOccurs="0"> + * <complexType> + * <complexContent> + * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> + * <sequence> + * <element name="meth" type="{http://www.w3.org/2001/XMLSchema}string"/> + * <element name="path" type="{http://www.w3.org/2001/XMLSchema}string"/> + * <element name="param" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="unbounded" minOccurs="0"/> + * <element name="desc" type="{http://www.w3.org/2001/XMLSchema}string"/> + * <element name="comments" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="unbounded" minOccurs="0"/> + * <element name="contentType" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="unbounded" minOccurs="0"/> + * <element name="expected" type="{http://www.w3.org/2001/XMLSchema}int"/> + * <element name="explicitErr" type="{http://www.w3.org/2001/XMLSchema}int" maxOccurs="unbounded" minOccurs="0"/> + * </sequence> + * </restriction> + * </complexContent> + * </complexType> + * </element> + * </sequence> + * </restriction> + * </complexContent> + * </complexType> + * </pre> + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "route" +}) +@XmlRootElement(name = "api") +public class Api { + + protected List<Api.Route> route; + + /** + * Gets the value of the route property. + * + * <p> + * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a <CODE>set</CODE> method for the route property. + * + * <p> + * For example, to add a new item, do as follows: + * <pre> + * getRoute().add(newItem); + * </pre> + * + * + * <p> + * Objects of the following type(s) are allowed in the list + * {@link Api.Route } + * + * + */ + public List<Api.Route> getRoute() { + if (route == null) { + route = new ArrayList<Api.Route>(); + } + return this.route; + } + + + /** + * <p>Java class for anonymous complex type. + * + * <p>The following schema fragment specifies the expected content contained within this class. + * + * <pre> + * <complexType> + * <complexContent> + * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> + * <sequence> + * <element name="meth" type="{http://www.w3.org/2001/XMLSchema}string"/> + * <element name="path" type="{http://www.w3.org/2001/XMLSchema}string"/> + * <element name="param" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="unbounded" minOccurs="0"/> + * <element name="desc" type="{http://www.w3.org/2001/XMLSchema}string"/> + * <element name="comments" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="unbounded" minOccurs="0"/> + * <element name="contentType" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="unbounded" minOccurs="0"/> + * <element name="expected" type="{http://www.w3.org/2001/XMLSchema}int"/> + * <element name="explicitErr" type="{http://www.w3.org/2001/XMLSchema}int" maxOccurs="unbounded" minOccurs="0"/> + * </sequence> + * </restriction> + * </complexContent> + * </complexType> + * </pre> + * + * + */ + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = { + "meth", + "path", + "param", + "desc", + "comments", + "contentType", + "expected", + "explicitErr" + }) + public static class Route { + + @XmlElement(required = true) + protected String meth; + @XmlElement(required = true) + protected String path; + protected List<String> param; + @XmlElement(required = true) + protected String desc; + protected List<String> comments; + protected List<String> contentType; + protected int expected; + @XmlElement(type = Integer.class) + protected List<Integer> explicitErr; + + /** + * Gets the value of the meth property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getMeth() { + return meth; + } + + /** + * Sets the value of the meth property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setMeth(String value) { + this.meth = value; + } + + /** + * Gets the value of the path property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getPath() { + return path; + } + + /** + * Sets the value of the path property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setPath(String value) { + this.path = value; + } + + /** + * Gets the value of the param property. + * + * <p> + * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a <CODE>set</CODE> method for the param property. + * + * <p> + * For example, to add a new item, do as follows: + * <pre> + * getParam().add(newItem); + * </pre> + * + * + * <p> + * Objects of the following type(s) are allowed in the list + * {@link String } + * + * + */ + public List<String> getParam() { + if (param == null) { + param = new ArrayList<String>(); + } + return this.param; + } + + /** + * Gets the value of the desc property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getDesc() { + return desc; + } + + /** + * Sets the value of the desc property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setDesc(String value) { + this.desc = value; + } + + /** + * Gets the value of the comments property. + * + * <p> + * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a <CODE>set</CODE> method for the comments property. + * + * <p> + * For example, to add a new item, do as follows: + * <pre> + * getComments().add(newItem); + * </pre> + * + * + * <p> + * Objects of the following type(s) are allowed in the list + * {@link String } + * + * + */ + public List<String> getComments() { + if (comments == null) { + comments = new ArrayList<String>(); + } + return this.comments; + } + + /** + * Gets the value of the contentType property. + * + * <p> + * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a <CODE>set</CODE> method for the contentType property. + * + * <p> + * For example, to add a new item, do as follows: + * <pre> + * getContentType().add(newItem); + * </pre> + * + * + * <p> + * Objects of the following type(s) are allowed in the list + * {@link String } + * + * + */ + public List<String> getContentType() { + if (contentType == null) { + contentType = new ArrayList<String>(); + } + return this.contentType; + } + + /** + * Gets the value of the expected property. + * + */ + public int getExpected() { + return expected; + } + + /** + * Sets the value of the expected property. + * + */ + public void setExpected(int value) { + this.expected = value; + } + + /** + * Gets the value of the explicitErr property. + * + * <p> + * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a <CODE>set</CODE> method for the explicitErr property. + * + * <p> + * For example, to add a new item, do as follows: + * <pre> + * getExplicitErr().add(newItem); + * </pre> + * + * + * <p> + * Objects of the following type(s) are allowed in the list + * {@link Integer } + * + * + */ + public List<Integer> getExplicitErr() { + if (explicitErr == null) { + explicitErr = new ArrayList<Integer>(); + } + return this.explicitErr; + } + + } + +} diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/JU_BaseDataFactory.java b/misc/env/src/test/java/org/onap/aaf/misc/env/JU_BaseDataFactory.java new file mode 100644 index 00000000..0c21bda3 --- /dev/null +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/JU_BaseDataFactory.java @@ -0,0 +1,82 @@ +/** + * ============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.misc.env; + +import static org.junit.Assert.assertTrue; +import static org.mockito.MockitoAnnotations.initMocks; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.aaf.misc.env.impl.EnvFactory; + +public class JU_BaseDataFactory { + + @Before + public void setUp() throws Exception { + initMocks(this); + } + + @Test + public void testGenSchemaException() { + Store env = Mockito.mock(Store.class); + Mockito.doReturn("testdir").when(env).get(null, EnvFactory.DEFAULT_SCHEMA_DIR); + try { + BaseDataFactory.genSchema(env, new String[] {}); + } catch (APIException e) { + assertTrue(e.getLocalizedMessage().contains("does not exist. You can set this with")); + } + } + + @Test + public void testGenSchemaXsdException() { + Store env = Mockito.mock(Store.class); + Mockito.doReturn(System.getProperty("user.dir")).when(env).get(null, EnvFactory.DEFAULT_SCHEMA_DIR); + String[] schemaFIles = new String[] {"../auth-client/src/main/xsd/aaf_2_0.xsd"}; + try { + BaseDataFactory.genSchema(env, schemaFIles); + } catch (APIException e) { + assertTrue(e.getLocalizedMessage().contains("for schema validation")); + } + } + + @Test + public void testGenSchemaNoException() { + Store env = Mockito.mock(Store.class); + Mockito.doReturn(System.getProperty("user.dir")).when(env).get(null, EnvFactory.DEFAULT_SCHEMA_DIR); + String[] schemaFIles = new String[] {"../../auth-client/src/main/xsd/aaf_2_0.xsd"}; + try { + BaseDataFactory.genSchema(env, schemaFIles); + } catch (APIException e) { + e.printStackTrace(); + } + } + + @Test + public void testGetQName() { + String[] schemaFIles = new String[] {"../../auth-client/src/main/xsd/aaf_2_0.xsd"}; + try { + BaseDataFactory.getQName(Api.class); + } catch (APIException e) { + assertTrue(e.getLocalizedMessage().contains("package-info does not have an XmlSchema annotation")); + } + } +} diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/JU_JavaUtilLogTarget.java b/misc/env/src/test/java/org/onap/aaf/misc/env/JU_JavaUtilLogTarget.java new file mode 100644 index 00000000..2617559d --- /dev/null +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/JU_JavaUtilLogTarget.java @@ -0,0 +1,85 @@ +/** + * ============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.misc.env.impl; + +import static org.junit.Assert.assertFalse; +import static org.mockito.MockitoAnnotations.initMocks; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; + +public class JU_JavaUtilLogTarget { + + @Mock + Level level; + + @Mock + Logger log; + + @Before + public void setup() { + initMocks(this); + } + + @Test + public void testLoggable() { + JavaUtilLogTarget logObj = new JavaUtilLogTarget( log, level); + boolean retVal = logObj.isLoggable(); + + assertFalse(retVal); + } + + @Test + public void testLog() { + JavaUtilLogTarget logObj = new JavaUtilLogTarget( log, level); + Mockito.doReturn(false).when(log).isLoggable(level); + logObj.log(new Object[] {"test","test2",""}); + Mockito.doReturn(true).when(log).isLoggable(level); + logObj.log(new Object[] {"test","test2",""}); + + } + + @Test + public void testLogThrowable() { + JavaUtilLogTarget logObj = new JavaUtilLogTarget( log, level); + + Mockito.doReturn(true).when(log).isLoggable(level); + logObj.log(new Throwable("test exception"), new Object[] {"test","test2",""}); + logObj.log(new Throwable(), new Object[] {"test","test2",""}); + } + + @Test + public void testPrintf() { + JavaUtilLogTarget logObj = new JavaUtilLogTarget( log, level); + + Mockito.doReturn(true).when(log).isLoggable(level); + logObj.printf("test", new Object[] {"test","test2",""}); + + Mockito.doReturn(false).when(log).isLoggable(level); + logObj.printf("test", new Object[] {"test","test2",""}); + } +} diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/JU_NullLifeCycle.java b/misc/env/src/test/java/org/onap/aaf/misc/env/JU_NullLifeCycle.java new file mode 100644 index 00000000..e685dfe6 --- /dev/null +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/JU_NullLifeCycle.java @@ -0,0 +1,43 @@ +/** + * ============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.misc.env.impl; + +import org.junit.Test; +import org.onap.aaf.misc.env.APIException; + +public class JU_NullLifeCycle { + + @Test + public void testServicePrestart() { + NullLifeCycle lifeCycleObj = new NullLifeCycle(); + try { + lifeCycleObj.servicePrestart(null); + lifeCycleObj.serviceDestroy(null); + lifeCycleObj.threadDestroy(null); + lifeCycleObj.threadPrestart(null); + lifeCycleObj.refresh(null); + }catch(APIException a) { + + } + } + +}
\ No newline at end of file diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_Log4JLogTargetTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_Log4JLogTargetTest.java index 9feaf3ef..2067e2ab 100644 --- a/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_Log4JLogTargetTest.java +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_Log4JLogTargetTest.java @@ -21,42 +21,88 @@ package org.onap.aaf.misc.env.impl;
-import static org.junit.Assert.assertFalse;
-import static org.powermock.api.mockito.PowerMockito.when;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.MockitoAnnotations.initMocks;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.Mockito;
import org.onap.aaf.misc.env.APIException;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({ Log4JLogTarget.class, Logger.class })
public class JU_Log4JLogTargetTest {
+ @Mock
+ Level level;
+
@Mock
Logger log;
@Before
public void setup() {
- MockitoAnnotations.initMocks(this);
- PowerMockito.mockStatic(Logger.class);
- when(Logger.getLogger("Info")).thenReturn(log);
- when(log.isEnabledFor (Level.DEBUG)).thenReturn(false);
+ initMocks(this);
}
@Test
- public void test() throws APIException {
- Log4JLogTarget target = new Log4JLogTarget(null, Level.INFO);
- Log4JLogTarget target1 = new Log4JLogTarget("Info", Level.DEBUG);
+ public void testLoggable() {
+ Log4JLogTarget logObj = null;
+ try {
+ logObj = new Log4JLogTarget( "testLogger", Level.DEBUG);
+ } catch (APIException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ boolean retVal = logObj.isLoggable();
+ assertTrue(retVal);
+ }
+
+ @Test
+ public void testLog() {
+ Log4JLogTarget logObj = null;
+ try {
+ logObj = new Log4JLogTarget( null, Level.DEBUG);
+ } catch (APIException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ logObj.log(new Object[] {"test"});
+ }
+
+ @Test
+ public void testLogThrowable() {
+ Log4JLogTarget logObj = null;
+ try {
+ logObj = new Log4JLogTarget( null, Level.DEBUG);
+ } catch (APIException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ logObj.log(new Throwable("test exception"), new Object[] {"test","test2","",null});
+ }
+
+ @Test
+ public void testPrintf() {
+ Log4JLogTarget logObj = null;
+ try {
+ logObj = new Log4JLogTarget( "", level);
+ } catch (APIException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ logObj.printf("test", new Object[] {"test","test2",""});
- assertFalse(target1.isLoggable());
+ }
+
+ @Test
+ public void testSetEnv() {
+ try {
+ Log4JLogTarget.setLog4JEnv("test", Mockito.mock(BasicEnv.class));
+ } catch (APIException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
}
\ No newline at end of file diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/jaxb/JU_JAXBDF.java b/misc/env/src/test/java/org/onap/aaf/misc/env/jaxb/JU_JAXBDF.java new file mode 100644 index 00000000..62c49032 --- /dev/null +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/jaxb/JU_JAXBDF.java @@ -0,0 +1,714 @@ +/** + * ============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.misc.env.jaxb; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.MockitoAnnotations.initMocks; + +import java.io.InputStream; +import java.io.OutputStream; +import java.io.StringReader; +import java.io.StringWriter; + +import javax.xml.bind.JAXBException; +import javax.xml.namespace.QName; +import javax.xml.validation.Schema; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.aaf.misc.env.APIException; +import org.onap.aaf.misc.env.Data; +import org.onap.aaf.misc.env.Env; +import org.onap.aaf.misc.env.EnvJAXB; +import org.onap.aaf.misc.env.LogTarget; +import org.onap.aaf.misc.env.TimeTaken; + +public class JU_JAXBDF { + + @Mock + EnvJAXB primaryEnv; + + @Mock + JAXBumar jumar; + + @Mock + JAXBmar jmar; + + @Mock + Env env; + + TimeTaken tt,ttObjectify; + + @Before + public void setUp() { + initMocks(this); + tt=Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(env).start("JAXB Stringify", Env.XML); + Mockito.doNothing().when(tt).done(); + ttObjectify=Mockito.mock(TimeTaken.class); + Mockito.doReturn(ttObjectify).when(env).start("JAXB Objectify", Env.XML); + Mockito.doNothing().when(ttObjectify).done(); + } + + @Test + public void testNewInstance() { + JAXBDF<?> bdfObj = null; + try { + bdfObj = new JAXBDF( null, new Class[] {this.getClass()}); + bdfObj.jumar = Mockito.mock(JAXBumar.class); + Mockito.doThrow(new IllegalAccessException("Test Exception")).when(bdfObj.jumar).newInstance(); + Object retVal = bdfObj.newInstance(); + } catch (IllegalAccessException e) { + assertEquals("Test Exception", e.getLocalizedMessage()); + } catch (APIException e) { + assertTrue(e.getMessage().contains("Test Exception")); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + @Test + public void testNewInstanceNoException() { + JAXBDF<?> bdfObj = null; + try { + bdfObj = new JAXBDF( null, new Class[] {this.getClass()}); + Object retVal = bdfObj.newInstance(); + assertTrue(retVal instanceof JU_JAXBDF); + } catch (APIException e) { + e.printStackTrace(); + } + + } + + @Test + public void testPrettyNoException() { + JAXBDF<?> bdfObj = null; + try { + bdfObj = new JAXBDF( null, Mockito.mock(Schema.class), new Class[] {this.getClass()}); + Object retVal = bdfObj.pretty(true); + assertTrue(retVal instanceof JAXBDF); + } catch (APIException e) { + e.printStackTrace(); + } + } + + @Test + public void testFragment() { + JAXBDF<?> bdfObj = null; + try { + bdfObj = new JAXBDF( null, Mockito.mock(QName.class), new Class[] {this.getClass()}); + Object retVal = bdfObj.asFragment(true); + assertTrue(retVal instanceof JAXBDF); + bdfObj.servicePrestart(null); + bdfObj.threadPrestart(null); + bdfObj.refresh(null); + bdfObj.threadDestroy(null); + bdfObj.serviceDestroy(null); + } catch (APIException e) { + e.printStackTrace(); + } + + } + + @Test + public void testNewData() { + JAXBDF<?> bdfObj = null; + try { + bdfObj = new JAXBDF( null, Mockito.mock(Schema.class),Mockito.mock(QName.class), new Class[] {this.getClass()}); + Data<?> retVal = bdfObj.newData(); + assertTrue(retVal instanceof JAXBData); + } catch (APIException e) { + e.printStackTrace(); + } + } + + @Test + public void testNewDataENV() { + JAXBDF<?> bdfObj = null; + try { + bdfObj = new JAXBDF( null, Mockito.mock(Schema.class),Mockito.mock(QName.class), new Class[] {this.getClass()}); + Data<?> retVal = bdfObj.newData(Mockito.mock(Env.class)); + assertTrue(retVal instanceof JAXBData); + } catch (APIException e) { + e.printStackTrace(); + } + } + + @Test + public void testNewDataType() { + JAXBDF<JAXBumar> bdfObj = null; + try { + bdfObj = new JAXBDF( null, Mockito.mock(Schema.class),Mockito.mock(QName.class), new Class[] {this.getClass()}); + Data<?> retVal = bdfObj.newData(new JAXBumar(new Class[] {this.getClass()})); + assertTrue(retVal instanceof JAXBData); + } catch (APIException e) { + e.printStackTrace(); + } catch (JAXBException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testNewDataStream() { + JAXBDF<?> bdfObj = null; + try { + bdfObj = new JAXBDF( null, Mockito.mock(Schema.class),Mockito.mock(QName.class), new Class[] {this.getClass()}); + bdfObj.jumar = Mockito.mock(JAXBumar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(env).debug(); + InputStream is = Mockito.mock(InputStream.class); + Mockito.doReturn(this.getClass()).when(bdfObj.jumar).unmarshal(logT, is); + Data<?> retVal = bdfObj.newDataFromStream(env, is); + assertTrue(retVal instanceof JAXBData); + } catch (APIException e) { + e.printStackTrace(); + } catch (JAXBException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testNewDataStreamException() { + JAXBDF<?> bdfObj = null; + try { + bdfObj = new JAXBDF( null, Mockito.mock(Schema.class),Mockito.mock(QName.class), new Class[] {this.getClass()}); + bdfObj.jumar = Mockito.mock(JAXBumar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(env).debug(); + InputStream is = Mockito.mock(InputStream.class); + Mockito.doThrow(new JAXBException("test")).when(bdfObj.jumar).unmarshal(logT, is); + Data<?> retVal = bdfObj.newDataFromStream(env, is); + } catch (APIException e) { + assertTrue(e.getMessage().contains("test")); + } catch (JAXBException e) { + // TODO Auto-generated catch block + assertTrue(e.getMessage().contains("test")); + } + } + + @Test + public void testNewDataFromString() { + JAXBDF<?> bdfObj = null; + try { + bdfObj = new JAXBDF( null, Mockito.mock(Schema.class),Mockito.mock(QName.class), new Class[] {this.getClass()}); + Data<?> retVal = bdfObj.newDataFromString("test"); + assertTrue(retVal instanceof JAXBData); + } catch (APIException e) { + e.printStackTrace(); + } + } + + @Test + public void testStringify() { + JAXBDF<JAXBmar> bdfObj = null; + try { + JAXBmar typeObj = new JAXBmar(new Class[] {this.getClass()}); + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + bdfObj = new JAXBDF( envJaxb, new Class[] {this.getClass()}); + bdfObj.jmar = Mockito.mock(JAXBmar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(envJaxb).debug(); + Mockito.doReturn(this.getClass()).when(bdfObj.jmar).marshal(logT, typeObj, Mockito.mock(StringWriter.class)); + String retVal = bdfObj.stringify(typeObj); + assertEquals("", retVal); + } catch (APIException e) { + e.printStackTrace(); + } catch (JAXBException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testStringifyException() { + JAXBDF<JAXBmar> bdfObj = null; + try { + JAXBmar typeObj = new JAXBmar(new Class[] {this.getClass()}); + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(envJaxb).debug(); + bdfObj = new JAXBDF<JAXBmar>( envJaxb, new Class[] {this.getClass()}); + bdfObj.jmar = Mockito.mock(JAXBmar.class); + Mockito.doThrow(new JAXBException("test") ).when(bdfObj.jmar).marshal(logT, typeObj, Mockito.mock(StringWriter.class)); + String retVal = bdfObj.stringify(typeObj); + System.out.println(retVal); + } catch (APIException e) { + assertTrue(e.getMessage().contains("test")); + } catch (JAXBException e) { + assertTrue(e.getMessage().contains("test")); + } + } + + @Test + public void testStringifyWriter() { + JAXBDF<JAXBmar> bdfObj = null; + try { + JAXBmar typeObj = new JAXBmar(new Class[] {this.getClass()}); + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + bdfObj = new JAXBDF( envJaxb, new Class[] {this.getClass()}); + bdfObj.jmar = Mockito.mock(JAXBmar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(envJaxb).debug(); + Mockito.doReturn(this.getClass()).when(bdfObj.jmar).marshal(logT, typeObj, Mockito.mock(StringWriter.class)); + bdfObj.stringify(typeObj, Mockito.mock(StringWriter.class)); + } catch (APIException e) { + e.printStackTrace(); + } catch (JAXBException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testStringifyWriterException() { + JAXBDF<JAXBmar> bdfObj = null; + try { + JAXBmar typeObj = new JAXBmar(new Class[] {this.getClass()}); + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + bdfObj = new JAXBDF( envJaxb, new Class[] {this.getClass()}); + bdfObj.jmar = Mockito.mock(JAXBmar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(envJaxb).debug(); + StringWriter sw = Mockito.mock(StringWriter.class); + Mockito.doThrow(new JAXBException("test")).when(bdfObj.jmar).marshal(logT, typeObj, sw); + bdfObj.stringify(typeObj, sw); + } catch (APIException e) { + assertTrue(e.getMessage().contains("test")); + } catch (JAXBException e) { + assertTrue(e.getMessage().contains("test")); + } + } + + @Test + public void testStringifyOS() { + JAXBDF<JAXBmar> bdfObj = null; + try { + JAXBmar typeObj = new JAXBmar(new Class[] {this.getClass()}); + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + bdfObj = new JAXBDF( envJaxb, new Class[] {this.getClass()}); + bdfObj.jmar = Mockito.mock(JAXBmar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(envJaxb).debug(); + Mockito.doReturn(this.getClass()).when(bdfObj.jmar).marshal(logT, typeObj, Mockito.mock(OutputStream.class)); + bdfObj.stringify(typeObj, Mockito.mock(OutputStream.class)); + } catch (APIException e) { + e.printStackTrace(); + } catch (JAXBException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testStringifyOsException() { + JAXBDF<JAXBmar> bdfObj = null; + try { + JAXBmar typeObj = new JAXBmar(new Class[] {this.getClass()}); + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + bdfObj = new JAXBDF( envJaxb, new Class[] {this.getClass()}); + bdfObj.jmar = Mockito.mock(JAXBmar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(envJaxb).debug(); + OutputStream sw = Mockito.mock(OutputStream.class); + Mockito.doThrow(new JAXBException("test")).when(bdfObj.jmar).marshal(logT, typeObj, sw); + bdfObj.stringify(typeObj, sw); + } catch (APIException e) { + assertTrue(e.getMessage().contains("test")); + } catch (JAXBException e) { + assertTrue(e.getMessage().contains("test")); + } + } + + @Test + public void testStringifyOptions() { + JAXBDF<JAXBmar> bdfObj = null; + try { + JAXBmar typeObj = new JAXBmar(new Class[] {this.getClass()}); + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + bdfObj = new JAXBDF( envJaxb, new Class[] {this.getClass()}); + bdfObj.jmar = Mockito.mock(JAXBmar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(envJaxb).debug(); + Mockito.doReturn(this.getClass()).when(bdfObj.jmar).marshal(logT, typeObj, Mockito.mock(OutputStream.class)); + bdfObj.stringify(env, typeObj, true); + } catch (APIException e) { + e.printStackTrace(); + } catch (JAXBException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testStringifyOSOptions() { + JAXBDF<JAXBmar> bdfObj = null; + try { + JAXBmar typeObj = new JAXBmar(new Class[] {this.getClass()}); + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + bdfObj = new JAXBDF( envJaxb, new Class[] {this.getClass()}); + bdfObj.jmar = Mockito.mock(JAXBmar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(env).debug(); + Mockito.doReturn(this.getClass()).when(bdfObj.jmar).marshal(logT, typeObj, Mockito.mock(OutputStream.class),true); + bdfObj.stringify(env, typeObj, Mockito.mock(OutputStream.class),true); + } catch (APIException e) { + e.printStackTrace(); + } catch (JAXBException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testStringifyOsOptionsException() { + JAXBDF<JAXBmar> bdfObj = null; + try { + JAXBmar typeObj = new JAXBmar(new Class[] {this.getClass()}); + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + bdfObj = new JAXBDF( envJaxb, new Class[] {this.getClass()}); + bdfObj.jmar = Mockito.mock(JAXBmar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(env).debug(); + OutputStream sw = Mockito.mock(OutputStream.class); + Mockito.doThrow(new JAXBException("test")).when(bdfObj.jmar).marshal(logT, typeObj, sw,true); + bdfObj.stringify(env, typeObj, sw,true); + } catch (APIException e) { + assertTrue(e.getMessage().contains("test")); + } catch (JAXBException e) { + assertTrue(e.getMessage().contains("test")); + } + } + @Test + public void testStringifySWOptions() { + JAXBDF<JAXBmar> bdfObj = null; + try { + JAXBmar typeObj = new JAXBmar(new Class[] {this.getClass()}); + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + bdfObj = new JAXBDF( envJaxb, new Class[] {this.getClass()}); + bdfObj.jmar = Mockito.mock(JAXBmar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(env).debug(); + Mockito.doReturn(this.getClass()).when(bdfObj.jmar).marshal(logT, typeObj, Mockito.mock(StringWriter.class),true); + bdfObj.stringify(env, typeObj, Mockito.mock(StringWriter.class),true); + } catch (APIException e) { + e.printStackTrace(); + } catch (JAXBException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void testStringifySWOptionsException() { + JAXBDF<JAXBmar> bdfObj = null; + try { + JAXBmar typeObj = new JAXBmar(new Class[] {this.getClass()}); + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + bdfObj = new JAXBDF( envJaxb, new Class[] {this.getClass()}); + bdfObj.jmar = Mockito.mock(JAXBmar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(env).debug(); + StringWriter sw = Mockito.mock(StringWriter.class); + Mockito.doThrow(new JAXBException("test")).when(bdfObj.jmar).marshal(logT, typeObj, sw,true); + bdfObj.stringify(env, typeObj, sw,true); + } catch (APIException e) { + assertTrue(e.getMessage().contains("test")); + } catch (JAXBException e) { + assertTrue(e.getMessage().contains("test")); + } + } + + @Test + public void testObjectifyEnv() { + JAXBDF<JAXBumar> bdfObj = null; + try { + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + bdfObj = new JAXBDF<JAXBumar>( envJaxb, new Class[] {this.getClass()}); + JAXBumar typeObj = new JAXBumar(new Class[] {this.getClass()}); + bdfObj.jumar = Mockito.mock(JAXBumar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(env).debug(); + Mockito.doReturn(this.getClass()).when(bdfObj.jumar).unmarshal(logT, Mockito.mock(StringReader.class)); + + bdfObj.objectify(env, Mockito.mock(StringReader.class)); + } catch (APIException e) { + assertTrue(e.getMessage().contains("test")); + } catch (JAXBException e) { + assertTrue(e.getMessage().contains("test")); + } + + } + @Test + public void testObjectifyEnvException() { + JAXBDF<JAXBumar> bdfObj = null; + try { + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + bdfObj = new JAXBDF<JAXBumar>( envJaxb, new Class[] {this.getClass()}); + JAXBumar typeObj = new JAXBumar(new Class[] {this.getClass()}); + bdfObj.jumar = Mockito.mock(JAXBumar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(env).debug(); + StringReader sr = Mockito.mock(StringReader.class); + Mockito.doThrow(new JAXBException("test")).when(bdfObj.jumar).unmarshal(logT, sr); + + bdfObj.objectify(env, sr); + } catch (APIException e) { + assertTrue(e.getMessage().contains("test")); + } catch (JAXBException e) { + assertTrue(e.getMessage().contains("test")); + } + + } + + @Test + public void testObjectifyRdr() { + JAXBDF<JAXBumar> bdfObj = null; + try { + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + bdfObj = new JAXBDF<JAXBumar>( envJaxb, new Class[] {this.getClass()}); + JAXBumar typeObj = new JAXBumar(new Class[] {this.getClass()}); + bdfObj.jumar = Mockito.mock(JAXBumar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(env).debug(); + Mockito.doReturn(this.getClass()).when(bdfObj.jumar).unmarshal(logT, Mockito.mock(StringReader.class)); + + bdfObj.objectify( Mockito.mock(StringReader.class)); + } catch (APIException e) { + assertTrue(e.getMessage().contains("test")); + } catch (JAXBException e) { + assertTrue(e.getMessage().contains("test")); + } + + } + @Test + public void testObjectifyRdrException() { + JAXBDF<JAXBumar> bdfObj = null; + try { + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + bdfObj = new JAXBDF<JAXBumar>( envJaxb, new Class[] {this.getClass()}); + JAXBumar typeObj = new JAXBumar(new Class[] {this.getClass()}); + bdfObj.jumar = Mockito.mock(JAXBumar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(envJaxb).debug(); + StringReader sr = Mockito.mock(StringReader.class); + Mockito.doThrow(new JAXBException("test")).when(bdfObj.jumar).unmarshal(logT, sr); + + bdfObj.objectify(sr); + } catch (APIException e) { + assertTrue(e.getMessage().contains("test")); + } catch (JAXBException e) { + assertTrue(e.getMessage().contains("test")); + } + + } + + @Test + public void testObjectifyEnvIS() { + JAXBDF<JAXBumar> bdfObj = null; + try { + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + bdfObj = new JAXBDF<JAXBumar>( envJaxb, new Class[] {this.getClass()}); + JAXBumar typeObj = new JAXBumar(new Class[] {this.getClass()}); + bdfObj.jumar = Mockito.mock(JAXBumar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(env).debug(); + Mockito.doReturn(this.getClass()).when(bdfObj.jumar).unmarshal(logT, Mockito.mock(InputStream.class)); + + bdfObj.objectify(env, Mockito.mock(InputStream.class)); + } catch (APIException e) { + assertTrue(e.getMessage().contains("test")); + } catch (JAXBException e) { + assertTrue(e.getMessage().contains("test")); + } + + } + @Test + public void testObjectifyEnvISException() { + JAXBDF<JAXBumar> bdfObj = null; + try { + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + bdfObj = new JAXBDF<JAXBumar>( envJaxb, new Class[] {this.getClass()}); + JAXBumar typeObj = new JAXBumar(new Class[] {this.getClass()}); + bdfObj.jumar = Mockito.mock(JAXBumar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(env).debug(); + InputStream sr = Mockito.mock(InputStream.class); + Mockito.doThrow(new JAXBException("test")).when(bdfObj.jumar).unmarshal(logT, sr); + + bdfObj.objectify(env, sr); + } catch (APIException e) { + assertTrue(e.getMessage().contains("test")); + } catch (JAXBException e) { + assertTrue(e.getMessage().contains("test")); + } + + } + + @Test + public void testObjectifyIs() { + JAXBDF<JAXBumar> bdfObj = null; + try { + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + bdfObj = new JAXBDF<JAXBumar>( envJaxb, new Class[] {this.getClass()}); + JAXBumar typeObj = new JAXBumar(new Class[] {this.getClass()}); + bdfObj.jumar = Mockito.mock(JAXBumar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(env).debug(); + Mockito.doReturn(this.getClass()).when(bdfObj.jumar).unmarshal(logT, Mockito.mock(InputStream.class)); + + bdfObj.objectify( Mockito.mock(InputStream.class)); + } catch (APIException e) { + assertTrue(e.getMessage().contains("test")); + } catch (JAXBException e) { + assertTrue(e.getMessage().contains("test")); + } + + } + @Test + public void testObjectifyIsException() { + JAXBDF<JAXBumar> bdfObj = null; + try { + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + bdfObj = new JAXBDF<JAXBumar>( envJaxb, new Class[] {this.getClass()}); + JAXBumar typeObj = new JAXBumar(new Class[] {this.getClass()}); + bdfObj.jumar = Mockito.mock(JAXBumar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(envJaxb).debug(); + InputStream sr = Mockito.mock(InputStream.class); + Mockito.doThrow(new JAXBException("test")).when(bdfObj.jumar).unmarshal(logT, sr); + + bdfObj.objectify(sr); + } catch (APIException e) { + assertTrue(e.getMessage().contains("test")); + } catch (JAXBException e) { + assertTrue(e.getMessage().contains("test")); + } + + } + + @Test + public void testObjectifyEnvStr() { + JAXBDF<JAXBumar> bdfObj = null; + try { + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + bdfObj = new JAXBDF<JAXBumar>( envJaxb, new Class[] {this.getClass()}); + JAXBumar typeObj = new JAXBumar(new Class[] {this.getClass()}); + bdfObj.jumar = Mockito.mock(JAXBumar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(env).debug(); + Mockito.doReturn(this.getClass()).when(bdfObj.jumar).unmarshal(logT, "test"); + + bdfObj.objectify(env, "test"); + } catch (APIException e) { + assertTrue(e.getMessage().contains("test")); + } catch (JAXBException e) { + assertTrue(e.getMessage().contains("test")); + } + + } + @Test + public void testObjectifyEnvStrException() { + JAXBDF<JAXBumar> bdfObj = null; + try { + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + bdfObj = new JAXBDF<JAXBumar>( envJaxb, new Class[] {this.getClass()}); + JAXBumar typeObj = new JAXBumar(new Class[] {this.getClass()}); + bdfObj.jumar = Mockito.mock(JAXBumar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(env).debug(); + InputStream sr = Mockito.mock(InputStream.class); + Mockito.doThrow(new JAXBException("test")).when(bdfObj.jumar).unmarshal(logT, "test"); + + bdfObj.objectify(env, "test"); + } catch (APIException e) { + assertTrue(e.getMessage().contains("test")); + } catch (JAXBException e) { + assertTrue(e.getMessage().contains("test")); + } + + } + + @Test + public void testObjectifyStr() { + JAXBDF<JAXBumar> bdfObj = null; + try { + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + bdfObj = new JAXBDF<JAXBumar>( envJaxb, new Class[] {this.getClass()}); + JAXBumar typeObj = new JAXBumar(new Class[] {this.getClass()}); + bdfObj.jumar = Mockito.mock(JAXBumar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(env).debug(); + Mockito.doReturn(this.getClass()).when(bdfObj.jumar).unmarshal(logT, "test"); + + bdfObj.objectify( "test"); + } catch (APIException e) { + assertTrue(e.getMessage().contains("test")); + } catch (JAXBException e) { + assertTrue(e.getMessage().contains("test")); + } + + } + @Test + public void testObjectifyStrException() { + JAXBDF<JAXBumar> bdfObj = null; + try { + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + bdfObj = new JAXBDF<JAXBumar>( envJaxb, new Class[] {this.getClass()}); + JAXBumar typeObj = new JAXBumar(new Class[] {this.getClass()}); + bdfObj.jumar = Mockito.mock(JAXBumar.class); + LogTarget logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(envJaxb).debug(); + InputStream sr = Mockito.mock(InputStream.class); + Mockito.doThrow(new JAXBException("test")).when(bdfObj.jumar).unmarshal(logT, "test"); + + bdfObj.objectify("test"); + } catch (APIException e) { + assertTrue(e.getMessage().contains("test")); + } catch (JAXBException e) { + assertTrue(e.getMessage().contains("test")); + } + + } + + @Test + public void testTypeClass() { + JAXBDF<JAXBumar> bdfObj = null; + try { + EnvJAXB envJaxb = Mockito.mock(EnvJAXB.class); + bdfObj = new JAXBDF<JAXBumar>( envJaxb, new Class[] {this.getClass()}); + + Object obj = bdfObj.getTypeClass(); + assertFalse(obj instanceof JU_JAXBDF); + } catch (APIException e) { + assertTrue(e.getMessage().contains("test")); + } + + } +} |