diff --git a/Contributing.md b/Contributing.md index 04eb2e7..9880ed0 100644 --- a/Contributing.md +++ b/Contributing.md @@ -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) ## Question or Problem? @@ -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) +## 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: diff --git a/pom.xml b/pom.xml index dc7b14f..cd07639 100644 --- a/pom.xml +++ b/pom.xml @@ -261,18 +261,6 @@ - - - - - - - - - - - - org.apache.maven.plugins maven-compiler-plugin diff --git a/testing/src/main/java/at/test/drm/AnnotaionDao.java b/testing/src/main/java/at/test/drm/DocumentDao.java similarity index 65% rename from testing/src/main/java/at/test/drm/AnnotaionDao.java rename to testing/src/main/java/at/test/drm/DocumentDao.java index 3ae2fac..c59fbc9 100644 --- a/testing/src/main/java/at/test/drm/AnnotaionDao.java +++ b/testing/src/main/java/at/test/drm/DocumentDao.java @@ -4,6 +4,6 @@ import org.springframework.stereotype.Repository; @Repository -public interface AnnotaionDao extends CrudRepository { +public interface DocumentDao extends CrudRepository { } diff --git a/testing/src/main/java/at/test/drm/AnnotationTest2.java b/testing/src/main/java/at/test/drm/DocumentEntity.java similarity index 86% rename from testing/src/main/java/at/test/drm/AnnotationTest2.java rename to testing/src/main/java/at/test/drm/DocumentEntity.java index 736267b..cc4eaaa 100644 --- a/testing/src/main/java/at/test/drm/AnnotationTest2.java +++ b/testing/src/main/java/at/test/drm/DocumentEntity.java @@ -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) diff --git a/testing/src/main/java/at/test/drm/Annotaion2Dao.java b/testing/src/main/java/at/test/drm/DogDao.java similarity index 65% rename from testing/src/main/java/at/test/drm/Annotaion2Dao.java rename to testing/src/main/java/at/test/drm/DogDao.java index 4aebc30..9f40394 100644 --- a/testing/src/main/java/at/test/drm/Annotaion2Dao.java +++ b/testing/src/main/java/at/test/drm/DogDao.java @@ -4,6 +4,6 @@ import org.springframework.stereotype.Repository; @Repository -public interface Annotaion2Dao extends CrudRepository { +public interface DogDao extends CrudRepository { } diff --git a/testing/src/main/java/at/test/drm/AnnotationTest.java b/testing/src/main/java/at/test/drm/DogEntity.java similarity index 86% rename from testing/src/main/java/at/test/drm/AnnotationTest.java rename to testing/src/main/java/at/test/drm/DogEntity.java index 657731c..dad00cc 100644 --- a/testing/src/main/java/at/test/drm/AnnotationTest.java +++ b/testing/src/main/java/at/test/drm/DogEntity.java @@ -12,7 +12,7 @@ @Relation @Entity @Data -public class AnnotationTest implements RelationIdentity { +public class DogEntity implements RelationIdentity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/testing/src/main/java/at/test/drm/Annotaion3Dao.java b/testing/src/main/java/at/test/drm/PersonDao.java similarity index 65% rename from testing/src/main/java/at/test/drm/Annotaion3Dao.java rename to testing/src/main/java/at/test/drm/PersonDao.java index 7671eb2..f405fa8 100644 --- a/testing/src/main/java/at/test/drm/Annotaion3Dao.java +++ b/testing/src/main/java/at/test/drm/PersonDao.java @@ -4,6 +4,6 @@ import org.springframework.stereotype.Repository; @Repository -public interface Annotaion3Dao extends CrudRepository { +public interface PersonDao extends CrudRepository { } diff --git a/testing/src/main/java/at/test/drm/AnnotationTest3.java b/testing/src/main/java/at/test/drm/PersonEntity.java similarity index 82% rename from testing/src/main/java/at/test/drm/AnnotationTest3.java rename to testing/src/main/java/at/test/drm/PersonEntity.java index 7d48327..5182acb 100644 --- a/testing/src/main/java/at/test/drm/AnnotationTest3.java +++ b/testing/src/main/java/at/test/drm/PersonEntity.java @@ -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; + } diff --git a/testing/src/main/resources/db/migration/V1_0_0__init_schema.sql b/testing/src/main/resources/db/migration/V1_0_0__init_schema.sql index c6a68c8..68104a0 100644 --- a/testing/src/main/resources/db/migration/V1_0_0__init_schema.sql +++ b/testing/src/main/resources/db/migration/V1_0_0__init_schema.sql @@ -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, diff --git a/testing/src/test/java/at/test/drm/ApplicationIntegrationTest.java b/testing/src/test/java/at/test/drm/ApplicationIntegrationTest.java index 67c1a27..27489f2 100644 --- a/testing/src/test/java/at/test/drm/ApplicationIntegrationTest.java +++ b/testing/src/test/java/at/test/drm/ApplicationIntegrationTest.java @@ -1,19 +1,21 @@ 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 @@ -21,11 +23,11 @@ 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 @@ -33,9 +35,9 @@ class ApplicationIntegrationTest { @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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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 """); } } diff --git a/testing/src/test/java/at/test/drm/RelationDaoFactoryTest.java b/testing/src/test/java/at/test/drm/RelationDaoFactoryTest.java index 559852d..0981c10 100644 --- a/testing/src/test/java/at/test/drm/RelationDaoFactoryTest.java +++ b/testing/src/test/java/at/test/drm/RelationDaoFactoryTest.java @@ -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) @@ -25,7 +27,7 @@ class RelationDaoFactoryTest { private ApplicationContext applicationContext; @Mock - private AnnotationTest2RelationDao annotationTest2RelationDao; + private DogEntityRelationDao dogEntityRelationDao; @Mock private RelationDao relationDao; @@ -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(); } @@ -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(); } diff --git a/testing/src/test/java/at/test/drm/RelationServiceTest.java b/testing/src/test/java/at/test/drm/RelationServiceTest.java index 4b9fe78..7abe0a5 100644 --- a/testing/src/test/java/at/test/drm/RelationServiceTest.java +++ b/testing/src/test/java/at/test/drm/RelationServiceTest.java @@ -23,7 +23,7 @@ public class RelationServiceTest { private RelationDaoFactory relationDaoFactory; @Mock - private AnnotationTestRelationDao annotationTestRelationDao; + private PersonEntityRelationDao personEntityRelationDao; @InjectMocks private RelationService relationService; @@ -31,39 +31,39 @@ public class RelationServiceTest { @Test void createRelation() { Mockito.when(relationDaoFactory.getDaoFromSourceObjectClass(any(Class.class))) - .thenReturn(annotationTestRelationDao); - AnnotationTest annotationTest = new AnnotationTest(); - annotationTest.setId(1L); - AnnotationTest2 annotationTest2 = new AnnotationTest2(); - annotationTest2.setId(1L); - relationService.createRelation(annotationTest, annotationTest2); + .thenReturn(personEntityRelationDao); + PersonEntity PersonEntity = new PersonEntity(); + PersonEntity.setId(1L); + DogEntity DogEntity = new DogEntity(); + DogEntity.setId(1L); + relationService.createRelation(PersonEntity, DogEntity); } @Test void deleteRelation() { Mockito.when(relationDaoFactory.getDaoFromSourceObjectClass(any(Class.class))) - .thenReturn(annotationTestRelationDao); - AnnotationTestRelation annotationTestRelation = new AnnotationTestRelation(); - annotationTestRelation.setSourceObject(new AnnotationTest()); - relationService.deleteRelation(annotationTestRelation); + .thenReturn(personEntityRelationDao); + PersonEntityRelation personEntityRelation = new PersonEntityRelation(); + personEntityRelation.setSourceObject(new PersonEntity()); + relationService.deleteRelation(personEntityRelation); } @Test void findRelationBySourceObject() { Mockito.when(relationDaoFactory.getDaoFromSourceObjectClass(any(Class.class))) - .thenReturn(annotationTestRelationDao); - AnnotationTest annotationTest = new AnnotationTest(); - annotationTest.setId(1L); - List relationBySourceObject = relationService.findRelationBySourceObject(annotationTest); + .thenReturn(personEntityRelationDao); + PersonEntity PersonEntity = new PersonEntity(); + PersonEntity.setId(1L); + List relationBySourceObject = relationService.findRelationBySourceObject(PersonEntity); } @Test void findRelationByTargetRelationIdentity() { Mockito.when(relationDaoFactory.getAllDaos()) - .thenReturn(Collections.singleton(annotationTestRelationDao)); - AnnotationTest annotationTest = new AnnotationTest(); - annotationTest.setId(1L); - Set relationByTargetRelationIdentity = relationService.findRelationByTargetRelationIdentity(annotationTest); + .thenReturn(Collections.singleton(personEntityRelationDao)); + PersonEntity PersonEntity = new PersonEntity(); + PersonEntity.setId(1L); + Set relationByTargetRelationIdentity = relationService.findRelationByTargetRelationIdentity(PersonEntity); } } diff --git a/testing/src/test/java/at/test/drm/RelationTest.java b/testing/src/test/java/at/test/drm/RelationTest.java index 44b72bd..f2e7e3d 100644 --- a/testing/src/test/java/at/test/drm/RelationTest.java +++ b/testing/src/test/java/at/test/drm/RelationTest.java @@ -1,17 +1,18 @@ package at.test.drm; -import at.drm.factory.RelationDaoFactory; -import at.drm.model.RelationLink; -import at.drm.service.RelationService; +import java.util.List; +import java.util.Set; + import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.ApplicationContext; -import java.util.List; -import java.util.Set; +import at.drm.factory.RelationDaoFactory; +import at.drm.model.RelationLink; +import at.drm.service.RelationService; @SpringBootTest @Disabled @@ -19,13 +20,13 @@ class RelationTest { @Autowired - private AnnotaionDao annotaionDao; + private PersonDao personEntityDao; @Autowired - private Annotaion2Dao annotaion2Dao; + private DogDao dogEntityDao; @Autowired - private Annotaion3Dao annotaion3Dao; + private DocumentDao documentEntityDao; private final RelationDaoFactory relationDaoFactory; @@ -41,23 +42,23 @@ public RelationTest(ApplicationContext applicationContext) { @Test void testCreateRelation() { - AnnotationTest annotationTest = new AnnotationTest(); - annotaionDao.save(annotationTest); + PersonEntity personEntity = new PersonEntity(); + personEntityDao.save(personEntity); - AnnotationTest2 annotationTest2 = new AnnotationTest2(); - annotaion2Dao.save(annotationTest2); + DogEntity dogEntity = new DogEntity(); + dogEntityDao.save(dogEntity); - AnnotationTest3 annotationTest3 = new AnnotationTest3(); - annotaion3Dao.save(annotationTest3); + DocumentEntity documentEntity = new DocumentEntity(); + documentEntityDao.save(documentEntity); - RelationLink test = relationService.createRelation(annotationTest, annotationTest2); - RelationLink test2 = relationService.createRelation(annotationTest, annotationTest3); - RelationLink test3 = relationService.createRelation(annotationTest2, annotationTest3); + RelationLink test = relationService.createRelation(personEntity, dogEntity); + RelationLink test2 = relationService.createRelation(personEntity, documentEntity); + RelationLink test3 = relationService.createRelation(dogEntity, documentEntity); - RelationLink relationLink = relationService.findRelationBySourceObjectAndRelationIdentity(annotationTest, annotationTest2); + RelationLink relationLink = relationService.findRelationBySourceObjectAndRelationIdentity(personEntity, dogEntity); - List relationBySourceObject = relationService.findRelationBySourceObject(annotationTest); - Set relationByTargetRelationIdentity = relationService.findRelationByTargetRelationIdentity(annotationTest3); + List relationBySourceObject = relationService.findRelationBySourceObject(personEntity); + Set relationByTargetRelationIdentity = relationService.findRelationByTargetRelationIdentity(documentEntity); relationService.deleteRelation(test); System.out.println();