Rename SwaggerObjectTest
[netconf.git] / restconf / sal-rest-docgen / src / test / java / org / opendaylight / netconf / sal / rest / doc / impl / ApiDocServiceImplTest.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.netconf.sal.rest.doc.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 com.fasterxml.jackson.databind.ObjectMapper;
15 import java.util.Optional;
16 import javax.ws.rs.core.UriInfo;
17 import org.junit.Before;
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.netconf.sal.rest.doc.api.ApiDocService;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
25
26 public final class ApiDocServiceImplTest extends AbstractApiDocTest {
27     private static final String HTTP_URL = "http://localhost/path";
28     private static final YangInstanceIdentifier INSTANCE_ID = YangInstanceIdentifier.builder()
29             .node(QName.create("", "nodes"))
30             .node(QName.create("", "node"))
31             .nodeWithKey(QName.create("", "node"), QName.create("", "id"), "123").build();
32     private static final ObjectMapper MAPPER = new ObjectMapper();
33
34     private ApiDocService apiDocService;
35
36     @Before
37     public void before() {
38         final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
39         when(mountPoint.getService(DOMSchemaService.class)).thenReturn(Optional.of(SCHEMA_SERVICE));
40
41         final DOMMountPointService service = mock(DOMMountPointService.class);
42         when(service.getMountPoint(INSTANCE_ID)).thenReturn(Optional.of(mountPoint));
43         final MountPointOpenApiGeneratorRFC8040 mountPointRFC8040 =
44                 new MountPointOpenApiGeneratorRFC8040(SCHEMA_SERVICE, service);
45         final ApiDocGeneratorRFC8040 apiDocGeneratorRFC8040 = new ApiDocGeneratorRFC8040(SCHEMA_SERVICE);
46         mountPointRFC8040.getMountPointOpenApi().onMountPointCreated(INSTANCE_ID);
47         apiDocService = new ApiDocServiceImpl(mountPointRFC8040, apiDocGeneratorRFC8040);
48     }
49
50     @Test
51     public void getListOfMounts() throws Exception {
52         final UriInfo mockInfo = DocGenTestHelper.createMockUriInfo(HTTP_URL);
53         // simulate the behavior of JacksonJaxbJsonProvider
54         final String result = MAPPER.writer().writeValueAsString(apiDocService.getListOfMounts(mockInfo).getEntity());
55         assertEquals("[{\"instance\":\"/nodes/node=123/\",\"id\":1}]", result);
56     }
57 }