aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-dao/src/test/java/org
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2017-02-19 10:28:42 +0200
committerMichael Lando <ml636r@att.com>2017-02-19 10:51:01 +0200
commit451a3400b76511393c62a444f588a4ed15f4a549 (patch)
treee4f5873a863d1d3e55618eab48b83262f874719d /catalog-dao/src/test/java/org
parent5abfe4e1fb5fae4bbd5fbc340519f52075aff3ff (diff)
Initial OpenECOMP SDC commit
Change-Id: I0924d5a6ae9cdc161ae17c68d3689a30d10f407b Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'catalog-dao/src/test/java/org')
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/resources/ArtifactDaoTest.java577
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/resources/AuditingDaoTest.java463
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/resources/CassandraTest.java74
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/resources/ESUsersDAOTest.java64
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/resources/TitanGenericDaoTest.java721
5 files changed, 1899 insertions, 0 deletions
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/ArtifactDaoTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/ArtifactDaoTest.java
new file mode 100644
index 0000000000..aa9d30cb12
--- /dev/null
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/ArtifactDaoTest.java
@@ -0,0 +1,577 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.resources;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import javax.annotation.Resource;
+
+import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
+import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.IGenericSearchDAO;
+import org.openecomp.sdc.be.dao.api.ResourceUploadStatus;
+import org.openecomp.sdc.be.dao.es.ElasticSearchClient;
+import org.openecomp.sdc.be.resources.api.IResourceUploader;
+import org.openecomp.sdc.be.resources.data.ESArtifactData;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.TestExecutionListeners;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
+import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
+import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
+
+import fj.data.Either;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("classpath:application-context-test.xml")
+@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class,
+ DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class }) // ,
+ // CassandraUnitTestExecutionListener.class})
+// @EmbeddedCassandra(host ="localhost", port=9042)
+public class ArtifactDaoTest {
+ private static final String TEST_IMAGES_DIRECTORY = "src/test/resources/images";
+
+ @Resource
+ ElasticSearchClient esclient;
+
+ /*
+ * @Resource(name = "artifact-dao") private IArtifactDAO artifactDAO;
+ */
+
+ @Resource(name = "resource-upload")
+ private IResourceUploader daoUploader;
+ ESArtifactData arData;
+
+ @Resource(name = "resource-dao")
+ private IGenericSearchDAO resourceDAO;
+
+ private String nodeType = "NodeType1";
+ private String nodeTypeVersion = "1.0.0";
+
+ private String nodeType2 = "NodeType2";
+ private String nodeTypeVersion2 = "1.0.1";
+
+ private String nodeType3 = "NodeType3";
+ private String nodeNypeVersion3 = "1.1.1";
+
+ private String topologyId = "topology";
+ private String topologyTemplateName = "topologyTemplate";
+ private String topologyTemplateVersion = "1.1.1";
+
+ private String nodeTypeTemplate1 = "NodeTypeTemplate1";
+ private String nodeTypeTemplate2 = "NodeTypeTemplate2";
+ private String nodeTypeTemplate3 = "NodeTypeTemplate3";
+
+ private static ConfigurationManager configurationManager;
+
+ @Before
+ public void before() {
+ // try {
+ // clearIndex(ICatalogDAO.RESOURCES_INDEX, ArtifactData.class);
+ // clearIndex(ICatalogDAO.RESOURCES_INDEX, ServiceArtifactData.class);
+ // } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+
+ }
+
+ @BeforeClass
+ public static void setupBeforeClass() {
+ ExternalConfiguration.setAppName("catalog-dao");
+ String appConfigDir = "src/test/resources/config/catalog-dao";
+ ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
+ appConfigDir);
+ configurationManager = new ConfigurationManager(configurationSource);
+ }
+
+ // @Before
+ // public void createSchema(){
+ // SdcSchemaBuilder.createSchema();
+ // }
+ //
+
+ @Test
+ public void testSaveNewArtifact() {
+ // daoUploader = new ArtifactUploader(artifactDAO);
+ if (daoUploader == null) {
+ assertTrue(false);
+ }
+ String strData = "qweqwqweqw34e4wrwer";
+
+ String myNodeType = "MyNewNodeType";
+
+ ESArtifactData arData = new ESArtifactData("artifactNewMarina11", strData.getBytes());
+
+ ResourceUploadStatus status = daoUploader.saveArtifact(arData, true);
+
+ assertEquals(status, ResourceUploadStatus.OK);
+
+ daoUploader.deleteArtifact(arData.getId());
+
+ }
+
+ /*
+ * @Test public void testSaveNewImage(){
+ *
+ * Path iconPath = Paths.get(TEST_IMAGES_DIRECTORY, "apache.png");
+ *
+ * ImageData imageData = new ImageData(); try {
+ * imageData.setData(Files.readAllBytes(iconPath));
+ * imageData.setComponentName("ComponentMarina");
+ * imageData.setComponentVersion("v.1.0");
+ * imageData.setArtifactName("apache.png");
+ * imageData.setResourceCreator("Marina");
+ * imageData.setResourceLastUpdater("Marina"); ResourceUploadStatus status =
+ * daoUploader.saveImage(imageData, true); assertEquals(status,
+ * ResourceUploadStatus.OK); } catch (IOException e) { // TODO
+ * Auto-generated catch block e.printStackTrace(); }
+ *
+ *
+ * }
+ */
+
+ // @Test
+ // public void testGetArtifactsList() {
+ // //daoUploader = new ArtifactUploader(artifactDAO);
+ // if(daoUploader==null){
+ // assertTrue(false);
+ // }
+ // String myNodeType = "MyListNodeType";
+ //
+ //
+ //
+ // //resourceDAO.save(indexedNodeType);
+ //
+ // String strData = "qweqwqweqw34e4wrwer";
+ // ESArtifactData arData1 = new ESArtifactData("artifactNewMarina_1",
+ // strData.getBytes());
+ //
+ //
+ // ResourceUploadStatus status = daoUploader.saveArtifact(arData1, true);
+ // assertEquals(status, ResourceUploadStatus.OK);
+ //
+ // ESArtifactData arData2 = new ESArtifactData("artifactNewMarina_2",
+ // strData.getBytes());
+ //
+ //
+ // status = daoUploader.saveArtifact(arData2, true);
+ // assertEquals(status, ResourceUploadStatus.OK);
+ //
+ // ESArtifactData arData3 = new ESArtifactData("artifactNewMarina_3",
+ // strData.getBytes());
+ //
+ //
+ // status = daoUploader.saveArtifact(arData3, true);
+ // assertEquals(status, ResourceUploadStatus.OK);
+ //
+ //
+ //
+ // Either<List<ESArtifactData>, ResourceUploadStatus> arrArray =
+ // daoUploader.getArtifacts(myNodeType, nodeTypeVersion);
+ // assertTrue(arrArray.isLeft());
+ //
+ // assertEquals(3, arrArray.left().value().size());
+ //
+ // daoUploader.deleteArtifact(arData1.getId());
+ // daoUploader.deleteArtifact(arData2.getId());
+ // daoUploader.deleteArtifact(arData3.getId());
+ //
+ // //resourceDAO.delete(IndexedNodeType.class, indexedNodeType.getId());
+ //
+ // }
+ //
+
+ /*
+ * @Test public void testGetSeviceArtifactsList() {
+ *
+ * if(daoUploader==null){ assertTrue(false); } String strData =
+ * "qweqwqweqw34e4wrwer";
+ *
+ * ServiceArtifactData serviceArData = new
+ * ServiceArtifactData("serviceArData", topologyTemplateName,
+ * topologyTemplateVersion, nodeTypeTemplate1, nodeType, nodeTypeVersion,
+ * "YANG", strData.getBytes(), strData.getBytes(), "Marina", null);
+ * //serviceArData.setRefArtifactId(arData.getId()); ResourceUploadStatus
+ * status = daoUploader.saveServiceArtifact(serviceArData, true);
+ *
+ * ServiceArtifactData serviceArData1 = new
+ * ServiceArtifactData("serviceArData1", topologyTemplateName,
+ * topologyTemplateVersion, nodeTypeTemplate2, nodeType2, nodeTypeVersion2,
+ * "YANG", strData.getBytes(), strData.getBytes(), "Marina", null);
+ * //serviceArData1.setRefArtifactId(arData4.getId()); status =
+ * daoUploader.saveServiceArtifact(serviceArData1, true);
+ * ServiceArtifactData getServiceData =
+ * daoUploader.getServiceArtifact(serviceArData.getId()).left().value();
+ *
+ * List<ServiceArtifactData> arrArray =
+ * daoUploader.getServiceArtifacts(topologyTemplateName,
+ * topologyTemplateVersion).left().value();
+ *
+ * assertEquals(2, arrArray.size());
+ *
+ * daoUploader.deleteArtifact(serviceArData.getId());
+ * daoUploader.deleteArtifact(serviceArData1.getId());
+ *
+ *
+ * }
+ */
+
+ @Test
+ public void testGetArtifact() {
+
+ String myNodeType = "MyNodeType";
+
+ // resourceDAO.save(indexedNodeType);
+ ESArtifactData arData = getArtifactData(myNodeType, nodeTypeVersion);
+
+ ESArtifactData getData = null;
+ Either<ESArtifactData, ResourceUploadStatus> getArtifactStatus = daoUploader
+ .getArtifact(myNodeType + "- dassasd" + ":" + nodeTypeVersion + ":updatedArtifact");
+ if (getArtifactStatus.isRight()) {
+ daoUploader.saveArtifact(arData, true);
+ getArtifactStatus = daoUploader.getArtifact(arData.getId());
+ }
+ assertNotNull(getArtifactStatus.left().value());
+
+ }
+
+ /*
+ * @Test public void testGetSeviceArtifact() {
+ *
+ * ServiceArtifactData servArData = getServiceArtifactData();
+ *
+ * Either<ServiceArtifactData, ResourceUploadStatus>
+ * getServiceArtifactStatus =
+ * daoUploader.getServiceArtifact("MyService:v.1.1:updatedServiceArtifact");
+ * if (!getServiceArtifactStatus.isLeft()){
+ * daoUploader.saveServiceArtifact(servArData, true);
+ * getServiceArtifactStatus =
+ * daoUploader.getServiceArtifact(servArData.getId()); }
+ *
+ * assertNotNull(getServiceArtifactStatus.left().value());
+ *
+ * daoUploader.deleteArtifact(getServiceArtifactStatus.left().value().getId(
+ * ));
+ *
+ *
+ * }
+ */
+
+ /*
+ * @Test public void testGetSeviceArtifactsCollection() {
+ *
+ * prepareTopolgyService(); prepareTestTopolgyService();
+ * Either<ServiceArtifactsDataCollection, ResourceUploadStatus>
+ * getServiceArtifactsCollectionStatus =
+ * daoUploader.getServiceArtifactsCollection(topologyTemplateName,
+ * topologyTemplateVersion); ServiceArtifactsDataCollection serviceAtrifacts
+ * = getServiceArtifactsCollectionStatus.left().value();
+ *
+ * Map<String, List<ArtifactData>> map =
+ * serviceAtrifacts.getServiceArtifactDataMap();
+ *
+ * List<ArtifactData> list = map.get(nodeType); assertNotNull(list);
+ * assertEquals(2, list.size());
+ *
+ *
+ * list = map.get(nodeTypeTemplate1 ); assertNotNull(list); assertEquals(1,
+ * list.size());
+ *
+ * list = map.get(nodeTypeTemplate2 ); assertNotNull(list); assertEquals(1,
+ * list.size());
+ *
+ *
+ * }
+ */
+
+ @Test
+ public void testUpdateArtifact() {
+ // daoUploader = new ArtifactUploader(artifactDAO);
+ if (daoUploader == null) {
+ assertTrue(false);
+ }
+ ResourceUploadStatus status = ResourceUploadStatus.OK;
+
+ String myNodeType = "MyUpdatedNodeType";
+
+ // resourceDAO.save(indexedNodeType);
+
+ ESArtifactData arData = getArtifactData(myNodeType, nodeTypeVersion);
+ Either<ESArtifactData, ResourceUploadStatus> getArtifactStatus = daoUploader.getArtifact(arData.getId());
+
+ if (!getArtifactStatus.isLeft())
+ status = daoUploader.saveArtifact(arData, false);
+
+ String payload1 = "new payloadjfdsgh";
+ arData.setDataAsArray(payload1.getBytes());
+
+ status = daoUploader.updateArtifact(arData);
+
+ assertEquals(status, ResourceUploadStatus.OK);
+ // resourceDAO.delete(IndexedNodeType.class, indexedNodeType.getId());
+
+ }
+
+ private ESArtifactData getArtifactData(String componentName, String componentVersion) {
+ String strData = "qweqwqweqw34e4wrwer";
+ ESArtifactData arData = new ESArtifactData("updatedArtifact", strData.getBytes());
+
+ return arData;
+ }
+
+ /*
+ * private ServiceArtifactData getServiceArtifactData(){ String strData =
+ * "qweqwqweqw34e4wrwer"; ServiceArtifactData arData = new
+ * ServiceArtifactData("updatedServiceArtifact", "MyService", "v.1.1",
+ * "MyComponentTemplate", "MyComponent", "v.1.1", "YANG",
+ * strData.getBytes(), strData.getBytes(), "Marina", null);
+ *
+ * return arData; }
+ */
+
+ /*
+ * private void prepareTopolgyService(){
+ *
+ * List<String> listCap = new ArrayList<String>(); listCap.add("very_evil");
+ * List<String> listCap1 = new ArrayList<String>(); listCap.add("evil");
+ * try{ // Initialize test data IndexedNodeType indexedNodeType = new
+ * IndexedNodeType(); CSARDependency dep = new CSARDependency();
+ * dep.setName(nodeType); dep.setVersion(nodeTypeVersion);
+ * indexedNodeType.setElementId(nodeType);
+ * indexedNodeType.setArchiveName(nodeType);
+ * indexedNodeType.setArchiveVersion(nodeTypeVersion);
+ * indexedNodeType.setCreationDate(new Date());
+ * indexedNodeType.setLastUpdateDate(new Date());
+ * indexedNodeType.setDefaultCapabilities(listCap);
+ * resourceDAO.save(indexedNodeType);
+ *
+ *
+ * IndexedNodeType indexedNodeType1 = new IndexedNodeType();
+ * indexedNodeType1.setElementId(nodeType2);
+ * indexedNodeType1.setArchiveName(nodeType2);
+ * indexedNodeType1.setArchiveVersion(nodeTypeVersion2); CSARDependency dep1
+ * = new CSARDependency(); dep1.setName(nodeType2);
+ * dep1.setVersion(nodeTypeVersion2); indexedNodeType1.setCreationDate(new
+ * Date()); indexedNodeType1.setLastUpdateDate(new Date());
+ * indexedNodeType1.setDefaultCapabilities(listCap1);
+ * resourceDAO.save(indexedNodeType1);
+ *
+ *
+ * indexedNodeType.setElementId(nodeType3);
+ * indexedNodeType.setArchiveName(nodeType3);
+ * indexedNodeType.setArchiveVersion(nodeNypeVersion3); CSARDependency dep2
+ * = new CSARDependency(); dep2.setName(nodeType3);
+ * dep2.setVersion(nodeNypeVersion3); indexedNodeType.setCreationDate(new
+ * Date()); indexedNodeType.setLastUpdateDate(new Date());
+ * indexedNodeType.setDefaultCapabilities(null);
+ * resourceDAO.save(indexedNodeType); String osgiliath100Id =
+ * indexedNodeType.getId();
+ *
+ * Topology topology = new Topology(); topology.setId(topologyId);
+ * Set<CSARDependency> dependencies = new HashSet<CSARDependency>();
+ * dependencies.add(dep); dependencies.add(dep2); dependencies.add(dep1);
+ * topology.setDependencies(dependencies); Map<String, NodeTemplate>
+ * nodeTemplates = new HashMap <String, NodeTemplate>();
+ *
+ * NodeTemplate template1 = new NodeTemplate(nodeType, null, null, null,
+ * null, null, null); template1.setName(nodeTypeTemplate1);
+ * nodeTemplates.put(nodeTypeTemplate1, template1 );
+ *
+ * NodeTemplate template2 = new NodeTemplate(nodeType2, null, null, null,
+ * null, null, null); template2.setName(nodeTypeTemplate2 );
+ * nodeTemplates.put(nodeTypeTemplate2, template2 );
+ *
+ * NodeTemplate template3 = new NodeTemplate(nodeType, null, null, null,
+ * null, null, null); template3.setName(nodeTypeTemplate3 );
+ * nodeTemplates.put(nodeTypeTemplate3, template3);
+ *
+ * topology.setNodeTemplates(nodeTemplates); resourceDAO.save(topology);
+ *
+ * TopologyTemplate topologyTemplate = new TopologyTemplate();
+ * topologyTemplate.setId(topologyTemplateName);
+ * topologyTemplate.setName(topologyTemplateName);
+ * topologyTemplate.setTopologyId(topology.getId());
+ * topologyTemplate.setDescription("my topology template");
+ * resourceDAO.save(topologyTemplate);
+ *
+ * String strData = "qweqwqweqw34e4wrwer"; ArtifactData arData = new
+ * ArtifactData("artifact1", nodeType, nodeTypeVersion, "YANG",
+ * strData.getBytes(), strData.getBytes(), "Marina"); ArtifactData arData1 =
+ * new ArtifactData("artifact2", nodeType, nodeTypeVersion, "YANG",
+ * strData.getBytes(), strData.getBytes(), "Marina"); ResourceUploadStatus
+ * status = daoUploader.saveArtifact(arData, true); status =
+ * daoUploader.saveArtifact(arData1, true);
+ *
+ * ArtifactData arData3 = new ArtifactData("artifact1", nodeType2,
+ * nodeTypeVersion2, "YANG", strData.getBytes(), strData.getBytes(),
+ * "Marina"); status = daoUploader.saveArtifact(arData3, true);
+ *
+ * ArtifactData arData4 = new ArtifactData("artifact2", nodeType2,
+ * nodeTypeVersion2, "YANG", strData.getBytes(), strData.getBytes(),
+ * "Marina"); status = daoUploader.saveArtifact(arData4, true);
+ *
+ * ServiceArtifactData serviceArData = new
+ * ServiceArtifactData("serviceArData", topologyTemplateName,
+ * topologyTemplateVersion, nodeTypeTemplate1, nodeType, nodeTypeVersion,
+ * "YANG", strData.getBytes(), strData.getBytes(), "Marina",
+ * arData.getId());
+ *
+ * status = daoUploader.saveServiceArtifact(serviceArData, true);
+ *
+ * ServiceArtifactData serviceArData1 = new
+ * ServiceArtifactData("serviceArData1", topologyTemplateName,
+ * topologyTemplateVersion, nodeTypeTemplate2, nodeType2, nodeTypeVersion2,
+ * "YANG", strData.getBytes(), strData.getBytes(), "Marina",
+ * arData4.getId());
+ *
+ * status = daoUploader.saveServiceArtifact(serviceArData1, true);
+ *
+ *
+ * } catch (Exception e) { // TODO Auto-generated catch block
+ * e.printStackTrace(); }
+ *
+ * }
+ *
+ * private void prepareTestTopolgyService(){
+ *
+ * List<String> listCap = new ArrayList<String>();
+ * listCap.add("very_evil test"); List<String> listCap1 = new
+ * ArrayList<String>(); listCap.add("evil test"); try{ // Initialize test
+ * data IndexedNodeType indexedNodeType = new IndexedNodeType();
+ * CSARDependency dep = new CSARDependency(); dep.setName(nodeType +
+ * " test"); dep.setVersion(nodeTypeVersion);
+ * indexedNodeType.setElementId(nodeType + " test");
+ * indexedNodeType.setArchiveName(nodeType + " test");
+ * indexedNodeType.setArchiveVersion(nodeTypeVersion);
+ * indexedNodeType.setCreationDate(new Date());
+ * indexedNodeType.setLastUpdateDate(new Date());
+ * indexedNodeType.setDefaultCapabilities(listCap);
+ * resourceDAO.save(indexedNodeType);
+ *
+ *
+ * IndexedNodeType indexedNodeType1 = new IndexedNodeType();
+ * indexedNodeType1.setElementId(nodeType2 + " test");
+ * indexedNodeType1.setArchiveName(nodeType2 + " test");
+ * indexedNodeType1.setArchiveVersion(nodeTypeVersion2); CSARDependency dep1
+ * = new CSARDependency(); dep1.setName(nodeType2 + " test");
+ * dep1.setVersion(nodeTypeVersion2); indexedNodeType1.setCreationDate(new
+ * Date()); indexedNodeType1.setLastUpdateDate(new Date());
+ * indexedNodeType1.setDefaultCapabilities(listCap1);
+ * resourceDAO.save(indexedNodeType1);
+ *
+ *
+ * indexedNodeType.setElementId(nodeType3 + " test");
+ * indexedNodeType.setArchiveName(nodeType3 + " test");
+ * indexedNodeType.setArchiveVersion(nodeNypeVersion3); CSARDependency dep2
+ * = new CSARDependency(); dep2.setName(nodeType3 + " test");
+ * dep2.setVersion(nodeNypeVersion3); indexedNodeType.setCreationDate(new
+ * Date()); indexedNodeType.setLastUpdateDate(new Date());
+ * indexedNodeType.setDefaultCapabilities(null);
+ * resourceDAO.save(indexedNodeType); String osgiliath100Id =
+ * indexedNodeType.getId();
+ *
+ * Topology topology = new Topology(); topology.setId(topologyId + " test");
+ * Set<CSARDependency> dependencies = new HashSet<CSARDependency>();
+ * dependencies.add(dep); dependencies.add(dep2); dependencies.add(dep1);
+ * topology.setDependencies(dependencies); Map<String, NodeTemplate>
+ * nodeTemplates = new HashMap <String, NodeTemplate>();
+ *
+ * NodeTemplate template1 = new NodeTemplate(nodeType + " test", null, null,
+ * null, null, null, null); template1.setName(nodeTypeTemplate1 + " test");
+ * nodeTemplates.put(nodeTypeTemplate1 + " test", template1 );
+ *
+ * NodeTemplate template2 = new NodeTemplate(nodeType2 + " test", null,
+ * null, null, null, null, null); template2.setName(nodeTypeTemplate2 +
+ * " test" ); nodeTemplates.put(nodeTypeTemplate2 + " test", template2 );
+ *
+ * NodeTemplate template3 = new NodeTemplate(nodeType, null, null, null,
+ * null, null, null); template3.setName(nodeTypeTemplate3 + " test" );
+ * nodeTemplates.put(nodeTypeTemplate3 + " test", template3);
+ *
+ * topology.setNodeTemplates(nodeTemplates); resourceDAO.save(topology);
+ *
+ * TopologyTemplate topologyTemplate = new TopologyTemplate();
+ * topologyTemplate.setId(topologyTemplateName + " test");
+ * topologyTemplate.setName(topologyTemplateName + " test");
+ * topologyTemplate.setTopologyId(topology.getId());
+ * topologyTemplate.setDescription("my topology template");
+ * resourceDAO.save(topologyTemplate);
+ *
+ * String strData = "qweqwqweqw34e4wrwer"; ArtifactData arData = new
+ * ArtifactData("artifact1 test", nodeType + " test", nodeTypeVersion,
+ * "YANG", strData.getBytes(), strData.getBytes(), "Marina"); ArtifactData
+ * arData1 = new ArtifactData("artifact2 test", nodeType + " test",
+ * nodeTypeVersion, "YANG", strData.getBytes(), strData.getBytes(),
+ * "Marina"); ResourceUploadStatus status = daoUploader.saveArtifact(arData,
+ * true); status = daoUploader.saveArtifact(arData1, true);
+ *
+ * ArtifactData arData3 = new ArtifactData("artifact1 test", nodeType2 +
+ * " test", nodeTypeVersion2, "YANG", strData.getBytes(),
+ * strData.getBytes(), "Marina"); status = daoUploader.saveArtifact(arData3,
+ * true);
+ *
+ * ArtifactData arData4 = new ArtifactData("artifact2 test", nodeType2 +
+ * " test", nodeTypeVersion2, "YANG", strData.getBytes(),
+ * strData.getBytes(), "Marina"); status = daoUploader.saveArtifact(arData4,
+ * true);
+ *
+ * ServiceArtifactData serviceArData = new
+ * ServiceArtifactData("serviceArData test" , topologyTemplateName +
+ * " test", topologyTemplateVersion, nodeTypeTemplate1 + " test", nodeType +
+ * " test", nodeTypeVersion, "YANG", strData.getBytes(), strData.getBytes(),
+ * "Marina", arData.getId());
+ *
+ * status = daoUploader.saveServiceArtifact(serviceArData, true);
+ *
+ * ServiceArtifactData serviceArData1 = new
+ * ServiceArtifactData("serviceArData1 test", topologyTemplateName +
+ * " test", topologyTemplateVersion, nodeTypeTemplate2 + " test", nodeType2
+ * + " test", nodeTypeVersion2, "YANG", strData.getBytes(),
+ * strData.getBytes(), "Marina", arData4.getId());
+ *
+ * status = daoUploader.saveServiceArtifact(serviceArData1, true);
+ *
+ *
+ * } catch (Exception e) { // TODO Auto-generated catch block
+ * e.printStackTrace(); }
+ *
+ * }
+ */
+
+ private void clearIndex(String indexName, Class<?> clazz) throws InterruptedException {
+
+ DeleteIndexResponse actionGet = esclient.getClient().admin().indices().delete(new DeleteIndexRequest(indexName))
+ .actionGet();
+ assertTrue(actionGet.isAcknowledged());
+ }
+
+}
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/AuditingDaoTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/AuditingDaoTest.java
new file mode 100644
index 0000000000..06d26f79f9
--- /dev/null
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/AuditingDaoTest.java
@@ -0,0 +1,463 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.resources;
+
+import fj.data.Either;
+import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
+import org.elasticsearch.action.search.SearchResponse;
+import org.elasticsearch.index.query.MatchAllQueryBuilder;
+import org.elasticsearch.search.SearchHit;
+import org.elasticsearch.search.SearchHits;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openecomp.sdc.be.config.Configuration;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.config.Configuration.ElasticSearchConfig.IndicesTimeFrequencyEntry;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.dao.es.ElasticSearchClient;
+import org.openecomp.sdc.be.dao.impl.AuditingDao;
+import org.openecomp.sdc.be.resources.data.auditing.*;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+import org.openecomp.sdc.common.datastructure.ESTimeBasedEvent;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.TestExecutionListeners;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
+import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
+import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import static org.junit.Assert.*;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("classpath:application-context-test.xml")
+@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class,
+ DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class })
+public class AuditingDaoTest {
+ private static Logger log = LoggerFactory.getLogger(AuditingDaoTest.class.getName());
+ @Resource(name = "elasticsearch-client")
+ private ElasticSearchClient esclient;
+
+ @Resource(name = "auditingDao")
+ private AuditingDao auditingDao;
+
+ private static ConfigurationManager configurationManager;
+ // private static Map<AuditingFieldsKeysEnum, String> auditField2esField;
+
+ @BeforeClass
+ public static void setupBeforeClass() {
+
+ ExternalConfiguration.setAppName("catalog-dao");
+ String appConfigDir = "src/test/resources/config/catalog-dao";
+ ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
+ appConfigDir);
+ configurationManager = new ConfigurationManager(configurationSource);
+ // initAudit2EsMap();
+ }
+
+ @After
+ public void tearDown() {
+ deleteOldIndexes();
+ }
+
+ @Before
+ public void setup() {
+ auditingDao.setConfigurationManager(configurationManager);
+ deleteOldIndexes();
+ }
+
+ private void deleteOldIndexes() {
+ DeleteIndexResponse deleteResponse = esclient.getClient().admin().indices()
+ .prepareDelete(auditingDao.getIndexPrefix() + "*").execute().actionGet();
+ if (!deleteResponse.isAcknowledged()) {
+ log.debug("Couldn't delete old auditing indexes!");
+ assertTrue(false);
+ }
+ }
+
+ // @Test
+ public void testAddUpdateAdminEventMinute() {
+
+ String timestamp = "2015-06-23 13:34:53.123";
+
+ String creationPeriod = Constants.MINUTE;
+ String expectedIndexName = auditingDao.getIndexPrefix() + "-2015-06-23-13-34";
+ assertTrue(!esclient.getClient().admin().indices().prepareExists(expectedIndexName).execute().actionGet()
+ .isExists());
+ Map<AuditingFieldsKeysEnum, Object> params = getUserAdminEventParams(timestamp);
+ testCreationPeriodScenario(params, creationPeriod, expectedIndexName, UserAdminEvent.class);
+ params = getUserAccessEventParams(timestamp);
+ testCreationPeriodScenario(params, creationPeriod, expectedIndexName, UserAccessEvent.class);
+ params = getResourceAdminEventParams(timestamp, "addResource");
+ testCreationPeriodScenario(params, creationPeriod, expectedIndexName, ResourceAdminEvent.class);
+ }
+
+ // @Test
+ public void testAddUpdateAdminEventYearly() {
+
+ String timestamp = "2016-06-23 13:34:53.123";
+ String creationPeriod = Constants.YEAR;
+ String expectedIndexName = auditingDao.getIndexPrefix() + "-2016";
+ assertTrue(!esclient.getClient().admin().indices().prepareExists(expectedIndexName).execute().actionGet()
+ .isExists());
+ Map<AuditingFieldsKeysEnum, Object> params = getUserAdminEventParams(timestamp);
+ testCreationPeriodScenario(params, creationPeriod, expectedIndexName, UserAdminEvent.class);
+ params = getUserAccessEventParams(timestamp);
+ testCreationPeriodScenario(params, creationPeriod, expectedIndexName, UserAccessEvent.class);
+ params = getResourceAdminEventParams(timestamp, "addResource");
+ testCreationPeriodScenario(params, creationPeriod, expectedIndexName, ResourceAdminEvent.class);
+ }
+
+ @Test
+ public void testGetDistributionStatusEvent() {
+
+ String timestamp1 = "2016-06-23 13:34:53.123";
+ String creationPeriod = Constants.MONTH;
+ String expectedIndexName1 = auditingDao.getIndexPrefix() + "-2016-06";
+ assertTrue(!esclient.getClient().admin().indices().prepareExists(expectedIndexName1).execute().actionGet()
+ .isExists());
+ Map<AuditingFieldsKeysEnum, Object> params = getDistributionStatusEventParams(timestamp1);
+ testCreationPeriodScenario(params, creationPeriod, expectedIndexName1, DistributionStatusEvent.class);
+ String timestamp2 = "2015-06-23 13:34:53.123";
+
+ String expectedIndexName2 = auditingDao.getIndexPrefix() + "-2015-06";
+ assertTrue(!esclient.getClient().admin().indices().prepareExists(expectedIndexName2).execute().actionGet()
+ .isExists());
+ Map<AuditingFieldsKeysEnum, Object> params2 = getDistributionStatusEventParams(timestamp2);
+ testCreationPeriodScenario(params2, creationPeriod, expectedIndexName2, DistributionStatusEvent.class);
+ Either<List<ESTimeBasedEvent>, ActionStatus> status = auditingDao.getListOfDistributionStatuses("123-456");
+ assertEquals(2, status.left().value().size());
+ }
+
+ @Test
+ public void testGetCountAdminEventMonthly() {
+
+ String timestamp1 = "2016-06-23 13:34:53.123";
+ String timestamp2 = "2015-06-23 13:34:53.123";
+ String creationPeriod = Constants.MONTH;
+ String expectedIndexName1 = auditingDao.getIndexPrefix() + "-2016-06";
+ assertTrue(!esclient.getClient().admin().indices().prepareExists(expectedIndexName1).execute().actionGet()
+ .isExists());
+ String expectedIndexName2 = auditingDao.getIndexPrefix() + "-2015-06";
+ assertTrue(!esclient.getClient().admin().indices().prepareExists(expectedIndexName2).execute().actionGet()
+ .isExists());
+
+ Map<AuditingFieldsKeysEnum, Object> params1 = getUserAdminEventParams(timestamp1);
+ testCreationPeriodScenario(params1, creationPeriod, expectedIndexName1, UserAdminEvent.class);
+ Map<AuditingFieldsKeysEnum, Object> params2 = getUserAdminEventParams(timestamp2);
+ testCreationPeriodScenario(params2, creationPeriod, expectedIndexName2, UserAdminEvent.class);
+
+ long count = auditingDao.count(UserAdminEvent.class, new MatchAllQueryBuilder());
+ log.debug("Testing auditing count {}", count);
+ assertEquals(2, count);
+ }
+
+ @Test
+ public void testServiceDistributionStatuses() {
+
+ String timestamp = "2016-06-23 13:34:53.123";
+ String creationPeriod = Constants.MONTH;
+ String expectedIndexName = auditingDao.getIndexPrefix() + "-2016-06";
+ assertTrue(!esclient.getClient().admin().indices().prepareExists(expectedIndexName).execute().actionGet()
+ .isExists());
+ Map<AuditingFieldsKeysEnum, Object> params = getUserAdminEventParams(timestamp);
+ testCreationPeriodScenario(params, creationPeriod, expectedIndexName, UserAdminEvent.class);
+ params = getUserAccessEventParams(timestamp);
+ testCreationPeriodScenario(params, creationPeriod, expectedIndexName, UserAccessEvent.class);
+ params = getResourceAdminEventParams(timestamp, "DRequest");
+ testCreationPeriodScenario(params, creationPeriod, expectedIndexName, ResourceAdminEvent.class);
+ params = getDistributionNotificationEventParams(timestamp);
+ testCreationPeriodScenario(params, creationPeriod, expectedIndexName, DistributionNotificationEvent.class);
+ Either<List<ESTimeBasedEvent>, ActionStatus> status = auditingDao
+ .getServiceDistributionStatusesList("SeviceId");
+ log.debug("Testing auditing count {}", status);
+ }
+
+ @Test
+ public void testAddUpdateAdminEventMonthly() {
+
+ String timestamp = "2016-06-23 13:34:53.123";
+ String creationPeriod = Constants.MONTH;
+ String expectedIndexName = auditingDao.getIndexPrefix() + "-2016-06";
+ assertTrue(!esclient.getClient().admin().indices().prepareExists(expectedIndexName).execute().actionGet()
+ .isExists());
+ Map<AuditingFieldsKeysEnum, Object> params = getUserAdminEventParams(timestamp);
+ testCreationPeriodScenario(params, creationPeriod, expectedIndexName, UserAdminEvent.class);
+ params = getUserAccessEventParams(timestamp);
+ testCreationPeriodScenario(params, creationPeriod, expectedIndexName, UserAccessEvent.class);
+ params = getResourceAdminEventParams(timestamp, "addResource");
+ testCreationPeriodScenario(params, creationPeriod, expectedIndexName, ResourceAdminEvent.class);
+ }
+
+ private SearchResponse testCreationPeriodScenario(Map<AuditingFieldsKeysEnum, Object> params, String creationPeriod,
+ String expectedIndexName, Class<? extends AuditingGenericEvent> clazz) {
+
+ String typeName = clazz.getSimpleName().toLowerCase();
+ log.debug("Testing auditing type {}", typeName);
+ setCreationPeriod(creationPeriod);
+ ActionStatus saveUserAdminEvent = auditingDao.addRecord(params, typeName);
+ assertEquals(ActionStatus.OK, saveUserAdminEvent);
+ assertTrue(esclient.getClient().admin().indices().prepareExists(expectedIndexName).execute().actionGet()
+ .isExists());
+ MatchAllQueryBuilder matchAllQueryBuilder = new MatchAllQueryBuilder();
+
+ SearchResponse searchResponse = esclient.getClient().prepareSearch(expectedIndexName).setTypes(typeName)
+ .setQuery(matchAllQueryBuilder).execute().actionGet();
+
+ SearchHits hits = searchResponse.getHits();
+ assertEquals(1, hits.getTotalHits());
+ log.debug("Checking that all expected fields are properly persisted");
+ validateHitValues(params, hits.getAt(0));
+ log.debug("testCreationPeriodScenario successful");
+ return searchResponse;
+ }
+
+ private void validateHitValues(Map<AuditingFieldsKeysEnum, Object> params, SearchHit searchHit) {
+ Map<String, Object> source = searchHit.getSource();
+ log.debug("Hit source is {}", searchHit.sourceAsString());
+ for (Entry<AuditingFieldsKeysEnum, Object> paramsEntry : params.entrySet()) {
+ AuditingFieldsKeysEnum key = paramsEntry.getKey();
+ log.debug("Testing auditing field {}", key.name());
+ Object value = paramsEntry.getValue();
+ // assertEquals(value, source.get(auditField2esField.get(key)));
+ assertEquals(value, source.get(key.getDisplayName()));
+ }
+ }
+
+ private void setCreationPeriod(String creationPeriod) {
+ Configuration configuration = configurationManager.getConfiguration();
+ List<IndicesTimeFrequencyEntry> indicesTimeFrequencyEntries = new ArrayList<>();
+ IndicesTimeFrequencyEntry indicesTimeFrequencyEntry = new IndicesTimeFrequencyEntry();
+ indicesTimeFrequencyEntry.setIndexPrefix("auditingevents");
+ indicesTimeFrequencyEntry.setCreationPeriod(creationPeriod);
+ configuration.getElasticSearch().setIndicesTimeFrequency(indicesTimeFrequencyEntries);
+ }
+
+ private Map<AuditingFieldsKeysEnum, Object> getUserAdminEventParams(String timestamp) {
+
+ Map<AuditingFieldsKeysEnum, Object> params = new HashMap<AuditingFieldsKeysEnum, Object>();
+ String action = "updateUser";
+ String modifierName = "moshe moshe";
+ String modifierUid = "mosheUid";
+ String userUid = "mosheUid";
+ String userBeforeName = "moshe moshe";
+ String userBeforeEmail = "moshe@moshe1.com";
+ String userBeforeRole = "TESTER";
+ String userAfterName = "moshe moshe";
+ String userAfterEmail = "moshe@moshe2.com";
+ String userAfterRole = "TESTER";
+ String userStatus = "200";
+ String userDesc = "OK";
+
+ params.put(AuditingFieldsKeysEnum.AUDIT_ACTION, action);
+ params.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID, modifierName + '(' + modifierUid + ')');
+ params.put(AuditingFieldsKeysEnum.AUDIT_USER_UID, userUid);
+ params.put(AuditingFieldsKeysEnum.AUDIT_USER_BEFORE,
+ userUid + ", " + userBeforeName + ", " + userBeforeEmail + ", " + userBeforeRole);
+ params.put(AuditingFieldsKeysEnum.AUDIT_USER_AFTER,
+ userUid + ", " + userAfterName + ", " + userAfterEmail + ", " + userAfterRole);
+ params.put(AuditingFieldsKeysEnum.AUDIT_STATUS, userStatus);
+ params.put(AuditingFieldsKeysEnum.AUDIT_DESC, userDesc);
+ params.put(AuditingFieldsKeysEnum.AUDIT_TIMESTAMP, timestamp);
+
+ return params;
+ }
+
+ private Map<AuditingFieldsKeysEnum, Object> getUserAccessEventParams(String timestamp) {
+
+ Map<AuditingFieldsKeysEnum, Object> params = new HashMap<AuditingFieldsKeysEnum, Object>();
+ String action = "userAccess";
+ String userUid = "mosheUid";
+ String userName = "moshe moshe";
+ String userStatus = "200";
+ String userDesc = "OK";
+
+ params.put(AuditingFieldsKeysEnum.AUDIT_ACTION, action);
+ params.put(AuditingFieldsKeysEnum.AUDIT_USER_UID, userName + '(' + userUid + ')');
+ params.put(AuditingFieldsKeysEnum.AUDIT_STATUS, userStatus);
+ params.put(AuditingFieldsKeysEnum.AUDIT_DESC, userDesc);
+ params.put(AuditingFieldsKeysEnum.AUDIT_TIMESTAMP, timestamp);
+
+ return params;
+ }
+
+ private Map<AuditingFieldsKeysEnum, Object> getResourceAdminEventParams(String timestamp, String action) {
+
+ Map<AuditingFieldsKeysEnum, Object> params = new HashMap<AuditingFieldsKeysEnum, Object>();
+
+ String modifierName = "moshe moshe";
+ String modifierUid = "mosheUid";
+ String resourceName = "Centos";
+ String resourceType = "Resource";
+ String currState = "READY_FOR_CERTIFICATION";
+ String prevState = "CHECKED_OUT";
+ String currVersion = "1.1.4";
+ String prevVersion = "1.1.3";
+ String status = "200";
+ String desc = "OK";
+ String distributionId = "123-456";
+ String serviceId = "SeviceId";
+
+ params.put(AuditingFieldsKeysEnum.AUDIT_ACTION, action);
+ params.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_NAME, modifierName);
+ params.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID, modifierUid);
+ params.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resourceName);
+ params.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_TYPE, resourceType);
+ params.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_STATE, currState);
+ params.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_PREV_STATE, prevState);
+ params.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_VERSION, currVersion);
+ params.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_PREV_VERSION, prevVersion);
+ params.put(AuditingFieldsKeysEnum.AUDIT_STATUS, status);
+ params.put(AuditingFieldsKeysEnum.AUDIT_DESC, desc);
+ params.put(AuditingFieldsKeysEnum.AUDIT_TIMESTAMP, timestamp);
+ params.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ID, distributionId);
+ params.put(AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID, serviceId);
+
+ return params;
+ }
+
+ private Map<AuditingFieldsKeysEnum, Object> getDistributionStatusEventParams(String timestamp) {
+
+ Map<AuditingFieldsKeysEnum, Object> params = new HashMap<AuditingFieldsKeysEnum, Object>();
+ String action = "DStatus";
+ String modifierName = "moshe moshe";
+ String modifierUid = "mosheUid";
+ String topicName = "Centos";
+ String serviceId = "SeviceId";
+ String resourceUrl = "resourceUrl";
+ String distributionId = "123-456";
+
+ String status = "200";
+ String desc = "OK";
+
+ params.put(AuditingFieldsKeysEnum.AUDIT_DESC, desc);
+ params.put(AuditingFieldsKeysEnum.AUDIT_TIMESTAMP, timestamp);
+ params.put(AuditingFieldsKeysEnum.AUDIT_STATUS, status);
+ params.put(AuditingFieldsKeysEnum.AUDIT_ACTION, action);
+ params.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ID, distributionId);
+ params.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_CONSUMER_ID, modifierUid);
+ params.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_TOPIC_NAME, topicName);
+ params.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_RESOURCE_URL, resourceUrl);
+ params.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_STATUS_TIME, timestamp);
+ params.put(AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID, serviceId);
+
+ return params;
+ }
+
+ // @Test
+ public void getListOfDistributionByActionTest() {
+
+ String timestamp = "2016-06-23 13:34:53.123";
+ String distributionId = "123-456";
+
+ String creationPeriod = Constants.MONTH;
+ String expectedIndexName = auditingDao.getIndexPrefix() + "-2016-06";
+ assertTrue(!esclient.getClient().admin().indices().prepareExists(expectedIndexName).execute().actionGet()
+ .isExists());
+
+ // Client client = esclient.getClient();
+ // final CreateIndexRequestBuilder createIndexRequestBuilder =
+ // client.admin().indices().prepareCreate(expectedIndexName);
+ // final XContentBuilder mappingBuilder =
+ // jsonBuilder().startObject().startObject("resourceadminevent")
+ // .startObject("_ttl").field("enabled", "true").field("default",
+ // "1s").endObject().endObject()
+ // .endObject();
+ // System.out.println(mappingBuilder.string());
+ // createIndexRequestBuilder.addMapping(documentType, mappingBuilder);
+ //
+ // // MAPPING DONE
+ // createIndexRequestBuilder.execute().actionGet();
+ //
+ //
+
+ Map<AuditingFieldsKeysEnum, Object> params = getResourceAdminEventParams(timestamp, "DRequest");
+ params.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ID, distributionId);
+ testCreationPeriodScenario(params, creationPeriod, expectedIndexName, ResourceAdminEvent.class);
+ params = getDistributionNotificationEventParams(timestamp);
+ params.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ID, distributionId);
+
+ testCreationPeriodScenario(params, creationPeriod, expectedIndexName, DistributionNotificationEvent.class);
+
+ Either<List<ESTimeBasedEvent>, ActionStatus> distributionByAction = auditingDao
+ .getListOfDistributionByAction(distributionId, "DRequest", "200", ResourceAdminEvent.class);
+ assertTrue(distributionByAction.isLeft());
+ assertFalse(distributionByAction.left().value().isEmpty());
+
+ distributionByAction = auditingDao.getListOfDistributionByAction(distributionId, "DNotify", "200",
+ DistributionNotificationEvent.class);
+ assertTrue(distributionByAction.isLeft());
+ assertFalse(distributionByAction.left().value().isEmpty());
+
+ }
+
+ private Map<AuditingFieldsKeysEnum, Object> getDistributionNotificationEventParams(String timestamp) {
+
+ Map<AuditingFieldsKeysEnum, Object> params = new HashMap<AuditingFieldsKeysEnum, Object>();
+
+ String action = "DNotify";
+ String modifierName = "moshe moshe";
+ String modifierUid = "mosheUid";
+ String resourceName = "Centos";
+ String resourceType = "Resource";
+
+ String currVersion = "1.1.4";
+ String currState = "READY_FOR_CERTIFICATION";
+ String status = "200";
+ String desc = "OK";
+ String did = "1027";
+ String topicName = "Centos";
+ String serviceId = "SeviceId";
+ String requestId = "12364";
+
+ params.put(AuditingFieldsKeysEnum.AUDIT_ACTION, action);
+ params.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_NAME, requestId);
+ params.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_UID, modifierUid);
+ params.put(AuditingFieldsKeysEnum.AUDIT_MODIFIER_NAME, modifierName);
+ params.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_NAME, resourceName);
+ params.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_TYPE, resourceType);
+ params.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_STATE, currState);
+ params.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_TOPIC_NAME, topicName);
+ params.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_VERSION, currVersion);
+ params.put(AuditingFieldsKeysEnum.AUDIT_STATUS, status);
+ params.put(AuditingFieldsKeysEnum.AUDIT_DESC, desc);
+ params.put(AuditingFieldsKeysEnum.AUDIT_TIMESTAMP, timestamp);
+ params.put(AuditingFieldsKeysEnum.AUDIT_DISTRIBUTION_ID, did);
+ params.put(AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID, serviceId);
+ return params;
+ }
+
+}
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/CassandraTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/CassandraTest.java
new file mode 100644
index 0000000000..caaf0702a5
--- /dev/null
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/CassandraTest.java
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.resources;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Session;
+import com.datastax.driver.mapping.Mapper;
+import com.datastax.driver.mapping.MappingManager;
+
+import org.openecomp.sdc.be.dao.Account;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CassandraTest {
+ private static Logger log = LoggerFactory.getLogger(CassandraTest.class.getName());
+ private Cluster cluster;
+
+ // #\@Test
+ public void testCrud() {
+ String node = "mtanjv9sdcg44";
+
+ cluster = Cluster.builder().addContactPoint(node).build();
+
+ // Query
+ String query = "CREATE KEYSPACE IF NOT EXISTS dstest WITH replication "
+ + "= {'class':'SimpleStrategy', 'replication_factor':1};";
+
+ String queryTable = "CREATE TABLE IF NOT EXISTS accounts(email varchar PRIMARY KEY, name varchar);";
+
+ Session session = cluster.connect();
+ // Executing the query
+ session.execute(query);
+ // //using the KeySpace
+ session.execute("USE dstest");
+ session.execute(queryTable);
+
+ Mapper<Account> mapper = new MappingManager(session).mapper(Account.class);
+ Account account = new Account("John Doe", "jd@example.com");
+ // Class<? extends Account> class1 = account.getClass();
+ // Class class2 = Account.class;
+ mapper.save(account);
+
+ Account whose = mapper.get("jd@example.com");
+ log.debug("Account name: {}", whose.getName());
+
+ account.setName("Samanta Smit");
+ mapper.save(account);
+ whose = mapper.get("jd@example.com");
+ log.debug("Account name: {}", whose.getName());
+
+ mapper.delete(account);
+ whose = mapper.get("jd@example.com");
+
+ cluster.close();
+ }
+}
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/ESUsersDAOTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/ESUsersDAOTest.java
new file mode 100644
index 0000000000..a99acbe2b7
--- /dev/null
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/ESUsersDAOTest.java
@@ -0,0 +1,64 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.resources;
+
+//@RunWith(SpringJUnit4ClassRunner.class)
+//@ContextConfiguration("classpath:application-context-test.xml")
+//@TestExecutionListeners(listeners = {DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class})
+public class ESUsersDAOTest {
+
+ // @Resource
+ // ElasticSearchClient esclient;
+ //
+ //// @Resource(name = "users-dao")
+ // private IUsersDAO usersDao;
+
+ // @Test
+ public void testNewUserStub() {
+
+ }
+
+ // @Test
+ public void testNewUser() {
+ // if( usersDao == null ){
+ // assertTrue(false);
+ // }
+ //
+ // String id = "yhufksd57834601";
+ // UserData userData = new UserData("Myname", "Mylastname", id, "email",
+ // "Tester");
+ //
+ // ActionStatus saveUserData = usersDao.saveUserData(userData);
+ // assertEquals(saveUserData, ActionStatus.OK);
+ //
+ // Either<UserData, ActionStatus> statusFromEs =
+ // usersDao.getUserData(id);
+ // assertTrue(statusFromEs.isLeft() );
+ // UserData fromEs = statusFromEs.left().value();
+ // assertNotNull(fromEs);
+ // assertEquals(userData, fromEs);
+ //
+ //
+ // usersDao.deleteUserData(id);
+
+ }
+
+}
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/TitanGenericDaoTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/TitanGenericDaoTest.java
new file mode 100644
index 0000000000..a4110f5be3
--- /dev/null
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/TitanGenericDaoTest.java
@@ -0,0 +1,721 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.resources;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+
+import org.apache.commons.configuration.BaseConfiguration;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
+import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
+import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.dao.utils.UserStatusEnum;
+import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
+import org.openecomp.sdc.be.resources.data.AdditionalInfoParameterData;
+import org.openecomp.sdc.be.resources.data.ArtifactData;
+import org.openecomp.sdc.be.resources.data.ComponentInstanceData;
+import org.openecomp.sdc.be.resources.data.GraphNodeLock;
+import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
+import org.openecomp.sdc.be.resources.data.UserData;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.api.UserRoleEnum;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.TestExecutionListeners;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
+import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
+import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
+
+import com.google.gson.Gson;
+import com.thinkaurelius.titan.core.PropertyKey;
+import com.thinkaurelius.titan.core.TitanEdge;
+import com.thinkaurelius.titan.core.TitanFactory;
+import com.thinkaurelius.titan.core.TitanGraph;
+import com.thinkaurelius.titan.core.TitanVertex;
+import com.thinkaurelius.titan.core.attribute.Text;
+import com.thinkaurelius.titan.core.schema.TitanManagement;
+
+import fj.data.Either;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("classpath:application-context-test.xml")
+@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class,
+ DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class })
+public class TitanGenericDaoTest {
+ private static Logger log = LoggerFactory.getLogger(TitanGenericDaoTest.class.getName());
+ private static ConfigurationManager configurationManager;
+
+ @Resource(name = "titan-generic-dao")
+ private TitanGenericDao titanDao;
+
+ @BeforeClass
+ public static void setupBeforeClass() {
+ ExternalConfiguration.setAppName("catalog-dao");
+ String appConfigDir = "src/test/resources/config/catalog-dao";
+ ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
+ appConfigDir);
+ configurationManager = new ConfigurationManager(configurationSource);
+ configurationManager.getConfiguration()
+ .setTitanCfgFile("../catalog-be/src/main/resources/config/titan.properties");
+ configurationManager.getConfiguration().setTitanInMemoryGraph(true);
+ }
+
+ // @Test
+ public void testcheckEdgeProps() {
+ TitanGraph graph = titanDao.getGraph().left().value();
+ TitanVertex v1 = graph.addVertex();
+ v1.property("prop1", 123);
+ TitanVertex v2 = graph.addVertex();
+ v2.property("prop1", 456);
+ TitanEdge addEdge = v1.addEdge("label11", v2);
+ addEdge.property("edgeProp", "my prop edge");
+ graph.tx().commit();
+
+ Either<TitanVertex, TitanOperationStatus> v11 = titanDao.getVertexByProperty("prop1", 123);
+ Iterator<Edge> edges = v11.left().value().edges(Direction.OUT, "label11");
+ Edge edge = edges.next();
+ // String value = (String)edge.value("edgeProp");
+ String value = (String) titanDao.getProperty(edge, "edgeProp");
+ log.debug(value);
+
+ }
+
+ @Test
+ public void testCrudNode() {
+
+ String id = "user12345abc";
+ UserData userData = new UserData("Myname123", "Mylastname", id, "email123", "Tester",
+ UserStatusEnum.ACTIVE.name(), null);
+
+ Either<UserData, TitanOperationStatus> newNode = titanDao.createNode(userData, UserData.class);
+
+ assertTrue(newNode.isLeft());
+
+ log.debug("{}", newNode.left().value());
+
+ titanDao.commit();
+
+ ImmutablePair<String, Object> keyValueId = userData.getKeyValueId();
+ Either<UserData, TitanOperationStatus> node = titanDao.getNode(keyValueId.getKey(), keyValueId.getValue(),
+ UserData.class);
+ titanDao.commit();
+ assertTrue(node.isLeft());
+ log.debug("{}", node.left().value());
+
+ userData.setRole("Designer");
+ node = titanDao.updateNode(userData, UserData.class);
+ assertTrue(node.isLeft());
+ log.debug("{}", node.left().value());
+ assertEquals(null, "Designer", node.left().value().getRole());
+ titanDao.commit();
+
+ node = titanDao.deleteNode(userData, UserData.class);
+ assertTrue(node.isLeft());
+ log.debug("{}", node.left().value());
+ titanDao.commit();
+
+ node = titanDao.getNode(keyValueId.getKey(), keyValueId.getValue(), UserData.class);
+ assertTrue(node.isRight());
+ log.debug("{}", node.right().value());
+
+ }
+
+ @Test
+ public void testGetByCategoryAndAll() {
+
+ // create 2 nodes
+ String id = "user12345abc";
+ UserData userData1 = new UserData("Myname123", "Mylastname", id, "email123", "Tester",
+ UserStatusEnum.ACTIVE.name(), null);
+
+ Either<UserData, TitanOperationStatus> node1 = titanDao.createNode(userData1, UserData.class);
+ assertTrue(node1.isLeft());
+ log.debug("{}", node1.left().value());
+
+ id = "userdfkoer45abc";
+ UserData userData2 = new UserData("Mynadyhme123", "Mylasghtname", id, "emaighdl123", "Designer",
+ UserStatusEnum.ACTIVE.name(), null);
+ Either<UserData, TitanOperationStatus> node2 = titanDao.createNode(userData2, UserData.class);
+ assertTrue(node2.isLeft());
+ log.debug("{}", node2.left().value());
+
+ titanDao.commit();
+
+ ImmutablePair<String, Object> keyValueId1 = userData1.getKeyValueId();
+ // get first node
+ Either<UserData, TitanOperationStatus> node = titanDao.getNode(keyValueId1.getKey(), keyValueId1.getValue(),
+ UserData.class);
+ assertTrue(node.isLeft());
+ log.debug("{}", node.left().value());
+ titanDao.commit();
+
+ // get all must be 2 + 1 default user = 3
+ Either<List<UserData>, TitanOperationStatus> all = titanDao.getAll(NodeTypeEnum.User, UserData.class);
+ assertTrue(all.isLeft());
+ assertTrue(all.left().value().size() > 0);
+
+ log.debug("{}", all.left().value());
+
+ Map<String, Object> props = new HashMap<String, Object>();
+
+ props.put(keyValueId1.getKey(), keyValueId1.getValue());
+
+ // get by criteria. must be 1
+ Either<List<UserData>, TitanOperationStatus> byCriteria = titanDao.getByCriteria(NodeTypeEnum.User, props,
+ UserData.class);
+ assertTrue(byCriteria.isLeft());
+ assertEquals(1, byCriteria.left().value().size());
+
+ log.debug("{}", byCriteria.left().value());
+
+ // delete all nodes
+ node = titanDao.deleteNode(userData1, UserData.class);
+ assertTrue(node.isLeft());
+ node = titanDao.deleteNode(userData2, UserData.class);
+ assertTrue(node.isLeft());
+ }
+
+ @Test
+ public void testGetEdgesForNode() {
+ String id = "user12345abc";
+ UserData userData = new UserData("Myname123", "Mylastname", id, "email123", UserRoleEnum.ADMIN.name(),
+ UserStatusEnum.ACTIVE.name(), null);
+ titanDao.createNode(userData, UserData.class);
+ ResourceMetadataData resourceData = new ResourceMetadataData();
+ resourceData.getMetadataDataDefinition().setName("resourceForLock");
+ resourceData.getMetadataDataDefinition().setVersion("0.1");
+ resourceData.getMetadataDataDefinition().setState("newState");
+ resourceData.getMetadataDataDefinition().setUniqueId(resourceData.getMetadataDataDefinition().getName() + "."
+ + resourceData.getMetadataDataDefinition().getVersion());
+
+ titanDao.createNode(resourceData, ResourceMetadataData.class);
+ titanDao.createRelation(userData, resourceData, GraphEdgeLabels.LAST_MODIFIER, null);
+ titanDao.commit();
+
+ Either<List<Edge>, TitanOperationStatus> eitherEdges = titanDao.getEdgesForNode(userData, Direction.OUT);
+ assertTrue(eitherEdges.isLeft());
+ assertTrue(eitherEdges.left().value().size() == 1);
+
+ eitherEdges = titanDao.getEdgesForNode(userData, Direction.IN);
+ assertTrue(eitherEdges.isLeft());
+ assertTrue(eitherEdges.left().value().size() == 0);
+
+ eitherEdges = titanDao.getEdgesForNode(resourceData, Direction.OUT);
+ assertTrue(eitherEdges.isLeft());
+ assertTrue(eitherEdges.left().value().size() == 0);
+
+ eitherEdges = titanDao.getEdgesForNode(resourceData, Direction.IN);
+ assertTrue(eitherEdges.isLeft());
+ assertTrue(eitherEdges.left().value().size() == 1);
+
+ eitherEdges = titanDao.getEdgesForNode(resourceData, Direction.BOTH);
+ assertTrue(eitherEdges.isLeft());
+ assertTrue(eitherEdges.left().value().size() == 1);
+
+ eitherEdges = titanDao.getEdgesForNode(userData, Direction.BOTH);
+ assertTrue(eitherEdges.isLeft());
+ assertTrue(eitherEdges.left().value().size() == 1);
+
+ titanDao.deleteNode(userData, UserData.class);
+ titanDao.deleteNode(resourceData, ResourceMetadataData.class);
+ titanDao.commit();
+ }
+
+ @Test
+ public void testLockElement() {
+
+ ResourceMetadataData resourceData = new ResourceMetadataData();
+
+ resourceData.getMetadataDataDefinition().setName("resourceForLock");
+ resourceData.getMetadataDataDefinition().setVersion("0.1");
+ resourceData.getMetadataDataDefinition().setState("newState");
+ resourceData.getMetadataDataDefinition().setUniqueId(resourceData.getMetadataDataDefinition().getName() + "."
+ + resourceData.getMetadataDataDefinition().getVersion());
+
+ Either<ResourceMetadataData, TitanOperationStatus> resource1 = titanDao.createNode(resourceData,
+ ResourceMetadataData.class);
+ assertTrue(resource1.isLeft());
+ titanDao.commit();
+ String lockId = "lock_" + resourceData.getLabel() + "_" + resource1.left().value().getUniqueId();
+
+ Either<GraphNodeLock, TitanOperationStatus> nodeLock = titanDao
+ .getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), lockId, GraphNodeLock.class);
+ assertTrue(nodeLock.isRight());
+ assertEquals(TitanOperationStatus.NOT_FOUND, nodeLock.right().value());
+
+ TitanOperationStatus status = titanDao.lockElement(resourceData);
+ assertEquals(TitanOperationStatus.OK, status);
+
+ nodeLock = titanDao.getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), lockId, GraphNodeLock.class);
+ assertTrue(nodeLock.isLeft());
+ assertEquals(lockId, nodeLock.left().value().getUniqueId());
+
+ titanDao.commit();
+
+ status = titanDao.lockElement(resourceData);
+ assertEquals(TitanOperationStatus.ALREADY_LOCKED, status);
+
+ status = titanDao.releaseElement(resourceData);
+ assertEquals(TitanOperationStatus.OK, status);
+
+ nodeLock = titanDao.getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), lockId, GraphNodeLock.class);
+ assertTrue(nodeLock.isRight());
+ assertEquals(TitanOperationStatus.NOT_FOUND, nodeLock.right().value());
+ titanDao.deleteNode(resourceData, ResourceMetadataData.class);
+ titanDao.commit();
+
+ }
+
+ @Test
+ public void testReLockElement() throws InterruptedException {
+
+ ResourceMetadataData resourceData = new ResourceMetadataData();
+
+ resourceData.getMetadataDataDefinition().setName("resourceForReLock");
+ resourceData.getMetadataDataDefinition().setVersion("0.1");
+ resourceData.getMetadataDataDefinition().setState("newState");
+ resourceData.getMetadataDataDefinition().setUniqueId(resourceData.getMetadataDataDefinition().getName() + "."
+ + resourceData.getMetadataDataDefinition().getVersion());
+
+ Either<ResourceMetadataData, TitanOperationStatus> resource1 = titanDao.createNode(resourceData,
+ ResourceMetadataData.class);
+ assertTrue(resource1.isLeft());
+ titanDao.commit();
+ String lockId = "lock_" + resourceData.getLabel() + "_" + resource1.left().value().getUniqueId();
+
+ Either<GraphNodeLock, TitanOperationStatus> nodeLock = titanDao
+ .getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), lockId, GraphNodeLock.class);
+ assertTrue(nodeLock.isRight());
+ assertEquals(TitanOperationStatus.NOT_FOUND, nodeLock.right().value());
+
+ // lock
+ TitanOperationStatus status = titanDao.lockElement(resourceData);
+ assertEquals(TitanOperationStatus.OK, status);
+
+ nodeLock = titanDao.getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), lockId, GraphNodeLock.class);
+ assertTrue(nodeLock.isLeft());
+ assertEquals(lockId, nodeLock.left().value().getUniqueId());
+ long time1 = nodeLock.left().value().getTime();
+
+ titanDao.commit();
+
+ // timeout
+ configurationManager.getConfiguration().setTitanLockTimeout(2L);
+ Thread.sleep(5001);
+
+ // relock
+ status = titanDao.lockElement(resourceData);
+ assertEquals(TitanOperationStatus.OK, status);
+
+ nodeLock = titanDao.getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), lockId, GraphNodeLock.class);
+ assertTrue(nodeLock.isLeft());
+ assertEquals(lockId, nodeLock.left().value().getUniqueId());
+
+ long time2 = nodeLock.left().value().getTime();
+
+ assertTrue(time2 > time1);
+
+ status = titanDao.releaseElement(resourceData);
+ assertEquals(TitanOperationStatus.OK, status);
+
+ nodeLock = titanDao.getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), lockId, GraphNodeLock.class);
+ assertTrue(nodeLock.isRight());
+ assertEquals(TitanOperationStatus.NOT_FOUND, nodeLock.right().value());
+
+ titanDao.deleteNode(resourceData, ResourceMetadataData.class);
+ titanDao.commit();
+
+ }
+
+ @Test
+ public void testBoolean() {
+ ResourceMetadataData resourceData = new ResourceMetadataData();
+
+ resourceData.getMetadataDataDefinition().setName("resourceForLock");
+ resourceData.getMetadataDataDefinition().setVersion("0.1");
+ resourceData.getMetadataDataDefinition().setState("NOT_CERTIFIED_CHECKOUT");
+ resourceData.getMetadataDataDefinition().setHighestVersion(true);
+ resourceData.getMetadataDataDefinition().setUniqueId(resourceData.getMetadataDataDefinition().getName() + "."
+ + resourceData.getMetadataDataDefinition().getVersion());
+
+ Either<ResourceMetadataData, TitanOperationStatus> resource1 = titanDao.createNode(resourceData,
+ ResourceMetadataData.class);
+ assertTrue(resource1.isLeft());
+
+ resourceData = new ResourceMetadataData();
+
+ resourceData.getMetadataDataDefinition().setName("resourceForLock");
+ resourceData.getMetadataDataDefinition().setVersion("0.2");
+ resourceData.getMetadataDataDefinition().setState("NOT_CERTIFIED_CHECKOUT");
+ resourceData.getMetadataDataDefinition().setHighestVersion(false);
+ resourceData.getMetadataDataDefinition().setUniqueId(resourceData.getMetadataDataDefinition().getName() + "."
+ + resourceData.getMetadataDataDefinition().getVersion());
+
+ Either<ResourceMetadataData, TitanOperationStatus> resource2 = titanDao.createNode(resourceData,
+ ResourceMetadataData.class);
+ titanDao.commit();
+
+ Map<String, Object> props = new HashMap<String, Object>();
+
+ props.put(GraphPropertiesDictionary.STATE.getProperty(), "NOT_CERTIFIED_CHECKOUT");
+ props.put("name", "resourceForLock");
+ props.put(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), false);
+
+ // get by criteria. must be 1
+ Either<List<ResourceMetadataData>, TitanOperationStatus> byCriteria = titanDao
+ .getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class);
+ assertTrue(byCriteria.isLeft());
+
+ titanDao.deleteNode(resource1.left().value(), ResourceMetadataData.class);
+
+ titanDao.deleteNode(resource2.left().value(), ResourceMetadataData.class);
+ titanDao.commit();
+ }
+
+ // @Test
+ public void testStringSearch() {
+ TitanGraph graph;
+
+ BaseConfiguration conf = new BaseConfiguration();
+ conf.setProperty("storage.backend", "inmemory");
+ graph = TitanFactory.open(conf);
+
+ // TitanManagement graphMgt = graph.getManagementSystem();
+ TitanManagement graphMgt = graph.openManagement();
+ PropertyKey propKey = graphMgt.makePropertyKey("string1").dataType(String.class).make();
+ graphMgt.buildIndex("string1", Vertex.class).addKey(propKey).unique().buildCompositeIndex();
+
+ propKey = graphMgt.makePropertyKey("string2").dataType(String.class).make();
+
+ // graphMgt.buildIndex("string2", Vertex.class).addKey(propKey,
+ // Mapping.TEXT.getParameter()).buildMixedIndex("search");
+ graphMgt.buildIndex("string2", Vertex.class).addKey(propKey).unique().buildCompositeIndex();
+ graphMgt.commit();
+
+ // TitanVertex v = graph.addVertex();
+ // v.addProperty("string1", "My new String 1");
+ // v.addProperty("string2", "String11");
+ // graph.commit();
+ //
+ // v = graph.addVertex();
+ // v.addProperty("string1", "my new string 1");
+ // v.addProperty("string2", "string11");
+ // graph.commit();
+ //
+ // System.out.println("First index search - case");
+ //
+ // Iterable<Vertex> vertices = graph.getVertices("string1", "My new
+ // String 1");
+ // Iterator<Vertex> iter = vertices.iterator();
+ // while ( iter.hasNext() ){
+ // Vertex ver = iter.next();
+ // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver));
+ // }
+ // System.out.println("First index search non case");
+ //
+ // vertices = graph.getVertices("string1", "my new string 1");
+ // iter = vertices.iterator();
+ // while ( iter.hasNext() ){
+ // Vertex ver = iter.next();
+ // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver));
+ // }
+ // System.out.println("Second index search case");
+ //
+ // vertices = graph.getVertices("string2", "String11");
+ // iter = vertices.iterator();
+ // while ( iter.hasNext() ){
+ // Vertex ver = iter.next();
+ // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver));
+ // }
+ // System.out.println("second index search non case");
+ //
+ // vertices = graph.getVertices("string2", "string11");
+ // iter = vertices.iterator();
+ // while ( iter.hasNext() ){
+ // Vertex ver = iter.next();
+ // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver));
+ // }
+ // System.out.println("Query index search case");
+ // vertices = graph.query().has("string1", "My new String
+ // 1").vertices();
+ // iter = vertices.iterator();
+ // while ( iter.hasNext() ){
+ // Vertex ver = iter.next();
+ // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver));
+ // }
+ // System.out.println("Query index search non case");
+ // vertices = graph.query().has("string1", "my new string
+ // 1").vertices();
+ // iter = vertices.iterator();
+ // while ( iter.hasNext() ){
+ // Vertex ver = iter.next();
+ // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver));
+ // }
+
+ log.debug("**** predicat index search non case");
+ Iterable<TitanVertex> vertices = graph.query().has("string1", Text.REGEX, "my new string 1").vertices();
+ Iterator<TitanVertex> iter = vertices.iterator();
+ while (iter.hasNext()) {
+ Vertex ver = iter.next();
+ // System.out.println(com.tinkerpop.blueprints.util.ElementHelper.getProperties(ver));
+ log.debug("{}", titanDao.getProperties(ver));
+ }
+
+ }
+
+ @Test
+ public void testDuplicateResultDueToTitanBug() {
+
+ // TitanGraph titanGraph = titanDao.getGraph().left().value();
+ // TitanManagement managementSystem = titanGraph.getManagementSystem();
+
+ // GraphPropertiesDictionary[] properties = {
+ // GraphPropertiesDictionary.IS_ABSTRACT,
+ // GraphPropertiesDictionary.ADDITIONAL_INFO_ID_TO_KEY,
+ // GraphPropertiesDictionary.POSITION_X,
+ // GraphPropertiesDictionary.ARTIFACT_TIMEOUT };
+ //
+ // for (GraphPropertiesDictionary property : properties) {
+ // if (false ==
+ // managementSystem.containsGraphIndex(property.getProperty())) {
+ // PropertyKey propKey1 =
+ // managementSystem.makePropertyKey(property.getProperty()).dataType(property.getClazz()).make();
+ // managementSystem.buildIndex(property.getProperty(),
+ // Vertex.class).addKey(propKey1).unique().buildCompositeIndex();
+ // }
+ // }
+
+ // managementSystem.commit();
+
+ ResourceMetadataData resourceData1 = new ResourceMetadataData();
+ resourceData1.getMetadataDataDefinition().setUniqueId("A");
+ ((ResourceMetadataDataDefinition) resourceData1.getMetadataDataDefinition()).setAbstract(true);
+ resourceData1.getMetadataDataDefinition().setName("aaaa");
+
+ Either<ResourceMetadataData, TitanOperationStatus> newNode1 = titanDao.createNode(resourceData1,
+ ResourceMetadataData.class);
+ assertTrue(newNode1.isLeft());
+ log.debug("{}", newNode1.left().value());
+ // titanDao.commit();
+
+ Map<String, Object> props = new HashMap<>();
+ props.put(GraphPropertiesDictionary.IS_ABSTRACT.getProperty(), true);
+ Either<List<ResourceMetadataData>, TitanOperationStatus> byCriteria = titanDao
+ .getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class);
+ assertTrue(byCriteria.isLeft());
+ assertEquals("check one result returned", 1, byCriteria.left().value().size());
+ // titanDao.commit();
+
+ ResourceMetadataData resourceToUpdate = new ResourceMetadataData();
+ ((ResourceMetadataDataDefinition) resourceToUpdate.getMetadataDataDefinition()).setAbstract(false);
+ resourceToUpdate.getMetadataDataDefinition().setUniqueId("A");
+ Either<ResourceMetadataData, TitanOperationStatus> updateNode = titanDao.updateNode(resourceToUpdate,
+ ResourceMetadataData.class);
+ assertTrue(updateNode.isLeft());
+ // titanDao.commit();
+
+ byCriteria = titanDao.getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class);
+ assertTrue(byCriteria.isRight());
+ assertEquals("check one result returned due to titan bug", TitanOperationStatus.NOT_FOUND,
+ byCriteria.right().value());
+
+ AdditionalInfoParameterData infoParameterData = new AdditionalInfoParameterData();
+ infoParameterData.getAdditionalInfoParameterDataDefinition().setUniqueId("123");
+ Map<String, String> idToKey = new HashMap<>();
+ idToKey.put("key1", "value1");
+ infoParameterData.setIdToKey(idToKey);
+
+ Either<AdditionalInfoParameterData, TitanOperationStatus> newNode2 = titanDao.createNode(infoParameterData,
+ AdditionalInfoParameterData.class);
+ assertTrue(newNode2.isLeft());
+ log.debug("{}", newNode2.left().value());
+ // titanDao.commit();
+
+ Map<String, String> idToKey2 = new HashMap<>();
+ idToKey2.put("key1", "value2");
+
+ Map<String, Object> props2 = new HashMap<>();
+ props2.put(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), "123");
+ Gson gson = new Gson();
+ props2.put(GraphPropertiesDictionary.ADDITIONAL_INFO_ID_TO_KEY.getProperty(), gson.toJson(idToKey2));
+ // props2.put(GraphPropertiesDictionary.ADDITIONAL_INFO_ID_TO_KEY.getProperty(),
+ // idToKey2);
+
+ Either<List<AdditionalInfoParameterData>, TitanOperationStatus> byCriteria2 = titanDao
+ .getByCriteria(NodeTypeEnum.AdditionalInfoParameters, props2, AdditionalInfoParameterData.class);
+ assertTrue(byCriteria2.isRight());
+ assertEquals("check one result returned due to titan bug", TitanOperationStatus.NOT_FOUND,
+ byCriteria2.right().value());
+
+ infoParameterData.setIdToKey(idToKey2);
+
+ Either<AdditionalInfoParameterData, TitanOperationStatus> updateNode2 = titanDao.updateNode(infoParameterData,
+ AdditionalInfoParameterData.class);
+ assertTrue(updateNode2.isLeft());
+ // titanDao.commit();
+
+ props2.put(GraphPropertiesDictionary.ADDITIONAL_INFO_ID_TO_KEY.getProperty(), idToKey);
+ byCriteria2 = titanDao.getByCriteria(NodeTypeEnum.AdditionalInfoParameters, props2,
+ AdditionalInfoParameterData.class);
+ assertTrue(byCriteria2.isRight());
+ assertEquals("check one result returned due to titan bug", TitanOperationStatus.NOT_FOUND,
+ byCriteria2.right().value());
+
+ ComponentInstanceData resourceInstanceData = new ComponentInstanceData();
+ resourceInstanceData.getComponentInstDataDefinition().setUniqueId("ri123");
+ resourceInstanceData.getComponentInstDataDefinition().setPosX("22");
+ resourceInstanceData.getComponentInstDataDefinition().setName("myresource_1");
+
+ Either<ComponentInstanceData, TitanOperationStatus> newNode3 = titanDao.createNode(resourceInstanceData,
+ ComponentInstanceData.class);
+ assertTrue(newNode3.isLeft());
+ log.debug("{}", newNode3.left().value());
+ // titanDao.commit();
+
+ resourceInstanceData.getComponentInstDataDefinition().setPosX("50");
+ Either<ComponentInstanceData, TitanOperationStatus> updateNode3 = titanDao.updateNode(resourceInstanceData,
+ ComponentInstanceData.class);
+ assertTrue(updateNode3.isLeft());
+ // titanDao.commit();
+
+ resourceInstanceData.getComponentInstDataDefinition().setName("myresource_2");
+ updateNode3 = titanDao.updateNode(resourceInstanceData, ComponentInstanceData.class);
+ assertTrue(updateNode3.isLeft());
+ // titanDao.commit();
+
+ Map<String, Object> props3 = new HashMap<>();
+ props3.put("positionX", "22");
+ Either<List<ComponentInstanceData>, TitanOperationStatus> byCriteria3 = titanDao
+ .getByCriteria(NodeTypeEnum.ResourceInstance, props3, ComponentInstanceData.class);
+ assertTrue(byCriteria3.isRight());
+ assertEquals("check one result returned due to titan bug", TitanOperationStatus.NOT_FOUND,
+ byCriteria3.right().value());
+
+ props3.put("positionX", "50");
+ byCriteria3 = titanDao.getByCriteria(NodeTypeEnum.ResourceInstance, props3, ComponentInstanceData.class);
+ assertTrue(byCriteria3.isLeft());
+
+ /////////////////////////// check integer ////////////////////////
+
+ ArtifactData artifactData = new ArtifactData();
+ artifactData.getArtifactDataDefinition().setUniqueId("ad234");
+ artifactData.getArtifactDataDefinition().setTimeout(100);
+
+ Either<ArtifactData, TitanOperationStatus> newNode4 = titanDao.createNode(artifactData, ArtifactData.class);
+ assertTrue(newNode4.isLeft());
+ log.debug("{}", newNode4.left().value());
+ // titanDao.commit();
+
+ artifactData.getArtifactDataDefinition().setTimeout(50);
+ Either<ArtifactData, TitanOperationStatus> updateNode4 = titanDao.updateNode(artifactData, ArtifactData.class);
+ assertTrue(updateNode4.isLeft());
+ // titanDao.commit();
+
+ Map<String, Object> props4 = new HashMap<>();
+ props4.put("timeout", 100);
+ Either<List<ArtifactData>, TitanOperationStatus> byCriteria4 = titanDao.getByCriteria(NodeTypeEnum.ArtifactRef,
+ props4, ArtifactData.class);
+ assertTrue(byCriteria4.isRight());
+ assertEquals("check one result returned due to titan bug", TitanOperationStatus.NOT_FOUND,
+ byCriteria4.right().value());
+
+ props4.put("timeout", 50);
+ byCriteria4 = titanDao.getByCriteria(NodeTypeEnum.ArtifactRef, props4, ArtifactData.class);
+ assertTrue(byCriteria4.isLeft());
+
+ titanDao.rollback();
+ }
+
+ @Test
+ public void testDuplicateResultUSeHasNotQueryDueToTitanBug() {
+
+ String name = "bbbb";
+
+ ResourceMetadataData resourceData1 = new ResourceMetadataData();
+ resourceData1.getMetadataDataDefinition().setUniqueId("A");
+ ((ResourceMetadataDataDefinition) resourceData1.getMetadataDataDefinition()).setAbstract(true);
+ resourceData1.getMetadataDataDefinition().setName(name);
+
+ Either<ResourceMetadataData, TitanOperationStatus> newNode1 = titanDao.createNode(resourceData1,
+ ResourceMetadataData.class);
+ assertTrue(newNode1.isLeft());
+ log.debug("{}", newNode1.left().value());
+ // titanDao.commit();
+
+ Map<String, Object> props = new HashMap<>();
+ props.put(GraphPropertiesDictionary.IS_ABSTRACT.getProperty(), true);
+ Either<List<ResourceMetadataData>, TitanOperationStatus> byCriteria = titanDao
+ .getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class);
+ assertTrue(byCriteria.isLeft());
+ assertEquals("check one result returned", 1, byCriteria.left().value().size());
+ // titanDao.commit();
+
+ ResourceMetadataData resourceToUpdate = new ResourceMetadataData();
+ ((ResourceMetadataDataDefinition) resourceToUpdate.getMetadataDataDefinition()).setAbstract(false);
+ resourceToUpdate.getMetadataDataDefinition().setUniqueId("A");
+ Either<ResourceMetadataData, TitanOperationStatus> updateNode = titanDao.updateNode(resourceToUpdate,
+ ResourceMetadataData.class);
+ assertTrue(updateNode.isLeft());
+ // titanDao.commit();
+
+ // no result where isAbstract = true
+ byCriteria = titanDao.getByCriteria(NodeTypeEnum.Resource, props, ResourceMetadataData.class);
+ assertTrue(byCriteria.isRight());
+ assertEquals("check one result returned due to titan bug", TitanOperationStatus.NOT_FOUND,
+ byCriteria.right().value());
+
+ // one result where isAbstract != true
+ byCriteria = titanDao.getByCriteria(NodeTypeEnum.Resource, null, props, ResourceMetadataData.class);
+ assertTrue(byCriteria.isLeft());
+ assertEquals("check one result returned", 1, byCriteria.left().value().size());
+
+ props.put(GraphPropertiesDictionary.IS_ABSTRACT.getProperty(), false);
+ byCriteria = titanDao.getByCriteria(NodeTypeEnum.Resource, null, props, ResourceMetadataData.class);
+ assertTrue(byCriteria.isRight());
+ assertEquals("check one result returned due to titan bug", TitanOperationStatus.NOT_FOUND,
+ byCriteria.right().value());
+
+ titanDao.rollback();
+
+ }
+
+}