2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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.impl;
23 import com.att.aft.dme2.internal.jersey.core.util.Base64;
24 import fj.data.Either;
25 import org.junit.Test;
26 import org.openecomp.sdc.be.dao.api.ResourceUploadStatus;
27 import org.openecomp.sdc.be.info.ArtifactAccessInfo;
28 import org.openecomp.sdc.be.resources.data.ESArtifactData;
30 import javax.ws.rs.core.Response;
31 import java.util.LinkedList;
32 import java.util.List;
34 public class DownloadArtifactLogicTest {
36 private DownloadArtifactLogic createTestSubject() {
37 return new DownloadArtifactLogic();
41 public void testDownloadArtifact() throws Exception {
42 DownloadArtifactLogic testSubject;
43 String artifactName = "";
44 String artifactId = "";
48 testSubject = createTestSubject();
49 result = testSubject.downloadArtifact(artifactName, Either.right(ResourceUploadStatus.COMPONENT_NOT_EXIST), artifactId);
50 result = testSubject.downloadArtifact(artifactName, Either.right(ResourceUploadStatus.ALREADY_EXIST), artifactId);
51 ESArtifactData ad = new ESArtifactData();
52 ad.setDataAsArray(Base64.encode("mock"));
53 result = testSubject.downloadArtifact(artifactName, Either.left(ad ), artifactId);
57 public void testConvertArtifactList() throws Exception {
58 DownloadArtifactLogic testSubject;
59 List<ESArtifactData> artifactsList = new LinkedList<>();
60 artifactsList.add(new ESArtifactData());
61 String servletPath = "mock";
62 List<ArtifactAccessInfo> result;
65 testSubject = createTestSubject();
66 result = testSubject.convertArtifactList(artifactsList, servletPath);
70 public void testCreateArtifactListResponse() throws Exception {
71 DownloadArtifactLogic testSubject;
72 String serviceName = "mock";
73 Either<List<ESArtifactData>, ResourceUploadStatus> getArtifactsStatus = Either.right(ResourceUploadStatus.COMPONENT_NOT_EXIST);
74 String servletPath = "mock";
78 testSubject = createTestSubject();
80 result = testSubject.createArtifactListResponse(serviceName, getArtifactsStatus, servletPath);
81 getArtifactsStatus = Either.right(ResourceUploadStatus.ALREADY_EXIST);
82 result = testSubject.createArtifactListResponse(serviceName, getArtifactsStatus, servletPath);
83 List<ESArtifactData> artifactsList = new LinkedList<>();
84 artifactsList.add(new ESArtifactData());
85 getArtifactsStatus = Either.left(artifactsList);
86 result = testSubject.createArtifactListResponse(serviceName, getArtifactsStatus, servletPath);
90 public void testBuildResponse() throws Exception {
91 DownloadArtifactLogic testSubject;
93 String errorMessage = "";
97 testSubject = createTestSubject();
98 result = testSubject.buildResponse(status, errorMessage);