From 356a620852ea6b54d620e9821e0752affc5650b0 Mon Sep 17 00:00:00 2001 From: jenniferboedker Date: Mon, 14 Dec 2020 14:25:58 +0100 Subject: [PATCH] add equals and hash to products --- .../dtos/business/services/AtomicProduct.groovy | 3 +++ .../dtos/business/services/DataStorage.groovy | 3 +++ .../dtos/business/services/PartialProduct.groovy | 3 +++ .../dtos/business/services/PrimaryAnalysis.groovy | 3 +++ .../datamodel/dtos/business/services/Product.groovy | 3 +++ .../dtos/business/services/ProjectManagement.groovy | 3 +++ .../dtos/business/services/SecondaryAnalysis.groovy | 3 +++ .../datamodel/dtos/business/services/Sequencing.groovy | 3 +++ .../datamodel/dtos/business/ProductItemSpec.groovy | 10 ++++++++++ 9 files changed, 34 insertions(+) diff --git a/src/main/groovy/life/qbic/datamodel/dtos/business/services/AtomicProduct.groovy b/src/main/groovy/life/qbic/datamodel/dtos/business/services/AtomicProduct.groovy index 2e4290dc1..e2b2eb869 100644 --- a/src/main/groovy/life/qbic/datamodel/dtos/business/services/AtomicProduct.groovy +++ b/src/main/groovy/life/qbic/datamodel/dtos/business/services/AtomicProduct.groovy @@ -1,5 +1,7 @@ package life.qbic.datamodel.dtos.business.services +import groovy.transform.EqualsAndHashCode + /** * Describes a product type that can only have positive natural unit multipliers (N={0,1...,inf+}) * @@ -8,6 +10,7 @@ package life.qbic.datamodel.dtos.business.services * * @since 1.12.0 */ +@EqualsAndHashCode(callSuper = true) class AtomicProduct extends Product { /** * Basic product constructor. diff --git a/src/main/groovy/life/qbic/datamodel/dtos/business/services/DataStorage.groovy b/src/main/groovy/life/qbic/datamodel/dtos/business/services/DataStorage.groovy index a37f0eccd..e2f2ab298 100644 --- a/src/main/groovy/life/qbic/datamodel/dtos/business/services/DataStorage.groovy +++ b/src/main/groovy/life/qbic/datamodel/dtos/business/services/DataStorage.groovy @@ -1,10 +1,13 @@ package life.qbic.datamodel.dtos.business.services +import groovy.transform.EqualsAndHashCode + /** * Describes a product for data storage services. * * @since 1.12.0 */ +@EqualsAndHashCode(callSuper = true) class DataStorage extends PartialProduct { /** * Basic product constructor. diff --git a/src/main/groovy/life/qbic/datamodel/dtos/business/services/PartialProduct.groovy b/src/main/groovy/life/qbic/datamodel/dtos/business/services/PartialProduct.groovy index 1ba8b8979..29b7f2003 100644 --- a/src/main/groovy/life/qbic/datamodel/dtos/business/services/PartialProduct.groovy +++ b/src/main/groovy/life/qbic/datamodel/dtos/business/services/PartialProduct.groovy @@ -1,5 +1,7 @@ package life.qbic.datamodel.dtos.business.services +import groovy.transform.EqualsAndHashCode + /** * Describes a product type that can only have positive natural unit multipliers (N={0,1...,inf+}) * @@ -9,6 +11,7 @@ package life.qbic.datamodel.dtos.business.services * * @since 1.12.0 */ +@EqualsAndHashCode(callSuper = true) class PartialProduct extends Product { /** * Basic product constructor. diff --git a/src/main/groovy/life/qbic/datamodel/dtos/business/services/PrimaryAnalysis.groovy b/src/main/groovy/life/qbic/datamodel/dtos/business/services/PrimaryAnalysis.groovy index 6cdaf8c96..58dd92147 100644 --- a/src/main/groovy/life/qbic/datamodel/dtos/business/services/PrimaryAnalysis.groovy +++ b/src/main/groovy/life/qbic/datamodel/dtos/business/services/PrimaryAnalysis.groovy @@ -1,10 +1,13 @@ package life.qbic.datamodel.dtos.business.services +import groovy.transform.EqualsAndHashCode + /** * Describes a product for primary bioinformatic analysis services. * * @since 1.12.0 */ +@EqualsAndHashCode(callSuper = true) class PrimaryAnalysis extends AtomicProduct { /** * Basic product constructor. diff --git a/src/main/groovy/life/qbic/datamodel/dtos/business/services/Product.groovy b/src/main/groovy/life/qbic/datamodel/dtos/business/services/Product.groovy index ded15a069..657ffe812 100644 --- a/src/main/groovy/life/qbic/datamodel/dtos/business/services/Product.groovy +++ b/src/main/groovy/life/qbic/datamodel/dtos/business/services/Product.groovy @@ -1,5 +1,7 @@ package life.qbic.datamodel.dtos.business.services +import groovy.transform.EqualsAndHashCode + /** * Holds information about a simple QBiC service product. * @@ -8,6 +10,7 @@ package life.qbic.datamodel.dtos.business.services * * @since 1.12.0 */ +@EqualsAndHashCode abstract class Product { /** diff --git a/src/main/groovy/life/qbic/datamodel/dtos/business/services/ProjectManagement.groovy b/src/main/groovy/life/qbic/datamodel/dtos/business/services/ProjectManagement.groovy index 5b719cb5e..70559377d 100644 --- a/src/main/groovy/life/qbic/datamodel/dtos/business/services/ProjectManagement.groovy +++ b/src/main/groovy/life/qbic/datamodel/dtos/business/services/ProjectManagement.groovy @@ -1,10 +1,13 @@ package life.qbic.datamodel.dtos.business.services +import groovy.transform.EqualsAndHashCode + /** * Describes a product for project management services. * * @since 1.12.0 */ +@EqualsAndHashCode(callSuper = true) class ProjectManagement extends PartialProduct { /** * Basic product constructor. diff --git a/src/main/groovy/life/qbic/datamodel/dtos/business/services/SecondaryAnalysis.groovy b/src/main/groovy/life/qbic/datamodel/dtos/business/services/SecondaryAnalysis.groovy index 6f73165de..78098f6ce 100644 --- a/src/main/groovy/life/qbic/datamodel/dtos/business/services/SecondaryAnalysis.groovy +++ b/src/main/groovy/life/qbic/datamodel/dtos/business/services/SecondaryAnalysis.groovy @@ -1,10 +1,13 @@ package life.qbic.datamodel.dtos.business.services +import groovy.transform.EqualsAndHashCode + /** * Describes a product for secondary bioinformatic analysis services. * * @since 1.12.0 */ +@EqualsAndHashCode(callSuper = true) class SecondaryAnalysis extends AtomicProduct { /** * Basic product constructor. diff --git a/src/main/groovy/life/qbic/datamodel/dtos/business/services/Sequencing.groovy b/src/main/groovy/life/qbic/datamodel/dtos/business/services/Sequencing.groovy index 8e123c590..48c8b81d7 100644 --- a/src/main/groovy/life/qbic/datamodel/dtos/business/services/Sequencing.groovy +++ b/src/main/groovy/life/qbic/datamodel/dtos/business/services/Sequencing.groovy @@ -1,10 +1,13 @@ package life.qbic.datamodel.dtos.business.services +import groovy.transform.EqualsAndHashCode + /** * Describes a product for sequencing services. * * @since 1.12.0 */ +@EqualsAndHashCode(callSuper = true) class Sequencing extends AtomicProduct { /** * Basic product constructor. diff --git a/src/test/groovy/life/qbic/datamodel/dtos/business/ProductItemSpec.groovy b/src/test/groovy/life/qbic/datamodel/dtos/business/ProductItemSpec.groovy index b1ed531da..d386ac179 100644 --- a/src/test/groovy/life/qbic/datamodel/dtos/business/ProductItemSpec.groovy +++ b/src/test/groovy/life/qbic/datamodel/dtos/business/ProductItemSpec.groovy @@ -16,11 +16,21 @@ class ProductItemSpec extends Specification { def "ProductItem shall store and provide the given properties: name, description and product"() { when: Product product = new Sequencing("RNA Sequencing", "This package manages the pricing for all RNA sequencings", 1.0, ProductUnit.PER_SAMPLE) + def productItem = new ProductItem(3.0, product) then: productItem.product == product } + def "Products shall be comparable"(){ + when: + Product product = new Sequencing("RNA Sequencing", "This package manages the pricing for all RNA sequencings", 1.0, ProductUnit.PER_SAMPLE) + Product product2 = new Sequencing("RNA Sequencing", "This package manages the pricing for all RNA sequencings", 1.0, ProductUnit.PER_SAMPLE) + + then: + product == product2 + } + }