[AAI-176 Amsterdam] Check in related link changes 21/7721/1
authorVenkata Harish K Kajur <vk250x@att.com>
Wed, 16 Aug 2017 12:49:04 +0000 (08:49 -0400)
committerVenkata Harish K Kajur <vk250x@att.com>
Wed, 16 Aug 2017 12:49:08 +0000 (08:49 -0400)
Change-Id: Ie72ccd9aa2fb3b214f6b8b1ca6280d5dd08b10a7
Signed-off-by: Venkata Harish K Kajur <vk250x@att.com>
aai-core/src/main/java/org/openecomp/aai/serialization/queryformats/utils/UrlBuilder.java
aai-core/src/main/java/org/openecomp/aai/util/AAIConstants.java
aai-core/src/test/java/org/openecomp/aai/serialization/queryformats/utils/UrlBuilderTest.java [new file with mode: 0644]

index 817a679..7f08856 100644 (file)
@@ -25,7 +25,6 @@ import java.net.URI;
 import java.net.URISyntaxException;
 
 import org.apache.tinkerpop.gremlin.structure.Vertex;
-
 import org.openecomp.aai.db.props.AAIProperties;
 import org.openecomp.aai.exceptions.AAIException;
 import org.openecomp.aai.introspection.Version;
@@ -43,7 +42,13 @@ public class UrlBuilder {
        public UrlBuilder (Version version, DBSerializer serializer) throws AAIException {
                this.serializer = serializer;
                this.version = version;
-               this.serverBase = AAIApiServerURLBase.get(AAIProperties.LATEST);
+        this.serverBase = AAIApiServerURLBase.get(AAIProperties.LATEST);
+       }
+
+       public UrlBuilder (Version version, DBSerializer serializer, String serverBase) {
+               this.serializer = serializer;
+               this.version = version;
+               this.serverBase = serverBase;
        }
        
        public String pathed(Vertex v) throws AAIFormatVertexException {
@@ -71,4 +76,8 @@ public class UrlBuilder {
 
                return result.toString();
        }
+
+       protected String getServerBase(Version v) throws AAIException {
+               return AAIApiServerURLBase.get(v);
+       }
 }
index 010f7a2..293ee72 100644 (file)
@@ -81,7 +81,8 @@ public final class AAIConstants {
        public static final String AAI_OLDSERVER_URL = "aai.oldserver.url";
        public static final String AAI_GLOBAL_CALLBACK_URL = "aai.global.callback.url";
        public static final String AAI_LOCAL_REST = "https://localhost:%d/aai/" + AAIProperties.LATEST + "/";
-       
+    public static final String AAI_APP_ROOT = "/aai/";
+
        public static final int AAI_RESOURCES_PORT = 8447;
        public static final int AAI_QUERY_PORT = 8446;
        public static final int AAI_LEGACY_PORT = 8443;
diff --git a/aai-core/src/test/java/org/openecomp/aai/serialization/queryformats/utils/UrlBuilderTest.java b/aai-core/src/test/java/org/openecomp/aai/serialization/queryformats/utils/UrlBuilderTest.java
new file mode 100644 (file)
index 0000000..481e3bb
--- /dev/null
@@ -0,0 +1,85 @@
+package org.openecomp.aai.serialization.queryformats.utils;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.when;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.aai.introspection.Version;
+import org.openecomp.aai.serialization.db.DBSerializer;
+import org.openecomp.aai.serialization.queryformats.exceptions.AAIFormatVertexException;
+import org.openecomp.aai.util.AAIConstants;
+
+public class UrlBuilderTest {
+
+       @Mock private DBSerializer serializer;
+       @Mock private Vertex v;
+       private static final String uri = "/test/uri";
+       private static final Object vId = new Long(123);
+       private static final String protocolAndHost = "http://localhost/aai/";
+       @BeforeClass
+       public static void setUp() {
+               System.setProperty("AJSC_HOME", ".");
+               System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
+
+       }
+       
+       @Before
+       public void before() throws UnsupportedEncodingException, URISyntaxException {
+               MockitoAnnotations.initMocks(this);
+               when(serializer.getURIForVertex(any(Vertex.class))).thenReturn(new URI(uri));
+               when(v.id()).thenReturn(vId);
+       }
+
+       @Ignore
+       @Test
+       public void v11Pathed() throws UnsupportedEncodingException, URISyntaxException, AAIFormatVertexException {
+               Version version = Version.v11;
+               UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost);
+               String result = builder.pathed(v);
+               
+               assertEquals("has no protocol and host", AAIConstants.AAI_APP_ROOT + version + uri, result);
+               
+       }
+
+       @Ignore
+       @Test
+       public void v11Id() throws UnsupportedEncodingException, URISyntaxException, AAIFormatVertexException {
+               Version version = Version.v11;
+               UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost);
+               String result = builder.id(v);
+               
+               assertEquals("has no protocol and host", AAIConstants.AAI_APP_ROOT + version + "/resources/id/" + vId, result);
+               
+       }
+       
+       @Test
+       public void beforeV11Pathed() throws UnsupportedEncodingException, URISyntaxException, AAIFormatVertexException {
+               Version version = Version.v10;
+               UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost);
+               String result = builder.pathed(v);
+               
+               assertEquals("has protocol and host", protocolAndHost + version + uri, result);
+               
+       }
+       
+       @Test
+       public void beforeV11Id() throws UnsupportedEncodingException, URISyntaxException, AAIFormatVertexException {
+               Version version = Version.v10;
+               UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost);
+               String result = builder.id(v);
+               
+               assertEquals("has protocol and host", protocolAndHost + version + "/resources/id/" + vId, result);
+               
+       }
+       
+}