2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.resources;
23 import fj.data.Either;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.openecomp.sdc.be.config.ConfigurationManager;
27 import org.openecomp.sdc.be.dao.api.IGenericSearchDAO;
28 import org.openecomp.sdc.be.dao.api.ResourceUploadStatus;
29 import org.openecomp.sdc.be.dao.es.ElasticSearchClient;
30 import org.openecomp.sdc.be.resources.api.IResourceUploader;
31 import org.openecomp.sdc.be.resources.data.ESArtifactData;
32 import org.openecomp.sdc.be.utils.DAOConfDependentTest;
33 import org.springframework.test.context.ContextConfiguration;
34 import org.springframework.test.context.TestExecutionListeners;
35 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
36 import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
37 import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
38 import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
40 import javax.annotation.Resource;
42 import static org.junit.Assert.*;
44 @RunWith(SpringJUnit4ClassRunner.class)
45 @ContextConfiguration("classpath:application-context-test.xml")
46 @TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class,
47 DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class }) // ,
48 // CassandraUnitTestExecutionListener.class})
49 public class ArtifactDaoTest extends DAOConfDependentTest {
50 private static final String TEST_IMAGES_DIRECTORY = "src/test/resources/images";
53 ElasticSearchClient esclient;
55 @Resource(name = "resource-upload")
56 private IResourceUploader daoUploader;
57 ESArtifactData arData;
59 @Resource(name = "resource-dao")
60 private IGenericSearchDAO resourceDAO;
62 private String nodeTypeVersion = "1.0.0";
64 private static ConfigurationManager configurationManager;
67 public void testSaveNewArtifact() {
68 // daoUploader = new ArtifactUploader(artifactDAO);
69 if (daoUploader == null) {
72 String strData = "qweqwqweqw34e4wrwer";
74 String myNodeType = "MyNewNodeType";
76 ESArtifactData arData = new ESArtifactData("artifactNewMarina11", strData.getBytes());
78 ResourceUploadStatus status = daoUploader.saveArtifact(arData, true);
80 assertEquals(status, ResourceUploadStatus.OK);
82 daoUploader.deleteArtifact(arData.getId());
87 public void testGetArtifact() {
89 String myNodeType = "MyNodeType";
91 // resourceDAO.save(indexedNodeType);
92 ESArtifactData arData = getArtifactData(myNodeType, nodeTypeVersion);
94 ESArtifactData getData = null;
95 Either<ESArtifactData, ResourceUploadStatus> getArtifactStatus = daoUploader
96 .getArtifact(myNodeType + "- dassasd" + ":" + nodeTypeVersion + ":updatedArtifact");
97 if (getArtifactStatus.isRight()) {
98 daoUploader.saveArtifact(arData, true);
99 getArtifactStatus = daoUploader.getArtifact(arData.getId());
101 assertNotNull(getArtifactStatus.left().value());
107 public void testUpdateArtifact() {
108 if (daoUploader == null) {
111 ResourceUploadStatus status = ResourceUploadStatus.OK;
113 String myNodeType = "MyUpdatedNodeType";
115 ESArtifactData arData = getArtifactData(myNodeType, nodeTypeVersion);
116 Either<ESArtifactData, ResourceUploadStatus> getArtifactStatus = daoUploader.getArtifact(arData.getId());
118 if (!getArtifactStatus.isLeft())
119 status = daoUploader.saveArtifact(arData, false);
121 String payload1 = "new payloadjfdsgh";
122 arData.setDataAsArray(payload1.getBytes());
124 status = daoUploader.updateArtifact(arData);
126 assertEquals(status, ResourceUploadStatus.OK);
129 private ESArtifactData getArtifactData(String componentName, String componentVersion) {
130 String strData = "qweqwqweqw34e4wrwer";
132 return new ESArtifactData("updatedArtifact", strData.getBytes());