|
| 1 | +/* |
| 2 | + * Copyright (c) 2017 Otávio Santana and others |
| 3 | + * All rights reserved. This program and the accompanying materials |
| 4 | + * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | + * and Apache License v2.0 which accompanies this distribution. |
| 6 | + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html |
| 7 | + * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. |
| 8 | + * |
| 9 | + * You may elect to redistribute this code under either of these licenses. |
| 10 | + * |
| 11 | + * Contributors: |
| 12 | + * |
| 13 | + * Otavio Santana |
| 14 | + */ |
| 15 | + |
| 16 | +package org.jnosql.diana.redis.key; |
| 17 | + |
| 18 | +import org.jnosql.diana.api.key.BucketManagerFactory; |
| 19 | +import org.junit.After; |
| 20 | +import org.junit.Assert; |
| 21 | +import org.junit.Before; |
| 22 | +import org.junit.Test; |
| 23 | + |
| 24 | +import java.util.Collection; |
| 25 | +import java.util.HashMap; |
| 26 | +import java.util.Map; |
| 27 | +import java.util.Set; |
| 28 | + |
| 29 | +import static org.junit.Assert.assertEquals; |
| 30 | +import static org.junit.Assert.assertNotNull; |
| 31 | +import static org.junit.Assert.assertNull; |
| 32 | +import static org.junit.Assert.assertTrue; |
| 33 | + |
| 34 | + |
| 35 | +public class RedisMapStringTest { |
| 36 | + |
| 37 | + private BucketManagerFactory entityManagerFactory; |
| 38 | + |
| 39 | + |
| 40 | + @Before |
| 41 | + public void init() { |
| 42 | + entityManagerFactory = RedisTestUtils.get(); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void shouldPutAndGetMap() { |
| 47 | + Map<String, String> vertebrates = entityManagerFactory.getMap("vertebrates_string", String.class, String.class); |
| 48 | + assertTrue(vertebrates.isEmpty()); |
| 49 | + |
| 50 | + assertNotNull(vertebrates.put("mammals", "mammals")); |
| 51 | + String species = vertebrates.get("mammals"); |
| 52 | + assertNotNull(species); |
| 53 | + assertEquals("mammals", vertebrates.get("mammals")); |
| 54 | + assertTrue(vertebrates.size() == 1); |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + public void shouldVerifyExist() { |
| 59 | + |
| 60 | + Map<String, String> vertebrates = entityManagerFactory.getMap("vertebrates_string", String.class, String.class); |
| 61 | + vertebrates.put("mammals", "mammals"); |
| 62 | + assertTrue(vertebrates.containsKey("mammals")); |
| 63 | + Assert.assertFalse(vertebrates.containsKey("redfish")); |
| 64 | + |
| 65 | + assertTrue(vertebrates.containsValue("mammals")); |
| 66 | + Assert.assertFalse(vertebrates.containsValue("fishes")); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + public void shouldShowKeyAndValues() { |
| 71 | + Map<String, String> vertebratesMap = new HashMap<>(); |
| 72 | + vertebratesMap.put("mammals", "mammals"); |
| 73 | + vertebratesMap.put("fishes", "fishes"); |
| 74 | + vertebratesMap.put("amphibians", "amphibians"); |
| 75 | + Map<String, String> vertebrates = entityManagerFactory.getMap("vertebrates_string", String.class, String.class); |
| 76 | + vertebrates.putAll(vertebratesMap); |
| 77 | + |
| 78 | + Set<String> keys = vertebrates.keySet(); |
| 79 | + Collection<String> collectionSpecies = vertebrates.values(); |
| 80 | + |
| 81 | + assertTrue(keys.size() == 3); |
| 82 | + assertTrue(collectionSpecies.size() == 3); |
| 83 | + assertNotNull(vertebrates.remove("mammals")); |
| 84 | + assertNull(vertebrates.remove("mammals")); |
| 85 | + assertNull(vertebrates.get("mammals")); |
| 86 | + assertTrue(vertebrates.size() == 2); |
| 87 | + } |
| 88 | + |
| 89 | + @After |
| 90 | + public void dispose() { |
| 91 | + Map<String, String> vertebrates = entityManagerFactory.getMap("vertebrates_string", String.class, String.class); |
| 92 | + vertebrates.clear(); |
| 93 | + } |
| 94 | + |
| 95 | +} |
0 commit comments