Remove NormalizedNodeInputOutput and related classes
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / md / sal / binding / impl / BindingDOMMountPointServiceAdapterTest.java
1 /*
2  * Copyright (c) 2019 FRINX 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.controller.md.sal.binding.impl;
9
10 import static org.mockito.ArgumentMatchers.any;
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.mock;
13 import static org.mockito.Mockito.spy;
14
15 import com.google.common.base.Optional;
16 import com.google.common.cache.LoadingCache;
17 import org.gaul.modernizer_maven_annotations.SuppressModernizer;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.mockito.Mock;
21 import org.mockito.MockitoAnnotations;
22 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
23 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
24 import org.opendaylight.mdsal.binding.dom.codec.impl.BindingNormalizedNodeCodecRegistry;
25 import org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy;
26 import org.opendaylight.yangtools.yang.binding.DataObject;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.opendaylight.yangtools.yang.common.QName;
29 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
30
31 @Deprecated
32 public class BindingDOMMountPointServiceAdapterTest {
33
34     @Mock
35     private DOMMountPointService mountService;
36     // Use a real instance of codec, since its getCodecRegistry() method is final and cannot be mocked
37     private BindingToNormalizedNodeCodec codec;
38     @Mock
39     private BindingNormalizedNodeCodecRegistry codecRegistry;
40     @Mock
41     private ClassLoadingStrategy classLoadingStrategy;
42
43     @Before
44     @SuppressModernizer
45     public void setUp() {
46         MockitoAnnotations.initMocks(this);
47         codec = spy(new BindingToNormalizedNodeCodec(classLoadingStrategy, codecRegistry));
48         doReturn(Optional.of(mock(DOMMountPoint.class)))
49                 .when(mountService).getMountPoint(any(YangInstanceIdentifier.class));
50         doReturn(YangInstanceIdentifier.create(new YangInstanceIdentifier.NodeIdentifier(QName.create("(a)b"))))
51                 .when(codec).toYangInstanceIdentifierBlocking(any(InstanceIdentifier.class));
52         doReturn(InstanceIdentifier.create(DataObject.class))
53                 .when(codecRegistry).fromYangInstanceIdentifier(any(YangInstanceIdentifier.class));
54     }
55
56     @Test(timeout = 30 * 1000)
57     public void testCaching() throws Exception {
58         BindingDOMMountPointServiceAdapter baService = new BindingDOMMountPointServiceAdapter(mountService, codec);
59         LoadingCache<DOMMountPoint, BindingMountPointAdapter> cache = baService.bindingMountpoints;
60
61         baService.getMountPoint(InstanceIdentifier.create(DataObject.class));
62
63         while (true) {
64             cache.cleanUp();
65             System.gc();
66             Thread.sleep(100);
67             if (cache.asMap().keySet().size() == 0) {
68                 // Cache has been cleared, the single cache entry was garbage collected
69                 return;
70             }
71         }
72     }
73 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.