summaryrefslogtreecommitdiffstats
path: root/aai-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'aai-core/src')
-rw-r--r--aai-core/src/main/java/org/openecomp/aai/serialization/queryformats/utils/UrlBuilder.java13
-rw-r--r--aai-core/src/main/java/org/openecomp/aai/util/AAIConstants.java3
-rw-r--r--aai-core/src/test/java/org/openecomp/aai/serialization/queryformats/utils/UrlBuilderTest.java85
3 files changed, 98 insertions, 3 deletions
diff --git a/aai-core/src/main/java/org/openecomp/aai/serialization/queryformats/utils/UrlBuilder.java b/aai-core/src/main/java/org/openecomp/aai/serialization/queryformats/utils/UrlBuilder.java
index 817a6795..7f088569 100644
--- a/aai-core/src/main/java/org/openecomp/aai/serialization/queryformats/utils/UrlBuilder.java
+++ b/aai-core/src/main/java/org/openecomp/aai/serialization/queryformats/utils/UrlBuilder.java
@@ -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);
+ }
}
diff --git a/aai-core/src/main/java/org/openecomp/aai/util/AAIConstants.java b/aai-core/src/main/java/org/openecomp/aai/util/AAIConstants.java
index 010f7a24..293ee723 100644
--- a/aai-core/src/main/java/org/openecomp/aai/util/AAIConstants.java
+++ b/aai-core/src/main/java/org/openecomp/aai/util/AAIConstants.java
@@ -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
index 00000000..481e3bba
--- /dev/null
+++ b/aai-core/src/test/java/org/openecomp/aai/serialization/queryformats/utils/UrlBuilderTest.java
@@ -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);
+
+ }
+
+}