summaryrefslogtreecommitdiffstats
path: root/aai-core/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'aai-core/src/test')
-rw-r--r--aai-core/src/test/java/org/onap/aai/AAIJunitRunner.java11
-rw-r--r--aai-core/src/test/java/org/onap/aai/AAISetup.java65
-rw-r--r--aai-core/src/test/java/org/onap/aai/AAISetupForSwagger.java25
-rw-r--r--aai-core/src/test/java/org/onap/aai/AbstractConfigTranslator.java34
-rw-r--r--aai-core/src/test/java/org/onap/aai/DataLinkSetup.java91
-rw-r--r--aai-core/src/test/java/org/onap/aai/HttpTestUtil.java161
-rw-r--r--aai-core/src/test/java/org/onap/aai/PayloadUtil.java26
-rw-r--r--aai-core/src/test/java/org/onap/aai/auth/AAIAuthCoreTest.java92
-rw-r--r--aai-core/src/test/java/org/onap/aai/auth/AAIUserTest.java13
-rw-r--r--aai-core/src/test/java/org/onap/aai/concurrent/AaiCallableTest.java12
-rw-r--r--aai-core/src/test/java/org/onap/aai/dbmap/AAIGraphTest.java122
-rw-r--r--aai-core/src/test/java/org/onap/aai/domain/restPolicyException/PolicyExceptionTest.java11
-rw-r--r--aai-core/src/test/java/org/onap/aai/domain/restPolicyException/RequestErrorTest.java5
-rw-r--r--aai-core/src/test/java/org/onap/aai/exceptions/AAIExceptionTest.java19
-rw-r--r--aai-core/src/test/java/org/onap/aai/exceptions/AAIExceptionWithInfoTest.java14
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/IntrospectorTestSpec.java34
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/JSONStrategyTest.java28
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/MoxyEngineTest.java15
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/PropertyPredicatesTest.java32
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/generator/CreateExampleTest.java39
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java180
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataLinkTest.java334
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/sideeffect/PrivateEdgeTest.java124
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/tools/CreateUUIDTest.java9
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/tools/DefaultFieldsTest.java15
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/tools/InjectKeysFromURITest.java31
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/tools/IntrospectorValidatorTest.java56
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/tools/RemoveNonVisiblePropertyTest.java12
-rw-r--r--aai-core/src/test/java/org/onap/aai/introspection/validation/IntrospectorValidationTest.java17
-rw-r--r--aai-core/src/test/java/org/onap/aai/logging/CustomLogPatternLayoutTest.java15
-rw-r--r--aai-core/src/test/java/org/onap/aai/logging/DME2RestFlagTest.java33
-rw-r--r--aai-core/src/test/java/org/onap/aai/logging/EcompErrorCategoryTest.java8
-rw-r--r--aai-core/src/test/java/org/onap/aai/logging/EcompResponseCodeTest.java8
-rw-r--r--aai-core/src/test/java/org/onap/aai/logging/EcompResponseDescriptionTest.java10
-rw-r--r--aai-core/src/test/java/org/onap/aai/logging/EelfClassOfCallerTest.java28
-rw-r--r--aai-core/src/test/java/org/onap/aai/logging/ErrorObjectTest.java127
-rw-r--r--aai-core/src/test/java/org/onap/aai/logging/LoggingContextTest.java28
-rw-r--r--aai-core/src/test/java/org/onap/aai/parsers/query/GraphTraversalTest.java683
-rw-r--r--aai-core/src/test/java/org/onap/aai/parsers/query/LegacyQueryTest.java111
-rw-r--r--aai-core/src/test/java/org/onap/aai/parsers/query/RelationshipGremlinQueryTest.java482
-rw-r--r--aai-core/src/test/java/org/onap/aai/parsers/query/RelationshipQueryTest.java188
-rw-r--r--aai-core/src/test/java/org/onap/aai/parsers/query/UniqueRelationshipQueryTest.java163
-rw-r--r--aai-core/src/test/java/org/onap/aai/parsers/query/UniqueURIQueryTest.java64
-rw-r--r--aai-core/src/test/java/org/onap/aai/parsers/relationship/RelationshipToURITest.java110
-rw-r--r--aai-core/src/test/java/org/onap/aai/parsers/uri/URIParserTest.java64
-rw-r--r--aai-core/src/test/java/org/onap/aai/parsers/uri/URIToDBKeyTest.java114
-rw-r--r--aai-core/src/test/java/org/onap/aai/parsers/uri/URIToExtensionInformationTest.java55
-rw-r--r--aai-core/src/test/java/org/onap/aai/parsers/uri/URIToObjectTest.java93
-rw-r--r--aai-core/src/test/java/org/onap/aai/parsers/uri/URIToRelationshipObjectTest.java105
-rw-r--r--aai-core/src/test/java/org/onap/aai/query/builder/ExcludeQueryTest.java111
-rw-r--r--aai-core/src/test/java/org/onap/aai/query/builder/GremlinTraversalTest.java13
-rw-r--r--aai-core/src/test/java/org/onap/aai/query/builder/QueryBuilderTestAbstraction.java263
-rw-r--r--aai-core/src/test/java/org/onap/aai/query/builder/QueryTestsConfigTranslator.java8
-rw-r--r--aai-core/src/test/java/org/onap/aai/query/builder/SimplePathTest.java64
-rw-r--r--aai-core/src/test/java/org/onap/aai/query/builder/TraversalQueryTest.java177
-rw-r--r--aai-core/src/test/java/org/onap/aai/query/builder/TraversalURIOptimizedQueryTest.java3
-rw-r--r--aai-core/src/test/java/org/onap/aai/query/builder/UntilTest.java50
-rw-r--r--aai-core/src/test/java/org/onap/aai/query/builder/optimization/AbstractGraphTraversalBuilderOptmizationTest.java85
-rw-r--r--aai-core/src/test/java/org/onap/aai/query/builder/optimization/AbstractGraphTraversalBuilderTestQueryiesToRun.java54
-rw-r--r--aai-core/src/test/java/org/onap/aai/query/builder/optimization/OptimizeEnum.java3
-rw-r--r--aai-core/src/test/java/org/onap/aai/query/builder/optimization/tests/AOneTenantOneVserversPerTenantTest.java3
-rw-r--r--aai-core/src/test/java/org/onap/aai/query/builder/optimization/tests/BTenTenantTenVserversPerTenantTest.java3
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/CloudRegionTest.java29
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/EdgeNotValidAnymoreTest.java47
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/EntitlementTest.java27
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/GenericVnfLInterfaceTest.java27
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/HPACapabilityTest.java27
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/ModelElementTest.java30
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/PrivateEdgeIntegrationOldClientTest.java51
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/PrivateEdgeIntegrationTest.java267
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/PserverDuplicateTest.java92
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/PserverTest.java37
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/RestHandlerTest.java11
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/TenantTest.java36
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/VipAddressListTest.java30
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java260
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/db/AAICoreFakeEdgesConfigTranslator.java41
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/db/AAICorePrivateEdgeTestConfigTranslator.java45
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/db/DbAliasTest.java207
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java1396
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializer_needsFakeRulesTest.java1262
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/db/EdgePropertyMapTest.java29
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/db/EdgeRulesTest.java90
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/db/EdgeSerializerTest.java134
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/engines/query/GraphTraversalQueryEngineTest.java575
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/engines/query/GraphTraversalQueryEngine_needsFakeEdgeRulesTest.java76
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/queryformats/ConsoleTest.java99
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/queryformats/CountQuerySupportTest.java227
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/queryformats/FormatTest.java33
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/queryformats/GraphSONTest.java923
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/queryformats/MultiFormatTest.java241
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/queryformats/QueryFormatTestHelper.java74
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/queryformats/RawFormatTest.java183
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/queryformats/ResourceFormatTest.java169
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/queryformats/ResourceWithSoTTest.java51
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/queryformats/SimpleFormatTest.java220
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/queryformats/utils/QueryParamInjectorTest.java51
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/queryformats/utils/UrlBuilderTest.java127
-rw-r--r--aai-core/src/test/java/org/onap/aai/serialization/tinkerpop/TreeBackedVertexTest.java236
-rw-r--r--aai-core/src/test/java/org/onap/aai/testutils/TestUtilConfigTranslatorforBusiness.java72
-rw-r--r--aai-core/src/test/java/org/onap/aai/testutils/TestUtilConfigTranslatorforDataLink.java54
-rw-r--r--aai-core/src/test/java/org/onap/aai/testutils/TestUtilConfigTranslatorforEdges.java76
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/AAIConfigCommandLinePropGetterTest.java128
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/AAIConfigTest.java175
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/AAIUtilsTest.java72
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/FileWatcherTest.java85
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/FormatDateTest.java77
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/JettyObfuscationConversionCommandLineUtilTest.java21
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/KeyValueListTest.java4
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/MapperUtilTest.java39
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/PojoUtilsTest.java564
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/RestURLEncoderTest.java49
-rw-r--r--aai-core/src/test/java/org/onap/aai/util/StoreNotificationEventTest.java360
113 files changed, 6901 insertions, 7288 deletions
diff --git a/aai-core/src/test/java/org/onap/aai/AAIJunitRunner.java b/aai-core/src/test/java/org/onap/aai/AAIJunitRunner.java
index 94fce5d4..da7446bb 100644
--- a/aai-core/src/test/java/org/onap/aai/AAIJunitRunner.java
+++ b/aai-core/src/test/java/org/onap/aai/AAIJunitRunner.java
@@ -17,14 +17,15 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.aai;
-import org.junit.runners.Parameterized;
-import org.onap.aai.util.AAIConstants;
+package org.onap.aai;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
+import org.junit.runners.Parameterized;
+import org.onap.aai.util.AAIConstants;
+
public class AAIJunitRunner extends Parameterized {
public AAIJunitRunner(Class<?> klass) throws Throwable {
@@ -33,12 +34,12 @@ public class AAIJunitRunner extends Parameterized {
modifyOxmHome();
}
- public void setProps(){
+ public void setProps() {
System.setProperty("AJSC_HOME", ".");
System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
}
- public void modifyOxmHome(){
+ public void modifyOxmHome() {
try {
Field aaiConstantsField = AAIConstants.class.getField("AAI_HOME_ETC_OXM");
setFinalStatic(aaiConstantsField, "../aai-schema/src/main/resources/oxm/");
diff --git a/aai-core/src/test/java/org/onap/aai/AAISetup.java b/aai-core/src/test/java/org/onap/aai/AAISetup.java
index b464ef46..ade20f4a 100644
--- a/aai-core/src/test/java/org/onap/aai/AAISetup.java
+++ b/aai-core/src/test/java/org/onap/aai/AAISetup.java
@@ -17,28 +17,28 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai;
import java.util.Map;
import org.junit.BeforeClass;
-
import org.junit.ClassRule;
import org.junit.Rule;
import org.onap.aai.config.ConfigConfiguration;
+import org.onap.aai.config.IntrospectionConfig;
+import org.onap.aai.config.RestBeanConfig;
import org.onap.aai.config.SpringContextAware;
import org.onap.aai.edges.EdgeIngestor;
-import org.onap.aai.config.IntrospectionConfig;
import org.onap.aai.introspection.LoaderFactory;
import org.onap.aai.introspection.MoxyLoader;
import org.onap.aai.nodes.NodeIngestor;
-import org.onap.aai.config.RestBeanConfig;
import org.onap.aai.rest.db.HttpEntry;
+import org.onap.aai.serialization.db.EdgeSerializer;
+import org.onap.aai.serialization.queryformats.QueryFormatTestHelper;
import org.onap.aai.setup.AAIConfigTranslator;
import org.onap.aai.setup.SchemaVersion;
import org.onap.aai.setup.SchemaVersions;
-import org.onap.aai.serialization.db.EdgeSerializer;
-import org.onap.aai.serialization.queryformats.QueryFormatTestHelper;
import org.onap.aai.util.AAIConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -47,19 +47,13 @@ import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.rules.SpringClassRule;
import org.springframework.test.context.junit4.rules.SpringMethodRule;
-
-@ContextConfiguration(classes = {
- ConfigConfiguration.class,
- AAIConfigTranslator.class,
- EdgeIngestor.class,
- EdgeSerializer.class,
- NodeIngestor.class,
- SpringContextAware.class,
- IntrospectionConfig.class,
- RestBeanConfig.class
-})
-@TestPropertySource(properties = { "schema.uri.base.path = /aai", "schema.xsd.maxoccurs = 5000" , "schema.translator.list=config",
- "schema.nodes.location=src/test/resources/onap/oxm", "schema.edges.location=src/test/resources/onap/dbedgerules"})
+@ContextConfiguration(
+ classes = {ConfigConfiguration.class, AAIConfigTranslator.class, EdgeIngestor.class, EdgeSerializer.class,
+ NodeIngestor.class, SpringContextAware.class, IntrospectionConfig.class, RestBeanConfig.class})
+@TestPropertySource(
+ properties = {"schema.uri.base.path = /aai", "schema.xsd.maxoccurs = 5000", "schema.translator.list=config",
+ "schema.nodes.location=src/test/resources/onap/oxm",
+ "schema.edges.location=src/test/resources/onap/dbedgerules"})
public abstract class AAISetup {
@ClassRule
@@ -69,28 +63,28 @@ public abstract class AAISetup {
public final SpringMethodRule springMethodRule = new SpringMethodRule();
@Autowired
- protected Map<SchemaVersion, MoxyLoader> moxyLoaderInstance;
+ protected Map<SchemaVersion, MoxyLoader> moxyLoaderInstance;
- @Autowired
- protected HttpEntry traversalHttpEntry;
+ @Autowired
+ protected HttpEntry traversalHttpEntry;
- @Autowired
- protected HttpEntry traversalUriHttpEntry;
+ @Autowired
+ protected HttpEntry traversalUriHttpEntry;
- @Autowired
- protected NodeIngestor nodeIngestor;
+ @Autowired
+ protected NodeIngestor nodeIngestor;
- @Autowired
- protected LoaderFactory loaderFactory;
+ @Autowired
+ protected LoaderFactory loaderFactory;
- @Autowired
- protected SchemaVersions schemaVersions;
+ @Autowired
+ protected SchemaVersions schemaVersions;
- @Value("${schema.uri.base.path}")
- protected String basePath;
+ @Value("${schema.uri.base.path}")
+ protected String basePath;
- @Value("${schema.xsd.maxoccurs}")
- protected String maxOccurs;
+ @Value("${schema.xsd.maxoccurs}")
+ protected String maxOccurs;
protected static final String SERVICE_NAME = "JUNIT";
@@ -99,9 +93,8 @@ public abstract class AAISetup {
System.setProperty("AJSC_HOME", ".");
System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
System.setProperty("aai.service.name", SERVICE_NAME);
- QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"), "src/test/resources/bundleconfig-local/etc/oxm/");
+ QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"),
+ "src/test/resources/bundleconfig-local/etc/oxm/");
}
-
-
}
diff --git a/aai-core/src/test/java/org/onap/aai/AAISetupForSwagger.java b/aai-core/src/test/java/org/onap/aai/AAISetupForSwagger.java
index 07731770..c11a5b2d 100644
--- a/aai-core/src/test/java/org/onap/aai/AAISetupForSwagger.java
+++ b/aai-core/src/test/java/org/onap/aai/AAISetupForSwagger.java
@@ -17,31 +17,27 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.aai;
+package org.onap.aai;
import org.junit.BeforeClass;
-
import org.junit.ClassRule;
import org.junit.Rule;
import org.onap.aai.edges.EdgeIngestor;
import org.onap.aai.nodes.NodeIngestor;
import org.onap.aai.serialization.queryformats.QueryFormatTestHelper;
import org.onap.aai.setup.SchemaLocationsBean;
-import org.onap.aai.util.AAIConstants;
import org.onap.aai.testutils.TestUtilConfigTranslatorforEdges;
+import org.onap.aai.util.AAIConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.rules.SpringClassRule;
import org.springframework.test.context.junit4.rules.SpringMethodRule;
-@ContextConfiguration(classes = {
- SchemaLocationsBean.class,
- TestUtilConfigTranslatorforEdges.class,
- EdgeIngestor.class,
- NodeIngestor.class
-})
+@ContextConfiguration(
+ classes = {SchemaLocationsBean.class, TestUtilConfigTranslatorforEdges.class, EdgeIngestor.class,
+ NodeIngestor.class})
@TestPropertySource(properties = {"schemaIngestPropLoc = src/test/resources/schemaIngest/schemaIngestTest.properties"})
public abstract class AAISetupForSwagger {
@@ -52,11 +48,9 @@ public abstract class AAISetupForSwagger {
@Rule
public final SpringMethodRule springMethodRule = new SpringMethodRule();
-
@Autowired
protected NodeIngestor nodeIngestor;
-
-
+
protected static final String SERVICE_NAME = "JUNIT";
@BeforeClass
@@ -64,9 +58,8 @@ public abstract class AAISetupForSwagger {
System.setProperty("AJSC_HOME", ".");
System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
System.setProperty("aai.service.name", SERVICE_NAME);
- QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"), "src/test/resources/bundleconfig-local/etc/oxm/");
+ QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"),
+ "src/test/resources/bundleconfig-local/etc/oxm/");
}
-
-
-
+
}
diff --git a/aai-core/src/test/java/org/onap/aai/AbstractConfigTranslator.java b/aai-core/src/test/java/org/onap/aai/AbstractConfigTranslator.java
index fb91e316..07183436 100644
--- a/aai-core/src/test/java/org/onap/aai/AbstractConfigTranslator.java
+++ b/aai-core/src/test/java/org/onap/aai/AbstractConfigTranslator.java
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai;
import java.io.File;
@@ -38,36 +39,35 @@ public abstract class AbstractConfigTranslator extends ConfigTranslator {
super(bean, schemaVersions);
}
-
-
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.onap.aai.setup.ConfigTranslator#getNodeFiles()
*/
@Override
public Map<SchemaVersion, List<String>> getNodeFiles() {
- String prefix = bean.getNodeDirectory() + AAIConstants.AAI_FILESEP ;
-
+ String prefix = bean.getNodeDirectory() + AAIConstants.AAI_FILESEP;
+
String suffix = ".xml";
-
+
Map<SchemaVersion, List<String>> files = new TreeMap<>();
for (SchemaVersion v : schemaVersions.getVersions()) {
-
+
List<String> container = getVersionNodeFiles(v);
-
-
+
files.put(v, container);
}
-
+
return files;
}
-
public List<String> getVersionNodeFiles(SchemaVersion v) {
- Pattern p = Pattern.compile("aai(.*)"+"_oxm_(.*).xml" );
-
+ Pattern p = Pattern.compile("aai(.*)" + "_oxm_(.*).xml");
+
List<String> container = new ArrayList<>();
- String directoryName = bean.getNodeDirectory() + AAIConstants.AAI_FILESEP + v.toString() + AAIConstants.AAI_FILESEP ;
-
+ String directoryName =
+ bean.getNodeDirectory() + AAIConstants.AAI_FILESEP + v.toString() + AAIConstants.AAI_FILESEP;
+
File[] files = new File(directoryName).listFiles();
for (File f : files) {
String fileName = f.getName();
@@ -76,10 +76,10 @@ public abstract class AbstractConfigTranslator extends ConfigTranslator {
String file = directoryName + m.group();
container.add(file.toString());
}
-
+
}
return container;
-
+
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/DataLinkSetup.java b/aai-core/src/test/java/org/onap/aai/DataLinkSetup.java
index 125bb111..f4d62d44 100644
--- a/aai-core/src/test/java/org/onap/aai/DataLinkSetup.java
+++ b/aai-core/src/test/java/org/onap/aai/DataLinkSetup.java
@@ -17,8 +17,11 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai;
+import java.util.Map;
+
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
@@ -47,31 +50,16 @@ import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.rules.SpringClassRule;
import org.springframework.test.context.junit4.rules.SpringMethodRule;
-import java.util.Map;
-
-
-@ContextConfiguration(classes = {
- ConfigConfiguration.class,
- TestUtilConfigTranslatorforDataLink.class,
- EdgeIngestor.class,
- EdgeSerializer.class,
- NodeIngestor.class,
- SpringContextAware.class,
- IntrospectionConfig.class,
- RestBeanConfig.class
-})
-@TestPropertySource(properties = {
- "schema.uri.base.path = /aai",
- "schema.xsd.maxoccurs = 5000",
- "schema.version.api.default = v4",
- "schema.version.edge.label.start = v4",
- "schema.version.depth.start = v3",
- "schema.version.app.root.start = v4",
- "schema.version.related.link.start = v4",
- "schema.version.namespace.change.start = v4",
- "schema.version.list = v1,v2,v3,v4",
- "schema.translator.list = config"
-})
+@ContextConfiguration(
+ classes = {ConfigConfiguration.class, TestUtilConfigTranslatorforDataLink.class, EdgeIngestor.class,
+ EdgeSerializer.class, NodeIngestor.class, SpringContextAware.class, IntrospectionConfig.class,
+ RestBeanConfig.class})
+@TestPropertySource(
+ properties = {"schema.uri.base.path = /aai", "schema.xsd.maxoccurs = 5000", "schema.version.api.default = v4",
+ "schema.version.edge.label.start = v4", "schema.version.depth.start = v3",
+ "schema.version.app.root.start = v4", "schema.version.related.link.start = v4",
+ "schema.version.namespace.change.start = v4", "schema.version.list = v1,v2,v3,v4",
+ "schema.translator.list = config"})
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public abstract class DataLinkSetup {
@@ -82,29 +70,29 @@ public abstract class DataLinkSetup {
public final SpringMethodRule springMethodRule = new SpringMethodRule();
@Autowired
- protected Map<SchemaVersion, MoxyLoader> moxyLoaderInstance;
-
- @Autowired
- protected HttpEntry traversalHttpEntry;
-
- @Autowired
- protected HttpEntry traversalUriHttpEntry;
-
- @Autowired
- protected NodeIngestor nodeIngestor;
-
- @Autowired
- protected LoaderFactory loaderFactory;
-
- @Autowired
- protected SchemaVersions schemaVersions;
-
- @Value("${schema.uri.base.path}")
- protected String basePath;
-
- @Value("${schema.xsd.maxoccurs}")
- protected String maxOccurs;
-
+ protected Map<SchemaVersion, MoxyLoader> moxyLoaderInstance;
+
+ @Autowired
+ protected HttpEntry traversalHttpEntry;
+
+ @Autowired
+ protected HttpEntry traversalUriHttpEntry;
+
+ @Autowired
+ protected NodeIngestor nodeIngestor;
+
+ @Autowired
+ protected LoaderFactory loaderFactory;
+
+ @Autowired
+ protected SchemaVersions schemaVersions;
+
+ @Value("${schema.uri.base.path}")
+ protected String basePath;
+
+ @Value("${schema.xsd.maxoccurs}")
+ protected String maxOccurs;
+
protected static final String SERVICE_NAME = "JUNIT";
@BeforeClass
@@ -112,9 +100,8 @@ public abstract class DataLinkSetup {
System.setProperty("AJSC_HOME", ".");
System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
System.setProperty("aai.service.name", SERVICE_NAME);
- QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"), "src/test/resources/bundleconfig-local/etc/oxm/");
+ QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"),
+ "src/test/resources/bundleconfig-local/etc/oxm/");
}
-
-
-
+
}
diff --git a/aai-core/src/test/java/org/onap/aai/HttpTestUtil.java b/aai-core/src/test/java/org/onap/aai/HttpTestUtil.java
index 6add23e0..6a9e7256 100644
--- a/aai-core/src/test/java/org/onap/aai/HttpTestUtil.java
+++ b/aai-core/src/test/java/org/onap/aai/HttpTestUtil.java
@@ -17,10 +17,24 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.when;
+
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import javax.ws.rs.core.*;
+
import org.javatuples.Pair;
import org.mockito.Mockito;
import org.onap.aai.config.SpringContextAware;
@@ -28,7 +42,6 @@ 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.setup.SchemaVersion;
import org.onap.aai.parsers.query.QueryParser;
import org.onap.aai.parsers.uri.URIToObject;
import org.onap.aai.rest.db.DBRequest;
@@ -37,25 +50,14 @@ import org.onap.aai.restcore.HttpMethod;
import org.onap.aai.restcore.RESTAPI;
import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
+import org.onap.aai.setup.SchemaVersion;
import org.onap.aai.setup.SchemaVersions;
-import javax.ws.rs.core.*;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.when;
-
public class HttpTestUtil extends RESTAPI {
+ protected HttpEntry traversalHttpEntry;
- protected HttpEntry traversalHttpEntry;
-
- protected HttpEntry traversalUriHttpEntry;
+ protected HttpEntry traversalUriHttpEntry;
private static final EELFLogger logger = EELFManager.getInstance().getLogger(HttpTestUtil.class);
@@ -80,13 +82,13 @@ public class HttpTestUtil extends RESTAPI {
}
- public void init(){
+ public void init() {
- httpHeaders = Mockito.mock(HttpHeaders.class);
- uriInfo = Mockito.mock(UriInfo.class);
+ httpHeaders = Mockito.mock(HttpHeaders.class);
+ uriInfo = Mockito.mock(UriInfo.class);
- headersMultiMap = new MultivaluedHashMap<>();
- queryParameters = Mockito.spy(new MultivaluedHashMap<>());
+ headersMultiMap = new MultivaluedHashMap<>();
+ queryParameters = Mockito.spy(new MultivaluedHashMap<>());
headersMultiMap.add("X-FromAppId", "JUNIT");
headersMultiMap.add("X-TransactionId", UUID.randomUUID().toString());
@@ -121,25 +123,25 @@ public class HttpTestUtil extends RESTAPI {
try {
- if(uri.startsWith("/aai/")){
+ if (uri.startsWith("/aai/")) {
uri = uri.substring(5);
}
logger.info("Starting the put request for the uri {} with payload {}", uri, payload);
- String [] arr = uri.split("/");
+ String[] arr = uri.split("/");
SchemaVersion version = null;
- if(arr != null && arr.length > 1){
- if(arr[0].matches("^v\\d+")){
+ if (arr != null && arr.length > 1) {
+ if (arr[0].matches("^v\\d+")) {
version = new SchemaVersion(arr[0]);
uri = uri.replaceAll("^v\\d+", "");
}
}
SchemaVersions schemaVersions = (SchemaVersions) SpringContextAware.getBean("schemaVersions");
- if(version == null){
+ if (version == null) {
version = schemaVersions.getDefaultVersion();
}
Mockito.when(uriInfo.getPath()).thenReturn(uri);
@@ -147,8 +149,8 @@ public class HttpTestUtil extends RESTAPI {
DBConnectionType type = DBConnectionType.REALTIME;
traversalHttpEntry.setHttpEntryProperties(version, type);
- Loader loader = traversalHttpEntry.getLoader();
- dbEngine = traversalHttpEntry.getDbEngine();
+ Loader loader = traversalHttpEntry.getLoader();
+ dbEngine = traversalHttpEntry.getDbEngine();
URI uriObject = UriBuilder.fromPath(uri).build();
URIToObject uriToObject = new URIToObject(loader, uriObject);
@@ -156,13 +158,13 @@ public class HttpTestUtil extends RESTAPI {
String objType = uriToObject.getEntityName();
QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject);
-
logger.info("Unmarshalling the payload to this {}", objType);
Introspector obj;
HttpMethod httpMethod;
- if(uri.contains("/relationship-list/relationship")){
- obj = loader.unmarshal("relationship", payload, org.onap.aai.restcore.MediaType.getEnum("application/json"));
+ if (uri.contains("/relationship-list/relationship")) {
+ obj = loader.unmarshal("relationship", payload,
+ org.onap.aai.restcore.MediaType.getEnum("application/json"));
httpMethod = HttpMethod.PUT_EDGE;
} else {
obj = loader.unmarshal(objType, payload, org.onap.aai.restcore.MediaType.getEnum("application/json"));
@@ -170,36 +172,36 @@ public class HttpTestUtil extends RESTAPI {
this.validateIntrospector(obj, loader, uriObject, httpMethod);
}
-
- DBRequest dbRequest =
- new DBRequest.Builder(httpMethod, uriObject, uriQuery, obj, httpHeaders, uriInfo, "JUNIT-TRANSACTION")
- .rawRequestContent(payload).build();
+ DBRequest dbRequest = new DBRequest.Builder(httpMethod, uriObject, uriQuery, obj, httpHeaders, uriInfo,
+ "JUNIT-TRANSACTION").rawRequestContent(payload).build();
List<DBRequest> dbRequestList = new ArrayList<>();
dbRequestList.add(dbRequest);
- Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = traversalHttpEntry.process(dbRequestList, "JUNIT");
+ Pair<Boolean, List<Pair<URI, Response>>> responsesTuple =
+ traversalHttpEntry.process(dbRequestList, "JUNIT");
response = responsesTuple.getValue1().get(0).getValue1();
} catch (AAIException e) {
response = this.consumerExceptionResponseGenerator(httpHeaders, uriInfo, HttpMethod.PUT, e);
success = false;
- } catch(Exception e){
+ } catch (Exception e) {
AAIException ex = new AAIException("AAI_4000", e);
response = this.consumerExceptionResponseGenerator(httpHeaders, uriInfo, HttpMethod.PUT, ex);
success = false;
} finally {
- if(success){
- if(response != null){
- if((response.getStatus() / 100) == 2){
- logger.info("Successfully completed the PUT request with status {} and committing it to DB", response.getStatus());
+ if (success) {
+ if (response != null) {
+ if ((response.getStatus() / 100) == 2) {
+ logger.info("Successfully completed the PUT request with status {} and committing it to DB",
+ response.getStatus());
} else {
logFailure(HttpMethod.PUT, response);
}
}
dbEngine.commit();
} else {
- if(response != null) {
+ if (response != null) {
logFailure(HttpMethod.PUT, response);
}
dbEngine.rollback();
@@ -209,7 +211,7 @@ public class HttpTestUtil extends RESTAPI {
return response;
}
- public Response doGet(String uri, String depth){
+ public Response doGet(String uri, String depth) {
this.init();
Response response = null;
@@ -218,36 +220,36 @@ public class HttpTestUtil extends RESTAPI {
try {
- if(uri.startsWith("/aai/")){
+ if (uri.startsWith("/aai/")) {
uri = uri.substring(5);
}
logger.info("Starting the GET request for the uri {} with depth {}", uri, depth);
- String [] arr = uri.split("/");
+ String[] arr = uri.split("/");
SchemaVersion version = null;
- if(arr != null && arr.length > 1){
- if(arr[0].matches("^v\\d+")){
+ if (arr != null && arr.length > 1) {
+ if (arr[0].matches("^v\\d+")) {
version = new SchemaVersion(arr[0]);
uri = uri.replaceAll("^v\\d+", "");
}
}
SchemaVersions schemaVersions = (SchemaVersions) SpringContextAware.getBean("schemaVersions");
- if(version == null){
+ if (version == null) {
version = schemaVersions.getDefaultVersion();
}
DBConnectionType type = DBConnectionType.REALTIME;
traversalHttpEntry.setHttpEntryProperties(version, type);
- Loader loader = traversalHttpEntry.getLoader();
- dbEngine = traversalHttpEntry.getDbEngine();
+ Loader loader = traversalHttpEntry.getLoader();
+ dbEngine = traversalHttpEntry.getDbEngine();
URI uriObject = UriBuilder.fromPath(uri).build();
- if(depth != null){
+ if (depth != null) {
queryParameters.add("depth", depth);
}
@@ -266,28 +268,29 @@ public class HttpTestUtil extends RESTAPI {
Introspector obj = loader.introspectorFromName(objType);
- DBRequest dbRequest =
- new DBRequest.Builder(HttpMethod.GET, uriObject, uriQuery, obj, httpHeaders, uriInfo, "JUNIT-TRANSACTION")
- .build();
+ DBRequest dbRequest = new DBRequest.Builder(HttpMethod.GET, uriObject, uriQuery, obj, httpHeaders, uriInfo,
+ "JUNIT-TRANSACTION").build();
List<DBRequest> dbRequestList = new ArrayList<>();
dbRequestList.add(dbRequest);
- Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = traversalHttpEntry.process(dbRequestList, "JUNIT");
+ Pair<Boolean, List<Pair<URI, Response>>> responsesTuple =
+ traversalHttpEntry.process(dbRequestList, "JUNIT");
response = responsesTuple.getValue1().get(0).getValue1();
} catch (AAIException e) {
response = this.consumerExceptionResponseGenerator(httpHeaders, uriInfo, HttpMethod.PUT, e);
success = false;
- } catch(Exception e){
+ } catch (Exception e) {
AAIException ex = new AAIException("AAI_4000", e);
response = this.consumerExceptionResponseGenerator(httpHeaders, uriInfo, HttpMethod.PUT, ex);
success = false;
} finally {
- if(success){
- if(response != null){
- if((response.getStatus() / 100) == 2){
- logger.info("Successfully completed the GET request with status {} and committing it to DB", response.getStatus());
+ if (success) {
+ if (response != null) {
+ if ((response.getStatus() / 100) == 2) {
+ logger.info("Successfully completed the GET request with status {} and committing it to DB",
+ response.getStatus());
} else {
logFailure(HttpMethod.GET, response);
}
@@ -318,21 +321,21 @@ public class HttpTestUtil extends RESTAPI {
uri = uri.replaceAll("/aai/", "");
logger.info("Starting the delete request for the uri {} with resource version {}", uri, resourceVersion);
- String [] arr = uri.split("/");
+ String[] arr = uri.split("/");
SchemaVersion version = null;
- if(arr != null && arr.length > 1){
- if(arr[0].matches("^v\\d+")){
+ if (arr != null && arr.length > 1) {
+ if (arr[0].matches("^v\\d+")) {
version = new SchemaVersion(arr[0]);
- if(!uri.contains("relationship-list/relationship")){
+ if (!uri.contains("relationship-list/relationship")) {
uri = uri.replaceAll("^v\\d+", "");
}
}
}
SchemaVersions schemaVersions = (SchemaVersions) SpringContextAware.getBean("schemaVersions");
- if(version == null){
+ if (version == null) {
version = schemaVersions.getDefaultVersion();
}
@@ -341,8 +344,8 @@ public class HttpTestUtil extends RESTAPI {
traversalHttpEntry.setHttpEntryProperties(version, type);
traversalHttpEntry.setHttpEntryProperties(version, type);
- Loader loader = traversalHttpEntry.getLoader();
- dbEngine = traversalHttpEntry.getDbEngine();
+ Loader loader = traversalHttpEntry.getLoader();
+ dbEngine = traversalHttpEntry.getDbEngine();
URI uriObject = UriBuilder.fromPath(uri).build();
URIToObject uriToObject = new URIToObject(loader, uriObject);
@@ -355,7 +358,7 @@ public class HttpTestUtil extends RESTAPI {
Introspector obj;
HttpMethod httpMethod;
- if(uri.contains("/relationship-list/relationship")){
+ if (uri.contains("/relationship-list/relationship")) {
obj = loader.introspectorFromName("relationship");
httpMethod = HttpMethod.DELETE_EDGE;
} else {
@@ -363,28 +366,29 @@ public class HttpTestUtil extends RESTAPI {
httpMethod = HttpMethod.DELETE;
}
- DBRequest dbRequest =
- new DBRequest.Builder(httpMethod, uriObject, uriQuery, obj, httpHeaders, uriInfo, "JUNIT-TRANSACTION")
- .build();
+ DBRequest dbRequest = new DBRequest.Builder(httpMethod, uriObject, uriQuery, obj, httpHeaders, uriInfo,
+ "JUNIT-TRANSACTION").build();
List<DBRequest> dbRequestList = new ArrayList<>();
dbRequestList.add(dbRequest);
- Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = traversalHttpEntry.process(dbRequestList, "JUNIT");
+ Pair<Boolean, List<Pair<URI, Response>>> responsesTuple =
+ traversalHttpEntry.process(dbRequestList, "JUNIT");
response = responsesTuple.getValue1().get(0).getValue1();
} catch (AAIException e) {
response = this.consumerExceptionResponseGenerator(httpHeaders, uriInfo, HttpMethod.PUT, e);
success = false;
- } catch(Exception e){
+ } catch (Exception e) {
AAIException ex = new AAIException("AAI_4000", e);
response = this.consumerExceptionResponseGenerator(httpHeaders, uriInfo, HttpMethod.PUT, ex);
success = false;
} finally {
- if(success){
- if(response != null){
- if((response.getStatus() / 100) == 2){
- logger.info("Successfully completed the DELETE request with status {} and committing it to DB", response.getStatus());
+ if (success) {
+ if (response != null) {
+ if ((response.getStatus() / 100) == 2) {
+ logger.info("Successfully completed the DELETE request with status {} and committing it to DB",
+ response.getStatus());
} else {
logFailure(HttpMethod.DELETE, response);
}
@@ -399,8 +403,9 @@ public class HttpTestUtil extends RESTAPI {
return response;
}
- public static void logFailure(HttpMethod httpMethod, Response response){
- logger.info("Unable to complete the {} request with status {} and rolling back", httpMethod.toString(), response.getStatus());
+ public static void logFailure(HttpMethod httpMethod, Response response) {
+ logger.info("Unable to complete the {} request with status {} and rolling back", httpMethod.toString(),
+ response.getStatus());
logger.info("Response body of failed request {}", response.getEntity());
}
diff --git a/aai-core/src/test/java/org/onap/aai/PayloadUtil.java b/aai-core/src/test/java/org/onap/aai/PayloadUtil.java
index 88261aa6..7ee6c39c 100644
--- a/aai-core/src/test/java/org/onap/aai/PayloadUtil.java
+++ b/aai-core/src/test/java/org/onap/aai/PayloadUtil.java
@@ -17,9 +17,10 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai;
-import org.apache.commons.io.IOUtils;
+import static org.junit.Assert.assertNotNull;
import java.io.IOException;
import java.io.InputStream;
@@ -28,7 +29,7 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import static org.junit.Assert.assertNotNull;
+import org.apache.commons.io.IOUtils;
public class PayloadUtil {
@@ -37,7 +38,8 @@ public class PayloadUtil {
public static String getExpectedPayload(String fileName) throws IOException {
- InputStream inputStream = PayloadUtil.class.getClassLoader().getResourceAsStream("payloads/expected/" + fileName);
+ InputStream inputStream =
+ PayloadUtil.class.getClassLoader().getResourceAsStream("payloads/expected/" + fileName);
String message = String.format("Unable to find the %s in src/test/resources", fileName);
assertNotNull(message, inputStream);
@@ -50,7 +52,8 @@ public class PayloadUtil {
public static String getResourcePayload(String fileName) throws IOException {
- InputStream inputStream = PayloadUtil.class.getClassLoader().getResourceAsStream("payloads/resource/" + fileName);
+ InputStream inputStream =
+ PayloadUtil.class.getClassLoader().getResourceAsStream("payloads/resource/" + fileName);
String message = String.format("Unable to find the %s in src/test/resources", fileName);
assertNotNull(message, inputStream);
@@ -63,14 +66,15 @@ public class PayloadUtil {
public static String getTemplatePayload(String fileName, Map<String, String> templateValueMap) throws Exception {
- InputStream inputStream = PayloadUtil.class.getClassLoader().getResourceAsStream("payloads/templates/" + fileName);
+ InputStream inputStream =
+ PayloadUtil.class.getClassLoader().getResourceAsStream("payloads/templates/" + fileName);
String message = String.format("Unable to find the %s in src/test/resources", fileName);
assertNotNull(message, inputStream);
String resource;
- if(cache.containsKey(fileName)){
+ if (cache.containsKey(fileName)) {
resource = cache.get(fileName);
} else {
resource = IOUtils.toString(inputStream);
@@ -81,14 +85,16 @@ public class PayloadUtil {
String resourceWithTemplateValues = resource;
- while(matcher.find()){
+ while (matcher.find()) {
int start = matcher.start() + 2;
int end = matcher.end() - 1;
String key = resource.substring(start, end);
- if(templateValueMap.containsKey(key)){
- resourceWithTemplateValues = resourceWithTemplateValues.replaceAll("\\$\\{" + key +"\\}", templateValueMap.get(key));
+ if (templateValueMap.containsKey(key)) {
+ resourceWithTemplateValues =
+ resourceWithTemplateValues.replaceAll("\\$\\{" + key + "\\}", templateValueMap.get(key));
} else {
- throw new RuntimeException("Unable to find the key value pair in map for the template processing for key " + key);
+ throw new RuntimeException(
+ "Unable to find the key value pair in map for the template processing for key " + key);
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/auth/AAIAuthCoreTest.java b/aai-core/src/test/java/org/onap/aai/auth/AAIAuthCoreTest.java
index 2c299869..d6075c1f 100644
--- a/aai-core/src/test/java/org/onap/aai/auth/AAIAuthCoreTest.java
+++ b/aai-core/src/test/java/org/onap/aai/auth/AAIAuthCoreTest.java
@@ -17,21 +17,22 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.auth;
+import static org.junit.Assert.*;
+
import org.junit.Before;
import org.junit.Test;
import org.onap.aai.AAISetup;
import org.onap.aai.auth.exceptions.AAIUnrecognizedFunctionException;
-import static org.junit.Assert.*;
-
public class AAIAuthCoreTest extends AAISetup {
private AAIAuthCore authCore;
@Before
- public void setup(){
+ public void setup() {
authCore = new AAIAuthCore("/aai");
}
@@ -40,16 +41,16 @@ public class AAIAuthCoreTest extends AAISetup {
String uri = "/aai/v3/search/edge-tag-query";
assertEquals("Get aai function name from " + uri, "search", authCore.getAuthPolicyFunctName(uri));
-
+
uri = "/aai/v10/search/edge-tag-query";
assertEquals("Get aai function name from " + uri, "search", authCore.getAuthPolicyFunctName(uri));
uri = "/aai/search/model";
assertEquals("Get aai function name from " + uri, "search", authCore.getAuthPolicyFunctName(uri));
-
+
uri = "/aai/v9/cloud-infrastructure/cloud-regions/cloud-region/somecloudregion/some-cloud-owner";
assertEquals("Get aai function name from " + uri, "cloud-infrastructure", authCore.getAuthPolicyFunctName(uri));
-
+
uri = "/aai/v8/network/pnfs/pnf/ff4ca01orc/p-interfaces";
assertEquals("Get aai function name from " + uri, "network", authCore.getAuthPolicyFunctName(uri));
@@ -91,17 +92,20 @@ public class AAIAuthCoreTest extends AAISetup {
@Test
public void validUsernameContainsTheWildcardIdAuthTest() throws AAIUnrecognizedFunctionException {
- assertTrue(authCore.authorize("cn=blah, testWildcardId, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "", "aafWildCardIssuer"));
+ assertTrue(authCore.authorize("cn=blah, testWildcardId, O=".toLowerCase(), "/aai/v0/testFunction/someUri",
+ "PUT", "", "aafWildCardIssuer"));
}
@Test
public void validUsernameContainsTheWildcardIdInvalidIssuerAuthTest() throws AAIUnrecognizedFunctionException {
- assertFalse(authCore.authorize("cn=blah, testWildcardId, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "", "invalidIssuer"));
+ assertFalse(authCore.authorize("cn=blah, testWildcardId, O=".toLowerCase(), "/aai/v0/testFunction/someUri",
+ "PUT", "", "invalidIssuer"));
}
@Test
public void invalidUsernameContainsRegularUsernameAuthTest() throws AAIUnrecognizedFunctionException {
- assertFalse(authCore.authorize("cn=blah, testUser, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", ""));
+ assertFalse(
+ authCore.authorize("cn=blah, testUser, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", ""));
}
@Test
@@ -116,93 +120,115 @@ public class AAIAuthCoreTest extends AAISetup {
@Test
public void validUsernameViaHaProxyAuthTest() throws AAIUnrecognizedFunctionException {
- assertTrue(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "testUser".toLowerCase()));
+ assertTrue(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT",
+ "testUser".toLowerCase()));
}
@Test
public void validUsernameInvalidHttpMethodViaHaProxyAuthTest() throws AAIUnrecognizedFunctionException {
- assertFalse(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "POST", "testUser".toLowerCase()));
+ assertFalse(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "POST",
+ "testUser".toLowerCase()));
}
@Test(expected = AAIUnrecognizedFunctionException.class)
public void validUsernameInvalidFunctionInURIViaHaProxyAuthTest() throws AAIUnrecognizedFunctionException {
- authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/badFunction/someUri", "PUT", "testUser".toLowerCase());
+ authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/badFunction/someUri", "PUT",
+ "testUser".toLowerCase());
}
@Test
public void invalidUsernameViaHaProxyAuthTest() throws AAIUnrecognizedFunctionException {
- assertFalse(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "invlaidTestUser".toLowerCase()));
+ assertFalse(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT",
+ "invlaidTestUser".toLowerCase()));
}
@Test
public void validUsernameIsTheExactWildcardIdViaHaProxyAuthTest() throws AAIUnrecognizedFunctionException {
- assertTrue(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "testWildcardId".toLowerCase()));
+ assertTrue(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT",
+ "testWildcardId".toLowerCase()));
}
@Test
public void validUsernameContainsTheWildcardIdViaHaProxyAuthTest() throws AAIUnrecognizedFunctionException {
- assertTrue(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "cn=blah, testWildcardId, O=".toLowerCase(), "aafWildCardIssuer"));
+ assertTrue(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT",
+ "cn=blah, testWildcardId, O=".toLowerCase(), "aafWildCardIssuer"));
}
@Test
public void invalidUsernameContainsRegularUsernameViaHaProxyAuthTest() throws AAIUnrecognizedFunctionException {
- assertFalse(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "cn=blah, testUser, O=".toLowerCase()));
+ assertFalse(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT",
+ "cn=blah, testUser, O=".toLowerCase()));
}
@Test
public void haProxyUsernameTwiceAuthTest() throws AAIUnrecognizedFunctionException {
- assertFalse(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "ha-proxy-user".toLowerCase()));
+ assertFalse(authCore.authorize("ha-proxy-user".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT",
+ "ha-proxy-user".toLowerCase()));
}
-
@Test
public void haProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException {
- assertTrue(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/util/echo", "GET", "", "aafWildCardIssuer"));
+ assertTrue(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/util/echo", "GET", "",
+ "aafWildCardIssuer"));
}
@Test
public void haProxyWildcardIdInvalidFunctionAuthTest() throws AAIUnrecognizedFunctionException {
- assertFalse(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", ""));
+ assertFalse(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(),
+ "/aai/v0/testFunction/someUri", "PUT", ""));
}
@Test
public void validUsernameViaHaProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException {
- assertTrue(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "testUser".toLowerCase(), "aafWildCardIssuer"));
+ assertTrue(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri",
+ "PUT", "testUser".toLowerCase(), "aafWildCardIssuer"));
}
@Test
public void validUsernameInvalidHttpMethodViaHaProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException {
- assertFalse(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "POST", "testUser".toLowerCase()));
+ assertFalse(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(),
+ "/aai/v0/testFunction/someUri", "POST", "testUser".toLowerCase()));
}
@Test(expected = AAIUnrecognizedFunctionException.class)
- public void validUsernameInvalidFunctionInURIViaHaProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException {
- authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/badFunction/someUri", "PUT", "testUser".toLowerCase());
+ public void validUsernameInvalidFunctionInURIViaHaProxyWildcardIdAuthTest()
+ throws AAIUnrecognizedFunctionException {
+ authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/badFunction/someUri", "PUT",
+ "testUser".toLowerCase());
}
@Test
public void invalidUsernameViaHaProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException {
- assertFalse(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "invlaidTestUser".toLowerCase()));
+ assertFalse(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(),
+ "/aai/v0/testFunction/someUri", "PUT", "invlaidTestUser".toLowerCase()));
}
@Test
- public void validUsernameIsTheExactWildcardIdViaHaProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException {
- assertTrue(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "testWildcardId".toLowerCase(), "aafWildCardIssuer"));
+ public void validUsernameIsTheExactWildcardIdViaHaProxyWildcardIdAuthTest()
+ throws AAIUnrecognizedFunctionException {
+ assertTrue(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri",
+ "PUT", "testWildcardId".toLowerCase(), "aafWildCardIssuer"));
}
@Test
- public void validUsernameContainsTheWildcardIdViaHaProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException {
- assertTrue(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "cn=blah, testWildcardId, O=".toLowerCase(), "aafWildCardIssuer"));
+ public void validUsernameContainsTheWildcardIdViaHaProxyWildcardIdAuthTest()
+ throws AAIUnrecognizedFunctionException {
+ assertTrue(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri",
+ "PUT", "cn=blah, testWildcardId, O=".toLowerCase(), "aafWildCardIssuer"));
}
@Test
- public void validUsernameContainsTheWildcardIdViaHaProxyWildcardIdInvalidIssuerAuthTest() throws AAIUnrecognizedFunctionException {
- assertFalse(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "cn=blah, testWildcardId, O=".toLowerCase(), "invalidIssuer"));
+ public void validUsernameContainsTheWildcardIdViaHaProxyWildcardIdInvalidIssuerAuthTest()
+ throws AAIUnrecognizedFunctionException {
+ assertFalse(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(),
+ "/aai/v0/testFunction/someUri", "PUT", "cn=blah, testWildcardId, O=".toLowerCase(), "invalidIssuer"));
}
@Test
- public void invalidUsernameContainsRegularUsernameViaHaProxyWildcardIdAuthTest() throws AAIUnrecognizedFunctionException {
- assertFalse(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(), "/aai/v0/testFunction/someUri", "PUT", "cn=blah, testUser, O=".toLowerCase()));
+ public void invalidUsernameContainsRegularUsernameViaHaProxyWildcardIdAuthTest()
+ throws AAIUnrecognizedFunctionException {
+ assertFalse(authCore.authorize("cn=blah, ha-proxy-wildcard-id, O=".toLowerCase(),
+ "/aai/v0/testFunction/someUri", "PUT", "cn=blah, testUser, O=".toLowerCase()));
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/auth/AAIUserTest.java b/aai-core/src/test/java/org/onap/aai/auth/AAIUserTest.java
index a90c7feb..cf5eafbd 100644
--- a/aai-core/src/test/java/org/onap/aai/auth/AAIUserTest.java
+++ b/aai-core/src/test/java/org/onap/aai/auth/AAIUserTest.java
@@ -17,13 +17,14 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.auth;
+import static org.junit.Assert.assertEquals;
+
import org.junit.Test;
import org.onap.aai.AAISetup;
-import static org.junit.Assert.assertEquals;
-
public class AAIUserTest extends AAISetup {
@Test
@@ -33,19 +34,19 @@ public class AAIUserTest extends AAISetup {
usr.setUserAccess("auth", "GET");
usr.setUserAccess("auth", "PUT");
usr.setUserAccess("authentication", "PUT", "GET", "POST");
-
+
assertEquals(true, usr.hasAccess("auth", "GET"));
assertEquals(true, usr.hasAccess("auth", "PUT"));
assertEquals(true, usr.hasAccess("authentication", "POST"));
}
-
+
@Test
public void testIsNotAuth() {
AAIUser usr = new AAIUser("testUser");
usr.addRole("testRole");
-
+
assertEquals(false, usr.hasAccess("auth", "GET"));
-
+
usr.setUserAccess("auth", "GET");
assertEquals(false, usr.hasAccess("auth", "PUT"));
}
diff --git a/aai-core/src/test/java/org/onap/aai/concurrent/AaiCallableTest.java b/aai-core/src/test/java/org/onap/aai/concurrent/AaiCallableTest.java
index 94b1ef6b..0c3857ae 100644
--- a/aai-core/src/test/java/org/onap/aai/concurrent/AaiCallableTest.java
+++ b/aai-core/src/test/java/org/onap/aai/concurrent/AaiCallableTest.java
@@ -17,32 +17,34 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.concurrent;
import static org.junit.Assert.assertTrue;
+
import java.lang.Object;
+
import org.junit.Test;
import org.onap.aai.AAISetup;
-import org.slf4j.MDC;
import org.onap.aai.concurrent.AaiCallable;
+import org.slf4j.MDC;
public class AaiCallableTest extends AAISetup {
@Test
public void testAaiCallable() {
MDC.put("test_name", "test_value");
-
+
AaiCallable<Object> task = new AaiCallable<Object>() {
@Override
public Object process() {
String mdcValue = MDC.get("test_name");
- assertTrue( "MDC value retained", "test_value".equals(mdcValue));
+ assertTrue("MDC value retained", "test_value".equals(mdcValue));
return (new Object());
}
};
try {
task.call();
- }
- catch (Exception e) {
+ } catch (Exception e) {
e.printStackTrace();
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/dbmap/AAIGraphTest.java b/aai-core/src/test/java/org/onap/aai/dbmap/AAIGraphTest.java
index 41a5f20b..48d2583d 100644
--- a/aai-core/src/test/java/org/onap/aai/dbmap/AAIGraphTest.java
+++ b/aai-core/src/test/java/org/onap/aai/dbmap/AAIGraphTest.java
@@ -17,8 +17,20 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.dbmap;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.Matchers.matchesPattern;
+import static org.junit.Assert.*;
+
+import java.io.FileNotFoundException;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphFactory;
import org.janusgraph.core.schema.JanusGraphIndex;
@@ -36,66 +48,65 @@ import org.onap.aai.schema.enums.PropertyMetadata;
import org.onap.aai.setup.SchemaVersions;
import org.onap.aai.util.AAIConstants;
-import java.io.FileNotFoundException;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.Matchers.matchesPattern;
-import static org.junit.Assert.*;
-
-public class AAIGraphTest extends AAISetup{
- @Before
- public void setup() {
- AAIGraph.getInstance();
- }
+public class AAIGraphTest extends AAISetup {
+ @Before
+ public void setup() {
+ AAIGraph.getInstance();
+ }
- @Test
- public void getRealtimeInstanceConnectionName() throws Exception {
+ @Test
+ public void getRealtimeInstanceConnectionName() throws Exception {
- JanusGraphManagement graphMgt = AAIGraph.getInstance().getGraph().openManagement();
- String connectionInstanceName = graphMgt.getOpenInstances().stream().filter(c -> c.contains("current")).findFirst().get();
- assertThat(connectionInstanceName, containsString(SERVICE_NAME));
- assertThat(connectionInstanceName, containsString("realtime"));
- assertThat(connectionInstanceName, matchesPattern("^\\d+_[\\w\\-\\d]+_" + SERVICE_NAME + "_realtime_\\d+\\(current\\)$"));
- graphMgt.rollback();
- }
+ JanusGraphManagement graphMgt = AAIGraph.getInstance().getGraph().openManagement();
+ String connectionInstanceName =
+ graphMgt.getOpenInstances().stream().filter(c -> c.contains("current")).findFirst().get();
+ assertThat(connectionInstanceName, containsString(SERVICE_NAME));
+ assertThat(connectionInstanceName, containsString("realtime"));
+ assertThat(connectionInstanceName,
+ matchesPattern("^\\d+_[\\w\\-\\d]+_" + SERVICE_NAME + "_realtime_\\d+\\(current\\)$"));
+ graphMgt.rollback();
+ }
- @Test
- public void getCachedInstanceConnectionName() throws Exception {
+ @Test
+ public void getCachedInstanceConnectionName() throws Exception {
- JanusGraphManagement graphMgt = AAIGraph.getInstance().getGraph(DBConnectionType.CACHED).openManagement();
- String connectionInstanceName = graphMgt.getOpenInstances().stream().filter(c -> c.contains("current")).findFirst().get();
- assertThat(connectionInstanceName, containsString(SERVICE_NAME));
- assertThat(connectionInstanceName, containsString("cached"));
- assertThat(connectionInstanceName, matchesPattern("^\\d+_[\\w\\-\\d]+_" + SERVICE_NAME + "_cached_\\d+\\(current\\)$"));
- graphMgt.rollback();
- }
+ JanusGraphManagement graphMgt = AAIGraph.getInstance().getGraph(DBConnectionType.CACHED).openManagement();
+ String connectionInstanceName =
+ graphMgt.getOpenInstances().stream().filter(c -> c.contains("current")).findFirst().get();
+ assertThat(connectionInstanceName, containsString(SERVICE_NAME));
+ assertThat(connectionInstanceName, containsString("cached"));
+ assertThat(connectionInstanceName,
+ matchesPattern("^\\d+_[\\w\\-\\d]+_" + SERVICE_NAME + "_cached_\\d+\\(current\\)$"));
+ graphMgt.rollback();
+ }
- @Test
- public void JanusGraphOpenNameTest() throws Exception{
- JanusGraph graph = JanusGraphFactory.open(new AAIGraphConfig.Builder(AAIConstants.REALTIME_DB_CONFIG).forService(SERVICE_NAME).withGraphType("graphType").buildConfiguration());
- JanusGraphManagement graphMgt = graph.openManagement();
- String connectionInstanceName = graphMgt.getOpenInstances().stream().filter(c -> c.contains("current")).findFirst().get();
- assertThat(connectionInstanceName,matchesPattern("^\\d+_[\\w\\-\\d]+_" + SERVICE_NAME + "_graphType_\\d+\\(current\\)$"));
- graphMgt.rollback();
- graph.close();
- }
+ @Test
+ public void JanusGraphOpenNameTest() throws Exception {
+ JanusGraph graph = JanusGraphFactory.open(new AAIGraphConfig.Builder(AAIConstants.REALTIME_DB_CONFIG)
+ .forService(SERVICE_NAME).withGraphType("graphType").buildConfiguration());
+ JanusGraphManagement graphMgt = graph.openManagement();
+ String connectionInstanceName =
+ graphMgt.getOpenInstances().stream().filter(c -> c.contains("current")).findFirst().get();
+ assertThat(connectionInstanceName,
+ matchesPattern("^\\d+_[\\w\\-\\d]+_" + SERVICE_NAME + "_graphType_\\d+\\(current\\)$"));
+ graphMgt.rollback();
+ graph.close();
+ }
- @Test (expected=FileNotFoundException.class)
- public void JanusGraphOpenNameWithInvalidFilePathTest() throws Exception{
- JanusGraph graph = JanusGraphFactory.open(new AAIGraphConfig.Builder("invalid").forService(SERVICE_NAME).withGraphType("graphType").buildConfiguration());
- JanusGraphManagement graphMgt = graph.openManagement();
- String connectionInstanceName = graphMgt.getOpenInstances().stream().filter(c -> c.contains("current")).findFirst().get();
- assertThat(connectionInstanceName,matchesPattern("^\\d+_[\\w\\-\\d]+_" + SERVICE_NAME + "_graphType_\\d+\\(current\\)$"));
- graphMgt.rollback();
- graph.close();
- }
+ @Test(expected = FileNotFoundException.class)
+ public void JanusGraphOpenNameWithInvalidFilePathTest() throws Exception {
+ JanusGraph graph = JanusGraphFactory.open(new AAIGraphConfig.Builder("invalid").forService(SERVICE_NAME)
+ .withGraphType("graphType").buildConfiguration());
+ JanusGraphManagement graphMgt = graph.openManagement();
+ String connectionInstanceName =
+ graphMgt.getOpenInstances().stream().filter(c -> c.contains("current")).findFirst().get();
+ assertThat(connectionInstanceName,
+ matchesPattern("^\\d+_[\\w\\-\\d]+_" + SERVICE_NAME + "_graphType_\\d+\\(current\\)$"));
+ graphMgt.rollback();
+ graph.close();
+ }
- @Ignore("Need to create schema specific to the test")
+ @Ignore("Need to create schema specific to the test")
@Test
public void checkIndexOfAliasedIndexedProps() throws Exception {
Set<String> aliasedIndexedProps = getAliasedIndexedProps();
@@ -104,14 +115,15 @@ public class AAIGraphTest extends AAISetup{
JanusGraphIndex index = graphMgt.getGraphIndex(aliasedIndexedProp);
assertNotNull(aliasedIndexedProp + " index exists", index);
assertEquals(aliasedIndexedProp + " index has 1 property keys", index.getFieldKeys().length, 1);
- assertThat(aliasedIndexedProp + " index indexes " + aliasedIndexedProp + " property key", index.getFieldKeys()[0].name(), is(aliasedIndexedProp));
+ assertThat(aliasedIndexedProp + " index indexes " + aliasedIndexedProp + " property key",
+ index.getFieldKeys()[0].name(), is(aliasedIndexedProp));
}
graphMgt.rollback();
}
private Set<String> getAliasedIndexedProps() {
Set<String> aliasedIndexedProps = new HashSet<>();
- LoaderFactory loaderFactory = SpringContextAware.getBean(LoaderFactory.class);
+ LoaderFactory loaderFactory = SpringContextAware.getBean(LoaderFactory.class);
SchemaVersions schemaVersions = SpringContextAware.getBean(SchemaVersions.class);
Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
Map<String, Introspector> objs = loader.getAllObjects();
diff --git a/aai-core/src/test/java/org/onap/aai/domain/restPolicyException/PolicyExceptionTest.java b/aai-core/src/test/java/org/onap/aai/domain/restPolicyException/PolicyExceptionTest.java
index e537c3df..63f01475 100644
--- a/aai-core/src/test/java/org/onap/aai/domain/restPolicyException/PolicyExceptionTest.java
+++ b/aai-core/src/test/java/org/onap/aai/domain/restPolicyException/PolicyExceptionTest.java
@@ -19,6 +19,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.domain.restPolicyException;
import static org.junit.Assert.assertEquals;
@@ -30,9 +31,9 @@ import org.junit.Before;
import org.junit.Test;
import org.onap.aai.AAISetup;
-public class PolicyExceptionTest extends AAISetup{
+public class PolicyExceptionTest extends AAISetup {
private PolicyException exception;
-
+
@Before
public void setup() {
exception = new PolicyException();
@@ -43,13 +44,13 @@ public class PolicyExceptionTest extends AAISetup{
exception.setAdditionalProperty("property1", "value1");
assertEquals(exception.getAdditionalProperties().get("property1"), "value1");
}
-
+
@Test
public void testGetMessageId() throws Exception {
exception.setMessageId("samplemessage");
assertEquals(exception.getMessageId(), "samplemessage");
}
-
+
@Test
public void testGetText() throws Exception {
exception.setText("sampletext");
@@ -63,6 +64,6 @@ public class PolicyExceptionTest extends AAISetup{
expectedVariables.add("secondvariable");
exception.setVariables(expectedVariables);
assertEquals(exception.getVariables(), expectedVariables);
-
+
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/domain/restPolicyException/RequestErrorTest.java b/aai-core/src/test/java/org/onap/aai/domain/restPolicyException/RequestErrorTest.java
index 77e95e48..803337aa 100644
--- a/aai-core/src/test/java/org/onap/aai/domain/restPolicyException/RequestErrorTest.java
+++ b/aai-core/src/test/java/org/onap/aai/domain/restPolicyException/RequestErrorTest.java
@@ -19,6 +19,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.domain.restPolicyException;
import static org.junit.Assert.assertEquals;
@@ -27,9 +28,9 @@ import org.junit.Before;
import org.junit.Test;
import org.onap.aai.AAISetup;
-public class RequestErrorTest extends AAISetup{
+public class RequestErrorTest extends AAISetup {
private RequestError reqError;
-
+
@Before
public void setup() {
reqError = new RequestError();
diff --git a/aai-core/src/test/java/org/onap/aai/exceptions/AAIExceptionTest.java b/aai-core/src/test/java/org/onap/aai/exceptions/AAIExceptionTest.java
index 99597f7f..aef06fae 100644
--- a/aai-core/src/test/java/org/onap/aai/exceptions/AAIExceptionTest.java
+++ b/aai-core/src/test/java/org/onap/aai/exceptions/AAIExceptionTest.java
@@ -17,20 +17,21 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.exceptions;
+import static org.junit.Assert.assertEquals;
+
import org.junit.Test;
import org.onap.aai.AAISetup;
-import static org.junit.Assert.assertEquals;
-
public class AAIExceptionTest extends AAISetup {
private static final String code = "4004";
private static final String details = "This is a detailed description of the exception.";
private static final Throwable cause = new RuntimeException("This is a runtime exception.");
private static final Throwable noMessage = new RuntimeException();
-
+
/**
* Test constructor with 0 params.
*
@@ -41,7 +42,7 @@ public class AAIExceptionTest extends AAISetup {
AAIException exception = new AAIException();
assertEquals(exception, exception);
}
-
+
/**
* Test constructor with 1 params.
*
@@ -52,7 +53,7 @@ public class AAIExceptionTest extends AAISetup {
AAIException exception = new AAIException(code);
assertEquals(exception, exception);
}
-
+
/**
* Test constructor with 2 params details.
*
@@ -63,7 +64,7 @@ public class AAIExceptionTest extends AAISetup {
AAIException exception = new AAIException(code, details);
assertEquals(details, exception.getMessage());
}
-
+
/**
* Test constructor with 2 params cause.
*
@@ -74,7 +75,7 @@ public class AAIExceptionTest extends AAISetup {
AAIException exception = new AAIException(code, cause);
assertEquals("java.lang.RuntimeException: This is a runtime exception.", exception.getMessage());
}
-
+
/**
* Test constructor with 2 params null message.
*
@@ -85,7 +86,7 @@ public class AAIExceptionTest extends AAISetup {
AAIException exception = new AAIException(code, noMessage);
assertEquals(noMessage.toString(), exception.getMessage());
}
-
+
/**
* Test constructor with 3 params.
*
@@ -97,7 +98,7 @@ public class AAIExceptionTest extends AAISetup {
String details = "This is a detailed description of the exception.";
assertEquals(details, exception.getMessage());
}
-
+
/**
* Test constructor with 3 params null message.
*
diff --git a/aai-core/src/test/java/org/onap/aai/exceptions/AAIExceptionWithInfoTest.java b/aai-core/src/test/java/org/onap/aai/exceptions/AAIExceptionWithInfoTest.java
index b0727813..34620731 100644
--- a/aai-core/src/test/java/org/onap/aai/exceptions/AAIExceptionWithInfoTest.java
+++ b/aai-core/src/test/java/org/onap/aai/exceptions/AAIExceptionWithInfoTest.java
@@ -17,18 +17,18 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.exceptions;
-import org.junit.Test;
-import org.onap.aai.AAISetup;
+import static org.junit.Assert.assertEquals;
import java.util.HashMap;
-import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import org.onap.aai.AAISetup;
public class AAIExceptionWithInfoTest extends AAISetup {
-
private static final HashMap<String, Object> map = new HashMap<String, Object>();
{
@@ -124,11 +124,11 @@ public class AAIExceptionWithInfoTest extends AAISetup {
HashMap<String, Object> newMap = new HashMap<String, Object>();
newMap.put("itemInteger", 2);
exception.setInfoHash(newMap);
-
+
assertEquals(newMap, exception.getInfoHash());
assertEquals(info, exception.getInfo());
}
-
+
/**
* Test set info.
*/
@@ -138,7 +138,7 @@ public class AAIExceptionWithInfoTest extends AAISetup {
String newInfo = "This is updated info.";
exception.setInfo(newInfo);
-
+
assertEquals(map, exception.getInfoHash());
assertEquals(newInfo, exception.getInfo());
}
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/IntrospectorTestSpec.java b/aai-core/src/test/java/org/onap/aai/introspection/IntrospectorTestSpec.java
index 44cbe6cc..804ce1bd 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/IntrospectorTestSpec.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/IntrospectorTestSpec.java
@@ -17,41 +17,31 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.introspection;
+import static org.junit.Assert.assertEquals;
+
import org.onap.aai.AAISetup;
import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
-import static org.junit.Assert.assertEquals;
-
public abstract class IntrospectorTestSpec extends AAISetup {
-
-
/**
* Container test set.
*
* @param wrappedPortGroups the wrapped port groups
- * @throws AAIUnknownObjectException
+ * @throws AAIUnknownObjectException
*/
protected void containerTestSet(Introspector wrappedPortGroups) throws AAIUnknownObjectException {
-
- assertEquals(
- "isContainer",
- true,
- wrappedPortGroups.isContainer());
-
- assertEquals(
- "newInstanceOfNestedProperty",
- "PortGroup",
+
+ assertEquals("isContainer", true, wrappedPortGroups.isContainer());
+
+ assertEquals("newInstanceOfNestedProperty", "PortGroup",
wrappedPortGroups.newInstanceOfNestedProperty("port-group").getClass().getSimpleName());
-
- assertEquals(
- "isComplexGenericType",
- true,
- wrappedPortGroups.isComplexGenericType("port-group"));
-
-
+
+ assertEquals("isComplexGenericType", true, wrappedPortGroups.isComplexGenericType("port-group"));
+
}
-
+
}
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/JSONStrategyTest.java b/aai-core/src/test/java/org/onap/aai/introspection/JSONStrategyTest.java
index 65b13c27..8b44b312 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/JSONStrategyTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/JSONStrategyTest.java
@@ -17,26 +17,26 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.introspection;
-import org.json.simple.JSONArray;
+import java.util.HashSet;
+import java.util.Set;
+import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.onap.aai.AAISetup;
-import java.util.HashSet;
-import java.util.Set;
-
-public class JSONStrategyTest extends AAISetup{
+public class JSONStrategyTest extends AAISetup {
private JSONStrategy jsonStrategy;
private JSONStrategy jsonStrategyContainer;
private JSONStrategy jsonStrategyComplex;
@Before
- public void setup(){
+ public void setup() {
try {
JSONObject pserver = new JSONObject();
pserver.put("hostname", "value1");
@@ -54,14 +54,13 @@ public class JSONStrategyTest extends AAISetup{
JSONObject complex = new JSONObject();
complex.put("pserver", pserver);
jsonStrategyComplex = new JSONStrategy(complex, "pservers-type");
- }
- catch (Exception e){
+ } catch (Exception e) {
System.out.println("error during setup: " + e.getMessage());
}
}
@Test
- public void getSetTest(){
+ public void getSetTest() {
jsonStrategy.setValue("ramInMegabytes", 1024);
Assert.assertEquals("value1", jsonStrategy.getValue("hostname"));
Assert.assertEquals(4, jsonStrategy.getValue("numberofCpus"));
@@ -79,7 +78,8 @@ public class JSONStrategyTest extends AAISetup{
@Test
public void getGenericTypeTest() {
// If the values of this object are arrays, return the type within the array
- Assert.assertEquals("class org.json.simple.JSONObject" , jsonStrategyContainer.getGenericTypeClass("pservers").toString());
+ Assert.assertEquals("class org.json.simple.JSONObject",
+ jsonStrategyContainer.getGenericTypeClass("pservers").toString());
}
@Test
@@ -87,6 +87,7 @@ public class JSONStrategyTest extends AAISetup{
Assert.assertEquals("org.json.simple.JSONObject", jsonStrategy.getJavaClassName());
Assert.assertEquals("org.json.simple.JSONObject", jsonStrategyContainer.getJavaClassName());
}
+
@Test
public void getTypeTest() {
Assert.assertEquals("java.lang.String", jsonStrategy.getType("hostname"));
@@ -100,16 +101,19 @@ public class JSONStrategyTest extends AAISetup{
@Test
public void newInstanceOfPropertyTest() {
- Assert.assertEquals("class org.json.simple.JSONArray", jsonStrategyContainer.newInstanceOfProperty("pservers").getClass().toString());
+ Assert.assertEquals("class org.json.simple.JSONArray",
+ jsonStrategyContainer.newInstanceOfProperty("pservers").getClass().toString());
}
@Test(expected = NullPointerException.class)
public void newInvalidInstanceOfPropertyTest() {
Assert.assertEquals(null, jsonStrategyContainer.newInstanceOfProperty("invalid").getClass().toString());
}
+
@Test
public void newInstanceOfNestedPropertyTest() {
- Assert.assertEquals("class org.json.simple.JSONObject", jsonStrategyContainer.newInstanceOfNestedProperty("pservers").getClass().toString());
+ Assert.assertEquals("class org.json.simple.JSONObject",
+ jsonStrategyContainer.newInstanceOfNestedProperty("pservers").getClass().toString());
}
@Test(expected = NullPointerException.class)
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/MoxyEngineTest.java b/aai-core/src/test/java/org/onap/aai/introspection/MoxyEngineTest.java
index 463c9174..0e6a9aab 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/MoxyEngineTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/MoxyEngineTest.java
@@ -17,31 +17,30 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.introspection;
import org.junit.Test;
import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
import org.springframework.test.annotation.DirtiesContext;
-
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class MoxyEngineTest extends IntrospectorTestSpec {
/**
* Container object.
- * @throws AAIUnknownObjectException
+ *
+ * @throws AAIUnknownObjectException
*/
@Test
public void containerObject() throws AAIUnknownObjectException {
-
+
Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion());
-
+
Introspector obj = loader.introspectorFromName("port-groups");
this.containerTestSet(obj);
-
+
}
-
-
-
+
}
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/PropertyPredicatesTest.java b/aai-core/src/test/java/org/onap/aai/introspection/PropertyPredicatesTest.java
index 190e3243..4473c8d4 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/PropertyPredicatesTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/PropertyPredicatesTest.java
@@ -17,58 +17,56 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.introspection;
-import org.junit.Before;
+import static org.hamcrest.Matchers.hasItems;
+import static org.hamcrest.Matchers.not;
+import static org.junit.Assert.assertThat;
+import java.util.Set;
+
+import org.junit.Before;
import org.junit.Test;
import org.onap.aai.AAISetup;
import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
import org.springframework.test.annotation.DirtiesContext;
-import java.util.Set;
-
-import static org.hamcrest.Matchers.hasItems;
-import static org.hamcrest.Matchers.not;
-import static org.junit.Assert.assertThat;
-
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class PropertyPredicatesTest extends AAISetup {
private Loader loader;
private ModelType introspectorFactoryType = ModelType.MOXY;
private Introspector obj;
-
+
@Before
public void setup() throws Exception {
loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion());
obj = loader.introspectorFromName("generic-vnf");
}
-
+
@Test
public void includeInTestGeneration() throws AAIUnknownObjectException {
-
+
Set<String> props = obj.getProperties(PropertyPredicates.includeInTestGeneration());
- assertThat("props not found", props,
- not(hasItems("model-invariant-id", "model-version-id")));
+ assertThat("props not found", props, not(hasItems("model-invariant-id", "model-version-id")));
}
-
+
@Test
public void isVisible() throws AAIUnknownObjectException {
-
+
Set<String> props = obj.getProperties(PropertyPredicates.isVisible());
assertThat("props not found", props, hasItems("model-invariant-id", "model-version-id"));
}
-
+
@Test
public void all() throws AAIUnknownObjectException {
-
+
Set<String> props = obj.getProperties();
assertThat("all found", props, hasItems("model-invariant-id", "model-version-id"));
}
-
}
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/generator/CreateExampleTest.java b/aai-core/src/test/java/org/onap/aai/introspection/generator/CreateExampleTest.java
index c7d4cf82..9c03331f 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/generator/CreateExampleTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/generator/CreateExampleTest.java
@@ -17,8 +17,15 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.introspection.generator;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -28,35 +35,27 @@ import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.*;
import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
public class CreateExampleTest extends AAISetup {
-
- private static CreateExample createExample;
- private Loader loader;
+
+ private static CreateExample createExample;
+ private Loader loader;
private static boolean classLoaded = false;
-
-
+
@BeforeClass
public static void setUp() {
-
-
+
}
-
-
+
@Before
- public void createLoaderVersion(){
- if(!classLoaded){
+ public void createLoaderVersion() {
+ if (!classLoaded) {
loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getAppRootVersion());
createExample = new CreateExample(loader, "edge-prop-names");
classLoaded = false;
}
}
-
+
@Test
public void testGetExampleObject() throws AAIException {
Introspector introspector = loader.introspectorFromName("edge-prop-names");
@@ -70,7 +69,7 @@ public class CreateExampleTest extends AAISetup {
Introspector introspector = loader.introspectorFromName("edge-prop-names");
createExample.processPrimitive(propName, introspector);
}
-
+
@Test
public void testProcessPrimitiveLong() throws AAIUnknownObjectException {
String propName = "vlan-id-inner";
@@ -84,14 +83,14 @@ public class CreateExampleTest extends AAISetup {
Introspector introspector = loader.introspectorFromName("vserver");
createExample.processPrimitive(propName, introspector);
}
-
+
@Test
public void testProcessPrimitiveInteger() throws AAIUnknownObjectException {
String propName = "module-index";
Introspector introspector = loader.introspectorFromName("vf-module");
createExample.processPrimitive(propName, introspector);
}
-
+
@Test
public void testProcessPrimitiveList() throws AAIUnknownObjectException {
String propName = "ipaddress-v4-vig";
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java
index f9911295..79597355 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataCopyTest.java
@@ -17,15 +17,29 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.introspection.sideeffect;
-import org.janusgraph.core.JanusGraphFactory;
-import org.janusgraph.core.JanusGraph;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.Collection;
+
import org.apache.commons.io.IOUtils;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.janusgraph.core.JanusGraph;
+import org.janusgraph.core.JanusGraphFactory;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
@@ -35,95 +49,85 @@ import org.mockito.MockitoAnnotations;
import org.onap.aai.AAISetup;
import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.dbmap.DBConnectionType;
+import org.onap.aai.edges.enums.EdgeProperty;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.*;
-
import org.onap.aai.introspection.sideeffect.exceptions.AAIMissingRequiredPropertyException;
import org.onap.aai.parsers.query.QueryParser;
import org.onap.aai.serialization.db.DBSerializer;
-import org.onap.aai.edges.enums.EdgeProperty;
-import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.JanusGraphDBEngine;
+import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.lang.reflect.InvocationTargetException;
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
-import java.util.Arrays;
-import java.util.Collection;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
@RunWith(value = Parameterized.class)
-public class DataCopyTest extends AAISetup{
+public class DataCopyTest extends AAISetup {
-
-
private static JanusGraph graph;
private final static ModelType introspectorFactoryType = ModelType.MOXY;
private final static DBConnectionType type = DBConnectionType.REALTIME;
private static Loader loader;
private static TransactionalGraphEngine dbEngine;
- @Mock private Vertex self;
- @Mock private VertexProperty<String> prop;
- @Mock private QueryParser uriQuery;
- @Rule public ExpectedException thrown = ExpectedException.none();
+ @Mock
+ private Vertex self;
+ @Mock
+ private VertexProperty<String> prop;
+ @Mock
+ private QueryParser uriQuery;
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
-
-
@Parameterized.Parameter(value = 0)
public QueryStyle queryStyle;
@Parameterized.Parameters(name = "QueryStyle.{0}")
public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][]{
- {QueryStyle.TRAVERSAL},
- {QueryStyle.TRAVERSAL_URI}
- });
+ return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
}
-
-
+
@BeforeClass
public static void setup() throws NoSuchFieldException, SecurityException, Exception {
- graph = JanusGraphFactory.build().set("storage.backend","inmemory").open();
+ graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
System.setProperty("AJSC_HOME", ".");
System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
-
- graph.traversal().addV("aai-node-type", "model", "model-invariant-id", "key1", AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key1").as("v1")
- .addV("aai-node-type", "model-ver", "model-ver", "myValue", "model-version-id", "key2", "model-version", "testValue", AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key1/model-vers/model-ver/key2")
+
+ graph.traversal()
+ .addV("aai-node-type", "model", "model-invariant-id", "key1", AAIProperties.AAI_URI,
+ "/service-design-and-creation/models/model/key1")
+ .as("v1")
+ .addV("aai-node-type", "model-ver", "model-ver", "myValue", "model-version-id", "key2", "model-version",
+ "testValue", AAIProperties.AAI_URI,
+ "/service-design-and-creation/models/model/key1/model-vers/model-ver/key2")
.addOutE("org.onap.relationships.inventory.BelongsTo", "v1", EdgeProperty.CONTAINS.toString(), true)
- .addV("aai-node-type", "model", "model-invariant-id", "key3", AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key3").as("v2")
- .addV("aai-node-type", "model-ver", "model-ver", "myValue", "model-version-id", "key4", AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key3/model-vers/model-ver/key4")
+ .addV("aai-node-type", "model", "model-invariant-id", "key3", AAIProperties.AAI_URI,
+ "/service-design-and-creation/models/model/key3")
+ .as("v2")
+ .addV("aai-node-type", "model-ver", "model-ver", "myValue", "model-version-id", "key4",
+ AAIProperties.AAI_URI,
+ "/service-design-and-creation/models/model/key3/model-vers/model-ver/key4")
.addOutE("org.onap.relationships.inventory.BelongsTo", "v2", EdgeProperty.CONTAINS.toString(), true)
- .next();
+ .next();
graph.tx().commit();
}
-
+
@AfterClass
public static void tearDown() {
graph.tx().rollback();
graph.close();
}
-
+
@Before
public void initMock() {
loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion());
MockitoAnnotations.initMocks(this);
- dbEngine = new JanusGraphDBEngine(
- queryStyle,
- type,
- loader);
+ dbEngine = new JanusGraphDBEngine(queryStyle, type, loader);
}
-
+
@Test
- public void runPopulatePersonaModelVer() throws URISyntaxException, AAIException, UnsupportedEncodingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, MalformedURLException {
-
+ public void runPopulatePersonaModelVer() throws URISyntaxException, AAIException, UnsupportedEncodingException,
+ IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException,
+ InstantiationException, NoSuchMethodException, MalformedURLException {
+
final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
final Introspector obj = loader.introspectorFromName("generic-vnf");
obj.setValue("vnf-id", "myId");
@@ -137,25 +141,26 @@ public class DataCopyTest extends AAISetup{
when(adminSpy.getTraversalSource()).thenReturn(traversal);
when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop);
when(prop.orElse(null)).thenReturn(obj.getURI());
- DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
- SideEffectRunner runner = new SideEffectRunner
- .Builder(spy, serializer).addSideEffect(DataCopy.class).build();
-
+ DBSerializer serializer =
+ new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
+ SideEffectRunner runner = new SideEffectRunner.Builder(spy, serializer).addSideEffect(DataCopy.class).build();
+
runner.execute(obj, self);
assertEquals("value populated", "testValue", obj.getValue("persona-model-version"));
-
+
g.tx().rollback();
-
-
+
}
-
+
@Test
- public void verifyNestedSideEffect() throws URISyntaxException, AAIException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, IOException {
-
+ public void verifyNestedSideEffect()
+ throws URISyntaxException, AAIException, IllegalAccessException, IllegalArgumentException,
+ InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, IOException {
+
final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
final Introspector obj = loader.unmarshal("customer", this.getJsonString("nested-case.json"));
- //System.out.println(obj.marshal(true));
+ // System.out.println(obj.marshal(true));
TransactionalGraphEngine spy = spy(dbEngine);
TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
Graph g = graph.newTransaction();
@@ -166,19 +171,21 @@ public class DataCopyTest extends AAISetup{
when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop);
when(prop.orElse(null)).thenReturn(obj.getURI());
when(uriQuery.isDependent()).thenReturn(false);
- DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
- Vertex v= serializer.createNewVertex(obj);
+ DBSerializer serializer =
+ new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
+ Vertex v = serializer.createNewVertex(obj);
serializer.serializeToDb(obj, v, uriQuery, obj.getURI(), "test");
-
- assertEquals("nested value populated", "testValue", g.traversal().V().has("service-instance-id", "nested-instance-key").next().property("persona-model-version").orElse(""));
+
+ assertEquals("nested value populated", "testValue", g.traversal().V()
+ .has("service-instance-id", "nested-instance-key").next().property("persona-model-version").orElse(""));
g.tx().rollback();
}
-
+
@Test
public void expectedMissingPropertyExceptionInURI() throws AAIException, UnsupportedEncodingException {
-
+
final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
final Introspector obj = loader.introspectorFromName("generic-vnf");
obj.setValue("vnf-id", "myId");
@@ -192,14 +199,14 @@ public class DataCopyTest extends AAISetup{
when(adminSpy.getTraversalSource()).thenReturn(traversal);
when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop);
when(prop.orElse(null)).thenReturn(obj.getURI());
- DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
- SideEffectRunner runner = new SideEffectRunner
- .Builder(spy, serializer).addSideEffect(DataCopy.class).build();
-
+ DBSerializer serializer =
+ new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
+ SideEffectRunner runner = new SideEffectRunner.Builder(spy, serializer).addSideEffect(DataCopy.class).build();
+
thrown.expect(AAIMissingRequiredPropertyException.class);
runner.execute(obj, self);
}
-
+
@Test
public void expectedMissingPropertyExceptionForResultingObject() throws AAIException, UnsupportedEncodingException {
final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
@@ -216,14 +223,14 @@ public class DataCopyTest extends AAISetup{
when(adminSpy.getTraversalSource()).thenReturn(traversal);
when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop);
when(prop.orElse(null)).thenReturn(obj.getURI());
- DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
- SideEffectRunner runner = new SideEffectRunner
- .Builder(spy, serializer).addSideEffect(DataCopy.class).build();
-
+ DBSerializer serializer =
+ new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
+ SideEffectRunner runner = new SideEffectRunner.Builder(spy, serializer).addSideEffect(DataCopy.class).build();
+
thrown.expect(AAIMissingRequiredPropertyException.class);
runner.execute(obj, self);
}
-
+
@Test
public void expectNoProcessingWithNoProperties() throws AAIException, UnsupportedEncodingException {
final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
@@ -238,24 +245,23 @@ public class DataCopyTest extends AAISetup{
when(adminSpy.getTraversalSource()).thenReturn(traversal);
when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop);
when(prop.orElse(null)).thenReturn(obj.getURI());
- DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
- SideEffectRunner runner = new SideEffectRunner
- .Builder(spy, serializer).addSideEffect(DataCopy.class).build();
-
+ DBSerializer serializer =
+ new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
+ SideEffectRunner runner = new SideEffectRunner.Builder(spy, serializer).addSideEffect(DataCopy.class).build();
+
runner.execute(obj, self);
-
+
assertEquals("no model-version-id", true, obj.getValue("model-version-id") == null);
assertEquals("no model-invariant-id", true, obj.getValue("model-invariant-id") == null);
-
+
}
-
+
private String getJsonString(String filename) throws IOException {
-
-
+
FileInputStream is = new FileInputStream("src/test/resources/oxm/sideeffect/" + filename);
- String s = IOUtils.toString(is, "UTF-8");
+ String s = IOUtils.toString(is, "UTF-8");
IOUtils.closeQuietly(is);
-
+
return s;
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataLinkTest.java b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataLinkTest.java
index 5b9a0fa6..cec342ea 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataLinkTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/DataLinkTest.java
@@ -17,18 +17,32 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.introspection.sideeffect;
-import org.janusgraph.core.JanusGraphFactory;
-import org.janusgraph.core.JanusGraph;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.*;
+import org.janusgraph.core.JanusGraph;
+import org.janusgraph.core.JanusGraphFactory;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
@@ -39,28 +53,15 @@ import org.onap.aai.AAISetup;
import org.onap.aai.DataLinkSetup;
import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.dbmap.DBConnectionType;
+import org.onap.aai.edges.enums.EdgeProperty;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.*;
import org.onap.aai.parsers.query.QueryParser;
import org.onap.aai.serialization.db.DBSerializer;
-import org.onap.aai.edges.enums.EdgeProperty;
-import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.JanusGraphDBEngine;
+import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
-import java.io.UnsupportedEncodingException;
-import java.lang.reflect.InvocationTargetException;
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
@RunWith(value = Parameterized.class)
public class DataLinkTest extends DataLinkSetup {
@@ -69,71 +70,88 @@ public class DataLinkTest extends DataLinkSetup {
private final static DBConnectionType type = DBConnectionType.REALTIME;
private static Loader loader;
private static TransactionalGraphEngine dbEngine;
- @Mock private QueryParser parser;
- @Mock private Vertex self;
- @Mock private VertexProperty<String> prop;
+ @Mock
+ private QueryParser parser;
+ @Mock
+ private Vertex self;
+ @Mock
+ private VertexProperty<String> prop;
@Rule
public ExpectedException thrown = ExpectedException.none();
-
-
@Parameterized.Parameter(value = 0)
public QueryStyle queryStyle;
@Parameterized.Parameters(name = "QueryStyle.{0}")
public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][]{
- {QueryStyle.TRAVERSAL},
- {QueryStyle.TRAVERSAL_URI}
- });
+ return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
}
-
+
@BeforeClass
public static void setup() throws NoSuchFieldException, SecurityException, Exception {
- graph = JanusGraphFactory.build().set("storage.backend","inmemory").open();
-
+ graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
- graph.traversal().addV("aai-node-type", "vpn-binding", "vpn-id", "addKey", AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/addKey").as("v1")
- .addV("aai-node-type", "vpn-binding", "vpn-id", "modifyKey", AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/modifyKey").as("v2")
- .addV("aai-node-type", "route-target", "global-route-target", "modifyTargetKey", "route-target-role", "modifyRoleKey", "linked", true, AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/modifyKey/route-targets/route-target/modifyTargetKey/modifyRoleKey")
+ graph.traversal()
+ .addV("aai-node-type", "vpn-binding", "vpn-id", "addKey", AAIProperties.AAI_URI,
+ "/network/vpn-bindings/vpn-binding/addKey")
+ .as("v1")
+ .addV("aai-node-type", "vpn-binding", "vpn-id", "modifyKey", AAIProperties.AAI_URI,
+ "/network/vpn-bindings/vpn-binding/modifyKey")
+ .as("v2")
+ .addV("aai-node-type", "route-target", "global-route-target", "modifyTargetKey", "route-target-role",
+ "modifyRoleKey", "linked", true, AAIProperties.AAI_URI,
+ "/network/vpn-bindings/vpn-binding/modifyKey/route-targets/route-target/modifyTargetKey/modifyRoleKey")
.addOutE("org.onap.relationships.inventory.BelongsTo", "v2", EdgeProperty.CONTAINS.toString(), true)
- .addV("aai-node-type", "vpn-binding", "vpn-id", "deleteKey",AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/deleteKey").as("v3" )
- .addV("aai-node-type", "route-target", "global-route-target", "deleteTargetKey", "route-target-role", "deleteRoleKey", "linked", true, AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/deleteKey/route-targets/route-target/deleteTargetKey/deleteRoleKey")
+ .addV("aai-node-type", "vpn-binding", "vpn-id", "deleteKey", AAIProperties.AAI_URI,
+ "/network/vpn-bindings/vpn-binding/deleteKey")
+ .as("v3")
+ .addV("aai-node-type", "route-target", "global-route-target", "deleteTargetKey", "route-target-role",
+ "deleteRoleKey", "linked", true, AAIProperties.AAI_URI,
+ "/network/vpn-bindings/vpn-binding/deleteKey/route-targets/route-target/deleteTargetKey/deleteRoleKey")
.addOutE("org.onap.relationships.inventory.BelongsTo", "v3", EdgeProperty.CONTAINS.toString(), true)
- .addV("aai-node-type", "vpn-binding", "vpn-id", "getKey", AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/getKey").as("v4")
- .addV("aai-node-type", "route-target", "global-route-target", "getTargetKey", "route-target-role", "getRoleKey", "linked", true, AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/getKey/route-targets/route-target/getTargetKeyNoLink/getRoleKeyNoLink")
+ .addV("aai-node-type", "vpn-binding", "vpn-id", "getKey", AAIProperties.AAI_URI,
+ "/network/vpn-bindings/vpn-binding/getKey")
+ .as("v4")
+ .addV("aai-node-type", "route-target", "global-route-target", "getTargetKey", "route-target-role",
+ "getRoleKey", "linked", true, AAIProperties.AAI_URI,
+ "/network/vpn-bindings/vpn-binding/getKey/route-targets/route-target/getTargetKeyNoLink/getRoleKeyNoLink")
.addOutE("org.onap.relationships.inventory.BelongsTo", "v4", EdgeProperty.CONTAINS.toString(), true)
- .addV("aai-node-type", "vpn-binding", "vpn-id", "getKeyNoLink", AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/getKeyNoLink").as("v5")
- .addV("aai-node-type", "route-target", "global-route-target", "getTargetKeyNoLink", "route-target-role", "getRoleKeyNoLink", AAIProperties.AAI_URI, "/network/vpn-bindings/vpn-binding/getKeyNoLink/route-targets/route-target/getTargetKeyNoLink/getRoleKeyNoLink")
+ .addV("aai-node-type", "vpn-binding", "vpn-id", "getKeyNoLink", AAIProperties.AAI_URI,
+ "/network/vpn-bindings/vpn-binding/getKeyNoLink")
+ .as("v5")
+ .addV("aai-node-type", "route-target", "global-route-target", "getTargetKeyNoLink", "route-target-role",
+ "getRoleKeyNoLink", AAIProperties.AAI_URI,
+ "/network/vpn-bindings/vpn-binding/getKeyNoLink/route-targets/route-target/getTargetKeyNoLink/getRoleKeyNoLink")
.addOutE("org.onap.relationships.inventory.BelongsTo", "v5", EdgeProperty.CONTAINS.toString(), true)
- .next();
+ .next();
graph.tx().commit();
- /*Commented for SysOut issues
+ /*
+ * Commented for SysOut issues
*/
- //graph.traversal().V().has("aai-uri","/network/vpn-bindings/vpn-binding/deleteKey").properties().forEachRemaining(p->System.out.println(p.key() +" : " + p.value()));
-
+ // graph.traversal().V().has("aai-uri","/network/vpn-bindings/vpn-binding/deleteKey").properties().forEachRemaining(p->System.out.println(p.key()
+ // +" : " + p.value()));
+
}
-
+
@AfterClass
public static void tearDown() {
graph.tx().rollback();
graph.close();
}
-
+
@Before
public void initMock() {
loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion());
MockitoAnnotations.initMocks(this);
- dbEngine = new JanusGraphDBEngine(
- queryStyle,
- type,
- loader);
+ dbEngine = new JanusGraphDBEngine(queryStyle, type, loader);
}
-
+
@Test
- public void verifyCreationOfVertex() throws URISyntaxException, AAIException, UnsupportedEncodingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, MalformedURLException {
-
+ public void verifyCreationOfVertex() throws URISyntaxException, AAIException, UnsupportedEncodingException,
+ IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException,
+ InstantiationException, NoSuchMethodException, MalformedURLException {
+
final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion());
final Introspector obj = loader.introspectorFromName("vpn-binding");
obj.setValue("vpn-id", "addKey");
@@ -143,44 +161,48 @@ public class DataLinkTest extends DataLinkSetup {
TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
Graph g = graph.newTransaction();
GraphTraversalSource traversal = g.traversal();
-// Graph g = graph.newTransaction();
-// GraphTraversalSource traversal = g;
- // System.out.println("Begin method inventory:");
+ // Graph g = graph.newTransaction();
+ // GraphTraversalSource traversal = g;
+ // System.out.println("Begin method inventory:");
Iterator<Vertex> vertexItr = traversal.V();
- while( vertexItr != null && vertexItr.hasNext() ){
+ while (vertexItr != null && vertexItr.hasNext()) {
Vertex v = vertexItr.next();
- // System.out.println("\nnodeType="+v.<String>property("aai-node-type"));
- for(String key: v.keys()) {
- // System.out.println("label="+v.label()+";key= "+key+";value= "+v.value(key)+";id= "+v.id());
+ // System.out.println("\nnodeType="+v.<String>property("aai-node-type"));
+ for (String key : v.keys()) {
+ // System.out.println("label="+v.label()+";key= "+key+";value= "+v.value(key)+";id= "+v.id());
}
Direction d = null;
Iterator<Edge> edgeItr = v.edges(Direction.BOTH);
- while( edgeItr != null && edgeItr.hasNext() ){
+ while (edgeItr != null && edgeItr.hasNext()) {
Edge e = edgeItr.next();
- //System.out.println("outV="+e.outVertex().property(AAIProperties.NODE_TYPE)+"/"+e.outVertex().id()+";inV= "+e.inVertex().property(AAIProperties.NODE_TYPE)+"/"+e.inVertex().id());
+ // System.out.println("outV="+e.outVertex().property(AAIProperties.NODE_TYPE)+"/"+e.outVertex().id()+";inV=
+ // "+e.inVertex().property(AAIProperties.NODE_TYPE)+"/"+e.inVertex().id());
}
}
- //System.out.println("End method inventory:");
+ // System.out.println("End method inventory:");
when(spy.asAdmin()).thenReturn(adminSpy);
when(adminSpy.getTraversalSource()).thenReturn(traversal);
when(spy.tx()).thenReturn(g);
when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop);
when(prop.orElse(null)).thenReturn(obj.getURI());
- DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
- SideEffectRunner runner = new SideEffectRunner
- .Builder(spy, serializer).addSideEffect(DataLinkWriter.class).build();
-
+ DBSerializer serializer =
+ new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
+ SideEffectRunner runner =
+ new SideEffectRunner.Builder(spy, serializer).addSideEffect(DataLinkWriter.class).build();
+
runner.execute(obj, self);
- assertEquals("route-target vertex found", true, traversal.V()
- .has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "key1").has("route-target-role", "key2").has("linked", true).hasNext());
+ assertEquals("route-target vertex found", true, traversal.V().has(AAIProperties.NODE_TYPE, "route-target")
+ .has("global-route-target", "key1").has("route-target-role", "key2").has("linked", true).hasNext());
g.tx().rollback();
-
+
}
-
+
@Test
- public void verifyModificationOfVertex() throws URISyntaxException, AAIException, UnsupportedEncodingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, MalformedURLException {
-
+ public void verifyModificationOfVertex() throws URISyntaxException, AAIException, UnsupportedEncodingException,
+ IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException,
+ InstantiationException, NoSuchMethodException, MalformedURLException {
+
final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion());
final Introspector obj = loader.introspectorFromName("vpn-binding");
obj.setValue("vpn-id", "modifyKey");
@@ -188,86 +210,101 @@ public class DataLinkTest extends DataLinkSetup {
obj.setValue("route-target-role", "modifyRoleKey2");
TransactionalGraphEngine spy = spy(dbEngine);
TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
-// Graph g = graph.newTransaction();
-// GraphTraversalSource traversal = g;
+ // Graph g = graph.newTransaction();
+ // GraphTraversalSource traversal = g;
Graph g = graph.newTransaction();
GraphTraversalSource traversal = g.traversal();
Iterator<Vertex> vertexItr = traversal.V();
- while( vertexItr != null && vertexItr.hasNext() ){
+ while (vertexItr != null && vertexItr.hasNext()) {
Vertex v = vertexItr.next();
- //System.out.println("\nnodeType="+v.<String>property("aai-node-type"));
- for(String key: v.keys()) {
- //System.out.println("label="+v.label()+";key= "+key+";value= "+v.value(key)+"/"+v.id());
+ // System.out.println("\nnodeType="+v.<String>property("aai-node-type"));
+ for (String key : v.keys()) {
+ // System.out.println("label="+v.label()+";key= "+key+";value= "+v.value(key)+"/"+v.id());
}
Direction d = null;
Iterator<Edge> edgeItr = v.edges(Direction.BOTH);
- while( edgeItr != null && edgeItr.hasNext() ){
+ while (edgeItr != null && edgeItr.hasNext()) {
Edge e = edgeItr.next();
- // System.out.println("outV="+e.outVertex().property(AAIProperties.NODE_TYPE)+"/"+e.outVertex().id()+";inV= "+e.inVertex().property(AAIProperties.NODE_TYPE)+"/"+e.inVertex().id());
+ // System.out.println("outV="+e.outVertex().property(AAIProperties.NODE_TYPE)+"/"+e.outVertex().id()+";inV=
+ // "+e.inVertex().property(AAIProperties.NODE_TYPE)+"/"+e.inVertex().id());
}
}
- // System.out.println("End method inventory:");
+ // System.out.println("End method inventory:");
when(spy.asAdmin()).thenReturn(adminSpy);
when(adminSpy.getTraversalSource()).thenReturn(traversal);
-// when(spy.tx()).thenReturn(graph);
+ // when(spy.tx()).thenReturn(graph);
when(spy.tx()).thenReturn(g);
when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop);
when(prop.orElse(null)).thenReturn(obj.getURI());
- DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
- SideEffectRunner runner = new SideEffectRunner
- .Builder(spy, serializer).addSideEffect(DataLinkWriter.class).build();
- //System.out.println("Traversal Source: "+traversal.toString());
+ DBSerializer serializer =
+ new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
+ SideEffectRunner runner =
+ new SideEffectRunner.Builder(spy, serializer).addSideEffect(DataLinkWriter.class).build();
+ // System.out.println("Traversal Source: "+traversal.toString());
vertexItr = traversal.V();
- // System.out.println("Begin method inventory:");
- while( vertexItr != null && vertexItr.hasNext() ){
+ // System.out.println("Begin method inventory:");
+ while (vertexItr != null && vertexItr.hasNext()) {
Vertex v = vertexItr.next();
- //System.out.println("\nnodeType="+v.<String>property("aai-node-type"));
- for(String key: v.keys()) {
- // System.out.println("label="+v.label()+";key= "+key+";value= "+v.value(key)+"/"+v.id());
+ // System.out.println("\nnodeType="+v.<String>property("aai-node-type"));
+ for (String key : v.keys()) {
+ // System.out.println("label="+v.label()+";key= "+key+";value= "+v.value(key)+"/"+v.id());
}
Iterator<Edge> edgeItr = v.edges(Direction.BOTH);
- while( edgeItr != null && edgeItr.hasNext() ){
+ while (edgeItr != null && edgeItr.hasNext()) {
Edge e = edgeItr.next();
- //System.out.println("outV="+e.outVertex().property(AAIProperties.NODE_TYPE)+"/"+e.outVertex().id()+";inV= "+e.inVertex().property(AAIProperties.NODE_TYPE)+"/"+e.inVertex().id());
+ // System.out.println("outV="+e.outVertex().property(AAIProperties.NODE_TYPE)+"/"+e.outVertex().id()+";inV=
+ // "+e.inVertex().property(AAIProperties.NODE_TYPE)+"/"+e.inVertex().id());
}
}
- //System.out.println("End method inventory:");
+ // System.out.println("End method inventory:");
try {
- runner.execute(obj, self);
- } catch(Exception e) {
+ runner.execute(obj, self);
+ } catch (Exception e) {
}
-// runner.execute(obj, self);
- //System.out.println("=================\n");
+ // runner.execute(obj, self);
+ // System.out.println("=================\n");
vertexItr = traversal.V();
- while( vertexItr != null && vertexItr.hasNext() ){
+ while (vertexItr != null && vertexItr.hasNext()) {
Vertex v = vertexItr.next();
- //System.out.println("\nnodeType="+v.<String>property("aai-node-type"));
- for(String key: v.keys()) {
- // System.out.println("label="+v.label()+";key= "+key+";value= "+v.value(key)+"/"+v.id());
+ // System.out.println("\nnodeType="+v.<String>property("aai-node-type"));
+ for (String key : v.keys()) {
+ // System.out.println("label="+v.label()+";key= "+key+";value= "+v.value(key)+"/"+v.id());
}
Iterator<Edge> edgeItr = v.edges(Direction.BOTH);
- while( edgeItr != null && edgeItr.hasNext() ){
+ while (edgeItr != null && edgeItr.hasNext()) {
Edge e = edgeItr.next();
- // System.out.println("outV="+e.outVertex().property(AAIProperties.NODE_TYPE)+"/"+e.outVertex().id()+";inV= "+e.inVertex().property(AAIProperties.NODE_TYPE)+"/"+e.inVertex().id());
+ // System.out.println("outV="+e.outVertex().property(AAIProperties.NODE_TYPE)+"/"+e.outVertex().id()+";inV=
+ // "+e.inVertex().property(AAIProperties.NODE_TYPE)+"/"+e.inVertex().id());
}
}
- assertThat("new route-target vertex found with/or without link", traversal.V()
- .has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "modifyTargetKey2").has("route-target-role", "modifyRoleKey2").hasNext(),is(true));
- assertThat("new route-target vertex found", traversal.V()
- .has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "modifyTargetKey2").has("route-target-role", "modifyRoleKey2").has("linked", true).hasNext(),is(true));
- assertThat("previous link removed", traversal.V()
- .has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "modifyTargetKey").has("route-target-role", "modifyRoleKey").has("linked").hasNext(),is(not(true)));
- assertThat("previous vertex still exists", traversal.V()
- .has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "modifyTargetKey").has("route-target-role", "modifyRoleKey").hasNext(),is(true));
+ assertThat("new route-target vertex found with/or without link",
+ traversal.V().has(AAIProperties.NODE_TYPE, "route-target")
+ .has("global-route-target", "modifyTargetKey2").has("route-target-role", "modifyRoleKey2")
+ .hasNext(),
+ is(true));
+ assertThat("new route-target vertex found",
+ traversal.V().has(AAIProperties.NODE_TYPE, "route-target")
+ .has("global-route-target", "modifyTargetKey2").has("route-target-role", "modifyRoleKey2")
+ .has("linked", true).hasNext(),
+ is(true));
+ assertThat("previous link removed",
+ traversal.V().has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "modifyTargetKey")
+ .has("route-target-role", "modifyRoleKey").has("linked").hasNext(),
+ is(not(true)));
+ assertThat("previous vertex still exists", traversal.V().has(AAIProperties.NODE_TYPE, "route-target")
+ .has("global-route-target", "modifyTargetKey").has("route-target-role", "modifyRoleKey").hasNext(),
+ is(true));
g.tx().rollback();
-
+
}
-
+
@Test
- public void verifyDeleteOfVertex() throws URISyntaxException, AAIException, UnsupportedEncodingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, MalformedURLException {
-
+ public void verifyDeleteOfVertex() throws URISyntaxException, AAIException, UnsupportedEncodingException,
+ IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException,
+ InstantiationException, NoSuchMethodException, MalformedURLException {
+
final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion());
final Introspector obj = loader.introspectorFromName("vpn-binding");
obj.setValue("vpn-id", "deleteKey");
@@ -281,27 +318,26 @@ public class DataLinkTest extends DataLinkSetup {
when(spy.tx()).thenReturn(g);
when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop);
when(prop.orElse(null)).thenReturn(obj.getURI());
- DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
- SideEffectRunner runner = new SideEffectRunner
- .Builder(spy, serializer).addSideEffect(DataLinkWriter.class).build();
-
+ DBSerializer serializer =
+ new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
+ SideEffectRunner runner =
+ new SideEffectRunner.Builder(spy, serializer).addSideEffect(DataLinkWriter.class).build();
+
runner.execute(obj, self);
- assertEquals("route-target vertex not found", false, traversal.V()
- .has(AAIProperties.NODE_TYPE, "route-target")
- .has("global-route-target", "deleteTargetKey")
- .has("route-target-role", "deleteRoleKey")
- .has("linked", true)
- .hasNext()
- );
+ assertEquals("route-target vertex not found", false,
+ traversal.V().has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "deleteTargetKey")
+ .has("route-target-role", "deleteRoleKey").has("linked", true).hasNext());
g.tx().rollback();
-
+
}
-
+
@Test
- public void verifyPropertyPopulation() throws URISyntaxException, AAIException, UnsupportedEncodingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, MalformedURLException {
-
+ public void verifyPropertyPopulation() throws URISyntaxException, AAIException, UnsupportedEncodingException,
+ IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException,
+ InstantiationException, NoSuchMethodException, MalformedURLException {
+
final Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion());
final Introspector obj = loader.introspectorFromName("vpn-binding");
obj.setValue("vpn-id", "getKey");
@@ -314,19 +350,24 @@ public class DataLinkTest extends DataLinkSetup {
when(spy.tx()).thenReturn(g);
when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop);
when(prop.orElse(null)).thenReturn(obj.getURI());
- DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
- SideEffectRunner runner = new SideEffectRunner
- .Builder(spy, serializer).addSideEffect(DataLinkReader.class).build();
-
+ DBSerializer serializer =
+ new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
+ SideEffectRunner runner =
+ new SideEffectRunner.Builder(spy, serializer).addSideEffect(DataLinkReader.class).build();
+
runner.execute(obj, self);
- assertEquals("both properties have been populated in target object", true, obj.getValue("global-route-target").equals("getTargetKey") && obj.getValue("route-target-role").equals("getRoleKey"));
+ assertEquals("both properties have been populated in target object", true,
+ obj.getValue("global-route-target").equals("getTargetKey")
+ && obj.getValue("route-target-role").equals("getRoleKey"));
g.tx().rollback();
-
+
}
-
+
@Test
- public void verifyPropertyPopulationWithV10OnlyPut() throws URISyntaxException, AAIException, UnsupportedEncodingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, InstantiationException, NoSuchMethodException, MalformedURLException {
+ public void verifyPropertyPopulationWithV10OnlyPut() throws URISyntaxException, AAIException,
+ UnsupportedEncodingException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
+ SecurityException, InstantiationException, NoSuchMethodException, MalformedURLException {
final Introspector obj = loader.introspectorFromName("vpn-binding");
obj.setValue("vpn-id", "getKeyNoLink");
final Introspector routeTargets = loader.introspectorFromName("route-targets");
@@ -351,16 +392,19 @@ public class DataLinkTest extends DataLinkSetup {
when(parser.isDependent()).thenReturn(false);
when(self.<String>property(AAIProperties.AAI_URI)).thenReturn(prop);
when(prop.orElse(null)).thenReturn(obj.getURI());
- DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
+ DBSerializer serializer =
+ new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
Vertex v = serializer.createNewVertex(obj);
serializer.serializeToDb(obj, v, parser, obj.getURI(), "testing");
Vertex routeTargetOneV = traversal.V().has("global-route-target", "getTargetKeyNoLink").next();
Vertex routeTargetTwoV = traversal.V().has("global-route-target", "getTargetKeyNoLink2").next();
- assertEquals("first route target put has linked", true, routeTargetOneV.property(AAIProperties.LINKED).orElse(false));
- assertEquals("second route target put does not have linked", false, routeTargetTwoV.property(AAIProperties.LINKED).orElse(false));
+ assertEquals("first route target put has linked", true,
+ routeTargetOneV.property(AAIProperties.LINKED).orElse(false));
+ assertEquals("second route target put does not have linked", false,
+ routeTargetTwoV.property(AAIProperties.LINKED).orElse(false));
g.tx().rollback();
-
+
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/PrivateEdgeTest.java b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/PrivateEdgeTest.java
index 5cd1fb53..1bae4065 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/PrivateEdgeTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/sideeffect/PrivateEdgeTest.java
@@ -17,9 +17,22 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.introspection.sideeffect;
-import org.springframework.test.annotation.DirtiesContext;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.StringContains.containsString;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -40,110 +53,76 @@ import org.onap.aai.serialization.db.DBSerializer;
import org.onap.aai.serialization.engines.JanusGraphDBEngine;
import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.empty;
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.StringContains.containsString;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
+import org.springframework.test.annotation.DirtiesContext;
@RunWith(value = Parameterized.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
-public class PrivateEdgeTest extends AAISetup{
+public class PrivateEdgeTest extends AAISetup {
private static JanusGraph graph;
private final static ModelType introspectorFactoryType = ModelType.MOXY;
private final static DBConnectionType type = DBConnectionType.REALTIME;
private Loader loader;
private static TransactionalGraphEngine dbEngine;
-
-
-
+
@Rule
public ExpectedException thrown = ExpectedException.none();
-
@Parameterized.Parameter(value = 0)
public QueryStyle queryStyle;
@Parameterized.Parameters(name = "QueryStyle.{0}")
public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][]{
- {QueryStyle.TRAVERSAL},
- {QueryStyle.TRAVERSAL_URI}
- });
+ return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
}
-
+
@BeforeClass
public static void setup() throws Exception {
- graph = JanusGraphFactory.build().set("storage.backend","inmemory").open();
+ graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
System.setProperty("AJSC_HOME", ".");
System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
-
-
graph.traversal()
- .addV("aai-node-type", "model",
- "model-invariant-id", "key1",
- AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key1").as("v1")
- .addV("aai-node-type", "model-ver",
- "model-ver", "myValue",
- "model-version-id", "key2",
- "model-version", "testValue",
- AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key1/model-vers/model-ver/key2")
- .addOutE("org.onap.relationships.inventory.BelongsTo", "v1",
- EdgeProperty.CONTAINS.toString(), true
- )
- .addV("aai-node-type", "model",
- "model-invariant-id", "key100",
- AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key100").as("v5")
- .addV("aai-node-type", "model-ver",
- "model-ver", "myValue",
- "model-version-id", "key200",
- "model-version", "testValue",
- AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key100/model-vers/model-ver/key200")
- .addOutE("org.onap.relationships.inventory.BelongsTo", "v5",
- EdgeProperty.CONTAINS.toString(), true
- )
- .addV("aai-node-type", "model",
- "model-invariant-id", "key3",
- AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key3").as("v2")
- .addV("aai-node-type", "model-ver",
- "model-ver", "myValue",
- "model-version-id", "key4",
- AAIProperties.AAI_URI, "/service-design-and-creation/models/model/key3/model-vers/model-ver/key4")
- .addOutE("org.onap.relationships.inventory.BelongsTo", "v2",
- EdgeProperty.CONTAINS.toString(), true
- )
- .next();
+ .addV("aai-node-type", "model", "model-invariant-id", "key1", AAIProperties.AAI_URI,
+ "/service-design-and-creation/models/model/key1")
+ .as("v1")
+ .addV("aai-node-type", "model-ver", "model-ver", "myValue", "model-version-id", "key2", "model-version",
+ "testValue", AAIProperties.AAI_URI,
+ "/service-design-and-creation/models/model/key1/model-vers/model-ver/key2")
+ .addOutE("org.onap.relationships.inventory.BelongsTo", "v1", EdgeProperty.CONTAINS.toString(), true)
+ .addV("aai-node-type", "model", "model-invariant-id", "key100", AAIProperties.AAI_URI,
+ "/service-design-and-creation/models/model/key100")
+ .as("v5")
+ .addV("aai-node-type", "model-ver", "model-ver", "myValue", "model-version-id", "key200",
+ "model-version", "testValue", AAIProperties.AAI_URI,
+ "/service-design-and-creation/models/model/key100/model-vers/model-ver/key200")
+ .addOutE("org.onap.relationships.inventory.BelongsTo", "v5", EdgeProperty.CONTAINS.toString(), true)
+ .addV("aai-node-type", "model", "model-invariant-id", "key3", AAIProperties.AAI_URI,
+ "/service-design-and-creation/models/model/key3")
+ .as("v2")
+ .addV("aai-node-type", "model-ver", "model-ver", "myValue", "model-version-id", "key4",
+ AAIProperties.AAI_URI,
+ "/service-design-and-creation/models/model/key3/model-vers/model-ver/key4")
+ .addOutE("org.onap.relationships.inventory.BelongsTo", "v2", EdgeProperty.CONTAINS.toString(), true)
+ .next();
graph.tx().commit();
}
-
+
@AfterClass
public static void tearDown() {
graph.tx().rollback();
graph.close();
}
-
+
@Before
public void initMock() {
loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion());
MockitoAnnotations.initMocks(this);
- dbEngine = new JanusGraphDBEngine(
- queryStyle,
- type,
- loader);
+ dbEngine = new JanusGraphDBEngine(queryStyle, type, loader);
}
-
+
@Test
public void testWhenPrivateEdgeThrowsExceptionWhenHavingOnlyOnePartOfKey() throws Exception {
@@ -158,15 +137,12 @@ public class PrivateEdgeTest extends AAISetup{
when(spy.asAdmin()).thenReturn(adminSpy);
when(adminSpy.getTraversalSource()).thenReturn(traversal);
- Vertex selfV = traversal.addV(
- "aai-node-type", "generic-vnf",
- "vnf-id", "myId",
- "aai-uri",obj.getURI(),
- "model-invariant-id", "key1"
- ).next();
+ Vertex selfV = traversal.addV("aai-node-type", "generic-vnf", "vnf-id", "myId", "aai-uri", obj.getURI(),
+ "model-invariant-id", "key1").next();
thrown.expectMessage(containsString("Cannot complete privateEdge uri"));
- DBSerializer serializer = new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
+ DBSerializer serializer =
+ new DBSerializer(schemaVersions.getDefaultVersion(), spy, introspectorFactoryType, "AAI_TEST");
PrivateEdge privateEdge = new PrivateEdge(obj, selfV, spy, serializer);
privateEdge.execute();
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/tools/CreateUUIDTest.java b/aai-core/src/test/java/org/onap/aai/introspection/tools/CreateUUIDTest.java
index e44fdd52..6d8508ce 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/tools/CreateUUIDTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/tools/CreateUUIDTest.java
@@ -17,8 +17,12 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.introspection.tools;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import org.junit.Before;
import org.junit.Test;
import org.onap.aai.AAISetup;
@@ -26,9 +30,6 @@ import org.onap.aai.introspection.*;
import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
import org.springframework.test.annotation.DirtiesContext;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class CreateUUIDTest extends AAISetup {
@@ -38,7 +39,7 @@ public class CreateUUIDTest extends AAISetup {
private Issue issue;
@Before
- public void setup(){
+ public void setup() {
createUUID = new CreateUUID();
loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
}
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/tools/DefaultFieldsTest.java b/aai-core/src/test/java/org/onap/aai/introspection/tools/DefaultFieldsTest.java
index 5fd185d5..664a69c5 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/tools/DefaultFieldsTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/tools/DefaultFieldsTest.java
@@ -17,8 +17,14 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.introspection.tools;
+import static junit.framework.TestCase.assertNotNull;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import org.junit.Before;
import org.junit.Test;
import org.onap.aai.AAISetup;
@@ -26,11 +32,6 @@ import org.onap.aai.introspection.*;
import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
import org.springframework.test.annotation.DirtiesContext;
-import static junit.framework.TestCase.assertNotNull;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class DefaultFieldsTest extends AAISetup {
@@ -40,8 +41,8 @@ public class DefaultFieldsTest extends AAISetup {
@Before
public void setup() {
- loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
- issue = new Issue();
+ loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
+ issue = new Issue();
defaultFields = new DefaultFields();
}
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/tools/InjectKeysFromURITest.java b/aai-core/src/test/java/org/onap/aai/introspection/tools/InjectKeysFromURITest.java
index 713a8ae0..cd5bdb93 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/tools/InjectKeysFromURITest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/tools/InjectKeysFromURITest.java
@@ -17,8 +17,17 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.introspection.tools;
+import static junit.framework.TestCase.assertNotNull;
+import static org.eclipse.persistence.jpa.jpql.Assert.fail;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URI;
+
import org.junit.Before;
import org.junit.Test;
import org.onap.aai.AAISetup;
@@ -26,14 +35,6 @@ import org.onap.aai.introspection.*;
import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
import org.springframework.test.annotation.DirtiesContext;
-import java.net.URI;
-
-import static junit.framework.TestCase.assertNotNull;
-import static org.eclipse.persistence.jpa.jpql.Assert.fail;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class InjectKeysFromURITest extends AAISetup {
@@ -43,19 +44,20 @@ public class InjectKeysFromURITest extends AAISetup {
@Before
public void setup() {
- loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
- issue = new Issue();
+ loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
+ issue = new Issue();
}
+
@Test
public void testInjectKeysFromURIOfPserverIsNotResolved() throws AAIUnknownObjectException {
try {
ik = new InjectKeysFromURI(loader, new URI("/aai/v12/cloud-infrastructure/complexes"));
- }catch(Exception e) {
+ } catch (Exception e) {
fail("InjectKeys instantiation threw an exception");
}
Introspector pserver = loader.introspectorFromName("pserver");
- pserver.setValue("in-maint",false);
+ pserver.setValue("in-maint", false);
pserver.setValue("hostname", "pserver2");
assertNotNull("Unable to load the template introspector", pserver);
@@ -68,13 +70,14 @@ public class InjectKeysFromURITest extends AAISetup {
assertFalse("Unable to resolve the pserver in-maint issue", issueResolved);
assertEquals("Introspector didn't successfully modify the pserver in-maint", false,
- pserver.getValue("in-maint"));
+ pserver.getValue("in-maint"));
}
+
@Test
public void testInjectKeysFromURIOfPserverSuccessfullyResolved() throws AAIUnknownObjectException {
try {
ik = new InjectKeysFromURI(loader, new URI("/aai/v12/cloud-infrastructure/pservers/pserver/pserver1"));
- }catch(Exception e) {
+ } catch (Exception e) {
fail("InjectKeys instantiation threw an exception");
}
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/tools/IntrospectorValidatorTest.java b/aai-core/src/test/java/org/onap/aai/introspection/tools/IntrospectorValidatorTest.java
index 68a03b3b..41c6353b 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/tools/IntrospectorValidatorTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/tools/IntrospectorValidatorTest.java
@@ -17,8 +17,15 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.introspection.tools;
+import static junit.framework.TestCase.assertNotNull;
+import static org.eclipse.persistence.jpa.jpql.Assert.fail;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import org.junit.Before;
import org.junit.Test;
import org.onap.aai.AAISetup;
@@ -26,12 +33,6 @@ import org.onap.aai.introspection.*;
import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
import org.springframework.test.annotation.DirtiesContext;
-import static junit.framework.TestCase.assertNotNull;
-import static org.eclipse.persistence.jpa.jpql.Assert.fail;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class IntrospectorValidatorTest extends AAISetup {
@@ -47,7 +48,7 @@ public class IntrospectorValidatorTest extends AAISetup {
issue = new Issue();
try {
introspector = loader.introspectorFromName("pserver");
- }catch(Exception e){
+ } catch (Exception e) {
fail("Introspector instantiation call threw an exception " + e);
}
b = new IntrospectorValidator.Builder();
@@ -59,11 +60,11 @@ public class IntrospectorValidatorTest extends AAISetup {
return true;
}
});
- //this method does nothing
- iv.processPrimitiveList("TEST",introspector);
+ // this method does nothing
+ iv.processPrimitiveList("TEST", introspector);
}
- public void setupIssue(String message, IssueType type, String propName, Introspector introspector){
+ public void setupIssue(String message, IssueType type, String propName, Introspector introspector) {
issue.setDetail(message);
issue.setType(type);
issue.setPropName(propName);
@@ -72,56 +73,57 @@ public class IntrospectorValidatorTest extends AAISetup {
@Test
public void testIntrospectorValidatorMaxDepth() throws AAIUnknownObjectException {
- setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
+ setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
b.restrictDepth(4);
assertEquals("Maximum Depth should be 4", 4, b.getMaximumDepth());
}
@Test
public void testIntrospectorValidatorValidationRequired() throws AAIUnknownObjectException {
- setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
+ setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
b.validateRequired(true);
assertTrue("Validation should be required", b.getValidateRequired());
}
@Test
- public void testIntrospectorValidatorValidatedFalse() throws AAIUnknownObjectException{
- setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
+ public void testIntrospectorValidatorValidatedFalse() throws AAIUnknownObjectException {
+ setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
try {
assertFalse("Not currently validated", iv.validate(introspector));
- }catch (Exception e){
+ } catch (Exception e) {
fail("Introspector validate call threw an exception " + e);
}
}
@Test
- public void testIntrospectorValidatorResolveIssues() throws AAIUnknownObjectException{
- setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
+ public void testIntrospectorValidatorResolveIssues() throws AAIUnknownObjectException {
+ setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
assertTrue("Introspector call to resolve issues should return true", iv.resolveIssues());
}
@Test
- public void testIntrospectorValidatorGetIssues() throws AAIUnknownObjectException{
- setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
+ public void testIntrospectorValidatorGetIssues() throws AAIUnknownObjectException {
+ setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
iv.getIssues();
}
@Test
- public void testIntrospectorValidatorProcessComplexObject() throws AAIUnknownObjectException{
- setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
+ public void testIntrospectorValidatorProcessComplexObject() throws AAIUnknownObjectException {
+ setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
iv.processComplexObj(introspector);
}
@Test
- public void testIntrospectorValidatorCreateComplexListSize() throws AAIUnknownObjectException{
- setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
- assertEquals("create complex list size should return 0", 0, iv.createComplexListSize(introspector, introspector));
+ public void testIntrospectorValidatorCreateComplexListSize() throws AAIUnknownObjectException {
+ setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
+ assertEquals("create complex list size should return 0", 0,
+ iv.createComplexListSize(introspector, introspector));
}
@Test
- public void testIntrospectorValidatorGetResolvers() throws AAIUnknownObjectException{
- setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector );
- assertNotNull("Get resolvers should not be null", b.getResolvers());
+ public void testIntrospectorValidatorGetResolvers() throws AAIUnknownObjectException {
+ setupIssue("Some message", IssueType.MISSING_REQUIRED_PROP, "hostname", introspector);
+ assertNotNull("Get resolvers should not be null", b.getResolvers());
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/tools/RemoveNonVisiblePropertyTest.java b/aai-core/src/test/java/org/onap/aai/introspection/tools/RemoveNonVisiblePropertyTest.java
index cf1b7782..a3380ee2 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/tools/RemoveNonVisiblePropertyTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/tools/RemoveNonVisiblePropertyTest.java
@@ -17,8 +17,13 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.introspection.tools;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import org.junit.Before;
import org.junit.Test;
import org.onap.aai.AAISetup;
@@ -26,10 +31,6 @@ import org.onap.aai.introspection.*;
import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
import org.springframework.test.annotation.DirtiesContext;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertNull;
-
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class RemoveNonVisiblePropertyTest extends AAISetup {
@@ -38,7 +39,7 @@ public class RemoveNonVisiblePropertyTest extends AAISetup {
private RemoveNonVisibleProperty rn;
@Before
- public void setup(){
+ public void setup() {
rn = new RemoveNonVisibleProperty();
loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
}
@@ -66,5 +67,4 @@ public class RemoveNonVisiblePropertyTest extends AAISetup {
assertFalse("Nonvisible property not present so should not have been removed", rn.resolveIssue(issue));
}
-
}
diff --git a/aai-core/src/test/java/org/onap/aai/introspection/validation/IntrospectorValidationTest.java b/aai-core/src/test/java/org/onap/aai/introspection/validation/IntrospectorValidationTest.java
index 0902aec8..7bb38790 100644
--- a/aai-core/src/test/java/org/onap/aai/introspection/validation/IntrospectorValidationTest.java
+++ b/aai-core/src/test/java/org/onap/aai/introspection/validation/IntrospectorValidationTest.java
@@ -17,15 +17,19 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.introspection.validation;
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.onap.aai.AAISetup;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.*;
-
import org.onap.aai.introspection.tools.IntrospectorValidator;
import org.onap.aai.introspection.tools.Issue;
import org.onap.aai.introspection.tools.IssueType;
@@ -33,10 +37,6 @@ import org.onap.aai.serialization.queryformats.QueryFormatTestHelper;
import org.onap.aai.util.AAIConstants;
import org.springframework.beans.factory.annotation.Autowired;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-
public class IntrospectorValidationTest extends AAISetup {
private final static ModelType introspectorFactoryType = ModelType.MOXY;
@@ -50,11 +50,9 @@ public class IntrospectorValidationTest extends AAISetup {
System.setProperty("AJSC_HOME", ".");
System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local");
loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getRelatedLinkVersion());
- validator = new IntrospectorValidator.Builder()
- .validateRequired(false)
- .restrictDepth(10000)
- .build();
+ validator = new IntrospectorValidator.Builder().validateRequired(false).restrictDepth(10000).build();
}
+
@Ignore
@Test
public void verifySuccessWhenEmpty() throws AAIException {
@@ -77,6 +75,7 @@ public class IntrospectorValidationTest extends AAISetup {
Issue issue = issues.get(0);
assertEquals("found expected issue", IssueType.DEPENDENT_PROP_NOT_FOUND, issue.getType());
}
+
@Ignore
@Test
public void verifyRequiresSuccess() throws AAIException {
diff --git a/aai-core/src/test/java/org/onap/aai/logging/CustomLogPatternLayoutTest.java b/aai-core/src/test/java/org/onap/aai/logging/CustomLogPatternLayoutTest.java
index 198bb064..dce34b53 100644
--- a/aai-core/src/test/java/org/onap/aai/logging/CustomLogPatternLayoutTest.java
+++ b/aai-core/src/test/java/org/onap/aai/logging/CustomLogPatternLayoutTest.java
@@ -17,31 +17,32 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.logging;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import org.junit.Test;
import org.onap.aai.logging.CNName;
import org.onap.aai.logging.CustomLogPatternLayout;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
public class CustomLogPatternLayoutTest {
-
+
/**
* Test null when defaultConverterMap doesn't have corresponding entry.
*/
@Test
- public void testNull(){
+ public void testNull() {
String s = CustomLogPatternLayout.defaultConverterMap.get("z");
assertFalse("Entry not found for key 'z'", CNName.class.getName().equals(s));
}
-
+
/**
* Test defaultConverterMap when valid entry exists.
*/
@Test
- public void testEntryFor_Z(){
+ public void testEntryFor_Z() {
CustomLogPatternLayout layout = new CustomLogPatternLayout();
String s = CustomLogPatternLayout.defaultConverterMap.get("z");
assertTrue("Entry not found for key 'z'", CNName.class.getName().equals(s));
diff --git a/aai-core/src/test/java/org/onap/aai/logging/DME2RestFlagTest.java b/aai-core/src/test/java/org/onap/aai/logging/DME2RestFlagTest.java
index 09e6ed1e..bc7f9499 100644
--- a/aai-core/src/test/java/org/onap/aai/logging/DME2RestFlagTest.java
+++ b/aai-core/src/test/java/org/onap/aai/logging/DME2RestFlagTest.java
@@ -17,12 +17,15 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.logging;
+
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
+
import ch.qos.logback.access.spi.IAccessEvent;
-import org.junit.*;
+import org.junit.*;
public class DME2RestFlagTest {
@@ -31,51 +34,49 @@ public class DME2RestFlagTest {
String[] temp = new String[4];
-
@Before
public void setUp() throws Exception {
mockAccEvent = mock(IAccessEvent.class);
- _DME2RestFlag= spy(DME2RestFlag.class);
+ _DME2RestFlag = spy(DME2RestFlag.class);
}
- private DME2RestFlag getTestObj(final boolean instanceStarted){
- return new DME2RestFlag(){
+
+ private DME2RestFlag getTestObj(final boolean instanceStarted) {
+ return new DME2RestFlag() {
@Override
- public
- boolean isStarted(){
+ public boolean isStarted() {
return instanceStarted;
}
};
}
@Test
- public void convertTestAllValid(){
- temp[0]= "temp1";
+ public void convertTestAllValid() {
+ temp[0] = "temp1";
temp[1] = "-";
when(mockAccEvent.getRequestParameter("envContext")).thenReturn(temp);
when(mockAccEvent.getRequestParameter("routeOffer")).thenReturn(temp);
when(mockAccEvent.getRequestParameter("version")).thenReturn(temp);
_DME2RestFlag = getTestObj(true);
- assertEquals(_DME2RestFlag.convert(mockAccEvent),"DME2");
+ assertEquals(_DME2RestFlag.convert(mockAccEvent), "DME2");
}
@Test
- public void convertMissingRouteTest(){
- temp[0]= "";
+ public void convertMissingRouteTest() {
+ temp[0] = "";
temp[1] = "-";
when(mockAccEvent.getRequestParameter("envContext")).thenReturn(temp);
when(mockAccEvent.getRequestParameter("routeOffer")).thenReturn(temp);
when(mockAccEvent.getRequestParameter("version")).thenReturn(temp);
_DME2RestFlag = getTestObj(true);
- assertEquals(_DME2RestFlag.convert(mockAccEvent),"REST");
+ assertEquals(_DME2RestFlag.convert(mockAccEvent), "REST");
}
@Test
- public void convertIsStartedFalseTest(){
+ public void convertIsStartedFalseTest() {
_DME2RestFlag = getTestObj(false);
- assertEquals(_DME2RestFlag.convert(mockAccEvent),"INACTIVE_HEADER_CONV");
+ assertEquals(_DME2RestFlag.convert(mockAccEvent), "INACTIVE_HEADER_CONV");
}
-
}
diff --git a/aai-core/src/test/java/org/onap/aai/logging/EcompErrorCategoryTest.java b/aai-core/src/test/java/org/onap/aai/logging/EcompErrorCategoryTest.java
index b29cf51f..65c78121 100644
--- a/aai-core/src/test/java/org/onap/aai/logging/EcompErrorCategoryTest.java
+++ b/aai-core/src/test/java/org/onap/aai/logging/EcompErrorCategoryTest.java
@@ -17,14 +17,15 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.logging;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import ch.qos.logback.classic.Level;
-
import ch.qos.logback.classic.spi.ILoggingEvent;
+
import org.junit.*;
public class EcompErrorCategoryTest {
@@ -36,11 +37,12 @@ public class EcompErrorCategoryTest {
public void setUp() throws Exception {
mockEvent = mock(ILoggingEvent.class);
- _ecompErrorCategory= spy(EcompErrorCategory.class);
+ _ecompErrorCategory = spy(EcompErrorCategory.class);
}
+
@Test
- public void warn(){
+ public void warn() {
String defaultCategory = "WARN";
assertEquals(_ecompErrorCategory.convert(mockEvent), defaultCategory);
}
diff --git a/aai-core/src/test/java/org/onap/aai/logging/EcompResponseCodeTest.java b/aai-core/src/test/java/org/onap/aai/logging/EcompResponseCodeTest.java
index 10edb456..8319f9a3 100644
--- a/aai-core/src/test/java/org/onap/aai/logging/EcompResponseCodeTest.java
+++ b/aai-core/src/test/java/org/onap/aai/logging/EcompResponseCodeTest.java
@@ -17,14 +17,15 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.logging;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import ch.qos.logback.classic.Level;
-
import ch.qos.logback.classic.spi.ILoggingEvent;
+
import org.junit.*;
public class EcompResponseCodeTest {
@@ -36,11 +37,12 @@ public class EcompResponseCodeTest {
public void setUp() throws Exception {
mockEvent = mock(ILoggingEvent.class);
- _ecompResponseCode= spy(EcompResponseCode.class);
+ _ecompResponseCode = spy(EcompResponseCode.class);
}
+
@Test
- public void getDefaultCode(){
+ public void getDefaultCode() {
assertEquals(_ecompResponseCode.convert(mockEvent), LoggingContext.UNKNOWN_ERROR);
}
diff --git a/aai-core/src/test/java/org/onap/aai/logging/EcompResponseDescriptionTest.java b/aai-core/src/test/java/org/onap/aai/logging/EcompResponseDescriptionTest.java
index fbdc998e..deec8828 100644
--- a/aai-core/src/test/java/org/onap/aai/logging/EcompResponseDescriptionTest.java
+++ b/aai-core/src/test/java/org/onap/aai/logging/EcompResponseDescriptionTest.java
@@ -17,31 +17,33 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.logging;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import ch.qos.logback.classic.Level;
-
import ch.qos.logback.classic.spi.ILoggingEvent;
+
import org.junit.*;
import org.onap.aai.logging.LoggingContext.LoggingField;
public class EcompResponseDescriptionTest {
- EcompResponseDescription _ecompResponseDescription;
+ EcompResponseDescription _ecompResponseDescription;
ILoggingEvent mockEvent;
@Before
public void setUp() throws Exception {
mockEvent = mock(ILoggingEvent.class);
- _ecompResponseDescription= spy(EcompResponseDescription.class);
+ _ecompResponseDescription = spy(EcompResponseDescription.class);
}
+
@Test
- public void getDefaultDesc(){
+ public void getDefaultDesc() {
assertEquals(_ecompResponseDescription.convert(mockEvent), _ecompResponseDescription.DefaultDescription);
}
diff --git a/aai-core/src/test/java/org/onap/aai/logging/EelfClassOfCallerTest.java b/aai-core/src/test/java/org/onap/aai/logging/EelfClassOfCallerTest.java
index be04f276..bc77ae81 100644
--- a/aai-core/src/test/java/org/onap/aai/logging/EelfClassOfCallerTest.java
+++ b/aai-core/src/test/java/org/onap/aai/logging/EelfClassOfCallerTest.java
@@ -17,11 +17,14 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.logging;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
+
import ch.qos.logback.classic.spi.ILoggingEvent;
+
import org.junit.*;
public class EelfClassOfCallerTest {
@@ -32,37 +35,36 @@ public class EelfClassOfCallerTest {
StackTraceElement[] cdaone = new StackTraceElement[1];
StackTraceElement[] cdazero = new StackTraceElement[0];
-
@Before
public void setUp() throws Exception {
mockEvent = mock(ILoggingEvent.class);
- _eelfClassOfCaller= spy(EelfClassOfCaller.class);
+ _eelfClassOfCaller = spy(EelfClassOfCaller.class);
}
-
@Test
- public void getFullyQualifiedNameCDALENFiveTest(){
- StackTraceElement temp = new StackTraceElement("classname_five","methodname","filename", 4);
- cdafive[2]=temp;
+ public void getFullyQualifiedNameCDALENFiveTest() {
+ StackTraceElement temp = new StackTraceElement("classname_five", "methodname", "filename", 4);
+ cdafive[2] = temp;
when(mockEvent.getCallerData()).thenReturn(cdafive);
- assertEquals(_eelfClassOfCaller.getFullyQualifiedName(mockEvent),"classname_five");
+ assertEquals(_eelfClassOfCaller.getFullyQualifiedName(mockEvent), "classname_five");
}
+
@Test
- public void getFullyQualifiedNameCDALenOneTest(){
- StackTraceElement temp = new StackTraceElement("classname_one","methodname","filename", 4);
- cdaone[0]=temp;
+ public void getFullyQualifiedNameCDALenOneTest() {
+ StackTraceElement temp = new StackTraceElement("classname_one", "methodname", "filename", 4);
+ cdaone[0] = temp;
when(mockEvent.getCallerData()).thenReturn(cdaone);
- assertEquals(_eelfClassOfCaller.getFullyQualifiedName(mockEvent),"classname_one");
+ assertEquals(_eelfClassOfCaller.getFullyQualifiedName(mockEvent), "classname_one");
}
@Test
- public void getFullyQualifiedNameCDALenZeroTest(){
+ public void getFullyQualifiedNameCDALenZeroTest() {
when(mockEvent.getCallerData()).thenReturn(cdazero);
- assertEquals(_eelfClassOfCaller.getFullyQualifiedName(mockEvent),"?");
+ assertEquals(_eelfClassOfCaller.getFullyQualifiedName(mockEvent), "?");
}
diff --git a/aai-core/src/test/java/org/onap/aai/logging/ErrorObjectTest.java b/aai-core/src/test/java/org/onap/aai/logging/ErrorObjectTest.java
index 8db1ece9..1c55bc11 100644
--- a/aai-core/src/test/java/org/onap/aai/logging/ErrorObjectTest.java
+++ b/aai-core/src/test/java/org/onap/aai/logging/ErrorObjectTest.java
@@ -17,145 +17,166 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.logging;
+import static org.junit.Assert.*;
+
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
-import static org.junit.Assert.*;
import org.junit.*;
public class ErrorObjectTest {
-
- ErrorObject newErrorObject = new ErrorObject("disposition","category","severity", 200, "restErrorCode","errorCode","errorText");
-
- //Constructor Tests
- @Test
- public void createObjectTest1(){
- //No HTTP Status argument
- ErrorObject errorObject = new ErrorObject("severity","errorcode","errortext","disposition","category");
+
+ ErrorObject newErrorObject =
+ new ErrorObject("disposition", "category", "severity", 200, "restErrorCode", "errorCode", "errorText");
+
+ // Constructor Tests
+ @Test
+ public void createObjectTest1() {
+ // No HTTP Status argument
+ ErrorObject errorObject = new ErrorObject("severity", "errorcode", "errortext", "disposition", "category");
assertNotNull(errorObject);
}
+
@Test
- public void createObjectTest2(){
- //HTTP Status code as integer
- ErrorObject errorObject = new ErrorObject("severity",200,"errorcode","errortext","disposition","category");
+ public void createObjectTest2() {
+ // HTTP Status code as integer
+ ErrorObject errorObject = new ErrorObject("severity", 200, "errorcode", "errortext", "disposition", "category");
assertNotNull(errorObject);
}
+
@Test
- public void createObjectTest3(){
- //HTTP Status code as Status
- ErrorObject errorObject = new ErrorObject("severity",Status.OK,"errorcode","errortext","disposition","category");
+ public void createObjectTest3() {
+ // HTTP Status code as Status
+ ErrorObject errorObject =
+ new ErrorObject("severity", Status.OK, "errorcode", "errortext", "disposition", "category");
assertNotNull(errorObject);
}
- //Disposition Tests
+
+ // Disposition Tests
@Test
public void getDispositionTest() {
assertEquals(newErrorObject.getDisposition(), "disposition");
}
+
@Test
public void setDispositionTest() {
newErrorObject.setDisposition("newDisposition");
assertEquals(newErrorObject.getDisposition(), "newDisposition");
}
-
- //Category Tests
+
+ // Category Tests
@Test
- public void getCategoryTest(){
+ public void getCategoryTest() {
assertEquals(newErrorObject.getCategory(), "category");
}
+
@Test
- public void setCategoryTest(){
+ public void setCategoryTest() {
newErrorObject.setCategory("newCategory");
assertEquals(newErrorObject.getCategory(), "newCategory");
}
-
- //Severity Tests
+
+ // Severity Tests
@Test
- public void getSeverityTest(){
+ public void getSeverityTest() {
assertEquals(newErrorObject.getSeverity(), "severity");
}
+
@Test
- public void setSeverityTest(){
+ public void setSeverityTest() {
newErrorObject.setSeverity("newSeverity");
assertEquals(newErrorObject.getSeverity(), "newSeverity");
}
-
- //Error Code Tests
+
+ // Error Code Tests
@Test
- public void getErrorCodeTest(){
+ public void getErrorCodeTest() {
assertEquals(newErrorObject.getErrorCode(), "errorCode");
}
+
@Test
- public void SetErrorCodeTest(){
+ public void SetErrorCodeTest() {
newErrorObject.setErrorCode("newErrorCode");
assertEquals(newErrorObject.getErrorCode(), "newErrorCode");
}
-
- //HTTP Response Code Tests
+
+ // HTTP Response Code Tests
@Test
- public void getHTTPCodeTest(){
+ public void getHTTPCodeTest() {
assertEquals(newErrorObject.getHTTPResponseCode(), Status.OK);
}
+
@Test
- public void setHTTPCodeTest(){
+ public void setHTTPCodeTest() {
newErrorObject.setHTTPResponseCode(201);
assertEquals(newErrorObject.getHTTPResponseCode(), Status.CREATED);
}
- @Test(expected=IllegalArgumentException.class)
- public void invalidHttpCodeTest(){
+
+ @Test(expected = IllegalArgumentException.class)
+ public void invalidHttpCodeTest() {
newErrorObject.setHTTPResponseCode(6281723);
}
- @Test(expected=IllegalArgumentException.class)
- public void invalidHttpCodeTest2(){
+
+ @Test(expected = IllegalArgumentException.class)
+ public void invalidHttpCodeTest2() {
newErrorObject.setHTTPResponseCode("82901");
}
-
- //Rest Error Code Tests
+
+ // Rest Error Code Tests
@Test
- public void getRestErrorCodeTest(){
+ public void getRestErrorCodeTest() {
assertEquals(newErrorObject.getRESTErrorCode(), "restErrorCode");
}
+
@Test
- public void setRestErrorCodeTest(){
+ public void setRestErrorCodeTest() {
newErrorObject.setRESTErrorCode("newRestErrorCode");
assertEquals(newErrorObject.getRESTErrorCode(), "newRestErrorCode");
}
-
- //Error Text Tests
+
+ // Error Text Tests
@Test
- public void getErrorTextTest(){
+ public void getErrorTextTest() {
assertEquals(newErrorObject.getErrorText(), "errorText");
}
+
@Test
- public void setErrorTextTest(){
+ public void setErrorTextTest() {
newErrorObject.setErrorText("newErrorText");
assertEquals(newErrorObject.getErrorText(), "newErrorText");
}
+
@Test
- public void getErrorCodeStringTest(){
+ public void getErrorCodeStringTest() {
assertEquals(newErrorObject.getErrorCodeString(), "disposition.category.errorCode");
}
+
@Test
- public void getErrorCodeStringDisposition5Test(){
- //get Error Code String while Disposition = 5
+ public void getErrorCodeStringDisposition5Test() {
+ // get Error Code String while Disposition = 5
newErrorObject.setDisposition("5");
assertEquals(newErrorObject.getErrorCodeString(), "ERR.5.category.errorCode");
}
+
@Test
- public void getSeverityCodeTest(){
+ public void getSeverityCodeTest() {
newErrorObject.setSeverity("WARN");
assertEquals(newErrorObject.getSeverityCode(newErrorObject.getSeverity()), "1");
-
+
newErrorObject.setSeverity("ERROR");
assertEquals(newErrorObject.getSeverityCode(newErrorObject.getSeverity()), "2");
-
+
newErrorObject.setSeverity("FATAL");
assertEquals(newErrorObject.getSeverityCode(newErrorObject.getSeverity()), "3");
}
- //To String Test
+
+ // To String Test
@Test
- public void toStringTest(){
- assertEquals(newErrorObject.toString(), "ErrorObject [errorCode=errorCode, errorText=errorText, restErrorCode=restErrorCode, httpResponseCode=OK, severity=severity, disposition=disposition, category=category]");
+ public void toStringTest() {
+ assertEquals(newErrorObject.toString(),
+ "ErrorObject [errorCode=errorCode, errorText=errorText, restErrorCode=restErrorCode, httpResponseCode=OK, severity=severity, disposition=disposition, category=category]");
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/logging/LoggingContextTest.java b/aai-core/src/test/java/org/onap/aai/logging/LoggingContextTest.java
index 0e2a1c3d..74347730 100644
--- a/aai-core/src/test/java/org/onap/aai/logging/LoggingContextTest.java
+++ b/aai-core/src/test/java/org/onap/aai/logging/LoggingContextTest.java
@@ -17,13 +17,14 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.logging;
-import org.junit.Test;
+import static org.junit.Assert.*;
import java.util.*;
-import static org.junit.Assert.*;
+import org.junit.Test;
public class LoggingContextTest {
@@ -33,9 +34,10 @@ public class LoggingContextTest {
public void testStopWatch() {
try {
LoggingContext.stopWatchStop();
- throw new AssertionError("No exception thrown when LoggingContext.stopWatchStop() called without a prior LoggingContext.stopWatchStart()");
+ throw new AssertionError(
+ "No exception thrown when LoggingContext.stopWatchStop() called without a prior LoggingContext.stopWatchStart()");
} catch (StopWatchNotStartedException e) {
- //Expected
+ // Expected
}
LoggingContext.stopWatchStart();
@@ -46,12 +48,12 @@ public class LoggingContextTest {
LoggingContext.stopWatchStop();
throw new AssertionError("No exception thrown when LoggingContext.stopWatchStop() twice in succession");
} catch (StopWatchNotStartedException e) {
- //Expected
+ // Expected
}
}
@Test
- public void testRequestId() { //AKA Transaction ID
+ public void testRequestId() { // AKA Transaction ID
final String sUuid = "57d51eaa-edc6-4f50-a69d-f2d4d2445120";
LoggingContext.requestId(sUuid);
@@ -64,12 +66,12 @@ public class LoggingContextTest {
assertEquals(LoggingContext.requestId(), uuid);
- LoggingContext.requestId("foo"); //Illegal - this will result in a new, randomly
- //generated UUID as per the logging spec
+ LoggingContext.requestId("foo"); // Illegal - this will result in a new, randomly
+ // generated UUID as per the logging spec
- assertNotNull(LoggingContext.requestId()); //Make sure ANY UUID was assigned
- assertNotEquals(LoggingContext.requestId(), uuid); //Make sure it actually changed from the last
- //known valid UUID
+ assertNotNull(LoggingContext.requestId()); // Make sure ANY UUID was assigned
+ assertNotEquals(LoggingContext.requestId(), uuid); // Make sure it actually changed from the last
+ // known valid UUID
}
@Test
@@ -83,13 +85,13 @@ public class LoggingContextTest {
@Test
public void testSaveRestore() {
- final Deque<Map<String, String>> contexts = new LinkedList<Map<String, String>> ();
+ final Deque<Map<String, String>> contexts = new LinkedList<Map<String, String>>();
LoggingContext.init();
for (int i = 0; i < MAX_STORED_CONTEXTS; i++) {
LoggingContext.customField1(String.valueOf(i));
-
+
assertEquals(LoggingContext.customField1(), String.valueOf(i));
LoggingContext.save();
diff --git a/aai-core/src/test/java/org/onap/aai/parsers/query/GraphTraversalTest.java b/aai-core/src/test/java/org/onap/aai/parsers/query/GraphTraversalTest.java
index 478f8bfa..1f347318 100644
--- a/aai-core/src/test/java/org/onap/aai/parsers/query/GraphTraversalTest.java
+++ b/aai-core/src/test/java/org/onap/aai/parsers/query/GraphTraversalTest.java
@@ -17,8 +17,25 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.parsers.query;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.Matchers.hasProperty;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertEquals;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.UriBuilder;
+
import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
@@ -35,26 +52,11 @@ import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.ModelType;
import org.onap.aai.rest.RestTokens;
-import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.JanusGraphDBEngine;
+import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
import org.springframework.test.annotation.DirtiesContext;
-import javax.ws.rs.core.MultivaluedHashMap;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.UriBuilder;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.Matchers.hasProperty;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertEquals;
-
@RunWith(value = Parameterized.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class GraphTraversalTest extends DataLinkSetup {
@@ -67,32 +69,26 @@ public class GraphTraversalTest extends DataLinkSetup {
@Parameterized.Parameters(name = "QueryStyle.{0}")
public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][]{
- {QueryStyle.TRAVERSAL},
- {QueryStyle.TRAVERSAL_URI}
- });
+ return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
}
- @Rule public ExpectedException thrown = ExpectedException.none();
-
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
/**
* Configure.
+ *
* @throws Exception
* @throws SecurityException
* @throws NoSuchFieldException
*/
@Before
public void configure() throws Exception {
- dbEngine =
- new JanusGraphDBEngine(queryStyle,
- loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()),
- false);
-
- dbEngineDepthVersion =
- new JanusGraphDBEngine(queryStyle,
- loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion()),
- false);
+ dbEngine = new JanusGraphDBEngine(queryStyle,
+ loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion()), false);
+
+ dbEngineDepthVersion = new JanusGraphDBEngine(queryStyle,
+ loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDepthVersion()), false);
}
/**
@@ -107,25 +103,15 @@ public class GraphTraversalTest extends DataLinkSetup {
QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex");
- assertEquals(
- "gremlin query should be " + expected.toString(),
- expected.toString(),
+ GraphTraversal<Vertex, Vertex> expected =
+ __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex");
+ assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
query.getQueryBuilder().getQuery().toString());
- assertEquals(
- "parent gremlin query should be equal to normal query",
- expected.toString(),
+ assertEquals("parent gremlin query should be equal to normal query", expected.toString(),
query.getQueryBuilder().getParentQuery().getQuery().toString());
- assertEquals(
- "result type should be complex",
- "complex",
- query.getResultType());
- assertEquals(
- "result type should be empty",
- "",
- query.getParentResultType());
- assertEquals("dependent",false, query.isDependent());
-
+ assertEquals("result type should be complex", "complex", query.getResultType());
+ assertEquals("result type should be empty", "", query.getParentResultType());
+ assertEquals("dependent", false, query.isDependent());
}
@@ -137,33 +123,21 @@ public class GraphTraversalTest extends DataLinkSetup {
*/
@Test
public void childQuery() throws UnsupportedEncodingException, AAIException {
- URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3").build();
+ URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3")
+ .build();
QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
- .has("physical-location-id", "key1").has("aai-node-type", "complex")
- .in("org.onap.relationships.inventory.BelongsTo")
- .has("aai-node-type", "ctag-pool")
- .has("target-pe", "key2").has("availability-zone-name", "key3");
- GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
- .has("physical-location-id", "key1").has("aai-node-type", "complex");
- assertEquals(
- "gremlin query should be " + expected.toString(),
- expected.toString(),
+ GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("physical-location-id", "key1")
+ .has("aai-node-type", "complex").in("org.onap.relationships.inventory.BelongsTo")
+ .has("aai-node-type", "ctag-pool").has("target-pe", "key2").has("availability-zone-name", "key3");
+ GraphTraversal<Vertex, Vertex> expectedParent =
+ __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex");
+ assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
query.getQueryBuilder().getQuery().toString());
- assertEquals(
- "parent gremlin query should be equal the query for complex",
- expectedParent.toString(),
+ assertEquals("parent gremlin query should be equal the query for complex", expectedParent.toString(),
query.getQueryBuilder().getParentQuery().getQuery().toString());
- assertEquals(
- "result type should be complex",
- "complex",
- query.getParentResultType());
- assertEquals(
- "result type should be ctag-pool",
- "ctag-pool",
- query.getResultType());
- assertEquals("dependent",true, query.isDependent());
-
+ assertEquals("result type should be complex", "complex", query.getParentResultType());
+ assertEquals("result type should be ctag-pool", "ctag-pool", query.getResultType());
+ assertEquals("dependent", true, query.isDependent());
}
@@ -175,42 +149,24 @@ public class GraphTraversalTest extends DataLinkSetup {
*/
@Test
public void namingExceptions() throws UnsupportedEncodingException, AAIException {
- URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build();
+ URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655")
+ .build();
QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
- .has("vnf-id", "key1").has("aai-node-type", "vce")
- .in("org.onap.relationships.inventory.BelongsTo")
- .has("aai-node-type", "port-group")
+ GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "vce")
+ .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "port-group")
.has("interface-id", "key2").in("org.onap.relationships.inventory.BelongsTo")
- .has("aai-node-type", "cvlan-tag")
- .has("cvlan-tag", 655);
- GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
- .has("vnf-id", "key1").has("aai-node-type", "vce")
- .in("org.onap.relationships.inventory.BelongsTo")
- .has("aai-node-type", "port-group")
- .has("interface-id", "key2");
- assertEquals(
- "gremlin query should be " + expected.toString(),
- expected.toString(),
+ .has("aai-node-type", "cvlan-tag").has("cvlan-tag", 655);
+ GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("vnf-id", "key1")
+ .has("aai-node-type", "vce").in("org.onap.relationships.inventory.BelongsTo")
+ .has("aai-node-type", "port-group").has("interface-id", "key2");
+ assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
query.getQueryBuilder().getQuery().toString());
- assertEquals(
- "parent gremlin query should be equal the query for port group",
- expectedParent.toString(),
+ assertEquals("parent gremlin query should be equal the query for port group", expectedParent.toString(),
query.getQueryBuilder().getParentQuery().getQuery().toString());
- assertEquals(
- "result type should be cvlan-tag",
- "cvlan-tag",
- query.getResultType());
- assertEquals(
- "result type should be port-group",
- "port-group",
- query.getParentResultType());
- assertEquals(
- "contaner type should be empty",
- "",
- query.getContainerType());
- assertEquals("dependent",true, query.isDependent());
-
+ assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());
+ assertEquals("result type should be port-group", "port-group", query.getParentResultType());
+ assertEquals("contaner type should be empty", "", query.getContainerType());
+ assertEquals("dependent", true, query.isDependent());
}
@@ -225,39 +181,21 @@ public class GraphTraversalTest extends DataLinkSetup {
public void getAll() throws UnsupportedEncodingException, AAIException {
URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags").build();
QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
- .has("vnf-id", "key1").has("aai-node-type", "vce")
- .in("org.onap.relationships.inventory.BelongsTo")
- .has("aai-node-type", "port-group")
+ GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "vce")
+ .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "port-group")
.has("interface-id", "key2").in("org.onap.relationships.inventory.BelongsTo")
.has("aai-node-type", "cvlan-tag");
- GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
- .has("vnf-id", "key1").has("aai-node-type", "vce")
- .in("org.onap.relationships.inventory.BelongsTo")
- .has("aai-node-type", "port-group")
- .has("interface-id", "key2");
- assertEquals(
- "gremlin query should be " + expected.toString(),
- expected.toString(),
+ GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("vnf-id", "key1")
+ .has("aai-node-type", "vce").in("org.onap.relationships.inventory.BelongsTo")
+ .has("aai-node-type", "port-group").has("interface-id", "key2");
+ assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
query.getQueryBuilder().getQuery().toString());
- assertEquals(
- "parent gremlin query should be equal the query for port group",
- expectedParent.toString(),
+ assertEquals("parent gremlin query should be equal the query for port group", expectedParent.toString(),
query.getQueryBuilder().getParentQuery().getQuery().toString());
- assertEquals(
- "result type should be port-group",
- "port-group",
- query.getParentResultType());
- assertEquals(
- "result type should be cvlan-tag",
- "cvlan-tag",
- query.getResultType());
- assertEquals(
- "container type should be cvlan-tags",
- "cvlan-tags",
- query.getContainerType());
- assertEquals("dependent",true, query.isDependent());
-
+ assertEquals("result type should be port-group", "port-group", query.getParentResultType());
+ assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());
+ assertEquals("container type should be cvlan-tags", "cvlan-tags", query.getContainerType());
+ assertEquals("dependent", true, query.isDependent());
}
@@ -265,36 +203,19 @@ public class GraphTraversalTest extends DataLinkSetup {
public void getAllParent() throws UnsupportedEncodingException, AAIException {
URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers").build();
QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
- .has("aai-node-type", "pserver");
- GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
- .has("aai-node-type", "pserver");
- assertEquals(
- "gremlin query should be " + expected.toString(),
- expected.toString(),
+ GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-node-type", "pserver");
+ GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("aai-node-type", "pserver");
+ assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
query.getQueryBuilder().getQuery().toString());
- assertEquals(
- "parent gremlin query should be equal the query for pserver",
- expectedParent.toString(),
+ assertEquals("parent gremlin query should be equal the query for pserver", expectedParent.toString(),
query.getQueryBuilder().getParentQuery().getQuery().toString());
- assertEquals(
- "parent result type should be empty",
- "",
- query.getParentResultType());
- assertEquals(
- "result type should be pserver",
- "pserver",
- query.getResultType());
- assertEquals(
- "container type should be pservers",
- "pservers",
- query.getContainerType());
- assertEquals("dependent",false, query.isDependent());
-
+ assertEquals("parent result type should be empty", "", query.getParentResultType());
+ assertEquals("result type should be pserver", "pserver", query.getResultType());
+ assertEquals("container type should be pservers", "pservers", query.getContainerType());
+ assertEquals("dependent", false, query.isDependent());
}
-
/**
* Gets the via query param.
*
@@ -304,86 +225,58 @@ public class GraphTraversalTest extends DataLinkSetup {
*/
@Test
public void getViaQueryParam() throws UnsupportedEncodingException, AAIException {
- URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant").build();
+ URI uri = UriBuilder
+ .fromPath("cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant")
+ .build();
MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
map.putSingle("tenant-name", "Tenant1");
QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
- .has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
- .has("aai-node-type", "cloud-region")
- .in("org.onap.relationships.inventory.BelongsTo")
- .has("aai-node-type", "tenant")
- .has("tenant-name", "Tenant1");
-
- GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
- .has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
- .has("aai-node-type", "cloud-region");
-
- assertEquals(
- "gremlin query should be " + expected.toString(),
- expected.toString(),
+ GraphTraversal<Vertex, Vertex> expected =
+ __.<Vertex>start().has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
+ .has("aai-node-type", "cloud-region").in("org.onap.relationships.inventory.BelongsTo")
+ .has("aai-node-type", "tenant").has("tenant-name", "Tenant1");
+
+ GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("cloud-owner", "mycloudowner")
+ .has("cloud-region-id", "mycloudregionid").has("aai-node-type", "cloud-region");
+
+ assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
query.getQueryBuilder().getQuery().toString());
- assertEquals(
- "parent gremlin query should be equal the query for cloud-region",
- expectedParent.toString(),
+ assertEquals("parent gremlin query should be equal the query for cloud-region", expectedParent.toString(),
query.getQueryBuilder().getParentQuery().getQuery().toString());
- assertEquals(
- "result type should be cloud-region",
- "cloud-region",
- query.getParentResultType());
- assertEquals(
- "result type should be tenant",
- "tenant",
- query.getResultType());
- assertEquals(
- "container type should be empty",
- "",
- query.getContainerType());
- assertEquals("dependent",true, query.isDependent());
+ assertEquals("result type should be cloud-region", "cloud-region", query.getParentResultType());
+ assertEquals("result type should be tenant", "tenant", query.getResultType());
+ assertEquals("container type should be empty", "", query.getContainerType());
+ assertEquals("dependent", true, query.isDependent());
}
@Test
public void getViaDuplicateQueryParam() throws UnsupportedEncodingException, AAIException {
- URI uri = UriBuilder.fromPath("cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant").build();
+ URI uri = UriBuilder
+ .fromPath("cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant")
+ .build();
MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
List<String> values = new ArrayList<>();
values.add("Tenant1");
values.add("Tenant2");
map.put("tenant-name", values);
QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
- .has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
- .has("aai-node-type", "cloud-region")
- .in("org.onap.relationships.inventory.BelongsTo")
- .has("aai-node-type", "tenant")
- .has("tenant-name", P.within(values));
-
- GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
- .has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
- .has("aai-node-type", "cloud-region");
-
- assertEquals(
- "gremlin query should be " + expected.toString(),
- expected.toString(),
+ GraphTraversal<Vertex, Vertex> expected =
+ __.<Vertex>start().has("cloud-owner", "mycloudowner").has("cloud-region-id", "mycloudregionid")
+ .has("aai-node-type", "cloud-region").in("org.onap.relationships.inventory.BelongsTo")
+ .has("aai-node-type", "tenant").has("tenant-name", P.within(values));
+
+ GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("cloud-owner", "mycloudowner")
+ .has("cloud-region-id", "mycloudregionid").has("aai-node-type", "cloud-region");
+
+ assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
query.getQueryBuilder().getQuery().toString());
- assertEquals(
- "parent gremlin query should be equal the query for cloud-region",
- expectedParent.toString(),
+ assertEquals("parent gremlin query should be equal the query for cloud-region", expectedParent.toString(),
query.getQueryBuilder().getParentQuery().getQuery().toString());
- assertEquals(
- "result type should be cloud-region",
- "cloud-region",
- query.getParentResultType());
- assertEquals(
- "result type should be tenant",
- "tenant",
- query.getResultType());
- assertEquals(
- "container type should be empty",
- "",
- query.getContainerType());
- assertEquals("dependent",true, query.isDependent());
+ assertEquals("result type should be cloud-region", "cloud-region", query.getParentResultType());
+ assertEquals("result type should be tenant", "tenant", query.getResultType());
+ assertEquals("container type should be empty", "", query.getContainerType());
+ assertEquals("dependent", true, query.isDependent());
}
@@ -400,34 +293,19 @@ public class GraphTraversalTest extends DataLinkSetup {
MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
map.putSingle("prov-status", "up");
QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
- .has("aai-node-type", "vnfc")
- .has("prov-status", "up");
+ GraphTraversal<Vertex, Vertex> expected =
+ __.<Vertex>start().has("aai-node-type", "vnfc").has("prov-status", "up");
- GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
- .has("aai-node-type", "vnfc");
+ GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("aai-node-type", "vnfc");
- assertEquals(
- "gremlin query should be " + expected.toString(),
- expected.toString(),
+ assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
query.getQueryBuilder().getQuery().toString());
- assertEquals(
- "parent",
- expectedParent.toString(),
+ assertEquals("parent", expectedParent.toString(),
query.getQueryBuilder().getParentQuery().getQuery().toString());
- assertEquals(
- "parent result type should be empty",
- "",
- query.getParentResultType());
- assertEquals(
- "result type should be vnfc",
- "vnfc",
- query.getResultType());
- assertEquals(
- "container type should be empty",
- "vnfcs",
- query.getContainerType());
- assertEquals("dependent",true, query.isDependent());
+ assertEquals("parent result type should be empty", "", query.getParentResultType());
+ assertEquals("result type should be vnfc", "vnfc", query.getResultType());
+ assertEquals("container type should be empty", "vnfcs", query.getContainerType());
+ assertEquals("dependent", true, query.isDependent());
}
@@ -445,40 +323,21 @@ public class GraphTraversalTest extends DataLinkSetup {
map.putSingle("cvlan-tag", "333");
QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
- .has("vnf-id", "key1").has("aai-node-type", "vce")
- .in("org.onap.relationships.inventory.BelongsTo")
- .has("aai-node-type", "port-group")
+ GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "vce")
+ .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "port-group")
.has("interface-id", "key2").in("org.onap.relationships.inventory.BelongsTo")
- .has("aai-node-type", "cvlan-tag")
- .has("cvlan-tag", 333);
- GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
- .has("vnf-id", "key1").has("aai-node-type", "vce")
- .in("org.onap.relationships.inventory.BelongsTo")
- .has("aai-node-type", "port-group")
- .has("interface-id", "key2");
- assertEquals(
- "gremlin query should be " + expected.toString(),
- expected.toString(),
+ .has("aai-node-type", "cvlan-tag").has("cvlan-tag", 333);
+ GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("vnf-id", "key1")
+ .has("aai-node-type", "vce").in("org.onap.relationships.inventory.BelongsTo")
+ .has("aai-node-type", "port-group").has("interface-id", "key2");
+ assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
query.getQueryBuilder().getQuery().toString());
- assertEquals(
- "parent gremlin query should be equal the query for port group",
- expectedParent.toString(),
+ assertEquals("parent gremlin query should be equal the query for port group", expectedParent.toString(),
query.getQueryBuilder().getParentQuery().getQuery().toString());
- assertEquals(
- "result type should be port-group",
- "port-group",
- query.getParentResultType());
- assertEquals(
- "result type should be cvlan-tag",
- "cvlan-tag",
- query.getResultType());
- assertEquals(
- "container type should be cvlan-tags",
- "cvlan-tags",
- query.getContainerType());
- assertEquals("dependent",true, query.isDependent());
-
+ assertEquals("result type should be port-group", "port-group", query.getParentResultType());
+ assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());
+ assertEquals("container type should be cvlan-tags", "cvlan-tags", query.getContainerType());
+ assertEquals("dependent", true, query.isDependent());
}
@@ -494,29 +353,18 @@ public class GraphTraversalTest extends DataLinkSetup {
QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
- .has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf"));
+ GraphTraversal<Vertex, Vertex> expected =
+ __.<Vertex>start().has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf"));
GraphTraversal<Vertex, Vertex> expectedParent = expected;
- assertEquals(
- "gremlin query should be " + expected.toString(),
- expected.toString(),
+ assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
query.getQueryBuilder().getQuery().toString());
- assertEquals(
- "parent gremlin query should be equal the query for port group",
- expectedParent.toString(),
+ assertEquals("parent gremlin query should be equal the query for port group", expectedParent.toString(),
query.getQueryBuilder().getParentQuery().getQuery().toString());
- assertEquals(
- "result type should be empty",
- "",
- query.getParentResultType());
- assertEquals(
- "result type should be vnf",
- "vnf",
- query.getResultType());
-
- assertEquals("dependent",false, query.isDependent());
+ assertEquals("result type should be empty", "", query.getParentResultType());
+ assertEquals("result type should be vnf", "vnf", query.getResultType());
+ assertEquals("dependent", false, query.isDependent());
}
@@ -540,30 +388,21 @@ public class GraphTraversalTest extends DataLinkSetup {
QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
- .has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf"))
- .union(__.in("org.onap.relationships.inventory.BelongsTo").has(AAIProperties.NODE_TYPE, "vf-module")).has("vf-module-id", "key2");
+ GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1")
+ .has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf"))
+ .union(__.in("org.onap.relationships.inventory.BelongsTo").has(AAIProperties.NODE_TYPE, "vf-module"))
+ .has("vf-module-id", "key2");
- GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
- .has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf"));
- assertEquals(
- "gremlin query should be " + expected.toString(),
- expected.toString(),
+ GraphTraversal<Vertex, Vertex> expectedParent =
+ __.<Vertex>start().has("vnf-id", "key1").has(AAIProperties.NODE_TYPE, P.within("vce", "generic-vnf"));
+ assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
query.getQueryBuilder().getQuery().toString());
- assertEquals(
- "parent gremlin query should be equal the query for ",
- expectedParent.toString(),
+ assertEquals("parent gremlin query should be equal the query for ", expectedParent.toString(),
query.getQueryBuilder().getParentQuery().getQuery().toString());
- assertEquals(
- "result type should be vnf",
- "vnf",
- query.getParentResultType());
- assertEquals(
- "result type should be vf-module",
- "vf-module",
- query.getResultType());
+ assertEquals("result type should be vnf", "vnf", query.getParentResultType());
+ assertEquals("result type should be vf-module", "vf-module", query.getResultType());
- assertEquals("dependent",true, query.isDependent());
+ assertEquals("dependent", true, query.isDependent());
}
@@ -603,34 +442,19 @@ public class GraphTraversalTest extends DataLinkSetup {
values.add("start");
map.put("prov-status", values);
QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri, map);
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
- .has("aai-node-type", "vnfc")
- .has("prov-status", P.within(values));
+ GraphTraversal<Vertex, Vertex> expected =
+ __.<Vertex>start().has("aai-node-type", "vnfc").has("prov-status", P.within(values));
- GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
- .has("aai-node-type", "vnfc");
+ GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("aai-node-type", "vnfc");
- assertEquals(
- "gremlin query should be " + expected.toString(),
- expected.toString(),
+ assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
query.getQueryBuilder().getQuery().toString());
- assertEquals(
- "parent",
- expectedParent.toString(),
+ assertEquals("parent", expectedParent.toString(),
query.getQueryBuilder().getParentQuery().getQuery().toString());
- assertEquals(
- "parent result type should be empty",
- "",
- query.getParentResultType());
- assertEquals(
- "result type should be vnfc",
- "vnfc",
- query.getResultType());
- assertEquals(
- "container type should be empty",
- "vnfcs",
- query.getContainerType());
- assertEquals("dependent",true, query.isDependent());
+ assertEquals("parent result type should be empty", "", query.getParentResultType());
+ assertEquals("result type should be vnfc", "vnfc", query.getResultType());
+ assertEquals("container type should be empty", "vnfcs", query.getContainerType());
+ assertEquals("dependent", true, query.isDependent());
}
@@ -640,31 +464,18 @@ public class GraphTraversalTest extends DataLinkSetup {
MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
map.putSingle("persona-model-customization-id", "key2");
QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri, map);
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
- .has("aai-node-type", "generic-vnf")
- .has("model-customization-id", "key2");
- GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
- .has("aai-node-type", "generic-vnf");
-
- assertEquals(
- "gremlin query should be " + expected.toString(),
- expected.toString(),
+ GraphTraversal<Vertex, Vertex> expected =
+ __.<Vertex>start().has("aai-node-type", "generic-vnf").has("model-customization-id", "key2");
+ GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("aai-node-type", "generic-vnf");
+
+ assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
query.getQueryBuilder().getQuery().toString());
- assertEquals(
- "parent",
- expectedParent.toString(),
+ assertEquals("parent", expectedParent.toString(),
query.getQueryBuilder().getParentQuery().getQuery().toString());
- assertEquals(
- "result type should be",
- "generic-vnf",
- query.getResultType());
- assertEquals(
- "result type should be empty",
- "",
- query.getParentResultType());
- assertEquals("dependent",true, query.isDependent());
-
+ assertEquals("result type should be", "generic-vnf", query.getResultType());
+ assertEquals("result type should be empty", "", query.getParentResultType());
+ assertEquals("dependent", true, query.isDependent());
}
@@ -674,30 +485,19 @@ public class GraphTraversalTest extends DataLinkSetup {
MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
map.putSingle("global-route-target", "key2");
QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri, map);
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
- .has("aai-node-type", "vpn-binding")
- .where(__.in("org.onap.relationships.inventory.BelongsTo").has(AAIProperties.NODE_TYPE, "route-target").has("global-route-target", "key2"));
- GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
- .has("aai-node-type", "vpn-binding");
-
- assertEquals(
- "gremlin query should be " + expected.toString(),
- expected.toString(),
+ GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-node-type", "vpn-binding")
+ .where(__.in("org.onap.relationships.inventory.BelongsTo").has(AAIProperties.NODE_TYPE, "route-target")
+ .has("global-route-target", "key2"));
+ GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("aai-node-type", "vpn-binding");
+
+ assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
query.getQueryBuilder().getQuery().toString());
- assertEquals(
- "parent",
- expectedParent.toString(),
+ assertEquals("parent", expectedParent.toString(),
query.getQueryBuilder().getParentQuery().getQuery().toString());
- assertEquals(
- "result type should be",
- "vpn-binding",
- query.getResultType());
- assertEquals(
- "result type should be empty",
- "",
- query.getParentResultType());
- assertEquals("dependent",true, query.isDependent());
+ assertEquals("result type should be", "vpn-binding", query.getResultType());
+ assertEquals("result type should be empty", "", query.getParentResultType());
+ assertEquals("dependent", true, query.isDependent());
}
@Test
@@ -705,107 +505,70 @@ public class GraphTraversalTest extends DataLinkSetup {
URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers").build();
QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri);
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
- .has("physical-location-id", "key1")
- .has("aai-node-type", "complex")
- .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver");
- GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
- .has("physical-location-id", "key1")
- .has("aai-node-type", "complex");
-
- assertEquals(
- "gremlin query should be " + expected.toString(),
- expected.toString(),
+ GraphTraversal<Vertex, Vertex> expected =
+ __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex")
+ .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver");
+ GraphTraversal<Vertex, Vertex> expectedParent =
+ __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex");
+
+ assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
query.getQueryBuilder().getQuery().toString());
- assertEquals(
- "parent",
- expectedParent.toString(),
+ assertEquals("parent", expectedParent.toString(),
query.getQueryBuilder().getParentQuery().getQuery().toString());
- assertEquals(
- "result type should be",
- "pserver",
- query.getResultType());
- assertEquals(
- "result type should be",
- "complex",
- query.getParentResultType());
- //this is controversial but we're not allowing writes on this currently
- assertEquals("dependent",true, query.isDependent());
+ assertEquals("result type should be", "pserver", query.getResultType());
+ assertEquals("result type should be", "complex", query.getParentResultType());
+ // this is controversial but we're not allowing writes on this currently
+ assertEquals("dependent", true, query.isDependent());
}
@Test
public void specificCousin() throws UnsupportedEncodingException, AAIException {
- URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers/pserver/key2").build();
+ URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers/pserver/key2")
+ .build();
QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri);
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
- .has("physical-location-id", "key1")
- .has("aai-node-type", "complex")
- .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver")
- .has("hostname", "key2");
- GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
- .has("physical-location-id", "key1")
- .has("aai-node-type", "complex");
-
- assertEquals(
- "gremlin query should be " + expected.toString(),
- expected.toString(),
+ GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("physical-location-id", "key1")
+ .has("aai-node-type", "complex").in("org.onap.relationships.inventory.LocatedIn")
+ .has("aai-node-type", "pserver").has("hostname", "key2");
+ GraphTraversal<Vertex, Vertex> expectedParent =
+ __.<Vertex>start().has("physical-location-id", "key1").has("aai-node-type", "complex");
+
+ assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
query.getQueryBuilder().getQuery().toString());
- assertEquals(
- "parent",
- expectedParent.toString(),
+ assertEquals("parent", expectedParent.toString(),
query.getQueryBuilder().getParentQuery().getQuery().toString());
- assertEquals(
- "result type should be",
- "pserver",
- query.getResultType());
- assertEquals(
- "result type should be",
- "complex",
- query.getParentResultType());
- //this is controversial but we're not allowing writes on this currently
- assertEquals("dependent",true, query.isDependent());
+ assertEquals("result type should be", "pserver", query.getResultType());
+ assertEquals("result type should be", "complex", query.getParentResultType());
+ // this is controversial but we're not allowing writes on this currently
+ assertEquals("dependent", true, query.isDependent());
}
@Test
public void doubleSpecificCousin() throws UnsupportedEncodingException, AAIException {
- URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/related-to/pservers/pserver/key2/related-to/vservers/vserver/key3").build();
+ URI uri = UriBuilder.fromPath(
+ "cloud-infrastructure/complexes/complex/key1/related-to/pservers/pserver/key2/related-to/vservers/vserver/key3")
+ .build();
QueryParser query = dbEngineDepthVersion.getQueryBuilder().createQueryFromURI(uri);
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
- .has("physical-location-id", "key1")
- .has("aai-node-type", "complex")
- .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver")
- .has("hostname", "key2")
- .in("tosca.relationships.HostedOn").has("aai-node-type", "vserver")
- .has("vserver-id", "key3");
- GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start()
- .has("physical-location-id", "key1")
- .has("aai-node-type", "complex")
- .in("org.onap.relationships.inventory.LocatedIn").has("aai-node-type", "pserver")
- .has("hostname", "key2");
-
- assertEquals(
- "gremlin query should be " + expected.toString(),
- expected.toString(),
+ GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("physical-location-id", "key1")
+ .has("aai-node-type", "complex").in("org.onap.relationships.inventory.LocatedIn")
+ .has("aai-node-type", "pserver").has("hostname", "key2").in("tosca.relationships.HostedOn")
+ .has("aai-node-type", "vserver").has("vserver-id", "key3");
+ GraphTraversal<Vertex, Vertex> expectedParent = __.<Vertex>start().has("physical-location-id", "key1")
+ .has("aai-node-type", "complex").in("org.onap.relationships.inventory.LocatedIn")
+ .has("aai-node-type", "pserver").has("hostname", "key2");
+
+ assertEquals("gremlin query should be " + expected.toString(), expected.toString(),
query.getQueryBuilder().getQuery().toString());
- assertEquals(
- "parent",
- expectedParent.toString(),
+ assertEquals("parent", expectedParent.toString(),
query.getQueryBuilder().getParentQuery().getQuery().toString());
- assertEquals(
- "result type should be",
- "vserver",
- query.getResultType());
- assertEquals(
- "result type should be",
- "pserver",
- query.getParentResultType());
- //this is controversial but we're not allowing writes on this currently
- assertEquals("dependent",true, query.isDependent());
+ assertEquals("result type should be", "vserver", query.getResultType());
+ assertEquals("result type should be", "pserver", query.getParentResultType());
+ // this is controversial but we're not allowing writes on this currently
+ assertEquals("dependent", true, query.isDependent());
}
@Test
diff --git a/aai-core/src/test/java/org/onap/aai/parsers/query/LegacyQueryTest.java b/aai-core/src/test/java/org/onap/aai/parsers/query/LegacyQueryTest.java
index 8272f775..4cdc55fa 100644
--- a/aai-core/src/test/java/org/onap/aai/parsers/query/LegacyQueryTest.java
+++ b/aai-core/src/test/java/org/onap/aai/parsers/query/LegacyQueryTest.java
@@ -17,42 +17,39 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.parsers.query;
+import static org.junit.Assert.assertEquals;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+
+import javax.ws.rs.core.UriBuilder;
+import javax.xml.bind.JAXBException;
+
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
import org.junit.Ignore;
import org.junit.Test;
import org.onap.aai.AAISetup;
import org.onap.aai.exceptions.AAIException;
-
import org.onap.aai.introspection.ModelType;
-import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.JanusGraphDBEngine;
+import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
import org.onap.aai.setup.SchemaVersion;
-import javax.ws.rs.core.UriBuilder;
-import javax.xml.bind.JAXBException;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-
-import static org.junit.Assert.assertEquals;
-
-
@Ignore
public class LegacyQueryTest extends AAISetup {
-
private TransactionalGraphEngine dbEngine;
private SchemaVersion version;
private DynamicJAXBContext context = nodeIngestor.getContextForVersion(version);
- public void setup(){
+ public void setup() {
version = new SchemaVersion("v10");
- dbEngine =
- new JanusGraphDBEngine(QueryStyle.GREMLIN_TRAVERSAL,
- loaderFactory.createLoaderForVersion(ModelType.MOXY, version),
- false);
+ dbEngine = new JanusGraphDBEngine(QueryStyle.GREMLIN_TRAVERSAL,
+ loaderFactory.createLoaderForVersion(ModelType.MOXY, version), false);
}
/**
@@ -64,26 +61,17 @@ public class LegacyQueryTest extends AAISetup {
*/
@Test
public void parentQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
-
+
URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1").build();
QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
- String expected =
- ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
- assertEquals(
- "gremlin query should be " + expected,
- expected,
- query.getQueryBuilder().getQuery());
- assertEquals(
- "parent gremlin query should be equal to normal query",
- expected,
+ String expected = ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
+ assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
+ assertEquals("parent gremlin query should be equal to normal query", expected,
query.getQueryBuilder().getParentQuery().getQuery());
- assertEquals(
- "result type should be pserver",
- "pserver",
- query.getResultType());
-
+ assertEquals("result type should be pserver", "pserver", query.getResultType());
+
}
/**
@@ -95,29 +83,19 @@ public class LegacyQueryTest extends AAISetup {
*/
@Test
public void childQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
- URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1/lag-interfaces/lag-interface/key2").build();
+ URI uri = UriBuilder.fromPath("cloud-infrastructure/pservers/pserver/key1/lag-interfaces/lag-interface/key2")
+ .build();
QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
- String expected =
- ".has('hostname', 'key1').has('aai-node-type', 'pserver')"
- + ".out('hasLAGInterface').has('aai-node-type', 'lag-interface')"
- + ".has('interface-name', 'key2')";
- String parentExpected =
- ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
- assertEquals(
- "gremlin query should be for node",
- expected,
- query.getQueryBuilder().getQuery());
- assertEquals(
- "parent gremlin query should be for parent",
- parentExpected,
+ String expected = ".has('hostname', 'key1').has('aai-node-type', 'pserver')"
+ + ".out('hasLAGInterface').has('aai-node-type', 'lag-interface')" + ".has('interface-name', 'key2')";
+ String parentExpected = ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
+ assertEquals("gremlin query should be for node", expected, query.getQueryBuilder().getQuery());
+ assertEquals("parent gremlin query should be for parent", parentExpected,
query.getQueryBuilder().getParentQuery().getQuery());
- assertEquals(
- "result type should be lag-interface",
- "lag-interface",
- query.getResultType());
+ assertEquals("result type should be lag-interface", "lag-interface", query.getResultType());
}
-
+
/**
* Naming exceptions.
*
@@ -127,32 +105,23 @@ public class LegacyQueryTest extends AAISetup {
*/
@Test
public void namingExceptions() throws JAXBException, UnsupportedEncodingException, AAIException {
- URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build();
-
+ URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655")
+ .build();
+
QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
- String expected =
- ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
+ String expected = ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
+ ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
+ ".has('interface-id', 'key2')"
+ ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')"
+ ".has('cvlan-tag', 655)";
- String expectedParent =
- ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
- + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
- + ".has('interface-id', 'key2')";
- assertEquals(
- "gremlin query should be " + expected,
- expected,
- query.getQueryBuilder().getQuery());
- assertEquals(
- "parent gremlin query should be equal the query for port group",
- expectedParent,
+ String expectedParent = ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
+ + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
+ + ".has('interface-id', 'key2')";
+ assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
+ assertEquals("parent gremlin query should be equal the query for port group", expectedParent,
query.getQueryBuilder().getParentQuery().getQuery());
- assertEquals(
- "result type should be cvlan-tag",
- "cvlan-tag",
- query.getResultType());
-
+ assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());
+
}
-
+
}
diff --git a/aai-core/src/test/java/org/onap/aai/parsers/query/RelationshipGremlinQueryTest.java b/aai-core/src/test/java/org/onap/aai/parsers/query/RelationshipGremlinQueryTest.java
index 045f6b30..96a22d4e 100644
--- a/aai-core/src/test/java/org/onap/aai/parsers/query/RelationshipGremlinQueryTest.java
+++ b/aai-core/src/test/java/org/onap/aai/parsers/query/RelationshipGremlinQueryTest.java
@@ -17,8 +17,19 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.parsers.query;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertEquals;
+
+import java.io.StringReader;
+import java.io.UnsupportedEncodingException;
+
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.transform.stream.StreamSource;
+
import org.eclipse.persistence.dynamic.DynamicEntity;
import org.eclipse.persistence.jaxb.UnmarshallerProperties;
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
@@ -31,20 +42,11 @@ import org.onap.aai.AAISetup;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.*;
import org.onap.aai.nodes.NodeIngestor;
-import org.onap.aai.setup.SchemaVersion;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.JanusGraphDBEngine;
+import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
-
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.transform.stream.StreamSource;
-import java.io.StringReader;
-import java.io.UnsupportedEncodingException;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.junit.Assert.assertEquals;
+import org.onap.aai.setup.SchemaVersion;
+import org.springframework.beans.factory.annotation.Autowired;
@Ignore
public class RelationshipGremlinQueryTest extends AAISetup {
@@ -59,12 +61,10 @@ public class RelationshipGremlinQueryTest extends AAISetup {
public ExpectedException thrown = ExpectedException.none();
@Before
- public void setup(){
+ public void setup() {
version = new SchemaVersion("v10");
- dbEngine =
- new JanusGraphDBEngine(QueryStyle.GREMLIN_TRAVERSAL,
- loaderFactory.createLoaderForVersion(ModelType.MOXY, version),
- false);
+ dbEngine = new JanusGraphDBEngine(QueryStyle.GREMLIN_TRAVERSAL,
+ loaderFactory.createLoaderForVersion(ModelType.MOXY, version), false);
}
/**
@@ -77,14 +77,8 @@ public class RelationshipGremlinQueryTest extends AAISetup {
@Test
public void parentQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
- String content =
- "{"
- + "\"related-to\" : \"pserver\","
- + "\"relationship-data\" : [{"
- + "\"relationship-key\" : \"pserver.hostname\","
- + "\"relationship-value\" : \"key1\""
- + "}]"
- + "}";
+ String content = "{" + "\"related-to\" : \"pserver\"," + "\"relationship-data\" : [{"
+ + "\"relationship-key\" : \"pserver.hostname\"," + "\"relationship-value\" : \"key1\"" + "}]" + "}";
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
@@ -92,25 +86,17 @@ public class RelationshipGremlinQueryTest extends AAISetup {
unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
Object obj = context.newDynamicEntity("Relationship");
- DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
+ DynamicEntity entity = (DynamicEntity) unmarshaller
+ .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
- String expected =
- ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
- assertEquals(
- "gremlin query should be " + expected,
- expected,
- query.getQueryBuilder().getQuery());
- assertEquals(
- "parent gremlin query should be equal to normal query",
- expected,
+ String expected = ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
+ assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
+ assertEquals("parent gremlin query should be equal to normal query", expected,
query.getQueryBuilder().getParentQuery().getQuery());
- assertEquals(
- "result type should be pserver",
- "pserver",
- query.getResultType());
+ assertEquals("result type should be pserver", "pserver", query.getResultType());
}
@@ -123,17 +109,10 @@ public class RelationshipGremlinQueryTest extends AAISetup {
*/
@Test
public void childQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
- String content =
- "{"
- + "\"related-to\" : \"lag-interface\","
- + "\"relationship-data\" : [{"
- + "\"relationship-key\" : \"pserver.hostname\","
- + "\"relationship-value\" : \"key1\""
- + "}, {"
- + "\"relationship-key\" : \"lag-interface.interface-name\","
- + "\"relationship-value\" : \"key2\""
- + "}]"
- + "}";
+ String content = "{" + "\"related-to\" : \"lag-interface\"," + "\"relationship-data\" : [{"
+ + "\"relationship-key\" : \"pserver.hostname\"," + "\"relationship-value\" : \"key1\"" + "}, {"
+ + "\"relationship-key\" : \"lag-interface.interface-name\"," + "\"relationship-value\" : \"key2\""
+ + "}]" + "}";
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
@@ -141,27 +120,20 @@ public class RelationshipGremlinQueryTest extends AAISetup {
unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
Object obj = context.newDynamicEntity("Relationship");
- DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
+ DynamicEntity entity = (DynamicEntity) unmarshaller
+ .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
- String expected = ".has('hostname', 'key1').has('aai-node-type', 'pserver').in('tosca.relationships.BindsTo').has('aai-node-type', 'lag-interface')"
- + ".has('interface-name', 'key2')";
- String parentExpected =
- ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
- assertEquals(
- "gremlin query should be for node",
- expected,
- query.getQueryBuilder().getQuery());
- assertEquals(
- "parent gremlin query should be for parent",
- parentExpected,
+ String expected =
+ ".has('hostname', 'key1').has('aai-node-type', 'pserver').in('tosca.relationships.BindsTo').has('aai-node-type', 'lag-interface')"
+ + ".has('interface-name', 'key2')";
+ String parentExpected = ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
+ assertEquals("gremlin query should be for node", expected, query.getQueryBuilder().getQuery());
+ assertEquals("parent gremlin query should be for parent", parentExpected,
query.getQueryBuilder().getParentQuery().getQuery());
- assertEquals(
- "result type should be lag-interface",
- "lag-interface",
- query.getResultType());
+ assertEquals("result type should be lag-interface", "lag-interface", query.getResultType());
}
/**
@@ -173,20 +145,10 @@ public class RelationshipGremlinQueryTest extends AAISetup {
*/
@Test
public void namingExceptions() throws JAXBException, UnsupportedEncodingException, AAIException {
- String content =
- "{"
- + "\"related-to\" : \"cvlan-tag\","
- + "\"relationship-data\" : [{"
- + "\"relationship-key\" : \"vce.vnf-id\","
- + "\"relationship-value\" : \"key1\""
- + "}, {"
- + "\"relationship-key\" : \"port-group.interface-id\","
- + "\"relationship-value\" : \"key2\""
- + "},{"
- + "\"relationship-key\" : \"cvlan-tag.cvlan-tag\","
- + "\"relationship-value\" : \"655\""
- + "}]"
- + "}";
+ String content = "{" + "\"related-to\" : \"cvlan-tag\"," + "\"relationship-data\" : [{"
+ + "\"relationship-key\" : \"vce.vnf-id\"," + "\"relationship-value\" : \"key1\"" + "}, {"
+ + "\"relationship-key\" : \"port-group.interface-id\"," + "\"relationship-value\" : \"key2\"" + "},{"
+ + "\"relationship-key\" : \"cvlan-tag.cvlan-tag\"," + "\"relationship-value\" : \"655\"" + "}]" + "}";
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
@@ -194,31 +156,22 @@ public class RelationshipGremlinQueryTest extends AAISetup {
unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
Object obj = context.newDynamicEntity("Relationship");
- DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
+ DynamicEntity entity = (DynamicEntity) unmarshaller
+ .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
- String expected =
- ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
+ String expected = ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
+ ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
+ ".has('interface-id', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')"
+ ".has('cvlan-tag', 655)";
- String expectedParent =
- ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
- + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
- + ".has('interface-id', 'key2')";
- assertEquals(
- "gremlin query should be " + expected,
- expected,
- query.getQueryBuilder().getQuery());
- assertEquals(
- "parent gremlin query should be equal the query for port group",
- expectedParent,
+ String expectedParent = ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
+ + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
+ + ".has('interface-id', 'key2')";
+ assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
+ assertEquals("parent gremlin query should be equal the query for port group", expectedParent,
query.getQueryBuilder().getParentQuery().getQuery());
- assertEquals(
- "result type should be cvlan-tag",
- "cvlan-tag",
- query.getResultType());
+ assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());
}
@@ -231,25 +184,13 @@ public class RelationshipGremlinQueryTest extends AAISetup {
*/
@Test
public void scrambledRelationship() throws JAXBException, UnsupportedEncodingException, AAIException {
- String content =
- "{"
- + "\"related-to\" : \"l3-interface-ipv4-address-list\","
- + "\"relationship-data\" : [{"
+ String content = "{" + "\"related-to\" : \"l3-interface-ipv4-address-list\"," + "\"relationship-data\" : [{"
+ "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\","
- + "\"relationship-value\" : \"key5\""
- + "},{"
- + "\"relationship-key\" : \"lag-interface.interface-name\","
- + "\"relationship-value\" : \"key2\""
- + "},{"
- + "\"relationship-key\" : \"l-interface.interface-name\","
- + "\"relationship-value\" : \"key3\""
- + "},{"
- + "\"relationship-key\" : \"vlan.vlan-interface\","
- + "\"relationship-value\" : \"key4\""
- + "},{"
- + "\"relationship-key\" : \"generic-vnf.vnf-id\","
- + "\"relationship-value\" : \"key1\""
- + "}]"
+ + "\"relationship-value\" : \"key5\"" + "},{"
+ + "\"relationship-key\" : \"lag-interface.interface-name\"," + "\"relationship-value\" : \"key2\""
+ + "},{" + "\"relationship-key\" : \"l-interface.interface-name\"," + "\"relationship-value\" : \"key3\""
+ + "},{" + "\"relationship-key\" : \"vlan.vlan-interface\"," + "\"relationship-value\" : \"key4\""
+ + "},{" + "\"relationship-key\" : \"generic-vnf.vnf-id\"," + "\"relationship-value\" : \"key1\"" + "}]"
+ "}";
scrambledRelationshipSpec(content);
}
@@ -263,25 +204,13 @@ public class RelationshipGremlinQueryTest extends AAISetup {
*/
@Test
public void reversedRelationship() throws JAXBException, UnsupportedEncodingException, AAIException {
- String content =
- "{"
- + "\"related-to\" : \"l3-interface-ipv4-address-list\","
- + "\"relationship-data\" : [{"
+ String content = "{" + "\"related-to\" : \"l3-interface-ipv4-address-list\"," + "\"relationship-data\" : [{"
+ "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\","
- + "\"relationship-value\" : \"key5\""
- + "},{"
- + "\"relationship-key\" : \"vlan.vlan-interface\","
- + "\"relationship-value\" : \"key4\""
- + "},{"
- + "\"relationship-key\" : \"l-interface.interface-name\","
- + "\"relationship-value\" : \"key3\""
- + "},{"
- + "\"relationship-key\" : \"lag-interface.interface-name\","
- + "\"relationship-value\" : \"key2\""
- + "},{"
- + "\"relationship-key\" : \"generic-vnf.vnf-id\","
- + "\"relationship-value\" : \"key1\""
- + "}]"
+ + "\"relationship-value\" : \"key5\"" + "},{" + "\"relationship-key\" : \"vlan.vlan-interface\","
+ + "\"relationship-value\" : \"key4\"" + "},{" + "\"relationship-key\" : \"l-interface.interface-name\","
+ + "\"relationship-value\" : \"key3\"" + "},{"
+ + "\"relationship-key\" : \"lag-interface.interface-name\"," + "\"relationship-value\" : \"key2\""
+ + "},{" + "\"relationship-key\" : \"generic-vnf.vnf-id\"," + "\"relationship-value\" : \"key1\"" + "}]"
+ "}";
scrambledRelationshipSpec(content);
}
@@ -295,26 +224,13 @@ public class RelationshipGremlinQueryTest extends AAISetup {
*/
@Test
public void orderedAmbiguousRelationship() throws JAXBException, UnsupportedEncodingException, AAIException {
- String content =
- "{"
- + "\"related-to\" : \"l3-interface-ipv4-address-list\","
- + "\"relationship-data\" : [{"
- + "\"relationship-key\" : \"generic-vnf.vnf-id\","
- + "\"relationship-value\" : \"key1\""
- + "},{"
- + "\"relationship-key\" : \"lag-interface.interface-name\","
- + "\"relationship-value\" : \"key2\""
- + "},{"
- + "\"relationship-key\" : \"l-interface.interface-name\","
- + "\"relationship-value\" : \"key3\""
- + "},{"
- + "\"relationship-key\" : \"vlan.vlan-interface\","
- + "\"relationship-value\" : \"key4\""
- + "},{"
- + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\","
- + "\"relationship-value\" : \"key5\""
- + "}]"
- + "}";
+ String content = "{" + "\"related-to\" : \"l3-interface-ipv4-address-list\"," + "\"relationship-data\" : [{"
+ + "\"relationship-key\" : \"generic-vnf.vnf-id\"," + "\"relationship-value\" : \"key1\"" + "},{"
+ + "\"relationship-key\" : \"lag-interface.interface-name\"," + "\"relationship-value\" : \"key2\""
+ + "},{" + "\"relationship-key\" : \"l-interface.interface-name\"," + "\"relationship-value\" : \"key3\""
+ + "},{" + "\"relationship-key\" : \"vlan.vlan-interface\"," + "\"relationship-value\" : \"key4\""
+ + "},{" + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\","
+ + "\"relationship-value\" : \"key5\"" + "}]" + "}";
scrambledRelationshipSpec(content);
}
@@ -326,8 +242,8 @@ public class RelationshipGremlinQueryTest extends AAISetup {
* @throws UnsupportedEncodingException the unsupported encoding exception
* @throws AAIException the AAI exception
*/
- public void scrambledRelationshipSpec(String content) throws JAXBException, UnsupportedEncodingException, AAIException {
-
+ public void scrambledRelationshipSpec(String content)
+ throws JAXBException, UnsupportedEncodingException, AAIException {
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
@@ -335,34 +251,26 @@ public class RelationshipGremlinQueryTest extends AAISetup {
unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
Object obj = context.newDynamicEntity("Relationship");
- DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
+ DynamicEntity entity = (DynamicEntity) unmarshaller
+ .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
- String expected =
- ".has('vnf-id', 'key1').has('aai-node-type', 'generic-vnf')"
+ String expected = ".has('vnf-id', 'key1').has('aai-node-type', 'generic-vnf')"
+ ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'lag-interface')"
+ ".has('interface-name', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'l-interface')"
+ ".has('interface-name', 'key3').out('tosca.relationships.LinksTo').has('aai-node-type', 'vlan')"
+ ".has('vlan-interface', 'key4').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'l3-interface-ipv4-address-list')"
+ ".has('l3-interface-ipv4-address', 'key5')";
- String expectedParent =
- ".has('vnf-id', 'key1').has('aai-node-type', 'generic-vnf')"
- + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'lag-interface')"
- + ".has('interface-name', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'l-interface')"
- + ".has('interface-name', 'key3').out('tosca.relationships.LinksTo').has('aai-node-type', 'vlan')"
- + ".has('vlan-interface', 'key4')";
- assertEquals(
- "gremlin query should be " + expected,
- expected,
- query.getQueryBuilder().getQuery());
- assertEquals(
- "parent gremlin query should be equal the query for vlan",
- expectedParent,
+ String expectedParent = ".has('vnf-id', 'key1').has('aai-node-type', 'generic-vnf')"
+ + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'lag-interface')"
+ + ".has('interface-name', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'l-interface')"
+ + ".has('interface-name', 'key3').out('tosca.relationships.LinksTo').has('aai-node-type', 'vlan')"
+ + ".has('vlan-interface', 'key4')";
+ assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
+ assertEquals("parent gremlin query should be equal the query for vlan", expectedParent,
query.getQueryBuilder().getParentQuery().getQuery());
- assertEquals(
- "result type should be l3-interface-ipv4-address-list",
- "l3-interface-ipv4-address-list",
+ assertEquals("result type should be l3-interface-ipv4-address-list", "l3-interface-ipv4-address-list",
query.getResultType());
}
@@ -376,21 +284,12 @@ public class RelationshipGremlinQueryTest extends AAISetup {
*/
@Test
public void shortCircuit() throws JAXBException, UnsupportedEncodingException, AAIException {
- String content =
- "{"
- + "\"related-to\" : \"cvlan-tag\","
+ String content = "{" + "\"related-to\" : \"cvlan-tag\","
+ "\"related-link\" : \"http://mock-system-name.com:8443/aai/v6/network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655\","
- + "\"relationship-data\" : [{"
- + "\"relationship-key\" : \"vce.vnf-id\","
- + "\"relationship-value\" : \"key1\""
- + "}, {"
- + "\"relationship-key\" : \"port-group.interface-id\","
- + "\"relationship-value\" : \"key2\""
- + "},{"
- + "\"relationship-key\" : \"cvlan-tag.cvlan-tag\","
- + "\"relationship-value\" : \"655\""
- + "}]"
- + "}";
+ + "\"relationship-data\" : [{" + "\"relationship-key\" : \"vce.vnf-id\","
+ + "\"relationship-value\" : \"key1\"" + "}, {" + "\"relationship-key\" : \"port-group.interface-id\","
+ + "\"relationship-value\" : \"key2\"" + "},{" + "\"relationship-key\" : \"cvlan-tag.cvlan-tag\","
+ + "\"relationship-value\" : \"655\"" + "}]" + "}";
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
@@ -398,39 +297,28 @@ public class RelationshipGremlinQueryTest extends AAISetup {
unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
Object obj = context.newDynamicEntity("Relationship");
- DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
+ DynamicEntity entity = (DynamicEntity) unmarshaller
+ .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
- String expected =
- ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
+ String expected = ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
+ ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
+ ".has('interface-id', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')"
+ ".has('cvlan-tag', 655)";
- String expectedParent =
- ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
- + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
- + ".has('interface-id', 'key2')";
- assertEquals(
- "gremlin query should be " + expected,
- expected,
- query.getQueryBuilder().getQuery());
- assertEquals(
- "parent gremlin query should be equal the query for port group",
- expectedParent,
+ String expectedParent = ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
+ + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
+ + ".has('interface-id', 'key2')";
+ assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
+ assertEquals("parent gremlin query should be equal the query for port group", expectedParent,
query.getQueryBuilder().getParentQuery().getQuery());
- assertEquals(
- "result type should be cvlan-tag",
- "cvlan-tag",
- query.getResultType());
+ assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());
}
@Test
public void shorterCircuit() throws JAXBException, UnsupportedEncodingException, AAIException {
- String content =
- "{"
- + "\"related-to\" : \"cvlan-tag\","
+ String content = "{" + "\"related-to\" : \"cvlan-tag\","
+ "\"related-link\" : \"file:///network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655\""
+ "}";
@@ -440,31 +328,22 @@ public class RelationshipGremlinQueryTest extends AAISetup {
unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
Object obj = context.newDynamicEntity("Relationship");
- DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
+ DynamicEntity entity = (DynamicEntity) unmarshaller
+ .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
- String expected =
- ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
+ String expected = ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
+ ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
+ ".has('interface-id', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')"
+ ".has('cvlan-tag', 655)";
- String expectedParent =
- ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
- + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
- + ".has('interface-id', 'key2')";
- assertEquals(
- "gremlin query should be " + expected,
- expected,
- query.getQueryBuilder().getQuery());
- assertEquals(
- "parent gremlin query should be equal the query for port group",
- expectedParent,
+ String expectedParent = ".has('vnf-id', 'key1').has('aai-node-type', 'vce')"
+ + ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'port-group')"
+ + ".has('interface-id', 'key2')";
+ assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
+ assertEquals("parent gremlin query should be equal the query for port group", expectedParent,
query.getQueryBuilder().getParentQuery().getQuery());
- assertEquals(
- "result type should be cvlan-tag",
- "cvlan-tag",
- query.getResultType());
+ assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());
}
@@ -477,21 +356,11 @@ public class RelationshipGremlinQueryTest extends AAISetup {
*/
@Test
public void doubleKey() throws JAXBException, UnsupportedEncodingException, AAIException {
- String content =
- "{"
- + "\"related-to\" : \"ctag-pool\","
- + "\"relationship-data\" : [{"
- + "\"relationship-key\" : \"complex.physical-location-id\","
- + "\"relationship-value\" : \"key1\""
- + " }, { "
- + "\"relationship-key\" : \"ctag-pool.target-pe\","
- + " \"relationship-value\" : \"key2\""
- + " },{"
- + "\"relationship-key\" : \"ctag-pool.availability-zone-name\","
- + "\"relationship-value\" : \"key3\""
- + "}]"
- + "}";
-
+ String content = "{" + "\"related-to\" : \"ctag-pool\"," + "\"relationship-data\" : [{"
+ + "\"relationship-key\" : \"complex.physical-location-id\"," + "\"relationship-value\" : \"key1\""
+ + " }, { " + "\"relationship-key\" : \"ctag-pool.target-pe\"," + " \"relationship-value\" : \"key2\""
+ + " },{" + "\"relationship-key\" : \"ctag-pool.availability-zone-name\","
+ + "\"relationship-value\" : \"key3\"" + "}]" + "}";
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
@@ -499,31 +368,21 @@ public class RelationshipGremlinQueryTest extends AAISetup {
unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
Object obj = context.newDynamicEntity("Relationship");
- DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
+ DynamicEntity entity = (DynamicEntity) unmarshaller
+ .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
- String expected =
- ".has('physical-location-id', 'key1').has('aai-node-type', 'complex')"
+ String expected = ".has('physical-location-id', 'key1').has('aai-node-type', 'complex')"
+ ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'ctag-pool')"
- + ".has('target-pe', 'key2')"
- + ".has('availability-zone-name', 'key3')";
- String expectedParent =
- ".has('physical-location-id', 'key1').has('aai-node-type', 'complex')";
-
- assertEquals(
- "gremlin query should be " + expected,
- expected,
- query.getQueryBuilder().getQuery());
- assertEquals(
- "parent gremlin query should be equal the query for port group",
- expectedParent,
+ + ".has('target-pe', 'key2')" + ".has('availability-zone-name', 'key3')";
+ String expectedParent = ".has('physical-location-id', 'key1').has('aai-node-type', 'complex')";
+
+ assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
+ assertEquals("parent gremlin query should be equal the query for port group", expectedParent,
query.getQueryBuilder().getParentQuery().getQuery());
- assertEquals(
- "result type should be ctag-pool",
- "ctag-pool",
- query.getResultType());
+ assertEquals("result type should be ctag-pool", "ctag-pool", query.getResultType());
}
@@ -536,15 +395,8 @@ public class RelationshipGremlinQueryTest extends AAISetup {
*/
@Test
public void abstractType() throws JAXBException, UnsupportedEncodingException, AAIException {
- String content =
- "{"
- + "\"related-to\" : \"vnf\","
- + "\"relationship-data\" : [{"
- + "\"relationship-key\" : \"vnf.vnf-id\","
- + "\"relationship-value\" : \"key1\""
- + " }]"
- + "}";
-
+ String content = "{" + "\"related-to\" : \"vnf\"," + "\"relationship-data\" : [{"
+ + "\"relationship-key\" : \"vnf.vnf-id\"," + "\"relationship-value\" : \"key1\"" + " }]" + "}";
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
@@ -552,31 +404,20 @@ public class RelationshipGremlinQueryTest extends AAISetup {
unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
Object obj = context.newDynamicEntity("Relationship");
- DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
+ DynamicEntity entity = (DynamicEntity) unmarshaller
+ .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
- String expected =
- ".has('vnf-id', 'key1')"
- + ".has('aai-node-type', P.within('vce','generic-vnf'))";
-
- String expectedParent =
- ".has('vnf-id', 'key1')"
- + ".has('aai-node-type', P.within('vce','generic-vnf'))";
-
- assertEquals(
- "gremlin query should be " + expected,
- expected,
- query.getQueryBuilder().getQuery());
- assertEquals(
- "parent gremlin query should be equal the query for port group",
- expectedParent,
+ String expected = ".has('vnf-id', 'key1')" + ".has('aai-node-type', P.within('vce','generic-vnf'))";
+
+ String expectedParent = ".has('vnf-id', 'key1')" + ".has('aai-node-type', P.within('vce','generic-vnf'))";
+
+ assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
+ assertEquals("parent gremlin query should be equal the query for port group", expectedParent,
query.getQueryBuilder().getParentQuery().getQuery());
- assertEquals(
- "result type should be vnf",
- "vnf",
- query.getResultType());
+ assertEquals("result type should be vnf", "vnf", query.getResultType());
}
@@ -589,26 +430,14 @@ public class RelationshipGremlinQueryTest extends AAISetup {
*/
@Test
public void invalidNodeName() throws JAXBException, UnsupportedEncodingException, AAIException {
- String content =
- "{"
- + "\"related-to\" : \"l3-interface-ipv4-address-list\","
- + "\"relationship-data\" : [{"
- + "\"relationship-key\" : \"generic-vnf.vnf-id\","
- + "\"relationship-value\" : \"key1\""
- + "},{"
- + "\"relationship-key\" : \"lag-interface.interface-name\","
- + "\"relationship-value\" : \"key2\""
- + "},{"
- + "\"relationship-key\" : \"l-infeaterface.interface-name\","
- + "\"relationship-value\" : \"key3\""
- + "},{"
- + "\"relationship-key\" : \"vlan.vlan-interface\","
- + "\"relationship-value\" : \"key4\""
- + "},{"
+ String content = "{" + "\"related-to\" : \"l3-interface-ipv4-address-list\"," + "\"relationship-data\" : [{"
+ + "\"relationship-key\" : \"generic-vnf.vnf-id\"," + "\"relationship-value\" : \"key1\"" + "},{"
+ + "\"relationship-key\" : \"lag-interface.interface-name\"," + "\"relationship-value\" : \"key2\""
+ + "},{" + "\"relationship-key\" : \"l-infeaterface.interface-name\","
+ + "\"relationship-value\" : \"key3\"" + "},{" + "\"relationship-key\" : \"vlan.vlan-interface\","
+ + "\"relationship-value\" : \"key4\"" + "},{"
+ "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\","
- + "\"relationship-value\" : \"key5\""
- + "}]"
- + "}";
+ + "\"relationship-value\" : \"key5\"" + "}]" + "}";
thrown.expect(AAIException.class);
thrown.expectMessage(containsString("invalid object name"));
@@ -618,7 +447,8 @@ public class RelationshipGremlinQueryTest extends AAISetup {
unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
Object obj = context.newDynamicEntity("Relationship");
- DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
+ DynamicEntity entity = (DynamicEntity) unmarshaller
+ .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
@@ -634,26 +464,13 @@ public class RelationshipGremlinQueryTest extends AAISetup {
*/
@Test
public void invalidPropertyName() throws JAXBException, UnsupportedEncodingException, AAIException {
- String content =
- "{"
- + "\"related-to\" : \"l3-interface-ipv4-address-list\","
- + "\"relationship-data\" : [{"
- + "\"relationship-key\" : \"generic-vnf.vnf-id\","
- + "\"relationship-value\" : \"key1\""
- + "},{"
- + "\"relationship-key\" : \"lag-interface.intfdaferface-name\","
- + "\"relationship-value\" : \"key2\""
- + "},{"
- + "\"relationship-key\" : \"l-interface.interface-name\","
- + "\"relationship-value\" : \"key3\""
- + "},{"
- + "\"relationship-key\" : \"vlan.vlan-interface\","
- + "\"relationship-value\" : \"key4\""
- + "},{"
- + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\","
- + "\"relationship-value\" : \"key5\""
- + "}]"
- + "}";
+ String content = "{" + "\"related-to\" : \"l3-interface-ipv4-address-list\"," + "\"relationship-data\" : [{"
+ + "\"relationship-key\" : \"generic-vnf.vnf-id\"," + "\"relationship-value\" : \"key1\"" + "},{"
+ + "\"relationship-key\" : \"lag-interface.intfdaferface-name\"," + "\"relationship-value\" : \"key2\""
+ + "},{" + "\"relationship-key\" : \"l-interface.interface-name\"," + "\"relationship-value\" : \"key3\""
+ + "},{" + "\"relationship-key\" : \"vlan.vlan-interface\"," + "\"relationship-value\" : \"key4\""
+ + "},{" + "\"relationship-key\" : \"l3-interface-ipv4-address-list.l3-interface-ipv4-address\","
+ + "\"relationship-value\" : \"key5\"" + "}]" + "}";
thrown.expect(AAIException.class);
thrown.expectMessage(containsString("invalid property name"));
@@ -663,7 +480,8 @@ public class RelationshipGremlinQueryTest extends AAISetup {
unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
Object obj = context.newDynamicEntity("Relationship");
- DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
+ DynamicEntity entity = (DynamicEntity) unmarshaller
+ .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
diff --git a/aai-core/src/test/java/org/onap/aai/parsers/query/RelationshipQueryTest.java b/aai-core/src/test/java/org/onap/aai/parsers/query/RelationshipQueryTest.java
index 71089c6b..b0f6b240 100644
--- a/aai-core/src/test/java/org/onap/aai/parsers/query/RelationshipQueryTest.java
+++ b/aai-core/src/test/java/org/onap/aai/parsers/query/RelationshipQueryTest.java
@@ -17,8 +17,18 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.parsers.query;
+import static org.junit.Assert.assertEquals;
+
+import java.io.StringReader;
+import java.io.UnsupportedEncodingException;
+
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.transform.stream.StreamSource;
+
import org.eclipse.persistence.dynamic.DynamicEntity;
import org.eclipse.persistence.jaxb.UnmarshallerProperties;
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
@@ -28,35 +38,25 @@ import org.junit.Test;
import org.onap.aai.AAISetup;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.*;
-import org.onap.aai.setup.SchemaVersion;
-import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.JanusGraphDBEngine;
+import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
-
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.transform.stream.StreamSource;
-import java.io.StringReader;
-import java.io.UnsupportedEncodingException;
-
-import static org.junit.Assert.assertEquals;
+import org.onap.aai.setup.SchemaVersion;
@Ignore
public class RelationshipQueryTest extends AAISetup {
-
private TransactionalGraphEngine dbEngine;
private SchemaVersion version;
private DynamicJAXBContext context = nodeIngestor.getContextForVersion(version);
@Before
- public void setup(){
+ public void setup() {
version = new SchemaVersion("v10");
- dbEngine =
- new JanusGraphDBEngine(QueryStyle.GREMLIN_TRAVERSAL,
- loaderFactory.createLoaderForVersion(ModelType.MOXY, version),
- false);
+ dbEngine = new JanusGraphDBEngine(QueryStyle.GREMLIN_TRAVERSAL,
+ loaderFactory.createLoaderForVersion(ModelType.MOXY, version), false);
}
+
/**
* Parent query.
*
@@ -67,14 +67,8 @@ public class RelationshipQueryTest extends AAISetup {
@Test
public void parentQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
- String content =
- "{"
- + "\"related-to\" : \"pserver\","
- + "\"relationship-data\" : [{"
- + "\"relationship-key\" : \"pserver.hostname\","
- + "\"relationship-value\" : \"key1\""
- + "}]"
- + "}";
+ String content = "{" + "\"related-to\" : \"pserver\"," + "\"relationship-data\" : [{"
+ + "\"relationship-key\" : \"pserver.hostname\"," + "\"relationship-value\" : \"key1\"" + "}]" + "}";
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
@@ -82,25 +76,17 @@ public class RelationshipQueryTest extends AAISetup {
unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
Object obj = context.newDynamicEntity("Relationship");
- DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
+ DynamicEntity entity = (DynamicEntity) unmarshaller
+ .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
- String expected =
- ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
- assertEquals(
- "gremlin query should be " + expected,
- expected,
- query.getQueryBuilder().getQuery());
- assertEquals(
- "parent gremlin query should be equal to normal query",
- expected,
+ String expected = ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
+ assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
+ assertEquals("parent gremlin query should be equal to normal query", expected,
query.getQueryBuilder().getParentQuery().getQuery());
- assertEquals(
- "result type should be pserver",
- "pserver",
- query.getResultType());
+ assertEquals("result type should be pserver", "pserver", query.getResultType());
}
@@ -114,17 +100,10 @@ public class RelationshipQueryTest extends AAISetup {
@Ignore
@Test
public void childQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
- String content =
- "{"
- + "\"related-to\" : \"lag-interface\","
- + "\"relationship-data\" : [{"
- + "\"relationship-key\" : \"pserver.hostname\","
- + "\"relationship-value\" : \"key1\""
- + "}, {"
- + "\"relationship-key\" : \"lag-interface.interface-name\","
- + "\"relationship-value\" : \"key2\""
- + "}]"
- + "}";
+ String content = "{" + "\"related-to\" : \"lag-interface\"," + "\"relationship-data\" : [{"
+ + "\"relationship-key\" : \"pserver.hostname\"," + "\"relationship-value\" : \"key1\"" + "}, {"
+ + "\"relationship-key\" : \"lag-interface.interface-name\"," + "\"relationship-value\" : \"key2\""
+ + "}]" + "}";
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
@@ -132,27 +111,19 @@ public class RelationshipQueryTest extends AAISetup {
unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
Object obj = context.newDynamicEntity("Relationship");
- DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
+ DynamicEntity entity = (DynamicEntity) unmarshaller
+ .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
String expected =
".has('hostname', 'key1').has('aai-node-type', 'pserver').out('hasLAGInterface').has('aai-node-type', 'lag-interface')"
- + ".has('interface-name', 'key2')";
- String parentExpected =
- ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
- assertEquals(
- "gremlin query should be for node",
- expected,
- query.getQueryBuilder().getQuery());
- assertEquals(
- "parent gremlin query should be for parent",
- parentExpected,
+ + ".has('interface-name', 'key2')";
+ String parentExpected = ".has('hostname', 'key1').has('aai-node-type', 'pserver')";
+ assertEquals("gremlin query should be for node", expected, query.getQueryBuilder().getQuery());
+ assertEquals("parent gremlin query should be for parent", parentExpected,
query.getQueryBuilder().getParentQuery().getQuery());
- assertEquals(
- "result type should be lag-interface",
- "lag-interface",
- query.getResultType());
+ assertEquals("result type should be lag-interface", "lag-interface", query.getResultType());
}
/**
@@ -165,20 +136,10 @@ public class RelationshipQueryTest extends AAISetup {
@Ignore
@Test
public void namingExceptions() throws JAXBException, UnsupportedEncodingException, AAIException {
- String content =
- "{"
- + "\"related-to\" : \"cvlan-tag\","
- + "\"relationship-data\" : [{"
- + "\"relationship-key\" : \"vce.vnf-id\","
- + "\"relationship-value\" : \"key1\""
- + "}, {"
- + "\"relationship-key\" : \"port-group.interface-id\","
- + "\"relationship-value\" : \"key2\""
- + "},{"
- + "\"relationship-key\" : \"cvlan-tag.cvlan-tag\","
- + "\"relationship-value\" : \"655\""
- + "}]"
- + "}";
+ String content = "{" + "\"related-to\" : \"cvlan-tag\"," + "\"relationship-data\" : [{"
+ + "\"relationship-key\" : \"vce.vnf-id\"," + "\"relationship-value\" : \"key1\"" + "}, {"
+ + "\"relationship-key\" : \"port-group.interface-id\"," + "\"relationship-value\" : \"key2\"" + "},{"
+ + "\"relationship-key\" : \"cvlan-tag.cvlan-tag\"," + "\"relationship-value\" : \"655\"" + "}]" + "}";
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
@@ -186,30 +147,23 @@ public class RelationshipQueryTest extends AAISetup {
unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
Object obj = context.newDynamicEntity("Relationship");
- DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
+ DynamicEntity entity = (DynamicEntity) unmarshaller
+ .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
String expected =
".has('vnf-id', 'key1').has('aai-node-type', 'vce').in('org.onap.relationships.inventory.BelongsTo')"
- + ".has('aai-node-type', 'port-group').has('interface-id', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')"
- + ".has('cvlan-tag', 655)";
+ + ".has('aai-node-type', 'port-group').has('interface-id', 'key2').in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'cvlan-tag')"
+ + ".has('cvlan-tag', 655)";
String expectedParent =
- ".has('vnf-id', 'key1').has('aai-node-type', 'vce').in('org.onap.relationships.inventory.BelongsTo')"
+ ".has('vnf-id', 'key1').has('aai-node-type', 'vce').in('org.onap.relationships.inventory.BelongsTo')"
+ ".has('aai-node-type', 'port-group').has('interface-id', 'key2')";
- assertEquals(
- "gremlin query should be " + expected,
- expected,
- query.getQueryBuilder().getQuery());
- assertEquals(
- "parent gremlin query should be equal the query for port group",
- expectedParent,
+ assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
+ assertEquals("parent gremlin query should be equal the query for port group", expectedParent,
query.getQueryBuilder().getParentQuery().getQuery());
- assertEquals(
- "result type should be cvlan-tag",
- "cvlan-tag",
- query.getResultType());
+ assertEquals("result type should be cvlan-tag", "cvlan-tag", query.getResultType());
}
@@ -223,21 +177,11 @@ public class RelationshipQueryTest extends AAISetup {
@Ignore
@Test
public void doubleKey() throws JAXBException, UnsupportedEncodingException, AAIException {
- String content =
- "{"
- + "\"related-to\" : \"ctag-pool\","
- + "\"relationship-data\" : [{"
- + "\"relationship-key\" : \"complex.physical-location-id\","
- + "\"relationship-value\" : \"key1\""
- + " }, { "
- + "\"relationship-key\" : \"ctag-pool.target-pe\","
- + " \"relationship-value\" : \"key2\""
- + " },{"
- + "\"relationship-key\" : \"ctag-pool.availability-zone-name\","
- + "\"relationship-value\" : \"key3\""
- + "}]"
- + "}";
-
+ String content = "{" + "\"related-to\" : \"ctag-pool\"," + "\"relationship-data\" : [{"
+ + "\"relationship-key\" : \"complex.physical-location-id\"," + "\"relationship-value\" : \"key1\""
+ + " }, { " + "\"relationship-key\" : \"ctag-pool.target-pe\"," + " \"relationship-value\" : \"key2\""
+ + " },{" + "\"relationship-key\" : \"ctag-pool.availability-zone-name\","
+ + "\"relationship-value\" : \"key3\"" + "}]" + "}";
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
@@ -245,31 +189,21 @@ public class RelationshipQueryTest extends AAISetup {
unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
Object obj = context.newDynamicEntity("Relationship");
- DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
+ DynamicEntity entity = (DynamicEntity) unmarshaller
+ .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
- String expected =
- ".has('physical-location-id', 'key1').has('aai-node-type', 'complex')"
+ String expected = ".has('physical-location-id', 'key1').has('aai-node-type', 'complex')"
+ ".in('org.onap.relationships.inventory.BelongsTo').has('aai-node-type', 'ctag-pool')"
- + ".has('target-pe', 'key2')"
- + ".has('availability-zone-name', 'key3')";
- String expectedParent =
- ".has('physical-location-id', 'key1').has('aai-node-type', 'complex')";
-
- assertEquals(
- "gremlin query should be " + expected,
- expected,
- query.getQueryBuilder().getQuery());
- assertEquals(
- "parent gremlin query should be equal the query for port group",
- expectedParent,
+ + ".has('target-pe', 'key2')" + ".has('availability-zone-name', 'key3')";
+ String expectedParent = ".has('physical-location-id', 'key1').has('aai-node-type', 'complex')";
+
+ assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
+ assertEquals("parent gremlin query should be equal the query for port group", expectedParent,
query.getQueryBuilder().getParentQuery().getQuery());
- assertEquals(
- "result type should be ctag-pool",
- "ctag-pool",
- query.getResultType());
+ assertEquals("result type should be ctag-pool", "ctag-pool", query.getResultType());
}
diff --git a/aai-core/src/test/java/org/onap/aai/parsers/query/UniqueRelationshipQueryTest.java b/aai-core/src/test/java/org/onap/aai/parsers/query/UniqueRelationshipQueryTest.java
index 319f0b88..68fc4376 100644
--- a/aai-core/src/test/java/org/onap/aai/parsers/query/UniqueRelationshipQueryTest.java
+++ b/aai-core/src/test/java/org/onap/aai/parsers/query/UniqueRelationshipQueryTest.java
@@ -17,8 +17,18 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.parsers.query;
+import static org.junit.Assert.assertEquals;
+
+import java.io.StringReader;
+import java.io.UnsupportedEncodingException;
+
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.transform.stream.StreamSource;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
import org.apache.tinkerpop.gremlin.structure.Vertex;
@@ -32,28 +42,20 @@ import org.onap.aai.AAISetup;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.*;
import org.onap.aai.nodes.NodeIngestor;
-import org.onap.aai.setup.SchemaVersion;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.JanusGraphDBEngine;
+import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
-
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.transform.stream.StreamSource;
-import java.io.StringReader;
-import java.io.UnsupportedEncodingException;
-
-import static org.junit.Assert.assertEquals;
+import org.onap.aai.setup.SchemaVersion;
+import org.springframework.beans.factory.annotation.Autowired;
@Ignore
public class UniqueRelationshipQueryTest extends AAISetup {
@Autowired
- private NodeIngestor ingestor ;
+ private NodeIngestor ingestor;
private TransactionalGraphEngine dbEngine;
- private SchemaVersion version ;
+ private SchemaVersion version;
private DynamicJAXBContext context = ingestor.getContextForVersion(version);
private Unmarshaller unmarshaller = null;
@@ -66,8 +68,7 @@ public class UniqueRelationshipQueryTest extends AAISetup {
public void setup() throws JAXBException {
version = new SchemaVersion("v10");
dbEngine = new JanusGraphDBEngine(QueryStyle.GREMLIN_UNIQUE,
- loaderFactory.createLoaderForVersion(ModelType.MOXY, version),
- false);
+ loaderFactory.createLoaderForVersion(ModelType.MOXY, version), false);
unmarshaller = context.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
@@ -84,24 +85,18 @@ public class UniqueRelationshipQueryTest extends AAISetup {
@Test
public void parentQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
- String content =
- "{"
- + "\"related-to\" : \"pserver\","
- + "\"relationship-data\" : [{"
- + "\"relationship-key\" : \"pserver.hostname\","
- + "\"relationship-value\" : \"key1\""
- + "}]"
- + "}";
+ String content = "{" + "\"related-to\" : \"pserver\"," + "\"relationship-data\" : [{"
+ + "\"relationship-key\" : \"pserver.hostname\"," + "\"relationship-value\" : \"key1\"" + "}]" + "}";
Object obj = context.newDynamicEntity("Relationship");
- DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
+ DynamicEntity entity = (DynamicEntity) unmarshaller
+ .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
String key = "pserver/key1";
- GraphTraversal<Vertex, Vertex> expected =
- __.<Vertex>start().has("aai-unique-key", key);
+ GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key);
String resultType = "pserver";
String containerType = "";
@@ -118,30 +113,22 @@ public class UniqueRelationshipQueryTest extends AAISetup {
*/
@Test
public void childQuery() throws JAXBException, UnsupportedEncodingException, AAIException {
- String content =
- "{"
- + "\"related-to\" : \"lag-interface\","
- + "\"relationship-data\" : [{"
- + "\"relationship-key\" : \"pserver.hostname\","
- + "\"relationship-value\" : \"key1\""
- + "}, {"
- + "\"relationship-key\" : \"lag-interface.interface-name\","
- + "\"relationship-value\" : \"key2\""
- + "}]"
- + "}";
+ String content = "{" + "\"related-to\" : \"lag-interface\"," + "\"relationship-data\" : [{"
+ + "\"relationship-key\" : \"pserver.hostname\"," + "\"relationship-value\" : \"key1\"" + "}, {"
+ + "\"relationship-key\" : \"lag-interface.interface-name\"," + "\"relationship-value\" : \"key2\""
+ + "}]" + "}";
Object obj = context.newDynamicEntity("Relationship");
- DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
+ DynamicEntity entity = (DynamicEntity) unmarshaller
+ .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
String key = "pserver/key1/lag-interface/key2";
- GraphTraversal<Vertex, Vertex> expected =
- __.<Vertex>start().has("aai-unique-key", key);
- GraphTraversal<Vertex, Vertex> parentExpected =
- __.<Vertex>start().has("aai-unique-key", "pserver/key1");
+ GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key);
+ GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key", "pserver/key1");
String resultType = "lag-interface";
String containerType = "";
@@ -157,30 +144,20 @@ public class UniqueRelationshipQueryTest extends AAISetup {
*/
@Test
public void namingExceptions() throws JAXBException, UnsupportedEncodingException, AAIException {
- String content =
- "{"
- + "\"related-to\" : \"cvlan-tag\","
- + "\"relationship-data\" : [{"
- + "\"relationship-key\" : \"vce.vnf-id\","
- + "\"relationship-value\" : \"key1\""
- + "}, {"
- + "\"relationship-key\" : \"port-group.interface-id\","
- + "\"relationship-value\" : \"key2\""
- + "},{"
- + "\"relationship-key\" : \"cvlan-tag.cvlan-tag\","
- + "\"relationship-value\" : \"655\""
- + "}]"
- + "}";
+ String content = "{" + "\"related-to\" : \"cvlan-tag\"," + "\"relationship-data\" : [{"
+ + "\"relationship-key\" : \"vce.vnf-id\"," + "\"relationship-value\" : \"key1\"" + "}, {"
+ + "\"relationship-key\" : \"port-group.interface-id\"," + "\"relationship-value\" : \"key2\"" + "},{"
+ + "\"relationship-key\" : \"cvlan-tag.cvlan-tag\"," + "\"relationship-value\" : \"655\"" + "}]" + "}";
Object obj = context.newDynamicEntity("Relationship");
- DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
+ DynamicEntity entity = (DynamicEntity) unmarshaller
+ .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
String key = "vce/key1/port-group/key2/cvlan-tag/655";
- GraphTraversal<Vertex, Vertex> expected =
- __.<Vertex>start().has("aai-unique-key", key);
+ GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key);
GraphTraversal<Vertex, Vertex> parentExpected =
__.<Vertex>start().has("aai-unique-key", "vce/key1/port-group/key2");
String resultType = "cvlan-tag";
@@ -199,28 +176,21 @@ public class UniqueRelationshipQueryTest extends AAISetup {
*/
@Test
public void doubleKey() throws JAXBException, UnsupportedEncodingException, AAIException {
- String content =
- "{"
- + "\"related-to\" : \"service-capability\","
- + "\"relationship-data\" : [{"
- + "\"relationship-key\" : \"service-capability.service-type\","
- + "\"relationship-value\" : \"key1\""
- + " }, { "
- + "\"relationship-key\" : \"service-capability.vnf-type\","
- + " \"relationship-value\" : \"key2\""
- + " }]"
- + "}";
+ String content = "{" + "\"related-to\" : \"service-capability\"," + "\"relationship-data\" : [{"
+ + "\"relationship-key\" : \"service-capability.service-type\"," + "\"relationship-value\" : \"key1\""
+ + " }, { " + "\"relationship-key\" : \"service-capability.vnf-type\","
+ + " \"relationship-value\" : \"key2\"" + " }]" + "}";
Object obj = context.newDynamicEntity("Relationship");
- DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
+ DynamicEntity entity = (DynamicEntity) unmarshaller
+ .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
String key = "service-capability/key1/key2";
- GraphTraversal<Vertex, Vertex> expected =
- __.<Vertex>start().has("aai-unique-key", key);
+ GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key);
GraphTraversal<Vertex, Vertex> parentExpected =
__.<Vertex>start().has("aai-unique-key", "service-capability/key1/key2");
String resultType = "service-capability";
@@ -239,31 +209,24 @@ public class UniqueRelationshipQueryTest extends AAISetup {
*/
@Test
public void shortCircuit() throws JAXBException, UnsupportedEncodingException, AAIException {
- String content =
- "{"
- + "\"related-to\" : \"cvlan-tag\","
+ String content = "{" + "\"related-to\" : \"cvlan-tag\","
+ "\"related-link\" : \"http://mock-system-name.com:8443/aai/v6/network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655\","
- + "\"relationship-data\" : [{"
- + "\"relationship-key\" : \"vce.hostname\","
- + "\"relationship-value\" : \"key1\""
- + "}, {"
- + "\"relationship-key\" : \"port-group.interface-name\","
- + "\"relationship-value\" : \"key2\""
- + "},{"
- + "\"relationship-key\" : \"cvlan-tag.-name\","
- + "\"relationship-value\" : \"655\""
- + "}]"
- + "}";
+ + "\"relationship-data\" : [{" + "\"relationship-key\" : \"vce.hostname\","
+ + "\"relationship-value\" : \"key1\"" + "}, {" + "\"relationship-key\" : \"port-group.interface-name\","
+ + "\"relationship-value\" : \"key2\"" + "},{" + "\"relationship-key\" : \"cvlan-tag.-name\","
+ + "\"relationship-value\" : \"655\"" + "}]" + "}";
Object obj = context.newDynamicEntity("Relationship");
- DynamicEntity entity = (DynamicEntity)unmarshaller.unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
+ DynamicEntity entity = (DynamicEntity) unmarshaller
+ .unmarshal(new StreamSource(new StringReader(content)), obj.getClass()).getValue();
Introspector wrappedObj = IntrospectorFactory.newInstance(ModelType.MOXY, entity);
QueryParser query = dbEngine.getQueryBuilder().createQueryFromRelationship(wrappedObj);
String key = "vce/key1/port-group/key2/cvlan-tag/655";
GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key);
- GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key", "vce/key1/port-group/key2");
+ GraphTraversal<Vertex, Vertex> parentExpected =
+ __.<Vertex>start().has("aai-unique-key", "vce/key1/port-group/key2");
String resultType = "cvlan-tag";
String containerType = "";
@@ -280,22 +243,12 @@ public class UniqueRelationshipQueryTest extends AAISetup {
* @param resultType the result type
* @param containerType the container type
*/
- public void testSet(QueryParser query, GraphTraversal<Vertex, Vertex> expected, GraphTraversal<Vertex, Vertex> parentExpected, String resultType, String containerType) {
- assertEquals(
- "gremlin query should be " + expected,
- expected,
- query.getQueryBuilder().getQuery());
- assertEquals(
- "parent gremlin query should be " + parentExpected,
- parentExpected,
+ public void testSet(QueryParser query, GraphTraversal<Vertex, Vertex> expected,
+ GraphTraversal<Vertex, Vertex> parentExpected, String resultType, String containerType) {
+ assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
+ assertEquals("parent gremlin query should be " + parentExpected, parentExpected,
query.getParentQueryBuilder().getParentQuery());
- assertEquals(
- "result type should be " + resultType,
- resultType,
- query.getResultType());
- assertEquals(
- "container type should be " + containerType,
- containerType,
- query.getContainerType());
+ assertEquals("result type should be " + resultType, resultType, query.getResultType());
+ assertEquals("container type should be " + containerType, containerType, query.getContainerType());
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/parsers/query/UniqueURIQueryTest.java b/aai-core/src/test/java/org/onap/aai/parsers/query/UniqueURIQueryTest.java
index 631574b4..1782c817 100644
--- a/aai-core/src/test/java/org/onap/aai/parsers/query/UniqueURIQueryTest.java
+++ b/aai-core/src/test/java/org/onap/aai/parsers/query/UniqueURIQueryTest.java
@@ -17,8 +17,16 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.parsers.query;
+import static org.junit.Assert.assertEquals;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+
+import javax.ws.rs.core.UriBuilder;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
import org.apache.tinkerpop.gremlin.structure.Vertex;
@@ -27,23 +35,15 @@ import org.junit.Ignore;
import org.junit.Test;
import org.onap.aai.AAISetup;
import org.onap.aai.exceptions.AAIException;
-
import org.onap.aai.introspection.ModelType;
-import org.onap.aai.setup.SchemaVersion;
-import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.JanusGraphDBEngine;
+import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
-
-import javax.ws.rs.core.UriBuilder;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-
-import static org.junit.Assert.assertEquals;
+import org.onap.aai.setup.SchemaVersion;
@Ignore
public class UniqueURIQueryTest extends AAISetup {
-
private TransactionalGraphEngine dbEngine;
private SchemaVersion version;
private DynamicJAXBContext context = nodeIngestor.getContextForVersion(version);
@@ -58,8 +58,7 @@ public class UniqueURIQueryTest extends AAISetup {
public void parentQuery() throws UnsupportedEncodingException, AAIException {
version = new SchemaVersion("v10");
dbEngine = new JanusGraphDBEngine(QueryStyle.GREMLIN_UNIQUE,
- loaderFactory.createLoaderForVersion(ModelType.MOXY, version),
- false);
+ loaderFactory.createLoaderForVersion(ModelType.MOXY, version), false);
URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1").build();
String key = "complex/key1";
QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
@@ -99,12 +98,13 @@ public class UniqueURIQueryTest extends AAISetup {
*/
@Test
public void childQuery() throws UnsupportedEncodingException, AAIException {
- URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3").build();
+ URI uri = UriBuilder.fromPath("cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3")
+ .build();
QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
String parentKey = "complex/key1";
String key = parentKey + "/ctag-pool/key2/key3";
GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", key);
- GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key", parentKey);
+ GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key", parentKey);
String parentResultType = "complex";
String resultType = "ctag-pool";
String containerType = "";
@@ -121,7 +121,8 @@ public class UniqueURIQueryTest extends AAISetup {
*/
@Test
public void namingExceptions() throws UnsupportedEncodingException, AAIException {
- URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build();
+ URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655")
+ .build();
QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
String parentKey = "vce/key1/port-group/key2";
String key = parentKey + "/cvlan-tag/655";
@@ -148,8 +149,9 @@ public class UniqueURIQueryTest extends AAISetup {
String parentKey = "vce/key1/port-group/key2";
URI uri = UriBuilder.fromPath(parentURI + "/cvlan-tags").build();
QueryParser query = dbEngine.getQueryBuilder().createQueryFromURI(uri);
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", parentKey).in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "cvlan-tag");
- GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key",parentKey);
+ GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("aai-unique-key", parentKey)
+ .in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "cvlan-tag");
+ GraphTraversal<Vertex, Vertex> parentExpected = __.<Vertex>start().has("aai-unique-key", parentKey);
String parentResultType = "port-group";
String resultType = "cvlan-tag";
String containerType = "cvlan-tags";
@@ -168,26 +170,14 @@ public class UniqueURIQueryTest extends AAISetup {
* @param resultType the result type
* @param containerType the container type
*/
- public void testSet(QueryParser query, GraphTraversal<Vertex, Vertex> expected, GraphTraversal<Vertex, Vertex> parentExpected, String parentResultType, String resultType, String containerType) {
- assertEquals(
- "gremlin query should be " + expected,
- expected,
- query.getQueryBuilder().getQuery());
- assertEquals(
- "parent gremlin query should be " + parentExpected,
- parentExpected,
+ public void testSet(QueryParser query, GraphTraversal<Vertex, Vertex> expected,
+ GraphTraversal<Vertex, Vertex> parentExpected, String parentResultType, String resultType,
+ String containerType) {
+ assertEquals("gremlin query should be " + expected, expected, query.getQueryBuilder().getQuery());
+ assertEquals("parent gremlin query should be " + parentExpected, parentExpected,
query.getQueryBuilder().getParentQuery().getQuery());
- assertEquals(
- "parent result type should be " + parentResultType,
- parentResultType,
- query.getParentResultType());
- assertEquals(
- "result type should be " + resultType,
- resultType,
- query.getResultType());
- assertEquals(
- "container type should be " + containerType,
- containerType,
- query.getContainerType());
+ assertEquals("parent result type should be " + parentResultType, parentResultType, query.getParentResultType());
+ assertEquals("result type should be " + resultType, resultType, query.getResultType());
+ assertEquals("container type should be " + containerType, containerType, query.getContainerType());
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/parsers/relationship/RelationshipToURITest.java b/aai-core/src/test/java/org/onap/aai/parsers/relationship/RelationshipToURITest.java
index 42f1fd44..ea872d4e 100644
--- a/aai-core/src/test/java/org/onap/aai/parsers/relationship/RelationshipToURITest.java
+++ b/aai-core/src/test/java/org/onap/aai/parsers/relationship/RelationshipToURITest.java
@@ -17,8 +17,18 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.parsers.relationship;
+import static org.hamcrest.Matchers.hasProperty;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertEquals;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
import org.apache.commons.io.IOUtils;
import org.junit.Ignore;
import org.junit.Rule;
@@ -32,38 +42,28 @@ import org.onap.aai.parsers.exceptions.AmbiguousMapAAIException;
import org.onap.aai.setup.SchemaVersion;
import org.springframework.test.annotation.DirtiesContext;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import static org.hamcrest.Matchers.hasProperty;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertEquals;
-
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class RelationshipToURITest extends AAISetup {
private final ModelType modelType = ModelType.MOXY;
private final SchemaVersion version10 = new SchemaVersion("v10");
-
-
+
@Rule
public ExpectedException thrown = ExpectedException.none();
-
+
@Test
public void onlyLink() throws AAIException, URISyntaxException, IOException {
Loader loader = loaderFactory.createLoaderForVersion(modelType, version10);
Introspector obj = loader.unmarshal("relationship", this.getJsonString("only-related-link.json"));
URI expected = new URI("/aai/v10/network/generic-vnfs/generic-vnf/key1");
-
+
RelationshipToURI parse = new RelationshipToURI(loader, obj);
-
+
URI uri = parse.getUri();
-
+
assertEquals("related-link is equal", expected.getPath(), uri.getPath());
}
-
+
@Test
public void onlyData() throws AAIException, URISyntaxException, IOException {
Loader loader = loaderFactory.createLoaderForVersion(modelType, version10);
@@ -71,71 +71,68 @@ public class RelationshipToURITest extends AAISetup {
URI expected = new URI("/network/generic-vnfs/generic-vnf/key1");
RelationshipToURI parse = new RelationshipToURI(loader, obj);
-
+
URI uri = parse.getUri();
-
+
assertEquals("related-link is equal", expected, uri);
}
-
+
@Test
public void failV10() throws AAIException, URISyntaxException, IOException {
Loader loader = loaderFactory.createLoaderForVersion(modelType, version10);
Introspector obj = loader.unmarshal("relationship", this.getJsonString("both-failv10-successv9.json"));
URI expected = new URI("/aai/v10/network/generic-vnfs/generic-vnf/key1");
-
+
thrown.expect(AAIIdentityMapParseException.class);
thrown.expect(hasProperty("code", is("AAI_3000")));
RelationshipToURI parse = new RelationshipToURI(loader, obj);
URI uri = parse.getUri();
-
+
}
-
+
@Test
public void failNothingToParse() throws AAIException, URISyntaxException, IOException {
Loader loader = loaderFactory.createLoaderForVersion(modelType, version10);
Introspector obj = loader.unmarshal("relationship", this.getJsonString("nothing-to-parse.json"));
URI expected = new URI("/aai/v10/network/generic-vnfs/generic-vnf/key1");
-
+
thrown.expect(AAIIdentityMapParseException.class);
thrown.expect(hasProperty("code", is("AAI_3000")));
RelationshipToURI parse = new RelationshipToURI(loader, obj);
-
+
URI uri = parse.getUri();
-
+
}
-
+
@Test
public void successV10() throws AAIException, URISyntaxException, IOException {
Loader loader = loaderFactory.createLoaderForVersion(modelType, version10);
Introspector obj = loader.unmarshal("relationship", this.getJsonString("both-successv10-failv9.json"));
URI expected = new URI("/aai/v10/network/generic-vnfs/generic-vnf/key1");
-
+
RelationshipToURI parse = new RelationshipToURI(loader, obj);
-
URI uri = parse.getUri();
-
+
assertEquals("related-link is equal", expected, uri);
-
}
-
+
@Test
public void ambiguousRelationship() throws AAIException, URISyntaxException, IOException {
Loader loader = loaderFactory.createLoaderForVersion(modelType, version10);
Introspector obj = loader.unmarshal("relationship", this.getJsonString("ambiguous-relationship.json"));
URI expected = new URI("/aai/v10/network/generic-vnfs/generic-vnf/key1");
-
+
thrown.expect(AmbiguousMapAAIException.class);
thrown.expect(hasProperty("code", is("AAI_6146")));
-
+
RelationshipToURI parse = new RelationshipToURI(loader, obj);
-
+
URI uri = parse.getUri();
-
+
assertEquals("related-link is equal", expected, uri);
-
}
@Ignore
@@ -144,54 +141,53 @@ public class RelationshipToURITest extends AAISetup {
Loader loader = loaderFactory.createLoaderForVersion(modelType, version10);
Introspector obj = loader.unmarshal("relationship", this.getJsonString("too-many-items-relationship.json"));
URI expected = new URI("/network/generic-vnfs/generic-vnf/key1/l-interfaces/l-interface/key2");
-
+
RelationshipToURI parse = new RelationshipToURI(loader, obj);
URI uri = parse.getUri();
-
+
assertEquals("related-link is equal", expected.toString(), uri.toString());
-
+
}
-
+
@Test
public void twoTopLevelNodes() throws AAIException, URISyntaxException, IOException {
Loader loader = loaderFactory.createLoaderForVersion(modelType, version10);
Introspector obj = loader.unmarshal("relationship", this.getJsonString("two-top-level-relationship.json"));
URI expected = new URI("/network/generic-vnfs/generic-vnf/key1/l-interfaces/l-interface/key2");
-
+
thrown.expect(AmbiguousMapAAIException.class);
thrown.expect(hasProperty("code", is("AAI_6146")));
-
+
RelationshipToURI parse = new RelationshipToURI(loader, obj);
-
+
URI uri = parse.getUri();
-
+
assertEquals("related-link is equal", expected, uri);
-
+
}
-
+
@Test
public void topLevelWithTwoKeys() throws AAIException, URISyntaxException, IOException {
Loader loader = loaderFactory.createLoaderForVersion(modelType, version10);
Introspector obj = loader.unmarshal("relationship", this.getJsonString("top-level-two-keys-relationship.json"));
- URI expected = new URI("/cloud-infrastructure/cloud-regions/cloud-region/key1/key2/availability-zones/availability-zone/key3");
-
+ URI expected = new URI(
+ "/cloud-infrastructure/cloud-regions/cloud-region/key1/key2/availability-zones/availability-zone/key3");
+
RelationshipToURI parse = new RelationshipToURI(loader, obj);
-
+
URI uri = parse.getUri();
-
+
assertEquals("related-link is equal", expected.toString(), uri.toString());
-
+
}
-
-
+
private String getJsonString(String filename) throws IOException {
-
-
+
FileInputStream is = new FileInputStream("src/test/resources/bundleconfig-local/etc/relationship/" + filename);
- String s = IOUtils.toString(is, "UTF-8");
+ String s = IOUtils.toString(is, "UTF-8");
IOUtils.closeQuietly(is);
-
+
return s;
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIParserTest.java b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIParserTest.java
index aab124f3..111772d2 100644
--- a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIParserTest.java
+++ b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIParserTest.java
@@ -17,8 +17,19 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.parsers.uri;
+import static org.hamcrest.Matchers.hasProperty;
+import static org.hamcrest.Matchers.is;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+
+import javax.annotation.PostConstruct;
+import javax.ws.rs.core.UriBuilder;
+import javax.xml.bind.JAXBException;
+
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -28,22 +39,13 @@ import org.onap.aai.introspection.Loader;
import org.onap.aai.introspection.ModelType;
import org.onap.aai.setup.SchemaVersion;
-import javax.annotation.PostConstruct;
-import javax.ws.rs.core.UriBuilder;
-import javax.xml.bind.JAXBException;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-
-import static org.hamcrest.Matchers.hasProperty;
-import static org.hamcrest.Matchers.is;
-
public class URIParserTest extends AAISetup {
- private Loader loader ;
+ private Loader loader;
@Rule
public ExpectedException thrown = ExpectedException.none();
-
+
/**
* Invalid path.
*
@@ -53,20 +55,25 @@ public class URIParserTest extends AAISetup {
* @throws UnsupportedEncodingException the unsupported encoding exception
*/
@PostConstruct
- public void createLoader(){
+ public void createLoader() {
loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, new SchemaVersion("v10"));
}
@Test
- public void invalidPath() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
- URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/network/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
-
+ public void invalidPath()
+ throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
+ URI uri =
+ UriBuilder
+ .fromPath("/aai/" + loader.getVersion()
+ + "/network/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3")
+ .build();
+
thrown.expect(AAIException.class);
- thrown.expect(hasProperty("code", is("AAI_3001")));
-
+ thrown.expect(hasProperty("code", is("AAI_3001")));
+
new URIToDBKey(loader, uri);
}
-
+
/**
* Invalid path no name space.
*
@@ -76,15 +83,17 @@ public class URIParserTest extends AAISetup {
* @throws UnsupportedEncodingException the unsupported encoding exception
*/
@Test
- public void invalidPathNoNameSpace() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
- URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
-
+ public void invalidPathNoNameSpace()
+ throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
+ URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion()
+ + "/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
+
thrown.expect(AAIException.class);
- thrown.expect(hasProperty("code", is("AAI_3000")));
-
+ thrown.expect(hasProperty("code", is("AAI_3000")));
+
new URIToDBKey(loader, uri);
}
-
+
/**
* Invalid path partial.
*
@@ -94,12 +103,13 @@ public class URIParserTest extends AAISetup {
* @throws UnsupportedEncodingException the unsupported encoding exception
*/
@Test
- public void invalidPathPartial() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
+ public void invalidPathPartial()
+ throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
URI uri = UriBuilder.fromPath("vservers/vserver/key2/l-interfaces/l-interface/key3").build();
-
+
thrown.expect(AAIException.class);
thrown.expect(hasProperty("code", is("AAI_3000")));
-
+
new URIToDBKey(loader, uri);
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToDBKeyTest.java b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToDBKeyTest.java
index 757fbc1f..f19e2681 100644
--- a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToDBKeyTest.java
+++ b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToDBKeyTest.java
@@ -17,35 +17,36 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.parsers.uri;
+import static org.hamcrest.Matchers.hasProperty;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertEquals;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+
+import javax.annotation.PostConstruct;
+import javax.ws.rs.core.UriBuilder;
+import javax.xml.bind.JAXBException;
+
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.onap.aai.AAISetup;
-import org.onap.aai.exceptions.AAIException;
-import org.onap.aai.parsers.exceptions.DoesNotStartWithValidNamespaceException;
import org.onap.aai.db.props.AAIProperties;
+import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.*;
-
-import javax.annotation.PostConstruct;
-import javax.ws.rs.core.UriBuilder;
-import javax.xml.bind.JAXBException;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-
-import static org.hamcrest.Matchers.hasProperty;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertEquals;
-
+import org.onap.aai.parsers.exceptions.DoesNotStartWithValidNamespaceException;
public class URIToDBKeyTest extends AAISetup {
- private Loader loader ;
+ private Loader loader;
@Rule
public ExpectedException thrown = ExpectedException.none();
-
+
/**
* Uri.
*
@@ -55,22 +56,24 @@ public class URIToDBKeyTest extends AAISetup {
* @throws UnsupportedEncodingException the unsupported encoding exception
*/
@PostConstruct
- public void createLoader(){
+ public void createLoader() {
loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
}
-
+
@Test
public void uri() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
- URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/cloudOwner-key/cloudRegion-key/tenants/tenant/tenantId-key/vservers/vserver/vserverId-key/l-interfaces/l-interface/key3").build();
+ URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion()
+ + "/cloud-infrastructure/cloud-regions/cloud-region/cloudOwner-key/cloudRegion-key/tenants/tenant/tenantId-key/vservers/vserver/vserverId-key/l-interfaces/l-interface/key3")
+ .build();
URIToDBKey parse = new URIToDBKey(loader, uri);
Object result = parse.getResult();
String expected = "cloud-region/tenant/vserver/l-interface";
-
+
assertEquals("blah", expected, result);
-
+
}
-
+
/**
* Uri no version.
*
@@ -80,17 +83,19 @@ public class URIToDBKeyTest extends AAISetup {
* @throws UnsupportedEncodingException the unsupported encoding exception
*/
@Test
- public void uriNoVersion() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
- URI uri = UriBuilder.fromPath("/cloud-infrastructure/cloud-regions/cloud-region/cloudOwner-key/cloudRegion-key/tenants/tenant/tenantId-key/vservers/vserver/vserverId-key/l-interfaces/l-interface/key3").build();
+ public void uriNoVersion()
+ throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
+ URI uri = UriBuilder.fromPath(
+ "/cloud-infrastructure/cloud-regions/cloud-region/cloudOwner-key/cloudRegion-key/tenants/tenant/tenantId-key/vservers/vserver/vserverId-key/l-interfaces/l-interface/key3")
+ .build();
URIToDBKey parse = new URIToDBKey(loader, uri);
Object result = parse.getResult();
-
+
String expected = "cloud-region/tenant/vserver/l-interface";
-
+
assertEquals("blah", expected, result);
-
+
}
-
/**
* Bad URI.
@@ -102,14 +107,16 @@ public class URIToDBKeyTest extends AAISetup {
*/
@Test
public void badURI() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
- URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/tenants/tenant/key1/vservers/vserver/key2/l-interadsfaces/l-interface/key3").build();
-
+ URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion()
+ + "/cloud-infrastructure/tenants/tenant/key1/vservers/vserver/key2/l-interadsfaces/l-interface/key3")
+ .build();
+
thrown.expect(AAIException.class);
- thrown.expect(hasProperty("code", is("AAI_3001")));
-
+ thrown.expect(hasProperty("code", is("AAI_3001")));
+
new URIToDBKey(loader, uri);
}
-
+
/**
* NotValid namespace.
*
@@ -119,13 +126,15 @@ public class URIToDBKeyTest extends AAISetup {
* @throws UnsupportedEncodingException the unsupported encoding exception
*/
@Test
- public void notValidNamespace() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
- URI uri = UriBuilder.fromPath("/cloud-region/cloud-regions/cloud-region/cloudOwner-key/cloudRegion-key/tenants/tenant/tenantId-key/vservers/vserver/vserverId-key/l-interfaces/l-interface/key3").build();
+ public void notValidNamespace()
+ throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
+ URI uri = UriBuilder.fromPath(
+ "/cloud-region/cloud-regions/cloud-region/cloudOwner-key/cloudRegion-key/tenants/tenant/tenantId-key/vservers/vserver/vserverId-key/l-interfaces/l-interface/key3")
+ .build();
thrown.expect(DoesNotStartWithValidNamespaceException.class);
URIToDBKey parse = new URIToDBKey(loader, uri);
}
-
-
+
/**
* No valid tokens.
*
@@ -135,15 +144,16 @@ public class URIToDBKeyTest extends AAISetup {
* @throws UnsupportedEncodingException the unsupported encoding exception
*/
@Test
- public void noValidTokens() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
+ public void noValidTokens()
+ throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud/blah/blah").build();
-
+
thrown.expect(AAIException.class);
- thrown.expect(hasProperty("code", is("AAI_3000")));
-
+ thrown.expect(hasProperty("code", is("AAI_3000")));
+
new URIToDBKey(loader, uri);
}
-
+
/**
* Starts with valid namespace.
*
@@ -153,17 +163,20 @@ public class URIToDBKeyTest extends AAISetup {
* @throws UnsupportedEncodingException the unsupported encoding exception
*/
@Test
- public void startsWithValidNamespace() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
- URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/cloudOwner-key/cloudRegion-key/tenants/tenant/tenantId-key/vservers/vserver/vserverId-key/l-interfaces/l-interface/key3").build();
-
+ public void startsWithValidNamespace()
+ throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
+ URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion()
+ + "/cloud-infrastructure/cloud-regions/cloud-region/cloudOwner-key/cloudRegion-key/tenants/tenant/tenantId-key/vservers/vserver/vserverId-key/l-interfaces/l-interface/key3")
+ .build();
+
URIToDBKey parse = new URIToDBKey(loader, uri);
Object result = parse.getResult();
String expected = "cloud-region/tenant/vserver/l-interface";
-
+
assertEquals("blah", expected, result);
}
-
+
/**
* Naming exceptions.
*
@@ -173,14 +186,15 @@ public class URIToDBKeyTest extends AAISetup {
*/
@Test
public void namingExceptions() throws IllegalArgumentException, AAIException, UnsupportedEncodingException {
- URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build();
+ URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655")
+ .build();
URIToDBKey parse = new URIToDBKey(loader, uri);
Object result = parse.getResult();
String expected = "vce/port-group/cvlan-tag";
-
+
assertEquals("blah", expected, result);
-
+
}
-
+
}
diff --git a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToExtensionInformationTest.java b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToExtensionInformationTest.java
index cb365bb7..7d7d284d 100644
--- a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToExtensionInformationTest.java
+++ b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToExtensionInformationTest.java
@@ -17,8 +17,18 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.parsers.uri;
+import static org.junit.Assert.assertEquals;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+
+import javax.annotation.PostConstruct;
+import javax.ws.rs.core.UriBuilder;
+import javax.xml.bind.JAXBException;
+
import org.junit.Test;
import org.onap.aai.AAISetup;
import org.onap.aai.exceptions.AAIException;
@@ -27,19 +37,10 @@ import org.onap.aai.introspection.ModelType;
import org.onap.aai.restcore.HttpMethod;
import org.onap.aai.setup.SchemaVersion;
-import javax.annotation.PostConstruct;
-import javax.ws.rs.core.UriBuilder;
-import javax.xml.bind.JAXBException;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-
-import static org.junit.Assert.assertEquals;
-
public class URIToExtensionInformationTest extends AAISetup {
-
- private Loader specificLoader ;
-
+ private Loader specificLoader;
+
/**
* Vservers V 7.
*
@@ -48,20 +49,25 @@ public class URIToExtensionInformationTest extends AAISetup {
* @throws IllegalArgumentException the illegal argument exception
* @throws UnsupportedEncodingException the unsupported encoding exception
*/
-
+
@PostConstruct
- public void createLoader(){
+ public void createLoader() {
specificLoader = loaderFactory.createLoaderForVersion(ModelType.MOXY, new SchemaVersion("v10"));
}
-
+
@Test
- public void vserversV8() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
- URI uri = UriBuilder.fromPath("/aai/" + specificLoader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/testOwner1/testRegion1/tenants/tenant/key1/vservers/vserver/key2").build();
+ public void vserversV8()
+ throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
+ URI uri = UriBuilder.fromPath("/aai/" + specificLoader.getVersion()
+ + "/cloud-infrastructure/cloud-regions/cloud-region/testOwner1/testRegion1/tenants/tenant/key1/vservers/vserver/key2")
+ .build();
URIToExtensionInformation parse = new URIToExtensionInformation(specificLoader, uri);
-
+
String namespace = "cloudInfrastructure";
- String preMethodName = "DynamicAddCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverPreProc";
- String postMethodName = "DynamicAddCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverPostProc";
+ String preMethodName =
+ "DynamicAddCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverPreProc";
+ String postMethodName =
+ "DynamicAddCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverPostProc";
String topLevel = "CloudRegion";
testSpec(parse, HttpMethod.PUT, namespace, preMethodName, postMethodName, topLevel);
@@ -77,12 +83,12 @@ public class URIToExtensionInformationTest extends AAISetup {
* @param postMethodName the post method name
* @param topLevel the top level
*/
- private void testSpec(URIToExtensionInformation info, HttpMethod httpMethod, String namespace, String preMethodName, String postMethodName, String topLevel) {
-
+ private void testSpec(URIToExtensionInformation info, HttpMethod httpMethod, String namespace, String preMethodName,
+ String postMethodName, String topLevel) {
String namespaceResult = info.getNamespace();
String methodNameResult = info.getMethodName(httpMethod, true);
-
+
assertEquals("namespace", namespace, namespaceResult);
assertEquals("preprocess method name", preMethodName, methodNameResult);
methodNameResult = info.getMethodName(httpMethod, false);
@@ -90,9 +96,8 @@ public class URIToExtensionInformationTest extends AAISetup {
assertEquals("postprocess method name", postMethodName, methodNameResult);
String topLevelResult = info.getTopObject();
-
+
assertEquals("topLevel", topLevel, topLevelResult);
}
-
-
+
}
diff --git a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToObjectTest.java b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToObjectTest.java
index 2bf1e35e..c28d5a7b 100644
--- a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToObjectTest.java
+++ b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToObjectTest.java
@@ -17,10 +17,20 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.parsers.uri;
-import org.onap.aai.schema.enums.ObjectMetadata;
-import org.onap.aai.setup.SchemaVersion;
+import static org.hamcrest.Matchers.hasProperty;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertEquals;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.util.HashMap;
+
+import javax.annotation.PostConstruct;
+import javax.ws.rs.core.UriBuilder;
+import javax.xml.bind.JAXBException;
import org.junit.Ignore;
import org.junit.Rule;
@@ -31,25 +41,16 @@ import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.*;
import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
+import org.onap.aai.schema.enums.ObjectMetadata;
+import org.onap.aai.setup.SchemaVersion;
import org.springframework.test.annotation.DirtiesContext;
-import javax.annotation.PostConstruct;
-import javax.ws.rs.core.UriBuilder;
-import javax.xml.bind.JAXBException;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.util.HashMap;
-
-import static org.hamcrest.Matchers.hasProperty;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertEquals;
-
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class URIToObjectTest extends AAISetup {
- private SchemaVersion version ;
+ private SchemaVersion version;
private SchemaVersion currentVersion;
- private Loader loader ;
+ private Loader loader;
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -63,7 +64,7 @@ public class URIToObjectTest extends AAISetup {
* @throws UnsupportedEncodingException the unsupported encoding exception
*/
@PostConstruct
- public void createLoader(){
+ public void createLoader() {
version = schemaVersions.getRelatedLinkVersion();
currentVersion = schemaVersions.getDefaultVersion();
loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getRelatedLinkVersion());
@@ -71,10 +72,13 @@ public class URIToObjectTest extends AAISetup {
@Test
public void uri() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
- URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
+ URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion()
+ + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3")
+ .build();
URIToObject parse = new URIToObject(loader, uri);
Introspector result = parse.getTopEntity();
- String expected = "{\"cloud-owner\":\"mycloudowner\",\"cloud-region-id\":\"mycloudregionid\",\"tenants\":{\"tenant\":[{\"tenant-id\":\"key1\",\"vservers\":{\"vserver\":[{\"vserver-id\":\"key2\",\"l-interfaces\":{\"l-interface\":[{\"interface-name\":\"key3\"}]}}]}}]}}";
+ String expected =
+ "{\"cloud-owner\":\"mycloudowner\",\"cloud-region-id\":\"mycloudregionid\",\"tenants\":{\"tenant\":[{\"tenant-id\":\"key1\",\"vservers\":{\"vserver\":[{\"vserver-id\":\"key2\",\"l-interfaces\":{\"l-interface\":[{\"interface-name\":\"key3\"}]}}]}}]}}";
String topEntity = "cloud-region";
String entity = "l-interface";
@@ -92,8 +96,11 @@ public class URIToObjectTest extends AAISetup {
* @throws AAIUnknownObjectException
*/
@Test
- public void uriNoVersion() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException, AAIUnknownObjectException {
- URI uri = UriBuilder.fromPath("/cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
+ public void uriNoVersion() throws JAXBException, AAIException, IllegalArgumentException,
+ UnsupportedEncodingException, AAIUnknownObjectException {
+ URI uri = UriBuilder.fromPath(
+ "/cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3")
+ .build();
HashMap<String, Introspector> relatedObjects = new HashMap<>();
Introspector tenantObj = this.loader.introspectorFromName("tenant");
tenantObj.setValue("tenant-id", "key1");
@@ -106,16 +113,15 @@ public class URIToObjectTest extends AAISetup {
URIToObject parse = new URIToObject(loader, uri, relatedObjects);
Introspector result = parse.getTopEntity();
- String expected = "{\"cloud-owner\":\"mycloudowner\",\"cloud-region-id\":\"mycloudregionid\",\"tenants\":{\"tenant\":[{\"tenant-id\":\"key1\",\"tenant-name\":\"name1\",\"vservers\":{\"vserver\":[{\"vserver-id\":\"key2\",\"vserver-name\":\"name2\",\"l-interfaces\":{\"l-interface\":[{\"interface-name\":\"key3\"}]}}]}}]}}";
+ String expected =
+ "{\"cloud-owner\":\"mycloudowner\",\"cloud-region-id\":\"mycloudregionid\",\"tenants\":{\"tenant\":[{\"tenant-id\":\"key1\",\"tenant-name\":\"name1\",\"vservers\":{\"vserver\":[{\"vserver-id\":\"key2\",\"vserver-name\":\"name2\",\"l-interfaces\":{\"l-interface\":[{\"interface-name\":\"key3\"}]}}]}}]}}";
String topEntity = "cloud-region";
String entity = "l-interface";
testSet(result.marshal(false), parse, expected, topEntity, entity, version);
-
}
-
/**
* Bad URI.
*
@@ -126,10 +132,12 @@ public class URIToObjectTest extends AAISetup {
*/
@Test
public void badURI() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
- URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interadsfaces/l-interface/key3").build();
+ URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion()
+ + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interadsfaces/l-interface/key3")
+ .build();
thrown.expect(AAIException.class);
- thrown.expect(hasProperty("code", is("AAI_3000")));
+ thrown.expect(hasProperty("code", is("AAI_3000")));
new URIToObject(loader, uri);
}
@@ -143,11 +151,15 @@ public class URIToObjectTest extends AAISetup {
* @throws UnsupportedEncodingException the unsupported encoding exception
*/
@Test
- public void startsWithValidNamespace() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
- URI uri = UriBuilder.fromPath("/cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
+ public void startsWithValidNamespace()
+ throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
+ URI uri = UriBuilder.fromPath(
+ "/cloud-infrastructure/cloud-regions/cloud-region/mycloudowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3")
+ .build();
URIToObject parse = new URIToObject(loader, uri);
Introspector result = parse.getTopEntity();
- String expected = "{\"cloud-owner\":\"mycloudowner\",\"cloud-region-id\":\"mycloudregionid\",\"tenants\":{\"tenant\":[{\"tenant-id\":\"key1\",\"vservers\":{\"vserver\":[{\"vserver-id\":\"key2\",\"l-interfaces\":{\"l-interface\":[{\"interface-name\":\"key3\"}]}}]}}]}}";
+ String expected =
+ "{\"cloud-owner\":\"mycloudowner\",\"cloud-region-id\":\"mycloudregionid\",\"tenants\":{\"tenant\":[{\"tenant-id\":\"key1\",\"vservers\":{\"vserver\":[{\"vserver-id\":\"key2\",\"l-interfaces\":{\"l-interface\":[{\"interface-name\":\"key3\"}]}}]}}]}}";
String topEntity = "cloud-region";
String entity = "l-interface";
@@ -163,7 +175,8 @@ public class URIToObjectTest extends AAISetup {
* @throws UnsupportedEncodingException the unsupported encoding exception
*/
@Test
- public void singleTopLevel() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
+ public void singleTopLevel()
+ throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
URI uri = UriBuilder.fromPath("/network/generic-vnfs/generic-vnf/key1").build();
URIToObject parse = new URIToObject(loader, uri);
Introspector result = parse.getTopEntity();
@@ -186,11 +199,14 @@ public class URIToObjectTest extends AAISetup {
*/
@Test
@Ignore
- public void namingExceptions() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
- URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655").build();
+ public void namingExceptions()
+ throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
+ URI uri = UriBuilder.fromPath("network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/655")
+ .build();
URIToObject parse = new URIToObject(loader, uri);
Introspector result = parse.getTopEntity();
- String expected = "{\"vnf-id\":\"key1\",\"port-groups\":{\"port-group\":[{\"interface-id\":\"key2\",\"cvlan-tags\":{\"cvlan-tag-entry\":[{\"cvlan-tag\":655}]}}]}}";
+ String expected =
+ "{\"vnf-id\":\"key1\",\"port-groups\":{\"port-group\":[{\"interface-id\":\"key2\",\"cvlan-tags\":{\"cvlan-tag-entry\":[{\"cvlan-tag\":655}]}}]}}";
String topEntity = "vce";
String entity = "cvlan-tag";
@@ -208,18 +224,22 @@ public class URIToObjectTest extends AAISetup {
@Test
@Ignore
public void noListObject() throws IllegalArgumentException, UnsupportedEncodingException, AAIException {
- URI uri = UriBuilder.fromPath("/aai/v6/network/vpls-pes/vpls-pe/0e6189fd-9257-49b9-a3be-d7ba980ccfc9/lag-interfaces/lag-interface/8ae5aa76-d597-4382-b219-04f266fe5e37/l-interfaces/l-interface/9e141d03-467b-437f-b4eb-b3133ec1e205/l3-interface-ipv4-address-list/8f19f0ea-a81f-488e-8d5c-9b7b53696c11").build();
+ URI uri = UriBuilder.fromPath(
+ "/aai/v6/network/vpls-pes/vpls-pe/0e6189fd-9257-49b9-a3be-d7ba980ccfc9/lag-interfaces/lag-interface/8ae5aa76-d597-4382-b219-04f266fe5e37/l-interfaces/l-interface/9e141d03-467b-437f-b4eb-b3133ec1e205/l3-interface-ipv4-address-list/8f19f0ea-a81f-488e-8d5c-9b7b53696c11")
+ .build();
URIToObject parse = new URIToObject(loader, uri);
Introspector result = parse.getTopEntity();
String topEntity = "vpls-pe";
String entity = "l3-interface-ipv4-address-list";
- String expected = "{\"equipment-name\":\"0e6189fd-9257-49b9-a3be-d7ba980ccfc9\",\"lag-interfaces\":{\"lag-interface\":[{\"interface-name\":\"8ae5aa76-d597-4382-b219-04f266fe5e37\",\"l-interfaces\":{\"l-interface\":[{\"interface-name\":\"9e141d03-467b-437f-b4eb-b3133ec1e205\",\"l3-interface-ipv4-address-list\":[{\"l3-interface-ipv4-address\":\"8f19f0ea-a81f-488e-8d5c-9b7b53696c11\"}]}]}}]}}";
+ String expected =
+ "{\"equipment-name\":\"0e6189fd-9257-49b9-a3be-d7ba980ccfc9\",\"lag-interfaces\":{\"lag-interface\":[{\"interface-name\":\"8ae5aa76-d597-4382-b219-04f266fe5e37\",\"l-interfaces\":{\"l-interface\":[{\"interface-name\":\"9e141d03-467b-437f-b4eb-b3133ec1e205\",\"l3-interface-ipv4-address-list\":[{\"l3-interface-ipv4-address\":\"8f19f0ea-a81f-488e-8d5c-9b7b53696c11\"}]}]}}]}}";
testSet(result.marshal(false), parse, expected, topEntity, entity, version);
}
@Test
- public void relativePath() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
+ public void relativePath()
+ throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
URI uri = UriBuilder.fromPath("./l-interfaces/l-interface/key1").build();
URIToObject parse = new URIToObject(loader, uri);
Introspector result = parse.getEntity();
@@ -242,7 +262,8 @@ public class URIToObjectTest extends AAISetup {
* @param entity the entity
* @param version the version
*/
- public void testSet(String json, URIToObject parse, String expected, String topEntity, String entity, SchemaVersion version) {
+ public void testSet(String json, URIToObject parse, String expected, String topEntity, String entity,
+ SchemaVersion version) {
assertEquals("blah", expected, json);
assertEquals("top entity", topEntity, parse.getTopEntityName());
diff --git a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToRelationshipObjectTest.java b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToRelationshipObjectTest.java
index 4d0ec6ca..e983d007 100644
--- a/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToRelationshipObjectTest.java
+++ b/aai-core/src/test/java/org/onap/aai/parsers/uri/URIToRelationshipObjectTest.java
@@ -17,8 +17,22 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.parsers.uri;
+import static org.hamcrest.Matchers.hasProperty;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertTrue;
+
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.annotation.PostConstruct;
+import javax.ws.rs.core.UriBuilder;
+import javax.xml.bind.JAXBException;
+
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -27,31 +41,20 @@ import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.*;
import org.onap.aai.setup.SchemaVersion;
-import javax.annotation.PostConstruct;
-import javax.ws.rs.core.UriBuilder;
-import javax.xml.bind.JAXBException;
-import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import static org.hamcrest.Matchers.hasProperty;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertTrue;
-
public class URIToRelationshipObjectTest extends AAISetup {
- private SchemaVersion latest ;
+ private SchemaVersion latest;
private Loader loader;
@Rule
public ExpectedException thrown = ExpectedException.none();
@PostConstruct
- public void createLoader(){
+ public void createLoader() {
latest = schemaVersions.getDefaultVersion();
loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, latest);
}
+
/**
* Uri.
*
@@ -59,20 +62,24 @@ public class URIToRelationshipObjectTest extends AAISetup {
* @throws AAIException the AAI exception
* @throws IllegalArgumentException the illegal argument exception
* @throws UnsupportedEncodingException the unsupported encoding exception
- * @throws URISyntaxException
+ * @throws URISyntaxException
* @throws MalformedURLException the malformed URL exception
*/
@Test
- public void uri() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException, URISyntaxException {
-
- URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
+ public void uri() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException,
+ URISyntaxException {
+
+ URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion()
+ + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3")
+ .build();
URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
Introspector result = parse.getResult();
- String expected = "\\{\"related-to\":\"l-interface\",\"related-link\":\"/aai/" + latest + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3\",\"relationship-data\":\\[\\{\"relationship-key\":\"cloud-region.cloud-owner\",\"relationship-value\":\"mycloudregionowner\"\\},\\{\"relationship-key\":\"cloud-region.cloud-region-id\",\"relationship-value\":\"mycloudregionid\"\\},\\{\"relationship-key\":\"tenant.tenant-id\",\"relationship-value\":\"key1\"\\},\\{\"relationship-key\":\"vserver.vserver-id\",\"relationship-value\":\"key2\"\\},\\{\"relationship-key\":\"l-interface.interface-name\",\"relationship-value\":\"key3\"\\}\\]\\}";
+ String expected = "\\{\"related-to\":\"l-interface\",\"related-link\":\"/aai/" + latest
+ + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3\",\"relationship-data\":\\[\\{\"relationship-key\":\"cloud-region.cloud-owner\",\"relationship-value\":\"mycloudregionowner\"\\},\\{\"relationship-key\":\"cloud-region.cloud-region-id\",\"relationship-value\":\"mycloudregionid\"\\},\\{\"relationship-key\":\"tenant.tenant-id\",\"relationship-value\":\"key1\"\\},\\{\"relationship-key\":\"vserver.vserver-id\",\"relationship-value\":\"key2\"\\},\\{\"relationship-key\":\"l-interface.interface-name\",\"relationship-value\":\"key3\"\\}\\]\\}";
assertTrue("blah", result.marshal(false).matches(expected));
-
+
}
-
+
/**
* Uri no version.
*
@@ -80,18 +87,21 @@ public class URIToRelationshipObjectTest extends AAISetup {
* @throws AAIException the AAI exception
* @throws IllegalArgumentException the illegal argument exception
* @throws UnsupportedEncodingException the unsupported encoding exception
- * @throws URISyntaxException
+ * @throws URISyntaxException
* @throws MalformedURLException the malformed URL exception
*/
@Test
- public void uriNoVersion() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException, URISyntaxException {
- URI uri = UriBuilder.fromPath("/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3").build();
+ public void uriNoVersion() throws JAXBException, AAIException, IllegalArgumentException,
+ UnsupportedEncodingException, URISyntaxException {
+ URI uri = UriBuilder.fromPath(
+ "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3")
+ .build();
URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
Introspector result = parse.getResult();
- String expected = "\\{\"related-to\":\"l-interface\",\"related-link\":\"/aai/" + latest + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3\",\"relationship-data\":\\[\\{\"relationship-key\":\"cloud-region.cloud-owner\",\"relationship-value\":\"mycloudregionowner\"\\},\\{\"relationship-key\":\"cloud-region.cloud-region-id\",\"relationship-value\":\"mycloudregionid\"\\},\\{\"relationship-key\":\"tenant.tenant-id\",\"relationship-value\":\"key1\"\\},\\{\"relationship-key\":\"vserver.vserver-id\",\"relationship-value\":\"key2\"\\},\\{\"relationship-key\":\"l-interface.interface-name\",\"relationship-value\":\"key3\"\\}\\]\\}";
+ String expected = "\\{\"related-to\":\"l-interface\",\"related-link\":\"/aai/" + latest
+ + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interfaces/l-interface/key3\",\"relationship-data\":\\[\\{\"relationship-key\":\"cloud-region.cloud-owner\",\"relationship-value\":\"mycloudregionowner\"\\},\\{\"relationship-key\":\"cloud-region.cloud-region-id\",\"relationship-value\":\"mycloudregionid\"\\},\\{\"relationship-key\":\"tenant.tenant-id\",\"relationship-value\":\"key1\"\\},\\{\"relationship-key\":\"vserver.vserver-id\",\"relationship-value\":\"key2\"\\},\\{\"relationship-key\":\"l-interface.interface-name\",\"relationship-value\":\"key3\"\\}\\]\\}";
assertTrue("blah", result.marshal(false).matches(expected));
-
}
/**
@@ -101,19 +111,25 @@ public class URIToRelationshipObjectTest extends AAISetup {
* @throws AAIException the AAI exception
* @throws IllegalArgumentException the illegal argument exception
* @throws UnsupportedEncodingException the unsupported encoding exception
- * @throws URISyntaxException
+ * @throws URISyntaxException
* @throws MalformedURLException the malformed URL exception
*/
@Test
- public void doubleKeyRelationship() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException, URISyntaxException {
- URI uri = UriBuilder.fromPath("/aai/" + latest + "/cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3/").build();
+ public void doubleKeyRelationship() throws JAXBException, AAIException, IllegalArgumentException,
+ UnsupportedEncodingException, URISyntaxException {
+ URI uri =
+ UriBuilder
+ .fromPath("/aai/" + latest
+ + "/cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3/")
+ .build();
URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
Introspector result = parse.getResult();
- String expected = "\\{\"related-to\":\"ctag-pool\",\"related-link\":\"/aai/" + latest + "/cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3\",\"relationship-data\":\\[\\{\"relationship-key\":\"complex.physical-location-id\",\"relationship-value\":\"key1\"\\},\\{\"relationship-key\":\"ctag-pool.target-pe\",\"relationship-value\":\"key2\"\\},\\{\"relationship-key\":\"ctag-pool.availability-zone-name\",\"relationship-value\":\"key3\"\\}\\]\\}";
+ String expected = "\\{\"related-to\":\"ctag-pool\",\"related-link\":\"/aai/" + latest
+ + "/cloud-infrastructure/complexes/complex/key1/ctag-pools/ctag-pool/key2/key3\",\"relationship-data\":\\[\\{\"relationship-key\":\"complex.physical-location-id\",\"relationship-value\":\"key1\"\\},\\{\"relationship-key\":\"ctag-pool.target-pe\",\"relationship-value\":\"key2\"\\},\\{\"relationship-key\":\"ctag-pool.availability-zone-name\",\"relationship-value\":\"key3\"\\}\\]\\}";
assertTrue("blah", result.marshal(false).matches(expected));
}
-
+
/**
* Uri with non string key.
*
@@ -121,17 +137,24 @@ public class URIToRelationshipObjectTest extends AAISetup {
* @throws AAIException the AAI exception
* @throws IllegalArgumentException the illegal argument exception
* @throws UnsupportedEncodingException the unsupported encoding exception
- * @throws URISyntaxException
+ * @throws URISyntaxException
* @throws MalformedURLException the malformed URL exception
*/
@Test
- public void uriWithNonStringKey() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException, URISyntaxException {
- URI uri = UriBuilder.fromPath("/aai/" + latest + "/network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/144").build();
+ public void uriWithNonStringKey() throws JAXBException, AAIException, IllegalArgumentException,
+ UnsupportedEncodingException, URISyntaxException {
+ URI uri =
+ UriBuilder
+ .fromPath("/aai/" + latest
+ + "/network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/144")
+ .build();
URIToRelationshipObject parse = new URIToRelationshipObject(loader, uri);
Introspector result = parse.getResult();
- String expected = "\\{\"related-to\":\"cvlan-tag\",\"related-link\":\"/aai/" + latest + "/network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/144\",\"relationship-data\":\\[\\{\"relationship-key\":\"vce.vnf-id\",\"relationship-value\":\"key1\"\\},\\{\"relationship-key\":\"port-group.interface-id\",\"relationship-value\":\"key2\"\\},\\{\"relationship-key\":\"cvlan-tag.cvlan-tag\",\"relationship-value\":\"144\"\\}\\]\\}";
+ String expected = "\\{\"related-to\":\"cvlan-tag\",\"related-link\":\"/aai/" + latest
+ + "/network/vces/vce/key1/port-groups/port-group/key2/cvlan-tags/cvlan-tag/144\",\"relationship-data\":\\[\\{\"relationship-key\":\"vce.vnf-id\",\"relationship-value\":\"key1\"\\},\\{\"relationship-key\":\"port-group.interface-id\",\"relationship-value\":\"key2\"\\},\\{\"relationship-key\":\"cvlan-tag.cvlan-tag\",\"relationship-value\":\"144\"\\}\\]\\}";
assertTrue("blah", result.marshal(false).matches(expected));
}
+
/**
* Bad URI.
*
@@ -142,12 +165,14 @@ public class URIToRelationshipObjectTest extends AAISetup {
*/
@Test
public void badURI() throws JAXBException, AAIException, IllegalArgumentException, UnsupportedEncodingException {
- URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion() + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interadsfaces/l-interface/key3").build();
-
+ URI uri = UriBuilder.fromPath("/aai/" + loader.getVersion()
+ + "/cloud-infrastructure/cloud-regions/cloud-region/mycloudregionowner/mycloudregionid/tenants/tenant/key1/vservers/vserver/key2/l-interadsfaces/l-interface/key3")
+ .build();
+
thrown.expect(AAIException.class);
- thrown.expect(hasProperty("code", is("AAI_3000")));
-
+ thrown.expect(hasProperty("code", is("AAI_3000")));
+
URIToObject parse = new URIToObject(loader, uri);
-
+
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/query/builder/ExcludeQueryTest.java b/aai-core/src/test/java/org/onap/aai/query/builder/ExcludeQueryTest.java
index e466de49..2d6e2291 100644
--- a/aai-core/src/test/java/org/onap/aai/query/builder/ExcludeQueryTest.java
+++ b/aai-core/src/test/java/org/onap/aai/query/builder/ExcludeQueryTest.java
@@ -17,8 +17,14 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.query.builder;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.T;
@@ -28,68 +34,64 @@ import org.junit.Before;
import org.junit.Test;
import org.onap.aai.AAISetup;
import org.onap.aai.db.props.AAIProperties;
+import org.onap.aai.edges.enums.EdgeType;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.Loader;
import org.onap.aai.introspection.ModelType;
-/*
- * import org.onap.aai.serialization.db.EdgeRules;
-
-import org.onap.aai.serialization.db.EdgeType;
- */
import org.onap.aai.serialization.db.EdgeSerializer;
import org.springframework.beans.factory.annotation.Autowired;
-import org.onap.aai.edges.enums.EdgeType;
import org.springframework.test.annotation.DirtiesContext;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.Assert.assertTrue;
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class ExcludeQueryTest extends AAISetup {
@Autowired
EdgeSerializer edgeSer;
-
+
private Loader loader;
-
+
@Before
public void setup() throws Exception {
loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
}
-
- private QueryBuilder<Vertex> buildTestQuery(QueryBuilder<Vertex> qb) throws AAIException{
- return qb.createEdgeTraversal(EdgeType.TREE, "cloud-region","availability-zone").getVerticesExcludeByProperty("hypervisor-type", "hypervisortype-11").store("x").cap("x").unfold().dedup();
+
+ private QueryBuilder<Vertex> buildTestQuery(QueryBuilder<Vertex> qb) throws AAIException {
+ return qb.createEdgeTraversal(EdgeType.TREE, "cloud-region", "availability-zone")
+ .getVerticesExcludeByProperty("hypervisor-type", "hypervisortype-11").store("x").cap("x").unfold()
+ .dedup();
}
-
+
@Test
public void gremlinQueryExcludeTest() throws AAIException {
Graph graph = TinkerGraph.open();
GraphTraversalSource g = graph.traversal();
-
- Vertex cloudregion = graph.addVertex(T.label, "cloud-region", T.id, "0", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region-id-1", "cloud-owner", "cloud-owner-1");
- Vertex availibityzone = graph.addVertex(T.label, "availability-zone", T.id, "1", "aai-node-type", "availability-zone", "availability-zone-name", "az-name-1", "hypervisor-type", "hypervisortype-1");
- Vertex availibityzone11 = graph.addVertex(T.label, "availability-zone", T.id, "11", "aai-node-type", "availability-zone", "availability-zone-name", "az-name-11", "hypervisor-type", "hypervisortype-11");
-
-
- Vertex cloudregion1 = graph.addVertex(T.label, "cloud-region", T.id, "3", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region-id-10", "cloud-owner", "cloud-owner-10");
- Vertex availibityzone1 = graph.addVertex(T.label, "availability-zone", T.id, "4", "aai-node-type", "availability-zone", "availability-zone-name", "az-name-10", "hypervisor-type", "hypervisortype-10");
- Vertex availibityzone12 = graph.addVertex(T.label, "availability-zone", T.id, "12", "aai-node-type", "availability-zone", "availability-zone-name", "az-name-12", "hypervisor-type", "hypervisortype-12");
-
+
+ Vertex cloudregion = graph.addVertex(T.label, "cloud-region", T.id, "0", "aai-node-type", "cloud-region",
+ "cloud-region-id", "cloud-region-id-1", "cloud-owner", "cloud-owner-1");
+ Vertex availibityzone = graph.addVertex(T.label, "availability-zone", T.id, "1", "aai-node-type",
+ "availability-zone", "availability-zone-name", "az-name-1", "hypervisor-type", "hypervisortype-1");
+ Vertex availibityzone11 = graph.addVertex(T.label, "availability-zone", T.id, "11", "aai-node-type",
+ "availability-zone", "availability-zone-name", "az-name-11", "hypervisor-type", "hypervisortype-11");
+
+ Vertex cloudregion1 = graph.addVertex(T.label, "cloud-region", T.id, "3", "aai-node-type", "cloud-region",
+ "cloud-region-id", "cloud-region-id-10", "cloud-owner", "cloud-owner-10");
+ Vertex availibityzone1 = graph.addVertex(T.label, "availability-zone", T.id, "4", "aai-node-type",
+ "availability-zone", "availability-zone-name", "az-name-10", "hypervisor-type", "hypervisortype-10");
+ Vertex availibityzone12 = graph.addVertex(T.label, "availability-zone", T.id, "12", "aai-node-type",
+ "availability-zone", "availability-zone-name", "az-name-12", "hypervisor-type", "hypervisortype-12");
+
edgeSer.addTreeEdge(g, cloudregion, availibityzone);
edgeSer.addTreeEdge(g, cloudregion, availibityzone11);
-
-
-
+
edgeSer.addTreeEdge(g, cloudregion1, availibityzone1);
edgeSer.addTreeEdge(g, cloudregion1, availibityzone12);
-
+
List<Vertex> expected = new ArrayList<>();
expected.add(availibityzone);
-
- GremlinTraversal<Vertex> qb = new GremlinTraversal<>(loader, g, cloudregion);
+
+ GremlinTraversal<Vertex> qb = new GremlinTraversal<>(loader, g, cloudregion);
QueryBuilder q = buildTestQuery(qb);
-
+
List<Vertex> results = q.toList();
assertTrue("results match", expected.containsAll(results) && results.containsAll(expected));
@@ -99,39 +101,36 @@ public class ExcludeQueryTest extends AAISetup {
public void traversalQueryExcludeTest() throws AAIException {
Graph graph = TinkerGraph.open();
GraphTraversalSource g = graph.traversal();
-
-
- Vertex cloudregion = graph.addVertex(T.label, "cloud-region", T.id, "0", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region-id-1", "cloud-owner", "cloud-owner-1");
- Vertex availibityzone = graph.addVertex(T.label, "availability-zone", T.id, "1", "aai-node-type", "availability-zone", "availability-zone-name", "az-name-1", "hypervisor-type", "hypervisortype-1");
- Vertex availibityzone11 = graph.addVertex(T.label, "availability-zone", T.id, "11", "aai-node-type", "availability-zone", "availability-zone-name", "az-name-11", "hypervisor-type", "hypervisortype-11");
-
-
- Vertex cloudregion1 = graph.addVertex(T.label, "cloud-region", T.id, "3", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region-id-10", "cloud-owner", "cloud-owner-10");
- Vertex availibityzone1 = graph.addVertex(T.label, "availability-zone", T.id, "4", "aai-node-type", "availability-zone", "availability-zone-name", "az-name-10", "hypervisor-type", "hypervisortype-10");
- Vertex availibityzone12 = graph.addVertex(T.label, "availability-zone", T.id, "12", "aai-node-type", "availability-zone", "availability-zone-name", "az-name-12", "hypervisor-type", "hypervisortype-12");
-
+
+ Vertex cloudregion = graph.addVertex(T.label, "cloud-region", T.id, "0", "aai-node-type", "cloud-region",
+ "cloud-region-id", "cloud-region-id-1", "cloud-owner", "cloud-owner-1");
+ Vertex availibityzone = graph.addVertex(T.label, "availability-zone", T.id, "1", "aai-node-type",
+ "availability-zone", "availability-zone-name", "az-name-1", "hypervisor-type", "hypervisortype-1");
+ Vertex availibityzone11 = graph.addVertex(T.label, "availability-zone", T.id, "11", "aai-node-type",
+ "availability-zone", "availability-zone-name", "az-name-11", "hypervisor-type", "hypervisortype-11");
+
+ Vertex cloudregion1 = graph.addVertex(T.label, "cloud-region", T.id, "3", "aai-node-type", "cloud-region",
+ "cloud-region-id", "cloud-region-id-10", "cloud-owner", "cloud-owner-10");
+ Vertex availibityzone1 = graph.addVertex(T.label, "availability-zone", T.id, "4", "aai-node-type",
+ "availability-zone", "availability-zone-name", "az-name-10", "hypervisor-type", "hypervisortype-10");
+ Vertex availibityzone12 = graph.addVertex(T.label, "availability-zone", T.id, "12", "aai-node-type",
+ "availability-zone", "availability-zone-name", "az-name-12", "hypervisor-type", "hypervisortype-12");
+
edgeSer.addTreeEdge(g, cloudregion, availibityzone);
edgeSer.addTreeEdge(g, cloudregion, availibityzone11);
-
-
-
+
edgeSer.addTreeEdge(g, cloudregion1, availibityzone1);
edgeSer.addTreeEdge(g, cloudregion1, availibityzone12);
-
+
List<Vertex> expected = new ArrayList<>();
expected.add(availibityzone);
-
-
-
-
- TraversalQuery<Vertex> qb = new TraversalQuery<>(loader, g, cloudregion);
+
+ TraversalQuery<Vertex> qb = new TraversalQuery<>(loader, g, cloudregion);
QueryBuilder<Vertex> q = buildTestQuery(qb);
-
+
List<Vertex> results = q.toList();
assertTrue("results match", expected.containsAll(results) && results.containsAll(expected));
}
-
-
}
diff --git a/aai-core/src/test/java/org/onap/aai/query/builder/GremlinTraversalTest.java b/aai-core/src/test/java/org/onap/aai/query/builder/GremlinTraversalTest.java
index 7873fc1b..6be9dc05 100644
--- a/aai-core/src/test/java/org/onap/aai/query/builder/GremlinTraversalTest.java
+++ b/aai-core/src/test/java/org/onap/aai/query/builder/GremlinTraversalTest.java
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.query.builder;
import org.apache.tinkerpop.gremlin.process.traversal.Path;
@@ -25,30 +26,31 @@ import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.introspection.ModelType;
+
public class GremlinTraversalTest extends QueryBuilderTestAbstraction {
-
+
@Override
protected QueryBuilder<Edge> getNewEdgeTraversalWithTestEdgeRules(Vertex v) {
loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
return new GremlinTraversal<>(loader, g, v);
}
-
+
@Override
protected QueryBuilder<Edge> getNewEdgeTraversalWithTestEdgeRules() {
loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
return new GremlinTraversal<>(loader, g);
}
-
+
@Override
protected QueryBuilder<Vertex> getNewVertexTraversalWithTestEdgeRules(Vertex v) {
return new GremlinTraversal<>(loader, g, v);
}
-
+
@Override
protected QueryBuilder<Vertex> getNewVertexTraversalWithTestEdgeRules() {
return new GremlinTraversal<>(loader, g);
}
-
+
@Override
protected QueryBuilder<Tree> getNewTreeTraversalWithTestEdgeRules(Vertex v) {
return new GremlinTraversal<>(loader, g, v);
@@ -69,5 +71,4 @@ public class GremlinTraversalTest extends QueryBuilderTestAbstraction {
return new GremlinTraversal<>(loader, g);
}
-
}
diff --git a/aai-core/src/test/java/org/onap/aai/query/builder/QueryBuilderTestAbstraction.java b/aai-core/src/test/java/org/onap/aai/query/builder/QueryBuilderTestAbstraction.java
index b26c0b05..0e527493 100644
--- a/aai-core/src/test/java/org/onap/aai/query/builder/QueryBuilderTestAbstraction.java
+++ b/aai-core/src/test/java/org/onap/aai/query/builder/QueryBuilderTestAbstraction.java
@@ -17,8 +17,18 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.query.builder;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
import org.apache.tinkerpop.gremlin.process.traversal.Path;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.BulkSet;
@@ -32,14 +42,15 @@ import org.junit.runner.RunWith;
import org.onap.aai.config.ConfigConfiguration;
import org.onap.aai.config.IntrospectionConfig;
import org.onap.aai.config.SpringContextAware;
+import org.onap.aai.db.props.AAIProperties;
+import org.onap.aai.edges.EdgeIngestor;
+import org.onap.aai.edges.enums.EdgeType;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.Loader;
import org.onap.aai.introspection.LoaderFactory;
import org.onap.aai.introspection.ModelType;
import org.onap.aai.nodes.NodeIngestor;
import org.onap.aai.serialization.db.EdgeSerializer;
-import org.onap.aai.edges.EdgeIngestor;
-import org.onap.aai.edges.enums.EdgeType;
import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException;
import org.onap.aai.serialization.queryformats.QueryFormatTestHelper;
import org.onap.aai.setup.SchemaLocationsBean;
@@ -50,37 +61,18 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import org.onap.aai.db.props.AAIProperties;
-
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
-import static org.junit.Assert.*;
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(classes = {
- ConfigConfiguration.class,
- QueryTestsConfigTranslator.class,
- NodeIngestor.class,
- EdgeIngestor.class,
- EdgeSerializer.class,
- SpringContextAware.class,
- IntrospectionConfig.class
-})
+@ContextConfiguration(
+ classes = {ConfigConfiguration.class, QueryTestsConfigTranslator.class, NodeIngestor.class, EdgeIngestor.class,
+ EdgeSerializer.class, SpringContextAware.class, IntrospectionConfig.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
-@TestPropertySource(properties = {
- "schema.translator.list = config",
- "schema.nodes.location=src/test/resources/onap/oxm",
- "schema.edges.location=src/test/resources/onap/dbedgerules"
-})
+@TestPropertySource(
+ properties = {"schema.translator.list = config", "schema.nodes.location=src/test/resources/onap/oxm",
+ "schema.edges.location=src/test/resources/onap/dbedgerules"})
public abstract class QueryBuilderTestAbstraction {
- protected Loader loader;
+ protected Loader loader;
protected static Graph graph;
protected GraphTraversalSource g;
@@ -93,12 +85,12 @@ public abstract class QueryBuilderTestAbstraction {
@Autowired
protected LoaderFactory loaderFactory;
-
@BeforeClass
public static void setup() throws Exception {
System.setProperty("AJSC_HOME", ".");
System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
- QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"), "src/test/resources/bundleconfig-local/etc/oxm/");
+ QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"),
+ "src/test/resources/bundleconfig-local/etc/oxm/");
graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
}
@@ -106,7 +98,6 @@ public abstract class QueryBuilderTestAbstraction {
public void configure() throws Exception {
loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
-
g = graph.traversal();
}
@@ -123,8 +114,8 @@ public abstract class QueryBuilderTestAbstraction {
@Test
public void createEdgeGVnfToVnfcTraversal() throws AAIException {
- Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","myvnf").next();
- Vertex vnfc = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
+ Vertex gvnf = g.addV("aai-node-type", "generic-vnf", "vnf-id", "myvnf").next();
+ Vertex vnfc = g.addV("aai-node-type", "vnfc", "vnfc-name", "a-name").next();
testEdgeSer.addEdge(g, gvnf, vnfc, "uses");
QueryBuilder<Vertex> tQ = getNewVertexTraversalWithTestEdgeRules(gvnf);
@@ -132,14 +123,13 @@ public abstract class QueryBuilderTestAbstraction {
assertEquals(vnfc, tQ.next());
-
}
@Test
public void createEdgeLinterfaceToLogicalLinkTraversal() throws AAIException {
- Vertex lInterface = g.addV("aai-node-type","l-interface","interface-name","l-interface-a").next();
- Vertex logicalLink = g.addV("aai-node-type","logical-link","link-name","logical-link-a").next();
+ Vertex lInterface = g.addV("aai-node-type", "l-interface", "interface-name", "l-interface-a").next();
+ Vertex logicalLink = g.addV("aai-node-type", "logical-link", "link-name", "logical-link-a").next();
testEdgeSer.addEdge(g, lInterface, logicalLink, "sourceLInterface");
QueryBuilder<Vertex> tQ = getNewVertexTraversalWithTestEdgeRules(lInterface);
@@ -149,21 +139,22 @@ public abstract class QueryBuilderTestAbstraction {
assertEquals(logicalLink, next);
-
}
@SuppressWarnings("rawtypes")
@Test
public void createEdgeLinterfaceToLogicalLinkTraversal_tree() throws AAIException {
- Vertex lInterface = g.addV("aai-node-type","l-interface","interface-name","l-interface-a").next();
- Vertex logicalLink = g.addV("aai-node-type","logical-link","link-name","logical-link-a").next();
+ Vertex lInterface = g.addV("aai-node-type", "l-interface", "interface-name", "l-interface-a").next();
+ Vertex logicalLink = g.addV("aai-node-type", "logical-link", "link-name", "logical-link-a").next();
testEdgeSer.addEdge(g, lInterface, logicalLink, "sourceLInterface");
QueryBuilder<Tree> tQ = getNewTreeTraversalWithTestEdgeRules(lInterface).createEdgeTraversal(EdgeType.COUSIN,
- loader.introspectorFromName("l-interface" ), loader.introspectorFromName("logical-link")).tree();
+ loader.introspectorFromName("l-interface"), loader.introspectorFromName("logical-link")).tree();
- Vertex lInterfaceExpected = graph.traversal().V().has("aai-node-type","l-interface").has("interface-name","l-interface-a").next();
- Vertex logicalLinkExpected = graph.traversal().V().has("aai-node-type", "logical-link").has("link-name","logical-link-a").next();
+ Vertex lInterfaceExpected =
+ graph.traversal().V().has("aai-node-type", "l-interface").has("interface-name", "l-interface-a").next();
+ Vertex logicalLinkExpected =
+ graph.traversal().V().has("aai-node-type", "logical-link").has("link-name", "logical-link-a").next();
Tree tree = tQ.next();
assertTrue(tree.containsKey(lInterfaceExpected));
assertTrue(((Tree) tree.get(lInterfaceExpected)).containsKey(logicalLinkExpected));
@@ -172,15 +163,18 @@ public abstract class QueryBuilderTestAbstraction {
@SuppressWarnings("rawtypes")
@Test
public void createEdgeLinterfaceToLogicalLinkTraversal_Path() throws AAIException {
- Vertex pInterface = g.addV("aai-node-type","p-interface","interface-name","p-interface-a").next();
- Vertex lInterface = g.addV("aai-node-type","l-interface","interface-name","l-interface-a").next();
- Vertex logicalLink = g.addV("aai-node-type","logical-link","link-name","logical-link-a").next();
+ Vertex pInterface = g.addV("aai-node-type", "p-interface", "interface-name", "p-interface-a").next();
+ Vertex lInterface = g.addV("aai-node-type", "l-interface", "interface-name", "l-interface-a").next();
+ Vertex logicalLink = g.addV("aai-node-type", "logical-link", "link-name", "logical-link-a").next();
testEdgeSer.addEdge(g, lInterface, logicalLink);
testEdgeSer.addTreeEdge(g, pInterface, lInterface);
- QueryBuilder<Path> tQ = getNewPathTraversalWithTestEdgeRules(pInterface).createEdgeTraversal(EdgeType.TREE,
- loader.introspectorFromName("p-interface" ), loader.introspectorFromName("l-interface")).createEdgeTraversal(EdgeType.COUSIN,
- loader.introspectorFromName("l-interface" ), loader.introspectorFromName("logical-link")).path();
+ QueryBuilder<Path> tQ = getNewPathTraversalWithTestEdgeRules(pInterface)
+ .createEdgeTraversal(EdgeType.TREE, loader.introspectorFromName("p-interface"),
+ loader.introspectorFromName("l-interface"))
+ .createEdgeTraversal(EdgeType.COUSIN, loader.introspectorFromName("l-interface"),
+ loader.introspectorFromName("logical-link"))
+ .path();
Path path = tQ.next();
assertThat(path.objects(), contains(pInterface, lInterface, logicalLink));
@@ -189,8 +183,8 @@ public abstract class QueryBuilderTestAbstraction {
@SuppressWarnings("rawtypes")
@Test
public void parentVertexTest() throws AAIException {
- Vertex pInterface = g.addV("aai-node-type","p-interface","interface-name","p-interface-a").next();
- Vertex lInterface = g.addV("aai-node-type","l-interface","interface-name","l-interface-a").next();
+ Vertex pInterface = g.addV("aai-node-type", "p-interface", "interface-name", "p-interface-a").next();
+ Vertex lInterface = g.addV("aai-node-type", "l-interface", "interface-name", "l-interface-a").next();
testEdgeSer.addTreeEdge(g, pInterface, lInterface);
@@ -200,29 +194,28 @@ public abstract class QueryBuilderTestAbstraction {
assertThat(parent, is(pInterface));
}
-
@Test
public void createEdgeLinterfaceToLogicalLinkIntrospectorTraversal() throws AAIException {
- Vertex lInterface = g.addV("aai-node-type","l-interface","interface-name","l-interface-a").next();
- Vertex logicalLink = g.addV("aai-node-type","logical-link","link-name","logical-link-a").next();
+ Vertex lInterface = g.addV("aai-node-type", "l-interface", "interface-name", "l-interface-a").next();
+ Vertex logicalLink = g.addV("aai-node-type", "logical-link", "link-name", "logical-link-a").next();
testEdgeSer.addEdge(g, lInterface, logicalLink, "sourceLInterface");
QueryBuilder<Vertex> tQ = getNewVertexTraversalWithTestEdgeRules(lInterface);
- tQ.createEdgeTraversal(EdgeType.COUSIN, loader.introspectorFromName("l-interface"), loader.introspectorFromName("logical-link"));
+ tQ.createEdgeTraversal(EdgeType.COUSIN, loader.introspectorFromName("l-interface"),
+ loader.introspectorFromName("logical-link"));
Vertex next = tQ.next();
assertEquals(logicalLink, next);
-
}
@Test
public void createEdgeLinterfaceToLogicalLinkVertexToIntrospectorTraversal() throws AAIException {
- Vertex lInterface = g.addV("aai-node-type","l-interface","interface-name","l-interface-a").next();
- Vertex logicalLink = g.addV("aai-node-type","logical-link","link-name","logical-link-a").next();
+ Vertex lInterface = g.addV("aai-node-type", "l-interface", "interface-name", "l-interface-a").next();
+ Vertex logicalLink = g.addV("aai-node-type", "logical-link", "link-name", "logical-link-a").next();
testEdgeSer.addEdge(g, lInterface, logicalLink, "sourceLInterface");
QueryBuilder<Vertex> tQ = getNewVertexTraversalWithTestEdgeRules(lInterface);
@@ -232,14 +225,13 @@ public abstract class QueryBuilderTestAbstraction {
assertEquals(logicalLink, next);
-
}
@Test
public void edgeToVertexTraversalTest() throws AAIException {
- Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
- Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
+ Vertex gvnf = g.addV("aai-node-type", "generic-vnf", "vnf-id", "gvnf").next();
+ Vertex vnfc1 = g.addV("aai-node-type", "vnfc", "vnfc-name", "a-name").next();
testEdgeSer.addEdge(g, gvnf, vnfc1);
@@ -251,14 +243,13 @@ public abstract class QueryBuilderTestAbstraction {
assertEquals("Has 1 vertexes ", 1, list.size());
assertTrue("Has vertex on the default edge ", list.contains(vnfc1));
-
}
@Test
public void edgeToVertexTraversalSingleOutRuleTest() throws AAIException {
- Vertex vce = g.addV("aai-node-type","vce","vnf-id","vce").next();
- Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
+ Vertex vce = g.addV("aai-node-type", "vce", "vnf-id", "vce").next();
+ Vertex vnfc1 = g.addV("aai-node-type", "vnfc", "vnfc-name", "a-name").next();
testEdgeSer.addEdge(g, vce, vnfc1);
@@ -276,14 +267,13 @@ public abstract class QueryBuilderTestAbstraction {
assertEquals("2 - Has 1 vertexes ", 1, list2.size());
assertTrue("2 - traversal results in vce ", list2.contains(vce));
-
}
@Test
public void edgeToVertexTraversalSingleInRuleTest() throws AAIException {
- Vertex vce = g.addV("aai-node-type","vce","vnf-id","vce").next();
- Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+ Vertex vce = g.addV("aai-node-type", "vce", "vnf-id", "vce").next();
+ Vertex pserver = g.addV("aai-node-type", "pserver", "hostname", "a-name").next();
testEdgeSer.addEdge(g, vce, pserver);
@@ -295,15 +285,14 @@ public abstract class QueryBuilderTestAbstraction {
assertEquals("1 - Has 1 vertexes ", 1, list.size());
assertTrue("1 - traversal results in vnfc ", list.contains(pserver));
-
}
@Test
public void edgeToVertexMultiRuleTraversalTest() throws AAIException {
- Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
- Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
- Vertex vnfc2 = g.addV("aai-node-type","vnfc","vnfc-name","b-name").next();
+ Vertex gvnf = g.addV("aai-node-type", "generic-vnf", "vnf-id", "gvnf").next();
+ Vertex vnfc1 = g.addV("aai-node-type", "vnfc", "vnfc-name", "a-name").next();
+ Vertex vnfc2 = g.addV("aai-node-type", "vnfc", "vnfc-name", "b-name").next();
testEdgeSer.addEdge(g, gvnf, vnfc1);
testEdgeSer.addEdge(g, gvnf, vnfc2, "re-uses");
@@ -317,15 +306,14 @@ public abstract class QueryBuilderTestAbstraction {
assertTrue("Has vertex on the default edge ", list.contains(vnfc1));
assertTrue("Has vertex on the re-uses edge ", list.contains(vnfc2));
-
}
@Test
public void edgeToVertexMultiLabelTest() throws AAIException {
- Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
- Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
- Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
+ Vertex gvnf = g.addV("aai-node-type", "generic-vnf", "vnf-id", "gvnf").next();
+ Vertex pserver = g.addV("aai-node-type", "pserver", "hostname", "a-name").next();
+ Vertex vnfc1 = g.addV("aai-node-type", "vnfc", "vnfc-name", "a-name").next();
testEdgeSer.addEdge(g, gvnf, vnfc1);
testEdgeSer.addEdge(g, pserver, vnfc1);
@@ -338,30 +326,28 @@ public abstract class QueryBuilderTestAbstraction {
assertEquals("Has 1 vertexes ", 1, list.size());
assertTrue("Only returns the generic vnf vertex", list.contains(gvnf));
-
}
@Test
public void limitTraversalTest() throws AAIException {
- g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
- g.addV("aai-node-type","vnfc","vnfc-name","b-name").next();
+ g.addV("aai-node-type", "vnfc", "vnfc-name", "a-name").next();
+ g.addV("aai-node-type", "vnfc", "vnfc-name", "b-name").next();
QueryBuilder<Vertex> tQ = new GremlinTraversal<>(loader, g);
- tQ.getVerticesByProperty("aai-node-type","vnfc").limit(1);
+ tQ.getVerticesByProperty("aai-node-type", "vnfc").limit(1);
List<Vertex> list = tQ.toList();
assertEquals("Has 1 vertexes ", 1, list.size());
-
}
@Test
public void getVertexesByPropertiesTraversalTest() throws AAIException {
- g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
- g.addV("aai-node-type","vnfc","vnfc-name","b-name").next();
+ g.addV("aai-node-type", "vnfc", "vnfc-name", "a-name").next();
+ g.addV("aai-node-type", "vnfc", "vnfc-name", "b-name").next();
QueryBuilder<Vertex> tQ = new GremlinTraversal<>(loader, g);
tQ.getVerticesByProperty("vnfc-name", Arrays.asList("a-name", "b-name"));
@@ -370,30 +356,28 @@ public abstract class QueryBuilderTestAbstraction {
assertEquals("Has 2 vertexes ", 2, list.size());
-
}
@Test
public void getVertexesByIndexedPropertyTraversalTest() throws AAIException {
- g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
- g.addV("aai-node-type","vnfc","vnfc-name","b-name").next();
+ g.addV("aai-node-type", "vnfc", "vnfc-name", "a-name").next();
+ g.addV("aai-node-type", "vnfc", "vnfc-name", "b-name").next();
QueryBuilder<Vertex> tQ = new GremlinTraversal<>(loader, g);
- tQ.getVerticesByIndexedProperty("aai-node-type","vnfc");
+ tQ.getVerticesByIndexedProperty("aai-node-type", "vnfc");
List<Vertex> list = tQ.toList();
assertEquals("Has 2 vertexes ", 2, list.size());
-
}
@Test
public void dedupTraversalTest() throws AAIException {
- Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
- Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+ Vertex gvnf = g.addV("aai-node-type", "generic-vnf", "vnf-id", "gvnf").next();
+ Vertex pserver = g.addV("aai-node-type", "pserver", "hostname", "a-name").next();
testEdgeSer.addEdge(g, gvnf, pserver);
testEdgeSer.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
@@ -406,14 +390,13 @@ public abstract class QueryBuilderTestAbstraction {
assertEquals("Has 2 vertexes ", 1, list.size());
assertTrue("result has pserver ", list.contains(pserver));
-
}
@Test
public void storeCapTraversalTest() throws AAIException {
- Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
- Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+ Vertex gvnf = g.addV("aai-node-type", "generic-vnf", "vnf-id", "gvnf").next();
+ Vertex pserver = g.addV("aai-node-type", "pserver", "hostname", "a-name").next();
testEdgeSer.addEdge(g, gvnf, pserver);
testEdgeSer.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
@@ -424,16 +407,15 @@ public abstract class QueryBuilderTestAbstraction {
List<BulkSet<Vertex>> list = tQ.toList();
assertEquals("Has 2 vertexes ", 1, list.size());
- assertEquals("result has pserver ",pserver, list.get(0).iterator().next());
-
+ assertEquals("result has pserver ", pserver, list.get(0).iterator().next());
}
@Test
public void storeCapUnfoldTraversalTest() throws AAIException {
- Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
- Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+ Vertex gvnf = g.addV("aai-node-type", "generic-vnf", "vnf-id", "gvnf").next();
+ Vertex pserver = g.addV("aai-node-type", "pserver", "hostname", "a-name").next();
testEdgeSer.addEdge(g, gvnf, pserver);
testEdgeSer.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
@@ -446,25 +428,24 @@ public abstract class QueryBuilderTestAbstraction {
assertEquals("Has 2 vertexes ", 2, list.size());
assertTrue("result has pserver ", list.contains(pserver));
-
}
@Test
public void nextAndHasNextTraversalTest() throws AAIException {
- Vertex v1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
- Vertex v2 = g.addV("aai-node-type","vnfc","vnfc-name","b-name").next();
+ Vertex v1 = g.addV("aai-node-type", "vnfc", "vnfc-name", "a-name").next();
+ Vertex v2 = g.addV("aai-node-type", "vnfc", "vnfc-name", "b-name").next();
QueryBuilder<Vertex> tQ = new GremlinTraversal<>(loader, g);
- tQ.getVerticesByProperty("aai-node-type","vnfc");
+ tQ.getVerticesByProperty("aai-node-type", "vnfc");
List<Vertex> list = new ArrayList<>();
- assertTrue("Has next 1 ",tQ.hasNext());
+ assertTrue("Has next 1 ", tQ.hasNext());
list.add(tQ.next());
- assertTrue("Has next 2 ",tQ.hasNext());
+ assertTrue("Has next 2 ", tQ.hasNext());
list.add(tQ.next());
- assertFalse("Has next 3 ",tQ.hasNext());
+ assertFalse("Has next 3 ", tQ.hasNext());
assertTrue("Has all the vertexes", list.contains(v1) && list.remove(v2));
}
@@ -472,8 +453,8 @@ public abstract class QueryBuilderTestAbstraction {
@Test
public void edgeToVertexMultiRuleOutTraversalTest() throws AAIException {
- Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
- Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+ Vertex gvnf = g.addV("aai-node-type", "generic-vnf", "vnf-id", "gvnf").next();
+ Vertex pserver = g.addV("aai-node-type", "pserver", "hostname", "a-name").next();
testEdgeSer.addEdge(g, gvnf, pserver);
testEdgeSer.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
@@ -486,14 +467,13 @@ public abstract class QueryBuilderTestAbstraction {
assertEquals("Has 2 vertexes ", 2, list.size());
assertTrue("result has pserver ", list.contains(pserver));
-
}
@Test
public void edgeToVertexMultiRuleInTraversalTest() throws AAIException {
- Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
- Vertex complex = g.addV("aai-node-type","complex","physical-location-id","a-name").next();
+ Vertex gvnf = g.addV("aai-node-type", "generic-vnf", "vnf-id", "gvnf").next();
+ Vertex complex = g.addV("aai-node-type", "complex", "physical-location-id", "a-name").next();
testEdgeSer.addEdge(g, gvnf, complex);
testEdgeSer.addEdge(g, gvnf, complex, "complex-generic-vnf-B");
@@ -506,14 +486,13 @@ public abstract class QueryBuilderTestAbstraction {
assertEquals("Has 2 vertexes ", 2, list.size());
assertTrue("result has pserver ", list.contains(complex));
-
}
@Test
public void edgeTraversalSingleInRuleTest() throws AAIException {
- Vertex vce = g.addV("aai-node-type","vce","vnf-id","vce").next();
- Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+ Vertex vce = g.addV("aai-node-type", "vce", "vnf-id", "vce").next();
+ Vertex pserver = g.addV("aai-node-type", "pserver", "hostname", "a-name").next();
Edge e = testEdgeSer.addEdge(g, vce, pserver);
@@ -525,14 +504,13 @@ public abstract class QueryBuilderTestAbstraction {
assertEquals("1 - Has 1 edge ", 1, list.size());
assertTrue("1 - traversal results in edge ", list.contains(e));
-
}
@Test
public void edgeTraversalSingleOutRuleTest() throws AAIException {
- Vertex vce = g.addV("aai-node-type","vce","vnf-id","vce").next();
- Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
+ Vertex vce = g.addV("aai-node-type", "vce", "vnf-id", "vce").next();
+ Vertex vnfc1 = g.addV("aai-node-type", "vnfc", "vnfc-name", "a-name").next();
Edge e = testEdgeSer.addEdge(g, vce, vnfc1);
@@ -544,14 +522,13 @@ public abstract class QueryBuilderTestAbstraction {
assertEquals("1 - Has 1 edge ", 1, list1.size());
assertTrue("1 - traversal results in edge ", list1.contains(e));
-
}
@Test
public void edgeTraversalMultiRuleOutTraversalTest() throws AAIException {
- Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
- Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+ Vertex gvnf = g.addV("aai-node-type", "generic-vnf", "vnf-id", "gvnf").next();
+ Vertex pserver = g.addV("aai-node-type", "pserver", "hostname", "a-name").next();
Edge e1 = testEdgeSer.addEdge(g, gvnf, pserver);
Edge e2 = testEdgeSer.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
@@ -565,14 +542,13 @@ public abstract class QueryBuilderTestAbstraction {
assertTrue("result has default edge ", list.contains(e1));
assertTrue("result has other edge ", list.contains(e2));
-
}
@Test
public void edgeTraversalMultiRuleInTraversalTest() throws AAIException {
- Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
- Vertex complex = g.addV("aai-node-type","complex","physical-location-id","a-name").next();
+ Vertex gvnf = g.addV("aai-node-type", "generic-vnf", "vnf-id", "gvnf").next();
+ Vertex complex = g.addV("aai-node-type", "complex", "physical-location-id", "a-name").next();
Edge e1 = testEdgeSer.addEdge(g, gvnf, complex);
Edge e2 = testEdgeSer.addEdge(g, gvnf, complex, "complex-generic-vnf-B");
@@ -586,15 +562,14 @@ public abstract class QueryBuilderTestAbstraction {
assertTrue("result has default edge ", list.contains(e1));
assertTrue("result has other edge ", list.contains(e2));
-
}
@Test
public void edgeTraversalMultiRuleTraversalTest() throws AAIException {
- Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
- Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
- Vertex vnfc2 = g.addV("aai-node-type","vnfc","vnfc-name","b-name").next();
+ Vertex gvnf = g.addV("aai-node-type", "generic-vnf", "vnf-id", "gvnf").next();
+ Vertex vnfc1 = g.addV("aai-node-type", "vnfc", "vnfc-name", "a-name").next();
+ Vertex vnfc2 = g.addV("aai-node-type", "vnfc", "vnfc-name", "b-name").next();
Edge e1 = testEdgeSer.addEdge(g, gvnf, vnfc1);
Edge e2 = testEdgeSer.addEdge(g, gvnf, vnfc2, "re-uses");
@@ -608,15 +583,14 @@ public abstract class QueryBuilderTestAbstraction {
assertTrue("result has default edge ", list.contains(e1));
assertTrue("result has other edge ", list.contains(e2));
-
}
@Ignore("This test is failing for TraversalQueryTest and Optimized but it passes for GremlinQueryTest")
- @Test (expected = NoEdgeRuleFoundException.class)
+ @Test(expected = NoEdgeRuleFoundException.class)
public void getEdgesBetweenWithLabelsEmptyListTest() throws AAIException {
- Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
- Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+ Vertex gvnf = g.addV("aai-node-type", "generic-vnf", "vnf-id", "gvnf").next();
+ Vertex pserver = g.addV("aai-node-type", "pserver", "hostname", "a-name").next();
testEdgeSer.addEdge(g, gvnf, pserver);
testEdgeSer.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
@@ -629,14 +603,15 @@ public abstract class QueryBuilderTestAbstraction {
@Test
public void getEdgesBetweenWithLabelsSingleItemTest() throws AAIException {
- Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
- Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+ Vertex gvnf = g.addV("aai-node-type", "generic-vnf", "vnf-id", "gvnf").next();
+ Vertex pserver = g.addV("aai-node-type", "pserver", "hostname", "a-name").next();
Edge e1 = testEdgeSer.addEdge(g, gvnf, pserver);
Edge e2 = testEdgeSer.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
QueryBuilder<Edge> tQ = getNewEdgeTraversalWithTestEdgeRules(gvnf);
- tQ.getEdgesBetweenWithLabels(EdgeType.COUSIN, "generic-vnf", "pserver", Collections.singletonList("generic-vnf-pserver-B"));
+ tQ.getEdgesBetweenWithLabels(EdgeType.COUSIN, "generic-vnf", "pserver",
+ Collections.singletonList("generic-vnf-pserver-B"));
List<Edge> list = tQ.toList();
@@ -649,14 +624,15 @@ public abstract class QueryBuilderTestAbstraction {
@Test
public void getEdgesBetweenWithLabelsMultipleItemTest() throws AAIException {
- Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
- Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+ Vertex gvnf = g.addV("aai-node-type", "generic-vnf", "vnf-id", "gvnf").next();
+ Vertex pserver = g.addV("aai-node-type", "pserver", "hostname", "a-name").next();
Edge e1 = testEdgeSer.addEdge(g, gvnf, pserver);
Edge e2 = testEdgeSer.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
QueryBuilder<Edge> tQ = getNewEdgeTraversalWithTestEdgeRules(gvnf);
- tQ.getEdgesBetweenWithLabels(EdgeType.COUSIN, "generic-vnf", "pserver", Arrays.asList("generic-vnf-pserver-B", "generic-vnf-pserver-A"));
+ tQ.getEdgesBetweenWithLabels(EdgeType.COUSIN, "generic-vnf", "pserver",
+ Arrays.asList("generic-vnf-pserver-B", "generic-vnf-pserver-A"));
List<Edge> list = tQ.toList();
@@ -667,7 +643,7 @@ public abstract class QueryBuilderTestAbstraction {
}
@Ignore("This test is failing for TraversalQueryTest and Optimized but it passes for GremlinQueryTest")
- @Test (expected = NoEdgeRuleFoundException.class)
+ @Test(expected = NoEdgeRuleFoundException.class)
public void createEdgeTraversalWithLabelsEmptyListTest() throws AAIException {
Vertex gvnf = getVertex();
@@ -677,12 +653,11 @@ public abstract class QueryBuilderTestAbstraction {
tQ.toList();
-
}
private Vertex getVertex() throws AAIException {
- Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
- Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+ Vertex gvnf = g.addV("aai-node-type", "generic-vnf", "vnf-id", "gvnf").next();
+ Vertex pserver = g.addV("aai-node-type", "pserver", "hostname", "a-name").next();
testEdgeSer.addEdge(g, gvnf, pserver);
testEdgeSer.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
@@ -692,14 +667,15 @@ public abstract class QueryBuilderTestAbstraction {
@Test
public void createEdgeTraversalWithLabelsSingleItemTest() throws AAIException {
- Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
- Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+ Vertex gvnf = g.addV("aai-node-type", "generic-vnf", "vnf-id", "gvnf").next();
+ Vertex pserver = g.addV("aai-node-type", "pserver", "hostname", "a-name").next();
Edge e1 = testEdgeSer.addEdge(g, gvnf, pserver);
Edge e2 = testEdgeSer.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
QueryBuilder<Edge> tQ = getNewEdgeTraversalWithTestEdgeRules(gvnf);
- tQ.getEdgesBetweenWithLabels(EdgeType.COUSIN, "generic-vnf", "pserver", Collections.singletonList("generic-vnf-pserver-B"));
+ tQ.getEdgesBetweenWithLabels(EdgeType.COUSIN, "generic-vnf", "pserver",
+ Collections.singletonList("generic-vnf-pserver-B"));
List<Edge> list = tQ.toList();
@@ -712,14 +688,15 @@ public abstract class QueryBuilderTestAbstraction {
@Test
public void createEdgeTraversalWithLabelsMultipleItemTest() throws AAIException {
- Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
- Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
+ Vertex gvnf = g.addV("aai-node-type", "generic-vnf", "vnf-id", "gvnf").next();
+ Vertex pserver = g.addV("aai-node-type", "pserver", "hostname", "a-name").next();
Edge e1 = testEdgeSer.addEdge(g, gvnf, pserver);
Edge e2 = testEdgeSer.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
QueryBuilder<Edge> tQ = getNewEdgeTraversalWithTestEdgeRules(gvnf);
- tQ.getEdgesBetweenWithLabels(EdgeType.COUSIN, "generic-vnf", "pserver", Arrays.asList("generic-vnf-pserver-B", "generic-vnf-pserver-A"));
+ tQ.getEdgesBetweenWithLabels(EdgeType.COUSIN, "generic-vnf", "pserver",
+ Arrays.asList("generic-vnf-pserver-B", "generic-vnf-pserver-A"));
List<Edge> list = tQ.toList();
diff --git a/aai-core/src/test/java/org/onap/aai/query/builder/QueryTestsConfigTranslator.java b/aai-core/src/test/java/org/onap/aai/query/builder/QueryTestsConfigTranslator.java
index 84c4bdd1..3661f3de 100644
--- a/aai-core/src/test/java/org/onap/aai/query/builder/QueryTestsConfigTranslator.java
+++ b/aai-core/src/test/java/org/onap/aai/query/builder/QueryTestsConfigTranslator.java
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.query.builder;
import java.util.*;
@@ -37,9 +38,10 @@ public class QueryTestsConfigTranslator extends AbstractConfigTranslator {
public QueryTestsConfigTranslator(SchemaLocationsBean bean, SchemaConfigVersions schemaVersions) {
super(bean, schemaVersions);
}
-
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see org.onap.aai.setup.ConfigTranslator#getEdgeFiles()
*/
@Override
diff --git a/aai-core/src/test/java/org/onap/aai/query/builder/SimplePathTest.java b/aai-core/src/test/java/org/onap/aai/query/builder/SimplePathTest.java
index 0a987c95..1929f4ea 100644
--- a/aai-core/src/test/java/org/onap/aai/query/builder/SimplePathTest.java
+++ b/aai-core/src/test/java/org/onap/aai/query/builder/SimplePathTest.java
@@ -17,8 +17,13 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.query.builder;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.T;
@@ -31,23 +36,18 @@ import org.onap.aai.edges.enums.EdgeType;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.Loader;
import org.onap.aai.introspection.ModelType;
-
import org.onap.aai.serialization.db.EdgeSerializer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
-import java.util.List;
-
-import static org.junit.Assert.assertTrue;
-
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class SimplePathTest extends AAISetup {
public Loader loader;
-
+
@Autowired
EdgeSerializer edgeSer;
-
+
@Before
public void setup() throws Exception {
loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
@@ -56,52 +56,52 @@ public class SimplePathTest extends AAISetup {
private QueryBuilder<Vertex> buildTestQuery(QueryBuilder<Vertex> qb) throws AAIException {
return qb.createEdgeTraversal(EdgeType.TREE, "generic-vnf", "l-interface")
.until(qb.newInstance().getVerticesByProperty("aai-node-type", "generic-vnf"))
- .repeat(qb.newInstance().union(
- qb.newInstance().createEdgeTraversal(EdgeType.TREE, "generic-vnf", "l-interface"),
- qb.newInstance().createEdgeTraversal(EdgeType.TREE, "l-interface", "generic-vnf"),
- qb.newInstance().createEdgeTraversal(EdgeType.COUSIN, "l-interface", "logical-link"),
- qb.newInstance().createEdgeTraversal(EdgeType.COUSIN, "logical-link", "l-interface")
- ).simplePath())
+ .repeat(qb.newInstance()
+ .union(qb.newInstance().createEdgeTraversal(EdgeType.TREE, "generic-vnf", "l-interface"),
+ qb.newInstance().createEdgeTraversal(EdgeType.TREE, "l-interface", "generic-vnf"),
+ qb.newInstance().createEdgeTraversal(EdgeType.COUSIN, "l-interface", "logical-link"),
+ qb.newInstance().createEdgeTraversal(EdgeType.COUSIN, "logical-link", "l-interface"))
+ .simplePath())
.store("x").cap("x").unfold().dedup();
}
-
- private GraphTraversalSource setupGraph() throws AAIException{
+
+ private GraphTraversalSource setupGraph() throws AAIException {
Graph graph = TinkerGraph.open();
GraphTraversalSource g = graph.traversal();
-
- Vertex gvnf1 = graph.addVertex(T.label, "generic-vnf", T.id, "00", "aai-node-type", "generic-vnf",
- "vnf-id", "gvnf1", "vnf-name", "genvnfname1", "nf-type", "sample-nf-type");
+
+ Vertex gvnf1 = graph.addVertex(T.label, "generic-vnf", T.id, "00", "aai-node-type", "generic-vnf", "vnf-id",
+ "gvnf1", "vnf-name", "genvnfname1", "nf-type", "sample-nf-type");
Vertex lint1 = graph.addVertex(T.label, "l-interface", T.id, "10", "aai-node-type", "l-interface",
- "interface-name", "lint1", "is-port-mirrored", "true", "in-maint", "true", "is-ip-unnumbered", "false");
-
+ "interface-name", "lint1", "is-port-mirrored", "true", "in-maint", "true", "is-ip-unnumbered", "false");
+
Vertex loglink1 = graph.addVertex(T.label, "logical-link", T.id, "20", "aai-node-type", "logical-link",
- "link-name", "loglink1", "in-maint", "false", "link-type", "sausage");
-
+ "link-name", "loglink1", "in-maint", "false", "link-type", "sausage");
+
Vertex lint2 = graph.addVertex(T.label, "l-interface", T.id, "11", "aai-node-type", "l-interface",
- "interface-name", "lint2", "is-port-mirrored", "true", "in-maint", "true", "is-ip-unnumbered", "false");
-
+ "interface-name", "lint2", "is-port-mirrored", "true", "in-maint", "true", "is-ip-unnumbered", "false");
+
Vertex lint3 = graph.addVertex(T.label, "l-interface", T.id, "12", "aai-node-type", "l-interface",
"interface-name", "lint3", "is-port-mirrored", "true", "in-maint", "true", "is-ip-unnumbered", "false");
-
- Vertex gvnf2 = graph.addVertex(T.label, "generic-vnf", T.id, "01", "aai-node-type", "generic-vnf",
- "vnf-id", "gvnf2", "vnf-name", "genvnfname2", "nf-type", "sample-nf-type");
-
+
+ Vertex gvnf2 = graph.addVertex(T.label, "generic-vnf", T.id, "01", "aai-node-type", "generic-vnf", "vnf-id",
+ "gvnf2", "vnf-name", "genvnfname2", "nf-type", "sample-nf-type");
+
edgeSer.addTreeEdge(g, gvnf1, lint1);
edgeSer.addEdge(g, lint1, loglink1);
edgeSer.addEdge(g, loglink1, lint2);
edgeSer.addEdge(g, loglink1, lint3);
edgeSer.addTreeEdge(g, gvnf2, lint3);
-
+
return g;
}
-
+
@Test
public void gremlinQueryTest() throws AAIException {
GraphTraversalSource g = setupGraph();
List<Vertex> expected = g.V("01").toList();
Vertex start = g.V("00").toList().get(0);
-
+
GremlinTraversal<Vertex> qb = new GremlinTraversal<>(loader, g, start);
QueryBuilder<Vertex> q = buildTestQuery(qb);
List<Vertex> results = q.toList();
@@ -113,7 +113,7 @@ public class SimplePathTest extends AAISetup {
GraphTraversalSource g = setupGraph();
List<Vertex> expected = g.V("01").toList();
Vertex start = g.V("00").toList().get(0);
-
+
TraversalQuery<Vertex> qb = new TraversalQuery<>(loader, g, start);
QueryBuilder<Vertex> q = buildTestQuery(qb);
List<Vertex> results = q.toList();
diff --git a/aai-core/src/test/java/org/onap/aai/query/builder/TraversalQueryTest.java b/aai-core/src/test/java/org/onap/aai/query/builder/TraversalQueryTest.java
index f82166bf..eb1e57c3 100644
--- a/aai-core/src/test/java/org/onap/aai/query/builder/TraversalQueryTest.java
+++ b/aai-core/src/test/java/org/onap/aai/query/builder/TraversalQueryTest.java
@@ -17,8 +17,17 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.query.builder;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
+
import org.apache.tinkerpop.gremlin.process.traversal.Path;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
@@ -28,44 +37,35 @@ import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.junit.Ignore;
import org.junit.Test;
import org.onap.aai.db.props.AAIProperties;
-import org.onap.aai.exceptions.AAIException;
import org.onap.aai.edges.enums.EdgeType;
+import org.onap.aai.exceptions.AAIException;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
public class TraversalQueryTest extends QueryBuilderTestAbstraction {
-
@Override
protected QueryBuilder<Edge> getNewEdgeTraversalWithTestEdgeRules(Vertex v) {
return new TraversalQuery<>(loader, g, v);
}
-
+
@Override
protected QueryBuilder<Edge> getNewEdgeTraversalWithTestEdgeRules() {
return new TraversalQuery<>(loader, g);
}
-
+
@Override
protected QueryBuilder<Vertex> getNewVertexTraversalWithTestEdgeRules(Vertex v) {
return new TraversalQuery<>(loader, g, v);
}
-
+
@Override
protected QueryBuilder<Vertex> getNewVertexTraversalWithTestEdgeRules() {
return new TraversalQuery<>(loader, g);
}
-
protected QueryBuilder<Vertex> getNewVertexTraversal() {
return new TraversalQuery<>(loader, g);
}
-
+
@Override
protected QueryBuilder<Tree> getNewTreeTraversalWithTestEdgeRules(Vertex v) {
return new TraversalQuery<>(loader, g, v);
@@ -85,34 +85,33 @@ public class TraversalQueryTest extends QueryBuilderTestAbstraction {
protected QueryBuilder<Path> getNewPathTraversalWithTestEdgeRules() {
return new TraversalQuery<>(loader, g);
}
-
+
@Test
public void unionQuery() {
QueryBuilder<Vertex> tQ = getNewVertexTraversal();
QueryBuilder<Vertex> tQ2 = getNewVertexTraversal();
QueryBuilder<Vertex> tQ3 = getNewVertexTraversal();
- tQ.union(
- tQ2.getVerticesByProperty("test1", "value1"),
- tQ3.getVerticesByIndexedProperty("test2", "value2"));
+ tQ.union(tQ2.getVerticesByProperty("test1", "value1"), tQ3.getVerticesByIndexedProperty("test2", "value2"));
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
- .union(__.has("test1", "value1"),__.has("test2", "value2"));
+ GraphTraversal<Vertex, Vertex> expected =
+ __.<Vertex>start().union(__.has("test1", "value1"), __.has("test2", "value2"));
assertEquals("they are equal", expected, tQ.getQuery());
-
}
@Test
public void traversalClones() throws UnsupportedEncodingException, AAIException, URISyntaxException {
QueryBuilder<Vertex> tQ = getNewVertexTraversal();
- QueryBuilder<Vertex> builder = tQ.createQueryFromURI(new URI("network/generic-vnfs/generic-vnf/key1")).getQueryBuilder();
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "generic-vnf");
+ QueryBuilder<Vertex> builder =
+ tQ.createQueryFromURI(new URI("network/generic-vnfs/generic-vnf/key1")).getQueryBuilder();
+ GraphTraversal<Vertex, Vertex> expected =
+ __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "generic-vnf");
GraphTraversal<Vertex, Vertex> containerExpected = __.<Vertex>start().has("aai-node-type", "generic-vnf");
assertEquals("query object", expected.toString(), builder.getQuery().toString());
- assertEquals("container query object", containerExpected.toString(), builder.getContainerQuery().getQuery().toString());
-
+ assertEquals("container query object", containerExpected.toString(),
+ builder.getContainerQuery().getQuery().toString());
}
@@ -123,149 +122,139 @@ public class TraversalQueryTest extends QueryBuilderTestAbstraction {
public void nestedTraversalClones() throws UnsupportedEncodingException, AAIException, URISyntaxException {
QueryBuilder<Vertex> tQ = getNewVertexTraversal();
- QueryBuilder<Vertex> builder = tQ.createQueryFromURI(new URI("network/generic-vnfs/generic-vnf/key1/l-interfaces/l-interface/key2")).getQueryBuilder();
- GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start()
- .has("vnf-id", "key1")
- .has("aai-node-type", "generic-vnf")
- .in("org.onap.relationships.inventory.BelongsTo").has(AAIProperties.NODE_TYPE, "l-interface")
- .has("interface-name", "key2");
- GraphTraversal<Vertex, Vertex> containerExpected = __.<Vertex>start()
- .has("vnf-id", "key1")
- .has("aai-node-type", "generic-vnf")
- .in("org.onap.relationships.inventory.BelongsTo")
- .has(AAIProperties.NODE_TYPE, "l-interface");
-
+ QueryBuilder<Vertex> builder =
+ tQ.createQueryFromURI(new URI("network/generic-vnfs/generic-vnf/key1/l-interfaces/l-interface/key2"))
+ .getQueryBuilder();
+ GraphTraversal<Vertex, Vertex> expected = __.<Vertex>start().has("vnf-id", "key1")
+ .has("aai-node-type", "generic-vnf").in("org.onap.relationships.inventory.BelongsTo")
+ .has(AAIProperties.NODE_TYPE, "l-interface").has("interface-name", "key2");
+ GraphTraversal<Vertex, Vertex> containerExpected =
+ __.<Vertex>start().has("vnf-id", "key1").has("aai-node-type", "generic-vnf")
+ .in("org.onap.relationships.inventory.BelongsTo").has(AAIProperties.NODE_TYPE, "l-interface");
+
assertEquals("query object", expected.toString(), builder.getQuery().toString());
- assertEquals("container query object", containerExpected.toString(), builder.getContainerQuery().getQuery().toString());
-
+ assertEquals("container query object", containerExpected.toString(),
+ builder.getContainerQuery().getQuery().toString());
}
-
+
@Test
public void abstractEdgeToVertexTraversalTest() throws AAIException {
-
- Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
- Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
-
+
+ Vertex gvnf = g.addV("aai-node-type", "generic-vnf", "vnf-id", "gvnf").next();
+ Vertex vnfc1 = g.addV("aai-node-type", "vnfc", "vnfc-name", "a-name").next();
+
testEdgeSer.addEdge(g, gvnf, vnfc1);
-
+
QueryBuilder<Vertex> tQ = getNewVertexTraversalWithTestEdgeRules(gvnf);
tQ.createEdgeTraversal(EdgeType.COUSIN, "vnf", "vnfc");
-
+
List<Vertex> list = tQ.toList();
assertEquals("Has 1 vertexes ", 1, list.size());
assertTrue("Has vertex on the default edge ", list.contains(vnfc1));
-
}
-
+
@Test
public void abstractEdgeToVertexTraversalSingleOutRuleTest() throws AAIException {
-
- Vertex vce = g.addV("aai-node-type","vce","vnf-id","vce").next();
- Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
-
+
+ Vertex vce = g.addV("aai-node-type", "vce", "vnf-id", "vce").next();
+ Vertex vnfc1 = g.addV("aai-node-type", "vnfc", "vnfc-name", "a-name").next();
+
testEdgeSer.addEdge(g, vce, vnfc1);
-
+
QueryBuilder<Vertex> tQ1 = getNewVertexTraversalWithTestEdgeRules(vce);
tQ1.createEdgeTraversal(EdgeType.COUSIN, "vnf", "vnfc");
-
+
QueryBuilder<Vertex> tQ2 = getNewVertexTraversalWithTestEdgeRules(vnfc1);
tQ2.createEdgeTraversal(EdgeType.COUSIN, "vnfc", "vnf");
-
+
List<Vertex> list1 = tQ1.toList();
List<Vertex> list2 = tQ2.toList();
-
+
assertEquals("1 - Has 1 vertexes ", 1, list1.size());
assertTrue("1 - traversal results in vnfc ", list1.contains(vnfc1));
assertEquals("2 - Has 1 vertexes ", 1, list2.size());
assertTrue("2 - traversal results in vce ", list2.contains(vce));
-
}
-
+
@Test
public void abstractEdgeToVertexTraversalSingleInRuleTest() throws AAIException {
-
- Vertex vce = g.addV("aai-node-type","vce","vnf-id","vce").next();
- Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
-
+
+ Vertex vce = g.addV("aai-node-type", "vce", "vnf-id", "vce").next();
+ Vertex pserver = g.addV("aai-node-type", "pserver", "hostname", "a-name").next();
+
testEdgeSer.addEdge(g, vce, pserver);
-
+
QueryBuilder<Vertex> tQ1 = getNewVertexTraversalWithTestEdgeRules(vce);
tQ1.createEdgeTraversal(EdgeType.COUSIN, "vnf", "pserver");
-
+
List<Vertex> list = tQ1.toList();
assertEquals("1 - Has 1 vertexes ", 1, list.size());
assertTrue("1 - traversal results in vnfc ", list.contains(pserver));
-
}
-
+
@Test
public void abstractEdgeToVertexMultiRuleTraversalTest() throws AAIException {
-
- Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
- Vertex vnfc1 = g.addV("aai-node-type","vnfc","vnfc-name","a-name").next();
- Vertex vnfc2 = g.addV("aai-node-type","vnfc","vnfc-name","b-name").next();
-
+
+ Vertex gvnf = g.addV("aai-node-type", "generic-vnf", "vnf-id", "gvnf").next();
+ Vertex vnfc1 = g.addV("aai-node-type", "vnfc", "vnfc-name", "a-name").next();
+ Vertex vnfc2 = g.addV("aai-node-type", "vnfc", "vnfc-name", "b-name").next();
+
testEdgeSer.addEdge(g, gvnf, vnfc1);
testEdgeSer.addEdge(g, gvnf, vnfc2, "re-uses");
-
+
QueryBuilder<Vertex> tQ = getNewVertexTraversalWithTestEdgeRules(gvnf);
tQ.createEdgeTraversal(EdgeType.COUSIN, "vnf", "vnfc");
-
+
List<Vertex> list = tQ.toList();
assertEquals("Has 2 vertexes ", 2, list.size());
assertTrue("Has vertex on the default edge ", list.contains(vnfc1));
assertTrue("Has vertex on the re-uses edge ", list.contains(vnfc2));
-
}
-
+
@Test
public void abstractEdgeToVertexMultiRuleOutTraversalTest() throws AAIException {
-
- Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
- Vertex pserver = g.addV("aai-node-type","pserver","hostname","a-name").next();
-
+
+ Vertex gvnf = g.addV("aai-node-type", "generic-vnf", "vnf-id", "gvnf").next();
+ Vertex pserver = g.addV("aai-node-type", "pserver", "hostname", "a-name").next();
+
testEdgeSer.addEdge(g, gvnf, pserver);
testEdgeSer.addEdge(g, gvnf, pserver, "generic-vnf-pserver-B");
-
+
QueryBuilder<Vertex> tQ = getNewVertexTraversalWithTestEdgeRules(gvnf);
tQ.createEdgeTraversal(EdgeType.COUSIN, "vnf", "pserver");
-
+
List<Vertex> list = tQ.toList();
-
+
assertEquals("Has 2 vertexes ", 2, list.size());
assertTrue("result has pserver ", list.contains(pserver));
-
}
-
+
@Test
public void abstractEdgeToVertexMultiRuleInTraversalTest() throws AAIException {
-
- Vertex gvnf = g.addV("aai-node-type","generic-vnf","vnf-id","gvnf").next();
- Vertex complex = g.addV("aai-node-type","complex","physical-location-id","a-name").next();
-
+
+ Vertex gvnf = g.addV("aai-node-type", "generic-vnf", "vnf-id", "gvnf").next();
+ Vertex complex = g.addV("aai-node-type", "complex", "physical-location-id", "a-name").next();
+
testEdgeSer.addEdge(g, gvnf, complex);
testEdgeSer.addEdge(g, gvnf, complex, "complex-generic-vnf-B");
-
+
QueryBuilder<Vertex> tQ = getNewVertexTraversalWithTestEdgeRules(gvnf);
tQ.createEdgeTraversal(EdgeType.COUSIN, "vnf", "complex");
-
+
List<Vertex> list = tQ.toList();
-
+
assertEquals("Has 2 vertexes ", 2, list.size());
assertTrue("result has pserver ", list.contains(complex));
-
}
-
-
}
diff --git a/aai-core/src/test/java/org/onap/aai/query/builder/TraversalURIOptimizedQueryTest.java b/aai-core/src/test/java/org/onap/aai/query/builder/TraversalURIOptimizedQueryTest.java
index 8ec01aaa..7ed90711 100644
--- a/aai-core/src/test/java/org/onap/aai/query/builder/TraversalURIOptimizedQueryTest.java
+++ b/aai-core/src/test/java/org/onap/aai/query/builder/TraversalURIOptimizedQueryTest.java
@@ -17,12 +17,14 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.query.builder;
import org.apache.tinkerpop.gremlin.process.traversal.Path;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
+
public class TraversalURIOptimizedQueryTest extends TraversalQueryTest {
@Override
@@ -45,7 +47,6 @@ public class TraversalURIOptimizedQueryTest extends TraversalQueryTest {
return new TraversalURIOptimizedQuery<>(loader, g);
}
-
@Override
protected QueryBuilder<Vertex> getNewVertexTraversal() {
return new TraversalURIOptimizedQuery<>(loader, g);
diff --git a/aai-core/src/test/java/org/onap/aai/query/builder/UntilTest.java b/aai-core/src/test/java/org/onap/aai/query/builder/UntilTest.java
index c5290375..dcf11ba2 100644
--- a/aai-core/src/test/java/org/onap/aai/query/builder/UntilTest.java
+++ b/aai-core/src/test/java/org/onap/aai/query/builder/UntilTest.java
@@ -17,8 +17,14 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.query.builder;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.T;
@@ -28,47 +34,41 @@ import org.junit.Before;
import org.junit.Test;
import org.onap.aai.AAISetup;
import org.onap.aai.db.props.AAIProperties;
+import org.onap.aai.edges.enums.EdgeType;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.Loader;
import org.onap.aai.introspection.ModelType;
-
import org.onap.aai.serialization.db.EdgeSerializer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
-import org.onap.aai.edges.enums.EdgeType;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.Assert.assertTrue;
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class UntilTest extends AAISetup {
private Loader loader;
-
+
@Autowired
EdgeSerializer edgeSer;
-
+
@Before
public void setup() throws Exception {
loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
}
-
- private QueryBuilder<Vertex> buildTestQuery(QueryBuilder<Vertex> qb) throws AAIException{
- return qb.until(qb.newInstance().getVerticesByProperty("aai-node-type", "l-interface")).repeat(
- qb.newInstance().union(
+
+ private QueryBuilder<Vertex> buildTestQuery(QueryBuilder<Vertex> qb) throws AAIException {
+ return qb.until(qb.newInstance().getVerticesByProperty("aai-node-type", "l-interface"))
+ .repeat(qb.newInstance().union(
qb.newInstance().createEdgeTraversal(EdgeType.TREE, "cloud-region", "tenant"),
qb.newInstance().createEdgeTraversal(EdgeType.TREE, "tenant", "vserver"),
- qb.newInstance().createEdgeTraversal(EdgeType.TREE, "vserver", "l-interface")
- )).store("x").cap("x").unfold().dedup();
+ qb.newInstance().createEdgeTraversal(EdgeType.TREE, "vserver", "l-interface")))
+ .store("x").cap("x").unfold().dedup();
}
-
+
@Test
public void gremlinQueryUntilTest() throws AAIException {
Graph graph = TinkerGraph.open();
GraphTraversalSource g = graph.traversal();
-
+
Vertex v1 = graph.addVertex(T.id, 1, "aai-node-type", "cloud-region");
Vertex v2 = graph.addVertex(T.id, 2, "aai-node-type", "tenant");
Vertex v3 = graph.addVertex(T.id, 3, "aai-node-type", "vserver");
@@ -78,10 +78,10 @@ public class UntilTest extends AAISetup {
edgeSer.addTreeEdge(g, v3, v4);
List<Vertex> expected = new ArrayList<>();
expected.add(v4);
-
- GremlinTraversal<Vertex> qb = new GremlinTraversal<>(loader, g, v1);
+
+ GremlinTraversal<Vertex> qb = new GremlinTraversal<>(loader, g, v1);
QueryBuilder q = buildTestQuery(qb);
-
+
List<Vertex> results = q.toList();
assertTrue("results match", expected.containsAll(results) && results.containsAll(expected));
@@ -91,7 +91,7 @@ public class UntilTest extends AAISetup {
public void traversalQueryUntilTest() throws AAIException {
Graph graph = TinkerGraph.open();
GraphTraversalSource g = graph.traversal();
-
+
Vertex v1 = graph.addVertex(T.id, 1, "aai-node-type", "cloud-region");
Vertex v2 = graph.addVertex(T.id, 2, "aai-node-type", "tenant");
Vertex v3 = graph.addVertex(T.id, 3, "aai-node-type", "vserver");
@@ -101,15 +101,13 @@ public class UntilTest extends AAISetup {
edgeSer.addTreeEdge(g, v3, v4);
List<Vertex> expected = new ArrayList<>();
expected.add(v4);
-
- TraversalQuery<Vertex> qb = new TraversalQuery<>(loader, g, v1);
+
+ TraversalQuery<Vertex> qb = new TraversalQuery<>(loader, g, v1);
QueryBuilder<Vertex> q = buildTestQuery(qb);
-
+
List<Vertex> results = q.toList();
assertTrue("results match", expected.containsAll(results) && results.containsAll(expected));
}
-
-
}
diff --git a/aai-core/src/test/java/org/onap/aai/query/builder/optimization/AbstractGraphTraversalBuilderOptmizationTest.java b/aai-core/src/test/java/org/onap/aai/query/builder/optimization/AbstractGraphTraversalBuilderOptmizationTest.java
index c8134b2d..911cb20c 100644
--- a/aai-core/src/test/java/org/onap/aai/query/builder/optimization/AbstractGraphTraversalBuilderOptmizationTest.java
+++ b/aai-core/src/test/java/org/onap/aai/query/builder/optimization/AbstractGraphTraversalBuilderOptmizationTest.java
@@ -17,9 +17,19 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.query.builder.optimization;
+import static org.junit.Assert.assertEquals;
+
import com.google.common.base.CaseFormat;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Random;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
@@ -32,7 +42,6 @@ import org.onap.aai.dbmap.DBConnectionType;
import org.onap.aai.introspection.Introspector;
import org.onap.aai.introspection.Loader;
import org.onap.aai.introspection.ModelType;
-
import org.onap.aai.query.builder.QueryBuilder;
import org.onap.aai.serialization.db.DBSerializer;
import org.onap.aai.serialization.db.EdgeSerializer;
@@ -41,17 +50,9 @@ import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
import org.springframework.beans.factory.annotation.Autowired;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Random;
+public abstract class AbstractGraphTraversalBuilderOptmizationTest extends AAISetup {
-import static org.junit.Assert.assertEquals;
-
-public abstract class AbstractGraphTraversalBuilderOptmizationTest extends AAISetup{
-
- protected static final List<String> RANDOM_VALUES = Arrays.asList("A","B","C","D","E");
+ protected static final List<String> RANDOM_VALUES = Arrays.asList("A", "B", "C", "D", "E");
protected static final String crUriPattern = "/cloud-infrastructure/cloud-regions/cloud-region/%s/%s";
protected static final String tenantUriPatternSuffix = "/tenants/tenant/%s";
@@ -84,14 +85,14 @@ public abstract class AbstractGraphTraversalBuilderOptmizationTest extends AAISe
protected static Random rand;
-
- protected void setupData(int tenantNum, int vserverPerTenantNum, String prefix) throws Exception{
+ protected void setupData(int tenantNum, int vserverPerTenantNum, String prefix) throws Exception {
loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, schemaVersions.getDefaultVersion());
graph = AAIGraph.getInstance().getGraph();
dbEngine = new JanusGraphDBEngine(queryStyle, type, loader);
g = dbEngine.startTransaction().traversal();
- dbser = new DBSerializer(schemaVersions.getDefaultVersion(), dbEngine, introspectorFactoryType, "AAI-TEST-" + prefix);
+ dbser = new DBSerializer(schemaVersions.getDefaultVersion(), dbEngine, introspectorFactoryType,
+ "AAI-TEST-" + prefix);
rand = new Random();
@@ -105,12 +106,9 @@ public abstract class AbstractGraphTraversalBuilderOptmizationTest extends AAISe
long startTime = System.currentTimeMillis();
for (int crCtr = 0; crCtr < 3; crCtr++) {
crUri = String.format(crUriPattern, prefix + "cloud-owner-" + crCtr, prefix + "cloud-region-id-" + crCtr);
- //System.out.println(crUri);
- cr = g.addV(AAIProperties.NODE_TYPE, CLOUD_REGION,
- CLOUD_REGION_ID, prefix + "cloud-region-id-" + crCtr,
- CLOUD_OWNER, prefix + "cloud-owner-" + crCtr,
- AAIProperties.AAI_URI, crUri
- ).next();
+ // System.out.println(crUri);
+ cr = g.addV(AAIProperties.NODE_TYPE, CLOUD_REGION, CLOUD_REGION_ID, prefix + "cloud-region-id-" + crCtr,
+ CLOUD_OWNER, prefix + "cloud-owner-" + crCtr, AAIProperties.AAI_URI, crUri).next();
for (int i = 0; i < tenantNum; i++) {
Introspector intro = loader.introspectorFromName(TENANT);
tenant = dbser.createNewVertex(intro);
@@ -118,7 +116,7 @@ public abstract class AbstractGraphTraversalBuilderOptmizationTest extends AAISe
intro.setValue(TENANT_ID, prefix + "tenant-id-" + i);
intro.setValue(TENANT_NAME, prefix + "tenant-name-" + i);
dbser.serializeSingleVertex(tenant, intro, "AAI-TEST-" + prefix);
- //System.out.println("Tenant " + crCtr + " " + i);
+ // System.out.println("Tenant " + crCtr + " " + i);
for (int j = 0; j < vserverPerTenantNum; j++) {
intro = loader.introspectorFromName(VSERVER);
vserver = dbser.createNewVertex(intro);
@@ -128,13 +126,15 @@ public abstract class AbstractGraphTraversalBuilderOptmizationTest extends AAISe
intro.setValue(PROV_STATUS, RANDOM_VALUES.get(rand.nextInt(RANDOM_VALUES.size())));
intro.setValue(VSERVER_SELFLINK, RANDOM_VALUES.get(rand.nextInt(RANDOM_VALUES.size())));
dbser.serializeSingleVertex(vserver, intro, "AAI-TEST-" + prefix);
- //System.out.println("Vserver " + crCtr + " " + i + " " + j);
+ // System.out.println("Vserver " + crCtr + " " + i + " " + j);
}
}
}
- //g.V().forEachRemaining(v -> v.properties().forEachRemaining(p -> System.out.println(p.key() + " : " + p.value())));
- //g.E().forEachRemaining(e -> System.out.println(e.outVertex().property(AAIProperties.NODE_TYPE).value() + " : " + e.inVertex().property(AAIProperties.NODE_TYPE).value()));
- long time = System.currentTimeMillis()-startTime;
+ // g.V().forEachRemaining(v -> v.properties().forEachRemaining(p -> System.out.println(p.key() + " : " +
+ // p.value())));
+ // g.E().forEachRemaining(e -> System.out.println(e.outVertex().property(AAIProperties.NODE_TYPE).value() + " :
+ // " + e.inVertex().property(AAIProperties.NODE_TYPE).value()));
+ long time = System.currentTimeMillis() - startTime;
System.out.println("Data load ended\n" + time);
}
@@ -149,48 +149,52 @@ public abstract class AbstractGraphTraversalBuilderOptmizationTest extends AAISe
System.out.println("Done");
}
- protected void execute(Method getQueryMethod, int numResultsExpected) throws Exception{
+ protected void execute(Method getQueryMethod, int numResultsExpected) throws Exception {
int iterations = numOfTimesToRun();
long noneTimer = 0;
long uriTimer = 0;
- for (int i = 0; i < iterations+1 ; i++) {
- if (i == 0 ) { // dont use incase initial cold starts
+ for (int i = 0; i < iterations + 1; i++) {
+ if (i == 0) { // dont use incase initial cold starts
timeQuery(getQuery(getQueryMethod, OptimizeEnum.NONE), numResultsExpected, OptimizeEnum.NONE);
timeQuery(getQuery(getQueryMethod, OptimizeEnum.URI), numResultsExpected, OptimizeEnum.URI);
} else {
- noneTimer += timeQuery(getQuery(getQueryMethod, OptimizeEnum.NONE), numResultsExpected, OptimizeEnum.NONE);
+ noneTimer +=
+ timeQuery(getQuery(getQueryMethod, OptimizeEnum.NONE), numResultsExpected, OptimizeEnum.NONE);
uriTimer += timeQuery(getQuery(getQueryMethod, OptimizeEnum.URI), numResultsExpected, OptimizeEnum.URI);
}
}
noneTimer /= iterations;
uriTimer /= iterations;
- System.out.println(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getQueryMethod.getName()).replace("-query", "") + "\t" + (noneTimer)/100000.0 + "\t" + (uriTimer)/100000.0);
- //System.out.println((noneTimer)/100000.0 + " ms, (Not optimized)");
- //System.out.println((uriTimer)/100000.0 + " ms, (URI optimized)");
+ System.out.println(
+ CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getQueryMethod.getName()).replace("-query", "")
+ + "\t" + (noneTimer) / 100000.0 + "\t" + (uriTimer) / 100000.0);
+ // System.out.println((noneTimer)/100000.0 + " ms, (Not optimized)");
+ // System.out.println((uriTimer)/100000.0 + " ms, (URI optimized)");
}
- private QueryBuilder<Vertex> getQuery(Method getQueryMethod, OptimizeEnum optimization) throws InvocationTargetException, IllegalAccessException {
+ private QueryBuilder<Vertex> getQuery(Method getQueryMethod, OptimizeEnum optimization)
+ throws InvocationTargetException, IllegalAccessException {
return (QueryBuilder<Vertex>) getQueryMethod.invoke(this, optimization);
}
-
private long timeQuery(QueryBuilder<Vertex> query, int numResultsExpected, OptimizeEnum optimized) {
- //System.out.println(optimized.toString());
+ // System.out.println(optimized.toString());
long startTime = System.nanoTime();
List<Vertex> result = query.toList();
long endTime = System.nanoTime();
-// if (!optimized) {
-// result.get(0).properties().forEachRemaining(p -> System.out.println(p.key() + " : " + p.value()));
-// }
- //System.out.println("Result size: " + result.size());
+ // if (!optimized) {
+ // result.get(0).properties().forEachRemaining(p -> System.out.println(p.key() + " : " + p.value()));
+ // }
+ // System.out.println("Result size: " + result.size());
if (numResultsExpected != Integer.MIN_VALUE) {
- assertEquals( optimized.toString() + " optimized" + " query results in " + numResultsExpected + " vserver ", numResultsExpected, result.size());
+ assertEquals(optimized.toString() + " optimized" + " query results in " + numResultsExpected + " vserver ",
+ numResultsExpected, result.size());
}
return endTime - startTime;
@@ -206,4 +210,3 @@ public abstract class AbstractGraphTraversalBuilderOptmizationTest extends AAISe
}
}
-
diff --git a/aai-core/src/test/java/org/onap/aai/query/builder/optimization/AbstractGraphTraversalBuilderTestQueryiesToRun.java b/aai-core/src/test/java/org/onap/aai/query/builder/optimization/AbstractGraphTraversalBuilderTestQueryiesToRun.java
index 8a80fb94..28e7a7f8 100644
--- a/aai-core/src/test/java/org/onap/aai/query/builder/optimization/AbstractGraphTraversalBuilderTestQueryiesToRun.java
+++ b/aai-core/src/test/java/org/onap/aai/query/builder/optimization/AbstractGraphTraversalBuilderTestQueryiesToRun.java
@@ -17,8 +17,15 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.query.builder.optimization;
+import java.lang.reflect.Method;
+import java.net.URI;
+
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.junit.Before;
import org.junit.Test;
@@ -26,12 +33,8 @@ import org.onap.aai.query.builder.QueryBuilder;
import org.onap.aai.query.builder.TraversalQuery;
import org.onap.aai.query.builder.TraversalURIOptimizedQuery;
-import javax.ws.rs.core.MultivaluedHashMap;
-import javax.ws.rs.core.MultivaluedMap;
-import java.lang.reflect.Method;
-import java.net.URI;
-
-public abstract class AbstractGraphTraversalBuilderTestQueryiesToRun extends AbstractGraphTraversalBuilderOptmizationTest {
+public abstract class AbstractGraphTraversalBuilderTestQueryiesToRun
+ extends AbstractGraphTraversalBuilderOptmizationTest {
protected static final String CLOUD_OWNER_1 = "cloud-owner-1";
protected static final String CLOUD_REGION_ID_1 = "cloud-region-id-1";
@@ -52,7 +55,6 @@ public abstract class AbstractGraphTraversalBuilderTestQueryiesToRun extends Abs
protected abstract String getPrefix();
-
private QueryBuilder<Vertex> getQueryBuilder(OptimizeEnum optimized) {
if (OptimizeEnum.URI.equals(optimized)) {
return new TraversalURIOptimizedQuery<>(loader, g);
@@ -63,7 +65,8 @@ public abstract class AbstractGraphTraversalBuilderTestQueryiesToRun extends Abs
private void callTest(String methodName, int numResultsExpected) throws Exception {
String queryMethodName = methodName.replace("Test", "Query");
- Method method = AbstractGraphTraversalBuilderTestQueryiesToRun.class.getMethod(queryMethodName, OptimizeEnum.class);
+ Method method =
+ AbstractGraphTraversalBuilderTestQueryiesToRun.class.getMethod(queryMethodName, OptimizeEnum.class);
this.execute(method, numResultsExpected);
}
@@ -74,7 +77,8 @@ public abstract class AbstractGraphTraversalBuilderTestQueryiesToRun extends Abs
}
public QueryBuilder<Vertex> vserverQuery(OptimizeEnum optimized) throws Exception {
- URI uri = new URI(String.format(vserverUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1, tenantId, vserverId));
+ URI uri = new URI(String.format(vserverUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1,
+ tenantId, vserverId));
return getQueryBuilder(optimized).createQueryFromURI(uri).getQueryBuilder();
}
@@ -85,7 +89,9 @@ public abstract class AbstractGraphTraversalBuilderTestQueryiesToRun extends Abs
}
public QueryBuilder<Vertex> vserversUnderATenantQuery(OptimizeEnum optimized) throws Exception {
- URI uri = new URI(String.format(tenantUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1, tenantId) + "/vservers");
+ URI uri = new URI(
+ String.format(tenantUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1, tenantId)
+ + "/vservers");
return getQueryBuilder(optimized).createQueryFromURI(uri).getQueryBuilder();
}
@@ -96,7 +102,9 @@ public abstract class AbstractGraphTraversalBuilderTestQueryiesToRun extends Abs
}
public QueryBuilder<Vertex> vserversUnderATenantWithNonIndexPropertyQuery(OptimizeEnum optimized) throws Exception {
- URI uri = new URI(String.format(tenantUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1, tenantId) + "/vservers");
+ URI uri = new URI(
+ String.format(tenantUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1, tenantId)
+ + "/vservers");
MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
map.putSingle(VSERVER_SELFLINK, randomFromList);
return getQueryBuilder(optimized).createQueryFromURI(uri, map).getQueryBuilder();
@@ -108,8 +116,11 @@ public abstract class AbstractGraphTraversalBuilderTestQueryiesToRun extends Abs
callTest(methodName, Integer.MIN_VALUE);
}
- public QueryBuilder<Vertex> vserversUnderATenantWithIndexPropertyWhereValueIsInMultipleQuery(OptimizeEnum optimized) throws Exception {
- URI uri = new URI(String.format(tenantUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1, tenantId) + "/vservers");
+ public QueryBuilder<Vertex> vserversUnderATenantWithIndexPropertyWhereValueIsInMultipleQuery(OptimizeEnum optimized)
+ throws Exception {
+ URI uri = new URI(
+ String.format(tenantUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1, tenantId)
+ + "/vservers");
MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
map.putSingle(PROV_STATUS, randomFromList);
return getQueryBuilder(optimized).createQueryFromURI(uri, map).getQueryBuilder();
@@ -121,8 +132,11 @@ public abstract class AbstractGraphTraversalBuilderTestQueryiesToRun extends Abs
callTest(methodName, Integer.MIN_VALUE);
}
- public QueryBuilder<Vertex> vserversUnderATenantWithIndexPropertyWhereValueIsSemiUniqueQuery(OptimizeEnum optimized) throws Exception {
- URI uri = new URI(String.format(tenantUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1, tenantId) + "/vservers");
+ public QueryBuilder<Vertex> vserversUnderATenantWithIndexPropertyWhereValueIsSemiUniqueQuery(OptimizeEnum optimized)
+ throws Exception {
+ URI uri = new URI(
+ String.format(tenantUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1, tenantId)
+ + "/vservers");
MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
map.putSingle(VSERVER_NAME, vserverName);
return getQueryBuilder(optimized).createQueryFromURI(uri, map).getQueryBuilder();
@@ -136,7 +150,8 @@ public abstract class AbstractGraphTraversalBuilderTestQueryiesToRun extends Abs
}
public QueryBuilder<Vertex> nonExistentVserverQuery(OptimizeEnum optimized) throws Exception {
- URI uri = new URI(String.format(vserverUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1, tenantId, "does-not-exist"));
+ URI uri = new URI(String.format(vserverUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1,
+ tenantId, "does-not-exist"));
return getQueryBuilder(optimized).createQueryFromURI(uri).getQueryBuilder();
}
@@ -147,7 +162,8 @@ public abstract class AbstractGraphTraversalBuilderTestQueryiesToRun extends Abs
}
public QueryBuilder<Vertex> vserverWithNonExistentTenantQuery(OptimizeEnum optimized) throws Exception {
- URI uri = new URI(String.format(vserverUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1, "does-not-exist", vserverId));
+ URI uri = new URI(String.format(vserverUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1,
+ "does-not-exist", vserverId));
return getQueryBuilder(optimized).createQueryFromURI(uri).getQueryBuilder();
}
@@ -158,7 +174,8 @@ public abstract class AbstractGraphTraversalBuilderTestQueryiesToRun extends Abs
}
public QueryBuilder<Vertex> vserverWithValidQueryParameterQuery(OptimizeEnum optimized) throws Exception {
- URI uri = new URI(String.format(vserverUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1, tenantId, vserverId));
+ URI uri = new URI(String.format(vserverUriPattern, getPrefix() + CLOUD_OWNER_1, getPrefix() + CLOUD_REGION_ID_1,
+ tenantId, vserverId));
MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
map.putSingle("vserver-name2", "someName");
return getQueryBuilder(optimized).createQueryFromURI(uri, map).getQueryBuilder();
@@ -177,5 +194,4 @@ public abstract class AbstractGraphTraversalBuilderTestQueryiesToRun extends Abs
return getQueryBuilder(optimized).createQueryFromURI(uri, map).getQueryBuilder();
}
-
}
diff --git a/aai-core/src/test/java/org/onap/aai/query/builder/optimization/OptimizeEnum.java b/aai-core/src/test/java/org/onap/aai/query/builder/optimization/OptimizeEnum.java
index 907f4ff5..e8e4399b 100644
--- a/aai-core/src/test/java/org/onap/aai/query/builder/optimization/OptimizeEnum.java
+++ b/aai-core/src/test/java/org/onap/aai/query/builder/optimization/OptimizeEnum.java
@@ -17,8 +17,9 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.query.builder.optimization;
public enum OptimizeEnum {
- URI,NONE
+ URI, NONE
}
diff --git a/aai-core/src/test/java/org/onap/aai/query/builder/optimization/tests/AOneTenantOneVserversPerTenantTest.java b/aai-core/src/test/java/org/onap/aai/query/builder/optimization/tests/AOneTenantOneVserversPerTenantTest.java
index c65dbb4e..4c6226ac 100644
--- a/aai-core/src/test/java/org/onap/aai/query/builder/optimization/tests/AOneTenantOneVserversPerTenantTest.java
+++ b/aai-core/src/test/java/org/onap/aai/query/builder/optimization/tests/AOneTenantOneVserversPerTenantTest.java
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.query.builder.optimization.tests;
import org.junit.BeforeClass;
@@ -32,7 +33,7 @@ public class AOneTenantOneVserversPerTenantTest extends AbstractGraphTraversalBu
@BeforeClass
public void setup() throws Exception {
- setupData(tenantNum,vserverPerTenantNum, prefix);
+ setupData(tenantNum, vserverPerTenantNum, prefix);
}
@Override
diff --git a/aai-core/src/test/java/org/onap/aai/query/builder/optimization/tests/BTenTenantTenVserversPerTenantTest.java b/aai-core/src/test/java/org/onap/aai/query/builder/optimization/tests/BTenTenantTenVserversPerTenantTest.java
index 83c965e4..aea2899b 100644
--- a/aai-core/src/test/java/org/onap/aai/query/builder/optimization/tests/BTenTenantTenVserversPerTenantTest.java
+++ b/aai-core/src/test/java/org/onap/aai/query/builder/optimization/tests/BTenTenantTenVserversPerTenantTest.java
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.query.builder.optimization.tests;
import org.junit.BeforeClass;
@@ -32,7 +33,7 @@ public class BTenTenantTenVserversPerTenantTest extends AbstractGraphTraversalBu
@BeforeClass
public void setup() throws Exception {
- setupData(tenantNum,vserverPerTenantNum, prefix);
+ setupData(tenantNum, vserverPerTenantNum, prefix);
}
@Override
diff --git a/aai-core/src/test/java/org/onap/aai/rest/CloudRegionTest.java b/aai-core/src/test/java/org/onap/aai/rest/CloudRegionTest.java
index baed76b3..e410f529 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/CloudRegionTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/CloudRegionTest.java
@@ -17,9 +17,19 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.rest;
+import static org.junit.Assert.assertEquals;
+
import com.jayway.jsonpath.JsonPath;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+
+import javax.ws.rs.core.Response;
+
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -32,13 +42,6 @@ import org.onap.aai.exceptions.AAIException;
import org.onap.aai.serialization.engines.QueryStyle;
import org.skyscreamer.jsonassert.JSONAssert;
-import javax.ws.rs.core.Response;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collection;
-
-import static org.junit.Assert.assertEquals;
-
/**
* <b>CloudRegionTest</b> is testing if you put a cloud region with all
* children nodes associated to it then you should be able to
@@ -54,14 +57,11 @@ public class CloudRegionTest extends AAISetup {
@Parameterized.Parameters(name = "QueryStyle.{0}")
public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][]{
- {QueryStyle.TRAVERSAL},
- {QueryStyle.TRAVERSAL_URI}
- });
+ return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
}
@Before
- public void setUp(){
+ public void setUp() {
httpTestUtil = new HttpTestUtil(queryStyle);
}
@@ -70,9 +70,10 @@ public class CloudRegionTest extends AAISetup {
public void testPutWithAllCloudRegionChildrenNodesAndCheckIfDeleteIsSuccessful() throws IOException, AAIException {
String cloudRegionPayload = PayloadUtil.getResourcePayload("cloud-region-with-all-children.json");
- String cloudRegionUri = "/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/junit-cloud-owner/junit-cloud-region";
+ String cloudRegionUri =
+ "/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/junit-cloud-owner/junit-cloud-region";
- Response response = httpTestUtil.doPut(cloudRegionUri, cloudRegionPayload);
+ Response response = httpTestUtil.doPut(cloudRegionUri, cloudRegionPayload);
assertEquals("Expected the cloud region to be created", 201, response.getStatus());
response = httpTestUtil.doGet(cloudRegionUri);
diff --git a/aai-core/src/test/java/org/onap/aai/rest/EdgeNotValidAnymoreTest.java b/aai-core/src/test/java/org/onap/aai/rest/EdgeNotValidAnymoreTest.java
index 1a69fc58..68fae9ce 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/EdgeNotValidAnymoreTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/EdgeNotValidAnymoreTest.java
@@ -17,8 +17,19 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.rest;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.junit.Assert.assertThat;
+
+import java.io.IOException;
+import java.util.UUID;
+
+import javax.ws.rs.core.Response;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
@@ -37,15 +48,6 @@ import org.onap.aai.edges.enums.EdgeProperty;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.serialization.engines.QueryStyle;
-import javax.ws.rs.core.Response;
-import java.io.IOException;
-import java.util.UUID;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.Matchers.not;
-import static org.junit.Assert.assertThat;
-
public class EdgeNotValidAnymoreTest extends AAISetup {
private HttpTestUtil testUtil;
@@ -53,7 +55,8 @@ public class EdgeNotValidAnymoreTest extends AAISetup {
@Before
public void setupData() throws IOException, AAIException {
- String cloudRegionEndpoint = "/aai/v13/cloud-infrastructure/cloud-regions/cloud-region/junit-cloud-owner-with-vlan/junit-cloud-region-with-vlan";
+ String cloudRegionEndpoint =
+ "/aai/v13/cloud-infrastructure/cloud-regions/cloud-region/junit-cloud-owner-with-vlan/junit-cloud-region-with-vlan";
String cloudRegionBody = PayloadUtil.getResourcePayload("cloud-region-with-vlan.json");
testUtil = new HttpTestUtil(QueryStyle.TRAVERSAL_URI);
@@ -62,18 +65,13 @@ public class EdgeNotValidAnymoreTest extends AAISetup {
JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction();
GraphTraversalSource g = transaction.traversal();
- Vertex configurationVertex = g.addV()
- .property( AAIProperties.NODE_TYPE, "configuration")
- .property( "configuration-id", "ci1")
- .property( "configuration-type", "ci1")
- .property( AAIProperties.AAI_URI, "/network/configurations/configuration/ci1")
- .property(AAIProperties.SOURCE_OF_TRUTH, "JUNIT")
- .next();
+ Vertex configurationVertex = g.addV().property(AAIProperties.NODE_TYPE, "configuration")
+ .property("configuration-id", "ci1").property("configuration-type", "ci1")
+ .property(AAIProperties.AAI_URI, "/network/configurations/configuration/ci1")
+ .property(AAIProperties.SOURCE_OF_TRUTH, "JUNIT").next();
- Vertex vlanVertex = g.V()
- .has("vlan-interface", "test-vlan-interface-1")
- .has(AAIProperties.NODE_TYPE, "vlan")
- .next();
+ Vertex vlanVertex =
+ g.V().has("vlan-interface", "test-vlan-interface-1").has(AAIProperties.NODE_TYPE, "vlan").next();
Edge edge = configurationVertex.addEdge("org.onap.relationships.inventory.PartOf", vlanVertex);
addEdge(edge);
@@ -104,16 +102,13 @@ public class EdgeNotValidAnymoreTest extends AAISetup {
}
@After
- public void teardown(){
+ public void teardown() {
JanusGraph janusGraph = AAIGraph.getInstance().getGraph();
JanusGraphTransaction transaction = janusGraph.newTransaction();
GraphTraversalSource g = transaction.traversal();
- g.V()
- .has(AAIProperties.SOURCE_OF_TRUTH, "JUNIT")
- .toList()
- .forEach((edge) -> edge.remove());
+ g.V().has(AAIProperties.SOURCE_OF_TRUTH, "JUNIT").toList().forEach((edge) -> edge.remove());
transaction.commit();
}
diff --git a/aai-core/src/test/java/org/onap/aai/rest/EntitlementTest.java b/aai-core/src/test/java/org/onap/aai/rest/EntitlementTest.java
index 3559b9d6..c992a946 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/EntitlementTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/EntitlementTest.java
@@ -17,9 +17,20 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.rest;
+import static org.junit.Assert.assertEquals;
+
import com.jayway.jsonpath.JsonPath;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+import java.util.Collection;
+
+import javax.ws.rs.core.Response;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -33,14 +44,6 @@ import org.onap.aai.serialization.engines.QueryStyle;
import org.skyscreamer.jsonassert.JSONAssert;
import org.springframework.test.annotation.DirtiesContext;
-import javax.ws.rs.core.Response;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.util.Arrays;
-import java.util.Collection;
-
-import static org.junit.Assert.assertEquals;
-
@RunWith(value = Parameterized.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class EntitlementTest extends AAISetup {
@@ -56,9 +59,7 @@ public class EntitlementTest extends AAISetup {
@Parameterized.Parameters(name = "QueryStyle.{0}")
public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][]{
- {QueryStyle.TRAVERSAL_URI}
- });
+ return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL_URI}});
}
@Before
@@ -72,7 +73,7 @@ public class EntitlementTest extends AAISetup {
public void testPutGenericVnfAndThenInsertEntitlement() throws IOException, AAIException {
String entitlementPayload = PayloadUtil.getResourcePayload("entitlement.json");
String entitlementUri = "/aai/v14/network/generic-vnfs/generic-vnf/vnf1/entitlements/entitlement/g1/r1";
- Response response = httpTestUtil.doPut(vnfUri, vnfPayload);
+ Response response = httpTestUtil.doPut(vnfUri, vnfPayload);
assertEquals("Expected the Generic Vnf to be created", 201, response.getStatus());
response = httpTestUtil.doGet(vnfUri);
@@ -80,7 +81,7 @@ public class EntitlementTest extends AAISetup {
String jsonResponse = response.getEntity().toString();
JSONAssert.assertEquals(vnfPayload, jsonResponse, false);
- response = httpTestUtil.doPut(entitlementUri, entitlementPayload);
+ response = httpTestUtil.doPut(entitlementUri, entitlementPayload);
assertEquals("Expected the Entitlement to be created", 201, response.getStatus());
}
diff --git a/aai-core/src/test/java/org/onap/aai/rest/GenericVnfLInterfaceTest.java b/aai-core/src/test/java/org/onap/aai/rest/GenericVnfLInterfaceTest.java
index 60519b1a..d6202f24 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/GenericVnfLInterfaceTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/GenericVnfLInterfaceTest.java
@@ -17,8 +17,19 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.rest;
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.core.Response;
+
import org.json.JSONObject;
import org.junit.After;
import org.junit.Before;
@@ -32,35 +43,23 @@ import org.onap.aai.exceptions.AAIException;
import org.onap.aai.serialization.engines.QueryStyle;
import org.skyscreamer.jsonassert.JSONAssert;
import org.springframework.test.annotation.DirtiesContext;
-import javax.ws.rs.core.Response;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
@RunWith(value = Parameterized.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class GenericVnfLInterfaceTest extends AAISetup {
private HttpTestUtil httpTestUtil;
-
@Parameterized.Parameter(value = 0)
public QueryStyle queryStyle;
@Parameterized.Parameters(name = "QueryStyle.{0}")
public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][]{
- {QueryStyle.TRAVERSAL},
- {QueryStyle.TRAVERSAL_URI}
- });
+ return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
}
@Before
- public void setUp(){
+ public void setUp() {
httpTestUtil = new HttpTestUtil(queryStyle);
}
diff --git a/aai-core/src/test/java/org/onap/aai/rest/HPACapabilityTest.java b/aai-core/src/test/java/org/onap/aai/rest/HPACapabilityTest.java
index 85eb0b00..a742313a 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/HPACapabilityTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/HPACapabilityTest.java
@@ -17,11 +17,19 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.rest;
+import static org.junit.Assert.assertEquals;
+
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.jayway.jsonpath.JsonPath;
+
+import java.util.*;
+
+import javax.ws.rs.core.Response;
+
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -33,11 +41,6 @@ import org.onap.aai.PayloadUtil;
import org.onap.aai.serialization.engines.QueryStyle;
import org.skyscreamer.jsonassert.JSONAssert;
-import javax.ws.rs.core.Response;
-import java.util.*;
-
-import static org.junit.Assert.assertEquals;
-
@Ignore
@RunWith(AAIJunitRunner.class)
public class HPACapabilityTest {
@@ -51,9 +54,7 @@ public class HPACapabilityTest {
@Parameterized.Parameters(name = "QueryStyle.{0}")
public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][]{
- {QueryStyle.TRAVERSAL}
- });
+ return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}});
}
@Before
@@ -82,9 +83,7 @@ public class HPACapabilityTest {
String cloudRegionPayload = PayloadUtil.getTemplatePayload("hpa.json", templateValuesMap);
String cloudRegionUri = String.format("/aai/v14/cloud-infrastructure/cloud-regions/cloud-region/%s/%s",
- templateValuesMap.get("cloud-owner"),
- templateValuesMap.get("cloud-region-id")
- );
+ templateValuesMap.get("cloud-owner"), templateValuesMap.get("cloud-region-id"));
Response response = httpTestUtil.doPut(cloudRegionUri, cloudRegionPayload);
assertEquals("Expected the cloud region to be created", 201, response.getStatus());
@@ -141,9 +140,9 @@ public class HPACapabilityTest {
System.out.println("#########################Flavor Response#########################");
String responseStr = response.getEntity().toString();
- List<String> capabilityIds = JsonPath.read(responseStr,
- "$.hpa-capabilities.hpa-capability[*].hpa-capability-id");
- for(String capabilityId : capabilityIds) {
+ List<String> capabilityIds =
+ JsonPath.read(responseStr, "$.hpa-capabilities.hpa-capability[*].hpa-capability-id");
+ for (String capabilityId : capabilityIds) {
deleteHPACapability(flavorUri, capabilityId);
}
diff --git a/aai-core/src/test/java/org/onap/aai/rest/ModelElementTest.java b/aai-core/src/test/java/org/onap/aai/rest/ModelElementTest.java
index d808c993..a5bcb2e5 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/ModelElementTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/ModelElementTest.java
@@ -17,9 +17,20 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.rest;
+import static org.junit.Assert.assertEquals;
+
import com.jayway.jsonpath.JsonPath;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+import java.util.Collection;
+
+import javax.ws.rs.core.Response;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -33,14 +44,6 @@ import org.onap.aai.serialization.engines.QueryStyle;
import org.skyscreamer.jsonassert.JSONAssert;
import org.springframework.test.annotation.DirtiesContext;
-import javax.ws.rs.core.Response;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.util.Arrays;
-import java.util.Collection;
-
-import static org.junit.Assert.assertEquals;
-
@RunWith(value = Parameterized.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class ModelElementTest extends AAISetup {
@@ -58,9 +61,7 @@ public class ModelElementTest extends AAISetup {
@Parameterized.Parameters(name = "QueryStyle.{0}")
public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][]{
- {QueryStyle.TRAVERSAL_URI}
- });
+ return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL_URI}});
}
@Before
@@ -69,12 +70,13 @@ public class ModelElementTest extends AAISetup {
modelPayload = PayloadUtil.getResourcePayload("model.json");
modelElementPayload = PayloadUtil.getResourcePayload("model-element.json");
modelUri = "/aai/v14/service-design-and-creation/models/model/24c04fc5-f3f8-43ec-8792-c6f940638676-test1";
- modelElementUri = "/aai/v14/service-design-and-creation/models/model/24c04fc5-f3f8-43ec-8792-c6f940638676-test1/model-vers/model-ver/0c4c59f0-9864-43ca-b0c2-ca38746b72a5-test1/model-elements/model-element/0dc2b8b6-af8d-4213-970b-7861a603fc86-test1/model-constraints/model-constraint/782ba24a-28ab-4fd0-8e69-da10cc5373f3-test1/constrained-element-sets/constrained-element-set/a33e65c3-1198-4d4c-9799-2b521e4c4212-test1/element-choice-sets/element-choice-set/7df27a94-06c8-46ef-9fc2-5900d8cffbb0-test1/model-elements/model-element/acf8b6cf-e051-4c1b-bcad-b24792f826cf-test1";
+ modelElementUri =
+ "/aai/v14/service-design-and-creation/models/model/24c04fc5-f3f8-43ec-8792-c6f940638676-test1/model-vers/model-ver/0c4c59f0-9864-43ca-b0c2-ca38746b72a5-test1/model-elements/model-element/0dc2b8b6-af8d-4213-970b-7861a603fc86-test1/model-constraints/model-constraint/782ba24a-28ab-4fd0-8e69-da10cc5373f3-test1/constrained-element-sets/constrained-element-set/a33e65c3-1198-4d4c-9799-2b521e4c4212-test1/element-choice-sets/element-choice-set/7df27a94-06c8-46ef-9fc2-5900d8cffbb0-test1/model-elements/model-element/acf8b6cf-e051-4c1b-bcad-b24792f826cf-test1";
}
@Test
public void testPutModelAndThenModelElementAndItShouldSucceed() throws IOException, AAIException {
- Response response = httpTestUtil.doPut(modelUri, modelPayload);
+ Response response = httpTestUtil.doPut(modelUri, modelPayload);
assertEquals("Expected the cloud region to be created", 201, response.getStatus());
response = httpTestUtil.doGet(modelUri);
@@ -82,7 +84,7 @@ public class ModelElementTest extends AAISetup {
String jsonResponse = response.getEntity().toString();
JSONAssert.assertEquals(modelPayload, jsonResponse, false);
- response = httpTestUtil.doPut(modelElementUri, modelElementPayload);
+ response = httpTestUtil.doPut(modelElementUri, modelElementPayload);
assertEquals("Expected the cloud region to be created", 201, response.getStatus());
}
diff --git a/aai-core/src/test/java/org/onap/aai/rest/PrivateEdgeIntegrationOldClientTest.java b/aai-core/src/test/java/org/onap/aai/rest/PrivateEdgeIntegrationOldClientTest.java
index a3520f56..0232c5aa 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/PrivateEdgeIntegrationOldClientTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/PrivateEdgeIntegrationOldClientTest.java
@@ -17,10 +17,21 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.rest;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertNotNull;
import com.jayway.jsonpath.JsonPath;
+
+import java.util.*;
+
+import javax.ws.rs.core.Response;
+
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.junit.Before;
import org.junit.Test;
@@ -34,15 +45,6 @@ import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.setup.SchemaVersion;
import org.springframework.test.annotation.DirtiesContext;
-import javax.ws.rs.core.Response;
-import java.util.*;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertNotNull;
-
@RunWith(value = Parameterized.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class PrivateEdgeIntegrationOldClientTest extends AAISetup {
@@ -53,7 +55,6 @@ public class PrivateEdgeIntegrationOldClientTest extends AAISetup {
private String modelId;
private String modelVerId;
-
@Parameterized.Parameter(value = 0)
public QueryStyle queryStyle;
@@ -62,10 +63,8 @@ public class PrivateEdgeIntegrationOldClientTest extends AAISetup {
@Parameterized.Parameters(name = "QueryStyle.{0} {1}")
public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][]{
- {QueryStyle.TRAVERSAL, new SchemaVersion("v14")},
- {QueryStyle.TRAVERSAL_URI, new SchemaVersion("v14")},
- });
+ return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL, new SchemaVersion("v14")},
+ {QueryStyle.TRAVERSAL_URI, new SchemaVersion("v14")},});
}
@Before
@@ -79,9 +78,10 @@ public class PrivateEdgeIntegrationOldClientTest extends AAISetup {
Map<String, String> modelTemplateValues = new HashMap<>();
modelTemplateValues.put("model-invariant-id", modelId);
- String modelPayload = PayloadUtil.getTemplatePayload("model.json", modelTemplateValues);
+ String modelPayload = PayloadUtil.getTemplatePayload("model.json", modelTemplateValues);
- Response response = httpTestUtil.doPut("/aai/"+version.toString()+"/service-design-and-creation/models/model/" + modelId, modelPayload);
+ Response response = httpTestUtil.doPut(
+ "/aai/" + version.toString() + "/service-design-and-creation/models/model/" + modelId, modelPayload);
assertNotNull(response);
assertThat("Model was not successfully created", response.getStatus(), is(201));
@@ -91,15 +91,17 @@ public class PrivateEdgeIntegrationOldClientTest extends AAISetup {
modelVersionTemplateValues.put("model-name", "some-model");
modelVersionTemplateValues.put("model-version", "testValue");
- String modelVersionPayload = PayloadUtil.getTemplatePayload("model-ver.json", modelVersionTemplateValues);
+ String modelVersionPayload = PayloadUtil.getTemplatePayload("model-ver.json", modelVersionTemplateValues);
- response = httpTestUtil.doPut("/aai/"+version.toString()+"/service-design-and-creation/models/model/" + modelId + "/model-vers/model-ver/" + modelVerId, modelVersionPayload);
+ response = httpTestUtil.doPut("/aai/" + version.toString() + "/service-design-and-creation/models/model/"
+ + modelId + "/model-vers/model-ver/" + modelVerId, modelVersionPayload);
assertNotNull(response);
assertThat("Model was not successfully created", response.getStatus(), is(201));
}
@Test
- public void testPutGenericVnfWithModelInfoToMatchExistingModelAndCheckIfPrivateEdgeCreatedAndDoGetOnOldModelAndMakeSureNoRelationship() throws Exception {
+ public void testPutGenericVnfWithModelInfoToMatchExistingModelAndCheckIfPrivateEdgeCreatedAndDoGetOnOldModelAndMakeSureNoRelationship()
+ throws Exception {
Map<String, String> genericVnfHashMap = new HashMap<>();
String genericVnf = "test-generic-" + UUID.randomUUID().toString();
@@ -109,16 +111,18 @@ public class PrivateEdgeIntegrationOldClientTest extends AAISetup {
genericVnfHashMap.put("model-version-id", modelVerId);
String genericVnfPayload = PayloadUtil.getTemplatePayload("generic-vnf.json", genericVnfHashMap);
- Response response = httpTestUtil.doPut("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayload);
+ Response response = httpTestUtil.doPut(
+ "/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayload);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is created", response.getStatus(), is(201));
- response = httpTestUtil.doGet("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf);
+ response = httpTestUtil.doGet("/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is created", response.getStatus(), is(200));
assertThat(response.getEntity().toString(), not(containsString("relationship-list")));
- List<Edge> edges = AAIGraph.getInstance().getGraph().newTransaction().traversal().E().has("private", true).toList();
+ List<Edge> edges =
+ AAIGraph.getInstance().getGraph().newTransaction().traversal().E().has("private", true).toList();
assertNotNull("List of edges should not be null", edges);
assertThat(edges.size(), is(1));
Edge oldEdge = edges.get(0);
@@ -130,7 +134,8 @@ public class PrivateEdgeIntegrationOldClientTest extends AAISetup {
assertThat(response.getEntity().toString(), not(containsString("relationship-list")));
String resourceVersion = JsonPath.read(response.getEntity().toString(), "$.resource-version");
- response = httpTestUtil.doDelete("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf, resourceVersion);
+ response = httpTestUtil.doDelete(
+ "/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf, resourceVersion);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is deleted", response.getStatus(), is(204));
diff --git a/aai-core/src/test/java/org/onap/aai/rest/PrivateEdgeIntegrationTest.java b/aai-core/src/test/java/org/onap/aai/rest/PrivateEdgeIntegrationTest.java
index b8709bdb..d3452153 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/PrivateEdgeIntegrationTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/PrivateEdgeIntegrationTest.java
@@ -17,11 +17,26 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.rest;
+import static junit.framework.TestCase.fail;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.jayway.jsonpath.JsonPath;
+
+import java.util.*;
+
+import javax.ws.rs.core.Response;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.janusgraph.core.JanusGraphTransaction;
@@ -37,18 +52,6 @@ import org.onap.aai.dbmap.AAIGraph;
import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.setup.SchemaVersion;
-import javax.ws.rs.core.Response;
-import java.util.*;
-
-import static junit.framework.TestCase.fail;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-
@RunWith(value = Parameterized.class)
public class PrivateEdgeIntegrationTest extends AAISetup {
@@ -67,18 +70,12 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
@Parameterized.Parameters(name = "QueryStyle.{0} Version.{1}")
public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][]{
- {QueryStyle.TRAVERSAL, new SchemaVersion("v10")},
- {QueryStyle.TRAVERSAL_URI, new SchemaVersion("v10")},
- {QueryStyle.TRAVERSAL, new SchemaVersion("v11")},
- {QueryStyle.TRAVERSAL_URI, new SchemaVersion("v11")},
- {QueryStyle.TRAVERSAL, new SchemaVersion("v12")},
- {QueryStyle.TRAVERSAL_URI, new SchemaVersion("v12")},
- {QueryStyle.TRAVERSAL, new SchemaVersion("v13")},
- {QueryStyle.TRAVERSAL_URI, new SchemaVersion("v13")},
- {QueryStyle.TRAVERSAL, new SchemaVersion("v14")},
- {QueryStyle.TRAVERSAL_URI, new SchemaVersion("v14")}
- });
+ return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL, new SchemaVersion("v10")},
+ {QueryStyle.TRAVERSAL_URI, new SchemaVersion("v10")}, {QueryStyle.TRAVERSAL, new SchemaVersion("v11")},
+ {QueryStyle.TRAVERSAL_URI, new SchemaVersion("v11")}, {QueryStyle.TRAVERSAL, new SchemaVersion("v12")},
+ {QueryStyle.TRAVERSAL_URI, new SchemaVersion("v12")}, {QueryStyle.TRAVERSAL, new SchemaVersion("v13")},
+ {QueryStyle.TRAVERSAL_URI, new SchemaVersion("v13")}, {QueryStyle.TRAVERSAL, new SchemaVersion("v14")},
+ {QueryStyle.TRAVERSAL_URI, new SchemaVersion("v14")}});
}
@Before
@@ -96,9 +93,10 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
Map<String, String> modelTemplateValues = new HashMap<>();
modelTemplateValues.put("model-invariant-id", modelId);
- String modelPayload = PayloadUtil.getTemplatePayload("model.json", modelTemplateValues);
+ String modelPayload = PayloadUtil.getTemplatePayload("model.json", modelTemplateValues);
- Response response = httpTestUtil.doPut("/aai/"+version.toString()+"/service-design-and-creation/models/model/" + modelId, modelPayload);
+ Response response = httpTestUtil.doPut(
+ "/aai/" + version.toString() + "/service-design-and-creation/models/model/" + modelId, modelPayload);
assertNotNull(response);
assertThat("Model was not successfully created", response.getStatus(), is(201));
@@ -108,9 +106,10 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
modelVersionTemplateValues.put("model-name", "some-model");
modelVersionTemplateValues.put("model-version", "testValue");
- String modelVersionPayload = PayloadUtil.getTemplatePayload("model-ver.json", modelVersionTemplateValues);
+ String modelVersionPayload = PayloadUtil.getTemplatePayload("model-ver.json", modelVersionTemplateValues);
- response = httpTestUtil.doPut("/aai/"+version.toString()+"/service-design-and-creation/models/model/" + modelId + "/model-vers/model-ver/" + modelVerId, modelVersionPayload);
+ response = httpTestUtil.doPut("/aai/" + version.toString() + "/service-design-and-creation/models/model/"
+ + modelId + "/model-vers/model-ver/" + modelVerId, modelVersionPayload);
assertNotNull(response);
assertThat("Model was not successfully created", response.getStatus(), is(201));
}
@@ -126,23 +125,26 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
genericVnfHashMap.put("model-version-id", modelVerId);
String genericVnfPayload = PayloadUtil.getTemplatePayload("generic-vnf.json", genericVnfHashMap);
- Response response = httpTestUtil.doPut("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayload);
+ Response response = httpTestUtil.doPut(
+ "/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayload);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is created", response.getStatus(), is(201));
- List<Edge> edges = AAIGraph.getInstance().getGraph().newTransaction().traversal().E().has("private", true).toList();
+ List<Edge> edges =
+ AAIGraph.getInstance().getGraph().newTransaction().traversal().E().has("private", true).toList();
assertNotNull("List of edges should not be null", edges);
assertThat(edges.size(), is(1));
Edge oldEdge = edges.get(0);
assertNotNull(oldEdge);
- response = httpTestUtil.doGet("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf);
+ response = httpTestUtil.doGet("/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is created", response.getStatus(), is(200));
assertThat(response.getEntity().toString(), not(containsString("relationship-list")));
String resourceVersion = JsonPath.read(response.getEntity().toString(), "$.resource-version");
- response = httpTestUtil.doDelete("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf, resourceVersion);
+ response = httpTestUtil.doDelete(
+ "/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf, resourceVersion);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is deleted", response.getStatus(), is(204));
@@ -152,7 +154,8 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
}
@Test
- public void testPutGenericVnfWithModelInfoToMatchExistingModelAndDoAnotherPutAndDontIncludeModelInfoAndPrivateEdgeShouldBeDeleted() throws Exception {
+ public void testPutGenericVnfWithModelInfoToMatchExistingModelAndDoAnotherPutAndDontIncludeModelInfoAndPrivateEdgeShouldBeDeleted()
+ throws Exception {
Map<String, String> genericVnfHashMap = new HashMap<>();
String genericVnf = "test-generic-" + UUID.randomUUID().toString();
@@ -162,34 +165,34 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
genericVnfHashMap.put("model-version-id", modelVerId);
String genericVnfPayload = PayloadUtil.getTemplatePayload("generic-vnf.json", genericVnfHashMap);
- Response response = httpTestUtil.doPut("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayload);
+ Response response = httpTestUtil.doPut(
+ "/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayload);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is created", response.getStatus(), is(201));
- response = httpTestUtil.doGet("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf);
+ response = httpTestUtil.doGet("/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is created", response.getStatus(), is(200));
assertThat(response.getEntity().toString(), not(containsString("relationship-list")));
- List<Edge> edges = AAIGraph.getInstance().getGraph().newTransaction().traversal().E().has("private", true).toList();
+ List<Edge> edges =
+ AAIGraph.getInstance().getGraph().newTransaction().traversal().E().has("private", true).toList();
assertNotNull("List of edges should not be null", edges);
assertThat(edges.size(), is(1));
Edge oldEdge = edges.get(0);
assertNotNull(oldEdge);
String resourceVersion = JsonPath.read(response.getEntity().toString(), "$.resource-version");
- String newGenericVnfPayload = "{\n" +
- " \"vnf-id\": \"" + genericVnf+ "\",\n" +
- " \"vnf-type\": \"someval\",\n" +
- " \"vnf-name\": \"someval\"\n," +
- " \"resource-version\": \"" + resourceVersion + "\"" +
- "}";
-
- response = httpTestUtil.doPut("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf, newGenericVnfPayload);
+ String newGenericVnfPayload = "{\n" + " \"vnf-id\": \"" + genericVnf + "\",\n"
+ + " \"vnf-type\": \"someval\",\n" + " \"vnf-name\": \"someval\"\n," + " \"resource-version\": \""
+ + resourceVersion + "\"" + "}";
+
+ response = httpTestUtil.doPut("/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf,
+ newGenericVnfPayload);
assertNotNull("Response returned from second put is null", response);
assertThat("Check the generic vnf is updated", response.getStatus(), is(200));
- response = httpTestUtil.doGet("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf);
+ response = httpTestUtil.doGet("/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf);
assertNotNull("Response returned from second put is null", response);
assertThat("Check the generic vnf is updated", response.getStatus(), is(200));
@@ -198,7 +201,8 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
assertThat("Expected the edges to be zero since updated with no model info", edges.size(), is(0));
resourceVersion = JsonPath.read(response.getEntity().toString(), "$.resource-version");
- response = httpTestUtil.doDelete("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf, resourceVersion);
+ response = httpTestUtil.doDelete(
+ "/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf, resourceVersion);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is deleted", response.getStatus(), is(204));
@@ -208,7 +212,8 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
}
@Test
- public void testPutGenericVnfWithModelInfoToMatchExistingModelAndCheckIfPrivateEdgeCreatedAndAlsoDoAnotherPutSameDataAndMakeSureEdgeIsStillThere() throws Exception {
+ public void testPutGenericVnfWithModelInfoToMatchExistingModelAndCheckIfPrivateEdgeCreatedAndAlsoDoAnotherPutSameDataAndMakeSureEdgeIsStillThere()
+ throws Exception {
Map<String, String> genericVnfHashMap = new HashMap<>();
String genericVnf = "test-generic-" + UUID.randomUUID().toString();
@@ -217,16 +222,18 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
genericVnfHashMap.put("model-version-id", modelVerId);
String genericVnfPayload = PayloadUtil.getTemplatePayload("generic-vnf.json", genericVnfHashMap);
- Response response = httpTestUtil.doPut("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayload);
+ Response response = httpTestUtil.doPut(
+ "/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayload);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is created", response.getStatus(), is(201));
- response = httpTestUtil.doGet("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf);
+ response = httpTestUtil.doGet("/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is created", response.getStatus(), is(200));
assertThat(response.getEntity().toString(), not(containsString("relationship-list")));
- List<Edge> edges = AAIGraph.getInstance().getGraph().newTransaction().traversal().E().has("private", true).toList();
+ List<Edge> edges =
+ AAIGraph.getInstance().getGraph().newTransaction().traversal().E().has("private", true).toList();
assertNotNull("List of edges should not be null", edges);
assertThat(edges.size(), is(1));
Edge oldEdge = edges.get(0);
@@ -234,13 +241,15 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
String resourceVersion = JsonPath.read(response.getEntity().toString(), "$.resource-version");
genericVnfHashMap.put("resource-version", resourceVersion);
- String genericVnfPayloadWithResource = PayloadUtil.getTemplatePayload("generic-vnf-resource.json", genericVnfHashMap);
+ String genericVnfPayloadWithResource =
+ PayloadUtil.getTemplatePayload("generic-vnf-resource.json", genericVnfHashMap);
- response = httpTestUtil.doPut("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayloadWithResource);
+ response = httpTestUtil.doPut("/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf,
+ genericVnfPayloadWithResource);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is updated", response.getStatus(), is(200));
- response = httpTestUtil.doGet("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf);
+ response = httpTestUtil.doGet("/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is created", response.getStatus(), is(200));
assertThat(response.getEntity().toString(), not(containsString("relationship-list")));
@@ -253,7 +262,8 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
assertNotNull(newEdge);
assertEquals(oldEdge, newEdge);
- response = httpTestUtil.doDelete("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf, resourceVersion);
+ response = httpTestUtil.doDelete(
+ "/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf, resourceVersion);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is deleted", response.getStatus(), is(204));
@@ -272,7 +282,8 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
genericVnfHashMap.put("model-version-id", "random-wrong-model-ver");
String genericVnfPayload = PayloadUtil.getTemplatePayload("generic-vnf.json", genericVnfHashMap);
- Response response = httpTestUtil.doPut("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayload);
+ Response response = httpTestUtil.doPut(
+ "/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayload);
assertNotNull("Response returned null", response);
String body = response.getEntity().toString();
@@ -286,14 +297,11 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
public void testPutGenericVnfWithModelMissingPartOfKeyReturnsBadRequest() throws Exception {
String genericVnf = "test-generic-" + UUID.randomUUID().toString();
- String genericVnfPayload = "{\n" +
- " \"vnf-id\": \"" + genericVnf + "\",\n" +
- " \"vnf-type\": \"someval\",\n" +
- " \"vnf-name\": \"someval\",\n" +
- " \"model-invariant-id\": \"some-model\"\n" +
- "}";
-
- Response response = httpTestUtil.doPut("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayload);
+ String genericVnfPayload = "{\n" + " \"vnf-id\": \"" + genericVnf + "\",\n" + " \"vnf-type\": \"someval\",\n"
+ + " \"vnf-name\": \"someval\",\n" + " \"model-invariant-id\": \"some-model\"\n" + "}";
+
+ Response response = httpTestUtil.doPut(
+ "/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayload);
assertNotNull("Response returned null", response);
String body = response.getEntity().toString();
@@ -303,7 +311,8 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
}
@Test
- public void testPutGenericVnfWithModelInfoToMatchExistingModelAndDeleteModelVerAndCheckIfPreventDeleteFailsWithBadRequest() throws Exception {
+ public void testPutGenericVnfWithModelInfoToMatchExistingModelAndDeleteModelVerAndCheckIfPreventDeleteFailsWithBadRequest()
+ throws Exception {
Map<String, String> genericVnfHashMap = new HashMap<>();
String genericVnf = "test-generic-" + UUID.randomUUID().toString();
@@ -313,28 +322,34 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
genericVnfHashMap.put("model-version-id", modelVerId);
String genericVnfPayload = PayloadUtil.getTemplatePayload("generic-vnf.json", genericVnfHashMap);
- Response response = httpTestUtil.doPut("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayload);
+ Response response = httpTestUtil.doPut(
+ "/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayload);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is created", response.getStatus(), is(201));
- List<Edge> edges = AAIGraph.getInstance().getGraph().newTransaction().traversal().E().has("private", true).toList();
+ List<Edge> edges =
+ AAIGraph.getInstance().getGraph().newTransaction().traversal().E().has("private", true).toList();
assertNotNull("List of edges should not be null", edges);
assertThat(edges.size(), is(1));
Edge oldEdge = edges.get(0);
assertNotNull(oldEdge);
- response = httpTestUtil.doGet("/aai/"+version.toString()+"/service-design-and-creation/models/model/" + modelId + "/model-vers/model-ver/" + modelVerId);
+ response = httpTestUtil.doGet("/aai/" + version.toString() + "/service-design-and-creation/models/model/"
+ + modelId + "/model-vers/model-ver/" + modelVerId);
assertNotNull(response);
assertThat(response.getStatus(), is(200));
String resourceVersion = JsonPath.read(response.getEntity().toString(), "$.resource-version");
- response = httpTestUtil.doDelete("/aai/"+version.toString()+"/service-design-and-creation/models/model/" + modelId + "/model-vers/model-ver/" + modelVerId, resourceVersion);
+ response = httpTestUtil.doDelete("/aai/" + version.toString() + "/service-design-and-creation/models/model/"
+ + modelId + "/model-vers/model-ver/" + modelVerId, resourceVersion);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is deleted", response.getStatus(), is(400));
- assertThat(response.getEntity().toString(), containsString(" Please clean up references from the following types [generic-vnf]"));
+ assertThat(response.getEntity().toString(),
+ containsString(" Please clean up references from the following types [generic-vnf]"));
}
@Test
- public void testPutWithGenericVnfToExistingModelAndUpdateWithNewModelInfoAndEdgeToOldModelShouldBeDeletedAndNewEdgeToNewModelShouldBeCreated() throws Exception {
+ public void testPutWithGenericVnfToExistingModelAndUpdateWithNewModelInfoAndEdgeToOldModelShouldBeDeletedAndNewEdgeToNewModelShouldBeCreated()
+ throws Exception {
Map<String, String> genericVnfHashMap = new HashMap<>();
String genericVnf = "test-generic-" + UUID.randomUUID().toString();
@@ -344,17 +359,19 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
genericVnfHashMap.put("model-version-id", modelVerId);
String genericVnfPayload = PayloadUtil.getTemplatePayload("generic-vnf.json", genericVnfHashMap);
- Response response = httpTestUtil.doPut("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayload);
+ Response response = httpTestUtil.doPut(
+ "/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayload);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is created", response.getStatus(), is(201));
- List<Edge> edges = AAIGraph.getInstance().getGraph().newTransaction().traversal().E().has("private", true).toList();
+ List<Edge> edges =
+ AAIGraph.getInstance().getGraph().newTransaction().traversal().E().has("private", true).toList();
assertNotNull("List of edges should not be null", edges);
assertThat(edges.size(), is(1));
Edge oldEdge = edges.get(0);
assertNotNull(oldEdge);
- response = httpTestUtil.doGet("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf);
+ response = httpTestUtil.doGet("/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is created", response.getStatus(), is(200));
assertThat(response.getEntity().toString(), not(containsString("relationship-list")));
@@ -370,9 +387,11 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
genericVnfHashMap.put("model-invariant-id", newModelId);
genericVnfHashMap.put("model-version-id", newModelVerId);
- String genericVnfPayloadWithResource = PayloadUtil.getTemplatePayload("generic-vnf-resource.json", genericVnfHashMap);
+ String genericVnfPayloadWithResource =
+ PayloadUtil.getTemplatePayload("generic-vnf-resource.json", genericVnfHashMap);
- response = httpTestUtil.doPut("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayloadWithResource);
+ response = httpTestUtil.doPut("/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf,
+ genericVnfPayloadWithResource);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is successfully updated based on new model", response.getStatus(), is(200));
@@ -383,13 +402,14 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
assertNotNull(newEdge);
assertNotEquals(oldEdge, newEdge);
- response = httpTestUtil.doGet("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf);
+ response = httpTestUtil.doGet("/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is created", response.getStatus(), is(200));
assertThat(response.getEntity().toString(), not(containsString("relationship-list")));
resourceVersion = JsonPath.read(response.getEntity().toString(), "$.resource-version");
- response = httpTestUtil.doDelete("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf, resourceVersion);
+ response = httpTestUtil.doDelete(
+ "/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf, resourceVersion);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is deleted", response.getStatus(), is(204));
@@ -399,7 +419,8 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
}
@Test
- public void testPutWithGenericVnfToExistingModelAndUpdateWithNewModelInfoThatDoesntExistAndCheckIfReturnsNotFoundAndOldEdgeShouldNotBeDeleted() throws Exception {
+ public void testPutWithGenericVnfToExistingModelAndUpdateWithNewModelInfoThatDoesntExistAndCheckIfReturnsNotFoundAndOldEdgeShouldNotBeDeleted()
+ throws Exception {
Map<String, String> genericVnfHashMap = new HashMap<>();
String genericVnf = "test-generic-" + UUID.randomUUID().toString();
@@ -409,17 +430,19 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
genericVnfHashMap.put("model-version-id", modelVerId);
String genericVnfPayload = PayloadUtil.getTemplatePayload("generic-vnf.json", genericVnfHashMap);
- Response response = httpTestUtil.doPut("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayload);
+ Response response = httpTestUtil.doPut(
+ "/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayload);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is created", response.getStatus(), is(201));
- List<Edge> edges = AAIGraph.getInstance().getGraph().newTransaction().traversal().E().has("private", true).toList();
+ List<Edge> edges =
+ AAIGraph.getInstance().getGraph().newTransaction().traversal().E().has("private", true).toList();
assertNotNull("List of edges should not be null", edges);
assertThat(edges.size(), is(1));
Edge oldEdge = edges.get(0);
assertNotNull(oldEdge);
- response = httpTestUtil.doGet("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf);
+ response = httpTestUtil.doGet("/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is created", response.getStatus(), is(200));
assertThat(response.getEntity().toString(), not(containsString("relationship-list")));
@@ -433,9 +456,11 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
genericVnfHashMap.put("model-invariant-id", newModelId);
genericVnfHashMap.put("model-version-id", newModelVerId);
- String genericVnfPayloadWithResource = PayloadUtil.getTemplatePayload("generic-vnf-resource.json", genericVnfHashMap);
+ String genericVnfPayloadWithResource =
+ PayloadUtil.getTemplatePayload("generic-vnf-resource.json", genericVnfHashMap);
- response = httpTestUtil.doPut("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayloadWithResource);
+ response = httpTestUtil.doPut("/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf,
+ genericVnfPayloadWithResource);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is failed due to missing model ver", response.getStatus(), is(404));
@@ -448,7 +473,8 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
}
@Test
- public void testPutWithGenericVnfToExistingModelAndUpdateVnfWithModelMissingPartOfKeyAndUpdateShouldFailAndOldEdgeShouldStillExist() throws Exception {
+ public void testPutWithGenericVnfToExistingModelAndUpdateVnfWithModelMissingPartOfKeyAndUpdateShouldFailAndOldEdgeShouldStillExist()
+ throws Exception {
Map<String, String> genericVnfHashMap = new HashMap<>();
String genericVnf = "test-generic-" + UUID.randomUUID().toString();
@@ -458,17 +484,19 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
genericVnfHashMap.put("model-version-id", modelVerId);
String genericVnfPayload = PayloadUtil.getTemplatePayload("generic-vnf.json", genericVnfHashMap);
- Response response = httpTestUtil.doPut("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayload);
+ Response response = httpTestUtil.doPut(
+ "/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayload);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is created", response.getStatus(), is(201));
- List<Edge> edges = AAIGraph.getInstance().getGraph().newTransaction().traversal().E().has("private", true).toList();
+ List<Edge> edges =
+ AAIGraph.getInstance().getGraph().newTransaction().traversal().E().has("private", true).toList();
assertNotNull("List of edges should not be null", edges);
assertThat(edges.size(), is(1));
Edge oldEdge = edges.get(0);
assertNotNull(oldEdge);
- response = httpTestUtil.doGet("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf);
+ response = httpTestUtil.doGet("/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is created", response.getStatus(), is(200));
assertThat(response.getEntity().toString(), not(containsString("relationship-list")));
@@ -484,15 +512,12 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
genericVnfHashMap.put("model-invariant-id", newModelId);
genericVnfHashMap.put("model-version-id", newModelVerId);
- String genericVnfPayloadWithResource = "{\n" +
- " \"vnf-id\": \"" + genericVnf + "\",\n" +
- " \"vnf-type\": \"someval\",\n" +
- " \"vnf-name\": \"someval\",\n" +
- " \"model-invariant-id\": \"" + newModelId + "\",\n" +
- " \"resource-version\": \"${resource-version}\"\n" +
- "}";
+ String genericVnfPayloadWithResource = "{\n" + " \"vnf-id\": \"" + genericVnf + "\",\n"
+ + " \"vnf-type\": \"someval\",\n" + " \"vnf-name\": \"someval\",\n" + " \"model-invariant-id\": \""
+ + newModelId + "\",\n" + " \"resource-version\": \"${resource-version}\"\n" + "}";
- response = httpTestUtil.doPut("/aai/"+version.toString()+"/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayloadWithResource);
+ response = httpTestUtil.doPut("/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf,
+ genericVnfPayloadWithResource);
assertNotNull("Response returned null", response);
assertThat("Check the generic vnf is failed due to missing model ver", response.getStatus(), is(400));
assertThat(response.getEntity().toString(), containsString("model-invariant-id requires model-version-id"));
@@ -506,7 +531,8 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
}
@Test
- public void testPutCustomerWithServiceInstanceThatHasModelVerThatExistsInDbAndDoGetOnCustomerAndCheckIfRelationshipIsNotThere() throws Exception {
+ public void testPutCustomerWithServiceInstanceThatHasModelVerThatExistsInDbAndDoGetOnCustomerAndCheckIfRelationshipIsNotThere()
+ throws Exception {
Map<String, String> customerHashMap = new HashMap<>();
@@ -517,40 +543,36 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
customerHashMap.put("model-version-id", modelVerId);
String customer = PayloadUtil.getTemplatePayload("customer.json", customerHashMap);
- Response response = httpTestUtil.doPut("/aai/"+version.toString()+"/business/customers/customer/" + customerHashMap.get("global-customer-id"), customer);
+ Response response = httpTestUtil.doPut("/aai/" + version.toString() + "/business/customers/customer/"
+ + customerHashMap.get("global-customer-id"), customer);
assertNotNull("Response returned null", response);
assertThat("Check the cloud region is created with link to generic vnf", response.getStatus(), is(201));
- List<Edge> edges = AAIGraph.getInstance().getGraph().newTransaction().traversal().E().has("private", true).toList();
+ List<Edge> edges =
+ AAIGraph.getInstance().getGraph().newTransaction().traversal().E().has("private", true).toList();
assertNotNull("List of edges should not be null", edges);
assertThat(edges.size(), is(1));
Edge oldEdge = edges.get(0);
assertNotNull(oldEdge);
- response = httpTestUtil.doGet("/aai/"+version.toString()+"/business/customers/customer/" + customerHashMap.get("global-customer-id"));
+ response = httpTestUtil.doGet("/aai/" + version.toString() + "/business/customers/customer/"
+ + customerHashMap.get("global-customer-id"));
assertNotNull("Response returned null", response);
assertThat("Check the customer is returned", response.getStatus(), is(200));
assertThat(response.getEntity().toString(), not(containsString("\"related-to\":\"model-ver\"")));
- String url = "/aai/" + version + "/business/customers/customer/" + customerHashMap.get("global-customer-id") + "/service-subscriptions/service-subscription/" + customerHashMap.get("subscription-type") + "/service-instances/service-instance/"+ customerHashMap.get("service-instance-id");
+ String url = "/aai/" + version + "/business/customers/customer/" + customerHashMap.get("global-customer-id")
+ + "/service-subscriptions/service-subscription/" + customerHashMap.get("subscription-type")
+ + "/service-instances/service-instance/" + customerHashMap.get("service-instance-id");
String genericVnf = "vnf-" + UUID.randomUUID().toString();
- String genericVnfPayload = "{\n" +
- " \"vnf-id\": \"" + genericVnf + "\",\n" +
- " \"vnf-type\": \"someval\",\n" +
- " \"vnf-name\": \"someval\",\n" +
- " \"relationship-list\": {\n" +
- " \"relationship\": [\n" +
- " {\n" +
- " \"related-to\": \"service-instance\",\n" +
- " \"related-link\": \"" + url + "\"\n" +
- " }\n" +
- " ]\n" +
- " }\n" +
- "}\n";
-
-
- response = httpTestUtil.doPut("/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf, genericVnfPayload);
+ String genericVnfPayload = "{\n" + " \"vnf-id\": \"" + genericVnf + "\",\n" + " \"vnf-type\": \"someval\",\n"
+ + " \"vnf-name\": \"someval\",\n" + " \"relationship-list\": {\n" + " \"relationship\": [\n"
+ + " {\n" + " \"related-to\": \"service-instance\",\n" + " \"related-link\": \"" + url
+ + "\"\n" + " }\n" + " ]\n" + " }\n" + "}\n";
+
+ response = httpTestUtil.doPut("/aai/" + version.toString() + "/network/generic-vnfs/generic-vnf/" + genericVnf,
+ genericVnfPayload);
assertNotNull("Response returned null", response);
assertThat("Check the customer is returned", response.getStatus(), is(201));
@@ -559,7 +581,8 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
assertThat("Check the customer is returned", response.getStatus(), is(200));
assertThat(response.getEntity().toString(), containsString("\"related-to\":\"service-instance\""));
- response = httpTestUtil.doGet("/aai/"+version.toString()+"/business/customers/customer/" + customerHashMap.get("global-customer-id"));
+ response = httpTestUtil.doGet("/aai/" + version.toString() + "/business/customers/customer/"
+ + customerHashMap.get("global-customer-id"));
assertNotNull("Response returned null", response);
assertThat("Check the customer is returned", response.getStatus(), is(200));
assertThat(response.getEntity().toString(), not(containsString("\"related-to\":\"model-ver\"")));
@@ -568,7 +591,7 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
}
@After
- public void tearDown(){
+ public void tearDown() {
JanusGraphTransaction transaction = AAIGraph.getInstance().getGraph().newTransaction();
boolean success = true;
@@ -577,15 +600,13 @@ public class PrivateEdgeIntegrationTest extends AAISetup {
GraphTraversalSource g = transaction.traversal();
- g.V().has("source-of-truth", "JUNIT")
- .toList()
- .forEach(v -> v.remove());
+ g.V().has("source-of-truth", "JUNIT").toList().forEach(v -> v.remove());
- } catch(Exception ex){
+ } catch (Exception ex) {
success = false;
logger.error("Unable to remove the vertexes", ex);
} finally {
- if(success){
+ if (success) {
transaction.commit();
} else {
transaction.rollback();
diff --git a/aai-core/src/test/java/org/onap/aai/rest/PserverDuplicateTest.java b/aai-core/src/test/java/org/onap/aai/rest/PserverDuplicateTest.java
index f0618b02..5fe3bd00 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/PserverDuplicateTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/PserverDuplicateTest.java
@@ -17,10 +17,27 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.rest;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
+
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import javax.ws.rs.core.Response;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.janusgraph.core.JanusGraph;
@@ -33,20 +50,6 @@ import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.dbmap.AAIGraph;
import org.onap.aai.serialization.engines.QueryStyle;
-import javax.ws.rs.core.Response;
-import java.util.List;
-import java.util.UUID;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
-
public class PserverDuplicateTest extends AAISetup {
private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(PserverDuplicateTest.class);
@@ -59,7 +62,7 @@ public class PserverDuplicateTest extends AAISetup {
hostname = getHostname();
final String aaiUri = "/cloud-infrastructure/pservers/pserver/" + hostname;
- final int threads = getNumberOfThreads();
+ final int threads = getNumberOfThreads();
ExecutorService service = Executors.newFixedThreadPool(threads);
@@ -67,27 +70,21 @@ public class PserverDuplicateTest extends AAISetup {
// Due to the lazy instantiation of the graph, it needs to create a new transaction to create schema
janusGraph.newTransaction().rollback();
- service.invokeAll(
- IntStream.range(0, threads)
- .mapToObj((i) -> (Callable<Void>) () -> {
- JanusGraphTransaction transaction = janusGraph.newTransaction();
- GraphTraversalSource g = transaction.traversal();
- try {
- g.addV()
- .property(AAIProperties.AAI_URI, aaiUri)
- .property(AAIProperties.NODE_TYPE, "pserver")
- .property("hostname", hostname)
- .next();
- transaction.commit();
- } catch (Exception e) {
- throw new Exception("Duplicate was found, error");
- }
- return null;
- }).collect(Collectors.toList())
- , 7, TimeUnit.SECONDS
- );
+ service.invokeAll(IntStream.range(0, threads).mapToObj((i) -> (Callable<Void>) () -> {
+ JanusGraphTransaction transaction = janusGraph.newTransaction();
+ GraphTraversalSource g = transaction.traversal();
+ try {
+ g.addV().property(AAIProperties.AAI_URI, aaiUri).property(AAIProperties.NODE_TYPE, "pserver")
+ .property("hostname", hostname).next();
+ transaction.commit();
+ } catch (Exception e) {
+ throw new Exception("Duplicate was found, error");
+ }
+ return null;
+ }).collect(Collectors.toList()), 7, TimeUnit.SECONDS);
- JanusGraphTransaction readOnlyTransaction = AAIGraph.getInstance().getGraph().buildTransaction().readOnly().start();
+ JanusGraphTransaction readOnlyTransaction =
+ AAIGraph.getInstance().getGraph().buildTransaction().readOnly().start();
GraphTraversalSource g = readOnlyTransaction.traversal();
List<Vertex> pserverList = g.V().has(AAIProperties.AAI_URI, aaiUri).toList();
@@ -95,22 +92,21 @@ public class PserverDuplicateTest extends AAISetup {
testUtil = new HttpTestUtil(QueryStyle.TRAVERSAL_URI);
- if(pserverList.size() == 1){
+ if (pserverList.size() == 1) {
return false;
}
return true;
}
-
@Ignore
public void testWhenDuplicatesExistInGraphThatGetAllSuceeds() throws InterruptedException {
int totalRetries = getNumOfRetries();
- for(int retry = 0; retry < totalRetries; retry++){
- if(!this.createDuplicate()){
- if(retry == (totalRetries-1)){
- fail("Unable to produce duplicates in the graph, " +
- "please increase retry or ignore test if it becomes impossible to create duplicate this test");
+ for (int retry = 0; retry < totalRetries; retry++) {
+ if (!this.createDuplicate()) {
+ if (retry == (totalRetries - 1)) {
+ fail("Unable to produce duplicates in the graph, "
+ + "please increase retry or ignore test if it becomes impossible to create duplicate this test");
}
} else {
// Successfully created a duplicate in the janus graph
@@ -121,20 +117,20 @@ public class PserverDuplicateTest extends AAISetup {
String endpoint = "/aai/v14/cloud-infrastructure/pservers";
Response response = testUtil.doGet(endpoint, null);
- LOGGER.info("GET ALL Pservers with duplicates status code {} and body {}", response.getStatus(), response.getEntity());
+ LOGGER.info("GET ALL Pservers with duplicates status code {} and body {}", response.getStatus(),
+ response.getEntity());
assertThat(response.getStatus(), is(200));
}
- public String getHostname(){
+ public String getHostname() {
return UUID.randomUUID().toString();
}
- public int getNumOfRetries(){
+ public int getNumOfRetries() {
return 10;
}
- public int getNumberOfThreads(){
- return 10;
+ public int getNumberOfThreads() {
+ return 10;
}
}
-
diff --git a/aai-core/src/test/java/org/onap/aai/rest/PserverTest.java b/aai-core/src/test/java/org/onap/aai/rest/PserverTest.java
index f7bea7c3..8ede3c32 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/PserverTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/PserverTest.java
@@ -17,11 +17,23 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.rest;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.jayway.jsonpath.JsonPath;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.core.Response;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -30,23 +42,13 @@ import org.onap.aai.AAISetup;
import org.onap.aai.HttpTestUtil;
import org.onap.aai.PayloadUtil;
import org.onap.aai.introspection.*;
-
import org.onap.aai.serialization.engines.QueryStyle;
import org.skyscreamer.jsonassert.JSONAssert;
import org.springframework.test.annotation.DirtiesContext;
-import javax.ws.rs.core.Response;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
@RunWith(value = Parameterized.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
-public class PserverTest extends AAISetup{
+public class PserverTest extends AAISetup {
private static EELFLogger logger = EELFManager.getInstance().getLogger(PserverTest.class);
private HttpTestUtil httpTestUtil;
@@ -57,15 +59,11 @@ public class PserverTest extends AAISetup{
@Parameterized.Parameters(name = "QueryStyle.{0}")
public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][]{
- {QueryStyle.TRAVERSAL},
- {QueryStyle.TRAVERSAL_URI}
- });
+ return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
}
-
@Before
- public void setUp(){
+ public void setUp() {
httpTestUtil = new HttpTestUtil(queryStyle);
relationshipMap = new HashMap<>();
}
@@ -103,7 +101,8 @@ public class PserverTest extends AAISetup{
response = httpTestUtil.doPut(cloudRegionUri, "{}");
assertNotNull("Expected the response to be not null", response);
assertEquals("Expect the cloud region to be created", 201, response.getStatus());
- logger.info("Successfully able to create the cloud region with payload that has no keys to be retrieved from uri");
+ logger.info(
+ "Successfully able to create the cloud region with payload that has no keys to be retrieved from uri");
response = httpTestUtil.doGet(cloudRegionUri);
assertNotNull("Expected the response to be not null", response);
@@ -120,7 +119,7 @@ public class PserverTest extends AAISetup{
assertEquals("Expect the cloud region relationship to pserver to be created", 200, response.getStatus());
logger.info("Successfully created the relationship between cloud region and pserver");
- response = httpTestUtil.doGet(cloudRegionUri);
+ response = httpTestUtil.doGet(cloudRegionUri);
assertNotNull("Expected the response to be not null", response);
assertEquals("Expect the cloud region to be created", 200, response.getStatus());
logger.info("Successfully retrieved the cloud region from db");
diff --git a/aai-core/src/test/java/org/onap/aai/rest/RestHandlerTest.java b/aai-core/src/test/java/org/onap/aai/rest/RestHandlerTest.java
index c25e2929..cba81d73 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/RestHandlerTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/RestHandlerTest.java
@@ -19,6 +19,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.rest;
import static org.junit.Assert.*;
@@ -30,11 +31,11 @@ public class RestHandlerTest {
@Test
public void testGetInstance() {
- RestHandlerService firstInstance = RestHandlerService.getInstance();
- RestHandlerService secondInstance = RestHandlerService.getInstance();
- assertNotNull(firstInstance);
- assertNotNull(secondInstance);
- assertTrue(firstInstance == secondInstance);
+ RestHandlerService firstInstance = RestHandlerService.getInstance();
+ RestHandlerService secondInstance = RestHandlerService.getInstance();
+ assertNotNull(firstInstance);
+ assertNotNull(secondInstance);
+ assertTrue(firstInstance == secondInstance);
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/rest/TenantTest.java b/aai-core/src/test/java/org/onap/aai/rest/TenantTest.java
index e031a326..f8172b02 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/TenantTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/TenantTest.java
@@ -17,9 +17,17 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.rest;
+import static org.junit.Assert.assertEquals;
+
import com.jayway.jsonpath.JsonPath;
+
+import java.util.*;
+
+import javax.ws.rs.core.Response;
+
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Ignore;
@@ -35,11 +43,6 @@ import org.skyscreamer.jsonassert.JSONAssert;
import org.springframework.test.context.junit4.rules.SpringClassRule;
import org.springframework.test.context.junit4.rules.SpringMethodRule;
-import javax.ws.rs.core.Response;
-import java.util.*;
-
-import static org.junit.Assert.assertEquals;
-
@RunWith(value = Parameterized.class)
public class TenantTest extends AAISetup {
@@ -50,20 +53,17 @@ public class TenantTest extends AAISetup {
@Rule
public final SpringMethodRule springMethodRule = new SpringMethodRule();
-
+
@Parameterized.Parameter(value = 0)
public QueryStyle queryStyle;
@Parameterized.Parameters(name = "QueryStyle.{0}")
public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][]{
- {QueryStyle.TRAVERSAL},
- {QueryStyle.TRAVERSAL_URI}
- });
+ return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
}
@Before
- public void setUp(){
+ public void setUp() {
httpTestUtil = new HttpTestUtil(queryStyle);
templateValuesMap = new HashMap<>();
}
@@ -79,32 +79,30 @@ public class TenantTest extends AAISetup {
String cloudRegionPayload = PayloadUtil.getTemplatePayload("cloud-region.json", templateValuesMap);
String cloudRegionUri = String.format("/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/%s/%s",
- templateValuesMap.get("cloud-owner"),
- templateValuesMap.get("cloud-region-id")
- );
+ templateValuesMap.get("cloud-owner"), templateValuesMap.get("cloud-region-id"));
String tenantUri = cloudRegionUri + "/tenants/tenant/" + templateValuesMap.get("tenant-id");
String tenantPayload = PayloadUtil.getTemplatePayload("tenant.json", templateValuesMap);
- Response response = httpTestUtil.doPut(cloudRegionUri, cloudRegionPayload);
+ Response response = httpTestUtil.doPut(cloudRegionUri, cloudRegionPayload);
assertEquals("Expected the cloud region to be created", 201, response.getStatus());
- response = httpTestUtil.doGet(tenantUri);
+ response = httpTestUtil.doGet(tenantUri);
assertEquals("Expected the cloud region to be created", 200, response.getStatus());
String responseStr = response.getEntity().toString();
JSONAssert.assertEquals(tenantPayload, responseStr, false);
String resourceVersion = JsonPath.read(responseStr, "$.resource-version");
- response = httpTestUtil.doDelete(tenantUri, resourceVersion);
+ response = httpTestUtil.doDelete(tenantUri, resourceVersion);
assertEquals("Expected the cloud region to be created", 204, response.getStatus());
- response = httpTestUtil.doGet(cloudRegionUri);
+ response = httpTestUtil.doGet(cloudRegionUri);
assertEquals("Expected the cloud region to be created", 200, response.getStatus());
responseStr = response.getEntity().toString();
resourceVersion = JsonPath.read(responseStr, "$.resource-version");
- response = httpTestUtil.doDelete(cloudRegionUri, resourceVersion);
+ response = httpTestUtil.doDelete(cloudRegionUri, resourceVersion);
assertEquals("Expected the cloud region to be created", 204, response.getStatus());
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/rest/VipAddressListTest.java b/aai-core/src/test/java/org/onap/aai/rest/VipAddressListTest.java
index 0351c2c3..354b030b 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/VipAddressListTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/VipAddressListTest.java
@@ -17,9 +17,19 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.rest;
+import static org.junit.Assert.assertEquals;
+
import com.jayway.jsonpath.JsonPath;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+
+import javax.ws.rs.core.Response;
+
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -32,13 +42,6 @@ import org.onap.aai.exceptions.AAIException;
import org.onap.aai.serialization.engines.QueryStyle;
import org.skyscreamer.jsonassert.JSONAssert;
-import javax.ws.rs.core.Response;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collection;
-
-import static org.junit.Assert.assertEquals;
-
@RunWith(value = Parameterized.class)
public class VipAddressListTest extends AAISetup {
@@ -49,13 +52,11 @@ public class VipAddressListTest extends AAISetup {
@Parameterized.Parameters(name = "QueryStyle.{0}")
public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][]{
- {QueryStyle.TRAVERSAL_URI}
- });
+ return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL_URI}});
}
@Before
- public void setUp(){
+ public void setUp() {
httpTestUtil = new HttpTestUtil(queryStyle);
}
@@ -63,9 +64,10 @@ public class VipAddressListTest extends AAISetup {
public void testPutWithAllCloudRegionChildrenNodesAndCheckIfDeleteIsSuccessful() throws IOException, AAIException {
String cloudRegionPayload = PayloadUtil.getResourcePayload("cloud-region.json");
- String cloudRegionUri = "/aai/v14/cloud-infrastructure/cloud-regions/cloud-region/cloud-region-owner-with-vip-ipv4/cloud-region-id-with-vip-ipv4";
+ String cloudRegionUri =
+ "/aai/v14/cloud-infrastructure/cloud-regions/cloud-region/cloud-region-owner-with-vip-ipv4/cloud-region-id-with-vip-ipv4";
- Response response = httpTestUtil.doPut(cloudRegionUri, cloudRegionPayload);
+ Response response = httpTestUtil.doPut(cloudRegionUri, cloudRegionPayload);
assertEquals("Expected the cloud region to be created", 201, response.getStatus());
response = httpTestUtil.doGet(cloudRegionUri);
@@ -77,7 +79,7 @@ public class VipAddressListTest extends AAISetup {
String vipIpv4Uri = cloudRegionUri + "/vip-ipv4-address-list/vip-ipv4-address-list-1";
String vipIpv4Payload = PayloadUtil.getResourcePayload("vip-ipv4-address-list.json");
- response = httpTestUtil.doPut(vipIpv4Uri, vipIpv4Payload);
+ response = httpTestUtil.doPut(vipIpv4Uri, vipIpv4Payload);
assertEquals("Expected the ipv4 address list to be created", 201, response.getStatus());
response = httpTestUtil.doGet(vipIpv4Uri);
diff --git a/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java b/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java
index 6e72a0f1..c01d270e 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java
@@ -17,10 +17,26 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
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;
@@ -44,20 +60,6 @@ import org.onap.aai.serialization.engines.QueryStyle;
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 {
@@ -71,7 +73,6 @@ public class HttpEntryTest extends AAISetup {
VALID_HTTP_STATUS_CODES.add(201);
VALID_HTTP_STATUS_CODES.add(204);
}
-
@Parameterized.Parameter(value = 0)
public QueryStyle queryStyle;
@@ -81,10 +82,7 @@ public class HttpEntryTest extends AAISetup {
*/
@Parameterized.Parameters(name = "QueryStyle.{0}")
public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][]{
- {QueryStyle.TRAVERSAL},
- {QueryStyle.TRAVERSAL_URI}
- });
+ return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
}
private HttpHeaders httpHeaders;
@@ -99,13 +97,13 @@ public class HttpEntryTest extends AAISetup {
private List<MediaType> outputMediaTypes;
@Before
- public void setup(){
+ public void setup() {
- httpHeaders = Mockito.mock(HttpHeaders.class);
- uriInfo = Mockito.mock(UriInfo.class);
+ httpHeaders = Mockito.mock(HttpHeaders.class);
+ uriInfo = Mockito.mock(UriInfo.class);
- headersMultiMap = new MultivaluedHashMap<>();
- queryParameters = Mockito.spy(new MultivaluedHashMap<>());
+ headersMultiMap = new MultivaluedHashMap<>();
+ queryParameters = Mockito.spy(new MultivaluedHashMap<>());
headersMultiMap.add("X-FromAppId", "JUNIT");
headersMultiMap.add("X-TransactionId", UUID.randomUUID().toString());
@@ -124,7 +122,6 @@ public class HttpEntryTest extends AAISetup {
when(httpHeaders.getRequestHeader("aai-request-context")).thenReturn(aaiRequestContextList);
-
when(uriInfo.getQueryParameters()).thenReturn(queryParameters);
when(uriInfo.getQueryParameters(false)).thenReturn(queryParameters);
@@ -134,7 +131,8 @@ public class HttpEntryTest extends AAISetup {
when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON);
}
- private Response doRequest(HttpEntry httpEntry, Loader loader, TransactionalGraphEngine dbEngine, HttpMethod method, String uri, String content) throws UnsupportedEncodingException, AAIException {
+ private Response doRequest(HttpEntry httpEntry, Loader loader, TransactionalGraphEngine dbEngine, HttpMethod method,
+ String uri, String content) throws UnsupportedEncodingException, AAIException {
URI uriObject = UriBuilder.fromPath(uri).build();
QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject);
String objType = uriQuery.getResultType();
@@ -155,11 +153,10 @@ public class HttpEntryTest extends AAISetup {
List<DBRequest> dbRequestList = new ArrayList<>();
dbRequestList.add(dbRequest);
- Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = httpEntry.process(dbRequestList, "JUNIT");
+ Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = httpEntry.process(dbRequestList, "JUNIT");
return responsesTuple.getValue1().get(0).getValue1();
}
-
@Test
public void test1PutOnPserver() throws UnsupportedEncodingException, AAIException {
@@ -171,7 +168,6 @@ public class HttpEntryTest extends AAISetup {
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
-
String uri = "/cloud-infrastructure/pservers/pserver/junit-test1";
String content = "{\"hostname\":\"junit-test1\"}";
Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
@@ -195,33 +191,30 @@ public class HttpEntryTest extends AAISetup {
}
@Test
- public void test3PutOnPInterface() {
+ public void test3PutOnPInterface() {
try {
- DBConnectionType type = DBConnectionType.REALTIME;
- traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
- Loader loader = traversalHttpEntry.getLoader();
- TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
-
- String uri = "/cloud-infrastructure/pservers/pserver/junit-test1/p-interfaces/p-interface/p1";
- String content = "{\"interface-name\":\"p1\"}";
- Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
- dbEngine.commit();
- assertEquals("Expected the p-interface to be created", 201, response.getStatus());
+ DBConnectionType type = DBConnectionType.REALTIME;
+ traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
+ Loader loader = traversalHttpEntry.getLoader();
+ TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
+
+ String uri = "/cloud-infrastructure/pservers/pserver/junit-test1/p-interfaces/p-interface/p1";
+ String content = "{\"interface-name\":\"p1\"}";
+ Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
+ dbEngine.commit();
+ assertEquals("Expected the p-interface to be created", 201, response.getStatus());
} catch (UnsupportedEncodingException | AAIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
-
-
@Test
public void test4GetOnPserver() throws UnsupportedEncodingException, AAIException {
DBConnectionType type = DBConnectionType.REALTIME;
traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
-
-
+
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
@@ -233,13 +226,13 @@ public class HttpEntryTest extends AAISetup {
dbEngine.commit();
assertEquals("Expected the pserver to be returned", 200, response.getStatus());
}
-
+
@Test
public void test5MergePatchOnPserver() throws UnsupportedEncodingException, AAIException {
DBConnectionType type = DBConnectionType.REALTIME;
traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
-
+
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
@@ -249,8 +242,9 @@ public class HttpEntryTest extends AAISetup {
dbEngine.commit();
assertEquals("Expected the pserver to be updated", 200, response.getStatus());
}
-
- private int doDelete(String resourceVersion, String uri, String nodeType) throws UnsupportedEncodingException, AAIException {
+
+ 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);
@@ -265,23 +259,21 @@ public class HttpEntryTest extends AAISetup {
Introspector obj = loader.introspectorFromName(nodeType);
- DBRequest dbRequest =
- new DBRequest.Builder(HttpMethod.DELETE, uriObject, uriQuery, obj, httpHeaders, uriInfo, "JUNIT-TRANSACTION")
- .rawRequestContent(content).build();
+ DBRequest dbRequest = new DBRequest.Builder(HttpMethod.DELETE, uriObject, uriQuery, obj, httpHeaders, uriInfo,
+ "JUNIT-TRANSACTION").rawRequestContent(content).build();
List<DBRequest> dbRequestList = new ArrayList<>();
dbRequestList.add(dbRequest);
- Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = traversalHttpEntry.process(dbRequestList, "JUNIT");
+ Pair<Boolean, List<Pair<URI, Response>>> responsesTuple = traversalHttpEntry.process(dbRequestList, "JUNIT");
Response response = responsesTuple.getValue1().get(0).getValue1();
dbEngine.commit();
return response.getStatus();
}
-
+
@Test
public void test6DeleteOnPserver() throws UnsupportedEncodingException, AAIException {
-
DBConnectionType type = DBConnectionType.REALTIME;
traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
Loader loader = traversalHttpEntry.getLoader();
@@ -295,19 +287,19 @@ public class HttpEntryTest extends AAISetup {
String msg = response.getEntity().toString();
JsonObject jsonObj = new JsonParser().parse(msg).getAsJsonObject();
String resourceVersion = "";
- if ( jsonObj.isJsonObject()) {
+ if (jsonObj.isJsonObject()) {
resourceVersion = jsonObj.get("resource-version").getAsString();
}
- assertEquals("Expected the pserver to be deleted", 204, doDelete(resourceVersion, "/cloud-infrastructure/pservers/pserver/junit-test1", "pserver"));
+ assertEquals("Expected the pserver to be deleted", 204,
+ doDelete(resourceVersion, "/cloud-infrastructure/pservers/pserver/junit-test1", "pserver"));
}
@Test
public void test7DeleteOnPserverNoPinterface() throws UnsupportedEncodingException, AAIException {
-
DBConnectionType type = DBConnectionType.REALTIME;
traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
- //HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, queryStyle, type);
+ // HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, queryStyle, type);
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
@@ -318,19 +310,19 @@ public class HttpEntryTest extends AAISetup {
String msg = response.getEntity().toString();
JsonObject jsonObj = new JsonParser().parse(msg).getAsJsonObject();
String resourceVersion = "";
- if ( jsonObj.isJsonObject()) {
+ if (jsonObj.isJsonObject()) {
resourceVersion = jsonObj.get("resource-version").getAsString();
}
- assertEquals("Expected the pserver to be deleted", 204, doDelete(resourceVersion, "/cloud-infrastructure/pservers/pserver/junit-test2", "pserver"));
+ assertEquals("Expected the pserver to be deleted", 204,
+ doDelete(resourceVersion, "/cloud-infrastructure/pservers/pserver/junit-test2", "pserver"));
}
-
@Test
public void test8FailedGetOnPserver() throws UnsupportedEncodingException, AAIException {
DBConnectionType type = DBConnectionType.REALTIME;
traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
- //HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, queryStyle, type);
+ // HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, queryStyle, type);
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
@@ -347,51 +339,54 @@ public class HttpEntryTest extends AAISetup {
DBConnectionType type = DBConnectionType.REALTIME;
traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
- //HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, queryStyle, type);
+ // HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, queryStyle, type);
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
- //Put pserver
+ // Put pserver
String uri = "/cloud-infrastructure/pservers/pserver/junit-edge-test-pserver";
String content = "{\"hostname\":\"junit-edge-test-pserver\"}";
doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
- //Put complex
+ // Put complex
uri = "/cloud-infrastructure/complexes/complex/junit-edge-test-complex";
- content = "{\"physical-location-id\":\"junit-edge-test-complex\",\"physical-location-type\":\"AAIDefault\",\"street1\":\"AAIDefault\",\"city\":\"AAIDefault\",\"state\":\"NJ\",\"postal-code\":\"07748\",\"country\":\"USA\",\"region\":\"US\"}";
+ content =
+ "{\"physical-location-id\":\"junit-edge-test-complex\",\"physical-location-type\":\"AAIDefault\",\"street1\":\"AAIDefault\",\"city\":\"AAIDefault\",\"state\":\"NJ\",\"postal-code\":\"07748\",\"country\":\"USA\",\"region\":\"US\"}";
doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
- //PutEdge
+ // PutEdge
uri = "/cloud-infrastructure/complexes/complex/junit-edge-test-complex/relationship-list/relationship";
- content = "{\"related-to\":\"pserver\",\"related-link\":\"/aai/" + schemaVersions.getDefaultVersion().toString() + "/cloud-infrastructure/pservers/pserver/junit-edge-test-pserver\",\"relationship-label\":\"org.onap.relationships.inventory.LocatedIn\"}";
+ content = "{\"related-to\":\"pserver\",\"related-link\":\"/aai/" + schemaVersions.getDefaultVersion().toString()
+ + "/cloud-infrastructure/pservers/pserver/junit-edge-test-pserver\",\"relationship-label\":\"org.onap.relationships.inventory.LocatedIn\"}";
Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT_EDGE, uri, content);
dbEngine.rollback();
- assertEquals("Expected the pserver relationship to be created", 200, response.getStatus());
+ assertEquals("Expected the pserver relationship to be created", 200, response.getStatus());
}
-
@Test
public void notificationOnRelatedToTest() throws UnsupportedEncodingException, AAIException {
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(), type, uebNotification);
+
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
- //Put pserver
+ // Put pserver
String uri = "/cloud-infrastructure/pservers/pserver/junit-edge-test-pserver";
String content = "{\"hostname\":\"junit-edge-test-pserver\"}";
doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
- //Put complex
+ // Put complex
uri = "/cloud-infrastructure/complexes/complex/junit-edge-test-complex";
- content = "{\"physical-location-id\":\"junit-edge-test-complex\",\"physical-location-type\":\"AAIDefault\",\"street1\":\"AAIDefault\",\"city\":\"AAIDefault\",\"state\":\"NJ\",\"postal-code\":\"07748\",\"country\":\"USA\",\"region\":\"US\"}";
+ content =
+ "{\"physical-location-id\":\"junit-edge-test-complex\",\"physical-location-type\":\"AAIDefault\",\"street1\":\"AAIDefault\",\"city\":\"AAIDefault\",\"state\":\"NJ\",\"postal-code\":\"07748\",\"country\":\"USA\",\"region\":\"US\"}";
doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
- //PutEdge
+ // PutEdge
uri = "/cloud-infrastructure/complexes/complex/junit-edge-test-complex/relationship-list/relationship";
- content = "{\"related-to\":\"pserver\",\"related-link\":\"/aai/" + schemaVersions.getDefaultVersion().toString() + "/cloud-infrastructure/pservers/pserver/junit-edge-test-pserver\",\"relationship-label\":\"org.onap.relationships.inventory.LocatedIn\"}";
+ content = "{\"related-to\":\"pserver\",\"related-link\":\"/aai/" + schemaVersions.getDefaultVersion().toString()
+ + "/cloud-infrastructure/pservers/pserver/junit-edge-test-pserver\",\"relationship-label\":\"org.onap.relationships.inventory.LocatedIn\"}";
doNothing().when(uebNotification).triggerEvents();
Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT_EDGE, uri, content);
@@ -413,8 +408,6 @@ public class HttpEntryTest extends AAISetup {
uebNotification.getEvents().get(1).getObj().marshal(false),
not(containsString("cloud-infrastructure/pservers/pserver/junit-edge-test-pserver")));
-
-
}
@Test
@@ -422,29 +415,32 @@ public class HttpEntryTest extends AAISetup {
DBConnectionType type = DBConnectionType.REALTIME;
traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
- //HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, queryStyle, type);
+ // HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, queryStyle, type);
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
- //Put pserver
+ // Put pserver
String uri = "/cloud-infrastructure/pservers/pserver/junit-edge-test-pserver";
String content = "{\"hostname\":\"junit-edge-test-pserver\"}";
doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
- //Put complex
+ // Put complex
uri = "/cloud-infrastructure/complexes/complex/junit-edge-test-complex";
- content = "{\"physical-location-id\":\"junit-edge-test-complex\",\"physical-location-type\":\"AAIDefault\",\"street1\":\"AAIDefault\",\"city\":\"AAIDefault\",\"state\":\"NJ\",\"postal-code\":\"07748\",\"country\":\"USA\",\"region\":\"US\"}";
+ content =
+ "{\"physical-location-id\":\"junit-edge-test-complex\",\"physical-location-type\":\"AAIDefault\",\"street1\":\"AAIDefault\",\"city\":\"AAIDefault\",\"state\":\"NJ\",\"postal-code\":\"07748\",\"country\":\"USA\",\"region\":\"US\"}";
doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
- //PutEdge
+ // PutEdge
uri = "/cloud-infrastructure/complexes/complex/junit-edge-test-complex/relationship-list/relationship";
- content = "{\"related-to\":\"pserver\",\"related-link\":\"/aai/" + schemaVersions.getDefaultVersion().toString() + "/cloud-infrastructure/pservers/pserver/junit-edge-test-pserver\",\"relationship-label\":\"junk\"}";
+ content = "{\"related-to\":\"pserver\",\"related-link\":\"/aai/" + schemaVersions.getDefaultVersion().toString()
+ + "/cloud-infrastructure/pservers/pserver/junit-edge-test-pserver\",\"relationship-label\":\"junk\"}";
Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT_EDGE, uri, content);
dbEngine.rollback();
String msg = response.getEntity().toString();
assertEquals("Expected the pserver to be created", 400, response.getStatus());
assertThat(msg, containsString("ERR.5.4.6107"));
- assertThat(msg, containsString("Required Edge-property not found in input data:org.onap.aai.edges.exceptions.EdgeRuleNotFoundException: No rule found for EdgeRuleQuery with filter params node type: complex, node type: pserver, label: junk, type: COUSIN, isPrivate: false"));
+ assertThat(msg, containsString(
+ "Required Edge-property not found in input data:org.onap.aai.edges.exceptions.EdgeRuleNotFoundException: No rule found for EdgeRuleQuery with filter params node type: complex, node type: pserver, label: junk, type: COUSIN, isPrivate: false"));
}
@@ -455,29 +451,34 @@ public class HttpEntryTest extends AAISetup {
DBConnectionType type = DBConnectionType.REALTIME;
traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
- //HttpEntry httpEntry = new HttpEntry(schemaVersions.getDefaultVersion(), ModelType.MOXY, QueryStyle.TRAVERSAL, type);
+ // HttpEntry httpEntry = new HttpEntry(schemaVersions.getDefaultVersion(), ModelType.MOXY, QueryStyle.TRAVERSAL,
+ // type);
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
- //Put pserver
+ // Put pserver
String pserverKey = "pserver-" + testName;
String pserverUri = "/cloud-infrastructure/pservers/pserver/" + pserverKey;
String content = "{\"hostname\":\"" + pserverKey + "\"}";
doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, pserverUri, content);
- //Put complex
+ // Put complex
String complexKey = "complex-" + testName;
String complexUri = "/cloud-infrastructure/complexes/complex/" + complexKey;
- content = "{\"physical-location-id\":\"" + complexKey + "\",\"physical-location-type\":\"AAIDefault\",\"street1\":\"AAIDefault\",\"city\":\"AAIDefault\",\"state\":\"NJ\",\"postal-code\":\"07748\",\"country\":\"USA\",\"region\":\"US\"}";
+ content = "{\"physical-location-id\":\"" + complexKey
+ + "\",\"physical-location-type\":\"AAIDefault\",\"street1\":\"AAIDefault\",\"city\":\"AAIDefault\",\"state\":\"NJ\",\"postal-code\":\"07748\",\"country\":\"USA\",\"region\":\"US\"}";
doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, complexUri, content);
- //PutEdge
- String relationshipUri = "/cloud-infrastructure/complexes/complex/" + complexKey + "/relationship-list/relationship";
- content = "{\"related-to\":\"pserver\",\"related-link\":\"/aai/" + schemaVersions.getDefaultVersion().toString() + "/cloud-infrastructure/pservers/pserver/" + pserverKey + "\",\"relationship-label\":\"org.onap.relationships.inventory.LocatedIn\"}";
+ // PutEdge
+ String relationshipUri =
+ "/cloud-infrastructure/complexes/complex/" + complexKey + "/relationship-list/relationship";
+ content = "{\"related-to\":\"pserver\",\"related-link\":\"/aai/" + schemaVersions.getDefaultVersion().toString()
+ + "/cloud-infrastructure/pservers/pserver/" + pserverKey
+ + "\",\"relationship-label\":\"org.onap.relationships.inventory.LocatedIn\"}";
doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT_EDGE, relationshipUri, content);
- //Get pserver with pathed
- queryParameters.add("format","pathed");
+ // Get pserver with pathed
+ queryParameters.add("format", "pathed");
content = "";
Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.GET, pserverUri, content);
queryParameters.remove("format");
@@ -497,26 +498,27 @@ public class HttpEntryTest extends AAISetup {
DBConnectionType type = DBConnectionType.REALTIME;
traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
- //HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, QueryStyle.TRAVERSAL, type);
+ // HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, QueryStyle.TRAVERSAL, type);
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
- //Put pserver
+ // Put pserver
String pserver1Key = "pserver-1-" + testName;
String pserver1Uri = "/cloud-infrastructure/pservers/pserver/" + pserver1Key;
String content = "{\"hostname\":\"" + pserver1Key + "\"}";
doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, pserver1Uri, content);
- //Put complex
+ // Put complex
String pserver2Key = "pserver-2-" + testName;
String pserver2Uri = "/cloud-infrastructure/pservers/pserver/" + pserver2Key;
content = "{\"hostname\":\"" + pserver2Key + "\"}";
doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, pserver2Uri, content);
- //Get pserver with pathed
- queryParameters.add("format","pathed");
+ // Get pserver with pathed
+ queryParameters.add("format", "pathed");
content = "";
- Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.GET, "/cloud-infrastructure/pservers", content);
+ Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.GET,
+ "/cloud-infrastructure/pservers", content);
queryParameters.remove("format");
String msg = response.getEntity().toString();
@@ -528,18 +530,20 @@ public class HttpEntryTest extends AAISetup {
}
- @Test
- public void testSetGetPaginationMethods(){
+ @Test
+ public void testSetGetPaginationMethods() {
DBConnectionType type = DBConnectionType.REALTIME;
traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
- //HttpEntry httpEntry = new HttpEntry(schemaVersions.getDefaultVersion(), ModelType.MOXY, QueryStyle.TRAVERSAL, type);
+ // HttpEntry httpEntry = new HttpEntry(schemaVersions.getDefaultVersion(), ModelType.MOXY, QueryStyle.TRAVERSAL,
+ // type);
traversalHttpEntry.setPaginationBucket(10);
traversalHttpEntry.setPaginationIndex(1);
traversalHttpEntry.setTotalsForPaging(101, traversalHttpEntry.getPaginationBucket());
assertEquals("Expected the pagination bucket size to be 10", 10, traversalHttpEntry.getPaginationBucket());
- assertEquals("Expected the total number of pagination buckets to be 11", 11, traversalHttpEntry.getTotalPaginationBuckets());
- assertEquals("Expected the pagination index to be 1",1, traversalHttpEntry.getPaginationIndex());
- assertEquals("Expected the total amount of vertices to be 101",101, traversalHttpEntry.getTotalVertices());
+ assertEquals("Expected the total number of pagination buckets to be 11", 11,
+ traversalHttpEntry.getTotalPaginationBuckets());
+ assertEquals("Expected the pagination index to be 1", 1, traversalHttpEntry.getPaginationIndex());
+ assertEquals("Expected the total amount of vertices to be 101", 101, traversalHttpEntry.getTotalVertices());
}
@Test
@@ -547,25 +551,27 @@ public class HttpEntryTest extends AAISetup {
DBConnectionType type = DBConnectionType.REALTIME;
traversalHttpEntry.setHttpEntryProperties(schemaVersions.getDefaultVersion(), type);
- //HttpEntry httpEntry = new HttpEntry(schemaVersions.getDefaultVersion(), ModelType.MOXY, queryStyle, type);
+ // HttpEntry httpEntry = new HttpEntry(schemaVersions.getDefaultVersion(), ModelType.MOXY, queryStyle, type);
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
- //Put pserver
+ // Put pserver
String uri = "/cloud-infrastructure/pservers/pserver/junit-edge-test-pserver";
String content = "{\"hostname\":\"junit-edge-test-pserver\"}";
doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
- //Put complex
+ // Put complex
uri = "/cloud-infrastructure/complexes/complex/junit-edge-test-complex";
- content = "{\"physical-location-id\":\"junit-edge-test-complex\",\"physical-location-type\":\"AAIDefault\",\"street1\":\"AAIDefault\",\"city\":\"AAIDefault\",\"state\":\"NJ\",\"postal-code\":\"07748\",\"country\":\"USA\",\"region\":\"US\"}";
+ content =
+ "{\"physical-location-id\":\"junit-edge-test-complex\",\"physical-location-type\":\"AAIDefault\",\"street1\":\"AAIDefault\",\"city\":\"AAIDefault\",\"state\":\"NJ\",\"postal-code\":\"07748\",\"country\":\"USA\",\"region\":\"US\"}";
doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
- //PutEdge
+ // PutEdge
uri = "/cloud-infrastructure/complexes/complex/junit-edge-test-complex/relationship-list/relationship";
- content = "{\"related-to\":\"pserver\",\"related-link\":\"/aai/" + schemaVersions.getDefaultVersion().toString() + "/cloud-infrastructure/pservers/pserver/junit-edge-test-pserver\",\"relationship-label\":\"org.onap.relationships.inventory.LocatedIn\"}";
+ content = "{\"related-to\":\"pserver\",\"related-link\":\"/aai/" + schemaVersions.getDefaultVersion().toString()
+ + "/cloud-infrastructure/pservers/pserver/junit-edge-test-pserver\",\"relationship-label\":\"org.onap.relationships.inventory.LocatedIn\"}";
doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT_EDGE, uri, content);
- //getRelatedTo
+ // getRelatedTo
uri = "/cloud-infrastructure/complexes/complex/junit-edge-test-complex/related-to/pservers";
content = "";
Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.GET, uri, content);
@@ -573,8 +579,9 @@ public class HttpEntryTest extends AAISetup {
dbEngine.rollback();
assertEquals("Expected the pserver to be created", 200, response.getStatus());
- assertThat("Related to pserver is returned.", respBody, containsString("\"hostname\":\"junit-edge-test-pserver\""));
-
+ assertThat("Related to pserver is returned.", respBody,
+ containsString("\"hostname\":\"junit-edge-test-pserver\""));
+
}
@Test
@@ -585,43 +592,44 @@ public class HttpEntryTest extends AAISetup {
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);
+ // HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, QueryStyle.TRAVERSAL, type);
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);
+ // HttpEntry httpEntry = new HttpEntry(Version.getLatest(), ModelType.MOXY, queryStyle, type);
Loader loader = traversalHttpEntry.getLoader();
TransactionalGraphEngine dbEngine = traversalHttpEntry.getDbEngine();
- //Put generic-vnf
+ // Put generic-vnf
String uri = "/network/generic-vnfs/generic-vnf/junit-abstract-test-generic-vnf";
String content = "{\"vnf-id\":\"junit-abstract-test-generic-vnf\",\"vnf-name\":\"junit-generic-vnf-name\"}";
doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
- //Put pserver
+ // Put pserver
uri = "/cloud-infrastructure/pservers/pserver/junit-abstract-test-pserver";
content = "{\"hostname\":\"junit-abstract-test-pserver\"}";
doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, uri, content);
- //PutEdge
+ // PutEdge
uri = "/cloud-infrastructure/pservers/pserver/junit-abstract-test-pserver/relationship-list/relationship";
- content = "{\"related-to\":\"vnf\",\"relationship-data\":[{\"relationship-key\":\"vnf.vnf-id\",\"relationship-value\":\"junit-abstract-test-generic-vnf\"}]}";
+ content =
+ "{\"related-to\":\"vnf\",\"relationship-data\":[{\"relationship-key\":\"vnf.vnf-id\",\"relationship-value\":\"junit-abstract-test-generic-vnf\"}]}";
doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT_EDGE, uri, content);
- //getRelatedTo
+ // getRelatedTo
uri = "/network/generic-vnfs/generic-vnf/junit-abstract-test-generic-vnf/related-to/pservers";
content = "";
Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.GET, uri, content);
String respBody = response.getEntity().toString();
dbEngine.rollback();
- assertThat("Related to pserver is returned.", respBody, containsString("\"hostname\":\"junit-abstract-test-pserver\""));
+ assertThat("Related to pserver is returned.", respBody,
+ containsString("\"hostname\":\"junit-abstract-test-pserver\""));
}
-} \ No newline at end of file
+}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/db/AAICoreFakeEdgesConfigTranslator.java b/aai-core/src/test/java/org/onap/aai/serialization/db/AAICoreFakeEdgesConfigTranslator.java
index 9c37ad99..a49394f1 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/db/AAICoreFakeEdgesConfigTranslator.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/db/AAICoreFakeEdgesConfigTranslator.java
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.serialization.db;
import java.util.*;
@@ -33,25 +34,25 @@ import org.onap.aai.setup.SchemaVersions;
*/
public class AAICoreFakeEdgesConfigTranslator extends AbstractConfigTranslator {
- public AAICoreFakeEdgesConfigTranslator(SchemaLocationsBean bean, SchemaConfigVersions schemaVersions) {
- super(bean, schemaVersions);
- }
-
- /* (non-Javadoc)
- * @see org.onap.aai.setup.ConfigTranslator#getEdgeFiles()
- */
- @Override
- public Map<SchemaVersion, List<String>> getEdgeFiles() {
- String file = "src/test/resources/dbedgerules/DbEdgeRules_test.json";
-
- Map<SchemaVersion, List<String>> files = new TreeMap<>();
- List<String> container = new ArrayList<>();
- container.add(file);
- files.put(schemaVersions.getDefaultVersion(), container);
-
- return files;
- }
-
-
+ public AAICoreFakeEdgesConfigTranslator(SchemaLocationsBean bean, SchemaConfigVersions schemaVersions) {
+ super(bean, schemaVersions);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.aai.setup.ConfigTranslator#getEdgeFiles()
+ */
+ @Override
+ public Map<SchemaVersion, List<String>> getEdgeFiles() {
+ String file = "src/test/resources/dbedgerules/DbEdgeRules_test.json";
+
+ Map<SchemaVersion, List<String>> files = new TreeMap<>();
+ List<String> container = new ArrayList<>();
+ container.add(file);
+ files.put(schemaVersions.getDefaultVersion(), container);
+
+ return files;
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/db/AAICorePrivateEdgeTestConfigTranslator.java b/aai-core/src/test/java/org/onap/aai/serialization/db/AAICorePrivateEdgeTestConfigTranslator.java
index 149d2849..24762d57 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/db/AAICorePrivateEdgeTestConfigTranslator.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/db/AAICorePrivateEdgeTestConfigTranslator.java
@@ -17,41 +17,42 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.serialization.db;
+import java.util.*;
+
import org.onap.aai.AbstractConfigTranslator;
import org.onap.aai.setup.SchemaConfigVersions;
import org.onap.aai.setup.SchemaLocationsBean;
import org.onap.aai.setup.SchemaVersion;
import org.onap.aai.setup.SchemaVersions;
-import java.util.*;
-
/**
* Quick and dirty access to the real schema files for updating core tests
*
*/
public class AAICorePrivateEdgeTestConfigTranslator extends AbstractConfigTranslator {
- public AAICorePrivateEdgeTestConfigTranslator(SchemaLocationsBean bean, SchemaConfigVersions schemaVersions) {
- super(bean, schemaVersions);
- }
-
- /* (non-Javadoc)
- * @see org.onap.aai.setup.ConfigTranslator#getEdgeFiles()
- */
- @Override
- public Map<SchemaVersion, List<String>> getEdgeFiles() {
- String file = "src/test/resources/dbedgerules/DbEdgeRules_PrivateEdges.json";
-
- Map<SchemaVersion, List<String>> files = new TreeMap<>();
- List<String> container = new ArrayList<>();
- container.add(file);
- files.put(schemaVersions.getDefaultVersion(), container);
-
- return files;
- }
-
-
+ public AAICorePrivateEdgeTestConfigTranslator(SchemaLocationsBean bean, SchemaConfigVersions schemaVersions) {
+ super(bean, schemaVersions);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.aai.setup.ConfigTranslator#getEdgeFiles()
+ */
+ @Override
+ public Map<SchemaVersion, List<String>> getEdgeFiles() {
+ String file = "src/test/resources/dbedgerules/DbEdgeRules_PrivateEdges.json";
+
+ Map<SchemaVersion, List<String>> files = new TreeMap<>();
+ List<String> container = new ArrayList<>();
+ container.add(file);
+ files.put(schemaVersions.getDefaultVersion(), container);
+
+ return files;
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/db/DbAliasTest.java b/aai-core/src/test/java/org/onap/aai/serialization/db/DbAliasTest.java
index d63220b7..944a4067 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/db/DbAliasTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/db/DbAliasTest.java
@@ -17,13 +17,28 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.serialization.db;
-import org.janusgraph.core.JanusGraphFactory;
-import org.janusgraph.core.JanusGraph;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.janusgraph.core.JanusGraph;
+import org.janusgraph.core.JanusGraphFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -36,116 +51,100 @@ import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.*;
import org.onap.aai.parsers.query.QueryParser;
import org.onap.aai.schema.enums.PropertyMetadata;
-import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.JanusGraphDBEngine;
+import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
import org.onap.aai.setup.SchemaVersion;
import org.springframework.test.annotation.DirtiesContext;
-import java.io.UnsupportedEncodingException;
-import java.lang.reflect.InvocationTargetException;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
@RunWith(value = Parameterized.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class DbAliasTest extends DataLinkSetup {
- private JanusGraph graph;
-
- private SchemaVersion version;
- private final ModelType introspectorFactoryType = ModelType.MOXY;
- private final DBConnectionType type = DBConnectionType.REALTIME;
- private Loader loader;
- private TransactionalGraphEngine dbEngine;
-
- @Parameterized.Parameter(value = 0)
- public QueryStyle queryStyle;
-
- @Parameterized.Parameters(name = "QueryStyle.{0}")
- public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][]{
- {QueryStyle.TRAVERSAL},
- {QueryStyle.TRAVERSAL_URI}
- });
- }
-
- @Before
- public void setup() throws Exception {
- version = schemaVersions.getDepthVersion();
- graph = JanusGraphFactory.build().set("storage.backend","inmemory").open();
- loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version);
- dbEngine = new JanusGraphDBEngine(
- queryStyle,
- type,
- loader);
- }
-
- @After
- public void tearDown() {
- graph.tx().rollback();
- graph.close();
- }
-
- @Test
- public void checkOnWrite() throws AAIException, UnsupportedEncodingException, URISyntaxException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, NoSuchMethodException, InterruptedException {
- final String property = "persona-model-customization-id";
- String dbPropertyName = property;
- TransactionalGraphEngine spy = spy(this.dbEngine);
- TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
- Graph g = graph.newTransaction();
- GraphTraversalSource traversal = g.traversal();
- when(spy.asAdmin()).thenReturn(adminSpy);
- when(adminSpy.getTraversalSource()).thenReturn(traversal);
- DBSerializer serializer = new DBSerializer(version, spy, introspectorFactoryType, "AAI_TEST");
- QueryParser uriQuery = spy.getQueryBuilder().createQueryFromURI(new URI("network/generic-vnfs/generic-vnf/key1"));
- Introspector obj = loader.introspectorFromName("generic-vnf");
- Vertex v = g.addVertex();
- Object id = v.id();
- obj.setValue("vnf-id", "key1");
- obj.setValue(property, "hello");
- serializer.serializeToDb(obj, v, uriQuery, "", "");
- g.tx().commit();
- v = graph.traversal().V(id).next();
- Map<PropertyMetadata, String> map = obj.getPropertyMetadata(property);
- if (map.containsKey(PropertyMetadata.DB_ALIAS)) {
- dbPropertyName = map.get(PropertyMetadata.DB_ALIAS);
- }
-
- assertEquals("dbAlias is ", "model-customization-id", dbPropertyName);
- assertEquals("dbAlias property exists", "hello", v.property(dbPropertyName).orElse(""));
- assertEquals("model property does not", "missing", v.property(property).orElse("missing"));
-
- }
-
- @Test
- public void checkOnRead() throws AAIException, UnsupportedEncodingException, URISyntaxException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, NoSuchMethodException, InterruptedException, MalformedURLException {
- final String property = "persona-model-customization-id";
-
- TransactionalGraphEngine spy = spy(dbEngine);
- TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
- Vertex v = graph.traversal().addV("vnf-id", "key1", "model-customization-id", "hello").next();
- graph.tx().commit();
- Graph g = graph.newTransaction();
- GraphTraversalSource traversal = g.traversal();
- when(spy.asAdmin()).thenReturn(adminSpy);
- when(adminSpy.getTraversalSource()).thenReturn(traversal);
- DBSerializer serializer = new DBSerializer(version, spy, introspectorFactoryType, "AAI_TEST");
- Introspector obj = loader.introspectorFromName("generic-vnf");
- serializer.dbToObject(Collections.singletonList(v), obj, 0, true, "false");
-
- assertEquals("dbAlias property exists", "hello", obj.getValue(property));
-
- }
-
+ private JanusGraph graph;
+
+ private SchemaVersion version;
+ private final ModelType introspectorFactoryType = ModelType.MOXY;
+ private final DBConnectionType type = DBConnectionType.REALTIME;
+ private Loader loader;
+ private TransactionalGraphEngine dbEngine;
+
+ @Parameterized.Parameter(value = 0)
+ public QueryStyle queryStyle;
+
+ @Parameterized.Parameters(name = "QueryStyle.{0}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
+ }
+
+ @Before
+ public void setup() throws Exception {
+ version = schemaVersions.getDepthVersion();
+ graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
+ loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version);
+ dbEngine = new JanusGraphDBEngine(queryStyle, type, loader);
+ }
+
+ @After
+ public void tearDown() {
+ graph.tx().rollback();
+ graph.close();
+ }
+
+ @Test
+ public void checkOnWrite() throws AAIException, UnsupportedEncodingException, URISyntaxException, SecurityException,
+ IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException,
+ NoSuchMethodException, InterruptedException {
+ final String property = "persona-model-customization-id";
+ String dbPropertyName = property;
+ TransactionalGraphEngine spy = spy(this.dbEngine);
+ TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
+ Graph g = graph.newTransaction();
+ GraphTraversalSource traversal = g.traversal();
+ when(spy.asAdmin()).thenReturn(adminSpy);
+ when(adminSpy.getTraversalSource()).thenReturn(traversal);
+ DBSerializer serializer = new DBSerializer(version, spy, introspectorFactoryType, "AAI_TEST");
+ QueryParser uriQuery =
+ spy.getQueryBuilder().createQueryFromURI(new URI("network/generic-vnfs/generic-vnf/key1"));
+ Introspector obj = loader.introspectorFromName("generic-vnf");
+ Vertex v = g.addVertex();
+ Object id = v.id();
+ obj.setValue("vnf-id", "key1");
+ obj.setValue(property, "hello");
+ serializer.serializeToDb(obj, v, uriQuery, "", "");
+ g.tx().commit();
+ v = graph.traversal().V(id).next();
+ Map<PropertyMetadata, String> map = obj.getPropertyMetadata(property);
+ if (map.containsKey(PropertyMetadata.DB_ALIAS)) {
+ dbPropertyName = map.get(PropertyMetadata.DB_ALIAS);
+ }
+
+ assertEquals("dbAlias is ", "model-customization-id", dbPropertyName);
+ assertEquals("dbAlias property exists", "hello", v.property(dbPropertyName).orElse(""));
+ assertEquals("model property does not", "missing", v.property(property).orElse("missing"));
+
+ }
+
+ @Test
+ public void checkOnRead() throws AAIException, UnsupportedEncodingException, URISyntaxException, SecurityException,
+ IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException,
+ NoSuchMethodException, InterruptedException, MalformedURLException {
+ final String property = "persona-model-customization-id";
+
+ TransactionalGraphEngine spy = spy(dbEngine);
+ TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin());
+ Vertex v = graph.traversal().addV("vnf-id", "key1", "model-customization-id", "hello").next();
+ graph.tx().commit();
+ Graph g = graph.newTransaction();
+ GraphTraversalSource traversal = g.traversal();
+ when(spy.asAdmin()).thenReturn(adminSpy);
+ when(adminSpy.getTraversalSource()).thenReturn(traversal);
+ DBSerializer serializer = new DBSerializer(version, spy, introspectorFactoryType, "AAI_TEST");
+ Introspector obj = loader.introspectorFromName("generic-vnf");
+ serializer.dbToObject(Collections.singletonList(v), obj, 0, true, "false");
+
+ assertEquals("dbAlias property exists", "hello", obj.getValue(property));
+
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java b/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java
index cbc1bd9a..b50adf2a 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializerTest.java
@@ -17,18 +17,28 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.serialization.db;
-import org.janusgraph.core.JanusGraphFactory;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.*;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.*;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
+import org.janusgraph.core.JanusGraphFactory;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.onap.aai.AAISetup;
-import org.onap.aai.util.AAIConstants;
import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.dbmap.DBConnectionType;
import org.onap.aai.edges.EdgeIngestor;
@@ -36,871 +46,871 @@ import org.onap.aai.edges.enums.EdgeType;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.*;
import org.onap.aai.parsers.query.QueryParser;
-import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.JanusGraphDBEngine;
+import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
import org.onap.aai.setup.SchemaVersion;
+import org.onap.aai.util.AAIConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.*;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
@RunWith(value = Parameterized.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class DbSerializerTest extends AAISetup {
- //to use, set thrown.expect to whatever your test needs
- //this line establishes default of expecting no exception to be thrown
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- protected static Graph graph;
-
- @Autowired
- protected EdgeSerializer edgeSer;
- @Autowired
- protected EdgeIngestor ei;
-
- private SchemaVersion version;
- private final ModelType introspectorFactoryType = ModelType.MOXY;
- private final DBConnectionType type = DBConnectionType.REALTIME;
- private Loader loader;
- private TransactionalGraphEngine dbEngine;
- private TransactionalGraphEngine engine; //for tests that aren't mocking the engine
- private DBSerializer dbser;
- TransactionalGraphEngine spy;
- TransactionalGraphEngine.Admin adminSpy;
-
- @Parameterized.Parameter(value = 0)
- public QueryStyle queryStyle;
-
- @Parameterized.Parameters(name = "QueryStyle.{0}")
- public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][]{
- {QueryStyle.TRAVERSAL},
- {QueryStyle.TRAVERSAL_URI}
- });
- }
-
- @BeforeClass
- public static void init() throws Exception {
- graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
-
- }
-
- @Before
- public void setup() throws Exception {
- //createGraph();
+ // to use, set thrown.expect to whatever your test needs
+ // this line establishes default of expecting no exception to be thrown
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ protected static Graph graph;
+
+ @Autowired
+ protected EdgeSerializer edgeSer;
+ @Autowired
+ protected EdgeIngestor ei;
+
+ private SchemaVersion version;
+ private final ModelType introspectorFactoryType = ModelType.MOXY;
+ private final DBConnectionType type = DBConnectionType.REALTIME;
+ private Loader loader;
+ private TransactionalGraphEngine dbEngine;
+ private TransactionalGraphEngine engine; // for tests that aren't mocking the engine
+ private DBSerializer dbser;
+ TransactionalGraphEngine spy;
+ TransactionalGraphEngine.Admin adminSpy;
+
+ @Parameterized.Parameter(value = 0)
+ public QueryStyle queryStyle;
+
+ @Parameterized.Parameters(name = "QueryStyle.{0}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] {{QueryStyle.TRAVERSAL}, {QueryStyle.TRAVERSAL_URI}});
+ }
+
+ @BeforeClass
+ public static void init() throws Exception {
+ graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
+
+ }
+
+ @Before
+ public void setup() throws Exception {
+ // createGraph();
version = schemaVersions.getDefaultVersion();
- loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version);
- dbEngine = new JanusGraphDBEngine(queryStyle, type, loader);
- spy = spy(dbEngine);
- adminSpy = spy(dbEngine.asAdmin());
-
-
- engine = new JanusGraphDBEngine(queryStyle, type, loader);
- dbser = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST");
- }
-
- @Test
- public void testFindDeletableDoesNotReturnDuplicates() throws AAIException {
-
- Vertex genericVnf1 = graph.addVertex("aai-node-type", "generic-vnf", "vnf-id", "vnf1", "vnf-name", "vnfName1");
-
- Vertex lInterface1 = graph.addVertex("aai-node-type", "l-interface", "interface-name", "lInterface1");
- Vertex lInterface2 = graph.addVertex("aai-node-type", "l-interface", "interface-name", "lInterface2");
-
- Vertex logicalLink1 = graph.addVertex("aai-node-type", "logical-link", "link-name", "logicalLink1");
- Vertex logicalLink2 = graph.addVertex("aai-node-type", "logical-link", "link-name", "logicalLink2");
-
- GraphTraversalSource g = graph.traversal();
-
- edgeSer.addTreeEdge(g, genericVnf1, lInterface1);
- edgeSer.addTreeEdge(g, genericVnf1, lInterface2);
- edgeSer.addEdge(g, lInterface1, logicalLink1);
- edgeSer.addEdge(g, lInterface1, logicalLink2);
- // This line will cause the logical link2 to be found twice under linterface 1
- // and also under the linterface 2 and since in the past deletable returned
- // duplicates this test checks that it shouldn't return duplicates
- edgeSer.addEdge(g, lInterface2, logicalLink2);
-
- when(spy.asAdmin()).thenReturn(adminSpy);
- when(adminSpy.getTraversalSource()).thenReturn(g);
- when(adminSpy.getReadOnlyTraversalSource()).thenReturn(g);
-
- List<Vertex> deletableVertexes = spy.getQueryEngine().findDeletable(genericVnf1);
- Set<Vertex> vertexSet = new HashSet<>();
-
- for (Vertex deletableVertex : deletableVertexes) {
- if(!vertexSet.contains(deletableVertex)){
- vertexSet.add(deletableVertex);
- } else {
- fail("Find deletable is returning a list of duplicate vertexes");
- }
- }
- }
-
- @After
- public void tearDown() throws Exception {
- engine.rollback();
- }
-
- @AfterClass
- public static void destroy() throws Exception {
- graph.close();
- }
-
-
- public void subnetSetup() throws AAIException {
- /*
- * This setus up the test graph, For future junits , add more vertices
- * and edges
- */
-
- Vertex l3interipv4addresslist_1 = graph.traversal().addV("aai-node-type", "l3-interface-ipv4-address-list",
- "l3-interface-ipv4-address", "l3-interface-ipv4-address-1").next();
- Vertex subnet_2 = graph.traversal().addV("aai-node-type", "subnet", "subnet-id", "subnet-id-2").next();
- Vertex l3interipv6addresslist_3 = graph.traversal().addV("aai-node-type", "l3-interface-ipv6-address-list",
- "l3-interface-ipv6-address", "l3-interface-ipv6-address-3").next();
- Vertex subnet_4 = graph.traversal().addV("aai-node-type", "subnet", "subnet-id", "subnet-id-4").next();
- Vertex subnet_5 = graph.traversal().addV("aai-node-type", "subnet", "subnet-id", "subnet-id-5").next();
- Vertex l3network_6 = graph.traversal()
- .addV("aai-node-type", "l3-network", "network-id", "network-id-6", "network-name", "network-name-6")
- .next();
-
- GraphTraversalSource g = graph.traversal();
- edgeSer.addEdge(g, l3interipv4addresslist_1, subnet_2);
- edgeSer.addEdge(g, l3interipv6addresslist_3, subnet_4);
- edgeSer.addTreeEdge(g, subnet_5, l3network_6);
- }
-
-
- public void l3NetworkSetup() throws AAIException {
- /*
- * This setus up the test graph, For future junits , add more vertices
- * and edges
- */
-
- Vertex l3network1 = graph.addVertex("aai-node-type", "l3-network", "network-id", "network-id-v1", "network-name", "network-name-v1");
- Vertex l3network2 = graph.addVertex("aai-node-type", "l3-network", "network-id", "network-id-v2", "network-name", "network-name-v2");
- Vertex subnet1 = graph.addVertex("aai-node-type", "subnet", "subnet-id", "subnet-id-v1");
- Vertex subnet2 = graph.addVertex("aai-node-type", "subnet", "subnet-id", "subnet-id-v2");
-
- Vertex l3interipv4addresslist_1 = graph.addVertex("aai-node-type", "l3-interface-ipv4-address-list",
- "l3-interface-ipv4-address", "l3-intr-v1");
- Vertex l3interipv6addresslist_1 = graph.addVertex("aai-node-type", "l3-interface-ipv6-address-list",
- "l3-interface-ipv6-address", "l3-interface-ipv6-v1");
-
-
-
-
-
- GraphTraversalSource g = graph.traversal();
- edgeSer.addTreeEdge(g, subnet1, l3network1);
- edgeSer.addEdge(g, l3interipv4addresslist_1, subnet1);
- edgeSer.addEdge(g, l3interipv6addresslist_1, subnet1);
+ loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version);
+ dbEngine = new JanusGraphDBEngine(queryStyle, type, loader);
+ spy = spy(dbEngine);
+ adminSpy = spy(dbEngine.asAdmin());
- edgeSer.addTreeEdge(g, subnet2, l3network2);
+ engine = new JanusGraphDBEngine(queryStyle, type, loader);
+ dbser = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST");
+ }
+ @Test
+ public void testFindDeletableDoesNotReturnDuplicates() throws AAIException {
+
+ Vertex genericVnf1 = graph.addVertex("aai-node-type", "generic-vnf", "vnf-id", "vnf1", "vnf-name", "vnfName1");
+
+ Vertex lInterface1 = graph.addVertex("aai-node-type", "l-interface", "interface-name", "lInterface1");
+ Vertex lInterface2 = graph.addVertex("aai-node-type", "l-interface", "interface-name", "lInterface2");
+
+ Vertex logicalLink1 = graph.addVertex("aai-node-type", "logical-link", "link-name", "logicalLink1");
+ Vertex logicalLink2 = graph.addVertex("aai-node-type", "logical-link", "link-name", "logicalLink2");
+
+ GraphTraversalSource g = graph.traversal();
+
+ edgeSer.addTreeEdge(g, genericVnf1, lInterface1);
+ edgeSer.addTreeEdge(g, genericVnf1, lInterface2);
+ edgeSer.addEdge(g, lInterface1, logicalLink1);
+ edgeSer.addEdge(g, lInterface1, logicalLink2);
+ // This line will cause the logical link2 to be found twice under linterface 1
+ // and also under the linterface 2 and since in the past deletable returned
+ // duplicates this test checks that it shouldn't return duplicates
+ edgeSer.addEdge(g, lInterface2, logicalLink2);
+
+ when(spy.asAdmin()).thenReturn(adminSpy);
+ when(adminSpy.getTraversalSource()).thenReturn(g);
+ when(adminSpy.getReadOnlyTraversalSource()).thenReturn(g);
+
+ List<Vertex> deletableVertexes = spy.getQueryEngine().findDeletable(genericVnf1);
+ Set<Vertex> vertexSet = new HashSet<>();
+
+ for (Vertex deletableVertex : deletableVertexes) {
+ if (!vertexSet.contains(deletableVertex)) {
+ vertexSet.add(deletableVertex);
+ } else {
+ fail("Find deletable is returning a list of duplicate vertexes");
+ }
+ }
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ engine.rollback();
+ }
+
+ @AfterClass
+ public static void destroy() throws Exception {
+ graph.close();
+ }
+
+ public void subnetSetup() throws AAIException {
+ /*
+ * This setus up the test graph, For future junits , add more vertices
+ * and edges
+ */
+
+ Vertex l3interipv4addresslist_1 = graph.traversal().addV("aai-node-type", "l3-interface-ipv4-address-list",
+ "l3-interface-ipv4-address", "l3-interface-ipv4-address-1").next();
+ Vertex subnet_2 = graph.traversal().addV("aai-node-type", "subnet", "subnet-id", "subnet-id-2").next();
+ Vertex l3interipv6addresslist_3 = graph.traversal().addV("aai-node-type", "l3-interface-ipv6-address-list",
+ "l3-interface-ipv6-address", "l3-interface-ipv6-address-3").next();
+ Vertex subnet_4 = graph.traversal().addV("aai-node-type", "subnet", "subnet-id", "subnet-id-4").next();
+ Vertex subnet_5 = graph.traversal().addV("aai-node-type", "subnet", "subnet-id", "subnet-id-5").next();
+ Vertex l3network_6 = graph.traversal()
+ .addV("aai-node-type", "l3-network", "network-id", "network-id-6", "network-name", "network-name-6")
+ .next();
+
+ GraphTraversalSource g = graph.traversal();
+ edgeSer.addEdge(g, l3interipv4addresslist_1, subnet_2);
+ edgeSer.addEdge(g, l3interipv6addresslist_3, subnet_4);
+ edgeSer.addTreeEdge(g, subnet_5, l3network_6);
+ }
+
+ public void l3NetworkSetup() throws AAIException {
+ /*
+ * This setus up the test graph, For future junits , add more vertices
+ * and edges
+ */
+
+ Vertex l3network1 = graph.addVertex("aai-node-type", "l3-network", "network-id", "network-id-v1",
+ "network-name", "network-name-v1");
+ Vertex l3network2 = graph.addVertex("aai-node-type", "l3-network", "network-id", "network-id-v2",
+ "network-name", "network-name-v2");
+ Vertex subnet1 = graph.addVertex("aai-node-type", "subnet", "subnet-id", "subnet-id-v1");
+ Vertex subnet2 = graph.addVertex("aai-node-type", "subnet", "subnet-id", "subnet-id-v2");
+
+ Vertex l3interipv4addresslist_1 = graph.addVertex("aai-node-type", "l3-interface-ipv4-address-list",
+ "l3-interface-ipv4-address", "l3-intr-v1");
+ Vertex l3interipv6addresslist_1 = graph.addVertex("aai-node-type", "l3-interface-ipv6-address-list",
+ "l3-interface-ipv6-address", "l3-interface-ipv6-v1");
+
+ GraphTraversalSource g = graph.traversal();
+ edgeSer.addTreeEdge(g, subnet1, l3network1);
+ edgeSer.addEdge(g, l3interipv4addresslist_1, subnet1);
+ edgeSer.addEdge(g, l3interipv6addresslist_1, subnet1);
+
+ edgeSer.addTreeEdge(g, subnet2, l3network2);
+
+ }
+
+ public void vserverSetup() throws AAIException {
+ /*
+ * This setus up the test graph, For future junits , add more vertices
+ * and edges
+ */
+
+ Vertex vserver1 = graph.addVertex("aai-node-type", "vserver", "vserver-id", "vss1",
+ AAIProperties.AAI_URI.toString(),
+ "/cloud-infrastructure/cloud-regions/cloud-region/me/123/tenants/tenant/453/vservers/vserver/vss1");
+
+ Vertex lInterface1 = graph.addVertex("aai-node-type", "l-interface", "interface-name", "lIntr1");
+ Vertex lInterface2 = graph.addVertex("aai-node-type", "l-interface", "interface-name", "lIntr2");
+
+ Vertex logicalLink1 = graph.addVertex("aai-node-type", "logical-link", "link-name", "logLink1");
+ Vertex logicalLink2 = graph.addVertex("aai-node-type", "logical-link", "link-name", "logLink2");
+
+ Vertex l3interipv4addresslist_1 = graph.addVertex("aai-node-type", "l3-interface-ipv4-address-list",
+ "l3-interface-ipv4-address", "l3-intr-ipv4-address-1");
+ Vertex l3interipv6addresslist_2 = graph.addVertex("aai-node-type", "l3-interface-ipv6-address-list",
+ "l3-interface-ipv4-address", "l3-intr-ipv6-address-1");
+
+ GraphTraversalSource g = graph.traversal();
+
+ edgeSer.addTreeEdge(g, lInterface1, vserver1);
+ edgeSer.addTreeEdge(g, lInterface2, vserver1);
+ edgeSer.addTreeEdge(g, l3interipv4addresslist_1, lInterface1);
+ edgeSer.addTreeEdge(g, l3interipv6addresslist_2, lInterface2);
+
+ edgeSer.addEdge(g, lInterface1, logicalLink1);
+ edgeSer.addEdge(g, lInterface2, logicalLink2);
+ }
+ @Test
+ public void subnetDelWithInEdgesIpv4Test() throws AAIException {
+ subnetSetup();
+ String expected_message =
+ "Object is being reference by additional objects preventing it from being deleted. Please clean up references from the following types [l3-interface-ipv4-address-list]";
- }
-
- public void vserverSetup() throws AAIException {
- /*
- * This setus up the test graph, For future junits , add more vertices
- * and edges
- */
-
- Vertex vserver1 = graph.addVertex("aai-node-type", "vserver", "vserver-id", "vss1",
- AAIProperties.AAI_URI.toString(),
- "/cloud-infrastructure/cloud-regions/cloud-region/me/123/tenants/tenant/453/vservers/vserver/vss1");
-
- Vertex lInterface1 = graph.addVertex("aai-node-type", "l-interface", "interface-name", "lIntr1");
- Vertex lInterface2 = graph.addVertex("aai-node-type", "l-interface", "interface-name", "lIntr2");
-
- Vertex logicalLink1 = graph.addVertex("aai-node-type", "logical-link", "link-name", "logLink1");
- Vertex logicalLink2 = graph.addVertex("aai-node-type", "logical-link", "link-name", "logLink2");
-
- Vertex l3interipv4addresslist_1 = graph.addVertex("aai-node-type", "l3-interface-ipv4-address-list",
- "l3-interface-ipv4-address", "l3-intr-ipv4-address-1");
- Vertex l3interipv6addresslist_2 = graph.addVertex("aai-node-type", "l3-interface-ipv6-address-list",
- "l3-interface-ipv4-address", "l3-intr-ipv6-address-1");
-
- GraphTraversalSource g = graph.traversal();
-
- edgeSer.addTreeEdge(g, lInterface1, vserver1);
- edgeSer.addTreeEdge(g, lInterface2, vserver1);
- edgeSer.addTreeEdge(g, l3interipv4addresslist_1, lInterface1);
- edgeSer.addTreeEdge(g, l3interipv6addresslist_2, lInterface2);
-
- edgeSer.addEdge(g, lInterface1, logicalLink1);
- edgeSer.addEdge(g, lInterface2, logicalLink2);
- }
-
- @Test
- public void subnetDelWithInEdgesIpv4Test() throws AAIException {
- subnetSetup();
- String expected_message = "Object is being reference by additional objects preventing it from being deleted. Please clean up references from the following types [l3-interface-ipv4-address-list]";
-
- /*
- * This subnet has in-edges with l3-ipv4 and NOT ok to delete
- */
- Vertex subnet = graph.traversal().V().has("aai-node-type", "subnet").has("subnet-id", "subnet-id-2").next();
+ /*
+ * This subnet has in-edges with l3-ipv4 and NOT ok to delete
+ */
+ Vertex subnet = graph.traversal().V().has("aai-node-type", "subnet").has("subnet-id", "subnet-id-2").next();
- String exceptionMessage = testCascadeDelete(subnet);
- assertEquals(expected_message, exceptionMessage);
+ String exceptionMessage = testCascadeDelete(subnet);
+ assertEquals(expected_message, exceptionMessage);
- }
+ }
- @Test
- public void subnetDelWithInEdgesIpv6Test() throws AAIException {
- subnetSetup();
- String expected_message = "Object is being reference by additional objects preventing it from being deleted. Please clean up references from the following types [l3-interface-ipv6-address-list]";
+ @Test
+ public void subnetDelWithInEdgesIpv6Test() throws AAIException {
+ subnetSetup();
+ String expected_message =
+ "Object is being reference by additional objects preventing it from being deleted. Please clean up references from the following types [l3-interface-ipv6-address-list]";
- /*
- * This subnet has in-edges with l3-ipv6 and NOT ok to delete
- */
- Vertex subnet = graph.traversal().V().has("aai-node-type", "subnet").has("subnet-id", "subnet-id-4").next();
- String exceptionMessage = testCascadeDelete(subnet);
- assertEquals(expected_message, exceptionMessage);
+ /*
+ * This subnet has in-edges with l3-ipv6 and NOT ok to delete
+ */
+ Vertex subnet = graph.traversal().V().has("aai-node-type", "subnet").has("subnet-id", "subnet-id-4").next();
+ String exceptionMessage = testCascadeDelete(subnet);
+ assertEquals(expected_message, exceptionMessage);
- }
+ }
- @Test
- public void subnetDelWithInEdgesL3network() throws AAIException {
- subnetSetup();
- String expected_message = "";
+ @Test
+ public void subnetDelWithInEdgesL3network() throws AAIException {
+ subnetSetup();
+ String expected_message = "";
- /*
- * This subnet has in-edges with l3-network and ok to delete
- */
- Vertex subnet = graph.traversal().V().has("aai-node-type", "subnet").has("subnet-id", "subnet-id-5").next();
+ /*
+ * This subnet has in-edges with l3-network and ok to delete
+ */
+ Vertex subnet = graph.traversal().V().has("aai-node-type", "subnet").has("subnet-id", "subnet-id-5").next();
- String exceptionMessage = testCascadeDelete(subnet);
- assertEquals(expected_message, exceptionMessage);
+ String exceptionMessage = testCascadeDelete(subnet);
+ assertEquals(expected_message, exceptionMessage);
- }
+ }
- public String testCascadeDelete(Vertex v) throws AAIException {
+ public String testCascadeDelete(Vertex v) throws AAIException {
- GraphTraversalSource traversal = graph.traversal();
- when(spy.asAdmin()).thenReturn(adminSpy);
- when(adminSpy.getTraversalSource()).thenReturn(traversal);
- when(adminSpy.getReadOnlyTraversalSource()).thenReturn(traversal);
+ GraphTraversalSource traversal = graph.traversal();
+ when(spy.asAdmin()).thenReturn(adminSpy);
+ when(adminSpy.getTraversalSource()).thenReturn(traversal);
+ when(adminSpy.getReadOnlyTraversalSource()).thenReturn(traversal);
- String exceptionMessage = "";
- DBSerializer serializer = new DBSerializer(version, spy, introspectorFactoryType, "AAI_TEST");
- List<Vertex> deletableVertices = spy.getQueryEngine().findDeletable(v);
+ String exceptionMessage = "";
+ DBSerializer serializer = new DBSerializer(version, spy, introspectorFactoryType, "AAI_TEST");
+ List<Vertex> deletableVertices = spy.getQueryEngine().findDeletable(v);
- try {
- serializer.delete(v, deletableVertices, "resourceVersion", false);
- } catch (AAIException exception) {
- exceptionMessage = exception.getMessage();
- }
- return exceptionMessage;
+ try {
+ serializer.delete(v, deletableVertices, "resourceVersion", false);
+ } catch (AAIException exception) {
+ exceptionMessage = exception.getMessage();
+ }
+ return exceptionMessage;
- }
+ }
- public String testDelete(Vertex v) throws AAIException {
+ public String testDelete(Vertex v) throws AAIException {
- GraphTraversalSource traversal = graph.traversal();
- when(spy.asAdmin()).thenReturn(adminSpy);
- when(adminSpy.getTraversalSource()).thenReturn(traversal);
- when(adminSpy.getReadOnlyTraversalSource()).thenReturn(traversal);
+ GraphTraversalSource traversal = graph.traversal();
+ when(spy.asAdmin()).thenReturn(adminSpy);
+ when(adminSpy.getTraversalSource()).thenReturn(traversal);
+ when(adminSpy.getReadOnlyTraversalSource()).thenReturn(traversal);
- String exceptionMessage = "";
- DBSerializer serializer = new DBSerializer(version, spy, introspectorFactoryType, "AAI_TEST");
+ String exceptionMessage = "";
+ DBSerializer serializer = new DBSerializer(version, spy, introspectorFactoryType, "AAI_TEST");
- try {
- serializer.delete(v, "resourceVersion", false);
- } catch (AAIException exception) {
- exceptionMessage = exception.getMessage();
- }
- return exceptionMessage;
+ try {
+ serializer.delete(v, "resourceVersion", false);
+ } catch (AAIException exception) {
+ exceptionMessage = exception.getMessage();
+ }
+ return exceptionMessage;
- }
+ }
- @Test
- public void createNewVertexTest() throws AAIException {
- engine.startTransaction();
+ @Test
+ public void createNewVertexTest() throws AAIException {
+ engine.startTransaction();
- Introspector testObj = loader.introspectorFromName("generic-vnf");
+ Introspector testObj = loader.introspectorFromName("generic-vnf");
- Vertex testVertex = dbser.createNewVertex(testObj);
- Vertex fromGraph = engine.tx().traversal().V().has("aai-node-type","generic-vnf").toList().get(0);
- assertEquals(testVertex.id(), fromGraph.id());
- assertEquals("AAI-TEST", fromGraph.property(AAIProperties.SOURCE_OF_TRUTH.toString()).value());
+ Vertex testVertex = dbser.createNewVertex(testObj);
+ Vertex fromGraph = engine.tx().traversal().V().has("aai-node-type", "generic-vnf").toList().get(0);
+ assertEquals(testVertex.id(), fromGraph.id());
+ assertEquals("AAI-TEST", fromGraph.property(AAIProperties.SOURCE_OF_TRUTH.toString()).value());
- }
+ }
@Test
- public void touchStandardVertexPropertiesTest() throws AAIException, InterruptedException {
- engine.startTransaction();
+ public void touchStandardVertexPropertiesTest() throws AAIException, InterruptedException {
+ engine.startTransaction();
- //if this test runs through too fast the value may not change, causing the test to fail. sleeping ensures a different value
+ // if this test runs through too fast the value may not change, causing the test to fail. sleeping ensures a
+ // different value
Thread.sleep(2);
- DBSerializer dbser2 = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST-2");
- Vertex vert = graph.addVertex("aai-node-type", "generic-vnf");
+ DBSerializer dbser2 = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST-2");
+ Vertex vert = graph.addVertex("aai-node-type", "generic-vnf");
- // Upon first creation of the Vertex and the DBSerializer
+ // Upon first creation of the Vertex and the DBSerializer
// the source of truth and created-ts should be the same as their modified counterparts
dbser2.touchStandardVertexProperties(vert, true);
- String createTS = (String)vert.property(AAIProperties.CREATED_TS).value();
- String modTS = (String)vert.property(AAIProperties.LAST_MOD_TS).value();
- String sot = (String)vert.property(AAIProperties.SOURCE_OF_TRUTH).value();
- String lastModSOT = (String)vert.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value();
+ String createTS = (String) vert.property(AAIProperties.CREATED_TS).value();
+ String modTS = (String) vert.property(AAIProperties.LAST_MOD_TS).value();
+ String sot = (String) vert.property(AAIProperties.SOURCE_OF_TRUTH).value();
+ String lastModSOT = (String) vert.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value();
assertTrue(createTS.equals(modTS));
assertTrue(sot.equals(lastModSOT));
- //if this test runs through too fast the value may not change, causing the test to fail. sleeping ensures a different value
+ // if this test runs through too fast the value may not change, causing the test to fail. sleeping ensures a
+ // different value
Thread.sleep(2);
// Not new vertex && new DBSerializer (A new serializer since a new one will be created per transaction)
// Here the vertex will be modified by a different source of truth
DBSerializer dbser3 = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST-3");
dbser3.touchStandardVertexProperties(vert, false);
- createTS = (String)vert.property(AAIProperties.CREATED_TS).value();
- modTS = (String)vert.property(AAIProperties.LAST_MOD_TS).value();
- sot = (String)vert.property(AAIProperties.SOURCE_OF_TRUTH).value();
- lastModSOT = (String)vert.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value();
+ createTS = (String) vert.property(AAIProperties.CREATED_TS).value();
+ modTS = (String) vert.property(AAIProperties.LAST_MOD_TS).value();
+ sot = (String) vert.property(AAIProperties.SOURCE_OF_TRUTH).value();
+ lastModSOT = (String) vert.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value();
assertFalse(createTS.equals(modTS));
assertFalse(sot.equals(lastModSOT));
- //if this test runs through too fast the value may not change, causing the test to fail. sleeping ensures a different value
+ // if this test runs through too fast the value may not change, causing the test to fail. sleeping ensures a
+ // different value
Thread.sleep(2);
// The currentTimeMillis used for the created-ts and modified-ts is created at DBSerializer instantiation
- // Every REST transaction should create a new DBSerializer - thus a new currentTimeMillis is used at the time of transaction.
+ // Every REST transaction should create a new DBSerializer - thus a new currentTimeMillis is used at the time of
+ // transaction.
// Using an existing vertex, but treating it as new && using an older DBSerializer
- dbser.touchStandardVertexProperties(vert, true);
- String resverStart = (String)vert.property(AAIProperties.RESOURCE_VERSION).value();
- String lastModTimeStart = (String)vert.property(AAIProperties.LAST_MOD_TS).value();
- createTS = (String)vert.property(AAIProperties.CREATED_TS).value();
- modTS = (String)vert.property(AAIProperties.LAST_MOD_TS).value();
+ dbser.touchStandardVertexProperties(vert, true);
+ String resverStart = (String) vert.property(AAIProperties.RESOURCE_VERSION).value();
+ String lastModTimeStart = (String) vert.property(AAIProperties.LAST_MOD_TS).value();
+ createTS = (String) vert.property(AAIProperties.CREATED_TS).value();
+ modTS = (String) vert.property(AAIProperties.LAST_MOD_TS).value();
assertTrue(createTS.equals(modTS));
assertEquals("AAI-TEST", vert.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value());
- //if this test runs through too fast the value may not change, causing the test to fail. sleeping ensures a different value
+ // if this test runs through too fast the value may not change, causing the test to fail. sleeping ensures a
+ // different value
Thread.sleep(2);
- dbser2.touchStandardVertexProperties(vert, false);
- String resourceVer = (String)vert.property(AAIProperties.RESOURCE_VERSION).value();
- String lastModTs = (String)vert.property(AAIProperties.LAST_MOD_TS).value();
- String lastModSoT = (String)vert.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value();
+ dbser2.touchStandardVertexProperties(vert, false);
+ String resourceVer = (String) vert.property(AAIProperties.RESOURCE_VERSION).value();
+ String lastModTs = (String) vert.property(AAIProperties.LAST_MOD_TS).value();
+ String lastModSoT = (String) vert.property(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH).value();
- assertFalse(resverStart.equals(resourceVer));
- assertFalse(lastModTimeStart.equals(lastModTs));
- assertEquals("AAI-TEST-2", lastModSoT);
- }
+ assertFalse(resverStart.equals(resourceVer));
+ assertFalse(lastModTimeStart.equals(lastModTs));
+ assertEquals("AAI-TEST-2", lastModSoT);
+ }
- @Test
- public void touchStandardVertexPropertiesAAIUUIDTest() throws AAIException, InterruptedException {
- engine.startTransaction();
+ @Test
+ public void touchStandardVertexPropertiesAAIUUIDTest() throws AAIException, InterruptedException {
+ engine.startTransaction();
- Graph graph = TinkerGraph.open();
- Vertex v = graph.addVertex("aai-node-type", "generic-vnf");
+ Graph graph = TinkerGraph.open();
+ Vertex v = graph.addVertex("aai-node-type", "generic-vnf");
- dbser.touchStandardVertexProperties(v, true);
+ dbser.touchStandardVertexProperties(v, true);
- assertTrue(v.property(AAIProperties.AAI_UUID).isPresent());
- try {
- UUID.fromString((String)v.property(AAIProperties.AAI_UUID).value());
- } catch (IllegalArgumentException e) {
- fail("Vertex uuid is not valid uuid");
- }
- }
+ assertTrue(v.property(AAIProperties.AAI_UUID).isPresent());
+ try {
+ UUID.fromString((String) v.property(AAIProperties.AAI_UUID).value());
+ } catch (IllegalArgumentException e) {
+ fail("Vertex uuid is not valid uuid");
+ }
+ }
- @Test
- public void verifyResourceVersion_SunnyDayTest() throws AAIException {
- engine.startTransaction();
+ @Test
+ public void verifyResourceVersion_SunnyDayTest() throws AAIException {
+ engine.startTransaction();
- assertTrue(dbser.verifyResourceVersion("delete", "vnfc", "abc", "abc", "vnfcs/vnfc/vnfcId"));
+ assertTrue(dbser.verifyResourceVersion("delete", "vnfc", "abc", "abc", "vnfcs/vnfc/vnfcId"));
- }
+ }
- @Test
- public void verifyResourceVersion_CreateWithRVTest() throws AAIException {
- engine.startTransaction();
+ @Test
+ public void verifyResourceVersion_CreateWithRVTest() throws AAIException {
+ engine.startTransaction();
- thrown.expect(AAIException.class);
- thrown.expectMessage("resource-version passed for create of generic-vnfs/generic-vnf/myid");
- dbser.verifyResourceVersion("create", "generic-vnf", null, "old-res-ver", "generic-vnfs/generic-vnf/myid");
+ thrown.expect(AAIException.class);
+ thrown.expectMessage("resource-version passed for create of generic-vnfs/generic-vnf/myid");
+ dbser.verifyResourceVersion("create", "generic-vnf", null, "old-res-ver", "generic-vnfs/generic-vnf/myid");
- }
+ }
- @Test
- public void verifyResourceVersion_MissingRVTest() throws AAIException {
- engine.startTransaction();
+ @Test
+ public void verifyResourceVersion_MissingRVTest() throws AAIException {
+ engine.startTransaction();
- thrown.expect(AAIException.class);
- thrown.expectMessage("resource-version not passed for update of generic-vnfs/generic-vnf/myid");
- dbser.verifyResourceVersion("update", "generic-vnf", "current-res-ver", null, "generic-vnfs/generic-vnf/myid");
+ thrown.expect(AAIException.class);
+ thrown.expectMessage("resource-version not passed for update of generic-vnfs/generic-vnf/myid");
+ dbser.verifyResourceVersion("update", "generic-vnf", "current-res-ver", null, "generic-vnfs/generic-vnf/myid");
- }
+ }
- @Test
- public void verifyResourceVersion_MismatchRVTest() throws AAIException {
- engine.startTransaction();
+ @Test
+ public void verifyResourceVersion_MismatchRVTest() throws AAIException {
+ engine.startTransaction();
- thrown.expect(AAIException.class);
- thrown.expectMessage("resource-version MISMATCH for update of generic-vnfs/generic-vnf/myid");
- dbser.verifyResourceVersion("update", "generic-vnf", "current-res-ver", "old-res-ver", "generic-vnfs/generic-vnf/myid");
+ thrown.expect(AAIException.class);
+ thrown.expectMessage("resource-version MISMATCH for update of generic-vnfs/generic-vnf/myid");
+ dbser.verifyResourceVersion("update", "generic-vnf", "current-res-ver", "old-res-ver",
+ "generic-vnfs/generic-vnf/myid");
- }
+ }
- @Test
- public void verifyResourceVersion_DeleteTest() throws AAIException {
- engine.startTransaction();
+ @Test
+ public void verifyResourceVersion_DeleteTest() throws AAIException {
+ engine.startTransaction();
- assertTrue (dbser.verifyResourceVersion("delete", "generic-vnf", "current-res-ver", AAIConstants.AAI_RESVERSION_DISABLED_UUID_DEFAULT,
- "generic-vnfs/generic-vnf/myid"));
+ assertTrue(dbser.verifyResourceVersion("delete", "generic-vnf", "current-res-ver",
+ AAIConstants.AAI_RESVERSION_DISABLED_UUID_DEFAULT, "generic-vnfs/generic-vnf/myid"));
- }
- @Test
- public void trimClassNameTest() throws AAIException {
- assertEquals("GenericVnf", dbser.trimClassName("GenericVnf"));
- assertEquals("GenericVnf", dbser.trimClassName("org.onap.aai.GenericVnf"));
- }
+ }
- @Test
- public void getURIForVertexTest() throws AAIException, URISyntaxException, UnsupportedEncodingException {
- engine.startTransaction();
+ @Test
+ public void trimClassNameTest() throws AAIException {
+ assertEquals("GenericVnf", dbser.trimClassName("GenericVnf"));
+ assertEquals("GenericVnf", dbser.trimClassName("org.onap.aai.GenericVnf"));
+ }
- Vertex cr = engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id", "123", "aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/me/123");
- Vertex ten = engine.tx().addVertex("aai-node-type", "tenant", "tenant-id", "453");
+ @Test
+ public void getURIForVertexTest() throws AAIException, URISyntaxException, UnsupportedEncodingException {
+ engine.startTransaction();
- edgeSer.addTreeEdge(engine.tx().traversal(), cr, ten);
+ Vertex cr = engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id",
+ "123", "aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/me/123");
+ Vertex ten = engine.tx().addVertex("aai-node-type", "tenant", "tenant-id", "453");
- ten.property("aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/me/123/tenants/tenant/453");
+ edgeSer.addTreeEdge(engine.tx().traversal(), cr, ten);
- URI compare = new URI("/cloud-infrastructure/cloud-regions/cloud-region/me/123/tenants/tenant/453");
- assertEquals(compare, dbser.getURIForVertex(ten));
+ ten.property("aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/me/123/tenants/tenant/453");
- URI compareFailure = new URI("/unknown-uri");
- ten.property("aai-uri").remove();
- assertEquals(compareFailure, dbser.getURIForVertex(ten));
+ URI compare = new URI("/cloud-infrastructure/cloud-regions/cloud-region/me/123/tenants/tenant/453");
+ assertEquals(compare, dbser.getURIForVertex(ten));
- }
+ URI compareFailure = new URI("/unknown-uri");
+ ten.property("aai-uri").remove();
+ assertEquals(compareFailure, dbser.getURIForVertex(ten));
- @Test
- public void getVertexPropertiesTest() throws AAIException, UnsupportedEncodingException {
- engine.startTransaction();
+ }
- Vertex cr = engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id", "123");
+ @Test
+ public void getVertexPropertiesTest() throws AAIException, UnsupportedEncodingException {
+ engine.startTransaction();
- Introspector crIntro = dbser.getVertexProperties(cr);
- assertEquals("cloud-region", crIntro.getDbName());
- assertEquals("me", crIntro.getValue("cloud-owner"));
- assertEquals("123", crIntro.getValue("cloud-region-id"));
+ Vertex cr =
+ engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id", "123");
- }
+ Introspector crIntro = dbser.getVertexProperties(cr);
+ assertEquals("cloud-region", crIntro.getDbName());
+ assertEquals("me", crIntro.getValue("cloud-owner"));
+ assertEquals("123", crIntro.getValue("cloud-region-id"));
- @Test
- public void getEdgeBetweenTest() throws AAIException {
- engine.startTransaction();
+ }
- Vertex cr = engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id", "123");
- Vertex ten = engine.tx().addVertex("aai-node-type", "tenant", "tenant-id", "453");
+ @Test
+ public void getEdgeBetweenTest() throws AAIException {
+ engine.startTransaction();
- edgeSer.addTreeEdge(engine.tx().traversal(), cr, ten);
+ Vertex cr =
+ engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id", "123");
+ Vertex ten = engine.tx().addVertex("aai-node-type", "tenant", "tenant-id", "453");
- Edge e = dbser.getEdgeBetween(EdgeType.TREE, ten, cr, null);
- assertEquals("org.onap.relationships.inventory.BelongsTo", e.label());
+ edgeSer.addTreeEdge(engine.tx().traversal(), cr, ten);
- }
+ Edge e = dbser.getEdgeBetween(EdgeType.TREE, ten, cr, null);
+ assertEquals("org.onap.relationships.inventory.BelongsTo", e.label());
- @Test
- public void deleteEdgeTest() throws AAIException, UnsupportedEncodingException {
- engine.startTransaction();
+ }
- Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf", "aai-uri", "/network/generic-vnfs/generic-vnf/myvnf");
- Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
+ @Test
+ public void deleteEdgeTest() throws AAIException, UnsupportedEncodingException {
+ engine.startTransaction();
- edgeSer.addEdge(engine.tx().traversal(), gvnf, vnfc);
+ Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
+ "/network/generic-vnfs/generic-vnf/myvnf");
+ Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri",
+ "/network/vnfcs/vnfc/a-name");
- Introspector relData = loader.introspectorFromName("relationship-data");
- relData.setValue("relationship-key", "vnfc.vnfc-name");
- relData.setValue("relationship-value", "a-name");
- Introspector relationship = loader.introspectorFromName("relationship");
- relationship.setValue("related-to", "vnfc");
- relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
- relationship.setValue("relationship-data",relData);
+ edgeSer.addEdge(engine.tx().traversal(), gvnf, vnfc);
- assertTrue(dbser.deleteEdge(relationship, gvnf));
+ Introspector relData = loader.introspectorFromName("relationship-data");
+ relData.setValue("relationship-key", "vnfc.vnfc-name");
+ relData.setValue("relationship-value", "a-name");
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-data", relData);
- assertFalse(engine.tx().traversal().V(gvnf).both("uses").hasNext());
- assertFalse(engine.tx().traversal().V(vnfc).both("uses").hasNext());
+ assertTrue(dbser.deleteEdge(relationship, gvnf));
- }
+ assertFalse(engine.tx().traversal().V(gvnf).both("uses").hasNext());
+ assertFalse(engine.tx().traversal().V(vnfc).both("uses").hasNext());
- @Test
- public void createEdgeTest() throws AAIException, UnsupportedEncodingException {
- engine.startTransaction();
+ }
- Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf", "aai-uri", "/network/generic-vnfs/generic-vnf/myvnf");
- Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
+ @Test
+ public void createEdgeTest() throws AAIException, UnsupportedEncodingException {
+ engine.startTransaction();
- //sunny day case
- Introspector relData = loader.introspectorFromName("relationship-data");
- relData.setValue("relationship-key", "vnfc.vnfc-name");
- relData.setValue("relationship-value", "a-name");
- Introspector relationship = loader.introspectorFromName("relationship");
- relationship.setValue("related-to", "vnfc");
- relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
- relationship.setValue("relationship-data",relData);
+ Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
+ "/network/generic-vnfs/generic-vnf/myvnf");
+ Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri",
+ "/network/vnfcs/vnfc/a-name");
- assertTrue(dbser.createEdge(relationship, gvnf));
- assertTrue(engine.tx().traversal().V(gvnf).both("org.onap.relationships.inventory.BelongsTo").hasNext());
- assertTrue(engine.tx().traversal().V(vnfc).both("org.onap.relationships.inventory.BelongsTo").hasNext());
+ // sunny day case
+ Introspector relData = loader.introspectorFromName("relationship-data");
+ relData.setValue("relationship-key", "vnfc.vnfc-name");
+ relData.setValue("relationship-value", "a-name");
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-data", relData);
- }
+ assertTrue(dbser.createEdge(relationship, gvnf));
+ assertTrue(engine.tx().traversal().V(gvnf).both("org.onap.relationships.inventory.BelongsTo").hasNext());
+ assertTrue(engine.tx().traversal().V(vnfc).both("org.onap.relationships.inventory.BelongsTo").hasNext());
- @Test
- public void createCousinEdgeThatShouldBeTreeTest() throws AAIException, UnsupportedEncodingException, URISyntaxException {
- engine.startTransaction();
+ }
- Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf", "aai-uri", "/network/generic-vnfs/generic-vnf/myvnf");
- Vertex vf = engine.tx().addVertex("aai-node-type","vf-module","vf-module-id","vf-id", "aai-uri", "/network/generic-vnfs/generic-vnf/myvnf/vf-modules/vf-module/vf-id");
+ @Test
+ public void createCousinEdgeThatShouldBeTreeTest()
+ throws AAIException, UnsupportedEncodingException, URISyntaxException {
+ engine.startTransaction();
+
+ Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
+ "/network/generic-vnfs/generic-vnf/myvnf");
+ Vertex vf = engine.tx().addVertex("aai-node-type", "vf-module", "vf-module-id", "vf-id", "aai-uri",
+ "/network/generic-vnfs/generic-vnf/myvnf/vf-modules/vf-module/vf-id");
+
+ edgeSer.addTreeEdge(engine.tx().traversal(), gvnf, vf);
+
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vf-module");
+ relationship.setValue("related-link", dbser.getURIForVertex(vf).toString());
+ Introspector relationshipList = loader.introspectorFromName("relationship-list");
+ relationshipList.setValue("relationship", Collections.singletonList(relationship.getUnderlyingObject()));
+
+ Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
+ Vertex gvnf2 = dbser.createNewVertex(gvnfObj);
+ gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
+ gvnfObj.setValue("vnf-id", "myvnf-1");
+
+ QueryParser uriQuery =
+ dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf-1"));
+
+ try {
+ dbser.serializeToDb(gvnfObj, gvnf2, uriQuery, null, "test");
+ } catch (AAIException e) {
+ assertEquals("AAI_6145", e.getCode());
+ }
+ }
+
+ @Test
+ public void createEdgeNodeDoesNotExistExceptionTest() throws AAIException, UnsupportedEncodingException {
+ engine.startTransaction();
+
+ Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
+ "/network/generic-vnfs/generic-vnf/myvnf");
+
+ // rainy day case, edge to non-existent object
+ Introspector relData = loader.introspectorFromName("relationship-data");
+ relData.setValue("relationship-key", "vnfc.vnfc-name");
+ relData.setValue("relationship-value", "b-name");
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/b-name");
+ relationship.setValue("relationship-data", relData);
+
+ thrown.expect(AAIException.class);
+ thrown.expectMessage("Node of type vnfc. Could not find object at: /network/vnfcs/vnfc/b-name");
+ dbser.createEdge(relationship, gvnf);
+
+ }
- edgeSer.addTreeEdge(engine.tx().traversal(), gvnf, vf);
+ @Test
+ public void serializeSingleVertexTopLevelTest() throws AAIException, UnsupportedEncodingException {
+ engine.startTransaction();
+
+ Introspector gvnf = loader.introspectorFromName("generic-vnf");
+ Vertex gvnfVert = dbser.createNewVertex(gvnf);
+
+ gvnf.setValue("vnf-id", "myvnf");
+ dbser.serializeSingleVertex(gvnfVert, gvnf, "test");
+ assertTrue(engine.tx().traversal().V().has("aai-node-type", "generic-vnf").has("vnf-id", "myvnf").hasNext());
+
+ }
+
+ @Test
+ public void serializeSingleVertexChildTest() throws AAIException, UnsupportedEncodingException {
+ engine.startTransaction();
- Introspector relationship = loader.introspectorFromName("relationship");
- relationship.setValue("related-to", "vf-module");
- relationship.setValue("related-link", dbser.getURIForVertex(vf).toString());
- Introspector relationshipList = loader.introspectorFromName("relationship-list");
- relationshipList.setValue("relationship", Collections.singletonList(relationship.getUnderlyingObject()));
+ Vertex cr = engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id",
+ "123", "aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/me/123");
+ Introspector tenIn = loader.introspectorFromName("tenant");
+ Vertex ten = dbser.createNewVertex(tenIn);
+ ten.property("aai-uri", cr.property("aai-uri").value().toString() + "/tenants/tenant/453");
- Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
- Vertex gvnf2 = dbser.createNewVertex(gvnfObj);
- gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
- gvnfObj.setValue("vnf-id", "myvnf-1");
+ edgeSer.addTreeEdge(engine.tx().traversal(), cr, ten);
- QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf-1"));
+ tenIn.setValue("tenant-id", "453");
+ tenIn.setValue("tenant-name", "mytenant");
- try {
- dbser.serializeToDb(gvnfObj, gvnf2, uriQuery, null, "test");
- } catch (AAIException e) {
- assertEquals("AAI_6145", e.getCode());
- }
- }
+ dbser.serializeSingleVertex(ten, tenIn, "test");
- @Test
- public void createEdgeNodeDoesNotExistExceptionTest() throws AAIException, UnsupportedEncodingException {
- engine.startTransaction();
+ assertTrue(engine.tx().traversal().V().has("aai-node-type", "tenant").has("tenant-id", "453")
+ .has("tenant-name", "mytenant").hasNext());
- Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf", "aai-uri", "/network/generic-vnfs/generic-vnf/myvnf");
+ }
- //rainy day case, edge to non-existent object
- Introspector relData = loader.introspectorFromName("relationship-data");
- relData.setValue("relationship-key", "vnfc.vnfc-name");
- relData.setValue("relationship-value", "b-name");
- Introspector relationship = loader.introspectorFromName("relationship");
- relationship.setValue("related-to", "vnfc");
- relationship.setValue("related-link", "/network/vnfcs/vnfc/b-name");
- relationship.setValue("relationship-data",relData);
+ @Test
+ public void getVertexPropertiesRelationshipHasLabelTest() throws AAIException, UnsupportedEncodingException {
+ engine.startTransaction();
- thrown.expect(AAIException.class);
- thrown.expectMessage("Node of type vnfc. Could not find object at: /network/vnfcs/vnfc/b-name");
- dbser.createEdge(relationship, gvnf);
+ Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "vnf-123", "aai-uri",
+ "/network/generic-vnfs/generic-vnf/vnf-123");
+ Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "vnfc-123", "aai-uri",
+ "/network/vnfcs/vnfc/vnfc-123");
- }
+ edgeSer.addEdge(engine.tx().traversal(), gvnf, vnfc);
- @Test
- public void serializeSingleVertexTopLevelTest() throws AAIException, UnsupportedEncodingException {
- engine.startTransaction();
+ Introspector obj = loader.introspectorFromName("generic-vnf");
+ obj = this.dbser.dbToObject(Arrays.asList(gvnf), obj, AAIProperties.MAXIMUM_DEPTH, false, "false");
- Introspector gvnf = loader.introspectorFromName("generic-vnf");
- Vertex gvnfVert = dbser.createNewVertex(gvnf);
+ MarshallerProperties properties =
+ new MarshallerProperties.Builder(org.onap.aai.restcore.MediaType.getEnum("application/json"))
+ .formatted(true).build();
+ System.out.println(obj.marshal(properties));
- gvnf.setValue("vnf-id", "myvnf");
- dbser.serializeSingleVertex(gvnfVert, gvnf, "test");
- assertTrue(engine.tx().traversal().V().has("aai-node-type","generic-vnf").has("vnf-id","myvnf").hasNext());
+ assertEquals("edge label between generic-vnf and vnfs is uses", "org.onap.relationships.inventory.BelongsTo",
+ obj.getWrappedValue("relationship-list").getWrappedListValue("relationship").get(0)
+ .getValue("relationship-label"));
- }
+ }
- @Test
- public void serializeSingleVertexChildTest() throws AAIException, UnsupportedEncodingException {
- engine.startTransaction();
+ @Test
+ public void getVertexPropertiesRelationshipOldVersionNoEdgeLabelTest()
+ throws AAIException, UnsupportedEncodingException {
- Vertex cr = engine.tx().addVertex("aai-node-type", "cloud-region", "cloud-owner", "me", "cloud-region-id", "123", "aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/me/123");
- Introspector tenIn = loader.introspectorFromName("tenant");
- Vertex ten = dbser.createNewVertex(tenIn);
- ten.property("aai-uri", cr.property("aai-uri").value().toString() + "/tenants/tenant/453");
+ SchemaVersion version = schemaVersions.getAppRootVersion();
+ DBSerializer dbser = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST");
+ Loader loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version);
- edgeSer.addTreeEdge(engine.tx().traversal(), cr, ten);
+ engine.startTransaction();
- tenIn.setValue("tenant-id", "453");
- tenIn.setValue("tenant-name", "mytenant");
+ Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "vnf-123", "aai-uri",
+ "/network/generic-vnfs/generic-vnf/vnf-123");
+ Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "vnfc-123", "aai-uri",
+ "/network/vnfcs/vnfc/vnfc-123");
- dbser.serializeSingleVertex(ten, tenIn, "test");
+ edgeSer.addEdge(engine.tx().traversal(), gvnf, vnfc);
- assertTrue(engine.tx().traversal().V().has("aai-node-type","tenant").has("tenant-id","453").has("tenant-name","mytenant").hasNext());
+ Introspector obj = loader.introspectorFromName("generic-vnf");
+ obj = dbser.dbToObject(Arrays.asList(gvnf), obj, AAIProperties.MAXIMUM_DEPTH, false, "false");
- }
+ assertEquals("Relationship does not contain edge-property", false, obj.getWrappedValue("relationship-list")
+ .getWrappedListValue("relationship").get(0).hasProperty("relationship-label"));
+ }
- @Test
- public void getVertexPropertiesRelationshipHasLabelTest() throws AAIException, UnsupportedEncodingException {
- engine.startTransaction();
+ @Test
+ public void createEdgeWithInvalidLabelTest() throws AAIException, UnsupportedEncodingException,
+ NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
- Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","vnf-123","aai-uri", "/network/generic-vnfs/generic-vnf/vnf-123");
- Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","vnfc-123","aai-uri", "/network/vnfcs/vnfc/vnfc-123");
+ engine.startTransaction();
- edgeSer.addEdge(engine.tx().traversal(), gvnf, vnfc);
+ Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
+ "/network/generic-vnfs/generic-vnf/myvnf");
+ engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
- Introspector obj = loader.introspectorFromName("generic-vnf");
- obj = this.dbser.dbToObject(Arrays.asList(gvnf), obj, AAIProperties.MAXIMUM_DEPTH, false, "false");
+ Introspector relData = loader.introspectorFromName("relationship-data");
+ relData.setValue("relationship-key", "vnfc.vnfc-name");
+ relData.setValue("relationship-value", "a-name");
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-data", relData);
+ relationship.setValue("relationship-label", "NA");
+ thrown.expect(AAIException.class);
+ thrown.expectMessage("No rule found");
+ thrown.expectMessage("node type: generic-vnf, node type: vnfc, label: NA, type: COUSIN");
+ dbser.createEdge(relationship, gvnf);
- MarshallerProperties properties = new MarshallerProperties
- .Builder(org.onap.aai.restcore.MediaType.getEnum("application/json")).formatted(true).build();
- System.out.println(obj.marshal(properties));
+ }
- assertEquals("edge label between generic-vnf and vnfs is uses",
- "org.onap.relationships.inventory.BelongsTo",
- obj.getWrappedValue("relationship-list")
- .getWrappedListValue("relationship")
- .get(0)
- .getValue("relationship-label")
- );
+ @Test
+ public void addRelatedToPropertyTest() throws AAIException {
+ engine.startTransaction();
+
+ Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myname", "vnf-name", "myname",
+ "aai-uri", "/network/generic-vnfs/generic-vnf/myname");
+ engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
+ Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getAppRootVersion());
+ Introspector gv = loader.introspectorFromName("generic-vnf");
+ gv.setValue("vnf-name", "myname");
+
+ Introspector rel = loader.introspectorFromName("relationship");
+ DBSerializer dbser = new DBSerializer(schemaVersions.getAppRootVersion(), dbEngine, ModelType.MOXY, "AAI-TEST");
+ dbser.addRelatedToProperty(rel, gvnf, "generic-vnf");
+ List<Introspector> relToProps = rel.getWrappedListValue("related-to-property");
+ assertThat(relToProps.size(), is(1));
+ Introspector relToProp = relToProps.get(0);
+ assertThat(relToProp.getValue("property-key"), is("generic-vnf.vnf-name"));
+ assertThat(relToProp.getValue("property-value"), is("myname"));
+ }
+ @Test
+ public void dbToObjectContainerMismatchTest() throws AAIException, UnsupportedEncodingException {
+ DBSerializer dbser = new DBSerializer(schemaVersions.getAppRootVersion(), dbEngine, ModelType.MOXY, "AAI-TEST");
+ Graph vertexMaker = TinkerGraph.open();
+ Vertex a = vertexMaker.addVertex(T.id, "0");
+ Vertex b = vertexMaker.addVertex(T.id, "1");
+ List<Vertex> vertices = Arrays.asList(a, b);
- }
+ Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getAppRootVersion());
+ Introspector intro = loader.introspectorFromName("image"); // just need any non-container object
- @Test
- public void getVertexPropertiesRelationshipOldVersionNoEdgeLabelTest() throws AAIException, UnsupportedEncodingException {
+ thrown.expect(AAIException.class);
+ thrown.expectMessage("query object mismatch: this object cannot hold multiple items.");
- SchemaVersion version = schemaVersions.getAppRootVersion();
- DBSerializer dbser = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST");
- Loader loader = loaderFactory.createLoaderForVersion(introspectorFactoryType, version);
+ dbser.dbToObject(vertices, intro, Integer.MAX_VALUE, true, "doesn't matter");
+ }
- engine.startTransaction();
+ @Test
+ public void dbToObjectTest() throws AAIException, UnsupportedEncodingException {
+ engine.startTransaction();
- Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","vnf-123", "aai-uri", "/network/generic-vnfs/generic-vnf/vnf-123");
- Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","vnfc-123", "aai-uri", "/network/vnfcs/vnfc/vnfc-123");
+ DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
+ Vertex gv1 = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1");
+ Vertex gv2 = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id2");
+ List<Vertex> vertices = Arrays.asList(gv1, gv2);
- edgeSer.addEdge(engine.tx().traversal(), gvnf, vnfc);
+ Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, version);
+ Introspector gvContainer = loader.introspectorFromName("generic-vnfs");
- Introspector obj = loader.introspectorFromName("generic-vnf");
- obj = dbser.dbToObject(Arrays.asList(gvnf), obj, AAIProperties.MAXIMUM_DEPTH, false, "false");
+ Introspector res = dbser.dbToObject(vertices, gvContainer, 0, true, "true");
+ List<Introspector> gvs = res.getWrappedListValue("generic-vnf");
+ assertTrue(gvs.size() == 2);
+ for (Introspector i : gvs) {
+ String vnfId = i.getValue("vnf-id");
+ assertTrue("id1".equals(vnfId) || "id2".equals(vnfId));
+ }
- assertEquals("Relationship does not contain edge-property", false, obj.getWrappedValue("relationship-list").getWrappedListValue("relationship").get(0).hasProperty("relationship-label"));
+ }
+ @Test
+ public void getEdgeBetweenNoLabelTest() throws AAIException {
+ DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
+ engine.startTransaction();
+ Vertex gv = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1");
+ Vertex lint = engine.tx().addVertex("aai-node-type", "l-interface", "interface-name", "name1");
+ edgeSer.addTreeEdge(engine.tx().traversal(), gv, lint);
- }
+ Edge res = dbser.getEdgeBetween(EdgeType.TREE, gv, lint);
+ assertEquals("org.onap.relationships.inventory.BelongsTo", res.label());
- @Test
- public void createEdgeWithInvalidLabelTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
+ }
- engine.startTransaction();
+ @Test
+ public void deleteItemsWithTraversal() throws AAIException {
+ DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
+ engine.startTransaction();
+ Vertex gv = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1");
+ Vertex lint = engine.tx().addVertex("aai-node-type", "l-interface", "interface-name", "name1");
- Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf", "aai-uri", "/network/generic-vnfs/generic-vnf/myvnf");
- engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
+ assertTrue(engine.tx().traversal().V().has("vnf-id", "id1").hasNext());
+ assertTrue(engine.tx().traversal().V().has("interface-name", "name1").hasNext());
- Introspector relData = loader.introspectorFromName("relationship-data");
- relData.setValue("relationship-key", "vnfc.vnfc-name");
- relData.setValue("relationship-value", "a-name");
- Introspector relationship = loader.introspectorFromName("relationship");
- relationship.setValue("related-to", "vnfc");
- relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
- relationship.setValue("relationship-data",relData);
- relationship.setValue("relationship-label", "NA");
+ dbser.deleteItemsWithTraversal(Arrays.asList(gv, lint));
- thrown.expect(AAIException.class);
- thrown.expectMessage("No rule found");
- thrown.expectMessage("node type: generic-vnf, node type: vnfc, label: NA, type: COUSIN");
- dbser.createEdge(relationship, gvnf);
+ assertTrue(!engine.tx().traversal().V().has("vnf-id", "id1").hasNext());
+ assertTrue(!engine.tx().traversal().V().has("interface-name", "name1").hasNext());
- }
+ }
- @Test
- public void addRelatedToPropertyTest() throws AAIException {
- engine.startTransaction();
+ @Test
+ public void serializeToDbWithParentTest() throws AAIException, UnsupportedEncodingException, URISyntaxException {
+ DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
+ engine.startTransaction();
+ Vertex gv = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1", "aai-uri",
+ "/network/generic-vnfs/generic-vnf/id1");
+ Vertex lint = engine.tx().addVertex("aai-node-type", "l-interface");
+ edgeSer.addTreeEdge(engine.tx().traversal(), gv, lint);
- Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf",
- "vnf-id","myname",
- "vnf-name","myname",
- "aai-uri", "/network/generic-vnfs/generic-vnf/myname"
- );
- engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
- Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getAppRootVersion());
- Introspector gv = loader.introspectorFromName("generic-vnf");
- gv.setValue("vnf-name", "myname");
+ Introspector lintIntro = loader.introspectorFromName("l-interface");
+ lintIntro.setValue("interface-name", "name1");
+ lintIntro.setValue("interface-role", "actor");
+ URI lintURI = new URI("/network/generic-vnfs/generic-vnf/id1/l-interfaces/l-interface/name1");
+ QueryParser uriQuery = engine.getQueryBuilder(gv).createQueryFromURI(lintURI);
+ dbser.serializeToDb(lintIntro, lint, uriQuery, "test-identifier", "AAI-TEST");
- Introspector rel = loader.introspectorFromName("relationship");
- DBSerializer dbser = new DBSerializer(schemaVersions.getAppRootVersion(), dbEngine,
- ModelType.MOXY, "AAI-TEST");
- dbser.addRelatedToProperty(rel, gvnf, "generic-vnf");
- List<Introspector> relToProps = rel.getWrappedListValue("related-to-property");
- assertThat(relToProps.size(), is(1));
- Introspector relToProp = relToProps.get(0);
- assertThat(relToProp.getValue("property-key"), is("generic-vnf.vnf-name"));
- assertThat(relToProp.getValue("property-value"), is("myname"));
- }
+ assertTrue(engine.tx().traversal().V(lint).has("interface-role", "actor").hasNext());
- @Test
- public void dbToObjectContainerMismatchTest() throws AAIException, UnsupportedEncodingException {
- DBSerializer dbser = new DBSerializer(schemaVersions.getAppRootVersion(), dbEngine,
- ModelType.MOXY, "AAI-TEST");
- Graph vertexMaker = TinkerGraph.open();
- Vertex a = vertexMaker.addVertex(T.id, "0");
- Vertex b = vertexMaker.addVertex(T.id, "1");
- List<Vertex> vertices = Arrays.asList(a,b);
+ }
- Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getAppRootVersion());
- Introspector intro = loader.introspectorFromName("image"); //just need any non-container object
+ @Test
+ public void getLatestVersionViewTest() throws AAIException, UnsupportedEncodingException {
+ DBSerializer dbser = new DBSerializer(version, engine, ModelType.MOXY, "AAI-TEST");
+ engine.startTransaction();
+ Vertex phys = engine.tx().addVertex("aai-node-type", "physical-link", "link-name", "zaldo", "speed-value",
+ "very-fast", "service-provider-bandwidth-up-units", "things");
+
+ Introspector res = dbser.getLatestVersionView(phys);
+ assertTrue("zaldo".equals(res.getValue("link-name")));
+ assertTrue("very-fast".equals(res.getValue("speed-value")));
+ assertTrue("things".equals(res.getValue("service-provider-bandwidth-up-units")));
+ }
- thrown.expect(AAIException.class);
- thrown.expectMessage("query object mismatch: this object cannot hold multiple items.");
-
- dbser.dbToObject(vertices, intro, Integer.MAX_VALUE, true, "doesn't matter");
- }
-
- @Test
- public void dbToObjectTest() throws AAIException, UnsupportedEncodingException {
- engine.startTransaction();
-
- DBSerializer dbser = new DBSerializer(version, engine,
- ModelType.MOXY, "AAI-TEST");
- Vertex gv1 = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1");
- Vertex gv2 = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id2");
- List<Vertex> vertices = Arrays.asList(gv1, gv2);
-
- Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, version);
- Introspector gvContainer = loader.introspectorFromName("generic-vnfs");
-
- Introspector res = dbser.dbToObject(vertices, gvContainer, 0, true, "true");
- List<Introspector> gvs = res.getWrappedListValue("generic-vnf");
- assertTrue(gvs.size() == 2);
- for (Introspector i : gvs) {
- String vnfId = i.getValue("vnf-id");
- assertTrue("id1".equals(vnfId) || "id2".equals(vnfId));
- }
-
-
- }
-
- @Test
- public void getEdgeBetweenNoLabelTest() throws AAIException {
- DBSerializer dbser = new DBSerializer(version, engine,
- ModelType.MOXY, "AAI-TEST");
- engine.startTransaction();
- Vertex gv = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1");
- Vertex lint = engine.tx().addVertex("aai-node-type", "l-interface", "interface-name", "name1");
- edgeSer.addTreeEdge(engine.tx().traversal(), gv, lint);
-
- Edge res = dbser.getEdgeBetween(EdgeType.TREE, gv, lint);
- assertEquals("org.onap.relationships.inventory.BelongsTo", res.label());
-
- }
-
- @Test
- public void deleteItemsWithTraversal() throws AAIException {
- DBSerializer dbser = new DBSerializer(version, engine,
- ModelType.MOXY, "AAI-TEST");
- engine.startTransaction();
- Vertex gv = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1");
- Vertex lint = engine.tx().addVertex("aai-node-type", "l-interface", "interface-name", "name1");
-
- assertTrue(engine.tx().traversal().V().has("vnf-id", "id1").hasNext());
- assertTrue(engine.tx().traversal().V().has("interface-name", "name1").hasNext());
-
- dbser.deleteItemsWithTraversal(Arrays.asList(gv, lint));
-
- assertTrue(!engine.tx().traversal().V().has("vnf-id", "id1").hasNext());
- assertTrue(!engine.tx().traversal().V().has("interface-name", "name1").hasNext());
-
-
- }
-
- @Test
- public void serializeToDbWithParentTest() throws AAIException, UnsupportedEncodingException, URISyntaxException {
- DBSerializer dbser = new DBSerializer(version, engine,
- ModelType.MOXY, "AAI-TEST");
- engine.startTransaction();
- Vertex gv = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "id1", "aai-uri", "/network/generic-vnfs/generic-vnf/id1");
- Vertex lint = engine.tx().addVertex("aai-node-type", "l-interface");
- edgeSer.addTreeEdge(engine.tx().traversal(), gv, lint);
-
- Introspector lintIntro = loader.introspectorFromName("l-interface");
- lintIntro.setValue("interface-name", "name1");
- lintIntro.setValue("interface-role", "actor");
- URI lintURI = new URI("/network/generic-vnfs/generic-vnf/id1/l-interfaces/l-interface/name1");
- QueryParser uriQuery = engine.getQueryBuilder(gv).createQueryFromURI(lintURI);
- dbser.serializeToDb(lintIntro, lint, uriQuery, "test-identifier", "AAI-TEST");
-
- assertTrue(engine.tx().traversal().V(lint).has("interface-role", "actor").hasNext());
-
-
- }
-
- @Test
- public void getLatestVersionViewTest() throws AAIException, UnsupportedEncodingException {
- DBSerializer dbser = new DBSerializer(version, engine,
- ModelType.MOXY, "AAI-TEST");
- engine.startTransaction();
- Vertex phys = engine.tx().addVertex("aai-node-type", "physical-link", "link-name", "zaldo",
- "speed-value", "very-fast", "service-provider-bandwidth-up-units", "things");
-
- Introspector res = dbser.getLatestVersionView(phys);
- assertTrue("zaldo".equals(res.getValue("link-name")));
- assertTrue("very-fast".equals(res.getValue("speed-value")));
- assertTrue("things".equals(res.getValue("service-provider-bandwidth-up-units")));
- }
+ @Test
+ public void cascadeVserverDeleteTest() throws AAIException {
+ vserverSetup();
+ String expected_message = "";
- @Test
- public void cascadeVserverDeleteTest() throws AAIException {
- vserverSetup();
- String expected_message = "";
+ /*
+ * vserver-->l-interface -->logical-link
+ * -->l3-ipvx-list
+ */
+ Vertex vserver = graph.traversal().V().has("aai-node-type", "vserver").has("vserver-id", "vss1").next();
- /* vserver-->l-interface -->logical-link
- * -->l3-ipvx-list
- */
- Vertex vserver = graph.traversal().V().has("aai-node-type", "vserver").has("vserver-id", "vss1").next();
-
- String exceptionMessage = testCascadeDelete(vserver);
- assertEquals(expected_message, exceptionMessage);
-
- }
-
- @Test
- public void cascadeL3NetworkPreventDeleteTest() throws AAIException {
- l3NetworkSetup();
- ArrayList expected_messages = new ArrayList<String>();
- expected_messages.add("Object is being reference by additional objects preventing it from being deleted. Please clean up references from the following types [l3-interface-ipv4-address-list, l3-interface-ipv6-address-list]");
- expected_messages.add("Object is being reference by additional objects preventing it from being deleted. Please clean up references from the following types [l3-interface-ipv6-address-list, l3-interface-ipv4-address-list]");
-
- /* vserver-->l-interface -->logical-link
- * -->l3-ipvx-list
- */
- Vertex l3network = graph.traversal().V().has("aai-node-type", "l3-network").has("network-id", "network-id-v1").next();
+ String exceptionMessage = testCascadeDelete(vserver);
+ assertEquals(expected_message, exceptionMessage);
- String exceptionMessage = testCascadeDelete(l3network);
- assertTrue(expected_messages.contains(exceptionMessage));
+ }
- }
+ @Test
+ public void cascadeL3NetworkPreventDeleteTest() throws AAIException {
+ l3NetworkSetup();
+ ArrayList expected_messages = new ArrayList<String>();
+ expected_messages.add(
+ "Object is being reference by additional objects preventing it from being deleted. Please clean up references from the following types [l3-interface-ipv4-address-list, l3-interface-ipv6-address-list]");
+ expected_messages.add(
+ "Object is being reference by additional objects preventing it from being deleted. Please clean up references from the following types [l3-interface-ipv6-address-list, l3-interface-ipv4-address-list]");
+
+ /*
+ * vserver-->l-interface -->logical-link
+ * -->l3-ipvx-list
+ */
+ Vertex l3network =
+ graph.traversal().V().has("aai-node-type", "l3-network").has("network-id", "network-id-v1").next();
+
+ String exceptionMessage = testCascadeDelete(l3network);
+ assertTrue(expected_messages.contains(exceptionMessage));
+
+ }
- @Test
- public void cascadeL3NetworkDeleteTest() throws AAIException {
- l3NetworkSetup();
- String expected_message = "";
+ @Test
+ public void cascadeL3NetworkDeleteTest() throws AAIException {
+ l3NetworkSetup();
+ String expected_message = "";
- /* vserver-->l-interface -->logical-link
- * -->l3-ipvx-list
- */
- Vertex l3network = graph.traversal().V().has("aai-node-type", "l3-network").has("network-id", "network-id-v2").next();
+ /*
+ * vserver-->l-interface -->logical-link
+ * -->l3-ipvx-list
+ */
+ Vertex l3network =
+ graph.traversal().V().has("aai-node-type", "l3-network").has("network-id", "network-id-v2").next();
- String exceptionMessage = testCascadeDelete(l3network);
- assertEquals(expected_message, exceptionMessage);
+ String exceptionMessage = testCascadeDelete(l3network);
+ assertEquals(expected_message, exceptionMessage);
- }
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializer_needsFakeRulesTest.java b/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializer_needsFakeRulesTest.java
index 1ddef28c..808dd631 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializer_needsFakeRulesTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/db/DbSerializer_needsFakeRulesTest.java
@@ -17,18 +17,25 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.serialization.db;
-import org.onap.aai.config.ConfigConfiguration;
-import org.onap.aai.setup.SchemaVersion;
-import org.onap.aai.setup.SchemaVersions;
-import org.onap.aai.util.AAIConstants;
-import org.janusgraph.core.JanusGraphFactory;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.*;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.*;
+import org.janusgraph.core.JanusGraphFactory;
import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
+import org.onap.aai.config.ConfigConfiguration;
import org.onap.aai.config.IntrospectionConfig;
import org.onap.aai.config.SpringContextAware;
import org.onap.aai.db.props.AAIProperties;
@@ -38,609 +45,678 @@ import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.*;
import org.onap.aai.nodes.NodeIngestor;
import org.onap.aai.parsers.query.QueryParser;
-import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.JanusGraphDBEngine;
+import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
import org.onap.aai.serialization.queryformats.QueryFormatTestHelper;
import org.onap.aai.setup.SchemaLocationsBean;
+import org.onap.aai.setup.SchemaVersion;
+import org.onap.aai.setup.SchemaVersions;
+import org.onap.aai.util.AAIConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.*;
-
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
//@RunWith(value = Parameterized.class) TODO replace this functionality
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(classes = {
- ConfigConfiguration.class,
- AAICoreFakeEdgesConfigTranslator.class,
- NodeIngestor.class,
- EdgeIngestor.class,
- EdgeSerializer.class,
- SpringContextAware.class,
- IntrospectionConfig.class
-})
-@TestPropertySource(properties = {
- "schema.translator.list = config",
- "schema.nodes.location=src/test/resources/onap/oxm",
- "schema.edges.location=src/test/resources/onap/dbedgerules"
-})
+@ContextConfiguration(
+ classes = {ConfigConfiguration.class, AAICoreFakeEdgesConfigTranslator.class, NodeIngestor.class,
+ EdgeIngestor.class, EdgeSerializer.class, SpringContextAware.class, IntrospectionConfig.class})
+@TestPropertySource(
+ properties = {"schema.translator.list = config", "schema.nodes.location=src/test/resources/onap/oxm",
+ "schema.edges.location=src/test/resources/onap/dbedgerules"})
public class DbSerializer_needsFakeRulesTest {
- //to use, set thrown.expect to whatever your test needs
- //this line establishes default of expecting no exception to be thrown
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- protected static Graph graph;
-
- @Autowired
- protected EdgeSerializer edgeSer;
- @Autowired
- protected EdgeIngestor ei;
- @Autowired
- protected SchemaVersions schemaVersions;
-
- private SchemaVersion version;
- private final ModelType introspectorFactoryType = ModelType.MOXY;
- private final DBConnectionType type = DBConnectionType.REALTIME;
- private Loader loader;
- private TransactionalGraphEngine dbEngine;
- private TransactionalGraphEngine engine; //for tests that aren't mocking the engine
- private DBSerializer dbser;
- TransactionalGraphEngine spy;
- TransactionalGraphEngine.Admin adminSpy;
-
- //@Parameterized.Parameter(value = 0)
- public QueryStyle queryStyle = QueryStyle.TRAVERSAL;
-
- /*@Parameterized.Parameters(name = "QueryStyle.{0}")
- public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][]{
- {QueryStyle.TRAVERSAL},
- {QueryStyle.TRAVERSAL_URI}
- });
- }*/
-
- @BeforeClass
- public static void init() throws Exception {
- graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
- System.setProperty("AJSC_HOME", ".");
+ // to use, set thrown.expect to whatever your test needs
+ // this line establishes default of expecting no exception to be thrown
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ protected static Graph graph;
+
+ @Autowired
+ protected EdgeSerializer edgeSer;
+ @Autowired
+ protected EdgeIngestor ei;
+ @Autowired
+ protected SchemaVersions schemaVersions;
+
+ private SchemaVersion version;
+ private final ModelType introspectorFactoryType = ModelType.MOXY;
+ private final DBConnectionType type = DBConnectionType.REALTIME;
+ private Loader loader;
+ private TransactionalGraphEngine dbEngine;
+ private TransactionalGraphEngine engine; // for tests that aren't mocking the engine
+ private DBSerializer dbser;
+ TransactionalGraphEngine spy;
+ TransactionalGraphEngine.Admin adminSpy;
+
+ // @Parameterized.Parameter(value = 0)
+ public QueryStyle queryStyle = QueryStyle.TRAVERSAL;
+
+ /*
+ * @Parameterized.Parameters(name = "QueryStyle.{0}")
+ * public static Collection<Object[]> data() {
+ * return Arrays.asList(new Object[][]{
+ * {QueryStyle.TRAVERSAL},
+ * {QueryStyle.TRAVERSAL_URI}
+ * });
+ * }
+ */
+
+ @BeforeClass
+ public static void init() throws Exception {
+ graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
+ System.setProperty("AJSC_HOME", ".");
System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
- QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"), "src/test/resources/bundleconfig-local/etc/oxm/");
+ QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"),
+ "src/test/resources/bundleconfig-local/etc/oxm/");
- }
+ }
- @Before
- public void setup() throws Exception {
- //createGraph();
+ @Before
+ public void setup() throws Exception {
+ // createGraph();
version = schemaVersions.getDefaultVersion();
- loader = SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectorFactoryType, version);
- dbEngine = new JanusGraphDBEngine(queryStyle, type, loader);
- spy = spy(dbEngine);
- adminSpy = spy(dbEngine.asAdmin());
-
-
- engine = new JanusGraphDBEngine(queryStyle, type, loader);
- dbser = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST");
- }
-
- @After
- public void tearDown() throws Exception {
- engine.rollback();
- }
-
- @AfterClass
- public static void destroy() throws Exception {
- graph.close();
- }
-
- public void subnetSetup() throws AAIException {
- /*
- * This setus up the test graph, For future junits , add more vertices
- * and edges
- */
-
- Vertex l3interipv4addresslist_1 = graph.traversal().addV("aai-node-type", "l3-interface-ipv4-address-list",
- "l3-interface-ipv4-address", "l3-interface-ipv4-address-1").next();
- Vertex subnet_2 = graph.traversal().addV("aai-node-type", "subnet", "subnet-id", "subnet-id-2").next();
- Vertex l3interipv6addresslist_3 = graph.traversal().addV("aai-node-type", "l3-interface-ipv6-address-list",
- "l3-interface-ipv6-address", "l3-interface-ipv6-address-3").next();
- Vertex subnet_4 = graph.traversal().addV("aai-node-type", "subnet", "subnet-id", "subnet-id-4").next();
- Vertex subnet_5 = graph.traversal().addV("aai-node-type", "subnet", "subnet-id", "subnet-id-5").next();
- Vertex l3network_6 = graph.traversal()
- .addV("aai-node-type", "l3-network", "network-id", "network-id-6", "network-name", "network-name-6")
- .next();
-
- GraphTraversalSource g = graph.traversal();
- edgeSer.addEdge(g, l3interipv4addresslist_1, subnet_2);
- edgeSer.addEdge(g, l3interipv6addresslist_3, subnet_4);
- edgeSer.addTreeEdge(g, subnet_5, l3network_6);
- }
-
- public String testDelete(Vertex v) throws AAIException {
-
- GraphTraversalSource traversal = graph.traversal();
- when(spy.asAdmin()).thenReturn(adminSpy);
- when(adminSpy.getTraversalSource()).thenReturn(traversal);
- when(adminSpy.getReadOnlyTraversalSource()).thenReturn(traversal);
-
- String exceptionMessage = "";
- DBSerializer serializer = new DBSerializer(version, spy, introspectorFactoryType, "AAI_TEST");
- try {
- serializer.delete(v, "resourceVersion", false);
- } catch (AAIException exception) {
- exceptionMessage = exception.getMessage();
- }
- return exceptionMessage;
-
- }
-
- @Test
- public void serializeToDbNewVertexAndEdgeAAIUUIDTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, URISyntaxException {
- String testName = new Object() {}.getClass().getEnclosingMethod().getName();
- DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
-
- engine.startTransaction();
-
- engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","vnfc-" + testName, AAIProperties.AAI_URI, "/network/vnfcs/vnfc/vnfc-" + testName);
-
- Introspector relationship = loader.introspectorFromName("relationship");
- relationship.setValue("related-to", "vnfc");
- relationship.setValue("related-link", "/network/vnfcs/vnfc/vnfc-" + testName);
-
- Introspector relationshipList = loader.introspectorFromName("relationship-list");
- relationshipList.setValue("relationship", Collections.singletonList(relationship.getUnderlyingObject()));
-
- Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
- Vertex gvnf = localDbser.createNewVertex(gvnfObj);
- gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
- gvnfObj.setValue("vnf-id", "vnf-" + testName);
-
- QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/vnf-" + testName));
-
- localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
- assertTrue("Generic-vnf has uuid ", gvnf.property(AAIProperties.AAI_UUID).isPresent());
- assertTrue("Edge has uuid ", gvnf.edges(Direction.BOTH).next().property(AAIProperties.AAI_UUID).isPresent());
-
- }
-
- @Test
- public void createEdgeWithValidLabelTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
-
- DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
-
- engine.startTransaction();
-
- Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf", "aai-uri", "/network/generic-vnfs/generic-vnf/myvnf");
- Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
-
- //sunny day case
- Introspector relData = loader.introspectorFromName("relationship-data");
- relData.setValue("relationship-key", "vnfc.vnfc-name");
- relData.setValue("relationship-value", "a-name");
- Introspector relationship = loader.introspectorFromName("relationship");
- relationship.setValue("related-to", "vnfc");
- relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
- relationship.setValue("relationship-data",relData);
- relationship.setValue("relationship-label", "over-uses");
-
- assertTrue(localDbser.createEdge(relationship, gvnf));
- assertTrue(engine.tx().traversal().V(gvnf).both("over-uses").hasNext());
- assertTrue(engine.tx().traversal().V(vnfc).both("over-uses").hasNext());
-
- }
-
- @Test
- public void createEdgeWithValidLabelWhenSameEdgeExistsTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
-
- DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
- engine.startTransaction();
-
- Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf", "aai-uri", "/network/generic-vnfs/generic-vnf/myvnf");
- Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
- edgeSer.addEdge(graph.traversal(), gvnf, vnfc, "re-uses");
-
- Introspector relData = loader.introspectorFromName("relationship-data");
- relData.setValue("relationship-key", "vnfc.vnfc-name");
- relData.setValue("relationship-value", "a-name");
- Introspector relationship = loader.introspectorFromName("relationship");
- relationship.setValue("related-to", "vnfc");
- relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
- relationship.setValue("relationship-data",relData);
- relationship.setValue("relationship-label", "re-uses");
-
- assertTrue(localDbser.createEdge(relationship, gvnf));
- assertTrue(engine.tx().traversal().V(gvnf).both("re-uses").hasNext());
- assertTrue(engine.tx().traversal().V(vnfc).both("re-uses").hasNext());
- assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V(vnfc).both().count().next());
-
- }
-
- @Test
- public void createEdgeWithValidLabelWhenDiffEdgeExistsTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
-
- DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
- engine.startTransaction();
-
- Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf", "aai-uri", "/network/generic-vnfs/generic-vnf/myvnf");
- Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
- edgeSer.addEdge(graph.traversal(), gvnf, vnfc, "uses");
-
- Introspector relData = loader.introspectorFromName("relationship-data");
- relData.setValue("relationship-key", "vnfc.vnfc-name");
- relData.setValue("relationship-value", "a-name");
- Introspector relationship = loader.introspectorFromName("relationship");
- relationship.setValue("related-to", "vnfc");
- relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
- relationship.setValue("relationship-data",relData);
- relationship.setValue("relationship-label", "uses");
- localDbser.createEdge(relationship, gvnf);
-
- relationship.setValue("relationship-label", "re-uses");
-
- assertTrue(localDbser.createEdge(relationship, gvnf));
- assertTrue(engine.tx().traversal().V(gvnf).both("re-uses").hasNext());
- assertTrue(engine.tx().traversal().V(vnfc).both("re-uses").hasNext());
- assertTrue(engine.tx().traversal().V(gvnf).both("uses").hasNext());
- assertTrue(engine.tx().traversal().V(vnfc).both("uses").hasNext());
- assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V(vnfc).both().count().next());
- assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V(gvnf).both().count().next());
-
- }
-
- @Test
- public void createEdgeWithNoLabelTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
-
- DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
- engine.startTransaction();
-
- Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf", "aai-uri", "/network/generic-vnfs/generic-vnf/myvnf");
- Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
-
- Introspector relData = loader.introspectorFromName("relationship-data");
- relData.setValue("relationship-key", "vnfc.vnfc-name");
- relData.setValue("relationship-value", "a-name");
- Introspector relationship = loader.introspectorFromName("relationship");
- relationship.setValue("related-to", "vnfc");
- relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
- relationship.setValue("relationship-data",relData);
- localDbser.createEdge(relationship, gvnf);
-
- assertTrue(localDbser.createEdge(relationship, gvnf));
- assertTrue(engine.tx().traversal().V(gvnf).both("uses").hasNext());
- assertTrue(engine.tx().traversal().V(vnfc).both("uses").hasNext());
- assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V(vnfc).both().count().next());
- assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V(gvnf).both().count().next());
-
-
- }
-
- @Test
- public void deleteEdgeWithNoLabelWhenMultipleExistsTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
-
- DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
- engine.startTransaction();
-
- Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf", "aai-uri", "/network/generic-vnfs/generic-vnf/myvnf");
- Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
- edgeSer.addEdge(graph.traversal(), gvnf, vnfc, "uses");
- edgeSer.addEdge(graph.traversal(), gvnf, vnfc, "re-uses");
- edgeSer.addEdge(graph.traversal(), gvnf, vnfc, "over-uses");
-
- Introspector relData = loader.introspectorFromName("relationship-data");
- relData.setValue("relationship-key", "vnfc.vnfc-name");
- relData.setValue("relationship-value", "a-name");
- Introspector relationship = loader.introspectorFromName("relationship");
- relationship.setValue("related-to", "vnfc");
- relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
- relationship.setValue("relationship-data",relData);
-
- assertTrue(localDbser.deleteEdge(relationship, gvnf));
- assertFalse("generic-vnf has no edge uses", engine.tx().traversal().V(gvnf).both("uses").hasNext());
- assertFalse("vnfc has no edge uses", engine.tx().traversal().V(vnfc).both("uses").hasNext());
- assertTrue("generic-vnf has edge re-uses", engine.tx().traversal().V(gvnf).both("re-uses").hasNext());
- assertTrue("vnfc has edge re-uses", engine.tx().traversal().V(vnfc).both("re-uses").hasNext());
- assertTrue("generic-vnf has edge re-uses", engine.tx().traversal().V(gvnf).both("over-uses").hasNext());
- assertTrue("vnfc has edge re-uses", engine.tx().traversal().V(vnfc).both("over-uses").hasNext());
- assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V(vnfc).both().count().next());
- assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V(gvnf).both().count().next());
-
- }
-
- @Test
- public void deleteEdgeWithValidLabelWhenMultipleExistsTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
-
- DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
-
- engine.startTransaction();
-
- Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf", "aai-uri", "/network/generic-vnfs/generic-vnf/myvnf");
- Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
- edgeSer.addEdge(graph.traversal(), gvnf, vnfc, "uses");
- edgeSer.addEdge(graph.traversal(), gvnf, vnfc, "re-uses");
- edgeSer.addEdge(graph.traversal(), gvnf, vnfc, "over-uses");
-
- Introspector relData = loader.introspectorFromName("relationship-data");
- relData.setValue("relationship-key", "vnfc.vnfc-name");
- relData.setValue("relationship-value", "a-name");
- Introspector relationship = loader.introspectorFromName("relationship");
- relationship.setValue("related-to", "vnfc");
- relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
- relationship.setValue("relationship-data",relData);
- relationship.setValue("relationship-label", "re-uses");
-
- assertTrue(localDbser.deleteEdge(relationship, gvnf));
- assertTrue("generic-vnf has edge uses", engine.tx().traversal().V(gvnf).both("uses").hasNext());
- assertTrue("vnfc has edge uses", engine.tx().traversal().V(vnfc).both("uses").hasNext());
- assertFalse("generic-vnf has no edge re-uses", engine.tx().traversal().V(gvnf).both("re-uses").hasNext());
- assertFalse("vnfc has no edge re-uses", engine.tx().traversal().V(vnfc).both("re-uses").hasNext());
- assertTrue("generic-vnf has edge re-uses", engine.tx().traversal().V(gvnf).both("over-uses").hasNext());
- assertTrue("vnfc has edge re-uses", engine.tx().traversal().V(vnfc).both("over-uses").hasNext());
- assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V(vnfc).both().count().next());
- assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V(gvnf).both().count().next());
-
- }
-
- @Test
- public void deleteEdgeWithValidInvalidLabelWhenMultipleExistsTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
-
- DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
-
- engine.startTransaction();
-
- Vertex gvnf = engine.tx().addVertex("aai-node-type","generic-vnf","vnf-id","myvnf", "aai-uri", "/network/generic-vnfs/generic-vnf/myvnf");
- Vertex vnfc = engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
- edgeSer.addEdge(graph.traversal(), gvnf, vnfc, "uses");
- edgeSer.addEdge(graph.traversal(), gvnf, vnfc, "re-uses");
- edgeSer.addEdge(graph.traversal(), gvnf, vnfc, "over-uses");
-
- Introspector relData = loader.introspectorFromName("relationship-data");
- relData.setValue("relationship-key", "vnfc.vnfc-name");
- relData.setValue("relationship-value", "a-name");
- Introspector relationship = loader.introspectorFromName("relationship");
- relationship.setValue("related-to", "vnfc");
- relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
- relationship.setValue("relationship-data",relData);
- relationship.setValue("relationship-label", "NA");
-
- thrown.expect(AAIException.class);
- thrown.expectMessage("No rule found");
- thrown.expectMessage("node type: generic-vnf, node type: vnfc, label: NA, type: COUSIN");
- localDbser.deleteEdge(relationship, gvnf);
- }
-
- @Test
- public void serializeToDbWithLabelTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, URISyntaxException {
-
- DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
-
- engine.startTransaction();
-
- engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
-
- Introspector relationship = loader.introspectorFromName("relationship");
- relationship.setValue("related-to", "vnfc");
- relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
- relationship.setValue("relationship-label", "re-uses");
- Introspector relationshipList = loader.introspectorFromName("relationship-list");
- relationshipList.setValue("relationship", Collections.singletonList(relationship.getUnderlyingObject()));
-
- Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
- Vertex gvnf = localDbser.createNewVertex(gvnfObj);
- gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
- gvnfObj.setValue("vnf-id", "myvnf");
-
- QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf"));
-
- localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
-
- assertTrue("vertex with vnf-id myvnf exists", engine.tx().traversal().V().has("vnf-id", "myvnf").hasNext());
- assertTrue("vertex with vnfc-name a-name exists", engine.tx().traversal().V().has("vnfc-name", "a-name").hasNext());
- assertFalse("generic-vnf has no edge re-uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("uses").hasNext());
- assertFalse("vnfc has no edge re-uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("uses").hasNext());
- assertTrue("generic-vnf has edge re-uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("re-uses").hasNext());
- assertTrue("vnfc has edge re-uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("re-uses").hasNext());
- assertFalse("generic-vnf has no edge re-uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("over-uses").hasNext());
- assertFalse("vnfc has no edge re-uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("over-uses").hasNext());
- assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V().has("vnfc-name", "a-name").both().count().next());
- assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V().has("vnf-id", "myvnf").both().count().next());
-
- }
-
- @Test
- public void serializeToDbWithoutLabelTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, URISyntaxException {
-
- DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
-
- engine.startTransaction();
-
- engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
-
- Introspector relationship = loader.introspectorFromName("relationship");
- relationship.setValue("related-to", "vnfc");
- relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
-
- Introspector relationshipList = loader.introspectorFromName("relationship-list");
- relationshipList.setValue("relationship", Collections.singletonList(relationship.getUnderlyingObject()));
-
- Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
- Vertex gvnf = localDbser.createNewVertex(gvnfObj);
- gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
- gvnfObj.setValue("vnf-id", "myvnf");
-
- QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf"));
-
- localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
-
- assertTrue("vertex with vnf-id myvnf exists", engine.tx().traversal().V().has("vnf-id", "myvnf").hasNext());
- assertTrue("vertex with vnfc-name a-name exists", engine.tx().traversal().V().has("vnfc-name", "a-name").hasNext());
- assertTrue("generic-vnf has edge uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("uses").hasNext());
- assertTrue("vnfc has edge uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("uses").hasNext());
- assertFalse("generic-vnf has no edge re-uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("re-uses").hasNext());
- assertFalse("vnfc has no edge re-uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("re-uses").hasNext());
- assertFalse("generic-vnf has no edge over-uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("over-uses").hasNext());
- assertFalse("vnfc has no edge over-uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("over-uses").hasNext());
- assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V().has("vnfc-name", "a-name").both().count().next());
- assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V().has("vnf-id", "myvnf").both().count().next());
-
- }
-
- @Test
- public void serializeToDbWithInvalidLabelTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, URISyntaxException {
-
- DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
-
- engine.startTransaction();
-
- engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
-
- Introspector relationship = loader.introspectorFromName("relationship");
- relationship.setValue("related-to", "vnfc");
- relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
- relationship.setValue("relationship-label", "NA");
- Introspector relationshipList = loader.introspectorFromName("relationship-list");
- relationshipList.setValue("relationship", Collections.singletonList(relationship.getUnderlyingObject()));
-
- Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
- Vertex gvnf = localDbser.createNewVertex(gvnfObj);
- gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
- gvnfObj.setValue("vnf-id", "myvnf");
-
- QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf"));
-
- thrown.expect(AAIException.class);
- thrown.expectMessage("No EdgeRule found for passed nodeTypes: generic-vnf, vnfc with label NA.");
- localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
-
- }
-
- @Test
- public void serializeToDbWithLabelAndEdgeExistsTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, URISyntaxException {
-
- DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
-
- engine.startTransaction();
- engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
-
- Introspector relationship;
- Introspector relationshipList;
- List<Object> relList = new ArrayList<>();
-
- // create generic-vnf
- Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
- Vertex gvnf = localDbser.createNewVertex(gvnfObj);
- gvnfObj.setValue("vnf-id", "myvnf");
- QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf"));
-
- // create relationship to vnfc
- relationship = loader.introspectorFromName("relationship");
- relationship.setValue("related-to", "vnfc");
- relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
- relList.add(relationship.getUnderlyingObject());
- relationshipList = loader.introspectorFromName("relationship-list");
- relationshipList.setValue("relationship", relList);
- gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
-
- // add gvnf to graph
- localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
-
- // add second relationship
- relationship = loader.introspectorFromName("relationship");
- relationship.setValue("related-to", "vnfc");
- relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
- relationship.setValue("relationship-label", "re-uses");
- relList.add(relationship.getUnderlyingObject());
- relationshipList = loader.introspectorFromName("relationship-list");
- relationshipList.setValue("relationship", relList);
- gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
-
- localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
-
- assertTrue("vertex with vnf-id myvnf exists", engine.tx().traversal().V().has("vnf-id", "myvnf").hasNext());
- assertTrue("vertex with vnfc-name a-name exists", engine.tx().traversal().V().has("vnfc-name", "a-name").hasNext());
- assertTrue("generic-vnf has edge uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("uses").hasNext());
- assertTrue("vnfc has edge uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("uses").hasNext());
- assertTrue("generic-vnf has edge re-uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("re-uses").hasNext());
- assertTrue("vnfc has edge re-uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("re-uses").hasNext());
- assertFalse("generic-vnf has no edge over-uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("over-uses").hasNext());
- assertFalse("vnfc has no edge over-uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("over-uses").hasNext());
- assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V().has("vnfc-name", "a-name").both().count().next());
- assertEquals("Number of edges between vertexes is 2", Long.valueOf(2), engine.tx().traversal().V().has("vnf-id", "myvnf").both().count().next());
-
- }
-
- @Test
- public void serializeToDbWithLabelDroppingRelationshipTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, URISyntaxException {
-
- DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
-
- engine.startTransaction();
- engine.tx().addVertex("aai-node-type","vnfc","vnfc-name","a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
-
-
- Introspector relationship;
- Introspector relationshipList;
- List<Object> relList = new ArrayList<>();
-
- // create generic-vnf
- Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
- Vertex gvnf = localDbser.createNewVertex(gvnfObj);
- gvnfObj.setValue("vnf-id", "myvnf");
- QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf"));
-
- // create relationship to vnfc
- relationship = loader.introspectorFromName("relationship");
- relationship.setValue("related-to", "vnfc");
- relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
- relList.add(relationship.getUnderlyingObject());
- // add second relationship
- relationship = loader.introspectorFromName("relationship");
- relationship.setValue("related-to", "vnfc");
- relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
- relationship.setValue("relationship-label", "re-uses");
- relList.add(relationship.getUnderlyingObject());
- relationshipList = loader.introspectorFromName("relationship-list");
- relationshipList.setValue("relationship", relList);
- gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
-
- // add gvnf to graph
- localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
-
- // drop second relationship
- relList.remove(1);
- relationshipList = loader.introspectorFromName("relationship-list");
- relationshipList.setValue("relationship", relList);
- gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
-
- localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
-
- assertTrue("vertex with vnf-id myvnf exists", engine.tx().traversal().V().has("vnf-id", "myvnf").hasNext());
- assertTrue("vertex with vnfc-name a-name exists", engine.tx().traversal().V().has("vnfc-name", "a-name").hasNext());
- assertTrue("generic-vnf has edge uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("uses").hasNext());
- assertTrue("vnfc has edge uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("uses").hasNext());
- assertFalse("generic-vnf no longer has edge re-uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("re-uses").hasNext());
- assertFalse("vnfc no longer has edge re-uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("re-uses").hasNext());
- assertFalse("generic-vnf has no edge over-uses", engine.tx().traversal().V().has("vnf-id", "myvnf").both("over-uses").hasNext());
- assertFalse("vnfc has no edge over-uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("over-uses").hasNext());
- assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V().has("vnfc-name", "a-name").both().count().next());
- assertEquals("Number of edges between vertexes is 1", Long.valueOf(1), engine.tx().traversal().V().has("vnf-id", "myvnf").both().count().next());
-
- }
-
- private DBSerializer getDBSerializerWithSpecificEdgeRules()
- throws NoSuchFieldException, AAIException, IllegalAccessException {
-
-
- DBSerializer localDbser = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST");
- return localDbser;
- }
+ loader = SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(introspectorFactoryType,
+ version);
+ dbEngine = new JanusGraphDBEngine(queryStyle, type, loader);
+ spy = spy(dbEngine);
+ adminSpy = spy(dbEngine.asAdmin());
+
+ engine = new JanusGraphDBEngine(queryStyle, type, loader);
+ dbser = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST");
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ engine.rollback();
+ }
+
+ @AfterClass
+ public static void destroy() throws Exception {
+ graph.close();
+ }
+
+ public void subnetSetup() throws AAIException {
+ /*
+ * This setus up the test graph, For future junits , add more vertices
+ * and edges
+ */
+
+ Vertex l3interipv4addresslist_1 = graph.traversal().addV("aai-node-type", "l3-interface-ipv4-address-list",
+ "l3-interface-ipv4-address", "l3-interface-ipv4-address-1").next();
+ Vertex subnet_2 = graph.traversal().addV("aai-node-type", "subnet", "subnet-id", "subnet-id-2").next();
+ Vertex l3interipv6addresslist_3 = graph.traversal().addV("aai-node-type", "l3-interface-ipv6-address-list",
+ "l3-interface-ipv6-address", "l3-interface-ipv6-address-3").next();
+ Vertex subnet_4 = graph.traversal().addV("aai-node-type", "subnet", "subnet-id", "subnet-id-4").next();
+ Vertex subnet_5 = graph.traversal().addV("aai-node-type", "subnet", "subnet-id", "subnet-id-5").next();
+ Vertex l3network_6 = graph.traversal()
+ .addV("aai-node-type", "l3-network", "network-id", "network-id-6", "network-name", "network-name-6")
+ .next();
+
+ GraphTraversalSource g = graph.traversal();
+ edgeSer.addEdge(g, l3interipv4addresslist_1, subnet_2);
+ edgeSer.addEdge(g, l3interipv6addresslist_3, subnet_4);
+ edgeSer.addTreeEdge(g, subnet_5, l3network_6);
+ }
+
+ public String testDelete(Vertex v) throws AAIException {
+
+ GraphTraversalSource traversal = graph.traversal();
+ when(spy.asAdmin()).thenReturn(adminSpy);
+ when(adminSpy.getTraversalSource()).thenReturn(traversal);
+ when(adminSpy.getReadOnlyTraversalSource()).thenReturn(traversal);
+
+ String exceptionMessage = "";
+ DBSerializer serializer = new DBSerializer(version, spy, introspectorFactoryType, "AAI_TEST");
+ try {
+ serializer.delete(v, "resourceVersion", false);
+ } catch (AAIException exception) {
+ exceptionMessage = exception.getMessage();
+ }
+ return exceptionMessage;
+
+ }
+
+ @Test
+ public void serializeToDbNewVertexAndEdgeAAIUUIDTest()
+ throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException,
+ IllegalArgumentException, IllegalAccessException, URISyntaxException {
+ String testName = new Object() {}.getClass().getEnclosingMethod().getName();
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
+
+ engine.startTransaction();
+
+ engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "vnfc-" + testName, AAIProperties.AAI_URI,
+ "/network/vnfcs/vnfc/vnfc-" + testName);
+
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/vnfc-" + testName);
+
+ Introspector relationshipList = loader.introspectorFromName("relationship-list");
+ relationshipList.setValue("relationship", Collections.singletonList(relationship.getUnderlyingObject()));
+
+ Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
+ Vertex gvnf = localDbser.createNewVertex(gvnfObj);
+ gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
+ gvnfObj.setValue("vnf-id", "vnf-" + testName);
+
+ QueryParser uriQuery = dbEngine.getQueryBuilder()
+ .createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/vnf-" + testName));
+
+ localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
+ assertTrue("Generic-vnf has uuid ", gvnf.property(AAIProperties.AAI_UUID).isPresent());
+ assertTrue("Edge has uuid ", gvnf.edges(Direction.BOTH).next().property(AAIProperties.AAI_UUID).isPresent());
+
+ }
+
+ @Test
+ public void createEdgeWithValidLabelTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException,
+ SecurityException, IllegalArgumentException, IllegalAccessException {
+
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
+
+ engine.startTransaction();
+
+ Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
+ "/network/generic-vnfs/generic-vnf/myvnf");
+ Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri",
+ "/network/vnfcs/vnfc/a-name");
+
+ // sunny day case
+ Introspector relData = loader.introspectorFromName("relationship-data");
+ relData.setValue("relationship-key", "vnfc.vnfc-name");
+ relData.setValue("relationship-value", "a-name");
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-data", relData);
+ relationship.setValue("relationship-label", "over-uses");
+
+ assertTrue(localDbser.createEdge(relationship, gvnf));
+ assertTrue(engine.tx().traversal().V(gvnf).both("over-uses").hasNext());
+ assertTrue(engine.tx().traversal().V(vnfc).both("over-uses").hasNext());
+
+ }
+
+ @Test
+ public void createEdgeWithValidLabelWhenSameEdgeExistsTest() throws AAIException, UnsupportedEncodingException,
+ NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
+
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
+ engine.startTransaction();
+
+ Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
+ "/network/generic-vnfs/generic-vnf/myvnf");
+ Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri",
+ "/network/vnfcs/vnfc/a-name");
+ edgeSer.addEdge(graph.traversal(), gvnf, vnfc, "re-uses");
+
+ Introspector relData = loader.introspectorFromName("relationship-data");
+ relData.setValue("relationship-key", "vnfc.vnfc-name");
+ relData.setValue("relationship-value", "a-name");
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-data", relData);
+ relationship.setValue("relationship-label", "re-uses");
+
+ assertTrue(localDbser.createEdge(relationship, gvnf));
+ assertTrue(engine.tx().traversal().V(gvnf).both("re-uses").hasNext());
+ assertTrue(engine.tx().traversal().V(vnfc).both("re-uses").hasNext());
+ assertEquals("Number of edges between vertexes is 1", Long.valueOf(1),
+ engine.tx().traversal().V(vnfc).both().count().next());
+
+ }
+
+ @Test
+ public void createEdgeWithValidLabelWhenDiffEdgeExistsTest() throws AAIException, UnsupportedEncodingException,
+ NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
+
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
+ engine.startTransaction();
+
+ Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
+ "/network/generic-vnfs/generic-vnf/myvnf");
+ Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri",
+ "/network/vnfcs/vnfc/a-name");
+ edgeSer.addEdge(graph.traversal(), gvnf, vnfc, "uses");
+
+ Introspector relData = loader.introspectorFromName("relationship-data");
+ relData.setValue("relationship-key", "vnfc.vnfc-name");
+ relData.setValue("relationship-value", "a-name");
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-data", relData);
+ relationship.setValue("relationship-label", "uses");
+ localDbser.createEdge(relationship, gvnf);
+
+ relationship.setValue("relationship-label", "re-uses");
+
+ assertTrue(localDbser.createEdge(relationship, gvnf));
+ assertTrue(engine.tx().traversal().V(gvnf).both("re-uses").hasNext());
+ assertTrue(engine.tx().traversal().V(vnfc).both("re-uses").hasNext());
+ assertTrue(engine.tx().traversal().V(gvnf).both("uses").hasNext());
+ assertTrue(engine.tx().traversal().V(vnfc).both("uses").hasNext());
+ assertEquals("Number of edges between vertexes is 2", Long.valueOf(2),
+ engine.tx().traversal().V(vnfc).both().count().next());
+ assertEquals("Number of edges between vertexes is 2", Long.valueOf(2),
+ engine.tx().traversal().V(gvnf).both().count().next());
+
+ }
+
+ @Test
+ public void createEdgeWithNoLabelTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException,
+ SecurityException, IllegalArgumentException, IllegalAccessException {
+
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
+ engine.startTransaction();
+
+ Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
+ "/network/generic-vnfs/generic-vnf/myvnf");
+ Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri",
+ "/network/vnfcs/vnfc/a-name");
+
+ Introspector relData = loader.introspectorFromName("relationship-data");
+ relData.setValue("relationship-key", "vnfc.vnfc-name");
+ relData.setValue("relationship-value", "a-name");
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-data", relData);
+ localDbser.createEdge(relationship, gvnf);
+
+ assertTrue(localDbser.createEdge(relationship, gvnf));
+ assertTrue(engine.tx().traversal().V(gvnf).both("uses").hasNext());
+ assertTrue(engine.tx().traversal().V(vnfc).both("uses").hasNext());
+ assertEquals("Number of edges between vertexes is 1", Long.valueOf(1),
+ engine.tx().traversal().V(vnfc).both().count().next());
+ assertEquals("Number of edges between vertexes is 1", Long.valueOf(1),
+ engine.tx().traversal().V(gvnf).both().count().next());
+
+ }
+
+ @Test
+ public void deleteEdgeWithNoLabelWhenMultipleExistsTest() throws AAIException, UnsupportedEncodingException,
+ NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
+
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
+ engine.startTransaction();
+
+ Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
+ "/network/generic-vnfs/generic-vnf/myvnf");
+ Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri",
+ "/network/vnfcs/vnfc/a-name");
+ edgeSer.addEdge(graph.traversal(), gvnf, vnfc, "uses");
+ edgeSer.addEdge(graph.traversal(), gvnf, vnfc, "re-uses");
+ edgeSer.addEdge(graph.traversal(), gvnf, vnfc, "over-uses");
+
+ Introspector relData = loader.introspectorFromName("relationship-data");
+ relData.setValue("relationship-key", "vnfc.vnfc-name");
+ relData.setValue("relationship-value", "a-name");
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-data", relData);
+
+ assertTrue(localDbser.deleteEdge(relationship, gvnf));
+ assertFalse("generic-vnf has no edge uses", engine.tx().traversal().V(gvnf).both("uses").hasNext());
+ assertFalse("vnfc has no edge uses", engine.tx().traversal().V(vnfc).both("uses").hasNext());
+ assertTrue("generic-vnf has edge re-uses", engine.tx().traversal().V(gvnf).both("re-uses").hasNext());
+ assertTrue("vnfc has edge re-uses", engine.tx().traversal().V(vnfc).both("re-uses").hasNext());
+ assertTrue("generic-vnf has edge re-uses", engine.tx().traversal().V(gvnf).both("over-uses").hasNext());
+ assertTrue("vnfc has edge re-uses", engine.tx().traversal().V(vnfc).both("over-uses").hasNext());
+ assertEquals("Number of edges between vertexes is 2", Long.valueOf(2),
+ engine.tx().traversal().V(vnfc).both().count().next());
+ assertEquals("Number of edges between vertexes is 2", Long.valueOf(2),
+ engine.tx().traversal().V(gvnf).both().count().next());
+
+ }
+
+ @Test
+ public void deleteEdgeWithValidLabelWhenMultipleExistsTest() throws AAIException, UnsupportedEncodingException,
+ NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
+
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
+
+ engine.startTransaction();
+
+ Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
+ "/network/generic-vnfs/generic-vnf/myvnf");
+ Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri",
+ "/network/vnfcs/vnfc/a-name");
+ edgeSer.addEdge(graph.traversal(), gvnf, vnfc, "uses");
+ edgeSer.addEdge(graph.traversal(), gvnf, vnfc, "re-uses");
+ edgeSer.addEdge(graph.traversal(), gvnf, vnfc, "over-uses");
+
+ Introspector relData = loader.introspectorFromName("relationship-data");
+ relData.setValue("relationship-key", "vnfc.vnfc-name");
+ relData.setValue("relationship-value", "a-name");
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-data", relData);
+ relationship.setValue("relationship-label", "re-uses");
+
+ assertTrue(localDbser.deleteEdge(relationship, gvnf));
+ assertTrue("generic-vnf has edge uses", engine.tx().traversal().V(gvnf).both("uses").hasNext());
+ assertTrue("vnfc has edge uses", engine.tx().traversal().V(vnfc).both("uses").hasNext());
+ assertFalse("generic-vnf has no edge re-uses", engine.tx().traversal().V(gvnf).both("re-uses").hasNext());
+ assertFalse("vnfc has no edge re-uses", engine.tx().traversal().V(vnfc).both("re-uses").hasNext());
+ assertTrue("generic-vnf has edge re-uses", engine.tx().traversal().V(gvnf).both("over-uses").hasNext());
+ assertTrue("vnfc has edge re-uses", engine.tx().traversal().V(vnfc).both("over-uses").hasNext());
+ assertEquals("Number of edges between vertexes is 2", Long.valueOf(2),
+ engine.tx().traversal().V(vnfc).both().count().next());
+ assertEquals("Number of edges between vertexes is 2", Long.valueOf(2),
+ engine.tx().traversal().V(gvnf).both().count().next());
+
+ }
+
+ @Test
+ public void deleteEdgeWithValidInvalidLabelWhenMultipleExistsTest()
+ throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException,
+ IllegalArgumentException, IllegalAccessException {
+
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
+
+ engine.startTransaction();
+
+ Vertex gvnf = engine.tx().addVertex("aai-node-type", "generic-vnf", "vnf-id", "myvnf", "aai-uri",
+ "/network/generic-vnfs/generic-vnf/myvnf");
+ Vertex vnfc = engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri",
+ "/network/vnfcs/vnfc/a-name");
+ edgeSer.addEdge(graph.traversal(), gvnf, vnfc, "uses");
+ edgeSer.addEdge(graph.traversal(), gvnf, vnfc, "re-uses");
+ edgeSer.addEdge(graph.traversal(), gvnf, vnfc, "over-uses");
+
+ Introspector relData = loader.introspectorFromName("relationship-data");
+ relData.setValue("relationship-key", "vnfc.vnfc-name");
+ relData.setValue("relationship-value", "a-name");
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-data", relData);
+ relationship.setValue("relationship-label", "NA");
+
+ thrown.expect(AAIException.class);
+ thrown.expectMessage("No rule found");
+ thrown.expectMessage("node type: generic-vnf, node type: vnfc, label: NA, type: COUSIN");
+ localDbser.deleteEdge(relationship, gvnf);
+ }
+
+ @Test
+ public void serializeToDbWithLabelTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException,
+ SecurityException, IllegalArgumentException, IllegalAccessException, URISyntaxException {
+
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
+
+ engine.startTransaction();
+
+ engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
+
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-label", "re-uses");
+ Introspector relationshipList = loader.introspectorFromName("relationship-list");
+ relationshipList.setValue("relationship", Collections.singletonList(relationship.getUnderlyingObject()));
+
+ Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
+ Vertex gvnf = localDbser.createNewVertex(gvnfObj);
+ gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
+ gvnfObj.setValue("vnf-id", "myvnf");
+
+ QueryParser uriQuery =
+ dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf"));
+
+ localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
+
+ assertTrue("vertex with vnf-id myvnf exists", engine.tx().traversal().V().has("vnf-id", "myvnf").hasNext());
+ assertTrue("vertex with vnfc-name a-name exists",
+ engine.tx().traversal().V().has("vnfc-name", "a-name").hasNext());
+ assertFalse("generic-vnf has no edge re-uses",
+ engine.tx().traversal().V().has("vnf-id", "myvnf").both("uses").hasNext());
+ assertFalse("vnfc has no edge re-uses",
+ engine.tx().traversal().V().has("vnfc-name", "a-name").both("uses").hasNext());
+ assertTrue("generic-vnf has edge re-uses",
+ engine.tx().traversal().V().has("vnf-id", "myvnf").both("re-uses").hasNext());
+ assertTrue("vnfc has edge re-uses",
+ engine.tx().traversal().V().has("vnfc-name", "a-name").both("re-uses").hasNext());
+ assertFalse("generic-vnf has no edge re-uses",
+ engine.tx().traversal().V().has("vnf-id", "myvnf").both("over-uses").hasNext());
+ assertFalse("vnfc has no edge re-uses",
+ engine.tx().traversal().V().has("vnfc-name", "a-name").both("over-uses").hasNext());
+ assertEquals("Number of edges between vertexes is 1", Long.valueOf(1),
+ engine.tx().traversal().V().has("vnfc-name", "a-name").both().count().next());
+ assertEquals("Number of edges between vertexes is 1", Long.valueOf(1),
+ engine.tx().traversal().V().has("vnf-id", "myvnf").both().count().next());
+
+ }
+
+ @Test
+ public void serializeToDbWithoutLabelTest() throws AAIException, UnsupportedEncodingException, NoSuchFieldException,
+ SecurityException, IllegalArgumentException, IllegalAccessException, URISyntaxException {
+
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
+
+ engine.startTransaction();
+
+ engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
+
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+
+ Introspector relationshipList = loader.introspectorFromName("relationship-list");
+ relationshipList.setValue("relationship", Collections.singletonList(relationship.getUnderlyingObject()));
+
+ Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
+ Vertex gvnf = localDbser.createNewVertex(gvnfObj);
+ gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
+ gvnfObj.setValue("vnf-id", "myvnf");
+
+ QueryParser uriQuery =
+ dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf"));
+
+ localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
+
+ assertTrue("vertex with vnf-id myvnf exists", engine.tx().traversal().V().has("vnf-id", "myvnf").hasNext());
+ assertTrue("vertex with vnfc-name a-name exists",
+ engine.tx().traversal().V().has("vnfc-name", "a-name").hasNext());
+ assertTrue("generic-vnf has edge uses",
+ engine.tx().traversal().V().has("vnf-id", "myvnf").both("uses").hasNext());
+ assertTrue("vnfc has edge uses", engine.tx().traversal().V().has("vnfc-name", "a-name").both("uses").hasNext());
+ assertFalse("generic-vnf has no edge re-uses",
+ engine.tx().traversal().V().has("vnf-id", "myvnf").both("re-uses").hasNext());
+ assertFalse("vnfc has no edge re-uses",
+ engine.tx().traversal().V().has("vnfc-name", "a-name").both("re-uses").hasNext());
+ assertFalse("generic-vnf has no edge over-uses",
+ engine.tx().traversal().V().has("vnf-id", "myvnf").both("over-uses").hasNext());
+ assertFalse("vnfc has no edge over-uses",
+ engine.tx().traversal().V().has("vnfc-name", "a-name").both("over-uses").hasNext());
+ assertEquals("Number of edges between vertexes is 1", Long.valueOf(1),
+ engine.tx().traversal().V().has("vnfc-name", "a-name").both().count().next());
+ assertEquals("Number of edges between vertexes is 1", Long.valueOf(1),
+ engine.tx().traversal().V().has("vnf-id", "myvnf").both().count().next());
+
+ }
+
+ @Test
+ public void serializeToDbWithInvalidLabelTest()
+ throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException,
+ IllegalArgumentException, IllegalAccessException, URISyntaxException {
+
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
+
+ engine.startTransaction();
+
+ engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
+
+ Introspector relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-label", "NA");
+ Introspector relationshipList = loader.introspectorFromName("relationship-list");
+ relationshipList.setValue("relationship", Collections.singletonList(relationship.getUnderlyingObject()));
+
+ Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
+ Vertex gvnf = localDbser.createNewVertex(gvnfObj);
+ gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
+ gvnfObj.setValue("vnf-id", "myvnf");
+
+ QueryParser uriQuery =
+ dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf"));
+
+ thrown.expect(AAIException.class);
+ thrown.expectMessage("No EdgeRule found for passed nodeTypes: generic-vnf, vnfc with label NA.");
+ localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
+
+ }
+
+ @Test
+ public void serializeToDbWithLabelAndEdgeExistsTest()
+ throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException,
+ IllegalArgumentException, IllegalAccessException, URISyntaxException {
+
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
+
+ engine.startTransaction();
+ engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
+
+ Introspector relationship;
+ Introspector relationshipList;
+ List<Object> relList = new ArrayList<>();
+
+ // create generic-vnf
+ Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
+ Vertex gvnf = localDbser.createNewVertex(gvnfObj);
+ gvnfObj.setValue("vnf-id", "myvnf");
+ QueryParser uriQuery =
+ dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf"));
+
+ // create relationship to vnfc
+ relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relList.add(relationship.getUnderlyingObject());
+ relationshipList = loader.introspectorFromName("relationship-list");
+ relationshipList.setValue("relationship", relList);
+ gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
+
+ // add gvnf to graph
+ localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
+
+ // add second relationship
+ relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-label", "re-uses");
+ relList.add(relationship.getUnderlyingObject());
+ relationshipList = loader.introspectorFromName("relationship-list");
+ relationshipList.setValue("relationship", relList);
+ gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
+
+ localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
+
+ assertTrue("vertex with vnf-id myvnf exists", engine.tx().traversal().V().has("vnf-id", "myvnf").hasNext());
+ assertTrue("vertex with vnfc-name a-name exists",
+ engine.tx().traversal().V().has("vnfc-name", "a-name").hasNext());
+ assertTrue("generic-vnf has edge uses",
+ engine.tx().traversal().V().has("vnf-id", "myvnf").both("uses").hasNext());
+ assertTrue("vnfc has edge uses",
+ engine.tx().traversal().V().has("vnfc-name", "a-name").both("uses").hasNext());
+ assertTrue("generic-vnf has edge re-uses",
+ engine.tx().traversal().V().has("vnf-id", "myvnf").both("re-uses").hasNext());
+ assertTrue("vnfc has edge re-uses",
+ engine.tx().traversal().V().has("vnfc-name", "a-name").both("re-uses").hasNext());
+ assertFalse("generic-vnf has no edge over-uses",
+ engine.tx().traversal().V().has("vnf-id", "myvnf").both("over-uses").hasNext());
+ assertFalse("vnfc has no edge over-uses",
+ engine.tx().traversal().V().has("vnfc-name", "a-name").both("over-uses").hasNext());
+ assertEquals("Number of edges between vertexes is 2", Long.valueOf(2),
+ engine.tx().traversal().V().has("vnfc-name", "a-name").both().count().next());
+ assertEquals("Number of edges between vertexes is 2", Long.valueOf(2),
+ engine.tx().traversal().V().has("vnf-id", "myvnf").both().count().next());
+
+ }
+
+ @Test
+ public void serializeToDbWithLabelDroppingRelationshipTest()
+ throws AAIException, UnsupportedEncodingException, NoSuchFieldException, SecurityException,
+ IllegalArgumentException, IllegalAccessException, URISyntaxException {
+
+ DBSerializer localDbser = getDBSerializerWithSpecificEdgeRules();
+
+ engine.startTransaction();
+ engine.tx().addVertex("aai-node-type", "vnfc", "vnfc-name", "a-name", "aai-uri", "/network/vnfcs/vnfc/a-name");
+
+ Introspector relationship;
+ Introspector relationshipList;
+ List<Object> relList = new ArrayList<>();
+
+ // create generic-vnf
+ Introspector gvnfObj = loader.introspectorFromName("generic-vnf");
+ Vertex gvnf = localDbser.createNewVertex(gvnfObj);
+ gvnfObj.setValue("vnf-id", "myvnf");
+ QueryParser uriQuery =
+ dbEngine.getQueryBuilder().createQueryFromURI(new URI("/network/generic-vnfs/generic-vnf/myvnf"));
+
+ // create relationship to vnfc
+ relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relList.add(relationship.getUnderlyingObject());
+ // add second relationship
+ relationship = loader.introspectorFromName("relationship");
+ relationship.setValue("related-to", "vnfc");
+ relationship.setValue("related-link", "/network/vnfcs/vnfc/a-name");
+ relationship.setValue("relationship-label", "re-uses");
+ relList.add(relationship.getUnderlyingObject());
+ relationshipList = loader.introspectorFromName("relationship-list");
+ relationshipList.setValue("relationship", relList);
+ gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
+
+ // add gvnf to graph
+ localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
+
+ // drop second relationship
+ relList.remove(1);
+ relationshipList = loader.introspectorFromName("relationship-list");
+ relationshipList.setValue("relationship", relList);
+ gvnfObj.setValue("relationship-list", relationshipList.getUnderlyingObject());
+
+ localDbser.serializeToDb(gvnfObj, gvnf, uriQuery, null, "test");
+
+ assertTrue("vertex with vnf-id myvnf exists", engine.tx().traversal().V().has("vnf-id", "myvnf").hasNext());
+ assertTrue("vertex with vnfc-name a-name exists",
+ engine.tx().traversal().V().has("vnfc-name", "a-name").hasNext());
+ assertTrue("generic-vnf has edge uses",
+ engine.tx().traversal().V().has("vnf-id", "myvnf").both("uses").hasNext());
+ assertTrue("vnfc has edge uses",
+ engine.tx().traversal().V().has("vnfc-name", "a-name").both("uses").hasNext());
+ assertFalse("generic-vnf no longer has edge re-uses",
+ engine.tx().traversal().V().has("vnf-id", "myvnf").both("re-uses").hasNext());
+ assertFalse("vnfc no longer has edge re-uses",
+ engine.tx().traversal().V().has("vnfc-name", "a-name").both("re-uses").hasNext());
+ assertFalse("generic-vnf has no edge over-uses",
+ engine.tx().traversal().V().has("vnf-id", "myvnf").both("over-uses").hasNext());
+ assertFalse("vnfc has no edge over-uses",
+ engine.tx().traversal().V().has("vnfc-name", "a-name").both("over-uses").hasNext());
+ assertEquals("Number of edges between vertexes is 1", Long.valueOf(1),
+ engine.tx().traversal().V().has("vnfc-name", "a-name").both().count().next());
+ assertEquals("Number of edges between vertexes is 1", Long.valueOf(1),
+ engine.tx().traversal().V().has("vnf-id", "myvnf").both().count().next());
+
+ }
+
+ private DBSerializer getDBSerializerWithSpecificEdgeRules()
+ throws NoSuchFieldException, AAIException, IllegalAccessException {
+
+ DBSerializer localDbser = new DBSerializer(version, engine, introspectorFactoryType, "AAI-TEST");
+ return localDbser;
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/db/EdgePropertyMapTest.java b/aai-core/src/test/java/org/onap/aai/serialization/db/EdgePropertyMapTest.java
index 2f3854e4..91097826 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/db/EdgePropertyMapTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/db/EdgePropertyMapTest.java
@@ -17,26 +17,27 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.serialization.db;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
import java.util.Map;
-import static org.junit.Assert.assertEquals;
+import org.junit.Test;
public class EdgePropertyMapTest {
- @Test
- public void run() {
- Map<String, String> map = new EdgePropertyMap<>();
- map.put("direction", "OUT");
- map.put("test", "hello");
- map.put("isParent", "${direction}");
- map.put("SVC-INFRA", "!${direction}");
-
- assertEquals("normal retrieval", "hello", map.get("test"));
- assertEquals("variable retrieval", "OUT", map.get("isParent"));
- assertEquals("negate variable retrieval", "IN", map.get("SVC-INFRA"));
- }
+ @Test
+ public void run() {
+ Map<String, String> map = new EdgePropertyMap<>();
+ map.put("direction", "OUT");
+ map.put("test", "hello");
+ map.put("isParent", "${direction}");
+ map.put("SVC-INFRA", "!${direction}");
+
+ assertEquals("normal retrieval", "hello", map.get("test"));
+ assertEquals("variable retrieval", "OUT", map.get("isParent"));
+ assertEquals("negate variable retrieval", "IN", map.get("SVC-INFRA"));
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/db/EdgeRulesTest.java b/aai-core/src/test/java/org/onap/aai/serialization/db/EdgeRulesTest.java
index 0bb07895..69206a40 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/db/EdgeRulesTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/db/EdgeRulesTest.java
@@ -19,10 +19,17 @@
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
+
package org.onap.aai.serialization.db;
+import static junit.framework.TestCase.fail;
+import static org.junit.Assert.assertEquals;
import com.google.common.collect.Multimap;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.junit.Rule;
import org.junit.Test;
@@ -37,64 +44,49 @@ import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException;
import org.onap.aai.setup.SchemaVersion;
import org.springframework.beans.factory.annotation.Autowired;
-import java.util.*;
-import java.util.stream.Collectors;
-
-import static junit.framework.TestCase.fail;
-import static org.junit.Assert.assertEquals;
-
public class EdgeRulesTest extends AAISetup {
- //set thrown.expect to whatever a specific test needs
- //this establishes a default of expecting no exceptions to be thrown
- @Rule
- public ExpectedException thrown = ExpectedException.none();
+ // set thrown.expect to whatever a specific test needs
+ // this establishes a default of expecting no exceptions to be thrown
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
- @Autowired
- private EdgeIngestor edgeIngestor;
+ @Autowired
+ private EdgeIngestor edgeIngestor;
- @Test
- public void verifyOutDirection() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
+ @Test
+ public void verifyOutDirection() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
- EdgeRuleQuery ruleQuery = new EdgeRuleQuery
- .Builder("cloud-region", "flavor")
- .edgeType(EdgeType.TREE)
- .build();
+ EdgeRuleQuery ruleQuery = new EdgeRuleQuery.Builder("cloud-region", "flavor").edgeType(EdgeType.TREE).build();
- EdgeRule rule = edgeIngestor.getRule(ruleQuery);
+ EdgeRule rule = edgeIngestor.getRule(ruleQuery);
- assertEquals("out direction", rule.getDirection(), Direction.IN);
- }
+ assertEquals("out direction", rule.getDirection(), Direction.IN);
+ }
- @Test
- public void verifyOutFlippedDirection() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
+ @Test
+ public void verifyOutFlippedDirection() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
- EdgeRuleQuery ruleQuery = new EdgeRuleQuery
- .Builder("flavor", "cloud-region")
- .edgeType(EdgeType.TREE)
- .build();
+ EdgeRuleQuery ruleQuery = new EdgeRuleQuery.Builder("flavor", "cloud-region").edgeType(EdgeType.TREE).build();
EdgeRule rule = edgeIngestor.getRule(ruleQuery);
- assertEquals("in direction", rule.getDirection(), Direction.OUT);
- }
+ assertEquals("in direction", rule.getDirection(), Direction.OUT);
+ }
- @Test
- public void verifyMultipleGet() throws EdgeRuleNotFoundException {
+ @Test
+ public void verifyMultipleGet() throws EdgeRuleNotFoundException {
- EdgeRuleQuery ruleQuery = new EdgeRuleQuery
- .Builder("model-element", "model-ver")
- .edgeType(EdgeType.TREE)
- .build();
+ EdgeRuleQuery ruleQuery =
+ new EdgeRuleQuery.Builder("model-element", "model-ver").edgeType(EdgeType.TREE).build();
- Multimap<String, EdgeRule> ruleMap = edgeIngestor.getRules(ruleQuery);
+ Multimap<String, EdgeRule> ruleMap = edgeIngestor.getRules(ruleQuery);
for (EdgeRule edgeRule : ruleMap.get("model|model-ver")) {
- assertEquals("has isA rule", "org.onap.relationships.inventory.IsA",
- edgeRule.getLabel());
+ assertEquals("has isA rule", "org.onap.relationships.inventory.IsA", edgeRule.getLabel());
}
- }
+ }
@Test
public void verifyAllRules() throws EdgeRuleNotFoundException {
@@ -105,29 +97,30 @@ public class EdgeRulesTest extends AAISetup {
for (SchemaVersion v : schemaVersions.getVersions()) {
Multimap<String, EdgeRule> all = edgeIngestor.getAllRules(schemaVersions.getDefaultVersion());
- //this part verifies the default properties
+ // this part verifies the default properties
// 1) can have only at most 1 containment edge between same node type pair
// 2) if there is at least 1 cousin edge, there must be exactly 1 cousin edge with default=true
for (String key : all.keySet()) {
Collection<EdgeRule> edgeRuleCollection = all.get(key);
- boolean foundContainment = false; //can have at most 1 containment rel btwn same pair of node types
+ boolean foundContainment = false; // can have at most 1 containment rel btwn same pair of node types
boolean foundCousin = false;
- boolean cousinDefault = false; //if there is a cousin edge there must be at least 1 default cousin defined
- Set<String> labels = new HashSet<>(); //all edges between the same pair must have different labels
+ boolean cousinDefault = false; // if there is a cousin edge there must be at least 1 default cousin
+ // defined
+ Set<String> labels = new HashSet<>(); // all edges between the same pair must have different labels
int cousinCount = 0;
- for(EdgeRule rule: edgeRuleCollection){
+ for (EdgeRule rule : edgeRuleCollection) {
EdgeRule match = rule;
- //check containment
+ // check containment
if (!("NONE".equals(match.getContains()))) {
if (foundContainment) {
fail("more than one containment edge defined for " + v.toString() + " " + key);
} else {
foundContainment = true;
}
- } else { //check cousin stuff
+ } else { // check cousin stuff
foundCousin = true;
cousinCount++;
if (match.isDefault()) {
@@ -139,7 +132,7 @@ public class EdgeRulesTest extends AAISetup {
}
}
- //check labels
+ // check labels
String label = match.getLabel();
if (labels.contains(label)) {
fail("same label found for multiple edges for " + v.toString() + " " + key);
@@ -148,7 +141,8 @@ public class EdgeRulesTest extends AAISetup {
}
}
if (foundCousin && !cousinDefault && cousinCount > 1) {
- fail("there is at least one cousin edge but none are designated the default for " + v.toString() + " " + key);
+ fail("there is at least one cousin edge but none are designated the default for " + v.toString()
+ + " " + key);
}
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/db/EdgeSerializerTest.java b/aai-core/src/test/java/org/onap/aai/serialization/db/EdgeSerializerTest.java
index 0cba621c..0c8bf8b5 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/db/EdgeSerializerTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/db/EdgeSerializerTest.java
@@ -17,8 +17,12 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.serialization.db;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -34,77 +38,77 @@ import org.onap.aai.exceptions.AAIException;
import org.onap.aai.serialization.db.exceptions.EdgeMultiplicityException;
import org.springframework.beans.factory.annotation.Autowired;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
public class EdgeSerializerTest extends AAISetup {
- @Autowired
- EdgeSerializer rules;
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- @Test
- public void addTreeEdgeTest() throws AAIException {
- Graph graph = TinkerGraph.open();
- Vertex v1 = graph.addVertex(T.id, "1", "aai-node-type", "cloud-region");
- Vertex v2 = graph.addVertex(T.id, "10", "aai-node-type", "tenant");
- GraphTraversalSource g = graph.traversal();
- rules.addTreeEdge(g, v1, v2);
- assertEquals(true, g.V(v1).in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "tenant").hasNext());
+ @Autowired
+ EdgeSerializer rules;
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void addTreeEdgeTest() throws AAIException {
+ Graph graph = TinkerGraph.open();
+ Vertex v1 = graph.addVertex(T.id, "1", "aai-node-type", "cloud-region");
+ Vertex v2 = graph.addVertex(T.id, "10", "aai-node-type", "tenant");
+ GraphTraversalSource g = graph.traversal();
+ rules.addTreeEdge(g, v1, v2);
+ assertEquals(true,
+ g.V(v1).in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type", "tenant").hasNext());
+
+ Vertex v3 = graph.addVertex(T.id, "2", "aai-node-type", "cloud-region");
+ assertEquals(null, rules.addTreeEdgeIfPossible(g, v3, v2));
+ }
- Vertex v3 = graph.addVertex(T.id, "2", "aai-node-type", "cloud-region");
- assertEquals(null, rules.addTreeEdgeIfPossible(g, v3, v2));
- }
+ @Test
+ public void addCousinEdgeTest() throws AAIException {
+ Graph graph = TinkerGraph.open();
+ Vertex v1 = graph.addVertex(T.id, "1", "aai-node-type", "flavor");
+ Vertex v2 = graph.addVertex(T.id, "10", "aai-node-type", "vserver");
+ GraphTraversalSource g = graph.traversal();
+ rules.addEdge(g, v1, v2);
+ assertEquals(true,
+ g.V(v2).out("org.onap.relationships.inventory.Uses").has("aai-node-type", "flavor").hasNext());
- @Test
- public void addCousinEdgeTest() throws AAIException {
- Graph graph = TinkerGraph.open();
- Vertex v1 = graph.addVertex(T.id, "1", "aai-node-type", "flavor");
- Vertex v2 = graph.addVertex(T.id, "10", "aai-node-type", "vserver");
- GraphTraversalSource g = graph.traversal();
- rules.addEdge(g, v1, v2);
- assertEquals(true, g.V(v2).out("org.onap.relationships.inventory.Uses").has("aai-node-type", "flavor").hasNext());
+ Vertex v3 = graph.addVertex(T.id, "2", "aai-node-type", "flavor");
+ assertEquals(null, rules.addEdgeIfPossible(g, v3, v2));
+ }
- Vertex v3 = graph.addVertex(T.id, "2", "aai-node-type", "flavor");
- assertEquals(null, rules.addEdgeIfPossible(g, v3, v2));
- }
+ @Test
+ public void multiplicityViolationTest() throws AAIException {
+ thrown.expect(EdgeMultiplicityException.class);
+ thrown.expectMessage(
+ "multiplicity rule violated: only one edge can exist with label: org.onap.relationships.inventory.Uses between vf-module and volume-group");
- @Test
- public void multiplicityViolationTest() throws AAIException {
- thrown.expect(EdgeMultiplicityException.class);
- thrown.expectMessage("multiplicity rule violated: only one edge can exist with label: org.onap.relationships.inventory.Uses between vf-module and volume-group");
+ Graph graph = TinkerGraph.open();
+ Vertex v1 = graph.addVertex(T.id, "1", "aai-node-type", "vf-module");
+ Vertex v2 = graph.addVertex(T.id, "10", "aai-node-type", "volume-group");
+ GraphTraversalSource g = graph.traversal();
- Graph graph = TinkerGraph.open();
- Vertex v1 = graph.addVertex(T.id, "1", "aai-node-type", "vf-module");
- Vertex v2 = graph.addVertex(T.id, "10", "aai-node-type", "volume-group");
- GraphTraversalSource g = graph.traversal();
+ rules.addEdge(g, v2, v1);
+ Vertex v3 = graph.addVertex(T.id, "3", "aai-node-type", "vf-module");
+ rules.addEdge(g, v2, v3);
+ }
- rules.addEdge(g, v2, v1);
- Vertex v3 = graph.addVertex(T.id, "3", "aai-node-type", "vf-module");
- rules.addEdge(g, v2, v3);
- }
-
- @Test
- public void addEdgeVerifyAAIUUIDCousinTest() throws AAIException {
- Graph graph = TinkerGraph.open();
- Vertex v1 = graph.addVertex(T.id, "1", "aai-node-type", "flavor");
- Vertex v2 = graph.addVertex(T.id, "10", "aai-node-type", "vserver");
- GraphTraversalSource g = graph.traversal();
- Edge e = rules.addEdge(g, v1, v2);
- assertTrue(e.property(AAIProperties.AAI_UUID).isPresent());
- //assertTrue(e.property(AAIProperties.AAI_UUID).value().toString().matches("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"));
- }
+ @Test
+ public void addEdgeVerifyAAIUUIDCousinTest() throws AAIException {
+ Graph graph = TinkerGraph.open();
+ Vertex v1 = graph.addVertex(T.id, "1", "aai-node-type", "flavor");
+ Vertex v2 = graph.addVertex(T.id, "10", "aai-node-type", "vserver");
+ GraphTraversalSource g = graph.traversal();
+ Edge e = rules.addEdge(g, v1, v2);
+ assertTrue(e.property(AAIProperties.AAI_UUID).isPresent());
+ // assertTrue(e.property(AAIProperties.AAI_UUID).value().toString().matches("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"));
+ }
- @Test
- public void addEdgeVerifyAAIUUIDTreeTest() throws AAIException {
- Graph graph = TinkerGraph.open();
- Vertex v1 = graph.addVertex(T.id, "1", "aai-node-type", "tenant");
- Vertex v2 = graph.addVertex(T.id, "10", "aai-node-type", "vserver");
- GraphTraversalSource g = graph.traversal();
- Edge e = rules.addTreeEdge(g, v1, v2);
- assertTrue(e.property(AAIProperties.AAI_UUID).isPresent());
- //assertTrue(e.property(AAIProperties.AAI_UUID).value().toString().matches("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"));
- }
+ @Test
+ public void addEdgeVerifyAAIUUIDTreeTest() throws AAIException {
+ Graph graph = TinkerGraph.open();
+ Vertex v1 = graph.addVertex(T.id, "1", "aai-node-type", "tenant");
+ Vertex v2 = graph.addVertex(T.id, "10", "aai-node-type", "vserver");
+ GraphTraversalSource g = graph.traversal();
+ Edge e = rules.addTreeEdge(g, v1, v2);
+ assertTrue(e.property(AAIProperties.AAI_UUID).isPresent());
+ // assertTrue(e.property(AAIProperties.AAI_UUID).value().toString().matches("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"));
+ }
-} \ No newline at end of file
+}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/engines/query/GraphTraversalQueryEngineTest.java b/aai-core/src/test/java/org/onap/aai/serialization/engines/query/GraphTraversalQueryEngineTest.java
index b9431217..5201cc5e 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/engines/query/GraphTraversalQueryEngineTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/engines/query/GraphTraversalQueryEngineTest.java
@@ -17,9 +17,20 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.serialization.engines.query;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.onap.aai.edges.enums.EdgeField.CONTAINS;
+
import com.jayway.jsonpath.JsonPath;
+
+import java.io.InputStream;
+import java.util.*;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
import org.apache.tinkerpop.gremlin.structure.*;
@@ -35,72 +46,65 @@ import org.onap.aai.serialization.db.EdgeSerializer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
-import java.io.InputStream;
-import java.util.*;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.onap.aai.edges.enums.EdgeField.CONTAINS;
-
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class GraphTraversalQueryEngineTest extends AAISetup {
- @Autowired
- EdgeSerializer edgeSer;
+ @Autowired
+ EdgeSerializer edgeSer;
- @Test
- public void testFindParents() throws AAIException {
- //setup
- Graph graph = TinkerGraph.open();
+ @Test
+ public void testFindParents() throws AAIException {
+ // setup
+ Graph graph = TinkerGraph.open();
- Vertex cloudreg = graph.addVertex(T.id, "00", "aai-node-type", "cloud-region");
- Vertex tenant = graph.addVertex(T.id, "10", "aai-node-type", "tenant");
- Vertex vserver = graph.addVertex(T.id, "20", "aai-node-type", "vserver");
+ Vertex cloudreg = graph.addVertex(T.id, "00", "aai-node-type", "cloud-region");
+ Vertex tenant = graph.addVertex(T.id, "10", "aai-node-type", "tenant");
+ Vertex vserver = graph.addVertex(T.id, "20", "aai-node-type", "vserver");
- GraphTraversalSource g = graph.traversal();
+ GraphTraversalSource g = graph.traversal();
- edgeSer.addTreeEdge(g, cloudreg, tenant);
- edgeSer.addTreeEdge(g, tenant, vserver);
+ edgeSer.addTreeEdge(g, cloudreg, tenant);
+ edgeSer.addTreeEdge(g, tenant, vserver);
- //expect start vertex back plus any parents
- List<Vertex> crExpected = new ArrayList<>(Arrays.asList(cloudreg)); //no parents
- List<Vertex> tenExpected = new ArrayList<>(Arrays.asList(tenant, cloudreg)); //only has the immediate parent
- List<Vertex> vsExpected = new ArrayList<>(Arrays.asList(vserver, tenant, cloudreg)); //parent & grandparent
+ // expect start vertex back plus any parents
+ List<Vertex> crExpected = new ArrayList<>(Arrays.asList(cloudreg)); // no parents
+ List<Vertex> tenExpected = new ArrayList<>(Arrays.asList(tenant, cloudreg)); // only has the immediate parent
+ List<Vertex> vsExpected = new ArrayList<>(Arrays.asList(vserver, tenant, cloudreg)); // parent & grandparent
- GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
+ GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
- //test
- List<Vertex> crRes = engine.findParents(cloudreg);
- assertTrue(crRes.containsAll(crExpected) && crExpected.containsAll(crRes));
+ // test
+ List<Vertex> crRes = engine.findParents(cloudreg);
+ assertTrue(crRes.containsAll(crExpected) && crExpected.containsAll(crRes));
- List<Vertex> tenRes = engine.findParents(tenant);
- assertTrue(tenRes.containsAll(tenExpected) && tenExpected.containsAll(tenRes));
+ List<Vertex> tenRes = engine.findParents(tenant);
+ assertTrue(tenRes.containsAll(tenExpected) && tenExpected.containsAll(tenRes));
- List<Vertex> vsRes = engine.findParents(vserver);
- assertTrue(vsRes.containsAll(vsExpected) && vsExpected.containsAll(vsRes));
- //verify expected ordering - start, parent, grandparent
- assertTrue(vsRes.get(0).equals(vserver));
- assertTrue(vsRes.get(1).equals(tenant));
- assertTrue(vsRes.get(2).equals(cloudreg));
- }
+ List<Vertex> vsRes = engine.findParents(vserver);
+ assertTrue(vsRes.containsAll(vsExpected) && vsExpected.containsAll(vsRes));
+ // verify expected ordering - start, parent, grandparent
+ assertTrue(vsRes.get(0).equals(vserver));
+ assertTrue(vsRes.get(1).equals(tenant));
+ assertTrue(vsRes.get(2).equals(cloudreg));
+ }
- @Test
- public void testFindAllParentsGivenAaiUris(){
+ @Test
+ public void testFindAllParentsGivenAaiUris() {
- //setup
+ // setup
Graph graph = TinkerGraph.open();
- Vertex cloudreg = graph.addVertex(T.id, "00", "aai-node-type", "cloud-region", "aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/testowner/testid");
- Vertex tenant = graph.addVertex(T.id, "10", "aai-node-type", "tenant", "aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/testowner/testid/tenants/tenant/testTenant1");
- Vertex vserver = graph.addVertex(T.id, "20", "aai-node-type", "vserver", "aai-uri", "/cloud-infrastructure/cloud-regions/cloud-region/testowner/testid/tenants/tenant/testTenant1/vservers/vserver/testVserver1");
+ Vertex cloudreg = graph.addVertex(T.id, "00", "aai-node-type", "cloud-region", "aai-uri",
+ "/cloud-infrastructure/cloud-regions/cloud-region/testowner/testid");
+ Vertex tenant = graph.addVertex(T.id, "10", "aai-node-type", "tenant", "aai-uri",
+ "/cloud-infrastructure/cloud-regions/cloud-region/testowner/testid/tenants/tenant/testTenant1");
+ Vertex vserver = graph.addVertex(T.id, "20", "aai-node-type", "vserver", "aai-uri",
+ "/cloud-infrastructure/cloud-regions/cloud-region/testowner/testid/tenants/tenant/testTenant1/vservers/vserver/testVserver1");
- String [] uris = new String[]{
- "/cloud-infrastructure/cloud-regions/cloud-region/testowner/testid/tenants/tenant/testTenant1",
- "/cloud-infrastructure/cloud-regions/cloud-region/testowner/testid/tenants/tenant/testTenant1/vservers/vserver/testVserver1",
- "/cloud-infrastructure/cloud-regions/cloud-region/testowner/testid"
- };
+ String[] uris = new String[] {
+ "/cloud-infrastructure/cloud-regions/cloud-region/testowner/testid/tenants/tenant/testTenant1",
+ "/cloud-infrastructure/cloud-regions/cloud-region/testowner/testid/tenants/tenant/testTenant1/vservers/vserver/testVserver1",
+ "/cloud-infrastructure/cloud-regions/cloud-region/testowner/testid"};
GraphTraversalSource g = graph.traversal();
GraphTraversalQueryEngine queryEngine = new GraphTraversalQueryEngine(g);
@@ -112,266 +116,267 @@ public class GraphTraversalQueryEngineTest extends AAISetup {
assertThat("Expected the element back to be cloud region", vertices.get(2), is(cloudreg));
}
- @Test
- public void testFindAllChildren() throws AAIException {
- //setup
- Graph graph = TinkerGraph.open();
+ @Test
+ public void testFindAllChildren() throws AAIException {
+ // setup
+ Graph graph = TinkerGraph.open();
+
+ Vertex cloudreg = graph.addVertex(T.id, "00", "aai-node-type", "cloud-region");
+ Vertex tenant = graph.addVertex(T.id, "10", "aai-node-type", "tenant");
+ Vertex vserver = graph.addVertex(T.id, "20", "aai-node-type", "vserver");
+ Vertex vserver2 = graph.addVertex(T.id, "21", "aai-node-type", "vserver");
+ Vertex oam = graph.addVertex(T.id, "30", "aai-node-type", "oam-network");
+
+ GraphTraversalSource g = graph.traversal();
+
+ edgeSer.addTreeEdge(g, cloudreg, tenant);
+ edgeSer.addTreeEdge(g, tenant, vserver);
+ edgeSer.addTreeEdge(g, tenant, vserver2);
+ edgeSer.addTreeEdge(g, cloudreg, oam);
+
+ List<Vertex> crExpected = new ArrayList<>(Arrays.asList(cloudreg, tenant, vserver, vserver2, oam));
+ List<Vertex> vsExpected = new ArrayList<>(Arrays.asList(vserver));
+
+ GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
+
+ // test
+ List<Vertex> crRes = engine.findAllChildren(cloudreg);
+ assertTrue(crRes.containsAll(crExpected) && crExpected.containsAll(crRes));
+
+ List<Vertex> vsRes = engine.findAllChildren(vserver);
+ assertTrue(vsRes.containsAll(vsExpected) && vsExpected.containsAll(vsRes));
+ }
+
+ @Test
+ public void testFindChildrenOfType() throws AAIException {
+ // setup
+ Graph graph = TinkerGraph.open();
+
+ Vertex gv = graph.addVertex(T.id, "00", "aai-node-type", "generic-vnf");
+ Vertex lint1 = graph.addVertex(T.id, "10", "aai-node-type", "l-interface");
+ Vertex lint2 = graph.addVertex(T.id, "11", "aai-node-type", "l-interface");
+ Vertex lag = graph.addVertex(T.id, "20", "aai-node-type", "lag-interface");
+ Vertex lint3 = graph.addVertex(T.id, "12", "aai-node-type", "l-interface");
+
+ GraphTraversalSource g = graph.traversal();
+
+ edgeSer.addTreeEdge(g, gv, lint1);
+ edgeSer.addTreeEdge(g, gv, lint2);
+ edgeSer.addTreeEdge(g, gv, lag);
+ edgeSer.addTreeEdge(g, lag, lint3);
+
+ List<Vertex> expected = new ArrayList<>(Arrays.asList(lint1, lint2));
+
+ GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
+
+ // test
+ List<Vertex> results = engine.findChildrenOfType(gv, "l-interface");
+ assertTrue(results.containsAll(expected) && expected.containsAll(results));
+ }
+
+ @Test
+ public void testFindChildren() throws AAIException {
+ // setup
+ Graph graph = TinkerGraph.open();
+
+ Vertex gv = graph.addVertex(T.id, "00", "aai-node-type", "generic-vnf");
+ Vertex lint1 = graph.addVertex(T.id, "10", "aai-node-type", "l-interface");
+ Vertex lint2 = graph.addVertex(T.id, "11", "aai-node-type", "l-interface");
+ Vertex lag = graph.addVertex(T.id, "20", "aai-node-type", "lag-interface");
+ Vertex lint3 = graph.addVertex(T.id, "12", "aai-node-type", "l-interface");
+
+ GraphTraversalSource g = graph.traversal();
+
+ edgeSer.addTreeEdge(g, gv, lint1);
+ edgeSer.addTreeEdge(g, gv, lint2);
+ edgeSer.addTreeEdge(g, gv, lag);
+ edgeSer.addTreeEdge(g, lag, lint3);
+
+ List<Vertex> expected = new ArrayList<>(Arrays.asList(lint1, lint2, lag));
+
+ GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
+
+ // test
+ List<Vertex> results = engine.findChildren(gv);
+ assertTrue(results.containsAll(expected) && expected.containsAll(results));
+ }
+
+ @Test
+ public void testFindRelatedVertices() throws AAIException {
+ // setup
+
+ Graph graph = TinkerGraph.open();
- Vertex cloudreg = graph.addVertex(T.id, "00", "aai-node-type", "cloud-region");
- Vertex tenant = graph.addVertex(T.id, "10", "aai-node-type", "tenant");
- Vertex vserver = graph.addVertex(T.id, "20", "aai-node-type", "vserver");
- Vertex vserver2 = graph.addVertex(T.id, "21", "aai-node-type", "vserver");
- Vertex oam = graph.addVertex(T.id, "30", "aai-node-type", "oam-network");
+ Vertex gv = graph.addVertex(T.id, "00", "aai-node-type", "generic-vnf");
+ Vertex lint = graph.addVertex(T.id, "10", "aai-node-type", "l-interface");
+ Vertex lint2 = graph.addVertex(T.id, "11", "aai-node-type", "l-interface");
+ Vertex log = graph.addVertex(T.id, "20", "aai-node-type", "logical-link");
- GraphTraversalSource g = graph.traversal();
+ GraphTraversalSource g = graph.traversal();
- edgeSer.addTreeEdge(g, cloudreg, tenant);
- edgeSer.addTreeEdge(g, tenant, vserver);
- edgeSer.addTreeEdge(g, tenant, vserver2);
- edgeSer.addTreeEdge(g, cloudreg, oam);
+ edgeSer.addTreeEdge(g, gv, lint);
+ edgeSer.addEdge(g, lint, log);
+ edgeSer.addEdge(g, log, lint2);
- List<Vertex> crExpected = new ArrayList<>(Arrays.asList(cloudreg, tenant, vserver, vserver2, oam));
- List<Vertex> vsExpected = new ArrayList<>(Arrays.asList(vserver));
+ List<Vertex> outExpected = new ArrayList<>(Arrays.asList(lint));
+ List<Vertex> inExpected = new ArrayList<>(Arrays.asList(lint, lint2));
+ List<Vertex> bothExpected = new ArrayList<>(Arrays.asList(log));
- GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
+ GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
- //test
- List<Vertex> crRes = engine.findAllChildren(cloudreg);
- assertTrue(crRes.containsAll(crExpected) && crExpected.containsAll(crRes));
+ // test
+ List<Vertex> outRes = engine.findRelatedVertices(gv, Direction.IN, "org.onap.relationships.inventory.BelongsTo",
+ "l-interface");
+ assertTrue(outRes.containsAll(outExpected) && outExpected.containsAll(outRes));
- List<Vertex> vsRes = engine.findAllChildren(vserver);
- assertTrue(vsRes.containsAll(vsExpected) && vsExpected.containsAll(vsRes));
- }
+ List<Vertex> inRes =
+ engine.findRelatedVertices(log, Direction.IN, "tosca.relationships.network.LinksTo", "l-interface");
+ assertTrue(inRes.containsAll(inExpected) && inExpected.containsAll(inRes));
- @Test
- public void testFindChildrenOfType() throws AAIException {
- //setup
- Graph graph = TinkerGraph.open();
+ List<Vertex> bothRes =
+ engine.findRelatedVertices(lint, Direction.BOTH, "tosca.relationships.network.LinksTo", "logical-link");
+ assertTrue(bothRes.containsAll(bothExpected) && bothExpected.containsAll(bothRes));
+ }
+
+ @Test
+ public void testFindSubGraph() throws AAIException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
+ // setup
+ Graph graph = TinkerGraph.open();
- Vertex gv = graph.addVertex(T.id, "00", "aai-node-type", "generic-vnf");
- Vertex lint1 = graph.addVertex(T.id, "10", "aai-node-type", "l-interface");
- Vertex lint2 = graph.addVertex(T.id, "11", "aai-node-type", "l-interface");
- Vertex lag = graph.addVertex(T.id, "20", "aai-node-type", "lag-interface");
- Vertex lint3 = graph.addVertex(T.id, "12", "aai-node-type", "l-interface");
+ Vertex cr = graph.addVertex(T.id, "00", "aai-node-type", "cloud-region");
+ Vertex ten = graph.addVertex(T.id, "10", "aai-node-type", "tenant");
+ Vertex ten2 = graph.addVertex(T.id, "11", "aai-node-type", "tenant");
+ Vertex vs = graph.addVertex(T.id, "20", "aai-node-type", "vserver");
+ Vertex vs2 = graph.addVertex(T.id, "21", "aai-node-type", "vserver");
+ Vertex lint = graph.addVertex(T.id, "30", "aai-node-type", "l-interface");
+ Vertex comp = graph.addVertex(T.id, "40", "aai-node-type", "complex");
+ Vertex ctag = graph.addVertex(T.id, "50", "aai-node-type", "ctag-pool");
+ Vertex gv = graph.addVertex(T.id, "60", "aai-node-type", "generic-vnf");
+ Vertex lag = graph.addVertex(T.id, "70", "aai-node-type", "lag-interface");
+ Vertex lint2 = graph.addVertex(T.id, "31", "aai-node-type", "l-interface");
+ Vertex log = graph.addVertex(T.id, "80", "aai-node-type", "logical-link");
+ Vertex vnfc = graph.addVertex(T.id, "90", "aai-node-type", "vnfc");
+ Vertex modelVer = graph.addVertex(T.id, "100", "aai-node-type", "model-ver");
- GraphTraversalSource g = graph.traversal();
+ GraphTraversalSource g = graph.traversal();
- edgeSer.addTreeEdge(g, gv, lint1);
- edgeSer.addTreeEdge(g, gv, lint2);
- edgeSer.addTreeEdge(g, gv, lag);
- edgeSer.addTreeEdge(g, lag, lint3);
-
- List<Vertex> expected = new ArrayList<>(Arrays.asList(lint1, lint2));
-
- GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
-
- //test
- List<Vertex> results = engine.findChildrenOfType(gv, "l-interface");
- assertTrue(results.containsAll(expected) && expected.containsAll(results));
- }
-
- @Test
- public void testFindChildren() throws AAIException {
- //setup
- Graph graph = TinkerGraph.open();
-
- Vertex gv = graph.addVertex(T.id, "00", "aai-node-type", "generic-vnf");
- Vertex lint1 = graph.addVertex(T.id, "10", "aai-node-type", "l-interface");
- Vertex lint2 = graph.addVertex(T.id, "11", "aai-node-type", "l-interface");
- Vertex lag = graph.addVertex(T.id, "20", "aai-node-type", "lag-interface");
- Vertex lint3 = graph.addVertex(T.id, "12", "aai-node-type", "l-interface");
-
- GraphTraversalSource g = graph.traversal();
-
- edgeSer.addTreeEdge(g, gv, lint1);
- edgeSer.addTreeEdge(g, gv, lint2);
- edgeSer.addTreeEdge(g, gv, lag);
- edgeSer.addTreeEdge(g, lag, lint3);
-
- List<Vertex> expected = new ArrayList<>(Arrays.asList(lint1, lint2, lag));
-
- GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
-
- //test
- List<Vertex> results = engine.findChildren(gv);
- assertTrue(results.containsAll(expected) && expected.containsAll(results));
- }
-
- @Test
- public void testFindRelatedVertices() throws AAIException {
- //setup
-
- Graph graph = TinkerGraph.open();
-
- Vertex gv = graph.addVertex(T.id, "00", "aai-node-type", "generic-vnf");
- Vertex lint = graph.addVertex(T.id, "10", "aai-node-type", "l-interface");
- Vertex lint2 = graph.addVertex(T.id, "11", "aai-node-type", "l-interface");
- Vertex log = graph.addVertex(T.id, "20", "aai-node-type", "logical-link");
-
- GraphTraversalSource g = graph.traversal();
-
- edgeSer.addTreeEdge(g, gv, lint);
- edgeSer.addEdge(g, lint, log);
- edgeSer.addEdge(g, log, lint2);
-
- List<Vertex> outExpected = new ArrayList<>(Arrays.asList(lint));
- List<Vertex> inExpected = new ArrayList<>(Arrays.asList(lint, lint2));
- List<Vertex> bothExpected = new ArrayList<>(Arrays.asList(log));
-
- GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
-
- //test
- List<Vertex> outRes = engine.findRelatedVertices(gv, Direction.IN, "org.onap.relationships.inventory.BelongsTo", "l-interface");
- assertTrue(outRes.containsAll(outExpected) && outExpected.containsAll(outRes));
-
- List<Vertex> inRes = engine.findRelatedVertices(log, Direction.IN, "tosca.relationships.network.LinksTo", "l-interface");
- assertTrue(inRes.containsAll(inExpected) && inExpected.containsAll(inRes));
-
- List<Vertex> bothRes = engine.findRelatedVertices(lint, Direction.BOTH, "tosca.relationships.network.LinksTo", "logical-link");
- assertTrue(bothRes.containsAll(bothExpected) && bothExpected.containsAll(bothRes));
- }
-
- @Test
- public void testFindSubGraph() throws AAIException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
- //setup
- Graph graph = TinkerGraph.open();
-
- Vertex cr = graph.addVertex(T.id, "00", "aai-node-type", "cloud-region");
- Vertex ten = graph.addVertex(T.id, "10", "aai-node-type", "tenant");
- Vertex ten2 = graph.addVertex(T.id, "11", "aai-node-type", "tenant");
- Vertex vs = graph.addVertex(T.id, "20", "aai-node-type", "vserver");
- Vertex vs2 = graph.addVertex(T.id, "21", "aai-node-type", "vserver");
- Vertex lint = graph.addVertex(T.id, "30", "aai-node-type", "l-interface");
- Vertex comp = graph.addVertex(T.id, "40", "aai-node-type", "complex");
- Vertex ctag = graph.addVertex(T.id, "50", "aai-node-type", "ctag-pool");
- Vertex gv = graph.addVertex(T.id, "60", "aai-node-type", "generic-vnf");
- Vertex lag = graph.addVertex(T.id, "70", "aai-node-type", "lag-interface");
- Vertex lint2 = graph.addVertex(T.id, "31", "aai-node-type", "l-interface");
- Vertex log = graph.addVertex(T.id, "80", "aai-node-type", "logical-link");
- Vertex vnfc = graph.addVertex(T.id, "90", "aai-node-type", "vnfc");
- Vertex modelVer = graph.addVertex(T.id, "100", "aai-node-type", "model-ver");
-
- GraphTraversalSource g = graph.traversal();
-
- Edge crTen = edgeSer.addTreeEdge(g, cr, ten);
- Edge crTen2 = edgeSer.addTreeEdge(g, cr, ten2);
- Edge tenVs = edgeSer.addTreeEdge(g, ten, vs);
- Edge tenVs2 = edgeSer.addTreeEdge(g, ten, vs2);
- Edge vsLInt = edgeSer.addTreeEdge(g, vs, lint);
- Edge lintLog = edgeSer.addEdge(g, lint, log);
- Edge vsGv = edgeSer.addEdge(g, vs, gv);
- edgeSer.addEdge(g, gv, vnfc);
-
- edgeSer.addTreeEdge(g, gv, lag);
- edgeSer.addTreeEdge(g, lag, lint2);
+ Edge crTen = edgeSer.addTreeEdge(g, cr, ten);
+ Edge crTen2 = edgeSer.addTreeEdge(g, cr, ten2);
+ Edge tenVs = edgeSer.addTreeEdge(g, ten, vs);
+ Edge tenVs2 = edgeSer.addTreeEdge(g, ten, vs2);
+ Edge vsLInt = edgeSer.addTreeEdge(g, vs, lint);
+ Edge lintLog = edgeSer.addEdge(g, lint, log);
+ Edge vsGv = edgeSer.addEdge(g, vs, gv);
+ edgeSer.addEdge(g, gv, vnfc);
+
+ edgeSer.addTreeEdge(g, gv, lag);
+ edgeSer.addTreeEdge(g, lag, lint2);
Edge modelVerEdge = edgeSer.addPrivateEdge(g, gv, modelVer, null);
- edgeSer.addTreeEdge(g, comp, ctag);
- Edge crComp = edgeSer.addEdge(g, cr, comp);
-
- //findSubGraph(cr, 0, true)
- List<Element> expected1 = new ArrayList<>(Arrays.asList(cr));
- //findSubGraph(cr, 2, true)
- List<Element> expected2 = new ArrayList<>(Arrays.asList(cr, ten, ten2, vs, vs2,
- crTen, crTen2, tenVs, tenVs2));
- //findSubGraph(cr)
- List<Element> expected3 = new ArrayList<>(Arrays.asList(cr, ten, ten2, comp, vs, vs2, lint, gv, log,
- crTen, crTen2, crComp, tenVs, tenVs2, vsLInt,
- vsGv, lintLog));
-
- GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
-
- //test
- Tree<Element> res1 = engine.findSubGraph(cr, 0, true);
- Set<Element> resList1 = treeToList(res1);
- assertTrue(resList1.containsAll(expected1) && expected1.containsAll(resList1));
-
- Tree<Element> res2 = engine.findSubGraph(cr, 2, true);
- Set<Element> resList2 = treeToList(res2);
- assertTrue(resList2.containsAll(expected2) && expected2.containsAll(resList2));
-
- Tree<Element> res3 = engine.findSubGraph(cr);
- Set<Element> resList3 = treeToList(res3);
- assertThat(resList3, containsInAnyOrder(expected3.toArray()));
-// assertTrue(resList3.containsAll(expected3) && expected3.containsAll(resList3));
- }
-
- /**
- * convenience helper method to make it easier to check the contents of the tree against
- * a list of expected results
- * @param tree - the tree whose contents you want in collection form
- * @return set of the contents of the tree
- */
- private Set<Element> treeToList(Tree<Element> tree) {
- Set<Element> ret = new HashSet<>();
-
- for (Element key : tree.keySet()) {
- ret.add(key);
- ret.addAll(treeToList(tree.get(key)));
- }
-
- return ret;
- }
-
- @Test
- public void testFindEdgesForVersion() throws AAIException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
- //setup
- Graph graph = TinkerGraph.open();
-
- Vertex gv = graph.addVertex(T.id, "00", "aai-node-type", "generic-vnf");
- Vertex vnfc = graph.addVertex(T.id, "10", "aai-node-type", "vnfc");
- Vertex lob = graph.addVertex(T.id, "20", "aai-node-type", "line-of-business");
- Vertex lint = graph.addVertex(T.id, "30", "aai-node-type", "l-interface");
- Vertex mv = graph.addVertex(T.id, "40", "aai-node-type", "model-ver");
- Vertex cr = graph.addVertex(T.id, "50", "aai-node-type", "cloud-region");
- Vertex tn = graph.addVertex(T.id, "60", "aai-node-type", "tenant");
-
- Edge cloudRegionToTenantEdge = tn
- .addEdge("some-edge", cr, CONTAINS.toString(), "NONE");
-
- GraphTraversalSource g = graph.traversal();
-
- edgeSer.addTreeEdge(g, gv, lint); //tree edge so shouldn't appear in results
- Edge gvVnfc = edgeSer.addEdge(g, gv, vnfc);
- edgeSer.addEdge(g, gv, lob); //v11/12 not v10
+ edgeSer.addTreeEdge(g, comp, ctag);
+ Edge crComp = edgeSer.addEdge(g, cr, comp);
+
+ // findSubGraph(cr, 0, true)
+ List<Element> expected1 = new ArrayList<>(Arrays.asList(cr));
+ // findSubGraph(cr, 2, true)
+ List<Element> expected2 = new ArrayList<>(Arrays.asList(cr, ten, ten2, vs, vs2, crTen, crTen2, tenVs, tenVs2));
+ // findSubGraph(cr)
+ List<Element> expected3 = new ArrayList<>(Arrays.asList(cr, ten, ten2, comp, vs, vs2, lint, gv, log, crTen,
+ crTen2, crComp, tenVs, tenVs2, vsLInt, vsGv, lintLog));
+
+ GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
+
+ // test
+ Tree<Element> res1 = engine.findSubGraph(cr, 0, true);
+ Set<Element> resList1 = treeToList(res1);
+ assertTrue(resList1.containsAll(expected1) && expected1.containsAll(resList1));
+
+ Tree<Element> res2 = engine.findSubGraph(cr, 2, true);
+ Set<Element> resList2 = treeToList(res2);
+ assertTrue(resList2.containsAll(expected2) && expected2.containsAll(resList2));
+
+ Tree<Element> res3 = engine.findSubGraph(cr);
+ Set<Element> resList3 = treeToList(res3);
+ assertThat(resList3, containsInAnyOrder(expected3.toArray()));
+ // assertTrue(resList3.containsAll(expected3) && expected3.containsAll(resList3));
+ }
+
+ /**
+ * convenience helper method to make it easier to check the contents of the tree against
+ * a list of expected results
+ *
+ * @param tree - the tree whose contents you want in collection form
+ * @return set of the contents of the tree
+ */
+ private Set<Element> treeToList(Tree<Element> tree) {
+ Set<Element> ret = new HashSet<>();
+
+ for (Element key : tree.keySet()) {
+ ret.add(key);
+ ret.addAll(treeToList(tree.get(key)));
+ }
+
+ return ret;
+ }
+
+ @Test
+ public void testFindEdgesForVersion() throws AAIException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
+ // setup
+ Graph graph = TinkerGraph.open();
+
+ Vertex gv = graph.addVertex(T.id, "00", "aai-node-type", "generic-vnf");
+ Vertex vnfc = graph.addVertex(T.id, "10", "aai-node-type", "vnfc");
+ Vertex lob = graph.addVertex(T.id, "20", "aai-node-type", "line-of-business");
+ Vertex lint = graph.addVertex(T.id, "30", "aai-node-type", "l-interface");
+ Vertex mv = graph.addVertex(T.id, "40", "aai-node-type", "model-ver");
+ Vertex cr = graph.addVertex(T.id, "50", "aai-node-type", "cloud-region");
+ Vertex tn = graph.addVertex(T.id, "60", "aai-node-type", "tenant");
+
+ Edge cloudRegionToTenantEdge = tn.addEdge("some-edge", cr, CONTAINS.toString(), "NONE");
+
+ GraphTraversalSource g = graph.traversal();
+
+ edgeSer.addTreeEdge(g, gv, lint); // tree edge so shouldn't appear in results
+ Edge gvVnfc = edgeSer.addEdge(g, gv, vnfc);
+ edgeSer.addEdge(g, gv, lob); // v11/12 not v10
Edge gvMvEdge = edgeSer.addPrivateEdge(g, gv, mv, null);
- List<Edge> expected = new ArrayList<>(Arrays.asList(gvVnfc));
+ List<Edge> expected = new ArrayList<>(Arrays.asList(gvVnfc));
- GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
+ GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
- //test
- Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getRelatedLinkVersion());
- List<Edge> results = engine.findEdgesForVersion(gv, loader);
- assertThat(results, containsInAnyOrder(expected.toArray()));
+ // test
+ Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getRelatedLinkVersion());
+ List<Edge> results = engine.findEdgesForVersion(gv, loader);
+ assertThat(results, containsInAnyOrder(expected.toArray()));
expected = new ArrayList<>(Arrays.asList(cloudRegionToTenantEdge));
- results = engine.findEdgesForVersion(cr, loader);
- assertThat(results, containsInAnyOrder(expected.toArray()));
- }
+ results = engine.findEdgesForVersion(cr, loader);
+ assertThat(results, containsInAnyOrder(expected.toArray()));
+ }
- @Test
- public void testFindCousinVertices() throws AAIException {
- //setup
- Graph graph = TinkerGraph.open();
+ @Test
+ public void testFindCousinVertices() throws AAIException {
+ // setup
+ Graph graph = TinkerGraph.open();
- Vertex gv = graph.addVertex(T.id, "00", "aai-node-type", "generic-vnf");
- Vertex vnfc = graph.addVertex(T.id, "10", "aai-node-type", "vnfc");
- Vertex lob = graph.addVertex(T.id, "20", "aai-node-type", "line-of-business");
- Vertex lint = graph.addVertex(T.id, "30", "aai-node-type", "l-interface");
+ Vertex gv = graph.addVertex(T.id, "00", "aai-node-type", "generic-vnf");
+ Vertex vnfc = graph.addVertex(T.id, "10", "aai-node-type", "vnfc");
+ Vertex lob = graph.addVertex(T.id, "20", "aai-node-type", "line-of-business");
+ Vertex lint = graph.addVertex(T.id, "30", "aai-node-type", "l-interface");
- GraphTraversalSource g = graph.traversal();
+ GraphTraversalSource g = graph.traversal();
- edgeSer.addTreeEdge(g, gv, lint); //tree edge so shouldn't appear in results
- edgeSer.addEdge(g, gv, vnfc);
- edgeSer.addEdge(g, gv, lob);
+ edgeSer.addTreeEdge(g, gv, lint); // tree edge so shouldn't appear in results
+ edgeSer.addEdge(g, gv, vnfc);
+ edgeSer.addEdge(g, gv, lob);
- List<Vertex> expected = new ArrayList<>(Arrays.asList(vnfc, lob));
+ List<Vertex> expected = new ArrayList<>(Arrays.asList(vnfc, lob));
- GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
+ GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
- //test
- List<Vertex> results = engine.findCousinVertices(gv);
- assertTrue(results.containsAll(expected) && expected.containsAll(results));
- }
+ // test
+ List<Vertex> results = engine.findCousinVertices(gv);
+ assertTrue(results.containsAll(expected) && expected.containsAll(results));
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/engines/query/GraphTraversalQueryEngine_needsFakeEdgeRulesTest.java b/aai-core/src/test/java/org/onap/aai/serialization/engines/query/GraphTraversalQueryEngine_needsFakeEdgeRulesTest.java
index 34ba2ab8..8c603558 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/engines/query/GraphTraversalQueryEngine_needsFakeEdgeRulesTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/engines/query/GraphTraversalQueryEngine_needsFakeEdgeRulesTest.java
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.serialization.engines.query;
import static org.junit.Assert.*;
@@ -45,46 +46,43 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(classes = {
- ConfigConfiguration.class,
- AAICoreFakeEdgesConfigTranslator.class,
- EdgeIngestor.class,
- EdgeSerializer.class
-})
+@ContextConfiguration(
+ classes = {ConfigConfiguration.class, AAICoreFakeEdgesConfigTranslator.class, EdgeIngestor.class,
+ EdgeSerializer.class})
@DirtiesContext
public class GraphTraversalQueryEngine_needsFakeEdgeRulesTest {
- @Autowired
- EdgeSerializer edgeSer;
-
- @Test
- public void testFindDeletable() throws AAIException {
- //setup
- Graph graph = TinkerGraph.open();
- Vertex parent = graph.addVertex(T.id, "00", "aai-node-type", "test-parent");
- Vertex child = graph.addVertex(T.id, "10", "aai-node-type", "test-child");
- Vertex cousin = graph.addVertex(T.id, "20", "aai-node-type", "test-cousin");
- Vertex grandchild = graph.addVertex(T.id, "30", "aai-node-type", "test-grandchild");
+ @Autowired
+ EdgeSerializer edgeSer;
+
+ @Test
+ public void testFindDeletable() throws AAIException {
+ // setup
+ Graph graph = TinkerGraph.open();
+ Vertex parent = graph.addVertex(T.id, "00", "aai-node-type", "test-parent");
+ Vertex child = graph.addVertex(T.id, "10", "aai-node-type", "test-child");
+ Vertex cousin = graph.addVertex(T.id, "20", "aai-node-type", "test-cousin");
+ Vertex grandchild = graph.addVertex(T.id, "30", "aai-node-type", "test-grandchild");
+
+ GraphTraversalSource g = graph.traversal();
+
+ edgeSer.addTreeEdge(g, parent, child); // delete-other-v=none, no cascade
+ edgeSer.addTreeEdge(g, child, grandchild); // d-o-v=out, yes from child
+ edgeSer.addEdge(g, cousin, child); // d-o-v=out, yes from cousin
+
+ List<Vertex> parentExpected = new ArrayList<>(Arrays.asList(parent));
+ List<Vertex> childExpected = new ArrayList<>(Arrays.asList(child, grandchild));
+ List<Vertex> cousinExpected = new ArrayList<>(Arrays.asList(cousin, child, grandchild));
+
+ GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
+
+ // tests
+ List<Vertex> parentDeletes = engine.findDeletable(parent);
+ assertTrue(parentExpected.containsAll(parentDeletes) && parentDeletes.containsAll(parentExpected));
+
+ List<Vertex> childDeletes = engine.findDeletable(child);
+ assertTrue(childExpected.containsAll(childDeletes) && childDeletes.containsAll(childExpected));
- GraphTraversalSource g = graph.traversal();
-
- edgeSer.addTreeEdge(g, parent, child); //delete-other-v=none, no cascade
- edgeSer.addTreeEdge(g, child, grandchild); //d-o-v=out, yes from child
- edgeSer.addEdge(g, cousin, child); //d-o-v=out, yes from cousin
-
- List<Vertex> parentExpected = new ArrayList<>(Arrays.asList(parent));
- List<Vertex> childExpected = new ArrayList<>(Arrays.asList(child, grandchild));
- List<Vertex> cousinExpected = new ArrayList<>(Arrays.asList(cousin, child, grandchild));
-
- GraphTraversalQueryEngine engine = new GraphTraversalQueryEngine(g);
-
- //tests
- List<Vertex> parentDeletes = engine.findDeletable(parent);
- assertTrue(parentExpected.containsAll(parentDeletes) && parentDeletes.containsAll(parentExpected));
-
- List<Vertex> childDeletes = engine.findDeletable(child);
- assertTrue(childExpected.containsAll(childDeletes) && childDeletes.containsAll(childExpected));
-
- List<Vertex> cousinDeletes = engine.findDeletable(cousin);
- assertTrue(cousinExpected.containsAll(cousinDeletes) && cousinDeletes.containsAll(cousinExpected));
- }
+ List<Vertex> cousinDeletes = engine.findDeletable(cousin);
+ assertTrue(cousinExpected.containsAll(cousinDeletes) && cousinDeletes.containsAll(cousinExpected));
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/ConsoleTest.java b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/ConsoleTest.java
index 501fdbf1..d33b4af9 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/ConsoleTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/ConsoleTest.java
@@ -17,64 +17,63 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.serialization.queryformats;
+import static org.junit.Assert.*;
+
import com.google.gson.JsonObject;
+
import org.junit.Test;
import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexException;
-import static org.junit.Assert.*;
-
public class ConsoleTest {
-
-
- Console fM1 = new Console();
-
- String param = "abcd";
-
- JsonObject resultVal;
-
- @Test
- public void classConsoleInstantiateCheck() {
- try {
- Console fm1 = new Console();
- assertNotNull("Created class Object is null", fm1);
- }
- catch(Exception e) {
- fail();
- }
+
+ Console fM1 = new Console();
+
+ String param = "abcd";
+
+ JsonObject resultVal;
+
+ @Test
+ public void classConsoleInstantiateCheck() {
+ try {
+ Console fm1 = new Console();
+ assertNotNull("Created class Object is null", fm1);
+ } catch (Exception e) {
+ fail();
+ }
}
-
- //Below method is expecting to throw an exception
-
- @Test(expected=NullPointerException.class)
+
+ // Below method is expecting to throw an exception
+
+ @Test(expected = NullPointerException.class)
public void formatObjectParamNullCheck() throws AAIFormatVertexException {
-
- param=null;
- Console fm3 = new Console();
- resultVal = fm3.formatObject(param).get();
- }
-
- @Test
+
+ param = null;
+ Console fm3 = new Console();
+ resultVal = fm3.formatObject(param).get();
+ }
+
+ @Test
public void formatObjectResultCheck() {
-
- try {
- Console fm2 = new Console();
-
- resultVal = fm2.formatObject(param).get();
- assertNotNull("The result is null", resultVal);
-
- //System.out.println(resultVal);
-
- JsonObject jsonObj = new JsonObject();
- jsonObj.addProperty("result", "abcd");
-
- assertEquals(jsonObj, resultVal);
-
- }
- catch (Exception e) {
- fail();
- }
- }
-
+
+ try {
+ Console fm2 = new Console();
+
+ resultVal = fm2.formatObject(param).get();
+ assertNotNull("The result is null", resultVal);
+
+ // System.out.println(resultVal);
+
+ JsonObject jsonObj = new JsonObject();
+ jsonObj.addProperty("result", "abcd");
+
+ assertEquals(jsonObj, resultVal);
+
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/CountQuerySupportTest.java b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/CountQuerySupportTest.java
index c83b5b39..a2976e0c 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/CountQuerySupportTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/CountQuerySupportTest.java
@@ -17,9 +17,18 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.serialization.queryformats;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
import com.google.gson.JsonObject;
+
+import java.util.Arrays;
+import java.util.List;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -47,119 +56,111 @@ import org.onap.aai.serialization.queryformats.utils.UrlBuilder;
import org.onap.aai.setup.SchemaVersion;
import org.springframework.beans.factory.annotation.Autowired;
-import java.util.Arrays;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
public class CountQuerySupportTest extends AAISetup {
- @Autowired
- private EdgeSerializer edgeSer;
-
- private Graph graph;
- private TransactionalGraphEngine dbEngine;
- private Loader loader;
- private final ModelType factoryType = ModelType.MOXY;
-
- private SchemaVersion version;
- Vertex pserver1;
- Vertex complex1;
- Vertex complex2;
-
- private DBSerializer serializer;
-
- private FormatFactory ff;
- private Formatter formatter;
-
-
-
- @Before
- public void setUp() throws Exception {
-
- version = schemaVersions.getDefaultVersion();
- MockitoAnnotations.initMocks(this);
-
- graph = TinkerGraph.open();
-
- pserver1 = graph.addVertex(T.label, "pserver", T.id, "2", "aai-node-type", "pserver", "hostname",
- "hostname-1");
- complex1 = graph.addVertex(T.label, "complex", T.id, "3", "aai-node-type", "complex",
- "physical-location-id", "physical-location-id-1", "country", "US");
-
- complex2 = graph.addVertex(T.label, "complex", T.id, "4", "aai-node-type", "complex",
- "physical-location-id", "physical-location-id-2", "country", "US");
-
- GraphTraversalSource g = graph.traversal();
- edgeSer.addEdge(g, pserver1, complex1);
-
- createLoaderEngineSetup();
-
- }
-
- @After
- public void tearDown() throws Exception {
- graph.close();
- }
-
- @Test
- public void verifyComplexVertexCountTest1() throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
- List<Object> complexList = Arrays.asList(this.complex1, this.complex2 );
- JsonObject jo = this.formatter.output(complexList);
- assertEquals(2, jo.get("results").getAsJsonArray().get(0).getAsJsonObject().get("complex").getAsInt());
- }
-
- @Test
- public void verifyPserverVertexCountTest1() throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
- List<Object> pserverList = Arrays.asList(this.pserver1 );
- JsonObject jo = this.formatter.output(pserverList);
- assertEquals(1, jo.get("results").getAsJsonArray().get(0).getAsJsonObject().get("pserver").getAsInt());
- }
-
- @Test
- public void verifyComplexVertexCountTest2() throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
- List<Object> list = Arrays.asList(this.complex1, this.pserver1, this.complex2 );
- JsonObject jo = this.formatter.output(list);
- assertEquals(2, jo.get("results").getAsJsonArray().get(0).getAsJsonObject().get("complex").getAsInt());
- }
-
- @Test
- public void verifyPserverVertexCountTest2() throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
- List<Object> list = Arrays.asList(this.complex1, this.pserver1, this.complex2 );
- JsonObject jo = this.formatter.output(list);
- assertEquals(1, jo.get("results").getAsJsonArray().get(0).getAsJsonObject().get("pserver").getAsInt());
- }
-
- @Test
- public void verifyLongTest() throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
- List<Object> complexList = Arrays.asList(Long.valueOf(22L) );
- JsonObject jo = this.formatter.output(complexList);
- assertEquals(22, jo.get("results").getAsJsonArray().get(0).getAsJsonObject().get("count").getAsInt());
- }
-
-
- public void createLoaderEngineSetup() throws AAIException {
-
- if (loader == null) {
- loader = loaderFactory.createLoaderForVersion(factoryType, version);
- //loader = LoaderFactory.createLoaderForVersion(factoryType, version);
- dbEngine = spy(new JanusGraphDBEngine(QueryStyle.TRAVERSAL, DBConnectionType.CACHED, loader));
- serializer = new DBSerializer(version, dbEngine, factoryType, "Junit");
-
- ff = new FormatFactory(loader, serializer, schemaVersions, basePath);
- formatter = ff.get(Format.count);
-
-
- TransactionalGraphEngine.Admin spyAdmin = spy(dbEngine.asAdmin());
-
- when(dbEngine.tx()).thenReturn(graph);
- when(dbEngine.asAdmin()).thenReturn(spyAdmin);
-
- when(spyAdmin.getReadOnlyTraversalSource())
- .thenReturn(graph.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance())));
- when(spyAdmin.getTraversalSource()).thenReturn(graph.traversal());
- }
- }
+ @Autowired
+ private EdgeSerializer edgeSer;
+
+ private Graph graph;
+ private TransactionalGraphEngine dbEngine;
+ private Loader loader;
+ private final ModelType factoryType = ModelType.MOXY;
+
+ private SchemaVersion version;
+ Vertex pserver1;
+ Vertex complex1;
+ Vertex complex2;
+
+ private DBSerializer serializer;
+
+ private FormatFactory ff;
+ private Formatter formatter;
+
+ @Before
+ public void setUp() throws Exception {
+
+ version = schemaVersions.getDefaultVersion();
+ MockitoAnnotations.initMocks(this);
+
+ graph = TinkerGraph.open();
+
+ pserver1 = graph.addVertex(T.label, "pserver", T.id, "2", "aai-node-type", "pserver", "hostname", "hostname-1");
+ complex1 = graph.addVertex(T.label, "complex", T.id, "3", "aai-node-type", "complex", "physical-location-id",
+ "physical-location-id-1", "country", "US");
+
+ complex2 = graph.addVertex(T.label, "complex", T.id, "4", "aai-node-type", "complex", "physical-location-id",
+ "physical-location-id-2", "country", "US");
+
+ GraphTraversalSource g = graph.traversal();
+ edgeSer.addEdge(g, pserver1, complex1);
+
+ createLoaderEngineSetup();
+
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ graph.close();
+ }
+
+ @Test
+ public void verifyComplexVertexCountTest1()
+ throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
+ List<Object> complexList = Arrays.asList(this.complex1, this.complex2);
+ JsonObject jo = this.formatter.output(complexList);
+ assertEquals(2, jo.get("results").getAsJsonArray().get(0).getAsJsonObject().get("complex").getAsInt());
+ }
+
+ @Test
+ public void verifyPserverVertexCountTest1()
+ throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
+ List<Object> pserverList = Arrays.asList(this.pserver1);
+ JsonObject jo = this.formatter.output(pserverList);
+ assertEquals(1, jo.get("results").getAsJsonArray().get(0).getAsJsonObject().get("pserver").getAsInt());
+ }
+
+ @Test
+ public void verifyComplexVertexCountTest2()
+ throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
+ List<Object> list = Arrays.asList(this.complex1, this.pserver1, this.complex2);
+ JsonObject jo = this.formatter.output(list);
+ assertEquals(2, jo.get("results").getAsJsonArray().get(0).getAsJsonObject().get("complex").getAsInt());
+ }
+
+ @Test
+ public void verifyPserverVertexCountTest2()
+ throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
+ List<Object> list = Arrays.asList(this.complex1, this.pserver1, this.complex2);
+ JsonObject jo = this.formatter.output(list);
+ assertEquals(1, jo.get("results").getAsJsonArray().get(0).getAsJsonObject().get("pserver").getAsInt());
+ }
+
+ @Test
+ public void verifyLongTest() throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
+ List<Object> complexList = Arrays.asList(Long.valueOf(22L));
+ JsonObject jo = this.formatter.output(complexList);
+ assertEquals(22, jo.get("results").getAsJsonArray().get(0).getAsJsonObject().get("count").getAsInt());
+ }
+
+ public void createLoaderEngineSetup() throws AAIException {
+
+ if (loader == null) {
+ loader = loaderFactory.createLoaderForVersion(factoryType, version);
+ // loader = LoaderFactory.createLoaderForVersion(factoryType, version);
+ dbEngine = spy(new JanusGraphDBEngine(QueryStyle.TRAVERSAL, DBConnectionType.CACHED, loader));
+ serializer = new DBSerializer(version, dbEngine, factoryType, "Junit");
+
+ ff = new FormatFactory(loader, serializer, schemaVersions, basePath);
+ formatter = ff.get(Format.count);
+
+ TransactionalGraphEngine.Admin spyAdmin = spy(dbEngine.asAdmin());
+
+ when(dbEngine.tx()).thenReturn(graph);
+ when(dbEngine.asAdmin()).thenReturn(spyAdmin);
+
+ when(spyAdmin.getReadOnlyTraversalSource())
+ .thenReturn(graph.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance())));
+ when(spyAdmin.getTraversalSource()).thenReturn(graph.traversal());
+ }
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/FormatTest.java b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/FormatTest.java
index 6838481e..965e7157 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/FormatTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/FormatTest.java
@@ -17,32 +17,33 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.serialization.queryformats;
+import static org.junit.Assert.*;
+
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.onap.aai.AAISetup;
import org.onap.aai.exceptions.AAIException;
-import static org.junit.Assert.*;
-
public class FormatTest extends AAISetup {
- @Rule
- public ExpectedException expectedEx = ExpectedException.none();
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
- @Test
- public void validFormatTest() throws AAIException {
- assertEquals(Format.count, Format.getFormat("count"));
- }
+ @Test
+ public void validFormatTest() throws AAIException {
+ assertEquals(Format.count, Format.getFormat("count"));
+ }
- @Test
- public void invalidFormatTest() throws AAIException {
- String format = "test";
- expectedEx.expect(AAIException.class);
- expectedEx.expectMessage("Unsupported format query parameter " + format + " in request.");
- Format.getFormat(format);
- }
+ @Test
+ public void invalidFormatTest() throws AAIException {
+ String format = "test";
+ expectedEx.expect(AAIException.class);
+ expectedEx.expectMessage("Unsupported format query parameter " + format + " in request.");
+ Format.getFormat(format);
+ }
-} \ No newline at end of file
+}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/GraphSONTest.java b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/GraphSONTest.java
index 154761ae..847a45ed 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/GraphSONTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/GraphSONTest.java
@@ -17,12 +17,22 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.serialization.queryformats;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsNot.not;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
+
+import java.util.Optional;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.T;
@@ -46,520 +56,423 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import java.util.Optional;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.IsNot.not;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(classes = {
- ConfigConfiguration.class,
- AAICorePrivateEdgeTestConfigTranslator.class,
- EdgeIngestor.class,
- EdgeSerializer.class,
- SpringContextAware.class
-})
+@ContextConfiguration(
+ classes = {ConfigConfiguration.class, AAICorePrivateEdgeTestConfigTranslator.class, EdgeIngestor.class,
+ EdgeSerializer.class, SpringContextAware.class})
@DirtiesContext
public class GraphSONTest {
private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(GraphSONTest.class);
- private Graph graph;
- private Vertex v1;
-
- @Autowired
- protected EdgeSerializer edgeSer;
-
- @Autowired
- protected EdgeIngestor rules;
-
- private JsonObject jsonObj = new JsonObject() ;
- private JsonObject properties = new JsonObject();
- private JsonArray name = new JsonArray() ;
- private JsonObject idVal = new JsonObject() ;
-
- private GraphSON graphSON;
-
- @Before
- public void setUp() {
-
- jsonObj.addProperty("id", 0);
- jsonObj.addProperty("label", "vertex");
-
- idVal.addProperty("id", 1);
- idVal.addProperty("value", "Sam");
-
- name.add(idVal);
- properties.add("name",name);
- jsonObj.add("properties", properties);
-
- graph = TinkerGraph.open();
- v1 = graph.addVertex("name", "Sam");
-
- graphSON = new GraphSON();
- }
-
- @Test
- public void classGraphSONTestWithVertex(){
-
- GraphSON graphSonObj1 = new GraphSON();
- JsonObject obj = graphSonObj1.formatObject(v1).get();
-
- assertEquals(jsonObj, obj);
- }
-
- /**
+ private Graph graph;
+ private Vertex v1;
+
+ @Autowired
+ protected EdgeSerializer edgeSer;
+
+ @Autowired
+ protected EdgeIngestor rules;
+
+ private JsonObject jsonObj = new JsonObject();
+ private JsonObject properties = new JsonObject();
+ private JsonArray name = new JsonArray();
+ private JsonObject idVal = new JsonObject();
+
+ private GraphSON graphSON;
+
+ @Before
+ public void setUp() {
+
+ jsonObj.addProperty("id", 0);
+ jsonObj.addProperty("label", "vertex");
+
+ idVal.addProperty("id", 1);
+ idVal.addProperty("value", "Sam");
+
+ name.add(idVal);
+ properties.add("name", name);
+ jsonObj.add("properties", properties);
+
+ graph = TinkerGraph.open();
+ v1 = graph.addVertex("name", "Sam");
+
+ graphSON = new GraphSON();
+ }
+
+ @Test
+ public void classGraphSONTestWithVertex() {
+
+ GraphSON graphSonObj1 = new GraphSON();
+ JsonObject obj = graphSonObj1.formatObject(v1).get();
+
+ assertEquals(jsonObj, obj);
+ }
+
+ /**
* Case where there is only one private edge
+ *
+ * <pre>
+ * {
+ * "id": 21,
+ * "inE": {
+ * "org.onap.relationships.inventory.isA": [
+ * {
+ * "id": 10,
+ * "properties": {
+ * "aai-uuid": "oafjdsiofjs",
+ * "private": true
+ * }
+ * }
+ * ]
+ * }
+ * "label": "model-ver",
+ * "properties": {
+ * "aai-node-type": [
+ * {
+ * "id": 5,
+ * "value": "model-ver"
+ * }
+ * ]
+ * }
+ * }
+ * </pre>
+ *
+ * @throws AAIException
+ */
+ @Test
+ public void testGraphWithVertexHavingPrivateEdges()
+ throws AAIException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
+
+ Vertex genericVnf = graph.addVertex(T.label, "generic-vnf", T.id, "20", "aai-node-type", "generic-vnf",
+ "vnf-id", "vnf-id-1", "vnf-name", "vnf-name-1");
+
+ Vertex modelVer = graph.addVertex(T.label, "model-ver", T.id, "21", "aai-node-type", "model-ver",
+ "model-version-id", "modelVer1", "model-name", "modelName1");
+
+ GraphTraversalSource source = graph.traversal();
+ edgeSer.addPrivateEdge(source, genericVnf, modelVer, null);
+
+ Optional<JsonObject> jsonObjectOptional = graphSON.formatObject(genericVnf);
+ JsonObject obj = jsonObjectOptional.get();
+ LOGGER.info(obj.toString());
+ assertNotNull(obj);
+ String value = obj.toString();
+
+ assertThat(value, not(containsString("private")));
+ assertThat(value, not(containsString("inE")));
+ assertThat(value, not(containsString("outE")));
+ }
+
+ /**
+ * Case where there is one private edge and regular edge
+ * with the same edge label name
+ *
+ * <pre>
+ * {
+ * "id": 21,
+ * "inE": {
+ * "org.onap.relationships.inventory.isA": [
+ * {
+ * "id": 10,
+ * "properties": {
+ * "aai-uuid": "oafjdsiofjs",
+ * "private": true
+ * }
+ * }
+ * {
+ * "id": 11,
+ * "properties": {
+ * "aai-uuid": "oafjdsiofjs",
+ * "private": false
+ * }
+ * }
+ * ]
+ * }
+ * "label": "model-ver",
+ * "properties": {
+ * "aai-node-type": [
+ * {
+ * "id": 5,
+ * "value": "model-ver"
+ * }
+ * ]
+ * }
+ * }
+ * </pre>
+ *
+ * @throws AAIException
+ */
+ @Test
+ public void testGraphWithSameLabelWithPrivateEdgeAndRegularEdge()
+ throws AAIException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
+
+ Vertex genericVnf = graph.addVertex(T.label, "generic-vnf", T.id, "20", "aai-node-type", "generic-vnf",
+ "vnf-id", "vnf-id-1", "vnf-name", "vnf-name-1");
+
+ Vertex modelVer = graph.addVertex(T.label, "model-ver", T.id, "21", "aai-node-type", "model-ver",
+ "model-version-id", "modelVer1", "model-name", "modelName1");
+
+ Vertex modelElement = graph.addVertex(T.label, "model-element", T.id, "22", "aai-node-type", "model-element");
+
+ GraphTraversalSource source = graph.traversal();
+ edgeSer.addPrivateEdge(source, genericVnf, modelVer, null);
+ edgeSer.addEdge(source, modelVer, modelElement, null);
+
+ Optional<JsonObject> jsonObjectOptional = graphSON.formatObject(modelVer);
+ JsonObject obj = jsonObjectOptional.get();
+ LOGGER.info(obj.toString());
+ assertNotNull(obj);
+ String value = obj.toString();
+ assertThat(value, not(containsString("\"private\":true")));
+ }
+
+ /**
+ * Case where there is one private edge and regular edge to same label
+ * And another regular edge to a different label
+ *
+ * <pre>
+ * {
+ * "id": 21,
+ * "inE": {
+ * "org.onap.relationships.inventory.isA": [
+ * {
+ * "id": 10,
+ * "properties": {
+ * "aai-uuid": "oafjdsiofjs",
+ * "private": true
+ * }
+ * },
+ * {
+ * "id": 11,
+ * "properties": {
+ * "aai-uuid": "oafjdsiofjs",
+ * "private": false
+ * }
+ * }
+ * ],
+ * "org.onap.relationships.inventory.BelongsTo": [
+ * {
+ * "id": 13,
+ * "properties": {
+ * "aai-uuid": "oafjdsiofjs",
+ * "private": false
+ * }
+ * }
+ * ]
+ * }
+ * "label": "model-ver",
+ * "properties": {
+ * "aai-node-type": [
+ * {
+ * "id": 5,
+ * "value": "model-ver"
+ * }
+ * ]
+ * }
+ * }
+ * </pre>
+ *
+ * @throws AAIException
+ */
+ @Test
+ public void testGraphWithMultipleLabelWithOneLabelWithPrivateEdgeAndRegularEdgeAndAnotherLabelWithRegularEdge()
+ throws AAIException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
+
+ Vertex genericVnf = graph.addVertex(T.label, "generic-vnf", T.id, "20", "aai-node-type", "generic-vnf",
+ "vnf-id", "vnf-id-1", "vnf-name", "vnf-name-1");
+
+ Vertex modelVer = graph.addVertex(T.label, "model-ver", T.id, "21", "aai-node-type", "model-ver",
+ "model-version-id", "modelVer1", "model-name", "modelName1");
+
+ Vertex modelElement = graph.addVertex(T.label, "model-element", T.id, "22", "aai-node-type", "model-element");
+
+ Vertex metadatum = graph.addVertex(T.label, "metadatum", T.id, "23", "aai-node-type", "metadatum");
+
+ GraphTraversalSource source = graph.traversal();
+ edgeSer.addPrivateEdge(source, genericVnf, modelVer, null);
+ edgeSer.addEdge(source, modelVer, modelElement, null);
+ edgeSer.addTreeEdge(source, modelVer, metadatum);
+
+ Optional<JsonObject> jsonObjectOptional = graphSON.formatObject(modelVer);
+ JsonObject obj = jsonObjectOptional.get();
+ LOGGER.info(obj.toString());
+ assertNotNull(obj);
+ String value = obj.toString();
+ assertThat(value, not(containsString("\"private\":true")));
+ }
+
+ @Test
+ public void testGraphCreateRegularOutAndInEdges() throws AAIException {
+
+ Vertex complex1 = graph.addVertex(T.label, "complex", T.id, "20", "aai-node-type", "complex");
+
+ Vertex pserver1 = graph.addVertex(T.label, "pserver", T.id, "22", "aai-node-type", "pserver", "hostname",
+ "test-pserver1");
+
+ Vertex pserver2 = graph.addVertex(T.label, "pserver", T.id, "23", "aai-node-type", "pserver", "hostname",
+ "test-pserver2");
+
+ GraphTraversalSource source = graph.traversal();
+ edgeSer.addEdge(source, pserver1, complex1, null);
+ edgeSer.addEdge(source, pserver2, complex1, null);
+
+ Optional<JsonObject> jsonObjectOptional = graphSON.formatObject(complex1);
+ JsonObject obj = jsonObjectOptional.get();
+ LOGGER.info(obj.toString());
+ assertNotNull(obj);
+ assertThat(obj.toString(), not(containsString("\"private\":true")));
+ assertThat(obj.toString(), containsString("inE"));
+ }
+
+ /**
+ * Case where there is one private edge and regular edge to same label
+ * And another regular edge to a different label
+ *
* <pre>
* {
- * "id": 21,
- * "inE": {
- * "org.onap.relationships.inventory.isA": [
- * {
- * "id": 10,
- * "properties": {
- * "aai-uuid": "oafjdsiofjs",
- * "private": true
- * }
- * }
- * ]
- * }
- * "label": "model-ver",
- * "properties": {
- * "aai-node-type": [
- * {
- * "id": 5,
- * "value": "model-ver"
- * }
- * ]
- * }
- * }
+ * "id": 21,
+ * "inE": {
+ * "org.onap.relationships.inventory.isA": [
+ * {
+ * "id": 10,
+ * "properties": {
+ * "aai-uuid": "oafjdsiofjs",
+ * "private": true
+ * }
+ * }
+ * ],
+ * "org.onap.relationships.inventory.BelongsTo": [
+ * {
+ * "id": 13,
+ * "properties": {
+ * "aai-uuid": "oafjdsiofjs",
+ * "private": true
+ * }
+ * }
+ * ]
+ * }
+ * "label": "model-ver",
+ * "properties": {
+ * "aai-node-type": [
+ * {
+ * "id": 5,
+ * "value": "model-ver"
+ * }
+ * ]
+ * }
+ * }
* </pre>
- *
- * @throws AAIException
- */
- @Test
- public void testGraphWithVertexHavingPrivateEdges() throws AAIException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
-
- Vertex genericVnf = graph.addVertex(
- T.label, "generic-vnf",
- T.id, "20",
- "aai-node-type", "generic-vnf",
- "vnf-id", "vnf-id-1",
- "vnf-name", "vnf-name-1"
- );
-
- Vertex modelVer = graph.addVertex(
- T.label, "model-ver",
- T.id, "21",
- "aai-node-type", "model-ver",
- "model-version-id", "modelVer1",
- "model-name", "modelName1"
- );
-
- GraphTraversalSource source = graph.traversal();
- edgeSer.addPrivateEdge(source, genericVnf, modelVer, null);
-
- Optional<JsonObject> jsonObjectOptional = graphSON.formatObject(genericVnf);
- JsonObject obj = jsonObjectOptional.get();
- LOGGER.info(obj.toString());
- assertNotNull(obj);
- String value = obj.toString();
-
- assertThat(value, not(containsString("private")));
- assertThat(value, not(containsString("inE")));
- assertThat(value, not(containsString("outE")));
- }
-
- /**
- * Case where there is one private edge and regular edge
- * with the same edge label name
- * <pre>
- * {
- * "id": 21,
- * "inE": {
- * "org.onap.relationships.inventory.isA": [
- * {
- * "id": 10,
- * "properties": {
- * "aai-uuid": "oafjdsiofjs",
- * "private": true
- * }
- * }
- * {
- * "id": 11,
- * "properties": {
- * "aai-uuid": "oafjdsiofjs",
- * "private": false
- * }
- * }
- * ]
- * }
- * "label": "model-ver",
- * "properties": {
- * "aai-node-type": [
- * {
- * "id": 5,
- * "value": "model-ver"
- * }
- * ]
- * }
- * }
- * </pre>
- *
- * @throws AAIException
- */
- @Test
- public void testGraphWithSameLabelWithPrivateEdgeAndRegularEdge() throws AAIException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
-
- Vertex genericVnf = graph.addVertex(
- T.label, "generic-vnf",
- T.id, "20",
- "aai-node-type", "generic-vnf",
- "vnf-id", "vnf-id-1",
- "vnf-name", "vnf-name-1"
- );
-
- Vertex modelVer = graph.addVertex(
- T.label, "model-ver",
- T.id, "21",
- "aai-node-type", "model-ver",
- "model-version-id", "modelVer1",
- "model-name", "modelName1"
- );
-
- Vertex modelElement = graph.addVertex(
- T.label, "model-element",
- T.id, "22",
- "aai-node-type", "model-element"
- );
-
-
-
- GraphTraversalSource source = graph.traversal();
- edgeSer.addPrivateEdge(source, genericVnf, modelVer, null);
- edgeSer.addEdge(source, modelVer, modelElement, null);
-
- Optional<JsonObject> jsonObjectOptional = graphSON.formatObject(modelVer);
- JsonObject obj = jsonObjectOptional.get();
- LOGGER.info(obj.toString());
- assertNotNull(obj);
- String value = obj.toString();
- assertThat(value, not(containsString("\"private\":true")));
- }
-
- /**
- * Case where there is one private edge and regular edge to same label
+ *
+ * @throws AAIException
+ */
+ @Test
+ public void testWhenMultipleEdgeLabelsBothOnlyHavePrivateEdges()
+ throws AAIException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
+
+ Vertex genericVnf = graph.addVertex(T.label, "generic-vnf", T.id, "20", "aai-node-type", "generic-vnf",
+ "vnf-id", "vnf-id-1", "vnf-name", "vnf-name-1");
+
+ Vertex modelVer = graph.addVertex(T.label, "model-ver", T.id, "21", "aai-node-type", "model-ver",
+ "model-version-id", "modelVer1", "model-name", "modelName1");
+
+ Vertex modelPrivate = graph.addVertex(T.label, "model-private", T.id, "22", "aai-node-type", "model-private");
+
+ GraphTraversalSource source = graph.traversal();
+ edgeSer.addPrivateEdge(source, genericVnf, modelVer, null);
+ edgeSer.addPrivateEdge(source, modelVer, modelPrivate, null);
+
+ Optional<JsonObject> jsonObjectOptional = graphSON.formatObject(modelVer);
+ JsonObject obj = jsonObjectOptional.get();
+ LOGGER.info(obj.toString());
+ assertNotNull(obj);
+ String value = obj.toString();
+ assertThat(value, not(containsString("\"private\":true")));
+ assertThat(value, not(containsString("inventory.BelongsTo")));
+ assertThat(value, not(containsString("inE")));
+ }
+
+ /**
+ * Case where there is one private edge and regular edge to same label
* And another regular edge to a different label
- * <pre>
- * {
- * "id": 21,
- * "inE": {
- * "org.onap.relationships.inventory.isA": [
- * {
- * "id": 10,
- * "properties": {
- * "aai-uuid": "oafjdsiofjs",
- * "private": true
- * }
- * },
- * {
- * "id": 11,
- * "properties": {
- * "aai-uuid": "oafjdsiofjs",
- * "private": false
- * }
- * }
- * ],
- * "org.onap.relationships.inventory.BelongsTo": [
- * {
- * "id": 13,
- * "properties": {
- * "aai-uuid": "oafjdsiofjs",
- * "private": false
- * }
- * }
- * ]
- * }
- * "label": "model-ver",
- * "properties": {
- * "aai-node-type": [
- * {
- * "id": 5,
- * "value": "model-ver"
- * }
- * ]
- * }
- * }
- * </pre>
- *
- * @throws AAIException
- */
- @Test
- public void testGraphWithMultipleLabelWithOneLabelWithPrivateEdgeAndRegularEdgeAndAnotherLabelWithRegularEdge() throws AAIException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
-
- Vertex genericVnf = graph.addVertex(
- T.label, "generic-vnf",
- T.id, "20",
- "aai-node-type", "generic-vnf",
- "vnf-id", "vnf-id-1",
- "vnf-name", "vnf-name-1"
- );
-
- Vertex modelVer = graph.addVertex(
- T.label, "model-ver",
- T.id, "21",
- "aai-node-type", "model-ver",
- "model-version-id", "modelVer1",
- "model-name", "modelName1"
- );
-
- Vertex modelElement = graph.addVertex(
- T.label, "model-element",
- T.id, "22",
- "aai-node-type", "model-element"
- );
-
- Vertex metadatum = graph.addVertex(
- T.label, "metadatum",
- T.id, "23",
- "aai-node-type", "metadatum"
- );
-
-
-
- GraphTraversalSource source = graph.traversal();
- edgeSer.addPrivateEdge(source, genericVnf, modelVer, null);
- edgeSer.addEdge(source, modelVer, modelElement, null);
- edgeSer.addTreeEdge(source, modelVer, metadatum);
-
- Optional<JsonObject> jsonObjectOptional = graphSON.formatObject(modelVer);
- JsonObject obj = jsonObjectOptional.get();
- LOGGER.info(obj.toString());
- assertNotNull(obj);
- String value = obj.toString();
- assertThat(value, not(containsString("\"private\":true")));
- }
-
- @Test
- public void testGraphCreateRegularOutAndInEdges() throws AAIException {
-
- Vertex complex1 = graph.addVertex(
- T.label, "complex",
- T.id, "20",
- "aai-node-type", "complex"
- );
-
- Vertex pserver1 = graph.addVertex(
- T.label, "pserver",
- T.id, "22",
- "aai-node-type", "pserver",
- "hostname", "test-pserver1"
- );
-
- Vertex pserver2 = graph.addVertex(
- T.label, "pserver",
- T.id, "23",
- "aai-node-type", "pserver",
- "hostname", "test-pserver2"
- );
-
-
-
- GraphTraversalSource source = graph.traversal();
- edgeSer.addEdge(source, pserver1, complex1, null);
- edgeSer.addEdge(source, pserver2, complex1, null);
-
-
- Optional<JsonObject> jsonObjectOptional = graphSON.formatObject(complex1);
- JsonObject obj = jsonObjectOptional.get();
- LOGGER.info(obj.toString());
- assertNotNull(obj);
- assertThat(obj.toString(), not(containsString("\"private\":true")));
- assertThat(obj.toString(), containsString("inE"));
- }
-
- /**
- * Case where there is one private edge and regular edge to same label
- * And another regular edge to a different label
- * <pre>
- * {
- * "id": 21,
- * "inE": {
- * "org.onap.relationships.inventory.isA": [
- * {
- * "id": 10,
- * "properties": {
- * "aai-uuid": "oafjdsiofjs",
- * "private": true
- * }
- * }
- * ],
- * "org.onap.relationships.inventory.BelongsTo": [
- * {
- * "id": 13,
- * "properties": {
- * "aai-uuid": "oafjdsiofjs",
- * "private": true
- * }
- * }
- * ]
- * }
- * "label": "model-ver",
- * "properties": {
- * "aai-node-type": [
- * {
- * "id": 5,
- * "value": "model-ver"
- * }
- * ]
- * }
- * }
- * </pre>
- *
- * @throws AAIException
- */
- @Test
- public void testWhenMultipleEdgeLabelsBothOnlyHavePrivateEdges() throws AAIException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
-
- Vertex genericVnf = graph.addVertex(
- T.label, "generic-vnf",
- T.id, "20",
- "aai-node-type", "generic-vnf",
- "vnf-id", "vnf-id-1",
- "vnf-name", "vnf-name-1"
- );
-
- Vertex modelVer = graph.addVertex(
- T.label, "model-ver",
- T.id, "21",
- "aai-node-type", "model-ver",
- "model-version-id", "modelVer1",
- "model-name", "modelName1"
- );
-
- Vertex modelPrivate = graph.addVertex(
- T.label, "model-private",
- T.id, "22",
- "aai-node-type", "model-private"
- );
-
-
-
- GraphTraversalSource source = graph.traversal();
- edgeSer.addPrivateEdge(source, genericVnf, modelVer, null);
- edgeSer.addPrivateEdge(source, modelVer, modelPrivate, null);
-
- Optional<JsonObject> jsonObjectOptional = graphSON.formatObject(modelVer);
- JsonObject obj = jsonObjectOptional.get();
- LOGGER.info(obj.toString());
- assertNotNull(obj);
- String value = obj.toString();
- assertThat(value, not(containsString("\"private\":true")));
- assertThat(value, not(containsString("inventory.BelongsTo")));
- assertThat(value, not(containsString("inE")));
- }
-
- /**
- * Case where there is one private edge and regular edge to same label
- * And another regular edge to a different label
- * <pre>
- * {
- * "id": 21,
- * "inE": {
- * "org.onap.relationships.inventory.isA": [
- * {
- * "id": 10,
- * "properties": {
- * "aai-uuid": "oafjdsiofjs",
- * "private": true
- * }
- * }
- * ],
- * "org.onap.relationships.inventory.BelongsTo": [
- * {
- * "id": 13,
- * "properties": {
- * "aai-uuid": "oafjdsiofjs",
- * "private": true
- * }
- * },
- * {
- * "id": 13,
- * "properties": {
- * "aai-uuid": "jaosjfaisj",
- * "private": false
- * }
- * }
- * ]
- * }
- * "label": "model-ver",
- * "properties": {
- * "aai-node-type": [
- * {
- * "id": 5,
- * "value": "model-ver"
- * }
- * ]
- * }
- * }
- * </pre>
- *
- * @throws AAIException
- */
- @Test
- public void testWhenMultipleEdgeLabelsBothHavePrivateEdgesButOneHasTreeEdgeAndPrivateEdge() throws AAIException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
-
- Vertex genericVnf = graph.addVertex(
- T.label, "generic-vnf",
- T.id, "20",
- "aai-node-type", "generic-vnf",
- "vnf-id", "vnf-id-1",
- "vnf-name", "vnf-name-1"
- );
-
- Vertex modelVer = graph.addVertex(
- T.label, "model-ver",
- T.id, "21",
- "aai-node-type", "model-ver",
- "model-version-id", "modelVer1",
- "model-name", "modelName1"
- );
-
- Vertex modelPrivate = graph.addVertex(
- T.label, "model-private",
- T.id, "22",
- "aai-node-type", "model-private"
- );
-
- Vertex metadatum = graph.addVertex(
- T.label, "metadatum",
- T.id, "23",
- "aai-node-type", "metadatum"
- );
-
- GraphTraversalSource source = graph.traversal();
- edgeSer.addPrivateEdge(source, genericVnf, modelVer, null);
- edgeSer.addPrivateEdge(source, modelVer, modelPrivate, null);
- edgeSer.addTreeEdge(source, modelVer, metadatum);
-
- Optional<JsonObject> jsonObjectOptional = graphSON.formatObject(modelVer);
- JsonObject obj = jsonObjectOptional.get();
- LOGGER.info(obj.toString());
- assertNotNull(obj);
- String value = obj.toString();
- assertThat(value, not(containsString("\"private\":true")));
- assertThat(value, containsString("inventory.BelongsTo"));
- }
-
- @Test
- public void parallelThresholdCehck(){
-
- GraphSON graphSonObj2 = new GraphSON();
- assertEquals(50, graphSonObj2.parallelThreshold());
-
- }
+ *
+ * <pre>
+ * {
+ * "id": 21,
+ * "inE": {
+ * "org.onap.relationships.inventory.isA": [
+ * {
+ * "id": 10,
+ * "properties": {
+ * "aai-uuid": "oafjdsiofjs",
+ * "private": true
+ * }
+ * }
+ * ],
+ * "org.onap.relationships.inventory.BelongsTo": [
+ * {
+ * "id": 13,
+ * "properties": {
+ * "aai-uuid": "oafjdsiofjs",
+ * "private": true
+ * }
+ * },
+ * {
+ * "id": 13,
+ * "properties": {
+ * "aai-uuid": "jaosjfaisj",
+ * "private": false
+ * }
+ * }
+ * ]
+ * }
+ * "label": "model-ver",
+ * "properties": {
+ * "aai-node-type": [
+ * {
+ * "id": 5,
+ * "value": "model-ver"
+ * }
+ * ]
+ * }
+ * }
+ * </pre>
+ *
+ * @throws AAIException
+ */
+ @Test
+ public void testWhenMultipleEdgeLabelsBothHavePrivateEdgesButOneHasTreeEdgeAndPrivateEdge()
+ throws AAIException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException {
+
+ Vertex genericVnf = graph.addVertex(T.label, "generic-vnf", T.id, "20", "aai-node-type", "generic-vnf",
+ "vnf-id", "vnf-id-1", "vnf-name", "vnf-name-1");
+
+ Vertex modelVer = graph.addVertex(T.label, "model-ver", T.id, "21", "aai-node-type", "model-ver",
+ "model-version-id", "modelVer1", "model-name", "modelName1");
+
+ Vertex modelPrivate = graph.addVertex(T.label, "model-private", T.id, "22", "aai-node-type", "model-private");
+
+ Vertex metadatum = graph.addVertex(T.label, "metadatum", T.id, "23", "aai-node-type", "metadatum");
+
+ GraphTraversalSource source = graph.traversal();
+ edgeSer.addPrivateEdge(source, genericVnf, modelVer, null);
+ edgeSer.addPrivateEdge(source, modelVer, modelPrivate, null);
+ edgeSer.addTreeEdge(source, modelVer, metadatum);
+
+ Optional<JsonObject> jsonObjectOptional = graphSON.formatObject(modelVer);
+ JsonObject obj = jsonObjectOptional.get();
+ LOGGER.info(obj.toString());
+ assertNotNull(obj);
+ String value = obj.toString();
+ assertThat(value, not(containsString("\"private\":true")));
+ assertThat(value, containsString("inventory.BelongsTo"));
+ }
+
+ @Test
+ public void parallelThresholdCehck() {
+
+ GraphSON graphSonObj2 = new GraphSON();
+ assertEquals(50, graphSonObj2.parallelThreshold());
+
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/MultiFormatTest.java b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/MultiFormatTest.java
index 0df32bd3..9ac79ca8 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/MultiFormatTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/MultiFormatTest.java
@@ -17,10 +17,18 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.serialization.queryformats;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.*;
+
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
+
+import java.io.UnsupportedEncodingException;
+
import org.apache.tinkerpop.gremlin.process.traversal.Path;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
@@ -38,136 +46,129 @@ import org.onap.aai.dbmap.DBConnectionType;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.introspection.Loader;
import org.onap.aai.introspection.ModelType;
-import org.onap.aai.setup.SchemaVersion;
import org.onap.aai.serialization.db.EdgeSerializer;
-import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.JanusGraphDBEngine;
+import org.onap.aai.serialization.engines.QueryStyle;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
import org.onap.aai.serialization.queryformats.exceptions.AAIFormatQueryResultFormatNotSupported;
import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexException;
import org.onap.aai.serialization.queryformats.utils.UrlBuilder;
+import org.onap.aai.setup.SchemaVersion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
-import java.io.UnsupportedEncodingException;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.*;
-
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class MultiFormatTest extends AAISetup {
- @Mock
- private UrlBuilder urlBuilder;
-
- private Graph graph;
- private TransactionalGraphEngine dbEngine;
- private Loader loader;
- private IdURL idFormat;
- private final ModelType factoryType = ModelType.MOXY;
- @Autowired
- private EdgeSerializer rules;
- private Tree<?> resultTree;
- private Path resultPath;
- private SchemaVersion version;
- private JsonObject expectedTreeIdFormat = new JsonParser()
- .parse("{\"nodes\":[{\"resource-type\":\"generic-vnf\",\"nodes\":[{\"resource-type\":\"vserver\",\"nodes\":[{\"resource-type\":\"pserver\"}]},{\"resource-type\":\"pserver\",\"nodes\":[{\"resource-type\":\"complex\"}]}]}]}").getAsJsonObject();
- private JsonObject expectedPathIdFormat = new JsonParser()
- .parse("{\"path\":[{\"resource-type\":\"generic-vnf\"},{\"resource-type\":\"vserver\"},{\"resource-type\":\"pserver\"},{\"resource-type\":\"complex\"}]}").getAsJsonObject();
-
-
-
- @Before
- public void setUp() throws Exception {
-
- version = schemaVersions.getAppRootVersion();
- MockitoAnnotations.initMocks(this);
-
- graph = TinkerGraph.open();
-
- Vertex gnvf1 = graph.addVertex(T.label, "generic-vnf", T.id, "0", "aai-node-type", "generic-vnf", "vnf-id",
- "vnf-id-1", "vnf-name", "vnf-name-1");
- Vertex vserver1 = graph.addVertex(T.label, "vserver", T.id, "1", "aai-node-type", "vserver", "vserver-id",
- "vserver-id-1", "vserver-name", "vserver-name-1");
- Vertex pserver1 = graph.addVertex(T.label, "pserver", T.id, "2", "aai-node-type", "pserver", "hostname",
- "hostname-1");
- Vertex complex1 = graph.addVertex(T.label, "complex", T.id, "3", "aai-node-type", "complex",
- "physical-location-id", "physical-location-id-1", "country", "US");
-
- Vertex pserver2 = graph.addVertex(T.label, "pserver", T.id, "5", "aai-node-type", "pserver", "hostname",
- "hostname-2");
- Vertex complex2 = graph.addVertex(T.label, "complex", T.id, "6", "aai-node-type", "complex",
- "physical-location-id", "physical-location-id-2", "country", "US");
-
- GraphTraversalSource g = graph.traversal();
- rules.addEdge(g, gnvf1, vserver1);
- rules.addEdge(g, vserver1, pserver1);
- rules.addEdge(g, pserver1, complex1);
- rules.addEdge(g, gnvf1, pserver2);
- rules.addEdge(g, pserver2, complex2);
-
- resultTree = graph.traversal().V("0").out().out().tree().next();
- resultPath = graph.traversal().V("0").out().hasId("1").out().hasId("2").out().hasId("3").path().next();
- }
-
- @Test
- public void testTreeResultQueryIdFormat()
- throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
-
- createLoaderEngineSetup();
- idFormat = new IdURL(loader, urlBuilder);
-
- assertNotNull(dbEngine.tx());
- assertNotNull(dbEngine.asAdmin());
-
- JsonObject json = idFormat.formatObject(resultTree).get();
-
- assertEquals(this.expectedTreeIdFormat, json);
-
- }
-
- @Test
- public void testPathResultQueryIdFormat()
- throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
-
- createLoaderEngineSetup();
- idFormat = new IdURL(loader, urlBuilder);
-
- assertNotNull(dbEngine.tx());
- assertNotNull(dbEngine.asAdmin());
-
- JsonObject json = idFormat.formatObject(resultPath).get();
-
- assertEquals(this.expectedPathIdFormat, json);
-
- }
-
-
- @Test(expected = AAIFormatQueryResultFormatNotSupported.class)
- public void testThrowsExceptionIfObjectNotSupported() throws AAIFormatVertexException,
- AAIException, UnsupportedEncodingException, AAIFormatQueryResultFormatNotSupported {
-
- loader = mock(Loader.class);
- idFormat = new IdURL(loader, urlBuilder);
- idFormat.formatObject(new String());
- }
-
- public void createLoaderEngineSetup() {
-
- if (loader == null) {
- loader = loaderFactory.createLoaderForVersion(factoryType,version);
- //loader = LoaderFactory.createLoaderForVersion(factoryType, version);
- dbEngine = spy(new JanusGraphDBEngine(QueryStyle.TRAVERSAL, DBConnectionType.CACHED, loader));
-
- TransactionalGraphEngine.Admin spyAdmin = spy(dbEngine.asAdmin());
-
- when(dbEngine.tx()).thenReturn(graph);
- when(dbEngine.asAdmin()).thenReturn(spyAdmin);
-
- when(spyAdmin.getReadOnlyTraversalSource())
- .thenReturn(graph.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance())));
- when(spyAdmin.getTraversalSource()).thenReturn(graph.traversal());
- }
- }
+ @Mock
+ private UrlBuilder urlBuilder;
+
+ private Graph graph;
+ private TransactionalGraphEngine dbEngine;
+ private Loader loader;
+ private IdURL idFormat;
+ private final ModelType factoryType = ModelType.MOXY;
+ @Autowired
+ private EdgeSerializer rules;
+ private Tree<?> resultTree;
+ private Path resultPath;
+ private SchemaVersion version;
+ private JsonObject expectedTreeIdFormat = new JsonParser().parse(
+ "{\"nodes\":[{\"resource-type\":\"generic-vnf\",\"nodes\":[{\"resource-type\":\"vserver\",\"nodes\":[{\"resource-type\":\"pserver\"}]},{\"resource-type\":\"pserver\",\"nodes\":[{\"resource-type\":\"complex\"}]}]}]}")
+ .getAsJsonObject();
+ private JsonObject expectedPathIdFormat = new JsonParser().parse(
+ "{\"path\":[{\"resource-type\":\"generic-vnf\"},{\"resource-type\":\"vserver\"},{\"resource-type\":\"pserver\"},{\"resource-type\":\"complex\"}]}")
+ .getAsJsonObject();
+
+ @Before
+ public void setUp() throws Exception {
+
+ version = schemaVersions.getAppRootVersion();
+ MockitoAnnotations.initMocks(this);
+
+ graph = TinkerGraph.open();
+
+ Vertex gnvf1 = graph.addVertex(T.label, "generic-vnf", T.id, "0", "aai-node-type", "generic-vnf", "vnf-id",
+ "vnf-id-1", "vnf-name", "vnf-name-1");
+ Vertex vserver1 = graph.addVertex(T.label, "vserver", T.id, "1", "aai-node-type", "vserver", "vserver-id",
+ "vserver-id-1", "vserver-name", "vserver-name-1");
+ Vertex pserver1 =
+ graph.addVertex(T.label, "pserver", T.id, "2", "aai-node-type", "pserver", "hostname", "hostname-1");
+ Vertex complex1 = graph.addVertex(T.label, "complex", T.id, "3", "aai-node-type", "complex",
+ "physical-location-id", "physical-location-id-1", "country", "US");
+
+ Vertex pserver2 =
+ graph.addVertex(T.label, "pserver", T.id, "5", "aai-node-type", "pserver", "hostname", "hostname-2");
+ Vertex complex2 = graph.addVertex(T.label, "complex", T.id, "6", "aai-node-type", "complex",
+ "physical-location-id", "physical-location-id-2", "country", "US");
+
+ GraphTraversalSource g = graph.traversal();
+ rules.addEdge(g, gnvf1, vserver1);
+ rules.addEdge(g, vserver1, pserver1);
+ rules.addEdge(g, pserver1, complex1);
+ rules.addEdge(g, gnvf1, pserver2);
+ rules.addEdge(g, pserver2, complex2);
+
+ resultTree = graph.traversal().V("0").out().out().tree().next();
+ resultPath = graph.traversal().V("0").out().hasId("1").out().hasId("2").out().hasId("3").path().next();
+ }
+
+ @Test
+ public void testTreeResultQueryIdFormat()
+ throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
+
+ createLoaderEngineSetup();
+ idFormat = new IdURL(loader, urlBuilder);
+
+ assertNotNull(dbEngine.tx());
+ assertNotNull(dbEngine.asAdmin());
+
+ JsonObject json = idFormat.formatObject(resultTree).get();
+
+ assertEquals(this.expectedTreeIdFormat, json);
+
+ }
+
+ @Test
+ public void testPathResultQueryIdFormat()
+ throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
+
+ createLoaderEngineSetup();
+ idFormat = new IdURL(loader, urlBuilder);
+
+ assertNotNull(dbEngine.tx());
+ assertNotNull(dbEngine.asAdmin());
+
+ JsonObject json = idFormat.formatObject(resultPath).get();
+
+ assertEquals(this.expectedPathIdFormat, json);
+
+ }
+
+ @Test(expected = AAIFormatQueryResultFormatNotSupported.class)
+ public void testThrowsExceptionIfObjectNotSupported() throws AAIFormatVertexException, AAIException,
+ UnsupportedEncodingException, AAIFormatQueryResultFormatNotSupported {
+
+ loader = mock(Loader.class);
+ idFormat = new IdURL(loader, urlBuilder);
+ idFormat.formatObject(new String());
+ }
+
+ public void createLoaderEngineSetup() {
+
+ if (loader == null) {
+ loader = loaderFactory.createLoaderForVersion(factoryType, version);
+ // loader = LoaderFactory.createLoaderForVersion(factoryType, version);
+ dbEngine = spy(new JanusGraphDBEngine(QueryStyle.TRAVERSAL, DBConnectionType.CACHED, loader));
+
+ TransactionalGraphEngine.Admin spyAdmin = spy(dbEngine.asAdmin());
+
+ when(dbEngine.tx()).thenReturn(graph);
+ when(dbEngine.asAdmin()).thenReturn(spyAdmin);
+
+ when(spyAdmin.getReadOnlyTraversalSource())
+ .thenReturn(graph.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance())));
+ when(spyAdmin.getTraversalSource()).thenReturn(graph.traversal());
+ }
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/QueryFormatTestHelper.java b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/QueryFormatTestHelper.java
index 609de5ff..f05e36dd 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/QueryFormatTestHelper.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/QueryFormatTestHelper.java
@@ -17,8 +17,16 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.serialization.queryformats;
+import static org.mockito.Matchers.isA;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.io.IoCore;
@@ -29,46 +37,38 @@ import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexException;
import org.onap.aai.serialization.queryformats.utils.UrlBuilder;
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
+public class QueryFormatTestHelper {
-import static org.mockito.Matchers.isA;
-import static org.mockito.Mockito.when;
+ public static final String testResources = "src/test/resources/org.onap.aai/serialization/queryformats/";
+ public static final String graphsonResources =
+ "src/test/resources/org.onap.aai/serialization/queryformats/graphson/";
-public class QueryFormatTestHelper {
+ public static void mockPathed(UrlBuilder mock) throws AAIFormatVertexException {
+ Answer<String> answer = new Answer<String>() {
+ public String answer(InvocationOnMock invocation) throws Throwable {
+ Vertex v = invocation.getArgumentAt(0, Vertex.class);
+
+ return v.<String>property(AAIProperties.AAI_URI).orElse("urimissing");
+ }
+ };
+ when(mock.pathed(isA(Vertex.class))).thenAnswer(answer);
+
+ }
+
+ public static Graph loadGraphson(String fileName) throws IOException {
+ final Graph graph = TinkerGraph.open();
+ graph.io(IoCore.graphson()).readGraph(QueryFormatTestHelper.graphsonResources + fileName);
-
- public static final String testResources = "src/test/resources/org.onap.aai/serialization/queryformats/";
- public static final String graphsonResources = "src/test/resources/org.onap.aai/serialization/queryformats/graphson/";
+ return graph;
+ }
-
- public static void mockPathed(UrlBuilder mock) throws AAIFormatVertexException {
- Answer<String> answer = new Answer<String>() {
- public String answer(InvocationOnMock invocation) throws Throwable {
- Vertex v = invocation.getArgumentAt(0, Vertex.class);
-
- return v.<String>property(AAIProperties.AAI_URI).orElse("urimissing");
- }
- };
- when(mock.pathed(isA(Vertex.class))).thenAnswer(answer);
+ public static void setFinalStatic(Field field, Object newValue) throws Exception {
+ field.setAccessible(true);
+ // remove final modifier from field
+ Field modifiersField = Field.class.getDeclaredField("modifiers");
+ modifiersField.setAccessible(true);
+ modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
+ field.set(null, newValue);
+ }
- }
-
- public static Graph loadGraphson(String fileName) throws IOException {
- final Graph graph = TinkerGraph.open();
- graph.io(IoCore.graphson()).readGraph(QueryFormatTestHelper.graphsonResources + fileName);
-
- return graph;
- }
-
- public static void setFinalStatic(Field field, Object newValue) throws Exception {
- field.setAccessible(true);
- // remove final modifier from field
- Field modifiersField = Field.class.getDeclaredField("modifiers");
- modifiersField.setAccessible(true);
- modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
- field.set(null, newValue);
- }
-
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/RawFormatTest.java b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/RawFormatTest.java
index c2d5e3cd..2d8c66c3 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/RawFormatTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/RawFormatTest.java
@@ -17,8 +17,13 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.serialization.queryformats;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -46,94 +51,98 @@ import org.onap.aai.setup.SchemaVersion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class RawFormatTest extends AAISetup {
- @Mock
- private UrlBuilder urlBuilder;
-
- private Graph graph;
- private TransactionalGraphEngine dbEngine;
- private Loader loader;
- private RawFormat rawFormat;
- private final ModelType factoryType = ModelType.MOXY;
-
- @Autowired
- private EdgeSerializer rules;
-
- private SchemaVersion version;
- private Vertex pserver;
- private Vertex complex;
-
- private DBSerializer serializer;
-
- @Before
- public void setUp() throws Exception {
-
- version = schemaVersions.getDefaultVersion();
-
- MockitoAnnotations.initMocks(this);
-
- graph = TinkerGraph.open();
-
- Vertex pserver1 = graph.addVertex(T.label, "pserver", T.id, "2", "aai-node-type", "pserver", "hostname",
- "hostname-1");
- Vertex complex1 = graph.addVertex(T.label, "complex", T.id, "3", "aai-node-type", "complex",
- "physical-location-id", "physical-location-id-1", "country", "US");
-
- GraphTraversalSource g = graph.traversal();
- rules.addEdge(g, pserver1, complex1);
-
- pserver = pserver1;
- complex = complex1;
-
- System.setProperty("AJSC_HOME", ".");
- System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
-
- createLoaderEngineSetup();
- }
-
- @Test
- public void verifyPserverRelatedToHasEdgeLabel () throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
- assertTrue(rawFormat.createRelationshipObject(pserver).get(0).getAsJsonObject().get("relationship-label").getAsString().equals("org.onap.relationships.inventory.LocatedIn"));
- }
-
- @Test
- public void verifyPserverRelatedToComplexLabel () throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
- assertTrue(rawFormat.createRelationshipObject(pserver).get(0).getAsJsonObject().get("node-type").getAsString().equals("complex"));
- }
-
- @Test
- public void verifyComplexRelatedToHasEdgeLabel () throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
- assertTrue(rawFormat.createRelationshipObject(complex).get(0).getAsJsonObject().get("relationship-label").getAsString().equals("org.onap.relationships.inventory.LocatedIn"));
- }
-
- @Test
- public void verifyComplexRelatedToPserverLabel () throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
- assertTrue(rawFormat.createRelationshipObject(complex).get(0).getAsJsonObject().get("node-type").getAsString().equals("pserver"));
- }
-
- public void createLoaderEngineSetup() throws AAIException {
-
- if (loader == null) {
- loader = loaderFactory.createLoaderForVersion(factoryType, version);
- //loader = LoaderFactory.createLoaderForVersion(factoryType, version);
- dbEngine = spy(new JanusGraphDBEngine(QueryStyle.TRAVERSAL, DBConnectionType.CACHED, loader));
- serializer = new DBSerializer(version, dbEngine, factoryType, "Junit");
- rawFormat = new RawFormat.Builder(loader, serializer, urlBuilder).build();
-
- TransactionalGraphEngine.Admin spyAdmin = spy(dbEngine.asAdmin());
-
- when(dbEngine.tx()).thenReturn(graph);
- when(dbEngine.asAdmin()).thenReturn(spyAdmin);
-
- when(spyAdmin.getReadOnlyTraversalSource())
- .thenReturn(graph.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance())));
- when(spyAdmin.getTraversalSource()).thenReturn(graph.traversal());
- }
- }
+ @Mock
+ private UrlBuilder urlBuilder;
+
+ private Graph graph;
+ private TransactionalGraphEngine dbEngine;
+ private Loader loader;
+ private RawFormat rawFormat;
+ private final ModelType factoryType = ModelType.MOXY;
+
+ @Autowired
+ private EdgeSerializer rules;
+
+ private SchemaVersion version;
+ private Vertex pserver;
+ private Vertex complex;
+
+ private DBSerializer serializer;
+
+ @Before
+ public void setUp() throws Exception {
+
+ version = schemaVersions.getDefaultVersion();
+
+ MockitoAnnotations.initMocks(this);
+
+ graph = TinkerGraph.open();
+
+ Vertex pserver1 =
+ graph.addVertex(T.label, "pserver", T.id, "2", "aai-node-type", "pserver", "hostname", "hostname-1");
+ Vertex complex1 = graph.addVertex(T.label, "complex", T.id, "3", "aai-node-type", "complex",
+ "physical-location-id", "physical-location-id-1", "country", "US");
+
+ GraphTraversalSource g = graph.traversal();
+ rules.addEdge(g, pserver1, complex1);
+
+ pserver = pserver1;
+ complex = complex1;
+
+ System.setProperty("AJSC_HOME", ".");
+ System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
+
+ createLoaderEngineSetup();
+ }
+
+ @Test
+ public void verifyPserverRelatedToHasEdgeLabel()
+ throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
+ assertTrue(rawFormat.createRelationshipObject(pserver).get(0).getAsJsonObject().get("relationship-label")
+ .getAsString().equals("org.onap.relationships.inventory.LocatedIn"));
+ }
+
+ @Test
+ public void verifyPserverRelatedToComplexLabel()
+ throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
+ assertTrue(rawFormat.createRelationshipObject(pserver).get(0).getAsJsonObject().get("node-type").getAsString()
+ .equals("complex"));
+ }
+
+ @Test
+ public void verifyComplexRelatedToHasEdgeLabel()
+ throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
+ assertTrue(rawFormat.createRelationshipObject(complex).get(0).getAsJsonObject().get("relationship-label")
+ .getAsString().equals("org.onap.relationships.inventory.LocatedIn"));
+ }
+
+ @Test
+ public void verifyComplexRelatedToPserverLabel()
+ throws AAIFormatVertexException, AAIException, AAIFormatQueryResultFormatNotSupported {
+ assertTrue(rawFormat.createRelationshipObject(complex).get(0).getAsJsonObject().get("node-type").getAsString()
+ .equals("pserver"));
+ }
+
+ public void createLoaderEngineSetup() throws AAIException {
+
+ if (loader == null) {
+ loader = loaderFactory.createLoaderForVersion(factoryType, version);
+ // loader = LoaderFactory.createLoaderForVersion(factoryType, version);
+ dbEngine = spy(new JanusGraphDBEngine(QueryStyle.TRAVERSAL, DBConnectionType.CACHED, loader));
+ serializer = new DBSerializer(version, dbEngine, factoryType, "Junit");
+ rawFormat = new RawFormat.Builder(loader, serializer, urlBuilder).build();
+
+ TransactionalGraphEngine.Admin spyAdmin = spy(dbEngine.asAdmin());
+
+ when(dbEngine.tx()).thenReturn(graph);
+ when(dbEngine.asAdmin()).thenReturn(spyAdmin);
+
+ when(spyAdmin.getReadOnlyTraversalSource())
+ .thenReturn(graph.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance())));
+ when(spyAdmin.getTraversalSource()).thenReturn(graph.traversal());
+ }
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/ResourceFormatTest.java b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/ResourceFormatTest.java
index d522ef5c..1a301b33 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/ResourceFormatTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/ResourceFormatTest.java
@@ -17,9 +17,20 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.serialization.queryformats;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
import com.google.gson.JsonObject;
+
+import java.util.Arrays;
+
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -43,122 +54,106 @@ import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexExcepti
import org.onap.aai.serialization.queryformats.utils.UrlBuilder;
import org.springframework.test.annotation.DirtiesContext;
-import javax.ws.rs.core.MultivaluedHashMap;
-import javax.ws.rs.core.MultivaluedMap;
-import java.util.Arrays;
-
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class ResourceFormatTest extends AAISetup {
- @Mock
- private UrlBuilder urlBuilder;
+ @Mock
+ private UrlBuilder urlBuilder;
- private Graph graph;
- private TransactionalGraphEngine dbEngine;
- private Loader loader;
- private DBSerializer serializer;
- private Resource resource;
- private Vertex vfModule;
- private Vertex unknown;
- private final ModelType factoryType = ModelType.MOXY;
+ private Graph graph;
+ private TransactionalGraphEngine dbEngine;
+ private Loader loader;
+ private DBSerializer serializer;
+ private Resource resource;
+ private Vertex vfModule;
+ private Vertex unknown;
+ private final ModelType factoryType = ModelType.MOXY;
- @Before
- public void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
+ MockitoAnnotations.initMocks(this);
- graph = TinkerGraph.open();
+ graph = TinkerGraph.open();
- vfModule = graph.addVertex(
- T.label, "vf-module",
- T.id, "5",
- "aai-node-type", "vf-module",
- "vf-module-id", "vf-module-id-val-68205",
- "vf-module-name", "example-vf-module-name-val-68205",
- "heat-stack-id", "example-heat-stack-id-val-68205",
- "orchestration-status", "example-orchestration-status-val-68205",
- "is-base-vf-module", "true",
- "resource-version", "1498166571906",
- "model-invariant-id", "fe8aac07-ce6c-4f9f-aa0d-b561c77da9e8",
- "model-invariant-id-local", "fe8aac07-ce6c-4f9f-aa0d-b561c77da9e8",
- "model-version-id", "0d23052d-8ffe-433e-a25d-da5da027bb7c",
- "model-version-id-local", "0d23052d-8ffe-433e-a25d-da5da027bb7c",
- "widget-model-id", "example-widget-model-id-val-68205",
- "widget-model-version", "example-widget--model-version-val-68205",
- "contrail-service-instance-fqdn", "example-contrail-service-instance-fqdn-val-68205"
- );
+ vfModule = graph.addVertex(T.label, "vf-module", T.id, "5", "aai-node-type", "vf-module", "vf-module-id",
+ "vf-module-id-val-68205", "vf-module-name", "example-vf-module-name-val-68205", "heat-stack-id",
+ "example-heat-stack-id-val-68205", "orchestration-status", "example-orchestration-status-val-68205",
+ "is-base-vf-module", "true", "resource-version", "1498166571906", "model-invariant-id",
+ "fe8aac07-ce6c-4f9f-aa0d-b561c77da9e8", "model-invariant-id-local",
+ "fe8aac07-ce6c-4f9f-aa0d-b561c77da9e8", "model-version-id", "0d23052d-8ffe-433e-a25d-da5da027bb7c",
+ "model-version-id-local", "0d23052d-8ffe-433e-a25d-da5da027bb7c", "widget-model-id",
+ "example-widget-model-id-val-68205", "widget-model-version", "example-widget--model-version-val-68205",
+ "contrail-service-instance-fqdn", "example-contrail-service-instance-fqdn-val-68205");
- unknown = graph.addVertex(T.label, "unknown", T.id, "1", "aai-node-type", "unknown", "vserver-id",
- "vserver-id-1", "vserver-name", "vserver-name-1");
- }
+ unknown = graph.addVertex(T.label, "unknown", T.id, "1", "aai-node-type", "unknown", "vserver-id",
+ "vserver-id-1", "vserver-name", "vserver-name-1");
+ }
- @Test
- public void testCreatePropertiesObjectReturnsProperProperties() throws AAIFormatVertexException, AAIException {
+ @Test
+ public void testCreatePropertiesObjectReturnsProperProperties() throws AAIFormatVertexException, AAIException {
- createLoaderEngineSetup();
- serializer = new DBSerializer(schemaVersions.getAppRootVersion(), dbEngine, factoryType, "Junit");
- resource = new Resource.Builder(loader, serializer, urlBuilder).build();
+ createLoaderEngineSetup();
+ serializer = new DBSerializer(schemaVersions.getAppRootVersion(), dbEngine, factoryType, "Junit");
+ resource = new Resource.Builder(loader, serializer, urlBuilder).build();
- assertNotNull(dbEngine.tx());
- assertNotNull(dbEngine.asAdmin());
+ assertNotNull(dbEngine.tx());
+ assertNotNull(dbEngine.asAdmin());
- JsonObject json = resource.getJsonFromVertex(vfModule).get();
+ JsonObject json = resource.getJsonFromVertex(vfModule).get();
- assertTrue(json.getAsJsonObject("vf-module").has("model-invariant-id"));
- assertTrue(json.getAsJsonObject("vf-module").has("model-version-id"));
+ assertTrue(json.getAsJsonObject("vf-module").has("model-invariant-id"));
+ assertTrue(json.getAsJsonObject("vf-module").has("model-version-id"));
- assertFalse(json.getAsJsonObject("vf-module").has("model-invariant-id-local"));
- assertFalse(json.getAsJsonObject("vf-module").has("model-version-id-local"));
+ assertFalse(json.getAsJsonObject("vf-module").has("model-invariant-id-local"));
+ assertFalse(json.getAsJsonObject("vf-module").has("model-version-id-local"));
- }
+ }
- @Test
- public void testUnknownVertex() throws AAIFormatVertexException, AAIException {
+ @Test
+ public void testUnknownVertex() throws AAIFormatVertexException, AAIException {
- createLoaderEngineSetup();
- serializer = new DBSerializer(schemaVersions.getAppRootVersion(), dbEngine, factoryType, "Junit");
- resource = new Resource.Builder(loader, serializer, urlBuilder).build();
+ createLoaderEngineSetup();
+ serializer = new DBSerializer(schemaVersions.getAppRootVersion(), dbEngine, factoryType, "Junit");
+ resource = new Resource.Builder(loader, serializer, urlBuilder).build();
- assertNotNull(dbEngine.tx());
- assertNotNull(dbEngine.asAdmin());
+ assertNotNull(dbEngine.tx());
+ assertNotNull(dbEngine.asAdmin());
- assertFalse(resource.getJsonFromVertex(unknown).isPresent());
+ assertFalse(resource.getJsonFromVertex(unknown).isPresent());
- }
+ }
- @Test
- public void testFormattingUnknownVertex() throws AAIFormatVertexException, AAIException {
+ @Test
+ public void testFormattingUnknownVertex() throws AAIFormatVertexException, AAIException {
- createLoaderEngineSetup();
- serializer = new DBSerializer(schemaVersions.getAppRootVersion(), dbEngine, factoryType, "Junit");
+ createLoaderEngineSetup();
+ serializer = new DBSerializer(schemaVersions.getAppRootVersion(), dbEngine, factoryType, "Junit");
- FormatFactory ff = new FormatFactory(loader, serializer,schemaVersions, basePath);
- MultivaluedMap mvm = new MultivaluedHashMap();
- mvm.add("depth","0");
- Formatter formatter = ff.get(Format.resource, mvm);
+ FormatFactory ff = new FormatFactory(loader, serializer, schemaVersions, basePath);
+ MultivaluedMap mvm = new MultivaluedHashMap();
+ mvm.add("depth", "0");
+ Formatter formatter = ff.get(Format.resource, mvm);
- JsonObject json = formatter.output(Arrays.asList(unknown,vfModule));
- System.out.println(json);
+ JsonObject json = formatter.output(Arrays.asList(unknown, vfModule));
+ System.out.println(json);
- }
+ }
- public void createLoaderEngineSetup(){
+ public void createLoaderEngineSetup() {
- if(loader == null){
- loader = loaderFactory.createLoaderForVersion(factoryType, schemaVersions.getAppRootVersion());
- dbEngine = spy(new JanusGraphDBEngine(QueryStyle.TRAVERSAL, DBConnectionType.CACHED, loader));
+ if (loader == null) {
+ loader = loaderFactory.createLoaderForVersion(factoryType, schemaVersions.getAppRootVersion());
+ dbEngine = spy(new JanusGraphDBEngine(QueryStyle.TRAVERSAL, DBConnectionType.CACHED, loader));
- TransactionalGraphEngine.Admin spyAdmin = spy(dbEngine.asAdmin());
+ TransactionalGraphEngine.Admin spyAdmin = spy(dbEngine.asAdmin());
- when(dbEngine.tx()).thenReturn(graph);
- when(dbEngine.asAdmin()).thenReturn(spyAdmin);
+ when(dbEngine.tx()).thenReturn(graph);
+ when(dbEngine.asAdmin()).thenReturn(spyAdmin);
- when(spyAdmin.getReadOnlyTraversalSource()).thenReturn(graph.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance())));
- when(spyAdmin.getTraversalSource()).thenReturn(graph.traversal());
- }
- }
+ when(spyAdmin.getReadOnlyTraversalSource())
+ .thenReturn(graph.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance())));
+ when(spyAdmin.getTraversalSource()).thenReturn(graph.traversal());
+ }
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/ResourceWithSoTTest.java b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/ResourceWithSoTTest.java
index ad28e697..75fe6ec6 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/ResourceWithSoTTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/ResourceWithSoTTest.java
@@ -17,9 +17,17 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.serialization.queryformats;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
import com.google.gson.JsonObject;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -42,12 +50,6 @@ import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexExcepti
import org.onap.aai.serialization.queryformats.utils.UrlBuilder;
import org.onap.aai.setup.SchemaVersion;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
public class ResourceWithSoTTest extends AAISetup {
@Mock
private UrlBuilder urlBuilder;
@@ -57,9 +59,9 @@ public class ResourceWithSoTTest extends AAISetup {
private Vertex patchVertex1;
private Vertex patchVertex2;
- private JsonObject jsonPutObj = new JsonObject() ;
- private JsonObject jsonPatchObj1 = new JsonObject() ;
- private JsonObject jsonPatchObj2 = new JsonObject() ;
+ private JsonObject jsonPutObj = new JsonObject();
+ private JsonObject jsonPatchObj1 = new JsonObject();
+ private JsonObject jsonPatchObj2 = new JsonObject();
private SchemaVersion version;
private ResourceWithSoT resourceWithSoT;
@@ -87,12 +89,8 @@ public class ResourceWithSoTTest extends AAISetup {
jsonPutObj.addProperty("last-mod-source-of-truth", "user_a");
jsonPutObj.addProperty("last-action-performed", "Created");
- putVertex = graph.addVertex(
- "aai-created-ts", timeNowInMs,
- "aai-last-mod-ts", timeNowInMs,
- "source-of-truth", "user_a",
- "last-mod-source-of-truth", "user_a"
- );
+ putVertex = graph.addVertex("aai-created-ts", timeNowInMs, "aai-last-mod-ts", timeNowInMs, "source-of-truth",
+ "user_a", "last-mod-source-of-truth", "user_a");
// PATCH / MODIFY with differing source of truths
jsonPatchObj1.addProperty("aai-created-ts", timeNowInMs);
@@ -101,12 +99,8 @@ public class ResourceWithSoTTest extends AAISetup {
jsonPatchObj1.addProperty("last-mod-source-of-truth", "user_b");
jsonPatchObj1.addProperty("last-action-performed", "Modified");
- patchVertex1 = graph.addVertex(
- "aai-created-ts", timeNowInMs,
- "aai-last-mod-ts", timeNowInMs,
- "source-of-truth", "user_a",
- "last-mod-source-of-truth", "user_b"
- );
+ patchVertex1 = graph.addVertex("aai-created-ts", timeNowInMs, "aai-last-mod-ts", timeNowInMs, "source-of-truth",
+ "user_a", "last-mod-source-of-truth", "user_b");
// PATCH / MODIFY with differing time stamps
jsonPatchObj2.addProperty("aai-created-ts", timeNowInMs);
@@ -115,12 +109,8 @@ public class ResourceWithSoTTest extends AAISetup {
jsonPatchObj2.addProperty("last-mod-source-of-truth", "user_a");
jsonPatchObj2.addProperty("last-action-performed", "Modified");
- patchVertex2 = graph.addVertex(
- "aai-created-ts", timeNowInMs,
- "aai-last-mod-ts", Long.toString(currentTimeMs + 1000),
- "source-of-truth", "user_a",
- "last-mod-source-of-truth", "user_a"
- );
+ patchVertex2 = graph.addVertex("aai-created-ts", timeNowInMs, "aai-last-mod-ts",
+ Long.toString(currentTimeMs + 1000), "source-of-truth", "user_a", "last-mod-source-of-truth", "user_a");
graph = TinkerGraph.open();
createLoaderEngineSetup();
@@ -148,7 +138,8 @@ public class ResourceWithSoTTest extends AAISetup {
JsonObject json1 = resourceWithSoT.getJsonFromVertex(patchVertex1).get();
assertEquals(jsonPatchObj1, json1);
- // Timestamps that have a large span in time difference will (likely) indicate that the transaction was not a create (thus, modify)
+ // Timestamps that have a large span in time difference will (likely) indicate that the transaction was not a
+ // create (thus, modify)
JsonObject json2 = resourceWithSoT.getJsonFromVertex(patchVertex2).get();
assertEquals(jsonPatchObj2, json2);
}
@@ -163,7 +154,7 @@ public class ResourceWithSoTTest extends AAISetup {
if (loader == null) {
loader = loaderFactory.createLoaderForVersion(factoryType, version);
- //loader = LoaderFactory.createLoaderForVersion(factoryType, version);
+ // loader = LoaderFactory.createLoaderForVersion(factoryType, version);
dbEngine = spy(new JanusGraphDBEngine(QueryStyle.TRAVERSAL, DBConnectionType.CACHED, loader));
serializer = new DBSerializer(version, dbEngine, factoryType, "Junit");
resourceWithSoT = new ResourceWithSoT.Builder(loader, serializer, urlBuilder).build();
@@ -174,7 +165,7 @@ public class ResourceWithSoTTest extends AAISetup {
when(dbEngine.asAdmin()).thenReturn(spyAdmin);
when(spyAdmin.getReadOnlyTraversalSource())
- .thenReturn(graph.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance())));
+ .thenReturn(graph.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance())));
when(spyAdmin.getTraversalSource()).thenReturn(graph.traversal());
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/SimpleFormatTest.java b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/SimpleFormatTest.java
index c347bc2d..ab899c01 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/SimpleFormatTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/SimpleFormatTest.java
@@ -17,9 +17,24 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.serialization.queryformats;
+import static org.junit.Assert.*;
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.*;
+
import com.google.gson.JsonObject;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -45,157 +60,138 @@ import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexExcepti
import org.onap.aai.serialization.queryformats.utils.UrlBuilder;
import org.springframework.test.annotation.DirtiesContext;
-import javax.ws.rs.core.MultivaluedHashMap;
-import javax.ws.rs.core.MultivaluedMap;
-import java.io.UnsupportedEncodingException;
-import java.util.Arrays;
-
-import static org.junit.Assert.*;
-import static org.mockito.Matchers.anyBoolean;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.*;
-
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
public class SimpleFormatTest extends AAISetup {
- @Mock
- private UrlBuilder urlBuilder;
+ @Mock
+ private UrlBuilder urlBuilder;
- private Graph graph;
- private TransactionalGraphEngine dbEngine;
- private Loader loader;
- private DBSerializer serializer;
- private RawFormat simpleFormat;
- private Vertex vfModule;
- private Vertex unknown;
- private final ModelType factoryType = ModelType.MOXY;
+ private Graph graph;
+ private TransactionalGraphEngine dbEngine;
+ private Loader loader;
+ private DBSerializer serializer;
+ private RawFormat simpleFormat;
+ private Vertex vfModule;
+ private Vertex unknown;
+ private final ModelType factoryType = ModelType.MOXY;
-
- @Before
- public void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
+ MockitoAnnotations.initMocks(this);
- graph = TinkerGraph.open();
+ graph = TinkerGraph.open();
- vfModule = graph.addVertex(
- T.label, "vf-module",
- T.id, "5",
- "aai-node-type", "vf-module",
- "vf-module-id", "vf-module-id-val-68205",
- "vf-module-name", "example-vf-module-name-val-68205",
- "heat-stack-id", "example-heat-stack-id-val-68205",
- "orchestration-status", "example-orchestration-status-val-68205",
- "is-base-vf-module", "true",
- "resource-version", "1498166571906",
- "model-invariant-id", "fe8aac07-ce6c-4f9f-aa0d-b561c77da9e8",
- "model-invariant-id-local", "fe8aac07-ce6c-4f9f-aa0d-b561c77da9e8",
- "model-version-id", "0d23052d-8ffe-433e-a25d-da5da027bb7c",
- "model-version-id-local", "0d23052d-8ffe-433e-a25d-da5da027bb7c",
- "widget-model-id", "example-widget-model-id-val-68205",
- "widget-model-version", "example-widget--model-version-val-68205",
- "contrail-service-instance-fqdn", "example-contrail-service-instance-fqdn-val-68205"
- );
+ vfModule = graph.addVertex(T.label, "vf-module", T.id, "5", "aai-node-type", "vf-module", "vf-module-id",
+ "vf-module-id-val-68205", "vf-module-name", "example-vf-module-name-val-68205", "heat-stack-id",
+ "example-heat-stack-id-val-68205", "orchestration-status", "example-orchestration-status-val-68205",
+ "is-base-vf-module", "true", "resource-version", "1498166571906", "model-invariant-id",
+ "fe8aac07-ce6c-4f9f-aa0d-b561c77da9e8", "model-invariant-id-local",
+ "fe8aac07-ce6c-4f9f-aa0d-b561c77da9e8", "model-version-id", "0d23052d-8ffe-433e-a25d-da5da027bb7c",
+ "model-version-id-local", "0d23052d-8ffe-433e-a25d-da5da027bb7c", "widget-model-id",
+ "example-widget-model-id-val-68205", "widget-model-version", "example-widget--model-version-val-68205",
+ "contrail-service-instance-fqdn", "example-contrail-service-instance-fqdn-val-68205");
- unknown = graph.addVertex(T.label, "unknown", T.id, "1", "aai-node-type", "unknown", "vserver-id",
- "vserver-id-1", "vserver-name", "vserver-name-1");
- }
+ unknown = graph.addVertex(T.label, "unknown", T.id, "1", "aai-node-type", "unknown", "vserver-id",
+ "vserver-id-1", "vserver-name", "vserver-name-1");
+ }
- @Test
- public void testCreatePropertiesObjectReturnsProperProperties() throws AAIFormatVertexException, AAIException {
+ @Test
+ public void testCreatePropertiesObjectReturnsProperProperties() throws AAIFormatVertexException, AAIException {
- createLoaderEngineSetup();
- serializer = new DBSerializer(schemaVersions.getRelatedLinkVersion(), dbEngine, factoryType, "Junit");
- simpleFormat = new RawFormat.Builder(loader, serializer, urlBuilder).nodesOnly(true).depth(0).modelDriven().build();
+ createLoaderEngineSetup();
+ serializer = new DBSerializer(schemaVersions.getRelatedLinkVersion(), dbEngine, factoryType, "Junit");
+ simpleFormat =
+ new RawFormat.Builder(loader, serializer, urlBuilder).nodesOnly(true).depth(0).modelDriven().build();
- assertNotNull(dbEngine.tx());
- assertNotNull(dbEngine.asAdmin());
+ assertNotNull(dbEngine.tx());
+ assertNotNull(dbEngine.asAdmin());
- JsonObject json = simpleFormat.createPropertiesObject(vfModule).get();
+ JsonObject json = simpleFormat.createPropertiesObject(vfModule).get();
- assertTrue(json.has("model-invariant-id"));
- assertTrue(json.has("model-version-id"));
+ assertTrue(json.has("model-invariant-id"));
+ assertTrue(json.has("model-version-id"));
- assertFalse(json.has("model-invariant-id-local"));
- assertFalse(json.has("model-version-id-local"));
+ assertFalse(json.has("model-invariant-id-local"));
+ assertFalse(json.has("model-version-id-local"));
- }
+ }
- @Test
- public void testUnknownVertex() throws AAIFormatVertexException, AAIException {
+ @Test
+ public void testUnknownVertex() throws AAIFormatVertexException, AAIException {
- createLoaderEngineSetup();
- serializer = new DBSerializer(schemaVersions.getRelatedLinkVersion(), dbEngine, factoryType, "Junit");
- simpleFormat = new RawFormat.Builder(loader, serializer, urlBuilder).nodesOnly(true).depth(0).modelDriven().build();
+ createLoaderEngineSetup();
+ serializer = new DBSerializer(schemaVersions.getRelatedLinkVersion(), dbEngine, factoryType, "Junit");
+ simpleFormat =
+ new RawFormat.Builder(loader, serializer, urlBuilder).nodesOnly(true).depth(0).modelDriven().build();
- assertNotNull(dbEngine.tx());
- assertNotNull(dbEngine.asAdmin());
+ assertNotNull(dbEngine.tx());
+ assertNotNull(dbEngine.asAdmin());
- assertFalse(simpleFormat.getJsonFromVertex(unknown).isPresent());
+ assertFalse(simpleFormat.getJsonFromVertex(unknown).isPresent());
- }
+ }
- @Test
- public void testFormattingUnknownVertex() throws AAIException {
+ @Test
+ public void testFormattingUnknownVertex() throws AAIException {
- createLoaderEngineSetup();
- serializer = new DBSerializer(schemaVersions.getRelatedLinkVersion(), dbEngine, factoryType, "Junit");
+ createLoaderEngineSetup();
+ serializer = new DBSerializer(schemaVersions.getRelatedLinkVersion(), dbEngine, factoryType, "Junit");
- FormatFactory ff = new FormatFactory(loader, serializer, schemaVersions, basePath);
- MultivaluedMap mvm = new MultivaluedHashMap();
- mvm.add("depth","0");
- Formatter formatter = ff.get(Format.simple, mvm);
+ FormatFactory ff = new FormatFactory(loader, serializer, schemaVersions, basePath);
+ MultivaluedMap mvm = new MultivaluedHashMap();
+ mvm.add("depth", "0");
+ Formatter formatter = ff.get(Format.simple, mvm);
- JsonObject json = formatter.output(Arrays.asList(unknown,vfModule));
-
+ JsonObject json = formatter.output(Arrays.asList(unknown, vfModule));
- }
+ }
- @Ignore
- @Test(expected = AAIFormatVertexException.class)
- public void testCreatePropertiesObjectThrowsExceptionIfSerializationFails() throws AAIFormatVertexException, AAIException, UnsupportedEncodingException {
+ @Ignore
+ @Test(expected = AAIFormatVertexException.class)
+ public void testCreatePropertiesObjectThrowsExceptionIfSerializationFails()
+ throws AAIFormatVertexException, AAIException, UnsupportedEncodingException {
- serializer = mock(DBSerializer.class);
- loader = mock(Loader.class);
+ serializer = mock(DBSerializer.class);
+ loader = mock(Loader.class);
- simpleFormat = new RawFormat.Builder(loader, serializer, urlBuilder).nodesOnly(true).depth(0).build();
+ simpleFormat = new RawFormat.Builder(loader, serializer, urlBuilder).nodesOnly(true).depth(0).build();
- when(serializer.dbToObject(anyObject(), anyObject(), anyInt(), anyBoolean(), anyString()))
- .thenThrow(new AAIException("Test Exception"));
+ when(serializer.dbToObject(anyObject(), anyObject(), anyInt(), anyBoolean(), anyString()))
+ .thenThrow(new AAIException("Test Exception"));
- simpleFormat.createPropertiesObject(vfModule);
- }
+ simpleFormat.createPropertiesObject(vfModule);
+ }
- @Ignore
- @Test(expected = AAIFormatVertexException.class)
- public void testCreatePropertiesObjectThrowsExceptionIfUnknownObject() throws AAIFormatVertexException, AAIException, UnsupportedEncodingException {
+ @Ignore
+ @Test(expected = AAIFormatVertexException.class)
+ public void testCreatePropertiesObjectThrowsExceptionIfUnknownObject()
+ throws AAIFormatVertexException, AAIException, UnsupportedEncodingException {
- loader = mock(Loader.class);
- serializer = mock(DBSerializer.class);
+ loader = mock(Loader.class);
+ serializer = mock(DBSerializer.class);
- simpleFormat = new RawFormat.Builder(loader, serializer, urlBuilder).nodesOnly(true).depth(0).build();
+ simpleFormat = new RawFormat.Builder(loader, serializer, urlBuilder).nodesOnly(true).depth(0).build();
- when(loader.introspectorFromName(anyString()))
- .thenThrow(new AAIUnknownObjectException("Test Exception"));
+ when(loader.introspectorFromName(anyString())).thenThrow(new AAIUnknownObjectException("Test Exception"));
- simpleFormat.createPropertiesObject(vfModule);
- }
+ simpleFormat.createPropertiesObject(vfModule);
+ }
- public void createLoaderEngineSetup(){
+ public void createLoaderEngineSetup() {
- if(loader == null){
- loader = loaderFactory.createLoaderForVersion(factoryType, schemaVersions.getRelatedLinkVersion());
- dbEngine = spy(new JanusGraphDBEngine(QueryStyle.TRAVERSAL, DBConnectionType.CACHED, loader));
+ if (loader == null) {
+ loader = loaderFactory.createLoaderForVersion(factoryType, schemaVersions.getRelatedLinkVersion());
+ dbEngine = spy(new JanusGraphDBEngine(QueryStyle.TRAVERSAL, DBConnectionType.CACHED, loader));
- TransactionalGraphEngine.Admin spyAdmin = spy(dbEngine.asAdmin());
+ TransactionalGraphEngine.Admin spyAdmin = spy(dbEngine.asAdmin());
- when(dbEngine.tx()).thenReturn(graph);
- when(dbEngine.asAdmin()).thenReturn(spyAdmin);
+ when(dbEngine.tx()).thenReturn(graph);
+ when(dbEngine.asAdmin()).thenReturn(spyAdmin);
- when(spyAdmin.getReadOnlyTraversalSource()).thenReturn(graph.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance())));
- when(spyAdmin.getTraversalSource()).thenReturn(graph.traversal());
- }
- }
+ when(spyAdmin.getReadOnlyTraversalSource())
+ .thenReturn(graph.traversal(GraphTraversalSource.build().with(ReadOnlyStrategy.instance())));
+ when(spyAdmin.getTraversalSource()).thenReturn(graph.traversal());
+ }
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/utils/QueryParamInjectorTest.java b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/utils/QueryParamInjectorTest.java
index 20f7868d..0b689d88 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/utils/QueryParamInjectorTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/utils/QueryParamInjectorTest.java
@@ -17,8 +17,14 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.serialization.queryformats.utils;
+import static org.junit.Assert.assertEquals;
+
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -28,31 +34,28 @@ import org.onap.aai.serialization.db.DBSerializer;
import org.onap.aai.serialization.queryformats.Resource;
import org.onap.aai.serialization.queryformats.Resource.Builder;
-import javax.ws.rs.core.MultivaluedHashMap;
-import javax.ws.rs.core.MultivaluedMap;
+public class QueryParamInjectorTest {
-import static org.junit.Assert.assertEquals;
+ @Mock
+ private Loader loader;
+ @Mock
+ private DBSerializer serializer;
+ @Mock
+ private UrlBuilder urlBuilder;
-public class QueryParamInjectorTest {
+ @Test
+ public void test() throws AAIException {
+ MockitoAnnotations.initMocks(this);
+ QueryParamInjector injector = QueryParamInjector.getInstance();
+
+ Builder b = new Builder(loader, serializer, urlBuilder);
+ MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
+ params.putSingle("nodesOnly", "true");
+ params.putSingle("depth", "10");
+ params.putSingle("invalid", "1000");
+ injector.injectParams(b, params);
-
- @Mock private Loader loader;
- @Mock private DBSerializer serializer;
- @Mock private UrlBuilder urlBuilder;
-
- @Test
- public void test() throws AAIException {
- MockitoAnnotations.initMocks(this);
- QueryParamInjector injector = QueryParamInjector.getInstance();
-
- Builder b = new Builder(loader, serializer, urlBuilder);
- MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
- params.putSingle("nodesOnly", "true");
- params.putSingle("depth", "10");
- params.putSingle("invalid", "1000");
- injector.injectParams(b, params);
-
- assertEquals("is nodes only", true, b.isNodesOnly());
- assertEquals("is depth 10", 10, b.getDepth());
- }
+ assertEquals("is nodes only", true, b.isNodesOnly());
+ assertEquals("is depth 10", 10, b.getDepth());
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/utils/UrlBuilderTest.java b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/utils/UrlBuilderTest.java
index 397999e2..08d29cd3 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/queryformats/utils/UrlBuilderTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/queryformats/utils/UrlBuilderTest.java
@@ -17,8 +17,17 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.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.Test;
@@ -30,70 +39,62 @@ import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexExcepti
import org.onap.aai.setup.SchemaVersion;
import org.onap.aai.util.AAIConstants;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.net.URISyntaxException;
+public class UrlBuilderTest extends AAISetup {
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.when;
+ @Mock
+ private DBSerializer serializer;
+ @Mock
+ private Vertex v;
-public class UrlBuilderTest extends AAISetup {
+ private static final String uri = "/test/uri";
+ private static final Object vId = new Long(123);
+ private static final String protocolAndHost = "http://localhost/aai/";
+
+ @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);
+ }
+
+ @Test
+ public void v11Pathed() throws AAIFormatVertexException {
+ SchemaVersion version = new SchemaVersion("v11");
+ UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost, schemaVersions, basePath);
+ String result = builder.pathed(v);
+
+ assertEquals("has no protocol and host", basePath + "/" + version + uri, result);
+
+ }
+
+ @Test
+ public void v11Id() {
+ SchemaVersion version = new SchemaVersion("v11");
+ UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost, schemaVersions, basePath);
+ String result = builder.id(v);
+
+ assertEquals("has no protocol and host", basePath + "/" + version + "/resources/id/" + vId, result);
+
+ }
+
+ @Test
+ public void beforeV11Pathed() throws AAIFormatVertexException {
+ SchemaVersion version = new SchemaVersion("v10");
+ UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost, schemaVersions, basePath);
+ String result = builder.pathed(v);
+
+ assertEquals("has protocol and host", protocolAndHost + version + uri, result);
+
+ }
+
+ @Test
+ public void beforeV11Id() {
+ SchemaVersion version = new SchemaVersion("v10");
+ UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost, schemaVersions, basePath);
+ String result = builder.id(v);
+
+ assertEquals("has protocol and host", protocolAndHost + version + "/resources/id/" + vId, result);
+
+ }
- @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/";
-
- @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);
- }
-
- @Test
- public void v11Pathed() throws AAIFormatVertexException {
- SchemaVersion version = new SchemaVersion("v11");
- UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost, schemaVersions, basePath);
- String result = builder.pathed(v);
-
- assertEquals("has no protocol and host", basePath + "/"+ version + uri, result);
-
- }
-
- @Test
- public void v11Id() {
- SchemaVersion version = new SchemaVersion("v11");
- UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost, schemaVersions, basePath);
- String result = builder.id(v);
-
- assertEquals("has no protocol and host", basePath + "/"+ version + "/resources/id/" + vId, result);
-
- }
-
- @Test
- public void beforeV11Pathed() throws AAIFormatVertexException {
- SchemaVersion version = new SchemaVersion("v10");
- UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost, schemaVersions, basePath);
- String result = builder.pathed(v);
-
- assertEquals("has protocol and host", protocolAndHost + version + uri, result);
-
- }
-
- @Test
- public void beforeV11Id() {
- SchemaVersion version = new SchemaVersion("v10");
- UrlBuilder builder = new UrlBuilder(version, serializer, protocolAndHost, schemaVersions, basePath);
- String result = builder.id(v);
-
- assertEquals("has protocol and host", protocolAndHost + version + "/resources/id/" + vId, result);
-
- }
-
}
diff --git a/aai-core/src/test/java/org/onap/aai/serialization/tinkerpop/TreeBackedVertexTest.java b/aai-core/src/test/java/org/onap/aai/serialization/tinkerpop/TreeBackedVertexTest.java
index 6d17674a..8eed7c64 100644
--- a/aai-core/src/test/java/org/onap/aai/serialization/tinkerpop/TreeBackedVertexTest.java
+++ b/aai-core/src/test/java/org/onap/aai/serialization/tinkerpop/TreeBackedVertexTest.java
@@ -17,8 +17,11 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.serialization.tinkerpop;
+import static org.junit.Assert.assertEquals;
+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
import org.apache.tinkerpop.gremlin.structure.*;
@@ -29,123 +32,124 @@ import org.junit.Test;
import org.onap.aai.edges.enums.EdgeProperty;
import org.onap.aai.serialization.engines.query.GraphTraversalQueryEngine;
-import static org.junit.Assert.assertEquals;
-
@Ignore
public class TreeBackedVertexTest {
- private Graph graph = TinkerGraph.open();
- private Object startKey = null;
- private Tree<Element> tree = null;
- private Tree<Element> treeDepth1 = null;
- private Tree<Element> treeDepth0NodeOnly = null;
-
- @Before
- public void configure() {
- GraphTraversalSource g = graph.traversal();
-
- startKey = g.addV(T.label, "vserver").as("v1").property("test", "hello")
- .addV(T.label, "vserver").as("v2")
- .addV(T.label, "interface").property("name", "interface 1").as("v10").addInE("hasChild", "v2").property(EdgeProperty.CONTAINS.toString(), true)
- .addV(T.label, "pserver").property("name", "pserver 1").as("v4").addOutE("runsOn", "v1").property(EdgeProperty.CONTAINS.toString(), false)
- .addV(T.label, "interface").property("name", "interface 2").as("v3").addInE("hasChild", "v1").property(EdgeProperty.CONTAINS.toString(), true)
- .addV(T.label, "address").property("name", "address 1").addInE("hasChild", "v3").property(EdgeProperty.CONTAINS.toString(), true)
- .addV(T.label, "address").property("name", "address 2").addInE("hasChild", "v3").property(EdgeProperty.CONTAINS.toString(), true)
- .addV(T.label, "complex").property("name", "complex 1").addInE("locatedIn", "v4").property(EdgeProperty.CONTAINS.toString(), false)
- .addV(T.label, "interface").property("name", "interface 3").addInE("hasChild", "v4").property(EdgeProperty.CONTAINS.toString(), true)
- .addV(T.label, "subnet").property("name", "subnet 1").as("v5").addInE("in", "v3").property(EdgeProperty.CONTAINS.toString(), false)
- .addV(T.label, "address").property("name", "address 3").as("v6").addInE("hasChild", "v5").property(EdgeProperty.CONTAINS.toString(), true)
- .select("v1").next();
-
- tree = new GraphTraversalQueryEngine(g).findSubGraph((Vertex)startKey);
- treeDepth1 = new GraphTraversalQueryEngine(g).findSubGraph((Vertex)startKey, 1, false);
- treeDepth0NodeOnly = new GraphTraversalQueryEngine(g).findSubGraph((Vertex)startKey, 0, true);
- }
-
- @Ignore
- @Test
- public void oneHopViaEdges() {
-
- //BulkSet set = (BulkSet)result;
- TreeBackedVertex v = new TreeBackedVertex((Vertex)tree.getObjectsAtDepth(1).iterator().next(), tree);
-
-
- assertEquals("locate child", v.edges(Direction.OUT).next().inVertex().property("name").orElse(""), "interface 2");
- assertEquals("locate cousin", v.edges(Direction.IN).next().outVertex().property("name").orElse(""), "pserver 1");
-
-
- }
-
- @Ignore
- @Test
- public void oneHopViaVertices() {
-
- //BulkSet set = (BulkSet)result;
- TreeBackedVertex v = new TreeBackedVertex((Vertex)tree.getObjectsAtDepth(1).iterator().next(), tree);
-
-
- assertEquals("locate child", "interface 2", v.vertices(Direction.OUT).next().property("name").orElse(""));
- assertEquals("locate cousin", "pserver 1", v.vertices(Direction.IN).next().property("name").orElse(""));
-
- }
-
- @Ignore
- @Test
- public void twoHopCousinViaVertices() {
-
- //BulkSet set = (BulkSet)result;
- TreeBackedVertex v = new TreeBackedVertex((Vertex)tree.getObjectsAtDepth(1).iterator().next(), tree);
-
-
- assertEquals("locate child", "subnet 1", v.vertices(Direction.OUT).next().vertices(Direction.OUT, "in").next().property("name").orElse(""));
-
- }
-
- @Test
- public void walkVerticesRestrictedDepth() {
-
- //BulkSet set = (BulkSet)result;
- TreeBackedVertex v = new TreeBackedVertex((Vertex)treeDepth1.getObjectsAtDepth(1).iterator().next(), treeDepth1);
-
-
- assertEquals("nothing returned", false, v.vertices(Direction.OUT).next()
- .vertices(Direction.OUT, "hasChild").hasNext());
-
- }
-
- @Test
- public void walkVertices() {
- TreeBackedVertex v = new TreeBackedVertex((Vertex)tree.getObjectsAtDepth(1).iterator().next(), tree);
- assertEquals("locate child", "address 2", v.vertices(Direction.OUT).next()
- .vertices(Direction.OUT, "hasChild").next().property("name").orElse(""));
- }
-
- @Test
- public void walkEdges() {
- TreeBackedVertex v = new TreeBackedVertex((Vertex)tree.getObjectsAtDepth(1).iterator().next(), tree);
-
- assertEquals("locate child", "address 2", v.edges(Direction.OUT).next().inVertex()
- .edges(Direction.OUT, "hasChild").next().inVertex().property("name").orElse(""));
- }
-
- @Test
- public void noEdgesFoudWithLabelVertices() {
- TreeBackedVertex v = new TreeBackedVertex((Vertex)tree.getObjectsAtDepth(1).iterator().next(), tree);
-
- assertEquals("missing hello label", false , v.vertices(Direction.OUT, "hello").hasNext());
- }
-
- @Test
- public void noEdgesFoudWithLabelEdges() {
- TreeBackedVertex v = new TreeBackedVertex((Vertex)tree.getObjectsAtDepth(1).iterator().next(), tree);
-
- assertEquals("missing hello label", false , v.edges(Direction.OUT, "hello").hasNext());
- }
-
- @Test
- public void depthZeroNodeOnly() {
- TreeBackedVertex v = new TreeBackedVertex((Vertex)treeDepth0NodeOnly.getObjectsAtDepth(1).iterator().next(), treeDepth0NodeOnly);
- assertEquals("no edges returned", false, v.edges(Direction.BOTH).hasNext());
- }
-
+ private Graph graph = TinkerGraph.open();
+ private Object startKey = null;
+ private Tree<Element> tree = null;
+ private Tree<Element> treeDepth1 = null;
+ private Tree<Element> treeDepth0NodeOnly = null;
+
+ @Before
+ public void configure() {
+ GraphTraversalSource g = graph.traversal();
+
+ startKey = g.addV(T.label, "vserver").as("v1").property("test", "hello").addV(T.label, "vserver").as("v2")
+ .addV(T.label, "interface").property("name", "interface 1").as("v10").addInE("hasChild", "v2")
+ .property(EdgeProperty.CONTAINS.toString(), true).addV(T.label, "pserver").property("name", "pserver 1")
+ .as("v4").addOutE("runsOn", "v1").property(EdgeProperty.CONTAINS.toString(), false)
+ .addV(T.label, "interface").property("name", "interface 2").as("v3").addInE("hasChild", "v1")
+ .property(EdgeProperty.CONTAINS.toString(), true).addV(T.label, "address").property("name", "address 1")
+ .addInE("hasChild", "v3").property(EdgeProperty.CONTAINS.toString(), true).addV(T.label, "address")
+ .property("name", "address 2").addInE("hasChild", "v3").property(EdgeProperty.CONTAINS.toString(), true)
+ .addV(T.label, "complex").property("name", "complex 1").addInE("locatedIn", "v4")
+ .property(EdgeProperty.CONTAINS.toString(), false).addV(T.label, "interface")
+ .property("name", "interface 3").addInE("hasChild", "v4")
+ .property(EdgeProperty.CONTAINS.toString(), true).addV(T.label, "subnet").property("name", "subnet 1")
+ .as("v5").addInE("in", "v3").property(EdgeProperty.CONTAINS.toString(), false).addV(T.label, "address")
+ .property("name", "address 3").as("v6").addInE("hasChild", "v5")
+ .property(EdgeProperty.CONTAINS.toString(), true).select("v1").next();
+
+ tree = new GraphTraversalQueryEngine(g).findSubGraph((Vertex) startKey);
+ treeDepth1 = new GraphTraversalQueryEngine(g).findSubGraph((Vertex) startKey, 1, false);
+ treeDepth0NodeOnly = new GraphTraversalQueryEngine(g).findSubGraph((Vertex) startKey, 0, true);
+ }
+
+ @Ignore
+ @Test
+ public void oneHopViaEdges() {
+
+ // BulkSet set = (BulkSet)result;
+ TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
+
+ assertEquals("locate child", v.edges(Direction.OUT).next().inVertex().property("name").orElse(""),
+ "interface 2");
+ assertEquals("locate cousin", v.edges(Direction.IN).next().outVertex().property("name").orElse(""),
+ "pserver 1");
+
+ }
+
+ @Ignore
+ @Test
+ public void oneHopViaVertices() {
+
+ // BulkSet set = (BulkSet)result;
+ TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
+
+ assertEquals("locate child", "interface 2", v.vertices(Direction.OUT).next().property("name").orElse(""));
+ assertEquals("locate cousin", "pserver 1", v.vertices(Direction.IN).next().property("name").orElse(""));
+
+ }
+
+ @Ignore
+ @Test
+ public void twoHopCousinViaVertices() {
+
+ // BulkSet set = (BulkSet)result;
+ TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
+
+ assertEquals("locate child", "subnet 1",
+ v.vertices(Direction.OUT).next().vertices(Direction.OUT, "in").next().property("name").orElse(""));
+
+ }
+
+ @Test
+ public void walkVerticesRestrictedDepth() {
+
+ // BulkSet set = (BulkSet)result;
+ TreeBackedVertex v =
+ new TreeBackedVertex((Vertex) treeDepth1.getObjectsAtDepth(1).iterator().next(), treeDepth1);
+
+ assertEquals("nothing returned", false,
+ v.vertices(Direction.OUT).next().vertices(Direction.OUT, "hasChild").hasNext());
+
+ }
+
+ @Test
+ public void walkVertices() {
+ TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
+ assertEquals("locate child", "address 2", v.vertices(Direction.OUT).next().vertices(Direction.OUT, "hasChild")
+ .next().property("name").orElse(""));
+ }
+
+ @Test
+ public void walkEdges() {
+ TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
+
+ assertEquals("locate child", "address 2", v.edges(Direction.OUT).next().inVertex()
+ .edges(Direction.OUT, "hasChild").next().inVertex().property("name").orElse(""));
+ }
+
+ @Test
+ public void noEdgesFoudWithLabelVertices() {
+ TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
+
+ assertEquals("missing hello label", false, v.vertices(Direction.OUT, "hello").hasNext());
+ }
+
+ @Test
+ public void noEdgesFoudWithLabelEdges() {
+ TreeBackedVertex v = new TreeBackedVertex((Vertex) tree.getObjectsAtDepth(1).iterator().next(), tree);
+
+ assertEquals("missing hello label", false, v.edges(Direction.OUT, "hello").hasNext());
+ }
+
+ @Test
+ public void depthZeroNodeOnly() {
+ TreeBackedVertex v = new TreeBackedVertex((Vertex) treeDepth0NodeOnly.getObjectsAtDepth(1).iterator().next(),
+ treeDepth0NodeOnly);
+ assertEquals("no edges returned", false, v.edges(Direction.BOTH).hasNext());
+ }
+
}
diff --git a/aai-core/src/test/java/org/onap/aai/testutils/TestUtilConfigTranslatorforBusiness.java b/aai-core/src/test/java/org/onap/aai/testutils/TestUtilConfigTranslatorforBusiness.java
index 6dab1743..279e0967 100644
--- a/aai-core/src/test/java/org/onap/aai/testutils/TestUtilConfigTranslatorforBusiness.java
+++ b/aai-core/src/test/java/org/onap/aai/testutils/TestUtilConfigTranslatorforBusiness.java
@@ -27,48 +27,48 @@ import java.util.Map;
import java.util.TreeMap;
import org.onap.aai.setup.ConfigTranslator;
+import org.onap.aai.setup.SchemaConfigVersions;
import org.onap.aai.setup.SchemaLocationsBean;
import org.onap.aai.setup.SchemaVersion;
-import org.onap.aai.setup.SchemaConfigVersions;
public class TestUtilConfigTranslatorforBusiness extends ConfigTranslator {
-
- public TestUtilConfigTranslatorforBusiness(SchemaLocationsBean bean, SchemaConfigVersions schemaVersions) {
- super(bean, schemaVersions);
- }
- @Override
- public Map<SchemaVersion, List<String>> getNodeFiles() {
+ public TestUtilConfigTranslatorforBusiness(SchemaLocationsBean bean, SchemaConfigVersions schemaVersions) {
+ super(bean, schemaVersions);
+ }
+
+ @Override
+ public Map<SchemaVersion, List<String>> getNodeFiles() {
+
+ List<String> files11 = new ArrayList<>();
+ files11.add("src/test/resources/oxm/business_oxm_v11.xml");
+
+ List<String> files13 = new ArrayList<>();
+ files13.add("src/test/resources/oxm/business_oxm_v13.xml");
+ files13.add("src/test/resources/oxm/common_oxm_v13.xml");
+ files13.add("src/test/resources/oxm/serviceDesign_oxm_v13.xml");
+ files13.add("src/test/resources/oxm/network_oxm_v13.xml");
+
+ Map<SchemaVersion, List<String>> input = new TreeMap<>();
+ input.put(new SchemaVersion("v11"), files11);
+ input.put(schemaVersions.getDefaultVersion(), files13);
+ return input;
+ }
+
+ @Override
+ public Map<SchemaVersion, List<String>> getEdgeFiles() {
+ List<String> files = new ArrayList<>();
+ files.add("src/test/resources/dbedgerules/DbEdgeBusinessRules_test.json");
+ Map<SchemaVersion, List<String>> input = new TreeMap<>();
+ input.put(schemaVersions.getDefaultVersion(), files);
- List<String> files11 = new ArrayList<>();
- files11.add("src/test/resources/oxm/business_oxm_v11.xml");
-
- List<String> files13 = new ArrayList<>();
- files13.add("src/test/resources/oxm/business_oxm_v13.xml");
- files13.add("src/test/resources/oxm/common_oxm_v13.xml");
- files13.add("src/test/resources/oxm/serviceDesign_oxm_v13.xml");
- files13.add("src/test/resources/oxm/network_oxm_v13.xml");
-
- Map<SchemaVersion, List<String>> input = new TreeMap<>();
- input.put(new SchemaVersion("v11"), files11);
- input.put(schemaVersions.getDefaultVersion(), files13);
- return input;
- }
+ List<String> files2 = new ArrayList<>();
+ files2.add("src/test/resources/dbedgerules/test.json");
- @Override
- public Map<SchemaVersion, List<String>> getEdgeFiles() {
- List<String> files = new ArrayList<>();
- files.add("src/test/resources/dbedgerules/DbEdgeBusinessRules_test.json");
- Map<SchemaVersion, List<String>> input = new TreeMap<>();
- input.put(schemaVersions.getDefaultVersion(), files);
-
- List<String> files2 = new ArrayList<>();
- files2.add("src/test/resources/dbedgerules/test.json");
+ List<String> files3 = new ArrayList<>();
+ files3.add("src/test/resources/dbedgerules/DbEdgeBusinessRules_test.json");
+ input.put(new SchemaVersion("v11"), files3);
- List<String> files3 = new ArrayList<>();
- files3.add("src/test/resources/dbedgerules/DbEdgeBusinessRules_test.json");
- input.put(new SchemaVersion("v11"), files3);
-
- return input;
- }
+ return input;
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/testutils/TestUtilConfigTranslatorforDataLink.java b/aai-core/src/test/java/org/onap/aai/testutils/TestUtilConfigTranslatorforDataLink.java
index d82c9d80..e5652fe1 100644
--- a/aai-core/src/test/java/org/onap/aai/testutils/TestUtilConfigTranslatorforDataLink.java
+++ b/aai-core/src/test/java/org/onap/aai/testutils/TestUtilConfigTranslatorforDataLink.java
@@ -20,37 +20,37 @@
package org.onap.aai.testutils;
+import java.util.*;
+
import org.onap.aai.setup.ConfigTranslator;
+import org.onap.aai.setup.SchemaConfigVersions;
import org.onap.aai.setup.SchemaLocationsBean;
import org.onap.aai.setup.SchemaVersion;
-import org.onap.aai.setup.SchemaConfigVersions;
-
-import java.util.*;
public class TestUtilConfigTranslatorforDataLink extends ConfigTranslator {
- public TestUtilConfigTranslatorforDataLink(SchemaLocationsBean bean, SchemaConfigVersions schemaVersions) {
- super(bean, schemaVersions);
- }
-
- @Override
- public Map<SchemaVersion, List<String>> getNodeFiles() {
-
- Map<SchemaVersion, List<String>> input = new TreeMap<>();
- input.put(new SchemaVersion("v1"), Arrays.asList("src/test/resources/oxm/dbalias_oxm_one.xml"));
- input.put(new SchemaVersion("v2"), Arrays.asList("src/test/resources/oxm/dbalias_oxm_two.xml"));
- input.put(new SchemaVersion("v3"), Arrays.asList("src/test/resources/oxm/dbalias_oxm_three.xml"));
- input.put(new SchemaVersion("v4"), Arrays.asList("src/test/resources/oxm/dbalias_oxm_four.xml"));
- return input;
- }
-
- @Override
- public Map<SchemaVersion, List<String>> getEdgeFiles() {
- Map<SchemaVersion, List<String>> input = new TreeMap<>();
- input.put(new SchemaVersion("v1"), Arrays.asList("src/test/resources/dbedgerules/DbEdgerules_one.json"));
- input.put(new SchemaVersion("v2"), Arrays.asList("src/test/resources/dbedgerules/DbEdgerules_two.json"));
- input.put(new SchemaVersion("v3"), Arrays.asList("src/test/resources/dbedgerules/DbEdgerules_three.json"));
- input.put(new SchemaVersion("v4"), Arrays.asList("src/test/resources/dbedgerules/DbEdgerules_four.json"));
- return input;
- }
+ public TestUtilConfigTranslatorforDataLink(SchemaLocationsBean bean, SchemaConfigVersions schemaVersions) {
+ super(bean, schemaVersions);
+ }
+
+ @Override
+ public Map<SchemaVersion, List<String>> getNodeFiles() {
+
+ Map<SchemaVersion, List<String>> input = new TreeMap<>();
+ input.put(new SchemaVersion("v1"), Arrays.asList("src/test/resources/oxm/dbalias_oxm_one.xml"));
+ input.put(new SchemaVersion("v2"), Arrays.asList("src/test/resources/oxm/dbalias_oxm_two.xml"));
+ input.put(new SchemaVersion("v3"), Arrays.asList("src/test/resources/oxm/dbalias_oxm_three.xml"));
+ input.put(new SchemaVersion("v4"), Arrays.asList("src/test/resources/oxm/dbalias_oxm_four.xml"));
+ return input;
+ }
+
+ @Override
+ public Map<SchemaVersion, List<String>> getEdgeFiles() {
+ Map<SchemaVersion, List<String>> input = new TreeMap<>();
+ input.put(new SchemaVersion("v1"), Arrays.asList("src/test/resources/dbedgerules/DbEdgerules_one.json"));
+ input.put(new SchemaVersion("v2"), Arrays.asList("src/test/resources/dbedgerules/DbEdgerules_two.json"));
+ input.put(new SchemaVersion("v3"), Arrays.asList("src/test/resources/dbedgerules/DbEdgerules_three.json"));
+ input.put(new SchemaVersion("v4"), Arrays.asList("src/test/resources/dbedgerules/DbEdgerules_four.json"));
+ return input;
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/testutils/TestUtilConfigTranslatorforEdges.java b/aai-core/src/test/java/org/onap/aai/testutils/TestUtilConfigTranslatorforEdges.java
index ca6c6740..d47a775c 100644
--- a/aai-core/src/test/java/org/onap/aai/testutils/TestUtilConfigTranslatorforEdges.java
+++ b/aai-core/src/test/java/org/onap/aai/testutils/TestUtilConfigTranslatorforEdges.java
@@ -27,48 +27,48 @@ import java.util.Map;
import java.util.TreeMap;
import org.onap.aai.setup.ConfigTranslator;
+import org.onap.aai.setup.SchemaConfigVersions;
import org.onap.aai.setup.SchemaLocationsBean;
import org.onap.aai.setup.SchemaVersion;
-import org.onap.aai.setup.SchemaConfigVersions;
public class TestUtilConfigTranslatorforEdges extends ConfigTranslator {
-
- public TestUtilConfigTranslatorforEdges(SchemaLocationsBean bean, SchemaConfigVersions schemaVersions) {
- super(bean, schemaVersions);
- }
- @Override
- public Map<SchemaVersion, List<String>> getNodeFiles() {
- List<String> files11 = new ArrayList<>();
- files11.add("src/test/resources/oxm/business_oxm_v11.xml");
-
- List<String> files13 = new ArrayList<>();
- files13.add("src/test/resources/oxm/business_oxm_v13.xml");
- files13.add("src/test/resources/oxm/common_oxm_v13.xml");
- files13.add("src/test/resources/oxm/serviceDesign_oxm_v13.xml");
- files13.add("src/test/resources/oxm/network_oxm_v13.xml");
-
- Map<SchemaVersion, List<String>> input = new TreeMap<>();
- input.put(new SchemaVersion("v11"), files11);
- input.put(new SchemaVersion("v13"), files13);
- return input;
- }
+ public TestUtilConfigTranslatorforEdges(SchemaLocationsBean bean, SchemaConfigVersions schemaVersions) {
+ super(bean, schemaVersions);
+ }
+
+ @Override
+ public Map<SchemaVersion, List<String>> getNodeFiles() {
+ List<String> files11 = new ArrayList<>();
+ files11.add("src/test/resources/oxm/business_oxm_v11.xml");
+
+ List<String> files13 = new ArrayList<>();
+ files13.add("src/test/resources/oxm/business_oxm_v13.xml");
+ files13.add("src/test/resources/oxm/common_oxm_v13.xml");
+ files13.add("src/test/resources/oxm/serviceDesign_oxm_v13.xml");
+ files13.add("src/test/resources/oxm/network_oxm_v13.xml");
+
+ Map<SchemaVersion, List<String>> input = new TreeMap<>();
+ input.put(new SchemaVersion("v11"), files11);
+ input.put(new SchemaVersion("v13"), files13);
+ return input;
+ }
+
+ @Override
+ public Map<SchemaVersion, List<String>> getEdgeFiles() {
+ List<String> files = new ArrayList<>();
+ files.add("src/test/resources/dbedgerules/test.json");
+ files.add("src/test/resources/dbedgerules/test2.json");
+ Map<SchemaVersion, List<String>> input = new TreeMap<>();
+ input.put(schemaVersions.getDefaultVersion(), files);
+
+ List<String> files2 = new ArrayList<>();
+ files2.add("src/test/resources/dbedgerules/DbEdgeBusinessRules_test.json");
+ input.put(new SchemaVersion("v10"), files2);
+ List<String> files3 = new ArrayList<>();
+ files3.add("src/test/resources/dbedgerules/EdgeDescriptionRules_test.json");
+ input.put(new SchemaVersion("v11"), files3);
- @Override
- public Map<SchemaVersion, List<String>> getEdgeFiles() {
- List<String> files = new ArrayList<>();
- files.add("src/test/resources/dbedgerules/test.json");
- files.add("src/test/resources/dbedgerules/test2.json");
- Map<SchemaVersion, List<String>> input = new TreeMap<>();
- input.put(schemaVersions.getDefaultVersion(), files);
-
- List<String> files2 = new ArrayList<>();
- files2.add("src/test/resources/dbedgerules/DbEdgeBusinessRules_test.json");
- input.put(new SchemaVersion("v10"), files2);
- List<String> files3 = new ArrayList<>();
- files3.add("src/test/resources/dbedgerules/EdgeDescriptionRules_test.json");
- input.put(new SchemaVersion("v11"), files3);
-
- return input;
- }
+ return input;
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/util/AAIConfigCommandLinePropGetterTest.java b/aai-core/src/test/java/org/onap/aai/util/AAIConfigCommandLinePropGetterTest.java
index 316cc150..c64c9a93 100644
--- a/aai-core/src/test/java/org/onap/aai/util/AAIConfigCommandLinePropGetterTest.java
+++ b/aai-core/src/test/java/org/onap/aai/util/AAIConfigCommandLinePropGetterTest.java
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.util;
import static org.junit.Assert.assertEquals;
@@ -30,74 +31,73 @@ import org.onap.aai.AAISetup;
public class AAIConfigCommandLinePropGetterTest extends AAISetup {
- private SecurityManager m;
- private TestSecurityManager sm;
+ private SecurityManager m;
+ private TestSecurityManager sm;
+
+ @Before
+ public void setUp() {
+ m = System.getSecurityManager();
+ sm = new TestSecurityManager();
+ System.setSecurityManager(sm);
+ }
+
+ @After
+ public void tearDown() {
+ System.setSecurityManager(m);
+ }
- @Before
- public void setUp()
- {
- m = System.getSecurityManager();
- sm = new TestSecurityManager();
- System.setSecurityManager(sm);
- }
+ @Test
+ public void testMainNoArgs() {
+ try {
+ AAIConfigCommandLinePropGetter.main(new String[] {});
+ } catch (SecurityException se) {
+ // assert main method ends with System.exit(0)
+ assertEquals("0", se.getMessage());
+ }
+ }
- @After
- public void tearDown()
- {
- System.setSecurityManager(m);
- }
+ @Test
+ public void testMainReadProp() {
+ try {
+ AAIConfigCommandLinePropGetter.main(new String[] {"aai.primary.filetransfer.serverlist"});
+ } catch (SecurityException se) {
+ // assert main method ends with System.exit(0)
+ assertEquals("0", se.getMessage());
+ }
+ }
- @Test
- public void testMainNoArgs() {
- try {
- AAIConfigCommandLinePropGetter.main(new String[] {});
- } catch (SecurityException se) {
- // assert main method ends with System.exit(0)
- assertEquals("0", se.getMessage());
- }
- }
-
- @Test
- public void testMainReadProp() {
- try {
- AAIConfigCommandLinePropGetter.main(new String[] {"aai.primary.filetransfer.serverlist"});
- } catch (SecurityException se) {
- // assert main method ends with System.exit(0)
- assertEquals("0", se.getMessage());
- }
- }
-
- @Test
- public void testMainOneArg() {
- try {
- AAIConfigCommandLinePropGetter.main(new String[] {"one"});
- } catch (SecurityException se) {
- // assert main method ends with System.exit(0)
- assertEquals("0", se.getMessage());
- }
- }
-
- @Test
- public void testMainMoreThanOneArg() {
- try {
- AAIConfigCommandLinePropGetter.main(new String[] {"one", "two"});
- } catch (SecurityException se) {
- // assert main method ends with System.exit(0)
- assertEquals("0", se.getMessage());
- }
- }
+ @Test
+ public void testMainOneArg() {
+ try {
+ AAIConfigCommandLinePropGetter.main(new String[] {"one"});
+ } catch (SecurityException se) {
+ // assert main method ends with System.exit(0)
+ assertEquals("0", se.getMessage());
+ }
+ }
+
+ @Test
+ public void testMainMoreThanOneArg() {
+ try {
+ AAIConfigCommandLinePropGetter.main(new String[] {"one", "two"});
+ } catch (SecurityException se) {
+ // assert main method ends with System.exit(0)
+ assertEquals("0", se.getMessage());
+ }
+ }
}
+
class TestSecurityManager extends SecurityManager {
- @Override
- public void checkPermission(Permission permission) {
- if ("exitVM".equals(permission.getName()))
- {
- throw new SecurityException("System.exit attempted and blocked.");
- }
- }
- @Override
- public void checkExit(int status) {
- throw new SecurityException(Integer.toString(status));
- }
+ @Override
+ public void checkPermission(Permission permission) {
+ if ("exitVM".equals(permission.getName())) {
+ throw new SecurityException("System.exit attempted and blocked.");
+ }
+ }
+
+ @Override
+ public void checkExit(int status) {
+ throw new SecurityException(Integer.toString(status));
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/util/AAIConfigTest.java b/aai-core/src/test/java/org/onap/aai/util/AAIConfigTest.java
index 51acdb74..69a8b89c 100644
--- a/aai-core/src/test/java/org/onap/aai/util/AAIConfigTest.java
+++ b/aai-core/src/test/java/org/onap/aai/util/AAIConfigTest.java
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.util;
import static org.junit.Assert.assertEquals;
@@ -39,92 +40,92 @@ import org.onap.aai.exceptions.AAIException;
public class AAIConfigTest extends AAISetup {
- @BeforeClass
- public static void setUp() throws AAIException {
- AAIConfig.init();
- }
-
- @Test
- public void testGetConfigFile() {
- String res = AAIConfig.getConfigFile();
- assertNotNull(res);
- assertTrue(res.endsWith("aaiconfig.properties"));
- }
-
- @Test
- public void testGetStringString() {
- String res = AAIConfig.get("aai.notificationEvent.default.sourceName", "somerandomvalue");
- assertNotNull(res);
- assertEquals("aai", res);
- }
-
- @Test
- public void testGetStringStringReturnDefaultvalue() {
- String res = AAIConfig.get("key", "result");
- assertNotNull(res);
- assertEquals("result", res);
- }
-
- @Test(expected = AAIException.class)
- public void testGetStringInvalidKey() throws AAIException {
- AAIConfig.get("key");
- }
-
- @Test(expected = AAIException.class)
- public void testGetStringEmptyResponse() throws AAIException {
- AAIConfig.get("aai.response.null");
- }
-
- @Test
- public void testGetStringReloadConfig() throws AAIException {
- String res = AAIConfig.get("aai.config.nodename");
- assertNotNull(res);
- assertEquals(AAIConfig.getNodeName(), res);
- }
-
- @Test
- public void testGetStringPassword() throws AAIException {
- String res = AAIConfig.get("aai.example.passwd");
- assertNotNull(res);
- assertEquals("changeit", res);
- }
-
- @Test(expected=NumberFormatException.class)
- public void testGetIntInvalidInput() throws AAIException {
- AAIConfig.getInt("aai.example.string");
- }
-
- @Test
- public void testGetInt() throws AAIException {
- int res = AAIConfig.getInt("aai.example.int");
- assertNotNull(res);
- assertEquals(7748, res);
- }
-
- @Test
- public void testGetNodeName() throws UnknownHostException {
- InetAddress ip = InetAddress.getLocalHost();
- String res = AAIConfig.getNodeName();
- assertNotNull(res);
- assertEquals(ip.getHostName(), res);
- }
-
- @Test
- public void testIsEmpty() {
- boolean res = AAIConfig.isEmpty("hllo world");
- assertFalse(res);
- }
-
- @Test
- public void testIsEmptyEmpty() {
- boolean res = AAIConfig.isEmpty("");
- assertTrue(res);
- }
-
- @Test
- public void testIsEmptyNull() {
- boolean res = AAIConfig.isEmpty(null);
- assertTrue(res);
- }
+ @BeforeClass
+ public static void setUp() throws AAIException {
+ AAIConfig.init();
+ }
+
+ @Test
+ public void testGetConfigFile() {
+ String res = AAIConfig.getConfigFile();
+ assertNotNull(res);
+ assertTrue(res.endsWith("aaiconfig.properties"));
+ }
+
+ @Test
+ public void testGetStringString() {
+ String res = AAIConfig.get("aai.notificationEvent.default.sourceName", "somerandomvalue");
+ assertNotNull(res);
+ assertEquals("aai", res);
+ }
+
+ @Test
+ public void testGetStringStringReturnDefaultvalue() {
+ String res = AAIConfig.get("key", "result");
+ assertNotNull(res);
+ assertEquals("result", res);
+ }
+
+ @Test(expected = AAIException.class)
+ public void testGetStringInvalidKey() throws AAIException {
+ AAIConfig.get("key");
+ }
+
+ @Test(expected = AAIException.class)
+ public void testGetStringEmptyResponse() throws AAIException {
+ AAIConfig.get("aai.response.null");
+ }
+
+ @Test
+ public void testGetStringReloadConfig() throws AAIException {
+ String res = AAIConfig.get("aai.config.nodename");
+ assertNotNull(res);
+ assertEquals(AAIConfig.getNodeName(), res);
+ }
+
+ @Test
+ public void testGetStringPassword() throws AAIException {
+ String res = AAIConfig.get("aai.example.passwd");
+ assertNotNull(res);
+ assertEquals("changeit", res);
+ }
+
+ @Test(expected = NumberFormatException.class)
+ public void testGetIntInvalidInput() throws AAIException {
+ AAIConfig.getInt("aai.example.string");
+ }
+
+ @Test
+ public void testGetInt() throws AAIException {
+ int res = AAIConfig.getInt("aai.example.int");
+ assertNotNull(res);
+ assertEquals(7748, res);
+ }
+
+ @Test
+ public void testGetNodeName() throws UnknownHostException {
+ InetAddress ip = InetAddress.getLocalHost();
+ String res = AAIConfig.getNodeName();
+ assertNotNull(res);
+ assertEquals(ip.getHostName(), res);
+ }
+
+ @Test
+ public void testIsEmpty() {
+ boolean res = AAIConfig.isEmpty("hllo world");
+ assertFalse(res);
+ }
+
+ @Test
+ public void testIsEmptyEmpty() {
+ boolean res = AAIConfig.isEmpty("");
+ assertTrue(res);
+ }
+
+ @Test
+ public void testIsEmptyNull() {
+ boolean res = AAIConfig.isEmpty(null);
+ assertTrue(res);
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/util/AAIUtilsTest.java b/aai-core/src/test/java/org/onap/aai/util/AAIUtilsTest.java
index b7f71d2b..e7132b58 100644
--- a/aai-core/src/test/java/org/onap/aai/util/AAIUtilsTest.java
+++ b/aai-core/src/test/java/org/onap/aai/util/AAIUtilsTest.java
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.util;
import static org.junit.Assert.assertEquals;
@@ -38,51 +39,52 @@ import org.junit.Test;
public class AAIUtilsTest {
- @Test
- public void testNullCheckWithNull() {
- List<String> newList = null;
- Iterable<String> res = AAIUtils.nullCheck(newList);
- assertNotNull("nullCheck() should return empty list", res);
- assertEquals(Collections.<String>emptyList(), res);
- }
+ @Test
+ public void testNullCheckWithNull() {
+ List<String> newList = null;
+ Iterable<String> res = AAIUtils.nullCheck(newList);
+ assertNotNull("nullCheck() should return empty list", res);
+ assertEquals(Collections.<String>emptyList(), res);
+ }
- @Test
- public void testNullCheckWithList() {
- List<String> newList = new ArrayList<String>();
- newList.add("testString");
+ @Test
+ public void testNullCheckWithList() {
+ List<String> newList = new ArrayList<String>();
+ newList.add("testString");
- Iterable<String> res = AAIUtils.nullCheck(newList);
+ Iterable<String> res = AAIUtils.nullCheck(newList);
- assertNotNull("nullCheck() should return back list", res);
- assertEquals(newList, res);
- }
+ assertNotNull("nullCheck() should return back list", res);
+ assertEquals(newList, res);
+ }
- @Test
- public void testGenDate() {
+ @Test
+ public void testGenDate() {
- Date d1 = new Date(0);
+ Date d1 = new Date(0);
- DateFormat formatter = new SimpleDateFormat("YYMMdd-HH:mm:ss:SSS");
- formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
- formatter.setLenient(false);
+ DateFormat formatter = new SimpleDateFormat("YYMMdd-HH:mm:ss:SSS");
+ formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
+ formatter.setLenient(false);
- Date d2 = null;
+ Date d2 = null;
- try {
- d2 = formatter.parse(AAIUtils.genDate());
- } catch (ParseException e) {
- fail("Date parsing exception");
- e.printStackTrace();
- }
+ try {
+ d2 = formatter.parse(AAIUtils.genDate());
+ } catch (ParseException e) {
+ fail("Date parsing exception");
+ e.printStackTrace();
+ }
- try {
- TimeUnit.SECONDS.sleep(1);
- } catch (InterruptedException e1) {}
+ try {
+ TimeUnit.SECONDS.sleep(1);
+ } catch (InterruptedException e1) {
+ }
- Date d3 = new Date();
+ Date d3 = new Date();
- assertTrue("Generated date is not after a past date", d2.after(d1));
- assertTrue("Generated date is not before a future date", d2.before(d3));
- }
+ assertTrue("Generated date is not after a past date", d2.after(d1));
+ assertTrue("Generated date is not before a future date", d2.before(d3));
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/util/FileWatcherTest.java b/aai-core/src/test/java/org/onap/aai/util/FileWatcherTest.java
index bc815918..f4838304 100644
--- a/aai-core/src/test/java/org/onap/aai/util/FileWatcherTest.java
+++ b/aai-core/src/test/java/org/onap/aai/util/FileWatcherTest.java
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.util;
import static org.junit.Assert.*;
@@ -27,50 +28,50 @@ import org.junit.Test;
import org.mockito.Mockito;
public class FileWatcherTest {
-
- class FileWatcherExtension extends FileWatcher {
- public FileWatcherExtension(File file) {
- super(file);
- }
+ class FileWatcherExtension extends FileWatcher {
+
+ public FileWatcherExtension(File file) {
+ super(file);
+ }
+
+ @Override
+ protected void onChange(File file) {
+ System.out.println("do nothing");
+ }
+ }
+
+ @Test
+ public void testFileWatcher() {
+ File file = new File("helloworld");
+ file.setLastModified(new Long(123));
+ FileWatcher fileWatcher = new FileWatcherExtension(file);
+ assertNotNull(fileWatcher);
+ file.deleteOnExit();
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testFileWatcher_nullConstructor() {
+ FileWatcher fileWatcher = new FileWatcherExtension(null);
+ assertNull(fileWatcher);
+ }
+
+ @Test
+ public void testRun() {
+ // verify that code is reachable outside of conditional check in run()
+ File file = new File("helloworld");
+ file.setLastModified(new Long(100));
+ FileWatcher fileWatcher = new FileWatcherExtension(file);
+ fileWatcher.run();
+ file.deleteOnExit();
+ }
- @Override
- protected void onChange(File file) {
- System.out.println("do nothing");
- }
- }
+ @Test
+ public void testOnChange() throws Exception {
+ FileWatcher fileWatcher = Mockito.mock(FileWatcher.class, Mockito.CALLS_REAL_METHODS);
- @Test
- public void testFileWatcher() {
- File file = new File("helloworld");
- file.setLastModified(new Long(123));
- FileWatcher fileWatcher = new FileWatcherExtension(file);
- assertNotNull(fileWatcher);
- file.deleteOnExit();
- }
-
- @Test(expected=NullPointerException.class)
- public void testFileWatcher_nullConstructor() {
- FileWatcher fileWatcher = new FileWatcherExtension(null);
- assertNull(fileWatcher);
- }
-
- @Test
- public void testRun() {
- // verify that code is reachable outside of conditional check in run()
- File file = new File("helloworld");
- file.setLastModified(new Long(100));
- FileWatcher fileWatcher = new FileWatcherExtension(file);
- fileWatcher.run();
- file.deleteOnExit();
- }
+ fileWatcher.onChange(Mockito.any(File.class));
- @Test
- public void testOnChange() throws Exception {
- FileWatcher fileWatcher = Mockito.mock(FileWatcher.class, Mockito.CALLS_REAL_METHODS);
-
- fileWatcher.onChange(Mockito.any(File.class));
-
- Mockito.verify(fileWatcher).onChange(Mockito.any(File.class));
- }
+ Mockito.verify(fileWatcher).onChange(Mockito.any(File.class));
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/util/FormatDateTest.java b/aai-core/src/test/java/org/onap/aai/util/FormatDateTest.java
index 6295990b..182916bc 100644
--- a/aai-core/src/test/java/org/onap/aai/util/FormatDateTest.java
+++ b/aai-core/src/test/java/org/onap/aai/util/FormatDateTest.java
@@ -17,8 +17,8 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.aai.util;
+package org.onap.aai.util;
import java.time.zone.ZoneRulesException;
@@ -29,46 +29,39 @@ import org.junit.Test;
@Ignore
public class FormatDateTest {
+ @Test(expected = IllegalArgumentException.class)
+ public void testExceptionThrownWhenInvalidPatternIsPassed() {
+ FormatDate formatDate = new FormatDate("XX/TT/GGGG");
+ formatDate.getDateTime();
+ }
+
+ @Test
+ public void correctPattern() {
+ FormatDate formatDate = new FormatDate("dd/mm/yyyy");
+ Assert.assertNotNull(formatDate.getDateTime());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void invalidPattern() {
+ FormatDate formatDate = new FormatDate("XX/TT/GGGG", "GMT");
+ formatDate.getDateTime();
+ }
+
+ @Test(expected = ZoneRulesException.class)
+ public void invalidZone() {
+ FormatDate formatDate = new FormatDate("dd/mm/yyyy", "IST");
+ formatDate.getDateTime();
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testExceptionThrownWhenInvalidPatternAndZoneIsPassed() {
+ FormatDate formatDate = new FormatDate("XX/TT/GGGG", "IST");
+ formatDate.getDateTime();
+ }
- @Test(expected=IllegalArgumentException.class)
- public void testExceptionThrownWhenInvalidPatternIsPassed()
- {
- FormatDate formatDate = new FormatDate("XX/TT/GGGG");
- formatDate.getDateTime();
- }
-
- @Test
- public void correctPattern()
- {
- FormatDate formatDate = new FormatDate("dd/mm/yyyy");
- Assert.assertNotNull(formatDate.getDateTime());
- }
-
- @Test(expected=IllegalArgumentException.class)
- public void invalidPattern()
- {
- FormatDate formatDate = new FormatDate("XX/TT/GGGG","GMT");
- formatDate.getDateTime();
- }
-
- @Test(expected=ZoneRulesException.class)
- public void invalidZone()
- {
- FormatDate formatDate = new FormatDate("dd/mm/yyyy","IST");
- formatDate.getDateTime();
- }
-
- @Test(expected=IllegalArgumentException.class)
- public void testExceptionThrownWhenInvalidPatternAndZoneIsPassed()
- {
- FormatDate formatDate = new FormatDate("XX/TT/GGGG","IST");
- formatDate.getDateTime();
- }
-
- @Test
- public void correctPatternAndZone()
- {
- FormatDate formatDate = new FormatDate("dd/mm/yyyy","GMT");
- Assert.assertNotNull(formatDate.getDateTime());
- }
+ @Test
+ public void correctPatternAndZone() {
+ FormatDate formatDate = new FormatDate("dd/mm/yyyy", "GMT");
+ Assert.assertNotNull(formatDate.getDateTime());
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/util/JettyObfuscationConversionCommandLineUtilTest.java b/aai-core/src/test/java/org/onap/aai/util/JettyObfuscationConversionCommandLineUtilTest.java
index 071b630b..b060a676 100644
--- a/aai-core/src/test/java/org/onap/aai/util/JettyObfuscationConversionCommandLineUtilTest.java
+++ b/aai-core/src/test/java/org/onap/aai/util/JettyObfuscationConversionCommandLineUtilTest.java
@@ -19,6 +19,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.util;
import static org.junit.Assert.assertTrue;
@@ -39,12 +40,12 @@ public class JettyObfuscationConversionCommandLineUtilTest {
*/
@Test
public void test() {
- //setup, this will catch main's print statements for evaluation
+ // setup, this will catch main's print statements for evaluation
PrintStream oldOutputStream = System.out;
System.setOut(new PrintStream(testOut));
- /* ------ TEST OBFUSCATION ----*/
- JettyObfuscationConversionCommandLineUtil.main(new String[]{"-e", "hello world"});
+ /* ------ TEST OBFUSCATION ---- */
+ JettyObfuscationConversionCommandLineUtil.main(new String[] {"-e", "hello world"});
/*
* testOut was also catching any logging statements which interfered with result checking.
* This regex business was the workaround - it tries to find the expected value in
@@ -56,21 +57,20 @@ public class JettyObfuscationConversionCommandLineUtilTest {
Matcher obfMatch = obfExpectPat.matcher(obfResult);
assertTrue(obfMatch.find());
- testOut.reset(); //clear out previous result
+ testOut.reset(); // clear out previous result
/* ------ TEST DEOBFUSCATION ----- */
- JettyObfuscationConversionCommandLineUtil.main(new String[]{"-d", obfExpected});
+ JettyObfuscationConversionCommandLineUtil.main(new String[] {"-d", obfExpected});
String deobfResult = testOut.toString();
String deobfExpected = "hello world";
Pattern deobfExpectPat = Pattern.compile(deobfExpected);
Matcher deobfMatch = deobfExpectPat.matcher(deobfResult);
assertTrue(deobfMatch.find());
- //clean up, resets to stdout
+ // clean up, resets to stdout
System.setOut(oldOutputStream);
}
-
/**
* Test.
*/
@@ -78,8 +78,8 @@ public class JettyObfuscationConversionCommandLineUtilTest {
public void testUsage() {
System.setOut(new PrintStream(testOut));
- /* ------ TEST OBFUSCATION ----*/
- JettyObfuscationConversionCommandLineUtil.main(new String[]{"-f", "hello world"});
+ /* ------ TEST OBFUSCATION ---- */
+ JettyObfuscationConversionCommandLineUtil.main(new String[] {"-f", "hello world"});
/*
* testOut was also catching any logging statements which interfered with result checking.
* This regex business was the workaround - it tries to find the expected value in
@@ -87,9 +87,8 @@ public class JettyObfuscationConversionCommandLineUtilTest {
*/
String obfResult = testOut.toString();
assertTrue(obfResult.startsWith("failed to parse input"));
-
- testOut.reset(); //clear out previous result
+ testOut.reset(); // clear out previous result
}
diff --git a/aai-core/src/test/java/org/onap/aai/util/KeyValueListTest.java b/aai-core/src/test/java/org/onap/aai/util/KeyValueListTest.java
index 88665065..38901781 100644
--- a/aai-core/src/test/java/org/onap/aai/util/KeyValueListTest.java
+++ b/aai-core/src/test/java/org/onap/aai/util/KeyValueListTest.java
@@ -17,11 +17,13 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.util;
+import static org.junit.Assert.*;
+
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.*;
public class KeyValueListTest {
KeyValueList kv;
diff --git a/aai-core/src/test/java/org/onap/aai/util/MapperUtilTest.java b/aai-core/src/test/java/org/onap/aai/util/MapperUtilTest.java
index 2d68f833..33da9c04 100644
--- a/aai-core/src/test/java/org/onap/aai/util/MapperUtilTest.java
+++ b/aai-core/src/test/java/org/onap/aai/util/MapperUtilTest.java
@@ -19,25 +19,24 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.aai.util;
-
+
+package org.onap.aai.util;
+
+import static org.junit.Assert.assertEquals;
+
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-
public class MapperUtilTest {
-
-
private JSONObject expectedJson;
private JSONObject sampleJson;
@Before
- public void setup(){
- expectedJson = new JSONObject();
- sampleJson = new JSONObject();
+ public void setup() {
+ expectedJson = new JSONObject();
+ sampleJson = new JSONObject();
}
@Test
@@ -46,8 +45,8 @@ public class MapperUtilTest {
expectedJson.put("shape", "box");
SampleClass sample = new SampleClass("black", "box");
assertEquals(expectedJson.toString(), MapperUtil.writeAsJSONString(sample));
- }
-
+ }
+
@Test
public void readAsObjectOfTest() throws Exception {
sampleJson.put("color", "black");
@@ -56,19 +55,21 @@ public class MapperUtilTest {
SampleClass actualObject = MapperUtil.readAsObjectOf(SampleClass.class, sampleJson.toString());
assertEquals(expectedObject.getColor(), actualObject.getColor());
assertEquals(expectedObject.getShape(), actualObject.getShape());
- }
+ }
}
-class SampleClass {
- private String color;
- private String shape;
+
+class SampleClass {
+ private String color;
+ private String shape;
public SampleClass() {
-
+
}
- public SampleClass(String c, String s){
- color = c;
- shape = s;
+
+ public SampleClass(String c, String s) {
+ color = c;
+ shape = s;
}
public String getColor() {
diff --git a/aai-core/src/test/java/org/onap/aai/util/PojoUtilsTest.java b/aai-core/src/test/java/org/onap/aai/util/PojoUtilsTest.java
index 35065fd5..e9069885 100644
--- a/aai-core/src/test/java/org/onap/aai/util/PojoUtilsTest.java
+++ b/aai-core/src/test/java/org/onap/aai/util/PojoUtilsTest.java
@@ -17,12 +17,17 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import com.google.common.collect.ImmutableListMultimap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Multimap;
+
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.Month;
@@ -42,287 +47,284 @@ import org.junit.Test;
import org.mockito.Mockito;
import org.onap.aai.domain.notificationEvent.NotificationEvent;
-import com.google.common.collect.ImmutableListMultimap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Multimap;
-
public class PojoUtilsTest {
- private PojoUtils pojoUtils;
-
- @Before
- public void init() {
- pojoUtils = new PojoUtils();
- }
-
- @Test
- public void testGetKeyValueList() throws Exception {
- Entity entity = getEntityObject();
- Person person = getPojoObject();
-
- List<KeyValueList> keyValueLists = pojoUtils.getKeyValueList(entity, person);
-
- for (KeyValueList keyValueList : keyValueLists) {
-
- if(keyValueList.getKey().equals("key")) {
- assertEquals("value", keyValueList.getValue());
- } else if (keyValueList.getKey().equals("name")) {
- assertEquals("Andrew", keyValueList.getValue());
- } else if(keyValueList.getKey().equals("nickname")) {
- assertEquals("Andy", keyValueList.getValue());
- } else if(keyValueList.getKey().equals("age")) {
- assertEquals("30", keyValueList.getValue());
- } else if(keyValueList.getKey().equals("weightlb")) {
- assertEquals("185", keyValueList.getValue());
- } else if(keyValueList.getKey().equals("heightcm")) {
- assertEquals("190", keyValueList.getValue());
- } else if(keyValueList.getKey().equals("pet")) {
- assertEquals("", keyValueList.getValue());
- }
- }
- }
-
- @Test
- public void testGetJsonFromObjectClassMockTest() throws Exception {
- PojoUtils pojoUtils = Mockito.mock(PojoUtils.class);
- String obj = "helloWorld";
- Mockito.when(pojoUtils.getJsonFromObject(Mockito.anyString())).thenCallRealMethod();
-
- pojoUtils.getJsonFromObject(obj);
-
- Mockito.verify(pojoUtils, Mockito.times(1)).getJsonFromObject(Mockito.anyString(), Mockito.eq(false), Mockito.eq(true));
- }
-
- @Test
- public void testGetJsonFromObjectClass() throws Exception {
- LocalDateTime date = LocalDateTime.of(2017, Month.SEPTEMBER, 18, 10, 55, 0, 300);
-
- String res = pojoUtils.getJsonFromObject(date);
-
- assertNotNull(res);
- assertTrue(res.contains("\"dayOfMonth\" : 18"));
- assertTrue(res.contains("\"dayOfWeek\" : \"MONDAY\""));
- assertTrue(res.contains("\"dayOfYear\" : 261"));
- assertTrue(res.contains("\"hour\" : 10"));
- assertTrue(res.contains("\"minute\" : 55"));
- assertTrue(res.contains("\"month\" : \"SEPTEMBER\""));
- assertTrue(res.contains("\"monthValue\" : 9"));
- assertTrue(res.contains("\"nano\" : 300"));
- assertTrue(res.contains("\"second\" : 0"));
- assertTrue(res.contains("\"year\" : 2017"));
- }
-
- @Test
- public void testGetJsonFromObjectClassNull() throws Exception {
- String res = pojoUtils.getJsonFromObject(null);
-
- assertNotNull(res);
- assertEquals("null", res);
- }
-
- @Test
- public void testGetJsonFromObjectNull() throws Exception {
- String res = pojoUtils.getJsonFromObject(null, false, true);
-
- assertNotNull(res);
- assertEquals("null", res);
- }
-
- @Test
- public void testGetJsonFromObject() throws Exception {
- LocalDateTime date = LocalDateTime.of(2017, Month.SEPTEMBER, 18, 10, 55, 0, 300);
-
- String res = pojoUtils.getJsonFromObject(date, false, false);
- assertNotNull(res);
-
- res = pojoUtils.getJsonFromObject(date, true, false);
- assertNotNull(res);
-
- res = pojoUtils.getJsonFromObject(date, true, true);
- assertNotNull(res);
- }
-
- @Test
- public void testGetJsonFromDynamicObject() throws Exception {
- DynamicEntity dynamicEntity = Mockito.mock(DynamicEntity.class);
- JAXBContext jaxbContext = Mockito.mock(JAXBContext.class);
- JAXBMarshaller marshaller = Mockito.mock(JAXBMarshaller.class);
-
- Mockito.when(jaxbContext.createMarshaller()).thenReturn(marshaller);
-
- String output = pojoUtils.getJsonFromDynamicObject(dynamicEntity, jaxbContext, true);
- assertEquals("", output);
- }
-
- @Test(expected = NullPointerException.class)
- public void testGetXmlFromObjectNull() throws Exception {
- pojoUtils.getXmlFromObject(null);
- }
-
- @Test
- public void testGetXmlFromObject() throws JAXBException, IOException {
- NotificationEvent notificationEvent = new NotificationEvent();
- notificationEvent.setCambriaPartition("partition");
-
- String res = pojoUtils.getXmlFromObject(notificationEvent);
-
- assertNotNull(res);
- assertTrue(res.contains("<NotificationEvent>"));
- assertTrue(res.contains("<cambria.partition>partition</cambria.partition>"));
- assertTrue(res.contains("</NotificationEvent>"));
- }
-
- @Test
- public void testGetLookupKeyEmptyKey() {
- String baseKey = "";
- Collection<String> keyProps = new ArrayList<String>();
- keyProps.add("key");
-
- HashMap<String, Object> lookup = new HashMap<String, Object>();
- lookup.put("key", "val");
- String expectedLookupKey = "key=val";
-
- String res = pojoUtils.getLookupKey(baseKey, lookup, keyProps);
- assertEquals(expectedLookupKey, res);
- }
-
- @Test
- public void testGetLookupKey() {
- String baseKey = "baseKey";
- Collection<String> keyProps = new ArrayList<String>();
- keyProps.add("key");
-
- HashMap<String, Object> lookup = new HashMap<String, Object>();
- lookup.put("key", "val");
- String expectedLookupKey = "baseKey&key=val";
-
- String res = pojoUtils.getLookupKey(baseKey, lookup, keyProps);
-
- assertEquals(expectedLookupKey, res);
- }
-
- @Test
- public void testGetLookupKeys() {
- HashMap<String, Object> lookup = new HashMap<>();
- lookup.put("multimapkey", "val");
- LinkedHashMap<String, HashMap<String, Object>> lookupHashes = new LinkedHashMap<>();
- lookupHashes.put("objectType", lookup);
-
- Multimap<String, String> multimap = ImmutableListMultimap.of("objectType", "multimapkey");
- String res = pojoUtils.getLookupKeys(lookupHashes, multimap);
-
- String lookupKey = "val";
- assertNotNull(res);
- assertEquals(lookupKey, res);
- }
-
- @Test
- public void testGetExampleObject() throws Exception {
- Person p = getPojoObject();
- pojoUtils.getExampleObject(p, true);
- assertNotNull(p);
- assertTrue(p.getName().contains("example-name-val-"));
- assertTrue(p.getNickname().contains("example-nickname-val-"));
- assertTrue(p.getPet().contains("example-pet-val-"));
- assertNotNull(p.getAge());
- assertNotNull(p.getHeightcm());
- assertNotNull(p.getWeightlb());
- assertTrue(p.isMarried());
- }
-
- private Entity getEntityObject() {
- Entity entity = new Entity();
- KeyValueList list = new KeyValueList();
- list.setKey("key");
- list.setValue("value");
-
- entity.setAction("action");
- entity.setKeyValueList(Lists.newArrayList(list));
- entity.setEquipmentRole("equipmentRole");
- entity.setSelfLink("selfLink");
-
- return entity;
- }
-
- private Person getPojoObject() {
- Person p = new Person("Andrew");
- p.setAge(30);
- p.setHeightcm((short) 190);
- p.setWeightlb(185);
- p.setNickname("Andy");
- p.setPet(null);
- return p;
- }
-
- class Person {
-
- private int age;
- private long weightlb;
- private short heightcm;
- private String nickname;
- private String name;
- private String pet;
- private boolean isMarried;
-
- public Person(String name) {
- this.name = name;
- }
-
- public int getAge() {
- return age;
- }
-
- public void setAge(int age) {
- this.age = age;
- }
-
- public long getWeightlb() {
- return weightlb;
- }
-
- public void setWeightlb(long weightlb) {
- this.weightlb = weightlb;
- }
-
- public short getHeightcm() {
- return heightcm;
- }
-
- public void setHeightcm(short heightcm) {
- this.heightcm = heightcm;
- }
-
- public String getNickname() {
- return nickname;
- }
-
- public void setNickname(String nickname) {
- this.nickname = nickname;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getPet() {
- return pet;
- }
-
- public void setPet(String pet) {
- this.pet = pet;
- }
-
- public boolean isMarried() {
- return isMarried;
- }
-
- public void setMarried(boolean isMarried) {
- this.isMarried = isMarried;
- }
-
- }
+ private PojoUtils pojoUtils;
+
+ @Before
+ public void init() {
+ pojoUtils = new PojoUtils();
+ }
+
+ @Test
+ public void testGetKeyValueList() throws Exception {
+ Entity entity = getEntityObject();
+ Person person = getPojoObject();
+
+ List<KeyValueList> keyValueLists = pojoUtils.getKeyValueList(entity, person);
+
+ for (KeyValueList keyValueList : keyValueLists) {
+
+ if (keyValueList.getKey().equals("key")) {
+ assertEquals("value", keyValueList.getValue());
+ } else if (keyValueList.getKey().equals("name")) {
+ assertEquals("Andrew", keyValueList.getValue());
+ } else if (keyValueList.getKey().equals("nickname")) {
+ assertEquals("Andy", keyValueList.getValue());
+ } else if (keyValueList.getKey().equals("age")) {
+ assertEquals("30", keyValueList.getValue());
+ } else if (keyValueList.getKey().equals("weightlb")) {
+ assertEquals("185", keyValueList.getValue());
+ } else if (keyValueList.getKey().equals("heightcm")) {
+ assertEquals("190", keyValueList.getValue());
+ } else if (keyValueList.getKey().equals("pet")) {
+ assertEquals("", keyValueList.getValue());
+ }
+ }
+ }
+
+ @Test
+ public void testGetJsonFromObjectClassMockTest() throws Exception {
+ PojoUtils pojoUtils = Mockito.mock(PojoUtils.class);
+ String obj = "helloWorld";
+ Mockito.when(pojoUtils.getJsonFromObject(Mockito.anyString())).thenCallRealMethod();
+
+ pojoUtils.getJsonFromObject(obj);
+
+ Mockito.verify(pojoUtils, Mockito.times(1)).getJsonFromObject(Mockito.anyString(), Mockito.eq(false),
+ Mockito.eq(true));
+ }
+
+ @Test
+ public void testGetJsonFromObjectClass() throws Exception {
+ LocalDateTime date = LocalDateTime.of(2017, Month.SEPTEMBER, 18, 10, 55, 0, 300);
+
+ String res = pojoUtils.getJsonFromObject(date);
+
+ assertNotNull(res);
+ assertTrue(res.contains("\"dayOfMonth\" : 18"));
+ assertTrue(res.contains("\"dayOfWeek\" : \"MONDAY\""));
+ assertTrue(res.contains("\"dayOfYear\" : 261"));
+ assertTrue(res.contains("\"hour\" : 10"));
+ assertTrue(res.contains("\"minute\" : 55"));
+ assertTrue(res.contains("\"month\" : \"SEPTEMBER\""));
+ assertTrue(res.contains("\"monthValue\" : 9"));
+ assertTrue(res.contains("\"nano\" : 300"));
+ assertTrue(res.contains("\"second\" : 0"));
+ assertTrue(res.contains("\"year\" : 2017"));
+ }
+
+ @Test
+ public void testGetJsonFromObjectClassNull() throws Exception {
+ String res = pojoUtils.getJsonFromObject(null);
+
+ assertNotNull(res);
+ assertEquals("null", res);
+ }
+
+ @Test
+ public void testGetJsonFromObjectNull() throws Exception {
+ String res = pojoUtils.getJsonFromObject(null, false, true);
+
+ assertNotNull(res);
+ assertEquals("null", res);
+ }
+
+ @Test
+ public void testGetJsonFromObject() throws Exception {
+ LocalDateTime date = LocalDateTime.of(2017, Month.SEPTEMBER, 18, 10, 55, 0, 300);
+
+ String res = pojoUtils.getJsonFromObject(date, false, false);
+ assertNotNull(res);
+
+ res = pojoUtils.getJsonFromObject(date, true, false);
+ assertNotNull(res);
+
+ res = pojoUtils.getJsonFromObject(date, true, true);
+ assertNotNull(res);
+ }
+
+ @Test
+ public void testGetJsonFromDynamicObject() throws Exception {
+ DynamicEntity dynamicEntity = Mockito.mock(DynamicEntity.class);
+ JAXBContext jaxbContext = Mockito.mock(JAXBContext.class);
+ JAXBMarshaller marshaller = Mockito.mock(JAXBMarshaller.class);
+
+ Mockito.when(jaxbContext.createMarshaller()).thenReturn(marshaller);
+
+ String output = pojoUtils.getJsonFromDynamicObject(dynamicEntity, jaxbContext, true);
+ assertEquals("", output);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testGetXmlFromObjectNull() throws Exception {
+ pojoUtils.getXmlFromObject(null);
+ }
+
+ @Test
+ public void testGetXmlFromObject() throws JAXBException, IOException {
+ NotificationEvent notificationEvent = new NotificationEvent();
+ notificationEvent.setCambriaPartition("partition");
+
+ String res = pojoUtils.getXmlFromObject(notificationEvent);
+
+ assertNotNull(res);
+ assertTrue(res.contains("<NotificationEvent>"));
+ assertTrue(res.contains("<cambria.partition>partition</cambria.partition>"));
+ assertTrue(res.contains("</NotificationEvent>"));
+ }
+
+ @Test
+ public void testGetLookupKeyEmptyKey() {
+ String baseKey = "";
+ Collection<String> keyProps = new ArrayList<String>();
+ keyProps.add("key");
+
+ HashMap<String, Object> lookup = new HashMap<String, Object>();
+ lookup.put("key", "val");
+ String expectedLookupKey = "key=val";
+
+ String res = pojoUtils.getLookupKey(baseKey, lookup, keyProps);
+ assertEquals(expectedLookupKey, res);
+ }
+
+ @Test
+ public void testGetLookupKey() {
+ String baseKey = "baseKey";
+ Collection<String> keyProps = new ArrayList<String>();
+ keyProps.add("key");
+
+ HashMap<String, Object> lookup = new HashMap<String, Object>();
+ lookup.put("key", "val");
+ String expectedLookupKey = "baseKey&key=val";
+
+ String res = pojoUtils.getLookupKey(baseKey, lookup, keyProps);
+
+ assertEquals(expectedLookupKey, res);
+ }
+
+ @Test
+ public void testGetLookupKeys() {
+ HashMap<String, Object> lookup = new HashMap<>();
+ lookup.put("multimapkey", "val");
+ LinkedHashMap<String, HashMap<String, Object>> lookupHashes = new LinkedHashMap<>();
+ lookupHashes.put("objectType", lookup);
+
+ Multimap<String, String> multimap = ImmutableListMultimap.of("objectType", "multimapkey");
+ String res = pojoUtils.getLookupKeys(lookupHashes, multimap);
+
+ String lookupKey = "val";
+ assertNotNull(res);
+ assertEquals(lookupKey, res);
+ }
+
+ @Test
+ public void testGetExampleObject() throws Exception {
+ Person p = getPojoObject();
+ pojoUtils.getExampleObject(p, true);
+ assertNotNull(p);
+ assertTrue(p.getName().contains("example-name-val-"));
+ assertTrue(p.getNickname().contains("example-nickname-val-"));
+ assertTrue(p.getPet().contains("example-pet-val-"));
+ assertNotNull(p.getAge());
+ assertNotNull(p.getHeightcm());
+ assertNotNull(p.getWeightlb());
+ assertTrue(p.isMarried());
+ }
+
+ private Entity getEntityObject() {
+ Entity entity = new Entity();
+ KeyValueList list = new KeyValueList();
+ list.setKey("key");
+ list.setValue("value");
+
+ entity.setAction("action");
+ entity.setKeyValueList(Lists.newArrayList(list));
+ entity.setEquipmentRole("equipmentRole");
+ entity.setSelfLink("selfLink");
+
+ return entity;
+ }
+
+ private Person getPojoObject() {
+ Person p = new Person("Andrew");
+ p.setAge(30);
+ p.setHeightcm((short) 190);
+ p.setWeightlb(185);
+ p.setNickname("Andy");
+ p.setPet(null);
+ return p;
+ }
+
+ class Person {
+
+ private int age;
+ private long weightlb;
+ private short heightcm;
+ private String nickname;
+ private String name;
+ private String pet;
+ private boolean isMarried;
+
+ public Person(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ public long getWeightlb() {
+ return weightlb;
+ }
+
+ public void setWeightlb(long weightlb) {
+ this.weightlb = weightlb;
+ }
+
+ public short getHeightcm() {
+ return heightcm;
+ }
+
+ public void setHeightcm(short heightcm) {
+ this.heightcm = heightcm;
+ }
+
+ public String getNickname() {
+ return nickname;
+ }
+
+ public void setNickname(String nickname) {
+ this.nickname = nickname;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getPet() {
+ return pet;
+ }
+
+ public void setPet(String pet) {
+ this.pet = pet;
+ }
+
+ public boolean isMarried() {
+ return isMarried;
+ }
+
+ public void setMarried(boolean isMarried) {
+ this.isMarried = isMarried;
+ }
+
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/util/RestURLEncoderTest.java b/aai-core/src/test/java/org/onap/aai/util/RestURLEncoderTest.java
index 757a7bb3..a41914d0 100644
--- a/aai-core/src/test/java/org/onap/aai/util/RestURLEncoderTest.java
+++ b/aai-core/src/test/java/org/onap/aai/util/RestURLEncoderTest.java
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.util;
import static org.junit.Assert.assertEquals;
@@ -27,35 +28,35 @@ import org.junit.Test;
public class RestURLEncoderTest {
- @Test
- public void testEncodeURL() throws Exception {
+ @Test
+ public void testEncodeURL() throws Exception {
- String url = "nodeKeyTest&more-string strings";
- String encodedUrl = "nodeKeyTest%26more-string%20strings";
+ String url = "nodeKeyTest&more-string strings";
+ String encodedUrl = "nodeKeyTest%26more-string%20strings";
- String res = RestURLEncoder.encodeURL(url);
- assertEquals(encodedUrl, res);
- }
+ String res = RestURLEncoder.encodeURL(url);
+ assertEquals(encodedUrl, res);
+ }
- @Test
- public void testEncodeURL_plusSign() throws Exception {
+ @Test
+ public void testEncodeURL_plusSign() throws Exception {
- String url = "nodeKeyTest+more+string";
- String encodedUrl = "nodeKeyTest%2Bmore%2Bstring";
+ String url = "nodeKeyTest+more+string";
+ String encodedUrl = "nodeKeyTest%2Bmore%2Bstring";
- String res = RestURLEncoder.encodeURL(url);
- assertEquals(encodedUrl, res);
- }
+ String res = RestURLEncoder.encodeURL(url);
+ assertEquals(encodedUrl, res);
+ }
- @Test
- public void testEncodeURL_noException() throws Exception {
- // no exception expected, none thrown: passes.
- try {
- String encodeResult = RestURLEncoder.encodeURL("");
+ @Test
+ public void testEncodeURL_noException() throws Exception {
+ // no exception expected, none thrown: passes.
+ try {
+ String encodeResult = RestURLEncoder.encodeURL("");
- assertNotNull("Result is not null", encodeResult);
- } catch (Exception e) {
- fail();
- }
- }
+ assertNotNull("Result is not null", encodeResult);
+ } catch (Exception e) {
+ fail();
+ }
+ }
}
diff --git a/aai-core/src/test/java/org/onap/aai/util/StoreNotificationEventTest.java b/aai-core/src/test/java/org/onap/aai/util/StoreNotificationEventTest.java
index 22df113b..08cbba20 100644
--- a/aai-core/src/test/java/org/onap/aai/util/StoreNotificationEventTest.java
+++ b/aai-core/src/test/java/org/onap/aai/util/StoreNotificationEventTest.java
@@ -17,10 +17,20 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.aai.util;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.databind.JsonMappingException;
+
+import java.io.IOException;
+
+import javax.json.Json;
+import javax.json.JsonObject;
+
import org.eclipse.persistence.dynamic.DynamicEntity;
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
import org.junit.Before;
@@ -36,182 +46,182 @@ import org.onap.aai.introspection.Introspector;
import org.onap.aai.introspection.Loader;
import org.onap.aai.introspection.ModelType;
-import javax.json.Json;
-import javax.json.JsonObject;
-import java.io.IOException;
+public class StoreNotificationEventTest extends AAISetup {
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+ private static AAIDmaapEventJMSProducer producer;
+ private static StoreNotificationEvent sne;
-public class StoreNotificationEventTest extends AAISetup {
+ @BeforeClass
+ public static void setUp() {
+ producer = Mockito.mock(AAIDmaapEventJMSProducer.class);
+ // sne = new StoreNotificationEvent(producer, "transiationId", "sourceOfTruth");
+ }
+
+ @Before
+ public void setUpBefore() {
+ producer = Mockito.mock(AAIDmaapEventJMSProducer.class);
+ sne = new StoreNotificationEvent(producer, "transiationId", "sourceOfTruth");
+
+ }
+
+ @Test(expected = AAIException.class)
+ public void testStoreEventNullObj() throws AAIException {
+ sne.storeEvent(new EventHeader(), null);
+ }
+
+ @Test(expected = AAIException.class)
+ public void testStoreEventInvalidObjForPojoUtils() throws AAIException {
+ sne.storeEvent(new EventHeader(), new Object());
+ }
+
+ @Test
+ public void testStoreEventEmptyEventHeader()
+ throws AAIException, JsonGenerationException, JsonMappingException, IOException {
+ JsonObject object = Json.createObjectBuilder().add("hello", "world").build();
+ String res = sne.storeEvent(new EventHeader(), object);
+
+ assertNotNull(res);
+ assertTrue(res.contains("\"cambria.partition\" : \"" + AAIConstants.UEB_PUB_PARTITION_AAI + "\""));
+ assertTrue(res.contains("\"event-header\""));
+ assertTrue(res.contains("\"id\""));
+ assertTrue(res.contains("\"timestamp\""));
+ assertTrue(res
+ .contains("\"source-name\" : \"" + AAIConfig.get("aai.notificationEvent.default.sourceName") + "\""));
+ assertTrue(res.contains("\"domain\" : \"" + AAIConfig.get("aai.notificationEvent.default.domain") + "\""));
+ assertTrue(res.contains(
+ "\"sequence-number\" : \"" + AAIConfig.get("aai.notificationEvent.default.sequenceNumber") + "\""));
+ assertTrue(res.contains("\"severity\" : \"" + AAIConfig.get("aai.notificationEvent.default.severity") + "\""));
+ assertTrue(
+ res.contains("\"event-type\" : \"" + AAIConfig.get("aai.notificationEvent.default.eventType") + "\""));
+ assertTrue(res.contains("\"version\" : \"" + AAIConfig.get("aai.notificationEvent.default.version") + "\""));
+ assertTrue(res.contains("\"action\" : \"UNK\""));
+ assertTrue(res.contains("\"entity-link\" : \"UNK\""));
+ assertTrue(res.contains("\"entity\""));
+ assertTrue(res.contains("\"hello\""));
+ assertTrue(res.contains("\"chars\" : \"world\""));
+ assertTrue(res.contains("\"string\" : \"world\""));
+ assertTrue(res.contains("\"valueType\" : \"STRING\""));
+ }
+
+ @Test
+ public void testStoreEvent() throws AAIException, JsonGenerationException, JsonMappingException, IOException {
+ JsonObject object = Json.createObjectBuilder().add("hello", "world").build();
+ EventHeader eh = new EventHeader();
+ eh.setId("123");
+ eh.setTimestamp("current-time");
+ eh.setEntityLink("entity-link");
+ eh.setAction("action!");
+ eh.setEventType("surprise");
+ eh.setDomain("PROD");
+ eh.setSourceName("source");
+ eh.setSequenceNumber("23");
+ eh.setSeverity("ALERT");
+ eh.setVersion("v12");
+
+ String res = sne.storeEvent(eh, object);
+
+ assertNotNull(res);
+ assertTrue(res.contains("\"cambria.partition\" : \"" + AAIConstants.UEB_PUB_PARTITION_AAI + "\""));
+ assertTrue(res.contains("\"event-header\""));
+ assertTrue(res.contains("\"id\" : \"123\""));
+ assertTrue(res.contains("\"timestamp\" : \"current-time\""));
+ assertTrue(res.contains("\"source-name\" : \"source\""));
+ assertTrue(res.contains("\"domain\" : \"PROD\""));
+ assertTrue(res.contains("\"sequence-number\" : \"23\""));
+ assertTrue(res.contains("\"severity\" : \"ALERT\""));
+ assertTrue(res.contains("\"event-type\" : \"surprise\""));
+ assertTrue(res.contains("\"version\" : \"v12\""));
+ assertTrue(res.contains("\"action\" : \"action!\""));
+ assertTrue(res.contains("\"entity-link\" : \"entity-link\""));
+ assertTrue(res.contains("\"entity\""));
+ assertTrue(res.contains("\"hello\""));
+ assertTrue(res.contains("\"chars\" : \"world\""));
+ assertTrue(res.contains("\"string\" : \"world\""));
+ assertTrue(res.contains("\"valueType\" : \"STRING\""));
+ }
+
+ @Test(expected = AAIException.class)
+ public void testStoreDynamicEventNullObj() throws AAIException {
+ DynamicEntity eventHeader = Mockito.mock(DynamicEntity.class);
+ DynamicJAXBContext notificationJaxbContext =
+ nodeIngestor.getContextForVersion(schemaVersions.getEdgeLabelVersion());
+ sne.storeDynamicEvent(notificationJaxbContext, "v12", eventHeader, null);
+ }
+
+ @Test(expected = Exception.class)
+ public void testStoreDynamicEventAAIException() throws Exception {
+
+ DynamicJAXBContext notificationJaxbContext =
+ nodeIngestor.getContextForVersion(schemaVersions.getEdgeLabelVersion());
+ DynamicEntity obj = Mockito.mock(DynamicEntity.class);
+ DynamicEntity eventHeader = Mockito.mock(DynamicEntity.class);
+ sne.storeDynamicEvent(notificationJaxbContext, "v12", eventHeader, obj);
+ }
+
+ @Test(expected = AAIException.class)
+ public void testStoreEventIntrospectorNullObj() throws Exception {
+ Loader loader = Mockito.mock(Loader.class);
+ sne.storeEvent(loader, null, null);
+ }
+
+ @Ignore("Stopped working since the model driven story")
+ @Test
+ public void testStoreEvent1Introspector() throws Exception {
+ Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getEdgeLabelVersion());
+ Introspector eventHeader = loader.introspectorFromName("notification-event-header");
+ eventHeader.setValue("id", "123");
+ eventHeader.setValue("timestamp", "current-time");
+ eventHeader.setValue("entity-link", "entity-link");
+ eventHeader.setValue("action", "action!");
+ eventHeader.setValue("event-type", "surprise");
+ eventHeader.setValue("domain", "PROD");
+ eventHeader.setValue("source-name", "source");
+ eventHeader.setValue("sequence-number", "23");
+ eventHeader.setValue("severity", "ALERT");
+ eventHeader.setValue("version", "v12");
+ Introspector obj = loader.introspectorFromName("notification-event");
+ String res = sne.storeEvent(loader, eventHeader, obj);
+
+ assertNotNull(res);
+ assertTrue(res.contains("\"cambria.partition\":\"" + AAIConstants.UEB_PUB_PARTITION_AAI + "\""));
+ assertTrue(res.contains("\"event-header\""));
+ assertTrue(res.contains("\"id\":\"123\""));
+ assertTrue(res.contains("\"timestamp\":\"current-time\""));
+ assertTrue(res.contains("\"source-name\":\"source\""));
+ assertTrue(res.contains("\"domain\":\"PROD\""));
+ assertTrue(res.contains("\"sequence-number\":\"23\""));
+ assertTrue(res.contains("\"severity\":\"ALERT\""));
+ assertTrue(res.contains("\"event-type\":\"surprise\""));
+ assertTrue(res.contains("\"version\":\"v12\""));
+ assertTrue(res.contains("\"action\":\"action!\""));
+ assertTrue(res.contains("\"entity-link\":\"entity-link\""));
+ assertTrue(res.contains("\"notification-event\""));
+ }
+
+ @Ignore("Stopped working since the model driven story")
+ @Test
+ public void testStoreEventIntrospectorEmptyEventHeader() throws Exception {
+ Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getEdgeLabelVersion());
+ Introspector eventHeader = loader.introspectorFromName("notification-event-header");
+ Introspector obj = loader.introspectorFromName("notification-event");
+
+ String res = sne.storeEvent(loader, eventHeader, obj);
- private static AAIDmaapEventJMSProducer producer;
- private static StoreNotificationEvent sne;
-
-
- @BeforeClass
- public static void setUp() {
- producer = Mockito.mock(AAIDmaapEventJMSProducer.class);
- // sne = new StoreNotificationEvent(producer, "transiationId", "sourceOfTruth");
- }
-
- @Before
- public void setUpBefore() {
- producer = Mockito.mock(AAIDmaapEventJMSProducer.class);
- sne = new StoreNotificationEvent(producer, "transiationId", "sourceOfTruth");
-
- }
-
- @Test(expected = AAIException.class)
- public void testStoreEventNullObj() throws AAIException {
- sne.storeEvent(new EventHeader(), null);
- }
-
- @Test(expected = AAIException.class)
- public void testStoreEventInvalidObjForPojoUtils() throws AAIException {
- sne.storeEvent(new EventHeader(), new Object());
- }
-
- @Test
- public void testStoreEventEmptyEventHeader() throws AAIException, JsonGenerationException, JsonMappingException, IOException {
- JsonObject object = Json.createObjectBuilder().add("hello", "world").build();
- String res = sne.storeEvent(new EventHeader(), object);
-
- assertNotNull(res);
- assertTrue(res.contains("\"cambria.partition\" : \"" + AAIConstants.UEB_PUB_PARTITION_AAI + "\""));
- assertTrue(res.contains("\"event-header\""));
- assertTrue(res.contains("\"id\""));
- assertTrue(res.contains("\"timestamp\""));
- assertTrue(res.contains("\"source-name\" : \"" + AAIConfig.get("aai.notificationEvent.default.sourceName") + "\""));
- assertTrue(res.contains("\"domain\" : \"" + AAIConfig.get("aai.notificationEvent.default.domain") + "\""));
- assertTrue(res.contains("\"sequence-number\" : \"" + AAIConfig.get("aai.notificationEvent.default.sequenceNumber") + "\""));
- assertTrue(res.contains("\"severity\" : \"" + AAIConfig.get("aai.notificationEvent.default.severity") + "\""));
- assertTrue(res.contains("\"event-type\" : \"" + AAIConfig.get("aai.notificationEvent.default.eventType") + "\""));
- assertTrue(res.contains("\"version\" : \"" + AAIConfig.get("aai.notificationEvent.default.version") + "\""));
- assertTrue(res.contains("\"action\" : \"UNK\""));
- assertTrue(res.contains("\"entity-link\" : \"UNK\""));
- assertTrue(res.contains("\"entity\""));
- assertTrue(res.contains("\"hello\""));
- assertTrue(res.contains("\"chars\" : \"world\""));
- assertTrue(res.contains("\"string\" : \"world\""));
- assertTrue(res.contains("\"valueType\" : \"STRING\""));
- }
-
- @Test
- public void testStoreEvent() throws AAIException, JsonGenerationException, JsonMappingException, IOException {
- JsonObject object = Json.createObjectBuilder().add("hello", "world").build();
- EventHeader eh = new EventHeader();
- eh.setId("123");
- eh.setTimestamp("current-time");
- eh.setEntityLink("entity-link");
- eh.setAction("action!");
- eh.setEventType("surprise");
- eh.setDomain("PROD");
- eh.setSourceName("source");
- eh.setSequenceNumber("23");
- eh.setSeverity("ALERT");
- eh.setVersion("v12");
-
- String res = sne.storeEvent(eh, object);
-
- assertNotNull(res);
- assertTrue(res.contains("\"cambria.partition\" : \"" + AAIConstants.UEB_PUB_PARTITION_AAI + "\""));
- assertTrue(res.contains("\"event-header\""));
- assertTrue(res.contains("\"id\" : \"123\""));
- assertTrue(res.contains("\"timestamp\" : \"current-time\""));
- assertTrue(res.contains("\"source-name\" : \"source\""));
- assertTrue(res.contains("\"domain\" : \"PROD\""));
- assertTrue(res.contains("\"sequence-number\" : \"23\""));
- assertTrue(res.contains("\"severity\" : \"ALERT\""));
- assertTrue(res.contains("\"event-type\" : \"surprise\""));
- assertTrue(res.contains("\"version\" : \"v12\""));
- assertTrue(res.contains("\"action\" : \"action!\""));
- assertTrue(res.contains("\"entity-link\" : \"entity-link\""));
- assertTrue(res.contains("\"entity\""));
- assertTrue(res.contains("\"hello\""));
- assertTrue(res.contains("\"chars\" : \"world\""));
- assertTrue(res.contains("\"string\" : \"world\""));
- assertTrue(res.contains("\"valueType\" : \"STRING\""));
- }
-
- @Test(expected=AAIException.class)
- public void testStoreDynamicEventNullObj() throws AAIException {
- DynamicEntity eventHeader = Mockito.mock(DynamicEntity.class);
- DynamicJAXBContext notificationJaxbContext = nodeIngestor.getContextForVersion(schemaVersions.getEdgeLabelVersion());
- sne.storeDynamicEvent(notificationJaxbContext, "v12", eventHeader, null);
- }
-
- @Test(expected = Exception.class)
- public void testStoreDynamicEventAAIException() throws Exception {
-
- DynamicJAXBContext notificationJaxbContext = nodeIngestor.getContextForVersion(schemaVersions.getEdgeLabelVersion());
- DynamicEntity obj = Mockito.mock(DynamicEntity.class);
- DynamicEntity eventHeader = Mockito.mock(DynamicEntity.class);
- sne.storeDynamicEvent(notificationJaxbContext, "v12", eventHeader, obj);
- }
-
- @Test(expected = AAIException.class)
- public void testStoreEventIntrospectorNullObj() throws Exception {
- Loader loader = Mockito.mock(Loader.class);
- sne.storeEvent(loader, null, null);
- }
-
- @Ignore("Stopped working since the model driven story")
- @Test
- public void testStoreEvent1Introspector() throws Exception {
- Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getEdgeLabelVersion());
- Introspector eventHeader = loader.introspectorFromName("notification-event-header");
- eventHeader.setValue("id", "123");
- eventHeader.setValue("timestamp", "current-time");
- eventHeader.setValue("entity-link", "entity-link");
- eventHeader.setValue("action", "action!");
- eventHeader.setValue("event-type", "surprise");
- eventHeader.setValue("domain", "PROD");
- eventHeader.setValue("source-name", "source");
- eventHeader.setValue("sequence-number", "23");
- eventHeader.setValue("severity", "ALERT");
- eventHeader.setValue("version", "v12");
- Introspector obj = loader.introspectorFromName("notification-event");
- String res = sne.storeEvent(loader, eventHeader, obj);
-
- assertNotNull(res);
- assertTrue(res.contains("\"cambria.partition\":\"" + AAIConstants.UEB_PUB_PARTITION_AAI + "\""));
- assertTrue(res.contains("\"event-header\""));
- assertTrue(res.contains("\"id\":\"123\""));
- assertTrue(res.contains("\"timestamp\":\"current-time\""));
- assertTrue(res.contains("\"source-name\":\"source\""));
- assertTrue(res.contains("\"domain\":\"PROD\""));
- assertTrue(res.contains("\"sequence-number\":\"23\""));
- assertTrue(res.contains("\"severity\":\"ALERT\""));
- assertTrue(res.contains("\"event-type\":\"surprise\""));
- assertTrue(res.contains("\"version\":\"v12\""));
- assertTrue(res.contains("\"action\":\"action!\""));
- assertTrue(res.contains("\"entity-link\":\"entity-link\""));
- assertTrue(res.contains("\"notification-event\""));
- }
-
- @Ignore("Stopped working since the model driven story")
- @Test
- public void testStoreEventIntrospectorEmptyEventHeader() throws Exception {
- Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getEdgeLabelVersion());
- Introspector eventHeader = loader.introspectorFromName("notification-event-header");
- Introspector obj = loader.introspectorFromName("notification-event");
-
- String res = sne.storeEvent(loader, eventHeader, obj);
-
- assertNotNull(res);
- assertTrue(res.contains("\"cambria.partition\":\"" + AAIConstants.UEB_PUB_PARTITION_AAI + "\""));
- assertTrue(res.contains("\"event-header\""));
- assertTrue(res.contains("\"id\""));
- assertTrue(res.contains("\"timestamp\""));
- assertTrue(res.contains("\"source-name\":\"" + AAIConfig.get("aai.notificationEvent.default.sourceName") + "\""));
- assertTrue(res.contains("\"domain\":\"" + AAIConfig.get("aai.notificationEvent.default.domain") + "\""));
- assertTrue(res.contains("\"sequence-number\":\"" + AAIConfig.get("aai.notificationEvent.default.sequenceNumber") + "\""));
- assertTrue(res.contains("\"severity\":\"" + AAIConfig.get("aai.notificationEvent.default.severity") + "\""));
- assertTrue(res.contains("\"event-type\":\"" + AAIConfig.get("aai.notificationEvent.default.eventType") + "\""));
- assertTrue(res.contains("\"version\":\"" + AAIConfig.get("aai.notificationEvent.default.version") + "\""));
- assertTrue(res.contains("\"action\":\"UNK\""));
- assertTrue(res.contains("\"entity-link\":\"UNK\""));
- assertTrue(res.contains("\"notification-event\""));
- }
+ assertNotNull(res);
+ assertTrue(res.contains("\"cambria.partition\":\"" + AAIConstants.UEB_PUB_PARTITION_AAI + "\""));
+ assertTrue(res.contains("\"event-header\""));
+ assertTrue(res.contains("\"id\""));
+ assertTrue(res.contains("\"timestamp\""));
+ assertTrue(
+ res.contains("\"source-name\":\"" + AAIConfig.get("aai.notificationEvent.default.sourceName") + "\""));
+ assertTrue(res.contains("\"domain\":\"" + AAIConfig.get("aai.notificationEvent.default.domain") + "\""));
+ assertTrue(res.contains(
+ "\"sequence-number\":\"" + AAIConfig.get("aai.notificationEvent.default.sequenceNumber") + "\""));
+ assertTrue(res.contains("\"severity\":\"" + AAIConfig.get("aai.notificationEvent.default.severity") + "\""));
+ assertTrue(res.contains("\"event-type\":\"" + AAIConfig.get("aai.notificationEvent.default.eventType") + "\""));
+ assertTrue(res.contains("\"version\":\"" + AAIConfig.get("aai.notificationEvent.default.version") + "\""));
+ assertTrue(res.contains("\"action\":\"UNK\""));
+ assertTrue(res.contains("\"entity-link\":\"UNK\""));
+ assertTrue(res.contains("\"notification-event\""));
+ }
}