b33beb40553ace5b68c12d6e44b1ef38e77f16d8
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / services / NodeConfigServiceImplTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. 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;
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.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
22 public class NodeConfigServiceImplTest extends ServiceMocking{
23
24     private static final Long DUMMY_XID_VALUE = 150L;
25     private static final SwitchConfigFlag DUMMY_FLAG = SwitchConfigFlag.FRAGNORMAL;
26     private static final String DUMMY_FLAG_STR = "FRAGNORMAL";
27     private static final Integer DUMMY_MISS_SEARCH_LENGTH = 3000;
28     NodeConfigServiceImpl nodeConfigService;
29
30     @Test
31     public void testSetConfig() throws Exception {
32         nodeConfigService = new NodeConfigServiceImpl(mockedRequestContextStack, mockedDeviceContext);
33         nodeConfigService.setConfig(dummyConfigInput());
34         verify(mockedRequestContextStack).createRequestContext();
35     }
36
37     @Test
38     public void testBuildRequest() throws Exception {
39         nodeConfigService = new NodeConfigServiceImpl(mockedRequestContextStack, mockedDeviceContext);
40         final OfHeader request = nodeConfigService.buildRequest(new Xid(DUMMY_XID_VALUE), dummyConfigInput());
41
42         assertTrue(request instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput);
43         org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput setConfigInput
44                 = (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput) request;
45         assertEquals(DUMMY_FLAG,setConfigInput.getFlags());
46         assertEquals(DUMMY_MISS_SEARCH_LENGTH, setConfigInput.getMissSendLen());
47         assertEquals(DUMMY_XID_VALUE, setConfigInput.getXid());
48     }
49
50     private SetConfigInput dummyConfigInput(){
51         SetConfigInputBuilder setConfigInputBuilder = new SetConfigInputBuilder();
52         setConfigInputBuilder.setFlag(DUMMY_FLAG_STR);
53         setConfigInputBuilder.setMissSearchLength(DUMMY_MISS_SEARCH_LENGTH);
54         return setConfigInputBuilder.build();
55     }
56 }