|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license |
| 3 | + * agreements. See the NOTICE file distributed with this work for additional information regarding |
| 4 | + * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the |
| 5 | + * "License"); you may not use this file except in compliance with the License. You may obtain a |
| 6 | + * copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software distributed under the License |
| 11 | + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 12 | + * or implied. See the License for the specific language governing permissions and limitations under |
| 13 | + * the License. |
| 14 | + */ |
| 15 | +package org.apache.fluo.api.config; |
| 16 | + |
| 17 | +import org.junit.Assert; |
| 18 | +import org.junit.Test; |
| 19 | + |
| 20 | +/** |
| 21 | + * @since 1.2.0 |
| 22 | + */ |
| 23 | +public class SimpleConfigurationTest { |
| 24 | + |
| 25 | + @Test |
| 26 | + public void testMerge() { |
| 27 | + SimpleConfiguration empty = new SimpleConfiguration(); |
| 28 | + SimpleConfiguration sc1 = new SimpleConfiguration(); |
| 29 | + SimpleConfiguration sc2 = new SimpleConfiguration(); |
| 30 | + SimpleConfiguration sc3 = new SimpleConfiguration(); |
| 31 | + SimpleConfiguration testEmpty = sc1.orElse(sc2).orElse(sc3); |
| 32 | + |
| 33 | + Assert.assertEquals(empty, testEmpty); |
| 34 | + |
| 35 | + sc1.setProperty("set1", "value1"); |
| 36 | + sc1.setProperty("set1", "value2"); |
| 37 | + sc1.setProperty("set3", "value3"); |
| 38 | + sc2.setProperty("set4", "value4"); |
| 39 | + sc2.setProperty("set5", "value5"); |
| 40 | + sc2.setProperty("set1", "value6"); // wont include as sc1 already has set1 |
| 41 | + sc3.setProperty("set7", "value7"); |
| 42 | + sc3.setProperty("set5", "value8"); // wont include as sc2 already has set5 |
| 43 | + |
| 44 | + SimpleConfiguration msc = sc1.orElse(sc2).orElse(sc3); |
| 45 | + |
| 46 | + SimpleConfiguration expected = new SimpleConfiguration(); |
| 47 | + expected.setProperty("set1", "value2"); |
| 48 | + expected.setProperty("set3", "value3"); |
| 49 | + expected.setProperty("set4", "value4"); |
| 50 | + expected.setProperty("set5", "value5"); |
| 51 | + expected.setProperty("set7", "value7"); |
| 52 | + |
| 53 | + SimpleConfiguration expNoOrder = new SimpleConfiguration(); |
| 54 | + expNoOrder.setProperty("set7", "value7"); |
| 55 | + expNoOrder.setProperty("set4", "value4"); |
| 56 | + expNoOrder.setProperty("set5", "value5"); |
| 57 | + expNoOrder.setProperty("set1", "value2"); |
| 58 | + expNoOrder.setProperty("set3", "value3"); |
| 59 | + |
| 60 | + SimpleConfiguration diff = new SimpleConfiguration(); |
| 61 | + diff.setProperty("set7", "value7"); |
| 62 | + diff.setProperty("set4", "value11"); |
| 63 | + diff.setProperty("set5", "value12"); |
| 64 | + diff.setProperty("set1", "value13"); |
| 65 | + diff.setProperty("set3", "value14"); |
| 66 | + |
| 67 | + SimpleConfiguration sc4 = sc3.orElse(sc1).orElse(sc2); |
| 68 | + SimpleConfiguration noChange = new SimpleConfiguration(sc4); |
| 69 | + sc3.setProperty("set25", "value25"); |
| 70 | + sc1.setProperty("set26", "value26"); |
| 71 | + sc2.setProperty("set27", "value27"); |
| 72 | + |
| 73 | + Assert.assertEquals(noChange, sc4); |
| 74 | + |
| 75 | + Assert.assertEquals(expected, msc); |
| 76 | + Assert.assertEquals(expNoOrder, msc); |
| 77 | + Assert.assertNotEquals(diff, msc); |
| 78 | + |
| 79 | + Assert.assertNotEquals(expected, sc1); |
| 80 | + Assert.assertNotEquals(expNoOrder, sc1); |
| 81 | + |
| 82 | + Assert.assertNotEquals(expected, sc2); |
| 83 | + Assert.assertNotEquals(expected, sc3); |
| 84 | + |
| 85 | + Assert.assertNotEquals(expNoOrder, sc2); |
| 86 | + Assert.assertNotEquals(expNoOrder, sc3); |
| 87 | + |
| 88 | + Assert.assertNotEquals(expNoOrder.toString(), msc.toString()); |
| 89 | + } |
| 90 | +} |
0 commit comments