Update the license for 2017-2018 license
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / serialization / queryformats / utils / UrlBuilderTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.onap.aai.serialization.queryformats.utils;
21
22 import org.apache.tinkerpop.gremlin.structure.Vertex;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.mockito.Mock;
26 import org.mockito.MockitoAnnotations;
27 import org.onap.aai.AAISetup;
28 import org.onap.aai.introspection.Version;
29 import org.onap.aai.serialization.db.DBSerializer;
30 import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexException;
31 import org.onap.aai.util.AAIConstants;
32
33 import java.io.UnsupportedEncodingException;
34 import java.net.URI;
35 import java.net.URISyntaxException;
36
37 import static org.junit.Assert.assertEquals;
38 import static org.mockito.Matchers.any;
39 import static org.mockito.Mockito.when;
40
41 public class UrlBuilderTest extends AAISetup {
42
43         @Mock
44         private DBSerializer serializer;
45         @Mock
46         private Vertex v;
47
48         private static final String uri = "/test/uri";
49         private static final Object vId = new Long(123);
50         private static final String protocolAndHost = "http://localhost/aai/";
51
52         @Before
53         public void before() throws UnsupportedEncodingException, URISyntaxException {
54                 MockitoAnnotations.initMocks(this);
55                 when(serializer.getURIForVertex(any(Vertex.class))).thenReturn(new URI(uri));
56                 when(v.id()).thenReturn(vId);
57         }
58
59         @Test
60         public void v11Pathed() throws UnsupportedEncodingException, URISyntaxException, AAIFormatVertexException {
61                 Version version = Version.v11;
62                 UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost);
63                 String result = builder.pathed(v);
64                 
65                 assertEquals("has no protocol and host", AAIConstants.AAI_APP_ROOT + version + uri, result);
66                 
67         }
68
69         @Test
70         public void v11Id() throws UnsupportedEncodingException, URISyntaxException, AAIFormatVertexException {
71                 Version version = Version.v11;
72                 UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost);
73                 String result = builder.id(v);
74                 
75                 assertEquals("has no protocol and host", AAIConstants.AAI_APP_ROOT + version + "/resources/id/" + vId, result);
76                 
77         }
78         
79         @Test
80         public void beforeV11Pathed() throws UnsupportedEncodingException, URISyntaxException, AAIFormatVertexException {
81                 Version version = Version.v10;
82                 UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost);
83                 String result = builder.pathed(v);
84                 
85                 assertEquals("has protocol and host", protocolAndHost + version + uri, result);
86                 
87         }
88         
89         @Test
90         public void beforeV11Id() throws UnsupportedEncodingException, URISyntaxException, AAIFormatVertexException {
91                 Version version = Version.v10;
92                 UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost);
93                 String result = builder.id(v);
94                 
95                 assertEquals("has protocol and host", protocolAndHost + version + "/resources/id/" + vId, result);
96                 
97         }
98         
99 }