Skip to content

Commit

Permalink
Merge pull request #88 from TAMULib/sprint-action-staging
Browse files Browse the repository at this point in the history
Sprint action staging
  • Loading branch information
wwelling committed Feb 3, 2021
2 parents 445bc9d + d714879 commit 6ce7354
Show file tree
Hide file tree
Showing 23 changed files with 1,421 additions and 229 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build

on: [ push, pull_request, workflow_dispatch ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: "Maven Cache"
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}

- name: "Setup Java"
uses: actions/setup-java@v1
with:
java-version: 1.8

- name: "Maven Test"
run: mvn clean test cobertura:cobertura jacoco:report coveralls:report -DdryRun=true

- name: "Coverage Report"
uses: MikeEdgar/github-action@raw_coverage_file
with:
github-token: ${{ secrets.github_token }}
path-to-file: './target/coveralls.json'
coverage-format: raw
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[![Build Status](https://github.com/TAMULib/CatalogService/workflows/Build/badge.svg)](https://github.com/TAMULib/CatalogService/actions?query=workflow%3ABuild)
[![Coverage Status](https://coveralls.io/repos/github/TAMULib/CatalogService/badge.svg)](https://coveralls.io/github/TAMULib/CatalogService)

# CatalogService
A service for interfacing with Library Catalogs
52 changes: 52 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
<id>tamu-snapshots</id>
<url>https://artifacts.library.tamu.edu/repository/maven-snapshots</url>
</repository>

<repository>
<id>mvnrepository</id>
<name>Maven Central Repository</name>
<url>https://repo1.maven.org/maven2/</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -82,6 +88,52 @@
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<configuration>
<quiet>true</quiet>
<instrumentation>
<ignoreTrivial>true</ignoreTrivial>
<ignores>
<ignore>java.util.logging.*</ignore>
<ignore>edu.tamu.app.config.AppEmailConfig</ignore>
</ignores>
<excludes>
<exclude>**/ProjectInitialization.class</exclude>
</excludes>
</instrumentation>
<formats>
<format>html</format>
<format>xml</format>
</formats>
<aggregate>true</aggregate>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/ProjectInitialization.class</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<configuration>
<repoToken></repoToken>
</configuration>
</plugin>
</plugins>
</build>

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 6ce7354

Please sign in to comment.