Martin Mucha has uploaded a new change for review.

Change subject: core: added test for missing translations in AuditLogMessages
......................................................................

core: added test for missing translations in AuditLogMessages

added test for missing translations in AuditLogMessages for keys from
AuditLogType

Change-Id: I3f0c95797ef5ff646ec6d5f6d1229d7fc7bf92d0
Signed-off-by: Martin Mucha <mmu...@redhat.com>
---
A 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirectorTest.java
1 file changed, 162 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/12/30012/1

diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirectorTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirectorTest.java
new file mode 100644
index 0000000..d911be0
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirectorTest.java
@@ -0,0 +1,162 @@
+package org.ovirt.engine.core.dal.dbbroker.auditloghandling;
+
+import static org.mockito.Mockito.RETURNS_DEFAULTS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.ResourceBundle;
+
+import org.hamcrest.CoreMatchers;
+import org.junit.Assert;
+<<<<<<< HEAD
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ErrorCollector;
+=======
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ErrorCollector;
+import org.ovirt.engine.core.common.AuditLogType;
+>>>>>>> 4d424bf... core: added test for missing translations in 
AuditLogMessages
+
+public class AuditLogDirectorTest {
+
+    @Rule
+    public ErrorCollector errorCollector = new ErrorCollector();
+<<<<<<< HEAD
+    private AuditLogDirector auditLogDirector;
+
+    @Before
+    public void setUp() throws Exception {
+        auditLogDirector = new AuditLogDirector();
+    }
+
+=======
+
+//
+//    @Mock
+//    DbFacade dbFacade;
+//    @Mock
+//    AuditLogDAO auditLogDao;
+//
+//    @Before
+//    public void initMocks() {
+//        initAuditLogDirectorMock();
+//        initDbFacadeMock();
+//    }
+//
+//    private void initDbFacadeMock() {
+//        when(dbFacade.getAuditLogDAO()).thenReturn(auditLogDao);
+//    }
+//
+//    private void initAuditLogDirectorMock() {
+//        PowerMockito.spy(AuditLogDirector.class);
+//        
PowerMockito.when(AuditLogDirector.getDbFacadeInstance()).thenReturn(dbFacade);
+//    }
+//
+//
+//    /**
+//     * The test assures that audit loggable objects with timeout, which were 
created without an explicit log type, with
+//     * a common key parts, except of the log type, are treated 
separately.<br>
+//     * The test invokes two {@Code AuditLogDirector.log()} calls and 
verifies that each call insert an entry into
+//     * the database.<br>
+//     */
+    // @Test
+    // public void testLegalAuditLog() {
+    // AuditLogableBase logableObject1 = new AuditLogableBase();
+    // AuditLogDirector.log(logableObject1, AuditLogType.IRS_DISK_SPACE_LOW);
+    //
+    // AuditLogableBase logableObject2 = new AuditLogableBase();
+    // AuditLogDirector.log(logableObject2, 
AuditLogType.IRS_DISK_SPACE_LOW_ERROR);
+    // Mockito.verify(auditLogDao, 
Mockito.times(2)).save(Mockito.any(AuditLog.class));
+    // }
+//
+//    /**
+//     * The test assures that audit loggable objects with timeout, which were 
created without an explicit log type and
+//     * share the same key are treated in respect to each other by the 
timeout gaps between events.<br>
+//     * The test invokes two {@Code AuditLogDirector.log()} calls and verify 
that only one call inserts an entry
+//     * into the database.
+//     */
+//    @Test
+//    public void testIllegalAuditLog() {
+//        AuditLogableBase logableObject1 = new AuditLogableBase();
+//        AuditLogDirector.log(logableObject1, 
AuditLogType.VDS_SLOW_STORAGE_RESPONSE_TIME);
+//        Mockito.verify(auditLogDao, 
Mockito.times(1)).save(Mockito.any(AuditLog.class));
+//
+//        AuditLogDirector.log(logableObject1, 
AuditLogType.VDS_SLOW_STORAGE_RESPONSE_TIME);
+//        Mockito.verify(auditLogDao, 
Mockito.times(1)).save(Mockito.any(AuditLog.class));
+//    }
+//
+>>>>>>> 4d424bf... core: added test for missing translations in 
AuditLogMessages
+    @Test
+    public void testResolveUnknownVariable() {
+        final String message = "This is my ${Variable}";
+        final String expectedResolved = String.format("This is my %1s", 
AuditLogDirector.UNKNOWN_VARIABLE_VALUE);
+        Map<String, String> values = Collections.emptyMap();
+        String resolvedMessage = auditLogDirector.resolveMessage(message, 
values);
+        Assert.assertEquals(expectedResolved, resolvedMessage);
+    }
+
+    @Test
+    public void testResolveKnownVariable() {
+        final String message = "This is my ${Variable}";
+        final String expectedResolved = "This is my value";
+        Map<String, String> values = Collections.singletonMap("variable", 
"value");
+        String resolvedMessage = auditLogDirector.resolveMessage(message, 
values);
+        Assert.assertEquals(expectedResolved, resolvedMessage);
+    }
+
+    @Test
+    public void testResolveCombinedMessage() {
+        final String message =
+                "${first} equals one, ${second} equals two, '${blank}' equals 
blank and ${nonExist} is unknown";
+        final String expectedResolved =
+                String.format("one equals one, two equals two, ' ' equals 
blank and %1s is unknown",
+                        AuditLogDirector.UNKNOWN_VARIABLE_VALUE);
+        Map<String, String> values = new HashMap<String, String>();
+        values.put("first", "one");
+        values.put("second", "two");
+        values.put("blank", " ");
+        String resolvedMessage = auditLogDirector.resolveMessage(message, 
values);
+        Assert.assertEquals(expectedResolved, resolvedMessage);
+    }
+
+    @Test
+    public void testResolveAuditLogableBase() {
+        final String vdsName = "TestVDS";
+        final String vmName = "TestVM";
+        final String message =
+                "The VM name is ${vmName}, the VDS name is ${vdsName} and the 
template name is ${vmTemplateName}";
+        final String expectedResolved =
+                String.format("The VM name is %1s, the VDS name is %2s and the 
template name is %3s",
+                        vmName,
+                        vdsName,
+                        AuditLogDirector.UNKNOWN_VARIABLE_VALUE);
+
+        AuditLogableBase logable = mock(AuditLogableBase.class, 
RETURNS_DEFAULTS);
+        when(logable.getVdsName()).thenReturn("TestVDS");
+        when(logable.getVmName()).thenReturn("TestVM");
+
+        String resolvedMessage = auditLogDirector.resolveMessage(message, 
logable);
+        Assert.assertEquals(expectedResolved, resolvedMessage);
+    }
+
+    @Test
+    public void testAllAuditLogTypesHaveTranslationInBundle() {
+        final ResourceBundle resourceBundle = 
AuditLogDirector.getResourceBundle();
+
+        for (AuditLogType auditLogType : AuditLogType.values()) {
+            final String key = auditLogType.name();
+            errorCollector.checkThat(
+                    "translation key=\"" + key + "\" is not present in 
resource bundle \"" +
+                            AuditLogDirector.getResourceBundleName() + "\"",
+                    resourceBundle.containsKey(key),
+                    CoreMatchers.is(true)
+            );
+        }
+    }
+}


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3f0c95797ef5ff646ec6d5f6d1229d7fc7bf92d0
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Martin Mucha <mmu...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to