481e3bba39dfefe0108f172f43de6c01dc176f22
[aai/aai-common.git] / aai-core / src / test / java / org / openecomp / aai / serialization / queryformats / utils / UrlBuilderTest.java
1 package org.openecomp.aai.serialization.queryformats.utils;
2 import static org.junit.Assert.assertEquals;
3 import static org.mockito.Matchers.any;
4 import static org.mockito.Mockito.when;
5
6 import java.io.UnsupportedEncodingException;
7 import java.net.URI;
8 import java.net.URISyntaxException;
9
10 import org.apache.tinkerpop.gremlin.structure.Vertex;
11 import org.junit.Before;
12 import org.junit.BeforeClass;
13 import org.junit.Ignore;
14 import org.junit.Test;
15 import org.mockito.Mock;
16 import org.mockito.MockitoAnnotations;
17 import org.openecomp.aai.introspection.Version;
18 import org.openecomp.aai.serialization.db.DBSerializer;
19 import org.openecomp.aai.serialization.queryformats.exceptions.AAIFormatVertexException;
20 import org.openecomp.aai.util.AAIConstants;
21
22 public class UrlBuilderTest {
23
24         @Mock private DBSerializer serializer;
25         @Mock private Vertex v;
26         private static final String uri = "/test/uri";
27         private static final Object vId = new Long(123);
28         private static final String protocolAndHost = "http://localhost/aai/";
29         @BeforeClass
30         public static void setUp() {
31                 System.setProperty("AJSC_HOME", ".");
32                 System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
33
34         }
35         
36         @Before
37         public void before() throws UnsupportedEncodingException, URISyntaxException {
38                 MockitoAnnotations.initMocks(this);
39                 when(serializer.getURIForVertex(any(Vertex.class))).thenReturn(new URI(uri));
40                 when(v.id()).thenReturn(vId);
41         }
42
43         @Ignore
44         @Test
45         public void v11Pathed() throws UnsupportedEncodingException, URISyntaxException, AAIFormatVertexException {
46                 Version version = Version.v11;
47                 UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost);
48                 String result = builder.pathed(v);
49                 
50                 assertEquals("has no protocol and host", AAIConstants.AAI_APP_ROOT + version + uri, result);
51                 
52         }
53
54         @Ignore
55         @Test
56         public void v11Id() throws UnsupportedEncodingException, URISyntaxException, AAIFormatVertexException {
57                 Version version = Version.v11;
58                 UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost);
59                 String result = builder.id(v);
60                 
61                 assertEquals("has no protocol and host", AAIConstants.AAI_APP_ROOT + version + "/resources/id/" + vId, result);
62                 
63         }
64         
65         @Test
66         public void beforeV11Pathed() throws UnsupportedEncodingException, URISyntaxException, AAIFormatVertexException {
67                 Version version = Version.v10;
68                 UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost);
69                 String result = builder.pathed(v);
70                 
71                 assertEquals("has protocol and host", protocolAndHost + version + uri, result);
72                 
73         }
74         
75         @Test
76         public void beforeV11Id() throws UnsupportedEncodingException, URISyntaxException, AAIFormatVertexException {
77                 Version version = Version.v10;
78                 UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost);
79                 String result = builder.id(v);
80                 
81                 assertEquals("has protocol and host", protocolAndHost + version + "/resources/id/" + vId, result);
82                 
83         }
84         
85 }