Summary Table

Categories Total Count
PII 0
URL 0
DNS 0
EKL 0
IP 0
PORT 0
VsID 0
CF 0
AI 0
VPD 0
PL 0
Other 0

File Content

package gov.va.med.ars.service.impl;

import static org.junit.Assert.assertNotNull;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.beans.factory.annotation.Autowired;

import gov.va.med.ars.dao.ars.ARSMetadataStorageRepository;
import gov.va.med.ars.dao.ars.ArsAttachmentsStorageRepository;
import gov.va.med.ars.model.response.MetaDataResponse;
import gov.va.med.ars.service.IDashboardService;
//import gov.va.med.ars.util.DateMatcher;
//import gov.va.med.ars.util.NewDateMatcher;
import gov.va.med.domain.ars.ArsAttachmentsStorage;
import gov.va.med.domain.ars.ArsMetadataStorage;

import static org.mockito.Mockito.any;
import static org.mockito.Mockito.same;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.argThat;

import static org.mockito.Mockito.when;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

@RunWith(MockitoJUnitRunner.class)
public class DashboardServiceImplTest {
private static final Logger logger = LogManager.getLogger(DashboardServiceImplTest.class);

@InjectMocks
DashboardServiceImpl dashboardService;

@Mock
ArsAttachmentsStorageRepository attachmentRepository;

@Mock
ARSMetadataStorageRepository metaDataRepository;

@Test
public void testMockIsWorking() {
assertNotNull("dashboard service Injection Failed", dashboardService);
}

@Test
public void getAttachmentsDetails_success() throws Exception {
DateFormat dateFormat = new SimpleDateFormat("ddmmyyyy");

ArsAttachmentsStorage arsAttachmentsStorage = new ArsAttachmentsStorage();
arsAttachmentsStorage.setAvailableStorage(new BigDecimal(200));
arsAttachmentsStorage.setAverageAttachmentsSize(new BigDecimal(300));
arsAttachmentsStorage.setId(100);
arsAttachmentsStorage.setStorageDate(new Date());
arsAttachmentsStorage.setTotalAttachments(new BigDecimal(232));
arsAttachmentsStorage.setTotalStorage(new BigDecimal(232));
arsAttachmentsStorage.setUsedStorage(new BigDecimal(32));

List<BigDecimal> usedStorageStatistic = new ArrayList<>();
List<BigDecimal> totalStorageStatistic = new ArrayList<>();
usedStorageStatistic.add(new BigDecimal(0));
usedStorageStatistic.add(new BigDecimal(32));
usedStorageStatistic.add(new BigDecimal(121));
usedStorageStatistic.add(new BigDecimal(120));
usedStorageStatistic.add(new BigDecimal(121));
usedStorageStatistic.add(new BigDecimal(121));
usedStorageStatistic.add(new BigDecimal(121));

totalStorageStatistic.add(new BigDecimal(0));
totalStorageStatistic.add(new BigDecimal(222));
totalStorageStatistic.add(new BigDecimal(141));
totalStorageStatistic.add(new BigDecimal(321));
totalStorageStatistic.add(new BigDecimal(232));
totalStorageStatistic.add(new BigDecimal(220));
totalStorageStatistic.add(new BigDecimal(121));

MetaDataResponse response = new MetaDataResponse();
response.setTotalStorage(arsAttachmentsStorage.getTotalStorage());
response.setAvailableStorage(arsAttachmentsStorage.getAvailableStorage());
response.setUsedStorage(arsAttachmentsStorage.getUsedStorage());
response.setPeakUsage(new BigDecimal(16));
response.setAverage(new BigDecimal(128));
response.setFromDate("03282018");
response.setToDate("04032018");
response.setTotalStorageStatistic(totalStorageStatistic);
response.setUsedStorageStatistic(usedStorageStatistic);
response.setTotalAttachments(arsAttachmentsStorage.getTotalAttachments());
response.setAverageAttachmentSize(arsAttachmentsStorage.getAverageAttachmentsSize());

List<ArsAttachmentsStorage> arsAttachmentsStorages = new ArrayList<>();
arsAttachmentsStorages.add(arsAttachmentsStorage);

when(attachmentRepository.count()).thenReturn((long) 1);
when(attachmentRepository.getRecords(any(Date.class), any(Date.class))).thenReturn(arsAttachmentsStorages);

MetaDataResponse attachmentsDetails = dashboardService.getAttachmentsDetails();
assertEquals(new BigDecimal(232), attachmentsDetails.getTotalStorage());
assertEquals(new BigDecimal(200), attachmentsDetails.getAvailableStorage());
assertEquals(new BigDecimal(32), attachmentsDetails.getUsedStorage());
assertEquals(new BigDecimal(32), attachmentsDetails.getPeakUsage());
assertEquals(new BigDecimal(200), attachmentsDetails.getAvailableStorage());
verify(attachmentRepository, times(1)).getRecords(any(Date.class), any(Date.class));

}

@Test
public void getMetaDataDetails_success() throws Exception {
ArsMetadataStorage arsMetadataStorage = new ArsMetadataStorage();
arsMetadataStorage.setAvailableStorage(new BigDecimal(200));
arsMetadataStorage.setId(100);
arsMetadataStorage.setStorageDate(new Date());

arsMetadataStorage.setTotalStorage(new BigDecimal(232));
arsMetadataStorage.setUsedStorage(new BigDecimal(32));

DateFormat dateFormat = new SimpleDateFormat("ddmmyyyy");

List<BigDecimal> usedStorageStatistic = new ArrayList<>();
List<BigDecimal> totalStorageStatistic = new ArrayList<>();
usedStorageStatistic.add(new BigDecimal(0));
usedStorageStatistic.add(new BigDecimal(32));
usedStorageStatistic.add(new BigDecimal(121));
usedStorageStatistic.add(new BigDecimal(120));
usedStorageStatistic.add(new BigDecimal(121));
usedStorageStatistic.add(new BigDecimal(121));
usedStorageStatistic.add(new BigDecimal(121));

totalStorageStatistic.add(new BigDecimal(0));
totalStorageStatistic.add(new BigDecimal(222));
totalStorageStatistic.add(new BigDecimal(141));
totalStorageStatistic.add(new BigDecimal(321));
totalStorageStatistic.add(new BigDecimal(232));
totalStorageStatistic.add(new BigDecimal(220));
totalStorageStatistic.add(new BigDecimal(121));

MetaDataResponse response = new MetaDataResponse();
response.setTotalStorage(arsMetadataStorage.getTotalStorage());
response.setAvailableStorage(arsMetadataStorage.getAvailableStorage());
response.setUsedStorage(arsMetadataStorage.getUsedStorage());
response.setPeakUsage(new BigDecimal(16));
response.setAverage(new BigDecimal(128));
response.setFromDate("03282018");
response.setToDate("04032018");
response.setTotalStorageStatistic(totalStorageStatistic);
response.setUsedStorageStatistic(usedStorageStatistic);

List<ArsMetadataStorage> arsAttachmentsStorages = new ArrayList<>();
arsAttachmentsStorages.add(arsMetadataStorage);

when(metaDataRepository.count()).thenReturn((long) 1);
when(metaDataRepository.getRecords(any(Date.class), any(Date.class))).thenReturn(arsAttachmentsStorages);

MetaDataResponse attachmentsDetails = dashboardService.getMetaDataDetails();

assertEquals(new BigDecimal(232), attachmentsDetails.getTotalStorage());
assertEquals(new BigDecimal(200), attachmentsDetails.getAvailableStorage());
assertEquals(new BigDecimal(32), attachmentsDetails.getUsedStorage());
assertEquals(new BigDecimal(32), attachmentsDetails.getPeakUsage());
assertEquals(new BigDecimal(200), attachmentsDetails.getAvailableStorage());

verify(metaDataRepository, times(1)).getRecords(any(Date.class), any(Date.class));

}

}