Skip to content
Snippets Groups Projects
Commit b3d48c1e authored by Martin Weise's avatar Martin Weise
Browse files

disregard the timestamps for now

Former-commit-id: 2ff48340
parent acc8f439
No related branches found
No related tags found
1 merge request!42Fixed the query service tests
Showing
with 257 additions and 47155 deletions
# Sandbox, normally we need to remove this
ZENODO_API_KEY=OjphEf9axmjOxPqe419sTkhlVKZKA335NH5OGw0g4DyRUSd0LMryNtjNWg7x
\ No newline at end of file
......@@ -4,6 +4,9 @@ target/
!**/src/main/**/target/
!**/src/test/**/target/
# Environment
.env
# IDE
fda-analyse-service/venv
.git.bfg-*
......
package at.tuwien.api.zenodo.deposit;
public enum AccessTypeDto {
OPEN("open"),
EMBARGOED("embargoed"),
RESTRICTED("restricted"),
CLOSED("closed");
private final String type;
AccessTypeDto(final String type) {
this.type = type;
}
@Override
public String toString() {
return type;
}
}
package at.tuwien.api.zenodo.deposit;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ContributorDto {
/**
* e.g. Rauber, Andreas
*/
private String name;
private String affiliation;
private String orcid;
private String gnd;
}
package at.tuwien.api.zenodo.deposit;
import at.tuwien.api.zenodo.MetadataDto;
import at.tuwien.api.zenodo.files.FileDto;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;
import java.time.Instant;
import java.util.List;
@Getter
......@@ -13,23 +11,36 @@ import java.util.List;
@Builder
@NoArgsConstructor
@AllArgsConstructor
/**
* TODO add created, modified, embargodate with +00:00 timezone
*/
public class DepositDto {
private String description;
@JsonProperty("conceptrecid")
private Long conceptRecId;
private Instant created;
private List<FileDto> files;
private Long owner;
private Long id;
@JsonProperty("access_conditions")
private String accessConditions;
private Instant modified;
private String doi;
private Long owner;
private LinksDto links;
private MetadataDto metadata;
@JsonProperty("prereserve_doi")
private Boolean prereserveDoi;
private ContributorDto[] contributors;
private List<FileDto> files;
private Long id;
@JsonProperty("record_id")
private Long recordId;
......
package at.tuwien.api.zenodo.deposit;
public enum ImageTypeDto {
FIGURE("figure"),
PLOT("plot"),
DRAWING("drawing"),
DIAGRAM("diagram"),
PHOTO("photo"),
OTHER("other");
private final String type;
ImageTypeDto(final String type) {
this.type = type;
}
@Override
public String toString() {
return type;
}
}
package at.tuwien.api.zenodo.deposit;
/**
* @apiNote https://sandbox.zenodo.org/api/licenses/
*/
public enum LicenseTypeDto {
BSD("bsd-license"),
CC_NC("cc-nc"),
CC_BY("cc-by");
private final String type;
LicenseTypeDto(final String type) {
this.type = type;
}
@Override
public String toString() {
return type;
}
}
package at.tuwien.api.zenodo.deposit;
import lombok.*;
import java.net.URI;
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class LinksDto {
private URI bucket;
private URI discard;
private URI edit;
private URI files;
private URI html;
private URI latest_draft;
private URI latest_draft_html;
private URI publish;
private URI self;
}
package at.tuwien.api.zenodo;
package at.tuwien.api.zenodo.deposit;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;
......
package at.tuwien.api.zenodo;
package at.tuwien.api.zenodo.deposit;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;
@Getter
......@@ -12,7 +11,6 @@ public class PreserveDoiDto {
private String doi;
@JsonProperty("recid")
private Long recId;
private Long recid;
}
package at.tuwien.api.zenodo.deposit;
public enum PublicationTypeDto {
ANNOTATION_COLLECTION("annotationcollection"),
BOOK("book"),
SECTION("section"),
CONFERENCE_PAPER("conferencepaper"),
DATA_MANAGEMENT_PLAN("datamanagementplan"),
ARTICLE("article"),
PATENT("patent"),
PREPRINT("preprint"),
PROJECT_DELIVERABLE("deliverable"),
PROJECT_MILESTONE("milestone"),
PROPOSAL("proposal"),
REPORT("report"),
SOFTWARE_DOCUMENTATION("softwaredocumentation"),
TAXONOMIC_TREATMENT("taxonomictreatment"),
TECHNICAL_NOTE("technicalnote"),
THESIS("thesis"),
WORKING_PAPER("workingpaper"),
OTHER("other");
private final String type;
PublicationTypeDto(final String type) {
this.type = type;
}
@Override
public String toString() {
return type;
}
}
package at.tuwien.api.zenodo.deposit;
public enum UploadTypeDto {
PUBLICATION("publication"),
POSTER("poster"),
PRESENTATION("presentation"),
DATASET("dataset"),
IMAGE("image"),
VIDEO("video"),
SOFTWARE("software"),
LESSON("lesson"),
PHYSICAL_OBJECT("physicalobject"),
OTHER("other");
private final String type;
UploadTypeDto(final String type) {
this.type = type;
}
@Override
public String toString() {
return type;
}
}
......@@ -26,14 +26,9 @@
<java.version>11</java.version>
<spring-cloud.version>3.0.1</spring-cloud.version>
<mapstruct.version>1.4.2.Final</mapstruct.version>
<docker.version>3.2.7</docker.version>
<testcontainers.version>1.15.2</testcontainers.version>
<swagger.version>2.1.7</swagger.version>
<springfox.version>3.0.0</springfox.version>
<jacoco.version>0.8.7</jacoco.version>
<jooq.version>3.14.11</jooq.version>
<opencsv.version>5.4</opencsv.version>
<javax-rs-api.version>2.1.1</javax-rs-api.version>
</properties>
<dependencies>
......@@ -54,11 +49,6 @@
<artifactId>spring-cloud-starter-bootstrap</artifactId>
<version>${spring-cloud.version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${javax-rs-api.version}</version>
</dependency>
<!-- Entities and API -->
<dependency>
<groupId>at.tuwien</groupId>
......@@ -84,6 +74,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- Zenodo -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-bom.version}</version>
</dependency>
<!-- Testing -->
<dependency>
<groupId>org.springframework.boot</groupId>
......
package at.tuwien;
import at.tuwien.api.zenodo.MetadataDto;
import at.tuwien.api.zenodo.PreserveDoiDto;
import at.tuwien.api.zenodo.deposit.ContributorDto;
import at.tuwien.api.zenodo.deposit.DepositDto;
import at.tuwien.api.zenodo.deposit.LicenseTypeDto;
import at.tuwien.api.zenodo.files.FileDto;
import at.tuwien.api.zenodo.files.FileLinksDto;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.test.context.TestPropertySource;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;
......@@ -16,14 +18,29 @@ public abstract class BaseUnitTest {
public final static Long DEPOSIT_1_ID = 1L;
public final static String DEPOSIT_1_TITLE = "Super cool document";
public final static String DEPOSIT_1_DESCRIPTION = "My document is the best";
public final static Instant DEPOSIT_1_CREATED = Instant.now().minus(1, ChronoUnit.HOURS);
public final static Instant DEPOSIT_1_MODIFIED = Instant.now();
public final static String DEPOSIT_1_STATE = "draft";
public final static String DEPOSIT_1_STATE = "unsubmitted";
public final static Boolean DEPOSIT_1_SUBMITTED = false;
public final static Long DEPOSIT_1_RECORD_ID = 1899L;
public final static LicenseTypeDto DEPOSIT_1_LICENSE = LicenseTypeDto.BSD;
public final static Long DEPOSIT_1_CONCEPT_RECORD_ID = 143L;
public final static Long DEPOSIT_1_OWNER = 144L;
public final static String CONTRIBUTOR_1_NAME = "von Goethe, Johann Wolfang";
public final static String CONTRIBUTOR_1_AFFILIATION = "Universität Leipzig";
public final static Long DEPOSIT_2_ID = 2L;
public final static String DEPOSIT_2_TITLE = "Test Document " + RandomStringUtils.randomAlphanumeric(10);
public final static String DEPOSIT_2_DESCRIPTION = "Test Description " + RandomStringUtils.randomAlphanumeric(100);
public final static Instant DEPOSIT_2_CREATED = Instant.now().minus(2, ChronoUnit.HOURS);
public final static Instant DEPOSIT_2_MODIFIED = Instant.now();
public final static LicenseTypeDto DEPOSIT_2_LICENSE = LicenseTypeDto.CC_BY;
public final static String DEPOSIT_2_STATE = "draft";
public final static Boolean DEPOSIT_2_SUBMITTED = false;
public final static String FILE_1_CHECKSUM = "deadbeef";
public final static String FILE_1_NAME = "data.csv";
public final static String FILE_1_ID = "73d5674b-2bda-400c-844e-4eef309afe5e";
......@@ -35,15 +52,6 @@ public abstract class BaseUnitTest {
public final static String DEPOSIT_1_DOI = "10.5072/zenodo.542201";
public final static Long DEPOSIT_1_REC_ID = 542201L;
public final static PreserveDoiDto DEPOSIT_1_PRESERVE_DOI = PreserveDoiDto.builder()
.doi(DEPOSIT_1_DOI)
.recId(DEPOSIT_1_REC_ID)
.build();
public final static MetadataDto FILE_1_METADATA_DTO = MetadataDto.builder()
.prereserveDoi(DEPOSIT_1_PRESERVE_DOI)
.build();
public final static FileLinksDto FILE_1_LINKS_DTO = FileLinksDto.builder()
.download(FILE_1_LINKS_DOWNLOAD)
.self(FILE_1_LINKS_SELF)
......@@ -57,18 +65,18 @@ public abstract class BaseUnitTest {
.links(FILE_1_LINKS_DTO)
.build();
public final static DepositDto DEPOSIT_1_DTO = DepositDto.builder()
public final static DepositDto DEPOSIT_1_RETURN_DTO = DepositDto.builder()
.id(DEPOSIT_1_ID)
.title(DEPOSIT_1_TITLE)
.created(DEPOSIT_1_CREATED)
.state(DEPOSIT_1_STATE)
.submitted(DEPOSIT_1_SUBMITTED)
.conceptRecId(DEPOSIT_1_CONCEPT_RECORD_ID)
.owner(DEPOSIT_1_OWNER)
.modified(DEPOSIT_1_MODIFIED)
.recordId(DEPOSIT_1_RECORD_ID)
.files(List.of(FILE_1_DTO))
.metadata(FILE_1_METADATA_DTO)
.build();
public final static ContributorDto CONTRIBUTOR_1_DTO = ContributorDto.builder()
.name(CONTRIBUTOR_1_NAME)
.affiliation(CONTRIBUTOR_1_AFFILIATION)
.build();
}
......@@ -5,6 +5,7 @@ import at.tuwien.api.zenodo.deposit.DepositDto;
import at.tuwien.config.ReadyConfig;
import at.tuwien.exception.ZenodoApiException;
import at.tuwien.exception.ZenodoAuthenticationException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -32,7 +33,7 @@ public class ZenodoServiceIntegrationTest extends BaseUnitTest {
public void listDeposit_succeeds() throws ZenodoApiException, ZenodoAuthenticationException {
/* test */
final List<DepositDto> response = zenodoService.listStoredCitations();
zenodoService.listCitations();
}
@Test
......@@ -40,6 +41,7 @@ public class ZenodoServiceIntegrationTest extends BaseUnitTest {
/* test */
final DepositDto response = zenodoService.storeCitation();
Assertions.assertNotNull(response.getId());
}
}
\ No newline at end of file
......@@ -7,9 +7,11 @@ import at.tuwien.exception.ZenodoApiException;
import at.tuwien.exception.ZenodoAuthenticationException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
......@@ -22,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;
@SpringBootTest
@ExtendWith(SpringExtension.class)
......@@ -38,56 +40,42 @@ public class ZenodoServiceUnitTest extends BaseUnitTest {
private RestTemplate zenodoTemplate;
@Test
public void listDeposit_succeeds() throws ZenodoApiException, ZenodoAuthenticationException {
public void listCitations_succeeds() throws ZenodoApiException, ZenodoAuthenticationException {
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.GET), eq(null), eq(DepositDto[].class), anyString()))
.thenReturn(ResponseEntity.ok(new DepositDto[]{DEPOSIT_1_DTO}));
.thenReturn(ResponseEntity.ok(new DepositDto[]{DEPOSIT_1_RETURN_DTO}));
/* test */
final List<DepositDto> response = zenodoService.listStoredCitations();
final List<DepositDto> response = zenodoService.listCitations();
assertEquals(1, response.size());
assertEquals(DEPOSIT_1_ID, response.get(0).getId());
}
@Test
public void listDeposit_noToken_fails() {
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.GET), eq(null), eq(DepositDto[].class), anyString()))
.thenReturn(ResponseEntity.status(HttpStatus.UNAUTHORIZED).build());
/* test */
assertThrows(ZenodoAuthenticationException.class, () -> {
zenodoService.listStoredCitations();
});
}
@Test
public void listDeposit_empty_fails() {
public void listCitations_empty_fails() {
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.GET), eq(null), eq(DepositDto[].class), anyString()))
.thenReturn(ResponseEntity.ok().build());
/* test */
assertThrows(ZenodoApiException.class, () -> {
zenodoService.listStoredCitations();
zenodoService.listCitations();
});
}
@Test
public void createDeposit_succeed() throws ZenodoApiException, ZenodoAuthenticationException {
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.POST), eq(null), eq(DepositDto.class), anyString()))
.thenReturn(ResponseEntity.ok(DEPOSIT_1_DTO));
public void storeCitation_succeed() throws ZenodoApiException, ZenodoAuthenticationException {
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.POST), Mockito.<HttpEntity<String>>any(), eq(DepositDto.class), anyString()))
.thenReturn(ResponseEntity.status(HttpStatus.CREATED)
.body(DEPOSIT_1_RETURN_DTO));
/* test */
final DepositDto response = zenodoService.storeCitation();
}
@Test
public void createDeposit_noToken_fails() {
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.POST), eq(null), eq(DepositDto.class), anyString()))
.thenReturn(ResponseEntity.status(HttpStatus.UNAUTHORIZED).build());
public void deleteCitation_succeeds() {
}
/* test */
assertThrows(ZenodoAuthenticationException.class, () -> {
zenodoService.storeCitation();
});
@Test
public void deleteCitation_noId_fails() {
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment