EdgeRules throws descriptive error on invalid rule
[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
23 import org.apache.tinkerpop.gremlin.structure.Vertex;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.mockito.Mock;
27 import org.mockito.MockitoAnnotations;
28 import org.openecomp.aai.AAISetup;
29 import org.openecomp.aai.introspection.Version;
30 import org.openecomp.aai.serialization.db.DBSerializer;
31 import org.openecomp.aai.serialization.queryformats.exceptions.AAIFormatVertexException;
32 import org.openecomp.aai.util.AAIConstants;
33
34 import java.io.UnsupportedEncodingException;
35 import java.net.URI;
36 import java.net.URISyntaxException;
37
38 import static org.junit.Assert.assertEquals;
39 import static org.mockito.Matchers.any;
40 import static org.mockito.Mockito.when;
41
42 public class UrlBuilderTest extends AAISetup {
43
44         @Mock
45         private DBSerializer serializer;
46         @Mock
47         private Vertex v;
48
49         private static final String uri = "/test/uri";
50         private static final Object vId = new Long(123);
51         private static final String protocolAndHost = "http://localhost/aai/";
52
53         @Before
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);
58         }
59
60         @Test
61         public void v11Pathed() throws UnsupportedEncodingException, URISyntaxException, AAIFormatVertexException {
62                 Version version = Version.v11;
63                 UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost);
64                 String result = builder.pathed(v);
65                 
66                 assertEquals("has no protocol and host", AAIConstants.AAI_APP_ROOT + version + uri, result);
67                 
68         }
69
70         @Test
71         public void v11Id() throws UnsupportedEncodingException, URISyntaxException, AAIFormatVertexException {
72                 Version version = Version.v11;
73                 UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost);
74                 String result = builder.id(v);
75                 
76                 assertEquals("has no protocol and host", AAIConstants.AAI_APP_ROOT + version + "/resources/id/" + vId, result);
77                 
78         }
79         
80         @Test
81         public void beforeV11Pathed() throws UnsupportedEncodingException, URISyntaxException, AAIFormatVertexException {
82                 Version version = Version.v10;
83                 UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost);
84                 String result = builder.pathed(v);
85                 
86                 assertEquals("has protocol and host", protocolAndHost + version + uri, result);
87                 
88         }
89         
90         @Test
91         public void beforeV11Id() throws UnsupportedEncodingException, URISyntaxException, AAIFormatVertexException {
92                 Version version = Version.v10;
93                 UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost);
94                 String result = builder.id(v);
95                 
96                 assertEquals("has protocol and host", protocolAndHost + version + "/resources/id/" + vId, result);
97                 
98         }
99         
100 }