Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ We encourage and appreciate feedback and contribution from the community!
- [Issue and Feature Requests](#issue)
- [PR Submission Guidelines](#submit-pr)
- [Coding Rules](#rules)
- [Set Up](#setup)

## <a name="question"></a> Question or Problem?

Expand All @@ -32,4 +33,13 @@ Please follow the rules as you work on the code:
- Leave the code better than you find it.
- Use the given Style Guide [Style Guide](https://github.com/Mom0aut/DynamicRelations/blob/master/StyleGuide.xml)

## <a name="setup"></a> Set Up
When starting out, make sure to check these few things before building the project:

- Ensure that Annotation Processor is enabled in your IDE.
- Ensure that the processor FQ name is added and set to:
```at.drm.processor.RelationProcessor```.
- For IntelliJ, ensure you use the inbuilt Build tool found at the 'Build' tab. Running ```mvn clean install```
in the CLI will NOT have Annotation Processors activated which is required for this project.

Happy contributing :smiley:
12 changes: 0 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -261,18 +261,6 @@

<build>
<plugins>
<!-- <plugin>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-maven-plugin</artifactId>-->
<!-- <configuration>-->
<!-- <excludes>-->
<!-- <exclude>-->
<!-- <groupId>org.projectlombok</groupId>-->
<!-- <artifactId>lombok</artifactId>-->
<!-- </exclude>-->
<!-- </excludes>-->
<!-- </configuration>-->
<!-- </plugin>-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
import org.springframework.stereotype.Repository;

@Repository
public interface AnnotaionDao extends CrudRepository<AnnotationTest, Long> {
public interface DocumentDao extends CrudRepository<DocumentEntity, Long> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

import at.drm.annotation.Relation;
import at.drm.model.RelationIdentity;
import lombok.Data;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.Data;

@Relation
@Entity
@Data
public class AnnotationTest2 implements RelationIdentity {
public class DocumentEntity implements RelationIdentity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
import org.springframework.stereotype.Repository;

@Repository
public interface Annotaion2Dao extends CrudRepository<AnnotationTest2, Long> {
public interface DogDao extends CrudRepository<DogEntity, Long> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Relation
@Entity
@Data
public class AnnotationTest implements RelationIdentity {
public class DogEntity implements RelationIdentity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
import org.springframework.stereotype.Repository;

@Repository
public interface Annotaion3Dao extends CrudRepository<AnnotationTest3, Long> {
public interface PersonDao extends CrudRepository<PersonEntity, Long> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.Getter;

@Relation
@Entity
@Data
public class AnnotationTest3 implements RelationIdentity {
public class PersonEntity implements RelationIdentity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

}
12 changes: 6 additions & 6 deletions testing/src/main/resources/db/migration/V1_0_0__init_schema.sql
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
CREATE TABLE ANNOTATION_TEST (
CREATE TABLE PERSON_ENTITY (
id BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY
);

CREATE TABLE ANNOTATION_TEST2 (
CREATE TABLE DOG_ENTITY (
id BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY
);

CREATE TABLE ANNOTATION_TEST3 (
CREATE TABLE DOCUMENT_ENTITY (
id BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY
);

CREATE TABLE ANNOTATION_TEST_RELATION (
CREATE TABLE PERSON_ENTITY_RELATION (
id BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
target_id BIGINT NOT NULL,
target_type VARCHAR(255) NOT NULL,
source_object BIGINT
);

CREATE TABLE ANNOTATION_TEST2RELATION (
CREATE TABLE DOG_ENTITY_RELATION (
id BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
target_id BIGINT NOT NULL,
target_type VARCHAR(255) NOT NULL,
source_object BIGINT
);

CREATE TABLE ANNOTATION_TEST3RELATION (
CREATE TABLE DOCUMENT_ENTITY_RELATION (
id BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
target_id BIGINT NOT NULL,
target_type VARCHAR(255) NOT NULL,
Expand Down
74 changes: 38 additions & 36 deletions testing/src/test/java/at/test/drm/ApplicationIntegrationTest.java
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
package at.test.drm;

import at.drm.EnableDynamicRelation;
import at.drm.model.RelationLink;
import at.drm.service.DynamicRelationsPrintService;
import at.drm.service.RelationService;
import io.zonky.test.db.AutoConfigureEmbeddedDatabase;
import io.zonky.test.db.AutoConfigureEmbeddedDatabase.DatabaseProvider;
import java.util.List;
import java.util.Set;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

import at.drm.EnableDynamicRelation;
import at.drm.model.RelationLink;
import at.drm.service.DynamicRelationsPrintService;
import at.drm.service.RelationService;
import io.zonky.test.db.AutoConfigureEmbeddedDatabase;
import io.zonky.test.db.AutoConfigureEmbeddedDatabase.DatabaseProvider;

@SpringBootTest
@ActiveProfiles("integration")
@EnableDynamicRelation
@AutoConfigureEmbeddedDatabase(provider = DatabaseProvider.ZONKY)
class ApplicationIntegrationTest {

@Autowired
private AnnotaionDao dao;
private PersonDao dao;
@Autowired
private Annotaion2Dao dao2;
private DogDao dao2;
@Autowired
private Annotaion3Dao dao3;
private DocumentDao dao3;
@Autowired
private RelationService relationService;
@Autowired
private DynamicRelationsPrintService dynamicRelationsPrintService;

@Test
void shouldFindRelationBySourceObject() {
var first = new AnnotationTest();
var second = new AnnotationTest2();
var third = new AnnotationTest3();
var first = new PersonEntity();
var second = new DogEntity();
var third = new DocumentEntity();
dao.save(first);
dao2.save(second);
dao3.save(third);
Expand All @@ -55,9 +57,9 @@ void shouldFindRelationBySourceObject() {

@Test
void shouldFindRelationByTarget() {
var first = new AnnotationTest();
var second = new AnnotationTest2();
var third = new AnnotationTest3();
var first = new PersonEntity();
var second = new DogEntity();
var third = new DocumentEntity();
dao.save(first);
dao2.save(second);
dao3.save(third);
Expand All @@ -78,9 +80,9 @@ void shouldFindRelationByTarget() {

@Test
void shouldFindRelationBySourceObjectAndIdentity() {
var first = new AnnotationTest();
var second = new AnnotationTest2();
var third = new AnnotationTest3();
var first = new PersonEntity();
var second = new DogEntity();
var third = new DocumentEntity();
dao.save(first);
dao2.save(second);
dao3.save(third);
Expand All @@ -99,9 +101,9 @@ void shouldFindRelationBySourceObjectAndIdentity() {

@Test
void shouldDeleteRelation() {
var first = new AnnotationTest();
var second = new AnnotationTest2();
var third = new AnnotationTest3();
var first = new PersonEntity();
var second = new DogEntity();
var third = new DocumentEntity();
dao.save(first);
dao2.save(second);
dao3.save(third);
Expand All @@ -120,9 +122,9 @@ void shouldDeleteRelation() {

@Test
void shouldPrintRelations() {
var first = new AnnotationTest();
var second = new AnnotationTest2();
var third = new AnnotationTest3();
var first = new PersonEntity();
var second = new DogEntity();
var third = new DocumentEntity();
dao.save(first);
dao2.save(second);
dao3.save(third);
Expand All @@ -134,18 +136,18 @@ void shouldPrintRelations() {
String actual = dynamicRelationsPrintService.printRelations(first);
System.out.println(actual);
Assertions.assertThat(actual).isEqualTo("""
AnnotationTestType
AnnotationTest3Type
AnnotationTest2Type
AnnotationTest3Type
PersonEntityType
DocumentEntityType
DogEntityType
DocumentEntityType
""");
}

@Test
void shouldPrintRelationsWithCyclicRelations() {
var first = new AnnotationTest();
var second = new AnnotationTest2();
var third = new AnnotationTest3();
var first = new PersonEntity();
var second = new DogEntity();
var third = new DocumentEntity();
dao.save(first);
dao2.save(second);
dao3.save(third);
Expand All @@ -156,11 +158,11 @@ void shouldPrintRelationsWithCyclicRelations() {
relationService.createRelation(third, second);

Assertions.assertThat(dynamicRelationsPrintService.printRelations(first)).isEqualTo("""
AnnotationTestType
AnnotationTest3Type
AnnotationTest2Type
AnnotationTest2Type
AnnotationTest3Type
PersonEntityType
DocumentEntityType
DogEntityType
DogEntityType
DocumentEntityType
""");
}
}
30 changes: 16 additions & 14 deletions testing/src/test/java/at/test/drm/RelationDaoFactoryTest.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package at.test.drm;

import at.drm.dao.RelationDao;
import at.drm.exception.NoRelationDaoFoundException;
import at.drm.factory.RelationDaoFactory;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.mockito.ArgumentMatchers.any;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.context.ApplicationContext;

import java.util.*;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.mockito.ArgumentMatchers.any;
import at.drm.dao.RelationDao;
import at.drm.exception.NoRelationDaoFoundException;
import at.drm.factory.RelationDaoFactory;


@ExtendWith(MockitoExtension.class)
Expand All @@ -25,7 +27,7 @@ class RelationDaoFactoryTest {
private ApplicationContext applicationContext;

@Mock
private AnnotationTest2RelationDao annotationTest2RelationDao;
private DogEntityRelationDao dogEntityRelationDao;

@Mock
private RelationDao relationDao;
Expand All @@ -36,20 +38,20 @@ class RelationDaoFactoryTest {
@Test
void getDaoFromSourceObjectClass() {
Mockito.when(applicationContext.getBeansOfType(any(Class.class)))
.thenReturn(Map.ofEntries(Map.entry("testDao", annotationTest2RelationDao)));
.thenReturn(Map.ofEntries(Map.entry("testDao", dogEntityRelationDao)));
RelationDao daoFromSourceObjectClass = relationDaoFactoryUnderTest.getDaoFromSourceObjectClass(
AnnotationTest2.class);
DogEntity.class);
assertThat(daoFromSourceObjectClass).isNotNull();
assertThat(daoFromSourceObjectClass).isInstanceOf(annotationTest2RelationDao.getClass());
assertThat(daoFromSourceObjectClass).isInstanceOf(dogEntityRelationDao.getClass());
}

@Test
void getDaoFromSourceObjectClassShouldThrowNoDaoFoundException() {
Mockito.when(applicationContext.getBeansOfType(any(Class.class)))
.thenReturn(Map.ofEntries(Map.entry("testDao", annotationTest2RelationDao)));
.thenReturn(Map.ofEntries(Map.entry("testDao", dogEntityRelationDao)));
NoRelationDaoFoundException exception = Assertions.assertThrows(NoRelationDaoFoundException.class, () -> {
relationDaoFactoryUnderTest.getDaoFromSourceObjectClass(
AnnotationTest.class);
PersonEntity.class);
});
assertThat(exception).isNotNull();
}
Expand All @@ -61,7 +63,7 @@ void getDaoFromSourceObjectClassShouldThrowRuntimeException() {
.thenReturn(Map.ofEntries(Map.entry("wrongTestDao", relationDao)));
RuntimeException exception = Assertions.assertThrows(RuntimeException.class, () -> {
relationDaoFactoryUnderTest.getDaoFromSourceObjectClass(
AnnotaionDao.class);
PersonEntity.class);
});
assertThat(exception).isNotNull();
}
Expand Down
Loading