Added oparent to sdc main
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / impl / DownloadArtifactLogicTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.impl;
22
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;
29
30 import javax.ws.rs.core.Response;
31 import java.util.LinkedList;
32 import java.util.List;
33
34 public class DownloadArtifactLogicTest {
35
36         private DownloadArtifactLogic createTestSubject() {
37                 return new DownloadArtifactLogic();
38         }
39
40         @Test
41         public void testDownloadArtifact() throws Exception {
42                 DownloadArtifactLogic testSubject;
43                 String artifactName = "";
44                 String artifactId = "";
45                 Response result;
46
47                 // default test
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);
54         }
55
56         @Test
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;
63
64                 // default test
65                 testSubject = createTestSubject();
66                 result = testSubject.convertArtifactList(artifactsList, servletPath);
67         }
68
69         @Test
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";
75                 Response result;
76
77                 // default test
78                 testSubject = createTestSubject();
79                 
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);
87         }
88
89         @Test
90         public void testBuildResponse() throws Exception {
91                 DownloadArtifactLogic testSubject;
92                 int status = 0;
93                 String errorMessage = "";
94                 Response result;
95
96                 // default test
97                 testSubject = createTestSubject();
98                 result = testSubject.buildResponse(status, errorMessage);
99         }
100 }