Merge "Fix connection when slave role request is unsupported"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / services / sal / NodeConfigServiceImplTest.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.sal;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13 import static org.mockito.Mockito.verify;
14
15 import org.junit.Test;
16 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
17 import org.opendaylight.openflowplugin.impl.services.ServiceMocking;
18 import org.opendaylight.openflowplugin.impl.services.sal.NodeConfigServiceImpl;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigInputBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
23
24 public class NodeConfigServiceImplTest extends ServiceMocking {
25
26     private static final Long DUMMY_XID_VALUE = 150L;
27     private static final SwitchConfigFlag DUMMY_FLAG = SwitchConfigFlag.FRAGNORMAL;
28     private static final String DUMMY_FLAG_STR = "FRAGNORMAL";
29     private static final Integer DUMMY_MISS_SEARCH_LENGTH = 3000;
30     NodeConfigServiceImpl nodeConfigService;
31
32     @Test
33     public void testSetConfig() throws Exception {
34         nodeConfigService = new NodeConfigServiceImpl(mockedRequestContextStack, mockedDeviceContext);
35         nodeConfigService.setConfig(dummyConfigInput());
36         verify(mockedRequestContextStack).createRequestContext();
37     }
38
39     @Test
40     public void testBuildRequest() throws Exception {
41         nodeConfigService = new NodeConfigServiceImpl(mockedRequestContextStack, mockedDeviceContext);
42         final OfHeader request = nodeConfigService.buildRequest(new Xid(DUMMY_XID_VALUE), dummyConfigInput());
43
44         assertTrue(request instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput);
45         org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput setConfigInput
46                 = (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput) request;
47         assertEquals(DUMMY_FLAG,setConfigInput.getFlags());
48         assertEquals(DUMMY_MISS_SEARCH_LENGTH, setConfigInput.getMissSendLen());
49         assertEquals(DUMMY_XID_VALUE, setConfigInput.getXid());
50     }
51
52     private SetConfigInput dummyConfigInput(){
53         SetConfigInputBuilder setConfigInputBuilder = new SetConfigInputBuilder();
54         setConfigInputBuilder.setFlag(DUMMY_FLAG_STR);
55         setConfigInputBuilder.setMissSearchLength(DUMMY_MISS_SEARCH_LENGTH);
56         return setConfigInputBuilder.build();
57     }
58 }