Change artifactId in sal-rest-docgen
[netconf.git] / restconf / restconf-openapi / src / test / java / org / opendaylight / netconf / sal / rest / doc / helper / 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.netconf.sal.rest.doc;
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 com.fasterxml.jackson.databind.JsonNode;
17 import java.net.URI;
18 import javax.ws.rs.core.UriBuilder;
19 import javax.ws.rs.core.UriInfo;
20 import org.mockito.ArgumentCaptor;
21
22 public final class DocGenTestHelper {
23
24     private DocGenTestHelper() {
25         // hidden on purpose
26     }
27
28     public static UriInfo createMockUriInfo(final String urlPrefix) throws Exception {
29         final URI uri = new URI(urlPrefix);
30         final UriBuilder mockBuilder = mock(UriBuilder.class);
31
32         final ArgumentCaptor<String> subStringCapture = ArgumentCaptor.forClass(String.class);
33         when(mockBuilder.path(subStringCapture.capture())).thenReturn(mockBuilder);
34         when(mockBuilder.build()).then(invocation -> URI.create(uri + "/" + subStringCapture.getValue()));
35
36         final UriInfo info = mock(UriInfo.class);
37         when(info.getRequestUriBuilder()).thenReturn(mockBuilder);
38         when(mockBuilder.replaceQuery(any())).thenReturn(mockBuilder);
39         when(info.getBaseUri()).thenReturn(uri);
40
41         return info;
42     }
43
44     /**
45      * Checks whether object {@code mainObject} contains in properties/items key $ref with concrete value.
46      */
47     public static void containsReferences(final JsonNode mainObject, final String childObject,
48             final String expectedRef) {
49         final JsonNode properties = mainObject.get("properties");
50         assertNotNull(properties);
51
52         final JsonNode childNode = properties.get(childObject);
53         assertNotNull(childNode);
54
55         //list case
56         JsonNode refWrapper = childNode.get("items");
57         if (refWrapper == null) {
58             //container case
59             refWrapper = childNode;
60         }
61         assertEquals(expectedRef, refWrapper.get("$ref").asText());
62     }
63 }