Merge "Sonar Fix: ConfigDAO.java"
authorJonathan Gathman <jonathan.gathman@att.com>
Tue, 22 Jan 2019 12:17:06 +0000 (12:17 +0000)
committerGerrit Code Review <gerrit@onap.org>
Tue, 22 Jan 2019 12:17:06 +0000 (12:17 +0000)
auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/actions/Key.java
auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/History.java
auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/Expiring.java
auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/update/NotifyCredExpiring.java
auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/reports/bodies/AbsCredBodyTest.java [new file with mode: 0644]
auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/ns/NS.java
auth/auth-cmd/src/main/java/org/onap/aaf/auth/cmd/perm/Grant.java
auth/auth-core/src/test/java/org/onap/aaf/auth/layer/FacadeImplTest.java [new file with mode: 0644]

index fb43a42..1ee655f 100644 (file)
@@ -3,6 +3,8 @@
  * org.onap.aaf
  * ===========================================================================
  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ *
+ * Modifications Copyright (C) 2019 IBM.
  * ===========================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,6 +23,7 @@
 
 package org.onap.aaf.auth.batch.actions;
 
+@FunctionalInterface
 public interface Key<HELPER> {
     public String key(HELPER H);
 }
index a172738..0a50ae0 100644 (file)
@@ -3,6 +3,8 @@
  * org.onap.aaf
  * ===========================================================================
  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ *
