Merge "Clean up instance checks and casts"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / services / singlelayer / SingleLayerGroupServiceTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowplugin.impl.services.singlelayer;
10
11 import static org.junit.Assert.assertEquals;
12
13 import org.junit.Test;
14 import org.opendaylight.openflowplugin.impl.services.ServiceMocking;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInputBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupMessage;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupModCommand;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
22
23 public class SingleLayerGroupServiceTest extends ServiceMocking {
24     private static final long GROUP_ID = 42;
25     private SingleLayerGroupService<AddGroupOutput> service;
26
27     @Override
28     protected void setup() throws Exception {
29         service = new SingleLayerGroupService<>(mockedRequestContextStack,
30                 mockedDeviceContext, AddGroupOutput.class);
31     }
32
33     @Test
34     public void buildRequest() throws Exception {
35         final AddGroupInput input = new AddGroupInputBuilder()
36                 .setGroupId(new GroupId(GROUP_ID))
37                 .build();
38
39         final OfHeader ofHeader = service.buildRequest(DUMMY_XID, input);
40         assertEquals(GroupMessage.class, ofHeader.getImplementedInterface());
41
42         final GroupMessage result = (GroupMessage) ofHeader;
43
44         assertEquals(GroupModCommand.OFPGCADD, result.getCommand());
45         assertEquals(GROUP_ID, result.getGroupId().getValue().longValue());
46     }
47 }