blob: 409f8eb351074ad499ab9e873816a5bf7a538fda [file] [log] [blame]
Ray Milkey39616f32015-05-14 15:43:00 -07001/*
2 * Copyright 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 */
16package org.onosproject.codec.impl;
17
18import org.junit.Test;
19import org.onosproject.core.DefaultGroupId;
20import org.onosproject.net.NetTestTools;
21import org.onosproject.net.flow.DefaultTrafficTreatment;
22import org.onosproject.net.group.DefaultGroup;
23import org.onosproject.net.group.DefaultGroupBucket;
24import org.onosproject.net.group.GroupBucket;
25import org.onosproject.net.group.GroupBuckets;
26import org.onosproject.net.group.GroupDescription;
27
28import com.fasterxml.jackson.databind.node.ObjectNode;
29import com.google.common.collect.ImmutableList;
30
31import static org.hamcrest.MatcherAssert.assertThat;
32import static org.onosproject.codec.impl.GroupJsonMatcher.matchesGroup;
33
34/**
35 * Group codec unit tests.
36 */
37
38public class GroupCodecTest {
39
40 @Test
41 public void codecTest() {
42 GroupBucket bucket1 = DefaultGroupBucket
43 .createSelectGroupBucket(DefaultTrafficTreatment.emptyTreatment());
44 GroupBucket bucket2 = DefaultGroupBucket
45 .createIndirectGroupBucket(DefaultTrafficTreatment.emptyTreatment());
46 GroupBuckets buckets = new GroupBuckets(ImmutableList.of(bucket1, bucket2));
47
48
49 DefaultGroup group = new DefaultGroup(
50 new DefaultGroupId(1),
51 NetTestTools.did("d1"),
52 GroupDescription.Type.INDIRECT,
53 buckets);
54
55 MockCodecContext context = new MockCodecContext();
56 GroupCodec codec = new GroupCodec();
57 ObjectNode groupJson = codec.encode(group, context);
58
59 assertThat(groupJson, matchesGroup(group));
60 }
61}