From f5565ab7375a7e185a7c25d9cffa17e058bbd271 Mon Sep 17 00:00:00 2001 From: Stefan Maute Date: Wed, 17 Feb 2021 13:29:17 +0100 Subject: [PATCH 1/3] moved ditto live signals into ditto-java-client; Signed-off-by: Stefan Maute --- java/pom.xml | 5 - .../client/live/LiveCommandProcessor.java | 6 +- .../FeaturePropertiesCommandHandling.java | 18 +- .../commands/FeaturesCommandHandling.java | 18 +- .../commands/LiveCommandAcknowledgeable.java | 6 +- .../live/commands/LiveCommandFactory.java | 141 +++++++ .../live/commands/LiveCommandHandler.java | 4 +- .../live/commands/LiveCommandHandlerImpl.java | 4 +- .../ThingAttributesCommandHandling.java | 18 +- .../live/commands/ThingCommandHandling.java | 14 +- .../live/commands/ThingsCommandHandling.java | 6 +- .../commands/base/AbstractLiveCommand.java | 104 +++++ .../base/ImmutableLiveCommandAnswer.java | 84 ++++ .../live/commands/base/LiveCommand.java | 42 ++ .../live/commands/base/LiveCommandAnswer.java | 45 +++ .../base/LiveCommandAnswerBuilder.java | 126 ++++++ .../base/LiveCommandAnswerFactory.java | 69 ++++ .../base/LiveCommandResponseFactory.java | 80 ++++ .../live/commands/base/LiveEventFactory.java | 23 ++ .../live/commands/base/package-info.java | 18 + .../AbstractLiveCommandAnswerBuilder.java | 118 ++++++ .../modify/AbstractModifyLiveCommand.java | 60 +++ .../modify/CreateThingLiveCommand.java | 38 ++ .../CreateThingLiveCommandAnswerBuilder.java | 73 ++++ ...eateThingLiveCommandAnswerBuilderImpl.java | 101 +++++ .../modify/CreateThingLiveCommandImpl.java | 93 +++++ .../modify/DeleteAttributeLiveCommand.java | 39 ++ ...leteAttributeLiveCommandAnswerBuilder.java | 85 +++++ ...AttributeLiveCommandAnswerBuilderImpl.java | 117 ++++++ .../DeleteAttributeLiveCommandImpl.java | 88 +++++ .../modify/DeleteAttributesLiveCommand.java | 28 ++ ...eteAttributesLiveCommandAnswerBuilder.java | 85 +++++ ...ttributesLiveCommandAnswerBuilderImpl.java | 114 ++++++ .../DeleteAttributesLiveCommandImpl.java | 76 ++++ .../DeleteFeatureDefinitionLiveCommand.java | 29 ++ ...ureDefinitionLiveCommandAnswerBuilder.java | 88 +++++ ...efinitionLiveCommandAnswerBuilderImpl.java | 118 ++++++ ...eleteFeatureDefinitionLiveCommandImpl.java | 87 +++++ ...teFeatureDesiredPropertiesLiveCommand.java | 30 ++ ...redPropertiesLiveCommandAnswerBuilder.java | 84 ++++ ...ropertiesLiveCommandAnswerBuilderImpl.java | 115 ++++++ ...atureDesiredPropertiesLiveCommandImpl.java | 89 +++++ ...leteFeatureDesiredPropertyLiveCommand.java | 40 ++ ...siredPropertyLiveCommandAnswerBuilder.java | 85 +++++ ...dPropertyLiveCommandAnswerBuilderImpl.java | 119 ++++++ ...FeatureDesiredPropertyLiveCommandImpl.java | 98 +++++ .../modify/DeleteFeatureLiveCommand.java | 29 ++ ...DeleteFeatureLiveCommandAnswerBuilder.java | 83 ++++ ...teFeatureLiveCommandAnswerBuilderImpl.java | 111 ++++++ .../modify/DeleteFeatureLiveCommandImpl.java | 84 ++++ .../DeleteFeaturePropertiesLiveCommand.java | 30 ++ ...urePropertiesLiveCommandAnswerBuilder.java | 85 +++++ ...ropertiesLiveCommandAnswerBuilderImpl.java | 114 ++++++ ...eleteFeaturePropertiesLiveCommandImpl.java | 88 +++++ .../DeleteFeaturePropertyLiveCommand.java | 38 ++ ...aturePropertyLiveCommandAnswerBuilder.java | 85 +++++ ...ePropertyLiveCommandAnswerBuilderImpl.java | 117 ++++++ .../DeleteFeaturePropertyLiveCommandImpl.java | 97 +++++ .../modify/DeleteFeaturesLiveCommand.java | 28 ++ ...eleteFeaturesLiveCommandAnswerBuilder.java | 83 ++++ ...eFeaturesLiveCommandAnswerBuilderImpl.java | 111 ++++++ .../modify/DeleteFeaturesLiveCommandImpl.java | 78 ++++ .../modify/DeleteThingLiveCommand.java | 28 ++ .../DeleteThingLiveCommandAnswerBuilder.java | 83 ++++ ...leteThingLiveCommandAnswerBuilderImpl.java | 108 ++++++ .../modify/DeleteThingLiveCommandImpl.java | 77 ++++ .../modify/MergeThingLiveCommand.java | 40 ++ .../MergeThingLiveCommandAnswerBuilder.java | 86 +++++ ...ergeThingLiveCommandAnswerBuilderImpl.java | 112 ++++++ .../modify/MergeThingLiveCommandImpl.java | 95 +++++ .../modify/ModifyAttributeLiveCommand.java | 51 +++ ...difyAttributeLiveCommandAnswerBuilder.java | 102 +++++ ...AttributeLiveCommandAnswerBuilderImpl.java | 130 +++++++ .../ModifyAttributeLiveCommandImpl.java | 95 +++++ .../modify/ModifyAttributesLiveCommand.java | 40 ++ ...ifyAttributesLiveCommandAnswerBuilder.java | 99 +++++ ...ttributesLiveCommandAnswerBuilderImpl.java | 126 ++++++ .../ModifyAttributesLiveCommandImpl.java | 88 +++++ .../ModifyFeatureDefinitionLiveCommand.java | 43 +++ ...ureDefinitionLiveCommandAnswerBuilder.java | 102 +++++ ...efinitionLiveCommandAnswerBuilderImpl.java | 134 +++++++ ...odifyFeatureDefinitionLiveCommandImpl.java | 97 +++++ ...fyFeatureDesiredPropertiesLiveCommand.java | 43 +++ ...redPropertiesLiveCommandAnswerBuilder.java | 101 +++++ ...ropertiesLiveCommandAnswerBuilderImpl.java | 133 +++++++ ...atureDesiredPropertiesLiveCommandImpl.java | 100 +++++ ...difyFeatureDesiredPropertyLiveCommand.java | 54 +++ ...siredPropertyLiveCommandAnswerBuilder.java | 101 +++++ ...dPropertyLiveCommandAnswerBuilderImpl.java | 136 +++++++ ...FeatureDesiredPropertyLiveCommandImpl.java | 108 ++++++ .../modify/ModifyFeatureLiveCommand.java | 42 ++ ...ModifyFeatureLiveCommandAnswerBuilder.java | 99 +++++ ...fyFeatureLiveCommandAnswerBuilderImpl.java | 126 ++++++ .../modify/ModifyFeatureLiveCommandImpl.java | 92 +++++ .../ModifyFeaturePropertiesLiveCommand.java | 43 +++ ...urePropertiesLiveCommandAnswerBuilder.java | 101 +++++ ...ropertiesLiveCommandAnswerBuilderImpl.java | 132 +++++++ ...odifyFeaturePropertiesLiveCommandImpl.java | 97 +++++ .../ModifyFeaturePropertyLiveCommand.java | 53 +++ ...aturePropertyLiveCommandAnswerBuilder.java | 101 +++++ ...ePropertyLiveCommandAnswerBuilderImpl.java | 135 +++++++ .../ModifyFeaturePropertyLiveCommandImpl.java | 106 ++++++ .../modify/ModifyFeaturesLiveCommand.java | 42 ++ ...odifyFeaturesLiveCommandAnswerBuilder.java | 100 +++++ ...yFeaturesLiveCommandAnswerBuilderImpl.java | 122 ++++++ .../modify/ModifyFeaturesLiveCommandImpl.java | 87 +++++ .../modify/ModifyLiveCommandFactory.java | 287 ++++++++++++++ .../modify/ModifyThingLiveCommand.java | 40 ++ .../ModifyThingLiveCommandAnswerBuilder.java | 100 +++++ ...difyThingLiveCommandAnswerBuilderImpl.java | 125 ++++++ .../modify/ModifyThingLiveCommandImpl.java | 88 +++++ .../live/commands/modify/package-info.java | 19 + .../AbstractLiveCommandAnswerBuilder.java | 86 +++++ .../query/AbstractQueryLiveCommand.java | 67 ++++ .../query/QueryLiveCommandFactory.java | 151 ++++++++ .../query/RetrieveAttributeLiveCommand.java | 40 ++ ...ieveAttributeLiveCommandAnswerBuilder.java | 60 +++ ...AttributeLiveCommandAnswerBuilderImpl.java | 87 +++++ .../RetrieveAttributeLiveCommandImpl.java | 77 ++++ .../query/RetrieveAttributesLiveCommand.java | 29 ++ ...eveAttributesLiveCommandAnswerBuilder.java | 60 +++ ...ttributesLiveCommandAnswerBuilderImpl.java | 84 ++++ .../RetrieveAttributesLiveCommandImpl.java | 67 ++++ .../RetrieveFeatureDefinitionLiveCommand.java | 30 ++ ...ureDefinitionLiveCommandAnswerBuilder.java | 57 +++ ...efinitionLiveCommandAnswerBuilderImpl.java | 88 +++++ ...rieveFeatureDefinitionLiveCommandImpl.java | 76 ++++ ...veFeatureDesiredPropertiesLiveCommand.java | 31 ++ ...redPropertiesLiveCommandAnswerBuilder.java | 60 +++ ...ropertiesLiveCommandAnswerBuilderImpl.java | 87 +++++ ...atureDesiredPropertiesLiveCommandImpl.java | 79 ++++ ...ieveFeatureDesiredPropertyLiveCommand.java | 42 ++ ...siredPropertyLiveCommandAnswerBuilder.java | 59 +++ ...dPropertyLiveCommandAnswerBuilderImpl.java | 89 +++++ ...FeatureDesiredPropertyLiveCommandImpl.java | 87 +++++ .../query/RetrieveFeatureLiveCommand.java | 30 ++ ...trieveFeatureLiveCommandAnswerBuilder.java | 60 +++ ...veFeatureLiveCommandAnswerBuilderImpl.java | 83 ++++ .../query/RetrieveFeatureLiveCommandImpl.java | 75 ++++ .../RetrieveFeaturePropertiesLiveCommand.java | 30 ++ ...urePropertiesLiveCommandAnswerBuilder.java | 60 +++ ...ropertiesLiveCommandAnswerBuilderImpl.java | 87 +++++ ...rieveFeaturePropertiesLiveCommandImpl.java | 77 ++++ .../RetrieveFeaturePropertyLiveCommand.java | 42 ++ ...aturePropertyLiveCommandAnswerBuilder.java | 59 +++ ...ePropertyLiveCommandAnswerBuilderImpl.java | 88 +++++ ...etrieveFeaturePropertyLiveCommandImpl.java | 84 ++++ .../query/RetrieveFeaturesLiveCommand.java | 28 ++ ...rieveFeaturesLiveCommandAnswerBuilder.java | 59 +++ ...eFeaturesLiveCommandAnswerBuilderImpl.java | 82 ++++ .../RetrieveFeaturesLiveCommandImpl.java | 67 ++++ .../query/RetrieveThingLiveCommand.java | 28 ++ ...RetrieveThingLiveCommandAnswerBuilder.java | 74 ++++ ...ieveThingLiveCommandAnswerBuilderImpl.java | 99 +++++ .../query/RetrieveThingLiveCommandImpl.java | 70 ++++ .../query/RetrieveThingsLiveCommand.java | 52 +++ ...etrieveThingsLiveCommandAnswerBuilder.java | 65 ++++ ...eveThingsLiveCommandAnswerBuilderImpl.java | 91 +++++ .../query/RetrieveThingsLiveCommandImpl.java | 94 +++++ .../live/commands/query/package-info.java | 19 + .../live/internal/LiveFeatureHandleImpl.java | 2 +- .../ditto/client/live/internal/LiveImpl.java | 4 +- .../live/internal/LiveThingHandleImpl.java | 2 +- .../ditto/client/DittoClientLiveTest.java | 6 +- .../client/DittoClientUsageExamples.java | 4 +- .../RunOSGiContainerIntegrationTest.java | 14 +- .../assertions/LiveCommandAnswerAssert.java | 166 ++++++++ .../assertions/LiveCommandAssert.java | 32 ++ .../assertions/LiveCommandAssertions.java | 38 ++ .../assertions/LiveCommandFactoryTest.java | 360 ++++++++++++++++++ .../assertions/ThingErrorResponseAssert.java | 75 ++++ .../base/ImmutableLiveCommandAnswerTest.java | 84 ++++ .../base/LiveCommandAnswerFactoryTest.java | 108 ++++++ ...ThingLiveCommandAnswerBuilderImplTest.java | 106 ++++++ .../CreateThingLiveCommandImplTest.java | 124 ++++++ ...ibuteLiveCommandAnswerBuilderImplTest.java | 126 ++++++ .../DeleteAttributeLiveCommandImplTest.java | 125 ++++++ ...butesLiveCommandAnswerBuilderImplTest.java | 125 ++++++ .../DeleteAttributesLiveCommandImplTest.java | 120 ++++++ ...itionLiveCommandAnswerBuilderImplTest.java | 118 ++++++ ...eFeatureDefinitionLiveCommandImplTest.java | 111 ++++++ ...rtiesLiveCommandAnswerBuilderImplTest.java | 126 ++++++ ...eDesiredPropertiesLiveCommandImplTest.java | 140 +++++++ ...pertyLiveCommandAnswerBuilderImplTest.java | 128 +++++++ ...ureDesiredPropertyLiveCommandImplTest.java | 128 +++++++ ...atureLiveCommandAnswerBuilderImplTest.java | 126 ++++++ .../DeleteFeatureLiveCommandImplTest.java | 122 ++++++ ...rtiesLiveCommandAnswerBuilderImplTest.java | 126 ++++++ ...eFeaturePropertiesLiveCommandImplTest.java | 122 ++++++ ...pertyLiveCommandAnswerBuilderImplTest.java | 128 +++++++ ...eteFeaturePropertyLiveCommandImplTest.java | 128 +++++++ ...turesLiveCommandAnswerBuilderImplTest.java | 125 ++++++ .../DeleteFeaturesLiveCommandImplTest.java | 120 ++++++ ...ThingLiveCommandAnswerBuilderImplTest.java | 123 ++++++ .../DeleteThingLiveCommandImplTest.java | 120 ++++++ ...ThingLiveCommandAnswerBuilderImplTest.java | 166 ++++++++ .../modify/MergeThingLiveCommandImplTest.java | 130 +++++++ ...ibuteLiveCommandAnswerBuilderImplTest.java | 152 ++++++++ .../ModifyAttributeLiveCommandImplTest.java | 128 +++++++ ...butesLiveCommandAnswerBuilderImplTest.java | 151 ++++++++ .../ModifyAttributesLiveCommandImplTest.java | 126 ++++++ ...itionLiveCommandAnswerBuilderImplTest.java | 142 +++++++ ...yFeatureDefinitionLiveCommandImplTest.java | 117 ++++++ ...rtiesLiveCommandAnswerBuilderImplTest.java | 152 ++++++++ ...eDesiredPropertiesLiveCommandImplTest.java | 127 ++++++ ...pertyLiveCommandAnswerBuilderImplTest.java | 154 ++++++++ ...ureDesiredPropertyLiveCommandImplTest.java | 130 +++++++ ...atureLiveCommandAnswerBuilderImplTest.java | 150 ++++++++ .../ModifyFeatureLiveCommandImplTest.java | 127 ++++++ ...rtiesLiveCommandAnswerBuilderImplTest.java | 152 ++++++++ ...yFeaturePropertiesLiveCommandImplTest.java | 127 ++++++ ...pertyLiveCommandAnswerBuilderImplTest.java | 154 ++++++++ ...ifyFeaturePropertyLiveCommandImplTest.java | 131 +++++++ ...turesLiveCommandAnswerBuilderImplTest.java | 151 ++++++++ .../ModifyFeaturesLiveCommandImplTest.java | 126 ++++++ .../modify/ModifyLiveCommandFactoryTest.java | 31 ++ ...ThingLiveCommandAnswerBuilderImplTest.java | 149 ++++++++ .../ModifyThingLiveCommandImplTest.java | 125 ++++++ .../query/QueryLiveCommandFactoryTest.java | 31 ++ ...ibuteLiveCommandAnswerBuilderImplTest.java | 111 ++++++ .../RetrieveAttributeLiveCommandImplTest.java | 126 ++++++ ...butesLiveCommandAnswerBuilderImplTest.java | 110 ++++++ ...RetrieveAttributesLiveCommandImplTest.java | 126 ++++++ ...itionLiveCommandAnswerBuilderImplTest.java | 106 ++++++ ...eFeatureDefinitionLiveCommandImplTest.java | 111 ++++++ ...rtiesLiveCommandAnswerBuilderImplTest.java | 111 ++++++ ...eDesiredPropertiesLiveCommandImplTest.java | 123 ++++++ ...pertyLiveCommandAnswerBuilderImplTest.java | 114 ++++++ ...ureDesiredPropertyLiveCommandImplTest.java | 129 +++++++ ...atureLiveCommandAnswerBuilderImplTest.java | 111 ++++++ .../RetrieveFeatureLiveCommandImplTest.java | 123 ++++++ ...rtiesLiveCommandAnswerBuilderImplTest.java | 111 ++++++ ...eFeaturePropertiesLiveCommandImplTest.java | 123 ++++++ ...pertyLiveCommandAnswerBuilderImplTest.java | 114 ++++++ ...eveFeaturePropertyLiveCommandImplTest.java | 130 +++++++ ...turesLiveCommandAnswerBuilderImplTest.java | 110 ++++++ .../RetrieveFeaturesLiveCommandImplTest.java | 122 ++++++ ...ThingLiveCommandAnswerBuilderImplTest.java | 110 ++++++ .../RetrieveThingLiveCommandImplTest.java | 122 ++++++ ...hingsLiveCommandAnswerBuilderImplTest.java | 107 ++++++ .../RetrieveThingsLiveCommandImplTest.java | 144 +++++++ 241 files changed, 21301 insertions(+), 68 deletions(-) create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/LiveCommandFactory.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/base/AbstractLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/base/ImmutableLiveCommandAnswer.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveCommandAnswer.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveCommandAnswerFactory.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveCommandResponseFactory.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveEventFactory.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/base/package-info.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/AbstractLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/AbstractModifyLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyLiveCommandFactory.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/modify/package-info.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/AbstractLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/AbstractQueryLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/QueryLiveCommandFactory.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommand.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommandAnswerBuilder.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommandAnswerBuilderImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommandImpl.java create mode 100644 java/src/main/java/org/eclipse/ditto/client/live/commands/query/package-info.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/assertions/LiveCommandAnswerAssert.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/assertions/LiveCommandAssert.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/assertions/LiveCommandAssertions.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/assertions/LiveCommandFactoryTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/assertions/ThingErrorResponseAssert.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/base/ImmutableLiveCommandAnswerTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/base/LiveCommandAnswerFactoryTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyLiveCommandFactoryTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/query/QueryLiveCommandFactoryTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommandImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommandAnswerBuilderImplTest.java create mode 100644 java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommandImplTest.java diff --git a/java/pom.xml b/java/pom.xml index d82622ac..386e6510 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -847,11 +847,6 @@ ditto-signals-commands-things ${ditto.version} - - org.eclipse.ditto - ditto-signals-commands-live - ${ditto.version} - org.eclipse.ditto ditto-signals-commands-messages diff --git a/java/src/main/java/org/eclipse/ditto/client/live/LiveCommandProcessor.java b/java/src/main/java/org/eclipse/ditto/client/live/LiveCommandProcessor.java index 5fd78fbb..506157db 100755 --- a/java/src/main/java/org/eclipse/ditto/client/live/LiveCommandProcessor.java +++ b/java/src/main/java/org/eclipse/ditto/client/live/LiveCommandProcessor.java @@ -17,10 +17,10 @@ import java.util.stream.Stream; import org.eclipse.ditto.client.live.commands.LiveCommandHandler; +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; import org.eclipse.ditto.signals.base.Signal; -import org.eclipse.ditto.signals.commands.live.base.LiveCommand; -import org.eclipse.ditto.signals.commands.live.base.LiveCommandAnswer; -import org.eclipse.ditto.signals.commands.live.base.LiveCommandAnswerBuilder; import org.slf4j.Logger; /** diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/FeaturePropertiesCommandHandling.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/FeaturePropertiesCommandHandling.java index 94608922..f9d37bb0 100755 --- a/java/src/main/java/org/eclipse/ditto/client/live/commands/FeaturePropertiesCommandHandling.java +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/FeaturePropertiesCommandHandling.java @@ -15,17 +15,17 @@ import java.util.function.Function; import org.eclipse.ditto.client.live.LiveCommandProcessor; -import org.eclipse.ditto.signals.commands.live.base.LiveCommandAnswerBuilder; -import org.eclipse.ditto.signals.commands.live.modify.DeleteFeaturePropertiesLiveCommand; -import org.eclipse.ditto.signals.commands.live.modify.DeleteFeaturePropertyLiveCommand; -import org.eclipse.ditto.signals.commands.live.modify.MergeThingLiveCommand; -import org.eclipse.ditto.signals.commands.live.modify.ModifyFeaturePropertiesLiveCommand; -import org.eclipse.ditto.signals.commands.live.modify.ModifyFeaturePropertyLiveCommand; -import org.eclipse.ditto.signals.commands.live.query.RetrieveFeaturePropertiesLiveCommand; -import org.eclipse.ditto.signals.commands.live.query.RetrieveFeaturePropertyLiveCommand; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.modify.DeleteFeaturePropertiesLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.DeleteFeaturePropertyLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.MergeThingLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.ModifyFeaturePropertiesLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.ModifyFeaturePropertyLiveCommand; +import org.eclipse.ditto.client.live.commands.query.RetrieveFeaturePropertiesLiveCommand; +import org.eclipse.ditto.client.live.commands.query.RetrieveFeaturePropertyLiveCommand; /** - * Provides the necessary functionality for registering {@link org.eclipse.ditto.signals.commands.live.base.LiveCommand + * Provides the necessary functionality for registering {@link org.eclipse.ditto.client.live.commands.base.LiveCommand * LiveCommand} functions to receive commands to manage and retrieve {@link org.eclipse.ditto.model.things.FeatureProperties * FeatureProperties}. * diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/FeaturesCommandHandling.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/FeaturesCommandHandling.java index ecea5465..7f6b9f6b 100755 --- a/java/src/main/java/org/eclipse/ditto/client/live/commands/FeaturesCommandHandling.java +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/FeaturesCommandHandling.java @@ -14,17 +14,17 @@ import java.util.function.Function; -import org.eclipse.ditto.signals.commands.live.base.LiveCommandAnswerBuilder; -import org.eclipse.ditto.signals.commands.live.modify.DeleteFeatureLiveCommand; -import org.eclipse.ditto.signals.commands.live.modify.DeleteFeaturesLiveCommand; -import org.eclipse.ditto.signals.commands.live.modify.MergeThingLiveCommand; -import org.eclipse.ditto.signals.commands.live.modify.ModifyFeatureLiveCommand; -import org.eclipse.ditto.signals.commands.live.modify.ModifyFeaturesLiveCommand; -import org.eclipse.ditto.signals.commands.live.query.RetrieveFeatureLiveCommand; -import org.eclipse.ditto.signals.commands.live.query.RetrieveFeaturesLiveCommand; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.modify.DeleteFeatureLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.DeleteFeaturesLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.MergeThingLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.ModifyFeatureLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.ModifyFeaturesLiveCommand; +import org.eclipse.ditto.client.live.commands.query.RetrieveFeatureLiveCommand; +import org.eclipse.ditto.client.live.commands.query.RetrieveFeaturesLiveCommand; /** - * Provides the necessary functionality for registering {@link org.eclipse.ditto.signals.commands.live.base.LiveCommand + * Provides the necessary functionality for registering {@link org.eclipse.ditto.client.live.commands.base.LiveCommand * LiveCommand} functions to receive commands to manage and retrieve {@link org.eclipse.ditto.model.things.Feature * Feature}s. * diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/LiveCommandAcknowledgeable.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/LiveCommandAcknowledgeable.java index 7ed0f684..f736a44d 100755 --- a/java/src/main/java/org/eclipse/ditto/client/live/commands/LiveCommandAcknowledgeable.java +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/LiveCommandAcknowledgeable.java @@ -17,13 +17,13 @@ import java.util.stream.Collectors; import org.eclipse.ditto.client.ack.Acknowledgeable; -import org.eclipse.ditto.client.changes.AcknowledgementRequestHandle; import org.eclipse.ditto.client.ack.internal.ImmutableAcknowledgementRequestHandle; +import org.eclipse.ditto.client.changes.AcknowledgementRequestHandle; +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; import org.eclipse.ditto.model.base.acks.AcknowledgementLabel; import org.eclipse.ditto.model.base.acks.AcknowledgementRequest; import org.eclipse.ditto.signals.base.Signal; -import org.eclipse.ditto.signals.commands.live.base.LiveCommand; -import org.eclipse.ditto.signals.commands.live.base.LiveCommandAnswerBuilder; /** * Acknowledgeable of a live command. diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/LiveCommandFactory.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/LiveCommandFactory.java new file mode 100644 index 00000000..5dbc8057 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/LiveCommandFactory.java @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands; + +import static org.eclipse.ditto.model.base.common.ConditionChecker.checkNotNull; + +import java.text.MessageFormat; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.client.live.commands.modify.ModifyLiveCommandFactory; +import org.eclipse.ditto.client.live.commands.query.QueryLiveCommandFactory; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.modify.CreateThing; +import org.eclipse.ditto.signals.commands.things.modify.DeleteAttribute; +import org.eclipse.ditto.signals.commands.things.modify.DeleteAttributes; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeature; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureDefinition; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureProperties; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureProperty; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatures; +import org.eclipse.ditto.signals.commands.things.modify.DeleteThing; +import org.eclipse.ditto.signals.commands.things.modify.MergeThing; +import org.eclipse.ditto.signals.commands.things.modify.ModifyAttribute; +import org.eclipse.ditto.signals.commands.things.modify.ModifyAttributes; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeature; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureDefinition; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureProperties; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureProperty; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatures; +import org.eclipse.ditto.signals.commands.things.modify.ModifyThing; +import org.eclipse.ditto.signals.commands.things.query.RetrieveAttribute; +import org.eclipse.ditto.signals.commands.things.query.RetrieveAttributes; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeature; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDefinition; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureProperties; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureProperty; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatures; +import org.eclipse.ditto.signals.commands.things.query.RetrieveThing; +import org.eclipse.ditto.signals.commands.things.query.RetrieveThings; + +/** + * A factory for creating immutable instances of {@link LiveCommand} based on existing Twin Commands. + * + * @since 2.0.0 + */ +@Immutable +public final class LiveCommandFactory { + + private static final int STRATEGIES_NUMBER = 26; + private static final LiveCommandFactory INSTANCE = new LiveCommandFactory(); + + private final Map> mappingStrategies; + + private LiveCommandFactory() { + mappingStrategies = Collections.unmodifiableMap(initMappingStrategies()); + } + + private static Map> initMappingStrategies() { + final Map> result = new HashMap<>(STRATEGIES_NUMBER); + result.put(CreateThing.TYPE, ModifyLiveCommandFactory::createThing); + result.put(DeleteAttribute.TYPE, ModifyLiveCommandFactory::deleteAttribute); + result.put(DeleteAttributes.TYPE, ModifyLiveCommandFactory::deleteAttributes); + result.put(DeleteFeature.TYPE, ModifyLiveCommandFactory::deleteFeature); + result.put(DeleteFeatureDefinition.TYPE, ModifyLiveCommandFactory::deleteFeatureDefinition); + result.put(DeleteFeatureProperties.TYPE, ModifyLiveCommandFactory::deleteFeatureProperties); + result.put(DeleteFeatureProperty.TYPE, ModifyLiveCommandFactory::deleteFeatureProperty); + result.put(DeleteFeatures.TYPE, ModifyLiveCommandFactory::deleteFeatures); + result.put(DeleteThing.TYPE, ModifyLiveCommandFactory::deleteThing); + result.put(ModifyAttribute.TYPE, ModifyLiveCommandFactory::modifyAttribute); + result.put(ModifyAttributes.TYPE, ModifyLiveCommandFactory::modifyAttributes); + result.put(ModifyFeature.TYPE, ModifyLiveCommandFactory::modifyFeature); + result.put(ModifyFeatureDefinition.TYPE, ModifyLiveCommandFactory::modifyFeatureDefinition); + result.put(ModifyFeatureProperties.TYPE, ModifyLiveCommandFactory::modifyFeatureProperties); + result.put(ModifyFeatureProperty.TYPE, ModifyLiveCommandFactory::modifyFeatureProperty); + result.put(ModifyFeatures.TYPE, ModifyLiveCommandFactory::modifyFeatures); + result.put(ModifyThing.TYPE, ModifyLiveCommandFactory::modifyThing); + result.put(MergeThing.TYPE, ModifyLiveCommandFactory::mergeThing); + + result.put(RetrieveAttribute.TYPE, QueryLiveCommandFactory::retrieveAttribute); + result.put(RetrieveAttributes.TYPE, QueryLiveCommandFactory::retrieveAttributes); + result.put(RetrieveFeature.TYPE, QueryLiveCommandFactory::retrieveFeature); + result.put(RetrieveFeatureDefinition.TYPE, QueryLiveCommandFactory::retrieveFeatureDefinition); + result.put(RetrieveFeatureProperties.TYPE, QueryLiveCommandFactory::retrieveFeatureProperties); + result.put(RetrieveFeatureProperty.TYPE, QueryLiveCommandFactory::retrieveFeatureProperty); + result.put(RetrieveFeatures.TYPE, QueryLiveCommandFactory::retrieveFeatures); + result.put(RetrieveThing.TYPE, QueryLiveCommandFactory::retrieveThing); + result.put(RetrieveThings.TYPE, QueryLiveCommandFactory::retrieveThings); + return result; + } + + /** + * Returns an instance of {@code LiveCommandFactory}. + * + * @return the instance. + */ + @Nonnull + public static LiveCommandFactory getInstance() { + return INSTANCE; + } + + /** + * Returns an immutable {@link LiveCommand} which is associated with the specified Command. + * + * @param command the command to get a LiveCommand for. + * @return the LiveCommand. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws IllegalArgumentException if the given command cannot be mapped to a LiveCommand because there is no + * mapping strategy associated with the command's type. + */ + @Nonnull + public LiveCommand getLiveCommand(@Nonnull final Command command) { + checkNotNull(command, "command"); + + final String commandType = command.getType(); + final Function commandToLiveCommand = mappingStrategies.get(commandType); + if (null == commandToLiveCommand) { + final String msgTemplate = "No mapping strategy for command <{0}> available!" + + " The command type <{1}> is unknown!"; + throw new IllegalArgumentException(MessageFormat.format(msgTemplate, command, commandType)); + } + return commandToLiveCommand.apply(command); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/LiveCommandHandler.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/LiveCommandHandler.java index fb27dade..4e891bcb 100755 --- a/java/src/main/java/org/eclipse/ditto/client/live/commands/LiveCommandHandler.java +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/LiveCommandHandler.java @@ -15,9 +15,9 @@ import java.util.function.Consumer; import java.util.function.Function; +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; import org.eclipse.ditto.signals.base.Signal; -import org.eclipse.ditto.signals.commands.live.base.LiveCommand; -import org.eclipse.ditto.signals.commands.live.base.LiveCommandAnswerBuilder; /** * Generic interface for handling a live command. diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/LiveCommandHandlerImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/LiveCommandHandlerImpl.java index 9db6ce42..f21c1e41 100755 --- a/java/src/main/java/org/eclipse/ditto/client/live/commands/LiveCommandHandlerImpl.java +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/LiveCommandHandlerImpl.java @@ -15,8 +15,8 @@ import java.util.function.Consumer; import java.util.function.Function; -import org.eclipse.ditto.signals.commands.live.base.LiveCommand; -import org.eclipse.ditto.signals.commands.live.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; /** * Package-private implementation of {@code LiveCommandHandler}. diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/ThingAttributesCommandHandling.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/ThingAttributesCommandHandling.java index 33e59f81..89cc96cf 100755 --- a/java/src/main/java/org/eclipse/ditto/client/live/commands/ThingAttributesCommandHandling.java +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/ThingAttributesCommandHandling.java @@ -15,17 +15,17 @@ import java.util.function.Function; import org.eclipse.ditto.client.live.LiveCommandProcessor; -import org.eclipse.ditto.signals.commands.live.base.LiveCommandAnswerBuilder; -import org.eclipse.ditto.signals.commands.live.modify.DeleteAttributeLiveCommand; -import org.eclipse.ditto.signals.commands.live.modify.DeleteAttributesLiveCommand; -import org.eclipse.ditto.signals.commands.live.modify.MergeThingLiveCommand; -import org.eclipse.ditto.signals.commands.live.modify.ModifyAttributeLiveCommand; -import org.eclipse.ditto.signals.commands.live.modify.ModifyAttributesLiveCommand; -import org.eclipse.ditto.signals.commands.live.query.RetrieveAttributeLiveCommand; -import org.eclipse.ditto.signals.commands.live.query.RetrieveAttributesLiveCommand; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.modify.DeleteAttributeLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.DeleteAttributesLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.MergeThingLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.ModifyAttributeLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.ModifyAttributesLiveCommand; +import org.eclipse.ditto.client.live.commands.query.RetrieveAttributeLiveCommand; +import org.eclipse.ditto.client.live.commands.query.RetrieveAttributesLiveCommand; /** - * Provides the necessary functionality for registering {@link org.eclipse.ditto.signals.commands.live.base.LiveCommand + * Provides the necessary functionality for registering {@link org.eclipse.ditto.client.live.commands.base.LiveCommand * LiveCommand} function to receive commands to manage and retrieve {@link java.util.jar.Attributes Attributes}. * * @since 1.0.0 diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/ThingCommandHandling.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/ThingCommandHandling.java index ec2d639a..42d0a648 100755 --- a/java/src/main/java/org/eclipse/ditto/client/live/commands/ThingCommandHandling.java +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/ThingCommandHandling.java @@ -15,15 +15,15 @@ import java.util.function.Function; import org.eclipse.ditto.client.live.LiveCommandProcessor; -import org.eclipse.ditto.signals.commands.live.base.LiveCommandAnswerBuilder; -import org.eclipse.ditto.signals.commands.live.modify.CreateThingLiveCommand; -import org.eclipse.ditto.signals.commands.live.modify.DeleteThingLiveCommand; -import org.eclipse.ditto.signals.commands.live.modify.MergeThingLiveCommand; -import org.eclipse.ditto.signals.commands.live.modify.ModifyThingLiveCommand; -import org.eclipse.ditto.signals.commands.live.query.RetrieveThingLiveCommand; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.modify.CreateThingLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.DeleteThingLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.MergeThingLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.ModifyThingLiveCommand; +import org.eclipse.ditto.client.live.commands.query.RetrieveThingLiveCommand; /** - * Provides the necessary functionality for registering {@link org.eclipse.ditto.signals.commands.live.base.LiveCommand + * Provides the necessary functionality for registering {@link org.eclipse.ditto.client.live.commands.base.LiveCommand * LiveCommand} functions to receive commands to manage and retrieve a particular {@link * org.eclipse.ditto.model.things.Thing Thing}. * diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/ThingsCommandHandling.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/ThingsCommandHandling.java index 75771bf0..77daa2bb 100755 --- a/java/src/main/java/org/eclipse/ditto/client/live/commands/ThingsCommandHandling.java +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/ThingsCommandHandling.java @@ -14,11 +14,11 @@ import java.util.function.Function; -import org.eclipse.ditto.signals.commands.live.base.LiveCommandAnswerBuilder; -import org.eclipse.ditto.signals.commands.live.query.RetrieveThingsLiveCommand; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.query.RetrieveThingsLiveCommand; /** - * Provides the necessary functionality for registering {@link org.eclipse.ditto.signals.commands.live.base.LiveCommand + * Provides the necessary functionality for registering {@link org.eclipse.ditto.client.live.commands.base.LiveCommand * LiveCommand} functions to receive commands to generally manage and retrieve {@link * org.eclipse.ditto.model.things.Thing Thing}s. * diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/base/AbstractLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/base/AbstractLiveCommand.java new file mode 100644 index 00000000..e7b583f1 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/base/AbstractLiveCommand.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.base; + +import static org.eclipse.ditto.model.base.common.ConditionChecker.checkNotNull; + +import java.util.Objects; +import java.util.function.Predicate; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.json.JsonField; +import org.eclipse.ditto.json.JsonObject; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.base.json.JsonSchemaVersion; +import org.eclipse.ditto.signals.commands.base.Command; + +/** + * An abstract base implementation for all {@link LiveCommand}s. + * + * @param the type of the LiveCommand; currently needed as return type for {@link #setDittoHeaders(DittoHeaders)}. + * @param the type of the LiveCommandAnswerBuilder to be returned for {@link #answer()}. + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +public abstract class AbstractLiveCommand, B extends LiveCommandAnswerBuilder> + implements LiveCommand { + + private final Command command; + + /** + * Constructs a new {@code AbstractLiveCommand} object. + * + * @param command the command to be wrapped by the returned object. + * @throws NullPointerException if {@code command} is {@code null}. + */ + protected AbstractLiveCommand(final Command command) { + this.command = checkNotNull(command, "command"); + } + + @Override + public JsonPointer getResourcePath() { + return command.getResourcePath(); + } + + @Nonnull + @Override + public String getManifest() { + return command.getManifest(); + } + + @Override + public DittoHeaders getDittoHeaders() { + return command.getDittoHeaders(); + } + + @Override + public String getType() { + return command.getType(); + } + + @Override + public JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate predicate) { + return command.toJson(schemaVersion, predicate); + } + + @Override + public final boolean equals(final Object o) { + if (this == o) { + return true; + } + if (!(o instanceof AbstractLiveCommand)) { + return false; + } + final AbstractLiveCommand that = (AbstractLiveCommand) o; + return Objects.equals(getClass(), that.getClass()) && Objects.equals(command, that.command); + } + + @Override + public final int hashCode() { + return Objects.hash(command); + } + + @Nonnull + @Override + public String toString() { + return "command=" + command; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/base/ImmutableLiveCommandAnswer.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/base/ImmutableLiveCommandAnswer.java new file mode 100644 index 00000000..91ae4638 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/base/ImmutableLiveCommandAnswer.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.base; + +import java.util.Objects; +import java.util.Optional; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.events.base.Event; + +/** + * Immutable implementation of {@link LiveCommandAnswer}. + */ +@Immutable +final class ImmutableLiveCommandAnswer implements LiveCommandAnswer { + + private final CommandResponse commandResponse; + private final Event event; + + private ImmutableLiveCommandAnswer(final CommandResponse theCommandResponse, final Event theEvent) { + commandResponse = theCommandResponse; + event = theEvent; + } + + /** + * Returns a new instance of {@code ImmutableCommandAnswer}. + * + * @return the instance. + */ + public static ImmutableLiveCommandAnswer newInstance(@Nullable final CommandResponse commandResponse, + @Nullable final Event event) { + return new ImmutableLiveCommandAnswer(commandResponse, event); + } + + @Nonnull + @Override + public Optional getResponse() { + return Optional.ofNullable(commandResponse); + } + + @Nonnull + @Override + public Optional getEvent() { + return Optional.ofNullable(event); + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final ImmutableLiveCommandAnswer that = (ImmutableLiveCommandAnswer) o; + return Objects.equals(commandResponse, that.commandResponse) + && Objects.equals(event, that.event); + } + + @Override + public int hashCode() { + return Objects.hash(commandResponse, event); + } + + @Override + public String toString() { + return getClass().getSimpleName() + " [" + "commandResponse=" + commandResponse + ", event=" + event + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveCommand.java new file mode 100644 index 00000000..0594effe --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveCommand.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.base; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.WithThingId; +import org.eclipse.ditto.signals.commands.base.Command; + +/** + * A Handle for live {@link Command}s giving access to the command. Also provides a {@code Command} specific + * {@link LiveCommandAnswerBuilder} used for building {@code CommandResponse}s to return and {@code Event}s + * to emit for incoming commands. + * + * @param the type of the LiveCommand; currently needed as return type for {@link #setDittoHeaders(DittoHeaders)}. + * @param the type of the LiveCommandAnswerBuilder to be returned for {@link #answer()}. + * + * @since 2.0.0 + */ +public interface LiveCommand, B extends LiveCommandAnswerBuilder> extends Command, WithThingId { + + /** + * Returns a builder for an answer to this command which could include a {@code CommandResponse}s or an {@code + * Event}. The answer is emitted automatically for the received {@code Command}. + * + * @return the LiveCommandAnswerBuilder for building responses and events. + */ + @Nonnull + B answer(); + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveCommandAnswer.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveCommandAnswer.java new file mode 100644 index 00000000..031b2877 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveCommandAnswer.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.base; + +import java.util.Optional; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.events.base.Event; + +/** + * This interface defines an answer for a received {@link LiveCommand}. + * + * @since 2.0.0 + */ +public interface LiveCommandAnswer { + + /** + * Returns the {@code CommandResponse} of this answer. + * + * @return the CommandResponse or an empty Optional. + */ + @Nonnull + Optional getResponse(); + + /** + * Returns the {@code Event} of this answer. + * + * @return the Event or an empty Optional. + */ + @Nonnull + Optional getEvent(); + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveCommandAnswerBuilder.java new file mode 100644 index 00000000..b128918f --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveCommandAnswerBuilder.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.base; + +import java.util.function.Function; + +import javax.annotation.ParametersAreNonnullByDefault; + +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.events.base.Event; + +/** + * A mutable builder with a fluent API for an immutable {@link LiveCommandAnswer}. + * This is the counterpart of {@link LiveCommand} interface. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +public interface LiveCommandAnswerBuilder { + + /** + * Interface for LiveCommandHandleResults which are {@code QueryCommands} (retrieving data). + * + * @param the type of the LiveCommandResponseFactory to use for building {@link CommandResponse}s. + */ + @ParametersAreNonnullByDefault + interface QueryCommandResponseStep extends LiveCommandAnswerBuilder { + + /** + * Configures the function for creating a {@link CommandResponse} for the incoming {@code Command}. + * + * @param createResponseFunction the function used to build the {@code CommandResponse} to be returned. + * @return the next step for building the answer. + * @throws NullPointerException if {@code createResponseFunction} is {@code null}. + */ + BuildStep withResponse(Function> createResponseFunction); + + /** + * Configures that no {@link CommandResponse} is sent for the incoming {@code Command}. + *

Be careful using this as the sender of the {@code Command} might wait for a {@code CommandResponse}.

+ * + * @return the next step for building the answer. + */ + BuildStep withoutResponse(); + } + + /** + * Interface for LiveCommandHandleResults which are {@code ModifyCommands} (changing data). + * + * @param the type of the LiveCommandResponseFactory to use for building {@link CommandResponse}s. + * @param the type of the LiveEventFactory to use for building {@link Event}s. + */ + @ParametersAreNonnullByDefault + interface ModifyCommandResponseStep extends + LiveCommandAnswerBuilder { + + /** + * Configures the function for creating a {@link CommandResponse} for the incoming {@code Command}. + * + * @param createResponseFunction the function used to build the {@code CommandResponse} to be returned. + * @return an EventStep LiveCommandAnswerBuilder in order to configure the {@code Event} to emit. + * @throws NullPointerException if {@code createResponseFunction} is {@code null}. + */ + EventStep withResponse(Function> createResponseFunction); + + /** + * Configures that no {@link CommandResponse} is sent for the incoming {@code Command}. + *

Be careful using this as the sender of the {@code Command} might wait for a {@code CommandResponse}.

+ * + * @return an EventStep LiveCommandAnswerBuilder in order to configure the {@code Event} to emit + */ + EventStep withoutResponse(); + } + + /** + * Interface for LiveCommandHandleResults which emit {@code Event}s. + * + * @param the type of the LiveEventFactory to use for building {@link Event}s + */ + @ParametersAreNonnullByDefault + interface EventStep extends LiveCommandAnswerBuilder { + + /** + * Configures the {@link Event} confirming the modifications requested in the incoming {@code Command}. + * + * @param createEventFunction the createEventFunction used to build the {@code Event} to be emitted + * @return the next step for building the answer. + * @throws NullPointerException if {@code createEventFunction} is {@code null}. + */ + BuildStep withEvent(Function> createEventFunction); + + /** + * Configures that no {@link Event} is sent for the incoming {@code Command}. + *

Be careful using this as the sender of the {@code Command} or another party might expect or + * wait for {@code Event}s.

+ * + * @return the next step for building the answer. + */ + BuildStep withoutEvent(); + } + + /** + * The final step for building the LiveCommandAnswer. + */ + @SuppressWarnings("squid:S1609") + interface BuildStep { + + /** + * Builds the {@link LiveCommandAnswer} to a {@code LiveCommand}. + * + * @return the new LiveCommandAnswer object. + */ + LiveCommandAnswer build(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveCommandAnswerFactory.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveCommandAnswerFactory.java new file mode 100644 index 00000000..23364a4c --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveCommandAnswerFactory.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.base; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.events.base.Event; + +/** + * A factory for creating immutable instances of {@link LiveCommandAnswer}. + * + * @since 2.0.0 + */ +@Immutable +public final class LiveCommandAnswerFactory { + + private LiveCommandAnswerFactory() { + throw new AssertionError(); + } + + /** + * Returns a new immutable instance of {@link LiveCommandAnswer} with the given CommandResponse. + * + * @param commandResponse the command response of the returned instance. + * @return the instance. + */ + @Nonnull + public static LiveCommandAnswer newLiveCommandAnswer(@Nullable final CommandResponse commandResponse) { + return ImmutableLiveCommandAnswer.newInstance(commandResponse, null); + } + + /** + * Returns a new immutable instance of {@link LiveCommandAnswer} with the given CommandResponse. + * + * @param event the event of the returned instance. + * @return the instance. + */ + @Nonnull + public static LiveCommandAnswer newLiveCommandAnswer(@Nullable final Event event) { + return ImmutableLiveCommandAnswer.newInstance(null, event); + } + + /** + * Returns a new immutable instance of {@link LiveCommandAnswer} with the given CommandResponse and Event. + * + * @param commandResponse the command response of the returned instance. + * @param event the event of the returned instance. + * @return the instance. + */ + @Nonnull + public static LiveCommandAnswer newLiveCommandAnswer(@Nullable final CommandResponse commandResponse, + @Nullable final Event event) { + return ImmutableLiveCommandAnswer.newInstance(commandResponse, event); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveCommandResponseFactory.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveCommandResponseFactory.java new file mode 100644 index 00000000..396cb89f --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveCommandResponseFactory.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.base; + +import org.eclipse.ditto.model.base.exceptions.DittoRuntimeException; +import org.eclipse.ditto.model.things.ThingId; +import org.eclipse.ditto.signals.commands.base.ErrorResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; + +/** + * Base for factories of {@link org.eclipse.ditto.signals.commands.base.CommandResponse}s which create + * {@code CommandResponse}s for incoming {@link org.eclipse.ditto.signals.commands.base.Command}s. + * + * @since 2.0.0 + */ +@SuppressWarnings("squid:S1609") +public interface LiveCommandResponseFactory { + + /** + * Creates a generic {@link ErrorResponse} which includes the passed {@link DittoRuntimeException}. + *

+ * Use this method only if you are absolutely sure that the counterpart which issued the {@link + * org.eclipse.ditto.signals.commands.base.Command} expects such a type of {@code ErrorResponse} + * for the issued {@code Command}. + * + * @param dittoRuntimeException the DittoRuntimeException to include in the ErrorResponse. + * @return the built ErrorResponse. + * @throws NullPointerException if {@code DittoRuntimeException} is {@code null}. + */ + default ThingErrorResponse errorResponse(final DittoRuntimeException dittoRuntimeException) { + return ThingErrorResponse.of(dittoRuntimeException); + } + + /** + * Creates a generic {@link ErrorResponse} which includes the passed {@link DittoRuntimeException}. + *

+ * Use this method only if you are absolutely sure that the counterpart which issued the {@link + * org.eclipse.ditto.signals.commands.base.Command} expects such a type of {@code ErrorResponse} + * for the issued {@code Command}. + * + * @param thingId the Thing ID of the related Thing. + * @param dittoRuntimeException the DittoRuntimeException to include in the ErrorResponse. + * @return the built ErrorResponse. + * @throws NullPointerException if {@code dittoRuntimeException} is {@code null}. + * @deprecated Thing ID is now typed. + * Use {@link #errorResponse(org.eclipse.ditto.model.things.ThingId, org.eclipse.ditto.model.base.exceptions.DittoRuntimeException)} + * instead. + */ + @Deprecated + default ThingErrorResponse errorResponse(final String thingId, final DittoRuntimeException dittoRuntimeException) { + return errorResponse(ThingId.of(thingId), dittoRuntimeException); + } + + /** + * Creates a generic {@link ErrorResponse} which includes the passed {@link DittoRuntimeException}. + *

+ * Use this method only if you are absolutely sure that the counterpart which issued the {@link + * org.eclipse.ditto.signals.commands.base.Command} expects such a type of {@code ErrorResponse} + * for the issued {@code Command}. + * + * @param thingId the Thing ID of the related Thing. + * @param dittoRuntimeException the DittoRuntimeException to include in the ErrorResponse. + * @return the built ErrorResponse. + * @throws NullPointerException if {@code dittoRuntimeException} is {@code null}. + */ + default ThingErrorResponse errorResponse(final ThingId thingId, final DittoRuntimeException dittoRuntimeException) { + return ThingErrorResponse.of(thingId, dittoRuntimeException); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveEventFactory.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveEventFactory.java new file mode 100644 index 00000000..48f2243c --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/base/LiveEventFactory.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.base; + +/** + * Base for factories of {@link org.eclipse.ditto.signals.events.base.Event}s which create {@code Event}s for incoming + * {@link org.eclipse.ditto.signals.commands.base.Command}s. + * + * @since 2.0.0 + */ +public interface LiveEventFactory { + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/base/package-info.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/base/package-info.java new file mode 100644 index 00000000..efca0ae6 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/base/package-info.java @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ + +/** + * This package provides commonly used interfaces and classes around {@link org.eclipse.ditto.client.live.commands.base.LiveCommand + * LiveCommand}. + */ +package org.eclipse.ditto.client.live.commands.base; diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/AbstractLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/AbstractLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..53f24f70 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/AbstractLiveCommandAnswerBuilder.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.eclipse.ditto.model.base.common.ConditionChecker.checkNotNull; + +import java.util.function.Function; + +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder.BuildStep; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder.EventStep; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder.ModifyCommandResponseStep; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerFactory; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.events.base.Event; + +/** + * Abstract base implementation for all {@link LiveCommandAnswerBuilder}s for modification commands. + * + * @param the type of the LiveCommand + * @param the type of the LiveCommandResponseFactory to be used as function parameter for the + * {@link #createResponseFunction} + * @param the type of the LiveEventFactory to bse used as function parameter for the {@link #createEventFunction} + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +abstract class AbstractLiveCommandAnswerBuilder + implements ModifyCommandResponseStep, EventStep, BuildStep { + + // This variable being protected is no problem as it is a) immutable and b) not visible beyond "modify" package. + protected final C command; + private Function> createResponseFunction; + private Function> createEventFunction; + + /** + * Constructs a new {@code AbstractLiveCommandAnswerBuilder} object. + * + * @param command the command to build an answer for. + * @throws NullPointerException if {@code command} is {@code null}. + */ + protected AbstractLiveCommandAnswerBuilder(final C command) { + this.command = checkNotNull(command, "command"); + createResponseFunction = r -> null; + createEventFunction = e -> null; + } + + @Override + public EventStep withResponse(final Function> createResponseFunction) { + this.createResponseFunction = + checkNotNull(createResponseFunction, "function for creating a command response"); + return this; + } + + @Override + public EventStep withoutResponse() { + return this; + } + + @Override + public BuildStep withEvent(final Function> createEventFunction) { + this.createEventFunction = checkNotNull(createEventFunction, "function for creating an event"); + return this; + } + + @Override + public BuildStep withoutEvent() { + return this; + } + + @Override + public LiveCommandAnswer build() { + final CommandResponse commandResponse = doCreateResponse(createResponseFunction); + final Event event = doCreateEvent(createEventFunction); + + return LiveCommandAnswerFactory.newLiveCommandAnswer(commandResponse, event); + } + + /** + * Creates a CommandResponse using the given Function. + * + * @param createResponseFunction the function for creating a CommandResponse with the help + * of the implied LiveCommandResponseFactory. + * @return the CommandResponse. + */ + @Nullable + protected abstract CommandResponse doCreateResponse(Function> createResponseFunction); + + /** + * Creates an Event using the given Function. + * + * @param createEventFunction the function for creating an Event with the help of the implied LiveEventFactory. + * @return the Event. + */ + @Nullable + protected abstract Event doCreateEvent(Function> createEventFunction); + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/AbstractModifyLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/AbstractModifyLiveCommand.java new file mode 100644 index 00000000..645fda2e --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/AbstractModifyLiveCommand.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import java.util.Optional; + +import org.eclipse.ditto.client.live.commands.base.AbstractLiveCommand; +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.model.base.json.JsonSchemaVersion; +import org.eclipse.ditto.model.things.ThingId; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommand; + +/** + * Abstract base implementation for LiveCommands wrapping {@link ThingModifyCommand}s. + * + * @param the type of the LiveCommand; currently needed as return type for + * {@link #setDittoHeaders(org.eclipse.ditto.model.base.headers.DittoHeaders)}. + * @param the type of the LiveCommandAnswerBuilder to be returned for {@link #answer()}. + * + * @since 2.0.0 + */ +abstract class AbstractModifyLiveCommand & ThingModifyCommand, B extends LiveCommandAnswerBuilder> + extends AbstractLiveCommand implements ThingModifyCommand { + + private final ThingModifyCommand thingModifyCommand; + + /** + * Constructs a new {@code AbstractModifyLiveCommand} object. + * + * @param thingModifyCommand the command to be wrapped by the returned object. + * @throws NullPointerException if {@code command} is {@code null}. + */ + protected AbstractModifyLiveCommand(final ThingModifyCommand thingModifyCommand) { + super(thingModifyCommand); + this.thingModifyCommand = thingModifyCommand; + } + + @Override + public ThingId getThingEntityId() { + return thingModifyCommand.getThingEntityId(); + } + + @Override + public Optional getEntity(final JsonSchemaVersion schemaVersion) { + return thingModifyCommand.getEntity(schemaVersion); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommand.java new file mode 100644 index 00000000..f9e44a9a --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommand.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.model.things.Thing; +import org.eclipse.ditto.signals.commands.things.modify.CreateThing; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommand; + +/** + * {@link CreateThing} live command giving access to the command and all of its special accessors. Also the entry point + * for creating a {@link CreateThingLiveCommandAnswerBuilder} capable of answering incoming commands. + * + * @since 2.0.0 + */ +public interface CreateThingLiveCommand + extends LiveCommand, + ThingModifyCommand { + + /** + * Returns the {@code Thing} to create. + * + * @return the Thing to create + * @see CreateThing#getThing() + */ + Thing getThing(); + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..5f3c16d0 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommandAnswerBuilder.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.modify.CreateThing; +import org.eclipse.ditto.signals.commands.things.modify.CreateThingResponse; +import org.eclipse.ditto.signals.events.things.ThingCreated; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s and {@code Event}s for {@link CreateThing} + * commands. + * + * @since 2.0.0 + */ +public interface CreateThingLiveCommandAnswerBuilder + extends LiveCommandAnswerBuilder.ModifyCommandResponseStep { + + /** + * Factory for {@code CommandResponse}s to {@link CreateThing} command. + */ + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Creates a {@link CreateThingResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + CreateThingResponse created(); + + /** + * Creates a {@link ThingErrorResponse} indicating a conflict. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.ThingConflictException ThingConflictException + */ + @Nonnull + ThingErrorResponse thingConflictError(); + } + + /** + * Factory for events triggered by {@link CreateThing} commands. + */ + @SuppressWarnings("squid:S1609") + interface EventFactory extends LiveEventFactory { + + /** + * Creates a {@link ThingCreated} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + ThingCreated created(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..939a28a6 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import java.time.Instant; +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.exceptions.DittoRuntimeException; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.ThingConflictException; +import org.eclipse.ditto.signals.commands.things.modify.CreateThingResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.ThingCreated; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer LiveCommandAnswer} for a + * {@link CreateThingLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class CreateThingLiveCommandAnswerBuilderImpl + extends + AbstractLiveCommandAnswerBuilder + implements CreateThingLiveCommandAnswerBuilder { + + private CreateThingLiveCommandAnswerBuilderImpl(final CreateThingLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code CreateThingLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static CreateThingLiveCommandAnswerBuilderImpl newInstance(final CreateThingLiveCommand command) { + return new CreateThingLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @Override + protected Event doCreateEvent(final Function> createEventFunction) { + return createEventFunction.apply(new EventFactoryImpl()); + } + + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public CreateThingResponse created() { + return CreateThingResponse.of(command.getThing(), command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse thingConflictError() { + final DittoRuntimeException exception = ThingConflictException.newBuilder(command.getThingEntityId()) + .dittoHeaders(command.getDittoHeaders()) + .build(); + return errorResponse(command.getThingEntityId(), exception); + } + } + + @Immutable + private final class EventFactoryImpl implements EventFactory { + + @Nonnull + @Override + public ThingCreated created() { + return ThingCreated.of(command.getThing(), -1, Instant.now(), command.getDittoHeaders(), null); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommandImpl.java new file mode 100644 index 00000000..a8ef700b --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommandImpl.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.Thing; +import org.eclipse.ditto.model.things.ThingId; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.modify.CreateThing; + +/** + * An immutable implementation of {@link CreateThingLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class CreateThingLiveCommandImpl + extends AbstractModifyLiveCommand + implements CreateThingLiveCommand { + + private final Thing thing; + + private CreateThingLiveCommandImpl(final CreateThing command) { + super(command); + thing = command.getThing(); + } + + /** + * Returns a new instance of {@code CreateThingLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link CreateThing}. + */ + @Nonnull + public static CreateThingLiveCommand of(final Command command) { + return new CreateThingLiveCommandImpl((CreateThing) command); + } + + @Override + public ThingId getThingEntityId() { + return thing.getEntityId().orElse(null); + } + + @Override + public Thing getThing() { + return thing; + } + + @Override + public Category getCategory() { + return Category.MODIFY; + } + + @Override + public CreateThingLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return of(CreateThing.of(thing, null, dittoHeaders)); + } + + @Override + public boolean changesAuthorization() { + return false; + } + + @Nonnull + @Override + public CreateThingLiveCommandAnswerBuilder answer() { + return CreateThingLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommand.java new file mode 100644 index 00000000..6ac96e4b --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommand.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.model.things.WithThingId; +import org.eclipse.ditto.signals.commands.things.modify.DeleteAttribute; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommand; + +/** + * {@link DeleteAttribute} live command giving access to the command and all of its special accessors. Also the entry + * point for creating a {@link DeleteAttributeLiveCommandAnswerBuilder} capable of answering incoming commands. + * + * @since 2.0.0 + */ +public interface DeleteAttributeLiveCommand + extends WithThingId, LiveCommand, + ThingModifyCommand { + + /** + * Returns the JSON pointer of the attribute to delete. + * + * @return the JSON pointer of the attribute to delete + * @see DeleteAttribute#getAttributePointer() + */ + JsonPointer getAttributePointer(); + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..7f06186f --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommandAnswerBuilder.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.modify.DeleteAttribute; +import org.eclipse.ditto.signals.commands.things.modify.DeleteAttributeResponse; +import org.eclipse.ditto.signals.events.things.AttributeDeleted; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s and {@code Event}s for {@link DeleteAttribute} + * commands. + * + * @since 2.0.0 + */ +public interface DeleteAttributeLiveCommandAnswerBuilder + extends + LiveCommandAnswerBuilder.ModifyCommandResponseStep { + + /** + * Factory for {@code CommandResponse}s to {@code DeleteAttribute} command. + */ + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Builds a {@link DeleteAttributeResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + DeleteAttributeResponse deleted(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the attribute was not accessible. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.AttributeNotAccessibleException + * AttributeNotAccessibleException + */ + @Nonnull + ThingErrorResponse attributeNotAccessibleError(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the attribute was not modifiable. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.AttributeNotModifiableException + * AttributeNotModifiableException + */ + @Nonnull + ThingErrorResponse attributeNotModifiableError(); + } + + /** + * Factory for events triggered by {@link DeleteAttribute} command. + */ + @SuppressWarnings("squid:S1609") + interface EventFactory extends LiveEventFactory { + + /** + * Creates a {@link AttributeDeleted} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + AttributeDeleted deleted(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..259093eb --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import java.time.Instant; +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.exceptions.DittoRuntimeException; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.AttributeNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.AttributeNotModifiableException; +import org.eclipse.ditto.signals.commands.things.modify.DeleteAttributeResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.AttributeDeleted; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link DeleteAttributeLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class DeleteAttributeLiveCommandAnswerBuilderImpl + extends + AbstractLiveCommandAnswerBuilder + implements DeleteAttributeLiveCommandAnswerBuilder { + + private DeleteAttributeLiveCommandAnswerBuilderImpl(final DeleteAttributeLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code DeleteAttributeLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static DeleteAttributeLiveCommandAnswerBuilderImpl newInstance(final DeleteAttributeLiveCommand command) { + return new DeleteAttributeLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @Override + protected Event doCreateEvent(final Function> createEventFunction) { + return createEventFunction.apply(new EventFactoryImpl()); + } + + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public DeleteAttributeResponse deleted() { + return DeleteAttributeResponse.of(command.getThingEntityId(), command.getAttributePointer(), + command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse attributeNotAccessibleError() { + final DittoRuntimeException exception = + AttributeNotAccessibleException.newBuilder(command.getThingEntityId(), + command.getAttributePointer()) + .dittoHeaders(command.getDittoHeaders()) + .build(); + return errorResponse(command.getThingEntityId(), exception); + } + + @Nonnull + @Override + public ThingErrorResponse attributeNotModifiableError() { + final DittoRuntimeException exception = + AttributeNotModifiableException.newBuilder(command.getThingEntityId(), + command.getAttributePointer()) + .dittoHeaders(command.getDittoHeaders()) + .build(); + return errorResponse(command.getThingEntityId(), exception); + } + } + + @Immutable + private final class EventFactoryImpl implements EventFactory { + + @Nonnull + @Override + public AttributeDeleted deleted() { + return AttributeDeleted.of(command.getThingEntityId(), command.getAttributePointer(), -1, Instant.now(), + command.getDittoHeaders(), null); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommandImpl.java new file mode 100644 index 00000000..670a7551 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommandImpl.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.modify.DeleteAttribute; + +/** + * An immutable implementation of {@link DeleteAttributeLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class DeleteAttributeLiveCommandImpl + extends AbstractModifyLiveCommand + implements DeleteAttributeLiveCommand { + + private final JsonPointer attributePointer; + + private DeleteAttributeLiveCommandImpl(final DeleteAttribute command) { + super(command); + attributePointer = command.getAttributePointer(); + } + + /** + * Returns a new instance of {@code DeleteAttributeLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link DeleteAttribute}. + */ + @Nonnull + public static DeleteAttributeLiveCommandImpl of(final Command command) { + return new DeleteAttributeLiveCommandImpl((DeleteAttribute) command); + } + + @Override + public JsonPointer getAttributePointer() { + return attributePointer; + } + + @Override + public Category getCategory() { + return Category.DELETE; + } + + @Override + public DeleteAttributeLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return new DeleteAttributeLiveCommandImpl( + DeleteAttribute.of(getThingEntityId(), attributePointer, dittoHeaders)); + } + + @Override + public boolean changesAuthorization() { + return false; + } + + @Nonnull + @Override + public DeleteAttributeLiveCommandAnswerBuilder answer() { + return DeleteAttributeLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommand.java new file mode 100644 index 00000000..d9d52324 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommand.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.signals.commands.things.modify.DeleteAttributes; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommand; + +/** + * {@link DeleteAttributes} live command giving access to the command and all of its special accessors. Also the entry + * point for creating a {@link DeleteAttributesLiveCommandAnswerBuilder} capable of answering incoming commands. + * + * @since 2.0.0 + */ +public interface DeleteAttributesLiveCommand + extends LiveCommand, + ThingModifyCommand { +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..0da109da --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommandAnswerBuilder.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.modify.DeleteAttributes; +import org.eclipse.ditto.signals.commands.things.modify.DeleteAttributesResponse; +import org.eclipse.ditto.signals.events.things.AttributesDeleted; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s and {@code Event}s for {@link DeleteAttributes} + * commands. + * + * @since 2.0.0 + */ +public interface DeleteAttributesLiveCommandAnswerBuilder + extends + LiveCommandAnswerBuilder.ModifyCommandResponseStep { + + /** + * Factory for {@code CommandResponse}s to {@link DeleteAttributes} command. + */ + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Builds a {@link DeleteAttributesResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + DeleteAttributesResponse deleted(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the attributes were not accessible. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.AttributesNotAccessibleException + * AttributesNotAccessibleException + */ + @Nonnull + ThingErrorResponse attributesNotAccessibleError(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the attributes were not modifiable. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.AttributesNotModifiableException + * AttributesNotModifiableException + */ + @Nonnull + ThingErrorResponse attributesNotModifiableError(); + } + + /** + * Factory for events triggered by {@link DeleteAttributes} command. + */ + @SuppressWarnings("squid:S1609") + interface EventFactory extends LiveEventFactory { + + /** + * Creates an {@link AttributesDeleted} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + AttributesDeleted deleted(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..411522af --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import java.time.Instant; +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.exceptions.DittoRuntimeException; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.AttributesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.AttributesNotModifiableException; +import org.eclipse.ditto.signals.commands.things.modify.DeleteAttributesResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.AttributesDeleted; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link DeleteAttributesLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class DeleteAttributesLiveCommandAnswerBuilderImpl + extends + AbstractLiveCommandAnswerBuilder + implements DeleteAttributesLiveCommandAnswerBuilder { + + private DeleteAttributesLiveCommandAnswerBuilderImpl(final DeleteAttributesLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code DeleteAttributesLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static DeleteAttributesLiveCommandAnswerBuilderImpl newInstance(final DeleteAttributesLiveCommand command) { + return new DeleteAttributesLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @Override + protected Event doCreateEvent(final Function> createEventFunction) { + return createEventFunction.apply(new EventFactoryImpl()); + } + + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public DeleteAttributesResponse deleted() { + return DeleteAttributesResponse.of(command.getThingEntityId(), command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse attributesNotAccessibleError() { + final DittoRuntimeException exception = + AttributesNotAccessibleException.newBuilder(command.getThingEntityId()) + .dittoHeaders(command.getDittoHeaders()) + .build(); + return errorResponse(command.getThingEntityId(), exception); + } + + @Nonnull + @Override + public ThingErrorResponse attributesNotModifiableError() { + final DittoRuntimeException exception = + AttributesNotModifiableException.newBuilder(command.getThingEntityId()) + .dittoHeaders(command.getDittoHeaders()) + .build(); + return errorResponse(command.getThingEntityId(), exception); + } + } + + @Immutable + private final class EventFactoryImpl implements EventFactory { + + @Nonnull + @Override + public AttributesDeleted deleted() { + return AttributesDeleted.of(command.getThingEntityId(), -1, Instant.now(), command.getDittoHeaders(), + null); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommandImpl.java new file mode 100644 index 00000000..ac7949a8 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommandImpl.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.modify.DeleteAttributes; + +/** + * An immutable implementation of {@link DeleteAttributesLiveCommand}. + * + * @since 2.0.0 + */ +@Immutable +final class DeleteAttributesLiveCommandImpl + extends AbstractModifyLiveCommand + implements DeleteAttributesLiveCommand { + + private DeleteAttributesLiveCommandImpl(final DeleteAttributes command) { + super(command); + } + + /** + * Returns a new instance of {@code DeleteAttributesLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link DeleteAttributes}. + */ + @Nonnull + public static DeleteAttributesLiveCommandImpl of(final Command command) { + return new DeleteAttributesLiveCommandImpl((DeleteAttributes) command); + } + + @Nonnull + @Override + public DeleteAttributesLiveCommandAnswerBuilder answer() { + return DeleteAttributesLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Override + public Category getCategory() { + return Category.DELETE; + } + + @Override + public DeleteAttributesLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return new DeleteAttributesLiveCommandImpl(DeleteAttributes.of(getThingEntityId(), dittoHeaders)); + } + + @Override + public boolean changesAuthorization() { + return false; + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommand.java new file mode 100644 index 00000000..dd0eac41 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommand.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.signals.base.WithFeatureId; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommand; + +/** + * {@link org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureDefinition} live command giving access to the + * command and all of its special accessors. Also the entry point for creating a + * {@link DeleteFeatureDefinitionLiveCommandAnswerBuilder} as answer for an incoming command. + * + * @since 2.0.0 + */ +public interface DeleteFeatureDefinitionLiveCommand + extends LiveCommand, + ThingModifyCommand, WithFeatureId { +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..b0fb96b0 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommandAnswerBuilder.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureDefinitionResponse; +import org.eclipse.ditto.signals.events.things.FeatureDefinitionDeleted; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s and {@code Event}s for {@link + * org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureDefinition} commands. + * + * @since 2.0.0 + */ +public interface DeleteFeatureDefinitionLiveCommandAnswerBuilder + extends + LiveCommandAnswerBuilder.ModifyCommandResponseStep { + + /** + * Factory for {@code CommandResponse}s to + * {@link org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureDefinition} command. + */ + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Builds a {@link DeleteFeatureDefinitionResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + DeleteFeatureDefinitionResponse deleted(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the Feature Definition was not accessible. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertiesNotAccessibleException + * FeaturePropertiesNotAccessibleException + */ + @Nonnull + ThingErrorResponse featureDefinitionNotAccessibleError(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the Feature Definition was not modifiable. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertiesNotModifiableException + * FeaturePropertiesNotModifiableException + */ + @Nonnull + ThingErrorResponse featureDefinitionNotModifiableError(); + + } + + /** + * Factory for events triggered by {@link org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureDefinition} + * command. + */ + @SuppressWarnings("squid:S1609") + interface EventFactory extends LiveEventFactory { + + /** + * Creates a {@link FeatureDefinitionDeleted} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + FeatureDefinitionDeleted deleted(); + + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..7f7c034f --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import java.time.Instant; +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDefinitionNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDefinitionNotModifiableException; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureDefinitionResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.FeatureDefinitionDeleted; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link DeleteFeatureDefinitionLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class DeleteFeatureDefinitionLiveCommandAnswerBuilderImpl + extends + AbstractLiveCommandAnswerBuilder + implements DeleteFeatureDefinitionLiveCommandAnswerBuilder { + + private DeleteFeatureDefinitionLiveCommandAnswerBuilderImpl(final DeleteFeatureDefinitionLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code DeleteFeatureDefinitionLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static DeleteFeatureDefinitionLiveCommandAnswerBuilderImpl newInstance( + final DeleteFeatureDefinitionLiveCommand command) { + + return new DeleteFeatureDefinitionLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @Override + protected Event doCreateEvent(final Function> createEventFunction) { + return createEventFunction.apply(new EventFactoryImpl()); + } + + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public DeleteFeatureDefinitionResponse deleted() { + return DeleteFeatureDefinitionResponse.of(command.getThingEntityId(), command.getFeatureId(), + command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse featureDefinitionNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + FeatureDefinitionNotAccessibleException.newBuilder(command.getThingEntityId(), + command.getFeatureId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + + @Nonnull + @Override + public ThingErrorResponse featureDefinitionNotModifiableError() { + return errorResponse(command.getThingEntityId(), + FeatureDefinitionNotModifiableException.newBuilder(command.getThingEntityId(), + command.getFeatureId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + + } + + private final class EventFactoryImpl implements EventFactory { + + @Nonnull + @Override + public FeatureDefinitionDeleted deleted() { + return FeatureDefinitionDeleted.of(command.getThingEntityId(), command.getFeatureId(), -1, + Instant.now(), command.getDittoHeaders(), null); + } + + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommandImpl.java new file mode 100644 index 00000000..6e6134c7 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommandImpl.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureDefinition; +import org.eclipse.ditto.utils.jsr305.annotations.AllValuesAreNonnullByDefault; + +/** + * An immutable implementation of {@link DeleteFeatureDefinitionLiveCommand}. + * + * @since 2.0.0 + */ +@AllValuesAreNonnullByDefault +@Immutable +final class DeleteFeatureDefinitionLiveCommandImpl + extends AbstractModifyLiveCommand + implements DeleteFeatureDefinitionLiveCommand { + + private final String featureId; + + private DeleteFeatureDefinitionLiveCommandImpl(final DeleteFeatureDefinition command) { + super(command); + featureId = command.getFeatureId(); + } + + /** + * Returns a new instance of {@code DeleteFeatureDefinitionLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link DeleteFeatureDefinition}. + */ + @Nonnull + public static DeleteFeatureDefinitionLiveCommandImpl of(final Command command) { + return new DeleteFeatureDefinitionLiveCommandImpl((DeleteFeatureDefinition) command); + } + + @Override + public String getFeatureId() { + return featureId; + } + + @Override + public Category getCategory() { + return Category.DELETE; + } + + @Override + public DeleteFeatureDefinitionLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return new DeleteFeatureDefinitionLiveCommandImpl(DeleteFeatureDefinition.of(getThingEntityId(), getFeatureId(), + dittoHeaders)); + } + + @Override + public boolean changesAuthorization() { + return false; + } + + @Nonnull + @Override + public DeleteFeatureDefinitionLiveCommandAnswerBuilder answer() { + return DeleteFeatureDefinitionLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommand.java new file mode 100644 index 00000000..bcfda845 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommand.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.signals.base.WithFeatureId; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureDesiredProperties; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommand; + +/** + * {@link DeleteFeatureDesiredProperties} live command giving access to the command and all of its special accessors. + * Also the entry point for creating a {@link DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilder} as answer + * for an incoming command. + * + * @since 2.0.0 + */ +public interface DeleteFeatureDesiredPropertiesLiveCommand + extends LiveCommand, + ThingModifyCommand, WithFeatureId { +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..be2a3a19 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilder.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureDesiredProperties; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureDesiredPropertiesResponse; +import org.eclipse.ditto.signals.events.things.FeatureDesiredPropertiesDeleted; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s and {@code Event}s for + * {@link DeleteFeatureDesiredProperties} commands. + * + * @since 2.0.0 + */ +public interface DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilder + extends LiveCommandAnswerBuilder.ModifyCommandResponseStep { + + /** + * Factory for {@code CommandResponse}s to {@link DeleteFeatureDesiredProperties} command. + */ + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Builds a {@link DeleteFeatureDesiredPropertiesResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + DeleteFeatureDesiredPropertiesResponse deleted(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the features desired properties were not accessible. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertiesNotAccessibleException + * FeatureDesiredPropertiesNotAccessibleException + */ + @Nonnull + ThingErrorResponse featureDesiredPropertiesNotAccessibleError(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the feature properties were not modifiable. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertiesNotModifiableException + * FeatureDesiredPropertiesNotModifiableException + */ + @Nonnull + ThingErrorResponse featureDesiredPropertiesNotModifiableError(); + } + + /** + * Factory for events triggered by {@link DeleteFeatureDesiredProperties} command. + */ + @SuppressWarnings("squid:S1609") + interface EventFactory extends LiveEventFactory { + + /** + * Creates a {@link FeatureDesiredPropertiesDeleted} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + FeatureDesiredPropertiesDeleted deleted(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..14d2a034 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import java.time.Instant; +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertiesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertiesNotModifiableException; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureDesiredPropertiesResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.FeatureDesiredPropertiesDeleted; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link DeleteFeatureDesiredPropertiesLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl + extends AbstractLiveCommandAnswerBuilder + implements DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilder { + + private DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl( + final DeleteFeatureDesiredPropertiesLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl newInstance( + final DeleteFeatureDesiredPropertiesLiveCommand command) { + return new DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @Override + protected Event doCreateEvent(final Function> createEventFunction) { + return createEventFunction.apply(new EventFactoryImpl()); + } + + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public DeleteFeatureDesiredPropertiesResponse deleted() { + return DeleteFeatureDesiredPropertiesResponse.of(command.getThingEntityId(), command.getFeatureId(), + command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse featureDesiredPropertiesNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + FeatureDesiredPropertiesNotAccessibleException.newBuilder(command.getThingEntityId(), + command.getFeatureId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + + @Nonnull + @Override + public ThingErrorResponse featureDesiredPropertiesNotModifiableError() { + return errorResponse(command.getThingEntityId(), + FeatureDesiredPropertiesNotModifiableException.newBuilder(command.getThingEntityId(), + command.getFeatureId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + + private final class EventFactoryImpl implements EventFactory { + + @Nonnull + @Override + public FeatureDesiredPropertiesDeleted deleted() { + return FeatureDesiredPropertiesDeleted.of(command.getThingEntityId(), command.getFeatureId(), -1, + Instant.now(), command.getDittoHeaders(), null); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommandImpl.java new file mode 100644 index 00000000..64d1e21f --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommandImpl.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureDesiredProperties; + +/** + * An immutable implementation of {@link DeleteFeatureDesiredPropertiesLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class DeleteFeatureDesiredPropertiesLiveCommandImpl + extends AbstractModifyLiveCommand + implements DeleteFeatureDesiredPropertiesLiveCommand { + + private final String featureId; + + private DeleteFeatureDesiredPropertiesLiveCommandImpl(final DeleteFeatureDesiredProperties command) { + super(command); + featureId = command.getFeatureId(); + } + + /** + * Returns a new instance of {@code DeleteFeatureDesiredPropertiesLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link DeleteFeatureDesiredProperties}. + */ + @Nonnull + public static DeleteFeatureDesiredPropertiesLiveCommandImpl of(final Command command) { + return new DeleteFeatureDesiredPropertiesLiveCommandImpl((DeleteFeatureDesiredProperties) command); + } + + @Override + public String getFeatureId() { + return featureId; + } + + @Override + public Category getCategory() { + return Category.DELETE; + } + + @Override + public DeleteFeatureDesiredPropertiesLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return new DeleteFeatureDesiredPropertiesLiveCommandImpl( + DeleteFeatureDesiredProperties.of(getThingEntityId(), getFeatureId(), + dittoHeaders)); + } + + @Override + public boolean changesAuthorization() { + return false; + } + + @Nonnull + @Override + public DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilder answer() { + return DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommand.java new file mode 100644 index 00000000..a7a4164d --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommand.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.signals.base.WithFeatureId; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureDesiredProperty; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommand; + +/** + * {@link DeleteFeatureDesiredProperty} live command giving access to the command and all of its special accessors. + * Also the entry point for creating a {@link DeleteFeatureDesiredPropertyLiveCommandAnswerBuilder} as answer + * for an incoming command. + * + * @since 2.0.0 + */ +public interface DeleteFeatureDesiredPropertyLiveCommand + extends + LiveCommand, + ThingModifyCommand, WithFeatureId { + + /** + * Returns the JSON pointer of the desired property to delete. + * + * @return the pointer. + */ + JsonPointer getDesiredPropertyPointer(); + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..03e5d554 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommandAnswerBuilder.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureDesiredProperty; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureDesiredPropertyResponse; +import org.eclipse.ditto.signals.events.things.FeatureDesiredPropertyDeleted; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s and {@code Event}s for + * {@link DeleteFeatureDesiredProperty} commands. + * + * @since 2.0.0 + */ +public interface DeleteFeatureDesiredPropertyLiveCommandAnswerBuilder + extends + LiveCommandAnswerBuilder.ModifyCommandResponseStep { + + /** + * Factory for {@code CommandResponse}s to {@link DeleteFeatureDesiredProperty} command. + */ + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Builds a {@link DeleteFeatureDesiredPropertyResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + DeleteFeatureDesiredPropertyResponse deleted(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the feature's desired property was not accessible. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertyNotAccessibleException + * FeatureDesiredPropertyNotAccessibleException + */ + @Nonnull + ThingErrorResponse featureDesiredPropertyNotAccessibleError(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the feature's desired property was not modifiable. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertyNotModifiableException + * FeatureDesiredPropertyNotModifiableException + */ + @Nonnull + ThingErrorResponse featureDesiredPropertyNotModifiableError(); + } + + /** + * Factory for events triggered by {@link DeleteFeatureDesiredProperty} command. + */ + @SuppressWarnings("squid:S1609") + interface EventFactory extends LiveEventFactory { + + /** + * Creates a {@link FeatureDesiredPropertyDeleted} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + FeatureDesiredPropertyDeleted deleted(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..cdb3c79e --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import java.time.Instant; +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertyNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertyNotModifiableException; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureDesiredPropertyResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.FeatureDesiredPropertyDeleted; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link DeleteFeatureDesiredPropertyLiveCommand} command. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class DeleteFeatureDesiredPropertyLiveCommandAnswerBuilderImpl + extends AbstractLiveCommandAnswerBuilder + implements DeleteFeatureDesiredPropertyLiveCommandAnswerBuilder { + + private DeleteFeatureDesiredPropertyLiveCommandAnswerBuilderImpl( + final DeleteFeatureDesiredPropertyLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code DeleteFeatureDesiredPropertyLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static DeleteFeatureDesiredPropertyLiveCommandAnswerBuilderImpl newInstance( + final DeleteFeatureDesiredPropertyLiveCommand command) { + return new DeleteFeatureDesiredPropertyLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @Override + protected Event doCreateEvent(final Function> createEventFunction) { + return createEventFunction.apply(new EventFactoryImpl()); + } + + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public DeleteFeatureDesiredPropertyResponse deleted() { + return DeleteFeatureDesiredPropertyResponse.of(command.getThingEntityId(), command.getFeatureId(), + command.getDesiredPropertyPointer(), + command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse featureDesiredPropertyNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + FeatureDesiredPropertyNotAccessibleException.newBuilder(command.getThingEntityId(), + command.getFeatureId(), + command.getDesiredPropertyPointer()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + + @Nonnull + @Override + public ThingErrorResponse featureDesiredPropertyNotModifiableError() { + return errorResponse(command.getThingEntityId(), + FeatureDesiredPropertyNotModifiableException.newBuilder(command.getThingEntityId(), + command.getFeatureId(), + command.getDesiredPropertyPointer()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + + @Immutable + private final class EventFactoryImpl implements EventFactory { + + @Nonnull + @Override + public FeatureDesiredPropertyDeleted deleted() { + return FeatureDesiredPropertyDeleted.of(command.getThingEntityId(), command.getFeatureId(), + command.getDesiredPropertyPointer(), -1, Instant.now(), command.getDittoHeaders(), null); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommandImpl.java new file mode 100644 index 00000000..5aa280a9 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommandImpl.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureDesiredProperty; + +/** + * An immutable implementation of {@link DeleteFeatureDesiredPropertyLiveCommand}. + * + * @since 2.0.0 + */ +@Immutable +final class DeleteFeatureDesiredPropertyLiveCommandImpl + extends AbstractModifyLiveCommand + implements DeleteFeatureDesiredPropertyLiveCommand { + + private final String featureId; + private final JsonPointer desiredPropertyPointer; + + /** + * @throws NullPointerException if {@code command} is {@code null}. + */ + private DeleteFeatureDesiredPropertyLiveCommandImpl(final DeleteFeatureDesiredProperty command) { + super(command); + featureId = command.getFeatureId(); + desiredPropertyPointer = command.getDesiredPropertyPointer(); + } + + /** + * Returns a new instance of {@code DeleteFeatureDesiredPropertyLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link DeleteFeatureDesiredProperty}. + */ + @Nonnull + public static DeleteFeatureDesiredPropertyLiveCommandImpl of(final Command command) { + return new DeleteFeatureDesiredPropertyLiveCommandImpl((DeleteFeatureDesiredProperty) command); + } + + @Override + public String getFeatureId() { + return featureId; + } + + @Override + public JsonPointer getDesiredPropertyPointer() { + return desiredPropertyPointer; + } + + @Override + public Category getCategory() { + return Category.DELETE; + } + + @Override + public DeleteFeatureDesiredPropertyLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return new DeleteFeatureDesiredPropertyLiveCommandImpl( + DeleteFeatureDesiredProperty.of(getThingEntityId(), getFeatureId(), + getDesiredPropertyPointer(), dittoHeaders)); + } + + @Override + public boolean changesAuthorization() { + return false; + } + + @Nonnull + @Override + public DeleteFeatureDesiredPropertyLiveCommandAnswerBuilder answer() { + return DeleteFeatureDesiredPropertyLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommand.java new file mode 100644 index 00000000..76ea9a1d --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommand.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.signals.base.WithFeatureId; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeature; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommand; + +/** + * {@link DeleteFeature} live command giving access to the command and all of its special accessors. Also the entry + * point for creating a {@link DeleteFeatureLiveCommandAnswerBuilder} capable of answering incoming commands. + * + * @since 2.0.0 + */ +public interface DeleteFeatureLiveCommand + extends LiveCommand, + ThingModifyCommand, WithFeatureId { +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..38d01162 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommandAnswerBuilder.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeature; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureResponse; +import org.eclipse.ditto.signals.events.things.FeatureDeleted; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s and {@code Event}s for {@link DeleteFeature} + * commands. + * + * @since 2.0.0 + */ +public interface DeleteFeatureLiveCommandAnswerBuilder extends LiveCommandAnswerBuilder.ModifyCommandResponseStep< + DeleteFeatureLiveCommandAnswerBuilder.ResponseFactory, DeleteFeatureLiveCommandAnswerBuilder.EventFactory> { + + /** + * Factory for {@code CommandResponse}s to {@link DeleteFeature} command. + */ + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Builds a {@link DeleteFeatureResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + DeleteFeatureResponse deleted(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the feature was not accessible. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeatureNotAccessibleException + * FeatureNotAccessibleException + */ + @Nonnull + ThingErrorResponse featureNotAccessibleError(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the feature was not modifiable. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeatureNotModifiableException + * FeatureNotModifiableException + */ + @Nonnull + ThingErrorResponse featureNotModifiableError(); + } + + /** + * Factory for events triggered by {@link DeleteFeature} command. + */ + @SuppressWarnings("squid:S1609") + interface EventFactory extends LiveEventFactory { + + /** + * Creates a {@link FeatureDeleted} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + FeatureDeleted deleted(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..460eddc0 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import java.time.Instant; +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureNotModifiableException; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.FeatureDeleted; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a {@link DeleteFeatureLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class DeleteFeatureLiveCommandAnswerBuilderImpl + extends + AbstractLiveCommandAnswerBuilder + implements DeleteFeatureLiveCommandAnswerBuilder { + + private DeleteFeatureLiveCommandAnswerBuilderImpl(final DeleteFeatureLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code DeleteFeatureLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static DeleteFeatureLiveCommandAnswerBuilderImpl newInstance(final DeleteFeatureLiveCommand command) { + return new DeleteFeatureLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @Override + protected Event doCreateEvent(final Function> createEventFunction) { + return createEventFunction.apply(new EventFactoryImpl()); + } + + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public DeleteFeatureResponse deleted() { + return DeleteFeatureResponse.of(command.getThingEntityId(), command.getFeatureId(), + command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse featureNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + FeatureNotAccessibleException.newBuilder(command.getThingEntityId(), command.getFeatureId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + + @Nonnull + @Override + public ThingErrorResponse featureNotModifiableError() { + return errorResponse(command.getThingEntityId(), + FeatureNotModifiableException.newBuilder(command.getThingEntityId(), command.getFeatureId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + + @Immutable + private final class EventFactoryImpl implements EventFactory { + + @Nonnull + @Override + public FeatureDeleted deleted() { + return FeatureDeleted.of(command.getThingEntityId(), command.getFeatureId(), -1, Instant.now(), + command.getDittoHeaders(), null); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommandImpl.java new file mode 100644 index 00000000..13ada5e0 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommandImpl.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeature; + +/** + * An immutable implementation of {@link DeleteFeatureLiveCommand}. + * + * @since 2.0.0 + */ +@Immutable +final class DeleteFeatureLiveCommandImpl + extends AbstractModifyLiveCommand + implements DeleteFeatureLiveCommand { + + private final String featureId; + + private DeleteFeatureLiveCommandImpl(final DeleteFeature command) { + super(command); + featureId = command.getFeatureId(); + } + + /** + * Returns a new instance of {@code DeleteFeatureLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link DeleteFeature}. + */ + @Nonnull + public static DeleteFeatureLiveCommandImpl of(final Command command) { + return new DeleteFeatureLiveCommandImpl((DeleteFeature) command); + } + + @Override + public String getFeatureId() { + return featureId; + } + + @Override + public Category getCategory() { + return Category.DELETE; + } + + @Override + public DeleteFeatureLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return new DeleteFeatureLiveCommandImpl(DeleteFeature.of(getThingEntityId(), getFeatureId(), dittoHeaders)); + } + + @Override + public boolean changesAuthorization() { + return false; + } + + @Nonnull + @Override + public DeleteFeatureLiveCommandAnswerBuilder answer() { + return DeleteFeatureLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommand.java new file mode 100644 index 00000000..1529c5cc --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommand.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.signals.base.WithFeatureId; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureProperties; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommand; + +/** + * {@link DeleteFeatureProperties} live command giving access to the command and all of its special accessors. + * Also the entry point for creating a {@link DeleteFeaturePropertiesLiveCommandAnswerBuilder} as answer + * for an incoming command. + * + * @since 2.0.0 + */ +public interface DeleteFeaturePropertiesLiveCommand extends + LiveCommand, + ThingModifyCommand, WithFeatureId { +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..e69eb016 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommandAnswerBuilder.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureProperties; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeaturePropertiesResponse; +import org.eclipse.ditto.signals.events.things.FeaturePropertiesDeleted; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s and {@code Event}s for + * {@link DeleteFeatureProperties} commands. + * + * @since 2.0.0 + */ +public interface DeleteFeaturePropertiesLiveCommandAnswerBuilder + extends + LiveCommandAnswerBuilder.ModifyCommandResponseStep { + + /** + * Factory for {@code CommandResponse}s to {@link DeleteFeatureProperties} command. + */ + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Builds a {@link DeleteFeaturePropertiesResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + DeleteFeaturePropertiesResponse deleted(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the feature properties were not accessible. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertiesNotAccessibleException + * FeaturePropertiesNotAccessibleException + */ + @Nonnull + ThingErrorResponse featurePropertiesNotAccessibleError(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the feature properties were not modifiable. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertiesNotModifiableException + * FeaturePropertiesNotModifiableException + */ + @Nonnull + ThingErrorResponse featurePropertiesNotModifiableError(); + } + + /** + * Factory for events triggered by {@link DeleteFeatureProperties} command. + */ + @SuppressWarnings("squid:S1609") + interface EventFactory extends LiveEventFactory { + + /** + * Creates a {@link FeaturePropertiesDeleted} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + FeaturePropertiesDeleted deleted(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..da7a66dd --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import java.time.Instant; +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertiesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertiesNotModifiableException; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeaturePropertiesResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.FeaturePropertiesDeleted; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link DeleteFeaturePropertiesLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class DeleteFeaturePropertiesLiveCommandAnswerBuilderImpl + extends AbstractLiveCommandAnswerBuilder + implements DeleteFeaturePropertiesLiveCommandAnswerBuilder { + + private DeleteFeaturePropertiesLiveCommandAnswerBuilderImpl(final DeleteFeaturePropertiesLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code DeleteFeaturePropertiesLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static DeleteFeaturePropertiesLiveCommandAnswerBuilderImpl newInstance( + final DeleteFeaturePropertiesLiveCommand command) { + return new DeleteFeaturePropertiesLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @Override + protected Event doCreateEvent(final Function> createEventFunction) { + return createEventFunction.apply(new EventFactoryImpl()); + } + + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public DeleteFeaturePropertiesResponse deleted() { + return DeleteFeaturePropertiesResponse.of(command.getThingEntityId(), command.getFeatureId(), + command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse featurePropertiesNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + FeaturePropertiesNotAccessibleException.newBuilder(command.getThingEntityId(), + command.getFeatureId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + + @Nonnull + @Override + public ThingErrorResponse featurePropertiesNotModifiableError() { + return errorResponse(command.getThingEntityId(), + FeaturePropertiesNotModifiableException.newBuilder(command.getThingEntityId(), + command.getFeatureId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + + private final class EventFactoryImpl implements EventFactory { + + @Nonnull + @Override + public FeaturePropertiesDeleted deleted() { + return FeaturePropertiesDeleted.of(command.getThingEntityId(), command.getFeatureId(), -1, + Instant.now(), command.getDittoHeaders(), null); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommandImpl.java new file mode 100644 index 00000000..fd4220ec --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommandImpl.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureProperties; + +/** + * An immutable implementation of {@link DeleteFeaturePropertiesLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class DeleteFeaturePropertiesLiveCommandImpl + extends + AbstractModifyLiveCommand + implements DeleteFeaturePropertiesLiveCommand { + + private final String featureId; + + private DeleteFeaturePropertiesLiveCommandImpl(final DeleteFeatureProperties command) { + super(command); + featureId = command.getFeatureId(); + } + + /** + * Returns a new instance of {@code DeleteFeaturePropertiesLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link DeleteFeatureProperties}. + */ + @Nonnull + public static DeleteFeaturePropertiesLiveCommandImpl of(final Command command) { + return new DeleteFeaturePropertiesLiveCommandImpl((DeleteFeatureProperties) command); + } + + @Override + public String getFeatureId() { + return featureId; + } + + @Override + public Category getCategory() { + return Category.DELETE; + } + + @Override + public DeleteFeaturePropertiesLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return new DeleteFeaturePropertiesLiveCommandImpl(DeleteFeatureProperties.of(getThingEntityId(), getFeatureId(), + dittoHeaders)); + } + + @Override + public boolean changesAuthorization() { + return false; + } + + @Nonnull + @Override + public DeleteFeaturePropertiesLiveCommandAnswerBuilder answer() { + return DeleteFeaturePropertiesLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommand.java new file mode 100644 index 00000000..a5391af7 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommand.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.signals.base.WithFeatureId; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureProperty; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommand; + +/** + * {@link DeleteFeatureProperty} live command giving access to the command and all of its special accessors. Also the + * entry point for creating a {@link DeleteFeaturePropertyLiveCommandAnswerBuilder} as answer for an incoming command. + * + * @since 2.0.0 + */ +public interface DeleteFeaturePropertyLiveCommand + extends LiveCommand, + ThingModifyCommand, WithFeatureId { + + /** + * Returns the JSON pointer of the Property to delete. + * + * @return the pointer. + */ + JsonPointer getPropertyPointer(); + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..78e84da7 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommandAnswerBuilder.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureProperty; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeaturePropertyResponse; +import org.eclipse.ditto.signals.events.things.FeaturePropertyDeleted; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s and {@code Event}s for {@link DeleteFeatureProperty} + * commands. + * + * @since 2.0.0 + */ +public interface DeleteFeaturePropertyLiveCommandAnswerBuilder + extends + LiveCommandAnswerBuilder.ModifyCommandResponseStep { + + /** + * Factory for {@code CommandResponse}s to {@link DeleteFeatureProperty} command. + */ + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Builds a {@link DeleteFeaturePropertyResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + DeleteFeaturePropertyResponse deleted(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the feature property was not accessible. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertyNotAccessibleException + * FeaturePropertyNotAccessibleException + */ + @Nonnull + ThingErrorResponse featurePropertyNotAccessibleError(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the feature property was not modifiable. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertyNotModifiableException + * FeaturePropertyNotModifiableException + */ + @Nonnull + ThingErrorResponse featurePropertyNotModifiableError(); + } + + /** + * Factory for events triggered by {@link DeleteFeatureProperty} command. + */ + @SuppressWarnings("squid:S1609") + interface EventFactory extends LiveEventFactory { + + /** + * Creates a {@link FeaturePropertyDeleted} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + FeaturePropertyDeleted deleted(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..f10c6f6d --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import java.time.Instant; +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertyNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertyNotModifiableException; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeaturePropertyResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.FeaturePropertyDeleted; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link DeleteFeaturePropertyLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class DeleteFeaturePropertyLiveCommandAnswerBuilderImpl + extends + AbstractLiveCommandAnswerBuilder + implements DeleteFeaturePropertyLiveCommandAnswerBuilder { + + private DeleteFeaturePropertyLiveCommandAnswerBuilderImpl(final DeleteFeaturePropertyLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code DeleteFeaturePropertyLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static DeleteFeaturePropertyLiveCommandAnswerBuilderImpl newInstance( + final DeleteFeaturePropertyLiveCommand command) { + return new DeleteFeaturePropertyLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @Override + protected Event doCreateEvent(final Function> createEventFunction) { + return createEventFunction.apply(new EventFactoryImpl()); + } + + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public DeleteFeaturePropertyResponse deleted() { + return DeleteFeaturePropertyResponse.of(command.getThingEntityId(), command.getFeatureId(), + command.getPropertyPointer(), + command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse featurePropertyNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + FeaturePropertyNotAccessibleException.newBuilder(command.getThingEntityId(), + command.getFeatureId(), + command.getPropertyPointer()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + + @Nonnull + @Override + public ThingErrorResponse featurePropertyNotModifiableError() { + return errorResponse(command.getThingEntityId(), + FeaturePropertyNotModifiableException.newBuilder(command.getThingEntityId(), + command.getFeatureId(), + command.getPropertyPointer()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + + @Immutable + private final class EventFactoryImpl implements EventFactory { + + @Nonnull + @Override + public FeaturePropertyDeleted deleted() { + return FeaturePropertyDeleted.of(command.getThingEntityId(), command.getFeatureId(), + command.getPropertyPointer(), -1, Instant.now(), command.getDittoHeaders(), null); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommandImpl.java new file mode 100644 index 00000000..e6f34de7 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommandImpl.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureProperty; + +/** + * An immutable implementation of {@link DeleteFeaturePropertyLiveCommand}. + * + * @since 2.0.0 + */ +@Immutable +final class DeleteFeaturePropertyLiveCommandImpl + extends + AbstractModifyLiveCommand + implements DeleteFeaturePropertyLiveCommand { + + private final String featureId; + private final JsonPointer propertyPointer; + + /** + * @throws NullPointerException if {@code command} is {@code null}. + */ + private DeleteFeaturePropertyLiveCommandImpl(final DeleteFeatureProperty command) { + super(command); + featureId = command.getFeatureId(); + propertyPointer = command.getPropertyPointer(); + } + + /** + * Returns a new instance of {@code DeleteFeaturePropertyLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link DeleteFeatureProperty}. + */ + @Nonnull + public static DeleteFeaturePropertyLiveCommandImpl of(final Command command) { + return new DeleteFeaturePropertyLiveCommandImpl((DeleteFeatureProperty) command); + } + + @Override + public String getFeatureId() { + return featureId; + } + + @Override + public JsonPointer getPropertyPointer() { + return propertyPointer; + } + + @Override + public Category getCategory() { + return Category.DELETE; + } + + @Override + public DeleteFeaturePropertyLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return new DeleteFeaturePropertyLiveCommandImpl(DeleteFeatureProperty.of(getThingEntityId(), getFeatureId(), + getPropertyPointer(), dittoHeaders)); + } + + @Override + public boolean changesAuthorization() { + return false; + } + + @Nonnull + @Override + public DeleteFeaturePropertyLiveCommandAnswerBuilder answer() { + return DeleteFeaturePropertyLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommand.java new file mode 100644 index 00000000..349ddcd4 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommand.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeature; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommand; + +/** + * {@link DeleteFeature} live command giving access to the command and all of its special accessors. Also the entry + * point for creating a {@link DeleteFeatureLiveCommandAnswerBuilder} capable of answering incoming commands. + * + * @since 2.0.0 + */ +public interface DeleteFeaturesLiveCommand + extends LiveCommand, + ThingModifyCommand { +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..9d2f28e3 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommandAnswerBuilder.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatures; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeaturesResponse; +import org.eclipse.ditto.signals.events.things.FeaturesDeleted; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s and {@code Event}s for {@link DeleteFeatures} + * commands. + * + * @since 2.0.0 + */ +public interface DeleteFeaturesLiveCommandAnswerBuilder extends LiveCommandAnswerBuilder.ModifyCommandResponseStep< + DeleteFeaturesLiveCommandAnswerBuilder.ResponseFactory, DeleteFeaturesLiveCommandAnswerBuilder.EventFactory> { + + /** + * Factory for {@code CommandResponse}s to {@link DeleteFeatures} command. + */ + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Builds a {@link DeleteFeaturesResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + DeleteFeaturesResponse deleted(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the features were not accessible. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeaturesNotAccessibleException + * FeaturesNotAccessibleException + */ + @Nonnull + ThingErrorResponse featuresNotAccessibleError(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the features were not modifiable. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeaturesNotModifiableException + * FeaturesNotModifiableException + */ + @Nonnull + ThingErrorResponse featuresNotModifiableError(); + } + + /** + * Factory for events triggered by {@link DeleteFeatures} command. + */ + @SuppressWarnings("squid:S1609") + interface EventFactory extends LiveEventFactory { + + /** + * Creates a {@link FeaturesDeleted} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + FeaturesDeleted deleted(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..a5b5b248 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import java.time.Instant; +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturesNotModifiableException; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeaturesResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.FeaturesDeleted; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer LiveCommandAnswer} for a + * {@link DeleteFeaturesLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class DeleteFeaturesLiveCommandAnswerBuilderImpl + extends + AbstractLiveCommandAnswerBuilder + implements DeleteFeaturesLiveCommandAnswerBuilder { + + private DeleteFeaturesLiveCommandAnswerBuilderImpl(final DeleteFeaturesLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code DeleteFeaturesLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static DeleteFeaturesLiveCommandAnswerBuilderImpl newInstance(final DeleteFeaturesLiveCommand command) { + return new DeleteFeaturesLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @Override + protected Event doCreateEvent(final Function> createEventFunction) { + return createEventFunction.apply(new EventFactoryImpl()); + } + + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public DeleteFeaturesResponse deleted() { + return DeleteFeaturesResponse.of(command.getThingEntityId(), command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse featuresNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + FeaturesNotAccessibleException.newBuilder(command.getThingEntityId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + + @Nonnull + @Override + public ThingErrorResponse featuresNotModifiableError() { + return errorResponse(command.getThingEntityId(), + FeaturesNotModifiableException.newBuilder(command.getThingEntityId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + + @Immutable + private final class EventFactoryImpl implements EventFactory { + + @Nonnull + @Override + public FeaturesDeleted deleted() { + return FeaturesDeleted.of(command.getThingEntityId(), -1, Instant.now(), command.getDittoHeaders(), + null); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommandImpl.java new file mode 100644 index 00000000..e07a28f5 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommandImpl.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatures; + +/** + * An immutable implementation of {@link DeleteFeaturesLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class DeleteFeaturesLiveCommandImpl + extends AbstractModifyLiveCommand + implements DeleteFeaturesLiveCommand { + + private DeleteFeaturesLiveCommandImpl(final DeleteFeatures command) { + super(command); + } + + /** + * Returns a new instance of {@code DeleteFeaturesLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link DeleteFeatures}. + */ + @Nonnull + public static DeleteFeaturesLiveCommandImpl of(final Command command) { + return new DeleteFeaturesLiveCommandImpl((DeleteFeatures) command); + } + + @Override + public Category getCategory() { + return Category.DELETE; + } + + @Override + public DeleteFeaturesLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return new DeleteFeaturesLiveCommandImpl(DeleteFeatures.of(getThingEntityId(), dittoHeaders)); + } + + @Override + public boolean changesAuthorization() { + return false; + } + + @Nonnull + @Override + public DeleteFeaturesLiveCommandAnswerBuilder answer() { + return DeleteFeaturesLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommand.java new file mode 100644 index 00000000..7dc69de5 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommand.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.signals.commands.things.modify.DeleteThing; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommand; + +/** + * {@link DeleteThing} live command giving access to the command and all of its special accessors. Also the entry point + * for creating a {@link DeleteThingLiveCommandAnswerBuilder} capable of answering incoming commands. + * + * @since 2.0.0 + */ +public interface DeleteThingLiveCommand + extends LiveCommand, + ThingModifyCommand { +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..ecbeae02 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommandAnswerBuilder.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.modify.DeleteThing; +import org.eclipse.ditto.signals.commands.things.modify.DeleteThingResponse; +import org.eclipse.ditto.signals.events.things.ThingDeleted; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s and {@code Event}s for {@link DeleteThing} + * commands. + * + * @since 2.0.0 + */ +public interface DeleteThingLiveCommandAnswerBuilder extends LiveCommandAnswerBuilder.ModifyCommandResponseStep< + DeleteThingLiveCommandAnswerBuilder.ResponseFactory, DeleteThingLiveCommandAnswerBuilder.EventFactory> { + + /** + * Factory for {@code CommandResponse}s to {@link DeleteThing} command. + */ + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Builds a {@link DeleteThingResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + DeleteThingResponse deleted(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the Thing was not accessible. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.ThingNotAccessibleException + * ThingNotAccessibleException + */ + @Nonnull + ThingErrorResponse thingNotAccessibleError(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the Thing was not deletable. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.ThingNotDeletableException + * ThingNotDeletableException + */ + @Nonnull + ThingErrorResponse thingNotDeletableError(); + } + + /** + * Factory for events triggered by {@link DeleteThing} command. + */ + @SuppressWarnings("squid:S1609") + interface EventFactory extends LiveEventFactory { + + /** + * Creates a {@link ThingDeleted} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + ThingDeleted deleted(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..7f51688d --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import java.time.Instant; +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.ThingNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.ThingNotDeletableException; +import org.eclipse.ditto.signals.commands.things.modify.DeleteThingResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.ThingDeleted; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a {@link DeleteThingLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class DeleteThingLiveCommandAnswerBuilderImpl + extends + AbstractLiveCommandAnswerBuilder + implements DeleteThingLiveCommandAnswerBuilder { + + private DeleteThingLiveCommandAnswerBuilderImpl(final DeleteThingLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code DeleteThingLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static DeleteThingLiveCommandAnswerBuilderImpl newInstance(final DeleteThingLiveCommand command) { + return new DeleteThingLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @Override + protected Event doCreateEvent(final Function> createEventFunction) { + return createEventFunction.apply(new EventFactoryImpl()); + } + + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public DeleteThingResponse deleted() { + return DeleteThingResponse.of(command.getThingEntityId(), command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse thingNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + ThingNotAccessibleException.newBuilder(command.getThingEntityId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + + @Nonnull + @Override + public ThingErrorResponse thingNotDeletableError() { + return errorResponse(command.getThingEntityId(), + ThingNotDeletableException.newBuilder(command.getThingEntityId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + + @Immutable + private final class EventFactoryImpl implements EventFactory { + + @Nonnull + @Override + public ThingDeleted deleted() { + return ThingDeleted.of(command.getThingEntityId(), -1, Instant.now(), command.getDittoHeaders(), null); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommandImpl.java new file mode 100644 index 00000000..589c8926 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommandImpl.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.modify.DeleteThing; + +/** + * An immutable implementation of {@link DeleteThingLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class DeleteThingLiveCommandImpl extends AbstractModifyLiveCommand implements DeleteThingLiveCommand { + + private DeleteThingLiveCommandImpl(final DeleteThing command) { + super(command); + } + + /** + * Returns a new instance of {@code DeleteThingLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link DeleteThing}. + */ + @Nonnull + public static DeleteThingLiveCommandImpl of(final Command command) { + return new DeleteThingLiveCommandImpl((DeleteThing) command); + } + + @Override + public Category getCategory() { + return Category.DELETE; + } + + @Override + public DeleteThingLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return new DeleteThingLiveCommandImpl(DeleteThing.of(getThingEntityId(), dittoHeaders)); + } + + @Override + public boolean changesAuthorization() { + return false; + } + + @Nonnull + @Override + public DeleteThingLiveCommandAnswerBuilder answer() { + return DeleteThingLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommand.java new file mode 100644 index 00000000..31552ac9 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommand.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommand; + +/** + * {@link org.eclipse.ditto.signals.commands.things.modify.MergeThing} live command giving access to the command and all of + * its special accessors. Also the entry point + * for creating a {@link ModifyThingLiveCommandAnswerBuilder} capable of answering incoming commands. + * + * @since 2.0.0 + */ +public interface MergeThingLiveCommand extends LiveCommand, ThingModifyCommand { + + /** + * @return the path where the changes are applied. + */ + JsonPointer getPath(); + + /** + * @return the value describing the changes that are applied to the existing thing. + */ + JsonValue getValue(); + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..a527102c --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommandAnswerBuilder.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.modify.MergeThingResponse; +import org.eclipse.ditto.signals.events.things.ThingMerged; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s and {@code Event}s for + * {@link org.eclipse.ditto.signals.commands.things.modify.MergeThing} commands. + * + * @since 2.0.0 + */ +public interface MergeThingLiveCommandAnswerBuilder extends + LiveCommandAnswerBuilder.ModifyCommandResponseStep { + + /** + * Factory for {@code CommandResponse}s to {@link org.eclipse.ditto.signals.commands.things.modify.MergeThing} + * command. + */ + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Builds a "merged" {@link org.eclipse.ditto.signals.commands.things.modify.MergeThingResponse} using the + * values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + MergeThingResponse merged(); + + /** + * Builds a {@link org.eclipse.ditto.signals.commands.things.ThingErrorResponse} indicating that the Thing was not accessible. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.ThingNotAccessibleException + * ThingNotAccessibleException + */ + @Nonnull + ThingErrorResponse thingNotAccessibleError(); + + /** + * Builds a {@link org.eclipse.ditto.signals.commands.things.ThingErrorResponse} indicating that the Thing was not modifiable. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.ThingNotModifiableException + * ThingNotModifiableException + */ + @Nonnull + ThingErrorResponse thingNotModifiableError(); + } + + /** + * Factory for events triggered by {@link org.eclipse.ditto.signals.commands.things.modify.MergeThing} command. + */ + interface EventFactory extends LiveEventFactory { + + /** + * Creates a {@link org.eclipse.ditto.signals.events.things.ThingMerged} event using the values of the {@code + * Command}. + * + * @return the event. + */ + @Nonnull + ThingMerged merged(); + + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..359fcbbf --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.eclipse.ditto.model.base.common.ConditionChecker.checkNotNull; + +import java.time.Instant; +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.ThingNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.ThingNotModifiableException; +import org.eclipse.ditto.signals.commands.things.modify.MergeThingResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.ThingMerged; + +/** + * A mutable builder with a fluent API for creating a {@link org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer} + * for a {@link MergeThingLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class MergeThingLiveCommandAnswerBuilderImpl + extends + AbstractLiveCommandAnswerBuilder + implements MergeThingLiveCommandAnswerBuilder { + + private MergeThingLiveCommandAnswerBuilderImpl(final MergeThingLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code MergeThingLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static MergeThingLiveCommandAnswerBuilderImpl newInstance(final MergeThingLiveCommand command) { + checkNotNull(command, "command"); + return new MergeThingLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @Override + protected Event doCreateEvent(final Function> createEventFunction) { + return createEventFunction.apply(new EventFactoryImpl()); + } + + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public MergeThingResponse merged() { + return MergeThingResponse.of(command.getThingEntityId(), command.getPath(), command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse thingNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + ThingNotAccessibleException.newBuilder(command.getThingEntityId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + + @Nonnull + @Override + public ThingErrorResponse thingNotModifiableError() { + return errorResponse(command.getThingEntityId(), + ThingNotModifiableException.newBuilder(command.getThingEntityId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + + @Immutable + private final class EventFactoryImpl implements EventFactory { + + @Nonnull + @Override + public ThingMerged merged() { + return ThingMerged.of(command.getThingEntityId(), command.getPath(), command.getValue(), -1, Instant.now(), + command.getDittoHeaders(), null); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommandImpl.java new file mode 100644 index 00000000..5a285eca --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommandImpl.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.modify.MergeThing; + +/** + * An immutable implementation of {@link MergeThingLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class MergeThingLiveCommandImpl extends AbstractModifyLiveCommand implements MergeThingLiveCommand { + + private final JsonPointer path; + private final JsonValue value; + + private MergeThingLiveCommandImpl(final MergeThing command) { + super(command); + path = command.getPath(); + value = command.getValue(); + } + + /** + * Returns a new instance of {@code MergeThingLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.modify.MergeThing}. + */ + @Nonnull + public static MergeThingLiveCommandImpl of(final Command command) { + return new MergeThingLiveCommandImpl((MergeThing) command); + } + + @Override + public JsonPointer getPath() { + return path; + } + + @Override + public JsonValue getValue() { + return value; + } + + @Override + public Category getCategory() { + return Category.MODIFY; + } + + @Override + public MergeThingLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return new MergeThingLiveCommandImpl(MergeThing.of(getThingEntityId(), getPath(), getValue(), dittoHeaders)); + } + + @Override + public boolean changesAuthorization() { + return false; + } + + @Nonnull + @Override + public MergeThingLiveCommandAnswerBuilder answer() { + return MergeThingLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommand.java new file mode 100644 index 00000000..4ffc063b --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommand.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.signals.commands.things.modify.ModifyAttribute; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommand; + +/** + * {@link ModifyAttribute} live command giving access to the command and all of its special accessors. Also the entry + * point for creating a {@link ModifyAttributeLiveCommandAnswerBuilder} capable of answering incoming commands. + * + * @since 2.0.0 + */ +public interface ModifyAttributeLiveCommand + extends LiveCommand, + ThingModifyCommand { + + /** + * Returns the JSON pointer of the attribute to modify. + * + * @return the JSON pointer. + * @see ModifyAttribute#getAttributePointer() + */ + @Nonnull + JsonPointer getAttributePointer(); + + /** + * Returns the value of the attribute to modify. + * + * @return the value. + * @see ModifyAttribute#getAttributeValue() + */ + @Nonnull + JsonValue getAttributeValue(); + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..88296f30 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommandAnswerBuilder.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.modify.ModifyAttribute; +import org.eclipse.ditto.signals.commands.things.modify.ModifyAttributeResponse; +import org.eclipse.ditto.signals.events.things.AttributeCreated; +import org.eclipse.ditto.signals.events.things.AttributeModified; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s and {@code Event}s for {@link ModifyAttribute} + * commands. + * + * @since 2.0.0 + */ +public interface ModifyAttributeLiveCommandAnswerBuilder extends LiveCommandAnswerBuilder.ModifyCommandResponseStep< + ModifyAttributeLiveCommandAnswerBuilder.ResponseFactory, + ModifyAttributeLiveCommandAnswerBuilder.EventFactory> { + + /** + * Factory for {@code CommandResponse}s to {@link ModifyAttribute} command. + */ + @ParametersAreNonnullByDefault + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Builds a "created" {@link ModifyAttributeResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + ModifyAttributeResponse created(); + + /** + * Builds a "modified" {@link ModifyAttributeResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + ModifyAttributeResponse modified(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the attribute was not accessible. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.AttributeNotAccessibleException + * AttributeNotAccessibleException + */ + @Nonnull + ThingErrorResponse attributeNotAccessibleError(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the attribute was not modifiable. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.AttributeNotModifiableException + * AttributeNotModifiableException + */ + @Nonnull + ThingErrorResponse attributeNotModifiableError(); + } + + /** + * Factory for events triggered by {@link ModifyAttribute} command. + */ + interface EventFactory extends LiveEventFactory { + + /** + * Creates a {@link AttributeCreated} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + AttributeCreated created(); + + /** + * Creates a {@link AttributeModified} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + AttributeModified modified(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..24293f8d --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import java.time.Instant; +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.AttributeNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.AttributeNotModifiableException; +import org.eclipse.ditto.signals.commands.things.modify.ModifyAttributeResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.AttributeCreated; +import org.eclipse.ditto.signals.events.things.AttributeModified; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link ModifyAttributeLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class ModifyAttributeLiveCommandAnswerBuilderImpl + extends + AbstractLiveCommandAnswerBuilder + implements ModifyAttributeLiveCommandAnswerBuilder { + + private ModifyAttributeLiveCommandAnswerBuilderImpl(final ModifyAttributeLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code ModifyAttributeLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static ModifyAttributeLiveCommandAnswerBuilderImpl newInstance(final ModifyAttributeLiveCommand command) { + return new ModifyAttributeLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @Override + protected Event doCreateEvent(final Function> createEventFunction) { + return createEventFunction.apply(new EventFactoryImpl()); + } + + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public ModifyAttributeResponse created() { + return ModifyAttributeResponse.created(command.getThingEntityId(), command.getAttributePointer(), + command.getAttributeValue(), + command.getDittoHeaders()); + } + + @Nonnull + @Override + public ModifyAttributeResponse modified() { + return ModifyAttributeResponse.modified(command.getThingEntityId(), command.getAttributePointer(), + command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse attributeNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + AttributeNotAccessibleException.newBuilder(command.getThingEntityId(), + command.getAttributePointer()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + + @Nonnull + @Override + public ThingErrorResponse attributeNotModifiableError() { + return errorResponse(command.getThingEntityId(), + AttributeNotModifiableException.newBuilder(command.getThingEntityId(), + command.getAttributePointer()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + + @Immutable + private final class EventFactoryImpl implements EventFactory { + + @Nonnull + @Override + public AttributeCreated created() { + return AttributeCreated.of(command.getThingEntityId(), command.getAttributePointer(), + command.getAttributeValue(), -1, Instant.now(), command.getDittoHeaders(), null); + } + + @Nonnull + @Override + public AttributeModified modified() { + return AttributeModified.of(command.getThingEntityId(), command.getAttributePointer(), + command.getAttributeValue(), -1, Instant.now(), command.getDittoHeaders(), null); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommandImpl.java new file mode 100644 index 00000000..e6878b1b --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommandImpl.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.modify.ModifyAttribute; + +/** + * An immutable implementation of {@link ModifyAttributeLiveCommand}. + * + * @since 2.0.0 + */ +@Immutable +final class ModifyAttributeLiveCommandImpl extends AbstractModifyLiveCommand implements ModifyAttributeLiveCommand { + + private final JsonPointer attributePointer; + private final JsonValue attributeValue; + + private ModifyAttributeLiveCommandImpl(final ModifyAttribute command) { + super(command); + attributePointer = command.getAttributePointer(); + attributeValue = command.getAttributeValue(); + } + + /** + * Returns a new instance of {@code ModifyAttributeLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link ModifyAttribute}. + */ + @Nonnull + public static ModifyAttributeLiveCommandImpl of(final Command command) { + return new ModifyAttributeLiveCommandImpl((ModifyAttribute) command); + } + + @Nonnull + @Override + public JsonPointer getAttributePointer() { + return attributePointer; + } + + @Nonnull + @Override + public JsonValue getAttributeValue() { + return attributeValue; + } + + @Override + public Category getCategory() { + return Category.MODIFY; + } + + @Override + public ModifyAttributeLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return new ModifyAttributeLiveCommandImpl(ModifyAttribute.of(getThingEntityId(), getAttributePointer(), + getAttributeValue(), dittoHeaders)); + } + + @Override + public boolean changesAuthorization() { + return false; + } + + @Nonnull + @Override + public ModifyAttributeLiveCommandAnswerBuilder answer() { + return ModifyAttributeLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommand.java new file mode 100644 index 00000000..4530c51b --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommand.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.model.things.Attributes; +import org.eclipse.ditto.signals.commands.things.modify.ModifyAttributes; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommand; + +/** + * {@link ModifyAttributes} live command giving access to the command and all of its special accessors. Also the entry + * point for creating a {@link ModifyAttributesLiveCommandAnswerBuilder} capable of answering incoming commands. + * + * @since 2.0.0 + */ +public interface ModifyAttributesLiveCommand extends LiveCommand, ThingModifyCommand { + + /** + * Returns the {@code Attributes} to modify. + * + * @return the Attributes. + * @see ModifyAttributes#getAttributes() + */ + @Nonnull + Attributes getAttributes(); + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..d135df0a --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommandAnswerBuilder.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.modify.ModifyAttributes; +import org.eclipse.ditto.signals.commands.things.modify.ModifyAttributesResponse; +import org.eclipse.ditto.signals.events.things.AttributesCreated; +import org.eclipse.ditto.signals.events.things.AttributesModified; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s and {@code Event}s for {@link ModifyAttributes} + * commands. + * + * @since 2.0.0 + */ +public interface ModifyAttributesLiveCommandAnswerBuilder extends LiveCommandAnswerBuilder.ModifyCommandResponseStep< + ModifyAttributesLiveCommandAnswerBuilder.ResponseFactory, ModifyAttributesLiveCommandAnswerBuilder.EventFactory> { + + /** + * Factory for {@code CommandResponse}s to {@link ModifyAttributes} command. + */ + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Builds a "created" {@link ModifyAttributesResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + ModifyAttributesResponse created(); + + /** + * Builds a "modified" {@link ModifyAttributesResponse} using the values of the {@code Command}. + * + * @return the response + */ + @Nonnull + ModifyAttributesResponse modified(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the attributes were not accessible. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.AttributesNotAccessibleException + * AttributesNotAccessibleException + */ + @Nonnull + ThingErrorResponse attributesNotAccessibleError(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the attributes were not modifiable. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.AttributesNotModifiableException + * AttributesNotModifiableException + */ + @Nonnull + ThingErrorResponse attributesNotModifiableError(); + } + + /** + * Factory for events triggered by {@link ModifyAttributes} command. + */ + interface EventFactory extends LiveEventFactory { + + /** + * Creates a {@link AttributesCreated} event using the values of the {@code Command}. + * + * @return the AttributesCreated event + */ + @Nonnull + AttributesCreated created(); + + /** + * Creates a {@link AttributesModified} event using the values of the {@code Command}. + * + * @return the AttributesModified event + */ + @Nonnull + AttributesModified modified(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..c4a96359 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import java.time.Instant; +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.AttributesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.AttributesNotModifiableException; +import org.eclipse.ditto.signals.commands.things.modify.ModifyAttributesResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.AttributesCreated; +import org.eclipse.ditto.signals.events.things.AttributesModified; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link ModifyAttributesLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class ModifyAttributesLiveCommandAnswerBuilderImpl + extends + AbstractLiveCommandAnswerBuilder + implements ModifyAttributesLiveCommandAnswerBuilder { + + private ModifyAttributesLiveCommandAnswerBuilderImpl(final ModifyAttributesLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code ModifyAttributesLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static ModifyAttributesLiveCommandAnswerBuilderImpl newInstance(final ModifyAttributesLiveCommand command) { + return new ModifyAttributesLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @Override + protected Event doCreateEvent(final Function> createEventFunction) { + return createEventFunction.apply(new EventFactoryImpl()); + } + + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public ModifyAttributesResponse created() { + return ModifyAttributesResponse.created(command.getThingEntityId(), command.getAttributes(), + command.getDittoHeaders()); + } + + @Nonnull + @Override + public ModifyAttributesResponse modified() { + return ModifyAttributesResponse.modified(command.getThingEntityId(), command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse attributesNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + AttributesNotAccessibleException.newBuilder(command.getThingEntityId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + + @Nonnull + @Override + public ThingErrorResponse attributesNotModifiableError() { + return errorResponse(command.getThingEntityId(), + AttributesNotModifiableException.newBuilder(command.getThingEntityId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + + @Immutable + private final class EventFactoryImpl implements EventFactory { + + @Nonnull + @Override + public AttributesCreated created() { + return AttributesCreated.of(command.getThingEntityId(), command.getAttributes(), -1, Instant.now(), + command.getDittoHeaders(), null); + } + + @Nonnull + @Override + public AttributesModified modified() { + return AttributesModified.of(command.getThingEntityId(), command.getAttributes(), -1, Instant.now(), + command.getDittoHeaders(), null); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommandImpl.java new file mode 100644 index 00000000..32cc8c41 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommandImpl.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.Attributes; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.modify.ModifyAttributes; + +/** + * An immutable implementation of {@link ModifyAttributesLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class ModifyAttributesLiveCommandImpl extends AbstractModifyLiveCommand implements ModifyAttributesLiveCommand { + + private final Attributes attributes; + + private ModifyAttributesLiveCommandImpl(final ModifyAttributes command) { + super(command); + attributes = command.getAttributes(); + } + + /** + * Returns a new instance of {@code ModifyAttributesLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link ModifyAttributes}. + */ + @Nonnull + public static ModifyAttributesLiveCommandImpl of(final Command command) { + return new ModifyAttributesLiveCommandImpl((ModifyAttributes) command); + } + + @Nonnull + @Override + public Attributes getAttributes() { + return attributes; + } + + @Override + public Category getCategory() { + return Category.MODIFY; + } + + @Override + public ModifyAttributesLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return new ModifyAttributesLiveCommandImpl( + ModifyAttributes.of(getThingEntityId(), getAttributes(), dittoHeaders)); + } + + @Override + public boolean changesAuthorization() { + return false; + } + + @Nonnull + @Override + public ModifyAttributesLiveCommandAnswerBuilder answer() { + return ModifyAttributesLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommand.java new file mode 100644 index 00000000..247035bd --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommand.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.model.things.FeatureDefinition; +import org.eclipse.ditto.signals.base.WithFeatureId; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureDefinition; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommand; + +/** + * {@link ModifyFeatureDefinition} live command giving access to the command and all of its special accessors. + * Also the entry point for creating a {@link ModifyFeatureDefinitionLiveCommandAnswerBuilder} as answer for an incoming + * command. + * + * @since 2.0.0 + */ +public interface ModifyFeatureDefinitionLiveCommand extends LiveCommand, ThingModifyCommand, + WithFeatureId { + + /** + * Returns the {@link FeatureDefinition} to modify. + * + * @return the Properties to modify. + * @see ModifyFeatureDefinition#getDefinition() + */ + @Nonnull + FeatureDefinition getDefinition(); + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..c4382f14 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommandAnswerBuilder.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureDefinition; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureDefinitionResponse; +import org.eclipse.ditto.signals.events.things.FeatureDefinitionCreated; +import org.eclipse.ditto.signals.events.things.FeatureDefinitionModified; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s and {@code Event}s for + * {@link ModifyFeatureDefinition} commands. + * + * @since 2.0.0 + */ +public interface ModifyFeatureDefinitionLiveCommandAnswerBuilder extends + LiveCommandAnswerBuilder.ModifyCommandResponseStep { + + /** + * Factory for {@code CommandResponse}s to {@link ModifyFeatureDefinition} command. + */ + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Builds a "created" {@link ModifyFeatureDefinitionResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + ModifyFeatureDefinitionResponse created(); + + /** + * Builds a "modified" {@link ModifyFeatureDefinitionResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + public ModifyFeatureDefinitionResponse modified(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the Feature Definition was not accessible. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeatureDefinitionNotAccessibleException + * FeatureDefinitionNotAccessibleException + */ + @Nonnull + ThingErrorResponse featureDefinitionNotAccessibleError(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the Feature Definition was not modifiable. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeatureDefinitionNotModifiableException + * FeatureDefinitionNotModifiableException + */ + @Nonnull + ThingErrorResponse featureDefinitionNotModifiableError(); + + } + + /** + * Factory for events triggered by {@link ModifyFeatureDefinition} command. + */ + interface EventFactory extends LiveEventFactory { + + /** + * Creates a {@link FeatureDefinitionCreated} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + FeatureDefinitionCreated created(); + + /** + * Creates a {@link FeatureDefinitionModified} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + FeatureDefinitionModified modified(); + + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..37fe146e --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import java.time.Instant; +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDefinitionNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDefinitionNotModifiableException; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureDefinitionResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.FeatureDefinitionCreated; +import org.eclipse.ditto.signals.events.things.FeatureDefinitionModified; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link ModifyFeatureDefinitionLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class ModifyFeatureDefinitionLiveCommandAnswerBuilderImpl + extends AbstractLiveCommandAnswerBuilder + implements ModifyFeatureDefinitionLiveCommandAnswerBuilder { + + private ModifyFeatureDefinitionLiveCommandAnswerBuilderImpl(final ModifyFeatureDefinitionLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code ModifyFeatureDefinitionLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static ModifyFeatureDefinitionLiveCommandAnswerBuilderImpl newInstance( + final ModifyFeatureDefinitionLiveCommand command) { + return new ModifyFeatureDefinitionLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @Override + protected Event doCreateEvent(final Function> createEventFunction) { + return createEventFunction.apply(new EventFactoryImpl()); + } + + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public ModifyFeatureDefinitionResponse created() { + return ModifyFeatureDefinitionResponse.created(command.getThingEntityId(), command.getFeatureId(), + command.getDefinition(), + command.getDittoHeaders()); + } + + @Nonnull + @Override + public ModifyFeatureDefinitionResponse modified() { + return ModifyFeatureDefinitionResponse.modified(command.getThingEntityId(), command.getFeatureId(), + command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse featureDefinitionNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + FeatureDefinitionNotAccessibleException.newBuilder(command.getThingEntityId(), + command.getFeatureId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + + @Nonnull + @Override + public ThingErrorResponse featureDefinitionNotModifiableError() { + return errorResponse(command.getThingEntityId(), + FeatureDefinitionNotModifiableException.newBuilder(command.getThingEntityId(), + command.getFeatureId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + + } + + @Immutable + private final class EventFactoryImpl implements EventFactory { + + @Nonnull + @Override + public FeatureDefinitionCreated created() { + return FeatureDefinitionCreated.of(command.getThingEntityId(), command.getFeatureId(), + command.getDefinition(), -1, Instant.now(), command.getDittoHeaders(), null); + } + + @Nonnull + @Override + public FeatureDefinitionModified modified() { + return FeatureDefinitionModified.of(command.getThingEntityId(), command.getFeatureId(), + command.getDefinition(), -1, Instant.now(), command.getDittoHeaders(), null); + } + + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommandImpl.java new file mode 100644 index 00000000..3563971a --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommandImpl.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.FeatureDefinition; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureDefinition; +import org.eclipse.ditto.utils.jsr305.annotations.AllValuesAreNonnullByDefault; + +/** + * An immutable implementation of {@link ModifyFeatureDefinitionLiveCommand}. + * + * @since 2.0.0 + */ +@AllValuesAreNonnullByDefault +@Immutable +final class ModifyFeatureDefinitionLiveCommandImpl + extends + AbstractModifyLiveCommand + implements ModifyFeatureDefinitionLiveCommand { + + private final String featureId; + private final FeatureDefinition featureProperties; + + private ModifyFeatureDefinitionLiveCommandImpl(final ModifyFeatureDefinition command) { + super(command); + featureId = command.getFeatureId(); + featureProperties = command.getDefinition(); + } + + /** + * Returns a new instance of {@code ModifyFeatureDefinitionLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link ModifyFeatureDefinition}. + */ + @Nonnull + public static ModifyFeatureDefinitionLiveCommandImpl of(final Command command) { + return new ModifyFeatureDefinitionLiveCommandImpl((ModifyFeatureDefinition) command); + } + + @Override + public String getFeatureId() { + return featureId; + } + + @Nonnull + @Override + public FeatureDefinition getDefinition() { + return featureProperties; + } + + @Override + public Category getCategory() { + return Category.MODIFY; + } + + @Override + public ModifyFeatureDefinitionLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return new ModifyFeatureDefinitionLiveCommandImpl(ModifyFeatureDefinition.of(getThingEntityId(), getFeatureId(), + getDefinition(), dittoHeaders)); + } + + @Override + public boolean changesAuthorization() { + return false; + } + + @Nonnull + @Override + public ModifyFeatureDefinitionLiveCommandAnswerBuilder answer() { + return ModifyFeatureDefinitionLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommand.java new file mode 100644 index 00000000..1220ba42 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommand.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.model.things.FeatureProperties; +import org.eclipse.ditto.signals.base.WithFeatureId; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureDesiredProperties; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommand; + +/** + * {@link ModifyFeatureDesiredProperties} live command giving access to the command and all of its special accessors. + * Also the entry point for creating a {@link ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilder} as answer for + * an incoming command. + * + * @since 2.0.0 + */ +public interface ModifyFeatureDesiredPropertiesLiveCommand extends LiveCommand, ThingModifyCommand, + WithFeatureId { + + /** + * Returns the {desired properties to modify. + * + * @return the Properties to modify. + * @see org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureDesiredProperties#getDesiredProperties() () + */ + @Nonnull + FeatureProperties getDesiredProperties(); + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..c16c257b --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilder.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureDesiredProperties; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureDesiredPropertiesResponse; +import org.eclipse.ditto.signals.events.things.FeatureDesiredPropertiesCreated; +import org.eclipse.ditto.signals.events.things.FeatureDesiredPropertiesModified; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s and {@code Event}s for + * {@link ModifyFeatureDesiredProperties} commands. + * + * @since 2.0.0 + */ +public interface ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilder + extends LiveCommandAnswerBuilder.ModifyCommandResponseStep< + ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilder.ResponseFactory, + ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilder.EventFactory> { + + /** + * Factory for {@code CommandResponse}s to {@link ModifyFeatureDesiredProperties} command. + */ + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Builds a "created" {@link ModifyFeatureDesiredPropertiesResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + ModifyFeatureDesiredPropertiesResponse created(); + + /** + * Builds a "modified" {@link ModifyFeatureDesiredPropertiesResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + public ModifyFeatureDesiredPropertiesResponse modified(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the feature's desired properties were not accessible. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertiesNotAccessibleException + * FeatureDesiredPropertiesNotAccessibleException + */ + @Nonnull + ThingErrorResponse featureDesiredPropertiesNotAccessibleError(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the feature's desired properties were not modifiable. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertiesNotModifiableException + * FeatureDesiredPropertiesNotModifiableException + */ + @Nonnull + ThingErrorResponse featureDesiredPropertiesNotModifiableError(); + } + + /** + * Factory for events triggered by {@link ModifyFeatureDesiredProperties} command. + */ + interface EventFactory extends LiveEventFactory { + + /** + * Creates a {@link FeatureDesiredPropertiesCreated} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + FeatureDesiredPropertiesCreated created(); + + /** + * Creates a {@link FeatureDesiredPropertiesModified} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + FeatureDesiredPropertiesModified modified(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..614145a6 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import java.time.Instant; +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertiesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertiesNotModifiableException; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureDesiredPropertiesResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.FeatureDesiredPropertiesCreated; +import org.eclipse.ditto.signals.events.things.FeatureDesiredPropertiesModified; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link ModifyFeatureDesiredPropertiesLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl + extends + AbstractLiveCommandAnswerBuilder + implements ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilder { + + private ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl( + final ModifyFeatureDesiredPropertiesLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl newInstance( + final ModifyFeatureDesiredPropertiesLiveCommand command) { + return new ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @Override + protected Event doCreateEvent(final Function> createEventFunction) { + return createEventFunction.apply(new EventFactoryImpl()); + } + + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public ModifyFeatureDesiredPropertiesResponse created() { + return ModifyFeatureDesiredPropertiesResponse.created(command.getThingEntityId(), command.getFeatureId(), + command.getDesiredProperties(), + command.getDittoHeaders()); + } + + @Nonnull + @Override + public ModifyFeatureDesiredPropertiesResponse modified() { + return ModifyFeatureDesiredPropertiesResponse.modified(command.getThingEntityId(), command.getFeatureId(), + command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse featureDesiredPropertiesNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + FeatureDesiredPropertiesNotAccessibleException.newBuilder(command.getThingEntityId(), + command.getFeatureId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + + @Nonnull + @Override + public ThingErrorResponse featureDesiredPropertiesNotModifiableError() { + return errorResponse(command.getThingEntityId(), + FeatureDesiredPropertiesNotModifiableException.newBuilder(command.getThingEntityId(), + command.getFeatureId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + + @Immutable + private final class EventFactoryImpl implements EventFactory { + + @Nonnull + @Override + public FeatureDesiredPropertiesCreated created() { + return FeatureDesiredPropertiesCreated.of(command.getThingEntityId(), command.getFeatureId(), + command.getDesiredProperties(), -1, Instant.now(), command.getDittoHeaders(), null); + } + + @Nonnull + @Override + public FeatureDesiredPropertiesModified modified() { + return FeatureDesiredPropertiesModified.of(command.getThingEntityId(), command.getFeatureId(), + command.getDesiredProperties(), -1, Instant.now(), command.getDittoHeaders(), null); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommandImpl.java new file mode 100644 index 00000000..fe0aa700 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommandImpl.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.FeatureProperties; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureDesiredProperties; + +/** + * An immutable implementation of {@link ModifyFeatureDesiredPropertiesLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class ModifyFeatureDesiredPropertiesLiveCommandImpl + extends + AbstractModifyLiveCommand + implements ModifyFeatureDesiredPropertiesLiveCommand { + + private final String featureId; + private final FeatureProperties desiredProperties; + + private ModifyFeatureDesiredPropertiesLiveCommandImpl(final ModifyFeatureDesiredProperties command) { + super(command); + featureId = command.getFeatureId(); + desiredProperties = command.getDesiredProperties(); + } + + + /** + * Returns a new instance of {@code ModifyFeatureDesiredPropertiesLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link ModifyFeatureDesiredProperties}. + */ + @Nonnull + public static ModifyFeatureDesiredPropertiesLiveCommandImpl of(final Command command) { + return new ModifyFeatureDesiredPropertiesLiveCommandImpl((ModifyFeatureDesiredProperties) command); + } + + @Override + public String getFeatureId() { + return featureId; + } + + @Nonnull + @Override + public FeatureProperties getDesiredProperties() { + return desiredProperties; + } + + @Override + public Category getCategory() { + return Category.MODIFY; + } + + @Override + public ModifyFeatureDesiredPropertiesLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return new ModifyFeatureDesiredPropertiesLiveCommandImpl( + ModifyFeatureDesiredProperties.of(getThingEntityId(), getFeatureId(), + getDesiredProperties(), dittoHeaders)); + } + + @Override + public boolean changesAuthorization() { + return false; + } + + @Nonnull + @Override + public ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilder answer() { + return ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommand.java new file mode 100644 index 00000000..de3e9b61 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommand.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.signals.base.WithFeatureId; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureDesiredProperty; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommand; + +/** + * {@link ModifyFeatureDesiredProperty} live command giving access to the command and all of its special accessors. + * Also the entry point for creating a {@link ModifyFeatureDesiredPropertyLiveCommandAnswerBuilder} as answer + * for an incoming command. + * + * @since 2.0.0 + */ +public interface ModifyFeatureDesiredPropertyLiveCommand + extends + LiveCommand, + ThingModifyCommand, WithFeatureId { + + /** + * Returns the JSON pointer of the Property to modify. + * + * @return the JSON pointer. + * @see org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureDesiredProperty#getDesiredPropertyPointer() () + */ + @Nonnull + JsonPointer getDesiredPropertyPointer(); + + /** + * Returns the value of the Property to modify. + * + * @return the value. + * @see org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureDesiredProperty#getDesiredPropertyValue() () + */ + @Nonnull + JsonValue getDesiredPropertyValue(); + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..8813568a --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommandAnswerBuilder.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureDesiredProperty; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureDesiredPropertyResponse; +import org.eclipse.ditto.signals.events.things.FeatureDesiredPropertyCreated; +import org.eclipse.ditto.signals.events.things.FeatureDesiredPropertyModified; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s and {@code Event}s for + * {@link ModifyFeatureDesiredProperty} commands. + * + * @since 2.0.0 + */ +public interface ModifyFeatureDesiredPropertyLiveCommandAnswerBuilder + extends LiveCommandAnswerBuilder.ModifyCommandResponseStep< + ModifyFeatureDesiredPropertyLiveCommandAnswerBuilder.ResponseFactory, + ModifyFeatureDesiredPropertyLiveCommandAnswerBuilder.EventFactory> { + + /** + * Factory for {@code CommandResponse}s to {@link ModifyFeatureDesiredProperty} command. + */ + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Builds a "created" {@link ModifyFeatureDesiredPropertyResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + ModifyFeatureDesiredPropertyResponse created(); + + /** + * Builds a "modified" {@link ModifyFeatureDesiredPropertyResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + ModifyFeatureDesiredPropertyResponse modified(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the feature's desired property was not accessible. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertyNotAccessibleException + * FeatureDesiredPropertyNotAccessibleException + */ + @Nonnull + ThingErrorResponse featureDesiredPropertyNotAccessibleError(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the feature's desired property was not modifiable. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertyNotModifiableException + * FeatureDesiredPropertyNotModifiableException + */ + @Nonnull + ThingErrorResponse featureDesiredPropertyNotModifiableError(); + } + + /** + * Factory for events triggered by {@link ModifyFeatureDesiredProperty} command. + */ + interface EventFactory extends LiveEventFactory { + + /** + * Creates a {@link FeatureDesiredPropertyCreated} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + FeatureDesiredPropertyCreated created(); + + /** + * Creates a {@link FeatureDesiredPropertyModified} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + FeatureDesiredPropertyModified modified(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..5059d2ac --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import java.time.Instant; +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertyNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertyNotModifiableException; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureDesiredPropertyResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.FeatureDesiredPropertyCreated; +import org.eclipse.ditto.signals.events.things.FeatureDesiredPropertyModified; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link ModifyFeatureDesiredPropertyLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class ModifyFeatureDesiredPropertyLiveCommandAnswerBuilderImpl + extends AbstractLiveCommandAnswerBuilder + implements ModifyFeatureDesiredPropertyLiveCommandAnswerBuilder { + + private ModifyFeatureDesiredPropertyLiveCommandAnswerBuilderImpl( + final ModifyFeatureDesiredPropertyLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code ModifyFeatureDesiredPropertyLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static ModifyFeatureDesiredPropertyLiveCommandAnswerBuilderImpl newInstance( + final ModifyFeatureDesiredPropertyLiveCommand command) { + return new ModifyFeatureDesiredPropertyLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @Override + protected Event doCreateEvent(final Function> createEventFunction) { + return createEventFunction.apply(new EventFactoryImpl()); + } + + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public ModifyFeatureDesiredPropertyResponse created() { + return ModifyFeatureDesiredPropertyResponse.created(command.getThingEntityId(), command.getFeatureId(), + command.getDesiredPropertyPointer(), + command.getDesiredPropertyValue(), command.getDittoHeaders()); + } + + @Nonnull + @Override + public ModifyFeatureDesiredPropertyResponse modified() { + return ModifyFeatureDesiredPropertyResponse.modified(command.getThingEntityId(), command.getFeatureId(), + command.getDesiredPropertyPointer(), + command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse featureDesiredPropertyNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + FeatureDesiredPropertyNotAccessibleException.newBuilder(command.getThingEntityId(), + command.getFeatureId(), + command.getDesiredPropertyPointer()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + + @Nonnull + @Override + public ThingErrorResponse featureDesiredPropertyNotModifiableError() { + return errorResponse(command.getThingEntityId(), + FeatureDesiredPropertyNotModifiableException.newBuilder(command.getThingEntityId(), + command.getFeatureId(), command.getDesiredPropertyPointer()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + + @Immutable + private final class EventFactoryImpl implements EventFactory { + + @Nonnull + @Override + public FeatureDesiredPropertyCreated created() { + return FeatureDesiredPropertyCreated.of(command.getThingEntityId(), command.getFeatureId(), + command.getDesiredPropertyPointer(), + command.getDesiredPropertyValue(), -1, Instant.now(), command.getDittoHeaders(), null); + } + + @Nonnull + @Override + public FeatureDesiredPropertyModified modified() { + return FeatureDesiredPropertyModified.of(command.getThingEntityId(), command.getFeatureId(), + command.getDesiredPropertyPointer(), command.getDesiredPropertyValue(), -1, Instant.now(), + command.getDittoHeaders(), null); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommandImpl.java new file mode 100644 index 00000000..5cbcce56 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommandImpl.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureDesiredProperty; + +/** + * An immutable implementation of {@link ModifyFeatureDesiredPropertyLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class ModifyFeatureDesiredPropertyLiveCommandImpl + extends + AbstractModifyLiveCommand + implements ModifyFeatureDesiredPropertyLiveCommand { + + private final String featureId; + private final JsonPointer desiredPropertyPointer; + private final JsonValue desiredPropertyValue; + + private ModifyFeatureDesiredPropertyLiveCommandImpl(final ModifyFeatureDesiredProperty command) { + super(command); + featureId = command.getFeatureId(); + desiredPropertyPointer = command.getDesiredPropertyPointer(); + desiredPropertyValue = command.getDesiredPropertyValue(); + } + + /** + * Returns a new instance of {@code ModifyFeatureDesiredPropertyLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link ModifyFeatureDesiredProperty}. + */ + @Nonnull + public static ModifyFeatureDesiredPropertyLiveCommandImpl of(final Command command) { + return new ModifyFeatureDesiredPropertyLiveCommandImpl((ModifyFeatureDesiredProperty) command); + } + + @Override + public String getFeatureId() { + return featureId; + } + + @Nonnull + @Override + public JsonPointer getDesiredPropertyPointer() { + return desiredPropertyPointer; + } + + @Nonnull + @Override + public JsonValue getDesiredPropertyValue() { + return desiredPropertyValue; + } + + @Override + public Category getCategory() { + return Category.MODIFY; + } + + @Override + public ModifyFeatureDesiredPropertyLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return new ModifyFeatureDesiredPropertyLiveCommandImpl( + ModifyFeatureDesiredProperty.of(getThingEntityId(), getFeatureId(), + getDesiredPropertyPointer(), getDesiredPropertyValue(), dittoHeaders)); + } + + @Override + public boolean changesAuthorization() { + return false; + } + + @Nonnull + @Override + public ModifyFeatureDesiredPropertyLiveCommandAnswerBuilder answer() { + return ModifyFeatureDesiredPropertyLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommand.java new file mode 100644 index 00000000..817ca675 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommand.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.model.things.Feature; +import org.eclipse.ditto.signals.base.WithFeatureId; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeature; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommand; + +/** + * {@link ModifyFeature} live command giving access to the command and all of its special accessors. Also the entry + * point for creating a {@link ModifyFeatureLiveCommandAnswerBuilder} capable of answering incoming commands. + * + * @since 2.0.0 + */ +public interface ModifyFeatureLiveCommand extends + LiveCommand, + ThingModifyCommand, + WithFeatureId { + + /** + * Returns the new {@code Feature} to modify. + * + * @return the Feature to modify + */ + @Nonnull + Feature getFeature(); + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..0016cbb2 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommandAnswerBuilder.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeature; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureResponse; +import org.eclipse.ditto.signals.events.things.FeatureCreated; +import org.eclipse.ditto.signals.events.things.FeatureModified; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s and {@code Event}s for {@link ModifyFeature} + * commands. + * + * @since 2.0.0 + */ +public interface ModifyFeatureLiveCommandAnswerBuilder extends LiveCommandAnswerBuilder.ModifyCommandResponseStep< + ModifyFeatureLiveCommandAnswerBuilder.ResponseFactory, ModifyFeatureLiveCommandAnswerBuilder.EventFactory> { + + /** + * Factory for {@code CommandResponse}s to {@link ModifyFeature} command. + */ + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Builds a "created" {@link ModifyFeatureResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + ModifyFeatureResponse created(); + + /** + * Builds a "modified" {@link ModifyFeatureResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + ModifyFeatureResponse modified(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the feature was not accessible. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeatureNotAccessibleException + * FeatureNotAccessibleException + */ + @Nonnull + ThingErrorResponse featureNotAccessibleError(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the feature was not modifiable. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeatureNotModifiableException + * FeatureNotModifiableException + */ + @Nonnull + ThingErrorResponse featureNotModifiableError(); + } + + /** + * Factory for events triggered by {@link ModifyFeature} command. + */ + interface EventFactory extends LiveEventFactory { + + /** + * Creates a {@link FeatureCreated} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + FeatureCreated created(); + + /** + * Creates a {@link FeatureModified} event using the values of the {@code Command}. + * + * @return the FeatureModified event + */ + @Nonnull + FeatureModified modified(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..3c046c3f --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import java.time.Instant; +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureNotModifiableException; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.FeatureCreated; +import org.eclipse.ditto.signals.events.things.FeatureModified; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a {@link ModifyFeatureLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class ModifyFeatureLiveCommandAnswerBuilderImpl + extends + AbstractLiveCommandAnswerBuilder + implements ModifyFeatureLiveCommandAnswerBuilder { + + private ModifyFeatureLiveCommandAnswerBuilderImpl(final ModifyFeatureLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code ModifyFeatureLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static ModifyFeatureLiveCommandAnswerBuilderImpl newInstance(final ModifyFeatureLiveCommand command) { + return new ModifyFeatureLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @Override + protected Event doCreateEvent(final Function> createEventFunction) { + return createEventFunction.apply(new EventFactoryImpl()); + } + + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public ModifyFeatureResponse created() { + return ModifyFeatureResponse.created(command.getThingEntityId(), command.getFeature(), + command.getDittoHeaders()); + } + + @Nonnull + @Override + public ModifyFeatureResponse modified() { + return ModifyFeatureResponse.modified(command.getThingEntityId(), command.getFeatureId(), + command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse featureNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + FeatureNotAccessibleException.newBuilder(command.getThingEntityId(), command.getFeatureId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + + @Nonnull + @Override + public ThingErrorResponse featureNotModifiableError() { + return errorResponse(command.getThingEntityId(), + FeatureNotModifiableException.newBuilder(command.getThingEntityId(), command.getFeatureId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + + @Immutable + private final class EventFactoryImpl implements EventFactory { + + @Nonnull + @Override + public FeatureCreated created() { + return FeatureCreated.of(command.getThingEntityId(), command.getFeature(), -1, Instant.now(), + command.getDittoHeaders(), null); + } + + @Nonnull + @Override + public FeatureModified modified() { + return FeatureModified.of(command.getThingEntityId(), command.getFeature(), -1, Instant.now(), + command.getDittoHeaders(), null); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommandImpl.java new file mode 100644 index 00000000..e270c626 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommandImpl.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.Feature; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeature; + +/** + * An immutable implementation of {@link ModifyFeatureLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class ModifyFeatureLiveCommandImpl extends AbstractModifyLiveCommand implements ModifyFeatureLiveCommand { + + private final Feature feature; + + private ModifyFeatureLiveCommandImpl(final ModifyFeature command) { + super(command); + feature = command.getFeature(); + } + + /** + * Returns a new instance of {@code ModifyFeatureLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link ModifyFeature}. + */ + @Nonnull + public static ModifyFeatureLiveCommandImpl of(final Command command) { + return new ModifyFeatureLiveCommandImpl((ModifyFeature) command); + } + + @Override + public String getFeatureId() { + return feature.getId(); + } + + @Nonnull + @Override + public Feature getFeature() { + return feature; + } + + @Override + public Category getCategory() { + return Category.MODIFY; + } + + @Override + public ModifyFeatureLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return new ModifyFeatureLiveCommandImpl(ModifyFeature.of(getThingEntityId(), getFeature(), dittoHeaders)); + } + + @Override + public boolean changesAuthorization() { + return false; + } + + @Nonnull + @Override + public ModifyFeatureLiveCommandAnswerBuilder answer() { + return ModifyFeatureLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommand.java new file mode 100644 index 00000000..e2ce4e7b --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommand.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.model.things.FeatureProperties; +import org.eclipse.ditto.signals.base.WithFeatureId; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureProperties; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommand; + +/** + * {@link ModifyFeatureProperties} live command giving access to the command and all of its special accessors. + * Also the entry point for creating a {@link ModifyFeaturePropertiesLiveCommandAnswerBuilder} as answer for an incoming + * command. + * + * @since 2.0.0 + */ +public interface ModifyFeaturePropertiesLiveCommand extends LiveCommand, ThingModifyCommand, + WithFeatureId { + + /** + * Returns the {@link FeatureProperties} to modify. + * + * @return the Properties to modify. + * @see ModifyFeatureProperties#getProperties() + */ + @Nonnull + FeatureProperties getProperties(); + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..627834a5 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommandAnswerBuilder.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureProperties; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeaturePropertiesResponse; +import org.eclipse.ditto.signals.events.things.FeaturePropertiesCreated; +import org.eclipse.ditto.signals.events.things.FeaturePropertiesModified; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s and {@code Event}s for + * {@link ModifyFeatureProperties} commands. + * + * @since 2.0.0 + */ +public interface ModifyFeaturePropertiesLiveCommandAnswerBuilder + extends LiveCommandAnswerBuilder.ModifyCommandResponseStep< + ModifyFeaturePropertiesLiveCommandAnswerBuilder.ResponseFactory, + ModifyFeaturePropertiesLiveCommandAnswerBuilder.EventFactory> { + + /** + * Factory for {@code CommandResponse}s to {@link ModifyFeatureProperties} command. + */ + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Builds a "created" {@link ModifyFeaturePropertiesResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + ModifyFeaturePropertiesResponse created(); + + /** + * Builds a "modified" {@link ModifyFeaturePropertiesResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + public ModifyFeaturePropertiesResponse modified(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the feature properties were not accessible. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertiesNotAccessibleException + * FeaturePropertiesNotAccessibleException + */ + @Nonnull + ThingErrorResponse featurePropertiesNotAccessibleError(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the feature properties were not modifiable. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertiesNotModifiableException + * FeaturePropertiesNotModifiableException + */ + @Nonnull + ThingErrorResponse featurePropertiesNotModifiableError(); + } + + /** + * Factory for events triggered by {@link ModifyFeatureProperties} command. + */ + interface EventFactory extends LiveEventFactory { + + /** + * Creates a {@link FeaturePropertiesCreated} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + FeaturePropertiesCreated created(); + + /** + * Creates a {@link FeaturePropertiesModified} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + FeaturePropertiesModified modified(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..87accc73 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import java.time.Instant; +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertiesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertiesNotModifiableException; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeaturePropertiesResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.FeaturePropertiesCreated; +import org.eclipse.ditto.signals.events.things.FeaturePropertiesModified; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link ModifyFeaturePropertiesLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class ModifyFeaturePropertiesLiveCommandAnswerBuilderImpl + extends + AbstractLiveCommandAnswerBuilder + implements ModifyFeaturePropertiesLiveCommandAnswerBuilder { + + private ModifyFeaturePropertiesLiveCommandAnswerBuilderImpl(final ModifyFeaturePropertiesLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code ModifyFeaturePropertiesLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static ModifyFeaturePropertiesLiveCommandAnswerBuilderImpl newInstance( + final ModifyFeaturePropertiesLiveCommand command) { + return new ModifyFeaturePropertiesLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @Override + protected Event doCreateEvent(final Function> createEventFunction) { + return createEventFunction.apply(new EventFactoryImpl()); + } + + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public ModifyFeaturePropertiesResponse created() { + return ModifyFeaturePropertiesResponse.created(command.getThingEntityId(), command.getFeatureId(), + command.getProperties(), + command.getDittoHeaders()); + } + + @Nonnull + @Override + public ModifyFeaturePropertiesResponse modified() { + return ModifyFeaturePropertiesResponse.modified(command.getThingEntityId(), command.getFeatureId(), + command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse featurePropertiesNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + FeaturePropertiesNotAccessibleException.newBuilder(command.getThingEntityId(), + command.getFeatureId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + + @Nonnull + @Override + public ThingErrorResponse featurePropertiesNotModifiableError() { + return errorResponse(command.getThingEntityId(), + FeaturePropertiesNotModifiableException.newBuilder(command.getThingEntityId(), + command.getFeatureId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + + @Immutable + private final class EventFactoryImpl implements EventFactory { + + @Nonnull + @Override + public FeaturePropertiesCreated created() { + return FeaturePropertiesCreated.of(command.getThingEntityId(), command.getFeatureId(), + command.getProperties(), -1, Instant.now(), command.getDittoHeaders(), null); + } + + @Nonnull + @Override + public FeaturePropertiesModified modified() { + return FeaturePropertiesModified.of(command.getThingEntityId(), command.getFeatureId(), + command.getProperties(), -1, Instant.now(), command.getDittoHeaders(), null); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommandImpl.java new file mode 100644 index 00000000..113318fa --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommandImpl.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.FeatureProperties; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureProperties; + +/** + * An immutable implementation of {@link ModifyFeaturePropertiesLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class ModifyFeaturePropertiesLiveCommandImpl + extends + AbstractModifyLiveCommand + implements ModifyFeaturePropertiesLiveCommand { + + private final String featureId; + private final FeatureProperties featureProperties; + + private ModifyFeaturePropertiesLiveCommandImpl(final ModifyFeatureProperties command) { + super(command); + featureId = command.getFeatureId(); + featureProperties = command.getProperties(); + } + + /** + * Returns a new instance of {@code ModifyFeaturePropertiesLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link ModifyFeatureProperties}. + */ + @Nonnull + public static ModifyFeaturePropertiesLiveCommandImpl of(final Command command) { + return new ModifyFeaturePropertiesLiveCommandImpl((ModifyFeatureProperties) command); + } + + @Override + public String getFeatureId() { + return featureId; + } + + @Nonnull + @Override + public FeatureProperties getProperties() { + return featureProperties; + } + + @Override + public Category getCategory() { + return Category.MODIFY; + } + + @Override + public ModifyFeaturePropertiesLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return new ModifyFeaturePropertiesLiveCommandImpl(ModifyFeatureProperties.of(getThingEntityId(), getFeatureId(), + getProperties(), dittoHeaders)); + } + + @Override + public boolean changesAuthorization() { + return false; + } + + @Nonnull + @Override + public ModifyFeaturePropertiesLiveCommandAnswerBuilder answer() { + return ModifyFeaturePropertiesLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommand.java new file mode 100644 index 00000000..737bdf9c --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommand.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.signals.base.WithFeatureId; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureProperty; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommand; + +/** + * {@link ModifyFeatureProperty} live command giving access to the command and all of its special accessors. + * Also the entry point for creating a {@link ModifyFeaturePropertyLiveCommandAnswerBuilder} as answer for + * an incoming command. + * + * @since 2.0.0 + */ +public interface ModifyFeaturePropertyLiveCommand + extends LiveCommand, + ThingModifyCommand, WithFeatureId { + + /** + * Returns the JSON pointer of the Property to modify. + * + * @return the JSON pointer. + * @see ModifyFeatureProperty#getPropertyPointer() + */ + @Nonnull + JsonPointer getPropertyPointer(); + + /** + * Returns the value of the Property to modify. + * + * @return the value. + * @see ModifyFeatureProperty#getPropertyValue() + */ + @Nonnull + JsonValue getPropertyValue(); + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..86b4e8e8 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommandAnswerBuilder.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureProperty; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeaturePropertyResponse; +import org.eclipse.ditto.signals.events.things.FeaturePropertyCreated; +import org.eclipse.ditto.signals.events.things.FeaturePropertyModified; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s and {@code Event}s for {@link ModifyFeatureProperty} + * commands. + * + * @since 2.0.0 + */ +public interface ModifyFeaturePropertyLiveCommandAnswerBuilder + extends LiveCommandAnswerBuilder.ModifyCommandResponseStep< + ModifyFeaturePropertyLiveCommandAnswerBuilder.ResponseFactory, + ModifyFeaturePropertyLiveCommandAnswerBuilder.EventFactory> { + + /** + * Factory for {@code CommandResponse}s to {@link ModifyFeatureProperty} command. + */ + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Builds a "created" {@link ModifyFeaturePropertyResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + ModifyFeaturePropertyResponse created(); + + /** + * Builds a "modified" {@link ModifyFeaturePropertyResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + ModifyFeaturePropertyResponse modified(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the feature property was not accessible. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertyNotAccessibleException + * FeaturePropertyNotAccessibleException + */ + @Nonnull + ThingErrorResponse featurePropertyNotAccessibleError(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the feature property was not modifiable. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertyNotModifiableException + * FeaturePropertyNotModifiableException + */ + @Nonnull + ThingErrorResponse featurePropertyNotModifiableError(); + } + + /** + * Factory for events triggered by {@link ModifyFeatureProperty} command. + */ + interface EventFactory extends LiveEventFactory { + + /** + * Creates a {@link FeaturePropertyCreated} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + FeaturePropertyCreated created(); + + /** + * Creates a {@link FeaturePropertyModified} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + FeaturePropertyModified modified(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..91bd2b9d --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import java.time.Instant; +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertyNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertyNotModifiableException; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeaturePropertyResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.FeaturePropertyCreated; +import org.eclipse.ditto.signals.events.things.FeaturePropertyModified; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link ModifyFeaturePropertyLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class ModifyFeaturePropertyLiveCommandAnswerBuilderImpl + extends AbstractLiveCommandAnswerBuilder + implements ModifyFeaturePropertyLiveCommandAnswerBuilder { + + private ModifyFeaturePropertyLiveCommandAnswerBuilderImpl(final ModifyFeaturePropertyLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code ModifyFeaturePropertyLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static ModifyFeaturePropertyLiveCommandAnswerBuilderImpl newInstance( + final ModifyFeaturePropertyLiveCommand command) { + return new ModifyFeaturePropertyLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @Override + protected Event doCreateEvent(final Function> createEventFunction) { + return createEventFunction.apply(new EventFactoryImpl()); + } + + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public ModifyFeaturePropertyResponse created() { + return ModifyFeaturePropertyResponse.created(command.getThingEntityId(), command.getFeatureId(), + command.getPropertyPointer(), + command.getPropertyValue(), command.getDittoHeaders()); + } + + @Nonnull + @Override + public ModifyFeaturePropertyResponse modified() { + return ModifyFeaturePropertyResponse.modified(command.getThingEntityId(), command.getFeatureId(), + command.getPropertyPointer(), + command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse featurePropertyNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + FeaturePropertyNotAccessibleException.newBuilder(command.getThingEntityId(), + command.getFeatureId(), + command.getPropertyPointer()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + + @Nonnull + @Override + public ThingErrorResponse featurePropertyNotModifiableError() { + return errorResponse(command.getThingEntityId(), + FeaturePropertyNotModifiableException.newBuilder(command.getThingEntityId(), + command.getFeatureId(), command.getPropertyPointer()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + + @Immutable + private final class EventFactoryImpl implements EventFactory { + + @Nonnull + @Override + public FeaturePropertyCreated created() { + return FeaturePropertyCreated.of(command.getThingEntityId(), command.getFeatureId(), + command.getPropertyPointer(), + command.getPropertyValue(), -1, Instant.now(), command.getDittoHeaders(), null); + } + + @Nonnull + @Override + public FeaturePropertyModified modified() { + return FeaturePropertyModified.of(command.getThingEntityId(), command.getFeatureId(), + command.getPropertyPointer(), command.getPropertyValue(), -1, Instant.now(), + command.getDittoHeaders(), null); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommandImpl.java new file mode 100644 index 00000000..a631fe45 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommandImpl.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureProperty; + +/** + * An immutable implementation of {@link ModifyFeaturePropertyLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class ModifyFeaturePropertyLiveCommandImpl + extends + AbstractModifyLiveCommand + implements ModifyFeaturePropertyLiveCommand { + + private final String featureId; + private final JsonPointer propertyPointer; + private final JsonValue propertyValue; + + private ModifyFeaturePropertyLiveCommandImpl(final ModifyFeatureProperty command) { + super(command); + featureId = command.getFeatureId(); + propertyPointer = command.getPropertyPointer(); + propertyValue = command.getPropertyValue(); + } + + /** + * Returns a new instance of {@code ModifyFeaturePropertyLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link ModifyFeatureProperty}. + */ + @Nonnull + public static ModifyFeaturePropertyLiveCommandImpl of(final Command command) { + return new ModifyFeaturePropertyLiveCommandImpl((ModifyFeatureProperty) command); + } + + @Override + public String getFeatureId() { + return featureId; + } + + @Nonnull + @Override + public JsonPointer getPropertyPointer() { + return propertyPointer; + } + + @Nonnull + @Override + public JsonValue getPropertyValue() { + return propertyValue; + } + + @Override + public Category getCategory() { + return Category.MODIFY; + } + + @Override + public ModifyFeaturePropertyLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return new ModifyFeaturePropertyLiveCommandImpl(ModifyFeatureProperty.of(getThingEntityId(), getFeatureId(), + getPropertyPointer(), getPropertyValue(), dittoHeaders)); + } + + @Override + public boolean changesAuthorization() { + return false; + } + + @Nonnull + @Override + public ModifyFeaturePropertyLiveCommandAnswerBuilder answer() { + return ModifyFeaturePropertyLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommand.java new file mode 100644 index 00000000..cd2657de --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommand.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.model.things.Features; +import org.eclipse.ditto.model.things.WithThingId; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatures; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommand; + +/** + * {@link ModifyFeatures} live command giving access to the command and all of its special accessors. Also the entry + * point for creating a {@link ModifyFeaturesLiveCommandAnswerBuilder} capable of answering incoming commands. + * + * @since 2.0.0 + */ +public interface ModifyFeaturesLiveCommand + extends WithThingId, LiveCommand, + ThingModifyCommand { + + /** + * Returns the new {@code Features} to modify. + * + * @return the Features to modify. + * @see ModifyFeatures#getFeatures() + */ + @Nonnull + Features getFeatures(); + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..14edfca8 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommandAnswerBuilder.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatures; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeaturesResponse; +import org.eclipse.ditto.signals.events.things.FeaturesCreated; +import org.eclipse.ditto.signals.events.things.FeaturesModified; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s and {@code Event}s for {@link ModifyFeatures} + * commands. + * + * @since 2.0.0 + */ +public interface ModifyFeaturesLiveCommandAnswerBuilder extends + LiveCommandAnswerBuilder.ModifyCommandResponseStep { + + /** + * Factory for {@code CommandResponse}s to {@link ModifyFeatures} command. + */ + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Builds a "created" {@link ModifyFeaturesResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + ModifyFeaturesResponse created(); + + /** + * Builds a "modified" {@link ModifyFeaturesResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + ModifyFeaturesResponse modified(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the features were not accessible. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeaturesNotAccessibleException + * FeaturesNotAccessibleException + */ + @Nonnull + ThingErrorResponse featuresNotAccessibleError(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the features were not modifiable. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.FeaturesNotModifiableException + * FeaturesNotModifiableException + */ + @Nonnull + ThingErrorResponse featuresNotModifiableError(); + } + + /** + * Factory for events triggered by {@link ModifyFeatures} command. + */ + interface EventFactory extends LiveEventFactory { + + /** + * Creates a {@link FeaturesCreated} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + FeaturesCreated created(); + + /** + * Creates a {@link FeaturesModified} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + FeaturesModified modified(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..1bc4b43b --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import java.time.Instant; +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturesNotModifiableException; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeaturesResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.FeaturesCreated; +import org.eclipse.ditto.signals.events.things.FeaturesModified; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a {@link + * ModifyFeaturesLiveCommand}. + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class ModifyFeaturesLiveCommandAnswerBuilderImpl + extends AbstractLiveCommandAnswerBuilder + implements ModifyFeaturesLiveCommandAnswerBuilder { + + private ModifyFeaturesLiveCommandAnswerBuilderImpl(final ModifyFeaturesLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code ModifyFeaturesLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static ModifyFeaturesLiveCommandAnswerBuilderImpl newInstance(final ModifyFeaturesLiveCommand command) { + return new ModifyFeaturesLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @Override + protected Event doCreateEvent(final Function> createEventFunction) { + return createEventFunction.apply(new EventFactoryImpl()); + } + + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public ModifyFeaturesResponse created() { + return ModifyFeaturesResponse.created(command.getThingEntityId(), command.getFeatures(), + command.getDittoHeaders()); + } + + @Nonnull + @Override + public ModifyFeaturesResponse modified() { + return ModifyFeaturesResponse.modified(command.getThingEntityId(), command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse featuresNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + FeaturesNotAccessibleException.newBuilder(command.getThingEntityId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + + @Nonnull + @Override + public ThingErrorResponse featuresNotModifiableError() { + return errorResponse(command.getThingEntityId(), + FeaturesNotModifiableException.newBuilder(command.getThingEntityId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + + @Immutable + private final class EventFactoryImpl implements EventFactory { + + @Nonnull + @Override + public FeaturesCreated created() { + return FeaturesCreated.of(command.getThingEntityId(), command.getFeatures(), -1, Instant.now(), + command.getDittoHeaders(), null); + } + + @Nonnull + @Override + public FeaturesModified modified() { + return FeaturesModified.of(command.getThingEntityId(), command.getFeatures(), -1, Instant.now(), + command.getDittoHeaders(), null); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommandImpl.java new file mode 100644 index 00000000..c201bcf5 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommandImpl.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.Features; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatures; + +/** + * An immutable implementation of {@link ModifyFeaturesLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class ModifyFeaturesLiveCommandImpl extends AbstractModifyLiveCommand implements ModifyFeaturesLiveCommand { + + private final Features features; + + private ModifyFeaturesLiveCommandImpl(final ModifyFeatures command) { + super(command); + features = command.getFeatures(); + } + + /** + * Returns a new instance of {@code ModifyFeaturesLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link ModifyFeatures}. + */ + @Nonnull + public static ModifyFeaturesLiveCommandImpl of(final Command command) { + return new ModifyFeaturesLiveCommandImpl((ModifyFeatures) command); + } + + @Nonnull + @Override + public Features getFeatures() { + return features; + } + + @Override + public Category getCategory() { + return Category.MODIFY; + } + + @Override + public ModifyFeaturesLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return new ModifyFeaturesLiveCommandImpl(ModifyFeatures.of(getThingEntityId(), getFeatures(), dittoHeaders)); + } + + @Override + public boolean changesAuthorization() { + return false; + } + + @Nonnull + @Override + public ModifyFeaturesLiveCommandAnswerBuilder answer() { + return ModifyFeaturesLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyLiveCommandFactory.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyLiveCommandFactory.java new file mode 100644 index 00000000..0d8818d1 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyLiveCommandFactory.java @@ -0,0 +1,287 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.signals.commands.base.Command; + +/** + * A factory for getting immutable instances of modify {@link LiveCommand LiveCommand}s. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +public final class ModifyLiveCommandFactory { + + private ModifyLiveCommandFactory() { + throw new AssertionError(); + } + + /** + * Returns a new immutable instance of {@code CreateThingLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.modify.CreateThing}. + */ + @Nonnull + public static CreateThingLiveCommand createThing(final Command command) { + return CreateThingLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code DeleteAttributeLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.modify.DeleteAttribute}. + */ + @Nonnull + public static DeleteAttributeLiveCommand deleteAttribute(final Command command) { + return DeleteAttributeLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code DeleteAttributesLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.modify.DeleteAttributes}. + */ + @Nonnull + public static DeleteAttributesLiveCommand deleteAttributes(final Command command) { + return DeleteAttributesLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code DeleteFeatureLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.modify.DeleteFeature}. + */ + @Nonnull + public static DeleteFeatureLiveCommand deleteFeature(final Command command) { + return DeleteFeatureLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code DeleteFeatureDefinitionLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureDefinition}. + */ + @Nonnull + public static DeleteFeatureDefinitionLiveCommand deleteFeatureDefinition(final Command command) { + return DeleteFeatureDefinitionLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code DeleteFeaturePropertiesLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureProperties}. + */ + @Nonnull + public static DeleteFeaturePropertiesLiveCommand deleteFeatureProperties(final Command command) { + return DeleteFeaturePropertiesLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code DeleteFeaturePropertyLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureProperty}. + */ + @Nonnull + public static DeleteFeaturePropertyLiveCommand deleteFeatureProperty(final Command command) { + return DeleteFeaturePropertyLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code DeleteFeaturesLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.modify.DeleteFeatures}. + */ + @Nonnull + public static DeleteFeaturesLiveCommand deleteFeatures(final Command command) { + return DeleteFeaturesLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code DeleteThingLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.modify.DeleteThing}. + */ + @Nonnull + public static DeleteThingLiveCommand deleteThing(final Command command) { + return DeleteThingLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code ModifyAttributeLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.modify.ModifyAttribute}. + */ + @Nonnull + public static ModifyAttributeLiveCommand modifyAttribute(final Command command) { + return ModifyAttributeLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code ModifyAttributesLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.modify.ModifyAttributes}. + */ + @Nonnull + public static ModifyAttributesLiveCommand modifyAttributes(final Command command) { + return ModifyAttributesLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code ModifyFeatureLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.modify.ModifyFeature}. + */ + @Nonnull + public static ModifyFeatureLiveCommand modifyFeature(final Command command) { + return ModifyFeatureLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code ModifyFeatureDefinitionLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureDefinition}. + */ + @Nonnull + public static ModifyFeatureDefinitionLiveCommand modifyFeatureDefinition(final Command command) { + return ModifyFeatureDefinitionLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code ModifyFeaturePropertiesLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureProperties}. + */ + @Nonnull + public static ModifyFeaturePropertiesLiveCommand modifyFeatureProperties(final Command command) { + return ModifyFeaturePropertiesLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code ModifyFeaturePropertyLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureProperty}. + */ + @Nonnull + public static ModifyFeaturePropertyLiveCommand modifyFeatureProperty(final Command command) { + return ModifyFeaturePropertyLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code ModifyFeaturesLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.modify.ModifyFeatures}. + */ + @Nonnull + public static ModifyFeaturesLiveCommand modifyFeatures(final Command command) { + return ModifyFeaturesLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code ModifyThingLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.modify.ModifyThing}. + */ + @Nonnull + public static ModifyThingLiveCommand modifyThing(final Command command) { + return ModifyThingLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code MergeThingLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.modify.MergeThing}. + */ + @Nonnull + public static MergeThingLiveCommand mergeThing(final Command command) { + return MergeThingLiveCommandImpl.of(command); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommand.java new file mode 100644 index 00000000..269ffb5a --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommand.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.model.things.Thing; +import org.eclipse.ditto.signals.commands.things.modify.ModifyThing; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommand; + +/** + * {@link ModifyThing} live command giving access to the command and all of its special accessors. Also the entry point + * for creating a {@link ModifyThingLiveCommandAnswerBuilder} capable of answering incoming commands. + * + * @since 2.0.0 + */ +public interface ModifyThingLiveCommand extends LiveCommand, ThingModifyCommand { + + /** + * Returns the {@code Thing} to modify. + * + * @return the Thing to modify. + * @see ModifyThing#getThing() + */ + @Nonnull + Thing getThing(); + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..75cc9a76 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommandAnswerBuilder.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.modify.ModifyThing; +import org.eclipse.ditto.signals.commands.things.modify.ModifyThingResponse; +import org.eclipse.ditto.signals.events.things.ThingCreated; +import org.eclipse.ditto.signals.events.things.ThingModified; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s and {@code Event}s for {@link ModifyThing} + * commands. + * + * @since 2.0.0 + */ +public interface ModifyThingLiveCommandAnswerBuilder + extends LiveCommandAnswerBuilder.ModifyCommandResponseStep { + + /** + * Factory for {@code CommandResponse}s to {@link ModifyThing} command. + */ + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Builds a "created" {@link ModifyThingResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + ModifyThingResponse created(); + + /** + * Builds a "modified" {@link ModifyThingResponse} using the values of the {@code Command}. + * + * @return the response. + */ + @Nonnull + ModifyThingResponse modified(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the Thing was not accessible. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.ThingNotAccessibleException + * ThingNotAccessibleException + */ + @Nonnull + ThingErrorResponse thingNotAccessibleError(); + + /** + * Builds a {@link ThingErrorResponse} indicating that the Thing was not modifiable. + * + * @return the response. + * @see org.eclipse.ditto.signals.commands.things.exceptions.ThingNotModifiableException + * ThingNotModifiableException + */ + @Nonnull + ThingErrorResponse thingNotModifiableError(); + } + + /** + * Factory for events triggered by {@link ModifyThing} command. + */ + interface EventFactory extends LiveEventFactory { + + /** + * Creates a {@link ThingCreated} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + ThingCreated created(); + + /** + * Creates a {@link ThingModified} event using the values of the {@code Command}. + * + * @return the event. + */ + @Nonnull + ThingModified modified(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..62d5189d --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.eclipse.ditto.model.base.common.ConditionChecker.checkNotNull; + +import java.time.Instant; +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.ThingNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.ThingNotModifiableException; +import org.eclipse.ditto.signals.commands.things.modify.ModifyThingResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.ThingCreated; +import org.eclipse.ditto.signals.events.things.ThingModified; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a {@link ModifyThingLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class ModifyThingLiveCommandAnswerBuilderImpl + extends + AbstractLiveCommandAnswerBuilder + implements ModifyThingLiveCommandAnswerBuilder { + + private ModifyThingLiveCommandAnswerBuilderImpl(final ModifyThingLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code ModifyThingLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static ModifyThingLiveCommandAnswerBuilderImpl newInstance(final ModifyThingLiveCommand command) { + checkNotNull(command, "command"); + return new ModifyThingLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @Override + protected Event doCreateEvent(final Function> createEventFunction) { + return createEventFunction.apply(new EventFactoryImpl()); + } + + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public ModifyThingResponse created() { + return ModifyThingResponse.created(command.getThing(), command.getDittoHeaders()); + } + + @Nonnull + @Override + public ModifyThingResponse modified() { + return ModifyThingResponse.modified(command.getThingEntityId(), command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse thingNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + ThingNotAccessibleException.newBuilder(command.getThingEntityId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + + @Nonnull + @Override + public ThingErrorResponse thingNotModifiableError() { + return errorResponse(command.getThingEntityId(), + ThingNotModifiableException.newBuilder(command.getThingEntityId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + + @Immutable + private final class EventFactoryImpl implements EventFactory { + + @Nonnull + @Override + public ThingCreated created() { + return ThingCreated.of(command.getThing(), -1, Instant.now(), command.getDittoHeaders(), null); + } + + @Nonnull + @Override + public ThingModified modified() { + return ThingModified.of(command.getThing(), -1, Instant.now(), command.getDittoHeaders(), null); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommandImpl.java new file mode 100644 index 00000000..510970fa --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommandImpl.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.Thing; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.modify.ModifyThing; + +/** + * An immutable implementation of {@link ModifyThingLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class ModifyThingLiveCommandImpl + extends AbstractModifyLiveCommand + implements ModifyThingLiveCommand { + + private final Thing thing; + + private ModifyThingLiveCommandImpl(final ModifyThing command) { + super(command); + thing = command.getThing(); + } + + /** + * Returns a new instance of {@code ModifyThingLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link ModifyThing}. + */ + @Nonnull + public static ModifyThingLiveCommandImpl of(final Command command) { + return new ModifyThingLiveCommandImpl((ModifyThing) command); + } + + @Nonnull + @Override + public Thing getThing() { + return thing; + } + + @Override + public Category getCategory() { + return Category.MODIFY; + } + + @Override + public ModifyThingLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return new ModifyThingLiveCommandImpl(ModifyThing.of(getThingEntityId(), getThing(), null, dittoHeaders)); + } + + @Override + public boolean changesAuthorization() { + return false; + } + + @Nonnull + @Override + public ModifyThingLiveCommandAnswerBuilder answer() { + return ModifyThingLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/package-info.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/package-info.java new file mode 100644 index 00000000..ef1544e8 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/modify/package-info.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ + +/** + * This package contains implementations of {@link org.eclipse.ditto.client.live.commands.base.LiveCommand + * LiveCommand} and {@link org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder + * LiveCommandAnswerBuilder} for modification operations like create, update and delete. + */ +package org.eclipse.ditto.client.live.commands.modify; diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/AbstractLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/AbstractLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..295539f0 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/AbstractLiveCommandAnswerBuilder.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.eclipse.ditto.model.base.common.ConditionChecker.checkNotNull; + +import java.util.function.Function; + +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerFactory; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.signals.commands.base.CommandResponse; + +/** + * Abstract base implementation for all {@link LiveCommandAnswerBuilder}s for query commands. + * + * @param the type of the LiveCommand + * @param the type of the LiveCommandResponseFactory to be used as function parameter for the + * {@link #createResponseFunction} + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +abstract class AbstractLiveCommandAnswerBuilder + implements LiveCommandAnswerBuilder.QueryCommandResponseStep, LiveCommandAnswerBuilder.BuildStep { + + // This variable being protected is no problem as it is a) immutable and b) not visible beyond "modify" package. + protected final C command; + private Function> createResponseFunction; + + /** + * Constructs a new {@code AbstractLiveCommandAnswerBuilder} object. + * + * @param command the command to build an answer for. + * @throws NullPointerException if {@code command} is {@code null}. + */ + protected AbstractLiveCommandAnswerBuilder(final C command) { + this.command = checkNotNull(command, "command"); + createResponseFunction = r -> null; + } + + @Override + public BuildStep withResponse(final Function> createResponseFunction) { + this.createResponseFunction = + checkNotNull(createResponseFunction, "function for creating a command response"); + return this; + } + + @Override + public BuildStep withoutResponse() { + return this; + } + + @Override + public LiveCommandAnswer build() { + final CommandResponse commandResponse = doCreateResponse(createResponseFunction); + + return LiveCommandAnswerFactory.newLiveCommandAnswer(commandResponse); + } + + /** + * Creates a CommandResponse using the given Function. + * + * @param createResponseFunction the function for creating a CommandResponse with the help of the implied + * LiveCommandResponseFactory. + * @return the CommandResponse. + */ + protected abstract CommandResponse doCreateResponse(Function> createResponseFunction); + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/AbstractQueryLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/AbstractQueryLiveCommand.java new file mode 100644 index 00000000..cbaee265 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/AbstractQueryLiveCommand.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import java.util.Optional; + +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.client.live.commands.base.AbstractLiveCommand; +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.json.JsonFieldSelector; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.ThingId; +import org.eclipse.ditto.signals.commands.things.query.ThingQueryCommand; + +/** + * Abstract base implementation for LiveCommands wrapping {@link ThingQueryCommand}s. + * + * @param the type of the LiveCommand; currently needed as return type for {@link #setDittoHeaders(DittoHeaders)}. + * @param the type of the LiveCommandAnswerBuilder to be returned for {@link #answer()}. + * + * @since 2.0.0 + */ +@Immutable +abstract class AbstractQueryLiveCommand & ThingQueryCommand, B extends LiveCommandAnswerBuilder> + extends AbstractLiveCommand implements ThingQueryCommand { + + private final ThingQueryCommand thingQueryCommand; + + /** + * Constructs a new {@code AbstractQueryLiveCommand} object. + * + * @param thingQueryCommand the command to be wrapped by the returned object. + * @throws NullPointerException if {@code command} is {@code null}. + */ + protected AbstractQueryLiveCommand(final ThingQueryCommand thingQueryCommand) { + super(thingQueryCommand); + this.thingQueryCommand = thingQueryCommand; + } + + @Override + public ThingId getThingEntityId() { + return thingQueryCommand.getThingEntityId(); + } + + @Override + public Optional getSelectedFields() { + return thingQueryCommand.getSelectedFields(); + } + + @Override + public Category getCategory() { + return Category.QUERY; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/QueryLiveCommandFactory.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/QueryLiveCommandFactory.java new file mode 100644 index 00000000..2d84451b --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/QueryLiveCommandFactory.java @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.utils.jsr305.annotations.AllValuesAreNonnullByDefault; + +/** + * A factory for getting immutable instances of query {@link LiveCommand LiveCommand}s. + * + * @since 2.0.0 + */ +@AllValuesAreNonnullByDefault +@Immutable +public final class QueryLiveCommandFactory { + + private QueryLiveCommandFactory() { + throw new AssertionError(); + } + + /** + * Returns a new immutable instance of {@code RetrieveAttributeLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.query.RetrieveAttribute RetrieveAttribute}. + */ + public static RetrieveAttributeLiveCommand retrieveAttribute(final Command command) { + return RetrieveAttributeLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code RetrieveAttributesLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.query.RetrieveAttributes RetrieveAttributes}. + */ + public static RetrieveAttributesLiveCommand retrieveAttributes(final Command command) { + return RetrieveAttributesLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code RetrieveFeatureLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.query.RetrieveFeature RetrieveFeature}. + */ + public static RetrieveFeatureLiveCommand retrieveFeature(final Command command) { + return RetrieveFeatureLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code RetrieveFeatureDefinitionLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDefinition RetrieveFeatureDefinition}. + */ + public static RetrieveFeatureDefinitionLiveCommand retrieveFeatureDefinition(final Command command) { + return RetrieveFeatureDefinitionLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code RetrieveFeaturePropertiesLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureProperties RetrieveFeatureProperties}. + */ + public static RetrieveFeaturePropertiesLiveCommand retrieveFeatureProperties(final Command command) { + return RetrieveFeaturePropertiesLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code RetrieveFeaturePropertyLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureProperty RetrieveFeatureProperty}. + */ + public static RetrieveFeaturePropertyLiveCommand retrieveFeatureProperty(final Command command) { + return RetrieveFeaturePropertyLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code RetrieveFeaturesLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.query.RetrieveFeatures RetrieveFeatures}. + */ + public static RetrieveFeaturesLiveCommand retrieveFeatures(final Command command) { + return RetrieveFeaturesLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code RetrieveThingLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.query.RetrieveThing RetrieveThing}. + */ + public static RetrieveThingLiveCommand retrieveThing(final Command command) { + return RetrieveThingLiveCommandImpl.of(command); + } + + /** + * Returns a new immutable instance of {@code RetrieveThingsLiveCommand}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of + * {@link org.eclipse.ditto.signals.commands.things.query.RetrieveThings RetrieveThings}. + */ + public static RetrieveThingsLiveCommand retrieveThings(final Command command) { + return RetrieveThingsLiveCommandImpl.of(command); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommand.java new file mode 100644 index 00000000..79bf1e6b --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommand.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.signals.commands.things.query.RetrieveAttribute; +import org.eclipse.ditto.signals.commands.things.query.ThingQueryCommand; + +/** + * {@link RetrieveAttribute} live command giving access to the command and all of its special accessors. + * Also the entry point for creating a {@link RetrieveAttributeLiveCommandAnswerBuilder} capable of + * answering incoming commands. + * + * @since 2.0.0 + */ +public interface RetrieveAttributeLiveCommand extends LiveCommand, ThingQueryCommand { + + /** + * Returns the JSON pointer of the attribute to retrieve. + * + * @return the JSON pointer. + */ + @Nonnull + JsonPointer getAttributePointer(); + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..849e114e --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommandAnswerBuilder.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.query.RetrieveAttribute; +import org.eclipse.ditto.signals.commands.things.query.RetrieveAttributeResponse; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s for {@link RetrieveAttribute} commands. + * + * @since 2.0.0 + */ +public interface RetrieveAttributeLiveCommandAnswerBuilder extends + LiveCommandAnswerBuilder.QueryCommandResponseStep { + + /** + * Factory for {@code CommandResponse}s to {@link RetrieveAttribute} command. + */ + @ParametersAreNonnullByDefault + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Creates a {@link RetrieveAttributeResponse} containing the retrieved value for the {@link RetrieveAttribute} + * command. + * + * @param attributeValue the value of the requested attribute. + * @return the response. + * @throws NullPointerException if {@code attributeValue} is {@code null} + */ + @Nonnull + RetrieveAttributeResponse retrieved(JsonValue attributeValue); + + /** + * Creates a {@link ThingErrorResponse} specifying that the requested attribute does not exist or the requesting + * user does not have enough permission to retrieve it. + * + * @return the response. + */ + @Nonnull + ThingErrorResponse attributeNotAccessibleError(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..dfc4f335 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.AttributeNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.query.RetrieveAttributeResponse; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link RetrieveAttributeLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class RetrieveAttributeLiveCommandAnswerBuilderImpl + extends + AbstractLiveCommandAnswerBuilder + implements RetrieveAttributeLiveCommandAnswerBuilder { + + private RetrieveAttributeLiveCommandAnswerBuilderImpl(final RetrieveAttributeLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code RetrieveAttributeLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static RetrieveAttributeLiveCommandAnswerBuilderImpl newInstance( + final RetrieveAttributeLiveCommand command) { + return new RetrieveAttributeLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @ParametersAreNonnullByDefault + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public RetrieveAttributeResponse retrieved(final JsonValue attributeValue) { + return RetrieveAttributeResponse.of(command.getThingEntityId(), command.getAttributePointer(), + attributeValue, + command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse attributeNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + AttributeNotAccessibleException.newBuilder(command.getThingEntityId(), + command.getAttributePointer()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommandImpl.java new file mode 100644 index 00000000..01c10416 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommandImpl.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.query.RetrieveAttribute; + +/** + * An immutable implementation of {@link RetrieveAttributeLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class RetrieveAttributeLiveCommandImpl extends AbstractQueryLiveCommand implements RetrieveAttributeLiveCommand { + + private final JsonPointer attributePointer; + + private RetrieveAttributeLiveCommandImpl(final RetrieveAttribute command) { + super(command); + attributePointer = command.getAttributePointer(); + } + + /** + * Returns a new instance of {@code RetrieveAttributeLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link RetrieveAttribute}. + */ + @Nonnull + public static RetrieveAttributeLiveCommandImpl of(final Command command) { + return new RetrieveAttributeLiveCommandImpl((RetrieveAttribute) command); + } + + @Nonnull + @Override + public JsonPointer getAttributePointer() { + return attributePointer; + } + + @Override + public RetrieveAttributeLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return of(RetrieveAttribute.of(getThingEntityId(), getAttributePointer(), dittoHeaders)); + } + + @Nonnull + @Override + public RetrieveAttributeLiveCommandAnswerBuilder answer() { + return RetrieveAttributeLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommand.java new file mode 100644 index 00000000..38878668 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommand.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.signals.commands.things.query.RetrieveAttributes; +import org.eclipse.ditto.signals.commands.things.query.ThingQueryCommand; + +/** + * {@link RetrieveAttributes} live command giving access to the command and all of its special accessors. + * Also the entry point for creating a {@link RetrieveAttributesLiveCommandAnswerBuilder} capable of + * answering incoming commands. + * + * @since 2.0.0 + */ +public interface RetrieveAttributesLiveCommand + extends LiveCommand, + ThingQueryCommand { +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..af12e381 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommandAnswerBuilder.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.model.things.Attributes; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.query.RetrieveAttributes; +import org.eclipse.ditto.signals.commands.things.query.RetrieveAttributesResponse; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s for {@link RetrieveAttributes} commands. + * + * @since 2.0.0 + */ +public interface RetrieveAttributesLiveCommandAnswerBuilder extends + LiveCommandAnswerBuilder.QueryCommandResponseStep { + + /** + * Factory for {@code CommandResponse}s to {@link RetrieveAttributes} command. + */ + @ParametersAreNonnullByDefault + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Creates a {@link RetrieveAttributesResponse} containing the retrieved value for the {@link + * RetrieveAttributes} command. + * + * @param attributes the value of the attributes. + * @return the response. + * @throws NullPointerException if {@code attributes} is {@code null}. + */ + @Nonnull + RetrieveAttributesResponse retrieved(Attributes attributes); + + /** + * Creates a {@link ThingErrorResponse} specifying that no attribute exists or the requesting user does not have + * enough permission to retrieve it. + * + * @return the response. + */ + @Nonnull + ThingErrorResponse attributesNotAccessibleError(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..dc57130f --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.things.Attributes; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.AttributesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.query.RetrieveAttributesResponse; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link RetrieveAttributesLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class RetrieveAttributesLiveCommandAnswerBuilderImpl + extends + AbstractLiveCommandAnswerBuilder + implements RetrieveAttributesLiveCommandAnswerBuilder { + + private RetrieveAttributesLiveCommandAnswerBuilderImpl(final RetrieveAttributesLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code RetrieveAttributeLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static RetrieveAttributesLiveCommandAnswerBuilderImpl newInstance( + final RetrieveAttributesLiveCommand command) { + return new RetrieveAttributesLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @ParametersAreNonnullByDefault + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public RetrieveAttributesResponse retrieved(final Attributes attributes) { + return RetrieveAttributesResponse.of(command.getThingEntityId(), attributes, command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse attributesNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + AttributesNotAccessibleException.newBuilder(command.getThingEntityId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommandImpl.java new file mode 100644 index 00000000..33527f6f --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommandImpl.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.query.RetrieveAttributes; + +/** + * An immutable implementation of {@link RetrieveAttributesLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class RetrieveAttributesLiveCommandImpl extends AbstractQueryLiveCommand implements RetrieveAttributesLiveCommand { + + private RetrieveAttributesLiveCommandImpl(final RetrieveAttributes command) { + super(command); + } + + /** + * Returns an instance of {@code RetrieveAttributesLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link RetrieveAttributes}. + */ + @Nonnull + public static RetrieveAttributesLiveCommandImpl of(final Command command) { + return new RetrieveAttributesLiveCommandImpl((RetrieveAttributes) command); + } + + @Override + public RetrieveAttributesLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return of(RetrieveAttributes.of(getThingEntityId(), getSelectedFields().orElse(null), dittoHeaders)); + } + + @Nonnull + @Override + public RetrieveAttributesLiveCommandAnswerBuilder answer() { + return RetrieveAttributesLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommand.java new file mode 100644 index 00000000..31570327 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommand.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.signals.base.WithFeatureId; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDefinition; +import org.eclipse.ditto.signals.commands.things.query.ThingQueryCommand; + +/** + * {@link RetrieveFeatureDefinition} live command giving access to the command and all of its special accessors. + * Also the entry point for creating a {@link RetrieveFeatureDefinitionLiveCommandAnswerBuilder} capable of answering + * incoming commands. + * + * @since 2.0.0 + */ +public interface RetrieveFeatureDefinitionLiveCommand + extends LiveCommand, + ThingQueryCommand, WithFeatureId { +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..aa0dbfac --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommandAnswerBuilder.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.model.things.FeatureDefinition; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDefinition; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDefinitionResponse; +import org.eclipse.ditto.utils.jsr305.annotations.AllValuesAreNonnullByDefault; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s for {@link RetrieveFeatureDefinition} commands. + * + * @since 2.0.0 + */ +public interface RetrieveFeatureDefinitionLiveCommandAnswerBuilder extends + LiveCommandAnswerBuilder.QueryCommandResponseStep { + + /** + * Factory for {@code CommandResponse}s to {@link RetrieveFeatureDefinition} command. + */ + @AllValuesAreNonnullByDefault + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Creates a {@link RetrieveFeatureDefinitionResponse} containing the retrieved value for the {@link + * RetrieveFeatureDefinition} command. + * + * @param featureDefinition the value of the requested Feature Definition + * @return a response containing the requested value + * @throws NullPointerException if {@code featureDefinition} is {@code null} + */ + RetrieveFeatureDefinitionResponse retrieved(FeatureDefinition featureDefinition); + + /** + * Creates a {@link ThingErrorResponse} specifying that no Feature Definition exist or the requesting user does + * not have enough permission to retrieve it. + * + * @return the error response + */ + ThingErrorResponse featureDefinitionNotAccessibleError(); + + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..5ef4f917 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import java.util.function.Function; + +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.things.FeatureDefinition; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDefinitionNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDefinitionResponse; +import org.eclipse.ditto.utils.jsr305.annotations.AllValuesAreNonnullByDefault; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link RetrieveFeatureDefinitionLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class RetrieveFeatureDefinitionLiveCommandAnswerBuilderImpl + extends + AbstractLiveCommandAnswerBuilder + implements RetrieveFeatureDefinitionLiveCommandAnswerBuilder { + + private RetrieveFeatureDefinitionLiveCommandAnswerBuilderImpl(final RetrieveFeatureDefinitionLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code RetrieveFeatureDefinitionLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static RetrieveFeatureDefinitionLiveCommandAnswerBuilderImpl newInstance( + final RetrieveFeatureDefinitionLiveCommand command) { + + return new RetrieveFeatureDefinitionLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @AllValuesAreNonnullByDefault + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Override + public RetrieveFeatureDefinitionResponse retrieved(final FeatureDefinition featureProperties) { + return RetrieveFeatureDefinitionResponse.of(command.getThingEntityId(), command.getFeatureId(), + featureProperties, + command.getDittoHeaders()); + } + + @Override + public ThingErrorResponse featureDefinitionNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + FeatureDefinitionNotAccessibleException.newBuilder(command.getThingEntityId(), + command.getFeatureId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommandImpl.java new file mode 100644 index 00000000..59148333 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommandImpl.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDefinition; + +/** + * An immutable implementation of {@link RetrieveFeatureDefinitionLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class RetrieveFeatureDefinitionLiveCommandImpl + extends AbstractQueryLiveCommand implements RetrieveFeatureDefinitionLiveCommand { + + private final String featureId; + + private RetrieveFeatureDefinitionLiveCommandImpl(final RetrieveFeatureDefinition command) { + super(command); + featureId = command.getFeatureId(); + } + + /** + * Returns an instance of {@code RetrieveFeatureDefinitionLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link RetrieveFeatureDefinition}. + */ + @Nonnull + public static RetrieveFeatureDefinitionLiveCommandImpl of(final Command command) { + return new RetrieveFeatureDefinitionLiveCommandImpl((RetrieveFeatureDefinition) command); + } + + @Override + public String getFeatureId() { + return featureId; + } + + @Override + public RetrieveFeatureDefinitionLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return of(RetrieveFeatureDefinition.of(getThingEntityId(), getFeatureId(), dittoHeaders)); + } + + @Nonnull + @Override + public RetrieveFeatureDefinitionLiveCommandAnswerBuilder answer() { + return RetrieveFeatureDefinitionLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommand.java new file mode 100644 index 00000000..27a0aa9b --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommand.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.signals.base.WithFeatureId; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDesiredProperties; +import org.eclipse.ditto.signals.commands.things.query.ThingQueryCommand; + +/** + * {@link RetrieveFeatureDesiredProperties} live command giving access to the command and all of its special accessors. + * Also the entry point for creating a {@link RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilder} capable of + * answering incoming commands. + * + * @since 2.0.0 + */ +public interface RetrieveFeatureDesiredPropertiesLiveCommand + extends + LiveCommand, + ThingQueryCommand, WithFeatureId { +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..45edef12 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilder.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.model.things.FeatureProperties; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDesiredProperties; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDesiredPropertiesResponse; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s for {@link RetrieveFeatureDesiredProperties} commands. + * + * @since 2.0.0 + */ +public interface RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilder extends + LiveCommandAnswerBuilder.QueryCommandResponseStep { + + /** + * Factory for {@code CommandResponse}s to {@link RetrieveFeatureDesiredProperties} command. + */ + @ParametersAreNonnullByDefault + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Creates a {@link RetrieveFeatureDesiredPropertiesResponse} containing the retrieved value for the {@link + * RetrieveFeatureDesiredProperties} command. + * + * @param featureDesiredProperties the value of the requested Feature desired properties + * @return a response containing the requested value + * @throws NullPointerException if {@code FeatureDesiredProperties} is {@code null} + */ + @Nonnull + RetrieveFeatureDesiredPropertiesResponse retrieved(FeatureProperties featureDesiredProperties); + + /** + * Creates a {@link ThingErrorResponse} specifying that no Feature desired property exist or the requesting user does + * not have enough permission to retrieve them. + * + * @return the error response + */ + @Nonnull + ThingErrorResponse featureDesiredPropertiesNotAccessibleError(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..1a281102 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.client.live.commands.query.RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilder.ResponseFactory; +import org.eclipse.ditto.model.things.FeatureProperties; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertiesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDesiredPropertiesResponse; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link RetrieveFeatureDesiredPropertiesLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl + extends AbstractLiveCommandAnswerBuilder + implements RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilder { + + private RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl( + final RetrieveFeatureDesiredPropertiesLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl newInstance( + final RetrieveFeatureDesiredPropertiesLiveCommand command) { + return new RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @ParametersAreNonnullByDefault + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public RetrieveFeatureDesiredPropertiesResponse retrieved(final FeatureProperties desiredProperties) { + return RetrieveFeatureDesiredPropertiesResponse.of(command.getThingEntityId(), command.getFeatureId(), + desiredProperties, command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse featureDesiredPropertiesNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + FeatureDesiredPropertiesNotAccessibleException.newBuilder(command.getThingEntityId(), + command.getFeatureId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommandImpl.java new file mode 100644 index 00000000..3a943d62 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommandImpl.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDesiredProperties; + +/** + * An immutable implementation of {@link RetrieveFeatureDesiredPropertiesLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class RetrieveFeatureDesiredPropertiesLiveCommandImpl + extends AbstractQueryLiveCommand + implements RetrieveFeatureDesiredPropertiesLiveCommand { + + private final String featureId; + + private RetrieveFeatureDesiredPropertiesLiveCommandImpl(final RetrieveFeatureDesiredProperties command) { + super(command); + featureId = command.getFeatureId(); + } + + /** + * Returns an instance of {@code RetrieveFeatureDesiredPropertiesLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link RetrieveFeatureDesiredProperties}. + */ + @Nonnull + public static RetrieveFeatureDesiredPropertiesLiveCommandImpl of(final Command command) { + return new RetrieveFeatureDesiredPropertiesLiveCommandImpl((RetrieveFeatureDesiredProperties) command); + } + + @Override + public String getFeatureId() { + return featureId; + } + + @Override + public RetrieveFeatureDesiredPropertiesLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return of(RetrieveFeatureDesiredProperties.of(getThingEntityId(), getFeatureId(), + getSelectedFields().orElse(null), + dittoHeaders)); + } + + @Nonnull + @Override + public RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilder answer() { + return RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommand.java new file mode 100644 index 00000000..a19698a9 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommand.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.signals.base.WithFeatureId; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDesiredProperty; +import org.eclipse.ditto.signals.commands.things.query.ThingQueryCommand; + +/** + * {@link RetrieveFeatureDesiredProperty} live command giving access to the command and all of its special accessors. + * Also the entry point for creating a {@link RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilder} capable of + * answering incoming commands. + * + * @since 2.0.0 + */ +public interface RetrieveFeatureDesiredPropertyLiveCommand + extends LiveCommand, + ThingQueryCommand, WithFeatureId { + + /** + * Returns the JSON pointer of the desired property to retrieve. + * + * @return the JSON pointer. + */ + @Nonnull + JsonPointer getDesiredPropertyPointer(); + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..0b63667a --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilder.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDesiredProperty; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDesiredPropertyResponse; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s for {@link RetrieveFeatureDesiredProperty} commands. + * + * @since 2.0.0 + */ +public interface RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilder extends + LiveCommandAnswerBuilder.QueryCommandResponseStep { + + /** + * Factory for {@code CommandResponse}s to {@link RetrieveFeatureDesiredProperty} command. + */ + @ParametersAreNonnullByDefault + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Creates a success response containing the retrieved value for the {@link RetrieveFeatureDesiredProperty} command. + * + * @param desiredPropertyValue the value of the requested Feature's desired property. + * @return the response. + * @throws NullPointerException if {@code propertyValue} is {@code null}. + */ + @Nonnull + RetrieveFeatureDesiredPropertyResponse retrieved(JsonValue desiredPropertyValue); + + /** + * Creates an error response specifying that the requested Feature's desired property does not exist or the requesting + * user does not have enough permission to retrieve them. + * + * @return the response. + */ + @Nonnull + ThingErrorResponse featureDesiredPropertyNotAccessibleError(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..0b619aa8 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertyNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDesiredPropertyResponse; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link RetrieveFeatureDesiredPropertyLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilderImpl + extends + AbstractLiveCommandAnswerBuilder + implements RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilder { + + private RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilderImpl( + final RetrieveFeatureDesiredPropertyLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code RetrieveFeaturePropertiesLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilderImpl newInstance( + final RetrieveFeatureDesiredPropertyLiveCommand command) { + return new RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @ParametersAreNonnullByDefault + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public RetrieveFeatureDesiredPropertyResponse retrieved(final JsonValue propertyValue) { + return RetrieveFeatureDesiredPropertyResponse.of(command.getThingEntityId(), command.getFeatureId(), + command.getDesiredPropertyPointer(), + propertyValue, command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse featureDesiredPropertyNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + FeatureDesiredPropertyNotAccessibleException.newBuilder(command.getThingEntityId(), + command.getFeatureId(), command.getDesiredPropertyPointer()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommandImpl.java new file mode 100644 index 00000000..9c160460 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommandImpl.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDesiredProperty; + +/** + * An immutable implementation of {@link RetrieveFeatureDesiredPropertyLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class RetrieveFeatureDesiredPropertyLiveCommandImpl + extends AbstractQueryLiveCommand + implements RetrieveFeatureDesiredPropertyLiveCommand { + + private final String featureId; + private final JsonPointer desiredPropertyPointer; + + private RetrieveFeatureDesiredPropertyLiveCommandImpl(final RetrieveFeatureDesiredProperty command) { + super(command); + featureId = command.getFeatureId(); + desiredPropertyPointer = command.getDesiredPropertyPointer(); + } + + /** + * Returns an instance of {@code RetrieveFeatureDesiredPropertyLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link RetrieveFeatureDesiredProperty}. + */ + @Nonnull + public static RetrieveFeatureDesiredPropertyLiveCommandImpl of(final Command command) { + return new RetrieveFeatureDesiredPropertyLiveCommandImpl((RetrieveFeatureDesiredProperty) command); + } + + @Override + public String getFeatureId() { + return featureId; + } + + @Nonnull + @Override + public JsonPointer getDesiredPropertyPointer() { + return desiredPropertyPointer; + } + + @Override + public RetrieveFeatureDesiredPropertyLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return of(RetrieveFeatureDesiredProperty.of(getThingEntityId(), getFeatureId(), getDesiredPropertyPointer(), + dittoHeaders)); + } + + @Nonnull + @Override + public RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilder answer() { + return RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommand.java new file mode 100644 index 00000000..3792e75d --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommand.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.signals.base.WithFeatureId; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeature; +import org.eclipse.ditto.signals.commands.things.query.ThingQueryCommand; + +/** + * {@link RetrieveFeature} live command giving access to the command and all of its special accessors. + * Also the entry point for creating a {@link RetrieveFeatureLiveCommandAnswerBuilder} capable of + * answering incoming commands. + * + * @since 2.0.0 + */ +public interface RetrieveFeatureLiveCommand + extends LiveCommand, + ThingQueryCommand, WithFeatureId { +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..390f0766 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommandAnswerBuilder.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.model.things.Feature; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeature; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureResponse; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s for {@link RetrieveFeature} commands. + * + * @since 2.0.0 + */ +public interface RetrieveFeatureLiveCommandAnswerBuilder extends + LiveCommandAnswerBuilder.QueryCommandResponseStep { + + /** + * Factory for {@code CommandResponse}s to {@link RetrieveFeature} command. + */ + @ParametersAreNonnullByDefault + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Creates a {@link RetrieveFeatureResponse} containing the retrieved value for the {@link RetrieveFeature} + * command. + * + * @param feature the value of the requested Feature. + * @return the response. + * @throws NullPointerException if {@code feature} is {@code null}. + */ + @Nonnull + RetrieveFeatureResponse retrieved(Feature feature); + + /** + * Creates a {@link ThingErrorResponse} specifying that the requested feature does not exist or the requesting + * user does not have enough permission to retrieve them. + * + * @return the response. + */ + @Nonnull + ThingErrorResponse featureNotAccessibleError(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..dd901a26 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.things.Feature; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureResponse; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link RetrieveFeatureLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class RetrieveFeatureLiveCommandAnswerBuilderImpl + extends + AbstractLiveCommandAnswerBuilder + implements RetrieveFeatureLiveCommandAnswerBuilder { + + private RetrieveFeatureLiveCommandAnswerBuilderImpl(final RetrieveFeatureLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code RetrieveFeatureLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static RetrieveFeatureLiveCommandAnswerBuilderImpl newInstance(final RetrieveFeatureLiveCommand command) { + return new RetrieveFeatureLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @ParametersAreNonnullByDefault + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public RetrieveFeatureResponse retrieved(final Feature feature) { + return RetrieveFeatureResponse.of(command.getThingEntityId(), feature, command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse featureNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + FeatureNotAccessibleException.newBuilder(command.getThingEntityId(), command.getFeatureId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommandImpl.java new file mode 100644 index 00000000..ea0326f2 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommandImpl.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeature; + +/** + * An immutable implementation of {@link RetrieveFeatureLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class RetrieveFeatureLiveCommandImpl extends AbstractQueryLiveCommand implements RetrieveFeatureLiveCommand { + + private final String featureId; + + private RetrieveFeatureLiveCommandImpl(final RetrieveFeature command) { + super(command); + featureId = command.getFeatureId(); + } + + /** + * Returns an instance of {@code RetrieveFeatureLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link RetrieveFeature}. + */ + @Nonnull + public static RetrieveFeatureLiveCommandImpl of(final Command command) { + return new RetrieveFeatureLiveCommandImpl((RetrieveFeature) command); + } + + @Override + public String getFeatureId() { + return featureId; + } + + @Override + public RetrieveFeatureLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return of(RetrieveFeature.of(getThingEntityId(), getFeatureId(), getSelectedFields().orElse(null), dittoHeaders)); + } + + @Nonnull + @Override + public RetrieveFeatureLiveCommandAnswerBuilder answer() { + return RetrieveFeatureLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommand.java new file mode 100644 index 00000000..d5839847 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommand.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.signals.base.WithFeatureId; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureProperties; +import org.eclipse.ditto.signals.commands.things.query.ThingQueryCommand; + +/** + * {@link RetrieveFeatureProperties} live command giving access to the command and all of its special accessors. + * Also the entry point for creating a {@link RetrieveFeaturePropertiesLiveCommandAnswerBuilder} capable of answering + * incoming commands. + * + * @since 2.0.0 + */ +public interface RetrieveFeaturePropertiesLiveCommand + extends LiveCommand, + ThingQueryCommand, WithFeatureId { +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..30f9a156 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommandAnswerBuilder.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.model.things.FeatureProperties; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureProperties; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeaturePropertiesResponse; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s for {@link RetrieveFeatureProperties} commands. + * + * @since 2.0.0 + */ +public interface RetrieveFeaturePropertiesLiveCommandAnswerBuilder extends + LiveCommandAnswerBuilder.QueryCommandResponseStep { + + /** + * Factory for {@code CommandResponse}s to {@link RetrieveFeatureProperties} command. + */ + @ParametersAreNonnullByDefault + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Creates a {@link RetrieveFeaturePropertiesResponse} containing the retrieved value for the {@link + * RetrieveFeatureProperties} command. + * + * @param featureProperties the value of the requested Feature properties + * @return a response containing the requested value + * @throws NullPointerException if {@code featureProperties} is {@code null} + */ + @Nonnull + RetrieveFeaturePropertiesResponse retrieved(FeatureProperties featureProperties); + + /** + * Creates a {@link ThingErrorResponse} specifying that no Feature property exist or the requesting user does + * not have enough permission to retrieve them. + * + * @return the error response + */ + @Nonnull + ThingErrorResponse featurePropertiesNotAccessibleError(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..a53bcfd2 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.things.FeatureProperties; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertiesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeaturePropertiesResponse; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link RetrieveFeaturePropertiesLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class RetrieveFeaturePropertiesLiveCommandAnswerBuilderImpl + extends AbstractLiveCommandAnswerBuilder + implements RetrieveFeaturePropertiesLiveCommandAnswerBuilder { + + private RetrieveFeaturePropertiesLiveCommandAnswerBuilderImpl(final RetrieveFeaturePropertiesLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code RetrieveFeaturePropertiesLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static RetrieveFeaturePropertiesLiveCommandAnswerBuilderImpl newInstance( + final RetrieveFeaturePropertiesLiveCommand command) { + return new RetrieveFeaturePropertiesLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @ParametersAreNonnullByDefault + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public RetrieveFeaturePropertiesResponse retrieved(final FeatureProperties featureProperties) { + return RetrieveFeaturePropertiesResponse.of(command.getThingEntityId(), command.getFeatureId(), + featureProperties, + command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse featurePropertiesNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + FeaturePropertiesNotAccessibleException.newBuilder(command.getThingEntityId(), + command.getFeatureId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommandImpl.java new file mode 100644 index 00000000..55bb2f1b --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommandImpl.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureProperties; + +/** + * An immutable implementation of {@link RetrieveFeaturePropertiesLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class RetrieveFeaturePropertiesLiveCommandImpl + extends AbstractQueryLiveCommand implements RetrieveFeaturePropertiesLiveCommand { + + private final String featureId; + + private RetrieveFeaturePropertiesLiveCommandImpl(final RetrieveFeatureProperties command) { + super(command); + featureId = command.getFeatureId(); + } + + /** + * Returns an instance of {@code RetrieveFeaturePropertiesLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link RetrieveFeatureProperties}. + */ + @Nonnull + public static RetrieveFeaturePropertiesLiveCommandImpl of(final Command command) { + return new RetrieveFeaturePropertiesLiveCommandImpl((RetrieveFeatureProperties) command); + } + + @Override + public String getFeatureId() { + return featureId; + } + + @Override + public RetrieveFeaturePropertiesLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return of(RetrieveFeatureProperties.of(getThingEntityId(), getFeatureId(), getSelectedFields().orElse(null), + dittoHeaders)); + } + + @Nonnull + @Override + public RetrieveFeaturePropertiesLiveCommandAnswerBuilder answer() { + return RetrieveFeaturePropertiesLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommand.java new file mode 100644 index 00000000..36b29e9a --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommand.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.signals.base.WithFeatureId; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureProperty; +import org.eclipse.ditto.signals.commands.things.query.ThingQueryCommand; + +/** + * {@link RetrieveFeatureProperty} live command giving access to the command and all of its special accessors. + * Also the entry point for creating a {@link RetrieveFeaturePropertyLiveCommandAnswerBuilder} capable + * of answering incoming commands. + * + * @since 2.0.0 + */ +public interface RetrieveFeaturePropertyLiveCommand + extends LiveCommand, + ThingQueryCommand, WithFeatureId { + + /** + * Returns the JSON pointer of the Property to retrieve. + * + * @return the JSON pointer. + */ + @Nonnull + JsonPointer getPropertyPointer(); + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..39050fc5 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommandAnswerBuilder.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureProperty; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeaturePropertyResponse; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s for {@link RetrieveFeatureProperty} commands. + * + * @since 2.0.0 + */ +public interface RetrieveFeaturePropertyLiveCommandAnswerBuilder extends + LiveCommandAnswerBuilder.QueryCommandResponseStep { + + /** + * Factory for {@code CommandResponse}s to {@link RetrieveFeatureProperty} command. + */ + @ParametersAreNonnullByDefault + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Creates a success response containing the retrieved value for the {@link RetrieveFeatureProperty} command. + * + * @param propertyValue the value of the requested Feature property. + * @return the response. + * @throws NullPointerException if {@code propertyValue} is {@code null}. + */ + @Nonnull + RetrieveFeaturePropertyResponse retrieved(JsonValue propertyValue); + + /** + * Creates an error response specifying that the requested Feature property does not exist or the requesting + * user does not have enough permission to retrieve them. + * + * @return the response. + */ + @Nonnull + ThingErrorResponse featurePropertyNotAccessibleError(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..7a06ef7b --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertyNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeaturePropertyResponse; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link RetrieveFeaturePropertyLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class RetrieveFeaturePropertyLiveCommandAnswerBuilderImpl + extends + AbstractLiveCommandAnswerBuilder + implements RetrieveFeaturePropertyLiveCommandAnswerBuilder { + + private RetrieveFeaturePropertyLiveCommandAnswerBuilderImpl(final RetrieveFeaturePropertyLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code RetrieveFeaturePropertiesLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static RetrieveFeaturePropertyLiveCommandAnswerBuilderImpl newInstance( + final RetrieveFeaturePropertyLiveCommand command) { + return new RetrieveFeaturePropertyLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @ParametersAreNonnullByDefault + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public RetrieveFeaturePropertyResponse retrieved(final JsonValue propertyValue) { + return RetrieveFeaturePropertyResponse.of(command.getThingEntityId(), command.getFeatureId(), + command.getPropertyPointer(), + propertyValue, command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse featurePropertyNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + FeaturePropertyNotAccessibleException.newBuilder(command.getThingEntityId(), + command.getFeatureId(), command.getPropertyPointer()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommandImpl.java new file mode 100644 index 00000000..82435418 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommandImpl.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureProperty; + +/** + * An immutable implementation of {@link RetrieveFeaturePropertyLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class RetrieveFeaturePropertyLiveCommandImpl extends AbstractQueryLiveCommand implements RetrieveFeaturePropertyLiveCommand { + + private final String featureId; + private final JsonPointer propertyPointer; + + private RetrieveFeaturePropertyLiveCommandImpl(final RetrieveFeatureProperty command) { + super(command); + featureId = command.getFeatureId(); + propertyPointer = command.getPropertyPointer(); + } + + /** + * Returns an instance of {@code RetrieveFeaturePropertyLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link RetrieveFeatureProperty}. + */ + @Nonnull + public static RetrieveFeaturePropertyLiveCommandImpl of(final Command command) { + return new RetrieveFeaturePropertyLiveCommandImpl((RetrieveFeatureProperty) command); + } + + @Override + public String getFeatureId() { + return featureId; + } + + @Nonnull + @Override + public JsonPointer getPropertyPointer() { + return propertyPointer; + } + + @Override + public RetrieveFeaturePropertyLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return of(RetrieveFeatureProperty.of(getThingEntityId(), getFeatureId(), getPropertyPointer(), dittoHeaders)); + } + + @Nonnull + @Override + public RetrieveFeaturePropertyLiveCommandAnswerBuilder answer() { + return RetrieveFeaturePropertyLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommand.java new file mode 100644 index 00000000..4e7086d8 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommand.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatures; +import org.eclipse.ditto.signals.commands.things.query.ThingQueryCommand; + +/** + * {@link RetrieveFeatures} live command giving access to the command and all of its special accessors. + * Also the entry point for creating a {@link RetrieveFeaturesLiveCommandAnswerBuilder} capable of + * answering incoming commands. + * + * @since 2.0.0 + */ +public interface RetrieveFeaturesLiveCommand extends LiveCommand, ThingQueryCommand { +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..bd58bedb --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommandAnswerBuilder.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.model.things.Features; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatures; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeaturesResponse; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s for {@link RetrieveFeatures} commands. + * + * @since 2.0.0 + */ +public interface RetrieveFeaturesLiveCommandAnswerBuilder extends + LiveCommandAnswerBuilder.QueryCommandResponseStep { + + /** + * Factory for {@code CommandResponse}s to {@link RetrieveFeatures} command. + */ + @ParametersAreNonnullByDefault + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Creates a success response containing the retrieved value for the {@link RetrieveFeatures} command. + * + * @param features the value of the requested Features. + * @return the response. + * @throws NullPointerException if {@code features} is {@code null}. + */ + @Nonnull + RetrieveFeaturesResponse retrieved(Features features); + + /** + * Creates an error response specifying that no Features exist or the requesting user does not have enough + * permission to retrieve them. + * + * @return the response. + */ + @Nonnull + ThingErrorResponse featuresNotAccessibleError(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..ebaefc01 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import java.util.function.Function; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.things.Features; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeaturesResponse; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link RetrieveFeaturesLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class RetrieveFeaturesLiveCommandAnswerBuilderImpl + extends + AbstractLiveCommandAnswerBuilder + implements RetrieveFeaturesLiveCommandAnswerBuilder { + + private RetrieveFeaturesLiveCommandAnswerBuilderImpl(final RetrieveFeaturesLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code RetrieveFeaturesLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static RetrieveFeaturesLiveCommandAnswerBuilderImpl newInstance(final RetrieveFeaturesLiveCommand command) { + return new RetrieveFeaturesLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @ParametersAreNonnullByDefault + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public RetrieveFeaturesResponse retrieved(final Features features) { + return RetrieveFeaturesResponse.of(command.getThingEntityId(), features, command.getDittoHeaders()); + } + + @Nonnull + @Override + public ThingErrorResponse featuresNotAccessibleError() { + return errorResponse(command.getThingEntityId(), FeaturesNotAccessibleException.newBuilder(command.getThingEntityId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommandImpl.java new file mode 100644 index 00000000..5b8d2d53 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommandImpl.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatures; + +/** + * An immutable implementation of {@link RetrieveFeaturesLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class RetrieveFeaturesLiveCommandImpl extends AbstractQueryLiveCommand implements RetrieveFeaturesLiveCommand { + + private RetrieveFeaturesLiveCommandImpl(final RetrieveFeatures command) { + super(command); + } + + /** + * Returns an instance of {@code RetrieveFeaturesLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link RetrieveFeatures}. + */ + @Nonnull + public static RetrieveFeaturesLiveCommandImpl of(final Command command) { + return new RetrieveFeaturesLiveCommandImpl((RetrieveFeatures) command); + } + + @Override + public RetrieveFeaturesLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + return of(RetrieveFeatures.of(getThingEntityId(), getSelectedFields().orElse(null), dittoHeaders)); + } + + @Nonnull + @Override + public RetrieveFeaturesLiveCommandAnswerBuilder answer() { + return RetrieveFeaturesLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommand.java new file mode 100644 index 00000000..c5c9ee61 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommand.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.signals.commands.things.query.RetrieveThing; +import org.eclipse.ditto.signals.commands.things.query.ThingQueryCommand; + +/** + * {@link RetrieveThing} live command giving access to the command and all of its special accessors. + * Also the entry point for creating a {@link RetrieveThingLiveCommandAnswerBuilder} capable of + * answering incoming commands. + * + * @since 2.0.0 + */ +public interface RetrieveThingLiveCommand extends LiveCommand, ThingQueryCommand { +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..c58bbf51 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommandAnswerBuilder.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import java.util.function.Predicate; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.json.JsonField; +import org.eclipse.ditto.model.things.Thing; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.query.RetrieveThing; +import org.eclipse.ditto.signals.commands.things.query.RetrieveThingResponse; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s for {@link RetrieveThing} commands. + * + * @since 2.0.0 + */ +public interface RetrieveThingLiveCommandAnswerBuilder extends + LiveCommandAnswerBuilder.QueryCommandResponseStep { + + /** + * Factory for {@code CommandResponse}s to {@link RetrieveThing} command. + */ + @ParametersAreNonnullByDefault + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Creates a success response containing the retrieved value for the {@link RetrieveThing} command. + * + * @param thing the value of the requested Thing. + * @param predicate a predicate determining which fields from the provided Thing should be included in the + * response. + * @return the response. + * @throws NullPointerException if any argument is {@code null}. + */ + @Nonnull + RetrieveThingResponse retrieved(Thing thing, Predicate predicate); + + /** + * Creates a success response containing the retrieved value for the {@link RetrieveThing} command. + * + * @param thing the value of the requested Thing. + * @return the response. + * @throws NullPointerException if {@code thing} is {@code null}. + */ + @Nonnull + RetrieveThingResponse retrieved(Thing thing); + + /** + * Creates an error response specifying that the requested Thing does not exist or the requesting user does not + * have enough permission to retrieve it. + * + * @return the response. + */ + @Nonnull + ThingErrorResponse thingNotAccessibleError(); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..841a7601 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import java.util.function.Function; +import java.util.function.Predicate; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.json.JsonField; +import org.eclipse.ditto.json.JsonFieldSelector; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.Thing; +import org.eclipse.ditto.model.things.ThingId; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.ThingNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.query.RetrieveThingResponse; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a {@link RetrieveThingLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class RetrieveThingLiveCommandAnswerBuilderImpl + extends AbstractLiveCommandAnswerBuilder + implements RetrieveThingLiveCommandAnswerBuilder { + + private RetrieveThingLiveCommandAnswerBuilderImpl(final RetrieveThingLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code RetrieveThingLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static RetrieveThingLiveCommandAnswerBuilderImpl newInstance(final RetrieveThingLiveCommand command) { + return new RetrieveThingLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @ParametersAreNonnullByDefault + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public RetrieveThingResponse retrieved(final Thing thing, final Predicate predicate) { + final DittoHeaders dittoHeaders = command.getDittoHeaders(); + final ThingId thingId = command.getThingEntityId(); + final Function fieldSelectorToResponse = + fieldSelector -> RetrieveThingResponse.of(thingId, thing, fieldSelector, predicate, dittoHeaders); + + return command.getSelectedFields() + .map(fieldSelectorToResponse) + .orElse(RetrieveThingResponse.of(thingId, thing, null, predicate, dittoHeaders)); + } + + @Nonnull + @Override + public RetrieveThingResponse retrieved(final Thing thing) { + return retrieved(thing, jsonField -> true); + } + + @Nonnull + @Override + public ThingErrorResponse thingNotAccessibleError() { + return errorResponse(command.getThingEntityId(), + ThingNotAccessibleException.newBuilder(command.getThingEntityId()) + .dittoHeaders(command.getDittoHeaders()) + .build()); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommandImpl.java new file mode 100644 index 00000000..d98beb7f --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommandImpl.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.query.RetrieveThing; + +/** + * An immutable implementation of {@link RetrieveThingLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class RetrieveThingLiveCommandImpl extends AbstractQueryLiveCommand implements RetrieveThingLiveCommand { + + private RetrieveThingLiveCommandImpl(final RetrieveThing command) { + super(command); + } + + /** + * Returns an instance of {@code RetrieveThingLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link RetrieveThing}. + */ + @Nonnull + public static RetrieveThingLiveCommandImpl of(final Command command) { + return new RetrieveThingLiveCommandImpl((RetrieveThing) command); + } + + @Override + public RetrieveThingLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + final RetrieveThing twinCommand = RetrieveThing.getBuilder(getThingEntityId(), dittoHeaders) + .withSelectedFields(getSelectedFields().orElse(null)) + .build(); + return of(twinCommand); + } + + @Nonnull + @Override + public RetrieveThingLiveCommandAnswerBuilder answer() { + return RetrieveThingLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommand.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommand.java new file mode 100644 index 00000000..86c4b9ea --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommand.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import java.util.List; +import java.util.stream.Collectors; + +import javax.annotation.Nonnull; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.model.things.ThingId; +import org.eclipse.ditto.signals.commands.base.WithNamespace; +import org.eclipse.ditto.signals.commands.things.query.RetrieveThings; +import org.eclipse.ditto.signals.commands.things.query.ThingQueryCommand; + +/** + * {@link RetrieveThings} live command giving access to the command and all of its special accessors. + * Also the entry point for creating a {@link RetrieveThingsLiveCommandAnswerBuilder} capable of + * answering incoming commands. + * + * @since 2.0.0 + */ +public interface RetrieveThingsLiveCommand + extends LiveCommand, + ThingQueryCommand, WithNamespace { + + /** + * Returns the identifiers of the {@code Thing}s to be retrieved. + * + * @return the identifiers + * @deprecated the thing ID is now typed. Use {@link #getThingEntityIds()} instead. + */ + @Nonnull + @Deprecated + default List getThingIds() { + return getThingEntityIds().stream().map(String::valueOf).collect(Collectors.toList()); + } + + @Nonnull + List getThingEntityIds(); + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommandAnswerBuilder.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommandAnswerBuilder.java new file mode 100644 index 00000000..c810c352 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommandAnswerBuilder.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import java.util.List; +import java.util.function.Predicate; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.base.LiveCommandResponseFactory; +import org.eclipse.ditto.json.JsonField; +import org.eclipse.ditto.model.things.Thing; +import org.eclipse.ditto.signals.commands.things.query.RetrieveThings; +import org.eclipse.ditto.signals.commands.things.query.RetrieveThingsResponse; + +/** + * LiveCommandAnswer builder for producing {@code CommandResponse}s for {@link RetrieveThings} commands. + * + * @since 2.0.0 + */ +public interface RetrieveThingsLiveCommandAnswerBuilder extends + LiveCommandAnswerBuilder.QueryCommandResponseStep { + + /** + * Factory for {@code CommandResponse}s to {@link RetrieveThings} command. + */ + @ParametersAreNonnullByDefault + interface ResponseFactory extends LiveCommandResponseFactory { + + /** + * Creates a success response containing the retrieved value for the {@link RetrieveThings} command. + * + * @param things the value of the requested Things. + * @param predicate a predicate determining which fields from the provided Things should be included in the + * response. + * @return the response. + * @throws NullPointerException if any argument is {@code null}. + */ + @Nonnull + RetrieveThingsResponse retrieved(List things, Predicate predicate); + + /** + * Creates a success response containing the retrieved value for the {@link RetrieveThings} command. + * + * @param things the value of the requested Things. + * @return the response. + * @throws NullPointerException if {@code things} is {@code null}. + */ + @Nonnull + RetrieveThingsResponse retrieved(List things); + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommandAnswerBuilderImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommandAnswerBuilderImpl.java new file mode 100644 index 00000000..2ea745d5 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommandAnswerBuilderImpl.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import java.util.List; +import java.util.function.Function; +import java.util.function.Predicate; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; +import javax.annotation.concurrent.NotThreadSafe; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.json.JsonField; +import org.eclipse.ditto.json.JsonFieldSelector; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.Thing; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.query.RetrieveThingsResponse; + +/** + * A mutable builder with a fluent API for creating a {@link LiveCommandAnswer} for a + * {@link RetrieveThingsLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@NotThreadSafe +final class RetrieveThingsLiveCommandAnswerBuilderImpl + extends AbstractLiveCommandAnswerBuilder + implements RetrieveThingsLiveCommandAnswerBuilder { + + private RetrieveThingsLiveCommandAnswerBuilderImpl(final RetrieveThingsLiveCommand command) { + super(command); + } + + /** + * Returns a new instance of {@code RetrieveThingsLiveCommandAnswerBuilderImpl}. + * + * @param command the command to build an answer for. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + */ + public static RetrieveThingsLiveCommandAnswerBuilderImpl newInstance(final RetrieveThingsLiveCommand command) { + return new RetrieveThingsLiveCommandAnswerBuilderImpl(command); + } + + @Override + protected CommandResponse doCreateResponse( + final Function> createResponseFunction) { + return createResponseFunction.apply(new ResponseFactoryImpl()); + } + + @ParametersAreNonnullByDefault + @Immutable + private final class ResponseFactoryImpl implements ResponseFactory { + + @Nonnull + @Override + public RetrieveThingsResponse retrieved(final List things, final Predicate predicate) { + final DittoHeaders dittoHeaders = command.getDittoHeaders(); + + final String namespace = command.getNamespace().orElse(null); + + final Function fieldSelectorToResponse = + fieldSelector -> RetrieveThingsResponse.of(things, fieldSelector, predicate, namespace, dittoHeaders); + + return command.getSelectedFields() + .map(fieldSelectorToResponse) + .orElse(RetrieveThingsResponse.of(things, predicate, namespace, dittoHeaders)); + } + + @Nonnull + @Override + public RetrieveThingsResponse retrieved(final List things) { + return retrieved(things, jsonField -> true); + } + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommandImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommandImpl.java new file mode 100644 index 00000000..e50271f4 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommandImpl.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import java.util.List; +import java.util.Optional; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; +import javax.annotation.concurrent.Immutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.ThingId; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.query.RetrieveThings; + +/** + * An immutable implementation of {@link RetrieveThingsLiveCommand}. + * + * @since 2.0.0 + */ +@ParametersAreNonnullByDefault +@Immutable +final class RetrieveThingsLiveCommandImpl extends AbstractQueryLiveCommand implements RetrieveThingsLiveCommand { + + private final List thingIds; + @Nullable private final String namespace; + + private RetrieveThingsLiveCommandImpl(final RetrieveThings command) { + super(command); + thingIds = command.getThingEntityIds(); + namespace = command.getNamespace().orElse(null); + } + + /** + * Returns an instance of {@code RetrieveThingsLiveCommandImpl}. + * + * @param command the command to base the result on. + * @return the instance. + * @throws NullPointerException if {@code command} is {@code null}. + * @throws ClassCastException if {@code command} is not an instance of {@link RetrieveThings}. + */ + @Nonnull + public static RetrieveThingsLiveCommandImpl of(final Command command) { + return new RetrieveThingsLiveCommandImpl((RetrieveThings) command); + } + + @Nonnull + @Override + public List getThingEntityIds() { + return thingIds; + } + + @Nonnull + @Override + public Optional getNamespace() { + return Optional.ofNullable(namespace); + } + + @Override + public RetrieveThingsLiveCommand setDittoHeaders(final DittoHeaders dittoHeaders) { + final RetrieveThings retrieveThingsCommand = RetrieveThings.getBuilder(getThingEntityIds()) + .dittoHeaders(dittoHeaders) + .selectedFields(getSelectedFields().orElse(null)) + .build(); + + return RetrieveThingsLiveCommandImpl.of(retrieveThingsCommand); + } + + @Nonnull + @Override + public RetrieveThingsLiveCommandAnswerBuilder answer() { + return RetrieveThingsLiveCommandAnswerBuilderImpl.newInstance(this); + } + + @Nonnull + @Override + public String toString() { + return getClass().getSimpleName() + "[" + super.toString() + ", namespace=" + namespace + "]"; + } + +} diff --git a/java/src/main/java/org/eclipse/ditto/client/live/commands/query/package-info.java b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/package-info.java new file mode 100644 index 00000000..6fd931b8 --- /dev/null +++ b/java/src/main/java/org/eclipse/ditto/client/live/commands/query/package-info.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ + +/** + * This package contains implementations of {@link org.eclipse.ditto.client.live.commands.base.LiveCommand + * LiveCommand} and {@link org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder + * LiveCommandAnswerBuilder} for query operations. + */ +package org.eclipse.ditto.client.live.commands.query; diff --git a/java/src/main/java/org/eclipse/ditto/client/live/internal/LiveFeatureHandleImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/internal/LiveFeatureHandleImpl.java index 37f46c7d..0eabb803 100755 --- a/java/src/main/java/org/eclipse/ditto/client/live/internal/LiveFeatureHandleImpl.java +++ b/java/src/main/java/org/eclipse/ditto/client/live/internal/LiveFeatureHandleImpl.java @@ -29,6 +29,7 @@ import org.eclipse.ditto.client.live.LiveFeatureHandle; import org.eclipse.ditto.client.live.LiveThingHandle; import org.eclipse.ditto.client.live.commands.LiveCommandHandler; +import org.eclipse.ditto.client.live.commands.base.LiveCommand; import org.eclipse.ditto.client.live.events.FeatureEventFactory; import org.eclipse.ditto.client.live.events.internal.ImmutableFeatureEventFactory; import org.eclipse.ditto.client.live.messages.MessageSerializerRegistry; @@ -42,7 +43,6 @@ import org.eclipse.ditto.model.things.ThingId; import org.eclipse.ditto.protocoladapter.TopicPath; import org.eclipse.ditto.signals.base.Signal; -import org.eclipse.ditto.signals.commands.live.base.LiveCommand; import org.eclipse.ditto.signals.events.base.Event; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/java/src/main/java/org/eclipse/ditto/client/live/internal/LiveImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/internal/LiveImpl.java index 27a5232f..4931c029 100644 --- a/java/src/main/java/org/eclipse/ditto/client/live/internal/LiveImpl.java +++ b/java/src/main/java/org/eclipse/ditto/client/live/internal/LiveImpl.java @@ -36,7 +36,9 @@ import org.eclipse.ditto.client.live.LiveCommandProcessor; import org.eclipse.ditto.client.live.LiveFeatureHandle; import org.eclipse.ditto.client.live.LiveThingHandle; +import org.eclipse.ditto.client.live.commands.LiveCommandFactory; import org.eclipse.ditto.client.live.commands.LiveCommandHandler; +import org.eclipse.ditto.client.live.commands.base.LiveCommand; import org.eclipse.ditto.client.live.events.GlobalEventFactory; import org.eclipse.ditto.client.live.events.internal.ImmutableGlobalEventFactory; import org.eclipse.ditto.client.live.messages.MessageSerializerRegistry; @@ -54,8 +56,6 @@ import org.eclipse.ditto.protocoladapter.ProtocolFactory; import org.eclipse.ditto.protocoladapter.TopicPath; import org.eclipse.ditto.signals.base.Signal; -import org.eclipse.ditto.signals.commands.live.LiveCommandFactory; -import org.eclipse.ditto.signals.commands.live.base.LiveCommand; import org.eclipse.ditto.signals.commands.messages.MessageCommand; import org.eclipse.ditto.signals.commands.messages.MessageCommandResponse; import org.eclipse.ditto.signals.commands.things.ThingCommand; diff --git a/java/src/main/java/org/eclipse/ditto/client/live/internal/LiveThingHandleImpl.java b/java/src/main/java/org/eclipse/ditto/client/live/internal/LiveThingHandleImpl.java index 0791a789..e4c177d5 100755 --- a/java/src/main/java/org/eclipse/ditto/client/live/internal/LiveThingHandleImpl.java +++ b/java/src/main/java/org/eclipse/ditto/client/live/internal/LiveThingHandleImpl.java @@ -29,6 +29,7 @@ import org.eclipse.ditto.client.live.LiveFeatureHandle; import org.eclipse.ditto.client.live.LiveThingHandle; import org.eclipse.ditto.client.live.commands.LiveCommandHandler; +import org.eclipse.ditto.client.live.commands.base.LiveCommand; import org.eclipse.ditto.client.live.events.ThingEventFactory; import org.eclipse.ditto.client.live.events.internal.ImmutableThingEventFactory; import org.eclipse.ditto.client.live.messages.MessageSerializerRegistry; @@ -43,7 +44,6 @@ import org.eclipse.ditto.model.things.ThingId; import org.eclipse.ditto.protocoladapter.TopicPath; import org.eclipse.ditto.signals.base.Signal; -import org.eclipse.ditto.signals.commands.live.base.LiveCommand; import org.eclipse.ditto.signals.events.base.Event; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/java/src/test/java/org/eclipse/ditto/client/DittoClientLiveTest.java b/java/src/test/java/org/eclipse/ditto/client/DittoClientLiveTest.java index ddce7896..d845a984 100644 --- a/java/src/test/java/org/eclipse/ditto/client/DittoClientLiveTest.java +++ b/java/src/test/java/org/eclipse/ditto/client/DittoClientLiveTest.java @@ -32,6 +32,9 @@ import org.eclipse.ditto.client.live.commands.FeaturesCommandHandling; import org.eclipse.ditto.client.live.commands.LiveCommandHandler; import org.eclipse.ditto.client.live.commands.ThingCommandHandling; +import org.eclipse.ditto.client.live.commands.modify.CreateThingLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.CreateThingLiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.modify.DeleteFeatureLiveCommandAnswerBuilder; import org.eclipse.ditto.client.live.events.FeatureEventFactory; import org.eclipse.ditto.client.live.messages.MessageRegistration; import org.eclipse.ditto.client.live.messages.MessageSender; @@ -54,9 +57,6 @@ import org.eclipse.ditto.signals.acks.base.Acknowledgements; import org.eclipse.ditto.signals.acks.things.ThingAcknowledgementFactory; import org.eclipse.ditto.signals.base.Signal; -import org.eclipse.ditto.signals.commands.live.modify.CreateThingLiveCommand; -import org.eclipse.ditto.signals.commands.live.modify.CreateThingLiveCommandAnswerBuilder; -import org.eclipse.ditto.signals.commands.live.modify.DeleteFeatureLiveCommandAnswerBuilder; import org.eclipse.ditto.signals.commands.messages.MessageCommand; import org.eclipse.ditto.signals.commands.messages.MessageCommandResponse; import org.eclipse.ditto.signals.commands.messages.SendClaimMessage; diff --git a/java/src/test/java/org/eclipse/ditto/client/DittoClientUsageExamples.java b/java/src/test/java/org/eclipse/ditto/client/DittoClientUsageExamples.java index eb734e56..6cbeb257 100755 --- a/java/src/test/java/org/eclipse/ditto/client/DittoClientUsageExamples.java +++ b/java/src/test/java/org/eclipse/ditto/client/DittoClientUsageExamples.java @@ -45,6 +45,8 @@ import org.eclipse.ditto.client.configuration.ProxyConfiguration; import org.eclipse.ditto.client.configuration.TrustStoreConfiguration; import org.eclipse.ditto.client.configuration.WebSocketMessagingConfiguration; +import org.eclipse.ditto.client.live.commands.modify.CreateThingLiveCommandAnswerBuilder; +import org.eclipse.ditto.client.live.commands.modify.ModifyFeaturePropertyLiveCommandAnswerBuilder; import org.eclipse.ditto.client.messaging.AuthenticationProvider; import org.eclipse.ditto.client.messaging.AuthenticationProviders; import org.eclipse.ditto.client.messaging.MessagingProvider; @@ -67,8 +69,6 @@ import org.eclipse.ditto.model.things.ThingsModelFactory; import org.eclipse.ditto.protocoladapter.JsonifiableAdaptable; import org.eclipse.ditto.protocoladapter.ProtocolFactory; -import org.eclipse.ditto.signals.commands.live.modify.CreateThingLiveCommandAnswerBuilder; -import org.eclipse.ditto.signals.commands.live.modify.ModifyFeaturePropertyLiveCommandAnswerBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/java/src/test/java/org/eclipse/ditto/client/RunOSGiContainerIntegrationTest.java b/java/src/test/java/org/eclipse/ditto/client/RunOSGiContainerIntegrationTest.java index 2668955c..722e253b 100755 --- a/java/src/test/java/org/eclipse/ditto/client/RunOSGiContainerIntegrationTest.java +++ b/java/src/test/java/org/eclipse/ditto/client/RunOSGiContainerIntegrationTest.java @@ -44,6 +44,13 @@ import org.atteo.classindex.ClassIndex; import org.eclipse.ditto.client.configuration.MessagingConfiguration; import org.eclipse.ditto.client.live.LiveThingHandle; +import org.eclipse.ditto.client.live.commands.LiveCommandFactory; +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.client.live.commands.base.LiveEventFactory; +import org.eclipse.ditto.client.live.commands.modify.CreateThingLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.ModifyLiveCommandFactory; +import org.eclipse.ditto.client.live.commands.query.QueryLiveCommandFactory; +import org.eclipse.ditto.client.live.commands.query.RetrieveThingLiveCommand; import org.eclipse.ditto.client.live.messages.MessageSender; import org.eclipse.ditto.client.live.messages.MessageSerializer; import org.eclipse.ditto.client.messaging.MessagingException; @@ -67,13 +74,6 @@ import org.eclipse.ditto.signals.base.JsonParsable; import org.eclipse.ditto.signals.commands.base.Command; import org.eclipse.ditto.signals.commands.base.CommandResponse; -import org.eclipse.ditto.signals.commands.live.LiveCommandFactory; -import org.eclipse.ditto.signals.commands.live.base.LiveCommand; -import org.eclipse.ditto.signals.commands.live.base.LiveEventFactory; -import org.eclipse.ditto.signals.commands.live.modify.CreateThingLiveCommand; -import org.eclipse.ditto.signals.commands.live.modify.ModifyLiveCommandFactory; -import org.eclipse.ditto.signals.commands.live.query.QueryLiveCommandFactory; -import org.eclipse.ditto.signals.commands.live.query.RetrieveThingLiveCommand; import org.eclipse.ditto.signals.commands.messages.MessageCommand; import org.eclipse.ditto.signals.commands.messages.MessageCommandResponse; import org.eclipse.ditto.signals.commands.things.ThingCommand; diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/assertions/LiveCommandAnswerAssert.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/assertions/LiveCommandAnswerAssert.java new file mode 100644 index 00000000..392c9529 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/assertions/LiveCommandAnswerAssert.java @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.assertions; + +import java.util.Optional; + +import org.assertj.core.api.AbstractAssert; +import org.assertj.core.api.Assertions; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions; +import org.eclipse.ditto.signals.commands.base.assertions.CommandResponseAssert; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.modify.MergeThingResponse; +import org.eclipse.ditto.signals.commands.things.modify.ThingModifyCommandResponse; +import org.eclipse.ditto.signals.commands.things.query.ThingQueryCommandResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.ThingModifiedEvent; +import org.eclipse.ditto.signals.events.things.assertions.ThingEventAssertions; +import org.eclipse.ditto.signals.events.things.assertions.ThingModifiedEventAssert; + +/** + * An assert for {@link org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer}s. + */ +public class LiveCommandAnswerAssert extends AbstractAssert { + + /** + * Constructs a new {@code LiveCommandAnswerAssert} object. + * + * @param actual the live command answer to be checked. + */ + public LiveCommandAnswerAssert(final LiveCommandAnswer actual) { + super(actual, LiveCommandAnswerAssert.class); + } + + public LiveCommandAnswerAssert hasNoEvent() { + isNotNull(); + final Optional actualEvent = actual.getEvent(); + Assertions.assertThat(actualEvent) + .overridingErrorMessage("Expected LiveCommandAnswer not to have an event but it had\n<%s>", + actualEvent.orElse(null)) + .isEmpty(); + return myself; + } + + public LiveCommandAnswerAssert hasEvent(final Event expectedEvent) { + isNotNull(); + final Optional actualEvent = actual.getEvent(); + Assertions.assertThat(actualEvent) + .overridingErrorMessage("Expected LiveCommandAnswer to have event\n<%s> but it had\n<%s>", + expectedEvent, actualEvent.orElse(null)) + .contains(expectedEvent); + return myself; + } + + public LiveCommandAnswerAssert hasResponse(final CommandResponse expectedCommandResponse) { + isNotNull(); + final Optional actualResponse = actual.getResponse(); + Assertions.assertThat(actualResponse) + .overridingErrorMessage("Expected LiveCommandAnswer to have response\n<%s> but it had\n<%s>", + expectedCommandResponse, actualResponse.orElse(null)) + .contains(expectedCommandResponse); + return myself; + } + + public CommandResponseAssert hasThingModifyCommandResponse() { + isNotNull(); + final Optional actualResponse = actual.getResponse(); + Assertions.assertThat(actualResponse) + .overridingErrorMessage("Expected LiveCommandAnswer to have a response but it had none") + .isPresent(); + + final CommandResponse commandResponse = actualResponse.orElse(null); + Assertions.assertThat(commandResponse) + .overridingErrorMessage("Expected LiveCommandAnswer has a\n but it " + + "had a\n<%s>", commandResponse.getClass().getSimpleName()) + .isInstanceOf(ThingModifyCommandResponse.class); + + return CommandAssertions.assertThat((ThingModifyCommandResponse) commandResponse); + } + + public CommandResponseAssert hasThingMergeCommandResponse() { + isNotNull(); + final Optional actualResponse = actual.getResponse(); + Assertions.assertThat(actualResponse) + .overridingErrorMessage("Expected LiveCommandAnswer to have a response but it had none") + .isPresent(); + + final CommandResponse commandResponse = actualResponse.orElse(null); + Assertions.assertThat(commandResponse) + .overridingErrorMessage("Expected LiveCommandAnswer has a\n but it " + + "had a\n<%s>", commandResponse.getClass().getSimpleName()) + .isInstanceOf(MergeThingResponse.class); + + return CommandAssertions.assertThat((MergeThingResponse) commandResponse); + } + + public ThingErrorResponseAssert hasThingErrorResponse() { + isNotNull(); + final Optional actualResponse = actual.getResponse(); + Assertions.assertThat(actualResponse) + .overridingErrorMessage("Expected LiveCommandAnswer to have a response but it had none") + .isPresent(); + + final CommandResponse commandResponse = actualResponse.orElse(null); + Assertions.assertThat(commandResponse) + .overridingErrorMessage("Expected LiveCommandAnswer has a\n but it " + + "had a\n<%s>", commandResponse.getClass().getSimpleName()) + .isInstanceOf(ThingErrorResponse.class); + + return new ThingErrorResponseAssert((ThingErrorResponse) commandResponse); + } + + public LiveCommandAnswerAssert hasNoResponse() { + isNotNull(); + final Optional actualResponse = actual.getResponse(); + Assertions.assertThat(actualResponse) + .overridingErrorMessage("Expected LiveCommandAnswer not to have a response but it had\n<%s>", + actualResponse.orElse(null)) + .isEmpty(); + return myself; + } + + public CommandResponseAssert hasThingQueryCommandResponse() { + isNotNull(); + final Optional actualResponse = actual.getResponse(); + Assertions.assertThat(actualResponse) + .overridingErrorMessage("Expected LiveCommandAnswer to have a response but it had none") + .isPresent(); + + final CommandResponse commandResponse = actualResponse.orElse(null); + Assertions.assertThat(commandResponse) + .overridingErrorMessage("Expected LiveCommandAnswer has a\n but it " + + "had a\n<%s>", commandResponse.getClass().getSimpleName()) + .isInstanceOf(ThingQueryCommandResponse.class); + + return CommandAssertions.assertThat((ThingQueryCommandResponse) commandResponse); + } + + public ThingModifiedEventAssert hasThingModifiedEvent() { + isNotNull(); + final Optional actualEvent = actual.getEvent(); + Assertions.assertThat(actualEvent) + .overridingErrorMessage("Expected LiveCommandAnswer to have an event but it had none") + .isPresent(); + + final Event event = actualEvent.orElse(null); + Assertions.assertThat(event) + .overridingErrorMessage("Expected LiveCommandAnswer has a\n but it " + + "had a\n<%s>", event.getClass().getSimpleName()) + .isInstanceOf(ThingModifiedEvent.class); + + return ThingEventAssertions.assertThat((ThingModifiedEvent) event); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/assertions/LiveCommandAssert.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/assertions/LiveCommandAssert.java new file mode 100644 index 00000000..e381928a --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/assertions/LiveCommandAssert.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.assertions; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.signals.commands.base.assertions.AbstractCommandAssert; + +/** + * An Assert for {@link org.eclipse.ditto.client.live.commands.base.LiveCommand}s. + */ +public class LiveCommandAssert extends AbstractCommandAssert { + + /** + * Constructs a new {@code LiveCommandAssert} object. + * + * @param actual the command response to be checked. + */ + public LiveCommandAssert(final LiveCommand actual) { + super(actual, LiveCommandAssert.class); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/assertions/LiveCommandAssertions.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/assertions/LiveCommandAssertions.java new file mode 100644 index 00000000..2be4d8c1 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/assertions/LiveCommandAssertions.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.assertions; + +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions; + +/** + * Custom test assertions for {@link org.eclipse.ditto.client.live.commands.base.LiveCommand}s. + */ +public class LiveCommandAssertions extends CommandAssertions { + + public static LiveCommandAssert assertThat(final LiveCommand liveCommand) { + return new LiveCommandAssert(liveCommand); + } + + /** + * Returns an Assert for checking the given {@link org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer}. + * + * @param liveCommandAnswer the live command answer to be checked. + * @return the Assert. + */ + public static LiveCommandAnswerAssert assertThat(final LiveCommandAnswer liveCommandAnswer) { + return new LiveCommandAnswerAssert(liveCommandAnswer); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/assertions/LiveCommandFactoryTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/assertions/LiveCommandFactoryTest.java new file mode 100644 index 00000000..1175680c --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/assertions/LiveCommandFactoryTest.java @@ -0,0 +1,360 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.assertions; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.AllowedReason.assumingFields; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.ditto.client.live.commands.LiveCommandFactory; +import org.eclipse.ditto.client.live.commands.base.LiveCommand; +import org.eclipse.ditto.client.live.commands.modify.CreateThingLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.DeleteAttributeLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.DeleteAttributesLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.DeleteFeatureLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.DeleteFeaturePropertiesLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.DeleteFeaturePropertyLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.DeleteFeaturesLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.DeleteThingLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.MergeThingLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.ModifyAttributeLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.ModifyAttributesLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.ModifyFeatureLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.ModifyFeaturePropertiesLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.ModifyFeaturePropertyLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.ModifyFeaturesLiveCommand; +import org.eclipse.ditto.client.live.commands.modify.ModifyThingLiveCommand; +import org.eclipse.ditto.client.live.commands.query.RetrieveAttributeLiveCommand; +import org.eclipse.ditto.client.live.commands.query.RetrieveAttributesLiveCommand; +import org.eclipse.ditto.client.live.commands.query.RetrieveFeatureLiveCommand; +import org.eclipse.ditto.client.live.commands.query.RetrieveFeaturePropertiesLiveCommand; +import org.eclipse.ditto.client.live.commands.query.RetrieveFeaturePropertyLiveCommand; +import org.eclipse.ditto.client.live.commands.query.RetrieveFeaturesLiveCommand; +import org.eclipse.ditto.client.live.commands.query.RetrieveThingLiveCommand; +import org.eclipse.ditto.client.live.commands.query.RetrieveThingsLiveCommand; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.ThingId; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.modify.CreateThing; +import org.eclipse.ditto.signals.commands.things.modify.DeleteAttribute; +import org.eclipse.ditto.signals.commands.things.modify.DeleteAttributes; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeature; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureProperties; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureProperty; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatures; +import org.eclipse.ditto.signals.commands.things.modify.DeleteThing; +import org.eclipse.ditto.signals.commands.things.modify.MergeThing; +import org.eclipse.ditto.signals.commands.things.modify.ModifyAttribute; +import org.eclipse.ditto.signals.commands.things.modify.ModifyAttributes; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeature; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureProperties; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureProperty; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatures; +import org.eclipse.ditto.signals.commands.things.modify.ModifyThing; +import org.eclipse.ditto.signals.commands.things.query.RetrieveAttribute; +import org.eclipse.ditto.signals.commands.things.query.RetrieveAttributes; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeature; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureProperties; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureProperty; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatures; +import org.eclipse.ditto.signals.commands.things.query.RetrieveThing; +import org.eclipse.ditto.signals.commands.things.query.RetrieveThings; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.LiveCommandFactory}. + */ +public final class LiveCommandFactoryTest { + + private LiveCommandFactory underTest; + + /** */ + @Before + public void setUp() { + underTest = LiveCommandFactory.getInstance(); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(LiveCommandFactory.class, + areImmutable(), + assumingFields("mappingStrategies").areSafelyCopiedUnmodifiableCollectionsWithImmutableElements()); + } + + /** */ + @Test + public void liveCommandFactoryIsSingleton() { + assertThat(underTest).isSameAs(LiveCommandFactory.getInstance()); + } + + /** + * This test runs in Maven just fine. Under IntelliJ it fails because IntelliJ reacts to violations of {@code + * @Nonnull} annotations by its own with an IllegalArgumentException. + */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetLiveCommandForNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> underTest.getLiveCommand(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetLiveCommandForCommandWithUnknownType() { + final Command commandMock = Mockito.mock(Command.class); + Mockito.when(commandMock.getType()).thenReturn("Harambe"); + + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> underTest.getLiveCommand(commandMock)) + .withMessage("No mapping strategy for command <%s> available! The command type <%s> is unknown!", + commandMock, commandMock.getType()) + .withNoCause(); + } + + /** */ + @Test + public void getCreateThingLiveCommandForCreateThing() { + final CreateThing twinCommand = CreateThing.of(TestConstants.Thing.THING, null, DittoHeaders.empty()); + createAndCheckLiveCommandFor(twinCommand, CreateThingLiveCommand.class); + } + + /** */ + @Test + public void getDeleteAttributeLiveCommandForDeleteAttribute() { + final DeleteAttribute twinCommand = DeleteAttribute.of(TestConstants.Thing.THING_ID, + TestConstants.Thing.LOCATION_ATTRIBUTE_POINTER, DittoHeaders.empty()); + createAndCheckLiveCommandFor(twinCommand, DeleteAttributeLiveCommand.class); + } + + /** */ + @Test + public void getDeleteAttributesLiveCommandForDeleteAttributes() { + final DeleteAttributes twinCommand = DeleteAttributes.of(TestConstants.Thing.THING_ID, DittoHeaders.empty()); + createAndCheckLiveCommandFor(twinCommand, DeleteAttributesLiveCommand.class); + } + + /** */ + @Test + public void getDeleteFeatureLiveCommandForDeleteFeature() { + final DeleteFeature twinCommand = + DeleteFeature.of(TestConstants.Thing.THING_ID, TestConstants.Feature.FLUX_CAPACITOR_ID, + DittoHeaders + .empty()); + createAndCheckLiveCommandFor(twinCommand, DeleteFeatureLiveCommand.class); + } + + /** */ + @Test + public void getDeleteFeaturePropertiesLiveCommandForDeleteFeatureProperties() { + final DeleteFeatureProperties twinCommand = + DeleteFeatureProperties.of(TestConstants.Thing.THING_ID, TestConstants.Feature.FLUX_CAPACITOR_ID, + DittoHeaders.empty()); + createAndCheckLiveCommandFor(twinCommand, DeleteFeaturePropertiesLiveCommand.class); + } + + /** */ + @Test + public void getDeleteFeaturePropertyLiveCommandForDeleteFeatureProperty() { + final DeleteFeatureProperty twinCommand = + DeleteFeatureProperty.of(TestConstants.Thing.THING_ID, TestConstants.Feature.FLUX_CAPACITOR_ID, + TestConstants.Feature.FLUX_CAPACITOR_PROPERTY_POINTER, DittoHeaders.empty()); + createAndCheckLiveCommandFor(twinCommand, DeleteFeaturePropertyLiveCommand.class); + } + + /** */ + @Test + public void getDeleteFeaturesLiveCommandForDeleteFeatures() { + final DeleteFeatures twinCommand = DeleteFeatures.of(TestConstants.Thing.THING_ID, DittoHeaders.empty()); + createAndCheckLiveCommandFor(twinCommand, DeleteFeaturesLiveCommand.class); + } + + /** */ + @Test + public void getDeleteThingLiveCommandForDeleteThing() { + final DeleteThing twinCommand = DeleteThing.of(TestConstants.Thing.THING_ID, DittoHeaders.empty()); + createAndCheckLiveCommandFor(twinCommand, DeleteThingLiveCommand.class); + } + + /** */ + @Test + public void getModifyAttributeLiveCommandForModifyAttribute() { + final ModifyAttribute twinCommand = + ModifyAttribute.of(TestConstants.Thing.THING_ID, TestConstants.Thing.LOCATION_ATTRIBUTE_POINTER, + TestConstants.Thing.LOCATION_ATTRIBUTE_VALUE, DittoHeaders.empty()); + createAndCheckLiveCommandFor(twinCommand, ModifyAttributeLiveCommand.class); + } + + /** */ + @Test + public void getModifyAttributesLiveCommandForModifyAttributes() { + final ModifyAttributes twinCommand = + ModifyAttributes.of(TestConstants.Thing.THING_ID, TestConstants.Thing.ATTRIBUTES, + DittoHeaders.empty()); + createAndCheckLiveCommandFor(twinCommand, ModifyAttributesLiveCommand.class); + } + + /** */ + @Test + public void getModifyFeatureLiveCommandForModifyFeature() { + final ModifyFeature twinCommand = + ModifyFeature.of(TestConstants.Thing.THING_ID, TestConstants.Feature.FLUX_CAPACITOR, + DittoHeaders.empty()); + createAndCheckLiveCommandFor(twinCommand, ModifyFeatureLiveCommand.class); + } + + /** */ + @Test + public void getModifyFeaturePropertiesLiveCommandForModifyFeatureProperties() { + final ModifyFeatureProperties twinCommand = + ModifyFeatureProperties.of(TestConstants.Thing.THING_ID, TestConstants.Feature.FLUX_CAPACITOR_ID, + TestConstants.Feature.FLUX_CAPACITOR_PROPERTIES, DittoHeaders.empty()); + createAndCheckLiveCommandFor(twinCommand, ModifyFeaturePropertiesLiveCommand.class); + } + + /** */ + @Test + public void getModifyFeaturePropertyLiveCommandForModifyFeatureProperty() { + final ModifyFeatureProperty twinCommand = + ModifyFeatureProperty.of(TestConstants.Thing.THING_ID, TestConstants.Feature.FLUX_CAPACITOR_ID, + TestConstants.Feature.FLUX_CAPACITOR_PROPERTY_POINTER, + TestConstants.Feature.FLUX_CAPACITOR_PROPERTY_VALUE, DittoHeaders.empty()); + createAndCheckLiveCommandFor(twinCommand, ModifyFeaturePropertyLiveCommand.class); + } + + /** */ + @Test + public void getModifyFeaturesLiveCommandForModifyFeatures() { + final ModifyFeatures twinCommand = + ModifyFeatures.of(TestConstants.Thing.THING_ID, TestConstants.Feature.FEATURES, DittoHeaders.empty()); + createAndCheckLiveCommandFor(twinCommand, ModifyFeaturesLiveCommand.class); + } + + /** + * + */ + @Test + public void getModifyThingLiveCommandForModifyThing() { + final ModifyThing twinCommand = ModifyThing.of(TestConstants.Thing.THING_ID, TestConstants.Thing.THING, null, + DittoHeaders.empty()); + createAndCheckLiveCommandFor(twinCommand, ModifyThingLiveCommand.class); + } + + /** + * + */ + @Test + public void getMergeThingLiveCommandForMergeThing() { + final MergeThing twinCommand = + MergeThing.of(TestConstants.Thing.THING_ID, TestConstants.PATH, TestConstants.VALUE, + DittoHeaders.empty()); + createAndCheckLiveCommandFor(twinCommand, MergeThingLiveCommand.class); + } + + /** + * + */ + @Test + public void getRetrieveAttributeLiveCommandForRetrieveAttribute() { + final RetrieveAttribute twinCommand = + RetrieveAttribute.of(TestConstants.Thing.THING_ID, TestConstants.Thing.LOCATION_ATTRIBUTE_POINTER, + DittoHeaders.empty()); + createAndCheckLiveCommandFor(twinCommand, RetrieveAttributeLiveCommand.class); + } + + /** */ + @Test + public void getRetrieveAttributesLiveCommandForRetrieveAttributes() { + final RetrieveAttributes twinCommand = + RetrieveAttributes.of(TestConstants.Thing.THING_ID, TestConstants.JSON_FIELD_SELECTOR_ATTRIBUTES, + DittoHeaders.empty()); + createAndCheckLiveCommandFor(twinCommand, RetrieveAttributesLiveCommand.class); + } + + /** */ + @Test + public void getRetrieveFeatureLiveCommandForRetrieveFeature() { + final RetrieveFeature twinCommand = + RetrieveFeature.of(TestConstants.Thing.THING_ID, TestConstants.Feature.FLUX_CAPACITOR_ID, + DittoHeaders.empty()); + createAndCheckLiveCommandFor(twinCommand, RetrieveFeatureLiveCommand.class); + } + + /** */ + @Test + public void getRetrieveFeaturePropertiesLiveCommandForRetrieveFeatureProperties() { + final RetrieveFeatureProperties twinCommand = + RetrieveFeatureProperties.of(TestConstants.Thing.THING_ID, TestConstants.Feature.FLUX_CAPACITOR_ID, + TestConstants.JSON_FIELD_SELECTOR_FEATURE_PROPERTIES, DittoHeaders.empty()); + createAndCheckLiveCommandFor(twinCommand, RetrieveFeaturePropertiesLiveCommand.class); + } + + /** */ + @Test + public void getRetrieveFeaturePropertyLiveCommandForRetrieveFeatureProperty() { + final RetrieveFeatureProperty twinCommand = + RetrieveFeatureProperty.of(TestConstants.Thing.THING_ID, TestConstants.Feature.FLUX_CAPACITOR_ID, + TestConstants.Feature.FLUX_CAPACITOR_PROPERTY_POINTER, DittoHeaders.empty()); + createAndCheckLiveCommandFor(twinCommand, RetrieveFeaturePropertyLiveCommand.class); + } + + /** */ + @Test + public void getRetrieveFeaturesLiveCommandForRetrieveFeatures() { + final RetrieveFeatures twinCommand = RetrieveFeatures.of(TestConstants.Thing.THING_ID, DittoHeaders.empty()); + createAndCheckLiveCommandFor(twinCommand, RetrieveFeaturesLiveCommand.class); + } + + /** */ + @Test + public void getRetrieveThingLiveCommandForRetrieveThing() { + final RetrieveThing twinCommand = RetrieveThing.of(TestConstants.Thing.THING_ID, DittoHeaders.empty()); + createAndCheckLiveCommandFor(twinCommand, RetrieveThingLiveCommand.class); + } + + /** */ + @Test + public void getRetrieveThingsLiveCommandForRetrieveThing() { + final List thingIds = Arrays.asList(ThingId.inDefaultNamespace("boatyMcBoatface"), + ThingId.inDefaultNamespace("Harambe")); + final RetrieveThings twinCommand = RetrieveThings.getBuilder(thingIds) + .dittoHeaders(DittoHeaders.empty()) + .build(); + createAndCheckLiveCommandFor(twinCommand, RetrieveThingsLiveCommand.class); + } + + private void createAndCheckLiveCommandFor(final Command twinCommand, + final Class expectedLiveCommandClass) { + final LiveCommand liveCommand = underTest.getLiveCommand(twinCommand); + + assertThat(liveCommand) + .withType(twinCommand.getType()) + .withResourcePath(twinCommand.getResourcePath()) + .withDittoHeaders(twinCommand.getDittoHeaders()) + .withManifest(twinCommand.getManifest()) + .hasJsonString(twinCommand.toJsonString()) + .isInstanceOf(expectedLiveCommandClass); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/assertions/ThingErrorResponseAssert.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/assertions/ThingErrorResponseAssert.java new file mode 100644 index 00000000..cbb0da14 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/assertions/ThingErrorResponseAssert.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.assertions; + +import org.assertj.core.api.Assertions; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.exceptions.DittoRuntimeException; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.assertions.AbstractCommandResponseAssert; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; + +/** + * An assert for {@link org.eclipse.ditto.signals.commands.things.ThingErrorResponse}. + */ +public final class ThingErrorResponseAssert extends AbstractCommandResponseAssert { + + public ThingErrorResponseAssert(final ThingErrorResponse actual) { + super(actual, ThingErrorResponseAssert.class); + } + + public ThingErrorResponseAssert withType(final CharSequence expectedType) { + return hasType(expectedType); + } + + public ThingErrorResponseAssert withDittoHeaders(final DittoHeaders expectedDittoHeaders) { + return hasDittoHeaders(expectedDittoHeaders); + } + + /** + * @since 2.0.0 + */ + public ThingErrorResponseAssert withStatus(final HttpStatus expectedStatus) { + return hasStatus(expectedStatus); + } + + public ThingErrorResponseAssert withDittoRuntimeException( + final DittoRuntimeException expectedDittoRuntimeException) { + return assertThatEquals(actual.getDittoRuntimeException(), expectedDittoRuntimeException, + "DittoRuntimeException"); + } + + public ThingErrorResponseAssert withDittoRuntimeExceptionOfType( + final Class expectedType) { + isNotNull(); + final DittoRuntimeException DittoRuntimeException = actual.getDittoRuntimeException(); + Assertions.assertThat(DittoRuntimeException) + .overridingErrorMessage( + "Expected DittoRuntimeException of ThingErrorResponse is of type\n<%s> but it " + + "was\n<%s>", expectedType.getSimpleName(), + DittoRuntimeException.getClass().getSimpleName()) + .isInstanceOf(expectedType); + return myself; + } + + private ThingErrorResponseAssert assertThatEquals(final T actual, final T expected, final String propertyName) { + isNotNull(); + Assertions.assertThat(actual) // + .overridingErrorMessage("Expected ThingErrorResponse to have %s " + "\n<%s> but it had\n<%s>", + propertyName, expected, actual) // + .isEqualTo(expected); + return this; + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/base/ImmutableLiveCommandAnswerTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/base/ImmutableLiveCommandAnswerTest.java new file mode 100644 index 00000000..6f90243a --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/base/ImmutableLiveCommandAnswerTest.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.base; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mutabilitydetector.unittesting.AllowedReason.provided; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.commands.things.ThingCommandResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.eclipse.ditto.signals.events.things.ThingEvent; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.base.ImmutableLiveCommandAnswer}. + */ +public final class ImmutableLiveCommandAnswerTest { + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(ImmutableLiveCommandAnswer.class, + areImmutable(), + provided(CommandResponse.class, Event.class).areAlsoImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(ImmutableLiveCommandAnswer.class) // + .usingGetClass() // + .verify(); + } + + /** */ + @Test + public void getResponseReturnsEmptyOptionalForNullResponse() { + final ImmutableLiveCommandAnswer underTest = ImmutableLiveCommandAnswer.newInstance(null, null); + + assertThat(underTest.getResponse()).isEmpty(); + } + + /** */ + @Test + public void getEventReturnsEmptyOptionalForNullEvent() { + final ImmutableLiveCommandAnswer underTest = ImmutableLiveCommandAnswer.newInstance(null, null); + + assertThat(underTest.getEvent()).isEmpty(); + } + + /** */ + @Test + public void getResponseReturnsExpected() { + final ThingCommandResponse responseMock = Mockito.mock(ThingCommandResponse.class); + final ImmutableLiveCommandAnswer underTest = ImmutableLiveCommandAnswer.newInstance(responseMock, null); + + assertThat(underTest.getResponse()).contains(responseMock); + } + + /** */ + @Test + public void getEventReturnsExpected() { + final ThingEvent eventMock = Mockito.mock(ThingEvent.class); + final ImmutableLiveCommandAnswer underTest = ImmutableLiveCommandAnswer.newInstance(null, eventMock); + + assertThat(underTest.getEvent()).contains(eventMock); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/base/LiveCommandAnswerFactoryTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/base/LiveCommandAnswerFactoryTest.java new file mode 100644 index 00000000..0afb31dd --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/base/LiveCommandAnswerFactoryTest.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.base; + +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions; +import org.eclipse.ditto.signals.commands.base.CommandResponse; +import org.eclipse.ditto.signals.events.base.Event; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerFactory}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class LiveCommandAnswerFactoryTest { + + @Mock + private CommandResponse commandResponseMock; + + @Mock + private Event eventMock; + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(LiveCommandAnswerFactory.class, areImmutable()); + } + + /** */ + @Test + public void getLiveCommandAnswerInstanceWithCommandResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = LiveCommandAnswerFactory.newLiveCommandAnswer(commandResponseMock); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasResponse(commandResponseMock) + .hasNoEvent(); + } + + /** */ + @Test + public void getLiveCommandAnswerInstanceWithNullCommandResponse() { + final LiveCommandAnswer liveCommandAnswer = + LiveCommandAnswerFactory.newLiveCommandAnswer((CommandResponse) null); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasNoEvent(); + } + + /** */ + @Test + public void getLiveCommandAnswerInstanceWithEventOnly() { + final LiveCommandAnswer liveCommandAnswer = LiveCommandAnswerFactory.newLiveCommandAnswer(eventMock); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasEvent(eventMock); + } + + /** */ + @Test + public void getLiveCommandAnswerInstanceWithNullEvent() { + final LiveCommandAnswer liveCommandAnswer = LiveCommandAnswerFactory.newLiveCommandAnswer((Event) null); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasNoEvent(); + } + + /** */ + @Test + public void getLiveCommandAnswerInstanceWithCommandResponseAndEvent() { + final LiveCommandAnswer liveCommandAnswer = LiveCommandAnswerFactory.newLiveCommandAnswer(commandResponseMock, + eventMock); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasResponse(commandResponseMock) + .hasEvent(eventMock); + } + + /** */ + @Test + public void getLiveCommandAnswerInstanceWithNullCommandResponseAndNullEvent() { + final LiveCommandAnswer liveCommandAnswer = + LiveCommandAnswerFactory.newLiveCommandAnswer((CommandResponse) null, + (Event) null); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasNoEvent(); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..b4940396 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions.assertThat; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.ThingConflictException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.CreateThingLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class CreateThingLiveCommandAnswerBuilderImplTest { + + @Mock + private CreateThingLiveCommand commandMock; + + private CreateThingLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getThing()).thenReturn(TestConstants.Thing.THING); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + + underTest = CreateThingLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> CreateThingLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithThingCreatedResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(CreateThingLiveCommandAnswerBuilder.ResponseFactory::created) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithThingConflictErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(CreateThingLiveCommandAnswerBuilder.ResponseFactory::thingConflictError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.CONFLICT) + .withDittoRuntimeExceptionOfType(ThingConflictException.class); + } + + /** */ + @Test + public void buildAnswerWithThingCreatedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(CreateThingLiveCommandAnswerBuilder.EventFactory::created) + .build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommandImplTest.java new file mode 100644 index 00000000..35852c0c --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/CreateThingLiveCommandImplTest.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.AllowedReason.provided; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.Thing; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.modify.CreateThing; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.CreateThingLiveCommandImpl}. + */ +public final class CreateThingLiveCommandImplTest { + + private CreateThing twinCommand; + private CreateThingLiveCommand underTest; + + /** */ + @Before + public void setUp() { + twinCommand = CreateThing.of(TestConstants.Thing.THING, null, DittoHeaders.empty()); + underTest = CreateThingLiveCommandImpl.of(twinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(CreateThingLiveCommandImpl.class, + areImmutable(), + provided(Thing.class).isAlsoImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(CreateThingLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingModifyCommand", "thing") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetCreateThingLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> CreateThingLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetCreateThingLiveCommandForCreateAttributeCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> CreateThingLiveCommandImpl.of(commandMock)) + .withMessageContaining(CreateThing.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getCreateThingLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(twinCommand.getType()) + .withDittoHeaders(twinCommand.getDittoHeaders()) + .withId(twinCommand.getThingEntityId()) + .withManifest(twinCommand.getManifest()) + .withResourcePath(twinCommand.getResourcePath()); + assertThat(underTest.getThing()).isEqualTo(twinCommand.getThing()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final CreateThingLiveCommand newCreateThingLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newCreateThingLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(twinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..21c1529c --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions.assertThat; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.AttributeNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.AttributeNotModifiableException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.DeleteAttributeLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class DeleteAttributeLiveCommandAnswerBuilderImplTest { + + @Mock + private DeleteAttributeLiveCommand commandMock; + + private DeleteAttributeLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getAttributePointer()).thenReturn(TestConstants.Thing.LOCATION_ATTRIBUTE_POINTER); + + underTest = DeleteAttributeLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> DeleteAttributeLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithDeleteAttributeResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(DeleteAttributeLiveCommandAnswerBuilder.ResponseFactory::deleted) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithAttributeNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + DeleteAttributeLiveCommandAnswerBuilder.ResponseFactory::attributeNotAccessibleError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(AttributeNotAccessibleException.class); + } + + /** */ + @Test + public void buildAnswerWithAttributeNotModifiableErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + DeleteAttributeLiveCommandAnswerBuilder.ResponseFactory::attributeNotModifiableError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.FORBIDDEN) + .withDittoRuntimeExceptionOfType(AttributeNotModifiableException.class); + } + + /** */ + @Test + public void buildAnswerWithAttributeDeletedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(DeleteAttributeLiveCommandAnswerBuilder.EventFactory::deleted) + .build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommandImplTest.java new file mode 100644 index 00000000..a2b5561b --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributeLiveCommandImplTest.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.AllowedReason.provided; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.modify.DeleteAttribute; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.DeleteAttributeLiveCommandImpl}. + */ +public final class DeleteAttributeLiveCommandImplTest { + + private DeleteAttribute twinCommand; + private DeleteAttributeLiveCommand underTest; + + /** */ + @Before + public void setUp() { + twinCommand = DeleteAttribute.of(TestConstants.Thing.THING_ID, + TestConstants.Thing.LOCATION_ATTRIBUTE_POINTER, DittoHeaders.empty()); + underTest = DeleteAttributeLiveCommandImpl.of(twinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(DeleteAttributeLiveCommandImpl.class, + areImmutable(), + provided(JsonPointer.class).isAlsoImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(DeleteAttributeLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingModifyCommand", "attributePointer") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetDeleteAttributeLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> DeleteAttributeLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetDeleteAttributeLiveCommandForCreateAttributeCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> DeleteAttributeLiveCommandImpl.of(commandMock)) + .withMessageContaining(DeleteAttribute.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getDeleteAttributeLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(twinCommand.getType()) + .withDittoHeaders(twinCommand.getDittoHeaders()) + .withId(twinCommand.getThingEntityId()) + .withManifest(twinCommand.getManifest()) + .withResourcePath(twinCommand.getResourcePath()); + assertThat(underTest.getAttributePointer()).isEqualTo(twinCommand.getAttributePointer()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final DeleteAttributeLiveCommand newDeleteAttributeLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newDeleteAttributeLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(twinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..7f8a7c36 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions.assertThat; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.AttributesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.AttributesNotModifiableException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.DeleteAttributesLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class DeleteAttributesLiveCommandAnswerBuilderImplTest { + + @Mock + private DeleteAttributesLiveCommand commandMock; + + private DeleteAttributesLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + + underTest = DeleteAttributesLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> DeleteAttributesLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithDeleteAttributesResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(DeleteAttributesLiveCommandAnswerBuilder.ResponseFactory::deleted) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithAttributesNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + DeleteAttributesLiveCommandAnswerBuilder.ResponseFactory::attributesNotAccessibleError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(AttributesNotAccessibleException.class); + } + + /** */ + @Test + public void buildAnswerWithAttributesNotModifiableErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + DeleteAttributesLiveCommandAnswerBuilder.ResponseFactory::attributesNotModifiableError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.FORBIDDEN) + .withDittoRuntimeExceptionOfType(AttributesNotModifiableException.class); + } + + /** */ + @Test + public void buildAnswerWithAttributesDeletedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(DeleteAttributesLiveCommandAnswerBuilder.EventFactory::deleted) + .build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommandImplTest.java new file mode 100644 index 00000000..ecad4287 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteAttributesLiveCommandImplTest.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.assertj.core.api.Assertions; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.modify.DeleteAttributes; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.DeleteAttributesLiveCommandImpl}. + */ +public final class DeleteAttributesLiveCommandImplTest { + + private DeleteAttributes twinCommand; + private DeleteAttributesLiveCommand underTest; + + /** */ + @Before + public void setUp() { + twinCommand = DeleteAttributes.of(TestConstants.Thing.THING_ID, DittoHeaders.empty()); + underTest = DeleteAttributesLiveCommandImpl.of(twinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(DeleteAttributesLiveCommandImpl.class, areImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(DeleteAttributesLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingModifyCommand") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetDeleteAttributesLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> DeleteAttributesLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetDeleteAttributesLiveCommandForCreateAttributesCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> DeleteAttributesLiveCommandImpl.of(commandMock)) + .withMessageContaining(DeleteAttributes.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getDeleteAttributesLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(twinCommand.getType()) + .withDittoHeaders(twinCommand.getDittoHeaders()) + .withId(twinCommand.getThingEntityId()) + .withManifest(twinCommand.getManifest()) + .withResourcePath(twinCommand.getResourcePath()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final DeleteAttributesLiveCommand newDeleteAttributesLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newDeleteAttributesLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + Assertions.assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(twinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..eb14ce7a --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatNullPointerException; +import static org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions.assertThat; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDefinitionNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDefinitionNotModifiableException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.DeleteFeatureDefinitionLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class DeleteFeatureDefinitionLiveCommandAnswerBuilderImplTest { + + @Mock + private DeleteFeatureDefinitionLiveCommand commandMock; + + private DeleteFeatureDefinitionLiveCommandAnswerBuilderImpl underTest; + + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getFeatureId()).thenReturn(TestConstants.Feature.FLUX_CAPACITOR_ID); + + underTest = DeleteFeatureDefinitionLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatNullPointerException() + .isThrownBy(() -> DeleteFeatureDefinitionLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage("The %s must not be null!", "command") + .withNoCause(); + } + + @Test + public void buildAnswerWithDeleteFeatureDefinitionResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(DeleteFeatureDefinitionLiveCommandAnswerBuilder.ResponseFactory::deleted) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + @Test + public void buildAnswerWithFeatureDefinitionNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(DeleteFeatureDefinitionLiveCommandAnswerBuilder + .ResponseFactory::featureDefinitionNotAccessibleError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(FeatureDefinitionNotAccessibleException.class); + } + + @Test + public void buildAnswerWithFeatureDefinitionNotModifiableErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(DeleteFeatureDefinitionLiveCommandAnswerBuilder + .ResponseFactory::featureDefinitionNotModifiableError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.FORBIDDEN) + .withDittoRuntimeExceptionOfType(FeatureDefinitionNotModifiableException.class); + } + + @Test + public void buildAnswerWithFeatureDefinitionDeletedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(DeleteFeatureDefinitionLiveCommandAnswerBuilder.EventFactory::deleted) + .build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommandImplTest.java new file mode 100644 index 00000000..7cced350 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDefinitionLiveCommandImplTest.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatNullPointerException; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureDefinition; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.DeleteFeatureDefinitionLiveCommandImpl}. + */ +public final class DeleteFeatureDefinitionLiveCommandImplTest { + + private DeleteFeatureDefinition twinCommand; + private DeleteFeatureDefinitionLiveCommand underTest; + + @Before + public void setUp() { + twinCommand = DeleteFeatureDefinition.of(TestConstants.Thing.THING_ID, + TestConstants.Feature.FLUX_CAPACITOR_ID, DittoHeaders.empty()); + underTest = DeleteFeatureDefinitionLiveCommandImpl.of(twinCommand); + } + + @Test + public void assertImmutability() { + assertInstancesOf(DeleteFeatureDefinitionLiveCommandImpl.class, areImmutable()); + } + + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(DeleteFeatureDefinitionLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingModifyCommand", "featureId") + .verify(); + } + + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetDeleteFeatureDefinitionLiveCommandForNull() { + assertThatNullPointerException() + .isThrownBy(() -> DeleteFeatureDefinitionLiveCommandImpl.of(null)) + .withMessage("The %s must not be null!", "command") + .withNoCause(); + } + + @Test + public void tryToGetDeleteFeatureDefinitionLiveCommandForCreateFeatureDefinitionCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> DeleteFeatureDefinitionLiveCommandImpl.of(commandMock)) + .withMessageContaining(DeleteFeatureDefinition.class.getName()) + .withNoCause(); + } + + @Test + public void getDeleteFeatureDefinitionLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(twinCommand.getType()) + .withDittoHeaders(twinCommand.getDittoHeaders()) + .withId(twinCommand.getThingEntityId()) + .withManifest(twinCommand.getManifest()) + .withResourcePath(twinCommand.getResourcePath()); + assertThat(underTest.getFeatureId()).isEqualTo(twinCommand.getFeatureId()); + } + + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final DeleteFeatureDefinitionLiveCommand newDeleteFeatureDefinitionLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newDeleteFeatureDefinitionLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(twinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..0056a114 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions.assertThat; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertiesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertiesNotModifiableException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilderImplTest { + + @Mock + private DeleteFeatureDesiredPropertiesLiveCommand commandMock; + + private DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getFeatureId()).thenReturn(TestConstants.Feature.HOVER_BOARD_ID); + + underTest = DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithDeleteFeatureDesiredPropertiesResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilder.ResponseFactory::deleted) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithFeatureDesiredPropertiesNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilder + .ResponseFactory::featureDesiredPropertiesNotAccessibleError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(FeatureDesiredPropertiesNotAccessibleException.class); + } + + /** */ + @Test + public void buildAnswerWithFeatureDesiredPropertiesNotModifiableErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilder + .ResponseFactory::featureDesiredPropertiesNotModifiableError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.FORBIDDEN) + .withDittoRuntimeExceptionOfType(FeatureDesiredPropertiesNotModifiableException.class); + } + + /** */ + @Test + public void buildAnswerWithFeatureDesiredPropertiesDeletedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(DeleteFeatureDesiredPropertiesLiveCommandAnswerBuilder.EventFactory::deleted) + .build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommandImplTest.java new file mode 100644 index 00000000..ab246720 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertiesLiveCommandImplTest.java @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureDesiredProperties; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.DeleteFeatureDesiredPropertiesLiveCommandImpl}. + */ +public final class DeleteFeatureDesiredPropertiesLiveCommandImplTest { + + private DeleteFeatureDesiredProperties twinCommand; + private DeleteFeatureDesiredPropertiesLiveCommand underTest; + + /** + * + */ + @Before + public void setUp() { + twinCommand = DeleteFeatureDesiredProperties.of(TestConstants.Thing.THING_ID, + TestConstants.Feature.HOVER_BOARD_ID, DittoHeaders.empty()); + underTest = DeleteFeatureDesiredPropertiesLiveCommandImpl.of(twinCommand); + } + + /** + * + */ + @Test + public void assertImmutability() { + assertInstancesOf(DeleteFeatureDesiredPropertiesLiveCommandImpl.class, areImmutable()); + } + + /** + * + */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(DeleteFeatureDesiredPropertiesLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingModifyCommand", "featureId") + .verify(); + } + + /** + * + */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetDeleteFeatureDesiredPropertiesLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> DeleteFeatureDesiredPropertiesLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** + * + */ + @Test + public void tryToGetDeleteFeatureDesiredPropertiesLiveCommandForCreateFeatureDesiredPropertiesCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> DeleteFeatureDesiredPropertiesLiveCommandImpl.of(commandMock)) + .withMessageContaining(DeleteFeatureDesiredProperties.class.getName()) + .withNoCause(); + } + + /** + * + */ + @Test + public void getDeleteFeatureDesiredPropertiesLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(twinCommand.getType()) + .withDittoHeaders(twinCommand.getDittoHeaders()) + .withId(twinCommand.getThingEntityId()) + .withManifest(twinCommand.getManifest()) + .withResourcePath(twinCommand.getResourcePath()); + assertThat(underTest.getFeatureId()).isEqualTo(twinCommand.getFeatureId()); + } + + /** + * + */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final DeleteFeatureDesiredPropertiesLiveCommand newDeleteFeatureDesiredPropertiesLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newDeleteFeatureDesiredPropertiesLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** + * + */ + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + /** + * + */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(twinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..c9a321ed --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertyNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertyNotModifiableException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.DeleteFeatureDesiredPropertyLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class DeleteFeatureDesiredPropertyLiveCommandAnswerBuilderImplTest { + + @Mock + private DeleteFeatureDesiredPropertyLiveCommand commandMock; + + private DeleteFeatureDesiredPropertyLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getFeatureId()).thenReturn(TestConstants.Feature.HOVER_BOARD_ID); + Mockito.when(commandMock.getDesiredPropertyPointer()) + .thenReturn(TestConstants.Feature.HOVER_BOARD_PROPERTY_POINTER); + + underTest = DeleteFeatureDesiredPropertyLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> DeleteFeatureDesiredPropertyLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithDeleteFeatureDesiredPropertyResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(DeleteFeatureDesiredPropertyLiveCommandAnswerBuilder.ResponseFactory::deleted) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithFeatureDesiredPropertyNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(DeleteFeatureDesiredPropertyLiveCommandAnswerBuilder + .ResponseFactory::featureDesiredPropertyNotAccessibleError) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(FeatureDesiredPropertyNotAccessibleException.class); + } + + /** */ + @Test + public void buildAnswerWithFeatureDesiredPropertyNotModifiableErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(DeleteFeatureDesiredPropertyLiveCommandAnswerBuilder + .ResponseFactory::featureDesiredPropertyNotModifiableError) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.FORBIDDEN) + .withDittoRuntimeExceptionOfType(FeatureDesiredPropertyNotModifiableException.class); + } + + /** */ + @Test + public void buildAnswerWithFeatureDesiredPropertyDeletedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(DeleteFeatureDesiredPropertyLiveCommandAnswerBuilder.EventFactory::deleted) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommandImplTest.java new file mode 100644 index 00000000..c003b9b3 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureDesiredPropertyLiveCommandImplTest.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.AllowedReason.provided; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureDesiredProperty; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.DeleteFeatureDesiredPropertyLiveCommandImpl}. + */ +public final class DeleteFeatureDesiredPropertyLiveCommandImplTest { + + private DeleteFeatureDesiredProperty twinCommand; + private DeleteFeatureDesiredPropertyLiveCommand underTest; + + /** */ + @Before + public void setUp() { + twinCommand = DeleteFeatureDesiredProperty.of(TestConstants.Thing.THING_ID, + TestConstants.Feature.HOVER_BOARD_ID, TestConstants.Feature.HOVER_BOARD_PROPERTY_POINTER, + DittoHeaders.empty()); + underTest = DeleteFeatureDesiredPropertyLiveCommandImpl.of(twinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(DeleteFeatureDesiredPropertyLiveCommandImpl.class, + areImmutable(), + provided(JsonPointer.class).isAlsoImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(DeleteFeatureDesiredPropertyLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingModifyCommand", "featureId", "desiredPropertyPointer") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetDeleteFeatureDesiredPropertyLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> DeleteFeatureDesiredPropertyLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetDeleteFeatureDesiredPropertyLiveCommandForCreateFeatureDesiredPropertyCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> DeleteFeatureDesiredPropertyLiveCommandImpl.of(commandMock)) + .withMessageContaining(DeleteFeatureDesiredProperty.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getDeleteFeatureDesiredPropertyLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(twinCommand.getType()) + .withDittoHeaders(twinCommand.getDittoHeaders()) + .withId(twinCommand.getThingEntityId()) + .withManifest(twinCommand.getManifest()) + .withResourcePath(twinCommand.getResourcePath()); + assertThat(underTest.getFeatureId()).isEqualTo(twinCommand.getFeatureId()); + assertThat(underTest.getDesiredPropertyPointer()).isEqualTo(twinCommand.getDesiredPropertyPointer()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final DeleteFeatureDesiredPropertyLiveCommand newDeleteFeatureDesiredPropertyLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newDeleteFeatureDesiredPropertyLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(twinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..98f3ef19 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions.assertThat; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureNotModifiableException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.DeleteFeatureLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class DeleteFeatureLiveCommandAnswerBuilderImplTest { + + @Mock + private DeleteFeatureLiveCommand commandMock; + + private DeleteFeatureLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getFeatureId()).thenReturn(TestConstants.Feature.FLUX_CAPACITOR_ID); + + underTest = DeleteFeatureLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> DeleteFeatureLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithDeleteFeatureResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(DeleteFeatureLiveCommandAnswerBuilder.ResponseFactory::deleted) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithFeatureNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + DeleteFeatureLiveCommandAnswerBuilder.ResponseFactory::featureNotAccessibleError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(FeatureNotAccessibleException.class); + } + + /** */ + @Test + public void buildAnswerWithFeatureNotModifiableErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + DeleteFeatureLiveCommandAnswerBuilder.ResponseFactory::featureNotModifiableError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.FORBIDDEN) + .withDittoRuntimeExceptionOfType(FeatureNotModifiableException.class); + } + + /** */ + @Test + public void buildAnswerWithFeatureDeletedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(DeleteFeatureLiveCommandAnswerBuilder.EventFactory::deleted) + .build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommandImplTest.java new file mode 100644 index 00000000..4f80d292 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeatureLiveCommandImplTest.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeature; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.DeleteFeatureLiveCommandImpl}. + */ +public final class DeleteFeatureLiveCommandImplTest { + + private DeleteFeature twinCommand; + private DeleteFeatureLiveCommand underTest; + + /** */ + @Before + public void setUp() { + twinCommand = DeleteFeature.of(TestConstants.Thing.THING_ID, + TestConstants.Feature.FLUX_CAPACITOR_ID, DittoHeaders.empty()); + underTest = DeleteFeatureLiveCommandImpl.of(twinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(DeleteFeatureLiveCommandImpl.class, areImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(DeleteFeatureLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingModifyCommand", "featureId") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetDeleteFeatureLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> DeleteFeatureLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetDeleteFeatureLiveCommandForCreateFeatureCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> DeleteFeatureLiveCommandImpl.of(commandMock)) + .withMessageContaining(DeleteFeature.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getDeleteFeatureLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(twinCommand.getType()) + .withDittoHeaders(twinCommand.getDittoHeaders()) + .withId(twinCommand.getThingEntityId()) + .withManifest(twinCommand.getManifest()) + .withResourcePath(twinCommand.getResourcePath()); + assertThat(underTest.getFeatureId()).isEqualTo(twinCommand.getFeatureId()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final DeleteFeatureLiveCommand newDeleteFeatureLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newDeleteFeatureLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(twinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..c97759a9 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions.assertThat; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertiesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertiesNotModifiableException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.DeleteFeaturePropertiesLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class DeleteFeaturePropertiesLiveCommandAnswerBuilderImplTest { + + @Mock + private DeleteFeaturePropertiesLiveCommand commandMock; + + private DeleteFeaturePropertiesLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getFeatureId()).thenReturn(TestConstants.Feature.FLUX_CAPACITOR_ID); + + underTest = DeleteFeaturePropertiesLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> DeleteFeaturePropertiesLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithDeleteFeaturePropertiesResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(DeleteFeaturePropertiesLiveCommandAnswerBuilder.ResponseFactory::deleted) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithFeaturePropertiesNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(DeleteFeaturePropertiesLiveCommandAnswerBuilder + .ResponseFactory::featurePropertiesNotAccessibleError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(FeaturePropertiesNotAccessibleException.class); + } + + /** */ + @Test + public void buildAnswerWithFeaturePropertiesNotModifiableErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(DeleteFeaturePropertiesLiveCommandAnswerBuilder + .ResponseFactory::featurePropertiesNotModifiableError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.FORBIDDEN) + .withDittoRuntimeExceptionOfType(FeaturePropertiesNotModifiableException.class); + } + + /** */ + @Test + public void buildAnswerWithFeaturePropertiesDeletedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(DeleteFeaturePropertiesLiveCommandAnswerBuilder.EventFactory::deleted) + .build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommandImplTest.java new file mode 100644 index 00000000..4cb58b92 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertiesLiveCommandImplTest.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureProperties; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.DeleteFeaturePropertiesLiveCommandImpl}. + */ +public final class DeleteFeaturePropertiesLiveCommandImplTest { + + private DeleteFeatureProperties twinCommand; + private DeleteFeaturePropertiesLiveCommand underTest; + + /** */ + @Before + public void setUp() { + twinCommand = DeleteFeatureProperties.of(TestConstants.Thing.THING_ID, + TestConstants.Feature.FLUX_CAPACITOR_ID, DittoHeaders.empty()); + underTest = DeleteFeaturePropertiesLiveCommandImpl.of(twinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(DeleteFeaturePropertiesLiveCommandImpl.class, areImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(DeleteFeaturePropertiesLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingModifyCommand", "featureId") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetDeleteFeaturePropertiesLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> DeleteFeaturePropertiesLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetDeleteFeaturePropertiesLiveCommandForCreateFeaturePropertiesCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> DeleteFeaturePropertiesLiveCommandImpl.of(commandMock)) + .withMessageContaining(DeleteFeatureProperties.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getDeleteFeaturePropertiesLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(twinCommand.getType()) + .withDittoHeaders(twinCommand.getDittoHeaders()) + .withId(twinCommand.getThingEntityId()) + .withManifest(twinCommand.getManifest()) + .withResourcePath(twinCommand.getResourcePath()); + assertThat(underTest.getFeatureId()).isEqualTo(twinCommand.getFeatureId()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final DeleteFeaturePropertiesLiveCommand newDeleteFeaturePropertiesLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newDeleteFeaturePropertiesLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(twinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..e3ed4662 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertyNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertyNotModifiableException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.DeleteFeaturePropertyLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class DeleteFeaturePropertyLiveCommandAnswerBuilderImplTest { + + @Mock + private DeleteFeaturePropertyLiveCommand commandMock; + + private DeleteFeaturePropertyLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getFeatureId()).thenReturn(TestConstants.Feature.FLUX_CAPACITOR_ID); + Mockito.when(commandMock.getPropertyPointer()) + .thenReturn(TestConstants.Feature.FLUX_CAPACITOR_PROPERTY_POINTER); + + underTest = DeleteFeaturePropertyLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> DeleteFeaturePropertyLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithDeleteFeaturePropertyResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(DeleteFeaturePropertyLiveCommandAnswerBuilder.ResponseFactory::deleted) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithFeaturePropertyNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(DeleteFeaturePropertyLiveCommandAnswerBuilder + .ResponseFactory::featurePropertyNotAccessibleError) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(FeaturePropertyNotAccessibleException.class); + } + + /** */ + @Test + public void buildAnswerWithFeaturePropertyNotModifiableErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(DeleteFeaturePropertyLiveCommandAnswerBuilder + .ResponseFactory::featurePropertyNotModifiableError) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.FORBIDDEN) + .withDittoRuntimeExceptionOfType(FeaturePropertyNotModifiableException.class); + } + + /** */ + @Test + public void buildAnswerWithFeaturePropertyDeletedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(DeleteFeaturePropertyLiveCommandAnswerBuilder.EventFactory::deleted) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommandImplTest.java new file mode 100644 index 00000000..48c9c22e --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturePropertyLiveCommandImplTest.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.AllowedReason.provided; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatureProperty; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.DeleteFeaturePropertyLiveCommandImpl}. + */ +public final class DeleteFeaturePropertyLiveCommandImplTest { + + private DeleteFeatureProperty twinCommand; + private DeleteFeaturePropertyLiveCommand underTest; + + /** */ + @Before + public void setUp() { + twinCommand = DeleteFeatureProperty.of(TestConstants.Thing.THING_ID, + TestConstants.Feature.FLUX_CAPACITOR_ID, TestConstants.Feature.FLUX_CAPACITOR_PROPERTY_POINTER, + DittoHeaders.empty()); + underTest = DeleteFeaturePropertyLiveCommandImpl.of(twinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(DeleteFeaturePropertyLiveCommandImpl.class, + areImmutable(), + provided(JsonPointer.class).isAlsoImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(DeleteFeaturePropertyLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingModifyCommand", "featureId", "propertyPointer") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetDeleteFeaturePropertyLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> DeleteFeaturePropertyLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetDeleteFeaturePropertyLiveCommandForCreateFeaturePropertyCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> DeleteFeaturePropertyLiveCommandImpl.of(commandMock)) + .withMessageContaining(DeleteFeatureProperty.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getDeleteFeaturePropertyLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(twinCommand.getType()) + .withDittoHeaders(twinCommand.getDittoHeaders()) + .withId(twinCommand.getThingEntityId()) + .withManifest(twinCommand.getManifest()) + .withResourcePath(twinCommand.getResourcePath()); + assertThat(underTest.getFeatureId()).isEqualTo(twinCommand.getFeatureId()); + assertThat(underTest.getPropertyPointer()).isEqualTo(twinCommand.getPropertyPointer()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final DeleteFeaturePropertyLiveCommand newDeleteFeaturePropertyLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newDeleteFeaturePropertyLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(twinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..d3738170 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturesNotModifiableException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.DeleteFeaturesLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class DeleteFeaturesLiveCommandAnswerBuilderImplTest { + + @Mock + private DeleteFeaturesLiveCommand commandMock; + + private DeleteFeaturesLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + + underTest = DeleteFeaturesLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> DeleteFeaturesLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithDeleteFeaturesResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(DeleteFeaturesLiveCommandAnswerBuilder.ResponseFactory::deleted) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithFeaturesNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + DeleteFeaturesLiveCommandAnswerBuilder.ResponseFactory::featuresNotAccessibleError) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(FeaturesNotAccessibleException.class); + } + + /** */ + @Test + public void buildAnswerWithFeaturesNotModifiableErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + DeleteFeaturesLiveCommandAnswerBuilder.ResponseFactory::featuresNotModifiableError) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.FORBIDDEN) + .withDittoRuntimeExceptionOfType(FeaturesNotModifiableException.class); + } + + /** */ + @Test + public void buildAnswerWithFeaturesDeletedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(DeleteFeaturesLiveCommandAnswerBuilder.EventFactory::deleted) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommandImplTest.java new file mode 100644 index 00000000..8c4aa177 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteFeaturesLiveCommandImplTest.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.modify.DeleteFeatures; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.DeleteFeaturesLiveCommandImpl}. + */ +public final class DeleteFeaturesLiveCommandImplTest { + + private DeleteFeatures twinCommand; + private DeleteFeaturesLiveCommand underTest; + + /** */ + @Before + public void setUp() { + twinCommand = DeleteFeatures.of(TestConstants.Thing.THING_ID, DittoHeaders.empty()); + underTest = DeleteFeaturesLiveCommandImpl.of(twinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(DeleteFeaturesLiveCommandImpl.class, areImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(DeleteFeaturesLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingModifyCommand") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetDeleteFeaturesLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> DeleteFeaturesLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetDeleteFeaturesLiveCommandForCreateFeaturesCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> DeleteFeaturesLiveCommandImpl.of(commandMock)) + .withMessageContaining(DeleteFeatures.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getDeleteFeaturesLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(twinCommand.getType()) + .withDittoHeaders(twinCommand.getDittoHeaders()) + .withId(twinCommand.getThingEntityId()) + .withManifest(twinCommand.getManifest()) + .withResourcePath(twinCommand.getResourcePath()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final DeleteFeaturesLiveCommand newDeleteFeaturesLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newDeleteFeaturesLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(twinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..226781af --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions.assertThat; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.ThingNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.ThingNotDeletableException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.DeleteThingLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class DeleteThingLiveCommandAnswerBuilderImplTest { + + @Mock + private DeleteThingLiveCommand commandMock; + + private DeleteThingLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + + underTest = DeleteThingLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> DeleteThingLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithDeleteThingResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(DeleteThingLiveCommandAnswerBuilder.ResponseFactory::deleted) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithThingNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(DeleteThingLiveCommandAnswerBuilder.ResponseFactory::thingNotAccessibleError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(ThingNotAccessibleException.class); + } + + /** */ + @Test + public void buildAnswerWithThingNotDeletableErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(DeleteThingLiveCommandAnswerBuilder.ResponseFactory::thingNotDeletableError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.FORBIDDEN) + .withDittoRuntimeExceptionOfType(ThingNotDeletableException.class); + } + + /** */ + @Test + public void buildAnswerWithThingDeletedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(DeleteThingLiveCommandAnswerBuilder.EventFactory::deleted) + .build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommandImplTest.java new file mode 100644 index 00000000..6f87ef06 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/DeleteThingLiveCommandImplTest.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.modify.DeleteThing; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.DeleteThingLiveCommandImpl}. + */ +public final class DeleteThingLiveCommandImplTest { + + private DeleteThing twinCommand; + private DeleteThingLiveCommand underTest; + + /** */ + @Before + public void setUp() { + twinCommand = DeleteThing.of(TestConstants.Thing.THING_ID, DittoHeaders.empty()); + underTest = DeleteThingLiveCommandImpl.of(twinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(DeleteThingLiveCommandImpl.class, areImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(DeleteThingLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingModifyCommand") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetDeleteThingLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> DeleteThingLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetDeleteThingLiveCommandForCreateThingCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> DeleteThingLiveCommandImpl.of(commandMock)) + .withMessageContaining(DeleteThing.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getDeleteThingLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(twinCommand.getType()) + .withDittoHeaders(twinCommand.getDittoHeaders()) + .withId(twinCommand.getThingEntityId()) + .withManifest(twinCommand.getManifest()) + .withResourcePath(twinCommand.getResourcePath()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final DeleteThingLiveCommand newDeleteThingLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newDeleteThingLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(twinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..34d93ed3 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.ThingNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.ThingNotModifiableException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.MergeThingLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class MergeThingLiveCommandAnswerBuilderImplTest { + + @Mock + private MergeThingLiveCommand commandMock; + + private MergeThingLiveCommandAnswerBuilderImpl underTest; + + /** + * + */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getPath()).thenReturn(TestConstants.PATH); + Mockito.when(commandMock.getValue()).thenReturn(TestConstants.VALUE); + + underTest = MergeThingLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** + * + */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> MergeThingLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** + * + */ + @Test + public void buildAnswerWithMergeThingCreatedResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(MergeThingLiveCommandAnswerBuilder.ResponseFactory::merged) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingMergeCommandResponse(); + } + + /** + * + */ + @Test + public void buildAnswerWithMergeThingModifiedResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(MergeThingLiveCommandAnswerBuilder.ResponseFactory::merged) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingMergeCommandResponse(); + } + + /** + * + */ + @Test + public void buildAnswerWithThingNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(MergeThingLiveCommandAnswerBuilder.ResponseFactory::thingNotAccessibleError) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(ThingNotAccessibleException.class); + } + + /** + * + */ + @Test + public void buildAnswerWithThingNotModifiableErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(MergeThingLiveCommandAnswerBuilder.ResponseFactory::thingNotModifiableError) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.FORBIDDEN) + .withDittoRuntimeExceptionOfType(ThingNotModifiableException.class); + } + + /** + * + */ + @Test + public void buildAnswerWithThingCreatedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(MergeThingLiveCommandAnswerBuilder.EventFactory::merged) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + + /** + * + */ + @Test + public void buildAnswerWithThingModifiedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(MergeThingLiveCommandAnswerBuilder.EventFactory::merged) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommandImplTest.java new file mode 100644 index 00000000..749d20f0 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/MergeThingLiveCommandImplTest.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.AllowedReason.provided; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.modify.MergeThing; +import org.junit.Before; +import org.junit.Test; + +import nl.jqno.equalsverifier.EqualsVerifier; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.MergeThingLiveCommandImpl}. + */ +public final class MergeThingLiveCommandImplTest { + + private MergeThing twinCommand; + private MergeThingLiveCommand underTest; + + /** + * + */ + @Before + public void setUp() { + twinCommand = MergeThing.of(TestConstants.Thing.THING_ID, TestConstants.PATH, TestConstants.VALUE, + DittoHeaders.empty()); + underTest = MergeThingLiveCommandImpl.of(twinCommand); + } + + /** + * + */ + @Test + public void assertImmutability() { + assertInstancesOf(MergeThingLiveCommandImpl.class, + areImmutable(), + provided(JsonPointer.class, JsonValue.class).areAlsoImmutable()); + } + + /** + * + */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(MergeThingLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingModifyCommand", "path", "value") + .verify(); + } + + /** + * + */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetMergeThingLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> MergeThingLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** + * + */ + @Test + public void getMergeThingLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(twinCommand.getType()) + .withDittoHeaders(twinCommand.getDittoHeaders()) + .withId(twinCommand.getThingEntityId()) + .withManifest(twinCommand.getManifest()) + .withResourcePath(twinCommand.getResourcePath()); + assertThat(underTest.getPath()).isEqualTo(TestConstants.PATH); + assertThat(underTest.getValue()).isEqualTo(TestConstants.VALUE); + } + + /** + * + */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final MergeThingLiveCommand newMergeThingLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newMergeThingLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** + * + */ + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + /** + * + */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(twinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..2a96a1e6 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions.assertThat; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.AttributeNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.AttributeNotModifiableException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.ModifyAttributeLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class ModifyAttributeLiveCommandAnswerBuilderImplTest { + + @Mock + private ModifyAttributeLiveCommand commandMock; + + private ModifyAttributeLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getAttributePointer()).thenReturn(TestConstants.Thing.LOCATION_ATTRIBUTE_POINTER); + Mockito.when(commandMock.getAttributeValue()).thenReturn(TestConstants.Thing.LOCATION_ATTRIBUTE_VALUE); + + underTest = ModifyAttributeLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> ModifyAttributeLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithModifyAttributeCreatedResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyAttributeLiveCommandAnswerBuilder.ResponseFactory::created) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithModifyAttributeModifiedResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyAttributeLiveCommandAnswerBuilder.ResponseFactory::modified) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithAttributeNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + ModifyAttributeLiveCommandAnswerBuilder.ResponseFactory::attributeNotAccessibleError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(AttributeNotAccessibleException.class); + } + + /** */ + @Test + public void buildAnswerWithAttributeNotModifiableErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + ModifyAttributeLiveCommandAnswerBuilder.ResponseFactory::attributeNotModifiableError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.FORBIDDEN) + .withDittoRuntimeExceptionOfType(AttributeNotModifiableException.class); + } + + /** */ + @Test + public void buildAnswerWithAttributeCreatedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(ModifyAttributeLiveCommandAnswerBuilder.EventFactory::created) + .build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + + /** */ + @Test + public void buildAnswerWithAttributeModifiedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(ModifyAttributeLiveCommandAnswerBuilder.EventFactory::modified) + .build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommandImplTest.java new file mode 100644 index 00000000..11230c2f --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributeLiveCommandImplTest.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.AllowedReason.provided; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.modify.ModifyAttribute; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.ModifyAttributeLiveCommandImpl}. + */ +public final class ModifyAttributeLiveCommandImplTest { + + private ModifyAttribute twinCommand; + private ModifyAttributeLiveCommand underTest; + + /** */ + @Before + public void setUp() { + twinCommand = ModifyAttribute.of(TestConstants.Thing.THING_ID, TestConstants.Thing.LOCATION_ATTRIBUTE_POINTER, + TestConstants.Thing.LOCATION_ATTRIBUTE_VALUE, DittoHeaders.empty()); + underTest = ModifyAttributeLiveCommandImpl.of(twinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(ModifyAttributeLiveCommandImpl.class, + areImmutable(), + provided(JsonPointer.class, JsonValue.class).areAlsoImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(ModifyAttributeLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingModifyCommand", "attributePointer", "attributeValue") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetModifyAttributeLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> ModifyAttributeLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetModifyAttributeLiveCommandForCreateThingCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> ModifyAttributeLiveCommandImpl.of(commandMock)) + .withMessageContaining(ModifyAttribute.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getModifyAttributeLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(twinCommand.getType()) + .withDittoHeaders(twinCommand.getDittoHeaders()) + .withId(twinCommand.getThingEntityId()) + .withManifest(twinCommand.getManifest()) + .withResourcePath(twinCommand.getResourcePath()); + assertThat(underTest.getAttributePointer()).isEqualTo(twinCommand.getAttributePointer()); + assertThat(underTest.getAttributeValue()).isEqualTo(twinCommand.getAttributeValue()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final ModifyAttributeLiveCommand newModifyAttributeLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newModifyAttributeLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(twinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..40a11eb3 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions.assertThat; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.AttributesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.AttributesNotModifiableException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.ModifyAttributesLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class ModifyAttributesLiveCommandAnswerBuilderImplTest { + + @Mock + private ModifyAttributesLiveCommand commandMock; + + private ModifyAttributesLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getAttributes()).thenReturn(TestConstants.Thing.ATTRIBUTES); + + underTest = ModifyAttributesLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> ModifyAttributesLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithModifyAttributesCreatedResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyAttributesLiveCommandAnswerBuilder.ResponseFactory::created) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithModifyAttributesModifiedResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyAttributesLiveCommandAnswerBuilder.ResponseFactory::modified) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithAttributesNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + ModifyAttributesLiveCommandAnswerBuilder.ResponseFactory::attributesNotAccessibleError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(AttributesNotAccessibleException.class); + } + + /** */ + @Test + public void buildAnswerWithAttributesNotModifiableErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + ModifyAttributesLiveCommandAnswerBuilder.ResponseFactory::attributesNotModifiableError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.FORBIDDEN) + .withDittoRuntimeExceptionOfType(AttributesNotModifiableException.class); + } + + /** */ + @Test + public void buildAnswerWithAttributesCreatedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(ModifyAttributesLiveCommandAnswerBuilder.EventFactory::created) + .build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + + /** */ + @Test + public void buildAnswerWithAttributesModifiedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(ModifyAttributesLiveCommandAnswerBuilder.EventFactory::modified) + .build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommandImplTest.java new file mode 100644 index 00000000..8a405056 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyAttributesLiveCommandImplTest.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.AllowedReason.provided; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.Attributes; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.modify.ModifyAttributes; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.ModifyAttributesLiveCommandImpl}. + */ +public final class ModifyAttributesLiveCommandImplTest { + + private ModifyAttributes twinCommand; + private ModifyAttributesLiveCommand underTest; + + /** */ + @Before + public void setUp() { + twinCommand = ModifyAttributes.of(TestConstants.Thing.THING_ID, TestConstants.Thing.ATTRIBUTES, + DittoHeaders.empty()); + underTest = ModifyAttributesLiveCommandImpl.of(twinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(ModifyAttributesLiveCommandImpl.class, + areImmutable(), + provided(Attributes.class).isAlsoImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(ModifyAttributesLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingModifyCommand", "attributes") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetModifyAttributesLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> ModifyAttributesLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetModifyAttributesLiveCommandForCreateThingCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> ModifyAttributesLiveCommandImpl.of(commandMock)) + .withMessageContaining(ModifyAttributes.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getModifyAttributesLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(twinCommand.getType()) + .withDittoHeaders(twinCommand.getDittoHeaders()) + .withId(twinCommand.getThingEntityId()) + .withManifest(twinCommand.getManifest()) + .withResourcePath(twinCommand.getResourcePath()); + assertThat(underTest.getAttributes()).isEqualTo(twinCommand.getAttributes()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final ModifyAttributesLiveCommand newModifyAttributesLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newModifyAttributesLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(twinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..64e4b93d --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatNullPointerException; +import static org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions.assertThat; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDefinitionNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDefinitionNotModifiableException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.ModifyFeatureDefinitionLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class ModifyFeatureDefinitionLiveCommandAnswerBuilderImplTest { + + @Mock + private ModifyFeatureDefinitionLiveCommand commandMock; + + private ModifyFeatureDefinitionLiveCommandAnswerBuilderImpl underTest; + + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getFeatureId()).thenReturn(TestConstants.Feature.FLUX_CAPACITOR_ID); + Mockito.when(commandMock.getDefinition()).thenReturn(TestConstants.Feature.FLUX_CAPACITOR_DEFINITION); + + underTest = ModifyFeatureDefinitionLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatNullPointerException() + .isThrownBy(() -> ModifyFeatureDefinitionLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage("The %s must not be null!", "command") + .withNoCause(); + } + + @Test + public void buildAnswerWithModifyFeatureDefinitionCreatedResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeatureDefinitionLiveCommandAnswerBuilder.ResponseFactory::created) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + @Test + public void buildAnswerWithModifyFeatureDefinitionModifiedResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeatureDefinitionLiveCommandAnswerBuilder.ResponseFactory::modified) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + @Test + public void buildAnswerWithFeatureDefinitionNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeatureDefinitionLiveCommandAnswerBuilder + .ResponseFactory::featureDefinitionNotAccessibleError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(FeatureDefinitionNotAccessibleException.class); + } + + @Test + public void buildAnswerWithFeatureDefinitionNotModifiableErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeatureDefinitionLiveCommandAnswerBuilder + .ResponseFactory::featureDefinitionNotModifiableError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.FORBIDDEN) + .withDittoRuntimeExceptionOfType(FeatureDefinitionNotModifiableException.class); + } + + @Test + public void buildAnswerWithFeatureDefinitionCreatedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(ModifyFeatureDefinitionLiveCommandAnswerBuilder.EventFactory::created) + .build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + + @Test + public void buildAnswerWithFeatureDefinitionModifiedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(ModifyFeatureDefinitionLiveCommandAnswerBuilder.EventFactory::modified) + .build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommandImplTest.java new file mode 100644 index 00000000..5b958d85 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDefinitionLiveCommandImplTest.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatNullPointerException; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.AllowedReason.provided; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.FeatureDefinition; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureDefinition; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.ModifyFeatureDefinitionLiveCommandImpl}. + */ +public final class ModifyFeatureDefinitionLiveCommandImplTest { + + private ModifyFeatureDefinition twinCommand; + private ModifyFeatureDefinitionLiveCommand underTest; + + @Before + public void setUp() { + twinCommand = ModifyFeatureDefinition.of(TestConstants.Thing.THING_ID, TestConstants.Feature.FLUX_CAPACITOR_ID, + TestConstants.Feature.FLUX_CAPACITOR_DEFINITION, DittoHeaders.empty()); + underTest = ModifyFeatureDefinitionLiveCommandImpl.of(twinCommand); + } + + @Test + public void assertImmutability() { + assertInstancesOf(ModifyFeatureDefinitionLiveCommandImpl.class, + areImmutable(), + provided(FeatureDefinition.class).isAlsoImmutable()); + } + + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(ModifyFeatureDefinitionLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingModifyCommand", "featureId", "featureProperties") + .verify(); + } + + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetModifyFeatureDefinitionLiveCommandForNull() { + assertThatNullPointerException() + .isThrownBy(() -> ModifyFeatureDefinitionLiveCommandImpl.of(null)) + .withMessage("The %s must not be null!", "command") + .withNoCause(); + } + + @Test + public void tryToGetModifyFeatureDefinitionLiveCommandForCreateThingCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> ModifyFeatureDefinitionLiveCommandImpl.of(commandMock)) + .withMessageContaining( + ModifyFeatureDefinition.class.getName()) + .withNoCause(); + } + + @Test + public void getModifyFeatureDefinitionLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(twinCommand.getType()) + .withDittoHeaders(twinCommand.getDittoHeaders()) + .withId(twinCommand.getThingEntityId()) + .withManifest(twinCommand.getManifest()) + .withResourcePath(twinCommand.getResourcePath()); + assertThat(underTest.getDefinition()).isEqualTo(twinCommand.getDefinition()); + assertThat(underTest.getFeatureId()).isEqualTo(twinCommand.getFeatureId()); + } + + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final ModifyFeatureDefinitionLiveCommand newModifyFeatureDefinitionLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newModifyFeatureDefinitionLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(twinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..2f9de1ac --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions.assertThat; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertiesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertiesNotModifiableException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilderImplTest { + + @Mock + private ModifyFeatureDesiredPropertiesLiveCommand commandMock; + + private ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getFeatureId()).thenReturn(TestConstants.Feature.HOVER_BOARD_ID); + Mockito.when(commandMock.getDesiredProperties()).thenReturn(TestConstants.Feature.HOVER_BOARD_PROPERTIES); + + underTest = ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithModifyFeatureDesiredPropertiesCreatedResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilder.ResponseFactory::created) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithModifyFeatureDesiredPropertiesModifiedResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilder.ResponseFactory::modified) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithFeatureDesiredPropertiesNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilder + .ResponseFactory::featureDesiredPropertiesNotAccessibleError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(FeatureDesiredPropertiesNotAccessibleException.class); + } + + /** */ + @Test + public void buildAnswerWithFeatureDesiredPropertiesNotModifiableErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilder + .ResponseFactory::featureDesiredPropertiesNotModifiableError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.FORBIDDEN) + .withDittoRuntimeExceptionOfType(FeatureDesiredPropertiesNotModifiableException.class); + } + + /** */ + @Test + public void buildAnswerWithFeatureDesiredPropertiesCreatedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilder.EventFactory::created) + .build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + + /** */ + @Test + public void buildAnswerWithFeatureDesiredPropertiesModifiedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(ModifyFeatureDesiredPropertiesLiveCommandAnswerBuilder.EventFactory::modified) + .build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommandImplTest.java new file mode 100644 index 00000000..95349b32 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertiesLiveCommandImplTest.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.AllowedReason.provided; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.FeatureProperties; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureDesiredProperties; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.ModifyFeatureDesiredPropertiesLiveCommandImpl}. + */ +public final class ModifyFeatureDesiredPropertiesLiveCommandImplTest { + + private ModifyFeatureDesiredProperties twinCommand; + private ModifyFeatureDesiredPropertiesLiveCommand underTest; + + /** */ + @Before + public void setUp() { + twinCommand = ModifyFeatureDesiredProperties.of(TestConstants.Thing.THING_ID, TestConstants.Feature.HOVER_BOARD_ID, + TestConstants.Feature.HOVER_BOARD_PROPERTIES, DittoHeaders.empty()); + underTest = ModifyFeatureDesiredPropertiesLiveCommandImpl.of(twinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(ModifyFeatureDesiredPropertiesLiveCommandImpl.class, + areImmutable(), + provided(FeatureProperties.class).isAlsoImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(ModifyFeatureDesiredPropertiesLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingModifyCommand", "featureId", "desiredProperties") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetModifyFeatureDesiredPropertiesLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> ModifyFeatureDesiredPropertiesLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetModifyFeatureDesiredPropertiesLiveCommandForCreateThingCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> ModifyFeatureDesiredPropertiesLiveCommandImpl.of(commandMock)) + .withMessageContaining( + ModifyFeatureDesiredProperties.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getModifyFeatureDesiredPropertiesLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(twinCommand.getType()) + .withDittoHeaders(twinCommand.getDittoHeaders()) + .withId(twinCommand.getThingEntityId()) + .withManifest(twinCommand.getManifest()) + .withResourcePath(twinCommand.getResourcePath()); + assertThat(underTest.getDesiredProperties()).isEqualTo(twinCommand.getDesiredProperties()); + assertThat(underTest.getFeatureId()).isEqualTo(twinCommand.getFeatureId()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final ModifyFeatureDesiredPropertiesLiveCommand newModifyFeatureDesiredPropertiesLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newModifyFeatureDesiredPropertiesLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(twinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..62dbfe31 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertyNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertyNotModifiableException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.ModifyFeatureDesiredPropertyLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class ModifyFeatureDesiredPropertyLiveCommandAnswerBuilderImplTest { + + @Mock + private ModifyFeatureDesiredPropertyLiveCommand commandMock; + + private ModifyFeatureDesiredPropertyLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getFeatureId()).thenReturn(TestConstants.Feature.HOVER_BOARD_ID); + Mockito.when(commandMock.getDesiredPropertyPointer()) + .thenReturn(TestConstants.Feature.HOVER_BOARD_PROPERTY_POINTER); + Mockito.when(commandMock.getDesiredPropertyValue()).thenReturn(TestConstants.Feature.HOVER_BOARD_PROPERTY_VALUE); + + underTest = ModifyFeatureDesiredPropertyLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> ModifyFeatureDesiredPropertyLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithModifyFeatureDesiredPropertyCreatedResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeatureDesiredPropertyLiveCommandAnswerBuilder.ResponseFactory::created) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithModifyFeatureDesiredPropertyModifiedResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeatureDesiredPropertyLiveCommandAnswerBuilder.ResponseFactory::modified) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithFeatureDesiredPropertyNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeatureDesiredPropertyLiveCommandAnswerBuilder + .ResponseFactory::featureDesiredPropertyNotAccessibleError) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(FeatureDesiredPropertyNotAccessibleException.class); + } + + /** */ + @Test + public void buildAnswerWithFeatureDesiredPropertyNotModifiableErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeatureDesiredPropertyLiveCommandAnswerBuilder + .ResponseFactory::featureDesiredPropertyNotModifiableError) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.FORBIDDEN) + .withDittoRuntimeExceptionOfType(FeatureDesiredPropertyNotModifiableException.class); + } + + /** */ + @Test + public void buildAnswerWithFeatureDesiredPropertyCreatedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(ModifyFeatureDesiredPropertyLiveCommandAnswerBuilder.EventFactory::created) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + + /** */ + @Test + public void buildAnswerWithFeatureDesiredPropertyModifiedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(ModifyFeatureDesiredPropertyLiveCommandAnswerBuilder.EventFactory::modified) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommandImplTest.java new file mode 100644 index 00000000..8c4c524c --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureDesiredPropertyLiveCommandImplTest.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.AllowedReason.provided; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureDesiredProperty; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.ModifyFeatureDesiredPropertyLiveCommandImpl}. + */ +public final class ModifyFeatureDesiredPropertyLiveCommandImplTest { + + private ModifyFeatureDesiredProperty twinCommand; + private ModifyFeatureDesiredPropertyLiveCommand underTest; + + /** */ + @Before + public void setUp() { + twinCommand = ModifyFeatureDesiredProperty.of(TestConstants.Thing.THING_ID, TestConstants.Feature.HOVER_BOARD_ID, + TestConstants.Feature.HOVER_BOARD_PROPERTY_POINTER, + TestConstants.Feature.HOVER_BOARD_PROPERTY_VALUE, DittoHeaders.empty()); + underTest = ModifyFeatureDesiredPropertyLiveCommandImpl.of(twinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(ModifyFeatureDesiredPropertyLiveCommandImpl.class, + areImmutable(), + provided(JsonPointer.class, JsonValue.class).areAlsoImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(ModifyFeatureDesiredPropertyLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingModifyCommand", "featureId", "desiredPropertyPointer", "desiredPropertyValue") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetModifyFeatureDesiredPropertyLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> ModifyFeatureDesiredPropertyLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetModifyFeatureDesiredPropertyLiveCommandForCreateThingCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> ModifyFeatureDesiredPropertyLiveCommandImpl.of(commandMock)) + .withMessageContaining( + ModifyFeatureDesiredProperty.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getModifyFeatureDesiredPropertyLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(twinCommand.getType()) + .withDittoHeaders(twinCommand.getDittoHeaders()) + .withId(twinCommand.getThingEntityId()) + .withManifest(twinCommand.getManifest()) + .withResourcePath(twinCommand.getResourcePath()); + assertThat(underTest.getFeatureId()).isEqualTo(twinCommand.getFeatureId()); + assertThat(underTest.getDesiredPropertyPointer()).isEqualTo(twinCommand.getDesiredPropertyPointer()); + assertThat(underTest.getDesiredPropertyValue()).isEqualTo(twinCommand.getDesiredPropertyValue()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final ModifyFeatureDesiredPropertyLiveCommand newModifyFeatureDesiredPropertyLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newModifyFeatureDesiredPropertyLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(twinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..fe78ccc2 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureNotModifiableException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.ModifyFeatureLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class ModifyFeatureLiveCommandAnswerBuilderImplTest { + + @Mock + private ModifyFeatureLiveCommand commandMock; + + private ModifyFeatureLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getFeatureId()).thenReturn(TestConstants.Feature.FLUX_CAPACITOR_ID); + Mockito.when(commandMock.getFeature()).thenReturn(TestConstants.Feature.FLUX_CAPACITOR); + + underTest = ModifyFeatureLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> ModifyFeatureLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithModifyFeatureCreatedResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeatureLiveCommandAnswerBuilder.ResponseFactory::created) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithModifyFeatureModifiedResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeatureLiveCommandAnswerBuilder.ResponseFactory::modified) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithFeatureNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeatureLiveCommandAnswerBuilder.ResponseFactory::featureNotAccessibleError) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(FeatureNotAccessibleException.class); + } + + /** */ + @Test + public void buildAnswerWithFeatureNotModifiableErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeatureLiveCommandAnswerBuilder.ResponseFactory::featureNotModifiableError) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.FORBIDDEN) + .withDittoRuntimeExceptionOfType(FeatureNotModifiableException.class); + } + + /** */ + @Test + public void buildAnswerWithFeatureCreatedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(ModifyFeatureLiveCommandAnswerBuilder.EventFactory::created) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + + /** */ + @Test + public void buildAnswerWithFeatureModifiedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(ModifyFeatureLiveCommandAnswerBuilder.EventFactory::modified) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommandImplTest.java new file mode 100644 index 00000000..7a855334 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeatureLiveCommandImplTest.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.AllowedReason.provided; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.assertj.core.api.Assertions; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.Feature; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeature; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.ModifyFeatureLiveCommandImpl}. + */ +public final class ModifyFeatureLiveCommandImplTest { + + private ModifyFeature twinCommand; + private ModifyFeatureLiveCommand underTest; + + /** */ + @Before + public void setUp() { + twinCommand = ModifyFeature.of(TestConstants.Thing.THING_ID, TestConstants.Feature.FLUX_CAPACITOR, + DittoHeaders.empty()); + underTest = ModifyFeatureLiveCommandImpl.of(twinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(ModifyFeatureLiveCommandImpl.class, + areImmutable(), + provided(Feature.class).isAlsoImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(ModifyFeatureLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingModifyCommand", "feature") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetModifyFeatureLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> ModifyFeatureLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetModifyFeatureLiveCommandForCreateThingCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> ModifyFeatureLiveCommandImpl.of(commandMock)) + .withMessageContaining(ModifyFeature.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getModifyFeatureLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(twinCommand.getType()) + .withDittoHeaders(twinCommand.getDittoHeaders()) + .withId(twinCommand.getThingEntityId()) + .withManifest(twinCommand.getManifest()) + .withResourcePath(twinCommand.getResourcePath()); + assertThat(underTest.getFeature()).isEqualTo(twinCommand.getFeature()); + assertThat(underTest.getFeatureId()).isEqualTo(twinCommand.getFeatureId()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final ModifyFeatureLiveCommand newModifyFeatureLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newModifyFeatureLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + Assertions.assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(twinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..96c0bf80 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions.assertThat; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertiesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertiesNotModifiableException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.ModifyFeaturePropertiesLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class ModifyFeaturePropertiesLiveCommandAnswerBuilderImplTest { + + @Mock + private ModifyFeaturePropertiesLiveCommand commandMock; + + private ModifyFeaturePropertiesLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getFeatureId()).thenReturn(TestConstants.Feature.FLUX_CAPACITOR_ID); + Mockito.when(commandMock.getProperties()).thenReturn(TestConstants.Feature.FLUX_CAPACITOR_PROPERTIES); + + underTest = ModifyFeaturePropertiesLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> ModifyFeaturePropertiesLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithModifyFeaturePropertiesCreatedResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeaturePropertiesLiveCommandAnswerBuilder.ResponseFactory::created) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithModifyFeaturePropertiesModifiedResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeaturePropertiesLiveCommandAnswerBuilder.ResponseFactory::modified) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithFeaturePropertiesNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeaturePropertiesLiveCommandAnswerBuilder + .ResponseFactory::featurePropertiesNotAccessibleError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(FeaturePropertiesNotAccessibleException.class); + } + + /** */ + @Test + public void buildAnswerWithFeaturePropertiesNotModifiableErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeaturePropertiesLiveCommandAnswerBuilder + .ResponseFactory::featurePropertiesNotModifiableError) + .withoutEvent() + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.FORBIDDEN) + .withDittoRuntimeExceptionOfType(FeaturePropertiesNotModifiableException.class); + } + + /** */ + @Test + public void buildAnswerWithFeaturePropertiesCreatedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(ModifyFeaturePropertiesLiveCommandAnswerBuilder.EventFactory::created) + .build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + + /** */ + @Test + public void buildAnswerWithFeaturePropertiesModifiedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(ModifyFeaturePropertiesLiveCommandAnswerBuilder.EventFactory::modified) + .build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommandImplTest.java new file mode 100644 index 00000000..1b304a28 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertiesLiveCommandImplTest.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.AllowedReason.provided; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.FeatureProperties; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureProperties; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.ModifyFeaturePropertiesLiveCommandImpl}. + */ +public final class ModifyFeaturePropertiesLiveCommandImplTest { + + private ModifyFeatureProperties twinCommand; + private ModifyFeaturePropertiesLiveCommand underTest; + + /** */ + @Before + public void setUp() { + twinCommand = ModifyFeatureProperties.of(TestConstants.Thing.THING_ID, TestConstants.Feature.FLUX_CAPACITOR_ID, + TestConstants.Feature.FLUX_CAPACITOR_PROPERTIES, DittoHeaders.empty()); + underTest = ModifyFeaturePropertiesLiveCommandImpl.of(twinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(ModifyFeaturePropertiesLiveCommandImpl.class, + areImmutable(), + provided(FeatureProperties.class).isAlsoImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(ModifyFeaturePropertiesLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingModifyCommand", "featureId", "featureProperties") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetModifyFeaturePropertiesLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> ModifyFeaturePropertiesLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetModifyFeaturePropertiesLiveCommandForCreateThingCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> ModifyFeaturePropertiesLiveCommandImpl.of(commandMock)) + .withMessageContaining( + ModifyFeatureProperties.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getModifyFeaturePropertiesLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(twinCommand.getType()) + .withDittoHeaders(twinCommand.getDittoHeaders()) + .withId(twinCommand.getThingEntityId()) + .withManifest(twinCommand.getManifest()) + .withResourcePath(twinCommand.getResourcePath()); + assertThat(underTest.getProperties()).isEqualTo(twinCommand.getProperties()); + assertThat(underTest.getFeatureId()).isEqualTo(twinCommand.getFeatureId()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final ModifyFeaturePropertiesLiveCommand newModifyFeaturePropertiesLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newModifyFeaturePropertiesLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(twinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..082d2892 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertyNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertyNotModifiableException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.ModifyFeaturePropertyLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class ModifyFeaturePropertyLiveCommandAnswerBuilderImplTest { + + @Mock + private ModifyFeaturePropertyLiveCommand commandMock; + + private ModifyFeaturePropertyLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getFeatureId()).thenReturn(TestConstants.Feature.FLUX_CAPACITOR_ID); + Mockito.when(commandMock.getPropertyPointer()) + .thenReturn(TestConstants.Feature.FLUX_CAPACITOR_PROPERTY_POINTER); + Mockito.when(commandMock.getPropertyValue()).thenReturn(TestConstants.Feature.FLUX_CAPACITOR_PROPERTY_VALUE); + + underTest = ModifyFeaturePropertyLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> ModifyFeaturePropertyLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithModifyFeaturePropertyCreatedResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeaturePropertyLiveCommandAnswerBuilder.ResponseFactory::created) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithModifyFeaturePropertyModifiedResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeaturePropertyLiveCommandAnswerBuilder.ResponseFactory::modified) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithFeaturePropertyNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeaturePropertyLiveCommandAnswerBuilder + .ResponseFactory::featurePropertyNotAccessibleError) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(FeaturePropertyNotAccessibleException.class); + } + + /** */ + @Test + public void buildAnswerWithFeaturePropertyNotModifiableErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeaturePropertyLiveCommandAnswerBuilder + .ResponseFactory::featurePropertyNotModifiableError) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.FORBIDDEN) + .withDittoRuntimeExceptionOfType(FeaturePropertyNotModifiableException.class); + } + + /** */ + @Test + public void buildAnswerWithFeaturePropertyCreatedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(ModifyFeaturePropertyLiveCommandAnswerBuilder.EventFactory::created) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + + /** */ + @Test + public void buildAnswerWithFeaturePropertyModifiedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(ModifyFeaturePropertyLiveCommandAnswerBuilder.EventFactory::modified) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommandImplTest.java new file mode 100644 index 00000000..2e9663f0 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturePropertyLiveCommandImplTest.java @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.AllowedReason.provided; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatureProperty; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.ModifyFeaturePropertyLiveCommandImpl}. + */ +public final class ModifyFeaturePropertyLiveCommandImplTest { + + private ModifyFeatureProperty twinCommand; + private ModifyFeaturePropertyLiveCommand underTest; + + /** */ + @Before + public void setUp() { + twinCommand = ModifyFeatureProperty.of(TestConstants.Thing.THING_ID, TestConstants.Feature.FLUX_CAPACITOR_ID, + TestConstants.Feature.FLUX_CAPACITOR_PROPERTY_POINTER, + TestConstants.Feature.FLUX_CAPACITOR_PROPERTY_VALUE, DittoHeaders.empty()); + underTest = ModifyFeaturePropertyLiveCommandImpl.of(twinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(ModifyFeaturePropertyLiveCommandImpl.class, + areImmutable(), + provided(JsonPointer.class, JsonValue.class).areAlsoImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(ModifyFeaturePropertyLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingModifyCommand", "featureId", "propertyPointer", "propertyValue") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetModifyFeaturePropertyLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> ModifyFeaturePropertyLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetModifyFeaturePropertyLiveCommandForCreateThingCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> ModifyFeaturePropertyLiveCommandImpl.of(commandMock)) + .withMessageContaining( + ModifyFeatureProperty.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getModifyFeaturePropertyLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(twinCommand.getType()) + .withDittoHeaders(twinCommand.getDittoHeaders()) + .withId(twinCommand.getThingEntityId()) + .withManifest(twinCommand.getManifest()) + .withResourcePath(twinCommand.getResourcePath()); + assertThat(underTest.getFeatureId()).isEqualTo(twinCommand.getFeatureId()); + assertThat(underTest.getPropertyPointer()).isEqualTo(twinCommand.getPropertyPointer()); + assertThat(underTest.getPropertyValue()).isEqualTo(twinCommand.getPropertyValue()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final ModifyFeaturePropertyLiveCommand newModifyFeaturePropertyLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newModifyFeaturePropertyLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(twinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..8412a54e --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturesNotModifiableException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.ModifyFeaturesLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class ModifyFeaturesLiveCommandAnswerBuilderImplTest { + + @Mock + private ModifyFeaturesLiveCommand commandMock; + + private ModifyFeaturesLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getFeatures()).thenReturn(TestConstants.Feature.FEATURES); + + underTest = ModifyFeaturesLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> ModifyFeaturesLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithModifyFeaturesCreatedResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeaturesLiveCommandAnswerBuilder.ResponseFactory::created) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithModifyFeaturesModifiedResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyFeaturesLiveCommandAnswerBuilder.ResponseFactory::modified) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithFeaturesNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + ModifyFeaturesLiveCommandAnswerBuilder.ResponseFactory::featuresNotAccessibleError) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(FeaturesNotAccessibleException.class); + } + + /** */ + @Test + public void buildAnswerWithFeaturesNotModifiableErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + ModifyFeaturesLiveCommandAnswerBuilder.ResponseFactory::featuresNotModifiableError) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.FORBIDDEN) + .withDittoRuntimeExceptionOfType(FeaturesNotModifiableException.class); + } + + /** */ + @Test + public void buildAnswerWithFeaturesCreatedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(ModifyFeaturesLiveCommandAnswerBuilder.EventFactory::created) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + + /** */ + @Test + public void buildAnswerWithFeaturesModifiedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(ModifyFeaturesLiveCommandAnswerBuilder.EventFactory::modified) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommandImplTest.java new file mode 100644 index 00000000..815512b1 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyFeaturesLiveCommandImplTest.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.AllowedReason.provided; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.assertj.core.api.Assertions; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.Features; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.modify.ModifyFeatures; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.ModifyFeaturesLiveCommandImpl}. + */ +public final class ModifyFeaturesLiveCommandImplTest { + + private ModifyFeatures twinCommand; + private ModifyFeaturesLiveCommand underTest; + + /** */ + @Before + public void setUp() { + twinCommand = ModifyFeatures.of(TestConstants.Thing.THING_ID, TestConstants.Feature.FEATURES, + DittoHeaders.empty()); + underTest = ModifyFeaturesLiveCommandImpl.of(twinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(ModifyFeaturesLiveCommandImpl.class, + areImmutable(), + provided(Features.class).isAlsoImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(ModifyFeaturesLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingModifyCommand", "features") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetModifyFeaturesLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> ModifyFeaturesLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetModifyFeaturesLiveCommandForCreateThingCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> ModifyFeaturesLiveCommandImpl.of(commandMock)) + .withMessageContaining(ModifyFeatures.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getModifyFeaturesLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(twinCommand.getType()) + .withDittoHeaders(twinCommand.getDittoHeaders()) + .withId(twinCommand.getThingEntityId()) + .withManifest(twinCommand.getManifest()) + .withResourcePath(twinCommand.getResourcePath()); + assertThat(underTest.getFeatures()).isEqualTo(twinCommand.getFeatures()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final ModifyFeaturesLiveCommand newModifyFeaturesLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newModifyFeaturesLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + Assertions.assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(twinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyLiveCommandFactoryTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyLiveCommandFactoryTest.java new file mode 100644 index 00000000..a18863b8 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyLiveCommandFactoryTest.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import org.junit.Test; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.ModifyLiveCommandFactory}. + */ +public final class ModifyLiveCommandFactoryTest { + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(ModifyLiveCommandFactory.class, areImmutable()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..99d3433c --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.ThingNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.exceptions.ThingNotModifiableException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.ModifyThingLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class ModifyThingLiveCommandAnswerBuilderImplTest { + + @Mock + private ModifyThingLiveCommand commandMock; + + private ModifyThingLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getThing()).thenReturn(TestConstants.Thing.THING); + + underTest = ModifyThingLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> ModifyThingLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithModifyThingCreatedResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyThingLiveCommandAnswerBuilder.ResponseFactory::created) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithModifyThingModifiedResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyThingLiveCommandAnswerBuilder.ResponseFactory::modified) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingModifyCommandResponse(); + } + + /** */ + @Test + public void buildAnswerWithThingNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyThingLiveCommandAnswerBuilder.ResponseFactory::thingNotAccessibleError) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(ThingNotAccessibleException.class); + } + + /** */ + @Test + public void buildAnswerWithThingNotModifiableErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(ModifyThingLiveCommandAnswerBuilder.ResponseFactory::thingNotModifiableError) + .withoutEvent() + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.FORBIDDEN) + .withDittoRuntimeExceptionOfType(ThingNotModifiableException.class); + } + + /** */ + @Test + public void buildAnswerWithThingCreatedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(ModifyThingLiveCommandAnswerBuilder.EventFactory::created) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + + /** */ + @Test + public void buildAnswerWithThingModifiedEventOnly() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse() + .withEvent(ModifyThingLiveCommandAnswerBuilder.EventFactory::modified) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasThingModifiedEvent(); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommandImplTest.java new file mode 100644 index 00000000..75f4e0d1 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/modify/ModifyThingLiveCommandImplTest.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.modify; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.AllowedReason.provided; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.Thing; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.modify.ModifyThing; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.modify.ModifyThingLiveCommandImpl}. + */ +public final class ModifyThingLiveCommandImplTest { + + private ModifyThing twinCommand; + private ModifyThingLiveCommand underTest; + + /** */ + @Before + public void setUp() { + twinCommand = ModifyThing.of(TestConstants.Thing.THING_ID, TestConstants.Thing.THING, null, DittoHeaders.empty + ()); + underTest = ModifyThingLiveCommandImpl.of(twinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(ModifyThingLiveCommandImpl.class, + areImmutable(), + provided(Thing.class).isAlsoImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(ModifyThingLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingModifyCommand", "thing") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetModifyThingLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> ModifyThingLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetModifyThingLiveCommandForCreateThingCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> ModifyThingLiveCommandImpl.of(commandMock)) + .withMessageContaining(ModifyThing.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getModifyThingLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(twinCommand.getType()) + .withDittoHeaders(twinCommand.getDittoHeaders()) + .withId(twinCommand.getThingEntityId()) + .withManifest(twinCommand.getManifest()) + .withResourcePath(twinCommand.getResourcePath()); + assertThat(underTest.getThing()).isEqualTo(twinCommand.getThing()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final ModifyThingLiveCommand newModifyThingLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newModifyThingLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(twinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/query/QueryLiveCommandFactoryTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/QueryLiveCommandFactoryTest.java new file mode 100644 index 00000000..e50cb419 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/QueryLiveCommandFactoryTest.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import org.junit.Test; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.query.QueryLiveCommandFactory}. + */ +public final class QueryLiveCommandFactoryTest { + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(QueryLiveCommandFactory.class, areImmutable()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..c7a4e75c --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.AttributeNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.query.RetrieveAttributeResponse; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.query.RetrieveAttributeLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class RetrieveAttributeLiveCommandAnswerBuilderImplTest { + + @Mock + private RetrieveAttributeLiveCommand commandMock; + + private RetrieveAttributeLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getAttributePointer()).thenReturn(TestConstants.Thing.LOCATION_ATTRIBUTE_POINTER); + + underTest = RetrieveAttributeLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> RetrieveAttributeLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithoutResponse() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse().build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasNoEvent(); + } + + /** */ + @Test + public void buildAnswerWithRetrieveAttributeResponseOnly() { + final JsonValue attributeValue = TestConstants.Thing.LOCATION_ATTRIBUTE_VALUE; + + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(responseFactory -> responseFactory.retrieved(attributeValue)) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingQueryCommandResponse() + .hasType(RetrieveAttributeResponse.TYPE) + .hasDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .hasResourcePath(JsonPointer.of("/attributes" + TestConstants.Thing.LOCATION_ATTRIBUTE_POINTER)); + } + + /** */ + @Test + public void buildAnswerWithAttributeNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + RetrieveAttributeLiveCommandAnswerBuilder.ResponseFactory::attributeNotAccessibleError) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(AttributeNotAccessibleException.class); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommandImplTest.java new file mode 100644 index 00000000..315e6a0d --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributeLiveCommandImplTest.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.AllowedReason.provided; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.query.RetrieveAttribute; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.query.RetrieveAttributeLiveCommandImpl}. + */ +public final class RetrieveAttributeLiveCommandImplTest { + + private RetrieveAttribute retrieveAttributeTwinCommand; + private RetrieveAttributeLiveCommand underTest; + + /** */ + @Before + public void setUp() { + retrieveAttributeTwinCommand = RetrieveAttribute.of(TestConstants.Thing.THING_ID, + TestConstants.Thing.LOCATION_ATTRIBUTE_POINTER, DittoHeaders.empty()); + underTest = RetrieveAttributeLiveCommandImpl.of(retrieveAttributeTwinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(RetrieveAttributeLiveCommandImpl.class, + areImmutable(), + provided(JsonPointer.class).isAlsoImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(RetrieveAttributeLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingQueryCommand", "attributePointer") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetRetrieveAttributeLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> RetrieveAttributeLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetRetrieveAttributeLiveCommandForCreateAttributeCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> RetrieveAttributeLiveCommandImpl.of(commandMock)) + .withMessageContaining(RetrieveAttribute.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getRetrieveAttributeLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(retrieveAttributeTwinCommand.getType()) + .withDittoHeaders(retrieveAttributeTwinCommand.getDittoHeaders()) + .withId(retrieveAttributeTwinCommand.getThingEntityId()) + .withManifest(retrieveAttributeTwinCommand.getManifest()) + .withResourcePath(retrieveAttributeTwinCommand.getResourcePath()); + assertThat(underTest.getAttributePointer()).isEqualTo(retrieveAttributeTwinCommand.getAttributePointer()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final RetrieveAttributeLiveCommand newRetrieveAttributeLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newRetrieveAttributeLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(retrieveAttributeTwinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..82b00bf1 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.Attributes; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.AttributesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.query.RetrieveAttributesResponse; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.query.RetrieveAttributesLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class RetrieveAttributesLiveCommandAnswerBuilderImplTest { + + @Mock + private RetrieveAttributesLiveCommand commandMock; + + private RetrieveAttributesLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + + underTest = RetrieveAttributesLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> RetrieveAttributesLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithoutResponse() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse().build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasNoEvent(); + } + + /** */ + @Test + public void buildAnswerWithRetrieveAttributesResponseOnly() { + final Attributes attributes = TestConstants.Thing.ATTRIBUTES; + + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(responseFactory -> responseFactory.retrieved(attributes)) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingQueryCommandResponse() + .hasType(RetrieveAttributesResponse.TYPE) + .hasDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .hasResourcePath(JsonPointer.of("attributes")); + } + + /** */ + @Test + public void buildAnswerWithAttributeNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + RetrieveAttributesLiveCommandAnswerBuilder.ResponseFactory::attributesNotAccessibleError) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(AttributesNotAccessibleException.class); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommandImplTest.java new file mode 100644 index 00000000..f18debca --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveAttributesLiveCommandImplTest.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.AllowedReason.provided; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.query.RetrieveAttributes; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.query.RetrieveAttributesLiveCommandImpl}. + */ +public final class RetrieveAttributesLiveCommandImplTest { + + private RetrieveAttributes retrieveAttributesTwinCommand; + private RetrieveAttributesLiveCommand underTest; + + /** */ + @Before + public void setUp() { + retrieveAttributesTwinCommand = RetrieveAttributes.of(TestConstants.Thing.THING_ID, + TestConstants.JSON_FIELD_SELECTOR_ATTRIBUTES, DittoHeaders.empty()); + underTest = RetrieveAttributesLiveCommandImpl.of(retrieveAttributesTwinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(RetrieveAttributesLiveCommandImpl.class, + areImmutable(), + provided(JsonPointer.class).isAlsoImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(RetrieveAttributesLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingQueryCommand") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetRetrieveAttributesLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> RetrieveAttributesLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetRetrieveAttributesLiveCommandForCreateAttributeCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> RetrieveAttributesLiveCommandImpl.of(commandMock)) + .withMessageContaining( + RetrieveAttributes.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getRetrieveAttributesLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(retrieveAttributesTwinCommand.getType()) + .withDittoHeaders(retrieveAttributesTwinCommand.getDittoHeaders()) + .withId(retrieveAttributesTwinCommand.getThingEntityId()) + .withManifest(retrieveAttributesTwinCommand.getManifest()) + .withResourcePath(retrieveAttributesTwinCommand.getResourcePath()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final RetrieveAttributesLiveCommand newRetrieveAttributesLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newRetrieveAttributesLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(retrieveAttributesTwinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..e0d4c012 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions.assertThat; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.FeatureDefinition; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDefinitionNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDefinitionResponse; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.query.RetrieveFeatureDefinitionLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class RetrieveFeatureDefinitionLiveCommandAnswerBuilderImplTest { + + @Mock + private RetrieveFeatureDefinitionLiveCommand commandMock; + + private RetrieveFeatureDefinitionLiveCommandAnswerBuilderImpl underTest; + + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getFeatureId()).thenReturn(TestConstants.Feature.FLUX_CAPACITOR_ID); + + underTest = RetrieveFeatureDefinitionLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> RetrieveFeatureDefinitionLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + @Test + public void buildAnswerWithoutResponse() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse().build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasNoEvent(); + } + + @Test + public void buildAnswerWithRetrieveFeatureDefinitionResponseOnly() { + final FeatureDefinition featureProperties = TestConstants.Feature.FLUX_CAPACITOR_DEFINITION; + + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(responseFactory -> responseFactory.retrieved(featureProperties)) + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingQueryCommandResponse() + .hasType(RetrieveFeatureDefinitionResponse.TYPE) + .hasDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .hasResourcePath(JsonPointer.of("features/" + TestConstants.Feature.FLUX_CAPACITOR_ID + "/definition")); + } + + @Test + public void buildAnswerWithFeatureDefinitionNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + RetrieveFeatureDefinitionLiveCommandAnswerBuilder.ResponseFactory::featureDefinitionNotAccessibleError) + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(FeatureDefinitionNotAccessibleException.class); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommandImplTest.java new file mode 100644 index 00000000..f84ff7ef --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDefinitionLiveCommandImplTest.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatNullPointerException; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDefinition; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.query.RetrieveFeatureDefinitionLiveCommandImpl}. + */ +public final class RetrieveFeatureDefinitionLiveCommandImplTest { + + private RetrieveFeatureDefinition retrieveFeatureDefinitionTwinCommand; + private RetrieveFeatureDefinitionLiveCommand underTest; + + @Before + public void setUp() { + retrieveFeatureDefinitionTwinCommand = RetrieveFeatureDefinition.of(TestConstants.Thing.THING_ID, + TestConstants.Feature.FLUX_CAPACITOR_ID, DittoHeaders.empty()); + underTest = RetrieveFeatureDefinitionLiveCommandImpl.of(retrieveFeatureDefinitionTwinCommand); + } + + @Test + public void assertImmutability() { + assertInstancesOf(RetrieveFeatureDefinitionLiveCommandImpl.class, areImmutable()); + } + + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(RetrieveFeatureDefinitionLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingQueryCommand", "featureId") + .verify(); + } + + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetRetrieveFeatureDefinitionLiveCommandForNull() { + assertThatNullPointerException() + .isThrownBy(() -> RetrieveFeatureDefinitionLiveCommandImpl.of(null)) + .withMessage("The %s must not be null!", "command") + .withNoCause(); + } + + @Test + public void tryToGetRetrieveFeatureDefinitionLiveCommandForCreateAttributeCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> RetrieveFeatureDefinitionLiveCommandImpl.of(commandMock)) + .withMessageContaining(RetrieveFeatureDefinition.class.getName()) + .withNoCause(); + } + + @Test + public void getRetrieveFeatureDefinitionLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(retrieveFeatureDefinitionTwinCommand.getType()) + .withDittoHeaders(retrieveFeatureDefinitionTwinCommand.getDittoHeaders()) + .withId(retrieveFeatureDefinitionTwinCommand.getThingEntityId()) + .withManifest(retrieveFeatureDefinitionTwinCommand.getManifest()) + .withResourcePath(retrieveFeatureDefinitionTwinCommand.getResourcePath()); + assertThat(underTest.getFeatureId()).isEqualTo(retrieveFeatureDefinitionTwinCommand.getFeatureId()); + } + + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final RetrieveFeatureDefinitionLiveCommand newRetrieveFeatureDefinitionLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newRetrieveFeatureDefinitionLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(retrieveFeatureDefinitionTwinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..e2d06567 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions.assertThat; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.FeatureProperties; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertiesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDesiredPropertiesResponse; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.query.RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilderImplTest { + + @Mock + private RetrieveFeatureDesiredPropertiesLiveCommand commandMock; + + private RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getFeatureId()).thenReturn(TestConstants.Feature.HOVER_BOARD_ID); + + underTest = RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithoutResponse() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse().build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasNoEvent(); + } + + /** */ + @Test + public void buildAnswerWithRetrieveFeatureDesiredPropertiesResponseOnly() { + final FeatureProperties desiredProperties = TestConstants.Feature.HOVER_BOARD_PROPERTIES; + + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(responseFactory -> responseFactory.retrieved(desiredProperties)) + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingQueryCommandResponse() + .hasType(RetrieveFeatureDesiredPropertiesResponse.TYPE) + .hasDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .hasResourcePath(JsonPointer.of("features/" + TestConstants.Feature.HOVER_BOARD_ID + "/desiredProperties")); + } + + /** */ + @Test + public void buildAnswerWithFeatureDesiredPropertiesNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + RetrieveFeatureDesiredPropertiesLiveCommandAnswerBuilder.ResponseFactory::featureDesiredPropertiesNotAccessibleError) + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(FeatureDesiredPropertiesNotAccessibleException.class); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommandImplTest.java new file mode 100644 index 00000000..99f836fa --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertiesLiveCommandImplTest.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDesiredProperties; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.query.RetrieveFeatureDesiredPropertiesLiveCommandImpl}. + */ +public final class RetrieveFeatureDesiredPropertiesLiveCommandImplTest { + + private RetrieveFeatureDesiredProperties retrieveFeatureDesiredPropertiesTwinCommand; + private RetrieveFeatureDesiredPropertiesLiveCommand underTest; + + /** */ + @Before + public void setUp() { + retrieveFeatureDesiredPropertiesTwinCommand = RetrieveFeatureDesiredProperties.of(TestConstants.Thing.THING_ID, + TestConstants.Feature.HOVER_BOARD_ID, TestConstants.JSON_FIELD_SELECTOR_ATTRIBUTES, + DittoHeaders.empty()); + underTest = RetrieveFeatureDesiredPropertiesLiveCommandImpl.of(retrieveFeatureDesiredPropertiesTwinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(RetrieveFeatureDesiredPropertiesLiveCommandImpl.class, areImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(RetrieveFeatureDesiredPropertiesLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingQueryCommand", "featureId") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetRetrieveFeatureDesiredPropertiesLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> RetrieveFeatureDesiredPropertiesLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetRetrieveFeatureDesiredPropertiesLiveCommandForCreateAttributeCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> RetrieveFeatureDesiredPropertiesLiveCommandImpl.of(commandMock)) + .withMessageContaining(RetrieveFeatureDesiredProperties.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getRetrieveFeatureDesiredPropertiesLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(retrieveFeatureDesiredPropertiesTwinCommand.getType()) + .withDittoHeaders(retrieveFeatureDesiredPropertiesTwinCommand.getDittoHeaders()) + .withId(retrieveFeatureDesiredPropertiesTwinCommand.getThingEntityId()) + .withManifest(retrieveFeatureDesiredPropertiesTwinCommand.getManifest()) + .withResourcePath(retrieveFeatureDesiredPropertiesTwinCommand.getResourcePath()); + assertThat(underTest.getFeatureId()).isEqualTo(retrieveFeatureDesiredPropertiesTwinCommand.getFeatureId()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final RetrieveFeatureDesiredPropertiesLiveCommand newRetrieveFeatureDesiredPropertiesLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newRetrieveFeatureDesiredPropertiesLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(retrieveFeatureDesiredPropertiesTwinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..d3574c13 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions.assertThat; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureDesiredPropertyNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDesiredPropertyResponse; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.query.RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilderImplTest { + + @Mock + private RetrieveFeatureDesiredPropertyLiveCommand commandMock; + + private RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getFeatureId()).thenReturn(TestConstants.Feature.HOVER_BOARD_ID); + Mockito.when(commandMock.getDesiredPropertyPointer()) + .thenReturn(TestConstants.Feature.HOVER_BOARD_PROPERTY_POINTER); + + underTest = RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithoutResponse() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse().build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasNoEvent(); + } + + /** */ + @Test + public void buildAnswerWithRetrieveFeatureDesiredPropertyResponseOnly() { + final JsonValue FeatureDesiredProperty = TestConstants.Feature.HOVER_BOARD_PROPERTY_VALUE; + + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(responseFactory -> responseFactory.retrieved(FeatureDesiredProperty)) + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingQueryCommandResponse() + .hasType(RetrieveFeatureDesiredPropertyResponse.TYPE) + .hasDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .hasResourcePath(JsonPointer.of( + "features/" + TestConstants.Feature.HOVER_BOARD_ID + "/desiredProperties/speed")); + } + + /** */ + @Test + public void buildAnswerWithFeatureDesiredPropertyNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + RetrieveFeatureDesiredPropertyLiveCommandAnswerBuilder.ResponseFactory::featureDesiredPropertyNotAccessibleError) + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(FeatureDesiredPropertyNotAccessibleException.class); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommandImplTest.java new file mode 100644 index 00000000..279d021f --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureDesiredPropertyLiveCommandImplTest.java @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2020 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.AllowedReason.provided; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.assertj.core.api.Assertions; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureDesiredProperty; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.query.RetrieveFeatureDesiredPropertyLiveCommandImpl}. + */ +public final class RetrieveFeatureDesiredPropertyLiveCommandImplTest { + + private RetrieveFeatureDesiredProperty retrieveFeatureDesiredPropertyTwinCommand; + private RetrieveFeatureDesiredPropertyLiveCommand underTest; + + /** */ + @Before + public void setUp() { + retrieveFeatureDesiredPropertyTwinCommand = RetrieveFeatureDesiredProperty.of(TestConstants.Thing.THING_ID, + TestConstants.Feature.HOVER_BOARD_ID, TestConstants.Feature.HOVER_BOARD_PROPERTY_POINTER, + DittoHeaders.empty()); + underTest = RetrieveFeatureDesiredPropertyLiveCommandImpl.of(retrieveFeatureDesiredPropertyTwinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(RetrieveFeatureDesiredPropertyLiveCommandImpl.class, + areImmutable(), + provided(JsonPointer.class).isAlsoImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(RetrieveFeatureDesiredPropertyLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingQueryCommand", "featureId", "desiredPropertyPointer") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetRetrieveFeatureDesiredPropertyLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> RetrieveFeatureDesiredPropertyLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetRetrieveFeatureDesiredPropertyLiveCommandForCreateAttributeCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> RetrieveFeatureDesiredPropertyLiveCommandImpl.of(commandMock)) + .withMessageContaining(RetrieveFeatureDesiredProperty.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getRetrieveFeatureDesiredPropertyLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(retrieveFeatureDesiredPropertyTwinCommand.getType()) + .withDittoHeaders(retrieveFeatureDesiredPropertyTwinCommand.getDittoHeaders()) + .withId(retrieveFeatureDesiredPropertyTwinCommand.getThingEntityId()) + .withManifest(retrieveFeatureDesiredPropertyTwinCommand.getManifest()) + .withResourcePath(retrieveFeatureDesiredPropertyTwinCommand.getResourcePath()); + assertThat(underTest.getFeatureId()).isEqualTo(retrieveFeatureDesiredPropertyTwinCommand.getFeatureId()); + assertThat(underTest.getDesiredPropertyPointer()) + .isEqualTo(retrieveFeatureDesiredPropertyTwinCommand.getDesiredPropertyPointer()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final RetrieveFeatureDesiredPropertyLiveCommand newRetrieveFeatureDesiredPropertyLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newRetrieveFeatureDesiredPropertyLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + Assertions.assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(retrieveFeatureDesiredPropertyTwinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..45cf089b --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.Feature; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeatureNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureResponse; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.query.RetrieveFeatureLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class RetrieveFeatureLiveCommandAnswerBuilderImplTest { + + @Mock + private RetrieveFeatureLiveCommand commandMock; + + private RetrieveFeatureLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getFeatureId()).thenReturn(TestConstants.Feature.FLUX_CAPACITOR_ID); + + underTest = RetrieveFeatureLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> RetrieveFeatureLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithoutResponse() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse().build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasNoEvent(); + } + + /** */ + @Test + public void buildAnswerWithRetrieveFeatureResponseOnly() { + final Feature feature = TestConstants.Feature.FLUX_CAPACITOR; + + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(responseFactory -> responseFactory.retrieved(feature)) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingQueryCommandResponse() + .hasType(RetrieveFeatureResponse.TYPE) + .hasDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .hasResourcePath(JsonPointer.of("features/" + feature.getId())); + } + + /** */ + @Test + public void buildAnswerWithFeatureNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + RetrieveFeatureLiveCommandAnswerBuilder.ResponseFactory::featureNotAccessibleError) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(FeatureNotAccessibleException.class); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommandImplTest.java new file mode 100644 index 00000000..7e82be05 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeatureLiveCommandImplTest.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeature; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.query.RetrieveFeatureLiveCommandImpl}. + */ +public final class RetrieveFeatureLiveCommandImplTest { + + private RetrieveFeature retrieveFeatureTwinCommand; + private RetrieveFeatureLiveCommand underTest; + + /** */ + @Before + public void setUp() { + retrieveFeatureTwinCommand = RetrieveFeature.of(TestConstants.Thing.THING_ID, + TestConstants.Feature.FLUX_CAPACITOR_ID, TestConstants.JSON_FIELD_SELECTOR_ATTRIBUTES, + DittoHeaders.empty()); + underTest = RetrieveFeatureLiveCommandImpl.of(retrieveFeatureTwinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(RetrieveFeatureLiveCommandImpl.class, areImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(RetrieveFeatureLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingQueryCommand", "featureId") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetRetrieveFeatureLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> RetrieveFeatureLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetRetrieveFeatureLiveCommandForCreateAttributeCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> RetrieveFeatureLiveCommandImpl.of(commandMock)) + .withMessageContaining(RetrieveFeature.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getRetrieveFeatureLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(retrieveFeatureTwinCommand.getType()) + .withDittoHeaders(retrieveFeatureTwinCommand.getDittoHeaders()) + .withId(retrieveFeatureTwinCommand.getThingEntityId()) + .withManifest(retrieveFeatureTwinCommand.getManifest()) + .withResourcePath(retrieveFeatureTwinCommand.getResourcePath()); + assertThat(underTest.getFeatureId()).isEqualTo(retrieveFeatureTwinCommand.getFeatureId()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final RetrieveFeatureLiveCommand newRetrieveFeatureLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newRetrieveFeatureLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(retrieveFeatureTwinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..03edefb2 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions.assertThat; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.FeatureProperties; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertiesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeaturePropertiesResponse; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.query.RetrieveFeaturePropertiesLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class RetrieveFeaturePropertiesLiveCommandAnswerBuilderImplTest { + + @Mock + private RetrieveFeaturePropertiesLiveCommand commandMock; + + private RetrieveFeaturePropertiesLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getFeatureId()).thenReturn(TestConstants.Feature.FLUX_CAPACITOR_ID); + + underTest = RetrieveFeaturePropertiesLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> RetrieveFeaturePropertiesLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithoutResponse() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse().build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasNoEvent(); + } + + /** */ + @Test + public void buildAnswerWithRetrieveFeaturePropertiesResponseOnly() { + final FeatureProperties featureProperties = TestConstants.Feature.FLUX_CAPACITOR_PROPERTIES; + + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(responseFactory -> responseFactory.retrieved(featureProperties)) + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingQueryCommandResponse() + .hasType(RetrieveFeaturePropertiesResponse.TYPE) + .hasDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .hasResourcePath(JsonPointer.of("features/" + TestConstants.Feature.FLUX_CAPACITOR_ID + "/properties")); + } + + /** */ + @Test + public void buildAnswerWithFeaturePropertiesNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + RetrieveFeaturePropertiesLiveCommandAnswerBuilder.ResponseFactory::featurePropertiesNotAccessibleError) + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(FeaturePropertiesNotAccessibleException.class); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommandImplTest.java new file mode 100644 index 00000000..073846f9 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertiesLiveCommandImplTest.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureProperties; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.query.RetrieveFeaturePropertiesLiveCommandImpl}. + */ +public final class RetrieveFeaturePropertiesLiveCommandImplTest { + + private RetrieveFeatureProperties retrieveFeaturePropertiesTwinCommand; + private RetrieveFeaturePropertiesLiveCommand underTest; + + /** */ + @Before + public void setUp() { + retrieveFeaturePropertiesTwinCommand = RetrieveFeatureProperties.of(TestConstants.Thing.THING_ID, + TestConstants.Feature.FLUX_CAPACITOR_ID, TestConstants.JSON_FIELD_SELECTOR_ATTRIBUTES, + DittoHeaders.empty()); + underTest = RetrieveFeaturePropertiesLiveCommandImpl.of(retrieveFeaturePropertiesTwinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(RetrieveFeaturePropertiesLiveCommandImpl.class, areImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(RetrieveFeaturePropertiesLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingQueryCommand", "featureId") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetRetrieveFeaturePropertiesLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> RetrieveFeaturePropertiesLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetRetrieveFeaturePropertiesLiveCommandForCreateAttributeCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> RetrieveFeaturePropertiesLiveCommandImpl.of(commandMock)) + .withMessageContaining(RetrieveFeatureProperties.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getRetrieveFeaturePropertiesLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(retrieveFeaturePropertiesTwinCommand.getType()) + .withDittoHeaders(retrieveFeaturePropertiesTwinCommand.getDittoHeaders()) + .withId(retrieveFeaturePropertiesTwinCommand.getThingEntityId()) + .withManifest(retrieveFeaturePropertiesTwinCommand.getManifest()) + .withResourcePath(retrieveFeaturePropertiesTwinCommand.getResourcePath()); + assertThat(underTest.getFeatureId()).isEqualTo(retrieveFeaturePropertiesTwinCommand.getFeatureId()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final RetrieveFeaturePropertiesLiveCommand newRetrieveFeaturePropertiesLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newRetrieveFeaturePropertiesLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(retrieveFeaturePropertiesTwinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..c561620b --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions.assertThat; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.json.JsonValue; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturePropertyNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeaturePropertyResponse; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.query.RetrieveFeaturePropertyLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class RetrieveFeaturePropertyLiveCommandAnswerBuilderImplTest { + + @Mock + private RetrieveFeaturePropertyLiveCommand commandMock; + + private RetrieveFeaturePropertyLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getFeatureId()).thenReturn(TestConstants.Feature.FLUX_CAPACITOR_ID); + Mockito.when(commandMock.getPropertyPointer()) + .thenReturn(TestConstants.Feature.FLUX_CAPACITOR_PROPERTY_POINTER); + + underTest = RetrieveFeaturePropertyLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> RetrieveFeaturePropertyLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithoutResponse() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse().build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasNoEvent(); + } + + /** */ + @Test + public void buildAnswerWithRetrieveFeaturePropertyResponseOnly() { + final JsonValue featureProperty = TestConstants.Feature.FLUX_CAPACITOR_PROPERTY_VALUE; + + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(responseFactory -> responseFactory.retrieved(featureProperty)) + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingQueryCommandResponse() + .hasType(RetrieveFeaturePropertyResponse.TYPE) + .hasDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .hasResourcePath(JsonPointer.of( + "features/" + TestConstants.Feature.FLUX_CAPACITOR_ID + "/properties/target_year_1")); + } + + /** */ + @Test + public void buildAnswerWithFeaturePropertyNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + RetrieveFeaturePropertyLiveCommandAnswerBuilder.ResponseFactory::featurePropertyNotAccessibleError) + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(FeaturePropertyNotAccessibleException.class); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommandImplTest.java new file mode 100644 index 00000000..5fd67961 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturePropertyLiveCommandImplTest.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.AllowedReason.provided; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.assertj.core.api.Assertions; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatureProperty; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.query.RetrieveFeaturePropertyLiveCommandImpl}. + */ +public final class RetrieveFeaturePropertyLiveCommandImplTest { + + private RetrieveFeatureProperty retrieveFeaturePropertyTwinCommand; + private RetrieveFeaturePropertyLiveCommand underTest; + + /** */ + @Before + public void setUp() { + retrieveFeaturePropertyTwinCommand = RetrieveFeatureProperty.of(TestConstants.Thing.THING_ID, + TestConstants.Feature.FLUX_CAPACITOR_ID, TestConstants.Feature.FLUX_CAPACITOR_PROPERTY_POINTER, + DittoHeaders.empty()); + underTest = RetrieveFeaturePropertyLiveCommandImpl.of(retrieveFeaturePropertyTwinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(RetrieveFeaturePropertyLiveCommandImpl.class, + areImmutable(), + provided(JsonPointer.class).isAlsoImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(RetrieveFeaturePropertyLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingQueryCommand", "featureId", "propertyPointer") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetRetrieveFeaturePropertyLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> RetrieveFeaturePropertyLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetRetrieveFeaturePropertyLiveCommandForCreateAttributeCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> RetrieveFeaturePropertyLiveCommandImpl.of(commandMock)) + .withMessageContaining(RetrieveFeatureProperty.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getRetrieveFeaturePropertyLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(retrieveFeaturePropertyTwinCommand.getType()) + .withDittoHeaders(retrieveFeaturePropertyTwinCommand.getDittoHeaders()) + .withId(retrieveFeaturePropertyTwinCommand.getThingEntityId()) + .withManifest(retrieveFeaturePropertyTwinCommand.getManifest()) + .withResourcePath(retrieveFeaturePropertyTwinCommand.getResourcePath()); + assertThat(underTest.getFeatureId()).isEqualTo(retrieveFeaturePropertyTwinCommand.getFeatureId()); + assertThat(underTest.getPropertyPointer()) + .isEqualTo(retrieveFeaturePropertyTwinCommand.getPropertyPointer()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final RetrieveFeaturePropertyLiveCommand newRetrieveFeaturePropertyLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newRetrieveFeaturePropertyLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + Assertions.assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(retrieveFeaturePropertyTwinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..435006a0 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions.assertThat; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.Features; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.FeaturesNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeaturesResponse; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.query.RetrieveFeaturesLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class RetrieveFeaturesLiveCommandAnswerBuilderImplTest { + + @Mock + private RetrieveFeaturesLiveCommand commandMock; + + private RetrieveFeaturesLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + + underTest = RetrieveFeaturesLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> RetrieveFeaturesLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithoutResponse() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse().build(); + + assertThat(liveCommandAnswer) + .hasNoResponse() + .hasNoEvent(); + } + + /** */ + @Test + public void buildAnswerWithRetrieveFeaturesResponseOnly() { + final Features features = TestConstants.Feature.FEATURES; + + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(responseFactory -> responseFactory.retrieved(features)) + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingQueryCommandResponse() + .hasType(RetrieveFeaturesResponse.TYPE) + .hasDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .hasResourcePath(JsonPointer.of("features")); + } + + /** */ + @Test + public void buildAnswerWithAttributeNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + RetrieveFeaturesLiveCommandAnswerBuilder.ResponseFactory::featuresNotAccessibleError) + .build(); + + assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(FeaturesNotAccessibleException.class); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommandImplTest.java new file mode 100644 index 00000000..fdfd8a5c --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveFeaturesLiveCommandImplTest.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.assertj.core.api.Assertions; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.query.RetrieveFeatures; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.query.RetrieveFeaturesLiveCommandImpl}. + */ +public final class RetrieveFeaturesLiveCommandImplTest { + + private RetrieveFeatures retrieveFeaturesTwinCommand; + private RetrieveFeaturesLiveCommand underTest; + + /** */ + @Before + public void setUp() { + retrieveFeaturesTwinCommand = RetrieveFeatures.of(TestConstants.Thing.THING_ID, + TestConstants.JSON_FIELD_SELECTOR_ATTRIBUTES, DittoHeaders.empty()); + underTest = RetrieveFeaturesLiveCommandImpl.of(retrieveFeaturesTwinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(RetrieveFeaturesLiveCommandImpl.class, areImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(RetrieveFeaturesLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingQueryCommand") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetRetrieveFeaturesLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> RetrieveFeaturesLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetRetrieveFeaturesLiveCommandForCreateAttributeCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> RetrieveFeaturesLiveCommandImpl.of(commandMock)) + .withMessageContaining(RetrieveFeatures.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getRetrieveFeaturesLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(retrieveFeaturesTwinCommand.getType()) + .withDittoHeaders(retrieveFeaturesTwinCommand.getDittoHeaders()) + .withId(retrieveFeaturesTwinCommand.getThingEntityId()) + .withManifest(retrieveFeaturesTwinCommand.getManifest()) + .withResourcePath(retrieveFeaturesTwinCommand.getResourcePath()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final RetrieveFeaturesLiveCommand newRetrieveFeaturesLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newRetrieveFeaturesLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + Assertions.assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(retrieveFeaturesTwinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..75934edb --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +import java.text.MessageFormat; + +import org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.model.base.common.HttpStatus; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.Thing; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.ThingErrorResponse; +import org.eclipse.ditto.signals.commands.things.exceptions.ThingNotAccessibleException; +import org.eclipse.ditto.signals.commands.things.query.RetrieveThingResponse; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.query.RetrieveThingLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class RetrieveThingLiveCommandAnswerBuilderImplTest { + + @Mock + private RetrieveThingLiveCommand commandMock; + + private RetrieveThingLiveCommandAnswerBuilderImpl underTest; + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getThingEntityId()).thenReturn(TestConstants.Thing.THING_ID); + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + + underTest = RetrieveThingLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> RetrieveThingLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithoutResponse() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse().build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasNoEvent(); + } + + /** */ + @Test + public void buildAnswerWithRetrieveThingResponseOnly() { + final Thing thing = TestConstants.Thing.THING; + + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(responseFactory -> responseFactory.retrieved(thing)) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingQueryCommandResponse() + .hasType(RetrieveThingResponse.TYPE) + .hasDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .hasResourcePath(JsonPointer.empty()); + } + + /** */ + @Test + public void buildAnswerWithThingNotAccessibleErrorResponseOnly() { + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse( + RetrieveThingLiveCommandAnswerBuilder.ResponseFactory::thingNotAccessibleError) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingErrorResponse() + .withType(ThingErrorResponse.TYPE) + .withDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .withStatus(HttpStatus.NOT_FOUND) + .withDittoRuntimeExceptionOfType(ThingNotAccessibleException.class); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommandImplTest.java new file mode 100644 index 00000000..2b91f577 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingLiveCommandImplTest.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; + +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.query.RetrieveThing; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.query.RetrieveThingLiveCommandImpl}. + */ +public final class RetrieveThingLiveCommandImplTest { + + private RetrieveThing retrieveThingTwinCommand; + private RetrieveThingLiveCommand underTest; + + /** */ + @Before + public void setUp() { + retrieveThingTwinCommand = RetrieveThing.getBuilder(TestConstants.Thing.THING_ID, DittoHeaders.empty()) + .withSelectedFields(TestConstants.JSON_FIELD_SELECTOR_ATTRIBUTES) + .build(); + underTest = RetrieveThingLiveCommandImpl.of(retrieveThingTwinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(RetrieveThingLiveCommandImpl.class, areImmutable()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(RetrieveThingLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingQueryCommand") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetRetrieveThingLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> RetrieveThingLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetRetrieveThingLiveCommandForCreateAttributeCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> RetrieveThingLiveCommandImpl.of(commandMock)) + .withMessageContaining(RetrieveThing.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getRetrieveThingLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(retrieveThingTwinCommand.getType()) + .withDittoHeaders(retrieveThingTwinCommand.getDittoHeaders()) + .withId(retrieveThingTwinCommand.getThingEntityId()) + .withManifest(retrieveThingTwinCommand.getManifest()) + .withResourcePath(retrieveThingTwinCommand.getResourcePath()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final RetrieveThingLiveCommand newRetrieveThingLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newRetrieveThingLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(retrieveThingTwinCommand.toString()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommandAnswerBuilderImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommandAnswerBuilderImplTest.java new file mode 100644 index 00000000..ee56d022 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommandAnswerBuilderImplTest.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +import org.eclipse.ditto.client.live.commands.assertions.LiveCommandAssertions; +import org.eclipse.ditto.client.live.commands.base.LiveCommandAnswer; +import org.eclipse.ditto.json.JsonFieldSelector; +import org.eclipse.ditto.json.JsonPointer; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.Thing; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.query.RetrieveThingsResponse; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.query.RetrieveThingsLiveCommandAnswerBuilderImpl}. + */ +@RunWith(MockitoJUnitRunner.class) +public final class RetrieveThingsLiveCommandAnswerBuilderImplTest { + + private static List thingIds; + + @Mock + private RetrieveThingsLiveCommand commandMock; + + private RetrieveThingsLiveCommandAnswerBuilderImpl underTest; + + /** */ + @BeforeClass + public static void initThingIds() { + thingIds = new ArrayList<>(); + thingIds.add(":foo"); + thingIds.add(":bar"); + thingIds.add(":baz"); + } + + /** */ + @Before + public void setUp() { + Mockito.when(commandMock.getDittoHeaders()).thenReturn(DittoHeaders.empty()); + Mockito.when(commandMock.getSelectedFields()).thenReturn(Optional.of(Mockito.mock(JsonFieldSelector.class))); + + underTest = RetrieveThingsLiveCommandAnswerBuilderImpl.newInstance(commandMock); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetNewInstanceWithNullCommand() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> RetrieveThingsLiveCommandAnswerBuilderImpl.newInstance(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void buildAnswerWithoutResponse() { + final LiveCommandAnswer liveCommandAnswer = underTest.withoutResponse().build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoResponse() + .hasNoEvent(); + } + + /** */ + @Test + public void buildAnswerWithRetrieveThingResponseOnly() { + final Thing thing = TestConstants.Thing.THING; + + final LiveCommandAnswer liveCommandAnswer = + underTest.withResponse(responseFactory -> responseFactory.retrieved(Collections.emptyList())) + .build(); + + LiveCommandAssertions.assertThat(liveCommandAnswer) + .hasNoEvent() + .hasThingQueryCommandResponse() + .hasType(RetrieveThingsResponse.TYPE) + .hasDittoHeaders(DittoHeaders.newBuilder().responseRequired(false).build()) + .hasResourcePath(JsonPointer.empty()); + } + +} diff --git a/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommandImplTest.java b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommandImplTest.java new file mode 100644 index 00000000..a5cdef48 --- /dev/null +++ b/java/src/test/java/org/eclipse/ditto/client/live/commands/query/RetrieveThingsLiveCommandImplTest.java @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.ditto.client.live.commands.query; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.eclipse.ditto.signals.commands.base.assertions.CommandAssertions.assertThat; +import static org.mutabilitydetector.unittesting.AllowedReason.assumingFields; +import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; +import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; + +import org.assertj.core.api.Assertions; +import org.eclipse.ditto.model.base.headers.DittoHeaders; +import org.eclipse.ditto.model.things.ThingId; +import org.eclipse.ditto.signals.commands.base.Command; +import org.eclipse.ditto.signals.commands.things.TestConstants; +import org.eclipse.ditto.signals.commands.things.query.RetrieveThings; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.mockito.Mockito; + +import nl.jqno.equalsverifier.EqualsVerifier; + + +/** + * Unit test for {@link org.eclipse.ditto.client.live.commands.query.RetrieveThingsLiveCommandImpl}. + */ +public final class RetrieveThingsLiveCommandImplTest { + + private static List thingIds; + + private RetrieveThings retrieveThingTwinCommand; + private RetrieveThingsLiveCommand underTest; + + /** */ + @BeforeClass + public static void initThingIds() { + thingIds = new ArrayList<>(); + thingIds.add(ThingId.inDefaultNamespace("foo")); + thingIds.add(ThingId.inDefaultNamespace("bar")); + thingIds.add(ThingId.inDefaultNamespace("baz")); + } + + /** */ + @Before + public void setUp() { + retrieveThingTwinCommand = RetrieveThings.getBuilder(thingIds) + .selectedFields(TestConstants.JSON_FIELD_SELECTOR_ATTRIBUTES) + .dittoHeaders(DittoHeaders.empty()) + .build(); + underTest = RetrieveThingsLiveCommandImpl.of(retrieveThingTwinCommand); + } + + /** */ + @Test + public void assertImmutability() { + assertInstancesOf(RetrieveThingsLiveCommandImpl.class, + areImmutable(), + assumingFields("thingIds").areSafelyCopiedUnmodifiableCollectionsWithImmutableElements()); + } + + /** */ + @Test + public void testHashCodeAndEquals() { + EqualsVerifier.forClass(RetrieveThingsLiveCommandImpl.class) + .withRedefinedSuperclass() + .withIgnoredFields("thingQueryCommand", "thingIds", "namespace") + .verify(); + } + + /** */ + @SuppressWarnings("ConstantConditions") + @Test + public void tryToGetRetrieveThingsLiveCommandForNull() { + assertThatExceptionOfType(NullPointerException.class) + .isThrownBy(() -> RetrieveThingsLiveCommandImpl.of(null)) + .withMessage(MessageFormat.format("The {0} must not be null!", "command")) + .withNoCause(); + } + + /** */ + @Test + public void tryToGetRetrieveThingsLiveCommandForCreateAttributeCommand() { + final Command commandMock = Mockito.mock(Command.class); + + assertThatExceptionOfType(ClassCastException.class) + .isThrownBy(() -> RetrieveThingsLiveCommandImpl.of(commandMock)) + .withMessageContaining(RetrieveThings.class.getName()) + .withNoCause(); + } + + /** */ + @Test + public void getRetrieveThingsLiveCommandReturnsExpected() { + assertThat(underTest) + .withType(retrieveThingTwinCommand.getType()) + .withDittoHeaders(retrieveThingTwinCommand.getDittoHeaders()) + .withId(retrieveThingTwinCommand.getThingEntityId()) + .withManifest(retrieveThingTwinCommand.getManifest()) + .withResourcePath(retrieveThingTwinCommand.getResourcePath()); + assertThat(underTest.getThingEntityIds()).isEqualTo(retrieveThingTwinCommand.getThingEntityIds()); + } + + /** */ + @Test + public void setDittoHeadersReturnsExpected() { + final DittoHeaders emptyDittoHeaders = DittoHeaders.empty(); + final RetrieveThingsLiveCommand newRetrieveThingsLiveCommand = + underTest.setDittoHeaders(emptyDittoHeaders); + + assertThat(newRetrieveThingsLiveCommand).withDittoHeaders(emptyDittoHeaders); + } + + /** */ + @Test + public void answerReturnsNotNull() { + Assertions.assertThat(underTest.answer()).isNotNull(); + } + + /** */ + @Test + public void toStringReturnsExpected() { + assertThat(underTest.toString()) + .contains(underTest.getClass().getSimpleName()) + .contains("command=") + .contains(retrieveThingTwinCommand.toString()) + .contains("namespace=null"); + } + +} From dbfb57db03c3a782e12f65ccba513a2e78ffcef5 Mon Sep 17 00:00:00 2001 From: Stefan Maute Date: Wed, 17 Feb 2021 13:36:40 +0100 Subject: [PATCH 2/3] remove test dependency for ditto-signals-commands-live; Signed-off-by: Stefan Maute --- java/pom.xml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/java/pom.xml b/java/pom.xml index 386e6510..e3211512 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -1040,13 +1040,6 @@ ${ditto.version} test - - org.eclipse.ditto - ditto-signals-commands-live - test-jar - ${ditto.version} - test - org.eclipse.ditto ditto-signals-events-base From 62414df25f7298383a1caeb18556fe9e0cacd4b4 Mon Sep 17 00:00:00 2001 From: Yannic Klem Date: Wed, 24 Feb 2021 16:01:44 +0100 Subject: [PATCH 3/3] remov unnecessary osgi stuff for ditto-signals-commands-live Signed-off-by: Yannic Klem --- java/src/main/assembly/assembly.xml | 1 - .../ditto/client/RunOSGiContainerIntegrationTest.java | 10 ---------- 2 files changed, 11 deletions(-) diff --git a/java/src/main/assembly/assembly.xml b/java/src/main/assembly/assembly.xml index 3a594278..26fa154d 100755 --- a/java/src/main/assembly/assembly.xml +++ b/java/src/main/assembly/assembly.xml @@ -48,7 +48,6 @@ org.eclipse.ditto:ditto-signals-commands-things org.eclipse.ditto:ditto-signals-commands-policies org.eclipse.ditto:ditto-signals-commands-messages - org.eclipse.ditto:ditto-signals-commands-live org.eclipse.ditto:ditto-signals-events-base org.eclipse.ditto:ditto-signals-events-things org.eclipse.ditto:ditto-signals-events-thingsearch diff --git a/java/src/test/java/org/eclipse/ditto/client/RunOSGiContainerIntegrationTest.java b/java/src/test/java/org/eclipse/ditto/client/RunOSGiContainerIntegrationTest.java index 722e253b..cec7a147 100755 --- a/java/src/test/java/org/eclipse/ditto/client/RunOSGiContainerIntegrationTest.java +++ b/java/src/test/java/org/eclipse/ditto/client/RunOSGiContainerIntegrationTest.java @@ -254,16 +254,6 @@ public void shouldBeAbleToResolveBundlesOfUsedDependencies() { checkBundleIsPresentInstalledAndActive(FrameworkUtil.getBundle(MessageCommand.class)); checkBundleIsPresentInstalledAndActive(FrameworkUtil.getBundle(MessageCommandResponse.class)); - // ditto-signals-commands-live: - LOG.info("Ensuring ditto-signals-commands-live is usable from OSGi.."); - checkBundleIsPresentInstalledAndActive(FrameworkUtil.getBundle(LiveCommandFactory.class)); - checkBundleIsPresentInstalledAndActive(FrameworkUtil.getBundle(QueryLiveCommandFactory.class)); - checkBundleIsPresentInstalledAndActive(FrameworkUtil.getBundle(RetrieveThingLiveCommand.class)); - checkBundleIsPresentInstalledAndActive(FrameworkUtil.getBundle(ModifyLiveCommandFactory.class)); - checkBundleIsPresentInstalledAndActive(FrameworkUtil.getBundle(CreateThingLiveCommand.class)); - checkBundleIsPresentInstalledAndActive(FrameworkUtil.getBundle(LiveCommand.class)); - checkBundleIsPresentInstalledAndActive(FrameworkUtil.getBundle(LiveEventFactory.class)); - // ditto-signals-events-base: LOG.info("Ensuring ditto-signals-events-base is usable from OSGi.."); checkBundleIsPresentInstalledAndActive(FrameworkUtil.getBundle(Event.class));