summaryrefslogtreecommitdiffstats
path: root/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services
diff options
context:
space:
mode:
authorkooper <sergey.sachkov@est.tech>2019-04-02 09:22:01 +0000
committerkooper <sergey.sachkov@est.tech>2019-04-02 09:22:01 +0000
commitb2f9dc5d3bc02564b4d952caa0bf2ccd20dfc6af (patch)
tree9d26cfd0a4771c38bc1f662d697bce77190d5e4c /openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services
parentddaa4ab7cbefb3c765b6d5732bef568a447f134a (diff)
Verify signature
Change-Id: I8fc5d50d74d3dd8031c96ee16708489dc7c789b8 Issue-ID: SDC-2163 Signed-off-by: kooper <sergey.sachkov@est.tech>
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services')
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImplTest.java121
1 files changed, 121 insertions, 0 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImplTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImplTest.java
new file mode 100644
index 0000000000..2dc6cd737c
--- /dev/null
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImplTest.java
@@ -0,0 +1,121 @@
+package org.openecomp.sdcrests.vsp.rest.services;
+
+import org.apache.cxf.jaxrs.ext.multipart.Attachment;
+import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
+import org.openecomp.sdc.activitylog.ActivityLogManager;
+import org.openecomp.sdc.activitylog.ActivityLogManagerFactory;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager;
+import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManagerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
+import org.openecomp.sdc.vendorsoftwareproduct.VspManagerFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManagerException;
+import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
+import org.openecomp.sdcrests.vendorsoftwareproducts.types.UploadFileResponseDto;
+import org.openecomp.sdcrests.vsp.rest.data.PackageArchive;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import javax.ws.rs.core.Response;
+
+import java.util.Optional;
+
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertFalse;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.MockitoAnnotations.initMocks;
+import static org.powermock.api.mockito.PowerMockito.mock;
+import static org.powermock.api.mockito.PowerMockito.mockStatic;
+import static org.powermock.api.mockito.PowerMockito.when;
+import static org.powermock.api.mockito.PowerMockito.whenNew;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({VspManagerFactory.class, ActivityLogManagerFactory.class,
+ OrchestrationTemplateCandidateManagerFactory.class, OrchestrationTemplateCandidateImpl.class})
+public class OrchestrationTemplateCandidateImplTest {
+
+ Logger logger = LoggerFactory.getLogger(OrchestrationTemplateCandidateImplTest.class);
+ @Mock
+ private OrchestrationTemplateCandidateManager candidateManager;
+ @Mock
+ private VendorSoftwareProductManager vendorSoftwareProductManager;
+ @Mock
+ private PackageArchive packageArchive;
+ @Mock
+ private VspManagerFactory vspManagerFactory;
+ @Mock
+ private ActivityLogManager activityLogManager;
+ @Mock
+ private ActivityLogManagerFactory activityLogManagerFactory;
+ @Mock
+ OrchestrationTemplateCandidateManagerFactory orchestrationTemplateCandidateManagerFactory;
+
+ private OrchestrationTemplateCandidateImpl orchestrationTemplateCandidate;
+
+ @Before
+ public void setUp(){
+ try {
+ initMocks(this);
+ packageArchive = mock(PackageArchive.class);
+ mockStatic(VspManagerFactory.class);
+ when(VspManagerFactory.getInstance()).thenReturn(vspManagerFactory);
+ when(vspManagerFactory.createInterface()).thenReturn(vendorSoftwareProductManager);
+ mockStatic(ActivityLogManagerFactory.class);
+ when(ActivityLogManagerFactory.getInstance()).thenReturn(activityLogManagerFactory);
+ when(activityLogManagerFactory.createInterface()).thenReturn(activityLogManager);
+ whenNew(PackageArchive.class).withAnyArguments().thenReturn(packageArchive);
+ mockStatic(OrchestrationTemplateCandidateManagerFactory.class);
+ when(OrchestrationTemplateCandidateManagerFactory.getInstance()).thenReturn(orchestrationTemplateCandidateManagerFactory);
+ when(orchestrationTemplateCandidateManagerFactory.createInterface()).thenReturn(candidateManager);
+ when(packageArchive.getArchiveFileName()).thenReturn(Optional.of("test"));
+ when(packageArchive.getPackageFileContents()).thenReturn(new byte[0]);
+ UploadFileResponse uploadFileResponse = new UploadFileResponse();
+ uploadFileResponse.setOnboardingType(OnboardingTypesEnum.ZIP);
+ uploadFileResponse.setNetworkPackageName("test");
+ when(candidateManager.upload(any(), any(), any(), any(), any())).thenReturn(uploadFileResponse);
+ }catch (Exception e){
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ @Test
+ public void uploadSignedTest() throws SecurityManagerException {
+ when(packageArchive.isSigned()).thenReturn(true);
+ when(packageArchive.isSignatureValid()).thenReturn(true);
+ orchestrationTemplateCandidate = new OrchestrationTemplateCandidateImpl();
+ Attachment attachment = mock(Attachment.class);
+ when(attachment.getContentDisposition()).thenReturn(new ContentDisposition("test"));
+ Response response = orchestrationTemplateCandidate.upload("1", "1", attachment, "1");
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
+
+ }
+
+ @Test
+ public void uploadNotSignedTest(){
+ when(packageArchive.isSigned()).thenReturn(false);
+ orchestrationTemplateCandidate = new OrchestrationTemplateCandidateImpl();
+ Attachment attachment = mock(Attachment.class);
+ when(attachment.getContentDisposition()).thenReturn(new ContentDisposition("test"));
+ Response response = orchestrationTemplateCandidate.upload("1", "1", attachment, "1");
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
+
+ }
+
+ @Test
+ public void uploadSignNotValidTest() throws SecurityManagerException {
+ when(packageArchive.isSigned()).thenReturn(true);
+ when(packageArchive.isSignatureValid()).thenReturn(false);
+ orchestrationTemplateCandidate = new OrchestrationTemplateCandidateImpl();
+ Attachment attachment = mock(Attachment.class);
+ when(attachment.getContentDisposition()).thenReturn(new ContentDisposition("test"));
+ Response response = orchestrationTemplateCandidate.upload("1", "1", attachment, "1");
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
+ assertFalse(((UploadFileResponseDto)response.getEntity()).getErrors().isEmpty());
+
+ }
+}