Skip to content

Commit

Permalink
Merge pull request #229 from ResearchCollectionsAndPreservation/stage…
Browse files Browse the repository at this point in the history
…4-dev

Dev to UAT
  • Loading branch information
srinduri04 authored Sep 30, 2021
2 parents b636861 + 6e7713c commit bb78d57
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
import org.recap.repository.jpa.ItemDetailsRepository;
import org.recap.util.PropertyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Scope;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
Expand All @@ -73,6 +75,7 @@
@Service
@Slf4j
@RefreshScope
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class NCIPProtocolConnector extends AbstractProtocolConnector {

private String ncipRequest = "NCIP2 request sent: ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.recap.model.request.ItemRequestInformation;
import org.recap.ils.protocol.rest.processor.RestProtocolJobResponsePollingProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
Expand All @@ -27,6 +29,7 @@

@Service
@Slf4j
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class RestProtocolConnector extends AbstractProtocolConnector {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.recap.model.ILSConfigProperties;
import org.recap.model.request.ItemRequestInformation;
import org.recap.model.response.*;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import java.text.ParseException;
Expand All @@ -23,6 +25,7 @@

@Service
@Slf4j
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class SIPProtocolConnector extends AbstractProtocolConnector {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,56 @@
package org.recap.ils.connector.factory;

import lombok.extern.slf4j.Slf4j;
import org.recap.ScsbConstants;
import org.recap.ils.connector.AbstractProtocolConnector;
import org.recap.ils.connector.NCIPProtocolConnector;
import org.recap.ils.connector.RestProtocolConnector;
import org.recap.ils.connector.SIPProtocolConnector;
import org.recap.model.ILSConfigProperties;
import org.recap.util.PropertyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@Component
public class ILSProtocolConnectorFactory extends BaseILSProtocolConnectorFactory {

private final List<AbstractProtocolConnector> protocolConnectors;
private final PropertyUtil propertyUtil;
@Autowired
private PropertyUtil propertyUtil;

@Autowired
public ILSProtocolConnectorFactory(List<AbstractProtocolConnector> protocolConnectors, PropertyUtil propertyUtil) {
this.protocolConnectors = protocolConnectors;
this.propertyUtil = propertyUtil;
}
private ApplicationContext applicationContext;

private static final Map<String, AbstractProtocolConnector> protocolConnectorsMap = new HashMap<>();

public AbstractProtocolConnector getIlsProtocolConnector(String institution) {
AbstractProtocolConnector connector = null;
ILSConfigProperties ilsConfigProperties = propertyUtil.getILSConfigProperties(institution);
String protocol = ilsConfigProperties.getProtocol();
AbstractProtocolConnector connector = protocolConnectors
.stream()
.filter(service -> service.supports(protocol))
.findFirst()
.orElseThrow(IllegalArgumentException::new);
connector.setInstitution(institution);
connector.setIlsConfigProperties(ilsConfigProperties);
if (protocolConnectorsMap.containsKey(institution)) {
connector = protocolConnectorsMap.get(institution);
if (connector != null){
connector.setInstitution(institution);
connector.setIlsConfigProperties(ilsConfigProperties);
}
} else {
if (ScsbConstants.SIP2_PROTOCOL.equalsIgnoreCase(protocol)) {
connector = applicationContext.getBean(SIPProtocolConnector.class);
} else if (ScsbConstants.REST_PROTOCOL.equalsIgnoreCase(protocol)) {
connector = applicationContext.getBean(RestProtocolConnector.class);
} else if (ScsbConstants.NCIP_PROTOCOL.equalsIgnoreCase(protocol)) {
connector = applicationContext.getBean(NCIPProtocolConnector.class);
}
if (connector != null){
connector.setInstitution(institution);
connector.setIlsConfigProperties(ilsConfigProperties);
protocolConnectorsMap.put(institution, connector);
}
}
return connector;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

import org.recap.ims.connector.AbstractLASImsLocationConnector;
import org.recap.ims.connector.GFALasImsLocationConnector;
import org.recap.model.IMSConfigProperties;
import org.recap.util.PropertyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
* Created by rajeshbabuk on 20/Jan/2021
*/
Expand Down
30 changes: 30 additions & 0 deletions src/test/java/org/recap/controller/CancelItemControllerUT.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.recap.BaseTestCaseUT;
import org.recap.PropertyKeyConstants;
import org.recap.ScsbCommonConstants;
import org.recap.ScsbConstants;
import org.recap.model.request.ItemRequestInformation;
Expand All @@ -19,6 +20,7 @@
import org.recap.util.CommonUtil;
import org.recap.request.util.ItemRequestServiceUtil;
import org.recap.util.PropertyUtil;
import org.springframework.test.util.ReflectionTestUtils;

import java.util.Arrays;
import java.util.Date;
Expand Down Expand Up @@ -125,6 +127,34 @@ public void testCancelRequestException() throws Exception {
cancelRequestResponse = cancelItemController.cancelRequest(requestItemEntity.getId());
assertNotNull(cancelRequestResponse);
}

@Test
public void processCancelRequest() throws Exception {
ItemRequestInformation itemRequestInformation = new ItemRequestInformation();
ItemInformationResponse itemInformationResponse = getItemInformationResponse();
itemInformationResponse.setHoldQueueLength("0");
RequestItemEntity requestItemEntity = createRequestItem();
Mockito.when(propertyUtil.getPropertyByInstitutionAndKey(itemRequestInformation.getRequestingInstitution(), PropertyKeyConstants.ILS.ILS_CHECKEDOUT_CIRCULATION_STATUS)).thenReturn(null);
Mockito.when(requestItemStatusDetailsRepository.findByRequestStatusCode(ScsbCommonConstants.REQUEST_STATUS_CANCELED)).thenReturn(createRequestItem().getRequestStatusEntity());
Mockito.when(requestItemDetailsRepository.save(requestItemEntity)).thenReturn(createRequestItem());
Mockito.when(itemRequestService.getEmailService()).thenReturn(emailService);
Mockito.doNothing().when(itemRequestService).saveItemChangeLogEntity(any(), any(), any(), any());
Mockito.doNothing().when(emailService).sendEmail(any(),any(),any(),any(),any(), any(),any());
ReflectionTestUtils.invokeMethod(cancelItemController,"processCancelRequest",itemRequestInformation,itemInformationResponse,requestItemEntity);
}

@Test
public void processRecall() throws Exception {
ItemRequestInformation itemRequestInformation = new ItemRequestInformation();
ItemInformationResponse itemInformationResponse = getItemInformationResponse();
itemInformationResponse.setHoldQueueLength("0");
RequestItemEntity requestItemEntity = createRequestItem();
Mockito.when(propertyUtil.getPropertyByInstitutionAndKey(itemRequestInformation.getRequestingInstitution(), PropertyKeyConstants.ILS.ILS_CHECKEDOUT_CIRCULATION_STATUS)).thenReturn(null);
Mockito.when(requestItemStatusDetailsRepository.findByRequestStatusCode(ScsbCommonConstants.REQUEST_STATUS_CANCELED)).thenReturn(createRequestItem().getRequestStatusEntity());
Mockito.when(requestItemDetailsRepository.save(requestItemEntity)).thenReturn(createRequestItem());
Mockito.doNothing().when(itemRequestService).saveItemChangeLogEntity(any(), any(), any(), any());
ReflectionTestUtils.invokeMethod(cancelItemController,"processRecall",itemRequestInformation,itemInformationResponse,requestItemEntity);
}
private ItemInformationResponse getItemInformationResponse() {
ItemRequestInformation itemRequestInformation = new ItemRequestInformation();
itemRequestInformation.setItemBarcodes(Arrays.asList("32101074849843"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void getIlsProtocolConnector(){
String institution = "PUL";
ILSConfigProperties ilsConfigProperties = new ILSConfigProperties();
ilsConfigProperties.setProtocol("NCIP");
ILSProtocolConnectorFactory ilsProtocolConnectorFactory = new ILSProtocolConnectorFactory(Arrays.asList(abstractProtocolConnector),propertyUtil);
ILSProtocolConnectorFactory ilsProtocolConnectorFactory = new ILSProtocolConnectorFactory();
Mockito.when(propertyUtil.getILSConfigProperties(any())).thenReturn(ilsConfigProperties);
Mockito.when(abstractProtocolConnector.supports("NCIP")).thenReturn(true);
AbstractProtocolConnector abstractProtocolConnector = ilsProtocolConnectorFactory.getIlsProtocolConnector(institution);
Expand Down
96 changes: 95 additions & 1 deletion src/test/java/org/recap/util/CommonUtilUT.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.recap.model.jpa.*;
import org.recap.repository.jpa.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.util.ReflectionTestUtils;

import java.util.*;

Expand Down Expand Up @@ -98,6 +99,27 @@ public void addItemAndReportEntitiesWithoutitemReportEntity() {
commonUtil.addItemAndReportEntities(itemEntities, reportEntities, processHoldings, holdingsEntity, itemMap);
}

@Test
public void addItemAndReportEntitiesWithoutProcessHoldings() {
List<ItemEntity> itemEntities = new ArrayList<>();
List<ReportEntity> reportEntities = new ArrayList<>();
boolean processHoldings = false;
HoldingsEntity holdingsEntity = getHoldingsEntity();
Map<String, Object> itemMap = new HashMap<>();
itemMap.put("itemEntity", getBibliographicEntity().getItemEntities().get(0));
commonUtil.addItemAndReportEntities(itemEntities, reportEntities, processHoldings, holdingsEntity, itemMap);
}
@Test
public void addItemAndReportEntitiesWithoutHoldingsEntity() {
List<ItemEntity> itemEntities = new ArrayList<>();
List<ReportEntity> reportEntities = new ArrayList<>();
boolean processHoldings = false;
HoldingsEntity holdingsEntity = new HoldingsEntity();
Map<String, Object> itemMap = new HashMap<>();
itemMap.put("itemEntity", getBibliographicEntity().getItemEntities().get(0));
commonUtil.addItemAndReportEntities(itemEntities, reportEntities, processHoldings, holdingsEntity, itemMap);
}

@Test
public void rollbackUpdateItemAvailabilityStatus() {
ItemEntity itemEntity = getBibliographicEntity().getItemEntities().get(0);
Expand All @@ -108,7 +130,18 @@ public void rollbackUpdateItemAvailabilityStatus() {

@Test
public void getFTPPropertiesMap() {
commonUtil.getFTPPropertiesMap();
Map<String, String> map = commonUtil.getFTPPropertiesMap();
assertNotNull(map);
}

@Test
public void getFTPPropertiesMapAvailable() {
Map<String, String> ftpPropertiesMap = new HashMap<>();
ftpPropertiesMap.put("Value","Test");
ReflectionTestUtils.setField(commonUtil,"ftpPropertiesMap" ,ftpPropertiesMap);
Map<String, String> map = commonUtil.getFTPPropertiesMap();
assertNotNull(map);
assertEquals(ftpPropertiesMap,map);
}

@Test
Expand All @@ -124,6 +157,34 @@ public void getItemStatusMap() {
commonUtil.getItemStatusMap();
}

@Test
public void getItemStatusMapWithItemStatus() {
Map<String, Integer> itemStatusMap = new HashMap<>();
itemStatusMap.put("AVAILABLE",1);
ReflectionTestUtils.setField(commonUtil,"itemStatusMap",itemStatusMap);
Map<String, Integer> map = commonUtil.getItemStatusMap();
assertNotNull(map);
assertEquals(itemStatusMap,map);
}
@Test
public void getCollectionGroupMapAvailable() {
Map<String, Integer> collectionGroupMap = new HashMap<>();
collectionGroupMap.put("SHARED",1);
ReflectionTestUtils.setField(commonUtil,"collectionGroupMap",collectionGroupMap);
Map<String, Integer> map = commonUtil.getCollectionGroupMap();
assertNotNull(map);
assertEquals(collectionGroupMap,map);
}
@Test
public void getInstitutionEntityMapAvailable() {
Map<String, Integer> institutionEntityMap = new HashMap<>();
institutionEntityMap.put("PUL",1);
ReflectionTestUtils.setField(commonUtil,"institutionEntityMap",institutionEntityMap);
Map<String, Integer> map = commonUtil.getInstitutionEntityMap();
assertNotNull(map);
assertEquals(institutionEntityMap,map);
}

@Test
public void getInstitutionEntityMap() {
InstitutionEntity institutionEntity = getInstitutionEntity();
Expand Down Expand Up @@ -208,6 +269,24 @@ public void getImsLocationCodeByItemBarcode() {
assertNotNull(imsLocationCode);
}

@Test
public void getImsLocationCodeByItemBarcodeWithoutItemEntity() {
String itemBarcode = "32959";
Mockito.when(itemDetailsRepository.findByBarcode(itemBarcode)).thenReturn(Collections.EMPTY_LIST);
String imsLocationCode = commonUtil.getImsLocationCodeByItemBarcode(itemBarcode);
assertNull(imsLocationCode);
}

@Test
public void getImsLocationCodeByItemBarcodeWithoutImsLocation() {
String itemBarcode = "32959";
ItemEntity itemEntity = getBibliographicEntity().getItemEntities().get(0);
itemEntity.setImsLocationEntity(null);
Mockito.when(itemDetailsRepository.findByBarcode(itemBarcode)).thenReturn(Arrays.asList(itemEntity));
String imsLocationCode = commonUtil.getImsLocationCodeByItemBarcode(itemBarcode);
assertNull(imsLocationCode);
}

@Test
public void checkIfImsItemStatusIsRequestableNotRetrievable(){
String imsLocationCode = "HD";
Expand All @@ -218,6 +297,15 @@ public void checkIfImsItemStatusIsRequestableNotRetrievable(){

}

@Test
public void checkIfImsItemIsNotOnFile(){
String imsLocationCode = "HD";
String imsItemStatus = "IN";
Mockito.when(propertyUtil.getPropertyByImsLocationAndKey(any(), any())).thenReturn("test");
Boolean result = commonUtil.checkIfImsItemIsNotOnFile(imsLocationCode,imsItemStatus);
assertFalse(result);
}

/*@Test
public void getExistingItemEntityOwningInstItemId() {
BibliographicEntity fetchedBibliographicEntity = getBibliographicEntity();
Expand All @@ -232,6 +320,12 @@ public void getBarcodesList() {
List<String> itemBarcodes = commonUtil.getBarcodesList(itemEntities);
assertNotNull(itemBarcodes);
}

@Test
public void getBarcodesListWithoutItemEntities() {
List<String> itemBarcodes = commonUtil.getBarcodesList(Collections.EMPTY_LIST);
assertNotNull(itemBarcodes);
}
@Test
public void getItemRequestInformation(){
ItemEntity itemEntity = getBibliographicEntity().getItemEntities().get(0);
Expand Down

0 comments on commit bb78d57

Please sign in to comment.