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
Branches
Tags
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/ ...@@ -4,6 +4,9 @@ target/
!**/src/main/**/target/ !**/src/main/**/target/
!**/src/test/**/target/ !**/src/test/**/target/
# Environment
.env
# IDE # IDE
fda-analyse-service/venv fda-analyse-service/venv
.git.bfg-* .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; package at.tuwien.api.zenodo.deposit;
import at.tuwien.api.zenodo.MetadataDto;
import at.tuwien.api.zenodo.files.FileDto; import at.tuwien.api.zenodo.files.FileDto;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*; import lombok.*;
import java.time.Instant;
import java.util.List; import java.util.List;
@Getter @Getter
...@@ -13,23 +11,36 @@ import java.util.List; ...@@ -13,23 +11,36 @@ import java.util.List;
@Builder @Builder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
/**
* TODO add created, modified, embargodate with +00:00 timezone
*/
public class DepositDto { public class DepositDto {
private String description;
@JsonProperty("conceptrecid") @JsonProperty("conceptrecid")
private Long conceptRecId; private Long conceptRecId;
private Instant created; private Long owner;
private List<FileDto> files;
private Long id; @JsonProperty("access_conditions")
private String accessConditions;
private Instant modified; private String doi;
private Long owner; private LinksDto links;
private MetadataDto metadata; private MetadataDto metadata;
@JsonProperty("prereserve_doi")
private Boolean prereserveDoi;
private ContributorDto[] contributors;
private List<FileDto> files;
private Long id;
@JsonProperty("record_id") @JsonProperty("record_id")
private Long recordId; 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 com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*; import lombok.*;
......
package at.tuwien.api.zenodo; package at.tuwien.api.zenodo.deposit;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*; import lombok.*;
@Getter @Getter
...@@ -12,7 +11,6 @@ public class PreserveDoiDto { ...@@ -12,7 +11,6 @@ public class PreserveDoiDto {
private String doi; 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 @@ ...@@ -26,14 +26,9 @@
<java.version>11</java.version> <java.version>11</java.version>
<spring-cloud.version>3.0.1</spring-cloud.version> <spring-cloud.version>3.0.1</spring-cloud.version>
<mapstruct.version>1.4.2.Final</mapstruct.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> <swagger.version>2.1.7</swagger.version>
<springfox.version>3.0.0</springfox.version> <springfox.version>3.0.0</springfox.version>
<jacoco.version>0.8.7</jacoco.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> </properties>
<dependencies> <dependencies>
...@@ -54,11 +49,6 @@ ...@@ -54,11 +49,6 @@
<artifactId>spring-cloud-starter-bootstrap</artifactId> <artifactId>spring-cloud-starter-bootstrap</artifactId>
<version>${spring-cloud.version}</version> <version>${spring-cloud.version}</version>
</dependency> </dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${javax-rs-api.version}</version>
</dependency>
<!-- Entities and API --> <!-- Entities and API -->
<dependency> <dependency>
<groupId>at.tuwien</groupId> <groupId>at.tuwien</groupId>
...@@ -84,6 +74,12 @@ ...@@ -84,6 +74,12 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> </dependency>
<!-- Zenodo -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-bom.version}</version>
</dependency>
<!-- Testing --> <!-- Testing -->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
......
package at.tuwien; package at.tuwien;
import at.tuwien.api.zenodo.MetadataDto; import at.tuwien.api.zenodo.deposit.ContributorDto;
import at.tuwien.api.zenodo.PreserveDoiDto;
import at.tuwien.api.zenodo.deposit.DepositDto; 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.FileDto;
import at.tuwien.api.zenodo.files.FileLinksDto; import at.tuwien.api.zenodo.files.FileLinksDto;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.TestPropertySource;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.List; import java.util.List;
...@@ -16,14 +18,29 @@ public abstract class BaseUnitTest { ...@@ -16,14 +18,29 @@ public abstract class BaseUnitTest {
public final static Long DEPOSIT_1_ID = 1L; public final static Long DEPOSIT_1_ID = 1L;
public final static String DEPOSIT_1_TITLE = "Super cool document"; 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_CREATED = Instant.now().minus(1, ChronoUnit.HOURS);
public final static Instant DEPOSIT_1_MODIFIED = Instant.now(); 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 Boolean DEPOSIT_1_SUBMITTED = false;
public final static Long DEPOSIT_1_RECORD_ID = 1899L; 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_CONCEPT_RECORD_ID = 143L;
public final static Long DEPOSIT_1_OWNER = 144L; 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_CHECKSUM = "deadbeef";
public final static String FILE_1_NAME = "data.csv"; public final static String FILE_1_NAME = "data.csv";
public final static String FILE_1_ID = "73d5674b-2bda-400c-844e-4eef309afe5e"; public final static String FILE_1_ID = "73d5674b-2bda-400c-844e-4eef309afe5e";
...@@ -35,15 +52,6 @@ public abstract class BaseUnitTest { ...@@ -35,15 +52,6 @@ public abstract class BaseUnitTest {
public final static String DEPOSIT_1_DOI = "10.5072/zenodo.542201"; public final static String DEPOSIT_1_DOI = "10.5072/zenodo.542201";
public final static Long DEPOSIT_1_REC_ID = 542201L; 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() public final static FileLinksDto FILE_1_LINKS_DTO = FileLinksDto.builder()
.download(FILE_1_LINKS_DOWNLOAD) .download(FILE_1_LINKS_DOWNLOAD)
.self(FILE_1_LINKS_SELF) .self(FILE_1_LINKS_SELF)
...@@ -57,18 +65,18 @@ public abstract class BaseUnitTest { ...@@ -57,18 +65,18 @@ public abstract class BaseUnitTest {
.links(FILE_1_LINKS_DTO) .links(FILE_1_LINKS_DTO)
.build(); .build();
public final static DepositDto DEPOSIT_1_DTO = DepositDto.builder() public final static DepositDto DEPOSIT_1_RETURN_DTO = DepositDto.builder()
.id(DEPOSIT_1_ID) .id(DEPOSIT_1_ID)
.title(DEPOSIT_1_TITLE) .title(DEPOSIT_1_TITLE)
.created(DEPOSIT_1_CREATED)
.state(DEPOSIT_1_STATE) .state(DEPOSIT_1_STATE)
.submitted(DEPOSIT_1_SUBMITTED) .submitted(DEPOSIT_1_SUBMITTED)
.conceptRecId(DEPOSIT_1_CONCEPT_RECORD_ID)
.owner(DEPOSIT_1_OWNER)
.modified(DEPOSIT_1_MODIFIED)
.recordId(DEPOSIT_1_RECORD_ID) .recordId(DEPOSIT_1_RECORD_ID)
.files(List.of(FILE_1_DTO)) .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(); .build();
} }
...@@ -5,6 +5,7 @@ import at.tuwien.api.zenodo.deposit.DepositDto; ...@@ -5,6 +5,7 @@ import at.tuwien.api.zenodo.deposit.DepositDto;
import at.tuwien.config.ReadyConfig; import at.tuwien.config.ReadyConfig;
import at.tuwien.exception.ZenodoApiException; import at.tuwien.exception.ZenodoApiException;
import at.tuwien.exception.ZenodoAuthenticationException; import at.tuwien.exception.ZenodoAuthenticationException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -32,7 +33,7 @@ public class ZenodoServiceIntegrationTest extends BaseUnitTest { ...@@ -32,7 +33,7 @@ public class ZenodoServiceIntegrationTest extends BaseUnitTest {
public void listDeposit_succeeds() throws ZenodoApiException, ZenodoAuthenticationException { public void listDeposit_succeeds() throws ZenodoApiException, ZenodoAuthenticationException {
/* test */ /* test */
final List<DepositDto> response = zenodoService.listStoredCitations(); zenodoService.listCitations();
} }
@Test @Test
...@@ -40,6 +41,7 @@ public class ZenodoServiceIntegrationTest extends BaseUnitTest { ...@@ -40,6 +41,7 @@ public class ZenodoServiceIntegrationTest extends BaseUnitTest {
/* test */ /* test */
final DepositDto response = zenodoService.storeCitation(); final DepositDto response = zenodoService.storeCitation();
Assertions.assertNotNull(response.getId());
} }
} }
\ No newline at end of file
...@@ -7,9 +7,11 @@ import at.tuwien.exception.ZenodoApiException; ...@@ -7,9 +7,11 @@ import at.tuwien.exception.ZenodoApiException;
import at.tuwien.exception.ZenodoAuthenticationException; import at.tuwien.exception.ZenodoAuthenticationException;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
...@@ -22,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; ...@@ -22,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.*;
@SpringBootTest @SpringBootTest
@ExtendWith(SpringExtension.class) @ExtendWith(SpringExtension.class)
...@@ -38,56 +40,42 @@ public class ZenodoServiceUnitTest extends BaseUnitTest { ...@@ -38,56 +40,42 @@ public class ZenodoServiceUnitTest extends BaseUnitTest {
private RestTemplate zenodoTemplate; private RestTemplate zenodoTemplate;
@Test @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())) 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 */ /* test */
final List<DepositDto> response = zenodoService.listStoredCitations(); final List<DepositDto> response = zenodoService.listCitations();
assertEquals(1, response.size()); assertEquals(1, response.size());
assertEquals(DEPOSIT_1_ID, response.get(0).getId());
} }
@Test @Test
public void listDeposit_noToken_fails() { public void listCitations_empty_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() {
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.GET), eq(null), eq(DepositDto[].class), anyString())) when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.GET), eq(null), eq(DepositDto[].class), anyString()))
.thenReturn(ResponseEntity.ok().build()); .thenReturn(ResponseEntity.ok().build());
/* test */ /* test */
assertThrows(ZenodoApiException.class, () -> { assertThrows(ZenodoApiException.class, () -> {
zenodoService.listStoredCitations(); zenodoService.listCitations();
}); });
} }
@Test @Test
public void createDeposit_succeed() throws ZenodoApiException, ZenodoAuthenticationException { public void storeCitation_succeed() throws ZenodoApiException, ZenodoAuthenticationException {
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.POST), eq(null), eq(DepositDto.class), anyString())) when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.POST), Mockito.<HttpEntity<String>>any(), eq(DepositDto.class), anyString()))
.thenReturn(ResponseEntity.ok(DEPOSIT_1_DTO)); .thenReturn(ResponseEntity.status(HttpStatus.CREATED)
.body(DEPOSIT_1_RETURN_DTO));
/* test */ /* test */
final DepositDto response = zenodoService.storeCitation(); final DepositDto response = zenodoService.storeCitation();
} }
@Test @Test
public void createDeposit_noToken_fails() { public void deleteCitation_succeeds() {
when(zenodoTemplate.exchange(anyString(), eq(HttpMethod.POST), eq(null), eq(DepositDto.class), anyString())) }
.thenReturn(ResponseEntity.status(HttpStatus.UNAUTHORIZED).build());
/* test */ @Test
assertThrows(ZenodoAuthenticationException.class, () -> { public void deleteCitation_noId_fails() {
zenodoService.storeCitation();
});
} }
} }
\ 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