Re-implement logic for security and securitySchemes
[netconf.git] / restconf / restconf-openapi / src / test / java / org / opendaylight / restconf / openapi / impl / OpenApiServiceImplTest.java
1 /*
2  * Copyright (c) 2018 ZTE Corporation 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.restconf.openapi.impl;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.mock;
12 import static org.mockito.Mockito.when;
13
14 import java.util.List;
15 import java.util.Optional;
16 import org.junit.Before;
17 import org.junit.BeforeClass;
18 import org.junit.Test;
19 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
20 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
21 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
22 import org.opendaylight.restconf.openapi.DocGenTestHelper;
23 import org.opendaylight.restconf.openapi.api.OpenApiService;
24 import org.opendaylight.restconf.openapi.model.MountPointInstance;
25 import org.opendaylight.yangtools.yang.common.QName;
26 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
27 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
28 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
29
30 public final class OpenApiServiceImplTest {
31     private static final String HTTP_URL = "http://localhost/path";
32     private static final YangInstanceIdentifier INSTANCE_ID = YangInstanceIdentifier.builder()
33             .node(QName.create("", "nodes"))
34             .node(QName.create("", "node"))
35             .nodeWithKey(QName.create("", "node"), QName.create("", "id"), "123").build();
36
37     private static EffectiveModelContext context;
38     private static DOMSchemaService schemaService;
39
40     private OpenApiService openApiService;
41
42     @BeforeClass
43     public static void beforeClass() {
44         schemaService = mock(DOMSchemaService.class);
45         context = YangParserTestUtils.parseYangResourceDirectory("/yang");
46         when(schemaService.getGlobalContext()).thenReturn(context);
47     }
48
49     @Before
50     public void before() {
51         final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
52         when(mountPoint.getService(DOMSchemaService.class)).thenReturn(Optional.of(schemaService));
53
54         final DOMMountPointService service = mock(DOMMountPointService.class);
55         when(service.getMountPoint(INSTANCE_ID)).thenReturn(Optional.of(mountPoint));
56         final MountPointOpenApiGeneratorRFC8040 mountPointRFC8040 =
57                 new MountPointOpenApiGeneratorRFC8040(schemaService, service);
58         final OpenApiGeneratorRFC8040 openApiGeneratorRFC8040 = new OpenApiGeneratorRFC8040(schemaService);
59         mountPointRFC8040.getMountPointOpenApi().onMountPointCreated(INSTANCE_ID);
60         openApiService = new OpenApiServiceImpl(mountPointRFC8040, openApiGeneratorRFC8040);
61     }
62
63     @Test
64     public void getListOfMounts() throws Exception {
65         final var mockInfo = DocGenTestHelper.createMockUriInfo(HTTP_URL);
66         final var entity = ((List<MountPointInstance>) openApiService.getListOfMounts(mockInfo).getEntity());
67         final var instance = entity.get(0);
68         assertEquals("/nodes/node=123/", instance.instance());
69         assertEquals(Long.valueOf(1), instance.id());
70     }
71 }