-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from jorizci/T2D-185
T2D-185 Review tests
- Loading branch information
Showing
55 changed files
with
1,507 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...ons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/AccessioningAcceptanceTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
|
||
} |
143 changes: 143 additions & 0 deletions
143
.../src/test/java/uk/ac/ebi/ampt2d/commons/accession/AccessioningServiceStepDefinitions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TestModel> 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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
...mons-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/CucumberTestConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TestModel, String, String> databaseService() { | ||
return new BasicSpringDataRepositoryDatabaseService<>( | ||
repository, | ||
TestEntity::new, | ||
inactiveService() | ||
); | ||
} | ||
|
||
@Bean | ||
public InactiveAccessionService<TestModel, String, TestEntity> inactiveService() { | ||
return new BasicJpaInactiveAccessionService<>( | ||
historyRepository, | ||
TestInactiveAccessionEntity::new, | ||
testInactiveAccessionRepository, | ||
TestStringOperationEntity::new | ||
); | ||
} | ||
|
||
@Bean | ||
public AccessioningService<TestModel, String, String> 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()); | ||
} | ||
|
||
} |
Oops, something went wrong.