Re-implement logic for security and securitySchemes
[netconf.git] / restconf / restconf-openapi / src / test / java / org / opendaylight / restconf / openapi / DocGenTestHelper.java
1 /*
2  * Copyright (c) 2014 Brocade Communications 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 package org.opendaylight.restconf.openapi;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.mockito.ArgumentMatchers.any;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.when;
15
16 import java.net.URI;
17 import java.util.Map;
18 import javax.ws.rs.core.UriBuilder;
19 import javax.ws.rs.core.UriInfo;
20 import org.mockito.ArgumentCaptor;
21 import org.opendaylight.restconf.openapi.model.Property;
22 import org.opendaylight.restconf.openapi.model.Schema;
23
24 public final class DocGenTestHelper {
25
26     private DocGenTestHelper() {
27         // hidden on purpose
28     }
29
30     public static UriInfo createMockUriInfo(final String urlPrefix) throws Exception {
31         final URI uri = new URI(urlPrefix);
32         final UriBuilder mockBuilder = mock(UriBuilder.class);
33
34         final ArgumentCaptor<String> subStringCapture = ArgumentCaptor.forClass(String.class);
35         when(mockBuilder.path(subStringCapture.capture())).thenReturn(mockBuilder);
36         when(mockBuilder.build()).then(invocation -> URI.create(uri + "/" + subStringCapture.getValue()));
37
38         final UriInfo info = mock(UriInfo.class);
39         when(info.getRequestUriBuilder()).thenReturn(mockBuilder);
40         when(mockBuilder.replaceQuery(any())).thenReturn(mockBuilder);
41         when(info.getBaseUri()).thenReturn(uri);
42
43         return info;
44     }
45
46     /**
47      * Checks whether object {@code mainObject} contains in properties/items key $ref with concrete value.
48      */
49     public static void containsReferences(final Schema mainObject, final String childObject,
50             final String expectedRef) {
51         final Map<String, Property> properties = mainObject.properties();
52         assertNotNull(properties);
53
54         final Property childNode = properties.get(childObject);
55         assertNotNull(childNode);
56
57         //list case
58         String refWrapper = childNode.items() == null ? childNode.ref() : childNode.items().ref();
59         assertEquals(expectedRef, refWrapper);
60     }
61 }