Skip to content

Commit

Permalink
define inverseTypeName and adapt port for db (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
salmma authored Jun 21, 2021
1 parent 4b74dc6 commit dd199ab
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ services:
POSTGRES_PASSWORD: planqk
POSTGRES_DB: planqk
ports:
- "5432:5432"
- "5060:5060"
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@
public class AlgorithmRelationType extends HasId {

private String name;

private String inverseTypeName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public AlgorithmRelationType update(@NonNull AlgorithmRelationType algorithmRela
final var persistedAlgorithmRelationType = findById(algorithmRelationType.getId());

persistedAlgorithmRelationType.setName(algorithmRelationType.getName());
persistedAlgorithmRelationType.setInverseTypeName(algorithmRelationType.getInverseTypeName());

return algorithmRelationTypeRepository.save(persistedAlgorithmRelationType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void createAlgorithmRelation() {
Algorithm sourceAlgorithm = getCreatedAlgorithm("sourceAlgorithmName");
Algorithm targetAlgorithm = getCreatedAlgorithm("targetAlgorithmName");

var algorithmRelationType = getCreatedAlgorithmRelationType("algorithmRelationTypeName");
var algorithmRelationType = getCreatedAlgorithmRelationType("algorithmRelationTypeName", "inverseAlgorithmRelationTypeName");

AlgorithmRelation algorithmRelation = buildAlgorithmRelation(
sourceAlgorithm, targetAlgorithm, algorithmRelationType, "description");
Expand All @@ -74,7 +74,7 @@ void createAlgorithmRelation_AlgorithmNotFound() {
targetAlgorithm.setName("targetAlgorithmName");
targetAlgorithm.setId(UUID.randomUUID());

var algorithmRelationType = getCreatedAlgorithmRelationType("algorithmRelationTypeName");
var algorithmRelationType = getCreatedAlgorithmRelationType("algorithmRelationTypeName", "inverseAlgorithmRelationTypeName");

AlgorithmRelation algorithmRelation = buildAlgorithmRelation(
sourceAlgorithm, targetAlgorithm, algorithmRelationType, "description");
Expand All @@ -87,7 +87,7 @@ void findAlgorithmRelationById_ElementFound() {
Algorithm sourceAlgorithm = getCreatedAlgorithm("sourceAlgorithmName");
Algorithm targetAlgorithm = getCreatedAlgorithm("targetAlgorithmName");

var algorithmRelationType = getCreatedAlgorithmRelationType("algorithmRelationTypeName");
var algorithmRelationType = getCreatedAlgorithmRelationType("algorithmRelationTypeName", "inverseAlgorithmRelationTypeName");

AlgorithmRelation algorithmRelation = buildAlgorithmRelation(
sourceAlgorithm, targetAlgorithm, algorithmRelationType, "description");
Expand All @@ -110,7 +110,7 @@ void updateAlgorithmRelation_ElementFound() {
Algorithm sourceAlgorithm = getCreatedAlgorithm("sourceAlgorithmName");
Algorithm targetAlgorithm = getCreatedAlgorithm("targetAlgorithmName");

var algorithmRelationType = getCreatedAlgorithmRelationType("algorithmRelationTypeName");
var algorithmRelationType = getCreatedAlgorithmRelationType("algorithmRelationTypeName", "inverseAlgorithmRelationTypeName");

AlgorithmRelation algorithmRelation = buildAlgorithmRelation(
sourceAlgorithm, targetAlgorithm, algorithmRelationType, "description");
Expand All @@ -121,7 +121,7 @@ void updateAlgorithmRelation_ElementFound() {
compareAlgorithmRelation.setId(persistedAlgorithmRelation.getId());

String editDescription = "editedDescription";
var editedType = getCreatedAlgorithmRelationType("editedAlgorithmRelationTypeName");
var editedType = getCreatedAlgorithmRelationType("editedAlgorithmRelationTypeName", "editedInverseAlgorithmRelationTypeName");
persistedAlgorithmRelation.setDescription(editDescription);
persistedAlgorithmRelation.setAlgorithmRelationType(editedType);

Expand All @@ -139,6 +139,10 @@ void updateAlgorithmRelation_ElementFound() {
.isNotEqualTo(compareAlgorithmRelation.getAlgorithmRelationType().getName());
assertThat(updatedAlgorithmRelation.getAlgorithmRelationType().getName())
.isEqualTo(editedType.getName());
assertThat(updatedAlgorithmRelation.getAlgorithmRelationType().getInverseTypeName())
.isNotEqualTo(compareAlgorithmRelation.getAlgorithmRelationType().getInverseTypeName());
assertThat(updatedAlgorithmRelation.getAlgorithmRelationType().getInverseTypeName())
.isEqualTo(editedType.getInverseTypeName());
assertThat(updatedAlgorithmRelation.getSourceAlgorithm().getId())
.isEqualTo(compareAlgorithmRelation.getSourceAlgorithm().getId());
assertThat(updatedAlgorithmRelation.getTargetAlgorithm().getId())
Expand All @@ -158,7 +162,7 @@ void deleteAlgorithmRelation_ElementFound() {
Algorithm sourceAlgorithm = getCreatedAlgorithm("sourceAlgorithmName");
Algorithm targetAlgorithm = getCreatedAlgorithm("targetAlgorithmName");

var algorithmRelationType = getCreatedAlgorithmRelationType("algorithmRelationTypeName");
var algorithmRelationType = getCreatedAlgorithmRelationType("algorithmRelationTypeName", "inverseAlgorithmRelationTypeName");

AlgorithmRelation algorithmRelation = buildAlgorithmRelation(
sourceAlgorithm, targetAlgorithm, algorithmRelationType, "description");
Expand All @@ -184,7 +188,7 @@ void checkIfAlgorithmIsInAlgorithmRelation_IsInRelation() {
Algorithm sourceAlgorithm = getCreatedAlgorithm("sourceAlgorithmName");
Algorithm targetAlgorithm = getCreatedAlgorithm("targetAlgorithmName");

var algorithmRelationType = getCreatedAlgorithmRelationType("algorithmRelationTypeName");
var algorithmRelationType = getCreatedAlgorithmRelationType("algorithmRelationTypeName", "inverseAlgorithmRelationTypeName");

AlgorithmRelation algorithmRelation = buildAlgorithmRelation(
sourceAlgorithm, targetAlgorithm, algorithmRelationType, "description");
Expand All @@ -203,7 +207,7 @@ void checkIfAlgorithmIsInAlgorithmRelation_IsNotInRelation() {
Algorithm targetAlgorithm = getCreatedAlgorithm("targetAlgorithmName");
Algorithm checkAlgorithm = getCreatedAlgorithm("checkAlgorithmName");

var algorithmRelationType = getCreatedAlgorithmRelationType("algorithmRelationTypeName");
var algorithmRelationType = getCreatedAlgorithmRelationType("algorithmRelationTypeName", "inverseAlgorithmRelationTypeName");

AlgorithmRelation algorithmRelation = buildAlgorithmRelation(
sourceAlgorithm, targetAlgorithm, algorithmRelationType, "description");
Expand All @@ -230,9 +234,10 @@ private Algorithm getCreatedAlgorithm(String name) {
return algorithmService.create(algorithm);
}

private AlgorithmRelationType getCreatedAlgorithmRelationType(String name) {
private AlgorithmRelationType getCreatedAlgorithmRelationType(String name, String inverseTypeName) {
AlgorithmRelationType algorithmRelationType = new AlgorithmRelationType();
algorithmRelationType.setName(name);
algorithmRelationType.setInverseTypeName(inverseTypeName);
return algorithmRelationTypeService.create(algorithmRelationType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,20 @@ public class AlgorithmRelationTypeServiceTest extends AtlasDatabaseTestBase {

@Test
void createAlgorithmRelationType() {
AlgorithmRelationType relationType = getFullAlgorithmRelationType("relationTypeName");
AlgorithmRelationType relationType = getFullAlgorithmRelationType("relationTypeName", "inverseAlgorithmRelationTypeName");

AlgorithmRelationType storedRelationType = algorithmRelationTypeService.create(relationType);

assertThat(storedRelationType.getId()).isNotNull();
assertThat(storedRelationType.getName()).isEqualTo(relationType.getName());
assertThat(storedRelationType.getInverseTypeName()).isEqualTo(relationType.getInverseTypeName());
}

@Test
void findAllAlgorithmRelationTypes() {
AlgorithmRelationType relationType1 = getFullAlgorithmRelationType("relationTypeName1");
AlgorithmRelationType relationType1 = getFullAlgorithmRelationType("relationTypeName1", "inverseAlgorithmRelationTypeName1");
algorithmRelationTypeService.create(relationType1);
AlgorithmRelationType relationType2 = getFullAlgorithmRelationType("relationTypeName2");
AlgorithmRelationType relationType2 = getFullAlgorithmRelationType("relationTypeName2", "inverseAlgorithmRelationTypeName2");
algorithmRelationTypeService.create(relationType2);

List<AlgorithmRelationType> algorithmRelationTypes = algorithmRelationTypeService.findAll(Pageable.unpaged()).getContent();
Expand All @@ -82,39 +83,44 @@ void findAlgorithmRelationTypeById_ElementNotFound() {

@Test
void findAlgorithmRelationTypeById_ElementFound() {
AlgorithmRelationType relationType = getFullAlgorithmRelationType("relationTypeName");
AlgorithmRelationType relationType = getFullAlgorithmRelationType("relationTypeName", "inverseAlgorithmRelationTypeName");

AlgorithmRelationType storedRelationType = algorithmRelationTypeService.create(relationType);

storedRelationType = algorithmRelationTypeService.findById(storedRelationType.getId());

assertThat(storedRelationType.getId()).isNotNull();
assertThat(storedRelationType.getName()).isEqualTo(relationType.getName());
assertThat(storedRelationType.getInverseTypeName()).isEqualTo(relationType.getInverseTypeName());
}

@Test
void UpdateAlgorithmRelationType_ElementNotFound() {
AlgorithmRelationType relationType = getFullAlgorithmRelationType("relationTypeName");
AlgorithmRelationType relationType = getFullAlgorithmRelationType("relationTypeName", "inverseAlgorithmRelationTypeName");
relationType.setId(UUID.randomUUID());
assertThrows(NoSuchElementException.class, () ->
algorithmRelationTypeService.update(relationType));
}

@Test
void updateAlgorithmRelationType_ElementFound() {
AlgorithmRelationType relationType = getFullAlgorithmRelationType("relationTypeName");
AlgorithmRelationType compareRelationType = getFullAlgorithmRelationType("relationTypeName");
AlgorithmRelationType relationType = getFullAlgorithmRelationType("relationTypeName", "inverseAlgorithmRelationTypeName");
AlgorithmRelationType compareRelationType = getFullAlgorithmRelationType("relationTypeName", "inverseAlgorithmRelationTypeName");

AlgorithmRelationType storedRelationType = algorithmRelationTypeService.create(relationType);
compareRelationType.setId(storedRelationType.getId());
String editName = "editedRelationTypeName";
String editInverseName = "editedinverseAlgorithmRelationTypeName";
storedRelationType.setName(editName);
storedRelationType.setInverseTypeName(editInverseName);
storedRelationType = algorithmRelationTypeService.update(storedRelationType);

assertThat(storedRelationType.getId()).isNotNull();
assertThat(storedRelationType.getId()).isEqualTo(compareRelationType.getId());
assertThat(storedRelationType.getName()).isNotEqualTo(compareRelationType.getName());
assertThat(storedRelationType.getName()).isEqualTo(editName);
assertThat(storedRelationType.getInverseTypeName()).isNotEqualTo(compareRelationType.getInverseTypeName());
assertThat(storedRelationType.getInverseTypeName()).isEqualTo(editInverseName);
}

@Test
Expand All @@ -129,7 +135,7 @@ void deleteAlgorithmRelationType_UsedInRelation() {
targetAlgorithm.setComputationModel(ComputationModel.CLASSIC);
Algorithm storedTargetAlgorithm = algorithmService.create(targetAlgorithm);

AlgorithmRelationType relationType = getFullAlgorithmRelationType("relationTypeName");
AlgorithmRelationType relationType = getFullAlgorithmRelationType("relationTypeName", "inverseAlgorithmRelationTypeName");
AlgorithmRelationType storedRelationType = algorithmRelationTypeService.create(relationType);

AlgorithmRelation algorithmRelation = new AlgorithmRelation();
Expand All @@ -147,7 +153,7 @@ void deleteAlgorithmRelationType_UsedInRelation() {

@Test
void deleteAlgorithmRelationType_Unused() {
AlgorithmRelationType relationType = getFullAlgorithmRelationType("relationTypeName");
AlgorithmRelationType relationType = getFullAlgorithmRelationType("relationTypeName", "inverseAlgorithmRelationTypeName");
AlgorithmRelationType storedRelationType = algorithmRelationTypeService.create(relationType);

assertDoesNotThrow(() -> algorithmRelationTypeService.findById(storedRelationType.getId()));
Expand All @@ -158,9 +164,10 @@ void deleteAlgorithmRelationType_Unused() {
algorithmRelationTypeService.findById(storedRelationType.getId()));
}

private AlgorithmRelationType getFullAlgorithmRelationType(String typeName) {
private AlgorithmRelationType getFullAlgorithmRelationType(String typeName, String inverseTypeName) {
AlgorithmRelationType algorithmRelationType = new AlgorithmRelationType();
algorithmRelationType.setName(typeName);
algorithmRelationType.setInverseTypeName(inverseTypeName);
return algorithmRelationType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ public class AlgorithmRelationTypeDto implements Identifyable {
@NotNull(groups = {ValidationGroups.Update.class, ValidationGroups.Create.class},
message = "RelationType-Name must not be null!")
private String name;

private String inverseTypeName;
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
* Default database in non-Docker development environments
* Target database for Liquibase operations, such as diff or update
-->
<db.url>jdbc:postgresql://localhost:5432/planqk</db.url>
<db.url>jdbc:postgresql://localhost:5060/planqk</db.url>
<db.username>planqk</db.username>
<db.password>planqk</db.password>
<checkstyle.config.location>checkstyle.xml</checkstyle.config.location>
Expand Down

0 comments on commit dd199ab

Please sign in to comment.