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.sdcrests.vsp.rest.services;
23 import org.apache.cxf.jaxrs.ext.multipart.Attachment;
24 import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition;
25 import org.apache.http.HttpStatus;
26 import org.junit.Assert;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.mockito.ArgumentMatchers;
30 import org.mockito.Mock;
31 import org.openecomp.core.enrichment.types.MonitoringUploadType;
32 import org.openecomp.sdc.logging.api.Logger;
33 import org.openecomp.sdc.logging.api.LoggerFactory;
34 import org.openecomp.sdc.vendorsoftwareproduct.ComponentManager;
35 import org.openecomp.sdc.vendorsoftwareproduct.MonitoringUploadsManager;
36 import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.MonitoringUploadStatus;
37 import org.openecomp.sdcrests.vendorsoftwareproducts.types.MonitoringUploadStatusDto;
40 import javax.ws.rs.core.Response;
41 import java.io.ByteArrayInputStream;
42 import java.util.UUID;
44 import static org.mockito.MockitoAnnotations.openMocks;
45 import static org.mockito.Mockito.when;
47 public class ComponentMonitoringUploadsImplTest {
49 private Logger logger = LoggerFactory.getLogger(ComponentMonitoringUploadsImplTest.class);
52 private ComponentManager componentManager;
55 private MonitoringUploadsManager uploadsManager;
57 private final String vspId = UUID.randomUUID().toString();
58 private final String versionId = UUID.randomUUID().toString();
59 private final String componentId = "" + System.currentTimeMillis();
60 private final String user = "cs0008";
62 private ComponentMonitoringUploadsImpl bean;
69 MonitoringUploadStatus result = new MonitoringUploadStatus();
70 result.setSnmpPoll("p");
71 result.setSnmpTrap("t");
72 result.setVesEvent("v");
73 when(uploadsManager.listFilenames(
74 ArgumentMatchers.eq(vspId),
75 ArgumentMatchers.any(),
76 ArgumentMatchers.eq(componentId))).thenReturn(result);
78 this.bean = new ComponentMonitoringUploadsImpl(uploadsManager, componentManager);
80 } catch (Exception e) {
81 logger.error(e.getMessage(), e);
86 public void testUpload() {
87 byte[] bytes = "Hello".getBytes();
88 Attachment a = new Attachment("foo", new ByteArrayInputStream(bytes), new ContentDisposition("filename"));
89 String type = MonitoringUploadType.SNMP_POLL.toString();
91 Response rsp = bean.upload(a, vspId, versionId, componentId, type, user);
92 Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
93 Assert.assertNull(rsp.getEntity());
95 catch (Exception ex) {
96 logger.error("test failed due to exception", ex);
97 Assert.fail("exception caught " + ex.getMessage());
103 public void testDelete() {
104 String type = MonitoringUploadType.SNMP_POLL.toString();
106 Response rsp = bean.delete(vspId, versionId, componentId, type, user);
107 Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
108 Assert.assertNull(rsp.getEntity());
110 catch (Exception ex) {
111 logger.error("test failed due to exception", ex);
112 Assert.fail("exception caught " + ex.getMessage());
117 public void testList() {
119 Response rsp = bean.list(vspId, versionId, componentId, user);
120 Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus());
121 Assert.assertNotNull(rsp.getEntity());
122 MonitoringUploadStatusDto dto = (MonitoringUploadStatusDto)rsp.getEntity();
123 Assert.assertEquals("p",dto.getSnmpPoll());
124 Assert.assertEquals("v",dto.getVesEvent());
125 Assert.assertEquals("t",dto.getSnmpTrap());
127 catch (Exception ex) {
128 logger.error("test failed due to exception", ex);
129 Assert.fail("exception caught " + ex.getMessage());