summaryrefslogtreecommitdiffstats
path: root/auth/auth-batch/src
diff options
context:
space:
mode:
authorSai Gandham <sg481n@att.com>2018-10-29 10:33:45 -0500
committerSai Gandham <sg481n@att.com>2018-10-29 10:34:03 -0500
commit7d6102863c924000d6e1b23f0c232f49e1f611a1 (patch)
treece7a54d7210996e6cd9fa3a72d8ac6240db7e709 /auth/auth-batch/src
parentd87c0e6b78cfe091eb9ee2312d10f7bb41b567db (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/auth-batch/src')
-rw-r--r--auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_CredPrintTest.java67
-rw-r--r--auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_FuturePrintTest.java61
-rw-r--r--auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_URFuturePrintTest.java57
-rw-r--r--auth/auth-batch/src/test/java/org/onap/aaf/auth/actions/test/JU_URPrintTest.java58
-rw-r--r--auth/auth-batch/src/test/java/org/onap/aaf/auth/helpers/test/JU_Approval.java6
-rw-r--r--auth/auth-batch/src/test/java/org/onap/aaf/auth/helpers/test/JU_UserRole.java258
6 files changed, 392 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);
+ }
}