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