X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=aai-core%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fserialization%2Fqueryformats%2FResourceWithSoTTest.java;fp=aai-core%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fserialization%2Fqueryformats%2FResourceWithSoTTest.java;h=a1206b59aa06ca864efa6f1145cf7dc76ee44bbc;hb=e190b0b67803241ad3a94a6c6396fc47a94e7fac;hp=ac08ae2cfd649ab99b66765bdf7d770628cec4cc;hpb=e5cf8b0a5bbad65dacdb1055f8b4894dce8cdb26;p=aai%2Faai-common.git 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 ac08ae2c..a1206b59 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 @@ -47,7 +47,10 @@ import org.onap.aai.serialization.engines.TransactionalGraphEngine; 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.test.annotation.DirtiesContext; +import org.springframework.test.annotation.DirtiesContext.ClassMode; +@DirtiesContext(classMode=ClassMode.BEFORE_CLASS) public class ResourceWithSoTTest extends AAISetup { @Mock private UrlBuilder urlBuilder; @@ -78,7 +81,7 @@ public class ResourceWithSoTTest extends AAISetup { graph = TinkerGraph.open(); long currentTimeMs = System.currentTimeMillis(); - String timeNowInMs = Long.toString(currentTimeMs); + final String timeNowInMs = Long.toString(currentTimeMs); // PUT / CREATE jsonPutObj.addProperty("aai-created-ts", timeNowInMs); @@ -114,6 +117,24 @@ public class ResourceWithSoTTest extends AAISetup { createLoaderEngineSetup(); } + public void createLoaderEngineSetup() throws AAIException { + + loader = loaderFactory.createLoaderForVersion(factoryType, version); + + dbEngine = spy(new JanusGraphDBEngine(QueryStyle.TRAVERSAL, loader)); + serializer = new DBSerializer(version, dbEngine, factoryType, "Junit"); + resourceWithSoT = new ResourceWithSoT.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().withStrategies(ReadOnlyStrategy.instance())); + when(spyAdmin.getTraversalSource()).thenReturn(graph.traversal()); + } + // This test is to simulate a PUT request @Test public void testGetJsonFromVertexWithCreateVertex() throws AAIFormatVertexException, AAIException { @@ -148,24 +169,4 @@ public class ResourceWithSoTTest extends AAISetup { Optional result = resourceWithSoT.getJsonFromVertex(null); assertFalse(result.isPresent()); } - - public void createLoaderEngineSetup() throws AAIException { - - if (loader == null) { - loader = loaderFactory.createLoaderForVersion(factoryType, version); - // loader = LoaderFactory.createLoaderForVersion(factoryType, version); - dbEngine = spy(new JanusGraphDBEngine(QueryStyle.TRAVERSAL, loader)); - serializer = new DBSerializer(version, dbEngine, factoryType, "Junit"); - resourceWithSoT = new ResourceWithSoT.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().withStrategies(ReadOnlyStrategy.instance())); - when(spyAdmin.getTraversalSource()).thenReturn(graph.traversal()); - } - } }