Skip to content

Commit

Permalink
Merge pull request #41 from jorizci/T2D-185
Browse files Browse the repository at this point in the history
T2D-185 Review tests
  • Loading branch information
Cristina Yenyxe Gonzalez Garcia authored Jul 19, 2018
2 parents b59eed7 + 91c26e6 commit d55911a
Show file tree
Hide file tree
Showing 55 changed files with 1,507 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -65,4 +66,14 @@ public ACCESSION getAccession() {
public List<AccessionWrapper<MODEL, HASH, ACCESSION>> getModelWrappers() {
return data;
}

public Optional<AccessionWrapper<MODEL, HASH, ACCESSION>> getVersion(int version) {
for (AccessionWrapper<MODEL, HASH, ACCESSION> wrapper : data) {
if (wrapper.getVersion() == version) {
return Optional.of(wrapper);
}
}
return Optional.empty();
}

}
23 changes: 23 additions & 0 deletions accession-commons-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
<artifactId>accession-commons-core</artifactId>
<version>0.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>uk.ac.ebi.ampt2d</groupId>
<artifactId>accession-commons-test</artifactId>
<version>0.5-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand All @@ -31,6 +37,23 @@
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>2.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>2.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>2.4.0</version>
</dependency>
</dependencies>

<repositories>
Expand Down
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 {

}
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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
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());
}

}
Loading

0 comments on commit d55911a

Please sign in to comment.