package org.onap.aai.rest.db;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.not;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.when;
-
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.util.*;
-
-import javax.ws.rs.core.*;
-
import org.javatuples.Pair;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.mockito.Mockito;
import org.onap.aai.AAISetup;
import org.onap.aai.db.props.AAIProperties;
-import org.onap.aai.dbmap.DBConnectionType;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.Introspector;
import org.onap.aai.introspection.Loader;
-import org.onap.aai.introspection.LoaderFactory;
import org.onap.aai.introspection.ModelType;
import org.onap.aai.parsers.query.QueryParser;
import org.onap.aai.rest.ueb.UEBNotification;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
import org.onap.aai.util.AAIConfig;
+import javax.ws.rs.core.*;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.util.*;
+
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.not;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.when;
+
@RunWith(value = Parameterized.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class HttpEntryTest extends AAISetup {
if (uri.endsWith("relationship")) {
objType = "relationship";
}
- Introspector obj = null;
+ Introspector obj;
if (method.equals(HttpMethod.GET)) {
obj = loader.introspectorFromName(objType);
} else {
/*
* TODO do the same with uri
*/
- DBConnectionType type = DBConnectionType.REALTIME;
- traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
+ traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
@Test
public void test2PutOnPserverNoPInterface() throws UnsupportedEncodingException, AAIException {
- DBConnectionType type = DBConnectionType.REALTIME;
- traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
+ traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
@Test
public void test3PutOnPInterface() {
try {
- DBConnectionType type = DBConnectionType.REALTIME;
- traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
+ traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
@Test
public void test4GetOnPserver() throws UnsupportedEncodingException, AAIException {
- DBConnectionType type = DBConnectionType.REALTIME;
- traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
+ traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
- URI uriObject = UriBuilder.fromPath("/cloud-infrastructure/pservers/pserver/junit-test1").build();
-
String uri = "/cloud-infrastructure/pservers/pserver/junit-test1";
String content = "{\"hostname\":\"junit-test1\", \"equip-type\":\"junit-equip-type\"}";
Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.GET, uri, content);
@Test
public void test5MergePatchOnPserver() throws UnsupportedEncodingException, AAIException {
- DBConnectionType type = DBConnectionType.REALTIME;
- traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
+ traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
private int doDelete(String resourceVersion, String uri, String nodeType)
throws UnsupportedEncodingException, AAIException {
queryParameters.add("resource-version", resourceVersion);
- DBConnectionType type = DBConnectionType.REALTIME;
- traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
+ traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
@Test
public void test6DeleteOnPserver() throws UnsupportedEncodingException, AAIException {
- DBConnectionType type = DBConnectionType.REALTIME;
- traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
+ traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
- URI uriObject = UriBuilder.fromPath("/cloud-infrastructure/pservers/pserver/junit-test1").build();
String uri = "/cloud-infrastructure/pservers/pserver/junit-test1";
String content = "";
Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.GET, uri, content);
@Test
public void test7DeleteOnPserverNoPinterface() throws UnsupportedEncodingException, AAIException {
- DBConnectionType type = DBConnectionType.REALTIME;
- traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
+ traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
// HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, queryStyle, type);
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
@Test
public void test8FailedGetOnPserver() throws UnsupportedEncodingException, AAIException {
- DBConnectionType type = DBConnectionType.REALTIME;
- traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
+ traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
// HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, queryStyle, type);
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
@Test
public void putEdgeTest() throws UnsupportedEncodingException, AAIException {
- DBConnectionType type = DBConnectionType.REALTIME;
- traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
+ traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
// HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, queryStyle, type);
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
Loader ld = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
UEBNotification uebNotification = Mockito.spy(new UEBNotification(ld, loaderFactory, schemaVersions));
- DBConnectionType type = DBConnectionType.REALTIME;
- traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type, uebNotification);
+ traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), uebNotification);
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
doNothing().when(uebNotification).triggerEvents();
Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT_EDGE, uri, content);
- response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.DELETE_EDGE, uri, content);
- dbEngine.rollback();
- assertEquals("Expected the pserver relationship to be deleted", 204, response.getStatus());
- assertEquals("Two notifications", 2, uebNotification.getEvents().size());
+ assertEquals("Expected the pserver relationship to be deleted", 200, response.getStatus());
+ assertEquals("Two notifications", 2, uebNotification.getEvents().size());
assertEquals("Notification generated for PUT edge", "UPDATE",
uebNotification.getEvents().get(0).getEventHeader().getValue("action").toString());
assertThat("Event body for the edge create has the related to",
uebNotification.getEvents().get(0).getObj().marshal(false),
containsString("cloud-infrastructure/pservers/pserver/junit-edge-test-pserver"));
+ response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.DELETE_EDGE, uri, content);
+ assertEquals("Expected the pserver relationship to be deleted", 204, response.getStatus());
+ assertEquals("Two notifications", 2, uebNotification.getEvents().size());
assertEquals("Notification generated for DELETE edge", "UPDATE",
- uebNotification.getEvents().get(1).getEventHeader().getValue("action").toString());
+ uebNotification.getEvents().get(0).getEventHeader().getValue("action").toString());
assertThat("Event body for the edge delete does not have the related to",
- uebNotification.getEvents().get(1).getObj().marshal(false),
+ uebNotification.getEvents().get(0).getObj().marshal(false),
not(containsString("cloud-infrastructure/pservers/pserver/junit-edge-test-pserver")));
+ dbEngine.rollback();
}
@Test
public void putEdgeWrongLabelTest() throws UnsupportedEncodingException, AAIException {
- DBConnectionType type = DBConnectionType.REALTIME;
- traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
+ traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
// HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, queryStyle, type);
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
final String testName = new Object() {}.getClass().getEnclosingMethod().getName();
- DBConnectionType type = DBConnectionType.REALTIME;
- traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
+ traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
// HttpEntry httpEntry = new HttpEntry(schemaVersions.getDefaultVersion(), ModelType.MOXY, QueryStyle.TRAVERSAL,
// type);
Loader loader = traversalHttpEntry.getLoader();
final String testName = new Object() {}.getClass().getEnclosingMethod().getName();
- DBConnectionType type = DBConnectionType.REALTIME;
- traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
- // HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, QueryStyle.TRAVERSAL, type);
+ traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
@Test
public void testSetGetPaginationMethods() {
- DBConnectionType type = DBConnectionType.REALTIME;
- traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
- // HttpEntry httpEntry = new HttpEntry(schemaVersions.getDefaultVersion(), ModelType.MOXY, QueryStyle.TRAVERSAL,
- // type);
+ traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
traversalHttpEntry.setPaginationBucket(10);
traversalHttpEntry.setPaginationIndex(1);
traversalHttpEntry.setTotalsForPaging(101, traversalHttpEntry.getPaginationBucket());
@Test
public void relatedToTest() throws UnsupportedEncodingException, AAIException {
- DBConnectionType type = DBConnectionType.REALTIME;
- traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
- // HttpEntry httpEntry = new HttpEntry(schemaVersions.getDefaultVersion(), ModelType.MOXY, queryStyle, type);
+ traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
}
@Test
- public void setDepthTest() throws UnsupportedEncodingException, AAIException {
+ public void setDepthTest() throws AAIException {
System.setProperty("AJSC_HOME", ".");
System.setProperty("BUNDLECONFIG_DIR", "src/main/test/resources");
String depthParam = AAIConfig.get("aai.rest.getall.depthparam");
- DBConnectionType type = DBConnectionType.REALTIME;
- traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
- // HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, QueryStyle.TRAVERSAL, type);
+ traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
int depth = traversalHttpEntry.setDepth(null, depthParam);
assertEquals(AAIProperties.MAXIMUM_DEPTH.intValue(), depth);
}
@Test
public void getAbstractTest() throws UnsupportedEncodingException, AAIException {
- DBConnectionType type = DBConnectionType.REALTIME;
- traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
- // HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, queryStyle, type);
+ traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion());
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();