blob: 0ac31123c03bd17e7cc0c4f7e716154d463272c2 [file] [log] [blame]
Yuta HIGUCHI41289382014-12-19 17:47:12 -08001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Yuta HIGUCHI41289382014-12-19 17:47:12 -08003 *
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
17package org.onosproject.provider.lldp.impl;
18
19import static org.junit.Assert.*;
20import static org.onosproject.net.DeviceId.deviceId;
21
22import java.io.File;
23import java.io.IOException;
24import java.net.URISyntaxException;
25import java.nio.file.Path;
26import java.nio.file.Paths;
27
28import org.junit.Rule;
29import org.junit.Test;
30import org.junit.rules.TemporaryFolder;
31import org.onosproject.net.Device;
32
33import com.google.common.collect.ImmutableMap;
34import com.google.common.collect.ImmutableSet;
35import com.google.common.io.Resources;
36
37public 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}