Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/TAMULib/CatalogService in…
Browse files Browse the repository at this point in the history
…to sprint-action-test
  • Loading branch information
wwelling committed Feb 3, 2021
2 parents e0903cd + 6ce7354 commit 1fb14a0
Show file tree
Hide file tree
Showing 21 changed files with 1,336 additions and 230 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: "Maven Test"
run: mvn clean test cobertura:cobertura jacoco:report coveralls:report -DdryRun=true

- name: "Send to Coveralls"
- name: "Coverage Report"
uses: MikeEdgar/github-action@raw_coverage_file
with:
github-token: ${{ secrets.github_token }}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/edu/tamu/app/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public User(User user) {
setUsername(user.getUsername());
setFirstName(user.getFirstName());
setLastName(user.getLastName());
// TODO: these probably should be added.
//setEmail(user.getEmail());
//setNetid(user.getNetid());
setRole(user.getRole());
}

Expand All @@ -77,6 +80,9 @@ public User(Credentials credentials) {
setUsername(credentials.getUin());
setFirstName(credentials.getFirstName());
setLastName(credentials.getLastName());
// TODO: these probably should be added.
//setEmail(credentials.getEmail());
//setNetid(credentials.getNetid());
setRole(Role.valueOf(credentials.getRole()));
}

Expand Down Expand Up @@ -109,7 +115,7 @@ public IRole getRole() {
@JsonSerialize(as = Role.class)
public void setRole(IRole role) {
this.role = (Role) role;
}
}

/**
* @return the netid
Expand Down Expand Up @@ -213,5 +219,5 @@ public Collection<? extends GrantedAuthority> getAuthorities() {
@JsonIgnore
public String getPassword() {
return null;
}
}
}
6 changes: 5 additions & 1 deletion src/main/java/edu/tamu/app/service/FolioCatalogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import edu.tamu.app.model.CatalogHolding;
import edu.tamu.app.utility.Marc21Xml;

class FolioCatalogService extends AbstractCatalogService {
public class FolioCatalogService extends AbstractCatalogService {
private static final String VERB_GET_RECORD = "GetRecord";
private static final String METADATA_PREFIX = "marc21_withholdings";
private static final String ERROR_ATTR_CODE = "code";
Expand All @@ -60,6 +60,10 @@ class FolioCatalogService extends AbstractCatalogService {

private RestTemplate restTemplate;

public FolioCatalogService() {
super();
}

public FolioCatalogService(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
*
*/

class VoyagerCatalogService extends AbstractCatalogService {
public class VoyagerCatalogService extends AbstractCatalogService {
private static final int REQUEST_TIMEOUT = 120000;

private final Logger logger = LoggerFactory.getLogger(this.getClass());
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/edu/tamu/app/utility/Marc21Xml.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,12 @@ public static Map<String,String> buildCoreItem(Node node) {
Map<String, String> itemData = new HashMap<String, String>();

for (int l = 0; l < itemDataCount; l++) {

// TODO: something like this may be needed to avoid processing "text" elements and nodes without any attributes.
//if (!itemDataNode.item(l).hasAttributes() || itemDataNode.item(l).getNodeType() != Node.ELEMENT_NODE) {
// continue;
//}

if (itemDataNode.item(l).getAttributes().getNamedItem(RECORD_CODE) != null) {
itemData.put(itemDataNode.item(l).getAttributes().getNamedItem(RECORD_NAME).getTextContent()
+ RECORD_CODE, itemDataNode.item(l).getAttributes().getNamedItem(RECORD_CODE).getTextContent());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package edu.tamu.app.controller;

import static edu.tamu.weaver.response.ApiStatus.ERROR;
import static edu.tamu.weaver.response.ApiStatus.SUCCESS;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.springframework.test.context.junit4.SpringRunner;

import edu.tamu.app.model.CatalogHolding;
import edu.tamu.app.service.CatalogServiceFactory;
import edu.tamu.app.service.FolioCatalogService;
import edu.tamu.weaver.response.ApiResponse;

@RunWith(SpringRunner.class)
public class CatalogAccessControllerTest {

@Mock
private CatalogServiceFactory catalogServiceFactory;

@Mock
private FolioCatalogService folioCatalogService;

@InjectMocks
private CatalogAccessController catalogAccessController;

@Before
public void setup() {
when(catalogServiceFactory.getOrCreateCatalogService(any(String.class))).thenReturn(folioCatalogService);
}

@Test
public void testGetHoldingsSuccess() {
when(folioCatalogService.getHoldingsByBibId(any(String.class))).thenReturn(new ArrayList<CatalogHolding>());

ApiResponse response = catalogAccessController.getHoldings("evans", "foo");
assertEquals("Did not receive expected successful response", SUCCESS, response.getMeta().getStatus());
}

@Test
public void testGetHoldingsFailure() {
when(folioCatalogService.getHoldingsByBibId(any(String.class))).thenReturn(null);

ApiResponse response = catalogAccessController.getHoldings("evans", "foo");
assertEquals("Did not receive expected error response", ERROR, response.getMeta().getStatus());
}

@Test
public void testGetHoldingSuccess() {
Map<String, Map<String, String>> catalogItems = new HashMap<>();
CatalogHolding holding = new CatalogHolding("marcRecordLeader", "mfhd", "issn", "isbn", "title", "author", "publisher", "place", "year", "genre", "edition", "fallBackLocationCode", "oclc", "recordId", "callNumber", catalogItems);

when(folioCatalogService.getHolding(any(String.class), any(String.class))).thenReturn(holding);

ApiResponse response = catalogAccessController.getHolding("evans", "foo", "bar");
assertEquals("Did not receive expected successful response", SUCCESS, response.getMeta().getStatus());
}

@Test
public void testGetHoldingFailure() {
when(folioCatalogService.getHolding(any(String.class), any(String.class))).thenReturn(null);

ApiResponse response = catalogAccessController.getHolding("evans", "foo", "bar");
assertEquals("Did not receive expected error response", ERROR, response.getMeta().getStatus());
}

}

This file was deleted.

112 changes: 0 additions & 112 deletions src/test/java/edu/tamu/app/controller/MockCatalogService.java

This file was deleted.

0 comments on commit 1fb14a0

Please sign in to comment.