0ac31123c03bd17e7cc0c4f7e716154d463272c2
[onosfw.git] /
1 /*
2  * Copyright 2014-2015 Open Networking Laboratory
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a 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
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onosproject.provider.lldp.impl;
18
19 import static org.junit.Assert.*;
20 import static org.onosproject.net.DeviceId.deviceId;
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.net.URISyntaxException;
25 import java.nio.file.Path;
26 import java.nio.file.Paths;
27
28 import org.junit.Rule;
29 import org.junit.Test;
30 import org.junit.rules.TemporaryFolder;
31 import org.onosproject.net.Device;
32
33 import com.google.common.collect.ImmutableMap;
34 import com.google.common.collect.ImmutableSet;
35 import com.google.common.io.Resources;
36
37 public class SuppressionRulesStoreTest {
38
39     @Rule
40     public TemporaryFolder tempFolder = new TemporaryFolder();
41
42     // "lldp_suppression.json"
43     SuppressionRules testData
44         = new SuppressionRules(ImmutableSet.of(deviceId("of:2222000000000000")),
45                                ImmutableSet.of(Device.Type.ROADM),
46                                ImmutableMap.of("no-lldp", SuppressionRules.ANY_VALUE,
47                                                "sendLLDP", "false"));
48
49     private static void assertRulesEqual(SuppressionRules expected, SuppressionRules actual) {
50         assertEquals(expected.getSuppressedDevice(),
51                      actual.getSuppressedDevice());
52         assertEquals(expected.getSuppressedDeviceType(),
53                      actual.getSuppressedDeviceType());
54         assertEquals(expected.getSuppressedAnnotation(),
55                      actual.getSuppressedAnnotation());
56     }
57
58     @Test
59     public void testRead() throws URISyntaxException, IOException {
60         Path path = Paths.get(Resources.getResource("lldp_suppression.json").toURI());
61
62         SuppressionRulesStore store = new SuppressionRulesStore(path.toString());
63
64         SuppressionRules rules = store.read();
65
66         assertRulesEqual(testData, rules);
67     }
68
69     @Test
70     public void testWrite() throws IOException {
71         File newFile = tempFolder.newFile();
72         SuppressionRulesStore store = new SuppressionRulesStore(newFile);
73         store.write(testData);
74
75         SuppressionRulesStore reload = new SuppressionRulesStore(newFile);
76         SuppressionRules rules = reload.read();
77
78         assertRulesEqual(testData, rules);
79     }
80 }