ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stoa...@apache.org
Subject [1/3] ambari git commit: AMBARI-15804. Audit logging cleanup and tests. (Daniel Gergely via stoader)
Date Tue, 12 Apr 2016 13:00:00 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 7f8da72ff -> af13ef739


http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UpgradeItemEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UpgradeItemEventCreatorTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UpgradeItemEventCreatorTest.java
new file mode 100644
index 0000000..dd4fdc7
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UpgradeItemEventCreatorTest.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.UpdateUpgradeItemRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.UpgradeItemEventCreator;
+import org.apache.ambari.server.controller.internal.UpgradeItemResourceProvider;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.junit.Test;
+
+public class UpgradeItemEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test
+  public void postTest() {
+    UpgradeItemEventCreator creator = new UpgradeItemEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(UpgradeItemResourceProvider.UPGRADE_ITEM_STAGE_ID, "1");
+    properties.put(UpgradeItemResourceProvider.UPGRADE_REQUEST_ID, "9");
+    properties.put(PropertyHelper.getPropertyId("UpgradeItem", "status"), "Status");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.UpgradeItem,
properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Action confirmation
by the user), RequestType(PUT), url(http://example.com:8080/api/v1/test), ResultStatus(200
OK), Stage id(1), Status(Status), Request id(9)";
+
+    Assert.assertTrue("Class mismatch", event instanceof UpdateUpgradeItemRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UserEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UserEventCreatorTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UserEventCreatorTest.java
new file mode 100644
index 0000000..746d87b
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/UserEventCreatorTest.java
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.ActivateUserRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.AdminUserRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.CreateUserRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.DeleteUserRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.UserPasswordChangeRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.UserEventCreator;
+import org.apache.ambari.server.controller.internal.UserResourceProvider;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class UserEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test
+  public void postTest() {
+    UserEventCreator creator = new UserEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(UserResourceProvider.USER_ADMIN_PROPERTY_ID, "false");
+    properties.put(UserResourceProvider.USER_ACTIVE_PROPERTY_ID, "true");
+    properties.put(UserResourceProvider.USER_USERNAME_PROPERTY_ID, "myUser");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.POST, Resource.Type.User,
properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(User creation),
RequestType(POST), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Created
Username(myUser), Active(yes), Administrator(no)";
+
+    Assert.assertTrue("Class mismatch", event instanceof CreateUserRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void deleteTest() {
+    UserEventCreator creator = new UserEventCreator();
+
+    Map<Resource.Type,String> resource = new HashMap<>();
+    resource.put(Resource.Type.User, "userToDelete");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.DELETE, Resource.Type.User,
null, resource);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(User delete),
RequestType(DELETE), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Deleted
Username(userToDelete)";
+
+    Assert.assertTrue("Class mismatch", event instanceof DeleteUserRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void activeTest() {
+    UserEventCreator creator = new UserEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(UserResourceProvider.USER_ACTIVE_PROPERTY_ID, "true");
+    properties.put(UserResourceProvider.USER_USERNAME_PROPERTY_ID, "myUser");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.User,
properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Set user active/inactive),
RequestType(PUT), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Affected
username(myUser), Active(yes)";
+
+    Assert.assertTrue("Class mismatch", event instanceof ActivateUserRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void adminTest() {
+    UserEventCreator creator = new UserEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(UserResourceProvider.USER_ADMIN_PROPERTY_ID, "false");
+    properties.put(UserResourceProvider.USER_USERNAME_PROPERTY_ID, "myUser");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.User,
properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Set user admin),
RequestType(PUT), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Affeted
username(myUser), Administrator(no)";
+
+    Assert.assertTrue("Class mismatch", event instanceof AdminUserRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void passwordChangeTest() {
+    UserEventCreator creator = new UserEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(UserResourceProvider.USER_OLD_PASSWORD_PROPERTY_ID, "oldPassword");
+    properties.put(UserResourceProvider.USER_USERNAME_PROPERTY_ID, "myUser");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.User,
properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(Password change),
RequestType(PUT), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Affected
username(myUser)";
+
+    Assert.assertTrue("Class mismatch", event instanceof UserPasswordChangeRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ValidationIgnoreEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ValidationIgnoreEventCreatorTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ValidationIgnoreEventCreatorTest.java
new file mode 100644
index 0000000..bf7b663
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ValidationIgnoreEventCreatorTest.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.ambari.server.audit.request.creator;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.request.eventcreator.ValidationIgnoreEventCreator;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class ValidationIgnoreEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test(expected = AssertionError.class)
+  public void postTest() {
+    ValidationIgnoreEventCreator creator = new ValidationIgnoreEventCreator();
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.POST, Resource.Type.Validation,
null, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEventCreatorTestHelper.getEvent(creator, request, result);
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ViewInstanceEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ViewInstanceEventCreatorTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ViewInstanceEventCreatorTest.java
new file mode 100644
index 0000000..4369273
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ViewInstanceEventCreatorTest.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.AddViewInstanceRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.ChangeViewInstanceRequestAuditEvent;
+import org.apache.ambari.server.audit.event.request.DeleteViewInstanceRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.ViewInstanceEventCreator;
+import org.apache.ambari.server.controller.internal.ViewInstanceResourceProvider;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class ViewInstanceEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test
+  public void postTest() {
+    ViewInstanceEventCreator creator = new ViewInstanceEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(ViewInstanceResourceProvider.VIEW_NAME_PROPERTY_ID, "MyView");
+    properties.put(ViewInstanceResourceProvider.VIEW_VERSION_PROPERTY_ID, "1.9");
+    properties.put(ViewInstanceResourceProvider.INSTANCE_NAME_PROPERTY_ID, "MyViewInstance");
+    properties.put(ViewInstanceResourceProvider.LABEL_PROPERTY_ID, "MyViewLabel");
+    properties.put(ViewInstanceResourceProvider.DESCRIPTION_PROPERTY_ID, "Test view");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.POST, Resource.Type.ViewInstance,
properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(View addition),
RequestType(POST), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Type(MyView),
Version(1.9), Name(MyViewInstance), Display name(MyViewLabel), Description(Test view)";
+
+    Assert.assertTrue("Class mismatch", event instanceof AddViewInstanceRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void putTest() {
+    ViewInstanceEventCreator creator = new ViewInstanceEventCreator();
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(ViewInstanceResourceProvider.VIEW_NAME_PROPERTY_ID, "MyView");
+    properties.put(ViewInstanceResourceProvider.VIEW_VERSION_PROPERTY_ID, "1.9");
+    properties.put(ViewInstanceResourceProvider.INSTANCE_NAME_PROPERTY_ID, "MyViewInstance");
+    properties.put(ViewInstanceResourceProvider.LABEL_PROPERTY_ID, "MyViewLabel");
+    properties.put(ViewInstanceResourceProvider.DESCRIPTION_PROPERTY_ID, "Test view");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.ViewInstance,
properties, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(View change),
RequestType(PUT), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Type(MyView),
Version(1.9), Name(MyViewInstance), Display name(MyViewLabel), Description(Test view)";
+
+    Assert.assertTrue("Class mismatch", event instanceof ChangeViewInstanceRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+  @Test
+  public void deleteTest() {
+    ViewInstanceEventCreator creator = new ViewInstanceEventCreator();
+
+    Map<Resource.Type,String> resource = new HashMap<>();
+    resource.put(Resource.Type.View, "MyView");
+    resource.put(Resource.Type.ViewVersion, "1.2");
+    resource.put(Resource.Type.ViewInstance, "MyViewInstance");
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.DELETE, Resource.Type.ViewInstance,
null, resource);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(View deletion),
RequestType(DELETE), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK), Type(MyView),
Version(1.2), Name(MyViewInstance)";
+
+    Assert.assertTrue("Class mismatch", event instanceof DeleteViewInstanceRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/af13ef73/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ViewPrivilegeEventCreatorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ViewPrivilegeEventCreatorTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ViewPrivilegeEventCreatorTest.java
new file mode 100644
index 0000000..ab2b068
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/audit/request/creator/ViewPrivilegeEventCreatorTest.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.ambari.server.audit.request.creator;
+
+import junit.framework.Assert;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.api.services.NamedPropertySet;
+import org.apache.ambari.server.api.services.Request;
+import org.apache.ambari.server.api.services.Result;
+import org.apache.ambari.server.api.services.ResultStatus;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.request.ViewPrivilegeChangeRequestAuditEvent;
+import org.apache.ambari.server.audit.request.eventcreator.ViewPrivilegeEventCreator;
+import org.apache.ambari.server.controller.internal.ViewPrivilegeResourceProvider;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+public class ViewPrivilegeEventCreatorTest extends AuditEventCreatorTestBase{
+
+  @Test
+  public void putTest() {
+    ViewPrivilegeEventCreator creator = new ViewPrivilegeEventCreator();
+
+    Map<String,Object> props = new HashMap<>();
+    props.put(ViewPrivilegeResourceProvider.PRIVILEGE_VIEW_NAME_PROPERTY_ID, "MyView");
+    props.put(ViewPrivilegeResourceProvider.PRIVILEGE_VIEW_VERSION_PROPERTY_ID, "MyView");
+    props.put(ViewPrivilegeResourceProvider.PRIVILEGE_INSTANCE_NAME_PROPERTY_ID, "MyView");
+
+    Map<String,Object> properties = new HashMap<>();
+    properties.put(ViewPrivilegeResourceProvider.PRINCIPAL_TYPE_PROPERTY_ID, "USER");
+    properties.put(ViewPrivilegeResourceProvider.PERMISSION_NAME_PROPERTY_ID, "Permission1");
+    properties.put(ViewPrivilegeResourceProvider.PRINCIPAL_NAME_PROPERTY_ID, userName);
+
+    Map<String,Object> properties2 = new HashMap<>();
+    properties2.put(ViewPrivilegeResourceProvider.PRINCIPAL_TYPE_PROPERTY_ID, "USER");
+    properties2.put(ViewPrivilegeResourceProvider.PERMISSION_NAME_PROPERTY_ID, "Permission2");
+    properties2.put(ViewPrivilegeResourceProvider.PRINCIPAL_NAME_PROPERTY_ID, userName +
"2");
+
+    Map<String,Object> properties3 = new HashMap<>();
+    properties3.put(ViewPrivilegeResourceProvider.PRINCIPAL_TYPE_PROPERTY_ID, "GROUP");
+    properties3.put(ViewPrivilegeResourceProvider.PERMISSION_NAME_PROPERTY_ID, "Permission1");
+    properties3.put(ViewPrivilegeResourceProvider.PRINCIPAL_NAME_PROPERTY_ID, "testgroup");
+
+    NamedPropertySet nps = new NamedPropertySet("1",properties);
+    NamedPropertySet nps2 = new NamedPropertySet("2",properties2);
+    NamedPropertySet nps3 = new NamedPropertySet("3",properties3);
+
+    Request request = AuditEventCreatorTestHelper.createRequest(Request.Type.PUT, Resource.Type.ViewPrivilege,
props, null);
+    Result result = AuditEventCreatorTestHelper.createResult(new ResultStatus(ResultStatus.STATUS.OK));
+
+    request.getBody().addPropertySet(nps);
+    request.getBody().addPropertySet(nps2);
+    request.getBody().addPropertySet(nps3);
+
+    AuditEvent event = AuditEventCreatorTestHelper.getEvent(creator, request, result);
+
+    String actual = event.getAuditMessage();
+    String expected = "User(" + userName + "), RemoteIp(1.2.3.4), Operation(View permission
change), RequestType(PUT), url(http://example.com:8080/api/v1/test), ResultStatus(200 OK),
Type(MyView), Version(MyView), Name(MyView), Permissions(\n" +
+      "Permission2: \n" +
+      "  Users: testuser2\n" +
+      "Permission1: \n" +
+      "  Users: testuser\n" +
+      "  Groups: testgroup)";
+
+    Assert.assertTrue("Class mismatch", event instanceof ViewPrivilegeChangeRequestAuditEvent);
+    Assert.assertEquals(expected, actual);
+    Assert.assertTrue(actual.contains(userName));
+  }
+
+
+}


Mime
View raw message