2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.aai.serialization.queryformats.utils;
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.Mockito.when;
27 import java.io.UnsupportedEncodingException;
29 import java.net.URISyntaxException;
31 import org.apache.tinkerpop.gremlin.structure.Vertex;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.mockito.Mock;
35 import org.mockito.MockitoAnnotations;
36 import org.onap.aai.AAISetup;
37 import org.onap.aai.exceptions.AAIException;
38 import org.onap.aai.serialization.db.DBSerializer;
39 import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexException;
40 import org.onap.aai.setup.SchemaVersion;
42 public class UrlBuilderTest extends AAISetup {
45 private DBSerializer serializer;
49 private static final String uri = "/test/uri";
50 private static final Object vId = Long.valueOf(123);
51 private static final String protocolAndHost = "http://localhost/aai/";
54 public void before() throws UnsupportedEncodingException, URISyntaxException {
55 MockitoAnnotations.initMocks(this);
56 when(serializer.getURIForVertex(any(Vertex.class))).thenReturn(new URI(uri));
57 when(v.id()).thenReturn(vId);
61 public void v11Pathed() throws AAIFormatVertexException, AAIException {
62 SchemaVersion version = new SchemaVersion("v11");
63 UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost, schemaVersions, basePath);
64 String result = builder.pathed(v);
66 assertEquals("has no protocol and host", basePath + "/" + version + uri, result);
71 public void v11Id() throws AAIException {
72 SchemaVersion version = new SchemaVersion("v11");
73 UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost, schemaVersions, basePath);
74 String result = builder.id(v);
76 assertEquals("has no protocol and host", basePath + "/" + version + "/resources/id/" + vId, result);
81 public void beforeV11Pathed() throws AAIFormatVertexException, AAIException {
82 SchemaVersion version = new SchemaVersion("v10");
83 UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost, schemaVersions, basePath);
84 String result = builder.pathed(v);
86 assertEquals("has protocol and host", protocolAndHost + version + uri, result);
91 public void beforeV11Id() throws AAIException {
92 SchemaVersion version = new SchemaVersion("v10");
93 UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost, schemaVersions, basePath);
94 String result = builder.id(v);
96 assertEquals("has protocol and host", protocolAndHost + version + "/resources/id/" + vId, result);