From 8e8d6a622427bfa92131bdbd4e5ce7ecf0199037 Mon Sep 17 00:00:00 2001 From: Andy Kruth Date: Tue, 11 Jun 2024 08:27:23 -0400 Subject: [PATCH 1/9] feat: STREAMP-12186: adding disable flags for entity status support --- .../core/services/ConsumerBindingService.java | 18 +-- .../core/services/ConsumerService.java | 18 +-- .../core/services/DomainService.java | 19 +-- .../core/services/InfrastructureService.java | 16 ++- .../core/services/ProcessBindingService.java | 18 +-- .../core/services/ProcessService.java | 19 +-- .../core/services/ProducerBindingService.java | 18 +-- .../core/services/ProducerService.java | 18 +-- .../core/services/SchemaService.java | 16 ++- .../core/services/StreamBindingService.java | 16 ++- .../core/services/StreamService.java | 19 +-- .../core/services/ZoneService.java | 17 +-- .../services/ConsumerBindingServiceTest.java | 14 +-- .../core/services/ConsumerServiceTest.java | 17 +-- .../core/services/DomainServiceTest.java | 26 ++--- .../services/InfrastructureServiceTest.java | 12 +- .../services/ProcessBindingServiceTest.java | 18 ++- .../core/services/ProcessServiceTest.java | 18 +-- .../services/ProducerBindingServiceTest.java | 14 +-- .../core/services/ProducerServiceTest.java | 18 +-- .../core/services/SchemaServiceTest.java | 14 +-- .../services/StreamBindingServiceTest.java | 12 +- .../core/services/StreamServiceTest.java | 47 ++++---- .../core/services/ZoneServiceTest.java | 12 +- .../impl/ConsumerBindingMutationImpl.java | 10 +- .../mutation/impl/ConsumerMutationImpl.java | 10 +- .../mutation/impl/DomainMutationImpl.java | 11 +- .../impl/InfrastructureMutationImpl.java | 11 +- .../impl/ProcessBindingMutationImpl.java | 13 ++- .../mutation/impl/ProcessMutationImpl.java | 13 ++- .../impl/ProducerBindingMutationImpl.java | 10 +- .../mutation/impl/ProducerMutationImpl.java | 10 +- .../mutation/impl/SchemaMutationImpl.java | 11 +- .../impl/StreamBindingMutationImpl.java | 10 +- .../mutation/impl/StreamMutationImpl.java | 10 +- .../mutation/impl/ZoneMutationImpl.java | 11 +- .../streamregistry/graphql/InputHelper.java | 28 +++++ .../impl/ConsumerBindingMutationImplTest.java | 40 ++++++- .../impl/ConsumerMutationImplTest.java | 40 ++++++- .../mutation/impl/DomainMutationImplTest.java | 97 ++++++++++++++++ .../impl/InfrastructureMutationImplTest.java | 98 ++++++++++++++++ .../impl/ProcessBindingMutationImplTest.java | 108 ++++++++++++++++++ .../impl/ProcessMutationImplTest.java | 107 +++++++++++++++++ .../impl/ProducerBindingMutationImplTest.java | 50 ++++++-- .../impl/ProducerMutationImplTest.java | 40 ++++++- .../mutation/impl/SchemaMutationImplTest.java | 98 ++++++++++++++++ .../impl/StreamBindingMutationImplTest.java | 46 +++++++- .../mutation/impl/StreamMutationImplTest.java | 40 ++++++- .../mutation/impl/ZoneMutationImplTest.java | 97 ++++++++++++++++ .../streamregistry/model/Consumer.java | 8 +- .../streamregistry/model/ConsumerBinding.java | 8 +- .../streamregistry/model/Domain.java | 8 +- .../streamregistry/model/Infrastructure.java | 8 +- .../streamregistry/model/Process.java | 17 ++- .../streamregistry/model/ProcessBinding.java | 17 ++- .../streamregistry/model/Producer.java | 8 +- .../streamregistry/model/ProducerBinding.java | 8 +- .../streamregistry/model/Schema.java | 8 +- .../streamregistry/model/Stream.java | 9 +- .../streamregistry/model/StreamBinding.java | 8 +- .../streamregistry/model/Zone.java | 8 +- .../streamregistry/repository/Repository.java | 10 +- .../repository/kafka/DefaultRepository.java | 36 ++++-- .../kafka/DefaultRepositoryTest.java | 47 ++++---- .../state/DefaultEntityView.java | 11 +- .../state/DefaultEntityViewUpdater.java | 11 +- .../streamregistry/state/EntityViews.java | 14 ++- .../state/DefaultEntityViewUpdaterTest.java | 42 ++++++- .../state/EntityViewUpdaterTest.java | 8 +- .../state/kafka/KafkaEventReceiver.java | 38 +++++- .../state/kafka/KafkaEventReceiverTest.java | 74 +++++++++++- 71 files changed, 1560 insertions(+), 299 deletions(-) create mode 100644 graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/InputHelper.java create mode 100644 graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/DomainMutationImplTest.java create mode 100644 graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/InfrastructureMutationImplTest.java create mode 100644 graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessBindingMutationImplTest.java create mode 100644 graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessMutationImplTest.java create mode 100644 graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/SchemaMutationImplTest.java create mode 100644 graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ZoneMutationImplTest.java diff --git a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ConsumerBindingService.java b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ConsumerBindingService.java index 6a2b3db97..543101960 100644 --- a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ConsumerBindingService.java +++ b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ConsumerBindingService.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2021 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,28 +54,32 @@ public Optional create(ConsumerBinding consumerBinding) throws } consumerBindingValidator.validateForCreate(consumerBinding); consumerBinding.setSpecification(handlerService.handleInsert(consumerBinding)); - return save(consumerBinding); + return saveSpecification(consumerBinding); } @PreAuthorize("hasPermission(#consumerBinding, 'UPDATE')") public Optional update(ConsumerBinding consumerBinding) throws ValidationException { val existing = consumerBindingView.get(consumerBinding.getKey()); - if (!existing.isPresent()) { + if (existing.isEmpty()) { throw new ValidationException("Can't update " + consumerBinding.getKey() + " because it doesn't exist"); } consumerBindingValidator.validateForUpdate(consumerBinding, existing.get()); consumerBinding.setSpecification(handlerService.handleUpdate(consumerBinding, existing.get())); - return save(consumerBinding); + return saveSpecification(consumerBinding); } @PreAuthorize("hasPermission(#consumerBinding, 'UPDATE_STATUS')") public Optional updateStatus(ConsumerBinding consumerBinding, Status status) { consumerBinding.setStatus(status); - return save(consumerBinding); + return saveStatus(consumerBinding); } - private Optional save(ConsumerBinding consumerBinding) { - return Optional.ofNullable(consumerBindingRepository.save(consumerBinding)); + private Optional saveSpecification(ConsumerBinding consumerBinding) { + return Optional.ofNullable(consumerBindingRepository.saveSpecification(consumerBinding)); + } + + private Optional saveStatus(ConsumerBinding consumerBinding) { + return Optional.ofNullable(consumerBindingRepository.saveStatus(consumerBinding)); } @PostAuthorize("returnObject.isPresent() ? hasPermission(returnObject, 'READ') : true") diff --git a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ConsumerService.java b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ConsumerService.java index 11f7f620b..aba269859 100644 --- a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ConsumerService.java +++ b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ConsumerService.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2022 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,28 +56,32 @@ public Optional create(Consumer consumer) throws ValidationException { } consumerValidator.validateForCreate(consumer); consumer.setSpecification(handlerService.handleInsert(consumer)); - return save(consumer); + return saveSpecification(consumer); } @PreAuthorize("hasPermission(#consumer, 'UPDATE')") public Optional update(Consumer consumer) throws ValidationException { val existing = consumerView.get(consumer.getKey()); - if (!existing.isPresent()) { + if (existing.isEmpty()) { throw new ValidationException("Can't update " + consumer.getKey().getName() + " because it doesn't exist"); } consumerValidator.validateForUpdate(consumer, existing.get()); consumer.setSpecification(handlerService.handleUpdate(consumer, existing.get())); - return save(consumer); + return saveSpecification(consumer); } @PreAuthorize("hasPermission(#consumer, 'UPDATE_STATUS')") public Optional updateStatus(Consumer consumer, Status status) { consumer.setStatus(status); - return save(consumer); + return saveStatus(consumer); } - private Optional save(Consumer consumer) { - return Optional.ofNullable(consumerRepository.save(consumer)); + private Optional saveSpecification(Consumer consumer) { + return Optional.ofNullable(consumerRepository.saveSpecification(consumer)); + } + + private Optional saveStatus(Consumer consumer) { + return Optional.ofNullable(consumerRepository.saveStatus(consumer)); } @PostAuthorize("returnObject.isPresent() ? hasPermission(returnObject, 'READ') : true") diff --git a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/DomainService.java b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/DomainService.java index 18946fa89..0e6dd7cd8 100644 --- a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/DomainService.java +++ b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/DomainService.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2022 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -68,30 +68,35 @@ public Optional create(Domain domain) throws ValidationException { } domainValidator.validateForCreate(domain); domain.setSpecification(handlerService.handleInsert(domain)); - return save(domain); + return saveSpecification(domain); } @PreAuthorize("hasPermission(#domain, 'UPDATE')") public Optional update(Domain domain) throws ValidationException { val existing = domainView.get(domain.getKey()); - if (!existing.isPresent()) { + if (existing.isEmpty()) { throw new ValidationException("Can't update " + domain.getKey().getName() + " because it doesn't exist"); } domainValidator.validateForUpdate(domain, existing.get()); domain.setSpecification(handlerService.handleUpdate(domain, existing.get())); - return save(domain); + return saveSpecification(domain); } @PreAuthorize("hasPermission(#domain, 'UPDATE_STATUS')") public Optional updateStatus(Domain domain, Status status) { domain.setStatus(status); - return save(domain); + return saveStatus(domain); } - private Optional save(Domain domain) { - return Optional.ofNullable(domainRepository.save(domain)); + private Optional saveSpecification(Domain domain) { + return Optional.ofNullable(domainRepository.saveSpecification(domain)); } + private Optional saveStatus(Domain domain) { + return Optional.ofNullable(domainRepository.saveStatus(domain)); + } + + @PostAuthorize("returnObject.isPresent() ? hasPermission(returnObject, 'READ') : true") public Optional get(DomainKey key) { return domainView.get(key); diff --git a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/InfrastructureService.java b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/InfrastructureService.java index 5be514d70..d096e2f8c 100644 --- a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/InfrastructureService.java +++ b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/InfrastructureService.java @@ -62,28 +62,32 @@ public Optional create(Infrastructure infrastructure) throws Val } infrastructureValidator.validateForCreate(infrastructure); infrastructure.setSpecification(handlerService.handleInsert(infrastructure)); - return save(infrastructure); + return saveSpecification(infrastructure); } @PreAuthorize("hasPermission(#infrastructure, 'UPDATE')") public Optional update(Infrastructure infrastructure) throws ValidationException { val existing = infrastructureView.get(infrastructure.getKey()); - if (!existing.isPresent()) { + if (existing.isEmpty()) { throw new ValidationException("Can't update " + infrastructure.getKey().getName() + " because it doesn't exist"); } infrastructureValidator.validateForUpdate(infrastructure, existing.get()); infrastructure.setSpecification(handlerService.handleUpdate(infrastructure, existing.get())); - return save(infrastructure); + return saveSpecification(infrastructure); } @PreAuthorize("hasPermission(#infrastructure, 'UPDATE_STATUS')") public Optional updateStatus(Infrastructure infrastructure, Status status) { infrastructure.setStatus(status); - return save(infrastructure); + return saveStatus(infrastructure); } - private Optional save(Infrastructure infrastructure) { - return Optional.ofNullable(infrastructureRepository.save(infrastructure)); + private Optional saveSpecification(Infrastructure infrastructure) { + return Optional.ofNullable(infrastructureRepository.saveSpecification(infrastructure)); + } + + private Optional saveStatus(Infrastructure infrastructure) { + return Optional.ofNullable(infrastructureRepository.saveStatus(infrastructure)); } @PostAuthorize("returnObject.isPresent() ? hasPermission(returnObject, 'READ') : true") diff --git a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessBindingService.java b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessBindingService.java index b5a2399ef..70c35c40a 100644 --- a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessBindingService.java +++ b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessBindingService.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2023 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,28 +53,32 @@ public Optional create(ProcessBinding processBinding) throws Val } processBindingValidator.validateForCreate(processBinding); processBinding.setSpecification(handlerService.handleInsert(processBinding)); - return save(processBinding); + return saveSpecification(processBinding); } @PreAuthorize("hasPermission(#processBinding, 'UPDATE')") public Optional update(ProcessBinding processBinding) throws ValidationException { val existing = processBindingView.get(processBinding.getKey()); - if (!existing.isPresent()) { + if (existing.isEmpty()) { throw new ValidationException("Can't update " + processBinding.getKey() + " because it doesn't exist"); } processBindingValidator.validateForUpdate(processBinding, existing.get()); processBinding.setSpecification(handlerService.handleUpdate(processBinding, existing.get())); - return save(processBinding); + return saveSpecification(processBinding); } @PreAuthorize("hasPermission(#processBinding, 'UPDATE_STATUS')") public Optional updateStatus(ProcessBinding processBinding, Status status) { processBinding.setStatus(status); - return save(processBinding); + return saveStatus(processBinding); } - private Optional save(ProcessBinding processBinding) { - return Optional.ofNullable(processBindingRepository.save(processBinding)); + private Optional saveSpecification(ProcessBinding processBinding) { + return Optional.ofNullable(processBindingRepository.saveSpecification(processBinding)); + } + + private Optional saveStatus(ProcessBinding processBinding) { + return Optional.ofNullable(processBindingRepository.saveStatus(processBinding)); } @PostAuthorize("returnObject.isPresent() ? hasPermission(returnObject, 'READ') : true") diff --git a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessService.java b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessService.java index 83d9b4a92..ea2b63288 100644 --- a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessService.java +++ b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessService.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2023 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -74,7 +74,7 @@ public Optional create(Process process) throws ValidationException { process.getOutputs().forEach(output -> producerService.canCreateProducer( buildProducer(process, zoneKey, output) ))); - return save(process); + return saveSpecification(process); } private Producer buildProducer(Process process, ZoneKey zoneKey, ProcessOutputStream output) { @@ -94,7 +94,7 @@ private Producer buildProducer(Process process, ZoneKey zoneKey, ProcessOutputSt @PreAuthorize("hasPermission(#process, 'UPDATE')") public Optional update(Process process) throws ValidationException { val existing = processView.get(process.getKey()); - if (!existing.isPresent()) { + if (existing.isEmpty()) { throw new ValidationException("Can't update " + process.getKey().getName() + " because it doesn't exist"); } processValidator.validateForUpdate(process, existing.get()); @@ -119,7 +119,7 @@ public Optional update(Process process) throws ValidationException { }); }); - return save(process); + return saveSpecification(process); } private Consumer buildConsumer(Process process, ZoneKey zoneKey, ProcessInputStream input) { @@ -139,13 +139,18 @@ private Consumer buildConsumer(Process process, ZoneKey zoneKey, ProcessInputStr @PreAuthorize("hasPermission(#process, 'UPDATE_STATUS')") public Optional updateStatus(Process process, Status status) { process.setStatus(status); - return save(process); + return saveStatus(process); } - private Optional save(Process process) { - return Optional.ofNullable(processRepository.save(process)); + private Optional saveSpecification(Process process) { + return Optional.ofNullable(processRepository.saveSpecification(process)); } + private Optional saveStatus(Process process) { + return Optional.ofNullable(processRepository.saveStatus(process)); + } + + @PostAuthorize("returnObject.isPresent() ? hasPermission(returnObject, 'READ') : true") public Optional get(ProcessKey key) { return processView.get(key); diff --git a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ProducerBindingService.java b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ProducerBindingService.java index 3721cd6ee..6435bdaaa 100644 --- a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ProducerBindingService.java +++ b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ProducerBindingService.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2021 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,28 +54,32 @@ public Optional create(ProducerBinding producerBinding) throws } producerBindingValidator.validateForCreate(producerBinding); producerBinding.setSpecification(handlerService.handleInsert(producerBinding)); - return save(producerBinding); + return saveSpecification(producerBinding); } @PreAuthorize("hasPermission(#producerBinding, 'UPDATE')") public Optional update(ProducerBinding producerBinding) throws ValidationException { val existing = producerBindingView.get(producerBinding.getKey()); - if (!existing.isPresent()) { + if (existing.isEmpty()) { throw new ValidationException("Can't update " + producerBinding.getKey() + " because it doesn't exist"); } producerBindingValidator.validateForUpdate(producerBinding, existing.get()); producerBinding.setSpecification(handlerService.handleUpdate(producerBinding, existing.get())); - return save(producerBinding); + return saveSpecification(producerBinding); } @PreAuthorize("hasPermission(#producerBinding, 'UPDATE_STATUS')") public Optional updateStatus(ProducerBinding producerBinding, Status status) { producerBinding.setStatus(status); - return save(producerBinding); + return saveStatus(producerBinding); } - private Optional save(ProducerBinding producerBinding) { - return Optional.ofNullable(producerBindingRepository.save(producerBinding)); + private Optional saveSpecification(ProducerBinding producerBinding) { + return Optional.ofNullable(producerBindingRepository.saveSpecification(producerBinding)); + } + + private Optional saveStatus(ProducerBinding producerBinding) { + return Optional.ofNullable(producerBindingRepository.saveStatus(producerBinding)); } @PostAuthorize("returnObject.isPresent() ? hasPermission(returnObject, 'READ') : true") diff --git a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ProducerService.java b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ProducerService.java index 651d7affd..9c33f77de 100644 --- a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ProducerService.java +++ b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ProducerService.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2022 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,28 +56,32 @@ public Optional create(Producer producer) throws ValidationException { } producerValidator.validateForCreate(producer); producer.setSpecification(handlerService.handleInsert(producer)); - return save(producer); + return saveSpecification(producer); } @PreAuthorize("hasPermission(#producer, 'UPDATE')") public Optional update(Producer producer) throws ValidationException { val existing = producerView.get(producer.getKey()); - if (!existing.isPresent()) { + if (existing.isEmpty()) { throw new ValidationException("Can't update " + producer.getKey().getName() + " because it doesn't exist"); } producerValidator.validateForUpdate(producer, existing.get()); producer.setSpecification(handlerService.handleUpdate(producer, existing.get())); - return save(producer); + return saveSpecification(producer); } @PreAuthorize("hasPermission(#producer, 'UPDATE_STATUS')") public Optional updateStatus(Producer producer, Status status) { producer.setStatus(status); - return save(producer); + return saveStatus(producer); } - private Optional save(Producer producer) { - return Optional.ofNullable(producerRepository.save(producer)); + private Optional saveSpecification(Producer producer) { + return Optional.ofNullable(producerRepository.saveSpecification(producer)); + } + + private Optional saveStatus(Producer producer) { + return Optional.ofNullable(producerRepository.saveStatus(producer)); } @PostAuthorize("returnObject.isPresent() ? hasPermission(returnObject, 'READ') : true") diff --git a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/SchemaService.java b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/SchemaService.java index 57baee789..1ce5327f2 100644 --- a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/SchemaService.java +++ b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/SchemaService.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2021 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,7 +53,7 @@ public Optional create(Schema schema) throws ValidationException { } schemaValidator.validateForCreate(schema); schema.setSpecification(handlerService.handleInsert(schema)); - return save(schema); + return saveSpecification(schema); } @PreAuthorize("hasPermission(#schema, 'UPDATE')") @@ -64,17 +64,21 @@ public Optional update(Schema schema) throws ValidationException { } schemaValidator.validateForUpdate(schema, existing.get()); schema.setSpecification(handlerService.handleUpdate(schema, existing.get())); - return save(schema); + return saveSpecification(schema); } @PreAuthorize("hasPermission(#schema, 'UPDATE_STATUS')") public Optional updateStatus(Schema schema, Status status) { schema.setStatus(status); - return save(schema); + return saveStatus(schema); } - private Optional save(Schema schema) { - return Optional.ofNullable(schemaRepository.save(schema)); + private Optional saveSpecification(Schema schema) { + return Optional.ofNullable(schemaRepository.saveSpecification(schema)); + } + + private Optional saveStatus(Schema schema) { + return Optional.ofNullable(schemaRepository.saveStatus(schema)); } @PostAuthorize("returnObject.isPresent() ? hasPermission(returnObject, 'READ') : true") diff --git a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/StreamBindingService.java b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/StreamBindingService.java index f49d8000d..4cd916f89 100644 --- a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/StreamBindingService.java +++ b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/StreamBindingService.java @@ -64,28 +64,32 @@ public Optional create(StreamBinding streamBinding) throws Valida } streamBindingValidator.validateForCreate(streamBinding); streamBinding.setSpecification(handlerService.handleInsert(streamBinding)); - return save(streamBinding); + return saveSpecification(streamBinding); } @PreAuthorize("hasPermission(#streamBinding, 'UPDATE')") public Optional update(StreamBinding streamBinding) throws ValidationException { val existing = streamBindingView.get(streamBinding.getKey()); - if (!existing.isPresent()) { + if (existing.isEmpty()) { throw new ValidationException("Can't update " + streamBinding.getKey() + " because it doesn't exist"); } streamBindingValidator.validateForUpdate(streamBinding, existing.get()); streamBinding.setSpecification(handlerService.handleUpdate(streamBinding, existing.get())); - return save(streamBinding); + return saveSpecification(streamBinding); } @PreAuthorize("hasPermission(#streamBinding, 'UPDATE_STATUS')") public Optional updateStatus(StreamBinding streamBinding, Status status) { streamBinding.setStatus(status); - return save(streamBinding); + return saveStatus(streamBinding); } - private Optional save(StreamBinding streamBinding) { - return Optional.ofNullable(streamBindingRepository.save(streamBinding)); + private Optional saveSpecification(StreamBinding streamBinding) { + return Optional.ofNullable(streamBindingRepository.saveSpecification(streamBinding)); + } + + private Optional saveStatus(StreamBinding streamBinding) { + return Optional.ofNullable(streamBindingRepository.saveStatus(streamBinding)); } @PostAuthorize("returnObject.isPresent() ? hasPermission(returnObject, 'READ') : true") diff --git a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/StreamService.java b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/StreamService.java index a3d446359..e94d9c70e 100644 --- a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/StreamService.java +++ b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/StreamService.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2023 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -73,30 +73,33 @@ public Optional create(Stream stream) throws ValidationException { } streamValidator.validateForCreate(stream); stream.setSpecification(handlerService.handleInsert(stream)); - return save(stream); + return saveSpecification(stream); } @PreAuthorize("hasPermission(#stream, 'UPDATE')") public Optional update(Stream stream) throws ValidationException { val existing = streamView.get(stream.getKey()); - if (!existing.isPresent()) { + if (existing.isEmpty()) { throw new ValidationException("Can't update " + stream.getKey() + " because it doesn't exist"); } stream.setSchemaKey(existing.get().getSchemaKey()); streamValidator.validateForUpdate(stream, existing.get()); stream.setSpecification(handlerService.handleUpdate(stream, existing.get())); - return save(stream); + return saveSpecification(stream); } @PreAuthorize("hasPermission(#stream, 'UPDATE_STATUS')") public Optional updateStatus(Stream stream, Status status) { stream.setStatus(status); - return save(stream); + return saveStatus(stream); } - private Optional save(Stream stream) { - stream = streamRepository.save(stream); - return Optional.ofNullable(stream); + private Optional saveSpecification(Stream stream) { + return Optional.ofNullable(streamRepository.saveSpecification(stream)); + } + + private Optional saveStatus(Stream stream) { + return Optional.ofNullable(streamRepository.saveStatus(stream)); } @PostAuthorize("returnObject.isPresent() ? hasPermission(returnObject, 'READ') : true") diff --git a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ZoneService.java b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ZoneService.java index 511202227..3e1734168 100644 --- a/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ZoneService.java +++ b/core/src/main/java/com/expediagroup/streamplatform/streamregistry/core/services/ZoneService.java @@ -66,29 +66,32 @@ public Optional create(Zone zone) throws ValidationException { } zoneValidator.validateForCreate(zone); zone.setSpecification(handlerService.handleInsert(zone)); - return save(zone); + return saveSpecification(zone); } @PreAuthorize("hasPermission(#zone, 'UPDATE')") public Optional update(Zone zone) throws ValidationException { val existing = zoneView.get(zone.getKey()); - if (!existing.isPresent()) { + if (existing.isEmpty()) { throw new ValidationException("Can't update " + zone.getKey().getName() + " because it doesn't exist"); } zoneValidator.validateForUpdate(zone, existing.get()); zone.setSpecification(handlerService.handleUpdate(zone, existing.get())); - return save(zone); + return saveSpecification(zone); } @PreAuthorize("hasPermission(#zone, 'UPDATE_STATUS')") public Optional updateStatus(Zone zone, Status status) { zone.setStatus(status); - return save(zone); + return saveStatus(zone); } - private Optional save(Zone zone) { - zone = zoneRepository.save(zone); - return Optional.ofNullable(zone); + private Optional saveSpecification(Zone zone) { + return Optional.ofNullable(zoneRepository.saveSpecification(zone)); + } + + private Optional saveStatus(Zone zone) { + return Optional.ofNullable(zoneRepository.saveStatus(zone)); } @PostAuthorize("returnObject.isPresent() ? hasPermission(returnObject, 'READ') : true") diff --git a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ConsumerBindingServiceTest.java b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ConsumerBindingServiceTest.java index e75a2f9dc..2296553ac 100644 --- a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ConsumerBindingServiceTest.java +++ b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ConsumerBindingServiceTest.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2021 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -73,7 +73,7 @@ public void create() { doNothing().when(consumerBindingValidator).validateForCreate(entity); when(handlerService.handleInsert(entity)).thenReturn(specification); - when(consumerBindingRepository.save(entity)).thenReturn(entity); + when(consumerBindingRepository.saveSpecification(entity)).thenReturn(entity); consumerBindingService.create(entity); @@ -81,7 +81,7 @@ public void create() { verify(consumerBindingRepository).findById(key); verify(consumerBindingValidator).validateForCreate(entity); verify(handlerService).handleInsert(entity); - verify(consumerBindingRepository).save(entity); + verify(consumerBindingRepository).saveSpecification(entity); } @Test @@ -98,7 +98,7 @@ public void update() { doNothing().when(consumerBindingValidator).validateForUpdate(entity, existingEntity); when(handlerService.handleUpdate(entity, existingEntity)).thenReturn(specification); - when(consumerBindingRepository.save(entity)).thenReturn(entity); + when(consumerBindingRepository.saveSpecification(entity)).thenReturn(entity); consumerBindingService.update(entity); @@ -106,7 +106,7 @@ public void update() { verify(consumerBindingRepository).findById(key); verify(consumerBindingValidator).validateForUpdate(entity, existingEntity); verify(handlerService).handleUpdate(entity, existingEntity); - verify(consumerBindingRepository).save(entity); + verify(consumerBindingRepository).saveSpecification(entity); } @Test @@ -114,11 +114,11 @@ public void updateStatus() { final Status status = mock(Status.class); final ConsumerBinding entity = mock(ConsumerBinding.class); - when(consumerBindingRepository.save(entity)).thenReturn(entity); + when(consumerBindingRepository.saveStatus(entity)).thenReturn(entity); consumerBindingService.updateStatus(entity, status); - verify(consumerBindingRepository).save(entity); + verify(consumerBindingRepository).saveStatus(entity); } @Test diff --git a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ConsumerServiceTest.java b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ConsumerServiceTest.java index 24a959a2f..aa3237f85 100644 --- a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ConsumerServiceTest.java +++ b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ConsumerServiceTest.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2021 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; +import java.util.List; import java.util.Optional; import org.junit.Before; @@ -85,7 +86,7 @@ public void create() { doNothing().when(consumerValidator).validateForCreate(entity); when(handlerService.handleInsert(entity)).thenReturn(specification); - when(consumerRepository.save(entity)).thenReturn(entity); + when(consumerRepository.saveSpecification(entity)).thenReturn(entity); consumerService.create(entity); @@ -93,7 +94,7 @@ public void create() { verify(consumerRepository).findById(key); verify(consumerValidator).validateForCreate(entity); verify(handlerService).handleInsert(entity); - verify(consumerRepository).save(entity); + verify(consumerRepository).saveSpecification(entity); } @Test @@ -110,7 +111,7 @@ public void update() { doNothing().when(consumerValidator).validateForUpdate(entity, existingEntity); when(handlerService.handleUpdate(entity, existingEntity)).thenReturn(specification); - when(consumerRepository.save(entity)).thenReturn(entity); + when(consumerRepository.saveSpecification(entity)).thenReturn(entity); consumerService.update(entity); @@ -118,7 +119,7 @@ public void update() { verify(consumerRepository).findById(key); verify(consumerValidator).validateForUpdate(entity, existingEntity); verify(handlerService).handleUpdate(entity, existingEntity); - verify(consumerRepository).save(entity); + verify(consumerRepository).saveSpecification(entity); } @Test @@ -126,11 +127,11 @@ public void updateStatus() { final Status status = mock(Status.class); final Consumer entity = mock(Consumer.class); - when(consumerRepository.save(entity)).thenReturn(entity); + when(consumerRepository.saveStatus(entity)).thenReturn(entity); consumerService.updateStatus(entity, status); - verify(consumerRepository).save(entity); + verify(consumerRepository).saveStatus(entity); } @Test @@ -144,7 +145,7 @@ public void delete() { when(bindingKey.getConsumerKey()).thenReturn(key); when(binding.getKey()).thenReturn(bindingKey); - when(consumerBindingRepository.findAll()).thenReturn(asList(binding)); + when(consumerBindingRepository.findAll()).thenReturn(List.of(binding)); consumerService.delete(entity); diff --git a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/DomainServiceTest.java b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/DomainServiceTest.java index a0ed8caed..44d63d517 100644 --- a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/DomainServiceTest.java +++ b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/DomainServiceTest.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2022 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package com.expediagroup.streamplatform.streamregistry.core.services; -import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; @@ -24,6 +23,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.util.List; import java.util.Optional; import org.junit.Before; @@ -117,7 +117,7 @@ public void create() { Mockito.doNothing().when(domainValidator).validateForCreate(entity); Mockito.when(handlerService.handleInsert(entity)).thenReturn(specification); - Mockito.when(domainRepository.save(any())).thenReturn(entity); + Mockito.when(domainRepository.saveSpecification(any())).thenReturn(entity); when(entity.getKey()).thenReturn(key); domainService.create(entity); @@ -126,7 +126,7 @@ public void create() { verify(domainRepository).findById(key); verify(domainValidator).validateForCreate(entity); verify(handlerService).handleInsert(entity); - verify(domainRepository).save(entity); + verify(domainRepository).saveSpecification(entity); } @Test @@ -142,7 +142,7 @@ public void update() { doNothing().when(domainValidator).validateForUpdate(entity, existingEntity); when(handlerService.handleUpdate(entity, existingEntity)).thenReturn(specification); - when(domainRepository.save(entity)).thenReturn(entity); + when(domainRepository.saveSpecification(entity)).thenReturn(entity); domainService.update(entity); @@ -150,7 +150,7 @@ public void update() { verify(domainRepository).findById(key); verify(domainValidator).validateForUpdate(entity, existingEntity); verify(handlerService).handleUpdate(entity, existingEntity); - verify(domainRepository).save(entity); + verify(domainRepository).saveSpecification(entity); } @Test @@ -158,11 +158,11 @@ public void updateStatus() { final Domain entity = mock(Domain.class); final Status status = mock(Status.class); - when(domainRepository.save(entity)).thenReturn(entity); + when(domainRepository.saveStatus(entity)).thenReturn(entity); domainService.updateStatus(entity, status); - verify(domainRepository).save(entity); + verify(domainRepository).saveStatus(entity); } @Test @@ -190,7 +190,7 @@ public void deleteDomainUsedInProcess() { final Process process = mock(Process.class); when(processKey.getDomainKey()).thenReturn(key); when(process.getKey()).thenReturn(processKey); - when(processRepository.findAll()).thenReturn(asList(process)); + when(processRepository.findAll()).thenReturn(List.of(process)); IllegalStateException ex = Assertions.assertThrows(IllegalStateException.class, () -> { domainService.delete(entity); }); @@ -209,7 +209,7 @@ public void deleteDomainUsedInStream() { when(stream.getKey()).thenReturn(streamkey); when(processRepository.findAll()).thenReturn(emptyList()); - when(streamRepository.findAll()).thenReturn(asList(stream)); + when(streamRepository.findAll()).thenReturn(List.of(stream)); IllegalStateException ex = Assertions.assertThrows(IllegalStateException.class, () -> { domainService.delete(entity); }); @@ -229,7 +229,7 @@ public void deleteDomainUsedInSchema() { when(processRepository.findAll()).thenReturn(emptyList()); when(streamRepository.findAll()).thenReturn(emptyList()); - when(schemaRepository.findAll()).thenReturn(asList(schema)); + when(schemaRepository.findAll()).thenReturn(List.of(schema)); IllegalStateException ex = Assertions.assertThrows(IllegalStateException.class, () -> { domainService.delete(entity); }); @@ -252,7 +252,7 @@ public void deleteDomainUsedInConsumer() { when(processRepository.findAll()).thenReturn(emptyList()); when(streamRepository.findAll()).thenReturn(emptyList()); when(producerRepository.findAll()).thenReturn(emptyList()); - when(consumerRepository.findAll()).thenReturn(asList(consumer)); + when(consumerRepository.findAll()).thenReturn(List.of(consumer)); IllegalStateException ex = Assertions.assertThrows(IllegalStateException.class, () -> { domainService.delete(entity); }); @@ -274,7 +274,7 @@ public void deleteDomainUsedInProducer() { when(processRepository.findAll()).thenReturn(emptyList()); when(streamRepository.findAll()).thenReturn(emptyList()); - when(producerRepository.findAll()).thenReturn(asList(producer)); + when(producerRepository.findAll()).thenReturn(List.of(producer)); IllegalStateException ex = Assertions.assertThrows(IllegalStateException.class, () -> { domainService.delete(entity); }); diff --git a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/InfrastructureServiceTest.java b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/InfrastructureServiceTest.java index 193152853..622ef2cb4 100644 --- a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/InfrastructureServiceTest.java +++ b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/InfrastructureServiceTest.java @@ -111,7 +111,7 @@ public void create() { Mockito.doNothing().when(infrastructureValidator).validateForCreate(entity); Mockito.when(handlerService.handleInsert(entity)).thenReturn(specification); - Mockito.when(infrastructureRepository.save(any())).thenReturn(entity); + Mockito.when(infrastructureRepository.saveSpecification(any())).thenReturn(entity); when(entity.getKey()).thenReturn(key); infrastructureService.create(entity); @@ -120,7 +120,7 @@ public void create() { verify(infrastructureRepository).findById(key); verify(infrastructureValidator).validateForCreate(entity); verify(handlerService).handleInsert(entity); - verify(infrastructureRepository).save(entity); + verify(infrastructureRepository).saveSpecification(entity); } @Test @@ -136,7 +136,7 @@ public void update() { doNothing().when(infrastructureValidator).validateForUpdate(entity, existingEntity); when(handlerService.handleUpdate(entity, existingEntity)).thenReturn(specification); - when(infrastructureRepository.save(entity)).thenReturn(entity); + when(infrastructureRepository.saveSpecification(entity)).thenReturn(entity); infrastructureService.update(entity); @@ -144,7 +144,7 @@ public void update() { verify(infrastructureRepository).findById(key); verify(infrastructureValidator).validateForUpdate(entity, existingEntity); verify(handlerService).handleUpdate(entity, existingEntity); - verify(infrastructureRepository).save(entity); + verify(infrastructureRepository).saveSpecification(entity); } @Test @@ -152,11 +152,11 @@ public void updateStatus() { final Infrastructure entity = mock(Infrastructure.class); final Status status = mock(Status.class); - when(infrastructureRepository.save(entity)).thenReturn(entity); + when(infrastructureRepository.saveStatus(entity)).thenReturn(entity); infrastructureService.updateStatus(entity, status); - verify(infrastructureRepository).save(entity); + verify(infrastructureRepository).saveStatus(entity); } @Test diff --git a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessBindingServiceTest.java b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessBindingServiceTest.java index a7e42e8bc..06ec1dae4 100644 --- a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessBindingServiceTest.java +++ b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessBindingServiceTest.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2023 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,8 +24,6 @@ import java.util.Optional; -import com.fasterxml.jackson.databind.ObjectMapper; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -56,8 +54,6 @@ public class ProcessBindingServiceTest { private ProcessBindingService processBindingService; - private ObjectMapper objectMapper = new ObjectMapper(); - @Before public void before() { processBindingService = new ProcessBindingService( @@ -80,7 +76,7 @@ public void create() { doNothing().when(processBindingValidator).validateForCreate(entity); when(handlerService.handleInsert(entity)).thenReturn(specification); - when(processBindingRepository.save(entity)).thenReturn(entity); + when(processBindingRepository.saveSpecification(entity)).thenReturn(entity); processBindingService.create(entity); @@ -88,7 +84,7 @@ public void create() { verify(processBindingRepository).findById(key); verify(processBindingValidator).validateForCreate(entity); verify(handlerService).handleInsert(entity); - verify(processBindingRepository).save(entity); + verify(processBindingRepository).saveSpecification(entity); } @Test @@ -105,7 +101,7 @@ public void update() { doNothing().when(processBindingValidator).validateForUpdate(entity, existingEntity); when(handlerService.handleUpdate(entity, existingEntity)).thenReturn(specification); - when(processBindingRepository.save(entity)).thenReturn(entity); + when(processBindingRepository.saveSpecification(entity)).thenReturn(entity); processBindingService.update(entity); @@ -113,7 +109,7 @@ public void update() { verify(processBindingRepository).findById(key); verify(processBindingValidator).validateForUpdate(entity, existingEntity); verify(handlerService).handleUpdate(entity, existingEntity); - verify(processBindingRepository).save(entity); + verify(processBindingRepository).saveSpecification(entity); } @Test @@ -121,11 +117,11 @@ public void updateStatus() { final Status status = mock(Status.class); final ProcessBinding entity = mock(ProcessBinding.class); - when(processBindingRepository.save(entity)).thenReturn(entity); + when(processBindingRepository.saveStatus(entity)).thenReturn(entity); processBindingService.updateStatus(entity, status); - verify(processBindingRepository).save(entity); + verify(processBindingRepository).saveStatus(entity); } @Test diff --git a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessServiceTest.java b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessServiceTest.java index 28685d5e6..d2250ef6b 100644 --- a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessServiceTest.java +++ b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ProcessServiceTest.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2023 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -111,14 +111,14 @@ public void create() { when(processRepository.findById(entity.getKey())).thenReturn(empty()); doNothing().when(processValidator).validateForCreate(entity); when(handlerService.handleInsert(entity)).thenReturn(specification); - when(processRepository.save(entity)).thenReturn(entity); + when(processRepository.saveSpecification(entity)).thenReturn(entity); processService.create(entity); verify(processRepository).findById(entity.getKey()); verify(processValidator).validateForCreate(entity); verify(handlerService).handleInsert(entity); - verify(processRepository).save(entity); + verify(processRepository).saveSpecification(entity); } @Test(expected = ValidationException.class) @@ -153,7 +153,7 @@ public void updateNoInputOutputChanges() { when(processRepository.findById(existing.getKey())).thenReturn(Optional.of(existing)); doNothing().when(processValidator).validateForUpdate(newEntity, existing); when(handlerService.handleUpdate(newEntity, existing)).thenReturn(specification); - when(processRepository.save(newEntity)).thenReturn(newEntity); + when(processRepository.saveSpecification(newEntity)).thenReturn(newEntity); processService.update(newEntity); @@ -162,7 +162,7 @@ public void updateNoInputOutputChanges() { verify(handlerService).handleUpdate(newEntity, existing); verify(consumerService, never()).canCreateConsumer(any(Consumer.class)); verify(producerService, never()).canCreateProducer(any(Producer.class)); - verify(processRepository).save(newEntity); + verify(processRepository).saveSpecification(newEntity); } @Test @@ -179,7 +179,7 @@ public void updateWithInputOutputChanges() { when(processRepository.findById(existing.getKey())).thenReturn(Optional.of(existing)); doNothing().when(processValidator).validateForUpdate(newEntity, existing); when(handlerService.handleUpdate(newEntity, existing)).thenReturn(specification); - when(processRepository.save(newEntity)).thenReturn(newEntity); + when(processRepository.saveSpecification(newEntity)).thenReturn(newEntity); processService.update(newEntity); @@ -188,7 +188,7 @@ public void updateWithInputOutputChanges() { verify(handlerService).handleUpdate(newEntity, existing); verify(consumerService, times(1)).canCreateConsumer(any(Consumer.class)); verify(producerService, times(1)).canCreateProducer(any(Producer.class)); - verify(processRepository).save(newEntity); + verify(processRepository).saveSpecification(newEntity); } @Test(expected = ValidationException.class) @@ -246,11 +246,11 @@ public void updateStatus() { final Status status = mock(Status.class); final Process entity = mock(Process.class); - when(processRepository.save(entity)).thenReturn(entity); + when(processRepository.saveStatus(entity)).thenReturn(entity); processService.updateStatus(entity, status); - verify(processRepository).save(entity); + verify(processRepository).saveStatus(entity); } @Test diff --git a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ProducerBindingServiceTest.java b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ProducerBindingServiceTest.java index 8f184e246..7c9060f79 100644 --- a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ProducerBindingServiceTest.java +++ b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ProducerBindingServiceTest.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2021 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -73,7 +73,7 @@ public void create() { doNothing().when(producerBindingValidator).validateForCreate(entity); when(handlerService.handleInsert(entity)).thenReturn(specification); - when(producerBindingRepository.save(entity)).thenReturn(entity); + when(producerBindingRepository.saveSpecification(entity)).thenReturn(entity); producerBindingService.create(entity); @@ -81,7 +81,7 @@ public void create() { verify(producerBindingRepository).findById(key); verify(producerBindingValidator).validateForCreate(entity); verify(handlerService).handleInsert(entity); - verify(producerBindingRepository).save(entity); + verify(producerBindingRepository).saveSpecification(entity); } @Test @@ -98,7 +98,7 @@ public void update() { doNothing().when(producerBindingValidator).validateForUpdate(entity, existingEntity); when(handlerService.handleUpdate(entity, existingEntity)).thenReturn(specification); - when(producerBindingRepository.save(entity)).thenReturn(entity); + when(producerBindingRepository.saveSpecification(entity)).thenReturn(entity); producerBindingService.update(entity); @@ -106,7 +106,7 @@ public void update() { verify(producerBindingRepository).findById(key); verify(producerBindingValidator).validateForUpdate(entity, existingEntity); verify(handlerService).handleUpdate(entity, existingEntity); - verify(producerBindingRepository).save(entity); + verify(producerBindingRepository).saveSpecification(entity); } @Test @@ -114,11 +114,11 @@ public void updateStatus() { final Status status = mock(Status.class); final ProducerBinding entity = mock(ProducerBinding.class); - when(producerBindingRepository.save(entity)).thenReturn(entity); + when(producerBindingRepository.saveStatus(entity)).thenReturn(entity); producerBindingService.updateStatus(entity, status); - verify(producerBindingRepository).save(entity); + verify(producerBindingRepository).saveStatus(entity); } @Test diff --git a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ProducerServiceTest.java b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ProducerServiceTest.java index b2ed2b487..310427376 100644 --- a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ProducerServiceTest.java +++ b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ProducerServiceTest.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2021 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; +import java.util.List; import java.util.Optional; import org.junit.Before; @@ -85,7 +86,7 @@ public void create() { doNothing().when(producerValidator).validateForCreate(entity); when(handlerService.handleInsert(entity)).thenReturn(specification); - when(producerRepository.save(entity)).thenReturn(entity); + when(producerRepository.saveSpecification(entity)).thenReturn(entity); producerService.create(entity); @@ -93,7 +94,7 @@ public void create() { verify(producerRepository).findById(key); verify(producerValidator).validateForCreate(entity); verify(handlerService).handleInsert(entity); - verify(producerRepository).save(entity); + verify(producerRepository).saveSpecification(entity); } @Test @@ -110,7 +111,7 @@ public void update() { doNothing().when(producerValidator).validateForUpdate(entity, existingEntity); when(handlerService.handleUpdate(entity, existingEntity)).thenReturn(specification); - when(producerRepository.save(entity)).thenReturn(entity); + when(producerRepository.saveSpecification(entity)).thenReturn(entity); producerService.update(entity); @@ -118,7 +119,7 @@ public void update() { verify(producerRepository).findById(key); verify(producerValidator).validateForUpdate(entity, existingEntity); verify(handlerService).handleUpdate(entity, existingEntity); - verify(producerRepository).save(entity); + verify(producerRepository).saveSpecification(entity); } @Test @@ -126,11 +127,11 @@ public void updateStatus() { final Status status = mock(Status.class); final Producer entity = mock(Producer.class); - when(producerRepository.save(entity)).thenReturn(entity); + when(producerRepository.saveStatus(entity)).thenReturn(entity); producerService.updateStatus(entity, status); - verify(producerRepository).save(entity); + verify(producerRepository).saveStatus(entity); } @Test @@ -144,7 +145,7 @@ public void delete() { when(bindingKey.getProducerKey()).thenReturn(key); when(binding.getKey()).thenReturn(bindingKey); - when(producerBindingRepository.findAll()).thenReturn(asList(binding)); + when(producerBindingRepository.findAll()).thenReturn(List.of(binding)); producerService.delete(entity); @@ -154,7 +155,6 @@ public void delete() { @Test public void delete_noChildren() { - final ProducerKey key = mock(ProducerKey.class); final Producer entity = mock(Producer.class); when(producerBindingRepository.findAll()).thenReturn(emptyList()); diff --git a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/SchemaServiceTest.java b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/SchemaServiceTest.java index bfe2aa1f1..f1289d9a8 100644 --- a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/SchemaServiceTest.java +++ b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/SchemaServiceTest.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2021 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -72,14 +72,14 @@ public void create() { doNothing().when(schemaValidator).validateForCreate(entity); when(handlerService.handleInsert(entity)).thenReturn(specification); - when(schemaRepository.save(entity)).thenReturn(entity); + when(schemaRepository.saveSpecification(entity)).thenReturn(entity); schemaService.create(entity); verify(entity).getKey(); verify(schemaValidator).validateForCreate(entity); verify(handlerService).handleInsert(entity); - verify(schemaRepository).save(entity); + verify(schemaRepository).saveSpecification(entity); } @Test @@ -95,7 +95,7 @@ public void update() { doNothing().when(schemaValidator).validateForUpdate(entity, existingEntity); when(handlerService.handleUpdate(entity, existingEntity)).thenReturn(specification); - when(schemaRepository.save(entity)).thenReturn(entity); + when(schemaRepository.saveSpecification(entity)).thenReturn(entity); schemaService.update(entity); @@ -103,7 +103,7 @@ public void update() { verify(schemaRepository).findById(key); verify(schemaValidator).validateForUpdate(entity, existingEntity); verify(handlerService).handleUpdate(entity, existingEntity); - verify(schemaRepository).save(entity); + verify(schemaRepository).saveSpecification(entity); } @Test @@ -111,11 +111,11 @@ public void updateStatus() { final Schema entity = mock(Schema.class); final Status status = mock(Status.class); - when(schemaRepository.save(entity)).thenReturn(entity); + when(schemaRepository.saveStatus(entity)).thenReturn(entity); schemaService.updateStatus(entity, status); - verify(schemaRepository).save(entity); + verify(schemaRepository).saveStatus(entity); } @Test diff --git a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/StreamBindingServiceTest.java b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/StreamBindingServiceTest.java index cab958ab1..c0e7615fd 100644 --- a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/StreamBindingServiceTest.java +++ b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/StreamBindingServiceTest.java @@ -108,7 +108,7 @@ public void create() { doNothing().when(streamBindingValidator).validateForCreate(entity); when(handlerService.handleInsert(entity)).thenReturn(specification); - when(streamBindingRepository.save(entity)).thenReturn(entity); + when(streamBindingRepository.saveSpecification(entity)).thenReturn(entity); streamBindingService.create(entity); @@ -116,7 +116,7 @@ public void create() { verify(streamBindingRepository).findById(key); verify(streamBindingValidator).validateForCreate(entity); verify(handlerService).handleInsert(entity); - verify(streamBindingRepository).save(entity); + verify(streamBindingRepository).saveSpecification(entity); } @Test @@ -133,7 +133,7 @@ public void update() { doNothing().when(streamBindingValidator).validateForUpdate(entity, existingEntity); when(handlerService.handleUpdate(entity, existingEntity)).thenReturn(specification); - when(streamBindingRepository.save(entity)).thenReturn(entity); + when(streamBindingRepository.saveSpecification(entity)).thenReturn(entity); streamBindingService.update(entity); @@ -141,7 +141,7 @@ public void update() { verify(streamBindingRepository).findById(key); verify(streamBindingValidator).validateForUpdate(entity, existingEntity); verify(handlerService).handleUpdate(entity, existingEntity); - verify(streamBindingRepository).save(entity); + verify(streamBindingRepository).saveSpecification(entity); } @Test @@ -149,11 +149,11 @@ public void updateStatus() { final Status status = mock(Status.class); final StreamBinding entity = mock(StreamBinding.class); - when(streamBindingRepository.save(entity)).thenReturn(entity); + when(streamBindingRepository.saveStatus(entity)).thenReturn(entity); streamBindingService.updateStatus(entity, status); - verify(streamBindingRepository).save(entity); + verify(streamBindingRepository).saveStatus(entity); } @Test diff --git a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/StreamServiceTest.java b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/StreamServiceTest.java index 0a1e1bc1b..041358f09 100644 --- a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/StreamServiceTest.java +++ b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/StreamServiceTest.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2022 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.util.List; import java.util.Optional; import com.fasterxml.jackson.databind.ObjectMapper; @@ -145,7 +146,7 @@ public void create() { doNothing().when(streamValidator).validateForCreate(entity); when(handlerService.handleInsert(entity)).thenReturn(specification); - when(streamRepository.save(entity)).thenReturn(entity); + when(streamRepository.saveSpecification(entity)).thenReturn(entity); streamService.create(entity); @@ -153,7 +154,7 @@ public void create() { verify(streamRepository).findById(key); verify(streamValidator).validateForCreate(entity); verify(handlerService).handleInsert(entity); - verify(streamRepository).save(entity); + verify(streamRepository).saveSpecification(entity); } @Test @@ -170,7 +171,7 @@ public void update() { doNothing().when(streamValidator).validateForUpdate(entity, existingEntity); when(handlerService.handleUpdate(entity, existingEntity)).thenReturn(specification); - when(streamRepository.save(entity)).thenReturn(entity); + when(streamRepository.saveSpecification(entity)).thenReturn(entity); streamService.update(entity); @@ -178,7 +179,7 @@ public void update() { verify(streamRepository).findById(key); verify(streamValidator).validateForUpdate(entity, existingEntity); verify(handlerService).handleUpdate(entity, existingEntity); - verify(streamRepository).save(entity); + verify(streamRepository).saveSpecification(entity); } @Test @@ -186,11 +187,11 @@ public void updateStatus() { final Status status = mock(Status.class); final Stream entity = mock(Stream.class); - when(streamRepository.save(entity)).thenReturn(entity); + when(streamRepository.saveStatus(entity)).thenReturn(entity); streamService.updateStatus(entity, status); - verify(streamRepository).save(entity); + verify(streamRepository).saveStatus(entity); } @Test @@ -219,11 +220,11 @@ public void delete() { when(producer.getKey()).thenReturn(producerKey); when(processRepository.findAll()).thenReturn(emptyList()); - when(streamBindingRepository.findAll()).thenReturn(asList(binding)); - when(producerRepository.findAll()).thenReturn(asList(producer)); - when(consumerRepository.findAll()).thenReturn(asList(consumer)); + when(streamBindingRepository.findAll()).thenReturn(List.of(binding)); + when(producerRepository.findAll()).thenReturn(List.of(producer)); + when(consumerRepository.findAll()).thenReturn(List.of(consumer)); when(schemaRepository.findById(any())).thenReturn(Optional.of(schema)); - when(streamRepository.findAll()).thenReturn(asList(entity)); + when(streamRepository.findAll()).thenReturn(List.of(entity)); streamService.delete(entity); @@ -266,9 +267,9 @@ public void delete_preserveSharedSchema() { when(producer.getKey()).thenReturn(producerKey); when(processRepository.findAll()).thenReturn(emptyList()); - when(streamBindingRepository.findAll()).thenReturn(asList(binding)); - when(producerRepository.findAll()).thenReturn(asList(producer)); - when(consumerRepository.findAll()).thenReturn(asList(consumer)); + when(streamBindingRepository.findAll()).thenReturn(List.of(binding)); + when(producerRepository.findAll()).thenReturn(List.of(producer)); + when(consumerRepository.findAll()).thenReturn(List.of(consumer)); when(streamRepository.findAll()).thenReturn(asList(entity, otherStream)); streamService.delete(entity); @@ -347,7 +348,7 @@ public void delete_multi() { when(producerRepository.findAll()).thenReturn(asList(producer1, producer2)); when(consumerRepository.findAll()).thenReturn(asList(consumer1, consumer2)); when(schemaRepository.findById(any())).thenReturn(Optional.of(schema)); - when(streamRepository.findAll()).thenReturn(asList(entity)); + when(streamRepository.findAll()).thenReturn(List.of(entity)); streamService.delete(entity); @@ -371,20 +372,20 @@ public void delete_singleStreamProcesses() { final StreamKey otherStreamKey = mock(StreamKey.class); final Process otherProcess = mock(Process.class); - when(otherProcess.getInputs()).thenReturn(asList(new ProcessInputStream(otherStreamKey, new ObjectMapper().createObjectNode()))); + when(otherProcess.getInputs()).thenReturn(List.of(new ProcessInputStream(otherStreamKey, new ObjectMapper().createObjectNode()))); when(otherProcess.getOutputs()).thenReturn(emptyList()); final Process inputProcess = mock(Process.class); - when(inputProcess.getInputs()).thenReturn(asList(new ProcessInputStream(streamKey, new ObjectMapper().createObjectNode()))); + when(inputProcess.getInputs()).thenReturn(List.of(new ProcessInputStream(streamKey, new ObjectMapper().createObjectNode()))); when(inputProcess.getOutputs()).thenReturn(emptyList()); final Process outputProcess = mock(Process.class); when(outputProcess.getInputs()).thenReturn(emptyList()); - when(outputProcess.getOutputs()).thenReturn(asList(new ProcessOutputStream(streamKey, new ObjectMapper().createObjectNode()))); + when(outputProcess.getOutputs()).thenReturn(List.of(new ProcessOutputStream(streamKey, new ObjectMapper().createObjectNode()))); final Process inputOutputProcess = mock(Process.class); - when(inputOutputProcess.getInputs()).thenReturn(asList(new ProcessInputStream(streamKey, new ObjectMapper().createObjectNode()))); - when(inputOutputProcess.getOutputs()).thenReturn(asList(new ProcessOutputStream(streamKey, new ObjectMapper().createObjectNode()))); + when(inputOutputProcess.getInputs()).thenReturn(List.of(new ProcessInputStream(streamKey, new ObjectMapper().createObjectNode()))); + when(inputOutputProcess.getOutputs()).thenReturn(List.of(new ProcessOutputStream(streamKey, new ObjectMapper().createObjectNode()))); when(processRepository.findAll()).thenReturn(asList(otherProcess, inputProcess, outputProcess, inputOutputProcess)); when(streamBindingRepository.findAll()).thenReturn(emptyList()); @@ -410,10 +411,10 @@ public void delete_failsOnMultipleStreamProcess() { final ProcessKey processKey = mock(ProcessKey.class); final Process process = mock(Process.class); - when(process.getInputs()).thenReturn(asList(new ProcessInputStream(otherStreamKey, new ObjectMapper().createObjectNode()))); - when(process.getOutputs()).thenReturn(asList(new ProcessOutputStream(streamKey, new ObjectMapper().createObjectNode()))); + when(process.getInputs()).thenReturn(List.of(new ProcessInputStream(otherStreamKey, new ObjectMapper().createObjectNode()))); + when(process.getOutputs()).thenReturn(List.of(new ProcessOutputStream(streamKey, new ObjectMapper().createObjectNode()))); when(process.getKey()).thenReturn(processKey); - when(processRepository.findAll()).thenReturn(asList(process)); + when(processRepository.findAll()).thenReturn(List.of(process)); streamService.delete(stream); } diff --git a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ZoneServiceTest.java b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ZoneServiceTest.java index f2d12f778..7d5f5ae4b 100644 --- a/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ZoneServiceTest.java +++ b/core/src/test/java/com/expediagroup/streamplatform/streamregistry/core/services/ZoneServiceTest.java @@ -127,7 +127,7 @@ public void create() { Mockito.doNothing().when(zoneValidator).validateForCreate(entity); Mockito.when(handlerService.handleInsert(entity)).thenReturn(specification); - Mockito.when(zoneRepository.save(any())).thenReturn(entity); + Mockito.when(zoneRepository.saveSpecification(any())).thenReturn(entity); when(entity.getKey()).thenReturn(key); zoneService.create(entity); @@ -136,7 +136,7 @@ public void create() { verify(zoneRepository).findById(key); verify(zoneValidator).validateForCreate(entity); verify(handlerService).handleInsert(entity); - verify(zoneRepository).save(entity); + verify(zoneRepository).saveSpecification(entity); } @Test @@ -152,7 +152,7 @@ public void update() { doNothing().when(zoneValidator).validateForUpdate(entity, existingEntity); when(handlerService.handleUpdate(entity, existingEntity)).thenReturn(specification); - when(zoneRepository.save(entity)).thenReturn(entity); + when(zoneRepository.saveSpecification(entity)).thenReturn(entity); zoneService.update(entity); @@ -160,7 +160,7 @@ public void update() { verify(zoneRepository).findById(key); verify(zoneValidator).validateForUpdate(entity, existingEntity); verify(handlerService).handleUpdate(entity, existingEntity); - verify(zoneRepository).save(entity); + verify(zoneRepository).saveSpecification(entity); } @Test @@ -168,11 +168,11 @@ public void updateStatus() { final Zone entity = mock(Zone.class); final Status status = mock(Status.class); - when(zoneRepository.save(entity)).thenReturn(entity); + when(zoneRepository.saveStatus(entity)).thenReturn(entity); zoneService.updateStatus(entity, status); - verify(zoneRepository).save(entity); + verify(zoneRepository).saveStatus(entity); } @Test diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerBindingMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerBindingMutationImpl.java index fdb18920a..d44cb39e9 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerBindingMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerBindingMutationImpl.java @@ -43,6 +43,9 @@ public class ConsumerBindingMutationImpl implements ConsumerBindingMutation { @Value("${entityView.exist.check.enabled:true}") private boolean checkExistEnabled; + @Value("${stream-registry.entity.status.enabled:true}") + private boolean entityStatusEnabled; + @Override public ConsumerBinding insert(ConsumerBindingKeyInput key, SpecificationInput specification) { return consumerBindingService.create(asConsumerBinding(key, specification)).get(); @@ -77,7 +80,12 @@ public Boolean delete(ConsumerBindingKeyInput key) { @Override public ConsumerBinding updateStatus(ConsumerBindingKeyInput key, StatusInput status) { ConsumerBinding consumerBinding = consumerBindingView.get(key.asConsumerBindingKey()).get(); - return consumerBindingService.updateStatus(consumerBinding, status.asStatus()).get(); + + if (entityStatusEnabled) { + return consumerBindingService.updateStatus(consumerBinding, status.asStatus()).get(); + } else { + return consumerBinding; + } } private ConsumerBinding asConsumerBinding(ConsumerBindingKeyInput key, SpecificationInput specification) { diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerMutationImpl.java index 523b9ead3..20e8bcd40 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerMutationImpl.java @@ -43,6 +43,9 @@ public class ConsumerMutationImpl implements ConsumerMutation { @Value("${entityView.exist.check.enabled:true}") private boolean checkExistEnabled; + @Value("${stream-registry.entity.status.enabled:true}") + private boolean entityStatusEnabled; + @Override public Consumer insert(ConsumerKeyInput key, SpecificationInput specification) { return consumerService.create(asConsumer(key, specification)).get(); @@ -77,7 +80,12 @@ public Boolean delete(ConsumerKeyInput key) { @Override public Consumer updateStatus(ConsumerKeyInput key, StatusInput status) { Consumer consumer = consumerView.get(key.asConsumerKey()).get(); - return consumerService.updateStatus(consumer, status.asStatus()).get(); + + if (entityStatusEnabled) { + return consumerService.updateStatus(consumer, status.asStatus()).get(); + } else { + return consumer; + } } private Consumer asConsumer(ConsumerKeyInput key, SpecificationInput specification) { diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/DomainMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/DomainMutationImpl.java index bfa8df993..9e4b75151 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/DomainMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/DomainMutationImpl.java @@ -19,6 +19,7 @@ import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import com.expediagroup.streamplatform.streamregistry.core.services.DomainService; @@ -36,6 +37,9 @@ public class DomainMutationImpl implements DomainMutation { private final DomainService domainService; private final DomainView domainView; + @Value("${stream-registry.entity.status.enabled:true}") + private boolean entityStatusEnabled; + @Override public Domain insert(DomainKeyInput key, SpecificationInput specification) { return domainService.create(asDomain(key, specification)).get(); @@ -65,7 +69,12 @@ public Boolean delete(DomainKeyInput key) { @Override public Domain updateStatus(DomainKeyInput key, StatusInput status) { Domain domain = domainView.get(key.asDomainKey()).get(); - return domainService.updateStatus(domain, status.asStatus()).get(); + + if (entityStatusEnabled) { + return domainService.updateStatus(domain, status.asStatus()).get(); + } else { + return domain; + } } private Domain asDomain(DomainKeyInput key, SpecificationInput specification) { diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/InfrastructureMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/InfrastructureMutationImpl.java index c8f0cfd6e..eb89a7d83 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/InfrastructureMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/InfrastructureMutationImpl.java @@ -19,6 +19,7 @@ import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import com.expediagroup.streamplatform.streamregistry.core.services.InfrastructureService; @@ -36,6 +37,9 @@ public class InfrastructureMutationImpl implements InfrastructureMutation { private final InfrastructureService infrastructureService; private final InfrastructureView infrastructureView; + @Value("${stream-registry.entity.status.enabled:true}") + private boolean entityStatusEnabled; + @Override public Infrastructure insert(InfrastructureKeyInput key, SpecificationInput specification) { return infrastructureService.create(asInfrastructure(key, specification)).get(); @@ -65,7 +69,12 @@ public Boolean delete(InfrastructureKeyInput key) { @Override public Infrastructure updateStatus(InfrastructureKeyInput key, StatusInput status) { Infrastructure infrastructure = infrastructureView.get(key.asInfrastructureKey()).get(); - return infrastructureService.updateStatus(infrastructure, status.asStatus()).get(); + + if (entityStatusEnabled) { + return infrastructureService.updateStatus(infrastructure, status.asStatus()).get(); + } else { + return infrastructure; + } } private Infrastructure asInfrastructure(InfrastructureKeyInput key, SpecificationInput specification) { diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessBindingMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessBindingMutationImpl.java index 4c3068534..eeace2ddc 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessBindingMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessBindingMutationImpl.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2023 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import com.expediagroup.streamplatform.streamregistry.core.services.ProcessBindingService; @@ -36,6 +37,9 @@ public class ProcessBindingMutationImpl implements ProcessBindingMutation { private final ProcessBindingService processBindingService; private final ProcessBindingView processBindingView; + @Value("${stream-registry.entity.status.enabled:true}") + private boolean entityStatusEnabled; + @Override public ProcessBinding insert(ProcessBindingKeyInput key, SpecificationInput specification, ZoneKeyInput zone, List inputs, List outputs) { @@ -68,7 +72,12 @@ public Boolean delete(ProcessBindingKeyInput key) { @Override public ProcessBinding updateStatus(ProcessBindingKeyInput key, StatusInput status) { ProcessBinding processBinding = processBindingView.get(key.asProcessBindingKey()).get(); - return processBindingService.updateStatus(processBinding, status.asStatus()).get(); + + if (entityStatusEnabled) { + return processBindingService.updateStatus(processBinding, status.asStatus()).get(); + } else { + return processBinding; + } } private ProcessBinding asProcessBinding(ProcessBindingKeyInput key, SpecificationInput specification, diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessMutationImpl.java index e446fc880..ad239023f 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessMutationImpl.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2023 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import com.expediagroup.streamplatform.streamregistry.core.services.ProcessService; @@ -36,6 +37,9 @@ public class ProcessMutationImpl implements ProcessMutation { private final ProcessService processService; private final ProcessView processView; + @Value("${stream-registry.entity.status.enabled:true}") + private boolean entityStatusEnabled; + @Override public Process insert(ProcessKeyInput key, SpecificationInput specification, List zones, List inputs, List outputs) { @@ -68,7 +72,12 @@ public Boolean delete(ProcessKeyInput key) { @Override public Process updateStatus(ProcessKeyInput key, StatusInput status) { Process stream = processView.get(key.asProcessKey()).get(); - return processService.updateStatus(stream, status.asStatus()).get(); + + if (entityStatusEnabled) { + return processService.updateStatus(stream, status.asStatus()).get(); + } else { + return stream; + } } private Process asProcess(ProcessKeyInput key, SpecificationInput specification, diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerBindingMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerBindingMutationImpl.java index f56e7bea5..830790a27 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerBindingMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerBindingMutationImpl.java @@ -40,6 +40,9 @@ public class ProducerBindingMutationImpl implements ProducerBindingMutation { @Value("${entityView.exist.check.enabled:true}") private boolean checkExistEnabled; + @Value("${stream-registry.entity.status.enabled:true}") + private boolean entityStatusEnabled; + private final ProducerBindingService producerBindingService; private final ProducerBindingView producerBindingView; @@ -77,7 +80,12 @@ public Boolean delete(ProducerBindingKeyInput key) { @Override public ProducerBinding updateStatus(ProducerBindingKeyInput key, StatusInput status) { ProducerBinding producerBinding = producerBindingView.get(key.asProducerBindingKey()).get(); - return producerBindingService.updateStatus(producerBinding, status.asStatus()).get(); + + if (entityStatusEnabled) { + return producerBindingService.updateStatus(producerBinding, status.asStatus()).get(); + } else { + return producerBinding; + } } private ProducerBinding asProducerBinding(ProducerBindingKeyInput key, SpecificationInput specification) { diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerMutationImpl.java index 9b175c0bb..e48ffd201 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerMutationImpl.java @@ -40,6 +40,9 @@ public class ProducerMutationImpl implements ProducerMutation { @Value("${entityView.exist.check.enabled:true}") private boolean checkExistEnabled; + @Value("${stream-registry.entity.status.enabled:true}") + private boolean entityStatusEnabled; + private final ProducerService producerService; private final ProducerView producerView; @@ -77,7 +80,12 @@ public Boolean delete(ProducerKeyInput key) { @Override public Producer updateStatus(ProducerKeyInput key, StatusInput status) { Producer producer = producerView.get(key.asProducerKey()).get(); - return producerService.updateStatus(producer, status.asStatus()).get(); + + if (entityStatusEnabled) { + return producerService.updateStatus(producer, status.asStatus()).get(); + } else { + return producer; + } } private Producer asProducer(ProducerKeyInput key, SpecificationInput specification) { diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/SchemaMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/SchemaMutationImpl.java index c40e48dd5..3998da1ea 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/SchemaMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/SchemaMutationImpl.java @@ -19,6 +19,7 @@ import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import com.expediagroup.streamplatform.streamregistry.core.services.SchemaService; @@ -36,6 +37,9 @@ public class SchemaMutationImpl implements SchemaMutation { private final SchemaService schemaService; private final SchemaView schemaView; + @Value("${stream-registry.entity.status.enabled:true}") + private boolean entityStatusEnabled; + @Override public Schema insert(SchemaKeyInput key, SpecificationInput specification) { return schemaService.create(asSchema(key, specification)).get(); @@ -64,7 +68,12 @@ public Boolean delete(SchemaKeyInput key) { @Override public Schema updateStatus(SchemaKeyInput key, StatusInput status) { Schema schema = schemaView.get(key.asSchemaKey()).get(); - return schemaService.updateStatus(schema, status.asStatus()).get(); + + if (entityStatusEnabled) { + return schemaService.updateStatus(schema, status.asStatus()).get(); + } else { + return schema; + } } private Schema asSchema(SchemaKeyInput key, SpecificationInput specification) { diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamBindingMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamBindingMutationImpl.java index 2d3c9612a..0e7e5ac8d 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamBindingMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamBindingMutationImpl.java @@ -40,6 +40,9 @@ public class StreamBindingMutationImpl implements StreamBindingMutation { @Value("${entityView.exist.check.enabled:true}") private boolean checkExistEnabled; + @Value("${stream-registry.entity.status.enabled:true}") + private boolean entityStatusEnabled; + private final StreamBindingService streamBindingService; private final StreamBindingView streamBindingView; @@ -77,7 +80,12 @@ public Boolean delete(StreamBindingKeyInput key) { @Override public StreamBinding updateStatus(StreamBindingKeyInput key, StatusInput status) { StreamBinding streamBinding = streamBindingView.get(key.asStreamBindingKey()).get(); - return streamBindingService.updateStatus(streamBinding, status.asStatus()).get(); + + if (entityStatusEnabled) { + return streamBindingService.updateStatus(streamBinding, status.asStatus()).get(); + } else { + return streamBinding; + } } private StreamBinding asStreamBinding(StreamBindingKeyInput key, SpecificationInput specification) { diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamMutationImpl.java index 7a5d6a915..f33f76a7b 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamMutationImpl.java @@ -41,6 +41,9 @@ public class StreamMutationImpl implements StreamMutation { @Value("${entityView.exist.check.enabled:true}") private boolean checkExistEnabled; + @Value("${stream-registry.entity.status.enabled:true}") + private boolean entityStatusEnabled; + private final StreamService streamService; private final StreamView streamView; @@ -78,7 +81,12 @@ public Boolean delete(StreamKeyInput key) { @Override public Stream updateStatus(StreamKeyInput key, StatusInput status) { Stream stream = streamView.get(key.asStreamKey()).get(); - return streamService.updateStatus(stream, status.asStatus()).get(); + + if (entityStatusEnabled) { + return streamService.updateStatus(stream, status.asStatus()).get(); + } else { + return stream; + } } private Stream asStream(StreamKeyInput key, SpecificationInput specification, Optional schema) { diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ZoneMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ZoneMutationImpl.java index 97d9bcca7..b92650aeb 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ZoneMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ZoneMutationImpl.java @@ -19,6 +19,7 @@ import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import com.expediagroup.streamplatform.streamregistry.core.services.ZoneService; @@ -35,6 +36,9 @@ public class ZoneMutationImpl implements ZoneMutation { private final ZoneService zoneService; private final ZoneView zoneView; + @Value("${stream-registry.entity.status.enabled:true}") + private boolean entityStatusEnabled; + @Override public Zone insert(ZoneKeyInput key, SpecificationInput specification) { return zoneService.create(asZone(key, specification)).get(); @@ -64,7 +68,12 @@ public Boolean delete(ZoneKeyInput key) { @Override public Zone updateStatus(ZoneKeyInput key, StatusInput status) { Zone zone = zoneView.get(key.asZoneKey()).get(); - return zoneService.updateStatus(zone, status.asStatus()).get(); + + if (entityStatusEnabled) { + return zoneService.updateStatus(zone, status.asStatus()).get(); + } else { + return zone; + } } private Zone asZone(ZoneKeyInput key, SpecificationInput specification) { diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/InputHelper.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/InputHelper.java new file mode 100644 index 000000000..bb1981ff1 --- /dev/null +++ b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/InputHelper.java @@ -0,0 +1,28 @@ +/** + * Copyright (C) 2018-2024 Expedia, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.expediagroup.streamplatform.streamregistry.graphql; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; + +public class InputHelper { + private static final ObjectMapper mapper = new ObjectMapper(); + + public static StatusInput statusInput() { + return StatusInput.builder().agentStatus(mapper.createObjectNode()).build(); + } +} diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerBindingMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerBindingMutationImplTest.java index eca57b713..b4c0e677b 100644 --- a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerBindingMutationImplTest.java +++ b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerBindingMutationImplTest.java @@ -15,11 +15,10 @@ */ package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import java.util.Optional; @@ -32,8 +31,10 @@ import com.expediagroup.streamplatform.streamregistry.core.services.ConsumerBindingService; import com.expediagroup.streamplatform.streamregistry.core.views.ConsumerBindingView; +import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.ConsumerBindingKeyInput; +import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; import com.expediagroup.streamplatform.streamregistry.model.ConsumerBinding; @RunWith(MockitoJUnitRunner.class) @@ -100,6 +101,39 @@ public void deleteWithCheckExistDisabledWhenEntityDoesNotExist() { assertTrue(result); } + @Test + public void updateStatusWithEntityStatusEnabled() { + ReflectionTestUtils.setField(consumerBindingMutation, "entityStatusEnabled", true); + ConsumerBindingKeyInput key = getConsumerBindingInputKey(); + Optional consumerBinding = Optional.of(getConsumer(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(consumerBindingView.get(any())).thenReturn(consumerBinding); + when(consumerBindingService.updateStatus(any(), any())).thenReturn(consumerBinding); + + ConsumerBinding result = consumerBindingMutation.updateStatus(key, statusInput); + + verify(consumerBindingView, times(1)).get(key.asConsumerBindingKey()); + verify(consumerBindingService, times(1)).updateStatus(consumerBinding.get(), statusInput.asStatus()); + assertEquals(consumerBinding.get(), result); + } + + @Test + public void updateStatusWithEntityStatusDisabled() { + ReflectionTestUtils.setField(consumerBindingMutation, "entityStatusEnabled", false); + ConsumerBindingKeyInput key = getConsumerBindingInputKey(); + Optional consumerBinding = Optional.of(getConsumer(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(consumerBindingView.get(any())).thenReturn(consumerBinding); + + ConsumerBinding result = consumerBindingMutation.updateStatus(key, statusInput); + + verify(consumerBindingView, times(1)).get(key.asConsumerBindingKey()); + verify(consumerBindingService, never()).updateStatus(consumerBinding.get(), statusInput.asStatus()); + assertEquals(consumerBinding.get(), result); + } + private ConsumerBindingKeyInput getConsumerBindingInputKey() { return ConsumerBindingKeyInput.builder() .streamDomain("domain") diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerMutationImplTest.java index 869e55239..2c69bff2b 100644 --- a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerMutationImplTest.java +++ b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerMutationImplTest.java @@ -15,11 +15,10 @@ */ package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import java.util.Optional; @@ -32,8 +31,10 @@ import com.expediagroup.streamplatform.streamregistry.core.services.ConsumerService; import com.expediagroup.streamplatform.streamregistry.core.views.ConsumerView; +import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.ConsumerKeyInput; +import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; import com.expediagroup.streamplatform.streamregistry.model.Consumer; @RunWith(MockitoJUnitRunner.class) @@ -96,6 +97,39 @@ public void deleteWithCheckExistDisabledWhenEntityDoesNotExist() { assertTrue(result); } + @Test + public void updateStatusWithEntityStatusEnabled() { + ReflectionTestUtils.setField(consumerMutation, "entityStatusEnabled", true); + ConsumerKeyInput key = getConsumerInputKey(); + Optional consumer = Optional.of(getConsumer(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(consumerView.get(any())).thenReturn(consumer); + when(consumerService.updateStatus(any(), any())).thenReturn(consumer); + + Consumer result = consumerMutation.updateStatus(key, statusInput); + + verify(consumerView, times(1)).get(key.asConsumerKey()); + verify(consumerService, times(1)).updateStatus(consumer.get(), statusInput.asStatus()); + assertEquals(consumer.get(), result); + } + + @Test + public void updateStatusWithEntityStatusDisabled() { + ReflectionTestUtils.setField(consumerMutation, "entityStatusEnabled", false); + ConsumerKeyInput key = getConsumerInputKey(); + Optional consumer = Optional.of(getConsumer(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(consumerView.get(any())).thenReturn(consumer); + + Consumer result = consumerMutation.updateStatus(key, statusInput); + + verify(consumerView, times(1)).get(key.asConsumerKey()); + verify(consumerService, never()).updateStatus(consumer.get(), statusInput.asStatus()); + assertEquals(consumer.get(), result); + } + private ConsumerKeyInput getConsumerInputKey() { return ConsumerKeyInput.builder() .streamDomain("domain") diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/DomainMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/DomainMutationImplTest.java new file mode 100644 index 000000000..1602ea571 --- /dev/null +++ b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/DomainMutationImplTest.java @@ -0,0 +1,97 @@ +/** + * Copyright (C) 2018-2024 Expedia, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +import java.util.Optional; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.expediagroup.streamplatform.streamregistry.core.services.DomainService; +import com.expediagroup.streamplatform.streamregistry.core.views.DomainView; +import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; +import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; +import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.DomainKeyInput; +import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; +import com.expediagroup.streamplatform.streamregistry.model.Domain; + +@RunWith(MockitoJUnitRunner.class) +public class DomainMutationImplTest { + + @Mock + private DomainService domainService; + + @Mock + private DomainView domainView; + + private DomainMutationImpl domainMutation; + + @Before + public void before() throws Exception { + domainMutation = new DomainMutationImpl(domainService, domainView); + } + + @Test + public void updateStatusWithEntityStatusEnabled() { + ReflectionTestUtils.setField(domainMutation, "entityStatusEnabled", true); + DomainKeyInput key = getDomainInputKey(); + Optional domain = Optional.of(getDomain(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(domainView.get(any())).thenReturn(domain); + when(domainService.updateStatus(any(), any())).thenReturn(domain); + + Domain result = domainMutation.updateStatus(key, statusInput); + + verify(domainView, times(1)).get(key.asDomainKey()); + verify(domainService, times(1)).updateStatus(domain.get(), statusInput.asStatus()); + assertEquals(domain.get(), result); + } + + @Test + public void updateStatusWithEntityStatusDisabled() { + ReflectionTestUtils.setField(domainMutation, "entityStatusEnabled", false); + DomainKeyInput key = getDomainInputKey(); + Optional domain = Optional.of(getDomain(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(domainView.get(any())).thenReturn(domain); + + Domain result = domainMutation.updateStatus(key, statusInput); + + verify(domainView, times(1)).get(key.asDomainKey()); + verify(domainService, never()).updateStatus(domain.get(), statusInput.asStatus()); + assertEquals(domain.get(), result); + } + + private DomainKeyInput getDomainInputKey() { + return DomainKeyInput.builder() + .name("domain") + .build(); + } + + private Domain getDomain(DomainKeyInput key) { + return new Domain(key.asDomainKey(), StateHelper.specification(), StateHelper.status()); + } +} diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/InfrastructureMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/InfrastructureMutationImplTest.java new file mode 100644 index 000000000..7b98eb3e2 --- /dev/null +++ b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/InfrastructureMutationImplTest.java @@ -0,0 +1,98 @@ +/** + * Copyright (C) 2018-2024 Expedia, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +import java.util.Optional; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.expediagroup.streamplatform.streamregistry.core.services.InfrastructureService; +import com.expediagroup.streamplatform.streamregistry.core.views.InfrastructureView; +import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; +import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; +import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.InfrastructureKeyInput; +import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; +import com.expediagroup.streamplatform.streamregistry.model.Infrastructure; + +@RunWith(MockitoJUnitRunner.class) +public class InfrastructureMutationImplTest { + + @Mock + private InfrastructureService infrastructureService; + + @Mock + private InfrastructureView infrastructureView; + + private InfrastructureMutationImpl infrastructureMutation; + + @Before + public void before() throws Exception { + infrastructureMutation = new InfrastructureMutationImpl(infrastructureService, infrastructureView); + } + + @Test + public void updateStatusWithEntityStatusEnabled() { + ReflectionTestUtils.setField(infrastructureMutation, "entityStatusEnabled", true); + InfrastructureKeyInput key = getInfrastructureInputKey(); + Optional infrastructure = Optional.of(getInfrastructure(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(infrastructureView.get(any())).thenReturn(infrastructure); + when(infrastructureService.updateStatus(any(), any())).thenReturn(infrastructure); + + Infrastructure result = infrastructureMutation.updateStatus(key, statusInput); + + verify(infrastructureView, times(1)).get(key.asInfrastructureKey()); + verify(infrastructureService, times(1)).updateStatus(infrastructure.get(), statusInput.asStatus()); + assertEquals(infrastructure.get(), result); + } + + @Test + public void updateStatusWithEntityStatusDisabled() { + ReflectionTestUtils.setField(infrastructureMutation, "entityStatusEnabled", false); + InfrastructureKeyInput key = getInfrastructureInputKey(); + Optional infrastructure = Optional.of(getInfrastructure(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(infrastructureView.get(any())).thenReturn(infrastructure); + + Infrastructure result = infrastructureMutation.updateStatus(key, statusInput); + + verify(infrastructureView, times(1)).get(key.asInfrastructureKey()); + verify(infrastructureService, never()).updateStatus(infrastructure.get(), statusInput.asStatus()); + assertEquals(infrastructure.get(), result); + } + + private InfrastructureKeyInput getInfrastructureInputKey() { + return InfrastructureKeyInput.builder() + .name("infrastructure") + .zone("zone") + .build(); + } + + private Infrastructure getInfrastructure(InfrastructureKeyInput key) { + return new Infrastructure(key.asInfrastructureKey(), StateHelper.specification(), StateHelper.status()); + } +} diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessBindingMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessBindingMutationImplTest.java new file mode 100644 index 000000000..f2d1a263a --- /dev/null +++ b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessBindingMutationImplTest.java @@ -0,0 +1,108 @@ +/** + * Copyright (C) 2018-2024 Expedia, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +import java.util.List; +import java.util.Optional; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.expediagroup.streamplatform.streamregistry.core.services.ProcessBindingService; +import com.expediagroup.streamplatform.streamregistry.core.views.ProcessBindingView; +import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; +import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; +import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.ProcessBindingKeyInput; +import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; +import com.expediagroup.streamplatform.streamregistry.model.ProcessBinding; +import com.expediagroup.streamplatform.streamregistry.model.keys.ZoneKey; + +@RunWith(MockitoJUnitRunner.class) +public class ProcessBindingMutationImplTest { + + @Mock + private ProcessBindingService processBindingService; + + @Mock + private ProcessBindingView processBindingView; + + private ProcessBindingMutationImpl processBindingMutation; + + @Before + public void before() throws Exception { + processBindingMutation = new ProcessBindingMutationImpl(processBindingService, processBindingView); + } + + @Test + public void updateStatusWithEntityStatusEnabled() { + ReflectionTestUtils.setField(processBindingMutation, "entityStatusEnabled", true); + ProcessBindingKeyInput key = getProcessBindingInputKey(); + Optional processBinding = Optional.of(getProcessBinding(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(processBindingView.get(any())).thenReturn(processBinding); + when(processBindingService.updateStatus(any(), any())).thenReturn(processBinding); + + ProcessBinding result = processBindingMutation.updateStatus(key, statusInput); + + verify(processBindingView, times(1)).get(key.asProcessBindingKey()); + verify(processBindingService, times(1)).updateStatus(processBinding.get(), statusInput.asStatus()); + assertEquals(processBinding.get(), result); + } + + @Test + public void updateStatusWithEntityStatusDisabled() { + ReflectionTestUtils.setField(processBindingMutation, "entityStatusEnabled", false); + ProcessBindingKeyInput key = getProcessBindingInputKey(); + Optional processBinding = Optional.of(getProcessBinding(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(processBindingView.get(any())).thenReturn(processBinding); + + ProcessBinding result = processBindingMutation.updateStatus(key, statusInput); + + verify(processBindingView, times(1)).get(key.asProcessBindingKey()); + verify(processBindingService, never()).updateStatus(processBinding.get(), statusInput.asStatus()); + assertEquals(processBinding.get(), result); + } + + private ProcessBindingKeyInput getProcessBindingInputKey() { + return ProcessBindingKeyInput.builder() + .domainName("domain") + .processName("process") + .infrastructureZone("zone") + .build(); + } + + private ProcessBinding getProcessBinding(ProcessBindingKeyInput key) { + return new ProcessBinding( + key.asProcessBindingKey(), + StateHelper.specification(), + new ZoneKey("zone"), + List.of(), + List.of(), + StateHelper.status() + ); + } +} diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessMutationImplTest.java new file mode 100644 index 000000000..abd3a6112 --- /dev/null +++ b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessMutationImplTest.java @@ -0,0 +1,107 @@ +/** + * Copyright (C) 2018-2024 Expedia, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +import java.util.List; +import java.util.Optional; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.expediagroup.streamplatform.streamregistry.core.services.ProcessService; +import com.expediagroup.streamplatform.streamregistry.core.views.ProcessView; +import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; +import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; +import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.ProcessKeyInput; +import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; +import com.expediagroup.streamplatform.streamregistry.model.Process; +import com.expediagroup.streamplatform.streamregistry.model.keys.ZoneKey; + +@RunWith(MockitoJUnitRunner.class) +public class ProcessMutationImplTest { + + @Mock + private ProcessService processService; + + @Mock + private ProcessView processView; + + private ProcessMutationImpl processMutation; + + @Before + public void before() throws Exception { + processMutation = new ProcessMutationImpl(processService, processView); + } + + @Test + public void updateStatusWithEntityStatusEnabled() { + ReflectionTestUtils.setField(processMutation, "entityStatusEnabled", true); + ProcessKeyInput key = getProcessInputKey(); + Optional process = Optional.of(getProcess(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(processView.get(any())).thenReturn(process); + when(processService.updateStatus(any(), any())).thenReturn(process); + + Process result = processMutation.updateStatus(key, statusInput); + + verify(processView, times(1)).get(key.asProcessKey()); + verify(processService, times(1)).updateStatus(process.get(), statusInput.asStatus()); + assertEquals(process.get(), result); + } + + @Test + public void updateStatusWithEntityStatusDisabled() { + ReflectionTestUtils.setField(processMutation, "entityStatusEnabled", false); + ProcessKeyInput key = getProcessInputKey(); + Optional process = Optional.of(getProcess(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(processView.get(any())).thenReturn(process); + + Process result = processMutation.updateStatus(key, statusInput); + + verify(processView, times(1)).get(key.asProcessKey()); + verify(processService, never()).updateStatus(process.get(), statusInput.asStatus()); + assertEquals(process.get(), result); + } + + private ProcessKeyInput getProcessInputKey() { + return ProcessKeyInput.builder() + .domain("domain") + .name("process") + .build(); + } + + private Process getProcess(ProcessKeyInput key) { + return new Process( + key.asProcessKey(), + StateHelper.specification(), + List.of(new ZoneKey("zone")), + List.of(), + List.of(), + StateHelper.status() + ); + } +} diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerBindingMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerBindingMutationImplTest.java index c5f8d9868..451a3c3ee 100644 --- a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerBindingMutationImplTest.java +++ b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerBindingMutationImplTest.java @@ -15,11 +15,10 @@ */ package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import java.util.Optional; @@ -32,8 +31,10 @@ import com.expediagroup.streamplatform.streamregistry.core.services.ProducerBindingService; import com.expediagroup.streamplatform.streamregistry.core.views.ProducerBindingView; +import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.ProducerBindingKeyInput; +import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; import com.expediagroup.streamplatform.streamregistry.model.ProducerBinding; @RunWith(MockitoJUnitRunner.class) @@ -55,7 +56,7 @@ public void before() throws Exception { @Test public void deleteWithCheckExistEnabledWhenEntityExists() { ReflectionTestUtils.setField(producerBindingMutation, "checkExistEnabled", true); - ProducerBindingKeyInput key = getproducerBindingInputKey(); + ProducerBindingKeyInput key = getProducerBindingInputKey(); when(producerBindingView.get(any())).thenReturn(Optional.of(getProducer(key))); Boolean result = producerBindingMutation.delete(key); verify(producerBindingView, times(1)).get(key.asProducerBindingKey()); @@ -66,7 +67,7 @@ public void deleteWithCheckExistEnabledWhenEntityExists() { @Test public void deleteWithCheckExistEnabledWhenEntityDoesNotExist() { ReflectionTestUtils.setField(producerBindingMutation, "checkExistEnabled", true); - ProducerBindingKeyInput key = getproducerBindingInputKey(); + ProducerBindingKeyInput key = getProducerBindingInputKey(); when(producerBindingView.get(any())).thenReturn(Optional.empty()); Boolean result = producerBindingMutation.delete(key); verify(producerBindingView, times(1)).get(key.asProducerBindingKey()); @@ -77,7 +78,7 @@ public void deleteWithCheckExistEnabledWhenEntityDoesNotExist() { @Test public void deleteWithCheckExistDisabledWhenEntityExists() { ReflectionTestUtils.setField(producerBindingMutation, "checkExistEnabled", false); - ProducerBindingKeyInput key = getproducerBindingInputKey(); + ProducerBindingKeyInput key = getProducerBindingInputKey(); when(producerBindingView.get(any())).thenReturn(Optional.of(getProducer(key))); Boolean result = producerBindingMutation.delete(key); verify(producerBindingView, times(1)).get(key.asProducerBindingKey()); @@ -88,7 +89,7 @@ public void deleteWithCheckExistDisabledWhenEntityExists() { @Test public void deleteWithCheckExistDisabledWhenEntityDoesNotExist() { ReflectionTestUtils.setField(producerBindingMutation, "checkExistEnabled", false); - ProducerBindingKeyInput key = getproducerBindingInputKey(); + ProducerBindingKeyInput key = getProducerBindingInputKey(); when(producerBindingView.get(any())).thenReturn(Optional.empty()); Boolean result = producerBindingMutation.delete(key); verify(producerBindingView, times(1)).get(key.asProducerBindingKey()); @@ -96,7 +97,40 @@ public void deleteWithCheckExistDisabledWhenEntityDoesNotExist() { assertTrue(result); } - private ProducerBindingKeyInput getproducerBindingInputKey() { + @Test + public void updateStatusWithEntityStatusEnabled() { + ReflectionTestUtils.setField(producerBindingMutation, "entityStatusEnabled", true); + ProducerBindingKeyInput key = getProducerBindingInputKey(); + Optional producerBinding = Optional.of(getProducer(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(producerBindingView.get(any())).thenReturn(producerBinding); + when(producerBindingService.updateStatus(any(), any())).thenReturn(producerBinding); + + ProducerBinding result = producerBindingMutation.updateStatus(key, statusInput); + + verify(producerBindingView, times(1)).get(key.asProducerBindingKey()); + verify(producerBindingService, times(1)).updateStatus(producerBinding.get(), statusInput.asStatus()); + assertEquals(producerBinding.get(), result); + } + + @Test + public void updateStatusWithEntityStatusDisabled() { + ReflectionTestUtils.setField(producerBindingMutation, "entityStatusEnabled", false); + ProducerBindingKeyInput key = getProducerBindingInputKey(); + Optional producerBinding = Optional.of(getProducer(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(producerBindingView.get(any())).thenReturn(producerBinding); + + ProducerBinding result = producerBindingMutation.updateStatus(key, statusInput); + + verify(producerBindingView, times(1)).get(key.asProducerBindingKey()); + verify(producerBindingService, never()).updateStatus(producerBinding.get(), statusInput.asStatus()); + assertEquals(producerBinding.get(), result); + } + + private ProducerBindingKeyInput getProducerBindingInputKey() { return ProducerBindingKeyInput.builder() .streamDomain("domain") .streamName("stream") diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerMutationImplTest.java index aac8da2e3..84b8255cc 100644 --- a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerMutationImplTest.java +++ b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerMutationImplTest.java @@ -15,11 +15,10 @@ */ package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import java.util.Optional; @@ -32,8 +31,10 @@ import com.expediagroup.streamplatform.streamregistry.core.services.ProducerService; import com.expediagroup.streamplatform.streamregistry.core.views.ProducerView; +import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.ProducerKeyInput; +import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; import com.expediagroup.streamplatform.streamregistry.model.Producer; @RunWith(MockitoJUnitRunner.class) @@ -98,6 +99,39 @@ public void deleteWithCheckExistDisabledWhenEntityDoesNotExist() { assertTrue(result); } + @Test + public void updateStatusWithEntityStatusEnabled() { + ReflectionTestUtils.setField(producerMutation, "entityStatusEnabled", true); + ProducerKeyInput key = getProducerInputKey(); + Optional producer = Optional.of(getProducer(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(producerView.get(any())).thenReturn(producer); + when(producerService.updateStatus(any(), any())).thenReturn(producer); + + Producer result = producerMutation.updateStatus(key, statusInput); + + verify(producerView, times(1)).get(key.asProducerKey()); + verify(producerService, times(1)).updateStatus(producer.get(), statusInput.asStatus()); + assertEquals(producer.get(), result); + } + + @Test + public void updateStatusWithEntityStatusDisabled() { + ReflectionTestUtils.setField(producerMutation, "entityStatusEnabled", false); + ProducerKeyInput key = getProducerInputKey(); + Optional producer = Optional.of(getProducer(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(producerView.get(any())).thenReturn(producer); + + Producer result = producerMutation.updateStatus(key, statusInput); + + verify(producerView, times(1)).get(key.asProducerKey()); + verify(producerService, never()).updateStatus(producer.get(), statusInput.asStatus()); + assertEquals(producer.get(), result); + } + private ProducerKeyInput getProducerInputKey() { return ProducerKeyInput.builder() .streamDomain("domain") diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/SchemaMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/SchemaMutationImplTest.java new file mode 100644 index 000000000..ce6afb085 --- /dev/null +++ b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/SchemaMutationImplTest.java @@ -0,0 +1,98 @@ +/** + * Copyright (C) 2018-2024 Expedia, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +import java.util.Optional; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.expediagroup.streamplatform.streamregistry.core.services.SchemaService; +import com.expediagroup.streamplatform.streamregistry.core.views.SchemaView; +import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; +import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; +import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.SchemaKeyInput; +import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; +import com.expediagroup.streamplatform.streamregistry.model.Schema; + +@RunWith(MockitoJUnitRunner.class) +public class SchemaMutationImplTest { + + @Mock + private SchemaService schemaService; + + @Mock + private SchemaView schemaView; + + private SchemaMutationImpl schemaMutation; + + @Before + public void before() throws Exception { + schemaMutation = new SchemaMutationImpl(schemaService, schemaView); + } + + @Test + public void updateStatusWithEntityStatusEnabled() { + ReflectionTestUtils.setField(schemaMutation, "entityStatusEnabled", true); + SchemaKeyInput key = getSchemaInputKey(); + Optional schema = Optional.of(getSchema(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(schemaView.get(any())).thenReturn(schema); + when(schemaService.updateStatus(any(), any())).thenReturn(schema); + + Schema result = schemaMutation.updateStatus(key, statusInput); + + verify(schemaView, times(1)).get(key.asSchemaKey()); + verify(schemaService, times(1)).updateStatus(schema.get(), statusInput.asStatus()); + assertEquals(schema.get(), result); + } + + @Test + public void updateStatusWithEntityStatusDisabled() { + ReflectionTestUtils.setField(schemaMutation, "entityStatusEnabled", false); + SchemaKeyInput key = getSchemaInputKey(); + Optional schema = Optional.of(getSchema(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(schemaView.get(any())).thenReturn(schema); + + Schema result = schemaMutation.updateStatus(key, statusInput); + + verify(schemaView, times(1)).get(key.asSchemaKey()); + verify(schemaService, never()).updateStatus(schema.get(), statusInput.asStatus()); + assertEquals(schema.get(), result); + } + + private SchemaKeyInput getSchemaInputKey() { + return SchemaKeyInput.builder() + .domain("domain") + .name("schema") + .build(); + } + + private Schema getSchema(SchemaKeyInput key) { + return new Schema(key.asSchemaKey(), StateHelper.specification(), StateHelper.status()); + } +} diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamBindingMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamBindingMutationImplTest.java index cde379e79..f466fe8ec 100644 --- a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamBindingMutationImplTest.java +++ b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamBindingMutationImplTest.java @@ -15,11 +15,10 @@ */ package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import java.util.Optional; @@ -32,7 +31,9 @@ import com.expediagroup.streamplatform.streamregistry.core.services.StreamBindingService; import com.expediagroup.streamplatform.streamregistry.core.views.StreamBindingView; +import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; +import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StreamBindingKeyInput; import com.expediagroup.streamplatform.streamregistry.model.StreamBinding; @@ -56,7 +57,7 @@ public void before() throws Exception { public void deleteWithCheckExistEnabledWhenEntityExists() { ReflectionTestUtils.setField(streamBindingMutation, "checkExistEnabled", true); StreamBindingKeyInput key = getStreamBindingInputKey(); - when(streamBindingView.get(any())).thenReturn(Optional.of(getStream(key))); + when(streamBindingView.get(any())).thenReturn(Optional.of(getStreamBinding(key))); Boolean result = streamBindingMutation.delete(key); verify(streamBindingView, times(1)).get(key.asStreamBindingKey()); verify(streamBindingService, times(1)).delete(any()); @@ -78,7 +79,7 @@ public void deleteWithCheckExistEnabledWhenEntityDoesNotExist() { public void deleteWithCheckExistDisabledWhenEntiyExists() { ReflectionTestUtils.setField(streamBindingMutation, "checkExistEnabled", false); StreamBindingKeyInput key = getStreamBindingInputKey(); - when(streamBindingView.get(any())).thenReturn(Optional.of(getStream(key))); + when(streamBindingView.get(any())).thenReturn(Optional.of(getStreamBinding(key))); Boolean result = streamBindingMutation.delete(key); verify(streamBindingView, times(1)).get(key.asStreamBindingKey()); verify(streamBindingService, times(1)).delete(any()); @@ -96,6 +97,39 @@ public void deleteWithCheckExistDisabledWhenEntiyDoesNotExist() { assertTrue(result); } + @Test + public void updateStatusWithEntityStatusEnabled() { + ReflectionTestUtils.setField(streamBindingMutation, "entityStatusEnabled", true); + StreamBindingKeyInput key = getStreamBindingInputKey(); + Optional streamBinding = Optional.of(getStreamBinding(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(streamBindingView.get(any())).thenReturn(streamBinding); + when(streamBindingService.updateStatus(any(), any())).thenReturn(streamBinding); + + StreamBinding result = streamBindingMutation.updateStatus(key, statusInput); + + verify(streamBindingView, times(1)).get(key.asStreamBindingKey()); + verify(streamBindingService, times(1)).updateStatus(streamBinding.get(), statusInput.asStatus()); + assertEquals(streamBinding.get(), result); + } + + @Test + public void updateStatusWithEntityStatusDisabled() { + ReflectionTestUtils.setField(streamBindingMutation, "entityStatusEnabled", false); + StreamBindingKeyInput key = getStreamBindingInputKey(); + Optional streamBinding = Optional.of(getStreamBinding(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(streamBindingView.get(any())).thenReturn(streamBinding); + + StreamBinding result = streamBindingMutation.updateStatus(key, statusInput); + + verify(streamBindingView, times(1)).get(key.asStreamBindingKey()); + verify(streamBindingService, never()).updateStatus(streamBinding.get(), statusInput.asStatus()); + assertEquals(streamBinding.get(), result); + } + private StreamBindingKeyInput getStreamBindingInputKey() { return StreamBindingKeyInput.builder() .streamDomain("domain") @@ -106,7 +140,7 @@ private StreamBindingKeyInput getStreamBindingInputKey() { .build(); } - private StreamBinding getStream(StreamBindingKeyInput key) { + private StreamBinding getStreamBinding(StreamBindingKeyInput key) { return new StreamBinding(key.asStreamBindingKey(), StateHelper.specification(), StateHelper.status()); } } diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamMutationImplTest.java index fa508e8c2..8203ddc9a 100644 --- a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamMutationImplTest.java +++ b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamMutationImplTest.java @@ -15,11 +15,10 @@ */ package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import java.util.Optional; @@ -32,7 +31,9 @@ import com.expediagroup.streamplatform.streamregistry.core.services.StreamService; import com.expediagroup.streamplatform.streamregistry.core.views.StreamView; +import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; +import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StreamKeyInput; import com.expediagroup.streamplatform.streamregistry.model.Stream; @@ -95,6 +96,39 @@ public void deleteWithCheckExistDisabledWhenEntityDoesNotExist() { assertTrue(result); } + @Test + public void updateStatusWithEntityStatusEnabled() { + ReflectionTestUtils.setField(streamMutation, "entityStatusEnabled", true); + StreamKeyInput key = getStreamInputKey(); + Optional stream = Optional.of(getStream(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(streamView.get(any())).thenReturn(stream); + when(streamService.updateStatus(any(), any())).thenReturn(stream); + + Stream result = streamMutation.updateStatus(key, statusInput); + + verify(streamView, times(1)).get(key.asStreamKey()); + verify(streamService, times(1)).updateStatus(stream.get(), statusInput.asStatus()); + assertEquals(stream.get(), result); + } + + @Test + public void updateStatusWithEntityStatusDisabled() { + ReflectionTestUtils.setField(streamMutation, "entityStatusEnabled", false); + StreamKeyInput key = getStreamInputKey(); + Optional stream = Optional.of(getStream(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(streamView.get(any())).thenReturn(stream); + + Stream result = streamMutation.updateStatus(key, statusInput); + + verify(streamView, times(1)).get(key.asStreamKey()); + verify(streamService, never()).updateStatus(stream.get(), statusInput.asStatus()); + assertEquals(stream.get(), result); + } + private StreamKeyInput getStreamInputKey() { return StreamKeyInput.builder() .domain("domain") diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ZoneMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ZoneMutationImplTest.java new file mode 100644 index 000000000..ffef0d573 --- /dev/null +++ b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ZoneMutationImplTest.java @@ -0,0 +1,97 @@ +/** + * Copyright (C) 2018-2024 Expedia, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +import java.util.Optional; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.expediagroup.streamplatform.streamregistry.core.services.ZoneService; +import com.expediagroup.streamplatform.streamregistry.core.views.ZoneView; +import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; +import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; +import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; +import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.ZoneKeyInput; +import com.expediagroup.streamplatform.streamregistry.model.Zone; + +@RunWith(MockitoJUnitRunner.class) +public class ZoneMutationImplTest { + + @Mock + private ZoneService zoneService; + + @Mock + private ZoneView zoneView; + + private ZoneMutationImpl zoneMutation; + + @Before + public void before() throws Exception { + zoneMutation = new ZoneMutationImpl(zoneService, zoneView); + } + + @Test + public void updateStatusWithEntityStatusEnabled() { + ReflectionTestUtils.setField(zoneMutation, "entityStatusEnabled", true); + ZoneKeyInput key = getZoneInputKey(); + Optional zone = Optional.of(getZone(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(zoneView.get(any())).thenReturn(zone); + when(zoneService.updateStatus(any(), any())).thenReturn(zone); + + Zone result = zoneMutation.updateStatus(key, statusInput); + + verify(zoneView, times(1)).get(key.asZoneKey()); + verify(zoneService, times(1)).updateStatus(zone.get(), statusInput.asStatus()); + assertEquals(zone.get(), result); + } + + @Test + public void updateStatusWithEntityStatusDisabled() { + ReflectionTestUtils.setField(zoneMutation, "entityStatusEnabled", false); + ZoneKeyInput key = getZoneInputKey(); + Optional zone = Optional.of(getZone(key)); + StatusInput statusInput = InputHelper.statusInput(); + + when(zoneView.get(any())).thenReturn(zone); + + Zone result = zoneMutation.updateStatus(key, statusInput); + + verify(zoneView, times(1)).get(key.asZoneKey()); + verify(zoneService, never()).updateStatus(zone.get(), statusInput.asStatus()); + assertEquals(zone.get(), result); + } + + private ZoneKeyInput getZoneInputKey() { + return ZoneKeyInput.builder() + .name("zone") + .build(); + } + + private Zone getZone(ZoneKeyInput key) { + return new Zone(key.asZoneKey(), StateHelper.specification(), StateHelper.status()); + } +} diff --git a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Consumer.java b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Consumer.java index 673b0cc20..3cf47932b 100644 --- a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Consumer.java +++ b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Consumer.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2020 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,4 +28,10 @@ public class Consumer implements Entity { private ConsumerKey key; private Specification specification; private Status status; + + public Consumer(ConsumerKey key, Specification specification) { + this.key = key; + this.specification = specification; + this.status = new Status(); + } } diff --git a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/ConsumerBinding.java b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/ConsumerBinding.java index 8402abe3b..9c6bd1bcc 100644 --- a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/ConsumerBinding.java +++ b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/ConsumerBinding.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2020 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,4 +28,10 @@ public class ConsumerBinding implements Entity { private ConsumerBindingKey key; private Specification specification; private Status status; + + public ConsumerBinding(ConsumerBindingKey key, Specification specification) { + this.key = key; + this.specification = specification; + this.status = new Status(); + } } diff --git a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Domain.java b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Domain.java index edc76751a..b138bdca9 100644 --- a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Domain.java +++ b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Domain.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2020 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,4 +28,10 @@ public class Domain implements Entity { private DomainKey key; private Specification specification; private Status status; + + public Domain(DomainKey key, Specification specification) { + this.key = key; + this.specification = specification; + this.status = new Status(); + } } diff --git a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Infrastructure.java b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Infrastructure.java index bb6358865..a96d2a476 100644 --- a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Infrastructure.java +++ b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Infrastructure.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2020 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,4 +28,10 @@ public class Infrastructure implements Entity { private InfrastructureKey key; private Specification specification; private Status status; + + public Infrastructure(InfrastructureKey key, Specification specification) { + this.key = key; + this.specification = specification; + this.status = new Status(); + } } diff --git a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Process.java b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Process.java index 18923ba47..60d1f6bc0 100644 --- a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Process.java +++ b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Process.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2023 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,4 +34,19 @@ public class Process implements Entity { private List inputs; private List outputs; private Status status; + + public Process( + ProcessKey key, + Specification specification, + List zones, + List inputs, + List outputs + ) { + this.key = key; + this.specification = specification; + this.zones = zones; + this.inputs = inputs; + this.outputs = outputs; + this.status = new Status(); + } } diff --git a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/ProcessBinding.java b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/ProcessBinding.java index acc63a28b..aee4d4007 100644 --- a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/ProcessBinding.java +++ b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/ProcessBinding.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2023 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,4 +34,19 @@ public class ProcessBinding implements Entity { private List inputs; private List outputs; private Status status; + + public ProcessBinding( + ProcessBindingKey key, + Specification specification, + ZoneKey zone, + List inputs, + List outputs + ) { + this.key = key; + this.specification = specification; + this.zone = zone; + this.inputs = inputs; + this.outputs = outputs; + this.status = new Status(); + } } diff --git a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Producer.java b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Producer.java index f21f715fe..8ba87d759 100644 --- a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Producer.java +++ b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Producer.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2020 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,4 +28,10 @@ public class Producer implements Entity { private ProducerKey key; private Specification specification; private Status status; + + public Producer(ProducerKey key, Specification specification) { + this.key = key; + this.specification = specification; + this.status = new Status(); + } } diff --git a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/ProducerBinding.java b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/ProducerBinding.java index a01d09246..a5719c3dc 100644 --- a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/ProducerBinding.java +++ b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/ProducerBinding.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2020 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,4 +28,10 @@ public class ProducerBinding implements Entity { private ProducerBindingKey key; private Specification specification; private Status status; + + public ProducerBinding(ProducerBindingKey key, Specification specification) { + this.key = key; + this.specification = specification; + this.status = new Status(); + } } diff --git a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Schema.java b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Schema.java index 7e866b7ff..3edcb4539 100644 --- a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Schema.java +++ b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Schema.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2020 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,4 +28,10 @@ public class Schema implements Entity { private SchemaKey key; private Specification specification; private Status status; + + public Schema(SchemaKey key, Specification specification) { + this.key = key; + this.specification = specification; + this.status = new Status(); + } } diff --git a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Stream.java b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Stream.java index 3696e6716..d4d2813e8 100644 --- a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Stream.java +++ b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Stream.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2020 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,4 +31,11 @@ public class Stream implements Entity { private SchemaKey schemaKey; private Specification specification; private Status status; + + public Stream(StreamKey key, Specification specification, SchemaKey schemaKey) { + this.key = key; + this.specification = specification; + this.schemaKey = schemaKey; + this.status = new Status(); + } } diff --git a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/StreamBinding.java b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/StreamBinding.java index 01edd473e..0366fb063 100644 --- a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/StreamBinding.java +++ b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/StreamBinding.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2020 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,4 +28,10 @@ public class StreamBinding implements Entity { private StreamBindingKey key; private Specification specification; private Status status; + + public StreamBinding(StreamBindingKey key, Specification specification) { + this.key = key; + this.specification = specification; + this.status = new Status(); + } } diff --git a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Zone.java b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Zone.java index 68b5aa59e..2ca721819 100644 --- a/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Zone.java +++ b/model/src/main/java/com/expediagroup/streamplatform/streamregistry/model/Zone.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2020 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,4 +29,10 @@ public class Zone implements Entity { private ZoneKey key; private Specification specification; private Status status; + + public Zone(ZoneKey key, Specification specification) { + this.key = key; + this.specification = specification; + this.status = new Status(); + } } diff --git a/repository/api/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/Repository.java b/repository/api/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/Repository.java index b27368a74..85e0b7732 100644 --- a/repository/api/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/Repository.java +++ b/repository/api/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/Repository.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2021 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,16 @@ import java.util.Optional; public interface Repository { + /** + * @deprecated Use {link {@link #saveSpecification(Object)}} or {link {@link #saveStatus(Object)}} + * to save the entity specification or entity status independently. + */ T save(T entity); + T saveSpecification(T entity); + + T saveStatus(T entity); + Optional findById(ID id); List findAll(); diff --git a/repository/kafka/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/DefaultRepository.java b/repository/kafka/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/DefaultRepository.java index 684c4073f..f7793de0a 100644 --- a/repository/kafka/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/DefaultRepository.java +++ b/repository/kafka/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/DefaultRepository.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2023 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,9 +48,18 @@ abstract class DefaultRepository< private final Converter converter; private final Class stateKeyClass; - //TODO deprecate - split specification from status so they are saveable separately. + /** + * @deprecated Use {link {@link #saveSpecification(com.expediagroup.streamplatform.streamregistry.model.Entity)}} or + * {link {@link #saveStatus(com.expediagroup.streamplatform.streamregistry.model.Entity)}} + * to save the entity specification or entity status independently. + */ @Override public ME save(ME entity) { + throw new UnsupportedOperationException(); + } + + @Override + public ME saveSpecification(ME entity) { Optional existing = findById(entity.getKey()); Entity stateEntity = converter.convertEntity(entity); List> futures = new ArrayList<>(); @@ -59,14 +68,27 @@ public ME save(ME entity) { if (!existingStateEntity.getSpecification().equals(stateEntity.getSpecification())) { send(Event.specification(stateEntity.getKey(), stateEntity.getSpecification()), futures); } + } else { + send(Event.specification(stateEntity.getKey(), stateEntity.getSpecification()), futures); + } + futures.forEach(CompletableFuture::join); + return entity; + } + + @Override + public ME saveStatus(ME entity) { + Optional existing = findById(entity.getKey()); + Entity stateEntity = converter.convertEntity(entity); + List> futures = new ArrayList<>(); + if (existing.isPresent()) { + Entity existingStateEntity = converter.convertEntity(existing.get()); for (StatusEntry entry : stateEntity.getStatus().getEntries()) { if (existingStateEntity.getStatus().getNames().contains(entry.getName()) - && !entry.getValue().equals(existingStateEntity.getStatus().getValue(entry.getName()))) { + && !entry.getValue().equals(existingStateEntity.getStatus().getValue(entry.getName()))) { send(Event.status(stateEntity.getKey(), entry), futures); } } } else { - send(Event.specification(stateEntity.getKey(), stateEntity.getSpecification()), futures); for (StatusEntry entry : stateEntity.getStatus().getEntries()) { send(Event.status(stateEntity.getKey(), entry), futures); } @@ -95,7 +117,7 @@ public List findAll() { @Override public List findAll(ME example) { - //This is only used by ProducerBinding and ConsumerBinding + // This is only used by ProducerBinding and ConsumerBinding throw new UnsupportedOperationException(); } @@ -103,9 +125,7 @@ public List findAll(ME example) { public void delete(ME entity) { List> futures = new ArrayList<>(); Entity stateEntity = converter.convertEntity(entity); - stateEntity.getStatus().getEntries().stream().forEach( e -> { - send(Event.statusDeletion(stateEntity.getKey(), e.getName()), futures); - }); + stateEntity.getStatus().getEntries().forEach(e -> send(Event.statusDeletion(stateEntity.getKey(), e.getName()), futures)); send(Event.specificationDeletion(stateEntity.getKey()), futures); futures.forEach(CompletableFuture::join); } diff --git a/repository/kafka/src/test/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/DefaultRepositoryTest.java b/repository/kafka/src/test/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/DefaultRepositoryTest.java index c7c08a840..d270e0ffc 100644 --- a/repository/kafka/src/test/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/DefaultRepositoryTest.java +++ b/repository/kafka/src/test/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/DefaultRepositoryTest.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2020 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,80 +63,73 @@ public void before() { } @Test - public void saveExistingSpecificationAndStatus() { + public void saveExistingSpecificationOnly() { Entity domain = SampleState.domain(); domain = domain.withSpecification(domain.getSpecification().withDescription("old description")); - domain = domain.withStatus(new DefaultStatus().with(new StatusEntry("agentStatus", mapper - .createObjectNode().put("foo", "bar")))); when(view.get(SampleState.domainKey())).thenReturn(Optional.of(domain)); when(sender.send(any(SpecificationEvent.class))).thenReturn(completedFuture(null)); - when(sender.send(any(StatusEvent.class))).thenReturn(completedFuture(null)); - Domain result = underTest.save(SampleModel.domain()); + Domain result = underTest.saveSpecification(SampleModel.domain()); assertThat(result, is(SampleModel.domain())); Entity expected = SampleState.domain(); verify(sender).send(Event.specification(expected.getKey(), expected.getSpecification())); - verify(sender).send(Event.status(expected.getKey(), new StatusEntry("agentStatus", mapper.createObjectNode()))); + verify(sender, never()).send(Event.status(expected.getKey(), new StatusEntry("agentStatus", mapper.createObjectNode()))); } @Test - public void saveExistingSpecificationOnly() { + public void saveExistingStatusOnly() { Entity domain = SampleState.domain(); - domain = domain.withSpecification(domain.getSpecification().withDescription("old description")); + domain = domain.withStatus(new DefaultStatus().with(new StatusEntry("agentStatus", mapper + .createObjectNode().put("foo", "bar")))); when(view.get(SampleState.domainKey())).thenReturn(Optional.of(domain)); - when(sender.send(any(SpecificationEvent.class))).thenReturn(completedFuture(null)); + when(sender.send(any(StatusEvent.class))).thenReturn(completedFuture(null)); - Domain result = underTest.save(SampleModel.domain()); + Domain result = underTest.saveStatus(SampleModel.domain()); assertThat(result, is(SampleModel.domain())); Entity expected = SampleState.domain(); - verify(sender).send(Event.specification(expected.getKey(), expected.getSpecification())); - verify(sender, never()).send(Event.status(expected.getKey(), new StatusEntry("agentStatus", mapper.createObjectNode()))); + verify(sender, never()).send(Event.specification(expected.getKey(), expected.getSpecification())); + verify(sender).send(Event.status(expected.getKey(), new StatusEntry("agentStatus", mapper.createObjectNode()))); } @Test - public void saveExistingStatusOnly() { - Entity domain = SampleState.domain(); - domain = domain.withStatus(new DefaultStatus().with(new StatusEntry("agentStatus", mapper - .createObjectNode().put("foo", "bar")))); - - when(view.get(SampleState.domainKey())).thenReturn(Optional.of(domain)); + public void saveNewSpecification() { + when(view.get(SampleState.domainKey())).thenReturn(Optional.empty()); - when(sender.send(any(StatusEvent.class))).thenReturn(completedFuture(null)); + when(sender.send(any(SpecificationEvent.class))).thenReturn(completedFuture(null)); - Domain result = underTest.save(SampleModel.domain()); + Domain result = underTest.saveSpecification(SampleModel.domain()); assertThat(result, is(SampleModel.domain())); Entity expected = SampleState.domain(); - verify(sender, never()).send(Event.specification(expected.getKey(), expected.getSpecification())); - verify(sender).send(Event.status(expected.getKey(), new StatusEntry("agentStatus", mapper.createObjectNode()))); + verify(sender).send(Event.specification(expected.getKey(), expected.getSpecification())); + verify(sender, never()).send(Event.status(expected.getKey(), new StatusEntry("agentStatus", mapper.createObjectNode()))); } @Test - public void saveNewSpecificationAndStatus() { + public void saveNewEntityStatus() { when(view.get(SampleState.domainKey())).thenReturn(Optional.empty()); - when(sender.send(any(SpecificationEvent.class))).thenReturn(completedFuture(null)); when(sender.send(any(StatusEvent.class))).thenReturn(completedFuture(null)); - Domain result = underTest.save(SampleModel.domain()); + Domain result = underTest.saveStatus(SampleModel.domain()); assertThat(result, is(SampleModel.domain())); Entity expected = SampleState.domain(); - verify(sender).send(Event.specification(expected.getKey(), expected.getSpecification())); + verify(sender, never()).send(Event.specification(expected.getKey(), expected.getSpecification())); verify(sender).send(Event.status(expected.getKey(), new StatusEntry("agentStatus", mapper.createObjectNode()))); } diff --git a/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityView.java b/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityView.java index d87c1c516..1d913de76 100644 --- a/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityView.java +++ b/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityView.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2023 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,10 +47,19 @@ public class DefaultEntityView implements EntityView { this(receiver, entities, new DefaultEntityViewUpdater(entities)); } + DefaultEntityView(EventReceiver receiver, Map, StateValue> entities, Boolean entityStatusEnabled) { + this(receiver, entities, new DefaultEntityViewUpdater(entities, entityStatusEnabled)); + } + + public DefaultEntityView(EventReceiver receiver, Boolean entityStatusEnabled) { + this(receiver, new ConcurrentHashMap<>(), entityStatusEnabled); + } + public DefaultEntityView(EventReceiver receiver) { this(receiver, new ConcurrentHashMap<>()); } + @Override public CompletableFuture load(@NonNull EntityViewListener listener) { val future = new CompletableFuture(); diff --git a/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdater.java b/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdater.java index 0f4c18a81..5e20a0984 100644 --- a/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdater.java +++ b/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdater.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2023 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import java.util.Map; import java.util.Optional; +import lombok.AllArgsConstructor; import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -37,9 +38,11 @@ @Slf4j @RequiredArgsConstructor +@AllArgsConstructor class DefaultEntityViewUpdater implements EntityViewUpdater { @NonNull private final Map, StateValue> entities; + private Boolean entityStatusEnabled = true; @Override public , S extends Specification> Entity update(Event event) { @@ -80,6 +83,12 @@ private , S extends Specification> Entity update(S private , S extends Specification> Entity update(StatusEvent event) { val oldEntity = (Entity) getExistingEntity(event.getKey()); + + if (!entityStatusEnabled) { + log.warn("Entity Status is disabled and is not persisted for key={}", event.getKey()); + return oldEntity; + } + if (oldEntity == null) { log.info("Received status {} non existent entity {}", event.getStatusEntry().getName(), event.getKey()); return null; diff --git a/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/EntityViews.java b/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/EntityViews.java index e6ea2d321..de530fd99 100644 --- a/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/EntityViews.java +++ b/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/EntityViews.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2023 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,12 +41,22 @@ public static EntityView defaultEntityView(EventReceiver receiver) { return new DefaultEntityView(receiver); } + @NonNull + public static EntityView defaultEntityView(EventReceiver receiver, Boolean entityStatusEnabled) { + return new DefaultEntityView(receiver, entityStatusEnabled); + } + @NonNull public static EntityView meteredEntityView(EventReceiver receiver, MeterRegistry meterRegistry) { + return meteredEntityView(receiver, meterRegistry, true); + } + + @NonNull + public static EntityView meteredEntityView(EventReceiver receiver, MeterRegistry meterRegistry, Boolean entityStatusEnabled) { Map, StateValue> entities = new ConcurrentHashMap<>(); meterRegistry.gaugeMapSize("stream_registry_state.view.entities", Tags.empty(), entities); - DefaultEntityViewUpdater defaultEntityViewUpdater = new DefaultEntityViewUpdater(entities); + DefaultEntityViewUpdater defaultEntityViewUpdater = new DefaultEntityViewUpdater(entities, entityStatusEnabled); return new DefaultEntityView(receiver, entities, new MeteredEntityViewUpdater(defaultEntityViewUpdater, meterRegistry)); } diff --git a/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdaterTest.java b/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdaterTest.java index 2f0af068f..e39c9caa0 100644 --- a/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdaterTest.java +++ b/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdaterTest.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2023 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,20 @@ */ package com.expediagroup.streamplatform.streamregistry.state; +import static com.expediagroup.streamplatform.streamregistry.state.SampleEntities.*; +import static com.expediagroup.streamplatform.streamregistry.state.SampleEntities.statusEvent; +import static com.expediagroup.streamplatform.streamregistry.state.StateValue.existing; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.hamcrest.collection.IsMapWithSize.aMapWithSize; +import static org.junit.Assert.*; + import java.util.Map; +import lombok.val; + +import org.junit.Test; + import com.expediagroup.streamplatform.streamregistry.state.model.Entity; public class DefaultEntityViewUpdaterTest extends EntityViewUpdaterTest { @@ -24,4 +36,32 @@ public class DefaultEntityViewUpdaterTest extends EntityViewUpdaterTest { public EntityViewUpdater entityViewUpdater(Map, StateValue> entities) { return new DefaultEntityViewUpdater(entities); } + + @Test + public void statusNotPersistedForExistingEntityWhenEntityStatusDisabled() { + EntityViewUpdater updater = new DefaultEntityViewUpdater(entities, false); + + entities.put(key, existing(oldEntity)); + val result = updater.update(statusEvent); + + assertEquals(oldEntity, result); + assertEquals(oldStatus, entities.get(key).entity.getStatus()); + } + + @Test + public void statusNotPersistedForMissingEntityWhenEntityStatusDisabled() { + EntityViewUpdater updater = new DefaultEntityViewUpdater(entities, false); + + val result = updater.update(statusEvent); + + assertNull(result); + } + + @Test + public void statusNoEntity() { + val result = underTest.update(statusEvent); + + assertThat(result, is(nullValue())); + assertThat(entities, is(aMapWithSize(0))); + } } diff --git a/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/EntityViewUpdaterTest.java b/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/EntityViewUpdaterTest.java index 81728394e..bf9e914fc 100644 --- a/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/EntityViewUpdaterTest.java +++ b/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/EntityViewUpdaterTest.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2023 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,11 +49,11 @@ public abstract class EntityViewUpdaterTest { - private final Map, StateValue> entities = new HashMap<>(); + final Map, StateValue> entities = new HashMap<>(); private final DefaultSpecification oldSpecification = specification.withDescription("old-description"); - private final DefaultStatus oldStatus = new DefaultStatus(); - private final Entity oldEntity = entity + final DefaultStatus oldStatus = new DefaultStatus(); + final Entity oldEntity = entity .withSpecification(oldSpecification) .withStatus(oldStatus); diff --git a/state/kafka-receiver/src/main/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventReceiver.java b/state/kafka-receiver/src/main/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventReceiver.java index 77205eafe..ac31554c7 100644 --- a/state/kafka-receiver/src/main/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventReceiver.java +++ b/state/kafka-receiver/src/main/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventReceiver.java @@ -58,6 +58,7 @@ import com.expediagroup.streamplatform.streamregistry.state.avro.AvroKey; import com.expediagroup.streamplatform.streamregistry.state.avro.AvroValue; import com.expediagroup.streamplatform.streamregistry.state.internal.EventCorrelator; +import com.expediagroup.streamplatform.streamregistry.state.model.event.StatusEvent; @Slf4j @RequiredArgsConstructor(access = PACKAGE) @@ -79,30 +80,51 @@ public class KafkaEventReceiver implements EventReceiver { private final KafkaConsumer consumer; @NonNull private final ScheduledExecutorService executorService; + @NonNull + private final Boolean entityStatusEnabled; + private final AtomicReference state = new AtomicReference<>(CREATED); private volatile boolean shuttingDown = false; private final AtomicBoolean started = new AtomicBoolean(false); - public KafkaEventReceiver(Config config, EventCorrelator correlator, Configurator> consumerConfigurator) { + public KafkaEventReceiver( + Config config, + EventCorrelator correlator, + Configurator> consumerConfigurator, + Boolean entityStatusEnabled + ) { this( config, correlator, new AvroConverter(), getKafkaConsumer(config, consumerConfigurator), - newScheduledThreadPool(THREAD_POOL_SIZE) + newScheduledThreadPool(THREAD_POOL_SIZE), + entityStatusEnabled ); } + public KafkaEventReceiver(Config config, EventCorrelator correlator, Configurator> consumerConfigurator) { + this(config, correlator, consumerConfigurator, true); + } + public KafkaEventReceiver(Config config, EventCorrelator correlator) { - this(config, correlator, kafkaConsumer -> { - }); + this(config, correlator, true); + } + + public KafkaEventReceiver(Config config, EventCorrelator correlator, Boolean entityStatusEnabled) { + this(config, correlator, kafkaConsumer -> {}, entityStatusEnabled); } public KafkaEventReceiver(Config config) { - this(config, null); + this(config, null, true); } + public KafkaEventReceiver(Config config, Boolean entityStatusEnabled) { + this(config, null, entityStatusEnabled); + } + + private static KafkaConsumer getKafkaConsumer(Config config, Configurator> consumerConfigurator) { KafkaConsumer kafkaConsumer = new KafkaConsumer<>(consumerConfig(config)); consumerConfigurator.configure(kafkaConsumer); @@ -158,7 +180,11 @@ void consume(EventReceiverListener listener) { val event = converter.toModel(record.key(), record.value()); currentOffset.set(record.offset()); try { - listener.onEvent(event); + if (event instanceof StatusEvent && !entityStatusEnabled) { + log.warn("Entity Status is disabled and will not trigger onEvent key={}", event.getKey()); + } else { + listener.onEvent(event); + } } catch (Exception e) { log.error("Listener failed for event {}", event, e); } diff --git a/state/kafka-receiver/src/test/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventReceiverTest.java b/state/kafka-receiver/src/test/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventReceiverTest.java index f4b8be91a..6fafdd336 100644 --- a/state/kafka-receiver/src/test/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventReceiverTest.java +++ b/state/kafka-receiver/src/test/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventReceiverTest.java @@ -69,6 +69,8 @@ import com.expediagroup.streamplatform.streamregistry.state.kafka.KafkaEventReceiver.Config; import com.expediagroup.streamplatform.streamregistry.state.model.Entity; import com.expediagroup.streamplatform.streamregistry.state.model.event.Event; +import com.expediagroup.streamplatform.streamregistry.state.model.event.SpecificationEvent; +import com.expediagroup.streamplatform.streamregistry.state.model.event.StatusEvent; import com.expediagroup.streamplatform.streamregistry.state.model.specification.Specification; @RunWith(MockitoJUnitRunner.Silent.class) @@ -92,7 +94,9 @@ public class KafkaEventReceiverTest { @Mock private AvroValue avroValue; @Mock - private Event event; + private SpecificationEvent event; + @Mock + private StatusEvent statusEvent; private final ScheduledExecutorService executorService = newScheduledThreadPool(2); @@ -105,7 +109,7 @@ public class KafkaEventReceiverTest { @Before public void before() { - underTest = new KafkaEventReceiver(config, correlator, converter, consumer, executorService); + underTest = new KafkaEventReceiver(config, correlator, converter, consumer, executorService, true); } @Test @@ -139,6 +143,72 @@ public void typical() throws Exception { inOrder.verify(correlator).received("foo"); } + @Test + public void receiverDoesNotCallOnEventForStatusEventWhenEventStatusDisabled() throws Exception { + val receiver = new KafkaEventReceiver(config, correlator, converter, consumer, executorService, false); + + when(config.getTopic()).thenReturn(topic); + when(consumer.partitionsFor(topic)).thenReturn(Collections.singletonList(partitionInfo)); + when(consumer.beginningOffsets(topicPartitions)).thenReturn(Collections.singletonMap(topicPartition, 0L)); + when(consumer.endOffsets(topicPartitions)).thenReturn(Collections.singletonMap(topicPartition, 0L)); + when(consumer.poll(Duration.ofMillis(100))).thenReturn(new ConsumerRecords<>(Collections.singletonMap(topicPartition, Collections.singletonList(record)))); + when(record.key()).thenReturn(avroKey); + when(record.value()).thenReturn(avroValue); + when(converter.toModel(avroKey, avroValue)).thenReturn(statusEvent); + when(record.headers()).thenReturn(new RecordHeaders(Collections.singletonList(new RecordHeader(CORRELATION_ID, "foo".getBytes(UTF_8))))); + val latch = new CountDownLatch(1); + doAnswer((correlationId) -> { + latch.countDown(); + return null; + }).when(correlator).received(anyString()); + + receiver.receive(listener); + assertThat(receiver.getState(), is(RUNNING)); + latch.await(1, SECONDS); + receiver.close(); + assertThat(receiver.getState(), is(NOT_RUNNING)); + + val inOrder = Mockito.inOrder(consumer, listener, correlator); + inOrder.verify(consumer).assign(topicPartitions); + inOrder.verify(consumer).seekToBeginning(topicPartitions); + inOrder.verify(listener).onEvent(LOAD_COMPLETE); + inOrder.verify(listener, never()).onEvent(statusEvent); + inOrder.verify(correlator).received("foo"); + } + + @Test + public void receiverCallsOnEventForSpecieficationEventWhenEventStatusDisabled() throws Exception { + val receiver = new KafkaEventReceiver(config, correlator, converter, consumer, executorService, false); + + when(config.getTopic()).thenReturn(topic); + when(consumer.partitionsFor(topic)).thenReturn(Collections.singletonList(partitionInfo)); + when(consumer.beginningOffsets(topicPartitions)).thenReturn(Collections.singletonMap(topicPartition, 0L)); + when(consumer.endOffsets(topicPartitions)).thenReturn(Collections.singletonMap(topicPartition, 0L)); + when(consumer.poll(Duration.ofMillis(100))).thenReturn(new ConsumerRecords<>(Collections.singletonMap(topicPartition, Collections.singletonList(record)))); + when(record.key()).thenReturn(avroKey); + when(record.value()).thenReturn(avroValue); + when(converter.toModel(avroKey, avroValue)).thenReturn(event); + when(record.headers()).thenReturn(new RecordHeaders(Collections.singletonList(new RecordHeader(CORRELATION_ID, "foo".getBytes(UTF_8))))); + val latch = new CountDownLatch(1); + doAnswer((correlationId) -> { + latch.countDown(); + return null; + }).when(correlator).received(anyString()); + + receiver.receive(listener); + assertThat(receiver.getState(), is(RUNNING)); + latch.await(1, SECONDS); + receiver.close(); + assertThat(receiver.getState(), is(NOT_RUNNING)); + + val inOrder = Mockito.inOrder(consumer, listener, correlator); + inOrder.verify(consumer).assign(topicPartitions); + inOrder.verify(consumer).seekToBeginning(topicPartitions); + inOrder.verify(listener).onEvent(LOAD_COMPLETE); + inOrder.verify(listener).onEvent(event); + inOrder.verify(correlator).received("foo"); + } + @Test public void listenerThrowsException() throws Exception { when(config.getTopic()).thenReturn(topic); From f57bd21ec4e10240ed2a9cf006210a90647bebbe Mon Sep 17 00:00:00 2001 From: Andy Kruth Date: Tue, 11 Jun 2024 09:19:19 -0400 Subject: [PATCH 2/9] touchup of deprecation annotation and Entity convenience constructor --- .../repository/kafka/DefaultRepository.java | 1 + .../streamregistry/state/model/Entity.java | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/repository/kafka/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/DefaultRepository.java b/repository/kafka/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/DefaultRepository.java index f7793de0a..7c963f14c 100644 --- a/repository/kafka/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/DefaultRepository.java +++ b/repository/kafka/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/DefaultRepository.java @@ -53,6 +53,7 @@ abstract class DefaultRepository< * {link {@link #saveStatus(com.expediagroup.streamplatform.streamregistry.model.Entity)}} * to save the entity specification or entity status independently. */ + @Deprecated @Override public ME save(ME entity) { throw new UnsupportedOperationException(); diff --git a/state/api/src/main/java/com/expediagroup/streamplatform/streamregistry/state/model/Entity.java b/state/api/src/main/java/com/expediagroup/streamplatform/streamregistry/state/model/Entity.java index 7a109d145..38057b4b9 100644 --- a/state/api/src/main/java/com/expediagroup/streamplatform/streamregistry/state/model/Entity.java +++ b/state/api/src/main/java/com/expediagroup/streamplatform/streamregistry/state/model/Entity.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2021 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ */ package com.expediagroup.streamplatform.streamregistry.state.model; +import lombok.AllArgsConstructor; import lombok.NonNull; import lombok.Value; import lombok.With; @@ -24,9 +25,11 @@ import com.expediagroup.streamplatform.streamregistry.state.model.specification.ProcessSpecification; import com.expediagroup.streamplatform.streamregistry.state.model.specification.Specification; import com.expediagroup.streamplatform.streamregistry.state.model.specification.StreamSpecification; +import com.expediagroup.streamplatform.streamregistry.state.model.status.DefaultStatus; import com.expediagroup.streamplatform.streamregistry.state.model.status.Status; @Value +@AllArgsConstructor public class Entity, S extends Specification> { @NonNull K key; @With @@ -34,6 +37,12 @@ public class Entity, S extends Specification> { @With @NonNull Status status; + public Entity(K key, S specification) { + this.key = key; + this.specification = specification; + this.status = new DefaultStatus(); + } + public interface Key {} @Value From aa4d928a4359375ee6470046a59a8da72bd4f81a Mon Sep 17 00:00:00 2001 From: Andy Kruth Date: Thu, 13 Jun 2024 09:13:54 -0400 Subject: [PATCH 3/9] adding entity status toggle to KafkaEventSender --- .../repository/kafka/KafkaConfiguration.java | 6 +- .../state/kafka/KafkaEventReceiver.java | 38 +---- .../state/kafka/KafkaEventReceiverTest.java | 141 ++++++++---------- .../state/kafka/KafkaEventSender.java | 10 +- .../state/kafka/KafkaEventSenderTest.java | 86 ++++++++++- 5 files changed, 166 insertions(+), 115 deletions(-) diff --git a/repository/kafka/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/KafkaConfiguration.java b/repository/kafka/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/KafkaConfiguration.java index 33fe9a372..aa1bc1be2 100644 --- a/repository/kafka/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/KafkaConfiguration.java +++ b/repository/kafka/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/KafkaConfiguration.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2023 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,6 +49,7 @@ EventSender eventSender( @Value("${repository.kafka.topic:_streamregistry}") String topic, @Value("${repository.kafka.schemaRegistryUrl}") String schemaRegistryUrl, @Value("${repository.kafka.propertiesPath:}") String propertiesPath, + @Value("${repository.kafka.entity.status.enabled:true}") Boolean entityStatusEnabled, EventCorrelator eventCorrelator ) { KafkaEventSender.Config config = KafkaEventSender.Config.builder() @@ -56,6 +57,7 @@ EventSender eventSender( .topic(topic) .schemaRegistryUrl(schemaRegistryUrl) .properties(readPropertiesFile(propertiesPath)) + .entityStatusEnabled(entityStatusEnabled) .build(); return new KafkaEventSender(config, eventCorrelator); } @@ -67,6 +69,7 @@ EventReceiver eventReceiver( @Value("${repository.kafka.groupId:stream-registry}") String groupId, @Value("${repository.kafka.schemaRegistryUrl}") String schemaRegistryUrl, @Value("${repository.kafka.propertiesPath:}") String propertiesPath, + @Value("${repository.kafka.entity.status.enabled:true}") Boolean entityStatusEnabled, EventCorrelator eventCorrelator ) { KafkaEventReceiver.Config receiverConfig = KafkaEventReceiver.Config.builder() @@ -75,6 +78,7 @@ EventReceiver eventReceiver( .groupId(groupId) .schemaRegistryUrl(schemaRegistryUrl) .properties(readPropertiesFile(propertiesPath)) + .entityStatusEnabled(entityStatusEnabled) .build(); return new KafkaEventReceiver(receiverConfig, eventCorrelator); } diff --git a/state/kafka-receiver/src/main/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventReceiver.java b/state/kafka-receiver/src/main/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventReceiver.java index ac31554c7..cb6749cfa 100644 --- a/state/kafka-receiver/src/main/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventReceiver.java +++ b/state/kafka-receiver/src/main/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventReceiver.java @@ -38,12 +38,8 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.atomic.*; -import lombok.Builder; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.Value; +import lombok.*; import lombok.extern.slf4j.Slf4j; -import lombok.val; import io.confluent.kafka.serializers.KafkaAvroDeserializer; @@ -58,6 +54,7 @@ import com.expediagroup.streamplatform.streamregistry.state.avro.AvroKey; import com.expediagroup.streamplatform.streamregistry.state.avro.AvroValue; import com.expediagroup.streamplatform.streamregistry.state.internal.EventCorrelator; +import com.expediagroup.streamplatform.streamregistry.state.model.event.StatusDeletionEvent; import com.expediagroup.streamplatform.streamregistry.state.model.event.StatusEvent; @Slf4j @@ -80,48 +77,28 @@ public class KafkaEventReceiver implements EventReceiver { private final KafkaConsumer consumer; @NonNull private final ScheduledExecutorService executorService; - @NonNull - private final Boolean entityStatusEnabled; private final AtomicReference state = new AtomicReference<>(CREATED); private volatile boolean shuttingDown = false; private final AtomicBoolean started = new AtomicBoolean(false); - public KafkaEventReceiver( - Config config, - EventCorrelator correlator, - Configurator> consumerConfigurator, - Boolean entityStatusEnabled - ) { + public KafkaEventReceiver(Config config, EventCorrelator correlator, Configurator> consumerConfigurator) { this( config, correlator, new AvroConverter(), getKafkaConsumer(config, consumerConfigurator), - newScheduledThreadPool(THREAD_POOL_SIZE), - entityStatusEnabled + newScheduledThreadPool(THREAD_POOL_SIZE) ); } - public KafkaEventReceiver(Config config, EventCorrelator correlator, Configurator> consumerConfigurator) { - this(config, correlator, consumerConfigurator, true); - } - public KafkaEventReceiver(Config config, EventCorrelator correlator) { - this(config, correlator, true); - } - - public KafkaEventReceiver(Config config, EventCorrelator correlator, Boolean entityStatusEnabled) { - this(config, correlator, kafkaConsumer -> {}, entityStatusEnabled); + this(config, correlator, kafkaConsumer -> {}); } public KafkaEventReceiver(Config config) { - this(config, null, true); - } - - public KafkaEventReceiver(Config config, Boolean entityStatusEnabled) { - this(config, null, entityStatusEnabled); + this(config, null); } @@ -180,7 +157,7 @@ void consume(EventReceiverListener listener) { val event = converter.toModel(record.key(), record.value()); currentOffset.set(record.offset()); try { - if (event instanceof StatusEvent && !entityStatusEnabled) { + if (!config.getEntityStatusEnabled() && (event instanceof StatusEvent || event instanceof StatusDeletionEvent)) { log.warn("Entity Status is disabled and will not trigger onEvent key={}", event.getKey()); } else { listener.onEvent(event); @@ -249,6 +226,7 @@ public static class Config { @NonNull String schemaRegistryUrl; @NonNull String groupId; Map properties; + @Builder.Default Boolean entityStatusEnabled = true; } public enum State { diff --git a/state/kafka-receiver/src/test/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventReceiverTest.java b/state/kafka-receiver/src/test/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventReceiverTest.java index 6fafdd336..8e485efbf 100644 --- a/state/kafka-receiver/src/test/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventReceiverTest.java +++ b/state/kafka-receiver/src/test/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventReceiverTest.java @@ -68,9 +68,7 @@ import com.expediagroup.streamplatform.streamregistry.state.internal.EventCorrelator; import com.expediagroup.streamplatform.streamregistry.state.kafka.KafkaEventReceiver.Config; import com.expediagroup.streamplatform.streamregistry.state.model.Entity; -import com.expediagroup.streamplatform.streamregistry.state.model.event.Event; -import com.expediagroup.streamplatform.streamregistry.state.model.event.SpecificationEvent; -import com.expediagroup.streamplatform.streamregistry.state.model.event.StatusEvent; +import com.expediagroup.streamplatform.streamregistry.state.model.event.*; import com.expediagroup.streamplatform.streamregistry.state.model.specification.Specification; @RunWith(MockitoJUnitRunner.Silent.class) @@ -96,7 +94,11 @@ public class KafkaEventReceiverTest { @Mock private SpecificationEvent event; @Mock + private SpecificationDeletionEvent deletionEvent; + @Mock private StatusEvent statusEvent; + @Mock + private StatusDeletionEvent statusDeletionEvent; private final ScheduledExecutorService executorService = newScheduledThreadPool(2); @@ -106,15 +108,12 @@ public class KafkaEventReceiverTest { private final TopicPartition topicPartition = new TopicPartition(topic, 0); private final List topicPartitions = Collections.singletonList(topicPartition); private final ConditionFactory await = Awaitility.await().atMost(2, SECONDS); + private CountDownLatch latch = new CountDownLatch(1); @Before public void before() { - underTest = new KafkaEventReceiver(config, correlator, converter, consumer, executorService, true); - } - - @Test - public void typical() throws Exception { when(config.getTopic()).thenReturn(topic); + when(config.getEntityStatusEnabled()).thenReturn(true); when(consumer.partitionsFor(topic)).thenReturn(Collections.singletonList(partitionInfo)); when(consumer.beginningOffsets(topicPartitions)).thenReturn(Collections.singletonMap(topicPartition, 0L)); when(consumer.endOffsets(topicPartitions)).thenReturn(Collections.singletonMap(topicPartition, 0L)); @@ -123,12 +122,18 @@ public void typical() throws Exception { when(record.value()).thenReturn(avroValue); when(converter.toModel(avroKey, avroValue)).thenReturn(event); when(record.headers()).thenReturn(new RecordHeaders(Collections.singletonList(new RecordHeader(CORRELATION_ID, "foo".getBytes(UTF_8))))); - val latch = new CountDownLatch(1); + + latch = new CountDownLatch(1); doAnswer((correlationId) -> { latch.countDown(); return null; }).when(correlator).received(anyString()); + underTest = new KafkaEventReceiver(config, correlator, converter, consumer, executorService); + } + + @Test + public void typical() throws Exception { underTest.receive(listener); assertThat(underTest.getState(), is(RUNNING)); latch.await(1, SECONDS); @@ -145,28 +150,14 @@ public void typical() throws Exception { @Test public void receiverDoesNotCallOnEventForStatusEventWhenEventStatusDisabled() throws Exception { - val receiver = new KafkaEventReceiver(config, correlator, converter, consumer, executorService, false); - - when(config.getTopic()).thenReturn(topic); - when(consumer.partitionsFor(topic)).thenReturn(Collections.singletonList(partitionInfo)); - when(consumer.beginningOffsets(topicPartitions)).thenReturn(Collections.singletonMap(topicPartition, 0L)); - when(consumer.endOffsets(topicPartitions)).thenReturn(Collections.singletonMap(topicPartition, 0L)); - when(consumer.poll(Duration.ofMillis(100))).thenReturn(new ConsumerRecords<>(Collections.singletonMap(topicPartition, Collections.singletonList(record)))); - when(record.key()).thenReturn(avroKey); - when(record.value()).thenReturn(avroValue); + when(config.getEntityStatusEnabled()).thenReturn(false); when(converter.toModel(avroKey, avroValue)).thenReturn(statusEvent); - when(record.headers()).thenReturn(new RecordHeaders(Collections.singletonList(new RecordHeader(CORRELATION_ID, "foo".getBytes(UTF_8))))); - val latch = new CountDownLatch(1); - doAnswer((correlationId) -> { - latch.countDown(); - return null; - }).when(correlator).received(anyString()); - receiver.receive(listener); - assertThat(receiver.getState(), is(RUNNING)); + underTest.receive(listener); + assertThat(underTest.getState(), is(RUNNING)); latch.await(1, SECONDS); - receiver.close(); - assertThat(receiver.getState(), is(NOT_RUNNING)); + underTest.close(); + assertThat(underTest.getState(), is(NOT_RUNNING)); val inOrder = Mockito.inOrder(consumer, listener, correlator); inOrder.verify(consumer).assign(topicPartitions); @@ -177,29 +168,34 @@ public void receiverDoesNotCallOnEventForStatusEventWhenEventStatusDisabled() th } @Test - public void receiverCallsOnEventForSpecieficationEventWhenEventStatusDisabled() throws Exception { - val receiver = new KafkaEventReceiver(config, correlator, converter, consumer, executorService, false); + public void receiverDoesNotCallOnEventForStatusDeletionEventWhenEventStatusDisabled() throws Exception { + when(config.getEntityStatusEnabled()).thenReturn(false); + when(converter.toModel(avroKey, avroValue)).thenReturn(statusDeletionEvent); - when(config.getTopic()).thenReturn(topic); - when(consumer.partitionsFor(topic)).thenReturn(Collections.singletonList(partitionInfo)); - when(consumer.beginningOffsets(topicPartitions)).thenReturn(Collections.singletonMap(topicPartition, 0L)); - when(consumer.endOffsets(topicPartitions)).thenReturn(Collections.singletonMap(topicPartition, 0L)); - when(consumer.poll(Duration.ofMillis(100))).thenReturn(new ConsumerRecords<>(Collections.singletonMap(topicPartition, Collections.singletonList(record)))); - when(record.key()).thenReturn(avroKey); - when(record.value()).thenReturn(avroValue); + underTest.receive(listener); + assertThat(underTest.getState(), is(RUNNING)); + latch.await(1, SECONDS); + underTest.close(); + assertThat(underTest.getState(), is(NOT_RUNNING)); + + val inOrder = Mockito.inOrder(consumer, listener, correlator); + inOrder.verify(consumer).assign(topicPartitions); + inOrder.verify(consumer).seekToBeginning(topicPartitions); + inOrder.verify(listener).onEvent(LOAD_COMPLETE); + inOrder.verify(listener, never()).onEvent(statusDeletionEvent); + inOrder.verify(correlator).received("foo"); + } + + @Test + public void receiverCallsOnEventForSpecificationEventWhenEventStatusDisabled() throws Exception { + when(config.getEntityStatusEnabled()).thenReturn(false); when(converter.toModel(avroKey, avroValue)).thenReturn(event); - when(record.headers()).thenReturn(new RecordHeaders(Collections.singletonList(new RecordHeader(CORRELATION_ID, "foo".getBytes(UTF_8))))); - val latch = new CountDownLatch(1); - doAnswer((correlationId) -> { - latch.countDown(); - return null; - }).when(correlator).received(anyString()); - receiver.receive(listener); - assertThat(receiver.getState(), is(RUNNING)); + underTest.receive(listener); + assertThat(underTest.getState(), is(RUNNING)); latch.await(1, SECONDS); - receiver.close(); - assertThat(receiver.getState(), is(NOT_RUNNING)); + underTest.close(); + assertThat(underTest.getState(), is(NOT_RUNNING)); val inOrder = Mockito.inOrder(consumer, listener, correlator); inOrder.verify(consumer).assign(topicPartitions); @@ -209,23 +205,28 @@ public void receiverCallsOnEventForSpecieficationEventWhenEventStatusDisabled() inOrder.verify(correlator).received("foo"); } + @Test + public void receiverCallsOnEventForDeletionEventWhenEventStatusDisabled() throws Exception { + when(config.getEntityStatusEnabled()).thenReturn(false); + when(converter.toModel(avroKey, avroValue)).thenReturn(deletionEvent); + + underTest.receive(listener); + assertThat(underTest.getState(), is(RUNNING)); + latch.await(1, SECONDS); + underTest.close(); + assertThat(underTest.getState(), is(NOT_RUNNING)); + + val inOrder = Mockito.inOrder(consumer, listener, correlator); + inOrder.verify(consumer).assign(topicPartitions); + inOrder.verify(consumer).seekToBeginning(topicPartitions); + inOrder.verify(listener).onEvent(LOAD_COMPLETE); + inOrder.verify(listener).onEvent(deletionEvent); + inOrder.verify(correlator).received("foo"); + } + @Test public void listenerThrowsException() throws Exception { - when(config.getTopic()).thenReturn(topic); - when(consumer.partitionsFor(topic)).thenReturn(Collections.singletonList(partitionInfo)); - when(consumer.beginningOffsets(topicPartitions)).thenReturn(Collections.singletonMap(topicPartition, 0L)); - when(consumer.endOffsets(topicPartitions)).thenReturn(Collections.singletonMap(topicPartition, 0L)); - when(consumer.poll(Duration.ofMillis(100))).thenReturn(new ConsumerRecords<>(Collections.singletonMap(topicPartition, Collections.singletonList(record)))); - when(record.key()).thenReturn(avroKey); - when(record.value()).thenReturn(avroValue); - when(converter.toModel(avroKey, avroValue)).thenReturn(event); - when(record.headers()).thenReturn(new RecordHeaders(Collections.singletonList(new RecordHeader(CORRELATION_ID, "foo".getBytes(UTF_8))))); doThrow(new RuntimeException("listener error")).when(listener).onEvent(event); - val latch = new CountDownLatch(1); - doAnswer((correlationId) -> { - latch.countDown(); - return null; - }).when(correlator).received(anyString()); underTest.receive(listener); latch.await(1, SECONDS); @@ -243,7 +244,6 @@ public void listenerThrowsException() throws Exception { @Test public void errorWhenMoreThanOnePartition() { - when(config.getTopic()).thenReturn(topic); val multiplePartitions = new ArrayList() {{ add(partitionInfo); add(partitionInfo); @@ -261,10 +261,6 @@ public void errorWhenMoreThanOnePartition() { @Test public void errorWhenRunningButUnableToPoll() throws Exception { val polls = new AtomicInteger(0); - when(config.getTopic()).thenReturn(topic); - when(consumer.partitionsFor(topic)).thenReturn(Collections.singletonList(partitionInfo)); - when(consumer.beginningOffsets(topicPartitions)).thenReturn(Collections.singletonMap(topicPartition, 0L)); - when(consumer.endOffsets(topicPartitions)).thenReturn(Collections.singletonMap(topicPartition, 0L)); when(consumer.poll(Duration.ofMillis(100))).thenAnswer(invocation -> { if (polls.getAndIncrement() < 10) { return new ConsumerRecords<>(Collections.singletonMap(topicPartition, Collections.singletonList(record))); @@ -272,19 +268,10 @@ public void errorWhenRunningButUnableToPoll() throws Exception { throw new RuntimeException("Some Kafka poll error here"); } }); - when(record.key()).thenReturn(avroKey); - when(record.value()).thenReturn(avroValue); - when(converter.toModel(avroKey, avroValue)).thenReturn(event); - when(record.headers()).thenReturn(new RecordHeaders(Collections.singletonList(new RecordHeader(CORRELATION_ID, "foo".getBytes(UTF_8))))); - val latch = new CountDownLatch(1); - doAnswer((correlationId) -> { - assertThat(underTest.getState(), is(RUNNING)); - latch.countDown(); - return null; - }).when(correlator).received(anyString()); underTest.receive(listener); latch.await(1, SECONDS); + assertThat(underTest.getState(), is(RUNNING)); val inOrder = Mockito.inOrder(consumer, listener, correlator); inOrder.verify(consumer).assign(topicPartitions); @@ -327,7 +314,7 @@ public void propertiesToConfigMapping() { put("ssl.truststore.password", "password"); put("ssl.endpoint.identification.algorithm", ""); }}; - Config config = new Config("bootstrap", "topic", "schemaRegistry", "groupId", properties); + Config config = new Config("bootstrap", "topic", "schemaRegistry", "groupId", properties, true); Map expected = new HashMap() {{ put(BOOTSTRAP_SERVERS_CONFIG, "bootstrap"); diff --git a/state/kafka-sender/src/main/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventSender.java b/state/kafka-sender/src/main/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventSender.java index 9bb217142..46a54682d 100644 --- a/state/kafka-sender/src/main/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventSender.java +++ b/state/kafka-sender/src/main/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventSender.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2023 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,6 +53,8 @@ import com.expediagroup.streamplatform.streamregistry.state.internal.EventCorrelator; import com.expediagroup.streamplatform.streamregistry.state.model.Entity; import com.expediagroup.streamplatform.streamregistry.state.model.event.Event; +import com.expediagroup.streamplatform.streamregistry.state.model.event.StatusDeletionEvent; +import com.expediagroup.streamplatform.streamregistry.state.model.event.StatusEvent; import com.expediagroup.streamplatform.streamregistry.state.model.specification.Specification; @Slf4j @@ -88,6 +90,11 @@ private static KafkaProducer getKafkaProducer(Config config, @Override public , S extends Specification> CompletableFuture send(@NonNull Event event) { + if (!config.getEntityStatusEnabled() && (event instanceof StatusEvent || event instanceof StatusDeletionEvent)) { + log.warn("Entity Status is disabled and will not send event with key={}", event.getKey()); + return CompletableFuture.completedFuture(null); + } + val avroEvent = converter.toAvro(event); return send(avroEvent.getKey(), avroEvent.getValue()); } @@ -190,5 +197,6 @@ public static class Config { @NonNull String topic; @NonNull String schemaRegistryUrl; Map properties; + @Builder.Default Boolean entityStatusEnabled = true; } } diff --git a/state/kafka-sender/src/test/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventSenderTest.java b/state/kafka-sender/src/test/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventSenderTest.java index 6cf8c626d..629780973 100644 --- a/state/kafka-sender/src/test/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventSenderTest.java +++ b/state/kafka-sender/src/test/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventSenderTest.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2022 Expedia, Inc. + * Copyright (C) 2018-2024 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,11 +22,9 @@ import static org.apache.kafka.clients.producer.ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.*; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import java.util.Arrays; import java.util.Collections; @@ -50,6 +48,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; import com.expediagroup.streamplatform.streamregistry.state.avro.AvroConverter; @@ -64,6 +63,7 @@ import com.expediagroup.streamplatform.streamregistry.state.model.event.Event; import com.expediagroup.streamplatform.streamregistry.state.model.specification.DefaultSpecification; import com.expediagroup.streamplatform.streamregistry.state.model.specification.Principal; +import com.expediagroup.streamplatform.streamregistry.state.model.status.StatusEntry; @RunWith(MockitoJUnitRunner.class) public class KafkaEventSenderTest { @@ -79,6 +79,8 @@ public class KafkaEventSenderTest { }}; private final DefaultSpecification specification = new DefaultSpecification("description", Collections.emptyList(), "type", mapper.createObjectNode(), security, "function"); private final Event event = Event.specification(key, specification); + private final Event deleteEvent = Event.specificationDeletion(key); + private final StatusEntry statusEntry = new StatusEntry("status", mapper.createObjectNode()); @Mock private AvroEvent avroEvent; @Mock private AvroKey avroKey; @@ -89,10 +91,82 @@ public class KafkaEventSenderTest { @Before public void before() { + Mockito.reset(producer, config); when(converter.toAvro(event)).thenReturn(avroEvent); when(avroEvent.getKey()).thenReturn(avroKey); when(avroEvent.getValue()).thenReturn(avroValue); when(config.getTopic()).thenReturn("topic"); + when(config.getEntityStatusEnabled()).thenReturn(true); + } + + @Test + public void entityStatusDisabledDoesNotSendStatus() { + when(config.getEntityStatusEnabled()).thenReturn(false); + + val underTest = new KafkaEventSender(config, new NullCorrelationStrategy(), converter, producer); + val statusEvent = Event.status(key, statusEntry); + val result = underTest.send(statusEvent); + + verify(producer, never()).send(any(), any()); + + assertTrue(result.isDone()); + } + + @Test + public void entityStatusDisabledDoesNotSendStatusDelete() { + when(config.getEntityStatusEnabled()).thenReturn(false); + + val underTest = new KafkaEventSender(config, new NullCorrelationStrategy(), converter, producer); + val statusDeleteEvent = Event.statusDeletion(key, "delete"); + val result = underTest.send(statusDeleteEvent); + + verify(producer, never()).send(any(), any()); + + assertTrue(result.isDone()); + } + + @Test + public void entityStatusDisabledSendsEntitySpecification() { + val underTest = new KafkaEventSender(config, new NullCorrelationStrategy(), converter, producer); + val result = underTest.send(event); + + verify(producer).send(recordCaptor.capture(), callbackCaptor.capture()); + + val record = recordCaptor.getValue(); + assertThat(record.topic(), is("topic")); + assertThat(record.key(), is(avroKey)); + assertThat(record.value(), is(avroValue)); + assertThat(record.headers().toArray().length, is(0)); + + val callback = callbackCaptor.getValue(); + assertThat(result.isDone(), is(false)); + val recordMetadata = mock(RecordMetadata.class); + callback.onCompletion(recordMetadata, null); + assertThat(result.isDone(), is(true)); + } + + @Test + public void entityStatusDisabledSendsEntityDeletion() { + when(config.getEntityStatusEnabled()).thenReturn(false); + when(converter.toAvro(deleteEvent)).thenReturn(avroEvent); + when(avroEvent.getValue()).thenReturn(null); + + val underTest = new KafkaEventSender(config, new NullCorrelationStrategy(), converter, producer); + val result = underTest.send(deleteEvent); + + verify(producer).send(recordCaptor.capture(), callbackCaptor.capture()); + + val record = recordCaptor.getValue(); + assertThat(record.topic(), is("topic")); + assertThat(record.key(), is(avroKey)); + assertNull(record.value()); + assertThat(record.headers().toArray().length, is(0)); + + val callback = callbackCaptor.getValue(); + assertThat(result.isDone(), is(false)); + val recordMetadata = mock(RecordMetadata.class); + callback.onCompletion(recordMetadata, null); + assertThat(result.isDone(), is(true)); } @Test @@ -201,7 +275,7 @@ public void propertiesToConfigMapping() { put("ssl.truststore.password", "password"); put("ssl.endpoint.identification.algorithm", ""); }}; - Config config = new Config("bootstrap", "topic", "schemaRegistry", properties); + Config config = new Config("bootstrap", "topic", "schemaRegistry", properties, true); Map expected = new HashMap() {{ put(BOOTSTRAP_SERVERS_CONFIG, "bootstrap"); From 39426f3eae782be665e2cae7f01b64b6e3d197cb Mon Sep 17 00:00:00 2001 From: Andy Kruth Date: Thu, 13 Jun 2024 09:17:24 -0400 Subject: [PATCH 4/9] removing unnecessary mutation impl changes --- .../impl/ConsumerBindingMutationImpl.java | 10 +- .../mutation/impl/ConsumerMutationImpl.java | 10 +- .../mutation/impl/DomainMutationImpl.java | 11 +- .../impl/InfrastructureMutationImpl.java | 11 +- .../impl/ProcessBindingMutationImpl.java | 11 +- .../mutation/impl/ProcessMutationImpl.java | 11 +- .../impl/ProducerBindingMutationImpl.java | 10 +- .../mutation/impl/ProducerMutationImpl.java | 10 +- .../mutation/impl/SchemaMutationImpl.java | 11 +- .../impl/StreamBindingMutationImpl.java | 10 +- .../mutation/impl/StreamMutationImpl.java | 10 +- .../mutation/impl/ZoneMutationImpl.java | 11 +- .../impl/ConsumerBindingMutationImplTest.java | 40 +------ .../impl/ConsumerMutationImplTest.java | 40 +------ .../mutation/impl/DomainMutationImplTest.java | 97 ---------------- .../impl/InfrastructureMutationImplTest.java | 98 ---------------- .../impl/ProcessBindingMutationImplTest.java | 108 ------------------ .../impl/ProcessMutationImplTest.java | 107 ----------------- .../impl/ProducerBindingMutationImplTest.java | 50 ++------ .../impl/ProducerMutationImplTest.java | 40 +------ .../mutation/impl/SchemaMutationImplTest.java | 98 ---------------- .../impl/StreamBindingMutationImplTest.java | 46 +------- .../mutation/impl/StreamMutationImplTest.java | 40 +------ .../mutation/impl/ZoneMutationImplTest.java | 97 ---------------- 24 files changed, 38 insertions(+), 949 deletions(-) delete mode 100644 graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/DomainMutationImplTest.java delete mode 100644 graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/InfrastructureMutationImplTest.java delete mode 100644 graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessBindingMutationImplTest.java delete mode 100644 graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessMutationImplTest.java delete mode 100644 graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/SchemaMutationImplTest.java delete mode 100644 graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ZoneMutationImplTest.java diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerBindingMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerBindingMutationImpl.java index d44cb39e9..fdb18920a 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerBindingMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerBindingMutationImpl.java @@ -43,9 +43,6 @@ public class ConsumerBindingMutationImpl implements ConsumerBindingMutation { @Value("${entityView.exist.check.enabled:true}") private boolean checkExistEnabled; - @Value("${stream-registry.entity.status.enabled:true}") - private boolean entityStatusEnabled; - @Override public ConsumerBinding insert(ConsumerBindingKeyInput key, SpecificationInput specification) { return consumerBindingService.create(asConsumerBinding(key, specification)).get(); @@ -80,12 +77,7 @@ public Boolean delete(ConsumerBindingKeyInput key) { @Override public ConsumerBinding updateStatus(ConsumerBindingKeyInput key, StatusInput status) { ConsumerBinding consumerBinding = consumerBindingView.get(key.asConsumerBindingKey()).get(); - - if (entityStatusEnabled) { - return consumerBindingService.updateStatus(consumerBinding, status.asStatus()).get(); - } else { - return consumerBinding; - } + return consumerBindingService.updateStatus(consumerBinding, status.asStatus()).get(); } private ConsumerBinding asConsumerBinding(ConsumerBindingKeyInput key, SpecificationInput specification) { diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerMutationImpl.java index 20e8bcd40..523b9ead3 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerMutationImpl.java @@ -43,9 +43,6 @@ public class ConsumerMutationImpl implements ConsumerMutation { @Value("${entityView.exist.check.enabled:true}") private boolean checkExistEnabled; - @Value("${stream-registry.entity.status.enabled:true}") - private boolean entityStatusEnabled; - @Override public Consumer insert(ConsumerKeyInput key, SpecificationInput specification) { return consumerService.create(asConsumer(key, specification)).get(); @@ -80,12 +77,7 @@ public Boolean delete(ConsumerKeyInput key) { @Override public Consumer updateStatus(ConsumerKeyInput key, StatusInput status) { Consumer consumer = consumerView.get(key.asConsumerKey()).get(); - - if (entityStatusEnabled) { - return consumerService.updateStatus(consumer, status.asStatus()).get(); - } else { - return consumer; - } + return consumerService.updateStatus(consumer, status.asStatus()).get(); } private Consumer asConsumer(ConsumerKeyInput key, SpecificationInput specification) { diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/DomainMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/DomainMutationImpl.java index 9e4b75151..bfa8df993 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/DomainMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/DomainMutationImpl.java @@ -19,7 +19,6 @@ import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import com.expediagroup.streamplatform.streamregistry.core.services.DomainService; @@ -37,9 +36,6 @@ public class DomainMutationImpl implements DomainMutation { private final DomainService domainService; private final DomainView domainView; - @Value("${stream-registry.entity.status.enabled:true}") - private boolean entityStatusEnabled; - @Override public Domain insert(DomainKeyInput key, SpecificationInput specification) { return domainService.create(asDomain(key, specification)).get(); @@ -69,12 +65,7 @@ public Boolean delete(DomainKeyInput key) { @Override public Domain updateStatus(DomainKeyInput key, StatusInput status) { Domain domain = domainView.get(key.asDomainKey()).get(); - - if (entityStatusEnabled) { - return domainService.updateStatus(domain, status.asStatus()).get(); - } else { - return domain; - } + return domainService.updateStatus(domain, status.asStatus()).get(); } private Domain asDomain(DomainKeyInput key, SpecificationInput specification) { diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/InfrastructureMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/InfrastructureMutationImpl.java index eb89a7d83..c8f0cfd6e 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/InfrastructureMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/InfrastructureMutationImpl.java @@ -19,7 +19,6 @@ import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import com.expediagroup.streamplatform.streamregistry.core.services.InfrastructureService; @@ -37,9 +36,6 @@ public class InfrastructureMutationImpl implements InfrastructureMutation { private final InfrastructureService infrastructureService; private final InfrastructureView infrastructureView; - @Value("${stream-registry.entity.status.enabled:true}") - private boolean entityStatusEnabled; - @Override public Infrastructure insert(InfrastructureKeyInput key, SpecificationInput specification) { return infrastructureService.create(asInfrastructure(key, specification)).get(); @@ -69,12 +65,7 @@ public Boolean delete(InfrastructureKeyInput key) { @Override public Infrastructure updateStatus(InfrastructureKeyInput key, StatusInput status) { Infrastructure infrastructure = infrastructureView.get(key.asInfrastructureKey()).get(); - - if (entityStatusEnabled) { - return infrastructureService.updateStatus(infrastructure, status.asStatus()).get(); - } else { - return infrastructure; - } + return infrastructureService.updateStatus(infrastructure, status.asStatus()).get(); } private Infrastructure asInfrastructure(InfrastructureKeyInput key, SpecificationInput specification) { diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessBindingMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessBindingMutationImpl.java index eeace2ddc..8d6febce8 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessBindingMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessBindingMutationImpl.java @@ -22,7 +22,6 @@ import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import com.expediagroup.streamplatform.streamregistry.core.services.ProcessBindingService; @@ -37,9 +36,6 @@ public class ProcessBindingMutationImpl implements ProcessBindingMutation { private final ProcessBindingService processBindingService; private final ProcessBindingView processBindingView; - @Value("${stream-registry.entity.status.enabled:true}") - private boolean entityStatusEnabled; - @Override public ProcessBinding insert(ProcessBindingKeyInput key, SpecificationInput specification, ZoneKeyInput zone, List inputs, List outputs) { @@ -72,12 +68,7 @@ public Boolean delete(ProcessBindingKeyInput key) { @Override public ProcessBinding updateStatus(ProcessBindingKeyInput key, StatusInput status) { ProcessBinding processBinding = processBindingView.get(key.asProcessBindingKey()).get(); - - if (entityStatusEnabled) { - return processBindingService.updateStatus(processBinding, status.asStatus()).get(); - } else { - return processBinding; - } + return processBindingService.updateStatus(processBinding, status.asStatus()).get(); } private ProcessBinding asProcessBinding(ProcessBindingKeyInput key, SpecificationInput specification, diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessMutationImpl.java index ad239023f..9890ecb7c 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessMutationImpl.java @@ -22,7 +22,6 @@ import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import com.expediagroup.streamplatform.streamregistry.core.services.ProcessService; @@ -37,9 +36,6 @@ public class ProcessMutationImpl implements ProcessMutation { private final ProcessService processService; private final ProcessView processView; - @Value("${stream-registry.entity.status.enabled:true}") - private boolean entityStatusEnabled; - @Override public Process insert(ProcessKeyInput key, SpecificationInput specification, List zones, List inputs, List outputs) { @@ -72,12 +68,7 @@ public Boolean delete(ProcessKeyInput key) { @Override public Process updateStatus(ProcessKeyInput key, StatusInput status) { Process stream = processView.get(key.asProcessKey()).get(); - - if (entityStatusEnabled) { - return processService.updateStatus(stream, status.asStatus()).get(); - } else { - return stream; - } + return processService.updateStatus(stream, status.asStatus()).get(); } private Process asProcess(ProcessKeyInput key, SpecificationInput specification, diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerBindingMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerBindingMutationImpl.java index 830790a27..f56e7bea5 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerBindingMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerBindingMutationImpl.java @@ -40,9 +40,6 @@ public class ProducerBindingMutationImpl implements ProducerBindingMutation { @Value("${entityView.exist.check.enabled:true}") private boolean checkExistEnabled; - @Value("${stream-registry.entity.status.enabled:true}") - private boolean entityStatusEnabled; - private final ProducerBindingService producerBindingService; private final ProducerBindingView producerBindingView; @@ -80,12 +77,7 @@ public Boolean delete(ProducerBindingKeyInput key) { @Override public ProducerBinding updateStatus(ProducerBindingKeyInput key, StatusInput status) { ProducerBinding producerBinding = producerBindingView.get(key.asProducerBindingKey()).get(); - - if (entityStatusEnabled) { - return producerBindingService.updateStatus(producerBinding, status.asStatus()).get(); - } else { - return producerBinding; - } + return producerBindingService.updateStatus(producerBinding, status.asStatus()).get(); } private ProducerBinding asProducerBinding(ProducerBindingKeyInput key, SpecificationInput specification) { diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerMutationImpl.java index e48ffd201..9b175c0bb 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerMutationImpl.java @@ -40,9 +40,6 @@ public class ProducerMutationImpl implements ProducerMutation { @Value("${entityView.exist.check.enabled:true}") private boolean checkExistEnabled; - @Value("${stream-registry.entity.status.enabled:true}") - private boolean entityStatusEnabled; - private final ProducerService producerService; private final ProducerView producerView; @@ -80,12 +77,7 @@ public Boolean delete(ProducerKeyInput key) { @Override public Producer updateStatus(ProducerKeyInput key, StatusInput status) { Producer producer = producerView.get(key.asProducerKey()).get(); - - if (entityStatusEnabled) { - return producerService.updateStatus(producer, status.asStatus()).get(); - } else { - return producer; - } + return producerService.updateStatus(producer, status.asStatus()).get(); } private Producer asProducer(ProducerKeyInput key, SpecificationInput specification) { diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/SchemaMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/SchemaMutationImpl.java index 3998da1ea..c40e48dd5 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/SchemaMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/SchemaMutationImpl.java @@ -19,7 +19,6 @@ import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import com.expediagroup.streamplatform.streamregistry.core.services.SchemaService; @@ -37,9 +36,6 @@ public class SchemaMutationImpl implements SchemaMutation { private final SchemaService schemaService; private final SchemaView schemaView; - @Value("${stream-registry.entity.status.enabled:true}") - private boolean entityStatusEnabled; - @Override public Schema insert(SchemaKeyInput key, SpecificationInput specification) { return schemaService.create(asSchema(key, specification)).get(); @@ -68,12 +64,7 @@ public Boolean delete(SchemaKeyInput key) { @Override public Schema updateStatus(SchemaKeyInput key, StatusInput status) { Schema schema = schemaView.get(key.asSchemaKey()).get(); - - if (entityStatusEnabled) { - return schemaService.updateStatus(schema, status.asStatus()).get(); - } else { - return schema; - } + return schemaService.updateStatus(schema, status.asStatus()).get(); } private Schema asSchema(SchemaKeyInput key, SpecificationInput specification) { diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamBindingMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamBindingMutationImpl.java index 0e7e5ac8d..2d3c9612a 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamBindingMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamBindingMutationImpl.java @@ -40,9 +40,6 @@ public class StreamBindingMutationImpl implements StreamBindingMutation { @Value("${entityView.exist.check.enabled:true}") private boolean checkExistEnabled; - @Value("${stream-registry.entity.status.enabled:true}") - private boolean entityStatusEnabled; - private final StreamBindingService streamBindingService; private final StreamBindingView streamBindingView; @@ -80,12 +77,7 @@ public Boolean delete(StreamBindingKeyInput key) { @Override public StreamBinding updateStatus(StreamBindingKeyInput key, StatusInput status) { StreamBinding streamBinding = streamBindingView.get(key.asStreamBindingKey()).get(); - - if (entityStatusEnabled) { - return streamBindingService.updateStatus(streamBinding, status.asStatus()).get(); - } else { - return streamBinding; - } + return streamBindingService.updateStatus(streamBinding, status.asStatus()).get(); } private StreamBinding asStreamBinding(StreamBindingKeyInput key, SpecificationInput specification) { diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamMutationImpl.java index f33f76a7b..7a5d6a915 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamMutationImpl.java @@ -41,9 +41,6 @@ public class StreamMutationImpl implements StreamMutation { @Value("${entityView.exist.check.enabled:true}") private boolean checkExistEnabled; - @Value("${stream-registry.entity.status.enabled:true}") - private boolean entityStatusEnabled; - private final StreamService streamService; private final StreamView streamView; @@ -81,12 +78,7 @@ public Boolean delete(StreamKeyInput key) { @Override public Stream updateStatus(StreamKeyInput key, StatusInput status) { Stream stream = streamView.get(key.asStreamKey()).get(); - - if (entityStatusEnabled) { - return streamService.updateStatus(stream, status.asStatus()).get(); - } else { - return stream; - } + return streamService.updateStatus(stream, status.asStatus()).get(); } private Stream asStream(StreamKeyInput key, SpecificationInput specification, Optional schema) { diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ZoneMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ZoneMutationImpl.java index b92650aeb..97d9bcca7 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ZoneMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ZoneMutationImpl.java @@ -19,7 +19,6 @@ import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import com.expediagroup.streamplatform.streamregistry.core.services.ZoneService; @@ -36,9 +35,6 @@ public class ZoneMutationImpl implements ZoneMutation { private final ZoneService zoneService; private final ZoneView zoneView; - @Value("${stream-registry.entity.status.enabled:true}") - private boolean entityStatusEnabled; - @Override public Zone insert(ZoneKeyInput key, SpecificationInput specification) { return zoneService.create(asZone(key, specification)).get(); @@ -68,12 +64,7 @@ public Boolean delete(ZoneKeyInput key) { @Override public Zone updateStatus(ZoneKeyInput key, StatusInput status) { Zone zone = zoneView.get(key.asZoneKey()).get(); - - if (entityStatusEnabled) { - return zoneService.updateStatus(zone, status.asStatus()).get(); - } else { - return zone; - } + return zoneService.updateStatus(zone, status.asStatus()).get(); } private Zone asZone(ZoneKeyInput key, SpecificationInput specification) { diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerBindingMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerBindingMutationImplTest.java index b4c0e677b..eca57b713 100644 --- a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerBindingMutationImplTest.java +++ b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerBindingMutationImplTest.java @@ -15,10 +15,11 @@ */ package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.util.Optional; @@ -31,10 +32,8 @@ import com.expediagroup.streamplatform.streamregistry.core.services.ConsumerBindingService; import com.expediagroup.streamplatform.streamregistry.core.views.ConsumerBindingView; -import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.ConsumerBindingKeyInput; -import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; import com.expediagroup.streamplatform.streamregistry.model.ConsumerBinding; @RunWith(MockitoJUnitRunner.class) @@ -101,39 +100,6 @@ public void deleteWithCheckExistDisabledWhenEntityDoesNotExist() { assertTrue(result); } - @Test - public void updateStatusWithEntityStatusEnabled() { - ReflectionTestUtils.setField(consumerBindingMutation, "entityStatusEnabled", true); - ConsumerBindingKeyInput key = getConsumerBindingInputKey(); - Optional consumerBinding = Optional.of(getConsumer(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(consumerBindingView.get(any())).thenReturn(consumerBinding); - when(consumerBindingService.updateStatus(any(), any())).thenReturn(consumerBinding); - - ConsumerBinding result = consumerBindingMutation.updateStatus(key, statusInput); - - verify(consumerBindingView, times(1)).get(key.asConsumerBindingKey()); - verify(consumerBindingService, times(1)).updateStatus(consumerBinding.get(), statusInput.asStatus()); - assertEquals(consumerBinding.get(), result); - } - - @Test - public void updateStatusWithEntityStatusDisabled() { - ReflectionTestUtils.setField(consumerBindingMutation, "entityStatusEnabled", false); - ConsumerBindingKeyInput key = getConsumerBindingInputKey(); - Optional consumerBinding = Optional.of(getConsumer(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(consumerBindingView.get(any())).thenReturn(consumerBinding); - - ConsumerBinding result = consumerBindingMutation.updateStatus(key, statusInput); - - verify(consumerBindingView, times(1)).get(key.asConsumerBindingKey()); - verify(consumerBindingService, never()).updateStatus(consumerBinding.get(), statusInput.asStatus()); - assertEquals(consumerBinding.get(), result); - } - private ConsumerBindingKeyInput getConsumerBindingInputKey() { return ConsumerBindingKeyInput.builder() .streamDomain("domain") diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerMutationImplTest.java index 2c69bff2b..869e55239 100644 --- a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerMutationImplTest.java +++ b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ConsumerMutationImplTest.java @@ -15,10 +15,11 @@ */ package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.util.Optional; @@ -31,10 +32,8 @@ import com.expediagroup.streamplatform.streamregistry.core.services.ConsumerService; import com.expediagroup.streamplatform.streamregistry.core.views.ConsumerView; -import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.ConsumerKeyInput; -import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; import com.expediagroup.streamplatform.streamregistry.model.Consumer; @RunWith(MockitoJUnitRunner.class) @@ -97,39 +96,6 @@ public void deleteWithCheckExistDisabledWhenEntityDoesNotExist() { assertTrue(result); } - @Test - public void updateStatusWithEntityStatusEnabled() { - ReflectionTestUtils.setField(consumerMutation, "entityStatusEnabled", true); - ConsumerKeyInput key = getConsumerInputKey(); - Optional consumer = Optional.of(getConsumer(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(consumerView.get(any())).thenReturn(consumer); - when(consumerService.updateStatus(any(), any())).thenReturn(consumer); - - Consumer result = consumerMutation.updateStatus(key, statusInput); - - verify(consumerView, times(1)).get(key.asConsumerKey()); - verify(consumerService, times(1)).updateStatus(consumer.get(), statusInput.asStatus()); - assertEquals(consumer.get(), result); - } - - @Test - public void updateStatusWithEntityStatusDisabled() { - ReflectionTestUtils.setField(consumerMutation, "entityStatusEnabled", false); - ConsumerKeyInput key = getConsumerInputKey(); - Optional consumer = Optional.of(getConsumer(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(consumerView.get(any())).thenReturn(consumer); - - Consumer result = consumerMutation.updateStatus(key, statusInput); - - verify(consumerView, times(1)).get(key.asConsumerKey()); - verify(consumerService, never()).updateStatus(consumer.get(), statusInput.asStatus()); - assertEquals(consumer.get(), result); - } - private ConsumerKeyInput getConsumerInputKey() { return ConsumerKeyInput.builder() .streamDomain("domain") diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/DomainMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/DomainMutationImplTest.java deleted file mode 100644 index 1602ea571..000000000 --- a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/DomainMutationImplTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Copyright (C) 2018-2024 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; - -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; - -import java.util.Optional; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.test.util.ReflectionTestUtils; - -import com.expediagroup.streamplatform.streamregistry.core.services.DomainService; -import com.expediagroup.streamplatform.streamregistry.core.views.DomainView; -import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; -import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; -import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.DomainKeyInput; -import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; -import com.expediagroup.streamplatform.streamregistry.model.Domain; - -@RunWith(MockitoJUnitRunner.class) -public class DomainMutationImplTest { - - @Mock - private DomainService domainService; - - @Mock - private DomainView domainView; - - private DomainMutationImpl domainMutation; - - @Before - public void before() throws Exception { - domainMutation = new DomainMutationImpl(domainService, domainView); - } - - @Test - public void updateStatusWithEntityStatusEnabled() { - ReflectionTestUtils.setField(domainMutation, "entityStatusEnabled", true); - DomainKeyInput key = getDomainInputKey(); - Optional domain = Optional.of(getDomain(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(domainView.get(any())).thenReturn(domain); - when(domainService.updateStatus(any(), any())).thenReturn(domain); - - Domain result = domainMutation.updateStatus(key, statusInput); - - verify(domainView, times(1)).get(key.asDomainKey()); - verify(domainService, times(1)).updateStatus(domain.get(), statusInput.asStatus()); - assertEquals(domain.get(), result); - } - - @Test - public void updateStatusWithEntityStatusDisabled() { - ReflectionTestUtils.setField(domainMutation, "entityStatusEnabled", false); - DomainKeyInput key = getDomainInputKey(); - Optional domain = Optional.of(getDomain(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(domainView.get(any())).thenReturn(domain); - - Domain result = domainMutation.updateStatus(key, statusInput); - - verify(domainView, times(1)).get(key.asDomainKey()); - verify(domainService, never()).updateStatus(domain.get(), statusInput.asStatus()); - assertEquals(domain.get(), result); - } - - private DomainKeyInput getDomainInputKey() { - return DomainKeyInput.builder() - .name("domain") - .build(); - } - - private Domain getDomain(DomainKeyInput key) { - return new Domain(key.asDomainKey(), StateHelper.specification(), StateHelper.status()); - } -} diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/InfrastructureMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/InfrastructureMutationImplTest.java deleted file mode 100644 index 7b98eb3e2..000000000 --- a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/InfrastructureMutationImplTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/** - * Copyright (C) 2018-2024 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; - -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; - -import java.util.Optional; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.test.util.ReflectionTestUtils; - -import com.expediagroup.streamplatform.streamregistry.core.services.InfrastructureService; -import com.expediagroup.streamplatform.streamregistry.core.views.InfrastructureView; -import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; -import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; -import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.InfrastructureKeyInput; -import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; -import com.expediagroup.streamplatform.streamregistry.model.Infrastructure; - -@RunWith(MockitoJUnitRunner.class) -public class InfrastructureMutationImplTest { - - @Mock - private InfrastructureService infrastructureService; - - @Mock - private InfrastructureView infrastructureView; - - private InfrastructureMutationImpl infrastructureMutation; - - @Before - public void before() throws Exception { - infrastructureMutation = new InfrastructureMutationImpl(infrastructureService, infrastructureView); - } - - @Test - public void updateStatusWithEntityStatusEnabled() { - ReflectionTestUtils.setField(infrastructureMutation, "entityStatusEnabled", true); - InfrastructureKeyInput key = getInfrastructureInputKey(); - Optional infrastructure = Optional.of(getInfrastructure(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(infrastructureView.get(any())).thenReturn(infrastructure); - when(infrastructureService.updateStatus(any(), any())).thenReturn(infrastructure); - - Infrastructure result = infrastructureMutation.updateStatus(key, statusInput); - - verify(infrastructureView, times(1)).get(key.asInfrastructureKey()); - verify(infrastructureService, times(1)).updateStatus(infrastructure.get(), statusInput.asStatus()); - assertEquals(infrastructure.get(), result); - } - - @Test - public void updateStatusWithEntityStatusDisabled() { - ReflectionTestUtils.setField(infrastructureMutation, "entityStatusEnabled", false); - InfrastructureKeyInput key = getInfrastructureInputKey(); - Optional infrastructure = Optional.of(getInfrastructure(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(infrastructureView.get(any())).thenReturn(infrastructure); - - Infrastructure result = infrastructureMutation.updateStatus(key, statusInput); - - verify(infrastructureView, times(1)).get(key.asInfrastructureKey()); - verify(infrastructureService, never()).updateStatus(infrastructure.get(), statusInput.asStatus()); - assertEquals(infrastructure.get(), result); - } - - private InfrastructureKeyInput getInfrastructureInputKey() { - return InfrastructureKeyInput.builder() - .name("infrastructure") - .zone("zone") - .build(); - } - - private Infrastructure getInfrastructure(InfrastructureKeyInput key) { - return new Infrastructure(key.asInfrastructureKey(), StateHelper.specification(), StateHelper.status()); - } -} diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessBindingMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessBindingMutationImplTest.java deleted file mode 100644 index f2d1a263a..000000000 --- a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessBindingMutationImplTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Copyright (C) 2018-2024 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; - -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; - -import java.util.List; -import java.util.Optional; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.test.util.ReflectionTestUtils; - -import com.expediagroup.streamplatform.streamregistry.core.services.ProcessBindingService; -import com.expediagroup.streamplatform.streamregistry.core.views.ProcessBindingView; -import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; -import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; -import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.ProcessBindingKeyInput; -import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; -import com.expediagroup.streamplatform.streamregistry.model.ProcessBinding; -import com.expediagroup.streamplatform.streamregistry.model.keys.ZoneKey; - -@RunWith(MockitoJUnitRunner.class) -public class ProcessBindingMutationImplTest { - - @Mock - private ProcessBindingService processBindingService; - - @Mock - private ProcessBindingView processBindingView; - - private ProcessBindingMutationImpl processBindingMutation; - - @Before - public void before() throws Exception { - processBindingMutation = new ProcessBindingMutationImpl(processBindingService, processBindingView); - } - - @Test - public void updateStatusWithEntityStatusEnabled() { - ReflectionTestUtils.setField(processBindingMutation, "entityStatusEnabled", true); - ProcessBindingKeyInput key = getProcessBindingInputKey(); - Optional processBinding = Optional.of(getProcessBinding(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(processBindingView.get(any())).thenReturn(processBinding); - when(processBindingService.updateStatus(any(), any())).thenReturn(processBinding); - - ProcessBinding result = processBindingMutation.updateStatus(key, statusInput); - - verify(processBindingView, times(1)).get(key.asProcessBindingKey()); - verify(processBindingService, times(1)).updateStatus(processBinding.get(), statusInput.asStatus()); - assertEquals(processBinding.get(), result); - } - - @Test - public void updateStatusWithEntityStatusDisabled() { - ReflectionTestUtils.setField(processBindingMutation, "entityStatusEnabled", false); - ProcessBindingKeyInput key = getProcessBindingInputKey(); - Optional processBinding = Optional.of(getProcessBinding(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(processBindingView.get(any())).thenReturn(processBinding); - - ProcessBinding result = processBindingMutation.updateStatus(key, statusInput); - - verify(processBindingView, times(1)).get(key.asProcessBindingKey()); - verify(processBindingService, never()).updateStatus(processBinding.get(), statusInput.asStatus()); - assertEquals(processBinding.get(), result); - } - - private ProcessBindingKeyInput getProcessBindingInputKey() { - return ProcessBindingKeyInput.builder() - .domainName("domain") - .processName("process") - .infrastructureZone("zone") - .build(); - } - - private ProcessBinding getProcessBinding(ProcessBindingKeyInput key) { - return new ProcessBinding( - key.asProcessBindingKey(), - StateHelper.specification(), - new ZoneKey("zone"), - List.of(), - List.of(), - StateHelper.status() - ); - } -} diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessMutationImplTest.java deleted file mode 100644 index abd3a6112..000000000 --- a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessMutationImplTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * Copyright (C) 2018-2024 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; - -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; - -import java.util.List; -import java.util.Optional; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.test.util.ReflectionTestUtils; - -import com.expediagroup.streamplatform.streamregistry.core.services.ProcessService; -import com.expediagroup.streamplatform.streamregistry.core.views.ProcessView; -import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; -import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; -import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.ProcessKeyInput; -import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; -import com.expediagroup.streamplatform.streamregistry.model.Process; -import com.expediagroup.streamplatform.streamregistry.model.keys.ZoneKey; - -@RunWith(MockitoJUnitRunner.class) -public class ProcessMutationImplTest { - - @Mock - private ProcessService processService; - - @Mock - private ProcessView processView; - - private ProcessMutationImpl processMutation; - - @Before - public void before() throws Exception { - processMutation = new ProcessMutationImpl(processService, processView); - } - - @Test - public void updateStatusWithEntityStatusEnabled() { - ReflectionTestUtils.setField(processMutation, "entityStatusEnabled", true); - ProcessKeyInput key = getProcessInputKey(); - Optional process = Optional.of(getProcess(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(processView.get(any())).thenReturn(process); - when(processService.updateStatus(any(), any())).thenReturn(process); - - Process result = processMutation.updateStatus(key, statusInput); - - verify(processView, times(1)).get(key.asProcessKey()); - verify(processService, times(1)).updateStatus(process.get(), statusInput.asStatus()); - assertEquals(process.get(), result); - } - - @Test - public void updateStatusWithEntityStatusDisabled() { - ReflectionTestUtils.setField(processMutation, "entityStatusEnabled", false); - ProcessKeyInput key = getProcessInputKey(); - Optional process = Optional.of(getProcess(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(processView.get(any())).thenReturn(process); - - Process result = processMutation.updateStatus(key, statusInput); - - verify(processView, times(1)).get(key.asProcessKey()); - verify(processService, never()).updateStatus(process.get(), statusInput.asStatus()); - assertEquals(process.get(), result); - } - - private ProcessKeyInput getProcessInputKey() { - return ProcessKeyInput.builder() - .domain("domain") - .name("process") - .build(); - } - - private Process getProcess(ProcessKeyInput key) { - return new Process( - key.asProcessKey(), - StateHelper.specification(), - List.of(new ZoneKey("zone")), - List.of(), - List.of(), - StateHelper.status() - ); - } -} diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerBindingMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerBindingMutationImplTest.java index 451a3c3ee..c5f8d9868 100644 --- a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerBindingMutationImplTest.java +++ b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerBindingMutationImplTest.java @@ -15,10 +15,11 @@ */ package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.util.Optional; @@ -31,10 +32,8 @@ import com.expediagroup.streamplatform.streamregistry.core.services.ProducerBindingService; import com.expediagroup.streamplatform.streamregistry.core.views.ProducerBindingView; -import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.ProducerBindingKeyInput; -import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; import com.expediagroup.streamplatform.streamregistry.model.ProducerBinding; @RunWith(MockitoJUnitRunner.class) @@ -56,7 +55,7 @@ public void before() throws Exception { @Test public void deleteWithCheckExistEnabledWhenEntityExists() { ReflectionTestUtils.setField(producerBindingMutation, "checkExistEnabled", true); - ProducerBindingKeyInput key = getProducerBindingInputKey(); + ProducerBindingKeyInput key = getproducerBindingInputKey(); when(producerBindingView.get(any())).thenReturn(Optional.of(getProducer(key))); Boolean result = producerBindingMutation.delete(key); verify(producerBindingView, times(1)).get(key.asProducerBindingKey()); @@ -67,7 +66,7 @@ public void deleteWithCheckExistEnabledWhenEntityExists() { @Test public void deleteWithCheckExistEnabledWhenEntityDoesNotExist() { ReflectionTestUtils.setField(producerBindingMutation, "checkExistEnabled", true); - ProducerBindingKeyInput key = getProducerBindingInputKey(); + ProducerBindingKeyInput key = getproducerBindingInputKey(); when(producerBindingView.get(any())).thenReturn(Optional.empty()); Boolean result = producerBindingMutation.delete(key); verify(producerBindingView, times(1)).get(key.asProducerBindingKey()); @@ -78,7 +77,7 @@ public void deleteWithCheckExistEnabledWhenEntityDoesNotExist() { @Test public void deleteWithCheckExistDisabledWhenEntityExists() { ReflectionTestUtils.setField(producerBindingMutation, "checkExistEnabled", false); - ProducerBindingKeyInput key = getProducerBindingInputKey(); + ProducerBindingKeyInput key = getproducerBindingInputKey(); when(producerBindingView.get(any())).thenReturn(Optional.of(getProducer(key))); Boolean result = producerBindingMutation.delete(key); verify(producerBindingView, times(1)).get(key.asProducerBindingKey()); @@ -89,7 +88,7 @@ public void deleteWithCheckExistDisabledWhenEntityExists() { @Test public void deleteWithCheckExistDisabledWhenEntityDoesNotExist() { ReflectionTestUtils.setField(producerBindingMutation, "checkExistEnabled", false); - ProducerBindingKeyInput key = getProducerBindingInputKey(); + ProducerBindingKeyInput key = getproducerBindingInputKey(); when(producerBindingView.get(any())).thenReturn(Optional.empty()); Boolean result = producerBindingMutation.delete(key); verify(producerBindingView, times(1)).get(key.asProducerBindingKey()); @@ -97,40 +96,7 @@ public void deleteWithCheckExistDisabledWhenEntityDoesNotExist() { assertTrue(result); } - @Test - public void updateStatusWithEntityStatusEnabled() { - ReflectionTestUtils.setField(producerBindingMutation, "entityStatusEnabled", true); - ProducerBindingKeyInput key = getProducerBindingInputKey(); - Optional producerBinding = Optional.of(getProducer(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(producerBindingView.get(any())).thenReturn(producerBinding); - when(producerBindingService.updateStatus(any(), any())).thenReturn(producerBinding); - - ProducerBinding result = producerBindingMutation.updateStatus(key, statusInput); - - verify(producerBindingView, times(1)).get(key.asProducerBindingKey()); - verify(producerBindingService, times(1)).updateStatus(producerBinding.get(), statusInput.asStatus()); - assertEquals(producerBinding.get(), result); - } - - @Test - public void updateStatusWithEntityStatusDisabled() { - ReflectionTestUtils.setField(producerBindingMutation, "entityStatusEnabled", false); - ProducerBindingKeyInput key = getProducerBindingInputKey(); - Optional producerBinding = Optional.of(getProducer(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(producerBindingView.get(any())).thenReturn(producerBinding); - - ProducerBinding result = producerBindingMutation.updateStatus(key, statusInput); - - verify(producerBindingView, times(1)).get(key.asProducerBindingKey()); - verify(producerBindingService, never()).updateStatus(producerBinding.get(), statusInput.asStatus()); - assertEquals(producerBinding.get(), result); - } - - private ProducerBindingKeyInput getProducerBindingInputKey() { + private ProducerBindingKeyInput getproducerBindingInputKey() { return ProducerBindingKeyInput.builder() .streamDomain("domain") .streamName("stream") diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerMutationImplTest.java index 84b8255cc..aac8da2e3 100644 --- a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerMutationImplTest.java +++ b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProducerMutationImplTest.java @@ -15,10 +15,11 @@ */ package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.util.Optional; @@ -31,10 +32,8 @@ import com.expediagroup.streamplatform.streamregistry.core.services.ProducerService; import com.expediagroup.streamplatform.streamregistry.core.views.ProducerView; -import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.ProducerKeyInput; -import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; import com.expediagroup.streamplatform.streamregistry.model.Producer; @RunWith(MockitoJUnitRunner.class) @@ -99,39 +98,6 @@ public void deleteWithCheckExistDisabledWhenEntityDoesNotExist() { assertTrue(result); } - @Test - public void updateStatusWithEntityStatusEnabled() { - ReflectionTestUtils.setField(producerMutation, "entityStatusEnabled", true); - ProducerKeyInput key = getProducerInputKey(); - Optional producer = Optional.of(getProducer(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(producerView.get(any())).thenReturn(producer); - when(producerService.updateStatus(any(), any())).thenReturn(producer); - - Producer result = producerMutation.updateStatus(key, statusInput); - - verify(producerView, times(1)).get(key.asProducerKey()); - verify(producerService, times(1)).updateStatus(producer.get(), statusInput.asStatus()); - assertEquals(producer.get(), result); - } - - @Test - public void updateStatusWithEntityStatusDisabled() { - ReflectionTestUtils.setField(producerMutation, "entityStatusEnabled", false); - ProducerKeyInput key = getProducerInputKey(); - Optional producer = Optional.of(getProducer(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(producerView.get(any())).thenReturn(producer); - - Producer result = producerMutation.updateStatus(key, statusInput); - - verify(producerView, times(1)).get(key.asProducerKey()); - verify(producerService, never()).updateStatus(producer.get(), statusInput.asStatus()); - assertEquals(producer.get(), result); - } - private ProducerKeyInput getProducerInputKey() { return ProducerKeyInput.builder() .streamDomain("domain") diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/SchemaMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/SchemaMutationImplTest.java deleted file mode 100644 index ce6afb085..000000000 --- a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/SchemaMutationImplTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/** - * Copyright (C) 2018-2024 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; - -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; - -import java.util.Optional; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.test.util.ReflectionTestUtils; - -import com.expediagroup.streamplatform.streamregistry.core.services.SchemaService; -import com.expediagroup.streamplatform.streamregistry.core.views.SchemaView; -import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; -import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; -import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.SchemaKeyInput; -import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; -import com.expediagroup.streamplatform.streamregistry.model.Schema; - -@RunWith(MockitoJUnitRunner.class) -public class SchemaMutationImplTest { - - @Mock - private SchemaService schemaService; - - @Mock - private SchemaView schemaView; - - private SchemaMutationImpl schemaMutation; - - @Before - public void before() throws Exception { - schemaMutation = new SchemaMutationImpl(schemaService, schemaView); - } - - @Test - public void updateStatusWithEntityStatusEnabled() { - ReflectionTestUtils.setField(schemaMutation, "entityStatusEnabled", true); - SchemaKeyInput key = getSchemaInputKey(); - Optional schema = Optional.of(getSchema(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(schemaView.get(any())).thenReturn(schema); - when(schemaService.updateStatus(any(), any())).thenReturn(schema); - - Schema result = schemaMutation.updateStatus(key, statusInput); - - verify(schemaView, times(1)).get(key.asSchemaKey()); - verify(schemaService, times(1)).updateStatus(schema.get(), statusInput.asStatus()); - assertEquals(schema.get(), result); - } - - @Test - public void updateStatusWithEntityStatusDisabled() { - ReflectionTestUtils.setField(schemaMutation, "entityStatusEnabled", false); - SchemaKeyInput key = getSchemaInputKey(); - Optional schema = Optional.of(getSchema(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(schemaView.get(any())).thenReturn(schema); - - Schema result = schemaMutation.updateStatus(key, statusInput); - - verify(schemaView, times(1)).get(key.asSchemaKey()); - verify(schemaService, never()).updateStatus(schema.get(), statusInput.asStatus()); - assertEquals(schema.get(), result); - } - - private SchemaKeyInput getSchemaInputKey() { - return SchemaKeyInput.builder() - .domain("domain") - .name("schema") - .build(); - } - - private Schema getSchema(SchemaKeyInput key) { - return new Schema(key.asSchemaKey(), StateHelper.specification(), StateHelper.status()); - } -} diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamBindingMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamBindingMutationImplTest.java index f466fe8ec..cde379e79 100644 --- a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamBindingMutationImplTest.java +++ b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamBindingMutationImplTest.java @@ -15,10 +15,11 @@ */ package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.util.Optional; @@ -31,9 +32,7 @@ import com.expediagroup.streamplatform.streamregistry.core.services.StreamBindingService; import com.expediagroup.streamplatform.streamregistry.core.views.StreamBindingView; -import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; -import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StreamBindingKeyInput; import com.expediagroup.streamplatform.streamregistry.model.StreamBinding; @@ -57,7 +56,7 @@ public void before() throws Exception { public void deleteWithCheckExistEnabledWhenEntityExists() { ReflectionTestUtils.setField(streamBindingMutation, "checkExistEnabled", true); StreamBindingKeyInput key = getStreamBindingInputKey(); - when(streamBindingView.get(any())).thenReturn(Optional.of(getStreamBinding(key))); + when(streamBindingView.get(any())).thenReturn(Optional.of(getStream(key))); Boolean result = streamBindingMutation.delete(key); verify(streamBindingView, times(1)).get(key.asStreamBindingKey()); verify(streamBindingService, times(1)).delete(any()); @@ -79,7 +78,7 @@ public void deleteWithCheckExistEnabledWhenEntityDoesNotExist() { public void deleteWithCheckExistDisabledWhenEntiyExists() { ReflectionTestUtils.setField(streamBindingMutation, "checkExistEnabled", false); StreamBindingKeyInput key = getStreamBindingInputKey(); - when(streamBindingView.get(any())).thenReturn(Optional.of(getStreamBinding(key))); + when(streamBindingView.get(any())).thenReturn(Optional.of(getStream(key))); Boolean result = streamBindingMutation.delete(key); verify(streamBindingView, times(1)).get(key.asStreamBindingKey()); verify(streamBindingService, times(1)).delete(any()); @@ -97,39 +96,6 @@ public void deleteWithCheckExistDisabledWhenEntiyDoesNotExist() { assertTrue(result); } - @Test - public void updateStatusWithEntityStatusEnabled() { - ReflectionTestUtils.setField(streamBindingMutation, "entityStatusEnabled", true); - StreamBindingKeyInput key = getStreamBindingInputKey(); - Optional streamBinding = Optional.of(getStreamBinding(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(streamBindingView.get(any())).thenReturn(streamBinding); - when(streamBindingService.updateStatus(any(), any())).thenReturn(streamBinding); - - StreamBinding result = streamBindingMutation.updateStatus(key, statusInput); - - verify(streamBindingView, times(1)).get(key.asStreamBindingKey()); - verify(streamBindingService, times(1)).updateStatus(streamBinding.get(), statusInput.asStatus()); - assertEquals(streamBinding.get(), result); - } - - @Test - public void updateStatusWithEntityStatusDisabled() { - ReflectionTestUtils.setField(streamBindingMutation, "entityStatusEnabled", false); - StreamBindingKeyInput key = getStreamBindingInputKey(); - Optional streamBinding = Optional.of(getStreamBinding(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(streamBindingView.get(any())).thenReturn(streamBinding); - - StreamBinding result = streamBindingMutation.updateStatus(key, statusInput); - - verify(streamBindingView, times(1)).get(key.asStreamBindingKey()); - verify(streamBindingService, never()).updateStatus(streamBinding.get(), statusInput.asStatus()); - assertEquals(streamBinding.get(), result); - } - private StreamBindingKeyInput getStreamBindingInputKey() { return StreamBindingKeyInput.builder() .streamDomain("domain") @@ -140,7 +106,7 @@ private StreamBindingKeyInput getStreamBindingInputKey() { .build(); } - private StreamBinding getStreamBinding(StreamBindingKeyInput key) { + private StreamBinding getStream(StreamBindingKeyInput key) { return new StreamBinding(key.asStreamBindingKey(), StateHelper.specification(), StateHelper.status()); } } diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamMutationImplTest.java index 8203ddc9a..fa508e8c2 100644 --- a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamMutationImplTest.java +++ b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/StreamMutationImplTest.java @@ -15,10 +15,11 @@ */ package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.util.Optional; @@ -31,9 +32,7 @@ import com.expediagroup.streamplatform.streamregistry.core.services.StreamService; import com.expediagroup.streamplatform.streamregistry.core.views.StreamView; -import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; -import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StreamKeyInput; import com.expediagroup.streamplatform.streamregistry.model.Stream; @@ -96,39 +95,6 @@ public void deleteWithCheckExistDisabledWhenEntityDoesNotExist() { assertTrue(result); } - @Test - public void updateStatusWithEntityStatusEnabled() { - ReflectionTestUtils.setField(streamMutation, "entityStatusEnabled", true); - StreamKeyInput key = getStreamInputKey(); - Optional stream = Optional.of(getStream(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(streamView.get(any())).thenReturn(stream); - when(streamService.updateStatus(any(), any())).thenReturn(stream); - - Stream result = streamMutation.updateStatus(key, statusInput); - - verify(streamView, times(1)).get(key.asStreamKey()); - verify(streamService, times(1)).updateStatus(stream.get(), statusInput.asStatus()); - assertEquals(stream.get(), result); - } - - @Test - public void updateStatusWithEntityStatusDisabled() { - ReflectionTestUtils.setField(streamMutation, "entityStatusEnabled", false); - StreamKeyInput key = getStreamInputKey(); - Optional stream = Optional.of(getStream(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(streamView.get(any())).thenReturn(stream); - - Stream result = streamMutation.updateStatus(key, statusInput); - - verify(streamView, times(1)).get(key.asStreamKey()); - verify(streamService, never()).updateStatus(stream.get(), statusInput.asStatus()); - assertEquals(stream.get(), result); - } - private StreamKeyInput getStreamInputKey() { return StreamKeyInput.builder() .domain("domain") diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ZoneMutationImplTest.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ZoneMutationImplTest.java deleted file mode 100644 index ffef0d573..000000000 --- a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ZoneMutationImplTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Copyright (C) 2018-2024 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.graphql.mutation.impl; - -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; - -import java.util.Optional; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.test.util.ReflectionTestUtils; - -import com.expediagroup.streamplatform.streamregistry.core.services.ZoneService; -import com.expediagroup.streamplatform.streamregistry.core.views.ZoneView; -import com.expediagroup.streamplatform.streamregistry.graphql.InputHelper; -import com.expediagroup.streamplatform.streamregistry.graphql.StateHelper; -import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; -import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.ZoneKeyInput; -import com.expediagroup.streamplatform.streamregistry.model.Zone; - -@RunWith(MockitoJUnitRunner.class) -public class ZoneMutationImplTest { - - @Mock - private ZoneService zoneService; - - @Mock - private ZoneView zoneView; - - private ZoneMutationImpl zoneMutation; - - @Before - public void before() throws Exception { - zoneMutation = new ZoneMutationImpl(zoneService, zoneView); - } - - @Test - public void updateStatusWithEntityStatusEnabled() { - ReflectionTestUtils.setField(zoneMutation, "entityStatusEnabled", true); - ZoneKeyInput key = getZoneInputKey(); - Optional zone = Optional.of(getZone(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(zoneView.get(any())).thenReturn(zone); - when(zoneService.updateStatus(any(), any())).thenReturn(zone); - - Zone result = zoneMutation.updateStatus(key, statusInput); - - verify(zoneView, times(1)).get(key.asZoneKey()); - verify(zoneService, times(1)).updateStatus(zone.get(), statusInput.asStatus()); - assertEquals(zone.get(), result); - } - - @Test - public void updateStatusWithEntityStatusDisabled() { - ReflectionTestUtils.setField(zoneMutation, "entityStatusEnabled", false); - ZoneKeyInput key = getZoneInputKey(); - Optional zone = Optional.of(getZone(key)); - StatusInput statusInput = InputHelper.statusInput(); - - when(zoneView.get(any())).thenReturn(zone); - - Zone result = zoneMutation.updateStatus(key, statusInput); - - verify(zoneView, times(1)).get(key.asZoneKey()); - verify(zoneService, never()).updateStatus(zone.get(), statusInput.asStatus()); - assertEquals(zone.get(), result); - } - - private ZoneKeyInput getZoneInputKey() { - return ZoneKeyInput.builder() - .name("zone") - .build(); - } - - private Zone getZone(ZoneKeyInput key) { - return new Zone(key.asZoneKey(), StateHelper.specification(), StateHelper.status()); - } -} From 8118e67ec71d12c1b48e4bbf77becc5e792b86ba Mon Sep 17 00:00:00 2001 From: Andy Kruth Date: Thu, 13 Jun 2024 09:26:43 -0400 Subject: [PATCH 5/9] removing instead of deprecating save method --- .../streamregistry/repository/Repository.java | 6 ------ .../repository/kafka/DefaultRepository.java | 11 ----------- 2 files changed, 17 deletions(-) diff --git a/repository/api/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/Repository.java b/repository/api/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/Repository.java index 85e0b7732..2098b5adb 100644 --- a/repository/api/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/Repository.java +++ b/repository/api/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/Repository.java @@ -20,12 +20,6 @@ import java.util.Optional; public interface Repository { - /** - * @deprecated Use {link {@link #saveSpecification(Object)}} or {link {@link #saveStatus(Object)}} - * to save the entity specification or entity status independently. - */ - T save(T entity); - T saveSpecification(T entity); T saveStatus(T entity); diff --git a/repository/kafka/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/DefaultRepository.java b/repository/kafka/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/DefaultRepository.java index 7c963f14c..e8c7c58fe 100644 --- a/repository/kafka/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/DefaultRepository.java +++ b/repository/kafka/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/DefaultRepository.java @@ -48,17 +48,6 @@ abstract class DefaultRepository< private final Converter converter; private final Class stateKeyClass; - /** - * @deprecated Use {link {@link #saveSpecification(com.expediagroup.streamplatform.streamregistry.model.Entity)}} or - * {link {@link #saveStatus(com.expediagroup.streamplatform.streamregistry.model.Entity)}} - * to save the entity specification or entity status independently. - */ - @Deprecated - @Override - public ME save(ME entity) { - throw new UnsupportedOperationException(); - } - @Override public ME saveSpecification(ME entity) { Optional existing = findById(entity.getKey()); From 544edab8f61fc9f1fcb05ff9ea1ea57ee01c7584 Mon Sep 17 00:00:00 2001 From: Andy Kruth Date: Thu, 13 Jun 2024 09:34:32 -0400 Subject: [PATCH 6/9] removing unnecessary changes to entity view specs --- .../state/DefaultEntityView.java | 9 ----- .../state/DefaultEntityViewUpdater.java | 9 ----- .../streamregistry/state/EntityViews.java | 12 +----- .../state/DefaultEntityViewUpdaterTest.java | 40 ------------------- .../state/EntityViewUpdaterTest.java | 6 +-- 5 files changed, 4 insertions(+), 72 deletions(-) diff --git a/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityView.java b/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityView.java index 1d913de76..94336112d 100644 --- a/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityView.java +++ b/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityView.java @@ -47,19 +47,10 @@ public class DefaultEntityView implements EntityView { this(receiver, entities, new DefaultEntityViewUpdater(entities)); } - DefaultEntityView(EventReceiver receiver, Map, StateValue> entities, Boolean entityStatusEnabled) { - this(receiver, entities, new DefaultEntityViewUpdater(entities, entityStatusEnabled)); - } - - public DefaultEntityView(EventReceiver receiver, Boolean entityStatusEnabled) { - this(receiver, new ConcurrentHashMap<>(), entityStatusEnabled); - } - public DefaultEntityView(EventReceiver receiver) { this(receiver, new ConcurrentHashMap<>()); } - @Override public CompletableFuture load(@NonNull EntityViewListener listener) { val future = new CompletableFuture(); diff --git a/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdater.java b/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdater.java index 5e20a0984..9cfade7b9 100644 --- a/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdater.java +++ b/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdater.java @@ -21,7 +21,6 @@ import java.util.Map; import java.util.Optional; -import lombok.AllArgsConstructor; import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -38,11 +37,9 @@ @Slf4j @RequiredArgsConstructor -@AllArgsConstructor class DefaultEntityViewUpdater implements EntityViewUpdater { @NonNull private final Map, StateValue> entities; - private Boolean entityStatusEnabled = true; @Override public , S extends Specification> Entity update(Event event) { @@ -83,12 +80,6 @@ private , S extends Specification> Entity update(S private , S extends Specification> Entity update(StatusEvent event) { val oldEntity = (Entity) getExistingEntity(event.getKey()); - - if (!entityStatusEnabled) { - log.warn("Entity Status is disabled and is not persisted for key={}", event.getKey()); - return oldEntity; - } - if (oldEntity == null) { log.info("Received status {} non existent entity {}", event.getStatusEntry().getName(), event.getKey()); return null; diff --git a/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/EntityViews.java b/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/EntityViews.java index de530fd99..8976e7db8 100644 --- a/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/EntityViews.java +++ b/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/EntityViews.java @@ -41,22 +41,12 @@ public static EntityView defaultEntityView(EventReceiver receiver) { return new DefaultEntityView(receiver); } - @NonNull - public static EntityView defaultEntityView(EventReceiver receiver, Boolean entityStatusEnabled) { - return new DefaultEntityView(receiver, entityStatusEnabled); - } - @NonNull public static EntityView meteredEntityView(EventReceiver receiver, MeterRegistry meterRegistry) { - return meteredEntityView(receiver, meterRegistry, true); - } - - @NonNull - public static EntityView meteredEntityView(EventReceiver receiver, MeterRegistry meterRegistry, Boolean entityStatusEnabled) { Map, StateValue> entities = new ConcurrentHashMap<>(); meterRegistry.gaugeMapSize("stream_registry_state.view.entities", Tags.empty(), entities); - DefaultEntityViewUpdater defaultEntityViewUpdater = new DefaultEntityViewUpdater(entities, entityStatusEnabled); + DefaultEntityViewUpdater defaultEntityViewUpdater = new DefaultEntityViewUpdater(entities); return new DefaultEntityView(receiver, entities, new MeteredEntityViewUpdater(defaultEntityViewUpdater, meterRegistry)); } diff --git a/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdaterTest.java b/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdaterTest.java index e39c9caa0..3a36519a2 100644 --- a/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdaterTest.java +++ b/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdaterTest.java @@ -15,20 +15,8 @@ */ package com.expediagroup.streamplatform.streamregistry.state; -import static com.expediagroup.streamplatform.streamregistry.state.SampleEntities.*; -import static com.expediagroup.streamplatform.streamregistry.state.SampleEntities.statusEvent; -import static com.expediagroup.streamplatform.streamregistry.state.StateValue.existing; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; -import static org.hamcrest.collection.IsMapWithSize.aMapWithSize; -import static org.junit.Assert.*; - import java.util.Map; -import lombok.val; - -import org.junit.Test; - import com.expediagroup.streamplatform.streamregistry.state.model.Entity; public class DefaultEntityViewUpdaterTest extends EntityViewUpdaterTest { @@ -36,32 +24,4 @@ public class DefaultEntityViewUpdaterTest extends EntityViewUpdaterTest { public EntityViewUpdater entityViewUpdater(Map, StateValue> entities) { return new DefaultEntityViewUpdater(entities); } - - @Test - public void statusNotPersistedForExistingEntityWhenEntityStatusDisabled() { - EntityViewUpdater updater = new DefaultEntityViewUpdater(entities, false); - - entities.put(key, existing(oldEntity)); - val result = updater.update(statusEvent); - - assertEquals(oldEntity, result); - assertEquals(oldStatus, entities.get(key).entity.getStatus()); - } - - @Test - public void statusNotPersistedForMissingEntityWhenEntityStatusDisabled() { - EntityViewUpdater updater = new DefaultEntityViewUpdater(entities, false); - - val result = updater.update(statusEvent); - - assertNull(result); - } - - @Test - public void statusNoEntity() { - val result = underTest.update(statusEvent); - - assertThat(result, is(nullValue())); - assertThat(entities, is(aMapWithSize(0))); - } } diff --git a/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/EntityViewUpdaterTest.java b/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/EntityViewUpdaterTest.java index bf9e914fc..a4cc3366d 100644 --- a/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/EntityViewUpdaterTest.java +++ b/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/EntityViewUpdaterTest.java @@ -49,11 +49,11 @@ public abstract class EntityViewUpdaterTest { - final Map, StateValue> entities = new HashMap<>(); + private final Map, StateValue> entities = new HashMap<>(); private final DefaultSpecification oldSpecification = specification.withDescription("old-description"); - final DefaultStatus oldStatus = new DefaultStatus(); - final Entity oldEntity = entity + private final DefaultStatus oldStatus = new DefaultStatus(); + private final Entity oldEntity = entity .withSpecification(oldSpecification) .withStatus(oldStatus); From 85923a356061fc3bd43d2db4baf73e0230566c1b Mon Sep 17 00:00:00 2001 From: Andy Kruth Date: Thu, 13 Jun 2024 09:45:31 -0400 Subject: [PATCH 7/9] removed unnecessary futures --- .../streamregistry/repository/kafka/DefaultRepository.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/repository/kafka/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/DefaultRepository.java b/repository/kafka/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/DefaultRepository.java index e8c7c58fe..20e02174d 100644 --- a/repository/kafka/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/DefaultRepository.java +++ b/repository/kafka/src/main/java/com/expediagroup/streamplatform/streamregistry/repository/kafka/DefaultRepository.java @@ -52,16 +52,14 @@ abstract class DefaultRepository< public ME saveSpecification(ME entity) { Optional existing = findById(entity.getKey()); Entity stateEntity = converter.convertEntity(entity); - List> futures = new ArrayList<>(); if (existing.isPresent()) { Entity existingStateEntity = converter.convertEntity(existing.get()); if (!existingStateEntity.getSpecification().equals(stateEntity.getSpecification())) { - send(Event.specification(stateEntity.getKey(), stateEntity.getSpecification()), futures); + sender.send(Event.specification(stateEntity.getKey(), stateEntity.getSpecification())).join(); } } else { - send(Event.specification(stateEntity.getKey(), stateEntity.getSpecification()), futures); + sender.send(Event.specification(stateEntity.getKey(), stateEntity.getSpecification())).join(); } - futures.forEach(CompletableFuture::join); return entity; } From 6bff6f3efdc3bca355978d56dc3bb09d80bef04c Mon Sep 17 00:00:00 2001 From: Andy Kruth Date: Thu, 13 Jun 2024 09:51:29 -0400 Subject: [PATCH 8/9] cleanup --- .../impl/ProcessBindingMutationImpl.java | 2 +- .../mutation/impl/ProcessMutationImpl.java | 2 +- .../streamregistry/graphql/InputHelper.java | 28 ------------------- .../state/DefaultEntityView.java | 2 +- .../state/DefaultEntityViewUpdater.java | 2 +- .../streamregistry/state/EntityViews.java | 2 +- .../state/DefaultEntityViewUpdaterTest.java | 2 +- .../state/EntityViewUpdaterTest.java | 2 +- 8 files changed, 7 insertions(+), 35 deletions(-) delete mode 100644 graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/InputHelper.java diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessBindingMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessBindingMutationImpl.java index 8d6febce8..4c3068534 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessBindingMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessBindingMutationImpl.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2024 Expedia, Inc. + * Copyright (C) 2018-2023 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessMutationImpl.java b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessMutationImpl.java index 9890ecb7c..e446fc880 100644 --- a/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessMutationImpl.java +++ b/graphql/api/src/main/java/com/expediagroup/streamplatform/streamregistry/graphql/mutation/impl/ProcessMutationImpl.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2024 Expedia, Inc. + * Copyright (C) 2018-2023 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/InputHelper.java b/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/InputHelper.java deleted file mode 100644 index bb1981ff1..000000000 --- a/graphql/api/src/test/java/com/expediagroup/streamplatform/streamregistry/graphql/InputHelper.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright (C) 2018-2024 Expedia, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.expediagroup.streamplatform.streamregistry.graphql; - -import com.fasterxml.jackson.databind.ObjectMapper; - -import com.expediagroup.streamplatform.streamregistry.graphql.model.inputs.StatusInput; - -public class InputHelper { - private static final ObjectMapper mapper = new ObjectMapper(); - - public static StatusInput statusInput() { - return StatusInput.builder().agentStatus(mapper.createObjectNode()).build(); - } -} diff --git a/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityView.java b/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityView.java index 94336112d..d87c1c516 100644 --- a/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityView.java +++ b/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityView.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2024 Expedia, Inc. + * Copyright (C) 2018-2023 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdater.java b/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdater.java index 9cfade7b9..0f4c18a81 100644 --- a/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdater.java +++ b/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdater.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2024 Expedia, Inc. + * Copyright (C) 2018-2023 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/EntityViews.java b/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/EntityViews.java index 8976e7db8..e6ea2d321 100644 --- a/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/EntityViews.java +++ b/state/core/src/main/java/com/expediagroup/streamplatform/streamregistry/state/EntityViews.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2024 Expedia, Inc. + * Copyright (C) 2018-2023 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdaterTest.java b/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdaterTest.java index 3a36519a2..2f0af068f 100644 --- a/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdaterTest.java +++ b/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/DefaultEntityViewUpdaterTest.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2024 Expedia, Inc. + * Copyright (C) 2018-2023 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/EntityViewUpdaterTest.java b/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/EntityViewUpdaterTest.java index a4cc3366d..81728394e 100644 --- a/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/EntityViewUpdaterTest.java +++ b/state/core/src/test/java/com/expediagroup/streamplatform/streamregistry/state/EntityViewUpdaterTest.java @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2024 Expedia, Inc. + * Copyright (C) 2018-2023 Expedia, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 054fcad9f7f379e13ac8660ed4d41e72e1259a4c Mon Sep 17 00:00:00 2001 From: Andy Kruth Date: Thu, 13 Jun 2024 10:45:08 -0400 Subject: [PATCH 9/9] star --- .../state/kafka/KafkaEventReceiver.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/state/kafka-receiver/src/main/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventReceiver.java b/state/kafka-receiver/src/main/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventReceiver.java index cb6749cfa..9614629c5 100644 --- a/state/kafka-receiver/src/main/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventReceiver.java +++ b/state/kafka-receiver/src/main/java/com/expediagroup/streamplatform/streamregistry/state/kafka/KafkaEventReceiver.java @@ -16,7 +16,11 @@ package com.expediagroup.streamplatform.streamregistry.state.kafka; import static com.expediagroup.streamplatform.streamregistry.state.internal.EventCorrelator.CORRELATION_ID; -import static com.expediagroup.streamplatform.streamregistry.state.kafka.KafkaEventReceiver.State.*; +import static com.expediagroup.streamplatform.streamregistry.state.kafka.KafkaEventReceiver.State.CREATED; +import static com.expediagroup.streamplatform.streamregistry.state.kafka.KafkaEventReceiver.State.ERROR; +import static com.expediagroup.streamplatform.streamregistry.state.kafka.KafkaEventReceiver.State.NOT_RUNNING; +import static com.expediagroup.streamplatform.streamregistry.state.kafka.KafkaEventReceiver.State.PENDING_SHUTDOWN; +import static com.expediagroup.streamplatform.streamregistry.state.kafka.KafkaEventReceiver.State.RUNNING; import static com.expediagroup.streamplatform.streamregistry.state.model.event.Event.LOAD_COMPLETE; import static io.confluent.kafka.serializers.KafkaAvroDeserializerConfig.SCHEMA_REGISTRY_URL_CONFIG; import static io.confluent.kafka.serializers.KafkaAvroDeserializerConfig.SPECIFIC_AVRO_READER_CONFIG; @@ -38,8 +42,12 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.atomic.*; -import lombok.*; +import lombok.Builder; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Value; import lombok.extern.slf4j.Slf4j; +import lombok.val; import io.confluent.kafka.serializers.KafkaAvroDeserializer;