|
| 1 | +package com.redislabs.redisgraph.impl; |
| 2 | + |
| 3 | +import java.util.Arrays; |
| 4 | +import java.util.HashMap; |
| 5 | +import java.util.IllegalFormatConversionException; |
| 6 | +import java.util.List; |
| 7 | +import java.util.Map; |
| 8 | + |
| 9 | +import org.junit.Assert; |
| 10 | +import org.junit.Rule; |
| 11 | +import org.junit.Test; |
| 12 | +import org.junit.rules.ExpectedException; |
| 13 | + |
| 14 | +public class UtilsTest { |
| 15 | + |
| 16 | + @Test |
| 17 | + public void testPrepareProcedure() { |
| 18 | + |
| 19 | + Assert.assertEquals("CALL prc()", Utils.prepareProcedure("prc", Arrays.asList(new String[]{}), new HashMap<>())); |
| 20 | + |
| 21 | + Assert.assertEquals("CALL prc(\"a\",\"b\")", Utils.prepareProcedure("prc", Arrays.asList(new String[]{"a", "b"}), new HashMap<>())); |
| 22 | + |
| 23 | + Map<String, List<String>> kwargs = new HashMap<>(); |
| 24 | + kwargs.put("y", Arrays.asList(new String[]{"ka", "kb"})); |
| 25 | + Assert.assertEquals("CALL prc(\"a\",\"b\")ka,kb", Utils.prepareProcedure("prc", Arrays.asList(new String[]{"a", "b"}), kwargs)); |
| 26 | + |
| 27 | + Assert.assertEquals("CALL prc()ka,kb", Utils.prepareProcedure("prc", Arrays.asList(new String[]{}), kwargs)); |
| 28 | + } |
| 29 | + |
| 30 | + @Rule |
| 31 | + public ExpectedException exceptionRule = ExpectedException.none(); |
| 32 | + |
| 33 | + |
| 34 | + @Test |
| 35 | + public void prepareQuery() { |
| 36 | + Assert.assertEquals("query %s %d end of query", Utils.prepareQuery("query %s %d end of query")); |
| 37 | + |
| 38 | + Assert.assertEquals("query 'a' 33 end of query", Utils.prepareQuery("query %s %d end of query", "a", 33)); |
| 39 | + |
| 40 | + exceptionRule.expect(IllegalFormatConversionException.class); |
| 41 | + Assert.assertEquals("CAL prc(\"a\",\"b\")ka,kb", Utils.prepareQuery("query %s %d end of query", "a", "b")); |
| 42 | + } |
| 43 | + |
| 44 | +} |
0 commit comments