Make methods static
[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 package org.opendaylight.openflowplugin.impl.services.sal;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
12 import static org.mockito.Mockito.verify;
13
14 import org.junit.Test;
15 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
16 import org.opendaylight.openflowplugin.impl.services.ServiceMocking;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigInputBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
21 import org.opendaylight.yangtools.yang.common.Uint16;
22 import org.opendaylight.yangtools.yang.common.Uint32;
23
24 public class NodeConfigServiceImplTest extends ServiceMocking {
25
26     private static final Uint32 DUMMY_XID_VALUE = Uint32.valueOf(150);
27     private static final SwitchConfigFlag DUMMY_FLAG = SwitchConfigFlag.FRAGNORMAL;
28     private static final String DUMMY_FLAG_STR = "FRAGNORMAL";
29     private static final Uint16 DUMMY_MISS_SEARCH_LENGTH = Uint16.valueOf(3000);
30     NodeConfigServiceImpl nodeConfigService;
31
32     @Test
33     public void testSetConfig() {
34         nodeConfigService = new NodeConfigServiceImpl(mockedRequestContextStack, mockedDeviceContext);
35         nodeConfigService.setConfig(dummyConfigInput());
36         verify(mockedRequestContextStack).createRequestContext();
37     }
38
39     @Test
40     public void testBuildRequest() {
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
45                 .opendaylight.openflow.protocol.rev130731.SetConfigInput);
46         org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput setConfigInput
47                 = (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput) request;
48         assertEquals(DUMMY_FLAG,setConfigInput.getFlags());
49         assertEquals(DUMMY_MISS_SEARCH_LENGTH, setConfigInput.getMissSendLen());
50         assertEquals(DUMMY_XID_VALUE, setConfigInput.getXid());
51     }
52
53     private static SetConfigInput dummyConfigInput() {
54         SetConfigInputBuilder setConfigInputBuilder = new SetConfigInputBuilder();
55         setConfigInputBuilder.setFlag(DUMMY_FLAG_STR);
56         setConfigInputBuilder.setMissSearchLength(DUMMY_MISS_SEARCH_LENGTH);
57         return setConfigInputBuilder.build();
58     }
59 }