Ray Milkey | 39616f3 | 2015-05-14 15:43:00 -0700 | [diff] [blame^] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.codec.impl; |
| 17 | |
| 18 | import org.junit.Test; |
| 19 | import org.onosproject.core.DefaultGroupId; |
| 20 | import org.onosproject.net.NetTestTools; |
| 21 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 22 | import org.onosproject.net.group.DefaultGroup; |
| 23 | import org.onosproject.net.group.DefaultGroupBucket; |
| 24 | import org.onosproject.net.group.GroupBucket; |
| 25 | import org.onosproject.net.group.GroupBuckets; |
| 26 | import org.onosproject.net.group.GroupDescription; |
| 27 | |
| 28 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 29 | import com.google.common.collect.ImmutableList; |
| 30 | |
| 31 | import static org.hamcrest.MatcherAssert.assertThat; |
| 32 | import static org.onosproject.codec.impl.GroupJsonMatcher.matchesGroup; |
| 33 | |
| 34 | /** |
| 35 | * Group codec unit tests. |
| 36 | */ |
| 37 | |
| 38 | public 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 | } |