diff --git a/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/core/models/AccessionVersionsWrapper.java b/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/core/models/AccessionVersionsWrapper.java index d8b16598..9e95dc63 100644 --- a/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/core/models/AccessionVersionsWrapper.java +++ b/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/core/models/AccessionVersionsWrapper.java @@ -23,6 +23,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -65,4 +66,14 @@ public ACCESSION getAccession() { public List> getModelWrappers() { return data; } + + public Optional> getVersion(int version) { + for (AccessionWrapper wrapper : data) { + if (wrapper.getVersion() == version) { + return Optional.of(wrapper); + } + } + return Optional.empty(); + } + } \ No newline at end of file diff --git a/accession-commons-jpa/pom.xml b/accession-commons-jpa/pom.xml index 9fabaff5..2c0b041c 100644 --- a/accession-commons-jpa/pom.xml +++ b/accession-commons-jpa/pom.xml @@ -22,6 +22,12 @@ accession-commons-core 0.5-SNAPSHOT + + uk.ac.ebi.ampt2d + accession-commons-test + 0.5-SNAPSHOT + test + org.springframework.boot spring-boot-starter-data-jpa @@ -31,6 +37,23 @@ h2 test + + io.cucumber + cucumber-java8 + 2.4.0 + test + + + io.cucumber + cucumber-junit + 2.4.0 + test + + + io.cucumber + cucumber-spring + 2.4.0 + diff --git a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/AccessioningAcceptanceTests.java b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/AccessioningAcceptanceTests.java new file mode 100644 index 00000000..f5ec3e83 --- /dev/null +++ b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/AccessioningAcceptanceTests.java @@ -0,0 +1,37 @@ +/* + * + * Copyright 2018 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.ebi.ampt2d.commons.accession; + +import cucumber.api.CucumberOptions; +import cucumber.api.junit.Cucumber; +import org.junit.runner.RunWith; + +@RunWith(Cucumber.class) +@CucumberOptions( + features = { + "src/test/resources/features/accession.feature", + "src/test/resources/features/modification.feature", + "src/test/resources/features/merge.feature", + "src/test/resources/features/retrieval.feature"}, + plugin = { + "pretty", + "html:target/cucumber"}, + tags = {"not @ignore"}) +public class AccessioningAcceptanceTests { + +} diff --git a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/AccessioningServiceStepDefinitions.java b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/AccessioningServiceStepDefinitions.java new file mode 100644 index 00000000..f135f733 --- /dev/null +++ b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/AccessioningServiceStepDefinitions.java @@ -0,0 +1,143 @@ +/* + * + * Copyright 2018 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.ebi.ampt2d.commons.accession; + +import cucumber.api.java.en.And; +import cucumber.api.java.en.Given; +import cucumber.api.java.en.Then; +import cucumber.api.java.en.When; +import org.junit.Ignore; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; +import uk.ac.ebi.ampt2d.commons.accession.core.exceptions.AccessionDoesNotExistException; +import uk.ac.ebi.ampt2d.commons.accession.core.exceptions.AccessionMergedException; +import uk.ac.ebi.ampt2d.commons.accession.core.exceptions.HashAlreadyExistsException; +import uk.ac.ebi.ampt2d.test.configuration.CucumberTestConfiguration; +import uk.ac.ebi.ampt2d.test.models.TestModel; +import uk.ac.ebi.ampt2d.test.testers.AccessioningServiceTester; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static org.hibernate.validator.internal.util.Contracts.assertTrue; + +@Ignore +@RunWith(SpringRunner.class) +@SpringBootTest(classes = {CucumberTestConfiguration.class}) +@DirtiesContext +public class AccessioningServiceStepDefinitions { + + @Autowired + private AccessioningServiceTester tester; + + @Given("^already accessioned ([\\w-,]+)$") + @When("^user submits ([\\w-,]+) to accessioning service$") + public void submitObjectsToAccessioningService(String objects) { + tester.getOrCreate(toModels(objects)); + } + + private List toModels(String values) { + return Arrays.stream(values.split(",")).map(TestModel::of).collect(Collectors.toList()); + } + + @Then("^user received accessions: ([\\w-,]+)$") + public void iShouldReceiveAccessions(String objects) { + final String[] accessions = objects.split(","); + tester.getSingleVersionResults().assertAccessions(accessions); + } + + @When("^user sends patch (\\w+) for accession ([\\w-]+)$") + public void userSendsPatchInputForAccession(String patchData, String accession) { + tester.patch(accession, TestModel.of(patchData)); + } + + @Then("^user should receive (\\d+) (?:patches|patch) for accession ([\\w-]+)") + public void userShouldReceivePatchesForAccession(int totalPatches, String accession) { + tester.getLastMultipleVersionResult().assertAccession(accession).assertTotalVersions(totalPatches); + } + + @And("^patch must have versions increased$") + public void patchMustHaveVersionsIncreased() { + tester.getLastMultipleVersionResult().assertVersionsAreIncreased(); + } + + @Then("^user should receive 'accession does not exist'$") + public void userReceivesAccessionDoesNotExistError() { + tester.getLastMethodResponse().assertThrow(AccessionDoesNotExistException.class); + } + + @When("^user updates ([\\w-]+) patch (\\d+) with ([\\w-]+)$") + public void userUpdatesAccessionWithInput(String accession, int patch, String newData) { + tester.update(accession, patch, newData); + } + + + @And("^hash of patch (\\d+) should be ([\\w-]+)$") + public void hashOfPatchShouldBeHash(int version, String hash) { + tester.getLastMultipleVersionResult().assertHash(version, hash); + } + + @When("^user merges ([\\w-]+) into ([\\w-]+) reason: ([\\w ]+)$") + public void userMergesAWithB(String accessionA, String accessionB, String reason) { + tester.merge(accessionA, accessionB, reason); + } + + @Then("^user should receive 'hash already exists exception'$") + public void weShouldHaveAHashAlreadyExistsException() { + tester.getLastMethodResponse().assertThrow(HashAlreadyExistsException.class); + } + + @Then("^operation finished correctly$") + public void lastProcessFinishedOk() { + tester.getLastMethodResponse().assertNoException(); + } + + @Then("^user should receive 'accession already merged exception'$") + public void weShouldHaveAAccessionAlreadyMerged() { + tester.getLastMethodResponse().assertThrow(AccessionMergedException.class); + } + + @When("^user retrieves objects: ([\\w-,]+)$") + public void userRetrievesObjectA(String values) { + tester.get(toModels(values)); + } + + @Then("^user receives (\\d+) elements$") + public void userReceivesANumberOfElements(int numberOfElements) { + tester.getSingleVersionResults().assertSize(numberOfElements); + } + + @And("^user received a response with values: ([\\w-,]+)$") + public void userReceivedAResponseWithObject(String values) { + tester.getSingleVersionResults().assertAccessionValues(values.split(",")); + } + + @When("^user retrieves accessions: ([\\w-,]+)$") + public void userRetrievesAccessionsIdServiceA(String accessionIds) { + tester.getAccessions(accessionIds.split(",")); + } + + @Then("^user receives no data$") + public void userReceivesNoData() { + assertTrue(tester.getSingleVersionResults().getData().isEmpty(),"User received data"); + } +} diff --git a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicAccessioningServiceTest.java b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicAccessioningServiceTest.java index ca6cf0cb..67703fda 100644 --- a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicAccessioningServiceTest.java +++ b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicAccessioningServiceTest.java @@ -31,8 +31,8 @@ import uk.ac.ebi.ampt2d.commons.accession.core.exceptions.HashAlreadyExistsException; import uk.ac.ebi.ampt2d.commons.accession.core.models.AccessionVersionsWrapper; import uk.ac.ebi.ampt2d.commons.accession.core.models.AccessionWrapper; -import uk.ac.ebi.ampt2d.test.TestModel; import uk.ac.ebi.ampt2d.test.configuration.TestJpaDatabaseServiceTestConfiguration; +import uk.ac.ebi.ampt2d.test.models.TestModel; import uk.ac.ebi.ampt2d.test.persistence.TestRepository; import java.util.Arrays; diff --git a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/persistence/jpa/repositories/BaseJpaAccessionedObjectRepositoryTest.java b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/persistence/jpa/repositories/BaseJpaAccessionedObjectRepositoryTest.java index 26ed2f64..f250f0ef 100644 --- a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/persistence/jpa/repositories/BaseJpaAccessionedObjectRepositoryTest.java +++ b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/persistence/jpa/repositories/BaseJpaAccessionedObjectRepositoryTest.java @@ -24,8 +24,8 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import uk.ac.ebi.ampt2d.commons.accession.core.models.AccessionWrapper; -import uk.ac.ebi.ampt2d.test.TestModel; import uk.ac.ebi.ampt2d.test.configuration.TestJpaDatabaseServiceTestConfiguration; +import uk.ac.ebi.ampt2d.test.models.TestModel; import uk.ac.ebi.ampt2d.test.persistence.TestEntity; import uk.ac.ebi.ampt2d.test.persistence.TestRepository; diff --git a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/persistence/jpa/services/JpaBasicSpringDataRepositoryDatabaseServiceTest.java b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/persistence/jpa/services/JpaBasicSpringDataRepositoryDatabaseServiceTest.java index a3587a7b..78e8cd57 100644 --- a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/persistence/jpa/services/JpaBasicSpringDataRepositoryDatabaseServiceTest.java +++ b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/persistence/jpa/services/JpaBasicSpringDataRepositoryDatabaseServiceTest.java @@ -34,8 +34,8 @@ import uk.ac.ebi.ampt2d.commons.accession.core.models.AccessionWrapper; import uk.ac.ebi.ampt2d.commons.accession.core.models.EventType; import uk.ac.ebi.ampt2d.commons.accession.core.models.SaveResponse; -import uk.ac.ebi.ampt2d.test.TestModel; import uk.ac.ebi.ampt2d.test.configuration.TestJpaDatabaseServiceTestConfiguration; +import uk.ac.ebi.ampt2d.test.models.TestModel; import uk.ac.ebi.ampt2d.test.persistence.TestInactiveAccessionEntity; import uk.ac.ebi.ampt2d.test.persistence.TestInactiveAccessionRepository; import uk.ac.ebi.ampt2d.test.persistence.TestRepository; diff --git a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/BasicRestControllerTestConfiguration.java b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/BasicRestControllerTestConfiguration.java index 980d3f35..412f65ee 100644 --- a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/BasicRestControllerTestConfiguration.java +++ b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/BasicRestControllerTestConfiguration.java @@ -35,7 +35,7 @@ import uk.ac.ebi.ampt2d.commons.accession.persistence.services.InactiveAccessionService; import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.repositories.BasicJpaAccessionedObjectCustomRepositoryImpl; import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.service.BasicJpaInactiveAccessionService; -import uk.ac.ebi.ampt2d.test.TestModel; +import uk.ac.ebi.ampt2d.test.models.TestModel; import uk.ac.ebi.ampt2d.test.persistence.TestEntity; import uk.ac.ebi.ampt2d.test.persistence.TestInactiveAccessionEntity; import uk.ac.ebi.ampt2d.test.persistence.TestInactiveAccessionRepository; diff --git a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/CucumberTestConfiguration.java b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/CucumberTestConfiguration.java new file mode 100644 index 00000000..022ed530 --- /dev/null +++ b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/CucumberTestConfiguration.java @@ -0,0 +1,110 @@ +/* + * + * Copyright 2018 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.ebi.ampt2d.test.configuration; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.boot.test.autoconfigure.core.AutoConfigureCache; +import org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureDataJpa; +import org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureTestEntityManager; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Scope; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import uk.ac.ebi.ampt2d.commons.accession.core.AccessioningService; +import uk.ac.ebi.ampt2d.commons.accession.core.BasicAccessioningService; +import uk.ac.ebi.ampt2d.commons.accession.core.DatabaseService; +import uk.ac.ebi.ampt2d.commons.accession.generators.SingleAccessionGenerator; +import uk.ac.ebi.ampt2d.commons.accession.hashing.SHA1HashingFunction; +import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.repositories.BasicJpaAccessionedObjectCustomRepositoryImpl; +import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.service.BasicJpaInactiveAccessionService; +import uk.ac.ebi.ampt2d.commons.accession.persistence.repositories.IAccessionedObjectCustomRepository; +import uk.ac.ebi.ampt2d.commons.accession.persistence.services.BasicSpringDataRepositoryDatabaseService; +import uk.ac.ebi.ampt2d.commons.accession.persistence.services.InactiveAccessionService; +import uk.ac.ebi.ampt2d.test.models.TestModel; +import uk.ac.ebi.ampt2d.test.persistence.TestEntity; +import uk.ac.ebi.ampt2d.test.persistence.TestInactiveAccessionEntity; +import uk.ac.ebi.ampt2d.test.persistence.TestInactiveAccessionRepository; +import uk.ac.ebi.ampt2d.test.persistence.TestRepository; +import uk.ac.ebi.ampt2d.test.persistence.TestStringHistoryRepository; +import uk.ac.ebi.ampt2d.test.persistence.TestStringOperationEntity; +import uk.ac.ebi.ampt2d.test.testers.AccessioningServiceTester; + +@Configuration +@ComponentScan(basePackageClasses = IAccessionedObjectCustomRepository.class) +@EnableJpaAuditing +@ComponentScan(basePackageClasses = BasicJpaAccessionedObjectCustomRepositoryImpl.class) +@EntityScan("uk.ac.ebi.ampt2d.test.persistence") +@EnableJpaRepositories(basePackages = {"uk.ac.ebi.ampt2d.test.persistence", + "uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.repositories" +}) +@AutoConfigureCache +@AutoConfigureDataJpa +@AutoConfigureTestEntityManager +public class CucumberTestConfiguration { + + @Autowired + private TestRepository repository; + + @Autowired + private TestStringHistoryRepository historyRepository; + + @Autowired + private TestInactiveAccessionRepository testInactiveAccessionRepository; + + @Bean + public DatabaseService databaseService() { + return new BasicSpringDataRepositoryDatabaseService<>( + repository, + TestEntity::new, + inactiveService() + ); + } + + @Bean + public InactiveAccessionService inactiveService() { + return new BasicJpaInactiveAccessionService<>( + historyRepository, + TestInactiveAccessionEntity::new, + testInactiveAccessionRepository, + TestStringOperationEntity::new + ); + } + + @Bean + public AccessioningService accessioningService() { + return new BasicAccessioningService<>( + SingleAccessionGenerator.ofHashAccessionGenerator( + TestModel::getValue, + s -> "id-service-" + s + ), + databaseService(), + TestModel::getValue, + new SHA1HashingFunction() + ); + } + + @Bean + @Scope("cucumber-glue") + public AccessioningServiceTester accessioningServiceTester() { + return new AccessioningServiceTester(accessioningService()); + } + +} diff --git a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/TestJpaDatabaseServiceTestConfiguration.java b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/TestJpaDatabaseServiceTestConfiguration.java index 0d5d7670..c803f703 100644 --- a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/TestJpaDatabaseServiceTestConfiguration.java +++ b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/TestJpaDatabaseServiceTestConfiguration.java @@ -19,6 +19,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.boot.test.autoconfigure.core.AutoConfigureCache; +import org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureDataJpa; +import org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureTestEntityManager; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -34,7 +37,7 @@ import uk.ac.ebi.ampt2d.commons.accession.persistence.services.InactiveAccessionService; import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.repositories.BasicJpaAccessionedObjectCustomRepositoryImpl; import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.service.BasicJpaInactiveAccessionService; -import uk.ac.ebi.ampt2d.test.TestModel; +import uk.ac.ebi.ampt2d.test.models.TestModel; import uk.ac.ebi.ampt2d.test.persistence.TestEntity; import uk.ac.ebi.ampt2d.test.persistence.TestInactiveAccessionEntity; import uk.ac.ebi.ampt2d.test.persistence.TestInactiveAccessionRepository; @@ -50,6 +53,9 @@ @EnableJpaRepositories(basePackages = {"uk.ac.ebi.ampt2d.test.persistence", "uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.repositories" }) +@AutoConfigureCache +@AutoConfigureDataJpa +@AutoConfigureTestEntityManager public class TestJpaDatabaseServiceTestConfiguration { @Autowired diff --git a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/persistence/TestEntity.java b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/persistence/TestEntity.java index fe6d43e5..4051db6c 100644 --- a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/persistence/TestEntity.java +++ b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/persistence/TestEntity.java @@ -19,7 +19,7 @@ import uk.ac.ebi.ampt2d.commons.accession.core.models.AccessionWrapper; import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.entities.AccessionedEntity; -import uk.ac.ebi.ampt2d.test.TestModel; +import uk.ac.ebi.ampt2d.test.models.TestModel; import javax.persistence.Entity; diff --git a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/persistence/TestInactiveAccessionEntity.java b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/persistence/TestInactiveAccessionEntity.java index 9ac88cb0..d60c813a 100644 --- a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/persistence/TestInactiveAccessionEntity.java +++ b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/persistence/TestInactiveAccessionEntity.java @@ -18,7 +18,7 @@ package uk.ac.ebi.ampt2d.test.persistence; import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.entities.InactiveAccessionEntity; -import uk.ac.ebi.ampt2d.test.TestModel; +import uk.ac.ebi.ampt2d.test.models.TestModel; import javax.persistence.Entity; import java.time.LocalDateTime; @@ -41,11 +41,6 @@ public String getValue() { return something; } - @Override - public String getAccession() { - return null; - } - @Override public String getHashedMessage() { return null; diff --git a/accession-commons-jpa/src/test/resources/features/accession.feature b/accession-commons-jpa/src/test/resources/features/accession.feature new file mode 100644 index 00000000..aaea86d6 --- /dev/null +++ b/accession-commons-jpa/src/test/resources/features/accession.feature @@ -0,0 +1,28 @@ +Feature: Accession generation + + Scenario Outline: I want to receive unique accession for my newly submitted / created objects, so they are + identifiable in the system. + When user submits to accessioning service + Then user received accessions: + Examples: + | input | accessions | + | A | id-service-A | + | B,C | id-service-B,id-service-C | + | D,E,F | id-service-D,id-service-E,id-service-F | + + Scenario Outline: I want to receive accessions for a mix of new and pre-existing objects. + Given already accessioned + When user submits to accessioning service + Then user received accessions: + Examples: + | objects | input | accessions | + | B | A | id-service-A | + | A | A | id-service-A | + | C | B,C | id-service-B,id-service-C | + | A,B,C,E | D,E,F | id-service-D,id-service-E,id-service-F | + + @ignore + Scenario: I want to generate accession in a space, based on clustering accessions from another existing space. + When user provides a list of ss accessions + Then user receives a rs list of accessions + And all rs must have at least one ss accessioned \ No newline at end of file diff --git a/accession-commons-jpa/src/test/resources/features/merge.feature b/accession-commons-jpa/src/test/resources/features/merge.feature new file mode 100644 index 00000000..6904f843 --- /dev/null +++ b/accession-commons-jpa/src/test/resources/features/merge.feature @@ -0,0 +1,37 @@ +Feature: Accession merge + + Scenario: I want to merge an object but the destination object does not exist. + Given already accessioned A + When user merges id-service-A into id-service-B reason: because i say so + Then user should receive 'accession does not exist' + + Scenario: I want to merge an object but the origin object does not exist. + Given already accessioned B + When user merges id-service-A into id-service-B reason: because i say so + Then user should receive 'accession does not exist' + + Scenario: I want to merge an object but none of the two exist. + When user merges id-service-A into id-service-B reason: because i say so + Then user should receive 'accession does not exist' + + Scenario: I want to merge an object + Given already accessioned A + And already accessioned B + When user merges id-service-A into id-service-B reason: because i say so + Then operation finished correctly + + Scenario: I want to merge an object but the object has been already merged + Given already accessioned A + And already accessioned B + And already accessioned C + And user merges id-service-B into id-service-C reason: because i say so + When user merges id-service-A into id-service-B reason: because i say so + Then user should receive 'accession already merged exception' + + Scenario: I want to merge an object to another and then to a third one + Given already accessioned A + And already accessioned B + And already accessioned C + When user merges id-service-A into id-service-B reason: because i say so + When user merges id-service-B into id-service-C reason: because i say so + Then operation finished correctly \ No newline at end of file diff --git a/accession-commons-jpa/src/test/resources/features/modification.feature b/accession-commons-jpa/src/test/resources/features/modification.feature new file mode 100644 index 00000000..890fda6d --- /dev/null +++ b/accession-commons-jpa/src/test/resources/features/modification.feature @@ -0,0 +1,40 @@ +Feature: Accession modification + + Scenario Outline: I want to create a new patch of an existing object, in order to register improvements made to it + without losing access to the old information. + Given already accessioned + When user sends patch for accession + Then user should receive 2 patches for accession + And patch must have versions increased + Examples: + | objects | input | accession | + | A | AA | id-service-A | + | B | BB | id-service-B | + | A,B,C,E | AA | id-service-A | + + Scenario: I want to create a new patch of a non existing object + When user sends patch AA for accession id-service-A + Then user should receive 'accession does not exist' + + Scenario Outline: I want to update the fields that identify uniquely an object, + without losing access to the old information. + Given already accessioned + When user updates patch with + Then user should receive 1 patch for accession + And hash of patch 1 should be + Examples: + | objects | input | accession | patch | hash | + | A | AA | id-service-A | 1 | 801C34269F74ED383FC97DE33604B8A905ADB635 | + | B | BB | id-service-B | 1 | 71C9DB717578B9EE49A59E69375C16C0627DFFEF | + | A,B,C,E | AA | id-service-A | 1 | 801C34269F74ED383FC97DE33604B8A905ADB635 | + + Scenario: I want to update the fields that identify uniquely an object, but another object already has the same + values. + Given already accessioned A,B + When user updates id-service-A patch 1 with B + Then user should receive 'hash already exists exception' + + Scenario: I want to update an object that does not exist + When user updates id-service-A patch 1 with AB + Then user should receive 'accession does not exist' + diff --git a/accession-commons-jpa/src/test/resources/features/retrieval.feature b/accession-commons-jpa/src/test/resources/features/retrieval.feature new file mode 100644 index 00000000..99edc725 --- /dev/null +++ b/accession-commons-jpa/src/test/resources/features/retrieval.feature @@ -0,0 +1,34 @@ +Feature: Accession retrieval + + Scenario: I want to get the accession of an object that is not in the system. + When user retrieves objects: A + Then user receives 0 elements + + Scenario: I want to get the accession of an object that it is on the system. + Given already accessioned A + When user retrieves objects: A + Then user receives 1 elements + And user received a response with values: A + And user received accessions: id-service-A + + Scenario: I want to get accessions of a mixture of objects that may or not be on the system. + Given already accessioned A + Given already accessioned C + Given already accessioned E + When user retrieves objects: A,B,C,D,E + Then user receives 3 elements + And user received a response with values: A,C,E + And user received accessions: id-service-A,id-service-C,id-service-E + + Scenario: I want to get a specific accession that doesn't exist in the system. + When user retrieves accessions: id-service-A + Then operation finished correctly + And user receives no data + + Scenario: I want to retrieve an accession that exists in the system + Given already accessioned A + Given already accessioned B + When user retrieves accessions: id-service-A,id-service-B + Then user receives 2 elements + And user received a response with values: A,B + And user received accessions: id-service-A,id-service-B \ No newline at end of file diff --git a/accession-commons-mongodb/pom.xml b/accession-commons-mongodb/pom.xml index cbee815e..a78ff364 100644 --- a/accession-commons-mongodb/pom.xml +++ b/accession-commons-mongodb/pom.xml @@ -17,6 +17,12 @@ + + uk.ac.ebi.ampt2d + accession-commons-test + 0.5-SNAPSHOT + test + uk.ac.ebi.ampt2d accession-commons-core @@ -32,6 +38,23 @@ 1.0.0-rc.5 test + + io.cucumber + cucumber-java8 + 2.4.0 + test + + + io.cucumber + cucumber-junit + 2.4.0 + test + + + io.cucumber + cucumber-spring + 2.4.0 + diff --git a/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/commons/accession/AccessioningAcceptanceTests.java b/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/commons/accession/AccessioningAcceptanceTests.java new file mode 100644 index 00000000..f5ec3e83 --- /dev/null +++ b/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/commons/accession/AccessioningAcceptanceTests.java @@ -0,0 +1,37 @@ +/* + * + * Copyright 2018 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.ebi.ampt2d.commons.accession; + +import cucumber.api.CucumberOptions; +import cucumber.api.junit.Cucumber; +import org.junit.runner.RunWith; + +@RunWith(Cucumber.class) +@CucumberOptions( + features = { + "src/test/resources/features/accession.feature", + "src/test/resources/features/modification.feature", + "src/test/resources/features/merge.feature", + "src/test/resources/features/retrieval.feature"}, + plugin = { + "pretty", + "html:target/cucumber"}, + tags = {"not @ignore"}) +public class AccessioningAcceptanceTests { + +} diff --git a/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/commons/accession/AccessioningServiceStepDefinitions.java b/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/commons/accession/AccessioningServiceStepDefinitions.java new file mode 100644 index 00000000..35782f57 --- /dev/null +++ b/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/commons/accession/AccessioningServiceStepDefinitions.java @@ -0,0 +1,162 @@ +/* + * + * Copyright 2018 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.ebi.ampt2d.commons.accession; + +import com.lordofthejars.nosqlunit.mongodb.MongoDbConfigurationBuilder; +import com.lordofthejars.nosqlunit.mongodb.MongoDbRule; +import cucumber.api.java.Before; +import cucumber.api.java.en.And; +import cucumber.api.java.en.Given; +import cucumber.api.java.en.Then; +import cucumber.api.java.en.When; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationContext; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; +import uk.ac.ebi.ampt2d.commons.accession.core.exceptions.AccessionDoesNotExistException; +import uk.ac.ebi.ampt2d.commons.accession.core.exceptions.AccessionMergedException; +import uk.ac.ebi.ampt2d.commons.accession.core.exceptions.HashAlreadyExistsException; +import uk.ac.ebi.ampt2d.test.configuration.MongoDbCucumberTestConfiguration; +import uk.ac.ebi.ampt2d.test.models.TestModel; +import uk.ac.ebi.ampt2d.test.rule.FixSpringMongoDbRule; +import uk.ac.ebi.ampt2d.test.testers.AccessioningServiceTester; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static org.hibernate.validator.internal.util.Contracts.assertTrue; + +@Ignore +@RunWith(SpringRunner.class) +@SpringBootTest(classes = {MongoDbCucumberTestConfiguration.class}) +@DirtiesContext +public class AccessioningServiceStepDefinitions { + + @Rule + public MongoDbRule mongoDbRule = new FixSpringMongoDbRule(MongoDbConfigurationBuilder.mongoDb() + .databaseName("accession-test").build()); + + //Required for nosql unit + @Autowired + private ApplicationContext applicationContext; + + @Autowired + private AccessioningServiceTester tester; + + @Before + public void setUp() { + mongoDbRule.getDatabaseOperation().deleteAll(); + } + + @Given("^already accessioned ([\\w-,]+)$") + @When("^user submits ([\\w-,]+) to accessioning service$") + public void submitObjectsToAccessioningService(String objects) { + tester.getOrCreate(toModels(objects)); + } + + private List toModels(String values) { + return Arrays.stream(values.split(",")).map(TestModel::of).collect(Collectors.toList()); + } + + @Then("^user received accessions: ([\\w-,]+)$") + public void iShouldReceiveAccessions(String objects) { + final String[] accessions = objects.split(","); + tester.getSingleVersionResults().assertAccessions(accessions); + } + + @When("^user sends patch (\\w+) for accession ([\\w-]+)$") + public void userSendsPatchInputForAccession(String patchData, String accession) { + tester.patch(accession, TestModel.of(patchData)); + } + + @Then("^user should receive (\\d+) (?:patches|patch) for accession ([\\w-]+)") + public void userShouldReceivePatchesForAccession(int totalPatches, String accession) { + tester.getLastMultipleVersionResult().assertAccession(accession).assertTotalVersions(totalPatches); + } + + @And("^patch must have versions increased$") + public void patchMustHaveVersionsIncreased() { + tester.getLastMultipleVersionResult().assertVersionsAreIncreased(); + } + + @Then("^user should receive 'accession does not exist'$") + public void userReceivesAccessionDoesNotExistError() { + tester.getLastMethodResponse().assertThrow(AccessionDoesNotExistException.class); + } + + @When("^user updates ([\\w-]+) patch (\\d+) with ([\\w-]+)$") + public void userUpdatesAccessionWithInput(String accession, int patch, String newData) { + tester.update(accession, patch, newData); + } + + + @And("^hash of patch (\\d+) should be ([\\w-]+)$") + public void hashOfPatchShouldBeHash(int version, String hash) { + tester.getLastMultipleVersionResult().assertHash(version, hash); + } + + @When("^user merges ([\\w-]+) into ([\\w-]+) reason: ([\\w ]+)$") + public void userMergesAWithB(String accessionA, String accessionB, String reason) { + tester.merge(accessionA, accessionB, reason); + } + + @Then("^user should receive 'hash already exists exception'$") + public void weShouldHaveAUnknownError() { + tester.getLastMethodResponse().assertThrow(HashAlreadyExistsException.class); + } + + @Then("^operation finished correctly$") + public void lastProcessFinishedOk() { + tester.getLastMethodResponse().assertNoException(); + } + + @Then("^user should receive 'accession already merged exception'$") + public void weShouldHaveAAccessionAlreadyMerged() { + tester.getLastMethodResponse().assertThrow(AccessionMergedException.class); + } + + @When("^user retrieves objects: ([\\w-,]+)$") + public void userRetrievesObjectA(String values) { + tester.get(toModels(values)); + } + + @Then("^user receives (\\d+) elements$") + public void userReceivesANumberOfElements(int numberOfElements) { + tester.getSingleVersionResults().assertSize(numberOfElements); + } + + @And("^user received a response with values: ([\\w-,]+)$") + public void userReceivedAResponseWithObject(String values) { + tester.getSingleVersionResults().assertAccessionValues(values.split(",")); + } + + @When("^user retrieves accessions: ([\\w-,]+)$") + public void userRetrievesAccessionsIdServiceA(String accessionIds) { + tester.getAccessions(accessionIds.split(",")); + } + + @Then("^user receives no data$") + public void userReceivesNoData() { + assertTrue(tester.getSingleVersionResults().getData().isEmpty(), "User received data"); + } +} diff --git a/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/commons/accession/persistence/mongodb/service/BasicMongoDbHistoryServiceTest.java b/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/commons/accession/persistence/mongodb/service/BasicMongoDbHistoryServiceTest.java index 7e3b9107..d30626fe 100644 --- a/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/commons/accession/persistence/mongodb/service/BasicMongoDbHistoryServiceTest.java +++ b/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/commons/accession/persistence/mongodb/service/BasicMongoDbHistoryServiceTest.java @@ -30,22 +30,18 @@ import org.springframework.test.context.junit4.SpringRunner; import uk.ac.ebi.ampt2d.commons.accession.core.AccessioningService; import uk.ac.ebi.ampt2d.commons.accession.core.HistoryService; -import uk.ac.ebi.ampt2d.commons.accession.core.exceptions.AccessionCouldNotBeGeneratedException; -import uk.ac.ebi.ampt2d.commons.accession.core.exceptions.AccessionDeprecatedException; import uk.ac.ebi.ampt2d.commons.accession.core.exceptions.AccessionDoesNotExistException; -import uk.ac.ebi.ampt2d.commons.accession.core.exceptions.AccessionMergedException; -import uk.ac.ebi.ampt2d.commons.accession.core.exceptions.HashAlreadyExistsException; -import uk.ac.ebi.ampt2d.test.AccessionTester; -import uk.ac.ebi.ampt2d.test.HistoryTester; -import uk.ac.ebi.ampt2d.test.TestModel; import uk.ac.ebi.ampt2d.test.configuration.MongoDbTestConfiguration; +import uk.ac.ebi.ampt2d.test.models.TestModel; import uk.ac.ebi.ampt2d.test.rule.FixSpringMongoDbRule; +import uk.ac.ebi.ampt2d.test.testers.AccessioningServiceTester; +import uk.ac.ebi.ampt2d.test.testers.HistoryTester; -import static uk.ac.ebi.ampt2d.test.HistoryTester.assertEventIsCreated; -import static uk.ac.ebi.ampt2d.test.HistoryTester.assertEventIsDeprecated; -import static uk.ac.ebi.ampt2d.test.HistoryTester.assertEventIsMerged; -import static uk.ac.ebi.ampt2d.test.HistoryTester.assertEventIsPatch; -import static uk.ac.ebi.ampt2d.test.HistoryTester.assertEventIsUpdated; +import static uk.ac.ebi.ampt2d.test.testers.HistoryTester.assertEventIsCreated; +import static uk.ac.ebi.ampt2d.test.testers.HistoryTester.assertEventIsDeprecated; +import static uk.ac.ebi.ampt2d.test.testers.HistoryTester.assertEventIsMerged; +import static uk.ac.ebi.ampt2d.test.testers.HistoryTester.assertEventIsPatch; +import static uk.ac.ebi.ampt2d.test.testers.HistoryTester.assertEventIsUpdated; @RunWith(SpringRunner.class) @SpringBootTest(classes = {MongoDbTestConfiguration.class}) @@ -73,8 +69,9 @@ public void testNoHistory() throws AccessionDoesNotExistException { @UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL) @Test - public void testHistoryNoOperations() throws AccessionDoesNotExistException, AccessionCouldNotBeGeneratedException { - getAccessionTester().accession("test-1"); + public void testHistoryNoOperations() throws AccessionDoesNotExistException { + getAccessionTester() + .getOrCreate("test-1"); getHistoryTester("id-test-1") .assertTotalEvents(1) .assertEvent(0, assertEventIsCreated()); @@ -82,11 +79,10 @@ public void testHistoryNoOperations() throws AccessionDoesNotExistException, Acc @UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL) @Test - public void testHistoryUpdate() throws AccessionDoesNotExistException, AccessionCouldNotBeGeneratedException, - AccessionMergedException, AccessionDeprecatedException, HashAlreadyExistsException { + public void testHistoryUpdate() throws AccessionDoesNotExistException { getAccessionTester() - .accession("test-2") - .update(1, "test-2-update-1"); + .getOrCreate("test-2") + .update("id-test-2", 1, "test-2-update-1"); getHistoryTester("id-test-2").assertTotalEvents(2) .assertEvent(0, assertEventIsCreated()) .assertEvent(1, assertEventIsUpdated("test-2-update-1", 1)); @@ -94,11 +90,10 @@ public void testHistoryUpdate() throws AccessionDoesNotExistException, Accession @UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL) @Test - public void testHistoryPatch() throws AccessionDoesNotExistException, AccessionCouldNotBeGeneratedException, - AccessionMergedException, AccessionDeprecatedException, HashAlreadyExistsException { + public void testHistoryPatch() throws AccessionDoesNotExistException { getAccessionTester() - .accession("test-3") - .patch("test-3-patch-2"); + .getOrCreate("test-3") + .patch("id-test-3", "test-3-patch-2"); getHistoryTester("id-test-3") .assertTotalEvents(2) .assertEvent(0, assertEventIsCreated()) @@ -107,12 +102,11 @@ public void testHistoryPatch() throws AccessionDoesNotExistException, AccessionC @UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL) @Test - public void testHistoryMultiplePatch() throws AccessionDoesNotExistException, AccessionCouldNotBeGeneratedException, - AccessionMergedException, AccessionDeprecatedException, HashAlreadyExistsException { + public void testHistoryMultiplePatch() throws AccessionDoesNotExistException { getAccessionTester() - .accession("test-3") - .patch("test-3-patch-2") - .patch("test-3-patch-3"); + .getOrCreate("test-3") + .patch("id-test-3", "test-3-patch-2") + .patch("id-test-3", "test-3-patch-3"); getHistoryTester("id-test-3") .assertTotalEvents(3) .assertEvent(0, assertEventIsCreated()) @@ -122,13 +116,12 @@ public void testHistoryMultiplePatch() throws AccessionDoesNotExistException, Ac @UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL) @Test - public void testHistoryPatchAndUpdate() throws AccessionDoesNotExistException, - AccessionCouldNotBeGeneratedException, - AccessionMergedException, AccessionDeprecatedException, HashAlreadyExistsException { + public void testHistoryPatchAndUpdate() throws AccessionDoesNotExistException { getAccessionTester() - .accession("test-4") - .patch("test-4-patch-2") - .update(2, "test-4-update-patch-2"); + .getOrCreate("test-4") + .patch("id-test-4", "test-4-patch-2") + .update("id-test-4", 2, "test-4-update-patch-2"); + getHistoryTester("id-test-4") .assertTotalEvents(3) .assertEvent(0, assertEventIsCreated()) @@ -138,12 +131,11 @@ public void testHistoryPatchAndUpdate() throws AccessionDoesNotExistException, @UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL) @Test - public void testDeprecate() throws AccessionDoesNotExistException, - AccessionCouldNotBeGeneratedException, - AccessionMergedException, AccessionDeprecatedException, HashAlreadyExistsException { + public void testDeprecate() throws AccessionDoesNotExistException { getAccessionTester() - .accession("test-5") - .deprecate(); + .getOrCreate("test-5") + .deprecate("id-test-5", "reason") + .getLastMethodResponse().assertNoException(); getHistoryTester("id-test-5") .assertTotalEvents(2) .assertEvent(0, assertEventIsCreated()) @@ -152,14 +144,12 @@ public void testDeprecate() throws AccessionDoesNotExistException, @UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL) @Test - public void testMerge() throws AccessionDoesNotExistException, - AccessionCouldNotBeGeneratedException, - AccessionMergedException, AccessionDeprecatedException, HashAlreadyExistsException { - getAccessionTester() - .accession("test-merge-1"); + public void testMerge() throws AccessionDoesNotExistException { getAccessionTester() - .accession("test-6") - .merge("id-test-merge-1"); + .getOrCreate("test-merge-1") + .getOrCreate("test-6") + .merge("id-test-6", "id-test-merge-1", "reason") + .getLastMethodResponse().assertNoException(); getHistoryTester("id-test-6") .assertTotalEvents(2) .assertEvent(0, assertEventIsCreated()) @@ -168,16 +158,14 @@ public void testMerge() throws AccessionDoesNotExistException, @UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL) @Test - public void testComplexCase() throws AccessionDoesNotExistException, - AccessionCouldNotBeGeneratedException, - AccessionMergedException, AccessionDeprecatedException, HashAlreadyExistsException { + public void testComplexCase() throws AccessionDoesNotExistException { getAccessionTester() - .accession("test-7") - .update(1, "test-7-update-1") - .patch("test-7-patch-2") - .update(2, "test-7-update-patch-2") - .update(2, "test-7-update-b-patch-2") - .deprecate(); + .getOrCreate("test-7") + .update("id-test-7", 1, "test-7-update-1") + .patch("id-test-7", "test-7-patch-2") + .update("id-test-7", 2, "test-7-update-patch-2") + .update("id-test-7", 2, "test-7-update-b-patch-2") + .deprecate("id-test-7", "reason"); getHistoryTester("id-test-7") .assertTotalEvents(6) @@ -193,8 +181,8 @@ private HistoryTester.HistoryAccessionTester getHistoryTester(String id) throws return new HistoryTester(historyService).accession(id); } - public AccessionTester getAccessionTester() { - return new AccessionTester(accessioningService); + public AccessioningServiceTester getAccessionTester() { + return new AccessioningServiceTester(accessioningService); } } diff --git a/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/configuration/MongoDbCucumberTestConfiguration.java b/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/configuration/MongoDbCucumberTestConfiguration.java new file mode 100644 index 00000000..11aebc92 --- /dev/null +++ b/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/configuration/MongoDbCucumberTestConfiguration.java @@ -0,0 +1,99 @@ +/* + * + * Copyright 2018 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.ebi.ampt2d.test.configuration; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.boot.test.autoconfigure.data.mongo.AutoConfigureDataMongo; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Scope; +import org.springframework.data.mongodb.config.EnableMongoAuditing; +import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; +import uk.ac.ebi.ampt2d.commons.accession.core.AccessioningService; +import uk.ac.ebi.ampt2d.commons.accession.core.BasicAccessioningService; +import uk.ac.ebi.ampt2d.commons.accession.core.DatabaseService; +import uk.ac.ebi.ampt2d.commons.accession.core.HistoryService; +import uk.ac.ebi.ampt2d.commons.accession.generators.SingleAccessionGenerator; +import uk.ac.ebi.ampt2d.commons.accession.hashing.SHA1HashingFunction; +import uk.ac.ebi.ampt2d.commons.accession.persistence.services.BasicHistoryService; +import uk.ac.ebi.ampt2d.commons.accession.persistence.services.BasicSpringDataRepositoryDatabaseService; +import uk.ac.ebi.ampt2d.test.models.TestModel; +import uk.ac.ebi.ampt2d.test.persistence.document.TestDocument; +import uk.ac.ebi.ampt2d.test.persistence.document.TestEventDocument; +import uk.ac.ebi.ampt2d.test.persistence.document.TestInactiveSubDocument; +import uk.ac.ebi.ampt2d.test.persistence.repository.TestOperationRepository; +import uk.ac.ebi.ampt2d.test.persistence.repository.TestRepository; +import uk.ac.ebi.ampt2d.test.persistence.service.TestMongoDbInactiveAccessionService; +import uk.ac.ebi.ampt2d.test.testers.AccessioningServiceTester; + +@Configuration +@EntityScan(basePackages = {"uk.ac.ebi.ampt2d.test.persistence.document"}) +@EnableMongoRepositories(basePackages = {"uk.ac.ebi.ampt2d.test.persistence.repository", + "uk.ac.ebi.ampt2d.commons.accession.persistence.mongodb.repository"}) +@EnableMongoAuditing +@AutoConfigureDataMongo +public class MongoDbCucumberTestConfiguration { + + @Autowired + private TestRepository testRepository; + + @Autowired + private TestOperationRepository testOperationRepository; + + @Bean + public TestMongoDbInactiveAccessionService testMongoDbInactiveAccessionService() { + return new TestMongoDbInactiveAccessionService( + testOperationRepository, + TestInactiveSubDocument::new, + TestEventDocument::new + ); + } + + @Bean + public DatabaseService testMongoDbService() { + return new BasicSpringDataRepositoryDatabaseService<>( + testRepository, + TestDocument::new, + testMongoDbInactiveAccessionService() + ); + } + + @Bean + public HistoryService testMongoDbHistoryService() { + return new BasicHistoryService<>(testRepository, testMongoDbInactiveAccessionService()); + } + + @Bean + public AccessioningService testMongoDbAccessioningService() { + return new BasicAccessioningService<>( + new SingleAccessionGenerator<>(o -> + "id-service-" + o.getValue()), + testMongoDbService(), + TestModel::getValue, + new SHA1HashingFunction() + ); + } + + @Bean + @Scope("cucumber-glue") + public AccessioningServiceTester accessioningServiceTester() { + return new AccessioningServiceTester(testMongoDbAccessioningService()); + } + +} diff --git a/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/configuration/MongoDbTestConfiguration.java b/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/configuration/MongoDbTestConfiguration.java index 4a9a42f7..876eb2ba 100644 --- a/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/configuration/MongoDbTestConfiguration.java +++ b/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/configuration/MongoDbTestConfiguration.java @@ -32,10 +32,10 @@ import uk.ac.ebi.ampt2d.commons.accession.hashing.SHA1HashingFunction; import uk.ac.ebi.ampt2d.commons.accession.persistence.services.BasicHistoryService; import uk.ac.ebi.ampt2d.commons.accession.persistence.services.BasicSpringDataRepositoryDatabaseService; -import uk.ac.ebi.ampt2d.test.TestModel; +import uk.ac.ebi.ampt2d.test.models.TestModel; import uk.ac.ebi.ampt2d.test.persistence.document.TestDocument; -import uk.ac.ebi.ampt2d.test.persistence.document.TestInactiveSubDocument; import uk.ac.ebi.ampt2d.test.persistence.document.TestEventDocument; +import uk.ac.ebi.ampt2d.test.persistence.document.TestInactiveSubDocument; import uk.ac.ebi.ampt2d.test.persistence.repository.TestOperationRepository; import uk.ac.ebi.ampt2d.test.persistence.repository.TestRepository; import uk.ac.ebi.ampt2d.test.persistence.service.TestMongoDbInactiveAccessionService; diff --git a/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/persistence/document/TestDocument.java b/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/persistence/document/TestDocument.java index 4f1e1bde..3e693db8 100644 --- a/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/persistence/document/TestDocument.java +++ b/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/persistence/document/TestDocument.java @@ -20,7 +20,7 @@ import org.springframework.data.mongodb.core.mapping.Document; import uk.ac.ebi.ampt2d.commons.accession.core.models.AccessionWrapper; import uk.ac.ebi.ampt2d.commons.accession.persistence.mongodb.document.AccessionedDocument; -import uk.ac.ebi.ampt2d.test.TestModel; +import uk.ac.ebi.ampt2d.test.models.TestModel; @Document public class TestDocument extends AccessionedDocument implements TestModel { diff --git a/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/persistence/document/TestEventDocument.java b/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/persistence/document/TestEventDocument.java index b6cc9f65..07691427 100644 --- a/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/persistence/document/TestEventDocument.java +++ b/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/persistence/document/TestEventDocument.java @@ -19,7 +19,7 @@ import org.springframework.data.mongodb.core.mapping.Document; import uk.ac.ebi.ampt2d.commons.accession.persistence.mongodb.document.EventDocument; -import uk.ac.ebi.ampt2d.test.TestModel; +import uk.ac.ebi.ampt2d.test.models.TestModel; @Document public class TestEventDocument extends EventDocument { diff --git a/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/persistence/document/TestInactiveSubDocument.java b/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/persistence/document/TestInactiveSubDocument.java index 3341e7ae..814e9dca 100644 --- a/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/persistence/document/TestInactiveSubDocument.java +++ b/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/persistence/document/TestInactiveSubDocument.java @@ -18,7 +18,7 @@ package uk.ac.ebi.ampt2d.test.persistence.document; import uk.ac.ebi.ampt2d.commons.accession.persistence.mongodb.document.InactiveSubDocument; -import uk.ac.ebi.ampt2d.test.TestModel; +import uk.ac.ebi.ampt2d.test.models.TestModel; public class TestInactiveSubDocument extends InactiveSubDocument implements TestModel { diff --git a/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/persistence/service/TestMongoDbInactiveAccessionService.java b/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/persistence/service/TestMongoDbInactiveAccessionService.java index 3aff9085..cc057333 100644 --- a/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/persistence/service/TestMongoDbInactiveAccessionService.java +++ b/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/persistence/service/TestMongoDbInactiveAccessionService.java @@ -19,7 +19,7 @@ import uk.ac.ebi.ampt2d.commons.accession.persistence.repositories.IHistoryRepository; import uk.ac.ebi.ampt2d.commons.accession.persistence.mongodb.service.BasicMongoDbInactiveAccessionService; -import uk.ac.ebi.ampt2d.test.TestModel; +import uk.ac.ebi.ampt2d.test.models.TestModel; import uk.ac.ebi.ampt2d.test.persistence.document.TestDocument; import uk.ac.ebi.ampt2d.test.persistence.document.TestInactiveSubDocument; import uk.ac.ebi.ampt2d.test.persistence.document.TestEventDocument; diff --git a/accession-commons-mongodb/src/test/resources/features/accession.feature b/accession-commons-mongodb/src/test/resources/features/accession.feature new file mode 100644 index 00000000..aaea86d6 --- /dev/null +++ b/accession-commons-mongodb/src/test/resources/features/accession.feature @@ -0,0 +1,28 @@ +Feature: Accession generation + + Scenario Outline: I want to receive unique accession for my newly submitted / created objects, so they are + identifiable in the system. + When user submits to accessioning service + Then user received accessions: + Examples: + | input | accessions | + | A | id-service-A | + | B,C | id-service-B,id-service-C | + | D,E,F | id-service-D,id-service-E,id-service-F | + + Scenario Outline: I want to receive accessions for a mix of new and pre-existing objects. + Given already accessioned + When user submits to accessioning service + Then user received accessions: + Examples: + | objects | input | accessions | + | B | A | id-service-A | + | A | A | id-service-A | + | C | B,C | id-service-B,id-service-C | + | A,B,C,E | D,E,F | id-service-D,id-service-E,id-service-F | + + @ignore + Scenario: I want to generate accession in a space, based on clustering accessions from another existing space. + When user provides a list of ss accessions + Then user receives a rs list of accessions + And all rs must have at least one ss accessioned \ No newline at end of file diff --git a/accession-commons-mongodb/src/test/resources/features/merge.feature b/accession-commons-mongodb/src/test/resources/features/merge.feature new file mode 100644 index 00000000..6904f843 --- /dev/null +++ b/accession-commons-mongodb/src/test/resources/features/merge.feature @@ -0,0 +1,37 @@ +Feature: Accession merge + + Scenario: I want to merge an object but the destination object does not exist. + Given already accessioned A + When user merges id-service-A into id-service-B reason: because i say so + Then user should receive 'accession does not exist' + + Scenario: I want to merge an object but the origin object does not exist. + Given already accessioned B + When user merges id-service-A into id-service-B reason: because i say so + Then user should receive 'accession does not exist' + + Scenario: I want to merge an object but none of the two exist. + When user merges id-service-A into id-service-B reason: because i say so + Then user should receive 'accession does not exist' + + Scenario: I want to merge an object + Given already accessioned A + And already accessioned B + When user merges id-service-A into id-service-B reason: because i say so + Then operation finished correctly + + Scenario: I want to merge an object but the object has been already merged + Given already accessioned A + And already accessioned B + And already accessioned C + And user merges id-service-B into id-service-C reason: because i say so + When user merges id-service-A into id-service-B reason: because i say so + Then user should receive 'accession already merged exception' + + Scenario: I want to merge an object to another and then to a third one + Given already accessioned A + And already accessioned B + And already accessioned C + When user merges id-service-A into id-service-B reason: because i say so + When user merges id-service-B into id-service-C reason: because i say so + Then operation finished correctly \ No newline at end of file diff --git a/accession-commons-mongodb/src/test/resources/features/modification.feature b/accession-commons-mongodb/src/test/resources/features/modification.feature new file mode 100644 index 00000000..890fda6d --- /dev/null +++ b/accession-commons-mongodb/src/test/resources/features/modification.feature @@ -0,0 +1,40 @@ +Feature: Accession modification + + Scenario Outline: I want to create a new patch of an existing object, in order to register improvements made to it + without losing access to the old information. + Given already accessioned + When user sends patch for accession + Then user should receive 2 patches for accession + And patch must have versions increased + Examples: + | objects | input | accession | + | A | AA | id-service-A | + | B | BB | id-service-B | + | A,B,C,E | AA | id-service-A | + + Scenario: I want to create a new patch of a non existing object + When user sends patch AA for accession id-service-A + Then user should receive 'accession does not exist' + + Scenario Outline: I want to update the fields that identify uniquely an object, + without losing access to the old information. + Given already accessioned + When user updates patch with + Then user should receive 1 patch for accession + And hash of patch 1 should be + Examples: + | objects | input | accession | patch | hash | + | A | AA | id-service-A | 1 | 801C34269F74ED383FC97DE33604B8A905ADB635 | + | B | BB | id-service-B | 1 | 71C9DB717578B9EE49A59E69375C16C0627DFFEF | + | A,B,C,E | AA | id-service-A | 1 | 801C34269F74ED383FC97DE33604B8A905ADB635 | + + Scenario: I want to update the fields that identify uniquely an object, but another object already has the same + values. + Given already accessioned A,B + When user updates id-service-A patch 1 with B + Then user should receive 'hash already exists exception' + + Scenario: I want to update an object that does not exist + When user updates id-service-A patch 1 with AB + Then user should receive 'accession does not exist' + diff --git a/accession-commons-mongodb/src/test/resources/features/retrieval.feature b/accession-commons-mongodb/src/test/resources/features/retrieval.feature new file mode 100644 index 00000000..99edc725 --- /dev/null +++ b/accession-commons-mongodb/src/test/resources/features/retrieval.feature @@ -0,0 +1,34 @@ +Feature: Accession retrieval + + Scenario: I want to get the accession of an object that is not in the system. + When user retrieves objects: A + Then user receives 0 elements + + Scenario: I want to get the accession of an object that it is on the system. + Given already accessioned A + When user retrieves objects: A + Then user receives 1 elements + And user received a response with values: A + And user received accessions: id-service-A + + Scenario: I want to get accessions of a mixture of objects that may or not be on the system. + Given already accessioned A + Given already accessioned C + Given already accessioned E + When user retrieves objects: A,B,C,D,E + Then user receives 3 elements + And user received a response with values: A,C,E + And user received accessions: id-service-A,id-service-C,id-service-E + + Scenario: I want to get a specific accession that doesn't exist in the system. + When user retrieves accessions: id-service-A + Then operation finished correctly + And user receives no data + + Scenario: I want to retrieve an accession that exists in the system + Given already accessioned A + Given already accessioned B + When user retrieves accessions: id-service-A,id-service-B + Then user receives 2 elements + And user received a response with values: A,B + And user received accessions: id-service-A,id-service-B \ No newline at end of file diff --git a/accession-commons-monotonic-generator-jpa/pom.xml b/accession-commons-monotonic-generator-jpa/pom.xml index 10de5b08..963d64d8 100644 --- a/accession-commons-monotonic-generator-jpa/pom.xml +++ b/accession-commons-monotonic-generator-jpa/pom.xml @@ -28,6 +28,12 @@ 0.5-SNAPSHOT test + + uk.ac.ebi.ampt2d + accession-commons-test + 0.5-SNAPSHOT + test + org.springframework.boot spring-boot-starter-data-jpa diff --git a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningTest.java b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningTest.java index 78173f77..50463871 100644 --- a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningTest.java +++ b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningTest.java @@ -29,8 +29,8 @@ import uk.ac.ebi.ampt2d.commons.accession.generators.monotonic.MonotonicAccessionGenerator; import uk.ac.ebi.ampt2d.commons.accession.hashing.SHA1HashingFunction; import uk.ac.ebi.ampt2d.commons.accession.service.BasicMonotonicAccessioningService; -import uk.ac.ebi.ampt2d.test.TestModel; import uk.ac.ebi.ampt2d.test.configuration.TestMonotonicDatabaseServiceTestConfiguration; +import uk.ac.ebi.ampt2d.test.models.TestModel; import uk.ac.ebi.ampt2d.test.persistence.TestMonotonicRepository; import uk.ac.ebi.ampt2d.test.service.TestMonotonicDatabaseService; @@ -160,7 +160,7 @@ public void testGetOrCreateWithExistingEntries() throws AccessionCouldNotBeGener assertEquals(3, accessions2.size()); TestTransaction.start(); - for(AccessionWrapper accession: accessions2){ + for (AccessionWrapper accession: accessions2) { repository.delete(accession.getHash()); } TestTransaction.flagForCommit(); diff --git a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningWithAlternateRangesTest.java b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningWithAlternateRangesTest.java index cf8a1fb2..94b0abdd 100644 --- a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningWithAlternateRangesTest.java +++ b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningWithAlternateRangesTest.java @@ -30,8 +30,8 @@ import uk.ac.ebi.ampt2d.commons.accession.hashing.SHA1HashingFunction; import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.monotonic.service.ContiguousIdBlockService; import uk.ac.ebi.ampt2d.commons.accession.service.BasicMonotonicAccessioningService; -import uk.ac.ebi.ampt2d.test.TestModel; import uk.ac.ebi.ampt2d.test.configuration.TestMonotonicDatabaseServiceTestConfiguration; +import uk.ac.ebi.ampt2d.test.models.TestModel; import uk.ac.ebi.ampt2d.test.service.TestMonotonicDatabaseService; import java.util.List; diff --git a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningWithInitValuesTest.java b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningWithInitValuesTest.java index 1e382fe7..2caefdd1 100644 --- a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningWithInitValuesTest.java +++ b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningWithInitValuesTest.java @@ -30,7 +30,7 @@ import uk.ac.ebi.ampt2d.commons.accession.generators.monotonic.MonotonicAccessionGenerator; import uk.ac.ebi.ampt2d.commons.accession.hashing.SHA1HashingFunction; import uk.ac.ebi.ampt2d.commons.accession.service.BasicMonotonicAccessioningService; -import uk.ac.ebi.ampt2d.test.TestModel; +import uk.ac.ebi.ampt2d.test.models.TestModel; import uk.ac.ebi.ampt2d.test.configuration.TestMonotonicDatabaseServiceTestConfiguration; import uk.ac.ebi.ampt2d.test.persistence.TestMonotonicEntity; import uk.ac.ebi.ampt2d.test.persistence.TestMonotonicRepository; diff --git a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/TestMonotonicDatabaseServiceTestConfiguration.java b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/TestMonotonicDatabaseServiceTestConfiguration.java index 7762e1c8..f343126d 100644 --- a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/TestMonotonicDatabaseServiceTestConfiguration.java +++ b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/TestMonotonicDatabaseServiceTestConfiguration.java @@ -27,7 +27,7 @@ import uk.ac.ebi.ampt2d.commons.accession.persistence.services.InactiveAccessionService; import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.monotonic.service.ContiguousIdBlockService; import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.service.BasicJpaInactiveAccessionService; -import uk.ac.ebi.ampt2d.test.TestModel; +import uk.ac.ebi.ampt2d.test.models.TestModel; import uk.ac.ebi.ampt2d.test.persistence.TestLongHistoryRepository; import uk.ac.ebi.ampt2d.test.persistence.TestLongOperationEntity; import uk.ac.ebi.ampt2d.test.persistence.TestMonotonicEntity; diff --git a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/persistence/TestMonotonicEntity.java b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/persistence/TestMonotonicEntity.java index 0f7a0302..613d0a6f 100644 --- a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/persistence/TestMonotonicEntity.java +++ b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/persistence/TestMonotonicEntity.java @@ -19,7 +19,7 @@ import uk.ac.ebi.ampt2d.commons.accession.core.models.AccessionWrapper; import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.entities.AccessionedEntity; -import uk.ac.ebi.ampt2d.test.TestModel; +import uk.ac.ebi.ampt2d.test.models.TestModel; import javax.persistence.Entity; diff --git a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/persistence/TestMonotonicInactiveAccessionEntity.java b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/persistence/TestMonotonicInactiveAccessionEntity.java index 542ab9b0..e18a82db 100644 --- a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/persistence/TestMonotonicInactiveAccessionEntity.java +++ b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/persistence/TestMonotonicInactiveAccessionEntity.java @@ -18,7 +18,7 @@ package uk.ac.ebi.ampt2d.test.persistence; import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.entities.InactiveAccessionEntity; -import uk.ac.ebi.ampt2d.test.TestModel; +import uk.ac.ebi.ampt2d.test.models.TestModel; import javax.persistence.Entity; diff --git a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/service/TestMonotonicDatabaseService.java b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/service/TestMonotonicDatabaseService.java index f85f198d..3f549f9a 100644 --- a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/service/TestMonotonicDatabaseService.java +++ b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/service/TestMonotonicDatabaseService.java @@ -23,7 +23,7 @@ import uk.ac.ebi.ampt2d.commons.accession.persistence.repositories.IAccessionedObjectRepository; import uk.ac.ebi.ampt2d.commons.accession.persistence.services.InactiveAccessionService; import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.monotonic.service.MonotonicDatabaseService; -import uk.ac.ebi.ampt2d.test.TestModel; +import uk.ac.ebi.ampt2d.test.models.TestModel; import uk.ac.ebi.ampt2d.test.persistence.TestMonotonicEntity; import java.util.Collection; diff --git a/accession-commons-test/pom.xml b/accession-commons-test/pom.xml new file mode 100644 index 00000000..acdcb8c0 --- /dev/null +++ b/accession-commons-test/pom.xml @@ -0,0 +1,82 @@ + + + 4.0.0 + + accession-commons-test + 0.5-SNAPSHOT + jar + + + accession-commons + uk.ac.ebi.ampt2d + 0.5-SNAPSHOT + + + + UTF-8 + + + + + org.springframework.boot + spring-boot-starter-test + + + uk.ac.ebi.ampt2d + accession-commons-core + 0.5-SNAPSHOT + + + + + + + false + + eva-releases + https://oss.jfrog.org/artifactory/libs-release + + + + true + + eva-snapshots + https://oss.jfrog.org/artifactory/libs-snapshot + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-surefire-plugin + + false + + + + + + + + eva-snapshots + https://oss.jfrog.org/artifactory/oss-snapshot-local + + + eva-releases + https://oss.jfrog.org/artifactory/oss-release-local + + + + + \ No newline at end of file diff --git a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/TestModel.java b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/models/TestModel.java similarity index 95% rename from accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/TestModel.java rename to accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/models/TestModel.java index 2a600855..cf697382 100644 --- a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/TestModel.java +++ b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/models/TestModel.java @@ -15,7 +15,7 @@ * limitations under the License. * */ -package uk.ac.ebi.ampt2d.test; +package uk.ac.ebi.ampt2d.test.models; public interface TestModel { diff --git a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/rest/BasicRestModel.java b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/rest/BasicRestModel.java similarity index 95% rename from accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/rest/BasicRestModel.java rename to accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/rest/BasicRestModel.java index 405673a1..53eca64a 100644 --- a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/rest/BasicRestModel.java +++ b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/rest/BasicRestModel.java @@ -17,8 +17,7 @@ */ package uk.ac.ebi.ampt2d.test.rest; - -import uk.ac.ebi.ampt2d.test.TestModel; +import uk.ac.ebi.ampt2d.test.models.TestModel; import javax.validation.constraints.NotNull; diff --git a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/rest/MockTestAccessionGenerator.java b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/rest/MockTestAccessionGenerator.java similarity index 98% rename from accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/rest/MockTestAccessionGenerator.java rename to accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/rest/MockTestAccessionGenerator.java index 4a8c5c8d..b2bd5c0b 100644 --- a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/rest/MockTestAccessionGenerator.java +++ b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/rest/MockTestAccessionGenerator.java @@ -17,13 +17,13 @@ */ package uk.ac.ebi.ampt2d.test.rest; -import uk.ac.ebi.ampt2d.commons.accession.core.models.AccessionWrapper; -import uk.ac.ebi.ampt2d.commons.accession.core.models.SaveResponse; import uk.ac.ebi.ampt2d.commons.accession.core.exceptions.AccessionCouldNotBeGeneratedException; import uk.ac.ebi.ampt2d.commons.accession.core.exceptions.AccessionIsNotPendingException; import uk.ac.ebi.ampt2d.commons.accession.core.exceptions.MissingUnsavedAccessionsException; +import uk.ac.ebi.ampt2d.commons.accession.core.models.AccessionWrapper; +import uk.ac.ebi.ampt2d.commons.accession.core.models.SaveResponse; import uk.ac.ebi.ampt2d.commons.accession.generators.AccessionGenerator; -import uk.ac.ebi.ampt2d.test.TestModel; +import uk.ac.ebi.ampt2d.test.models.TestModel; import java.util.ArrayList; import java.util.HashMap; diff --git a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/rest/MockTestAccessioningService.java b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/rest/MockTestAccessioningService.java similarity index 96% rename from accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/rest/MockTestAccessioningService.java rename to accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/rest/MockTestAccessioningService.java index bf60740f..6825c0d5 100644 --- a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/rest/MockTestAccessioningService.java +++ b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/rest/MockTestAccessioningService.java @@ -19,7 +19,7 @@ import uk.ac.ebi.ampt2d.commons.accession.core.BasicAccessioningService; import uk.ac.ebi.ampt2d.commons.accession.core.DatabaseService; -import uk.ac.ebi.ampt2d.test.TestModel; +import uk.ac.ebi.ampt2d.test.models.TestModel; /** * Mock service, generates accessions using in-memory data structures diff --git a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/rest/TestController.java b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/rest/TestController.java similarity index 96% rename from accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/rest/TestController.java rename to accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/rest/TestController.java index 9190bb1f..635dc1ed 100644 --- a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/rest/TestController.java +++ b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/rest/TestController.java @@ -21,7 +21,7 @@ import org.springframework.web.bind.annotation.RestController; import uk.ac.ebi.ampt2d.commons.accession.core.DatabaseService; import uk.ac.ebi.ampt2d.commons.accession.rest.controllers.BasicRestController; -import uk.ac.ebi.ampt2d.test.TestModel; +import uk.ac.ebi.ampt2d.test.models.TestModel; @RestController @RequestMapping(value = "/v1/test") diff --git a/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/AccessionTester.java b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/AccessionTester.java similarity index 97% rename from accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/AccessionTester.java rename to accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/AccessionTester.java index 319dff89..e407d384 100644 --- a/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/AccessionTester.java +++ b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/AccessionTester.java @@ -15,7 +15,7 @@ * limitations under the License. * */ -package uk.ac.ebi.ampt2d.test; +package uk.ac.ebi.ampt2d.test.testers; import uk.ac.ebi.ampt2d.commons.accession.core.AccessioningService; import uk.ac.ebi.ampt2d.commons.accession.core.exceptions.AccessionCouldNotBeGeneratedException; @@ -24,6 +24,7 @@ import uk.ac.ebi.ampt2d.commons.accession.core.exceptions.AccessionMergedException; import uk.ac.ebi.ampt2d.commons.accession.core.exceptions.HashAlreadyExistsException; import uk.ac.ebi.ampt2d.commons.accession.core.models.AccessionWrapper; +import uk.ac.ebi.ampt2d.test.models.TestModel; import java.util.Arrays; diff --git a/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/AccessionVersionWrapperTester.java b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/AccessionVersionWrapperTester.java new file mode 100644 index 00000000..dc22c85e --- /dev/null +++ b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/AccessionVersionWrapperTester.java @@ -0,0 +1,70 @@ +/* + * + * Copyright 2018 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.ebi.ampt2d.test.testers; + +import uk.ac.ebi.ampt2d.commons.accession.core.models.AccessionVersionsWrapper; +import uk.ac.ebi.ampt2d.commons.accession.core.models.AccessionWrapper; +import uk.ac.ebi.ampt2d.test.models.TestModel; +import uk.ac.ebi.ampt2d.test.utils.ThrowingSupplier; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class AccessionVersionWrapperTester + extends MethodResponseTester> { + + public AccessionVersionWrapperTester( + ThrowingSupplier> functionCall) { + super(functionCall); + } + + public AccessionVersionWrapperTester assertTotalVersions(int total) { + assertEquals(total, getData().getModelWrappers().size()); + return this; + } + + public AccessionVersionWrapperTester assertVersionsAreIncreased() { + final List> wrappers = + new ArrayList<>(getData().getModelWrappers()); + + wrappers.sort(Comparator.comparingInt(AccessionWrapper::getVersion)); + int minValue = wrappers.get(0).getVersion(); + for (int i = 1; i < wrappers.size(); i++) { + if (wrappers.get(i).getVersion() <= minValue) { + fail("Multiple patches with same version number '" + minValue + "'"); + } + } + return this; + } + + public AccessionVersionWrapperTester assertAccession(String accession) { + assertEquals(accession, getData().getAccession()); + return this; + } + + public AccessionVersionWrapperTester assertHash(int version, String hash) { + final AccessionWrapper wrapper = getData().getVersion(version) + .orElseThrow(() -> new AssertionError("Version not found")); + assertEquals(hash, wrapper.getHash()); + return this; + } +} diff --git a/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/AccessionWrapperCollectionTester.java b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/AccessionWrapperCollectionTester.java new file mode 100644 index 00000000..c52db2e9 --- /dev/null +++ b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/AccessionWrapperCollectionTester.java @@ -0,0 +1,78 @@ +/* + * + * Copyright 2018 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.ebi.ampt2d.test.testers; + +import uk.ac.ebi.ampt2d.commons.accession.core.models.AccessionWrapper; +import uk.ac.ebi.ampt2d.test.models.TestModel; +import uk.ac.ebi.ampt2d.test.utils.ThrowingSupplier; + +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class AccessionWrapperCollectionTester + extends MethodResponseTester>> { + + public AccessionWrapperCollectionTester( + ThrowingSupplier>> functionCall) { + super(functionCall); + } + + public void assertSize(int length) { + assertEquals(length, getData().size()); + } + + public void assertAccessions(String... accessions) { + assertSize(accessions.length); + for (String accession: accessions) { + assertAccessionIsPresent(accession); + } + } + + public void assertAccessionIsPresent(String accession) { + for (AccessionWrapper wrapper: getData()) { + if (Objects.equals(wrapper.getAccession(), accession)) { + return; + } + } + fail("Accession '" + accession + "' is not present, accessions in list '" + getAccessionList() + "'"); + } + + private List getAccessionList() { + return getData().stream().map(AccessionWrapper::getAccession).collect(Collectors.toList()); + } + + public void assertAccessionValues(String... values) { + assertSize(values.length); + for (String value: values) { + assertAccessionWithValueIsPresent(value); + } + } + + public void assertAccessionWithValueIsPresent(String value) { + for (AccessionWrapper wrapper: getData()) { + if (Objects.equals(wrapper.getData().getValue(), value)) { + return; + } + } + fail("No object with value '" + value + "' was present in list '" + getAccessionList() + "'"); + } +} diff --git a/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/AccessioningServiceTester.java b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/AccessioningServiceTester.java new file mode 100644 index 00000000..82d5b24f --- /dev/null +++ b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/AccessioningServiceTester.java @@ -0,0 +1,114 @@ +/* + * + * Copyright 2018 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.ebi.ampt2d.test.testers; + +import uk.ac.ebi.ampt2d.commons.accession.core.AccessioningService; +import uk.ac.ebi.ampt2d.test.models.TestModel; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +public class AccessioningServiceTester { + + private final AccessioningService accessioningService; + + private List singleVersionResults; + + private List multipleVersionResults; + + private IMethodTester lastMethodResponse; + + public AccessioningServiceTester(AccessioningService accessioningService) { + this.accessioningService = accessioningService; + this.singleVersionResults = new ArrayList<>(); + this.multipleVersionResults = new ArrayList<>(); + } + + public AccessioningServiceTester getOrCreate(String... values) { + return getOrCreate(toModels(values)); + } + + public AccessioningServiceTester getOrCreate(List models) { + addToCollection(singleVersionResults, + new AccessionWrapperCollectionTester(() -> accessioningService.getOrCreate(models))); + return this; + } + + public AccessionWrapperCollectionTester getSingleVersionResults() { + return singleVersionResults.get(singleVersionResults.size() - 1); + } + + public AccessioningServiceTester patch(String accession, String patchData) { + return patch(accession, TestModel.of(patchData)); + } + + public AccessioningServiceTester patch(String accession, TestModel patchData) { + addToCollection(multipleVersionResults, + new AccessionVersionWrapperTester(() -> accessioningService.patch(accession, patchData))); + return this; + } + + public AccessionVersionWrapperTester getLastMultipleVersionResult() { + return multipleVersionResults.get(multipleVersionResults.size() - 1); + } + + public AccessioningServiceTester update(String accession, int version, String data) { + addToCollection(multipleVersionResults, + new AccessionVersionWrapperTester(() -> + accessioningService.update(accession, version, TestModel.of(data)))); + return this; + } + + public AccessioningServiceTester merge(String accessionA, String accessionB, String reason) { + lastMethodResponse = new MethodTester(() -> accessioningService.merge(accessionA, accessionB, reason)); + return this; + } + + public IMethodTester getLastMethodResponse() { + return lastMethodResponse; + } + + public AccessionWrapperCollectionTester get(List models) { + return addToCollection(singleVersionResults, + new AccessionWrapperCollectionTester(() -> accessioningService.get(models))); + } + + public AccessionWrapperCollectionTester getAccessions(String... accessionIds) { + return addToCollection(singleVersionResults, + new AccessionWrapperCollectionTester(() -> + accessioningService.getByAccessions(Arrays.asList(accessionIds)))); + } + + private T addToCollection(Collection collection, T t) { + collection.add(t); + lastMethodResponse = t; + return t; + } + + private List toModels(String... values) { + return Arrays.stream(values).map(TestModel::of).collect(Collectors.toList()); + } + + public AccessioningServiceTester deprecate(String accessionId, String reason) { + lastMethodResponse = new MethodTester(() -> accessioningService.deprecate(accessionId, reason)); + return this; + } +} diff --git a/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/HistoryTester.java b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/HistoryTester.java similarity index 94% rename from accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/HistoryTester.java rename to accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/HistoryTester.java index 46109db9..0396aadb 100644 --- a/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/HistoryTester.java +++ b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/HistoryTester.java @@ -15,12 +15,14 @@ * limitations under the License. * */ -package uk.ac.ebi.ampt2d.test; +package uk.ac.ebi.ampt2d.test.testers; +import org.junit.Assert; import uk.ac.ebi.ampt2d.commons.accession.core.HistoryService; import uk.ac.ebi.ampt2d.commons.accession.core.exceptions.AccessionDoesNotExistException; import uk.ac.ebi.ampt2d.commons.accession.core.models.EventType; import uk.ac.ebi.ampt2d.commons.accession.core.models.HistoryEvent; +import uk.ac.ebi.ampt2d.test.models.TestModel; import java.util.List; import java.util.function.Consumer; @@ -74,7 +76,7 @@ public static Consumer> assertNullMergedInto() { } public static Consumer> assertMergedInto(String accession) { - return event -> assertEquals(accession, event.getMergedInto()); + return event -> Assert.assertEquals(accession, event.getMergedInto()); } public static Consumer> assertNullVersion() { @@ -82,7 +84,7 @@ public static Consumer> assertNullVersion() { } public static Consumer> assertVersion(int version) { - return event -> assertEquals(new Integer(version), event.getVersion()); + return event -> Assert.assertEquals(new Integer(version), event.getVersion()); } public static Consumer> assertNullData() { diff --git a/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/IMethodTester.java b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/IMethodTester.java new file mode 100644 index 00000000..0e394903 --- /dev/null +++ b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/IMethodTester.java @@ -0,0 +1,47 @@ +/* + * + * Copyright 2018 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.ebi.ampt2d.test.testers; + +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +public interface IMethodTester { + + default void assertNoException() { + getException().ifPresent(e -> fail("Unexpected exception thrown '" + e.getClass().getName() + "'")); + } + + default void assertThrow(Class exceptionClass) { + Exception thrownException = getException().get(); + assertNotNull("No exception was thrown", thrownException); + assertThatThrownBy(() -> { + throw thrownException; + }).isInstanceOf(exceptionClass); + } + + /** + * Returns exception thrown in method execution if any. + * + * @return + */ + Optional getException(); + +} diff --git a/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/MethodResponseTester.java b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/MethodResponseTester.java new file mode 100644 index 00000000..7e4cff3e --- /dev/null +++ b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/MethodResponseTester.java @@ -0,0 +1,51 @@ +/* + * + * Copyright 2018 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.ebi.ampt2d.test.testers; + +import uk.ac.ebi.ampt2d.test.utils.ThrowingSupplier; + +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +public class MethodResponseTester implements IMethodTester{ + + private Exception exception; + + private T data; + + public MethodResponseTester(ThrowingSupplier functionCall) { + try { + data = functionCall.get(); + } catch (Exception e) { + this.exception = e; + } + } + + @Override + public Optional getException() { + return Optional.ofNullable(exception); + } + + public T getData() { + assertNoException(); + return data; + } +} diff --git a/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/MethodTester.java b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/MethodTester.java new file mode 100644 index 00000000..3e9a11d2 --- /dev/null +++ b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/MethodTester.java @@ -0,0 +1,40 @@ +/* + * + * Copyright 2018 EMBL - European Bioinformatics Institute + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package uk.ac.ebi.ampt2d.test.testers; + +import uk.ac.ebi.ampt2d.test.utils.VoidThrowingSupplier; + +import java.util.Optional; + +public class MethodTester implements IMethodTester { + + private Exception exception; + + public MethodTester(VoidThrowingSupplier functionCall) { + try { + functionCall.get(); + } catch (Exception e) { + this.exception = e; + } + } + + @Override + public Optional getException() { + return Optional.ofNullable(exception); + } +} diff --git a/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/TestModel.java b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/utils/ThrowingSupplier.java similarity index 80% rename from accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/TestModel.java rename to accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/utils/ThrowingSupplier.java index 2a600855..efbffef9 100644 --- a/accession-commons-mongodb/src/test/java/uk/ac/ebi/ampt2d/test/TestModel.java +++ b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/utils/ThrowingSupplier.java @@ -15,14 +15,12 @@ * limitations under the License. * */ -package uk.ac.ebi.ampt2d.test; +package uk.ac.ebi.ampt2d.test.utils; -public interface TestModel { +@FunctionalInterface +public interface ThrowingSupplier { - String getValue(); - - static TestModel of(String value) { - return () -> value; - } + T get() throws Exception; } + diff --git a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/TestModel.java b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/utils/VoidThrowingSupplier.java similarity index 80% rename from accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/TestModel.java rename to accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/utils/VoidThrowingSupplier.java index 2a600855..a84e49b1 100644 --- a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/TestModel.java +++ b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/utils/VoidThrowingSupplier.java @@ -15,14 +15,12 @@ * limitations under the License. * */ -package uk.ac.ebi.ampt2d.test; +package uk.ac.ebi.ampt2d.test.utils; -public interface TestModel { +@FunctionalInterface +public interface VoidThrowingSupplier { - String getValue(); - - static TestModel of(String value) { - return () -> value; - } + void get() throws Exception; } + diff --git a/pom.xml b/pom.xml index 751e9c5b..b6af4616 100644 --- a/pom.xml +++ b/pom.xml @@ -12,6 +12,7 @@ accession-commons-monotonic-generator-jpa accession-commons-jpa accession-commons-mongodb + accession-commons-test accession-commons