+ * Modifications Copyright (C) 2018 IBM.
  * ===========================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -43,9 +45,60 @@ public class History  {
     public final String subject;
     public final String target;
     public final String user;
-    public final int yr_mon;
+    public final int yrMon;
+
+    public static Creator<History> sansConstruct = new Creator<History> () {
+        @Override
+        public History create(Row row) {
+            return new History(
+                    row.getUUID(0),
+                    row.getString(1),
+                    row.getString(2),
+                    row.getString(3),
+                    row.getString(4),
+                    row.getString(5),
+                    row.getInt(6));
+        }
+
+        @Override
+        public String select() {
+            return "SELECT id, action, memo, subject, target, user, yr_mon from authz.history LIMIT 10000000 ";
+        }
+    };
+
+    public static Creator<History> avecConstruct = new Creator<History> () {
+        private final StringBuilder sb = new StringBuilder();
+
+        @Override
+        public History create(Row row) {
+            ByteBuffer bb = row.getBytes(3);
+            sb.setLength(0);
+
+            if (bb!=null && bb.hasRemaining()) {
+                sb.append("0x");
+                while (bb.hasRemaining()) {
+                    sb.append(String.format("%02x",bb.get()));
+                }
+                bb.flip();
+            }
+            return new History(
+                    row.getUUID(0),
+                    row.getString(1),
+                    row.getString(2),
+                    sb.toString(),
+                    row.getString(4),
+                    row.getString(5),
+                    row.getString(6),
+                    row.getInt(7));
+        }
+
+        @Override
+        public String select() {
+            return "SELECT id, action, memo, reconstruct, subject, target, user, yr_mon from authz.history LIMIT 10000000 ";
+        }
+    };
     
-    public History(UUID id, String action, String memo, String subject, String target, String user, int yr_mon) {
+    public History(UUID id, String action, String memo, String subject, String target, String user, int yrMon) {
         this.id = id;
         this.action = action;
         this.memo = memo;
@@ -53,10 +106,10 @@ public class History  {
         this.subject = subject;
         this.target = target;
         this.user = user;
-        this.yr_mon = yr_mon;
+        this.yrMon = yrMon;
     }
     
-    public History(UUID id, String action, String memo, String reconstruct, String subject, String target, String user, int yr_mon) {
+    public History(UUID id, String action, String memo, String reconstruct, String subject, String target, String user, int yrMon) {
         this.id = id;
         this.action = action;
         this.memo = memo;
@@ -64,7 +117,7 @@ public class History  {
         this.subject = subject;
         this.target = target;
         this.user = user;
-        this.yr_mon = yr_mon;
+        this.yrMon = yrMon;
     }
 
     public static void load(Trans trans, Session session, Creator<History> creator, Loader<History> loader) {
@@ -100,7 +153,7 @@ public class History  {
     public String toString() {
         return String.format("%s %d %s, %s, %s, %s, %s", 
                 id.toString(),
-                yr_mon,
+                yrMon,
                 user,
                 target,
                 action,
@@ -123,56 +176,4 @@ public class History  {
     public boolean equals(Object obj) {
         return id.equals(obj);
     }
-    
-    public static Creator<History> sansConstruct = new Creator<History> () {
-        @Override
-        public History create(Row row) {
-            return new History(
-                    row.getUUID(0),
-                    row.getString(1),
-                    row.getString(2),
-                    row.getString(3),
-                    row.getString(4),
-                    row.getString(5),
-                    row.getInt(6));
-        }
-
-        @Override
-        public String select() {
-            return "SELECT id, action, memo, subject, target, user, yr_mon from authz.history LIMIT 10000000 ";
-        }
-    };
-
-    public static Creator<History> avecConstruct = new Creator<History> () {
-        private final StringBuilder sb = new StringBuilder();
-        
-        @Override
-        public History create(Row row) {
-            ByteBuffer bb = row.getBytes(3);
-            sb.setLength(0);
-            
-            if (bb!=null && bb.hasRemaining()) {
-                sb.append("0x");
-                while (bb.hasRemaining()) {
-                    sb.append(String.format("%02x",bb.get()));
-                }
-                bb.flip();
-            }
-            return new History(
-                    row.getUUID(0),
-                    row.getString(1),
-                    row.getString(2),
-                    sb.toString(),
-                    row.getString(4),
-                    row.getString(5),
-                    row.getString(6),
-                    row.getInt(7));
-        }
-
-        @Override
-        public String select() {
-            return "SELECT id, action, memo, reconstruct, subject, target, user, yr_mon from authz.history LIMIT 10000000 ";
-        }
-    };
-
 }
\ No newline at end of file
index d8eee6d..7ed26ce 100644 (file)
@@ -3,6 +3,8 @@
  * org.onap.aaf
  * ===========================================================================
  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ *
+ * Modifications Copyright (C) 2019 IBM.
  * ===========================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -119,20 +121,17 @@ public class Expiring extends Batch {
 
                        Map<String, Set<UserRole>> owners = new TreeMap<String, Set<UserRole>>();
                        trans.info().log("Process UserRoles");
-                       UserRole.load(trans, session, UserRole.v2_0_11, new Visitor<UserRole>() {
-                               @Override
-                               public void visit(UserRole ur) {
-                                       // Cannot just delete owners, unless there is at least one left. Process later
-                                       if ("owner".equals(ur.rname())) {
-                                               Set<UserRole> urs = owners.get(ur.role());
-                                               if (urs == null) {
-                                                       urs = new HashSet<UserRole>();
-                                                       owners.put(ur.role(), urs);
-                                               }
-                                               urs.add(ur);
-                                       } else {
-                                               writeAnalysis(trans,ur);
+                       UserRole.load(trans, session, UserRole.v2_0_11, ur -> {
+                               // Cannot just delete owners, unless there is at least one left. Process later
+                               if ("owner".equals(ur.rname())) {
+                                       Set<UserRole> urs = owners.get(ur.role());
+                                       if (urs == null) {
+                                               urs = new HashSet<UserRole>();
+                                               owners.put(ur.role(), urs);
                                        }
+                                       urs.add(ur);
+                               } else {
+                                       writeAnalysis(trans,ur);
                                }
                        });
 
index ab7525b..ce00816 100644 (file)
@@ -3,6 +3,8 @@
  * org.onap.aaf
  * ===========================================================================
  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ *
+ * Modifications Copyright (C) 2018 IBM.
  * ===========================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -28,9 +30,7 @@ import java.io.PrintStream;
 import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.Date;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -48,11 +48,9 @@ import org.onap.aaf.auth.batch.helpers.NS;
 import org.onap.aaf.auth.batch.helpers.Notification;
 import org.onap.aaf.auth.batch.helpers.UserRole;
 import org.onap.aaf.auth.batch.helpers.Notification.TYPE;
-import org.onap.aaf.auth.dao.cass.CredDAO;
 import org.onap.aaf.auth.dao.hl.Question;
 import org.onap.aaf.auth.env.AuthzTrans;
 import org.onap.aaf.auth.layer.Result;
-import org.onap.aaf.auth.org.EmailWarnings;
 import org.onap.aaf.auth.org.Organization;
 import org.onap.aaf.auth.org.Organization.Identity;
 import org.onap.aaf.auth.org.OrganizationException;
diff --git a/auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/reports/bodies/AbsCredBodyTest.java b/auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/reports/bodies/AbsCredBodyTest.java
new file mode 100644 (file)
index 0000000..b38344a
--- /dev/null
@@ -0,0 +1,62 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2019 IBM 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.batch.reports.bodies;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.aaf.auth.batch.reports.Notify;
+import org.onap.aaf.auth.env.AuthzTrans;
+
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.*;
+
+public class AbsCredBodyTest {
+
+    @Test
+    public void testUserWithValue() {
+        String testStr = "test";
+        List<String> row = Collections.singletonList(testStr);
+        AbsCredBody absCredBody = new AbsCredBody("") {
+            @Override
+            public String body(AuthzTrans trans, Notify n, String id) {
+                return null;
+            }
+        };
+        Assert.assertEquals(testStr, absCredBody.user(row));
+    }
+
+    @Test
+    public void testUserWithoutValue() {
+        //String testStr = "test";
+        List<String> row = Collections.EMPTY_LIST;
+        AbsCredBody absCredBody = new AbsCredBody("") {
+            @Override
+            public String body(AuthzTrans trans, Notify n, String id) {
+                return null;
+            }
+        };
+        Assert.assertNull(absCredBody.user(row));
+    }
+}
\ No newline at end of file
index 3f601b7..092610c 100644 (file)
@@ -26,7 +26,6 @@ package org.onap.aaf.auth.cmd.ns;
 import org.onap.aaf.auth.cmd.AAFcli;
 import org.onap.aaf.auth.cmd.BaseCmd;
 import org.onap.aaf.auth.cmd.DeprecatedCMD;
-import org.onap.aaf.misc.env.APIException;
 
 public class NS extends BaseCmd<NS> {
 
index dd45fb4..ca958c2 100644 (file)
@@ -3,6 +3,8 @@
  * org.onap.aaf
  * ===========================================================================
  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ *
+ * Modifications Copyright (C) 2018 IBM.
  * ===========================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -41,7 +43,7 @@ import aaf.v2_0.RolePermRequest;
  *
  */
 public class Grant extends Cmd {
-    private final static String[] options = {"grant","ungrant","setTo"};
+    private static final String[] options = {"grant","ungrant","setTo"};
 
     public Grant(Perm parent) {
         super(parent,null,
@@ -74,7 +76,8 @@ public class Grant extends Cmd {
         
                 if (option != 2) {
                     String[] roles = args[idx++].split(",");
-                    String strA,strB;
+                    String strA;
+                    String strB;
                     for (String role : roles) {
                         rpr.setRole(role);
                         if (option==0) {
diff --git a/auth/auth-core/src/test/java/org/onap/aaf/auth/layer/FacadeImplTest.java b/auth/auth-core/src/test/java/org/onap/aaf/auth/layer/FacadeImplTest.java
new file mode 100644 (file)
index 0000000..241622f
--- /dev/null
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aaf
+ * * ===========================================================================
+ * * Copyright © 2019 IBM 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.layer;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.onap.aaf.misc.env.Data.TYPE;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class FacadeImplTest {
+
+    FacadeImpl facade;
+    HttpServletResponse response;
+
+    @Before
+    public void setUp() throws Exception {
+        facade = new FacadeImpl() {
+        };
+        response = mock(HttpServletResponse.class);
+    }
+
+    @Test
+    public void setContentType() {
+        TYPE type = TYPE.JSON;
+        facade.setContentType(response, type);
+        verify(response).setContentType("application/json");
+
+        type = TYPE.XML;
+        facade.setContentType(response, type);
+        verify(response).setContentType("text.xml");
+    }
+
+    @Test
+    public void setCacheControlOff() {
+        facade.setCacheControlOff(response);
+        verify(response).setHeader("Cache-Control", "no-store");
+        verify(response).setHeader("Pragma", "no-cache");
+    }
+}
\ No newline at end of file