diff options
author | Sai Gandham <sg481n@att.com> | 2018-10-29 10:33:45 -0500 |
---|---|---|
committer | Sai Gandham <sg481n@att.com> | 2018-10-29 10:34:03 -0500 |
commit | 7d6102863c924000d6e1b23f0c232f49e1f611a1 (patch) | |
tree | ce7a54d7210996e6cd9fa3a72d8ac6240db7e709 /auth | |
parent | d87c0e6b78cfe091eb9ee2312d10f7bb41b567db (diff) |
Add more junits for batch & cm
Issue-ID: AAF-111
Change-Id: Id0c5d966fdd19b5f9e6c42448110409bf288fcbf
Signed-off-by: Sai Gandham <sg481n@att.com>
Diffstat (limited to 'auth')
10 files changed, 740 insertions, 115 deletions
diff --git a/auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_CredPrintTest.java b/auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_CredPrintTest.java new file mode 100644 index 00000000..2e6ad09c --- /dev/null +++ b/auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_CredPrintTest.java @@ -0,0 +1,67 @@ +/** + * ============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.actions.test; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.onap.aaf.auth.actions.CredPrint; +import org.onap.aaf.auth.dao.cass.CredDAO; +import org.onap.aaf.auth.dao.cass.CredDAO.Data; +import org.onap.aaf.auth.env.AuthzTrans; +import org.onap.aaf.auth.layer.Result; +import org.onap.aaf.misc.env.LogTarget; + +public class JU_CredPrintTest { + + @Mock + private AuthzTrans trans; + private Data cred; + @Mock + LogTarget target; + + @Before + public void setUp() throws Exception { + initMocks(this); + when(trans.info()).thenReturn(target); + cred = new CredDAO.Data(); + cred.type = CredDAO.BASIC_AUTH; + } + + @Test + public void testCred() { + CredPrint print = new CredPrint("text"); + + Result<Void> result = print.exec(trans, cred, "text"); + + assertEquals(result.status, result.ok().status); + assertEquals(CredPrint.type(CredDAO.BASIC_AUTH), "OLD"); + assertEquals(CredPrint.type(CredDAO.BASIC_AUTH_SHA256), "U/P"); + assertEquals(CredPrint.type(CredDAO.CERT_SHA256_RSA), "Cert"); + assertEquals(CredPrint.type(0), "Unknown"); + } + +} diff --git a/auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_FuturePrintTest.java b/auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_FuturePrintTest.java new file mode 100644 index 00000000..121bf48f --- /dev/null +++ b/auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_FuturePrintTest.java @@ -0,0 +1,61 @@ +/** + * ============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.actions.test; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import java.util.Calendar; +import java.util.UUID; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.onap.aaf.auth.actions.FuturePrint; +import org.onap.aaf.auth.env.AuthzTrans; +import org.onap.aaf.auth.helpers.Future; +import org.onap.aaf.auth.layer.Result; +import org.onap.aaf.misc.env.LogTarget; + +public class JU_FuturePrintTest { + @Mock + private AuthzTrans trans; + @Mock + LogTarget target; + private Future future; + + @Before + public void setUp() throws Exception { + initMocks(this); + future = new Future(new UUID(1l, 1l), "memo", "target", Calendar.getInstance().getTime(), + Calendar.getInstance().getTime(), null); + when(trans.info()).thenReturn(target); + } + + @Test + public void testURFuturePrint() { + FuturePrint print = new FuturePrint("Info Text"); + assertEquals(Result.ok().status, print.exec(trans, future, "text").status); + } + +} diff --git a/auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_URFuturePrintTest.java b/auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_URFuturePrintTest.java new file mode 100644 index 00000000..95406425 --- /dev/null +++ b/auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_URFuturePrintTest.java @@ -0,0 +1,57 @@ +/** + * ============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.actions.test; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import java.util.Calendar; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.onap.aaf.auth.actions.URFuturePrint; +import org.onap.aaf.auth.env.AuthzTrans; +import org.onap.aaf.auth.helpers.UserRole; +import org.onap.aaf.auth.layer.Result; +import org.onap.aaf.misc.env.LogTarget; + +public class JU_URFuturePrintTest { + @Mock + private AuthzTrans trans; + @Mock + LogTarget target; + + @Before + public void setUp() throws Exception { + initMocks(this); + when(trans.info()).thenReturn(target); + } + + @Test + public void testURFuturePrint() { + URFuturePrint print = new URFuturePrint("Info Text"); + UserRole ur = new UserRole("user", "ns", "rname", Calendar.getInstance().getTime()); + assertEquals(Result.ok().status, print.exec(trans, ur, "text").status); + } + +} diff --git a/auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_URPrintTest.java b/auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_URPrintTest.java new file mode 100644 index 00000000..1e99ec66 --- /dev/null +++ b/auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_URPrintTest.java @@ -0,0 +1,58 @@ +/** + * ============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.actions.test; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import java.util.Calendar; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.onap.aaf.auth.actions.URPrint; +import org.onap.aaf.auth.env.AuthzTrans; +import org.onap.aaf.auth.helpers.UserRole; +import org.onap.aaf.auth.layer.Result; +import org.onap.aaf.misc.env.LogTarget; + +public class JU_URPrintTest { + @Mock + private AuthzTrans trans; + @Mock + LogTarget target; + + @Before + public void setUp() throws Exception { + initMocks(this); + when(trans.info()).thenReturn(target); + } + + @Test + public void testURPrint() { + URPrint print = new URPrint("Info Text"); + UserRole ur = new UserRole("user", "ns", "rname", Calendar.getInstance().getTime()); + assertEquals(Result.ok().status, print.exec(trans, ur, "text").status); + } + +} diff --git a/auth/auth-batch/src/test/java/org/onap/aaf/auth/helpers/test/JU_Approval.java b/auth/auth-batch/src/test/java/org/onap/aaf/auth/helpers/test/JU_Approval.java index ab86a648..6020dcc0 100644 --- a/auth/auth-batch/src/test/java/org/onap/aaf/auth/helpers/test/JU_Approval.java +++ b/auth/auth-batch/src/test/java/org/onap/aaf/auth/helpers/test/JU_Approval.java @@ -138,12 +138,6 @@ public class JU_Approval { } @Test - public void testSizeForDeletion() { - approval = new Approval(id, ticket, "approver", date, "user", "memo", "operation", "status", "type", 100l); - Assert.assertEquals(0, approval.sizeForDeletion()); - } - - @Test public void testPendingDelete() { Assert.assertFalse(approval.pendingDelete(approval)); } diff --git a/auth/auth-batch/src/test/java/org/onap/aaf/auth/helpers/test/JU_UserRole.java b/auth/auth-batch/src/test/java/org/onap/aaf/auth/helpers/test/JU_UserRole.java index b6ba7d48..da802e15 100644 --- a/auth/auth-batch/src/test/java/org/onap/aaf/auth/helpers/test/JU_UserRole.java +++ b/auth/auth-batch/src/test/java/org/onap/aaf/auth/helpers/test/JU_UserRole.java @@ -21,126 +21,166 @@ package org.onap.aaf.auth.helpers.test; -import static org.junit.Assert.*; -import org.junit.After; +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Date; +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.actions.URDelete; import org.onap.aaf.auth.dao.cass.UserRoleDAO; import org.onap.aaf.auth.env.AuthzTrans; +import org.onap.aaf.auth.helpers.Creator; import org.onap.aaf.auth.helpers.UserRole; +import org.onap.aaf.auth.helpers.creators.RowCreator; +import org.onap.aaf.misc.env.Env; +import org.onap.aaf.misc.env.LogTarget; +import org.onap.aaf.misc.env.TimeTaken; +import org.onap.aaf.misc.env.Trans; + +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.Session; +import com.datastax.driver.core.SimpleStatement; import junit.framework.Assert; -import static org.mockito.Mockito.*; +public class JU_UserRole { -import java.io.PrintStream; -import java.util.Date; + UserRole userRole; + UserRole userRole1; + Date date; + PrintStream ds; -import org.junit.Test; + @Before + public void setUp() { + date = new Date(); + userRole = new UserRole("user", "ns", "rname", date); + userRole = new UserRole("user", "role", "ns", "rname", date); + } -public class JU_UserRole { - - UserRole userRole; - UserRole userRole1; - Date date; - PrintStream ds; - - @Before - public void setUp() { - date = new Date(); - userRole = new UserRole("user", "ns", "rname", date); - userRole = new UserRole("user", "role", "ns", "rname", date); - } - - @Test - public void testTotalLoaded() { - Assert.assertEquals(0, userRole.totalLoaded()); - } - - @Test - public void testDeleted() { - Assert.assertEquals(0, userRole.deleted()); - } - - @Test - public void testExpunge() { - userRole.expunge(); - } - - @Test - public void testSetDeleteStream() { - userRole.setDeleteStream(ds); - } - - @Test - public void testSetRecoverStream() { - userRole.setRecoverStream(ds); - } - - @Test - public void testUrdd() { - Assert.assertTrue(userRole.urdd() instanceof UserRoleDAO.Data); - } - - @Test - public void testUser() { - Assert.assertEquals("user", userRole.user()); - } - - @Test - public void testRole() { - Assert.assertEquals("role", userRole.role()); - } - - @Test - public void testNs() { - Assert.assertEquals("ns", userRole.ns()); - } - - @Test - public void testRName() { - Assert.assertEquals("rname", userRole.rname()); - } - - @Test - public void testExpires() { - Assert.assertEquals(date, userRole.expires()); - userRole.expires(date); - } - - @Test - public void testToString() { - Assert.assertTrue(userRole.toString() instanceof String); - } - - @Test - public void testGet() { - userRole.get("u", "r"); - } - - @Test - public void testResetLocalData() { - userRole.resetLocalData(); - } - - @Test - public void testSizeForDeletion() { - Assert.assertEquals(0, userRole.sizeForDeletion()); - } - - @Test - public void testPendingDelete() { - Assert.assertFalse(userRole.pendingDelete(userRole)); - } - - @Test - public void testActuateDeletionNow() { - AuthzTrans trans = mock(AuthzTrans.class); - URDelete urd = mock(URDelete.class); - userRole.actuateDeletionNow(trans,urd); - } + @Test + public void testTotalLoaded() { + Assert.assertEquals(0, userRole.totalLoaded()); + } + + @Test + public void testDeleted() { + Assert.assertEquals(0, userRole.deleted()); + } + + @Test + public void testExpunge() { + userRole.expunge(); + } + + @Test + public void testSetDeleteStream() { + userRole.setDeleteStream(ds); + } + + @Test + public void testSetRecoverStream() { + userRole.setRecoverStream(ds); + } + + @Test + public void testUrdd() { + Assert.assertTrue(userRole.urdd() instanceof UserRoleDAO.Data); + } + + @Test + public void testUser() { + Assert.assertEquals("user", userRole.user()); + } + + @Test + public void testRole() { + Assert.assertEquals("role", userRole.role()); + } + + @Test + public void testNs() { + Assert.assertEquals("ns", userRole.ns()); + } + + @Test + public void testRName() { + Assert.assertEquals("rname", userRole.rname()); + } + + @Test + public void testExpires() { + Assert.assertEquals(date, userRole.expires()); + userRole.expires(date); + } + + @Test + public void testToString() { + Assert.assertTrue(userRole.toString() instanceof String); + } + + @Test + public void testGet() { + userRole.get("u", "r"); + } + + @Test + public void testResetLocalData() { + userRole.resetLocalData(); + } + + @Test + public void testSizeForDeletion() { + Assert.assertEquals(0, userRole.sizeForDeletion()); + } + + @Test + public void testPendingDelete() { + Assert.assertFalse(userRole.pendingDelete(userRole)); + } + + @Test + public void testActuateDeletionNow() { + AuthzTrans trans = mock(AuthzTrans.class); + URDelete urd = mock(URDelete.class); + userRole.actuateDeletionNow(trans, urd); + } + + @Test + public void testV2() { + UserRole.v2_0_11.create(RowCreator.getRow()); + assertEquals("select user,role,ns,rname,expires from authz.user_role", UserRole.v2_0_11.select()); + } + + @Test + public void testLoad() { + Creator<UserRole> creator = mock(Creator.class); + Trans trans = mock(Trans.class); + Session session = mock(Session.class); + LogTarget target = mock(LogTarget.class); + TimeTaken tt = mock(TimeTaken.class); + ResultSet results = mock(ResultSet.class); + + List<Row> rows = new ArrayList<Row>(); + + when(trans.info()).thenReturn(target); + when(trans.start("Read UserRoles", Env.REMOTE)).thenReturn(tt); + when(trans.start("Load UserRole", Env.SUB)).thenReturn(tt); + when(session.execute(any(SimpleStatement.class))).thenReturn(results); + when(results.iterator()).thenReturn(rows.iterator()); + + List<Row> list = new ArrayList<Row>(); + list.add(RowCreator.getRow()); + list.add(RowCreator.getRow()); + + UserRole.load(trans, session, creator); + } } diff --git a/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/ca/JU_X509ChainTest.java b/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/ca/JU_X509ChainTest.java new file mode 100644 index 00000000..06ea9e6e --- /dev/null +++ b/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/ca/JU_X509ChainTest.java @@ -0,0 +1,72 @@ +/** + * ============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.cm.ca; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import java.io.IOException; +import java.io.Reader; +import java.security.Principal; +import java.security.cert.Certificate; +import java.security.cert.X509Certificate; +import java.util.ArrayList; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.onap.aaf.cadi.configure.CertException; + +public class JU_X509ChainTest { + + @Mock + X509Certificate x509; + + @Mock + X509ChainWithIssuer orig; + @Mock + Principal subject; + @Mock + Reader reader; + @Mock + X509Certificate cert; + + @Before + public void setUp() throws Exception { + initMocks(this); + // when(subject.get) + // when(x509.getSubjectDN()).thenReturn(subject); + when(cert.getEncoded()).thenReturn("x509".getBytes()); + } + + @Test + public void test() throws IOException, CertException { + Certificate[] certs = { x509 }; + X509andChain x509Chain = new X509andChain(cert, new ArrayList<String>()); + x509Chain.addTrustChainEntry(cert); + + assertNotNull(x509Chain.getX509()); + assertEquals(2, x509Chain.getTrustChain().length); + } + +} diff --git a/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/ca/JU_X509ChainWithIssuerTest.java b/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/ca/JU_X509ChainWithIssuerTest.java new file mode 100644 index 00000000..7b6afce7 --- /dev/null +++ b/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/ca/JU_X509ChainWithIssuerTest.java @@ -0,0 +1,74 @@ +/** + * ============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.cm.ca; + +import static org.junit.Assert.assertNull; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import java.io.IOException; +import java.io.Reader; +import java.security.Principal; +import java.security.cert.Certificate; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.onap.aaf.cadi.configure.CertException; + +public class JU_X509ChainWithIssuerTest { + + @Mock + X509Certificate x509; + + @Mock + X509ChainWithIssuer orig; + @Mock + Principal subject; + @Mock + Reader reader; + + @Before + public void setUp() throws Exception { + initMocks(this); + // when(subject.get) + when(x509.getSubjectDN()).thenReturn(subject); + when(x509.getEncoded()).thenReturn("x509".getBytes()); + } + + @Test + public void test() throws IOException, CertException { + X509ChainWithIssuer x509Chain = new X509ChainWithIssuer(orig, x509); + + assertNull(x509Chain.getIssuerDN()); + Certificate[] certs = { x509 }; + // Certificate cert = ; + x509Chain = new X509ChainWithIssuer(certs); + List<Reader> rdrs = new ArrayList<Reader>(); + rdrs.add(null); + + x509Chain = new X509ChainWithIssuer(rdrs); + } + +} diff --git a/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/data/JU_CertReqTest.java b/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/data/JU_CertReqTest.java new file mode 100644 index 00000000..1ab26531 --- /dev/null +++ b/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/data/JU_CertReqTest.java @@ -0,0 +1,62 @@ +/** + * ============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.cm.data; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.util.ArrayList; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.onap.aaf.auth.cm.ca.CA; +import org.onap.aaf.auth.cm.cert.CSRMeta; +import org.onap.aaf.cadi.configure.CertException; + +public class JU_CertReqTest { + + @Mock + CA ca; + + @Mock + CSRMeta csr; + + @Before + public void setUp() throws Exception { + initMocks(this); + when(ca.newCSRMeta()).thenReturn(csr); + when(csr.cn()).thenReturn("cn123"); + when(csr.mechID()).thenReturn("mechId"); + } + + @Test + public void testCertResp() throws IOException, GeneralSecurityException, CertException { + CertReq req = new CertReq(); + req.certAuthority = ca; + req.fqdns = new ArrayList<String>(); + + assertEquals(csr, req.getCSRMeta()); + } +} diff --git a/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/data/JU_CertRespTest.java b/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/data/JU_CertRespTest.java new file mode 100644 index 00000000..1366e706 --- /dev/null +++ b/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/data/JU_CertRespTest.java @@ -0,0 +1,140 @@ +/** + * ============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.cm.data; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.security.KeyPair; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.cert.X509Certificate; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Answers; +import org.mockito.Mock; +import org.onap.aaf.auth.cm.ca.CA; +import org.onap.aaf.auth.cm.cert.CSRMeta; +import org.onap.aaf.cadi.configure.CertException; +import org.onap.aaf.misc.env.Trans; + +public class JU_CertRespTest { + + @Mock + CSRMeta csrMeta; + + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + Trans trans; + + @Mock + X509Certificate x509; + + @Mock + CA ca; + + @Before + public void setUp() throws Exception { + initMocks(this); + CertDrop drop = new CertDrop(); + CertRenew renew = new CertRenew(); + + PublicKey publicKey = new PublicKey() { + + @Override + public String getFormat() { + // TODO Auto-generated method stub + return null; + } + + @Override + public byte[] getEncoded() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getAlgorithm() { + // TODO Auto-generated method stub + return null; + } + }; + PrivateKey privateKey = new PrivateKey() { + + @Override + public String getFormat() { + // TODO Auto-generated method stub + return null; + } + + @Override + public byte[] getEncoded() { + // TODO Auto-generated method stub + return "privatekey".getBytes(); + } + + @Override + public String getAlgorithm() { + // TODO Auto-generated method stub + return null; + } + }; + KeyPair keypair = new KeyPair(publicKey, privateKey); + + when(csrMeta.keypair(trans)).thenReturn(keypair); + when(csrMeta.challenge()).thenReturn("challenge"); + when(x509.getSubjectDN()).thenReturn(null); + when(x509.getEncoded()).thenReturn("x509Certificate".getBytes()); + + } + + @Test + public void testCertResp() throws IOException, GeneralSecurityException, CertException { + CertResp resp = new CertResp("CERT"); + + assertEquals("CERT", resp.asCertString()); + assertEquals("", resp.challenge()); + + String[] trustChain = { "trustChain" }; + String[] notes = { "notes" }; + + String[] caIssureDNs = { "caIssuer" }; + String[] trustedCAs = { "trustedCAs" }; + + when(ca.getCaIssuerDNs()).thenReturn(caIssureDNs); + when(ca.getEnv()).thenReturn("Env"); + when(ca.getTrustedCAs()).thenReturn(trustedCAs); + + resp = new CertResp(trans, ca, x509, csrMeta, trustChain, notes); + + assertNotNull(resp.privateString()); + assertEquals("challenge", resp.challenge()); + assertEquals("notes", resp.notes()[0]); + assertEquals("trustChain", resp.trustChain()[0]); + assertEquals("caIssuer", resp.caIssuerDNs()[0]); + assertEquals("trustedCAs", resp.trustCAs()[0]); + assertEquals("Env", resp.env()); + } +} |