2 * Copyright (c) 2018 ZTE Corporation and others. All rights reserved.
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
8 package org.opendaylight.controller.sal.rest.doc.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.mock;
12 import static org.mockito.Mockito.when;
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.netconf.sal.rest.doc.impl.AllModulesDocGenerator;
24 import org.opendaylight.netconf.sal.rest.doc.impl.ApiDocGeneratorDraftO2;
25 import org.opendaylight.netconf.sal.rest.doc.impl.ApiDocGeneratorRFC8040;
26 import org.opendaylight.netconf.sal.rest.doc.impl.ApiDocServiceImpl;
27 import org.opendaylight.netconf.sal.rest.doc.impl.MountPointSwaggerGeneratorDraft02;
28 import org.opendaylight.netconf.sal.rest.doc.impl.MountPointSwaggerGeneratorRFC8040;
29 import org.opendaylight.yangtools.yang.common.QName;
30 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
32 public final class ApiDocServiceImplTest extends AbstractApiDocTest {
33 private static final String HTTP_URL = "http://localhost/path";
34 private static final YangInstanceIdentifier INSTANCE_ID = YangInstanceIdentifier.builder()
35 .node(QName.create("", "nodes"))
36 .node(QName.create("", "node"))
37 .nodeWithKey(QName.create("", "node"), QName.create("", "id"), "123").build();
39 private ApiDocService apiDocService;
42 public void before() {
43 final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
44 when(mountPoint.getService(DOMSchemaService.class)).thenReturn(Optional.of(SCHEMA_SERVICE));
46 final DOMMountPointService service = mock(DOMMountPointService.class);
47 when(service.getMountPoint(INSTANCE_ID)).thenReturn(Optional.of(mountPoint));
48 final MountPointSwaggerGeneratorDraft02 mountPointDraft02 =
49 new MountPointSwaggerGeneratorDraft02(SCHEMA_SERVICE, service);
50 final MountPointSwaggerGeneratorRFC8040 mountPointRFC8040 =
51 new MountPointSwaggerGeneratorRFC8040(SCHEMA_SERVICE, service);
52 final ApiDocGeneratorDraftO2 apiDocGeneratorDraftO2 = new ApiDocGeneratorDraftO2(SCHEMA_SERVICE);
53 final ApiDocGeneratorRFC8040 apiDocGeneratorRFC8040 = new ApiDocGeneratorRFC8040(SCHEMA_SERVICE);
54 mountPointDraft02.getMountPointSwagger().onMountPointCreated(INSTANCE_ID);
55 final AllModulesDocGenerator allModulesDocGenerator = new AllModulesDocGenerator(apiDocGeneratorDraftO2,
56 apiDocGeneratorRFC8040);
57 apiDocService = new ApiDocServiceImpl(mountPointDraft02, mountPointRFC8040, apiDocGeneratorDraftO2,
58 apiDocGeneratorRFC8040, allModulesDocGenerator);
62 public void getListOfMounts() throws Exception {
63 final UriInfo mockInfo = DocGenTestHelper.createMockUriInfo(HTTP_URL);
64 // simulate the behavior of JacksonJaxbJsonProvider
65 final ObjectMapper mapper = new ObjectMapper();
66 final String result = mapper.writer().writeValueAsString(apiDocService.getListOfMounts(mockInfo).getEntity());
67 assertEquals("[{\"instance\":\"/nodes/node/123/\",\"id\":1}]", result);