Eli Mesika has uploaded a new change for review.

Change subject: core: Fix API tests for Events
......................................................................

core: Fix API tests for Events

Fixing the BackendEventsResourceTest based in the changed in
AusitLog.setMessage done in the previous patch.

Change-Id: I5bb02a94c7e8f7f578e79389ae44dde4b25c53f8
Signed-off-by: Eli Mesika <[email protected]>
---
M 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/model/PermitType.java
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendEventsResource.java
M 
backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendEventsResourceTest.java
M 
backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/EventMapper.java
M 
backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/PermitMapper.java
5 files changed, 41 insertions(+), 46 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/23/10523/1

diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/model/PermitType.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/model/PermitType.java
index 0d91ac2..472913a 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/model/PermitType.java
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/model/PermitType.java
@@ -16,7 +16,6 @@
 
 package org.ovirt.engine.api.model;
 
-
 public enum PermitType {
     CREATE_VM,
     DELETE_VM,
@@ -96,7 +95,8 @@
     PORT_MIRRORING,
 
     // Login action group
-    LOGIN;
+    LOGIN,
+    INJECT_EXTERNAL_EVENTS;
 
     public String value() {
         return name().toLowerCase();
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendEventsResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendEventsResource.java
index 6e3756e..4f89522 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendEventsResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendEventsResource.java
@@ -39,7 +39,7 @@
     @Override
     @SingleEntityResource
     public EventResource getEventSubResource(String id) {
-        return new BackendEventResource(id, this);
+        return inject(new BackendEventResource(id, this));
     }
 
     private List<AuditLog> getBackendCollection() {
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendEventsResourceTest.java
 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendEventsResourceTest.java
index dca9d53..67c8c99 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendEventsResourceTest.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendEventsResourceTest.java
@@ -2,13 +2,17 @@
 
 import static org.easymock.EasyMock.expect;
 
+import java.util.Date;
 import java.util.List;
 
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 
 import org.junit.Test;
+import org.ovirt.engine.api.model.Event;
+import org.ovirt.engine.api.model.LogSeverity;
 import org.ovirt.engine.core.common.AuditLogSeverity;
+import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.action.AddExternalEventParameters;
 import org.ovirt.engine.core.common.action.RemoveExternalEventParameters;
 import org.ovirt.engine.core.common.action.VdcActionType;
@@ -17,35 +21,25 @@
 import org.ovirt.engine.core.common.queries.GetAuditLogByIdParameters;
 import org.ovirt.engine.core.common.queries.VdcQueryType;
 
-public class BackendEventsResourceTest extends 
AbstractBackendCollectionResourceTest<org.ovirt.engine.api.model.Event, 
AuditLog, BackendEventsResource> {
+public class BackendEventsResourceTest extends 
AbstractBackendCollectionResourceTest<Event, AuditLog, BackendEventsResource> {
 
-    private static final long[] LOG_IDS = {1};
-    private static final String[] ORIGIN_NAMES = {"plug-in-1"};
-    private static final AuditLogSeverity[] SEVERITIES = 
{AuditLogSeverity.ALERT};
-    private static final int[] CUSTOMER_EVENT_IDS = {1};
-    private static final String[] MESSAGES = {"messsage 1"};
+    private static final long[] LOG_IDS = { 1, 2, 3 };
+    private static final String[] MESSAGES = {"alert1", "alert2", "alert3"};
+    private static final String[] ORIGIN_NAMES = { "plug-in-1", "plug-in-2", 
"plug-in-3" };
+    private static final Integer[] CUSTOMER_EVENT_IDS = { 11, 22, 33 };
 
     public BackendEventsResourceTest() {
         super(new BackendEventsResource(), SearchType.AuditLog, "Events : ");
     }
 
-    static org.ovirt.engine.core.common.businessentities.AuditLog 
setUpEntityExpectations(
-            org.ovirt.engine.core.common.businessentities.AuditLog entity, int 
index) {
-        expect(entity.getaudit_log_id()).andReturn(LOG_IDS[index]).anyTimes();
-        expect(entity.getseverity()).andReturn(SEVERITIES[index]).anyTimes();
-        expect(entity.getmessage()).andReturn(MESSAGES[index]).anyTimes();
-        expect(entity.getOrigin()).andReturn(ORIGIN_NAMES[index]).anyTimes();
-        
expect(entity.getCustomEventId()).andReturn(CUSTOMER_EVENT_IDS[index]).anyTimes();
-        return entity;
-    }
-
     static org.ovirt.engine.api.model.Event getModel(int index) {
         org.ovirt.engine.api.model.Event model = new 
org.ovirt.engine.api.model.Event();
         model.setId(String.valueOf(LOG_IDS[index]));
-        model.setSeverity(SEVERITIES[index].name());
+        model.setSeverity(AuditLogSeverity.ALERT.name());
         model.setDescription(MESSAGES[index]);
         model.setOrigin(ORIGIN_NAMES[index]);
         model.setCustomId(CUSTOMER_EVENT_IDS[index]);
+        model.setFloodRate(30);
         return model;
     }
 
@@ -66,44 +60,39 @@
                                   getEntity(0));
         Response response = collection.add(getModel(0));
         assertEquals(201, response.getStatus());
-        assertTrue(response.getEntity() instanceof AuditLog);
-        verifyModel((AuditLog) response.getEntity(), 0);
+        assertTrue(response.getEntity() instanceof Event);
+        verifyModel((Event) response.getEntity(), 0);
     }
 
-    protected void verifyModel(AuditLog model, int index) {
-        assertNotNull(model.getaudit_log_id());
-        assertNotNull(model.getseverity());
-        assertNotNull(model.getmessage());
-        assertNotNull(model.getOrigin());
-        assertNotNull(model.getCustomEventId());
+    protected void verifyModel(Event model, int index) {
+        assertNotNull(model);
+        assertEquals(model.getId(), String.valueOf(LOG_IDS[index]));
+        assertEquals(model.getSeverity(), LogSeverity.ALERT.value());
+        assertEquals(model.getDescription(), MESSAGES[index]);
+        assertEquals(model.getOrigin(), ORIGIN_NAMES[index]);
+        assertEquals(model.getCustomId(), CUSTOMER_EVENT_IDS[index]);
     }
 
 
     @Test
     public void testRemove() throws Exception {
         setUriInfo(setUpBasicUriExpectations());
-        setUpGetEntityExpectations();
         setUpActionExpectations(VdcActionType.RemoveExternalEvent, 
RemoveExternalEventParameters.class, new String[] {
-                "auditLogId" }, new Object[] {LOG_IDS[0]}, true, true);
+                "Id" }, new Object[] { LOG_IDS[0] }, true, true, false);
+        setUpQueryExpectations("");
         verifyRemove(collection.remove(String.valueOf(LOG_IDS[0])));
     }
 
     protected org.ovirt.engine.core.common.businessentities.AuditLog 
getEntity(int index) {
-        AuditLog auditLog =  new AuditLog();
-        auditLog.setaudit_log_id(LOG_IDS[index]);
-        auditLog.setseverity(SEVERITIES[index]);
-        auditLog.setmessage(MESSAGES[index]);
-        auditLog.setOrigin(ORIGIN_NAMES[index]);
-        auditLog.setCustomEventId(CUSTOMER_EVENT_IDS[index]);
-        return setUpEntityExpectations(auditLog, index);
-    }
-
-    private void setUpGetEntityExpectations() throws Exception {
-        setUpGetEntityExpectations(VdcQueryType.GetAuditLogById,
-                GetAuditLogByIdParameters.class,
-                new String[] { "AuditLogId" },
-                new Object[] { LOG_IDS[0] },
-                new org.ovirt.engine.core.common.businessentities.AuditLog());
+        AuditLog auditLogMock = 
control.createMock(org.ovirt.engine.core.common.businessentities.AuditLog.class);
+        
expect(auditLogMock.getaudit_log_id()).andReturn(LOG_IDS[index]).anyTimes();
+        
expect(auditLogMock.getseverity()).andReturn(AuditLogSeverity.ALERT).anyTimes();
+        
expect(auditLogMock.getmessage()).andReturn(MESSAGES[index]).anyTimes();
+        
expect(auditLogMock.getOrigin()).andReturn(ORIGIN_NAMES[index]).anyTimes();
+        
expect(auditLogMock.getCustomEventId()).andReturn(CUSTOMER_EVENT_IDS[index]).anyTimes();
+        
expect(auditLogMock.getlog_type()).andReturn(AuditLogType.EXTERNAL_ALERT).anyTimes();
+        expect(auditLogMock.getlog_time()).andReturn(new Date()).anyTimes();
+        return auditLogMock;
     }
 
     @Test
diff --git 
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/EventMapper.java
 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/EventMapper.java
index 8e05691..0a7e2d4 100644
--- 
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/EventMapper.java
+++ 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/EventMapper.java
@@ -91,7 +91,9 @@
         auditLog.setseverity(map(event.getSeverity(), null));
         auditLog.setlog_time(event.isSetTime() ? 
event.getTime().toGregorianCalendar().getTime()
                 : new Date((Calendar.getInstance().getTimeInMillis())));
-        auditLog.setmessage(event.getDescription());
+        if (event.getDescription() != null) {
+            auditLog.setmessage(event.getDescription());
+        }
         NGuid guid = (event.isSetUser()) ? new NGuid(event.getUser().getId()) 
: NGuid.Empty;
         if (!guid.equals(NGuid.Empty)) {
             auditLog.setuser_id(guid);
diff --git 
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/PermitMapper.java
 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/PermitMapper.java
index c771205..094b77a 100644
--- 
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/PermitMapper.java
+++ 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/PermitMapper.java
@@ -158,6 +158,8 @@
             return PermitType.PORT_MIRRORING;
         case LOGIN:
             return PermitType.LOGIN;
+        case INJECT_EXTERNAL_EVENTS:
+            return PermitType.INJECT_EXTERNAL_EVENTS;
         default:
             return null;
         }
@@ -278,6 +280,8 @@
             return ActionGroup.PORT_MIRRORING;
         case LOGIN:
             return ActionGroup.LOGIN;
+        case INJECT_EXTERNAL_EVENTS:
+            return ActionGroup.INJECT_EXTERNAL_EVENTS;
         default:
             return null;
         }


--
To view, visit http://gerrit.ovirt.org/10523
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5bb02a94c7e8f7f578e79389ae44dde4b25c53f8
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Eli Mesika <[email protected]>
Gerrit-Reviewer: Ori Liel <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to