2 * Copyright 2014-2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onosproject.provider.lldp.impl;
19 import static org.junit.Assert.*;
20 import static org.onosproject.net.DeviceId.deviceId;
23 import java.io.IOException;
24 import java.net.URISyntaxException;
25 import java.nio.file.Path;
26 import java.nio.file.Paths;
28 import org.junit.Rule;
29 import org.junit.Test;
30 import org.junit.rules.TemporaryFolder;
31 import org.onosproject.net.Device;
33 import com.google.common.collect.ImmutableMap;
34 import com.google.common.collect.ImmutableSet;
35 import com.google.common.io.Resources;
37 public class SuppressionRulesStoreTest {
40 public TemporaryFolder tempFolder = new TemporaryFolder();
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"));
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());
59 public void testRead() throws URISyntaxException, IOException {
60 Path path = Paths.get(Resources.getResource("lldp_suppression.json").toURI());
62 SuppressionRulesStore store = new SuppressionRulesStore(path.toString());
64 SuppressionRules rules = store.read();
66 assertRulesEqual(testData, rules);
70 public void testWrite() throws IOException {
71 File newFile = tempFolder.newFile();
72 SuppressionRulesStore store = new SuppressionRulesStore(newFile);
73 store.write(testData);
75 SuppressionRulesStore reload = new SuppressionRulesStore(newFile);
76 SuppressionRules rules = reload.read();
78 assertRulesEqual(testData, rules);